file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/175142722.c
#include <stdio.h> #define GIGEL 1 #ifdef CHANGE #undef GIGEL #define GIGEL 0 #endif int main(int argc, char const *argv[]) { printf("GIGEL = %d\n", GIGEL); return 0; }
the_stack_data/1270226.c
#include <assert.h> int main() { int a[2]; int *p = &(a[0]); int *q = &(a[1]); assert(p <= a); assert(p < a); assert(p >= a); assert(p > a); assert(p <= q); assert(p < q); assert(p >= q); assert(p > q); assert(q <= p); assert(q < p); assert(q >= p); assert(q > p); }
the_stack_data/68127.c
/* { dg-do compile } */ /* { dg-options "-O2 -fdump-tree-optimized" } */ int min_test(long a, long b, long c) { int cmp1 = a < b; int cmp2 = a < c; return cmp1 & cmp2; } int max_test (long a, long b, long c) { int cmp1 = a > b; int cmp2 = a > c; return cmp1 & cmp2; } /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "optimized" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "optimized" } } */
the_stack_data/953540.c
#include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <unistd.h> int isPrime(long int p){ int i = 2; while (i < p) { if(p%i == 0){ return 0; } i++; } return 1; } int process(void * arg){ int *i = (int *) arg; long int v; int ret; int cnt=0; //printf("Received %d & %d\n", i[0], i[1]); while ( (ret = read(i[0], &v, sizeof(long int) )) > 0 ) { //printf("receiving %ld\n", v); cnt=isPrime(v)?cnt+1:cnt; //printf("isPrime(%ld)? [%c]\n", v, isPrime(v)?'Y':'N'); } close(i[0]); return cnt; } int main(int argc, char const *argv[]) { pthread_t* p; int i, r, num_threads, num; void * res; int ** msPipe; long int value = 0; int cnt= 0; if (argc != 3){ printf("Usage: %s <num-threads> <num>\n", argv[0]); exit(EXIT_FAILURE); } num_threads = atoi(argv[1]); num = atoi(argv[2]); p = malloc(sizeof(pthread_t)*num_threads); msPipe = malloc(sizeof(int*)*num_threads); for (i = 0; i < num_threads; ++i) { msPipe[i] = malloc(sizeof(int)*2); if (pipe(msPipe[i]) != 0 ) { printf("Pipe creating problem [%d]\n", i); return 0; } pthread_create(&p[i], NULL, (void *)process, msPipe[i]); } i = 0; while(value < num ){ //printf("Writing %ld, to %d\n", value, (int)(value%num_threads) ); write(msPipe[(int)(value%num_threads)][1], &value, sizeof(long int)); value++; } for (i = 0 ; i<num_threads; i++){ if (close(msPipe[i][1]) != 0 ) { printf("Pipe creating problem [%d]\n", i); return 0; } } for (i = 0; i < num_threads; ++i) { r=pthread_join(p[i], &res); if(r==1){ printf("[%d] exited with failure\n",i ); exit(EXIT_FAILURE); } cnt+=res; printf("Thread %d returned %d\n", i, res ); } printf("TOTAL:%d\n",cnt ); return 0; }
the_stack_data/47058.c
#include<stdio.h> int main(){ int A,B, SOMA; scanf("%d %d", &A, &B); SOMA=A+B; printf("SOMA = %d\n", SOMA); return 0; }
the_stack_data/211080686.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <assert.h> char* argv[5]; char arg_length[] = "--length"; char arg_length_val[] = "131"; // is independent from input length char arg_keyed[] = "--keyed"; char arg_keyed_val[] = "77686174732074686520456c7669736820776f726420666f7220667269656e64"; // is independent from input length char arg_derive_key[] = "--derive-key"; char arg_derive_key_val[] = "BLAKE3 2019-12-27 16:29:52 test vectors context"; // is independent from input length int __builtin_popcountll(unsigned long long x) { int count = 0; while (x) { if (x & 1ULL) count++; x >>=1; } return count; } void test() { // Test the default hash. printf("Test the default hash."); main(1, argv); // Test the extended hash. printf("Test the extended hash."); argv[1] = arg_length; argv[2] = arg_length_val; main(3, argv); // Test the default keyed hash. printf("Test the extended hash."); argv[1] = arg_keyed; argv[2] = arg_keyed_val; main(3, argv); // Test the extended keyed hash. printf("Test the extended keyed hash."); argv[1] = arg_keyed; argv[2] = arg_keyed_val; argv[3] = arg_length; argv[4] = arg_length_val; main(5, argv); // Test the default derive key. printf("Test the default derive key."); argv[1] = arg_derive_key; argv[2] = arg_derive_key_val; main(3, argv); // Test the extended derive key. printf("Test the extended derive key."); argv[1] = arg_derive_key; argv[2] = arg_derive_key_val; argv[3] = arg_length; argv[4] = arg_length_val; main(5, argv); }
the_stack_data/154830442.c
/* * Copyright 2011 ArtForz * Copyright 2011-2013 pooler // Copyright (c) 2017 The PuffsCoin developers * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. See COPYING for more details. */ #include <string.h> #include <inttypes.h> #if defined(__arm__) && defined(__APCS_32__) #define EXTERN_SHA256 #endif static const uint32_t sha256_h[8] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 }; static const uint32_t sha256_k[64] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 }; void sha256_init(uint32_t *state) { memcpy(state, sha256_h, 32); } /* to quiet strict compiler warning */ uint32_t swab32(uint32_t i); uint32_t be32dec(uint32_t *i); uint32_t be32enc(uint32_t *j, uint32_t i); /* Elementary functions used by SHA256 */ #define Ch(x, y, z) ((x & (y ^ z)) ^ z) #define Maj(x, y, z) ((x & (y | z)) | (y & z)) #define ROTR(x, n) ((x >> n) | (x << (32 - n))) #define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) #define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) #define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ (x >> 3)) #define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ (x >> 10)) /* SHA256 round function */ #define RND(a, b, c, d, e, f, g, h, k) \ do { \ t0 = h + S1(e) + Ch(e, f, g) + k; \ t1 = S0(a) + Maj(a, b, c); \ d += t0; \ h = t0 + t1; \ } while (0) /* Adjusted round function for rotating state */ #define RNDr(S, W, i) \ RND(S[(64 - i) & 7], S[(65 - i) & 7], \ S[(66 - i) & 7], S[(67 - i) & 7], \ S[(68 - i) & 7], S[(69 - i) & 7], \ S[(70 - i) & 7], S[(71 - i) & 7], \ W[i] + sha256_k[i]) #ifndef EXTERN_SHA256 /* * SHA256 block compression function. The 256-bit state is transformed via * the 512-bit input block to produce a new state. */ void sha256_transform(uint32_t *state, const uint32_t *block, int swap) { uint32_t W[64]; uint32_t S[8]; uint32_t t0, t1; int i; /* 1. Prepare message schedule W. */ if (swap) { for (i = 0; i < 16; i++) W[i] = swab32(block[i]); } else memcpy(W, block, 64); for (i = 16; i < 64; i += 2) { W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; W[i+1] = s1(W[i - 1]) + W[i - 6] + s0(W[i - 14]) + W[i - 15]; } /* 2. Initialize working variables. */ memcpy(S, state, 32); /* 3. Mix. */ RNDr(S, W, 0); RNDr(S, W, 1); RNDr(S, W, 2); RNDr(S, W, 3); RNDr(S, W, 4); RNDr(S, W, 5); RNDr(S, W, 6); RNDr(S, W, 7); RNDr(S, W, 8); RNDr(S, W, 9); RNDr(S, W, 10); RNDr(S, W, 11); RNDr(S, W, 12); RNDr(S, W, 13); RNDr(S, W, 14); RNDr(S, W, 15); RNDr(S, W, 16); RNDr(S, W, 17); RNDr(S, W, 18); RNDr(S, W, 19); RNDr(S, W, 20); RNDr(S, W, 21); RNDr(S, W, 22); RNDr(S, W, 23); RNDr(S, W, 24); RNDr(S, W, 25); RNDr(S, W, 26); RNDr(S, W, 27); RNDr(S, W, 28); RNDr(S, W, 29); RNDr(S, W, 30); RNDr(S, W, 31); RNDr(S, W, 32); RNDr(S, W, 33); RNDr(S, W, 34); RNDr(S, W, 35); RNDr(S, W, 36); RNDr(S, W, 37); RNDr(S, W, 38); RNDr(S, W, 39); RNDr(S, W, 40); RNDr(S, W, 41); RNDr(S, W, 42); RNDr(S, W, 43); RNDr(S, W, 44); RNDr(S, W, 45); RNDr(S, W, 46); RNDr(S, W, 47); RNDr(S, W, 48); RNDr(S, W, 49); RNDr(S, W, 50); RNDr(S, W, 51); RNDr(S, W, 52); RNDr(S, W, 53); RNDr(S, W, 54); RNDr(S, W, 55); RNDr(S, W, 56); RNDr(S, W, 57); RNDr(S, W, 58); RNDr(S, W, 59); RNDr(S, W, 60); RNDr(S, W, 61); RNDr(S, W, 62); RNDr(S, W, 63); /* 4. Mix local working variables into global state */ for (i = 0; i < 8; i++) state[i] += S[i]; } #endif /* EXTERN_SHA256 */ static const uint32_t sha256d_hash1[16] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000100 }; /* static void sha256d_80_swap(uint32_t *hash, const uint32_t *data) { uint32_t S[16]; int i; sha256_init(S); sha256_transform(S, data, 0); sha256_transform(S, data + 16, 0); memcpy(S + 8, sha256d_hash1 + 8, 32); sha256_init(hash); sha256_transform(hash, S, 0); for (i = 0; i < 8; i++) hash[i] = swab32(hash[i]); } */ void sha256d(unsigned char *hash, const unsigned char *data, int len) { uint32_t S[16], T[16]; int i, r; sha256_init(S); for (r = len; r > -9; r -= 64) { if (r < 64) memset(T, 0, 64); memcpy(T, data + len - r, r > 64 ? 64 : (r < 0 ? 0 : r)); if (r >= 0 && r < 64) ((unsigned char *)T)[r] = 0x80; for (i = 0; i < 16; i++) T[i] = be32dec(T + i); if (r < 56) T[15] = 8 * len; sha256_transform(S, T, 0); } memcpy(S + 8, sha256d_hash1 + 8, 32); sha256_init(T); sha256_transform(T, S, 0); for (i = 0; i < 8; i++) be32enc((uint32_t *)hash + i, T[i]); } /* static inline void sha256d_preextend(uint32_t *W) { W[16] = s1(W[14]) + W[ 9] + s0(W[ 1]) + W[ 0]; W[17] = s1(W[15]) + W[10] + s0(W[ 2]) + W[ 1]; W[18] = s1(W[16]) + W[11] + W[ 2]; W[19] = s1(W[17]) + W[12] + s0(W[ 4]); W[20] = W[13] + s0(W[ 5]) + W[ 4]; W[21] = W[14] + s0(W[ 6]) + W[ 5]; W[22] = W[15] + s0(W[ 7]) + W[ 6]; W[23] = W[16] + s0(W[ 8]) + W[ 7]; W[24] = W[17] + s0(W[ 9]) + W[ 8]; W[25] = s0(W[10]) + W[ 9]; W[26] = s0(W[11]) + W[10]; W[27] = s0(W[12]) + W[11]; W[28] = s0(W[13]) + W[12]; W[29] = s0(W[14]) + W[13]; W[30] = s0(W[15]) + W[14]; W[31] = s0(W[16]) + W[15]; } */ /* static inline void sha256d_prehash(uint32_t *S, const uint32_t *W) { uint32_t t0, t1; RNDr(S, W, 0); RNDr(S, W, 1); RNDr(S, W, 2); } */ #ifdef EXTERN_SHA256 void sha256d_ms(uint32_t *hash, uint32_t *W, const uint32_t *midstate, const uint32_t *prehash); #else /* static inline void sha256d_ms(uint32_t *hash, uint32_t *W, const uint32_t *midstate, const uint32_t *prehash) { uint32_t S[64]; uint32_t t0, t1; int i; S[18] = W[18]; S[19] = W[19]; S[20] = W[20]; S[22] = W[22]; S[23] = W[23]; S[24] = W[24]; S[30] = W[30]; S[31] = W[31]; W[18] += s0(W[3]); W[19] += W[3]; W[20] += s1(W[18]); W[21] = s1(W[19]); W[22] += s1(W[20]); W[23] += s1(W[21]); W[24] += s1(W[22]); W[25] = s1(W[23]) + W[18]; W[26] = s1(W[24]) + W[19]; W[27] = s1(W[25]) + W[20]; W[28] = s1(W[26]) + W[21]; W[29] = s1(W[27]) + W[22]; W[30] += s1(W[28]) + W[23]; W[31] += s1(W[29]) + W[24]; for (i = 32; i < 64; i += 2) { W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; W[i+1] = s1(W[i - 1]) + W[i - 6] + s0(W[i - 14]) + W[i - 15]; } memcpy(S, prehash, 32); RNDr(S, W, 3); RNDr(S, W, 4); RNDr(S, W, 5); RNDr(S, W, 6); RNDr(S, W, 7); RNDr(S, W, 8); RNDr(S, W, 9); RNDr(S, W, 10); RNDr(S, W, 11); RNDr(S, W, 12); RNDr(S, W, 13); RNDr(S, W, 14); RNDr(S, W, 15); RNDr(S, W, 16); RNDr(S, W, 17); RNDr(S, W, 18); RNDr(S, W, 19); RNDr(S, W, 20); RNDr(S, W, 21); RNDr(S, W, 22); RNDr(S, W, 23); RNDr(S, W, 24); RNDr(S, W, 25); RNDr(S, W, 26); RNDr(S, W, 27); RNDr(S, W, 28); RNDr(S, W, 29); RNDr(S, W, 30); RNDr(S, W, 31); RNDr(S, W, 32); RNDr(S, W, 33); RNDr(S, W, 34); RNDr(S, W, 35); RNDr(S, W, 36); RNDr(S, W, 37); RNDr(S, W, 38); RNDr(S, W, 39); RNDr(S, W, 40); RNDr(S, W, 41); RNDr(S, W, 42); RNDr(S, W, 43); RNDr(S, W, 44); RNDr(S, W, 45); RNDr(S, W, 46); RNDr(S, W, 47); RNDr(S, W, 48); RNDr(S, W, 49); RNDr(S, W, 50); RNDr(S, W, 51); RNDr(S, W, 52); RNDr(S, W, 53); RNDr(S, W, 54); RNDr(S, W, 55); RNDr(S, W, 56); RNDr(S, W, 57); RNDr(S, W, 58); RNDr(S, W, 59); RNDr(S, W, 60); RNDr(S, W, 61); RNDr(S, W, 62); RNDr(S, W, 63); for (i = 0; i < 8; i++) S[i] += midstate[i]; W[18] = S[18]; W[19] = S[19]; W[20] = S[20]; W[22] = S[22]; W[23] = S[23]; W[24] = S[24]; W[30] = S[30]; W[31] = S[31]; memcpy(S + 8, sha256d_hash1 + 8, 32); S[16] = s1(sha256d_hash1[14]) + sha256d_hash1[ 9] + s0(S[ 1]) + S[ 0]; S[17] = s1(sha256d_hash1[15]) + sha256d_hash1[10] + s0(S[ 2]) + S[ 1]; S[18] = s1(S[16]) + sha256d_hash1[11] + s0(S[ 3]) + S[ 2]; S[19] = s1(S[17]) + sha256d_hash1[12] + s0(S[ 4]) + S[ 3]; S[20] = s1(S[18]) + sha256d_hash1[13] + s0(S[ 5]) + S[ 4]; S[21] = s1(S[19]) + sha256d_hash1[14] + s0(S[ 6]) + S[ 5]; S[22] = s1(S[20]) + sha256d_hash1[15] + s0(S[ 7]) + S[ 6]; S[23] = s1(S[21]) + S[16] + s0(sha256d_hash1[ 8]) + S[ 7]; S[24] = s1(S[22]) + S[17] + s0(sha256d_hash1[ 9]) + sha256d_hash1[ 8]; S[25] = s1(S[23]) + S[18] + s0(sha256d_hash1[10]) + sha256d_hash1[ 9]; S[26] = s1(S[24]) + S[19] + s0(sha256d_hash1[11]) + sha256d_hash1[10]; S[27] = s1(S[25]) + S[20] + s0(sha256d_hash1[12]) + sha256d_hash1[11]; S[28] = s1(S[26]) + S[21] + s0(sha256d_hash1[13]) + sha256d_hash1[12]; S[29] = s1(S[27]) + S[22] + s0(sha256d_hash1[14]) + sha256d_hash1[13]; S[30] = s1(S[28]) + S[23] + s0(sha256d_hash1[15]) + sha256d_hash1[14]; S[31] = s1(S[29]) + S[24] + s0(S[16]) + sha256d_hash1[15]; for (i = 32; i < 60; i += 2) { S[i] = s1(S[i - 2]) + S[i - 7] + s0(S[i - 15]) + S[i - 16]; S[i+1] = s1(S[i - 1]) + S[i - 6] + s0(S[i - 14]) + S[i - 15]; } S[60] = s1(S[58]) + S[53] + s0(S[45]) + S[44]; sha256_init(hash); RNDr(hash, S, 0); RNDr(hash, S, 1); RNDr(hash, S, 2); RNDr(hash, S, 3); RNDr(hash, S, 4); RNDr(hash, S, 5); RNDr(hash, S, 6); RNDr(hash, S, 7); RNDr(hash, S, 8); RNDr(hash, S, 9); RNDr(hash, S, 10); RNDr(hash, S, 11); RNDr(hash, S, 12); RNDr(hash, S, 13); RNDr(hash, S, 14); RNDr(hash, S, 15); RNDr(hash, S, 16); RNDr(hash, S, 17); RNDr(hash, S, 18); RNDr(hash, S, 19); RNDr(hash, S, 20); RNDr(hash, S, 21); RNDr(hash, S, 22); RNDr(hash, S, 23); RNDr(hash, S, 24); RNDr(hash, S, 25); RNDr(hash, S, 26); RNDr(hash, S, 27); RNDr(hash, S, 28); RNDr(hash, S, 29); RNDr(hash, S, 30); RNDr(hash, S, 31); RNDr(hash, S, 32); RNDr(hash, S, 33); RNDr(hash, S, 34); RNDr(hash, S, 35); RNDr(hash, S, 36); RNDr(hash, S, 37); RNDr(hash, S, 38); RNDr(hash, S, 39); RNDr(hash, S, 40); RNDr(hash, S, 41); RNDr(hash, S, 42); RNDr(hash, S, 43); RNDr(hash, S, 44); RNDr(hash, S, 45); RNDr(hash, S, 46); RNDr(hash, S, 47); RNDr(hash, S, 48); RNDr(hash, S, 49); RNDr(hash, S, 50); RNDr(hash, S, 51); RNDr(hash, S, 52); RNDr(hash, S, 53); RNDr(hash, S, 54); RNDr(hash, S, 55); RNDr(hash, S, 56); hash[2] += hash[6] + S1(hash[3]) + Ch(hash[3], hash[4], hash[5]) + S[57] + sha256_k[57]; hash[1] += hash[5] + S1(hash[2]) + Ch(hash[2], hash[3], hash[4]) + S[58] + sha256_k[58]; hash[0] += hash[4] + S1(hash[1]) + Ch(hash[1], hash[2], hash[3]) + S[59] + sha256_k[59]; hash[7] += hash[3] + S1(hash[0]) + Ch(hash[0], hash[1], hash[2]) + S[60] + sha256_k[60] + sha256_h[7]; } */ #endif /* EXTERN_SHA256 */ #if HAVE_SHA256_4WAY void sha256d_ms_4way(uint32_t *hash, uint32_t *data, const uint32_t *midstate, const uint32_t *prehash); static inline int scanhash_sha256d_4way(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done) { uint32_t data[4 * 64] __attribute__((aligned(128))); uint32_t hash[4 * 8] __attribute__((aligned(32))); uint32_t midstate[4 * 8] __attribute__((aligned(32))); uint32_t prehash[4 * 8] __attribute__((aligned(32))); uint32_t n = pdata[19] - 1; const uint32_t first_nonce = pdata[19]; const uint32_t Htarg = ptarget[7]; int i, j; memcpy(data, pdata + 16, 64); sha256d_preextend(data); for (i = 31; i >= 0; i--) for (j = 0; j < 4; j++) data[i * 4 + j] = data[i]; sha256_init(midstate); sha256_transform(midstate, pdata, 0); memcpy(prehash, midstate, 32); sha256d_prehash(prehash, pdata + 16); for (i = 7; i >= 0; i--) { for (j = 0; j < 4; j++) { midstate[i * 4 + j] = midstate[i]; prehash[i * 4 + j] = prehash[i]; } } do { for (i = 0; i < 4; i++) data[4 * 3 + i] = ++n; sha256d_ms_4way(hash, data, midstate, prehash); for (i = 0; i < 4; i++) { if (swab32(hash[4 * 7 + i]) <= Htarg) { pdata[19] = data[4 * 3 + i]; sha256d_80_swap(hash, pdata); if (fulltest(hash, ptarget)) { *hashes_done = n - first_nonce + 1; return 1; } } } } while (n < max_nonce && !work_restart[thr_id].restart); *hashes_done = n - first_nonce + 1; pdata[19] = n; return 0; } #endif /* HAVE_SHA256_4WAY */ #if HAVE_SHA256_8WAY void sha256d_ms_8way(uint32_t *hash, uint32_t *data, const uint32_t *midstate, const uint32_t *prehash); #endif /* HAVE_SHA256_8WAY */
the_stack_data/93887716.c
#include <stdio.h> #include <time.h> #include <stdlib.h> #define N 100 #define BOARD_SIZE 5 typedef struct Position { int board; int row; int column; } Position; typedef struct PositionList { Position positions[N]; int length; } PositionList; void add_position(PositionList *l, int b, int r, int c) { if (l->length == N) { printf("ERROR adding to a full list: %d %d %d", b, r, c); exit(0); } l->positions[l->length].board = b; l->positions[l->length].row = r; l->positions[l->length].column = c; l->length++; } int run(char* s) { int boards[N][BOARD_SIZE][BOARD_SIZE] = {0}; int draws[N] = {0}; int marked[N] = {0}; int won[N] = {0}; PositionList pos[N]; int i = 0, k = 0, b = -1, r = 0, c = 0, j, complete, count_wins = 0; while (s[i]) { if (k < N) { if (s[i] == ',' || s[i] == '\n') { pos[k].length = 0; k++; } else draws[k] = draws[k]*10+(int)(s[i]-'0'); i++; continue; } if (b == -1) { while (s[i] == '\n' || s[i] == ' ') i++; b = 0; continue; } if (s[i] == ' ') { while (s[i] == ' ') i++; add_position(pos + boards[b][r][c], b, r, c); c++; continue; } if (s[i] == '\n') { while (s[i] == '\n' || s[i] == ' ') i++; add_position(pos + boards[b][r][c], b, r, c); if (r < BOARD_SIZE-1) { r++; c = 0; continue; } b++; r = 0; c = 0; continue; } boards[b][r][c] = boards[b][r][c]*10+(int)(s[i]-'0'); i++; } if (c != 0) { add_position(pos + boards[b][r][c], b, r, c); } for (i = 0; i < N; i++) { marked[draws[i]] = 1; for (k = 0; k < pos[draws[i]].length; k++) { b = pos[draws[i]].positions[k].board; r = pos[draws[i]].positions[k].row; c = pos[draws[i]].positions[k].column; if (won[b]) continue; complete = 1; for (j = 0; j < BOARD_SIZE; j++) { if (!marked[boards[b][r][(c+j)%BOARD_SIZE]]) { complete = 0; break; } } if (!complete) { complete = 1; for (j = 0; j < BOARD_SIZE; j++) { if (!marked[boards[b][(r+j)%BOARD_SIZE][c]]) { complete = 0; break; } } } if (complete) { won[b] = 1; count_wins++; } if (complete && count_wins == N) { complete = 0; for (r = 0; r < BOARD_SIZE; r++) for (c = 0; c < BOARD_SIZE; c++) complete += (!marked[boards[b][r][c]])?boards[b][r][c]:0; return complete*draws[i]; } } } return 0; } int main(int argc, char** argv) { if (argc < 2) { printf("Missing one argument\n"); exit(1); } clock_t start = clock(); int answer = run(argv[1]); printf("_duration:%f\n%d\n", (float)( clock () - start ) * 1000.0 / CLOCKS_PER_SEC, answer); return 0; }
the_stack_data/80258.c
/** ****************************************************************************** * @file stm32l4xx_ll_comp.c * @author MCD Application Team * @brief COMP LL module driver ****************************************************************************** * @attention * * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2> * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ #if defined(USE_FULL_LL_DRIVER) /* Includes ------------------------------------------------------------------*/ #include "stm32l4xx_ll_comp.h" #ifdef USE_FULL_ASSERT #include "stm32_assert.h" #else #define assert_param(expr) ((void)0U) #endif /** @addtogroup STM32L4xx_LL_Driver * @{ */ #if defined (COMP1) || defined (COMP2) /** @addtogroup COMP_LL COMP * @{ */ /* Private types -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /* Private macros ------------------------------------------------------------*/ /** @addtogroup COMP_LL_Private_Macros * @{ */ /* Check of parameters for configuration of COMP hierarchical scope: */ /* COMP instance. */ #define IS_LL_COMP_POWER_MODE(__POWER_MODE__) \ ( ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED) \ || ((__POWER_MODE__) == LL_COMP_POWERMODE_MEDIUMSPEED) \ || ((__POWER_MODE__) == LL_COMP_POWERMODE_ULTRALOWPOWER) \ ) /* Note: On this STM32 serie, comparator input plus parameters are */ /* the same on all COMP instances. */ /* However, comparator instance kept as macro parameter for */ /* compatibility with other STM32 families. */ #if defined(COMP_CSR_INPSEL_1) #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \ ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \ || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \ || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO3) \ ) #else #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \ ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \ || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \ ) #endif /* Note: On this STM32 serie, comparator input minus parameters are */ /* the same on all COMP instances. */ /* However, comparator instance kept as macro parameter for */ /* compatibility with other STM32 families. */ #if defined(COMP_CSR_INMESEL_1) #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \ ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO3) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO5) \ ) #else #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \ ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \ || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \ ) #endif #define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \ ( ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE) \ || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_LOW) \ || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_MEDIUM) \ || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_HIGH) \ ) #define IS_LL_COMP_OUTPUT_POLARITY(__POLARITY__) \ ( ((__POLARITY__) == LL_COMP_OUTPUTPOL_NONINVERTED) \ || ((__POLARITY__) == LL_COMP_OUTPUTPOL_INVERTED) \ ) #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__OUTPUT_BLANKING_SOURCE__) \ ( ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) \ || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1) \ || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1) \ || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1) \ || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2) \ || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2) \ || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2) \ ) /** * @} */ /* Private function prototypes -----------------------------------------------*/ /* Exported functions --------------------------------------------------------*/ /** @addtogroup COMP_LL_Exported_Functions * @{ */ /** @addtogroup COMP_LL_EF_Init * @{ */ /** * @brief De-initialize registers of the selected COMP instance * to their default reset values. * @note If comparator is locked, de-initialization by software is * not possible. * The only way to unlock the comparator is a device hardware reset. * @param COMPx COMP instance * @retval An ErrorStatus enumeration value: * - SUCCESS: COMP registers are de-initialized * - ERROR: COMP registers are not de-initialized */ ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx) { ErrorStatus status = SUCCESS; /* Check the parameters */ assert_param(IS_COMP_ALL_INSTANCE(COMPx)); /* Note: Hardware constraint (refer to description of this function): */ /* COMP instance must not be locked. */ if(LL_COMP_IsLocked(COMPx) == 0U) { LL_COMP_WriteReg(COMPx, CSR, 0x00000000U); } else { /* Comparator instance is locked: de-initialization by software is */ /* not possible. */ /* The only way to unlock the comparator is a device hardware reset. */ status = ERROR; } return status; } /** * @brief Initialize some features of COMP instance. * @note This function configures features of the selected COMP instance. * Some features are also available at scope COMP common instance * (common to several COMP instances). * Refer to functions having argument "COMPxy_COMMON" as parameter. * @param COMPx COMP instance * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure * @retval An ErrorStatus enumeration value: * - SUCCESS: COMP registers are initialized * - ERROR: COMP registers are not initialized */ ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct) { ErrorStatus status = SUCCESS; /* Check the parameters */ assert_param(IS_COMP_ALL_INSTANCE(COMPx)); assert_param(IS_LL_COMP_POWER_MODE(COMP_InitStruct->PowerMode)); assert_param(IS_LL_COMP_INPUT_PLUS(COMPx, COMP_InitStruct->InputPlus)); assert_param(IS_LL_COMP_INPUT_MINUS(COMPx, COMP_InitStruct->InputMinus)); assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct->InputHysteresis)); assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct->OutputPolarity)); assert_param(IS_LL_COMP_OUTPUT_BLANKING_SOURCE(COMP_InitStruct->OutputBlankingSource)); /* Note: Hardware constraint (refer to description of this function) */ /* COMP instance must not be locked. */ if(LL_COMP_IsLocked(COMPx) == 0U) { /* Configuration of comparator instance : */ /* - PowerMode */ /* - InputPlus */ /* - InputMinus */ /* - InputHysteresis */ /* - OutputPolarity */ /* - OutputBlankingSource */ #if defined(COMP_CSR_INMESEL_1) MODIFY_REG(COMPx->CSR, COMP_CSR_PWRMODE | COMP_CSR_INPSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN | COMP_CSR_INMESEL | COMP_CSR_INMSEL | COMP_CSR_HYST | COMP_CSR_POLARITY | COMP_CSR_BLANKING , COMP_InitStruct->PowerMode | COMP_InitStruct->InputPlus | COMP_InitStruct->InputMinus | COMP_InitStruct->InputHysteresis | COMP_InitStruct->OutputPolarity | COMP_InitStruct->OutputBlankingSource ); #else MODIFY_REG(COMPx->CSR, COMP_CSR_PWRMODE | COMP_CSR_INPSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN | COMP_CSR_INMSEL | COMP_CSR_HYST | COMP_CSR_POLARITY | COMP_CSR_BLANKING , COMP_InitStruct->PowerMode | COMP_InitStruct->InputPlus | COMP_InitStruct->InputMinus | COMP_InitStruct->InputHysteresis | COMP_InitStruct->OutputPolarity | COMP_InitStruct->OutputBlankingSource ); #endif } else { /* Initialization error: COMP instance is locked. */ status = ERROR; } return status; } /** * @brief Set each @ref LL_COMP_InitTypeDef field to default value. * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure * whose fields will be set to default values. * @retval None */ void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct) { /* Set COMP_InitStruct fields to default values */ COMP_InitStruct->PowerMode = LL_COMP_POWERMODE_ULTRALOWPOWER; COMP_InitStruct->InputPlus = LL_COMP_INPUT_PLUS_IO1; COMP_InitStruct->InputMinus = LL_COMP_INPUT_MINUS_VREFINT; COMP_InitStruct->InputHysteresis = LL_COMP_HYSTERESIS_NONE; COMP_InitStruct->OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED; COMP_InitStruct->OutputBlankingSource = LL_COMP_BLANKINGSRC_NONE; } /** * @} */ /** * @} */ /** * @} */ #endif /* COMP1 || COMP2 */ /** * @} */ #endif /* USE_FULL_LL_DRIVER */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
the_stack_data/126703735.c
#include <sys/types.h> #include <unistd.h> static pid_t c_fork(void) { return fork(); }
the_stack_data/61496.c
#include <stdio.h> int test(void) { printf("hello world\n"); return 0; } int main () { int x; x = test(); printf("%d\n", x); return 0; }
the_stack_data/168894596.c
/******************************************************************************* * Quad precision implementation of discrete Legendre transform (DLT). * Copyright (c) 2015 Nick Hale and Alex Townsend * * 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/>. * ******************************************************************************/ #include <math.h> #include <stdio.h> #include <stdlib.h> #include <quadmath.h> void main( void); void drive(int N, long double *v, long double *x, long double *w, long double *c); void gaussq(__float128 **a, __float128 *b, __float128 *x, int n); /******************************************************************************/ /******************************************************************************/ /******************************************************************************/ void drive(int N, long double *v, long double *x, long double *w, long double *c) { long int i, j, l; __float128 xi, vi, P, Pm1, Pm2, n, Pp, Ppm1, Ppm2; __float128 **a, *cq, *vq; FILE * fid; // Dynamic storage: a = calloc(N, sizeof(__float128 *)); --a; for ( i = 1; i <= N; ++i ) { a[i] = calloc(N, sizeof(__float128)); --a[i]; } vq = calloc(N, sizeof(__float128)); --vq; cq = calloc(N, sizeof(__float128)); --cq; for ( i = 0 ; i < N ; i++ ) { xi = ((__float128)x[i]); for ( l = 0 ; l < 2 ; l++ ) { // Improve accuracy of root via Newton. Pm2 = 1.; Pm1 = xi; Ppm2 = 0.; Ppm1 = 1.; for ( j = 2 ; j <= N ; j++ ) { n = ((__float128)j); P = (2. - 1./n) * Pm1 * xi - (1. - 1./n) * Pm2; Pp = (2. - 1./n) * (Pm1 + Ppm1 * xi) - (1. - 1./n) * Ppm2; Pm2 = Pm1; Pm1 = P; Ppm2 = Ppm1; Ppm1 = Pp; } xi -= P / Pp; } Pm2 = 1.; Pm1 = xi; a[i+1][1] = Pm2; a[i+1][2] = Pm1; for ( j = 2 ; j < N ; j++ ) { n = ((__float128)j); P = (2. - 1./n) * Pm1 * xi - (1. - 1./n) * Pm2; a[i+1][j+1] = P; Pm2 = Pm1; Pm1 = P; } } for ( i = 0 ; i < N ; i++ ) { vq[i+1] = (__float128)v[i]; } gaussq(a, vq, cq, N); for ( i = 0 ; i < N ; i++ ) { c[i] = (double)cq[i+1]; } for ( i = 1; i <= N; ++i ) { free(++a[i]); } free(++a); free(++vq); free(++cq); return; } /******************************************************************************/ /******************************************************************************/ /******************************************************************************/ /* Gaussian elimination code. */ void gaussq(__float128 **a, __float128 *b, __float128 *x, int n) { int i,j,k,m; __float128 xfac, temp, temp1, amax; /* Forward reduction */ for ( k = 1; k <= n - 1; ++k ) { amax = (__float128) fabsq(a[k][k]) ; m = k; /* Determine pivot */ for ( i = k + 1; i <= n; i++ ){ xfac = (__float128) fabsq(a[i][k]); if ( xfac > amax ) { amax = xfac; m = i; } } /* Row interchanges */ if ( m != k ) { temp1 = b[k]; b[k] = b[m]; b[m] = temp1; for ( j = k; j <= n; j++ ) { temp = a[k][j]; a[k][j] = a[m][j]; a[m][j] = temp; } } /* Row ellimination */ for ( i = k + 1; i <= n; ++i ) { xfac = a[i][k]/a[k][k]; for ( j = k + 1; j <= n; ++j ) { a[i][j] = a[i][j] - xfac*a[k][j]; } b[i] = b[i] - xfac*b[k]; } } /* Back substitution */ for ( j = 1; j <= n; ++j ) { k = n - j + 1; x[k] = b[k]; for ( i = k + 1; i <= n; ++i ) { x[k] = x[k] - a[k][i]*x[i]; } x[k] = x[k]/a[k][k]; } } /******************************************************************************/ /******************************************************************************/ /******************************************************************************/ void main( void ) { int k, N = 0; long double v[100002]; long double x[100002]; long double w[100002]; long double c[100002]; FILE * fid; ; fid = fopen("data.bin", "r"); while (!feof(fid)) { if ( fscanf(fid, "%Lf", &c[N]) == 1 ) ++N; } fclose(fid); fid = fopen("data_x.bin", "r"); for ( k = 0; k < N ; k++ ) { fscanf(fid, "%Lf", &x[k]); } fclose(fid); fid = fopen("data_w.bin", "r"); for ( k = 0; k < N ; k++ ) { fscanf(fid, "%Lf", &w[k]); } fclose(fid); drive( N, c, x, w, v ); fid = fopen("results.bin", "w+"); for ( k = 0; k < N ; k++ ) fprintf(fid, "%33.33Lg\n", v[k]); fclose(fid); }
the_stack_data/58114.c
/* ************************************************************************** */ /* */ /* :::::::: */ /* ft_isdigit.c :+: :+: */ /* +:+ */ /* By: rnijhuis <[email protected]> +#+ */ /* +#+ */ /* Created: 2021/11/09 09:43:53 by rnijhuis #+# #+# */ /* Updated: 2021/11/09 09:43:53 by rnijhuis ######## odam.nl */ /* */ /* ************************************************************************** */ int ft_isdigit(int c) { return (c >= '0' && c <= '9'); }
the_stack_data/125141344.c
// C Program to Reverse a Number // C programming source code to reverse a number entered by user with output.. #include <stdio.h> int main() { int n, reversedNumber = 0, remainder; printf("Enter an integer: "); scanf("%d", &n); while(n != 0) { remainder = n%10; reversedNumber = reversedNumber*10 + remainder; n /= 10; } printf("Reversed Number = %d", reversedNumber); return 0; } // https://www.programiz.com/c-programming/examples/reverse-number
the_stack_data/243894420.c
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <string.h> typedef struct num { int num; struct num * next; } student; int main(void) { int i, j; student* head = NULL; student* tail = NULL; student* p = NULL; student* q = NULL; student *temp; bool ishead = true; for (i=1; i<31; i++) { student *people = malloc(sizeof(student)); people->num = i; if (ishead){ head = people; head -> next = NULL; tail = people; ishead = false; } else { tail->next = people; tail = people; } } if (NULL != tail || NULL == tail) { tail->next = head; } i=30; p=head; q=head; while (i>15) { for (j=1; j<10; j++) { if (j==9) { printf("the num %d get off \n", p->num); i--; q->next = p->next; free(p); p = q->next; } else { q=p; p = p->next; } } } return 0; }
the_stack_data/1026489.c
#include <stdio.h> #include <string.h> /* * ----------------------------------- * | Pedro Daniel Jardim | * | UFV | * | 29/02/2020 | * ---------------------------------- * */ void main () { char pergunta[10]; while (scanf(" %[^\n]", pergunta) != EOF) { if (strcmp(pergunta, "esquerda") == 0) printf("ingles\n"); else if (strcmp(pergunta, "direita") == 0) printf("frances\n"); else if (strcmp(pergunta, "nenhuma") == 0) printf("portugues\n"); else if (strcmp(pergunta, "as duas") == 0) printf("caiu\n"); } }
the_stack_data/1267553.c
/*****************************************************************/ /* Class: Computer Programming, Fall 2019 */ /* Author: 林天佑 */ /* ID: 108820003 */ /* Date: 2019.09.17 */ /* Purpose: Be the best student. */ /* GitHub: https://github.com/Xanonymous-GitHub/main/tree/HW */ /*****************************************************************/ #include<stdio.h> int main(int argc,char* argv[]){ //show a message that tells user there is the input place. printf("Enter phone number [(xxx) xxx-xxxx]: "); //init three variables to store the user datas int a,b,c; //get the data that user inputed. scanf("(%d) %d-%d",&a,&b,&c); //output the result. printf("You entered %d.%d.%d",a,b,c); return 0; }
the_stack_data/76700428.c
/*********************************************************************** * FILENAME : main.c * * DESCRIPTION : * Simple record store for a hosptial * * * AUTHOR : P.T.R. Muthukumarana(170393U) * * **/ /** * Note : Code for some validation was not included because the source * would otherwise be longer. * * */ #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <string.h> #include <ctype.h> #include <time.h> #include "md5.h" #define MAX_ATTRIBUTE_SIZE 256 #define MAX_ATTRIBUTE_COUNT 10 #define PERMISSION_SIZE 100 #define MAX_RECORD_LENGTH ((MAX_ATTRIBUTE_SIZE + 1) * MAX_ATTRIBUTE_COUNT) #define CONFIG_FILE "config.dat" #define DATA_FILE "data.dat"; #define DESCRIPTION_LENGTH 256 typedef enum PrivilegeLevelEnum { LEVEL1, LEVEL2, LEVEL3, LEVEL4 } PrivilegeLevel; typedef enum UserTypeEnum { PATIENT, HOSPITAL_STAFF, DOCTOR, ADMIN } UserType; typedef enum RecordTypeEnum { ID_RECORD, USER_RECORD, PATIENT_INFO_RECORD, SICKNESS_INFO_RECORD, DRUG_PRESCRIPTION_RECORD, LAB_TEST_PRESCRIPTION_RECORD } RecordType; typedef struct IdStruct { int last_user_id; int last_patient_info_id; int last_sickness_info_id; int last_drug_prescription_id; int last_lab_test_prescription_id; } Id; typedef struct UserStruct { int id; char username[MAX_ATTRIBUTE_SIZE]; char password[MAX_ATTRIBUTE_SIZE]; UserType user_type; PrivilegeLevel privilege_level; } User; typedef struct PatientInfoStruct { int id; int user_id; char name[MAX_ATTRIBUTE_SIZE]; char phone[20]; char gender; int birth_year; } PatientInfo; typedef struct SicknessInfoStruct { int id; int patient_id; int doctor_id; char datetime[100]; char description[DESCRIPTION_LENGTH]; } SicknessInfo; typedef struct PrescriptionStruct { int id; int patient_id; int doctor_id; char datetime[100]; char prescription[DESCRIPTION_LENGTH]; } Prescription; bool search(const char **array, char *item) { for (int i = 0; i < sizeof(array) / sizeof(array[0]); i++) { if (strncmp(array[i], item, sizeof(char) * (strlen(array[i]) + 1)) == 0) { return true; } } return false; } User *current_user; const char *level1_privileges[4] = { "READ_SELF_PATIENT_RECORD", "READ_SELF_LAB_PRESCRIPTION_RECORD", "READ_SELF_DRUG_PRESCRIPTION_RECORD", "READ_SELF_SICKNESS_RECORD"}; const char *level2_privileges[4] = { "CREATE_PATIENT_RECORD", "READ_ANY_PATIENT_RECORD", "READ_ANY_LAB_PRESCRIPTION_RECORD", "READ_ANY_DRUG_PRESCRIPTION_RECORD", }; const char *level3_privileges[6] = { "CREATE_SICKNESS_RECORD", "CREATE_PRESCRIPTION_RECORD", "READ_ANY_PATIENT_RECORD", "READ_ANY_LAB_PRESCRIPTION_RECORD", "READ_ANY_DRUG_PRESCRIPTION_RECORD", "READ_ANY_SICKNESS_RECORD"}; const char *level4_privileges[1] = { "CREATE_USER_RECORD"}; bool has_privilege(PrivilegeLevel level, char *privilege) { switch (level) { case LEVEL1: return search(level1_privileges, privilege); case LEVEL2: return search(level2_privileges, privilege); case LEVEL3: return search(level3_privileges, privilege); case LEVEL4: return search(level4_privileges, privilege); default: return false; } } char *generate_privilege_string(char *holder, RecordType type, char *action, char *owner) { char *record_string; switch (type) { case USER_RECORD: record_string = "USER_RECORD"; break; case PATIENT_INFO_RECORD: record_string = "PATIENT_RECORD"; break; case DRUG_PRESCRIPTION_RECORD: record_string = "DRUG_PRESCRIPTION_RECORD"; break; case LAB_TEST_PRESCRIPTION_RECORD: record_string = "LAB_TEST_PRESCRIPTION_RECORD"; break; case SICKNESS_INFO_RECORD: record_string = "SICKNESS_RECORD"; break; default: printf("Error incorrect record type"); exit(2); break; } sprintf("%s_%s_%s", action, owner, record_string); return holder; } char *user_record_to_string(User *record, char *str) { sprintf(str, "%d;%d;%s;%s;%d;%d\n", USER_RECORD, record->id, record->username, record->password, record->user_type, record->privilege_level); return str; } char *prescription_to_string(Prescription *record, char *str, RecordType type) { sprintf(str, "%d;%d;%d;%d;%s;%s\n", type, record->id, record->patient_id, record->doctor_id, record->datetime, record->prescription); return str; } char *patient_info_to_string(PatientInfo *record, char *str) { sprintf(str, "%d;%d;%d;%s;%s;%c;%d\n", PATIENT_INFO_RECORD, record->id, record->user_id, record->name, record->phone, record->gender, record->birth_year); return str; } char *sickness_info_to_string(SicknessInfo *record, char *str) { sprintf(str, "%d;%d;%d;%d;%s;%s\n", SICKNESS_INFO_RECORD, record->id, record->patient_id, record->doctor_id, record->datetime, record->description); return str; } char *id_to_string(Id *record, char *str) { sprintf(str, "%d;%d;%d;%d;%d;%d;%d\n", ID_RECORD, 0, record->last_user_id, record->last_patient_info_id, record->last_sickness_info_id, record->last_drug_prescription_id, record->last_lab_test_prescription_id); return str; } char *get_file_name(RecordType record_type) { char *file_name; switch (record_type) { case USER_RECORD: case ID_RECORD: file_name = CONFIG_FILE; break; case PATIENT_INFO_RECORD: case SICKNESS_INFO_RECORD: case LAB_TEST_PRESCRIPTION_RECORD: case DRUG_PRESCRIPTION_RECORD: file_name = DATA_FILE; } return file_name; } FILE *open_file(RecordType record_type, char *mode) { char *file_name = get_file_name(record_type); FILE *file = fopen(file_name, mode); if (file == NULL) { printf("Error: Coudln't open %s file!", file_name); exit(1); } return file; } void read_line(char *holder) { fgets(holder, MAX_ATTRIBUTE_SIZE, stdin); holder[strlen(holder) - 1] = '\0'; } bool read_character(char *c) { char buffer[MAX_ATTRIBUTE_SIZE]; read_line(buffer); if (strlen(buffer) > 1) { return false; } else { *(c) = buffer[0]; return true; } } bool read_digit(int *digit) { char c; bool status = read_character(&c); if (status) { if (isdigit(c)) { *digit = c - '0'; return true; } } return false; } void *allocate_space_for_record(RecordType type) { switch (type) { case USER_RECORD: return malloc(sizeof(User)); case PATIENT_INFO_RECORD: return malloc(sizeof(PatientInfo)); case DRUG_PRESCRIPTION_RECORD: case LAB_TEST_PRESCRIPTION_RECORD: return malloc(sizeof(Prescription)); case SICKNESS_INFO_RECORD: return malloc(sizeof(SicknessInfo)); case ID_RECORD: return malloc(sizeof(Id)); default: printf("Error incorrect record type"); exit(2); } } void set_attribute_for_record(void *record, RecordType type, int attribute, char *token) { switch (type) { case USER_RECORD: { User *user = (User *)record; switch (attribute) { case 1: user->id = atoi(token); break; case 2: strcpy(user->username, token); break; case 3: strcpy(user->password, token); break; case 4: user->user_type = atoi(token); break; case 5: user->privilege_level = atoi(token); break; } } break; case PATIENT_INFO_RECORD: { PatientInfo *patient_info = (PatientInfo *)record; switch (attribute) { case 1: patient_info->id = atoi(token); break; case 2: patient_info->user_id = atoi(token); case 3: strcpy(patient_info->name, token); break; case 4: strcpy(patient_info->phone, token); break; case 5: patient_info->gender = (char)token[0]; break; case 6: patient_info->birth_year = atoi(token); break; } } break; case DRUG_PRESCRIPTION_RECORD: case LAB_TEST_PRESCRIPTION_RECORD: { Prescription *prescription = (Prescription *)record; switch (attribute) { case 1: prescription->id = atoi(token); break; case 2: prescription->patient_id = atoi(token); break; case 3: prescription->doctor_id = atoi(token); break; case 4: strcpy(prescription->datetime, token); break; case 5: strcpy(prescription->prescription, token); break; } } break; case SICKNESS_INFO_RECORD: { SicknessInfo *sickness_info = (SicknessInfo *)record; switch (attribute) { case 1: sickness_info->id = atoi(token); break; case 2: sickness_info->patient_id = atoi(token); break; case 3: sickness_info->doctor_id = atoi(token); break; case 4: strcpy(sickness_info->datetime, token); break; case 5: strcpy(sickness_info->description, token); break; } } case ID_RECORD: { Id *ids = (Id *)record; switch (attribute) { case 2: ids->last_user_id = atoi(token); break; case 3: ids->last_patient_info_id = atoi(token); break; case 4: ids->last_sickness_info_id = atoi(token); break; case 5: ids->last_drug_prescription_id = atoi(token); break; case 6: ids->last_lab_test_prescription_id = atoi(token); break; } } break; default: printf("Error incorrect record type"); exit(2); } } int next_token(char *string, char *token, int *current) { int t = 0; while (string[*current] != '\0') { if (string[*current] == ';' || string[*current] == '\n') { (*current)++; token[t] = '\0'; return 1; } else { token[t] = string[*current]; t++; } (*current)++; } return -1; } void *find_single_record(RecordType record_type, int search_attribute, char *value) { FILE *file = open_file(record_type, "r"); char *buffer = NULL; size_t len = 0; bool found = false; void *current = allocate_space_for_record(record_type); int token_start, attribute; char token[MAX_ATTRIBUTE_SIZE]; while (getline(&buffer, &len, file) != -1) { token_start = 0; attribute = 0; while (next_token(buffer, token, &token_start) != -1) { if (attribute == 0) { if (atoi(token) != record_type) break; } // else // { if (attribute == search_attribute && strncmp(value, token, sizeof token) == 0) { found = true; } set_attribute_for_record(current, record_type, attribute, token); // } attribute++; } if (found) { break; } } if (buffer != NULL) free(buffer); // if (token != NULL) // free(token); fclose(file); if (found) return current; else return NULL; } // update_record void update_record(RecordType record_type, int id, char *new_row) { FILE *file = open_file(record_type, "r"); char *buffer = NULL; char *content = NULL; char *token = (char *)malloc(MAX_ATTRIBUTE_SIZE + 1); int start; size_t len = 0; while (getline(&buffer, &len, file) != -1) { start = 0; if (next_token(buffer, token, &start) != -1) { if (atoi(token) == id) { // Space is needed for attributes, commas and the null byte if (content == NULL) { content = malloc((strlen(new_row) + 1) * sizeof(char)); strcpy(content, new_row); } else { content = realloc(content, (strlen(content) + strlen(new_row) + 1) * sizeof(char)); strcat(content, new_row); } } else { if (content == NULL) { content = malloc((strlen(buffer) + 1) * sizeof(char)); strcpy(content, buffer); } else { content = realloc(content, (strlen(content) + strlen(buffer) + 1) * sizeof(char)); strcat(content, buffer); } } } } free(buffer); fclose(file); char temp_file_name[100]; strcpy(temp_file_name, get_file_name(record_type)); strcat(temp_file_name, ".tmp"); FILE *temp = fopen(temp_file_name, "w"); fputs(content, temp); free(content); fclose(temp); remove(get_file_name(record_type)); rename(temp_file_name, get_file_name(record_type)); } int get_last_id(RecordType type) { Id *ids = (Id *)find_single_record(ID_RECORD, 0, "0"); int num; switch (type) { case USER_RECORD: num = ids->last_user_id; break; case PATIENT_INFO_RECORD: num = ids->last_patient_info_id; break; case DRUG_PRESCRIPTION_RECORD: num = ids->last_drug_prescription_id; break; case LAB_TEST_PRESCRIPTION_RECORD: num = ids->last_lab_test_prescription_id; break; case SICKNESS_INFO_RECORD: num = ids->last_drug_prescription_id; break; default: printf("Error incorrect record type"); exit(2); break; } return num; } void set_last_id(RecordType type, int new_id) { char ids[MAX_RECORD_LENGTH]; Id *id = (Id *)find_single_record(ID_RECORD, 0, "0"); switch (type) { case USER_RECORD: id->last_user_id = new_id; break; case PATIENT_INFO_RECORD: id->last_patient_info_id = new_id; break; case DRUG_PRESCRIPTION_RECORD: id->last_drug_prescription_id = new_id; break; case LAB_TEST_PRESCRIPTION_RECORD: id->last_lab_test_prescription_id = new_id; break; case SICKNESS_INFO_RECORD: id->last_drug_prescription_id = new_id; break; default: printf("Error incorrect record type\n"); exit(2); break; } id_to_string(id, ids); update_record(ID_RECORD, 0, ids); } void append_record(RecordType record_type, char *record) { int last_id = get_last_id(record_type); FILE *file = open_file(record_type, "a"); fputs(record, file); fclose(file); set_last_id(record_type, last_id + 1); } size_t get_record_size(RecordType type) { switch (type) { case USER_RECORD: return sizeof(User); case PATIENT_INFO_RECORD: return sizeof(PatientInfo); case DRUG_PRESCRIPTION_RECORD: case LAB_TEST_PRESCRIPTION_RECORD: return sizeof(Prescription); case SICKNESS_INFO_RECORD: return sizeof(SicknessInfo); default: printf("Error incorrect record type\n"); exit(2); } } void *find_all_records(RecordType record_type, int search_attribute, char *value) { static long start = 0; FILE *file = open_file(record_type, "r"); fseek(file, start, SEEK_SET); char *buffer = NULL; size_t len = 0; bool found = false; void *current = allocate_space_for_record(record_type); int token_start, attribute; char *token = (char *)malloc(MAX_ATTRIBUTE_SIZE + 1); while (getline(&buffer, &len, file) != -1) { token_start = 0; attribute = 0; start += strlen(buffer); while (next_token(buffer, token, &token_start) != -1) { if (attribute == 0) { if (atoi(token) != record_type) break; } if (attribute == search_attribute && strcmp(value, token) == 0) { found = true; } set_attribute_for_record(current, record_type, attribute, token); attribute++; } if (found) { break; } } if (buffer != NULL) free(buffer); if (token != NULL) free(token); fclose(file); if (found) return current; else return NULL; } char *generate_hash(char *string) { unsigned char digest[16]; MD5_CTX context; MD5_Init(&context); MD5_Update(&context, string, strlen(string)); MD5_Final(digest, &context); char md5string[33]; for (int i = 0; i < 16; ++i) sprintf(&md5string[i * 2], "%02x", (unsigned int)digest[i]); char *copy = malloc(33 * sizeof(char)); strcpy(copy, md5string); return copy; } bool prompt_login() { char username[MAX_ATTRIBUTE_SIZE]; char password[MAX_ATTRIBUTE_SIZE]; printf("Username: "); read_line(username); printf("Password: "); read_line(password); User *user = (User *)find_single_record(USER_RECORD, 2, username); if (user != NULL) { if (strcmp(generate_hash(password), user->password) == 0) { printf("\nLogin success!\n\nYour user id is %d\n\n", user->id); current_user = user; return true; } else { printf("\nWrong password\n"); } } else { printf("\nInvalid user\n"); } printf("\n"); return false; } void view_sickness_info_action() { char patient_id[100]; PatientInfo *pi; printf("Enter Patient Id: "); read_line(patient_id); if ((pi = find_single_record(PATIENT_INFO_RECORD, 1, patient_id)) == NULL) { printf("Invalid patient id"); return; } if ( (pi->user_id == current_user->id && has_privilege(current_user->privilege_level, "READ_SELF_SICKNESS_RECORD")) || has_privilege(current_user->privilege_level, "READ_ANY_SICKNESS_RECORD")) { char n; printf("Press q to quit; Press n to print next record\n"); do { read_character(&n); if (n == 'n') { SicknessInfo *p; p = find_all_records(SICKNESS_INFO_RECORD, 2, patient_id); if (p == NULL) { printf("No more records\n"); return; } else { printf("patient id: %d\ndoctor id: %d\ndate time: %s\nprescription: %s\n", p->patient_id, p->doctor_id, p->datetime, p->description); } } } while (n != 'q'); } else { printf("You do not have permission for this action\n"); } } void view_lab_test_prescription_action() { char patient_id[100]; PatientInfo *pi; printf("Enter Patient Id: "); read_line(patient_id); if ((pi = find_single_record(PATIENT_INFO_RECORD, 1, patient_id)) == NULL) { printf("Invalid patient id"); return; } if ( (pi->user_id == current_user->id && has_privilege(current_user->privilege_level, "READ_SELF_LAB_PRESCRIPTION_RECORD")) || has_privilege(current_user->privilege_level, "READ_ANY_LAB_PRESCRIPTION_INFO_RECORD")) { char n; printf("Press q to quit; Press n to print next record\n"); do { read_character(&n); if (n == 'n') { Prescription *p; p = find_all_records(LAB_TEST_PRESCRIPTION_RECORD, 2, patient_id); if (p == NULL) { printf("No more records\n"); return; } else { printf("patient id: %d\ndoctor id: %d\ndate time: %s\nprescription: %s\n", p->patient_id, p->doctor_id, p->datetime, p->prescription); } } } while (n != 'q'); } else { printf("You do not have permission for this action\n"); } } void view_drug_prescription_action() { char patient_id[100]; PatientInfo *pi; printf("Enter Patient Id: "); read_line(patient_id); if ( (pi = find_single_record(PATIENT_INFO_RECORD, 1, patient_id)) == NULL) { printf("Invalid patient id"); return; } if ( (pi->user_id == current_user->id && has_privilege(current_user->privilege_level, "READ_SELF_DRUG_PRESCRIPTION_RECORD")) || has_privilege(current_user->privilege_level, "READ_ANY_DRUG_PRESCRIPTION_RECORD")) { char n; printf("Press q to quit; Press n to print next record\n"); do { read_character(&n); if (n == 'n') { Prescription *p; p = find_all_records(DRUG_PRESCRIPTION_RECORD, 2, patient_id); if (p == NULL) { printf("No more records\n"); return; } else { printf("patient id: %d\ndoctor id: %d\ndate time: %s\nprescription: %s\n", p->patient_id, p->doctor_id, p->datetime, p->prescription); } } } while (n != 'q'); } else { printf("You do not have permission for this action\n"); } } void view_patient_info_action() { char patient_id[100]; PatientInfo *pi; printf("Enter Patient Id: "); read_line(patient_id); if ( (pi = find_single_record(PATIENT_INFO_RECORD, 1, patient_id)) == NULL) { printf("Invalid patient id"); return; } if ( (pi->user_id == current_user->id && has_privilege(current_user->privilege_level, "READ_SELF_PATIENT_RECORD")) || has_privilege(current_user->privilege_level, "READ_ANY_PATIENT_RECORD")) { printf("id: %d\nname: %s\nphone: %s\ngender: %c\nbirthyear: %d\n", pi->id, pi->name, pi->phone, pi->gender, pi->birth_year); } else { printf("You do not have permission for this action\n"); } } void add_lab_test_prescription_action() { if (has_privilege(current_user->privilege_level, "CREATE_LAB_TEST_PRESCRIPTION_RECORD")) { char patient_id[100]; int doctor_id = current_user->id; char datetime[100]; char description[DESCRIPTION_LENGTH]; time_t rawtime; struct tm *timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); strcpy(datetime, asctime(timeinfo)); datetime[strlen(datetime) - 1] = '\0'; printf("Patient Id: "); read_line(patient_id); if (find_single_record(PATIENT_INFO_RECORD, 1, patient_id) == NULL) { printf("Invalid patient id"); return; } fgets(description, DESCRIPTION_LENGTH, stdin); printf("Prescription : "); fgets(description, DESCRIPTION_LENGTH, stdin); Prescription si; si.id = get_last_id(LAB_TEST_PRESCRIPTION_RECORD); si.doctor_id = doctor_id; si.patient_id = atoi(patient_id); strcpy(si.datetime, datetime); description[strlen(description) - 1] = '\0'; strcpy(si.prescription, description); char record[MAX_RECORD_LENGTH]; prescription_to_string(&si, record, LAB_TEST_PRESCRIPTION_RECORD); append_record(LAB_TEST_PRESCRIPTION_RECORD, record); printf("Record added successfully!\n"); } else { printf("You do not have permission for this action\n"); } } void add_drug_prescription_action() { if (has_privilege(current_user->privilege_level, "CREATE_DRUG_PRESCRIPTION_RECORD")) { char patient_id[100]; int doctor_id = current_user->id; char datetime[100]; char description[DESCRIPTION_LENGTH]; time_t rawtime; struct tm *timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); strcpy(datetime, asctime(timeinfo)); datetime[strlen(datetime) - 1] = '\0'; printf("Patient Id: "); read_line(patient_id); if (find_single_record(PATIENT_INFO_RECORD, 1, patient_id) == NULL) { printf("Invalid patient id"); return; } fgets(description, DESCRIPTION_LENGTH, stdin); printf("Prescription : "); fgets(description, DESCRIPTION_LENGTH, stdin); Prescription si; si.id = get_last_id(DRUG_PRESCRIPTION_RECORD); si.doctor_id = doctor_id; si.patient_id = atoi(patient_id); strcpy(si.datetime, datetime); description[strlen(description) - 1] = '\0'; strcpy(si.prescription, description); char record[MAX_RECORD_LENGTH]; prescription_to_string(&si, record, DRUG_PRESCRIPTION_RECORD); append_record(DRUG_PRESCRIPTION_RECORD, record); printf("Record added successfully!\n"); } else { printf("You do not have permission for this action\n"); } } void add_sickness_info_action() { if (has_privilege(current_user->privilege_level, "CREATE_SICKNESS_INFO_RECORD")) { char patient_id[100]; int doctor_id = current_user->id; char datetime[100]; char description[DESCRIPTION_LENGTH]; time_t rawtime; struct tm *timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); strcpy(datetime, asctime(timeinfo)); datetime[strlen(datetime) - 1] = '\0'; printf("Patient Id: "); read_line(patient_id); if (find_single_record(PATIENT_INFO_RECORD, 1, patient_id) == NULL) { printf("Invalid patient id"); return; } printf("Description : "); read_line(description); SicknessInfo si; si.id = get_last_id(SICKNESS_INFO_RECORD); si.doctor_id = doctor_id; si.patient_id = atoi(patient_id); strcpy(si.datetime, datetime); description[strlen(description) - 1] = '\0'; strcpy(si.description, description); char record[MAX_RECORD_LENGTH]; sickness_info_to_string(&si, record); append_record(SICKNESS_INFO_RECORD, record); printf("Record added successfully!\n"); } else { printf("You do not have permission for this action\n"); } } void add_patient_action() { if (has_privilege(current_user->privilege_level, "CREATE_PATIENT_RECORD")) { char user_id[100]; char name[MAX_ATTRIBUTE_SIZE]; char buffer[MAX_ATTRIBUTE_SIZE]; char phone[20]; char gender; int birth_year; printf("Patient User Account Id: "); read_line(user_id); if (find_single_record(USER_RECORD, 1, user_id) == NULL) { printf("Non-existant user id\n"); return; } printf("Patient Name: "); read_line(name); printf("Patient Phone: "); read_line(phone); printf("Gender (M or F): "); if (!(read_character(&gender)) || (gender != 'M' && gender != 'F')) { printf("Invalid gender\n"); return; } printf("Patient Birth Year: "); read_line(buffer); birth_year = atoi(buffer); // ("%d", &birth_year) == 0) // { // printf("Invalid year\n"); // return; // } PatientInfo pi; pi.user_id = atoi(user_id); pi.id = get_last_id(PATIENT_INFO_RECORD) + 1; strcpy(pi.name, name); strcpy(pi.phone, phone); pi.gender = gender; pi.birth_year = birth_year; char record[MAX_RECORD_LENGTH]; patient_info_to_string(&pi, record); append_record(PATIENT_INFO_RECORD, record); printf("Patient record created successfully!\n"); } else { printf("You do not have permission for this action\n"); } } void add_user_action() { if (has_privilege(current_user->privilege_level, "CREATE_USER_RECORD")) { char username[MAX_ATTRIBUTE_SIZE]; char password[MAX_ATTRIBUTE_SIZE]; int user_type; int privilege_level; printf("New Username: "); read_line(username); if (find_single_record(USER_RECORD, 2, username) != NULL) { printf("\nUsername taken\n"); return; } printf("Password: "); read_line(password); printf("User Type (0 - Patient, 1 - Hostpial Staff, 2- Doctor)\n: "); if (!read_digit(&user_type) || user_type < 0 || user_type > 2) { printf("\nInvalid user type\n"); return; } printf("privilege level (1 - Level1, 2 - Level2, 3 - Level3, 4 - Level4)\n: "); if (!read_digit(&privilege_level) || privilege_level < 1 || privilege_level > 4) { printf("\nInvalid privilege level\n"); return; } privilege_level--; char record[MAX_RECORD_LENGTH]; User user; strcpy(user.username, username); strcpy(user.password, generate_hash(password)); user.privilege_level = privilege_level; user.user_type = user_type; user.id = get_last_id(USER_RECORD) + 1; user_record_to_string(&user, record); append_record(USER_RECORD, record); printf("Record added successfully!\n"); } else { printf("You do not have permission for this action\n"); } } void print_menu() { printf("\na - Add User (Admin Only)\n"); printf("b - Add Patient (Staff Only)\n"); printf("c - Add Sickness Info Record (Doctors Only)\n"); printf("d - Add Drug Prescription Record (Doctors Only)\n"); printf("e - Add Lab Test Prescription Record (Doctors Only)\n"); printf("f - View Patient Info (Patients, Clerks and Doctors Only)\n"); printf("g - View Patient Drug Prescription Records (Patients (Self),Staff and Doctors Only)\n"); printf("h - View Patient Lab Test Prescription Records (Patients(Self), Staff and Doctors Only)\n"); printf("i - View Sickness Info Record (Patients(Self) and Doctors Only)\n"); printf("m - Print this menu\n\n"); } void do_action(char c) { switch (c) { case 'a': printf("\nAdd User Command Selected\n\n"); add_user_action(); break; case 'b': printf("\nAdd Patient Command Selected\n\n"); add_patient_action(); break; case 'c': printf("\nAdd Sickness Info Command Selected\n\n"); add_sickness_info_action(); break; case 'd': printf("\nAdd Drug Prescription Command Selected\n\n"); add_drug_prescription_action(); break; case 'e': printf("\nAdd Lab Test Command Selected\n\n"); add_lab_test_prescription_action(); break; case 'f': printf("\nView Patient Info Command Selected\n\n"); view_patient_info_action(); break; case 'g': printf("\nView Drug Prescriptions Command Selected\n\n"); view_drug_prescription_action(); break; case 'h': printf("\nView Lab Test Prescriptons Command Selected\n\n"); view_lab_test_prescription_action(); break; case 'i': printf("\nView Sickness Info Command Selected\n\n"); view_sickness_info_action(); break; case 'm': print_menu(); break; default: printf("\nInvalid command!\n\n"); break; } } int main() { printf("Press Ctrl + C to exit\n\n"); while (!prompt_login()) ; char c; print_menu(); do { printf("Enter command: "); if (!read_character(&c)) { printf("Multiple characters were not expected"); continue; } do_action(c); } while (c != 'q'); }
the_stack_data/29825815.c
int main(){ int j = 10; int i = 2; i = (i + j) << 9; i = (i + j) >> 3; return i; }
the_stack_data/89201080.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <string.h> #ifndef PASSWORD #define PASSWORD "CSCG{FLAG_FROM_STAGE_1}" #endif // pwn2: gcc pwn2.c -o pwn2 // --------------------------------------------------- SETUP void ignore_me_init_buffering() { setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); } void kill_on_timeout(int sig) { if (sig == SIGALRM) { printf("[!] Anti DoS Signal. Patch me out for testing."); _exit(0); } } void ignore_me_init_signal() { signal(SIGALRM, kill_on_timeout); alarm(60); } // just a safe alternative to gets() size_t read_input(int fd, char *buf, size_t size) { size_t i; for (i = 0; i < size-1; ++i) { char c; if (read(fd, &c, 1) <= 0) { _exit(0); } if (c == '\n') { break; } buf[i] = c; } buf[i] = '\0'; return i; } // --------------------------------------------------- MENU void WINgardium_leviosa() { printf("┌───────────────────────┐\n"); printf("│ You are a Slytherin.. │\n"); printf("└───────────────────────┘\n"); system("/bin/sh"); } void check_password_stage1() { char read_buf[0xff]; printf("Enter the password of stage 1:\n"); memset(read_buf, 0, sizeof(read_buf)); read_input(0, read_buf, sizeof(read_buf)); if(strcmp(read_buf, PASSWORD) != 0) { printf("-10 Points for Ravenclaw!\n"); _exit(0); } else { printf("+10 Points for Ravenclaw!\n"); } } void welcome() { char read_buf[0xff]; printf("Enter your witch name:\n"); gets(read_buf); printf("┌───────────────────────┐\n"); printf("│ You are a Ravenclaw! │\n"); printf("└───────────────────────┘\n"); printf(read_buf); } void AAAAAAAA() { char read_buf[0xff]; printf(" enter your magic spell:\n"); gets(read_buf); if(strcmp(read_buf, "Expelliarmus") == 0) { printf("~ Protego!\n"); } else { printf("-10 Points for Ravenclaw!\n"); _exit(0); } } // --------------------------------------------------- MAIN void main(int argc, char* argv[]) { ignore_me_init_buffering(); ignore_me_init_signal(); check_password_stage1(); welcome(); AAAAAAAA(); }
the_stack_data/453223.c
#include <stdio.h> int main() { int c, nl; nl = 0; while ((c = getchar()) != EOF) if (c == '\n') ++nl; printf("%d\n", nl); }
the_stack_data/70450968.c
//@ ltl invariant negative: ( ( ([] (<> (! AP((10.0 <= tot_transm_time))))) || (! ([] (<> ( (! AP((mgr_l != 0))) && (X AP((mgr_l != 0)))))))) || (! ([] (<> AP((1.0 <= _diverge_delta)))))); extern float __VERIFIER_nondet_float(void); extern int __VERIFIER_nondet_int(void); char __VERIFIER_nondet_bool(void) { return __VERIFIER_nondet_int() != 0; } float _diverge_delta, _x__diverge_delta; char st15_evt1, _x_st15_evt1; char st15_evt0, _x_st15_evt0; float st15_req_time, _x_st15_req_time; char st15_l, _x_st15_l; char st14_evt1, _x_st14_evt1; char st14_evt0, _x_st14_evt0; float st14_req_time, _x_st14_req_time; char st14_l, _x_st14_l; float st5_req_time, _x_st5_req_time; char st13_l, _x_st13_l; char mgr_l, _x_mgr_l; char st3_evt1, _x_st3_evt1; char st5_l, _x_st5_l; char st4_evt1, _x_st4_evt1; float st6_req_time, _x_st6_req_time; float st4_req_time, _x_st4_req_time; char st2_evt1, _x_st2_evt1; char st4_l, _x_st4_l; char st2_evt0, _x_st2_evt0; char st13_evt1, _x_st13_evt1; char mgr_evt1, _x_mgr_evt1; float st2_req_time, _x_st2_req_time; float mgr_timeout, _x_mgr_timeout; char st2_l, _x_st2_l; char st13_evt0, _x_st13_evt0; char mgr_evt0, _x_mgr_evt0; char st1_evt1, _x_st1_evt1; float st3_req_time, _x_st3_req_time; char st0_l, _x_st0_l; char st1_evt0, _x_st1_evt0; float delta, _x_delta; char st3_l, _x_st3_l; char st1_l, _x_st1_l; float tot_transm_time, _x_tot_transm_time; char st3_evt0, _x_st3_evt0; float st0_req_time, _x_st0_req_time; float st13_req_time, _x_st13_req_time; float mgr_c, _x_mgr_c; char st0_evt1, _x_st0_evt1; char st0_evt0, _x_st0_evt0; char st4_evt0, _x_st4_evt0; float st1_req_time, _x_st1_req_time; char st5_evt0, _x_st5_evt0; char st5_evt1, _x_st5_evt1; float st7_req_time, _x_st7_req_time; char st6_l, _x_st6_l; char st6_evt0, _x_st6_evt0; char st6_evt1, _x_st6_evt1; float st8_req_time, _x_st8_req_time; char st7_l, _x_st7_l; char st7_evt0, _x_st7_evt0; char st7_evt1, _x_st7_evt1; float st9_req_time, _x_st9_req_time; char st8_l, _x_st8_l; char st8_evt0, _x_st8_evt0; char st8_evt1, _x_st8_evt1; float st10_req_time, _x_st10_req_time; char st9_l, _x_st9_l; char st9_evt0, _x_st9_evt0; char st9_evt1, _x_st9_evt1; float st11_req_time, _x_st11_req_time; char st10_l, _x_st10_l; char st10_evt0, _x_st10_evt0; char st10_evt1, _x_st10_evt1; float st12_req_time, _x_st12_req_time; char st11_l, _x_st11_l; char st11_evt0, _x_st11_evt0; char st11_evt1, _x_st11_evt1; char st12_l, _x_st12_l; char st12_evt0, _x_st12_evt0; char st12_evt1, _x_st12_evt1; int main() { _diverge_delta = __VERIFIER_nondet_float(); st15_evt1 = __VERIFIER_nondet_bool(); st15_evt0 = __VERIFIER_nondet_bool(); st15_req_time = __VERIFIER_nondet_float(); st15_l = __VERIFIER_nondet_bool(); st14_evt1 = __VERIFIER_nondet_bool(); st14_evt0 = __VERIFIER_nondet_bool(); st14_req_time = __VERIFIER_nondet_float(); st14_l = __VERIFIER_nondet_bool(); st5_req_time = __VERIFIER_nondet_float(); st13_l = __VERIFIER_nondet_bool(); mgr_l = __VERIFIER_nondet_bool(); st3_evt1 = __VERIFIER_nondet_bool(); st5_l = __VERIFIER_nondet_bool(); st4_evt1 = __VERIFIER_nondet_bool(); st6_req_time = __VERIFIER_nondet_float(); st4_req_time = __VERIFIER_nondet_float(); st2_evt1 = __VERIFIER_nondet_bool(); st4_l = __VERIFIER_nondet_bool(); st2_evt0 = __VERIFIER_nondet_bool(); st13_evt1 = __VERIFIER_nondet_bool(); mgr_evt1 = __VERIFIER_nondet_bool(); st2_req_time = __VERIFIER_nondet_float(); mgr_timeout = __VERIFIER_nondet_float(); st2_l = __VERIFIER_nondet_bool(); st13_evt0 = __VERIFIER_nondet_bool(); mgr_evt0 = __VERIFIER_nondet_bool(); st1_evt1 = __VERIFIER_nondet_bool(); st3_req_time = __VERIFIER_nondet_float(); st0_l = __VERIFIER_nondet_bool(); st1_evt0 = __VERIFIER_nondet_bool(); delta = __VERIFIER_nondet_float(); st3_l = __VERIFIER_nondet_bool(); st1_l = __VERIFIER_nondet_bool(); tot_transm_time = __VERIFIER_nondet_float(); st3_evt0 = __VERIFIER_nondet_bool(); st0_req_time = __VERIFIER_nondet_float(); st13_req_time = __VERIFIER_nondet_float(); mgr_c = __VERIFIER_nondet_float(); st0_evt1 = __VERIFIER_nondet_bool(); st0_evt0 = __VERIFIER_nondet_bool(); st4_evt0 = __VERIFIER_nondet_bool(); st1_req_time = __VERIFIER_nondet_float(); st5_evt0 = __VERIFIER_nondet_bool(); st5_evt1 = __VERIFIER_nondet_bool(); st7_req_time = __VERIFIER_nondet_float(); st6_l = __VERIFIER_nondet_bool(); st6_evt0 = __VERIFIER_nondet_bool(); st6_evt1 = __VERIFIER_nondet_bool(); st8_req_time = __VERIFIER_nondet_float(); st7_l = __VERIFIER_nondet_bool(); st7_evt0 = __VERIFIER_nondet_bool(); st7_evt1 = __VERIFIER_nondet_bool(); st9_req_time = __VERIFIER_nondet_float(); st8_l = __VERIFIER_nondet_bool(); st8_evt0 = __VERIFIER_nondet_bool(); st8_evt1 = __VERIFIER_nondet_bool(); st10_req_time = __VERIFIER_nondet_float(); st9_l = __VERIFIER_nondet_bool(); st9_evt0 = __VERIFIER_nondet_bool(); st9_evt1 = __VERIFIER_nondet_bool(); st11_req_time = __VERIFIER_nondet_float(); st10_l = __VERIFIER_nondet_bool(); st10_evt0 = __VERIFIER_nondet_bool(); st10_evt1 = __VERIFIER_nondet_bool(); st12_req_time = __VERIFIER_nondet_float(); st11_l = __VERIFIER_nondet_bool(); st11_evt0 = __VERIFIER_nondet_bool(); st11_evt1 = __VERIFIER_nondet_bool(); st12_l = __VERIFIER_nondet_bool(); st12_evt0 = __VERIFIER_nondet_bool(); st12_evt1 = __VERIFIER_nondet_bool(); int __ok = (((((st15_l != 0) && (((st15_evt1 != 0) && ( !(st15_evt0 != 0))) || ((( !(st15_evt0 != 0)) && ( !(st15_evt1 != 0))) || ((st15_evt0 != 0) && ( !(st15_evt1 != 0)))))) && ( !(st15_req_time <= 0.0))) && ((((st14_l != 0) && (((st14_evt1 != 0) && ( !(st14_evt0 != 0))) || ((( !(st14_evt0 != 0)) && ( !(st14_evt1 != 0))) || ((st14_evt0 != 0) && ( !(st14_evt1 != 0)))))) && ( !(st14_req_time <= 0.0))) && ((((st13_l != 0) && (((st13_evt1 != 0) && ( !(st13_evt0 != 0))) || ((( !(st13_evt0 != 0)) && ( !(st13_evt1 != 0))) || ((st13_evt0 != 0) && ( !(st13_evt1 != 0)))))) && ( !(st13_req_time <= 0.0))) && ((((st12_l != 0) && (((st12_evt1 != 0) && ( !(st12_evt0 != 0))) || ((( !(st12_evt0 != 0)) && ( !(st12_evt1 != 0))) || ((st12_evt0 != 0) && ( !(st12_evt1 != 0)))))) && ( !(st12_req_time <= 0.0))) && ((((st11_l != 0) && (((st11_evt1 != 0) && ( !(st11_evt0 != 0))) || ((( !(st11_evt0 != 0)) && ( !(st11_evt1 != 0))) || ((st11_evt0 != 0) && ( !(st11_evt1 != 0)))))) && ( !(st11_req_time <= 0.0))) && ((((st10_l != 0) && (((st10_evt1 != 0) && ( !(st10_evt0 != 0))) || ((( !(st10_evt0 != 0)) && ( !(st10_evt1 != 0))) || ((st10_evt0 != 0) && ( !(st10_evt1 != 0)))))) && ( !(st10_req_time <= 0.0))) && ((((st9_l != 0) && (((st9_evt1 != 0) && ( !(st9_evt0 != 0))) || ((( !(st9_evt0 != 0)) && ( !(st9_evt1 != 0))) || ((st9_evt0 != 0) && ( !(st9_evt1 != 0)))))) && ( !(st9_req_time <= 0.0))) && ((((st8_l != 0) && (((st8_evt1 != 0) && ( !(st8_evt0 != 0))) || ((( !(st8_evt0 != 0)) && ( !(st8_evt1 != 0))) || ((st8_evt0 != 0) && ( !(st8_evt1 != 0)))))) && ( !(st8_req_time <= 0.0))) && ((((st7_l != 0) && (((st7_evt1 != 0) && ( !(st7_evt0 != 0))) || ((( !(st7_evt0 != 0)) && ( !(st7_evt1 != 0))) || ((st7_evt0 != 0) && ( !(st7_evt1 != 0)))))) && ( !(st7_req_time <= 0.0))) && ((((st6_l != 0) && (((st6_evt1 != 0) && ( !(st6_evt0 != 0))) || ((( !(st6_evt0 != 0)) && ( !(st6_evt1 != 0))) || ((st6_evt0 != 0) && ( !(st6_evt1 != 0)))))) && ( !(st6_req_time <= 0.0))) && ((((st5_l != 0) && (((st5_evt1 != 0) && ( !(st5_evt0 != 0))) || ((( !(st5_evt0 != 0)) && ( !(st5_evt1 != 0))) || ((st5_evt0 != 0) && ( !(st5_evt1 != 0)))))) && ( !(st5_req_time <= 0.0))) && ((((st4_l != 0) && (((st4_evt1 != 0) && ( !(st4_evt0 != 0))) || ((( !(st4_evt0 != 0)) && ( !(st4_evt1 != 0))) || ((st4_evt0 != 0) && ( !(st4_evt1 != 0)))))) && ( !(st4_req_time <= 0.0))) && ((((st3_l != 0) && (((st3_evt1 != 0) && ( !(st3_evt0 != 0))) || ((( !(st3_evt0 != 0)) && ( !(st3_evt1 != 0))) || ((st3_evt0 != 0) && ( !(st3_evt1 != 0)))))) && ( !(st3_req_time <= 0.0))) && ((((st2_l != 0) && (((st2_evt1 != 0) && ( !(st2_evt0 != 0))) || ((( !(st2_evt0 != 0)) && ( !(st2_evt1 != 0))) || ((st2_evt0 != 0) && ( !(st2_evt1 != 0)))))) && ( !(st2_req_time <= 0.0))) && ((((st1_l != 0) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((( !(st1_evt0 != 0)) && ( !(st1_evt1 != 0))) || ((st1_evt0 != 0) && ( !(st1_evt1 != 0)))))) && ( !(st1_req_time <= 0.0))) && ((((st0_l != 0) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((( !(st0_evt0 != 0)) && ( !(st0_evt1 != 0))) || ((st0_evt0 != 0) && ( !(st0_evt1 != 0)))))) && ( !(st0_req_time <= 0.0))) && (((((mgr_l != 0) && (((mgr_evt1 != 0) && ( !(mgr_evt0 != 0))) || ((( !(mgr_evt0 != 0)) && ( !(mgr_evt1 != 0))) || ((mgr_evt0 != 0) && ( !(mgr_evt1 != 0)))))) && ((mgr_c == 0.0) && (mgr_timeout == 0.0))) && ((mgr_l != 0) || (mgr_c <= mgr_timeout))) && ((tot_transm_time == 0.0) && (0.0 <= delta))))))))))))))))))) && (delta == _diverge_delta)); while (__ok) { _x__diverge_delta = __VERIFIER_nondet_float(); _x_st15_evt1 = __VERIFIER_nondet_bool(); _x_st15_evt0 = __VERIFIER_nondet_bool(); _x_st15_req_time = __VERIFIER_nondet_float(); _x_st15_l = __VERIFIER_nondet_bool(); _x_st14_evt1 = __VERIFIER_nondet_bool(); _x_st14_evt0 = __VERIFIER_nondet_bool(); _x_st14_req_time = __VERIFIER_nondet_float(); _x_st14_l = __VERIFIER_nondet_bool(); _x_st5_req_time = __VERIFIER_nondet_float(); _x_st13_l = __VERIFIER_nondet_bool(); _x_mgr_l = __VERIFIER_nondet_bool(); _x_st3_evt1 = __VERIFIER_nondet_bool(); _x_st5_l = __VERIFIER_nondet_bool(); _x_st4_evt1 = __VERIFIER_nondet_bool(); _x_st6_req_time = __VERIFIER_nondet_float(); _x_st4_req_time = __VERIFIER_nondet_float(); _x_st2_evt1 = __VERIFIER_nondet_bool(); _x_st4_l = __VERIFIER_nondet_bool(); _x_st2_evt0 = __VERIFIER_nondet_bool(); _x_st13_evt1 = __VERIFIER_nondet_bool(); _x_mgr_evt1 = __VERIFIER_nondet_bool(); _x_st2_req_time = __VERIFIER_nondet_float(); _x_mgr_timeout = __VERIFIER_nondet_float(); _x_st2_l = __VERIFIER_nondet_bool(); _x_st13_evt0 = __VERIFIER_nondet_bool(); _x_mgr_evt0 = __VERIFIER_nondet_bool(); _x_st1_evt1 = __VERIFIER_nondet_bool(); _x_st3_req_time = __VERIFIER_nondet_float(); _x_st0_l = __VERIFIER_nondet_bool(); _x_st1_evt0 = __VERIFIER_nondet_bool(); _x_delta = __VERIFIER_nondet_float(); _x_st3_l = __VERIFIER_nondet_bool(); _x_st1_l = __VERIFIER_nondet_bool(); _x_tot_transm_time = __VERIFIER_nondet_float(); _x_st3_evt0 = __VERIFIER_nondet_bool(); _x_st0_req_time = __VERIFIER_nondet_float(); _x_st13_req_time = __VERIFIER_nondet_float(); _x_mgr_c = __VERIFIER_nondet_float(); _x_st0_evt1 = __VERIFIER_nondet_bool(); _x_st0_evt0 = __VERIFIER_nondet_bool(); _x_st4_evt0 = __VERIFIER_nondet_bool(); _x_st1_req_time = __VERIFIER_nondet_float(); _x_st5_evt0 = __VERIFIER_nondet_bool(); _x_st5_evt1 = __VERIFIER_nondet_bool(); _x_st7_req_time = __VERIFIER_nondet_float(); _x_st6_l = __VERIFIER_nondet_bool(); _x_st6_evt0 = __VERIFIER_nondet_bool(); _x_st6_evt1 = __VERIFIER_nondet_bool(); _x_st8_req_time = __VERIFIER_nondet_float(); _x_st7_l = __VERIFIER_nondet_bool(); _x_st7_evt0 = __VERIFIER_nondet_bool(); _x_st7_evt1 = __VERIFIER_nondet_bool(); _x_st9_req_time = __VERIFIER_nondet_float(); _x_st8_l = __VERIFIER_nondet_bool(); _x_st8_evt0 = __VERIFIER_nondet_bool(); _x_st8_evt1 = __VERIFIER_nondet_bool(); _x_st10_req_time = __VERIFIER_nondet_float(); _x_st9_l = __VERIFIER_nondet_bool(); _x_st9_evt0 = __VERIFIER_nondet_bool(); _x_st9_evt1 = __VERIFIER_nondet_bool(); _x_st11_req_time = __VERIFIER_nondet_float(); _x_st10_l = __VERIFIER_nondet_bool(); _x_st10_evt0 = __VERIFIER_nondet_bool(); _x_st10_evt1 = __VERIFIER_nondet_bool(); _x_st12_req_time = __VERIFIER_nondet_float(); _x_st11_l = __VERIFIER_nondet_bool(); _x_st11_evt0 = __VERIFIER_nondet_bool(); _x_st11_evt1 = __VERIFIER_nondet_bool(); _x_st12_l = __VERIFIER_nondet_bool(); _x_st12_evt0 = __VERIFIER_nondet_bool(); _x_st12_evt1 = __VERIFIER_nondet_bool(); __ok = (((((((((_x_st15_evt1 != 0) && ( !(_x_st15_evt0 != 0))) || ((( !(_x_st15_evt0 != 0)) && ( !(_x_st15_evt1 != 0))) || ((_x_st15_evt0 != 0) && ( !(_x_st15_evt1 != 0))))) && ( !(_x_st15_req_time <= 0.0))) && ((((st15_l != 0) == (_x_st15_l != 0)) && (st15_req_time == _x_st15_req_time)) || ( !(( !(delta <= 0.0)) || ((st15_evt1 != 0) && ( !(st15_evt0 != 0))))))) && ((((( !(st15_evt0 != 0)) && ( !(st15_evt1 != 0))) && ( !(_x_st15_l != 0))) && ((st15_req_time == _x_st15_req_time) && (_x_mgr_timeout == st15_req_time))) || ( !((st15_l != 0) && ((delta == 0.0) && ((( !(st15_evt0 != 0)) && ( !(st15_evt1 != 0))) || ((st15_evt0 != 0) && ( !(st15_evt1 != 0))))))))) && ((((st15_evt0 != 0) && ( !(st15_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st15_l != 0))) || ( !(( !(st15_l != 0)) && ((delta == 0.0) && ((( !(st15_evt0 != 0)) && ( !(st15_evt1 != 0))) || ((st15_evt0 != 0) && ( !(st15_evt1 != 0))))))))) && ((((((((_x_st14_evt1 != 0) && ( !(_x_st14_evt0 != 0))) || ((( !(_x_st14_evt0 != 0)) && ( !(_x_st14_evt1 != 0))) || ((_x_st14_evt0 != 0) && ( !(_x_st14_evt1 != 0))))) && ( !(_x_st14_req_time <= 0.0))) && ((((st14_l != 0) == (_x_st14_l != 0)) && (st14_req_time == _x_st14_req_time)) || ( !(( !(delta <= 0.0)) || ((st14_evt1 != 0) && ( !(st14_evt0 != 0))))))) && ((((( !(st14_evt0 != 0)) && ( !(st14_evt1 != 0))) && ( !(_x_st14_l != 0))) && ((st14_req_time == _x_st14_req_time) && (_x_mgr_timeout == st14_req_time))) || ( !((st14_l != 0) && ((delta == 0.0) && ((( !(st14_evt0 != 0)) && ( !(st14_evt1 != 0))) || ((st14_evt0 != 0) && ( !(st14_evt1 != 0))))))))) && ((((st14_evt0 != 0) && ( !(st14_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st14_l != 0))) || ( !(( !(st14_l != 0)) && ((delta == 0.0) && ((( !(st14_evt0 != 0)) && ( !(st14_evt1 != 0))) || ((st14_evt0 != 0) && ( !(st14_evt1 != 0))))))))) && ((((((((_x_st13_evt1 != 0) && ( !(_x_st13_evt0 != 0))) || ((( !(_x_st13_evt0 != 0)) && ( !(_x_st13_evt1 != 0))) || ((_x_st13_evt0 != 0) && ( !(_x_st13_evt1 != 0))))) && ( !(_x_st13_req_time <= 0.0))) && ((((st13_l != 0) == (_x_st13_l != 0)) && (st13_req_time == _x_st13_req_time)) || ( !(( !(delta <= 0.0)) || ((st13_evt1 != 0) && ( !(st13_evt0 != 0))))))) && ((((( !(st13_evt0 != 0)) && ( !(st13_evt1 != 0))) && ( !(_x_st13_l != 0))) && ((st13_req_time == _x_st13_req_time) && (_x_mgr_timeout == st13_req_time))) || ( !((st13_l != 0) && ((delta == 0.0) && ((( !(st13_evt0 != 0)) && ( !(st13_evt1 != 0))) || ((st13_evt0 != 0) && ( !(st13_evt1 != 0))))))))) && ((((st13_evt0 != 0) && ( !(st13_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st13_l != 0))) || ( !(( !(st13_l != 0)) && ((delta == 0.0) && ((( !(st13_evt0 != 0)) && ( !(st13_evt1 != 0))) || ((st13_evt0 != 0) && ( !(st13_evt1 != 0))))))))) && ((((((((_x_st12_evt1 != 0) && ( !(_x_st12_evt0 != 0))) || ((( !(_x_st12_evt0 != 0)) && ( !(_x_st12_evt1 != 0))) || ((_x_st12_evt0 != 0) && ( !(_x_st12_evt1 != 0))))) && ( !(_x_st12_req_time <= 0.0))) && ((((st12_l != 0) == (_x_st12_l != 0)) && (st12_req_time == _x_st12_req_time)) || ( !(( !(delta <= 0.0)) || ((st12_evt1 != 0) && ( !(st12_evt0 != 0))))))) && ((((( !(st12_evt0 != 0)) && ( !(st12_evt1 != 0))) && ( !(_x_st12_l != 0))) && ((st12_req_time == _x_st12_req_time) && (_x_mgr_timeout == st12_req_time))) || ( !((st12_l != 0) && ((delta == 0.0) && ((( !(st12_evt0 != 0)) && ( !(st12_evt1 != 0))) || ((st12_evt0 != 0) && ( !(st12_evt1 != 0))))))))) && ((((st12_evt0 != 0) && ( !(st12_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st12_l != 0))) || ( !(( !(st12_l != 0)) && ((delta == 0.0) && ((( !(st12_evt0 != 0)) && ( !(st12_evt1 != 0))) || ((st12_evt0 != 0) && ( !(st12_evt1 != 0))))))))) && ((((((((_x_st11_evt1 != 0) && ( !(_x_st11_evt0 != 0))) || ((( !(_x_st11_evt0 != 0)) && ( !(_x_st11_evt1 != 0))) || ((_x_st11_evt0 != 0) && ( !(_x_st11_evt1 != 0))))) && ( !(_x_st11_req_time <= 0.0))) && ((((st11_l != 0) == (_x_st11_l != 0)) && (st11_req_time == _x_st11_req_time)) || ( !(( !(delta <= 0.0)) || ((st11_evt1 != 0) && ( !(st11_evt0 != 0))))))) && ((((( !(st11_evt0 != 0)) && ( !(st11_evt1 != 0))) && ( !(_x_st11_l != 0))) && ((st11_req_time == _x_st11_req_time) && (_x_mgr_timeout == st11_req_time))) || ( !((st11_l != 0) && ((delta == 0.0) && ((( !(st11_evt0 != 0)) && ( !(st11_evt1 != 0))) || ((st11_evt0 != 0) && ( !(st11_evt1 != 0))))))))) && ((((st11_evt0 != 0) && ( !(st11_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st11_l != 0))) || ( !(( !(st11_l != 0)) && ((delta == 0.0) && ((( !(st11_evt0 != 0)) && ( !(st11_evt1 != 0))) || ((st11_evt0 != 0) && ( !(st11_evt1 != 0))))))))) && ((((((((_x_st10_evt1 != 0) && ( !(_x_st10_evt0 != 0))) || ((( !(_x_st10_evt0 != 0)) && ( !(_x_st10_evt1 != 0))) || ((_x_st10_evt0 != 0) && ( !(_x_st10_evt1 != 0))))) && ( !(_x_st10_req_time <= 0.0))) && ((((st10_l != 0) == (_x_st10_l != 0)) && (st10_req_time == _x_st10_req_time)) || ( !(( !(delta <= 0.0)) || ((st10_evt1 != 0) && ( !(st10_evt0 != 0))))))) && ((((( !(st10_evt0 != 0)) && ( !(st10_evt1 != 0))) && ( !(_x_st10_l != 0))) && ((st10_req_time == _x_st10_req_time) && (_x_mgr_timeout == st10_req_time))) || ( !((st10_l != 0) && ((delta == 0.0) && ((( !(st10_evt0 != 0)) && ( !(st10_evt1 != 0))) || ((st10_evt0 != 0) && ( !(st10_evt1 != 0))))))))) && ((((st10_evt0 != 0) && ( !(st10_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st10_l != 0))) || ( !(( !(st10_l != 0)) && ((delta == 0.0) && ((( !(st10_evt0 != 0)) && ( !(st10_evt1 != 0))) || ((st10_evt0 != 0) && ( !(st10_evt1 != 0))))))))) && ((((((((_x_st9_evt1 != 0) && ( !(_x_st9_evt0 != 0))) || ((( !(_x_st9_evt0 != 0)) && ( !(_x_st9_evt1 != 0))) || ((_x_st9_evt0 != 0) && ( !(_x_st9_evt1 != 0))))) && ( !(_x_st9_req_time <= 0.0))) && ((((st9_l != 0) == (_x_st9_l != 0)) && (st9_req_time == _x_st9_req_time)) || ( !(( !(delta <= 0.0)) || ((st9_evt1 != 0) && ( !(st9_evt0 != 0))))))) && ((((( !(st9_evt0 != 0)) && ( !(st9_evt1 != 0))) && ( !(_x_st9_l != 0))) && ((st9_req_time == _x_st9_req_time) && (_x_mgr_timeout == st9_req_time))) || ( !((st9_l != 0) && ((delta == 0.0) && ((( !(st9_evt0 != 0)) && ( !(st9_evt1 != 0))) || ((st9_evt0 != 0) && ( !(st9_evt1 != 0))))))))) && ((((st9_evt0 != 0) && ( !(st9_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st9_l != 0))) || ( !(( !(st9_l != 0)) && ((delta == 0.0) && ((( !(st9_evt0 != 0)) && ( !(st9_evt1 != 0))) || ((st9_evt0 != 0) && ( !(st9_evt1 != 0))))))))) && ((((((((_x_st8_evt1 != 0) && ( !(_x_st8_evt0 != 0))) || ((( !(_x_st8_evt0 != 0)) && ( !(_x_st8_evt1 != 0))) || ((_x_st8_evt0 != 0) && ( !(_x_st8_evt1 != 0))))) && ( !(_x_st8_req_time <= 0.0))) && ((((st8_l != 0) == (_x_st8_l != 0)) && (st8_req_time == _x_st8_req_time)) || ( !(( !(delta <= 0.0)) || ((st8_evt1 != 0) && ( !(st8_evt0 != 0))))))) && ((((( !(st8_evt0 != 0)) && ( !(st8_evt1 != 0))) && ( !(_x_st8_l != 0))) && ((st8_req_time == _x_st8_req_time) && (_x_mgr_timeout == st8_req_time))) || ( !((st8_l != 0) && ((delta == 0.0) && ((( !(st8_evt0 != 0)) && ( !(st8_evt1 != 0))) || ((st8_evt0 != 0) && ( !(st8_evt1 != 0))))))))) && ((((st8_evt0 != 0) && ( !(st8_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st8_l != 0))) || ( !(( !(st8_l != 0)) && ((delta == 0.0) && ((( !(st8_evt0 != 0)) && ( !(st8_evt1 != 0))) || ((st8_evt0 != 0) && ( !(st8_evt1 != 0))))))))) && ((((((((_x_st7_evt1 != 0) && ( !(_x_st7_evt0 != 0))) || ((( !(_x_st7_evt0 != 0)) && ( !(_x_st7_evt1 != 0))) || ((_x_st7_evt0 != 0) && ( !(_x_st7_evt1 != 0))))) && ( !(_x_st7_req_time <= 0.0))) && ((((st7_l != 0) == (_x_st7_l != 0)) && (st7_req_time == _x_st7_req_time)) || ( !(( !(delta <= 0.0)) || ((st7_evt1 != 0) && ( !(st7_evt0 != 0))))))) && ((((( !(st7_evt0 != 0)) && ( !(st7_evt1 != 0))) && ( !(_x_st7_l != 0))) && ((st7_req_time == _x_st7_req_time) && (_x_mgr_timeout == st7_req_time))) || ( !((st7_l != 0) && ((delta == 0.0) && ((( !(st7_evt0 != 0)) && ( !(st7_evt1 != 0))) || ((st7_evt0 != 0) && ( !(st7_evt1 != 0))))))))) && ((((st7_evt0 != 0) && ( !(st7_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st7_l != 0))) || ( !(( !(st7_l != 0)) && ((delta == 0.0) && ((( !(st7_evt0 != 0)) && ( !(st7_evt1 != 0))) || ((st7_evt0 != 0) && ( !(st7_evt1 != 0))))))))) && ((((((((_x_st6_evt1 != 0) && ( !(_x_st6_evt0 != 0))) || ((( !(_x_st6_evt0 != 0)) && ( !(_x_st6_evt1 != 0))) || ((_x_st6_evt0 != 0) && ( !(_x_st6_evt1 != 0))))) && ( !(_x_st6_req_time <= 0.0))) && ((((st6_l != 0) == (_x_st6_l != 0)) && (st6_req_time == _x_st6_req_time)) || ( !(( !(delta <= 0.0)) || ((st6_evt1 != 0) && ( !(st6_evt0 != 0))))))) && ((((( !(st6_evt0 != 0)) && ( !(st6_evt1 != 0))) && ( !(_x_st6_l != 0))) && ((st6_req_time == _x_st6_req_time) && (_x_mgr_timeout == st6_req_time))) || ( !((st6_l != 0) && ((delta == 0.0) && ((( !(st6_evt0 != 0)) && ( !(st6_evt1 != 0))) || ((st6_evt0 != 0) && ( !(st6_evt1 != 0))))))))) && ((((st6_evt0 != 0) && ( !(st6_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st6_l != 0))) || ( !(( !(st6_l != 0)) && ((delta == 0.0) && ((( !(st6_evt0 != 0)) && ( !(st6_evt1 != 0))) || ((st6_evt0 != 0) && ( !(st6_evt1 != 0))))))))) && ((((((((_x_st5_evt1 != 0) && ( !(_x_st5_evt0 != 0))) || ((( !(_x_st5_evt0 != 0)) && ( !(_x_st5_evt1 != 0))) || ((_x_st5_evt0 != 0) && ( !(_x_st5_evt1 != 0))))) && ( !(_x_st5_req_time <= 0.0))) && ((((st5_l != 0) == (_x_st5_l != 0)) && (st5_req_time == _x_st5_req_time)) || ( !(( !(delta <= 0.0)) || ((st5_evt1 != 0) && ( !(st5_evt0 != 0))))))) && ((((( !(st5_evt0 != 0)) && ( !(st5_evt1 != 0))) && ( !(_x_st5_l != 0))) && ((st5_req_time == _x_st5_req_time) && (_x_mgr_timeout == st5_req_time))) || ( !((st5_l != 0) && ((delta == 0.0) && ((( !(st5_evt0 != 0)) && ( !(st5_evt1 != 0))) || ((st5_evt0 != 0) && ( !(st5_evt1 != 0))))))))) && ((((st5_evt0 != 0) && ( !(st5_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st5_l != 0))) || ( !(( !(st5_l != 0)) && ((delta == 0.0) && ((( !(st5_evt0 != 0)) && ( !(st5_evt1 != 0))) || ((st5_evt0 != 0) && ( !(st5_evt1 != 0))))))))) && ((((((((_x_st4_evt1 != 0) && ( !(_x_st4_evt0 != 0))) || ((( !(_x_st4_evt0 != 0)) && ( !(_x_st4_evt1 != 0))) || ((_x_st4_evt0 != 0) && ( !(_x_st4_evt1 != 0))))) && ( !(_x_st4_req_time <= 0.0))) && ((((st4_l != 0) == (_x_st4_l != 0)) && (st4_req_time == _x_st4_req_time)) || ( !(( !(delta <= 0.0)) || ((st4_evt1 != 0) && ( !(st4_evt0 != 0))))))) && ((((( !(st4_evt0 != 0)) && ( !(st4_evt1 != 0))) && ( !(_x_st4_l != 0))) && ((st4_req_time == _x_st4_req_time) && (_x_mgr_timeout == st4_req_time))) || ( !((st4_l != 0) && ((delta == 0.0) && ((( !(st4_evt0 != 0)) && ( !(st4_evt1 != 0))) || ((st4_evt0 != 0) && ( !(st4_evt1 != 0))))))))) && ((((st4_evt0 != 0) && ( !(st4_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st4_l != 0))) || ( !(( !(st4_l != 0)) && ((delta == 0.0) && ((( !(st4_evt0 != 0)) && ( !(st4_evt1 != 0))) || ((st4_evt0 != 0) && ( !(st4_evt1 != 0))))))))) && ((((((((_x_st3_evt1 != 0) && ( !(_x_st3_evt0 != 0))) || ((( !(_x_st3_evt0 != 0)) && ( !(_x_st3_evt1 != 0))) || ((_x_st3_evt0 != 0) && ( !(_x_st3_evt1 != 0))))) && ( !(_x_st3_req_time <= 0.0))) && ((((st3_l != 0) == (_x_st3_l != 0)) && (st3_req_time == _x_st3_req_time)) || ( !(( !(delta <= 0.0)) || ((st3_evt1 != 0) && ( !(st3_evt0 != 0))))))) && ((((( !(st3_evt0 != 0)) && ( !(st3_evt1 != 0))) && ( !(_x_st3_l != 0))) && ((st3_req_time == _x_st3_req_time) && (_x_mgr_timeout == st3_req_time))) || ( !((st3_l != 0) && ((delta == 0.0) && ((( !(st3_evt0 != 0)) && ( !(st3_evt1 != 0))) || ((st3_evt0 != 0) && ( !(st3_evt1 != 0))))))))) && ((((st3_evt0 != 0) && ( !(st3_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st3_l != 0))) || ( !(( !(st3_l != 0)) && ((delta == 0.0) && ((( !(st3_evt0 != 0)) && ( !(st3_evt1 != 0))) || ((st3_evt0 != 0) && ( !(st3_evt1 != 0))))))))) && ((((((((_x_st2_evt1 != 0) && ( !(_x_st2_evt0 != 0))) || ((( !(_x_st2_evt0 != 0)) && ( !(_x_st2_evt1 != 0))) || ((_x_st2_evt0 != 0) && ( !(_x_st2_evt1 != 0))))) && ( !(_x_st2_req_time <= 0.0))) && ((((st2_l != 0) == (_x_st2_l != 0)) && (st2_req_time == _x_st2_req_time)) || ( !(( !(delta <= 0.0)) || ((st2_evt1 != 0) && ( !(st2_evt0 != 0))))))) && ((((( !(st2_evt0 != 0)) && ( !(st2_evt1 != 0))) && ( !(_x_st2_l != 0))) && ((st2_req_time == _x_st2_req_time) && (_x_mgr_timeout == st2_req_time))) || ( !((st2_l != 0) && ((delta == 0.0) && ((( !(st2_evt0 != 0)) && ( !(st2_evt1 != 0))) || ((st2_evt0 != 0) && ( !(st2_evt1 != 0))))))))) && ((((st2_evt0 != 0) && ( !(st2_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st2_l != 0))) || ( !(( !(st2_l != 0)) && ((delta == 0.0) && ((( !(st2_evt0 != 0)) && ( !(st2_evt1 != 0))) || ((st2_evt0 != 0) && ( !(st2_evt1 != 0))))))))) && ((((((((_x_st1_evt1 != 0) && ( !(_x_st1_evt0 != 0))) || ((( !(_x_st1_evt0 != 0)) && ( !(_x_st1_evt1 != 0))) || ((_x_st1_evt0 != 0) && ( !(_x_st1_evt1 != 0))))) && ( !(_x_st1_req_time <= 0.0))) && ((((st1_l != 0) == (_x_st1_l != 0)) && (st1_req_time == _x_st1_req_time)) || ( !(( !(delta <= 0.0)) || ((st1_evt1 != 0) && ( !(st1_evt0 != 0))))))) && ((((( !(st1_evt0 != 0)) && ( !(st1_evt1 != 0))) && ( !(_x_st1_l != 0))) && ((st1_req_time == _x_st1_req_time) && (_x_mgr_timeout == st1_req_time))) || ( !((st1_l != 0) && ((delta == 0.0) && ((( !(st1_evt0 != 0)) && ( !(st1_evt1 != 0))) || ((st1_evt0 != 0) && ( !(st1_evt1 != 0))))))))) && ((((st1_evt0 != 0) && ( !(st1_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st1_l != 0))) || ( !(( !(st1_l != 0)) && ((delta == 0.0) && ((( !(st1_evt0 != 0)) && ( !(st1_evt1 != 0))) || ((st1_evt0 != 0) && ( !(st1_evt1 != 0))))))))) && ((((((((_x_st0_evt1 != 0) && ( !(_x_st0_evt0 != 0))) || ((( !(_x_st0_evt0 != 0)) && ( !(_x_st0_evt1 != 0))) || ((_x_st0_evt0 != 0) && ( !(_x_st0_evt1 != 0))))) && ( !(_x_st0_req_time <= 0.0))) && ((((st0_l != 0) == (_x_st0_l != 0)) && (st0_req_time == _x_st0_req_time)) || ( !(( !(delta <= 0.0)) || ((st0_evt1 != 0) && ( !(st0_evt0 != 0))))))) && ((((( !(st0_evt0 != 0)) && ( !(st0_evt1 != 0))) && ( !(_x_st0_l != 0))) && ((st0_req_time == _x_st0_req_time) && (_x_mgr_timeout == st0_req_time))) || ( !((st0_l != 0) && ((delta == 0.0) && ((( !(st0_evt0 != 0)) && ( !(st0_evt1 != 0))) || ((st0_evt0 != 0) && ( !(st0_evt1 != 0))))))))) && ((((st0_evt0 != 0) && ( !(st0_evt1 != 0))) && ((_x_st0_l != 0) && ( !(mgr_c <= 0.0)))) || ( !(( !(st0_l != 0)) && ((delta == 0.0) && ((( !(st0_evt0 != 0)) && ( !(st0_evt1 != 0))) || ((st0_evt0 != 0) && ( !(st0_evt1 != 0))))))))) && ((((((((_x_mgr_evt1 != 0) && ( !(_x_mgr_evt0 != 0))) || ((( !(_x_mgr_evt0 != 0)) && ( !(_x_mgr_evt1 != 0))) || ((_x_mgr_evt0 != 0) && ( !(_x_mgr_evt1 != 0))))) && ((_x_mgr_l != 0) || (_x_mgr_c <= _x_mgr_timeout))) && (((((mgr_l != 0) == (_x_mgr_l != 0)) && ((delta + (mgr_c + (-1.0 * _x_mgr_c))) == 0.0)) && (mgr_timeout == _x_mgr_timeout)) || ( !(((mgr_evt1 != 0) && ( !(mgr_evt0 != 0))) || ( !(delta <= 0.0)))))) && (((( !(mgr_evt0 != 0)) && ( !(mgr_evt1 != 0))) && (( !(_x_mgr_l != 0)) && (_x_mgr_c == 0.0))) || ( !((mgr_l != 0) && (((( !(mgr_evt0 != 0)) && ( !(mgr_evt1 != 0))) || ((mgr_evt0 != 0) && ( !(mgr_evt1 != 0)))) && (delta == 0.0)))))) && ((((_x_mgr_l != 0) && ((mgr_evt0 != 0) && ( !(mgr_evt1 != 0)))) && ((_x_mgr_c == 0.0) && (_x_mgr_timeout == 0.0))) || ( !(( !(mgr_l != 0)) && (((( !(mgr_evt0 != 0)) && ( !(mgr_evt1 != 0))) || ((mgr_evt0 != 0) && ( !(mgr_evt1 != 0)))) && (delta == 0.0)))))) && (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((0.0 <= _x_delta) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st1_evt1 != 0) && ( !(st1_evt0 != 0))))) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st2_evt1 != 0) && ( !(st2_evt0 != 0))))) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st3_evt1 != 0) && ( !(st3_evt0 != 0))))) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st4_evt1 != 0) && ( !(st4_evt0 != 0))))) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st5_evt1 != 0) && ( !(st5_evt0 != 0))))) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st6_evt1 != 0) && ( !(st6_evt0 != 0))))) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st7_evt1 != 0) && ( !(st7_evt0 != 0))))) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st8_evt1 != 0) && ( !(st8_evt0 != 0))))) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st9_evt1 != 0) && ( !(st9_evt0 != 0))))) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st10_evt1 != 0) && ( !(st10_evt0 != 0))))) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st11_evt1 != 0) && ( !(st11_evt0 != 0))))) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st12_evt1 != 0) && ( !(st12_evt0 != 0))))) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st13_evt1 != 0) && ( !(st13_evt0 != 0))))) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st14_evt1 != 0) && ( !(st14_evt0 != 0))))) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st15_evt1 != 0) && ( !(st15_evt0 != 0))))) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((st2_evt1 != 0) && ( !(st2_evt0 != 0))))) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((st3_evt1 != 0) && ( !(st3_evt0 != 0))))) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((st4_evt1 != 0) && ( !(st4_evt0 != 0))))) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((st5_evt1 != 0) && ( !(st5_evt0 != 0))))) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((st6_evt1 != 0) && ( !(st6_evt0 != 0))))) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((st7_evt1 != 0) && ( !(st7_evt0 != 0))))) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((st8_evt1 != 0) && ( !(st8_evt0 != 0))))) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((st9_evt1 != 0) && ( !(st9_evt0 != 0))))) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((st10_evt1 != 0) && ( !(st10_evt0 != 0))))) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((st11_evt1 != 0) && ( !(st11_evt0 != 0))))) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((st12_evt1 != 0) && ( !(st12_evt0 != 0))))) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((st13_evt1 != 0) && ( !(st13_evt0 != 0))))) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((st14_evt1 != 0) && ( !(st14_evt0 != 0))))) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((st15_evt1 != 0) && ( !(st15_evt0 != 0))))) && (((st2_evt1 != 0) && ( !(st2_evt0 != 0))) || ((st3_evt1 != 0) && ( !(st3_evt0 != 0))))) && (((st2_evt1 != 0) && ( !(st2_evt0 != 0))) || ((st4_evt1 != 0) && ( !(st4_evt0 != 0))))) && (((st2_evt1 != 0) && ( !(st2_evt0 != 0))) || ((st5_evt1 != 0) && ( !(st5_evt0 != 0))))) && (((st2_evt1 != 0) && ( !(st2_evt0 != 0))) || ((st6_evt1 != 0) && ( !(st6_evt0 != 0))))) && (((st2_evt1 != 0) && ( !(st2_evt0 != 0))) || ((st7_evt1 != 0) && ( !(st7_evt0 != 0))))) && (((st2_evt1 != 0) && ( !(st2_evt0 != 0))) || ((st8_evt1 != 0) && ( !(st8_evt0 != 0))))) && (((st2_evt1 != 0) && ( !(st2_evt0 != 0))) || ((st9_evt1 != 0) && ( !(st9_evt0 != 0))))) && (((st2_evt1 != 0) && ( !(st2_evt0 != 0))) || ((st10_evt1 != 0) && ( !(st10_evt0 != 0))))) && (((st2_evt1 != 0) && ( !(st2_evt0 != 0))) || ((st11_evt1 != 0) && ( !(st11_evt0 != 0))))) && (((st2_evt1 != 0) && ( !(st2_evt0 != 0))) || ((st12_evt1 != 0) && ( !(st12_evt0 != 0))))) && (((st2_evt1 != 0) && ( !(st2_evt0 != 0))) || ((st13_evt1 != 0) && ( !(st13_evt0 != 0))))) && (((st2_evt1 != 0) && ( !(st2_evt0 != 0))) || ((st14_evt1 != 0) && ( !(st14_evt0 != 0))))) && (((st2_evt1 != 0) && ( !(st2_evt0 != 0))) || ((st15_evt1 != 0) && ( !(st15_evt0 != 0))))) && (((st3_evt1 != 0) && ( !(st3_evt0 != 0))) || ((st4_evt1 != 0) && ( !(st4_evt0 != 0))))) && (((st3_evt1 != 0) && ( !(st3_evt0 != 0))) || ((st5_evt1 != 0) && ( !(st5_evt0 != 0))))) && (((st3_evt1 != 0) && ( !(st3_evt0 != 0))) || ((st6_evt1 != 0) && ( !(st6_evt0 != 0))))) && (((st3_evt1 != 0) && ( !(st3_evt0 != 0))) || ((st7_evt1 != 0) && ( !(st7_evt0 != 0))))) && (((st3_evt1 != 0) && ( !(st3_evt0 != 0))) || ((st8_evt1 != 0) && ( !(st8_evt0 != 0))))) && (((st3_evt1 != 0) && ( !(st3_evt0 != 0))) || ((st9_evt1 != 0) && ( !(st9_evt0 != 0))))) && (((st3_evt1 != 0) && ( !(st3_evt0 != 0))) || ((st10_evt1 != 0) && ( !(st10_evt0 != 0))))) && (((st3_evt1 != 0) && ( !(st3_evt0 != 0))) || ((st11_evt1 != 0) && ( !(st11_evt0 != 0))))) && (((st3_evt1 != 0) && ( !(st3_evt0 != 0))) || ((st12_evt1 != 0) && ( !(st12_evt0 != 0))))) && (((st3_evt1 != 0) && ( !(st3_evt0 != 0))) || ((st13_evt1 != 0) && ( !(st13_evt0 != 0))))) && (((st3_evt1 != 0) && ( !(st3_evt0 != 0))) || ((st14_evt1 != 0) && ( !(st14_evt0 != 0))))) && (((st3_evt1 != 0) && ( !(st3_evt0 != 0))) || ((st15_evt1 != 0) && ( !(st15_evt0 != 0))))) && (((st4_evt1 != 0) && ( !(st4_evt0 != 0))) || ((st5_evt1 != 0) && ( !(st5_evt0 != 0))))) && (((st4_evt1 != 0) && ( !(st4_evt0 != 0))) || ((st6_evt1 != 0) && ( !(st6_evt0 != 0))))) && (((st4_evt1 != 0) && ( !(st4_evt0 != 0))) || ((st7_evt1 != 0) && ( !(st7_evt0 != 0))))) && (((st4_evt1 != 0) && ( !(st4_evt0 != 0))) || ((st8_evt1 != 0) && ( !(st8_evt0 != 0))))) && (((st4_evt1 != 0) && ( !(st4_evt0 != 0))) || ((st9_evt1 != 0) && ( !(st9_evt0 != 0))))) && (((st4_evt1 != 0) && ( !(st4_evt0 != 0))) || ((st10_evt1 != 0) && ( !(st10_evt0 != 0))))) && (((st4_evt1 != 0) && ( !(st4_evt0 != 0))) || ((st11_evt1 != 0) && ( !(st11_evt0 != 0))))) && (((st4_evt1 != 0) && ( !(st4_evt0 != 0))) || ((st12_evt1 != 0) && ( !(st12_evt0 != 0))))) && (((st4_evt1 != 0) && ( !(st4_evt0 != 0))) || ((st13_evt1 != 0) && ( !(st13_evt0 != 0))))) && (((st4_evt1 != 0) && ( !(st4_evt0 != 0))) || ((st14_evt1 != 0) && ( !(st14_evt0 != 0))))) && (((st4_evt1 != 0) && ( !(st4_evt0 != 0))) || ((st15_evt1 != 0) && ( !(st15_evt0 != 0))))) && (((st5_evt1 != 0) && ( !(st5_evt0 != 0))) || ((st6_evt1 != 0) && ( !(st6_evt0 != 0))))) && (((st5_evt1 != 0) && ( !(st5_evt0 != 0))) || ((st7_evt1 != 0) && ( !(st7_evt0 != 0))))) && (((st5_evt1 != 0) && ( !(st5_evt0 != 0))) || ((st8_evt1 != 0) && ( !(st8_evt0 != 0))))) && (((st5_evt1 != 0) && ( !(st5_evt0 != 0))) || ((st9_evt1 != 0) && ( !(st9_evt0 != 0))))) && (((st5_evt1 != 0) && ( !(st5_evt0 != 0))) || ((st10_evt1 != 0) && ( !(st10_evt0 != 0))))) && (((st5_evt1 != 0) && ( !(st5_evt0 != 0))) || ((st11_evt1 != 0) && ( !(st11_evt0 != 0))))) && (((st5_evt1 != 0) && ( !(st5_evt0 != 0))) || ((st12_evt1 != 0) && ( !(st12_evt0 != 0))))) && (((st5_evt1 != 0) && ( !(st5_evt0 != 0))) || ((st13_evt1 != 0) && ( !(st13_evt0 != 0))))) && (((st5_evt1 != 0) && ( !(st5_evt0 != 0))) || ((st14_evt1 != 0) && ( !(st14_evt0 != 0))))) && (((st5_evt1 != 0) && ( !(st5_evt0 != 0))) || ((st15_evt1 != 0) && ( !(st15_evt0 != 0))))) && (((st6_evt1 != 0) && ( !(st6_evt0 != 0))) || ((st7_evt1 != 0) && ( !(st7_evt0 != 0))))) && (((st6_evt1 != 0) && ( !(st6_evt0 != 0))) || ((st8_evt1 != 0) && ( !(st8_evt0 != 0))))) && (((st6_evt1 != 0) && ( !(st6_evt0 != 0))) || ((st9_evt1 != 0) && ( !(st9_evt0 != 0))))) && (((st6_evt1 != 0) && ( !(st6_evt0 != 0))) || ((st10_evt1 != 0) && ( !(st10_evt0 != 0))))) && (((st6_evt1 != 0) && ( !(st6_evt0 != 0))) || ((st11_evt1 != 0) && ( !(st11_evt0 != 0))))) && (((st6_evt1 != 0) && ( !(st6_evt0 != 0))) || ((st12_evt1 != 0) && ( !(st12_evt0 != 0))))) && (((st6_evt1 != 0) && ( !(st6_evt0 != 0))) || ((st13_evt1 != 0) && ( !(st13_evt0 != 0))))) && (((st6_evt1 != 0) && ( !(st6_evt0 != 0))) || ((st14_evt1 != 0) && ( !(st14_evt0 != 0))))) && (((st6_evt1 != 0) && ( !(st6_evt0 != 0))) || ((st15_evt1 != 0) && ( !(st15_evt0 != 0))))) && (((st7_evt1 != 0) && ( !(st7_evt0 != 0))) || ((st8_evt1 != 0) && ( !(st8_evt0 != 0))))) && (((st7_evt1 != 0) && ( !(st7_evt0 != 0))) || ((st9_evt1 != 0) && ( !(st9_evt0 != 0))))) && (((st7_evt1 != 0) && ( !(st7_evt0 != 0))) || ((st10_evt1 != 0) && ( !(st10_evt0 != 0))))) && (((st7_evt1 != 0) && ( !(st7_evt0 != 0))) || ((st11_evt1 != 0) && ( !(st11_evt0 != 0))))) && (((st7_evt1 != 0) && ( !(st7_evt0 != 0))) || ((st12_evt1 != 0) && ( !(st12_evt0 != 0))))) && (((st7_evt1 != 0) && ( !(st7_evt0 != 0))) || ((st13_evt1 != 0) && ( !(st13_evt0 != 0))))) && (((st7_evt1 != 0) && ( !(st7_evt0 != 0))) || ((st14_evt1 != 0) && ( !(st14_evt0 != 0))))) && (((st7_evt1 != 0) && ( !(st7_evt0 != 0))) || ((st15_evt1 != 0) && ( !(st15_evt0 != 0))))) && (((st8_evt1 != 0) && ( !(st8_evt0 != 0))) || ((st9_evt1 != 0) && ( !(st9_evt0 != 0))))) && (((st8_evt1 != 0) && ( !(st8_evt0 != 0))) || ((st10_evt1 != 0) && ( !(st10_evt0 != 0))))) && (((st8_evt1 != 0) && ( !(st8_evt0 != 0))) || ((st11_evt1 != 0) && ( !(st11_evt0 != 0))))) && (((st8_evt1 != 0) && ( !(st8_evt0 != 0))) || ((st12_evt1 != 0) && ( !(st12_evt0 != 0))))) && (((st8_evt1 != 0) && ( !(st8_evt0 != 0))) || ((st13_evt1 != 0) && ( !(st13_evt0 != 0))))) && (((st8_evt1 != 0) && ( !(st8_evt0 != 0))) || ((st14_evt1 != 0) && ( !(st14_evt0 != 0))))) && (((st8_evt1 != 0) && ( !(st8_evt0 != 0))) || ((st15_evt1 != 0) && ( !(st15_evt0 != 0))))) && (((st9_evt1 != 0) && ( !(st9_evt0 != 0))) || ((st10_evt1 != 0) && ( !(st10_evt0 != 0))))) && (((st9_evt1 != 0) && ( !(st9_evt0 != 0))) || ((st11_evt1 != 0) && ( !(st11_evt0 != 0))))) && (((st9_evt1 != 0) && ( !(st9_evt0 != 0))) || ((st12_evt1 != 0) && ( !(st12_evt0 != 0))))) && (((st9_evt1 != 0) && ( !(st9_evt0 != 0))) || ((st13_evt1 != 0) && ( !(st13_evt0 != 0))))) && (((st9_evt1 != 0) && ( !(st9_evt0 != 0))) || ((st14_evt1 != 0) && ( !(st14_evt0 != 0))))) && (((st9_evt1 != 0) && ( !(st9_evt0 != 0))) || ((st15_evt1 != 0) && ( !(st15_evt0 != 0))))) && (((st10_evt1 != 0) && ( !(st10_evt0 != 0))) || ((st11_evt1 != 0) && ( !(st11_evt0 != 0))))) && (((st10_evt1 != 0) && ( !(st10_evt0 != 0))) || ((st12_evt1 != 0) && ( !(st12_evt0 != 0))))) && (((st10_evt1 != 0) && ( !(st10_evt0 != 0))) || ((st13_evt1 != 0) && ( !(st13_evt0 != 0))))) && (((st10_evt1 != 0) && ( !(st10_evt0 != 0))) || ((st14_evt1 != 0) && ( !(st14_evt0 != 0))))) && (((st10_evt1 != 0) && ( !(st10_evt0 != 0))) || ((st15_evt1 != 0) && ( !(st15_evt0 != 0))))) && (((st11_evt1 != 0) && ( !(st11_evt0 != 0))) || ((st12_evt1 != 0) && ( !(st12_evt0 != 0))))) && (((st11_evt1 != 0) && ( !(st11_evt0 != 0))) || ((st13_evt1 != 0) && ( !(st13_evt0 != 0))))) && (((st11_evt1 != 0) && ( !(st11_evt0 != 0))) || ((st14_evt1 != 0) && ( !(st14_evt0 != 0))))) && (((st11_evt1 != 0) && ( !(st11_evt0 != 0))) || ((st15_evt1 != 0) && ( !(st15_evt0 != 0))))) && (((st12_evt1 != 0) && ( !(st12_evt0 != 0))) || ((st13_evt1 != 0) && ( !(st13_evt0 != 0))))) && (((st12_evt1 != 0) && ( !(st12_evt0 != 0))) || ((st14_evt1 != 0) && ( !(st14_evt0 != 0))))) && (((st12_evt1 != 0) && ( !(st12_evt0 != 0))) || ((st15_evt1 != 0) && ( !(st15_evt0 != 0))))) && (((st13_evt1 != 0) && ( !(st13_evt0 != 0))) || ((st14_evt1 != 0) && ( !(st14_evt0 != 0))))) && (((st13_evt1 != 0) && ( !(st13_evt0 != 0))) || ((st15_evt1 != 0) && ( !(st15_evt0 != 0))))) && (((st14_evt1 != 0) && ( !(st14_evt0 != 0))) || ((st15_evt1 != 0) && ( !(st15_evt0 != 0))))) && ((( !(mgr_evt0 != 0)) && ( !(mgr_evt1 != 0))) == ((( !(st15_evt0 != 0)) && ( !(st15_evt1 != 0))) || ((( !(st14_evt0 != 0)) && ( !(st14_evt1 != 0))) || ((( !(st13_evt0 != 0)) && ( !(st13_evt1 != 0))) || ((( !(st12_evt0 != 0)) && ( !(st12_evt1 != 0))) || ((( !(st11_evt0 != 0)) && ( !(st11_evt1 != 0))) || ((( !(st10_evt0 != 0)) && ( !(st10_evt1 != 0))) || ((( !(st9_evt0 != 0)) && ( !(st9_evt1 != 0))) || ((( !(st8_evt0 != 0)) && ( !(st8_evt1 != 0))) || ((( !(st7_evt0 != 0)) && ( !(st7_evt1 != 0))) || ((( !(st6_evt0 != 0)) && ( !(st6_evt1 != 0))) || ((( !(st5_evt0 != 0)) && ( !(st5_evt1 != 0))) || ((( !(st4_evt0 != 0)) && ( !(st4_evt1 != 0))) || ((( !(st3_evt0 != 0)) && ( !(st3_evt1 != 0))) || ((( !(st2_evt0 != 0)) && ( !(st2_evt1 != 0))) || ((( !(st0_evt0 != 0)) && ( !(st0_evt1 != 0))) || (( !(st1_evt0 != 0)) && ( !(st1_evt1 != 0)))))))))))))))))))) && (((mgr_evt0 != 0) && ( !(mgr_evt1 != 0))) == (((st15_evt0 != 0) && ( !(st15_evt1 != 0))) || (((st14_evt0 != 0) && ( !(st14_evt1 != 0))) || (((st13_evt0 != 0) && ( !(st13_evt1 != 0))) || (((st12_evt0 != 0) && ( !(st12_evt1 != 0))) || (((st11_evt0 != 0) && ( !(st11_evt1 != 0))) || (((st10_evt0 != 0) && ( !(st10_evt1 != 0))) || (((st9_evt0 != 0) && ( !(st9_evt1 != 0))) || (((st8_evt0 != 0) && ( !(st8_evt1 != 0))) || (((st7_evt0 != 0) && ( !(st7_evt1 != 0))) || (((st6_evt0 != 0) && ( !(st6_evt1 != 0))) || (((st5_evt0 != 0) && ( !(st5_evt1 != 0))) || (((st4_evt0 != 0) && ( !(st4_evt1 != 0))) || (((st3_evt0 != 0) && ( !(st3_evt1 != 0))) || (((st2_evt0 != 0) && ( !(st2_evt1 != 0))) || (((st0_evt0 != 0) && ( !(st0_evt1 != 0))) || ((st1_evt0 != 0) && ( !(st1_evt1 != 0)))))))))))))))))))) && (((tot_transm_time + ((-1.0 * _x_tot_transm_time) + mgr_c)) == 0.0) || ( !((_x_mgr_l != 0) && ( !(mgr_l != 0)))))) && (((_x_mgr_l != 0) && ( !(mgr_l != 0))) || (tot_transm_time == _x_tot_transm_time)))))))))))))))))))) && (((delta == _x__diverge_delta) || ( !(1.0 <= _diverge_delta))) && ((1.0 <= _diverge_delta) || ((delta + (_diverge_delta + (-1.0 * _x__diverge_delta))) == 0.0)))); _diverge_delta = _x__diverge_delta; st15_evt1 = _x_st15_evt1; st15_evt0 = _x_st15_evt0; st15_req_time = _x_st15_req_time; st15_l = _x_st15_l; st14_evt1 = _x_st14_evt1; st14_evt0 = _x_st14_evt0; st14_req_time = _x_st14_req_time; st14_l = _x_st14_l; st5_req_time = _x_st5_req_time; st13_l = _x_st13_l; mgr_l = _x_mgr_l; st3_evt1 = _x_st3_evt1; st5_l = _x_st5_l; st4_evt1 = _x_st4_evt1; st6_req_time = _x_st6_req_time; st4_req_time = _x_st4_req_time; st2_evt1 = _x_st2_evt1; st4_l = _x_st4_l; st2_evt0 = _x_st2_evt0; st13_evt1 = _x_st13_evt1; mgr_evt1 = _x_mgr_evt1; st2_req_time = _x_st2_req_time; mgr_timeout = _x_mgr_timeout; st2_l = _x_st2_l; st13_evt0 = _x_st13_evt0; mgr_evt0 = _x_mgr_evt0; st1_evt1 = _x_st1_evt1; st3_req_time = _x_st3_req_time; st0_l = _x_st0_l; st1_evt0 = _x_st1_evt0; delta = _x_delta; st3_l = _x_st3_l; st1_l = _x_st1_l; tot_transm_time = _x_tot_transm_time; st3_evt0 = _x_st3_evt0; st0_req_time = _x_st0_req_time; st13_req_time = _x_st13_req_time; mgr_c = _x_mgr_c; st0_evt1 = _x_st0_evt1; st0_evt0 = _x_st0_evt0; st4_evt0 = _x_st4_evt0; st1_req_time = _x_st1_req_time; st5_evt0 = _x_st5_evt0; st5_evt1 = _x_st5_evt1; st7_req_time = _x_st7_req_time; st6_l = _x_st6_l; st6_evt0 = _x_st6_evt0; st6_evt1 = _x_st6_evt1; st8_req_time = _x_st8_req_time; st7_l = _x_st7_l; st7_evt0 = _x_st7_evt0; st7_evt1 = _x_st7_evt1; st9_req_time = _x_st9_req_time; st8_l = _x_st8_l; st8_evt0 = _x_st8_evt0; st8_evt1 = _x_st8_evt1; st10_req_time = _x_st10_req_time; st9_l = _x_st9_l; st9_evt0 = _x_st9_evt0; st9_evt1 = _x_st9_evt1; st11_req_time = _x_st11_req_time; st10_l = _x_st10_l; st10_evt0 = _x_st10_evt0; st10_evt1 = _x_st10_evt1; st12_req_time = _x_st12_req_time; st11_l = _x_st11_l; st11_evt0 = _x_st11_evt0; st11_evt1 = _x_st11_evt1; st12_l = _x_st12_l; st12_evt0 = _x_st12_evt0; st12_evt1 = _x_st12_evt1; } }
the_stack_data/75137604.c
// RUN: %clam -O0 --crab-dom=zones --crab-check=assert --crab-sanity-checks "%s" 2>&1 | OutputCheck -l debug %s // CHECK: ^2 Number of total safe checks$ // CHECK: ^0 Number of total error checks$ // CHECK: ^0 Number of total warning checks$ extern void __CRAB_assume (int); extern void __CRAB_assert(int); extern int __CRAB_nd(void); int main() { int k = __CRAB_nd(); int n = __CRAB_nd(); __CRAB_assume (k > 0); __CRAB_assume (n > 0); int x = k; int y = k; while (x < n) { x++; y++; } __CRAB_assert (x >= y); __CRAB_assert (x <= y); return 0; }
the_stack_data/32605.c
int _strcmp(char *s1, char *s2){ while(*s1 != '\0' && *s2 != '\0'){ if(*s1 != *s2) break; s1++; s2++; } return(*s1 - *s2); } int _strncmp(char *s1, char *s2, unsigned int n){ unsigned int i = 0; while(*s1 != '\0' && *s2 != '\0' && ++i < n){ if(*s1 != *s2) break; s1++; s2++; } return(*s1 - *s2); } int _strlen(char *str){ int i; for(i = 0; str[i] != '\0'; i++); return(i); }
the_stack_data/89200308.c
/* Insertion sort */ #include<stdio.h> void insertion_sort(int* arr, int n); int main() { int n, i; printf("Enter the number of elements\n"); scanf("%d", &n); int arr[n]; // Declaring an array of size 'n' printf("Enter the elements\n"); for(i = 0; i < n; i++) { scanf("%d", &arr[i]); // Reading the elements into the array } insertion_sort(arr, n); // function call printf("After insertion sort\n"); for(i = 0; i < n; i++) { printf("%d\t", arr[i]); // Sorted array is printed } return 0; } void insertion_sort(int* arr, int n) { // After 'i' iterations, the first 'i' elements will be sorted int i, value, hole; // Start of core algorithm------ for(i = 1; i < n; i++) { value = arr[i]; // The i'th value, which is compared with the values of i-1 elements hole = i; while(hole >= 0 && arr[hole - 1] > value) { arr[hole] = arr[hole - 1]; // Replace the hole, if an element lower than the i'th value is found with the value of 'i - 1'th element hole -= 1; // Decrement hole to successively compare the previous elements of the hole } arr[hole] = value; // Place the i'th value in appropriate position } // ------ End of core algorithm }
the_stack_data/192330294.c
#include <string.h> #include <stdio.h> void main(int argc, char** argv) { char* buff=malloc(20); strcpy(buff, argv[1]); free(buff); }
the_stack_data/15143.c
// gcc server.c #include <assert.h> #include <errno.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <unistd.h> #define SRV_PORT 55226 #define TCPRIV_INFO "tcpriv[info]: " #define TCPRIV_ERRO "tcpriv[erro]: " #define TCPOLEN_EXP_TCPRIV_BASE 10 #define TCPOLEN_EXP_TCPRIV_BASE_ALIGNED 12 /* ref: https://www.iana.org/assignments/tcp-parameters/tcp-parameters.xhtml */ #define TCPOPT_TCPRIV_MAGIC 0xF991 #define OPTION_SACK_ADVERTISE (1 << 0) #define OPTION_TS (1 << 1) #define OPTION_MD5 (1 << 2) #define OPTION_WSCALE (1 << 3) #define OPTION_FAST_OPEN_COOKIE (1 << 8) #define OPTION_SMC (1 << 9) #define OPTION_MPTCP (1 << 10) /* 1 << 10 was used by MPTCP */ #define OPTION_TCPRIV (1 << 11) #ifndef TCP_SAVE_SYN #define TCP_SAVE_SYN 27 #endif #ifndef TCP_SAVED_SYN #define TCP_SAVED_SYN 28 #endif #define TCPOPT_NOP 1 /* Padding */ #define TCPOPT_EOL 0 /* End of options */ #define TCPOPT_MSS 2 /* Segment size negotiating */ #define TCPOPT_WINDOW 3 /* Window scaling */ #define TCPOPT_SACK_PERM 4 /* SACK Permitted */ #define TCPOPT_SACK 5 /* SACK Block */ #define TCPOPT_TIMESTAMP 8 /* Better RTT estimations/PAWS */ #define TCPOPT_MD5SIG 19 /* MD5 Signature (RFC2385) */ #define TCPOPT_FASTOPEN 34 /* Fast open (RFC7413) */ #define TCPOPT_EXP 254 /* Experimental */ /* Magic number to be after the option value for sharing TCP ** experimental options. See draft-ietf-tcpm-experimental-options-00.txt **/ #define TCPOPT_FASTOPEN_MAGIC 0xF989 /* ** TCP option lengths **/ #define TCPOLEN_MSS 4 #define TCPOLEN_WINDOW 3 #define TCPOLEN_SACK_PERM 2 #define TCPOLEN_TIMESTAMP 10 #define TCPOLEN_MD5SIG 18 #define TCPOLEN_FASTOPEN_BASE 2 #define TCPOLEN_EXP_FASTOPEN_BASE 4 /* But this is what stacks really send out. */ #define TCPOLEN_TSTAMP_ALIGNED 12 #define TCPOLEN_WSCALE_ALIGNED 4 #define TCPOLEN_SACKPERM_ALIGNED 4 #define TCPOLEN_SACK_BASE 2 #define TCPOLEN_SACK_BASE_ALIGNED 4 #define TCPOLEN_SACK_PERBLOCK 8 #define TCPOLEN_MD5SIG_ALIGNED 20 #define TCPOLEN_MSS_ALIGNED 4 static void fail(const char *msg) { fprintf(stderr, TCPRIV_ERRO "%s\n", msg); exit(1); } static void fail_perror(const char *msg) { perror(msg); exit(1); } // ref: https://lwn.net/Articles/645130/ /* Get and validate the saved SYN. */ static void read_saved_syn(int fd, int address_family) { unsigned char syn[500]; unsigned int tcpriv_uid, tcpriv_magic; unsigned char tcpriv_kind, tcpriv_len; socklen_t syn_len = sizeof(syn); memset(syn, 0, sizeof(syn)); /* Read the saved SYN. */ if (getsockopt(fd, IPPROTO_TCP, TCP_SAVED_SYN, syn, &syn_len) != 0) fail_perror(TCPRIV_ERRO "first getsockopt TCP_SAVED_SYN failed"); /* Check the length and first byte of the SYN. */ if (address_family == AF_INET) { printf(TCPRIV_INFO "syn_len: %d\n", syn_len); assert(syn_len == 60); assert(syn[0] >> 4 == 0x4); /* IPv4 */ } else if (address_family == AF_INET6) { assert(syn_len == 80); assert(syn[0] >> 4 == 0x6); /* IPv6 */ } else { assert(!"bad address family"); } /* Check the last few bytes of the SYN, which will be TCP options. */ assert(syn[syn_len - 4] == 0x01); /* TCP option: kind = NOP */ assert(syn[syn_len - 3] == 0x03); /* TCP option: kind = window scale */ assert(syn[syn_len - 2] == 0x03); /* TCP option: length = 3 */ assert(syn[syn_len - 1] == 0x06 || syn[syn_len - 1] == 0x07); /* TCP option: window scale = 6 or 7 */ for (int i = 0; i < syn_len; i++) { if (syn[i] == TCPOPT_EXP && syn[i + 1] == TCPOLEN_EXP_TCPRIV_BASE && ntohl(*(unsigned int *)&syn[i + 1 + 1]) == TCPOPT_TCPRIV_MAGIC) { /* tcpriv options field structure kind[1] + length[1] + magic[4] + content[4] */ tcpriv_kind = syn[i]; tcpriv_len = syn[i + 1]; tcpriv_magic = ntohl(*(unsigned int *)&syn[i + 1 + 1]); tcpriv_uid = ntohl(*(unsigned int *)&syn[i + 1 + 4 + 1]); printf(TCPRIV_INFO "found tcpriv's information: kind=%u length=%u ExID=0x%x uid=%u \n", tcpriv_kind, tcpriv_len, tcpriv_magic, tcpriv_uid); break; } } /* Check the tcpriv option fields */ assert(tcpriv_kind == TCPOPT_EXP); assert(tcpriv_len == TCPOLEN_EXP_TCPRIV_BASE); assert(tcpriv_magic == TCPOPT_TCPRIV_MAGIC); assert(tcpriv_uid == 1000); /* If we try TCP_SAVED_SYN again it should succeed with 0 length. */ if (getsockopt(fd, IPPROTO_TCP, TCP_SAVED_SYN, syn, &syn_len) != 0) fail("repeated getsockopt TCP_SAVED_SYN failed"); assert(syn_len == 0); } int main() { unsigned short port = SRV_PORT; struct sockaddr_in srv_addr, cli_addr; int srv_fd, cli_fd; int one = 1; int cli_addr_size = sizeof(cli_addr); memset(&srv_addr, 0, sizeof(srv_addr)); srv_addr.sin_port = htons(port); srv_addr.sin_family = AF_INET; srv_addr.sin_addr.s_addr = htonl(INADDR_ANY); srv_fd = socket(AF_INET, SOCK_STREAM, 0); bind(srv_fd, (struct sockaddr *)&srv_addr, sizeof(srv_addr)); /* even if you don't set TCP_SAVE_SYN below, you can use tcp_save_syn_listen via LD_PRELOAD and listen() set * TCP_SAVE_SYN into socket automatically. */ // if (setsockopt(srv_fd, IPPROTO_TCP, TCP_SAVE_SYN, &one, sizeof(one)) < 0) // fail_perror(TCPRIV_ERRO "setsockopt TCP_SAVE_SYN"); listen(srv_fd, 1); printf(TCPRIV_INFO "waiting...\n"); cli_fd = accept(srv_fd, (struct sockaddr *)&cli_addr, &cli_addr_size); printf(TCPRIV_INFO "connected: %s\n", inet_ntoa(cli_addr.sin_addr)); read_saved_syn(cli_fd, ((struct sockaddr *)&cli_addr)->sa_family); close(cli_fd); printf(TCPRIV_INFO "all test success.\n"); return 0; }
the_stack_data/231394426.c
/* { dg-do compile } */ /* { dg-options "-O2 -mieee" } */ float foo(unsigned char n) { float r = 10 * n; asm volatile("" : : : "memory"); return r; }
the_stack_data/50136963.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 maximum(int x, int y); int minimum(int x, int y); int multiply(int x, int y); 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 maximum(int x, int y) { int max; if(x>=y) max=x; else max=y; return max; } int minimum(int x, int y) { int min; if(x<y) min=x; else min=y; return min; } int multiply(int x, int y) { return x*y; }
the_stack_data/124170.c
/************************************************************************************ * arch/sim/src/sim/up_critmon.c * * Copyright (C) 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <[email protected]> * * 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 NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * ************************************************************************************/ /************************************************************************************ * Included Files ************************************************************************************/ #include <stdint.h> #include <time.h> /************************************************************************************ * Pre-processor Definitions ************************************************************************************/ #undef USE_CLOCK /* Too slow */ #define USE_CLOCK_GETTIME 1 /* Better */ /* From nuttx/clock.h */ #define NSEC_PER_SEC 1000000000 /* From fixedmath.h */ #define b32ONE 0x0000000100000000 /* 1 */ #define b32toi(a) ((a) >> 32) /* Conversion to integer */ #define itob32(i) (((b32_t)(i)) << 32) /* Conversion from integer */ #define b32frac(a) ((a) & 0x00000000ffffffff) /* Take fractional part */ /************************************************************************************ * Private Types ************************************************************************************/ /* From fixedmath.h */ typedef int64_t b32_t; /************************************************************************************ * Private Data ************************************************************************************/ /************************************************************************************ * Public Functions ************************************************************************************/ /************************************************************************************ * Name: up_critmon_gettime ************************************************************************************/ #if defined(USE_CLOCK) uint32_t up_critmon_gettime(void) { return (uint32_t)clock() + 1; /* Avoid returning zero which means clock-not-ready */ } #else /* USE_CLOCK_GETTIME */ uint32_t up_critmon_gettime(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return (uint32_t)ts.tv_nsec; } #endif /************************************************************************************ * Name: up_critmon_gettime ************************************************************************************/ #if defined(USE_CLOCK) void up_critmon_convert(uint32_t elapsed, struct timespec *ts) { b32_t b32elapsed; b32elapsed = itob32(elapsed) / CLOCKS_PER_SEC; ts->tv_sec = b32toi(b32elapsed); ts->tv_nsec = NSEC_PER_SEC * b32frac(b32elapsed) / b32ONE; } #else /* USE_CLOCK_GETTIME */ void up_critmon_convert(uint32_t elapsed, struct timespec *ts) { ts->tv_sec = 0; ts->tv_nsec = elapsed; } #endif
the_stack_data/103636.c
// Objective-C - GNUstep / Clang int multiply(int a, int b) { return a * b; }
the_stack_data/162642170.c
/*** * This code is a part of EvoApproxLib library (ehw.fit.vutbr.cz/approxlib) distributed under The MIT License. * When used, please cite the following article(s): V. Mrazek, Z. Vasicek, L. Sekanina, H. Jiang and J. Han, "Scalable Construction of Approximate Multipliers With Formally Guaranteed Worst Case Error" in IEEE Transactions on Very Large Scale Integration (VLSI) Systems, vol. 26, no. 11, pp. 2572-2576, Nov. 2018. doi: 10.1109/TVLSI.2018.2856362 * This file contains a circuit from a sub-set of pareto optimal circuits with respect to the pwr and mre parameters ***/ // MAE% = 0.00057 % // MAE = 24580 // WCE% = 0.0023 % // WCE = 98369 // WCRE% = 6500.00 % // EP% = 92.19 % // MRE% = 0.052 % // MSE = 12526.994e5 // PDK45_PWR = 2.124 mW // PDK45_AREA = 2640.3 um2 // PDK45_DELAY = 2.95 ns #include <stdint.h> #include <stdlib.h> int32_t mul16s_GK2(int16_t A, int16_t B) { int32_t P, P_; uint16_t tmp, C_10_0,C_10_1,C_10_10,C_10_11,C_10_12,C_10_13,C_10_14,C_10_15,C_10_2,C_10_3,C_10_4,C_10_5,C_10_6,C_10_7,C_10_8,C_10_9,C_11_0,C_11_1,C_11_10,C_11_11,C_11_12,C_11_13,C_11_14,C_11_15,C_11_2,C_11_3,C_11_4,C_11_5,C_11_6,C_11_7,C_11_8,C_11_9,C_12_0,C_12_1,C_12_10,C_12_11,C_12_12,C_12_13,C_12_14,C_12_15,C_12_2,C_12_3,C_12_4,C_12_5,C_12_6,C_12_7,C_12_8,C_12_9,C_13_0,C_13_1,C_13_10,C_13_11,C_13_12,C_13_13,C_13_14,C_13_15,C_13_2,C_13_3,C_13_4,C_13_5,C_13_6,C_13_7,C_13_8,C_13_9,C_14_0,C_14_1,C_14_10,C_14_11,C_14_12,C_14_13,C_14_14,C_14_15,C_14_2,C_14_3,C_14_4,C_14_5,C_14_6,C_14_7,C_14_8,C_14_9,C_15_0,C_15_1,C_15_10,C_15_11,C_15_12,C_15_13,C_15_14,C_15_15,C_15_2,C_15_3,C_15_4,C_15_5,C_15_6,C_15_7,C_15_8,C_15_9,C_16_0,C_16_1,C_16_10,C_16_11,C_16_12,C_16_13,C_16_14,C_16_15,C_16_2,C_16_3,C_16_4,C_16_5,C_16_6,C_16_7,C_16_8,C_16_9,C_2_13,C_2_15,C_3_10,C_3_11,C_3_12,C_3_13,C_3_14,C_3_15,C_3_2,C_3_3,C_3_4,C_3_5,C_3_6,C_3_7,C_3_8,C_3_9,C_4_1,C_4_10,C_4_11,C_4_12,C_4_13,C_4_14,C_4_15,C_4_2,C_4_3,C_4_4,C_4_5,C_4_6,C_4_7,C_4_8,C_4_9,C_5_0,C_5_1,C_5_10,C_5_11,C_5_12,C_5_13,C_5_14,C_5_15,C_5_2,C_5_3,C_5_4,C_5_5,C_5_6,C_5_7,C_5_8,C_5_9,C_6_0,C_6_1,C_6_10,C_6_11,C_6_12,C_6_13,C_6_14,C_6_15,C_6_2,C_6_3,C_6_4,C_6_5,C_6_6,C_6_7,C_6_8,C_6_9,C_7_0,C_7_1,C_7_10,C_7_11,C_7_12,C_7_13,C_7_14,C_7_15,C_7_2,C_7_3,C_7_4,C_7_5,C_7_6,C_7_7,C_7_8,C_7_9,C_8_0,C_8_1,C_8_10,C_8_11,C_8_12,C_8_13,C_8_14,C_8_15,C_8_2,C_8_3,C_8_4,C_8_5,C_8_6,C_8_7,C_8_8,C_8_9,C_9_0,C_9_1,C_9_10,C_9_11,C_9_12,C_9_13,C_9_14,C_9_15,C_9_2,C_9_3,C_9_4,C_9_5,C_9_6,C_9_7,C_9_8,C_9_9,S_0_15,S_10_0,S_10_1,S_10_10,S_10_11,S_10_12,S_10_13,S_10_14,S_10_15,S_10_2,S_10_3,S_10_4,S_10_5,S_10_6,S_10_7,S_10_8,S_10_9,S_11_0,S_11_1,S_11_10,S_11_11,S_11_12,S_11_13,S_11_14,S_11_15,S_11_2,S_11_3,S_11_4,S_11_5,S_11_6,S_11_7,S_11_8,S_11_9,S_12_0,S_12_1,S_12_10,S_12_11,S_12_12,S_12_13,S_12_14,S_12_15,S_12_2,S_12_3,S_12_4,S_12_5,S_12_6,S_12_7,S_12_8,S_12_9,S_13_0,S_13_1,S_13_10,S_13_11,S_13_12,S_13_13,S_13_14,S_13_15,S_13_2,S_13_3,S_13_4,S_13_5,S_13_6,S_13_7,S_13_8,S_13_9,S_14_0,S_14_1,S_14_10,S_14_11,S_14_12,S_14_13,S_14_14,S_14_15,S_14_2,S_14_3,S_14_4,S_14_5,S_14_6,S_14_7,S_14_8,S_14_9,S_15_0,S_15_1,S_15_10,S_15_11,S_15_12,S_15_13,S_15_14,S_15_15,S_15_2,S_15_3,S_15_4,S_15_5,S_15_6,S_15_7,S_15_8,S_15_9,S_16_0,S_16_1,S_16_10,S_16_11,S_16_12,S_16_13,S_16_14,S_16_15,S_16_2,S_16_3,S_16_4,S_16_5,S_16_6,S_16_7,S_16_8,S_16_9,S_1_14,S_2_10,S_2_11,S_2_12,S_2_13,S_2_14,S_2_15,S_2_3,S_2_4,S_2_5,S_2_6,S_2_7,S_2_8,S_2_9,S_3_10,S_3_11,S_3_12,S_3_13,S_3_14,S_3_15,S_3_2,S_3_3,S_3_4,S_3_5,S_3_6,S_3_7,S_3_8,S_3_9,S_4_1,S_4_10,S_4_11,S_4_12,S_4_13,S_4_14,S_4_15,S_4_2,S_4_3,S_4_4,S_4_5,S_4_6,S_4_7,S_4_8,S_4_9,S_5_0,S_5_1,S_5_10,S_5_11,S_5_12,S_5_13,S_5_14,S_5_15,S_5_2,S_5_3,S_5_4,S_5_5,S_5_6,S_5_7,S_5_8,S_5_9,S_6_0,S_6_1,S_6_10,S_6_11,S_6_12,S_6_13,S_6_14,S_6_15,S_6_2,S_6_3,S_6_4,S_6_5,S_6_6,S_6_7,S_6_8,S_6_9,S_7_0,S_7_1,S_7_10,S_7_11,S_7_12,S_7_13,S_7_14,S_7_15,S_7_2,S_7_3,S_7_4,S_7_5,S_7_6,S_7_7,S_7_8,S_7_9,S_8_0,S_8_1,S_8_10,S_8_11,S_8_12,S_8_13,S_8_14,S_8_15,S_8_2,S_8_3,S_8_4,S_8_5,S_8_6,S_8_7,S_8_8,S_8_9,S_9_0,S_9_1,S_9_10,S_9_11,S_9_12,S_9_13,S_9_14,S_9_15,S_9_2,S_9_3,S_9_4,S_9_5,S_9_6,S_9_7,S_9_8,S_9_9; S_0_15 = 1; S_1_14 = 1; S_2_3 = (((A>>2)&1) & ((B>>3)&1)); S_2_4 = (((A>>2)&1) & ((B>>4)&1)); S_2_5 = (((A>>2)&1) & ((B>>5)&1)); S_2_6 = (((A>>2)&1) & ((B>>6)&1)); S_2_7 = (((A>>2)&1) & ((B>>7)&1)); S_2_8 = (((A>>2)&1) & ((B>>8)&1)); S_2_9 = (((A>>2)&1) & ((B>>9)&1)); S_2_10 = (((A>>2)&1) & ((B>>10)&1)); S_2_11 = (((A>>2)&1) & ((B>>11)&1)); S_2_12 = (((A>>2)&1) & ((B>>12)&1)); S_2_13 = S_1_14^(((A>>2)&1) & ((B>>13)&1)); C_2_13 = S_1_14&(((A>>2)&1) & ((B>>13)&1)); S_2_14 = (((A>>2)&1) & ((B>>14)&1)); S_2_15 = 1^(((((A>>2)&1) & ((B>>15)&1)))^1); C_2_15 = 1&(((((A>>2)&1) & ((B>>15)&1)))^1); S_3_2 = S_2_3^(((A>>3)&1) & ((B>>2)&1)); C_3_2 = S_2_3&(((A>>3)&1) & ((B>>2)&1)); S_3_3 = S_2_4^(((A>>3)&1) & ((B>>3)&1)); C_3_3 = S_2_4&(((A>>3)&1) & ((B>>3)&1)); S_3_4 = S_2_5^(((A>>3)&1) & ((B>>4)&1)); C_3_4 = S_2_5&(((A>>3)&1) & ((B>>4)&1)); S_3_5 = S_2_6^(((A>>3)&1) & ((B>>5)&1)); C_3_5 = S_2_6&(((A>>3)&1) & ((B>>5)&1)); S_3_6 = S_2_7^(((A>>3)&1) & ((B>>6)&1)); C_3_6 = S_2_7&(((A>>3)&1) & ((B>>6)&1)); S_3_7 = S_2_8^(((A>>3)&1) & ((B>>7)&1)); C_3_7 = S_2_8&(((A>>3)&1) & ((B>>7)&1)); S_3_8 = S_2_9^(((A>>3)&1) & ((B>>8)&1)); C_3_8 = S_2_9&(((A>>3)&1) & ((B>>8)&1)); S_3_9 = S_2_10^(((A>>3)&1) & ((B>>9)&1)); C_3_9 = S_2_10&(((A>>3)&1) & ((B>>9)&1)); S_3_10 = S_2_11^(((A>>3)&1) & ((B>>10)&1)); C_3_10 = S_2_11&(((A>>3)&1) & ((B>>10)&1)); S_3_11 = S_2_12^(((A>>3)&1) & ((B>>11)&1)); C_3_11 = S_2_12&(((A>>3)&1) & ((B>>11)&1)); S_3_12 = S_2_13^(((A>>3)&1) & ((B>>12)&1)); C_3_12 = S_2_13&(((A>>3)&1) & ((B>>12)&1)); tmp = S_2_14^C_2_13; S_3_13 = tmp^(((A>>3)&1) & ((B>>13)&1)); C_3_13 = (tmp&(((A>>3)&1) & ((B>>13)&1)))|(S_2_14&C_2_13); S_3_14 = S_2_15^(((A>>3)&1) & ((B>>14)&1)); C_3_14 = S_2_15&(((A>>3)&1) & ((B>>14)&1)); S_3_15 = C_2_15^(((((A>>3)&1) & ((B>>15)&1)))^1); C_3_15 = C_2_15&(((((A>>3)&1) & ((B>>15)&1)))^1); S_4_1 = S_3_2^(((A>>4)&1) & ((B>>1)&1)); C_4_1 = S_3_2&(((A>>4)&1) & ((B>>1)&1)); tmp = S_3_3^C_3_2; S_4_2 = tmp^(((A>>4)&1) & ((B>>2)&1)); C_4_2 = (tmp&(((A>>4)&1) & ((B>>2)&1)))|(S_3_3&C_3_2); tmp = S_3_4^C_3_3; S_4_3 = tmp^(((A>>4)&1) & ((B>>3)&1)); C_4_3 = (tmp&(((A>>4)&1) & ((B>>3)&1)))|(S_3_4&C_3_3); tmp = S_3_5^C_3_4; S_4_4 = tmp^(((A>>4)&1) & ((B>>4)&1)); C_4_4 = (tmp&(((A>>4)&1) & ((B>>4)&1)))|(S_3_5&C_3_4); tmp = S_3_6^C_3_5; S_4_5 = tmp^(((A>>4)&1) & ((B>>5)&1)); C_4_5 = (tmp&(((A>>4)&1) & ((B>>5)&1)))|(S_3_6&C_3_5); tmp = S_3_7^C_3_6; S_4_6 = tmp^(((A>>4)&1) & ((B>>6)&1)); C_4_6 = (tmp&(((A>>4)&1) & ((B>>6)&1)))|(S_3_7&C_3_6); tmp = S_3_8^C_3_7; S_4_7 = tmp^(((A>>4)&1) & ((B>>7)&1)); C_4_7 = (tmp&(((A>>4)&1) & ((B>>7)&1)))|(S_3_8&C_3_7); tmp = S_3_9^C_3_8; S_4_8 = tmp^(((A>>4)&1) & ((B>>8)&1)); C_4_8 = (tmp&(((A>>4)&1) & ((B>>8)&1)))|(S_3_9&C_3_8); tmp = S_3_10^C_3_9; S_4_9 = tmp^(((A>>4)&1) & ((B>>9)&1)); C_4_9 = (tmp&(((A>>4)&1) & ((B>>9)&1)))|(S_3_10&C_3_9); tmp = S_3_11^C_3_10; S_4_10 = tmp^(((A>>4)&1) & ((B>>10)&1)); C_4_10 = (tmp&(((A>>4)&1) & ((B>>10)&1)))|(S_3_11&C_3_10); tmp = S_3_12^C_3_11; S_4_11 = tmp^(((A>>4)&1) & ((B>>11)&1)); C_4_11 = (tmp&(((A>>4)&1) & ((B>>11)&1)))|(S_3_12&C_3_11); tmp = S_3_13^C_3_12; S_4_12 = tmp^(((A>>4)&1) & ((B>>12)&1)); C_4_12 = (tmp&(((A>>4)&1) & ((B>>12)&1)))|(S_3_13&C_3_12); tmp = S_3_14^C_3_13; S_4_13 = tmp^(((A>>4)&1) & ((B>>13)&1)); C_4_13 = (tmp&(((A>>4)&1) & ((B>>13)&1)))|(S_3_14&C_3_13); tmp = S_3_15^C_3_14; S_4_14 = tmp^(((A>>4)&1) & ((B>>14)&1)); C_4_14 = (tmp&(((A>>4)&1) & ((B>>14)&1)))|(S_3_15&C_3_14); S_4_15 = C_3_15^(((((A>>4)&1) & ((B>>15)&1)))^1); C_4_15 = C_3_15&(((((A>>4)&1) & ((B>>15)&1)))^1); S_5_0 = S_4_1^(((A>>5)&1) & ((B>>0)&1)); C_5_0 = S_4_1&(((A>>5)&1) & ((B>>0)&1)); tmp = S_4_2^C_4_1; S_5_1 = tmp^(((A>>5)&1) & ((B>>1)&1)); C_5_1 = (tmp&(((A>>5)&1) & ((B>>1)&1)))|(S_4_2&C_4_1); tmp = S_4_3^C_4_2; S_5_2 = tmp^(((A>>5)&1) & ((B>>2)&1)); C_5_2 = (tmp&(((A>>5)&1) & ((B>>2)&1)))|(S_4_3&C_4_2); tmp = S_4_4^C_4_3; S_5_3 = tmp^(((A>>5)&1) & ((B>>3)&1)); C_5_3 = (tmp&(((A>>5)&1) & ((B>>3)&1)))|(S_4_4&C_4_3); tmp = S_4_5^C_4_4; S_5_4 = tmp^(((A>>5)&1) & ((B>>4)&1)); C_5_4 = (tmp&(((A>>5)&1) & ((B>>4)&1)))|(S_4_5&C_4_4); tmp = S_4_6^C_4_5; S_5_5 = tmp^(((A>>5)&1) & ((B>>5)&1)); C_5_5 = (tmp&(((A>>5)&1) & ((B>>5)&1)))|(S_4_6&C_4_5); tmp = S_4_7^C_4_6; S_5_6 = tmp^(((A>>5)&1) & ((B>>6)&1)); C_5_6 = (tmp&(((A>>5)&1) & ((B>>6)&1)))|(S_4_7&C_4_6); tmp = S_4_8^C_4_7; S_5_7 = tmp^(((A>>5)&1) & ((B>>7)&1)); C_5_7 = (tmp&(((A>>5)&1) & ((B>>7)&1)))|(S_4_8&C_4_7); tmp = S_4_9^C_4_8; S_5_8 = tmp^(((A>>5)&1) & ((B>>8)&1)); C_5_8 = (tmp&(((A>>5)&1) & ((B>>8)&1)))|(S_4_9&C_4_8); tmp = S_4_10^C_4_9; S_5_9 = tmp^(((A>>5)&1) & ((B>>9)&1)); C_5_9 = (tmp&(((A>>5)&1) & ((B>>9)&1)))|(S_4_10&C_4_9); tmp = S_4_11^C_4_10; S_5_10 = tmp^(((A>>5)&1) & ((B>>10)&1)); C_5_10 = (tmp&(((A>>5)&1) & ((B>>10)&1)))|(S_4_11&C_4_10); tmp = S_4_12^C_4_11; S_5_11 = tmp^(((A>>5)&1) & ((B>>11)&1)); C_5_11 = (tmp&(((A>>5)&1) & ((B>>11)&1)))|(S_4_12&C_4_11); tmp = S_4_13^C_4_12; S_5_12 = tmp^(((A>>5)&1) & ((B>>12)&1)); C_5_12 = (tmp&(((A>>5)&1) & ((B>>12)&1)))|(S_4_13&C_4_12); tmp = S_4_14^C_4_13; S_5_13 = tmp^(((A>>5)&1) & ((B>>13)&1)); C_5_13 = (tmp&(((A>>5)&1) & ((B>>13)&1)))|(S_4_14&C_4_13); tmp = S_4_15^C_4_14; S_5_14 = tmp^(((A>>5)&1) & ((B>>14)&1)); C_5_14 = (tmp&(((A>>5)&1) & ((B>>14)&1)))|(S_4_15&C_4_14); S_5_15 = C_4_15^(((((A>>5)&1) & ((B>>15)&1)))^1); C_5_15 = C_4_15&(((((A>>5)&1) & ((B>>15)&1)))^1); tmp = S_5_1^C_5_0; S_6_0 = tmp^(((A>>6)&1) & ((B>>0)&1)); C_6_0 = (tmp&(((A>>6)&1) & ((B>>0)&1)))|(S_5_1&C_5_0); tmp = S_5_2^C_5_1; S_6_1 = tmp^(((A>>6)&1) & ((B>>1)&1)); C_6_1 = (tmp&(((A>>6)&1) & ((B>>1)&1)))|(S_5_2&C_5_1); tmp = S_5_3^C_5_2; S_6_2 = tmp^(((A>>6)&1) & ((B>>2)&1)); C_6_2 = (tmp&(((A>>6)&1) & ((B>>2)&1)))|(S_5_3&C_5_2); tmp = S_5_4^C_5_3; S_6_3 = tmp^(((A>>6)&1) & ((B>>3)&1)); C_6_3 = (tmp&(((A>>6)&1) & ((B>>3)&1)))|(S_5_4&C_5_3); tmp = S_5_5^C_5_4; S_6_4 = tmp^(((A>>6)&1) & ((B>>4)&1)); C_6_4 = (tmp&(((A>>6)&1) & ((B>>4)&1)))|(S_5_5&C_5_4); tmp = S_5_6^C_5_5; S_6_5 = tmp^(((A>>6)&1) & ((B>>5)&1)); C_6_5 = (tmp&(((A>>6)&1) & ((B>>5)&1)))|(S_5_6&C_5_5); tmp = S_5_7^C_5_6; S_6_6 = tmp^(((A>>6)&1) & ((B>>6)&1)); C_6_6 = (tmp&(((A>>6)&1) & ((B>>6)&1)))|(S_5_7&C_5_6); tmp = S_5_8^C_5_7; S_6_7 = tmp^(((A>>6)&1) & ((B>>7)&1)); C_6_7 = (tmp&(((A>>6)&1) & ((B>>7)&1)))|(S_5_8&C_5_7); tmp = S_5_9^C_5_8; S_6_8 = tmp^(((A>>6)&1) & ((B>>8)&1)); C_6_8 = (tmp&(((A>>6)&1) & ((B>>8)&1)))|(S_5_9&C_5_8); tmp = S_5_10^C_5_9; S_6_9 = tmp^(((A>>6)&1) & ((B>>9)&1)); C_6_9 = (tmp&(((A>>6)&1) & ((B>>9)&1)))|(S_5_10&C_5_9); tmp = S_5_11^C_5_10; S_6_10 = tmp^(((A>>6)&1) & ((B>>10)&1)); C_6_10 = (tmp&(((A>>6)&1) & ((B>>10)&1)))|(S_5_11&C_5_10); tmp = S_5_12^C_5_11; S_6_11 = tmp^(((A>>6)&1) & ((B>>11)&1)); C_6_11 = (tmp&(((A>>6)&1) & ((B>>11)&1)))|(S_5_12&C_5_11); tmp = S_5_13^C_5_12; S_6_12 = tmp^(((A>>6)&1) & ((B>>12)&1)); C_6_12 = (tmp&(((A>>6)&1) & ((B>>12)&1)))|(S_5_13&C_5_12); tmp = S_5_14^C_5_13; S_6_13 = tmp^(((A>>6)&1) & ((B>>13)&1)); C_6_13 = (tmp&(((A>>6)&1) & ((B>>13)&1)))|(S_5_14&C_5_13); tmp = S_5_15^C_5_14; S_6_14 = tmp^(((A>>6)&1) & ((B>>14)&1)); C_6_14 = (tmp&(((A>>6)&1) & ((B>>14)&1)))|(S_5_15&C_5_14); S_6_15 = C_5_15^(((((A>>6)&1) & ((B>>15)&1)))^1); C_6_15 = C_5_15&(((((A>>6)&1) & ((B>>15)&1)))^1); tmp = S_6_1^C_6_0; S_7_0 = tmp^(((A>>7)&1) & ((B>>0)&1)); C_7_0 = (tmp&(((A>>7)&1) & ((B>>0)&1)))|(S_6_1&C_6_0); tmp = S_6_2^C_6_1; S_7_1 = tmp^(((A>>7)&1) & ((B>>1)&1)); C_7_1 = (tmp&(((A>>7)&1) & ((B>>1)&1)))|(S_6_2&C_6_1); tmp = S_6_3^C_6_2; S_7_2 = tmp^(((A>>7)&1) & ((B>>2)&1)); C_7_2 = (tmp&(((A>>7)&1) & ((B>>2)&1)))|(S_6_3&C_6_2); tmp = S_6_4^C_6_3; S_7_3 = tmp^(((A>>7)&1) & ((B>>3)&1)); C_7_3 = (tmp&(((A>>7)&1) & ((B>>3)&1)))|(S_6_4&C_6_3); tmp = S_6_5^C_6_4; S_7_4 = tmp^(((A>>7)&1) & ((B>>4)&1)); C_7_4 = (tmp&(((A>>7)&1) & ((B>>4)&1)))|(S_6_5&C_6_4); tmp = S_6_6^C_6_5; S_7_5 = tmp^(((A>>7)&1) & ((B>>5)&1)); C_7_5 = (tmp&(((A>>7)&1) & ((B>>5)&1)))|(S_6_6&C_6_5); tmp = S_6_7^C_6_6; S_7_6 = tmp^(((A>>7)&1) & ((B>>6)&1)); C_7_6 = (tmp&(((A>>7)&1) & ((B>>6)&1)))|(S_6_7&C_6_6); tmp = S_6_8^C_6_7; S_7_7 = tmp^(((A>>7)&1) & ((B>>7)&1)); C_7_7 = (tmp&(((A>>7)&1) & ((B>>7)&1)))|(S_6_8&C_6_7); tmp = S_6_9^C_6_8; S_7_8 = tmp^(((A>>7)&1) & ((B>>8)&1)); C_7_8 = (tmp&(((A>>7)&1) & ((B>>8)&1)))|(S_6_9&C_6_8); tmp = S_6_10^C_6_9; S_7_9 = tmp^(((A>>7)&1) & ((B>>9)&1)); C_7_9 = (tmp&(((A>>7)&1) & ((B>>9)&1)))|(S_6_10&C_6_9); tmp = S_6_11^C_6_10; S_7_10 = tmp^(((A>>7)&1) & ((B>>10)&1)); C_7_10 = (tmp&(((A>>7)&1) & ((B>>10)&1)))|(S_6_11&C_6_10); tmp = S_6_12^C_6_11; S_7_11 = tmp^(((A>>7)&1) & ((B>>11)&1)); C_7_11 = (tmp&(((A>>7)&1) & ((B>>11)&1)))|(S_6_12&C_6_11); tmp = S_6_13^C_6_12; S_7_12 = tmp^(((A>>7)&1) & ((B>>12)&1)); C_7_12 = (tmp&(((A>>7)&1) & ((B>>12)&1)))|(S_6_13&C_6_12); tmp = S_6_14^C_6_13; S_7_13 = tmp^(((A>>7)&1) & ((B>>13)&1)); C_7_13 = (tmp&(((A>>7)&1) & ((B>>13)&1)))|(S_6_14&C_6_13); tmp = S_6_15^C_6_14; S_7_14 = tmp^(((A>>7)&1) & ((B>>14)&1)); C_7_14 = (tmp&(((A>>7)&1) & ((B>>14)&1)))|(S_6_15&C_6_14); S_7_15 = C_6_15^(((((A>>7)&1) & ((B>>15)&1)))^1); C_7_15 = C_6_15&(((((A>>7)&1) & ((B>>15)&1)))^1); tmp = S_7_1^C_7_0; S_8_0 = tmp^(((A>>8)&1) & ((B>>0)&1)); C_8_0 = (tmp&(((A>>8)&1) & ((B>>0)&1)))|(S_7_1&C_7_0); tmp = S_7_2^C_7_1; S_8_1 = tmp^(((A>>8)&1) & ((B>>1)&1)); C_8_1 = (tmp&(((A>>8)&1) & ((B>>1)&1)))|(S_7_2&C_7_1); tmp = S_7_3^C_7_2; S_8_2 = tmp^(((A>>8)&1) & ((B>>2)&1)); C_8_2 = (tmp&(((A>>8)&1) & ((B>>2)&1)))|(S_7_3&C_7_2); tmp = S_7_4^C_7_3; S_8_3 = tmp^(((A>>8)&1) & ((B>>3)&1)); C_8_3 = (tmp&(((A>>8)&1) & ((B>>3)&1)))|(S_7_4&C_7_3); tmp = S_7_5^C_7_4; S_8_4 = tmp^(((A>>8)&1) & ((B>>4)&1)); C_8_4 = (tmp&(((A>>8)&1) & ((B>>4)&1)))|(S_7_5&C_7_4); tmp = S_7_6^C_7_5; S_8_5 = tmp^(((A>>8)&1) & ((B>>5)&1)); C_8_5 = (tmp&(((A>>8)&1) & ((B>>5)&1)))|(S_7_6&C_7_5); tmp = S_7_7^C_7_6; S_8_6 = tmp^(((A>>8)&1) & ((B>>6)&1)); C_8_6 = (tmp&(((A>>8)&1) & ((B>>6)&1)))|(S_7_7&C_7_6); tmp = S_7_8^C_7_7; S_8_7 = tmp^(((A>>8)&1) & ((B>>7)&1)); C_8_7 = (tmp&(((A>>8)&1) & ((B>>7)&1)))|(S_7_8&C_7_7); tmp = S_7_9^C_7_8; S_8_8 = tmp^(((A>>8)&1) & ((B>>8)&1)); C_8_8 = (tmp&(((A>>8)&1) & ((B>>8)&1)))|(S_7_9&C_7_8); tmp = S_7_10^C_7_9; S_8_9 = tmp^(((A>>8)&1) & ((B>>9)&1)); C_8_9 = (tmp&(((A>>8)&1) & ((B>>9)&1)))|(S_7_10&C_7_9); tmp = S_7_11^C_7_10; S_8_10 = tmp^(((A>>8)&1) & ((B>>10)&1)); C_8_10 = (tmp&(((A>>8)&1) & ((B>>10)&1)))|(S_7_11&C_7_10); tmp = S_7_12^C_7_11; S_8_11 = tmp^(((A>>8)&1) & ((B>>11)&1)); C_8_11 = (tmp&(((A>>8)&1) & ((B>>11)&1)))|(S_7_12&C_7_11); tmp = S_7_13^C_7_12; S_8_12 = tmp^(((A>>8)&1) & ((B>>12)&1)); C_8_12 = (tmp&(((A>>8)&1) & ((B>>12)&1)))|(S_7_13&C_7_12); tmp = S_7_14^C_7_13; S_8_13 = tmp^(((A>>8)&1) & ((B>>13)&1)); C_8_13 = (tmp&(((A>>8)&1) & ((B>>13)&1)))|(S_7_14&C_7_13); tmp = S_7_15^C_7_14; S_8_14 = tmp^(((A>>8)&1) & ((B>>14)&1)); C_8_14 = (tmp&(((A>>8)&1) & ((B>>14)&1)))|(S_7_15&C_7_14); S_8_15 = C_7_15^(((((A>>8)&1) & ((B>>15)&1)))^1); C_8_15 = C_7_15&(((((A>>8)&1) & ((B>>15)&1)))^1); tmp = S_8_1^C_8_0; S_9_0 = tmp^(((A>>9)&1) & ((B>>0)&1)); C_9_0 = (tmp&(((A>>9)&1) & ((B>>0)&1)))|(S_8_1&C_8_0); tmp = S_8_2^C_8_1; S_9_1 = tmp^(((A>>9)&1) & ((B>>1)&1)); C_9_1 = (tmp&(((A>>9)&1) & ((B>>1)&1)))|(S_8_2&C_8_1); tmp = S_8_3^C_8_2; S_9_2 = tmp^(((A>>9)&1) & ((B>>2)&1)); C_9_2 = (tmp&(((A>>9)&1) & ((B>>2)&1)))|(S_8_3&C_8_2); tmp = S_8_4^C_8_3; S_9_3 = tmp^(((A>>9)&1) & ((B>>3)&1)); C_9_3 = (tmp&(((A>>9)&1) & ((B>>3)&1)))|(S_8_4&C_8_3); tmp = S_8_5^C_8_4; S_9_4 = tmp^(((A>>9)&1) & ((B>>4)&1)); C_9_4 = (tmp&(((A>>9)&1) & ((B>>4)&1)))|(S_8_5&C_8_4); tmp = S_8_6^C_8_5; S_9_5 = tmp^(((A>>9)&1) & ((B>>5)&1)); C_9_5 = (tmp&(((A>>9)&1) & ((B>>5)&1)))|(S_8_6&C_8_5); tmp = S_8_7^C_8_6; S_9_6 = tmp^(((A>>9)&1) & ((B>>6)&1)); C_9_6 = (tmp&(((A>>9)&1) & ((B>>6)&1)))|(S_8_7&C_8_6); tmp = S_8_8^C_8_7; S_9_7 = tmp^(((A>>9)&1) & ((B>>7)&1)); C_9_7 = (tmp&(((A>>9)&1) & ((B>>7)&1)))|(S_8_8&C_8_7); tmp = S_8_9^C_8_8; S_9_8 = tmp^(((A>>9)&1) & ((B>>8)&1)); C_9_8 = (tmp&(((A>>9)&1) & ((B>>8)&1)))|(S_8_9&C_8_8); tmp = S_8_10^C_8_9; S_9_9 = tmp^(((A>>9)&1) & ((B>>9)&1)); C_9_9 = (tmp&(((A>>9)&1) & ((B>>9)&1)))|(S_8_10&C_8_9); tmp = S_8_11^C_8_10; S_9_10 = tmp^(((A>>9)&1) & ((B>>10)&1)); C_9_10 = (tmp&(((A>>9)&1) & ((B>>10)&1)))|(S_8_11&C_8_10); tmp = S_8_12^C_8_11; S_9_11 = tmp^(((A>>9)&1) & ((B>>11)&1)); C_9_11 = (tmp&(((A>>9)&1) & ((B>>11)&1)))|(S_8_12&C_8_11); tmp = S_8_13^C_8_12; S_9_12 = tmp^(((A>>9)&1) & ((B>>12)&1)); C_9_12 = (tmp&(((A>>9)&1) & ((B>>12)&1)))|(S_8_13&C_8_12); tmp = S_8_14^C_8_13; S_9_13 = tmp^(((A>>9)&1) & ((B>>13)&1)); C_9_13 = (tmp&(((A>>9)&1) & ((B>>13)&1)))|(S_8_14&C_8_13); tmp = S_8_15^C_8_14; S_9_14 = tmp^(((A>>9)&1) & ((B>>14)&1)); C_9_14 = (tmp&(((A>>9)&1) & ((B>>14)&1)))|(S_8_15&C_8_14); S_9_15 = C_8_15^(((((A>>9)&1) & ((B>>15)&1)))^1); C_9_15 = C_8_15&(((((A>>9)&1) & ((B>>15)&1)))^1); tmp = S_9_1^C_9_0; S_10_0 = tmp^(((A>>10)&1) & ((B>>0)&1)); C_10_0 = (tmp&(((A>>10)&1) & ((B>>0)&1)))|(S_9_1&C_9_0); tmp = S_9_2^C_9_1; S_10_1 = tmp^(((A>>10)&1) & ((B>>1)&1)); C_10_1 = (tmp&(((A>>10)&1) & ((B>>1)&1)))|(S_9_2&C_9_1); tmp = S_9_3^C_9_2; S_10_2 = tmp^(((A>>10)&1) & ((B>>2)&1)); C_10_2 = (tmp&(((A>>10)&1) & ((B>>2)&1)))|(S_9_3&C_9_2); tmp = S_9_4^C_9_3; S_10_3 = tmp^(((A>>10)&1) & ((B>>3)&1)); C_10_3 = (tmp&(((A>>10)&1) & ((B>>3)&1)))|(S_9_4&C_9_3); tmp = S_9_5^C_9_4; S_10_4 = tmp^(((A>>10)&1) & ((B>>4)&1)); C_10_4 = (tmp&(((A>>10)&1) & ((B>>4)&1)))|(S_9_5&C_9_4); tmp = S_9_6^C_9_5; S_10_5 = tmp^(((A>>10)&1) & ((B>>5)&1)); C_10_5 = (tmp&(((A>>10)&1) & ((B>>5)&1)))|(S_9_6&C_9_5); tmp = S_9_7^C_9_6; S_10_6 = tmp^(((A>>10)&1) & ((B>>6)&1)); C_10_6 = (tmp&(((A>>10)&1) & ((B>>6)&1)))|(S_9_7&C_9_6); tmp = S_9_8^C_9_7; S_10_7 = tmp^(((A>>10)&1) & ((B>>7)&1)); C_10_7 = (tmp&(((A>>10)&1) & ((B>>7)&1)))|(S_9_8&C_9_7); tmp = S_9_9^C_9_8; S_10_8 = tmp^(((A>>10)&1) & ((B>>8)&1)); C_10_8 = (tmp&(((A>>10)&1) & ((B>>8)&1)))|(S_9_9&C_9_8); tmp = S_9_10^C_9_9; S_10_9 = tmp^(((A>>10)&1) & ((B>>9)&1)); C_10_9 = (tmp&(((A>>10)&1) & ((B>>9)&1)))|(S_9_10&C_9_9); tmp = S_9_11^C_9_10; S_10_10 = tmp^(((A>>10)&1) & ((B>>10)&1)); C_10_10 = (tmp&(((A>>10)&1) & ((B>>10)&1)))|(S_9_11&C_9_10); tmp = S_9_12^C_9_11; S_10_11 = tmp^(((A>>10)&1) & ((B>>11)&1)); C_10_11 = (tmp&(((A>>10)&1) & ((B>>11)&1)))|(S_9_12&C_9_11); tmp = S_9_13^C_9_12; S_10_12 = tmp^(((A>>10)&1) & ((B>>12)&1)); C_10_12 = (tmp&(((A>>10)&1) & ((B>>12)&1)))|(S_9_13&C_9_12); tmp = S_9_14^C_9_13; S_10_13 = tmp^(((A>>10)&1) & ((B>>13)&1)); C_10_13 = (tmp&(((A>>10)&1) & ((B>>13)&1)))|(S_9_14&C_9_13); tmp = S_9_15^C_9_14; S_10_14 = tmp^(((A>>10)&1) & ((B>>14)&1)); C_10_14 = (tmp&(((A>>10)&1) & ((B>>14)&1)))|(S_9_15&C_9_14); S_10_15 = C_9_15^(((((A>>10)&1) & ((B>>15)&1)))^1); C_10_15 = C_9_15&(((((A>>10)&1) & ((B>>15)&1)))^1); tmp = S_10_1^C_10_0; S_11_0 = tmp^(((A>>11)&1) & ((B>>0)&1)); C_11_0 = (tmp&(((A>>11)&1) & ((B>>0)&1)))|(S_10_1&C_10_0); tmp = S_10_2^C_10_1; S_11_1 = tmp^(((A>>11)&1) & ((B>>1)&1)); C_11_1 = (tmp&(((A>>11)&1) & ((B>>1)&1)))|(S_10_2&C_10_1); tmp = S_10_3^C_10_2; S_11_2 = tmp^(((A>>11)&1) & ((B>>2)&1)); C_11_2 = (tmp&(((A>>11)&1) & ((B>>2)&1)))|(S_10_3&C_10_2); tmp = S_10_4^C_10_3; S_11_3 = tmp^(((A>>11)&1) & ((B>>3)&1)); C_11_3 = (tmp&(((A>>11)&1) & ((B>>3)&1)))|(S_10_4&C_10_3); tmp = S_10_5^C_10_4; S_11_4 = tmp^(((A>>11)&1) & ((B>>4)&1)); C_11_4 = (tmp&(((A>>11)&1) & ((B>>4)&1)))|(S_10_5&C_10_4); tmp = S_10_6^C_10_5; S_11_5 = tmp^(((A>>11)&1) & ((B>>5)&1)); C_11_5 = (tmp&(((A>>11)&1) & ((B>>5)&1)))|(S_10_6&C_10_5); tmp = S_10_7^C_10_6; S_11_6 = tmp^(((A>>11)&1) & ((B>>6)&1)); C_11_6 = (tmp&(((A>>11)&1) & ((B>>6)&1)))|(S_10_7&C_10_6); tmp = S_10_8^C_10_7; S_11_7 = tmp^(((A>>11)&1) & ((B>>7)&1)); C_11_7 = (tmp&(((A>>11)&1) & ((B>>7)&1)))|(S_10_8&C_10_7); tmp = S_10_9^C_10_8; S_11_8 = tmp^(((A>>11)&1) & ((B>>8)&1)); C_11_8 = (tmp&(((A>>11)&1) & ((B>>8)&1)))|(S_10_9&C_10_8); tmp = S_10_10^C_10_9; S_11_9 = tmp^(((A>>11)&1) & ((B>>9)&1)); C_11_9 = (tmp&(((A>>11)&1) & ((B>>9)&1)))|(S_10_10&C_10_9); tmp = S_10_11^C_10_10; S_11_10 = tmp^(((A>>11)&1) & ((B>>10)&1)); C_11_10 = (tmp&(((A>>11)&1) & ((B>>10)&1)))|(S_10_11&C_10_10); tmp = S_10_12^C_10_11; S_11_11 = tmp^(((A>>11)&1) & ((B>>11)&1)); C_11_11 = (tmp&(((A>>11)&1) & ((B>>11)&1)))|(S_10_12&C_10_11); tmp = S_10_13^C_10_12; S_11_12 = tmp^(((A>>11)&1) & ((B>>12)&1)); C_11_12 = (tmp&(((A>>11)&1) & ((B>>12)&1)))|(S_10_13&C_10_12); tmp = S_10_14^C_10_13; S_11_13 = tmp^(((A>>11)&1) & ((B>>13)&1)); C_11_13 = (tmp&(((A>>11)&1) & ((B>>13)&1)))|(S_10_14&C_10_13); tmp = S_10_15^C_10_14; S_11_14 = tmp^(((A>>11)&1) & ((B>>14)&1)); C_11_14 = (tmp&(((A>>11)&1) & ((B>>14)&1)))|(S_10_15&C_10_14); S_11_15 = C_10_15^(((((A>>11)&1) & ((B>>15)&1)))^1); C_11_15 = C_10_15&(((((A>>11)&1) & ((B>>15)&1)))^1); tmp = S_11_1^C_11_0; S_12_0 = tmp^(((A>>12)&1) & ((B>>0)&1)); C_12_0 = (tmp&(((A>>12)&1) & ((B>>0)&1)))|(S_11_1&C_11_0); tmp = S_11_2^C_11_1; S_12_1 = tmp^(((A>>12)&1) & ((B>>1)&1)); C_12_1 = (tmp&(((A>>12)&1) & ((B>>1)&1)))|(S_11_2&C_11_1); tmp = S_11_3^C_11_2; S_12_2 = tmp^(((A>>12)&1) & ((B>>2)&1)); C_12_2 = (tmp&(((A>>12)&1) & ((B>>2)&1)))|(S_11_3&C_11_2); tmp = S_11_4^C_11_3; S_12_3 = tmp^(((A>>12)&1) & ((B>>3)&1)); C_12_3 = (tmp&(((A>>12)&1) & ((B>>3)&1)))|(S_11_4&C_11_3); tmp = S_11_5^C_11_4; S_12_4 = tmp^(((A>>12)&1) & ((B>>4)&1)); C_12_4 = (tmp&(((A>>12)&1) & ((B>>4)&1)))|(S_11_5&C_11_4); tmp = S_11_6^C_11_5; S_12_5 = tmp^(((A>>12)&1) & ((B>>5)&1)); C_12_5 = (tmp&(((A>>12)&1) & ((B>>5)&1)))|(S_11_6&C_11_5); tmp = S_11_7^C_11_6; S_12_6 = tmp^(((A>>12)&1) & ((B>>6)&1)); C_12_6 = (tmp&(((A>>12)&1) & ((B>>6)&1)))|(S_11_7&C_11_6); tmp = S_11_8^C_11_7; S_12_7 = tmp^(((A>>12)&1) & ((B>>7)&1)); C_12_7 = (tmp&(((A>>12)&1) & ((B>>7)&1)))|(S_11_8&C_11_7); tmp = S_11_9^C_11_8; S_12_8 = tmp^(((A>>12)&1) & ((B>>8)&1)); C_12_8 = (tmp&(((A>>12)&1) & ((B>>8)&1)))|(S_11_9&C_11_8); tmp = S_11_10^C_11_9; S_12_9 = tmp^(((A>>12)&1) & ((B>>9)&1)); C_12_9 = (tmp&(((A>>12)&1) & ((B>>9)&1)))|(S_11_10&C_11_9); tmp = S_11_11^C_11_10; S_12_10 = tmp^(((A>>12)&1) & ((B>>10)&1)); C_12_10 = (tmp&(((A>>12)&1) & ((B>>10)&1)))|(S_11_11&C_11_10); tmp = S_11_12^C_11_11; S_12_11 = tmp^(((A>>12)&1) & ((B>>11)&1)); C_12_11 = (tmp&(((A>>12)&1) & ((B>>11)&1)))|(S_11_12&C_11_11); tmp = S_11_13^C_11_12; S_12_12 = tmp^(((A>>12)&1) & ((B>>12)&1)); C_12_12 = (tmp&(((A>>12)&1) & ((B>>12)&1)))|(S_11_13&C_11_12); tmp = S_11_14^C_11_13; S_12_13 = tmp^(((A>>12)&1) & ((B>>13)&1)); C_12_13 = (tmp&(((A>>12)&1) & ((B>>13)&1)))|(S_11_14&C_11_13); tmp = S_11_15^C_11_14; S_12_14 = tmp^(((A>>12)&1) & ((B>>14)&1)); C_12_14 = (tmp&(((A>>12)&1) & ((B>>14)&1)))|(S_11_15&C_11_14); S_12_15 = C_11_15^(((((A>>12)&1) & ((B>>15)&1)))^1); C_12_15 = C_11_15&(((((A>>12)&1) & ((B>>15)&1)))^1); tmp = S_12_1^C_12_0; S_13_0 = tmp^(((A>>13)&1) & ((B>>0)&1)); C_13_0 = (tmp&(((A>>13)&1) & ((B>>0)&1)))|(S_12_1&C_12_0); tmp = S_12_2^C_12_1; S_13_1 = tmp^(((A>>13)&1) & ((B>>1)&1)); C_13_1 = (tmp&(((A>>13)&1) & ((B>>1)&1)))|(S_12_2&C_12_1); tmp = S_12_3^C_12_2; S_13_2 = tmp^(((A>>13)&1) & ((B>>2)&1)); C_13_2 = (tmp&(((A>>13)&1) & ((B>>2)&1)))|(S_12_3&C_12_2); tmp = S_12_4^C_12_3; S_13_3 = tmp^(((A>>13)&1) & ((B>>3)&1)); C_13_3 = (tmp&(((A>>13)&1) & ((B>>3)&1)))|(S_12_4&C_12_3); tmp = S_12_5^C_12_4; S_13_4 = tmp^(((A>>13)&1) & ((B>>4)&1)); C_13_4 = (tmp&(((A>>13)&1) & ((B>>4)&1)))|(S_12_5&C_12_4); tmp = S_12_6^C_12_5; S_13_5 = tmp^(((A>>13)&1) & ((B>>5)&1)); C_13_5 = (tmp&(((A>>13)&1) & ((B>>5)&1)))|(S_12_6&C_12_5); tmp = S_12_7^C_12_6; S_13_6 = tmp^(((A>>13)&1) & ((B>>6)&1)); C_13_6 = (tmp&(((A>>13)&1) & ((B>>6)&1)))|(S_12_7&C_12_6); tmp = S_12_8^C_12_7; S_13_7 = tmp^(((A>>13)&1) & ((B>>7)&1)); C_13_7 = (tmp&(((A>>13)&1) & ((B>>7)&1)))|(S_12_8&C_12_7); tmp = S_12_9^C_12_8; S_13_8 = tmp^(((A>>13)&1) & ((B>>8)&1)); C_13_8 = (tmp&(((A>>13)&1) & ((B>>8)&1)))|(S_12_9&C_12_8); tmp = S_12_10^C_12_9; S_13_9 = tmp^(((A>>13)&1) & ((B>>9)&1)); C_13_9 = (tmp&(((A>>13)&1) & ((B>>9)&1)))|(S_12_10&C_12_9); tmp = S_12_11^C_12_10; S_13_10 = tmp^(((A>>13)&1) & ((B>>10)&1)); C_13_10 = (tmp&(((A>>13)&1) & ((B>>10)&1)))|(S_12_11&C_12_10); tmp = S_12_12^C_12_11; S_13_11 = tmp^(((A>>13)&1) & ((B>>11)&1)); C_13_11 = (tmp&(((A>>13)&1) & ((B>>11)&1)))|(S_12_12&C_12_11); tmp = S_12_13^C_12_12; S_13_12 = tmp^(((A>>13)&1) & ((B>>12)&1)); C_13_12 = (tmp&(((A>>13)&1) & ((B>>12)&1)))|(S_12_13&C_12_12); tmp = S_12_14^C_12_13; S_13_13 = tmp^(((A>>13)&1) & ((B>>13)&1)); C_13_13 = (tmp&(((A>>13)&1) & ((B>>13)&1)))|(S_12_14&C_12_13); tmp = S_12_15^C_12_14; S_13_14 = tmp^(((A>>13)&1) & ((B>>14)&1)); C_13_14 = (tmp&(((A>>13)&1) & ((B>>14)&1)))|(S_12_15&C_12_14); S_13_15 = C_12_15^(((((A>>13)&1) & ((B>>15)&1)))^1); C_13_15 = C_12_15&(((((A>>13)&1) & ((B>>15)&1)))^1); tmp = S_13_1^C_13_0; S_14_0 = tmp^(((A>>14)&1) & ((B>>0)&1)); C_14_0 = (tmp&(((A>>14)&1) & ((B>>0)&1)))|(S_13_1&C_13_0); tmp = S_13_2^C_13_1; S_14_1 = tmp^(((A>>14)&1) & ((B>>1)&1)); C_14_1 = (tmp&(((A>>14)&1) & ((B>>1)&1)))|(S_13_2&C_13_1); tmp = S_13_3^C_13_2; S_14_2 = tmp^(((A>>14)&1) & ((B>>2)&1)); C_14_2 = (tmp&(((A>>14)&1) & ((B>>2)&1)))|(S_13_3&C_13_2); tmp = S_13_4^C_13_3; S_14_3 = tmp^(((A>>14)&1) & ((B>>3)&1)); C_14_3 = (tmp&(((A>>14)&1) & ((B>>3)&1)))|(S_13_4&C_13_3); tmp = S_13_5^C_13_4; S_14_4 = tmp^(((A>>14)&1) & ((B>>4)&1)); C_14_4 = (tmp&(((A>>14)&1) & ((B>>4)&1)))|(S_13_5&C_13_4); tmp = S_13_6^C_13_5; S_14_5 = tmp^(((A>>14)&1) & ((B>>5)&1)); C_14_5 = (tmp&(((A>>14)&1) & ((B>>5)&1)))|(S_13_6&C_13_5); tmp = S_13_7^C_13_6; S_14_6 = tmp^(((A>>14)&1) & ((B>>6)&1)); C_14_6 = (tmp&(((A>>14)&1) & ((B>>6)&1)))|(S_13_7&C_13_6); tmp = S_13_8^C_13_7; S_14_7 = tmp^(((A>>14)&1) & ((B>>7)&1)); C_14_7 = (tmp&(((A>>14)&1) & ((B>>7)&1)))|(S_13_8&C_13_7); tmp = S_13_9^C_13_8; S_14_8 = tmp^(((A>>14)&1) & ((B>>8)&1)); C_14_8 = (tmp&(((A>>14)&1) & ((B>>8)&1)))|(S_13_9&C_13_8); tmp = S_13_10^C_13_9; S_14_9 = tmp^(((A>>14)&1) & ((B>>9)&1)); C_14_9 = (tmp&(((A>>14)&1) & ((B>>9)&1)))|(S_13_10&C_13_9); tmp = S_13_11^C_13_10; S_14_10 = tmp^(((A>>14)&1) & ((B>>10)&1)); C_14_10 = (tmp&(((A>>14)&1) & ((B>>10)&1)))|(S_13_11&C_13_10); tmp = S_13_12^C_13_11; S_14_11 = tmp^(((A>>14)&1) & ((B>>11)&1)); C_14_11 = (tmp&(((A>>14)&1) & ((B>>11)&1)))|(S_13_12&C_13_11); tmp = S_13_13^C_13_12; S_14_12 = tmp^(((A>>14)&1) & ((B>>12)&1)); C_14_12 = (tmp&(((A>>14)&1) & ((B>>12)&1)))|(S_13_13&C_13_12); tmp = S_13_14^C_13_13; S_14_13 = tmp^(((A>>14)&1) & ((B>>13)&1)); C_14_13 = (tmp&(((A>>14)&1) & ((B>>13)&1)))|(S_13_14&C_13_13); tmp = S_13_15^C_13_14; S_14_14 = tmp^(((A>>14)&1) & ((B>>14)&1)); C_14_14 = (tmp&(((A>>14)&1) & ((B>>14)&1)))|(S_13_15&C_13_14); S_14_15 = C_13_15^(((((A>>14)&1) & ((B>>15)&1)))^1); C_14_15 = C_13_15&(((((A>>14)&1) & ((B>>15)&1)))^1); tmp = S_14_1^C_14_0; S_15_0 = tmp^(((((A>>15)&1) & ((B>>0)&1)))^1); C_15_0 = (tmp&(((((A>>15)&1) & ((B>>0)&1)))^1))|(S_14_1&C_14_0); tmp = S_14_2^C_14_1; S_15_1 = tmp^(((((A>>15)&1) & ((B>>1)&1)))^1); C_15_1 = (tmp&(((((A>>15)&1) & ((B>>1)&1)))^1))|(S_14_2&C_14_1); tmp = S_14_3^C_14_2; S_15_2 = tmp^(((((A>>15)&1) & ((B>>2)&1)))^1); C_15_2 = (tmp&(((((A>>15)&1) & ((B>>2)&1)))^1))|(S_14_3&C_14_2); tmp = S_14_4^C_14_3; S_15_3 = tmp^(((((A>>15)&1) & ((B>>3)&1)))^1); C_15_3 = (tmp&(((((A>>15)&1) & ((B>>3)&1)))^1))|(S_14_4&C_14_3); tmp = S_14_5^C_14_4; S_15_4 = tmp^(((((A>>15)&1) & ((B>>4)&1)))^1); C_15_4 = (tmp&(((((A>>15)&1) & ((B>>4)&1)))^1))|(S_14_5&C_14_4); tmp = S_14_6^C_14_5; S_15_5 = tmp^(((((A>>15)&1) & ((B>>5)&1)))^1); C_15_5 = (tmp&(((((A>>15)&1) & ((B>>5)&1)))^1))|(S_14_6&C_14_5); tmp = S_14_7^C_14_6; S_15_6 = tmp^(((((A>>15)&1) & ((B>>6)&1)))^1); C_15_6 = (tmp&(((((A>>15)&1) & ((B>>6)&1)))^1))|(S_14_7&C_14_6); tmp = S_14_8^C_14_7; S_15_7 = tmp^(((((A>>15)&1) & ((B>>7)&1)))^1); C_15_7 = (tmp&(((((A>>15)&1) & ((B>>7)&1)))^1))|(S_14_8&C_14_7); tmp = S_14_9^C_14_8; S_15_8 = tmp^(((((A>>15)&1) & ((B>>8)&1)))^1); C_15_8 = (tmp&(((((A>>15)&1) & ((B>>8)&1)))^1))|(S_14_9&C_14_8); tmp = S_14_10^C_14_9; S_15_9 = tmp^(((((A>>15)&1) & ((B>>9)&1)))^1); C_15_9 = (tmp&(((((A>>15)&1) & ((B>>9)&1)))^1))|(S_14_10&C_14_9); tmp = S_14_11^C_14_10; S_15_10 = tmp^(((((A>>15)&1) & ((B>>10)&1)))^1); C_15_10 = (tmp&(((((A>>15)&1) & ((B>>10)&1)))^1))|(S_14_11&C_14_10); tmp = S_14_12^C_14_11; S_15_11 = tmp^(((((A>>15)&1) & ((B>>11)&1)))^1); C_15_11 = (tmp&(((((A>>15)&1) & ((B>>11)&1)))^1))|(S_14_12&C_14_11); tmp = S_14_13^C_14_12; S_15_12 = tmp^(((((A>>15)&1) & ((B>>12)&1)))^1); C_15_12 = (tmp&(((((A>>15)&1) & ((B>>12)&1)))^1))|(S_14_13&C_14_12); tmp = S_14_14^C_14_13; S_15_13 = tmp^(((((A>>15)&1) & ((B>>13)&1)))^1); C_15_13 = (tmp&(((((A>>15)&1) & ((B>>13)&1)))^1))|(S_14_14&C_14_13); tmp = S_14_15^C_14_14; S_15_14 = tmp^(((((A>>15)&1) & ((B>>14)&1)))^1); C_15_14 = (tmp&(((((A>>15)&1) & ((B>>14)&1)))^1))|(S_14_15&C_14_14); S_15_15 = C_14_15^(((A>>15)&1) & ((B>>15)&1)); C_15_15 = C_14_15&(((A>>15)&1) & ((B>>15)&1)); S_16_0 = S_15_1^C_15_0; C_16_0 = S_15_1&C_15_0; tmp = S_15_2^C_16_0; S_16_1 = tmp^C_15_1; C_16_1 = (tmp&C_15_1)|(S_15_2&C_16_0); tmp = S_15_3^C_16_1; S_16_2 = tmp^C_15_2; C_16_2 = (tmp&C_15_2)|(S_15_3&C_16_1); tmp = S_15_4^C_16_2; S_16_3 = tmp^C_15_3; C_16_3 = (tmp&C_15_3)|(S_15_4&C_16_2); tmp = S_15_5^C_16_3; S_16_4 = tmp^C_15_4; C_16_4 = (tmp&C_15_4)|(S_15_5&C_16_3); tmp = S_15_6^C_16_4; S_16_5 = tmp^C_15_5; C_16_5 = (tmp&C_15_5)|(S_15_6&C_16_4); tmp = S_15_7^C_16_5; S_16_6 = tmp^C_15_6; C_16_6 = (tmp&C_15_6)|(S_15_7&C_16_5); tmp = S_15_8^C_16_6; S_16_7 = tmp^C_15_7; C_16_7 = (tmp&C_15_7)|(S_15_8&C_16_6); tmp = S_15_9^C_16_7; S_16_8 = tmp^C_15_8; C_16_8 = (tmp&C_15_8)|(S_15_9&C_16_7); tmp = S_15_10^C_16_8; S_16_9 = tmp^C_15_9; C_16_9 = (tmp&C_15_9)|(S_15_10&C_16_8); tmp = S_15_11^C_16_9; S_16_10 = tmp^C_15_10; C_16_10 = (tmp&C_15_10)|(S_15_11&C_16_9); tmp = S_15_12^C_16_10; S_16_11 = tmp^C_15_11; C_16_11 = (tmp&C_15_11)|(S_15_12&C_16_10); tmp = S_15_13^C_16_11; S_16_12 = tmp^C_15_12; C_16_12 = (tmp&C_15_12)|(S_15_13&C_16_11); tmp = S_15_14^C_16_12; S_16_13 = tmp^C_15_13; C_16_13 = (tmp&C_15_13)|(S_15_14&C_16_12); tmp = S_15_15^C_16_13; S_16_14 = tmp^C_15_14; C_16_14 = (tmp&C_15_14)|(S_15_15&C_16_13); tmp = 1^C_16_14; S_16_15 = tmp^C_15_15; C_16_15 = (tmp&C_15_15)|(1&C_16_14); P = 0; P |= (S_5_0 & 1) << 5; P |= (S_6_0 & 1) << 6; P |= (S_7_0 & 1) << 7; P |= (S_8_0 & 1) << 8; P |= (S_9_0 & 1) << 9; P |= (S_10_0 & 1) << 10; P |= (S_11_0 & 1) << 11; P |= (S_12_0 & 1) << 12; P |= (S_13_0 & 1) << 13; P |= (S_14_0 & 1) << 14; P |= (S_15_0 & 1) << 15; P |= (S_16_0 & 1) << 16; P |= (S_16_1 & 1) << 17; P |= (S_16_2 & 1) << 18; P |= (S_16_3 & 1) << 19; P |= (S_16_4 & 1) << 20; P |= (S_16_5 & 1) << 21; P |= (S_16_6 & 1) << 22; P |= (S_16_7 & 1) << 23; P |= (S_16_8 & 1) << 24; P |= (S_16_9 & 1) << 25; P |= (S_16_10 & 1) << 26; P |= (S_16_11 & 1) << 27; P |= (S_16_12 & 1) << 28; P |= (S_16_13 & 1) << 29; P |= (S_16_14 & 1) << 30; P |= (S_16_15 & 1) << 31; return P; }
the_stack_data/73575050.c
// This file is part of CPAchecker, // a tool for configurable software verification: // https://cpachecker.sosy-lab.org // // SPDX-FileCopyrightText: 2007-2020 Dirk Beyer <https://www.sosy-lab.org> // SPDX-FileCopyrightText: 2014-2017 Université Grenoble Alpes // // SPDX-License-Identifier: Apache-2.0 void assert(int cond) { if (!cond) { ERROR: return; } } extern _Bool __VERIFIER_nondet_bool(); int main() { int i = 0; while(__VERIFIER_nondet_bool()){ if (i == 4) { i = 0; } i++; } assert(i >= 0 && i < 5); }
the_stack_data/343464.c
#include "stdio.h" int sorting_function(int *arr,int arr_len) { int tmp = 0; int d = arr_len; int yes_no = 0; int sum = 0; while(yes_no || (d>1)) { if( d > 1) {d = d/1.24733;} else { d = 1; } yes_no = 0; for(int i = 0; d + i < arr_len; i++) { if(arr[i] > arr[d+i]) { tmp = arr[i]; arr[i] = arr[d+i]; arr[d+i] = tmp; sum++; yes_no = 1; } } } return sum; } int print(int *arr,int arr_len) { for(int i = 0; i < arr_len; i++) { if(i<arr_len-1) { printf("%d ",arr[i]); }else { printf("%d",arr[i]); } } printf("\n"); return 0; } int main() { int n; scanf("%d",&n); int arr[n]; for(int i = 0; i < n; i++) { scanf("%d",&arr[i]); } sorting_function(arr,n); print(arr,n); }
the_stack_data/232955516.c
/* * Generated by MTK Easy PinMux Tool Version 1.0.4 for 7687. Copyright MediaTek Inc. (C) 2015. * Thu Jun 30 15:06:22 2016 * Do Not Modify the File. */ /***************************************************************************** * * Filename: * --------- * ***.* * * Project: * -------- * * Description: * ------------ * * Author: * ------- * *============================================================================ ****************************************************************************/ const unsigned char BSP_CTP_EINT = 0xff; const unsigned char HAL_ACCDET_EINT = 0xff; const unsigned char HAL_MSDC_EINT = 0xff; const unsigned char BSP_GNSS_EINT = 0xff;
the_stack_data/92326112.c
/* { dg-do compile } */ /* { dg-options "-O" } */ void * sbrk (unsigned int increment) { volatile register __attribute__ ((__spu_vector__)) unsigned int sp_r1 __asm__ ("1"); unsigned int sps; sps = __builtin_spu_extract (sp_r1, 0); if (sps - 4096 >= increment) return 0; else return ((void *) -1); }
the_stack_data/37638798.c
#include "stdio.h" #include "stdlib.h" struct node { int data; struct node *link; }; struct node *head = NULL, *x, *y, *z; void create(); void ins_at_beg(); void ins_at_pos(); void del_at_beg(); void del_at_pos(); void traverse(); void search(); void sort(); void update(); void rev_traverse(struct node *p); main() { int ch; printf("--------------------------------MENU-----------------------------------"); printf("\n 1.Creation \n 2.Insertion at beginning \n 3.Insertion at remaining"); printf("\n 4.Deletion at beginning \n 5.Deletion at remaining \n 6.Traverse"); printf("\n 7.Search\n 8.Sort\n 9.Update\n 10.Exit\n"); printf("-----------------------------------------------------------------------"); while (1) { printf("\n Please enter your choice:"); scanf("%d", &ch); switch(ch) { case 1: create(); break; case 2: ins_at_beg(); break; case 3: ins_at_pos(); break; case 4: del_at_beg(); break; case 5: del_at_pos(); break; case 6: traverse(); break; case 7: search(); break; case 8: sort(); break; case 9: update(); break; case 10: rev_traverse(head); exit(0); default: printf("Sorry wrong input\n"); } } } /*Function to create a new circular linked list*/ void create() { char c; x = (struct node*)malloc(sizeof(struct node)); printf("\n Enter the data:"); scanf("%d", &x->data); x->link = x; head = x; printf("\n If you wish to continue press y otherwise n:"); scanf(" %c", &c); while (c != 'n') { y = (struct node*)malloc(sizeof(struct node)); printf("\n Enter the data:"); scanf("%d", &y->data); x->link = y; y->link = head; x = y; printf("\n If you wish to continue press y otherwise n:"); scanf(" %c", &c); } } /*Function to insert an element at the begining of the list*/ void ins_at_beg() { x = head; y = (struct node*)malloc(sizeof(struct node)); printf("\n Enter the data:"); scanf("%d", &y->data); while (x->link != head) { x = x->link; } x->link = y; y->link = head; head = y; } /*Function to insert an element at any position the list*/ void ins_at_pos() { struct node *ptr; int c = 1, pos, count = 1; y = (struct node*)malloc(sizeof(struct node)); if (head == NULL) { printf("cannot enter an element at this place"); } printf("\n Enter the data:"); scanf("%d", &y->data); printf("\n Enter the position to be inserted:"); scanf("%d", &pos); x = head; ptr = head; while (ptr->link != head) { count++; ptr = ptr->link; } count++; if (pos > count) { printf("OUT OF BOUND"); return; } while (c < pos) { z = x; x = x->link; c++; } y->link = x; z->link = y; } /*Function to delete an element at any begining of the list*/ void del_at_beg() { if (head == NULL) printf("\n List is empty"); else { x = head; y = head; while (x->link != head) { x = x->link; } head = y->link; x->link = head; free(y); } } /*Function to delete an element at any position the list*/ void del_at_pos() { if (head == NULL) printf("\n List is empty"); else { int c = 1, pos; printf("\n Enter the position to be deleted:"); scanf("%d", &pos); x = head; while (c < pos) { y = x; x = x->link; c++; } y->link = x->link; free(x); } } /*Function to display the elements in the list*/ void traverse() { if (head == NULL) printf("\n List is empty"); else { x = head; while (x->link != head) { printf("%d->", x->data); x = x->link; } printf("%d", x->data); } } /*Function to search an element in the list*/ void search() { int search_val, count = 0, flag = 0; printf("\nenter the element to search\n"); scanf("%d", &search_val); if (head == NULL) printf("\nList is empty nothing to search"); else { x = head; while (x->link != head) { if (x->data == search_val) { printf("\nthe element is found at %d", count); flag = 1; break; } count++; x = x->link; } if (flag == 0) { printf("\nelement not found"); } } } /*Function to sort the list in ascending order*/ void sort() { struct node *ptr, *nxt; int temp; if (head == NULL) { printf("empty linkedlist"); } else { ptr = head; while (ptr->link != head) { nxt = ptr->link; while (nxt != head) { if (nxt != head) { if (ptr->data > nxt->data) { temp = ptr->data; ptr->data = nxt->data; nxt->data = temp; } } else { break; } nxt = nxt->link; } ptr = ptr->link; } } } /*Function to update an element at any position the list*/ void update() { struct node *ptr; int search_val; int replace_val; int flag = 0; if (head == NULL) { printf("\n empty list"); } else { printf("enter the value to be edited\n"); scanf("%d", &search_val); fflush(stdin); printf("enter the value to be replace\n"); scanf("%d", &replace_val); ptr = head; while (ptr->link != head) { if (ptr->data == search_val) { ptr->data = replace_val; flag = 1; break; } ptr = ptr->link; } if (ptr->data == search_val) { ptr->data = replace_val; flag = 1; } if (flag == 1) { printf("\nUPdate sucessful"); } else { printf("\n update not successful"); } } } /*Function to display the elements of the list in reverse order*/ void rev_traverse(struct node *p) { int i = 0; if (head == NULL) { printf("empty linked list\n"); } else { if (p->link != head) { i = p->data; rev_traverse(p->link); printf(" %d", i); } if (p->link == head) { printf(" %d", p->data); } } }
the_stack_data/198580090.c
//***************************************************************************** // // startup_gcc.c - Startup code for use with GNU tools. // // Copyright (c) 2008-2013 Texas Instruments Incorporated. All rights reserved. // Software License Agreement // // Texas Instruments (TI) is supplying this software for use solely and // exclusively on TI's microcontroller products. The software is owned by // TI and/or its suppliers, and is protected under applicable copyright // laws. You may not combine this software with "viral" open-source // software in order to form a larger program. // // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL // DAMAGES, FOR ANY REASON WHATSOEVER. // // This is part of revision 10636 of the RDK-IDM-SBC Firmware Package. // //***************************************************************************** //***************************************************************************** // // Forward declaration of the default fault handlers. // //***************************************************************************** void ResetISR(void); static void NmiSR(void); static void FaultISR(void); static void IntDefaultHandler(void); //***************************************************************************** // // External declarations for the interrupt handlers used by the application. // //***************************************************************************** extern void TouchScreenIntHandler(void); extern void lwIPEthernetIntHandler(void); extern void SoundIntHandler(void); extern void SysTickIntHandler(void); //***************************************************************************** // // The entry point for the application. // //***************************************************************************** extern int main(void); //***************************************************************************** // // Reserve space for the system stack. // //***************************************************************************** static unsigned long pulStack[256]; //***************************************************************************** // // The vector table. Note that the proper constructs must be placed on this to // ensure that it ends up at physical address 0x0000.0000. // //***************************************************************************** __attribute__ ((section(".isr_vector"))) void (* const g_pfnVectors[])(void) = { (void (*)(void))((unsigned long)pulStack + sizeof(pulStack)), // The initial stack pointer ResetISR, // The reset handler NmiSR, // The NMI handler FaultISR, // The hard fault handler IntDefaultHandler, // The MPU fault handler IntDefaultHandler, // The bus fault handler IntDefaultHandler, // The usage fault handler 0, // Reserved 0, // Reserved 0, // Reserved 0, // Reserved IntDefaultHandler, // SVCall handler IntDefaultHandler, // Debug monitor handler 0, // Reserved IntDefaultHandler, // The PendSV handler SysTickIntHandler, // The SysTick handler IntDefaultHandler, // GPIO Port A IntDefaultHandler, // GPIO Port B IntDefaultHandler, // GPIO Port C IntDefaultHandler, // GPIO Port D IntDefaultHandler, // GPIO Port E IntDefaultHandler, // UART0 Rx and Tx IntDefaultHandler, // UART1 Rx and Tx IntDefaultHandler, // SSI0 Rx and Tx IntDefaultHandler, // I2C0 Master and Slave IntDefaultHandler, // PWM Fault IntDefaultHandler, // PWM Generator 0 IntDefaultHandler, // PWM Generator 1 IntDefaultHandler, // PWM Generator 2 IntDefaultHandler, // Quadrature Encoder 0 IntDefaultHandler, // ADC Sequence 0 IntDefaultHandler, // ADC Sequence 1 IntDefaultHandler, // ADC Sequence 2 TouchScreenIntHandler, // ADC Sequence 3 IntDefaultHandler, // Watchdog timer IntDefaultHandler, // Timer 0 subtimer A IntDefaultHandler, // Timer 0 subtimer B IntDefaultHandler, // Timer 1 subtimer A IntDefaultHandler, // Timer 1 subtimer B IntDefaultHandler, // Timer 2 subtimer A IntDefaultHandler, // Timer 2 subtimer B IntDefaultHandler, // Analog Comparator 0 IntDefaultHandler, // Analog Comparator 1 IntDefaultHandler, // Analog Comparator 2 IntDefaultHandler, // System Control (PLL, OSC, BO) IntDefaultHandler, // FLASH Control IntDefaultHandler, // GPIO Port F IntDefaultHandler, // GPIO Port G IntDefaultHandler, // GPIO Port H IntDefaultHandler, // UART2 Rx and Tx IntDefaultHandler, // SSI1 Rx and Tx IntDefaultHandler, // Timer 3 subtimer A IntDefaultHandler, // Timer 3 subtimer B IntDefaultHandler, // I2C1 Master and Slave IntDefaultHandler, // Quadrature Encoder 1 IntDefaultHandler, // CAN0 IntDefaultHandler, // CAN1 IntDefaultHandler, // CAN2 lwIPEthernetIntHandler, // Ethernet IntDefaultHandler, // Hibernate IntDefaultHandler, // USB0 IntDefaultHandler, // PWM Generator 3 IntDefaultHandler, // uDMA Software Transfer IntDefaultHandler, // uDMA Error IntDefaultHandler, // ADC1 Sequence 0 IntDefaultHandler, // ADC1 Sequence 1 IntDefaultHandler, // ADC1 Sequence 2 IntDefaultHandler, // ADC1 Sequence 3 SoundIntHandler, // I2S0 IntDefaultHandler, // External Bus Interface 0 IntDefaultHandler // GPIO Port J }; //***************************************************************************** // // The following are constructs created by the linker, indicating where the // the "data" and "bss" segments reside in memory. The initializers for the // for the "data" segment resides immediately following the "text" segment. // //***************************************************************************** extern unsigned long _etext; extern unsigned long _data; extern unsigned long _edata; extern unsigned long _bss; extern unsigned long _ebss; //***************************************************************************** // // This is the code that gets called when the processor first starts execution // following a reset event. Only the absolutely necessary set is performed, // after which the application supplied entry() routine is called. Any fancy // actions (such as making decisions based on the reset cause register, and // resetting the bits in that register) are left solely in the hands of the // application. // //***************************************************************************** void ResetISR(void) { unsigned long *pulSrc, *pulDest; // // Copy the data segment initializers from flash to SRAM. // pulSrc = &_etext; for(pulDest = &_data; pulDest < &_edata; ) { *pulDest++ = *pulSrc++; } // // Zero fill the bss segment. // __asm(" ldr r0, =_bss\n" " ldr r1, =_ebss\n" " mov r2, #0\n" " .thumb_func\n" "zero_loop:\n" " cmp r0, r1\n" " it lt\n" " strlt r2, [r0], #4\n" " blt zero_loop"); // // Call the application's entry point. // main(); } //***************************************************************************** // // This is the code that gets called when the processor receives a NMI. This // simply enters an infinite loop, preserving the system state for examination // by a debugger. // //***************************************************************************** static void NmiSR(void) { // // Enter an infinite loop. // while(1) { } } //***************************************************************************** // // This is the code that gets called when the processor receives a fault // interrupt. This simply enters an infinite loop, preserving the system state // for examination by a debugger. // //***************************************************************************** static void FaultISR(void) { // // Enter an infinite loop. // while(1) { } } //***************************************************************************** // // This is the code that gets called when the processor receives an unexpected // interrupt. This simply enters an infinite loop, preserving the system state // for examination by a debugger. // //***************************************************************************** static void IntDefaultHandler(void) { // // Go into an infinite loop. // while(1) { } }
the_stack_data/818574.c
#include <stdio.h> #include <time.h> #include <stdlib.h> int run(char *input) { char acc[4] = {0}; // accumulator for ints int acc_i = 0, parsed_total = 0; int parsed[300]; // 300 should be far enough, tested inputs are around 200 // Parse ints for (; *input != '\0'; ++input) { if (*input == '\n') { parsed[parsed_total++] = atoi(acc); acc_i = 0; for (int j = 0; j < 4; j++) acc[j] = 0; } else { acc[acc_i++] = *input; } } for (int i1 = 0; i1 < parsed_total; i1++) for (int i2 = i1 + 1; i2 < parsed_total; i2++) { if (i1 + i2 >= 2020) continue; for (int i3 = i2 + 1; i3 < parsed_total; i3++) if (parsed[i1] + parsed[i2] + parsed[i3] == 2020) return parsed[i1] * parsed[i2] * parsed[i3]; } return 0; } int main(int argc, char **argv) { clock_t start = clock(); int answer = run(argv[1]); printf("_duration:%f\n%d\n", (float)(clock() - start) * 1000.0 / CLOCKS_PER_SEC, answer); return 0; }
the_stack_data/181393053.c
/** trasversing spirally */ /** 1: easy */ #include <stdio.h> #include <stdlib.h> void show_block(int *a, int w, int i0, int i1, int j0, int j1) { // printf("%d->%d %d-> %d\n", i0, i1, j0, j1); int i, j; int s0 = (i0 < i1) ? 1 : -1; int s1 = (j0 < j1) ? 1 : -1; for (i = i0; i != i1; i += s0) { for (j = j0; j != j1; j += s1) { printf("%d ", a[i * w + j]); } } } void show_spiral(int *a, int m, int n, int w) { show_block(a, w, 0, 1, 0, n); show_block(a, w, 1, m, n - 1, n); if (n == 1 || m == 1) { printf("\n"); return; } show_block(a, w, m - 1, m, n - 2, -1); show_block(a, w, m - 2, 0, 0, 1); if (m == 2 || n == 2) { printf("\n"); return; } show_spiral(a + w + 1, m - 2, n - 2, w); } int main() { int t, m, n, sz, *a, i; for (scanf("%d", &t); t != 0; t--) { for (scanf("%d%d", &m, &n), sz = m * n, a = malloc(sizeof(int) * sz), i = 0; i != sz; i++) { scanf("%d", &a[i]); } show_spiral(a, m, n, n); free(a); } return 0; }
the_stack_data/92329104.c
// t == 40 ///////////////////////////////////////////////////////////// // Original ///////////////////////////////////////////////////////////// // States visited : 6483 // Analysis time : 106.12s // # subsumed nodes : 3082 // # calls to solver during interpolation : 981426 // Total time on interpolation phase: 32 %. // Total time on backward phase: 7 %. // Total time on forward phase: 10 %. // Total time on memo store phase: 10 %. // Total time on memo lookup phase: 33 %. // Total time on partition phase: 8 %. ///////////////////////////////////////////////////////////// // Decompiled ///////////////////////////////////////////////////////////// int main() { register char B0; register char B1; register char B2; register char B3; register char B4; register char B5; register char B6; register char B7; register char B8; register char B9; register char B10; register char B11; register char B12; register char B13; register char B14; register char B15; register char B16; register char B17; register char B18; register char B19; register char B20; register char B21; register char B22; register char B23; register char B24; register char B25; register char B26; register char B27; register char B28; register char B29; register char B30; register char B31; register char B32; register char B33; register char B34; register char B35; register char B36; register char B37; register char B38; register char B39; register char B40; register char B41; register char B42; register char B43; register char B44; register char B45; register char B46; register char B47; register char B48; register char B49; register char B50; register char B51; register char B52; register char B53; register char B54; register char B55; register char B56; register char B57; register char B58; register char B59; register char B60; register char B61; register char B62; register char B63; register unsigned long X1; register unsigned long X2; register unsigned long X3; register unsigned long X4 ; register unsigned long X5 ; register unsigned long X6 ; register int X7; register int X8; register int X9; register unsigned long X10 ; register unsigned long X11 ; register int X12 ; register int X13 ; register int X14; register int X15; register int X16; register int X17 ; register int X18 ; register int X19; register int X20; register int X21; register int X22; register int X23; register int X24; register char X25; register char X27; register char X26; register char X28; register char X29; register char X30 ; register char X31; register char X32 ; register char X33; register char X34; register char X35; register char X36; register char X37; register char X38; register char X39; register char X40; register char X41; register char X42; register char X43; register char X44; register char X45; register char X46; register char X47; register char X48; register char X49; register char X50; register char X51; register char X52; register char X53; register char X54; register char X55; register char X56; register char X57; register char X58; register char X59; register char X60; register char X61; register char X62; register char X63; register char X64; register char X65; register char X66; register char X67; register char X68; register char X69; register char X70; register char X71; register char X72; register char X73; register char X74; register char X75; register char X76; register char X77; register char X78; register char X79; register char X80; register char X81; register char X82; register char X83; register char X84; register char X85; register char X86; register unsigned long time; register char stable; register char step; register char X87; register char X88; register char X89; register char X90; register char X91; register char X92; register char X93; register char X94; register char X95; register char X96; register char X97; register char X98; register char X99; register char X100; register char X101; register char X102; register int t; t=0; X1 = 0; X2 = 0; X3 = 0; X87 = 0; X88 = 0; X89 = 0; X90 = 0; X91 = 0; X92 = 0; X93 = 0; X94 = 0; X95 = 0; X96 = 0; X97 = 0; X98 = 0; X99 = 0; X100 = 0; X101 = 0; X102 = 0; t++; if (B4) { X3 = time; t++; } if (B4 || B6) { X2 = time; t++; } if ((X4 != 0) && (time - X4 >= 0.5)){ X53 = 0; X4 = 0; t++; } if ((X5 != 0) && (time - X5 >= 0.5)){ X50 = 0; X5 = 0; t++; } if ((X6 != 0) && (time - X6 >= 0.5)){ X50 = 0; X6 = 0; t++; } if ((X10 != 0) && (time - X10 >= 0.5)){ X10 = 0; t++; } if ((X11 != 0) && (time - X11 >= 0.5)){ X11 = 0; t++; } if ((B0 || X22 != X24)) { X1 = time; t++; } time = 1; stable = 0; step = 0; t++; { stable = 1; step++; t++; { switch (X99) { case 1 : { if ((!(X81) && X83)) { stable = 0; X15 = 0; X99 = 2; t++; break; } break; } case 2 : { if ((X81 && !(X83))) { stable = 0; X15 = -100; X99 = 1; t++; break; } if ((X84 && !(X86))) { stable = 0; X15 = 100; X99 = 3; t++; break; } break; } case 3 : { if ((!(X84) && X86)) { stable = 0; X15 = 0; X99 = 2; t++; break; } break; } default: { stable = 0; X15 = 0; X99 = 2; t++; break; } } } { { if (!B10) { X90 = 3; t++; } B11 = 0; t++; if (!B16) { X100 = 1; t++; } B17 = 0; t++; if (!B19) { B0 = 0; X102 = 1; t++; } B20 = 0; t++; if (!B13) { B4 = 0; B6 = 0; X91 = 2; X7 = 0; X92 = 1; B5 = 1; X93 = 1; t++; } B14 = 0; B11 = 1; B17 = 1; B20 = 1; B14 = 1; t++; if (X68 != X70) { if ((!X77)) { X60 = X68; t++; } } if (X71 != X72) { if (X77) { X68 = X71; t++; } } if (X65 != X67) { if ((!X77)) { X61 = X65; t++; } } if (X73 != X74) { if (X77) { X65 = X73; t++; } } } } B10 = B12; B13 = B15; B16 = B18; B19 = B21; X36 = X76; X34 = X61; X32 = X75; X30 = X60; t++; X84 = X52; X81 = X49; X18 = X13; X63 = X55; X17 = X12; X62 = X42; X76 = X36; X61 = X34; X75 = X32; X60 = X30; X59 = X38; X78 = X39; X36 = X76; X34 = X61; X32 = X75; X30 = X60; t++; if (!B13 && B15 && !B14) { B4 = 0; B6 = 0; t++; } if (B13) { if (!B10) { X90 = 3; t++; } B11 = 0; t++; if (!B19) { B0 = 0; X102 = 1; t++; } B20 = 0; B11 = 1; B20 = 1; t++; switch (X91) { case 1 : { if ((X7 == 59 && !(X9 == 59))) { stable = 0; X91 = 3; X94 = 3; t++; break; } break; } case 2 : { if (((X39 && !(X41))) && ((X49))) { stable = 0; X50 = 0; X6 = time; X91 = 3; X94 = 3; t++; break; } switch (X87) { case 1 : { if (!(X43)) { stable = 0; X50 = 0; X87 = 3; t++; break; } break; } case 2 : { if (!(X46)) { stable = 0; X53 = 0; X87 = 3; t++; break; } break; } case 3 : { if ((X46)) { stable = 0; X53 = 1; X87 = 2; t++; break; } if ((X43)) { stable = 0; X50 = 1; X87 = 1; t++; break; } break; } default: { stable = 0; X87 = 3; t++; break; } } break; } case 3 : { if (((X7 > 60 && !(X9 > 60))) && ((!(X26 || X25)))) { stable = 0; X50 = 0; X53 = 0; X91 = 1; t++; break; } if (((X39 && !(X41))) && ((X52))) { stable = 0; X53 = 0; X4 = time; X91 = 2; X87 = 3; t++; break; } if (((X39 && !(X41))) && ((X49))) { stable = 0; X50 = 0; X5 = time; X91 = 2; X87 = 3; t++; break; } switch (X94) { case 1 : { if ((X12 >= 405)) { stable = 0; X53 = 0; X94 = 3; t++; break; } switch (X97) { case 1 : { if ((X43 && !(X45)) || (X46 && !(X48))) { stable = 0; X53 = 0; X94 = 3; X97 = 0; t++; break; } break; } case 2 : { if ((X43 && !(X45))) { stable = 0; X97 = 1; t++; break; } if ((!(X46) && X48)) { stable = 0; X53 = 0; X94 = 3; X97 = 0; t++; break; } break; } default: { stable = 0; X97 = 2; t++; break; } } break; } case 2 : { if ((X12 <= 0)) { stable = 0; X50 = 0; X94 = 3; t++; break; } switch (X98) { case 1 : { if ((X46 && !(X48)) || (X43 && !(X45))) { stable = 0; X50 = 0; X94 = 3; t++; break; } switch (X95) { case 1 : { B23 = 0; t++; if (B22) { stable = 0; X50 = 1; X27 = 0; X95 = 2; X53 = 0; B17 = 1; t++; break; } break; } case 2 : { if (B24) { stable = 0; X27 = 1; B23 = 1; X95 = 1; B17 = 0; X50 = 0; X10 = time; X53 = 1; t++; break; } break; } default: { stable = 0; X95 = 2; B17 = 1; t++; break; } } break; } case 2 : { if ((!(X43) && X45)) { stable = 0; X50 = 0; X94 = 3; t++; break; } switch (X96) { case 1 : { B23 = 0; t++; if (B22) { stable = 0; X28 = 0; X96 = 2; X53 = 0; B17 = 1; X50 = 1; t++; break; } break; } case 2 : { if (B24) { stable = 0; X50 = 0; X28 = 1; B23 = 1; X96 = 1; B17 = 0; X11 = time; X53 = 1; t++; break; } if ((X46 && !(X48))) { stable = 0; X98 = 1; X96 = 0; t++; break; } break; } default: { stable = 0; X96 = 2; B17 = 1; X50 = 1; t++; break; } } break; } default: { stable = 0; X98 = 2; X96 = 2; B17 = 1; X50 = 1; t++; break; } } break; } case 3 : { if (((X43 && !(X45))) && ((X12 > 0))) { stable = 0; X94 = 2; X98 = 2; X96 = 2; B17 = 1; X50 = 1; t++; break; } if (((X46 && !(X48))) && ((X12 < 405))) { stable = 0; X53 = 1; X94 = 1; X97 = 2; t++; break; } break; } default: { stable = 0; X94 = 3; t++; break; } } break; } default: { stable = 0; X91 = 2; t++; break; } } switch (X92) { case 1 : { B5 = 0; t++; if ((step == 1 && X2 != 0 && (time - X2 == 1)) && ((X49 || X52))) { stable = 0; X7 = X7 + 1; X92 = 1; B5 = 1; X93 = 1; t++; break; } switch (X93) { case 1 : { if ((step == 1 && X3 != 0 && (time - X3 == 3)) && (((!(X49 || X52)) && X7 > 0))) { stable = 0; X7 = X7 - 1; X93 = 1; t++; break; } break; } default: { stable = 0; B5 = 1; X93 = 1; t++; break; } } break; } default: { stable = 0; X7 = 0; X92 = 1; B5 = 1; X93 = 1; t++; break; } } B5 = B4; B7 = B6; t++; } X84 = X52; X81 = X49; X18 = X13; X63 = X55; X17 = X12; X62 = X42; X76 = X36; X61 = X34; X75 = X32; X60 = X30; X59 = X38; X78 = X39; X36 = X76; X34 = X61; X32 = X75; X30 = X60; t++; X84 = X52; X81 = X49; X18 = X13; X63 = X55; X17 = X12; X62 = X42; X76 = X36; X61 = X34; X75 = X32; X60 = X30; X59 = X38; X78 = X39; X36 = X76; X34 = X61; X32 = X75; X30 = X60; t++; X84 = X52; X81 = X49; X18 = X13; X63 = X55; X17 = X12; X62 = X42; X76 = X36; X61 = X34; X75 = X32; X60 = X30; X59 = X38; X78 = X39; B11 = B10; B14 = B13; B17 = B16; B20 = B19; X9 = X7; X14 = X13; X15 = X16; X19 = X18; X24 = X22; X31 = X30; X33 = X32; X35 = X34; X37 = X36; X39 = X40; X41 = X39; X43 = X44; X45 = X43; X46 = X47; X48 = X46; X49 = X50; X51 = X49; X52 = X53; X54 = X52; X56 = X55; X64 = X63; X67 = X65; X70 = X68; X72 = X71; X74 = X73; X78 = X79; X80 = X78; X81 = X82; X83 = X81; X84 = X85; X86 = X84; t++; } //_ABORT(t >= 40); return 0; }
the_stack_data/484179.c
/* HAL raised several warnings, ignore them */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" #ifdef STM32F3xx #include "stm32f3xx_hal_i2s_ex.c" #elif STM32F4xx #include "stm32f4xx_hal_i2s_ex.c" #elif STM32H7xx #include "stm32h7xx_hal_i2s_ex.c" #endif #pragma GCC diagnostic pop
the_stack_data/151706490.c
#include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <sys/msg.h> struct msg_st { long int msg_type; char text[BUFSIZ]; }; int main() { int running = 1; int msgid = -1; struct msg_st data; long int msgtype = 0; //注意1 //建立消息队列 msgid = msgget((key_t)1234, 0666 | IPC_CREAT); if(msgid == -1) { fprintf(stderr, "msgget failed with error: %d\n", errno); exit(EXIT_FAILURE); } //从队列中获取消息,直到遇到end消息为止 while(running) { if(msgrcv(msgid, (void*)&data, BUFSIZ, msgtype, 0) == -1) { fprintf(stderr, "msgrcv failed with errno: %d\n", errno); exit(EXIT_FAILURE); } printf("You wrote: %s\n",data.text); //遇到end结束 if(strncmp(data.text, "end", 3) == 0) running = 0; } //删除消息队列 if(msgctl(msgid, IPC_RMID, 0) == -1) { fprintf(stderr, "msgctl(IPC_RMID) failed\n"); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); }
the_stack_data/182952163.c
//Incluyo biblioteca de entrada/salida. #include <stdio.h> int funcionUno(int x, int y){ return x+y; } int funcionDos(int x, int y){ return x-y; } int funcionTres(int x, int y){ return x*y; } float funcionCuatro(int x, int y){ float result=0.0; if(y>0){ result= (float)x/ (float)y; }else{ printf("No se puede hacer esta operacion para los numeros %d--%d \n", x,y); } return result; } int main(){ int a,b,c; float d; printf("Bienvenidos a este programa \n"); printf("Ingrese el num uno \n"); scanf("%d",&a); printf("Ingrese el num dos \n"); scanf("%d",&b); //Operaciones c=funcionUno(a,b); printf("Resultado operacion uno %d \n", c); c=funcionDos(a,b); printf("Resultado operacion dos %d \n", c); c=funcionTres(a,b); printf("Resultado operacion tres %d \n", c); d=funcionCuatro(a,b); printf("Resultado operacion cuatro %f \n", d); return 0; }
the_stack_data/198581318.c
/* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ enum Foo { A, B, C = 10, D, E = 1, F, G = F + C }; int other_enum_main() { enum Foo foo_a = A; enum Foo foo_b = B; enum Foo foo_c = C; enum Foo foo_d = D; enum Foo foo_e = E; enum Foo foo_f = F; enum Foo foo_g = G; } int other_enum_test() { enum Foo foo_g = G; enum Foo foo_a = A; if (foo_g == 12) return foo_g / foo_a; else return 0; }
the_stack_data/1173679.c
/* Copyright 2020 Andrew Li, Gavin Li [email protected] [email protected] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include <stdint.h> /* * y = x^8 + x^4 + x^3 + x + 1 * maximum length = 2^m-1 = 2^8-1 = 255 */ uint32_t lfsr8(void) { static uint32_t lfsr = 3; lfsr = lfsr >> 1 | ((lfsr & (1<<4) ?1:0) ^ (lfsr & 1<<3 ?1:0) ^ (lfsr & 1<<1 ?1:0) ^ (lfsr & 1)) << 7; return lfsr; }
the_stack_data/26699687.c
/* Print a file in hexidecimal. * * Written by Taylor Holberton * * Compile: 'gcc xxd.c -o xxd' * */ /* TODO: * - When itoa becomes supported (or similar), print * the file offset add the beginning of the (like GNU xxd). * - When fwrite() is supported, the program * should write the output to the file specified * by the second argument. * - When fgetc(stdin) is supported, read from standard * input when no input file is specified. * - Support '-reverse' option, which reverts the program * output back into a normal file. * */ #include <stdio.h> #include <stdlib.h> #include <stdint.h> static int xxd(const char *filename); int main(int argc, const char **argv) { if (argc <= 1) { puts("Usage: xxd.app <input>\n"); return EXIT_FAILURE; } return xxd(argv[1]); } static int xxd(const char *filename) { FILE *file = fopen(filename, "rb"); if (file == NULL) return EXIT_FAILURE; char buffer[16]; char hexchars[] = "0123456789abcdef"; size_t byte_index = 0; size_t column = 1; while (!feof(file)) { size_t read_count = fread(buffer, 1, sizeof(buffer), file); if (read_count == 0) break; for (size_t i = 0; i < 16; i++) { if (i < read_count) { uint8_t byte = buffer[i]; fwrite(&hexchars[(byte & 0xf0) >> 4], 1, 1, stdout); fwrite(&hexchars[(byte & 0x0f) >> 0], 1, 1, stdout); } else { fwrite(" ", 2, 1, stdout); } column++; byte_index++; if ((byte_index % 2) == 0) { /* space */ fwrite(" ", 1, 1, stdout); column++; } } /* print extra space */ fwrite(" ", 1, 1, stdout); for (size_t i = 0; i < read_count; i++) { char c = buffer[i]; /* check if character is printable */ if (((c < 32) && (c != '\t')) || (c >= 127)) fwrite(".", 1, 1, stdout); else fwrite(&c, 1, 1, stdout); } fwrite("\n", 1, 1, stdout); } fclose(file); return EXIT_SUCCESS; }
the_stack_data/75138612.c
/* Brightness.c Modify the brightness on laptop running a linux distro. You need root privileges to run as it read/writes to /sys/class/backlight/intel_backlight/brightness. To avoid the password prompt for something as trivial as this, the setuid permission bit wouldn't hurt. chown root:user and chmod 4750 suggested ---- or if you have multiple users chown root:staff and chmod 4755 */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <limits.h> #include <errno.h> #define BUFSIZE 5 #define BRIGHTNESS_HIGH 4882 #define BRIGHTNESS_LOW 500 #define BRIGHTNESS_INTERVAL 500 static const char brightness_path[] = "/sys/class/backlight/intel_backlight/brightness"; static char buf[BUFSIZE]; static void printError(const char msg[]) { const int bPathLen = strlen(brightness_path); char errstr[150]; memcpy(errstr, brightness_path, bPathLen); memcpy(errstr+bPathLen, msg, strlen(msg) + 1); perror(errstr); } static int readBrightness() { FILE *file = 0; memset(buf, 0, BUFSIZE); file = fopen(brightness_path, "r"); if (!file) { printError("Error opening file to read."); exit(1); } fgets(buf, BUFSIZE, file); fclose(file); errno = 0; char *endptr = 0; long val = strtol(buf, &endptr, 10); /* Check for various possible errors */ if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) || (errno != 0 && val == 0) || (*endptr != '\0' && *endptr != '\n') ) { printError(" file content is not valid."); exit(1); } return (int)val; } static int convertBrightness(int bval) { int brightness = 0; /* -1 and 0 values for sight-damaging dim... */ switch(bval) { case -1: brightness = 80; break; case 0: brightness = 120; break; case 10: brightness = BRIGHTNESS_HIGH; break; default: brightness = bval * 500; } if (brightness > BRIGHTNESS_HIGH || brightness < 80) { fprintf(stderr, "Error: Invalid brightness value.\n"); exit(1); } return brightness; } static void setBrightness(int brightness) { FILE *file = 0; memset(buf, 0, BUFSIZE); file = fopen(brightness_path, "w"); if (!file) { printError("Error opening file for write."); exit(1); } fprintf(file, "%d", brightness); fclose(file); } int main(int argc, char **argv) { errno = 0; char *endptr = 0; if (argc == 1) { /*arg not given, set brightness to opposite extreme or highest*/ int brightness = readBrightness(); if (brightness == BRIGHTNESS_HIGH) { setBrightness(BRIGHTNESS_LOW); } else { setBrightness(BRIGHTNESS_HIGH); } } else { /*argument given, set brightness to value or decrement/increment*/ if (strcmp(argv[1], "+") == 0) { int brightness = readBrightness() + BRIGHTNESS_INTERVAL; if (brightness < BRIGHTNESS_HIGH) { setBrightness(brightness); } else { setBrightness(BRIGHTNESS_HIGH); } } else if (strcmp(argv[1], "-") == 0) { int brightness = readBrightness() - BRIGHTNESS_INTERVAL; if (brightness > BRIGHTNESS_LOW) { setBrightness(brightness); } else { setBrightness(BRIGHTNESS_LOW); } } else { int bval = (int) strtol(argv[1], &endptr, 10); if (*endptr != '\0') { printError("Error: Invalid brightness value.\n"); return 1; } setBrightness(convertBrightness(bval)); } } return 0; }
the_stack_data/103266480.c
/* Optimizing brainfuck implementation of dialect based on Daniel's dbfi (see "A very short self-interpreter") This interpreter has only one input: program and input to the program have to be separated with ! e.g. ",.!a" prints 'a' To use it in interactive mode paste your program as input. This program can be compiled with NOLNR macro defined. NOLNR disables optimization of linear loops (where '<>' balanced), e.g. [->+>++<<]. Linear loop is then executed in one step. Oleg Mazonka 4 Dec 2006 http://mazonka.com/ */ #include <stdlib.h> #include <stdio.h> #include <string.h> typedef struct _op { int shift, off; int * d, sz; struct _op * go; int c; int igo, linear; int * db, dbsz; } op; void printop(op *z) { int j; printf("op='"); if( !strchr("<>+-",z->c) ) printf("%c",(char)z->c); for( j=0; j<z->dbsz; j++ ) printf("%c",(char)z->db[j]); printf("' shift=%d off=%d go=%d { " ,z->shift, z->off, z->igo ); for( j=0; j<z->sz; j++ ) printf("%d ",z->d[j]); printf("}\n"); } void * zalloc(void *p, int sz, int osz) { p = realloc(p,sz); memset((char*)p+osz,0,sz-osz); return p; } #define zalloci(p,sz,osz) zalloc(p,(sz)*sizeof(int),(osz)*sizeof(int)); int getbf() { int a; next: a = getchar(); if( a==-1 ) return -1; if( !strchr(",.[]+-<>!",a) ) goto next; return a; } int consume(op *o) { int mp=0,i; int a = o->c; if( strchr("[]",a) ) a=getbf(); o->sz = 1; o->d = zalloci(0,1,0); o->off = 0; o->dbsz=0; o->db=0; for(;;a=getbf()) { if( a==-1 || a=='!' ) break; if( strchr(",.[]",a) ) break; o->db = zalloci(o->db,o->dbsz+1,o->dbsz); o->db[o->dbsz++] = a; if( a=='+' ) o->d[mp] = (o->d[mp]+1)%255; if( a=='-' ) o->d[mp] = (o->d[mp]-1)%255; if( a=='>' ) { mp++; if( mp>=o->sz ) { o->d = zalloci(o->d,o->sz+1,o->sz); o->sz++; } } if( a=='<' ) { if( mp>0 ) mp--; else { o->off--; o->d = zalloci(o->d,o->sz+1,o->sz); for( i=o->sz; i>0; i-- ) o->d[i] = o->d[i-1]; o->d[0] = 0; o->sz++; } } } o->shift = mp + o->off; /* cut corners */ while( o->sz && o->d[o->sz-1] == 0 ) o->sz--; while( o->sz && o->d[0] == 0 ) { o->sz--; for( i=0; i<o->sz; i++ ) o->d[i] = o->d[i+1]; o->off++; } return a; } int main() { op * o=0, *z, *zend; int sz=0, i, *m, mp, msz; int a = getbf(); for(;;sz++) { o = zalloc(o,(sz+1)*sizeof(op),sz*sizeof(op)); if( a==-1 || a=='!' ) break; o[sz].c = a; if( strchr(",.",a) ){ a=getbf(); continue; } if( a==']' ) { int l=1, i=sz; while(l&&i>=0) if(i--) l+=(o[i].c==']')-(o[i].c=='['); if( i<0 ){ printf("unbalanced ']'\n"); exit(1); } o[i].igo = sz; o[sz].igo = i; } a = consume(o+sz); } for( i=0;i<sz;i++ ) { o[i].go = &o[o[i].igo]; #ifndef NOLNR if( o[i].c == '[' && o[i].igo == i+1 && o[i].shift==0 && o[i].off <= 0 ) { o[i].linear = -o[i].d[-o[i].off]; if( o[i].linear < 0 ) { printf("Warning: infinite loop "); printop(&o[i]); printf("linear=%d\n",o[i].linear); o[i].linear = 0; } } else o[i].linear = 0; #endif } msz = 1000; /* any number */ m = zalloci(0,msz,0); mp=0; z = o; zend = o+sz; for( ; z!=zend; ++z ) { #ifdef DBG printop(z); #endif if( z->c == ']' ) { if( m[mp] ) z=z->go; } else if( z->c == '[' ) { if( !m[mp] ) z=z->go; } else if( z->c == ',' ){ m[mp] = getchar(); continue; } else if( z->c == '.' ){ putchar(m[mp]); continue; } /* apply */ if( z->sz ) { int nmsz = mp+z->sz+z->off; if( nmsz > msz ) { m = zalloci(m,nmsz,msz); msz = nmsz; } #ifndef NOLNR if( z->linear ) { int del = m[mp]/z->linear; for( i=0; i<z->sz; i++ ) m[mp+z->off+i]+=del*z->d[i]; }else #endif for( i=0; i<z->sz; i++ ) m[mp+z->off+i]+=z->d[i]; } if( z->shift>0 ) { int nmsz = mp+z->shift+1; if( nmsz > msz ) { m = zalloci(m,nmsz,msz); msz = nmsz; } } mp += z->shift; #ifdef DBG for( i=0; i<msz; i++ ) { if( i==mp ) printf("'"); printf("%d ",m[i]); } printf("\n"); #endif } return 0; }
the_stack_data/200143375.c
/** * * */
the_stack_data/715012.c
#if 0 /* Screen saver library by Anders Norlander <[email protected]> This library is (hopefully) compatible with Microsoft's screen saver library. This is public domain software. */ #include <windows.h> #include <scrnsave.h> #include <regstr.h> /* screen saver window class */ #define CLASS_SCRNSAVE TEXT("WindowsScreenSaverClass") /* globals */ HWND hMainWindow = NULL; BOOL fChildPreview = FALSE; HINSTANCE hMainInstance; TCHAR szName[TITLEBARNAMELEN]; TCHAR szAppName[APPNAMEBUFFERLEN]; TCHAR szIniFile[MAXFILELEN]; TCHAR szScreenSaver[22]; TCHAR szHelpFile[MAXFILELEN]; TCHAR szNoHelpMemory[BUFFLEN]; UINT MyHelpMessage; /* local house keeping */ static HINSTANCE hPwdLib = NULL; static POINT pt_orig; static BOOL checking_pwd = FALSE; static BOOL closing = FALSE; static BOOL w95 = FALSE; typedef BOOL (WINAPI *VERIFYPWDPROC)(HWND); typedef DWORD (WINAPI *CHPWDPROC)(LPCTSTR, HWND, DWORD, PVOID); static VERIFYPWDPROC VerifyScreenSavePwd = NULL; /* function names */ #define szVerifyPassword "VerifyScreenSavePwd" #ifdef UNICODE #define szPwdChangePassword "PwdChangePasswordW" #else #define szPwdChangePassword "PwdChangePasswordA" #endif static void TerminateScreenSaver(HWND hWnd); static BOOL RegisterClasses(void); static LRESULT WINAPI SysScreenSaverProc(HWND,UINT,WPARAM,LPARAM); static int LaunchScreenSaver(HWND hParent); static void LaunchConfig(void); static int ISSPACE(char c) { return (c == ' ' || c == '\t'); } #define ISNUM(c) ((c) >= '0' && c <= '9') static unsigned long _toul(const char *s) { unsigned long res; unsigned long n; const char *p; for (p = s; *p; p++) if (!ISNUM(*p)) break; p--; res = 0; for (n = 1; p >= s; p--, n *= 10) res += (*p - '0') * n; return res; } /* screen saver entry point */ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR CmdLine, int nCmdShow) { LPSTR p; OSVERSIONINFO vi; /* initialize */ hMainInstance = hInst; vi.dwOSVersionInfoSize = sizeof(vi); GetVersionEx(&vi); /* check if we are going to check for passwords */ if (vi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { HKEY hKey; /* we are using windows 95 */ w95 = TRUE; if (RegOpenKey(HKEY_CURRENT_USER, REGSTR_PATH_SCREENSAVE ,&hKey) == ERROR_SUCCESS) { DWORD check_pwd; DWORD size = sizeof(DWORD); DWORD type; LONG res; res = RegQueryValueEx(hKey, REGSTR_VALUE_USESCRPASSWORD, NULL, &type, (PBYTE) &check_pwd, &size); if (check_pwd && res == ERROR_SUCCESS) { hPwdLib = LoadLibrary(TEXT("PASSWORD.CPL")); if (hPwdLib) VerifyScreenSavePwd = GetProcAddress(hPwdLib, szVerifyPassword); } RegCloseKey(hKey); } } /* parse arguments */ for (p = CmdLine; *p; p++) { switch (*p) { case 'S': case 's': /* start screen saver */ return LaunchScreenSaver(NULL); case 'P': case 'p': { /* start screen saver in preview window */ HWND hParent; fChildPreview = TRUE; while (ISSPACE(*++p)); hParent = (HWND) (unsigned long long)_toul(p); if (hParent && IsWindow(hParent)) return LaunchScreenSaver(hParent); } return 0; case 'C': case 'c': /* display configure dialog */ LaunchConfig(); return 0; case 'A': case 'a': { /* change screen saver password */ HWND hParent; while (ISSPACE(*++p)); hParent = (HWND) (unsigned long long) _toul(p); if (!hParent || !IsWindow(hParent)) hParent = GetForegroundWindow(); ScreenSaverChangePassword(hParent); } return 0; case '-': case '/': case ' ': default: break; } } LaunchConfig(); return 0; } static void LaunchConfig(void) { /* FIXME: should this be called */ RegisterDialogClasses(hMainInstance); /* display configure dialog */ DialogBox(hMainInstance, MAKEINTRESOURCE(DLG_SCRNSAVECONFIGURE), GetForegroundWindow(), (DLGPROC) ScreenSaverConfigureDialog); } static int LaunchScreenSaver(HWND hParent) { BOOL foo; UINT style; RECT rc; MSG msg; /* don't allow other tasks to get into the foreground */ if (w95 && !fChildPreview) SystemParametersInfo(SPI_SCREENSAVERRUNNING, TRUE, &foo, 0); msg.wParam = 0; /* register classes, both user defined and classes used by screen saver library */ if (!RegisterClasses()) { MessageBox(NULL, TEXT("RegisterClasses() failed"), NULL, MB_ICONHAND); goto restore; } /* a slightly different approach needs to be used when displaying in a preview window */ if (hParent) { style = WS_CHILD; GetClientRect(hParent, &rc); } else { style = WS_POPUP; rc.left = GetSystemMetrics(SM_XVIRTUALSCREEN); rc.top = GetSystemMetrics(SM_YVIRTUALSCREEN); rc.right = GetSystemMetrics(SM_CXVIRTUALSCREEN); rc.bottom = GetSystemMetrics(SM_CYVIRTUALSCREEN); style |= WS_VISIBLE; } /* create main screen saver window */ hMainWindow = CreateWindowEx(hParent ? 0 : WS_EX_TOPMOST, CLASS_SCRNSAVE, TEXT("SCREENSAVER"), style, rc.left, rc.top, rc.right, rc.bottom, hParent, NULL, hMainInstance, NULL); /* display window and start pumping messages */ if (hMainWindow) { UpdateWindow(hMainWindow); ShowWindow(hMainWindow, SW_SHOW); while (GetMessage(&msg, NULL, 0, 0) == TRUE) { TranslateMessage(&msg); DispatchMessage(&msg); } } restore: /* restore system */ if (w95 && !fChildPreview) SystemParametersInfo(SPI_SCREENSAVERRUNNING, FALSE, &foo, 0); FreeLibrary(hPwdLib); return msg.wParam; } /* this function takes care of *must* do tasks, like terminating screen saver */ static LRESULT WINAPI SysScreenSaverProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CREATE: if (!fChildPreview) SetCursor(NULL); /* mouse is not supposed to move from this position */ GetCursorPos(&pt_orig); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_TIMER: if (closing) return 0; break; case WM_PAINT: if (closing) return DefWindowProc(hWnd, msg, wParam, lParam); break; case WM_SYSCOMMAND: if (!fChildPreview) switch (wParam) { case SC_CLOSE: case SC_SCREENSAVE: case SC_NEXTWINDOW: case SC_PREVWINDOW: return FALSE; } break; case WM_MOUSEMOVE: case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: case WM_KEYDOWN: case WM_SYSKEYDOWN: case WM_NCACTIVATE: case WM_ACTIVATE: case WM_ACTIVATEAPP: if (closing) return DefWindowProc(hWnd, msg, wParam, lParam); break; } return ScreenSaverProc(hWnd, msg, wParam, lParam); } LONG WINAPI DefScreenSaverProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { /* don't do any special processing when in preview mode */ if (fChildPreview || closing) return DefWindowProc(hWnd, msg, wParam, lParam); switch (msg) { case WM_CLOSE: TerminateScreenSaver(hWnd); /* do NOT pass this to DefWindowProc; it will terminate even if an invalid password was given. */ return 0; case SCRM_VERIFYPW: /* verify password or return TRUE if password checking is turned off */ if (VerifyScreenSavePwd) return VerifyScreenSavePwd(hWnd); else return TRUE; case WM_SETCURSOR: if (checking_pwd) break; SetCursor(NULL); return TRUE; case WM_NCACTIVATE: case WM_ACTIVATE: case WM_ACTIVATEAPP: if (wParam != FALSE) break; case WM_MOUSEMOVE: { POINT pt; GetCursorPos(&pt); if (pt.x == pt_orig.x && pt.y == pt_orig.y) break; } case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: case WM_KEYDOWN: case WM_SYSKEYDOWN: /* try to terminate screen saver */ if (!checking_pwd) PostMessage(hWnd, WM_CLOSE, 0, 0); break; } return DefWindowProc(hWnd, msg, wParam, lParam); } static void TerminateScreenSaver(HWND hWnd) { /* don't allow recursion */ if (checking_pwd || closing) return; /* verify password */ if (VerifyScreenSavePwd) { checking_pwd = TRUE; closing = SendMessage(hWnd, SCRM_VERIFYPW, 0, 0); checking_pwd = FALSE; } else closing = TRUE; /* are we closing? */ if (closing) { DestroyWindow(hWnd); } else GetCursorPos(&pt_orig); /* if not: get new mouse position */ } /* Register screen saver window class and call user supplied hook. */ static BOOL RegisterClasses(void) { WNDCLASS cls; cls.hCursor = NULL; cls.hIcon = LoadIcon(hMainInstance, MAKEINTATOM(ID_APP)); cls.lpszMenuName = NULL; cls.lpszClassName = CLASS_SCRNSAVE; cls.hbrBackground = GetStockObject(BLACK_BRUSH); cls.hInstance = hMainInstance; cls.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_PARENTDC; cls.lpfnWndProc = (WNDPROC) SysScreenSaverProc; cls.cbWndExtra = 0; cls.cbClsExtra = 0; if (!RegisterClass(&cls)) return FALSE; return RegisterDialogClasses(hMainInstance); } void WINAPI ScreenSaverChangePassword(HWND hParent) { /* load Master Password Router (MPR) */ HINSTANCE hMpr = LoadLibrary(TEXT("MPR.DLL")); if (hMpr) { CHPWDPROC ChangePassword; ChangePassword = (CHPWDPROC) GetProcAddress(hMpr, szPwdChangePassword); /* change password for screen saver provider */ if (ChangePassword) ChangePassword(TEXT("SCRSAVE"), hParent, 0, NULL); FreeLibrary(hMpr); } } #endif
the_stack_data/1225512.c
// KMSAN: kernel-infoleak in vmx_get_nested_state // https://syzkaller.appspot.com/bug?id=5199b695d40ee67d4754c9f4c2e7c7a59256bd8d // status:fixed // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include <arpa/inet.h> #include <endian.h> #include <errno.h> #include <fcntl.h> #include <net/if.h> #include <net/if_arp.h> #include <netinet/in.h> #include <pthread.h> #include <sched.h> #include <setjmp.h> #include <signal.h> #include <stdarg.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <sys/mount.h> #include <sys/prctl.h> #include <sys/resource.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/time.h> #include <sys/types.h> #include <sys/uio.h> #include <sys/wait.h> #include <time.h> #include <unistd.h> #include <linux/futex.h> #include <linux/if_addr.h> #include <linux/if_ether.h> #include <linux/if_link.h> #include <linux/if_tun.h> #include <linux/in6.h> #include <linux/ip.h> #include <linux/kvm.h> #include <linux/neighbour.h> #include <linux/net.h> #include <linux/netlink.h> #include <linux/rtnetlink.h> #include <linux/tcp.h> #include <linux/veth.h> unsigned long long procid; static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ { \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { int state; } event_t; static void event_init(event_t* ev) { ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { if (ev->state) exit(1); __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG); } static void event_wait(event_t* ev) { while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0); } static int event_isset(event_t* ev) { return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE); } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; for (;;) { uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts); if (__atomic_load_n(&ev->state, __ATOMIC_RELAXED)) return 1; now = current_time_ms(); if (now - start > timeout) return 0; } } static bool write_file(const char* file, const char* what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } static struct { char* pos; int nesting; struct nlattr* nested[8]; char buf[1024]; } nlmsg; static void netlink_init(int typ, int flags, const void* data, int size) { memset(&nlmsg, 0, sizeof(nlmsg)); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg.buf; hdr->nlmsg_type = typ; hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags; memcpy(hdr + 1, data, size); nlmsg.pos = (char*)(hdr + 1) + NLMSG_ALIGN(size); } static void netlink_attr(int typ, const void* data, int size) { struct nlattr* attr = (struct nlattr*)nlmsg.pos; attr->nla_len = sizeof(*attr) + size; attr->nla_type = typ; memcpy(attr + 1, data, size); nlmsg.pos += NLMSG_ALIGN(attr->nla_len); } static void netlink_nest(int typ) { struct nlattr* attr = (struct nlattr*)nlmsg.pos; attr->nla_type = typ; nlmsg.pos += sizeof(*attr); nlmsg.nested[nlmsg.nesting++] = attr; } static void netlink_done(void) { struct nlattr* attr = nlmsg.nested[--nlmsg.nesting]; attr->nla_len = nlmsg.pos - (char*)attr; } static int netlink_send(int sock) { if (nlmsg.pos > nlmsg.buf + sizeof(nlmsg.buf) || nlmsg.nesting) exit(1); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg.buf; hdr->nlmsg_len = nlmsg.pos - nlmsg.buf; struct sockaddr_nl addr; memset(&addr, 0, sizeof(addr)); addr.nl_family = AF_NETLINK; unsigned n = sendto(sock, nlmsg.buf, hdr->nlmsg_len, 0, (struct sockaddr*)&addr, sizeof(addr)); if (n != hdr->nlmsg_len) exit(1); n = recv(sock, nlmsg.buf, sizeof(nlmsg.buf), 0); if (n < sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr)) exit(1); if (hdr->nlmsg_type != NLMSG_ERROR) exit(1); return -((struct nlmsgerr*)(hdr + 1))->error; } static void netlink_add_device_impl(const char* type, const char* name) { struct ifinfomsg hdr; memset(&hdr, 0, sizeof(hdr)); netlink_init(RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr)); if (name) netlink_attr(IFLA_IFNAME, name, strlen(name)); netlink_nest(IFLA_LINKINFO); netlink_attr(IFLA_INFO_KIND, type, strlen(type)); } static void netlink_add_device(int sock, const char* type, const char* name) { netlink_add_device_impl(type, name); netlink_done(); int err = netlink_send(sock); (void)err; } static void netlink_add_veth(int sock, const char* name, const char* peer) { netlink_add_device_impl("veth", name); netlink_nest(IFLA_INFO_DATA); netlink_nest(VETH_INFO_PEER); nlmsg.pos += sizeof(struct ifinfomsg); netlink_attr(IFLA_IFNAME, peer, strlen(peer)); netlink_done(); netlink_done(); netlink_done(); int err = netlink_send(sock); (void)err; } static void netlink_add_hsr(int sock, const char* name, const char* slave1, const char* slave2) { netlink_add_device_impl("hsr", name); netlink_nest(IFLA_INFO_DATA); int ifindex1 = if_nametoindex(slave1); netlink_attr(IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1)); int ifindex2 = if_nametoindex(slave2); netlink_attr(IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2)); netlink_done(); netlink_done(); int err = netlink_send(sock); (void)err; } static void netlink_device_change(int sock, const char* name, bool up, const char* master, const void* mac, int macsize) { struct ifinfomsg hdr; memset(&hdr, 0, sizeof(hdr)); if (up) hdr.ifi_flags = hdr.ifi_change = IFF_UP; netlink_init(RTM_NEWLINK, 0, &hdr, sizeof(hdr)); netlink_attr(IFLA_IFNAME, name, strlen(name)); if (master) { int ifindex = if_nametoindex(master); netlink_attr(IFLA_MASTER, &ifindex, sizeof(ifindex)); } if (macsize) netlink_attr(IFLA_ADDRESS, mac, macsize); int err = netlink_send(sock); (void)err; } static int netlink_add_addr(int sock, const char* dev, const void* addr, int addrsize) { struct ifaddrmsg hdr; memset(&hdr, 0, sizeof(hdr)); hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6; hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120; hdr.ifa_scope = RT_SCOPE_UNIVERSE; hdr.ifa_index = if_nametoindex(dev); netlink_init(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr, sizeof(hdr)); netlink_attr(IFA_LOCAL, addr, addrsize); netlink_attr(IFA_ADDRESS, addr, addrsize); return netlink_send(sock); } static void netlink_add_addr4(int sock, const char* dev, const char* addr) { struct in_addr in_addr; inet_pton(AF_INET, addr, &in_addr); int err = netlink_add_addr(sock, dev, &in_addr, sizeof(in_addr)); (void)err; } static void netlink_add_addr6(int sock, const char* dev, const char* addr) { struct in6_addr in6_addr; inet_pton(AF_INET6, addr, &in6_addr); int err = netlink_add_addr(sock, dev, &in6_addr, sizeof(in6_addr)); (void)err; } static void netlink_add_neigh(int sock, const char* name, const void* addr, int addrsize, const void* mac, int macsize) { struct ndmsg hdr; memset(&hdr, 0, sizeof(hdr)); hdr.ndm_family = addrsize == 4 ? AF_INET : AF_INET6; hdr.ndm_ifindex = if_nametoindex(name); hdr.ndm_state = NUD_PERMANENT; netlink_init(RTM_NEWNEIGH, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr)); netlink_attr(NDA_DST, addr, addrsize); netlink_attr(NDA_LLADDR, mac, macsize); int err = netlink_send(sock); (void)err; } static int tunfd = -1; static int tun_frags_enabled; #define SYZ_TUN_MAX_PACKET_SIZE 1000 #define TUN_IFACE "syz_tun" #define LOCAL_MAC 0xaaaaaaaaaaaa #define REMOTE_MAC 0xaaaaaaaaaabb #define LOCAL_IPV4 "172.20.20.170" #define REMOTE_IPV4 "172.20.20.187" #define LOCAL_IPV6 "fe80::aa" #define REMOTE_IPV6 "fe80::bb" #define IFF_NAPI 0x0010 #define IFF_NAPI_FRAGS 0x0020 static void initialize_tun(void) { tunfd = open("/dev/net/tun", O_RDWR | O_NONBLOCK); if (tunfd == -1) { printf("tun: can't open /dev/net/tun: please enable CONFIG_TUN=y\n"); printf("otherwise fuzzing or reproducing might not work as intended\n"); return; } const int kTunFd = 240; if (dup2(tunfd, kTunFd) < 0) exit(1); close(tunfd); tunfd = kTunFd; struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, TUN_IFACE, IFNAMSIZ); ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_NAPI | IFF_NAPI_FRAGS; if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) { ifr.ifr_flags = IFF_TAP | IFF_NO_PI; if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) exit(1); } if (ioctl(tunfd, TUNGETIFF, (void*)&ifr) < 0) exit(1); tun_frags_enabled = (ifr.ifr_flags & IFF_NAPI_FRAGS) != 0; char sysctl[64]; sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/accept_dad", TUN_IFACE); write_file(sysctl, "0"); sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/router_solicitations", TUN_IFACE); write_file(sysctl, "0"); int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); netlink_add_addr4(sock, TUN_IFACE, LOCAL_IPV4); netlink_add_addr6(sock, TUN_IFACE, LOCAL_IPV6); uint64_t macaddr = REMOTE_MAC; struct in_addr in_addr; inet_pton(AF_INET, REMOTE_IPV4, &in_addr); netlink_add_neigh(sock, TUN_IFACE, &in_addr, sizeof(in_addr), &macaddr, ETH_ALEN); struct in6_addr in6_addr; inet_pton(AF_INET6, REMOTE_IPV6, &in6_addr); netlink_add_neigh(sock, TUN_IFACE, &in6_addr, sizeof(in6_addr), &macaddr, ETH_ALEN); macaddr = LOCAL_MAC; netlink_device_change(sock, TUN_IFACE, true, 0, &macaddr, ETH_ALEN); close(sock); } #define DEV_IPV4 "172.20.20.%d" #define DEV_IPV6 "fe80::%02hx" #define DEV_MAC 0x00aaaaaaaaaa static void initialize_netdevices(void) { char netdevsim[16]; sprintf(netdevsim, "netdevsim%d", (int)procid); struct { const char* type; const char* dev; } devtypes[] = { {"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"}, {"vcan", "vcan0"}, {"bond", "bond0"}, {"team", "team0"}, {"dummy", "dummy0"}, {"nlmon", "nlmon0"}, {"caif", "caif0"}, {"batadv", "batadv0"}, {"vxcan", "vxcan1"}, {"netdevsim", netdevsim}, {"veth", 0}, }; const char* devmasters[] = {"bridge", "bond", "team"}; struct { const char* name; int macsize; bool noipv6; } devices[] = { {"lo", ETH_ALEN}, {"sit0", 0}, {"bridge0", ETH_ALEN}, {"vcan0", 0, true}, {"tunl0", 0}, {"gre0", 0}, {"gretap0", ETH_ALEN}, {"ip_vti0", 0}, {"ip6_vti0", 0}, {"ip6tnl0", 0}, {"ip6gre0", 0}, {"ip6gretap0", ETH_ALEN}, {"erspan0", ETH_ALEN}, {"bond0", ETH_ALEN}, {"veth0", ETH_ALEN}, {"veth1", ETH_ALEN}, {"team0", ETH_ALEN}, {"veth0_to_bridge", ETH_ALEN}, {"veth1_to_bridge", ETH_ALEN}, {"veth0_to_bond", ETH_ALEN}, {"veth1_to_bond", ETH_ALEN}, {"veth0_to_team", ETH_ALEN}, {"veth1_to_team", ETH_ALEN}, {"veth0_to_hsr", ETH_ALEN}, {"veth1_to_hsr", ETH_ALEN}, {"hsr0", 0}, {"dummy0", ETH_ALEN}, {"nlmon0", 0}, {"vxcan1", 0, true}, {"caif0", ETH_ALEN}, {"batadv0", ETH_ALEN}, {netdevsim, ETH_ALEN}, }; int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); unsigned i; for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) netlink_add_device(sock, devtypes[i].type, devtypes[i].dev); for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) { char master[32], slave0[32], veth0[32], slave1[32], veth1[32]; sprintf(slave0, "%s_slave_0", devmasters[i]); sprintf(veth0, "veth0_to_%s", devmasters[i]); netlink_add_veth(sock, slave0, veth0); sprintf(slave1, "%s_slave_1", devmasters[i]); sprintf(veth1, "veth1_to_%s", devmasters[i]); netlink_add_veth(sock, slave1, veth1); sprintf(master, "%s0", devmasters[i]); netlink_device_change(sock, slave0, false, master, 0, 0); netlink_device_change(sock, slave1, false, master, 0, 0); } netlink_device_change(sock, "bridge_slave_0", true, 0, 0, 0); netlink_device_change(sock, "bridge_slave_1", true, 0, 0, 0); netlink_add_veth(sock, "hsr_slave_0", "veth0_to_hsr"); netlink_add_veth(sock, "hsr_slave_1", "veth1_to_hsr"); netlink_add_hsr(sock, "hsr0", "hsr_slave_0", "hsr_slave_1"); netlink_device_change(sock, "hsr_slave_0", true, 0, 0, 0); netlink_device_change(sock, "hsr_slave_1", true, 0, 0, 0); for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) { char addr[32]; sprintf(addr, DEV_IPV4, i + 10); netlink_add_addr4(sock, devices[i].name, addr); if (!devices[i].noipv6) { sprintf(addr, DEV_IPV6, i + 10); netlink_add_addr6(sock, devices[i].name, addr); } uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40); netlink_device_change(sock, devices[i].name, true, 0, &macaddr, devices[i].macsize); } close(sock); } static void initialize_netdevices_init(void) { int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); struct { const char* type; int macsize; bool noipv6; bool noup; } devtypes[] = { {"nr", 7, true}, {"rose", 5, true, true}, }; unsigned i; for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) { char dev[32], addr[32]; sprintf(dev, "%s%d", devtypes[i].type, (int)procid); sprintf(addr, "172.30.%d.%d", i, (int)procid + 1); netlink_add_addr4(sock, dev, addr); if (!devtypes[i].noipv6) { sprintf(addr, "fe88::%02hx:%02hx", i, (int)procid + 1); netlink_add_addr6(sock, dev, addr); } int macsize = devtypes[i].macsize; uint64_t macaddr = 0xbbbbbb + ((unsigned long long)i << (8 * (macsize - 2))) + (procid << (8 * (macsize - 1))); netlink_device_change(sock, dev, !devtypes[i].noup, 0, &macaddr, macsize); } close(sock); } const char kvm_asm16_cpl3[] = "\x0f\x20\xc0\x66\x83\xc8\x01\x0f\x22\xc0\xb8\xa0" "\x00\x0f\x00\xd8\xb8\x2b\x00\x8e\xd8\x8e\xc0\x8e" "\xe0\x8e\xe8\xbc\x00\x01\xc7\x06\x00\x01\x1d\xba" "\xc7\x06\x02\x01\x23\x00\xc7\x06\x04\x01\x00\x01" "\xc7\x06\x06\x01\x2b\x00\xcb"; const char kvm_asm32_paged[] = "\x0f\x20\xc0\x0d\x00\x00\x00\x80\x0f\x22\xc0"; const char kvm_asm32_vm86[] = "\x66\xb8\xb8\x00\x0f\x00\xd8\xea\x00\x00\x00\x00\xd0\x00"; const char kvm_asm32_paged_vm86[] = "\x0f\x20\xc0\x0d\x00\x00\x00\x80\x0f\x22" "\xc0\x66\xb8\xb8\x00\x0f\x00\xd8\xea\x00" "\x00\x00\x00\xd0\x00"; const char kvm_asm64_enable_long[] = "\x0f\x20\xc0\x0d\x00\x00\x00\x80\x0f\x22" "\xc0\xea\xde\xc0\xad\x0b\x50\x00\x48\xc7" "\xc0\xd8\x00\x00\x00\x0f\x00\xd8"; const char kvm_asm64_init_vm[] = "\x0f\x20\xc0\x0d\x00\x00\x00\x80\x0f\x22\xc0\xea\xde\xc0\xad\x0b\x50\x00" "\x48\xc7\xc0\xd8\x00\x00\x00\x0f\x00\xd8\x48\xc7\xc1\x3a\x00\x00\x00\x0f" "\x32\x48\x83\xc8\x05\x0f\x30\x0f\x20\xe0\x48\x0d\x00\x20\x00\x00\x0f\x22" "\xe0\x48\xc7\xc1\x80\x04\x00\x00\x0f\x32\x48\xc7\xc2\x00\x60\x00\x00\x89" "\x02\x48\xc7\xc2\x00\x70\x00\x00\x89\x02\x48\xc7\xc0\x00\x5f\x00\x00\xf3" "\x0f\xc7\x30\x48\xc7\xc0\x08\x5f\x00\x00\x66\x0f\xc7\x30\x0f\xc7\x30\x48" "\xc7\xc1\x81\x04\x00\x00\x0f\x32\x48\x83\xc8\x3f\x48\x21\xd0\x48\xc7\xc2" "\x00\x40\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x02\x40\x00\x00\x48\xb8\x84\x9e" "\x99\xf3\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x1e\x40\x00\x00\x48\xc7" "\xc0\x81\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc1\x83\x04\x00\x00\x0f\x32\x48" "\x0d\xff\x6f\x03\x00\x48\x21\xd0\x48\xc7\xc2\x0c\x40\x00\x00\x0f\x79\xd0" "\x48\xc7\xc1\x84\x04\x00\x00\x0f\x32\x48\x0d\xff\x17\x00\x00\x48\x21\xd0" "\x48\xc7\xc2\x12\x40\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x04\x2c\x00\x00\x48" "\xc7\xc0\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x00\x28\x00\x00\x48\xc7" "\xc0\xff\xff\xff\xff\x0f\x79\xd0\x48\xc7\xc2\x02\x0c\x00\x00\x48\xc7\xc0" "\x50\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc0\x58\x00\x00\x00\x48\xc7\xc2\x00" "\x0c\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x04\x0c\x00\x00\x0f\x79\xd0\x48\xc7" "\xc2\x06\x0c\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x08\x0c\x00\x00\x0f\x79\xd0" "\x48\xc7\xc2\x0a\x0c\x00\x00\x0f\x79\xd0\x48\xc7\xc0\xd8\x00\x00\x00\x48" "\xc7\xc2\x0c\x0c\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x02\x2c\x00\x00\x48\xc7" "\xc0\x00\x05\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x00\x4c\x00\x00\x48\xc7\xc0" "\x50\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x10\x6c\x00\x00\x48\xc7\xc0\x00" "\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x12\x6c\x00\x00\x48\xc7\xc0\x00\x00" "\x00\x00\x0f\x79\xd0\x0f\x20\xc0\x48\xc7\xc2\x00\x6c\x00\x00\x48\x89\xc0" "\x0f\x79\xd0\x0f\x20\xd8\x48\xc7\xc2\x02\x6c\x00\x00\x48\x89\xc0\x0f\x79" "\xd0\x0f\x20\xe0\x48\xc7\xc2\x04\x6c\x00\x00\x48\x89\xc0\x0f\x79\xd0\x48" "\xc7\xc2\x06\x6c\x00\x00\x48\xc7\xc0\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7" "\xc2\x08\x6c\x00\x00\x48\xc7\xc0\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2" "\x0a\x6c\x00\x00\x48\xc7\xc0\x00\x3a\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x0c" "\x6c\x00\x00\x48\xc7\xc0\x00\x10\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x0e\x6c" "\x00\x00\x48\xc7\xc0\x00\x38\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x14\x6c\x00" "\x00\x48\xc7\xc0\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x16\x6c\x00\x00" "\x48\x8b\x04\x25\x10\x5f\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x00\x00\x00\x00" "\x48\xc7\xc0\x01\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x02\x00\x00\x00\x48" "\xc7\xc0\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x00\x20\x00\x00\x48\xc7" "\xc0\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x02\x20\x00\x00\x48\xc7\xc0" "\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x04\x20\x00\x00\x48\xc7\xc0\x00" "\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x06\x20\x00\x00\x48\xc7\xc0\x00\x00" "\x00\x00\x0f\x79\xd0\x48\xc7\xc1\x77\x02\x00\x00\x0f\x32\x48\xc1\xe2\x20" "\x48\x09\xd0\x48\xc7\xc2\x00\x2c\x00\x00\x48\x89\xc0\x0f\x79\xd0\x48\xc7" "\xc2\x04\x40\x00\x00\x48\xc7\xc0\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2" "\x0a\x40\x00\x00\x48\xc7\xc0\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x0e" "\x40\x00\x00\x48\xc7\xc0\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x10\x40" "\x00\x00\x48\xc7\xc0\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x16\x40\x00" "\x00\x48\xc7\xc0\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x14\x40\x00\x00" "\x48\xc7\xc0\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x00\x60\x00\x00\x48" "\xc7\xc0\xff\xff\xff\xff\x0f\x79\xd0\x48\xc7\xc2\x02\x60\x00\x00\x48\xc7" "\xc0\xff\xff\xff\xff\x0f\x79\xd0\x48\xc7\xc2\x1c\x20\x00\x00\x48\xc7\xc0" "\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x1e\x20\x00\x00\x48\xc7\xc0\x00" "\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x20\x20\x00\x00\x48\xc7\xc0\x00\x00" "\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x22\x20\x00\x00\x48\xc7\xc0\x00\x00\x00" "\x00\x0f\x79\xd0\x48\xc7\xc2\x00\x08\x00\x00\x48\xc7\xc0\x58\x00\x00\x00" "\x0f\x79\xd0\x48\xc7\xc2\x02\x08\x00\x00\x48\xc7\xc0\x50\x00\x00\x00\x0f" "\x79\xd0\x48\xc7\xc2\x04\x08\x00\x00\x48\xc7\xc0\x58\x00\x00\x00\x0f\x79" "\xd0\x48\xc7\xc2\x06\x08\x00\x00\x48\xc7\xc0\x58\x00\x00\x00\x0f\x79\xd0" "\x48\xc7\xc2\x08\x08\x00\x00\x48\xc7\xc0\x58\x00\x00\x00\x0f\x79\xd0\x48" "\xc7\xc2\x0a\x08\x00\x00\x48\xc7\xc0\x58\x00\x00\x00\x0f\x79\xd0\x48\xc7" "\xc2\x0c\x08\x00\x00\x48\xc7\xc0\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2" "\x0e\x08\x00\x00\x48\xc7\xc0\xd8\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x12" "\x68\x00\x00\x48\xc7\xc0\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x14\x68" "\x00\x00\x48\xc7\xc0\x00\x3a\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x16\x68\x00" "\x00\x48\xc7\xc0\x00\x10\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x18\x68\x00\x00" "\x48\xc7\xc0\x00\x38\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x00\x48\x00\x00\x48" "\xc7\xc0\xff\xff\x0f\x00\x0f\x79\xd0\x48\xc7\xc2\x02\x48\x00\x00\x48\xc7" "\xc0\xff\xff\x0f\x00\x0f\x79\xd0\x48\xc7\xc2\x04\x48\x00\x00\x48\xc7\xc0" "\xff\xff\x0f\x00\x0f\x79\xd0\x48\xc7\xc2\x06\x48\x00\x00\x48\xc7\xc0\xff" "\xff\x0f\x00\x0f\x79\xd0\x48\xc7\xc2\x08\x48\x00\x00\x48\xc7\xc0\xff\xff" "\x0f\x00\x0f\x79\xd0\x48\xc7\xc2\x0a\x48\x00\x00\x48\xc7\xc0\xff\xff\x0f" "\x00\x0f\x79\xd0\x48\xc7\xc2\x0c\x48\x00\x00\x48\xc7\xc0\x00\x00\x00\x00" "\x0f\x79\xd0\x48\xc7\xc2\x0e\x48\x00\x00\x48\xc7\xc0\xff\x1f\x00\x00\x0f" "\x79\xd0\x48\xc7\xc2\x10\x48\x00\x00\x48\xc7\xc0\xff\x1f\x00\x00\x0f\x79" "\xd0\x48\xc7\xc2\x12\x48\x00\x00\x48\xc7\xc0\xff\x1f\x00\x00\x0f\x79\xd0" "\x48\xc7\xc2\x14\x48\x00\x00\x48\xc7\xc0\x93\x40\x00\x00\x0f\x79\xd0\x48" "\xc7\xc2\x16\x48\x00\x00\x48\xc7\xc0\x9b\x20\x00\x00\x0f\x79\xd0\x48\xc7" "\xc2\x18\x48\x00\x00\x48\xc7\xc0\x93\x40\x00\x00\x0f\x79\xd0\x48\xc7\xc2" "\x1a\x48\x00\x00\x48\xc7\xc0\x93\x40\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x1c" "\x48\x00\x00\x48\xc7\xc0\x93\x40\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x1e\x48" "\x00\x00\x48\xc7\xc0\x93\x40\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x20\x48\x00" "\x00\x48\xc7\xc0\x82\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x22\x48\x00\x00" "\x48\xc7\xc0\x8b\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x1c\x68\x00\x00\x48" "\xc7\xc0\x00\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x1e\x68\x00\x00\x48\xc7" "\xc0\x00\x91\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x20\x68\x00\x00\x48\xc7\xc0" "\x02\x00\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x06\x28\x00\x00\x48\xc7\xc0\x00" "\x05\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x0a\x28\x00\x00\x48\xc7\xc0\x00\x00" "\x00\x00\x0f\x79\xd0\x48\xc7\xc2\x0c\x28\x00\x00\x48\xc7\xc0\x00\x00\x00" "\x00\x0f\x79\xd0\x48\xc7\xc2\x0e\x28\x00\x00\x48\xc7\xc0\x00\x00\x00\x00" "\x0f\x79\xd0\x48\xc7\xc2\x10\x28\x00\x00\x48\xc7\xc0\x00\x00\x00\x00\x0f" "\x79\xd0\x0f\x20\xc0\x48\xc7\xc2\x00\x68\x00\x00\x48\x89\xc0\x0f\x79\xd0" "\x0f\x20\xd8\x48\xc7\xc2\x02\x68\x00\x00\x48\x89\xc0\x0f\x79\xd0\x0f\x20" "\xe0\x48\xc7\xc2\x04\x68\x00\x00\x48\x89\xc0\x0f\x79\xd0\x48\xc7\xc0\x18" "\x5f\x00\x00\x48\x8b\x10\x48\xc7\xc0\x20\x5f\x00\x00\x48\x8b\x08\x48\x31" "\xc0\x0f\x78\xd0\x48\x31\xc8\x0f\x79\xd0\x0f\x01\xc2\x48\xc7\xc2\x00\x44" "\x00\x00\x0f\x78\xd0\xf4"; const char kvm_asm64_vm_exit[] = "\x48\xc7\xc3\x00\x44\x00\x00\x0f\x78\xda\x48" "\xc7\xc3\x02\x44\x00\x00\x0f\x78\xd9\x48\xc7" "\xc0\x00\x64\x00\x00\x0f\x78\xc0\x48\xc7\xc3" "\x1e\x68\x00\x00\x0f\x78\xdb\xf4"; const char kvm_asm64_cpl3[] = "\x0f\x20\xc0\x0d\x00\x00\x00\x80\x0f\x22\xc0\xea\xde\xc0\xad\x0b\x50\x00" "\x48\xc7\xc0\xd8\x00\x00\x00\x0f\x00\xd8\x48\xc7\xc0\x6b\x00\x00\x00\x8e" "\xd8\x8e\xc0\x8e\xe0\x8e\xe8\x48\xc7\xc4\x80\x0f\x00\x00\x48\xc7\x04\x24" "\x1d\xba\x00\x00\x48\xc7\x44\x24\x04\x63\x00\x00\x00\x48\xc7\x44\x24\x08" "\x80\x0f\x00\x00\x48\xc7\x44\x24\x0c\x6b\x00\x00\x00\xcb"; #define ADDR_TEXT 0x0000 #define ADDR_GDT 0x1000 #define ADDR_LDT 0x1800 #define ADDR_PML4 0x2000 #define ADDR_PDP 0x3000 #define ADDR_PD 0x4000 #define ADDR_STACK0 0x0f80 #define ADDR_VAR_HLT 0x2800 #define ADDR_VAR_SYSRET 0x2808 #define ADDR_VAR_SYSEXIT 0x2810 #define ADDR_VAR_IDT 0x3800 #define ADDR_VAR_TSS64 0x3a00 #define ADDR_VAR_TSS64_CPL3 0x3c00 #define ADDR_VAR_TSS16 0x3d00 #define ADDR_VAR_TSS16_2 0x3e00 #define ADDR_VAR_TSS16_CPL3 0x3f00 #define ADDR_VAR_TSS32 0x4800 #define ADDR_VAR_TSS32_2 0x4a00 #define ADDR_VAR_TSS32_CPL3 0x4c00 #define ADDR_VAR_TSS32_VM86 0x4e00 #define ADDR_VAR_VMXON_PTR 0x5f00 #define ADDR_VAR_VMCS_PTR 0x5f08 #define ADDR_VAR_VMEXIT_PTR 0x5f10 #define ADDR_VAR_VMWRITE_FLD 0x5f18 #define ADDR_VAR_VMWRITE_VAL 0x5f20 #define ADDR_VAR_VMXON 0x6000 #define ADDR_VAR_VMCS 0x7000 #define ADDR_VAR_VMEXIT_CODE 0x9000 #define ADDR_VAR_USER_CODE 0x9100 #define ADDR_VAR_USER_CODE2 0x9120 #define SEL_LDT (1 << 3) #define SEL_CS16 (2 << 3) #define SEL_DS16 (3 << 3) #define SEL_CS16_CPL3 ((4 << 3) + 3) #define SEL_DS16_CPL3 ((5 << 3) + 3) #define SEL_CS32 (6 << 3) #define SEL_DS32 (7 << 3) #define SEL_CS32_CPL3 ((8 << 3) + 3) #define SEL_DS32_CPL3 ((9 << 3) + 3) #define SEL_CS64 (10 << 3) #define SEL_DS64 (11 << 3) #define SEL_CS64_CPL3 ((12 << 3) + 3) #define SEL_DS64_CPL3 ((13 << 3) + 3) #define SEL_CGATE16 (14 << 3) #define SEL_TGATE16 (15 << 3) #define SEL_CGATE32 (16 << 3) #define SEL_TGATE32 (17 << 3) #define SEL_CGATE64 (18 << 3) #define SEL_CGATE64_HI (19 << 3) #define SEL_TSS16 (20 << 3) #define SEL_TSS16_2 (21 << 3) #define SEL_TSS16_CPL3 ((22 << 3) + 3) #define SEL_TSS32 (23 << 3) #define SEL_TSS32_2 (24 << 3) #define SEL_TSS32_CPL3 ((25 << 3) + 3) #define SEL_TSS32_VM86 (26 << 3) #define SEL_TSS64 (27 << 3) #define SEL_TSS64_HI (28 << 3) #define SEL_TSS64_CPL3 ((29 << 3) + 3) #define SEL_TSS64_CPL3_HI (30 << 3) #define MSR_IA32_FEATURE_CONTROL 0x3a #define MSR_IA32_VMX_BASIC 0x480 #define MSR_IA32_SMBASE 0x9e #define MSR_IA32_SYSENTER_CS 0x174 #define MSR_IA32_SYSENTER_ESP 0x175 #define MSR_IA32_SYSENTER_EIP 0x176 #define MSR_IA32_STAR 0xC0000081 #define MSR_IA32_LSTAR 0xC0000082 #define MSR_IA32_VMX_PROCBASED_CTLS2 0x48B #define NEXT_INSN $0xbadc0de #define PREFIX_SIZE 0xba1d #define KVM_SMI _IO(KVMIO, 0xb7) #define CR0_PE 1 #define CR0_MP (1 << 1) #define CR0_EM (1 << 2) #define CR0_TS (1 << 3) #define CR0_ET (1 << 4) #define CR0_NE (1 << 5) #define CR0_WP (1 << 16) #define CR0_AM (1 << 18) #define CR0_NW (1 << 29) #define CR0_CD (1 << 30) #define CR0_PG (1 << 31) #define CR4_VME 1 #define CR4_PVI (1 << 1) #define CR4_TSD (1 << 2) #define CR4_DE (1 << 3) #define CR4_PSE (1 << 4) #define CR4_PAE (1 << 5) #define CR4_MCE (1 << 6) #define CR4_PGE (1 << 7) #define CR4_PCE (1 << 8) #define CR4_OSFXSR (1 << 8) #define CR4_OSXMMEXCPT (1 << 10) #define CR4_UMIP (1 << 11) #define CR4_VMXE (1 << 13) #define CR4_SMXE (1 << 14) #define CR4_FSGSBASE (1 << 16) #define CR4_PCIDE (1 << 17) #define CR4_OSXSAVE (1 << 18) #define CR4_SMEP (1 << 20) #define CR4_SMAP (1 << 21) #define CR4_PKE (1 << 22) #define EFER_SCE 1 #define EFER_LME (1 << 8) #define EFER_LMA (1 << 10) #define EFER_NXE (1 << 11) #define EFER_SVME (1 << 12) #define EFER_LMSLE (1 << 13) #define EFER_FFXSR (1 << 14) #define EFER_TCE (1 << 15) #define PDE32_PRESENT 1 #define PDE32_RW (1 << 1) #define PDE32_USER (1 << 2) #define PDE32_PS (1 << 7) #define PDE64_PRESENT 1 #define PDE64_RW (1 << 1) #define PDE64_USER (1 << 2) #define PDE64_ACCESSED (1 << 5) #define PDE64_DIRTY (1 << 6) #define PDE64_PS (1 << 7) #define PDE64_G (1 << 8) struct tss16 { uint16_t prev; uint16_t sp0; uint16_t ss0; uint16_t sp1; uint16_t ss1; uint16_t sp2; uint16_t ss2; uint16_t ip; uint16_t flags; uint16_t ax; uint16_t cx; uint16_t dx; uint16_t bx; uint16_t sp; uint16_t bp; uint16_t si; uint16_t di; uint16_t es; uint16_t cs; uint16_t ss; uint16_t ds; uint16_t ldt; } __attribute__((packed)); struct tss32 { uint16_t prev, prevh; uint32_t sp0; uint16_t ss0, ss0h; uint32_t sp1; uint16_t ss1, ss1h; uint32_t sp2; uint16_t ss2, ss2h; uint32_t cr3; uint32_t ip; uint32_t flags; uint32_t ax; uint32_t cx; uint32_t dx; uint32_t bx; uint32_t sp; uint32_t bp; uint32_t si; uint32_t di; uint16_t es, esh; uint16_t cs, csh; uint16_t ss, ssh; uint16_t ds, dsh; uint16_t fs, fsh; uint16_t gs, gsh; uint16_t ldt, ldth; uint16_t trace; uint16_t io_bitmap; } __attribute__((packed)); struct tss64 { uint32_t reserved0; uint64_t rsp[3]; uint64_t reserved1; uint64_t ist[7]; uint64_t reserved2; uint32_t reserved3; uint32_t io_bitmap; } __attribute__((packed)); static void fill_segment_descriptor(uint64_t* dt, uint64_t* lt, struct kvm_segment* seg) { uint16_t index = seg->selector >> 3; uint64_t limit = seg->g ? seg->limit >> 12 : seg->limit; uint64_t sd = (limit & 0xffff) | (seg->base & 0xffffff) << 16 | (uint64_t)seg->type << 40 | (uint64_t)seg->s << 44 | (uint64_t)seg->dpl << 45 | (uint64_t)seg->present << 47 | (limit & 0xf0000ULL) << 48 | (uint64_t)seg->avl << 52 | (uint64_t)seg->l << 53 | (uint64_t)seg->db << 54 | (uint64_t)seg->g << 55 | (seg->base & 0xff000000ULL) << 56; NONFAILING(dt[index] = sd); NONFAILING(lt[index] = sd); } static void fill_segment_descriptor_dword(uint64_t* dt, uint64_t* lt, struct kvm_segment* seg) { fill_segment_descriptor(dt, lt, seg); uint16_t index = seg->selector >> 3; NONFAILING(dt[index + 1] = 0); NONFAILING(lt[index + 1] = 0); } static void setup_syscall_msrs(int cpufd, uint16_t sel_cs, uint16_t sel_cs_cpl3) { char buf[sizeof(struct kvm_msrs) + 5 * sizeof(struct kvm_msr_entry)]; memset(buf, 0, sizeof(buf)); struct kvm_msrs* msrs = (struct kvm_msrs*)buf; struct kvm_msr_entry* entries = msrs->entries; msrs->nmsrs = 5; entries[0].index = MSR_IA32_SYSENTER_CS; entries[0].data = sel_cs; entries[1].index = MSR_IA32_SYSENTER_ESP; entries[1].data = ADDR_STACK0; entries[2].index = MSR_IA32_SYSENTER_EIP; entries[2].data = ADDR_VAR_SYSEXIT; entries[3].index = MSR_IA32_STAR; entries[3].data = ((uint64_t)sel_cs << 32) | ((uint64_t)sel_cs_cpl3 << 48); entries[4].index = MSR_IA32_LSTAR; entries[4].data = ADDR_VAR_SYSRET; ioctl(cpufd, KVM_SET_MSRS, msrs); } static void setup_32bit_idt(struct kvm_sregs* sregs, char* host_mem, uintptr_t guest_mem) { sregs->idt.base = guest_mem + ADDR_VAR_IDT; sregs->idt.limit = 0x1ff; uint64_t* idt = (uint64_t*)(host_mem + sregs->idt.base); int i; for (i = 0; i < 32; i++) { struct kvm_segment gate; gate.selector = i << 3; switch (i % 6) { case 0: gate.type = 6; gate.base = SEL_CS16; break; case 1: gate.type = 7; gate.base = SEL_CS16; break; case 2: gate.type = 3; gate.base = SEL_TGATE16; break; case 3: gate.type = 14; gate.base = SEL_CS32; break; case 4: gate.type = 15; gate.base = SEL_CS32; break; case 6: gate.type = 11; gate.base = SEL_TGATE32; break; } gate.limit = guest_mem + ADDR_VAR_USER_CODE2; gate.present = 1; gate.dpl = 0; gate.s = 0; gate.g = 0; gate.db = 0; gate.l = 0; gate.avl = 0; fill_segment_descriptor(idt, idt, &gate); } } static void setup_64bit_idt(struct kvm_sregs* sregs, char* host_mem, uintptr_t guest_mem) { sregs->idt.base = guest_mem + ADDR_VAR_IDT; sregs->idt.limit = 0x1ff; uint64_t* idt = (uint64_t*)(host_mem + sregs->idt.base); int i; for (i = 0; i < 32; i++) { struct kvm_segment gate; gate.selector = (i * 2) << 3; gate.type = (i & 1) ? 14 : 15; gate.base = SEL_CS64; gate.limit = guest_mem + ADDR_VAR_USER_CODE2; gate.present = 1; gate.dpl = 0; gate.s = 0; gate.g = 0; gate.db = 0; gate.l = 0; gate.avl = 0; fill_segment_descriptor_dword(idt, idt, &gate); } } struct kvm_text { uintptr_t typ; const void* text; uintptr_t size; }; struct kvm_opt { uint64_t typ; uint64_t val; }; #define KVM_SETUP_PAGING (1 << 0) #define KVM_SETUP_PAE (1 << 1) #define KVM_SETUP_PROTECTED (1 << 2) #define KVM_SETUP_CPL3 (1 << 3) #define KVM_SETUP_VIRT86 (1 << 4) #define KVM_SETUP_SMM (1 << 5) #define KVM_SETUP_VM (1 << 6) static uintptr_t syz_kvm_setup_cpu(uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6, uintptr_t a7) { const int vmfd = a0; const int cpufd = a1; char* const host_mem = (char*)a2; const struct kvm_text* const text_array_ptr = (struct kvm_text*)a3; const uintptr_t text_count = a4; const uintptr_t flags = a5; const struct kvm_opt* const opt_array_ptr = (struct kvm_opt*)a6; uintptr_t opt_count = a7; const uintptr_t page_size = 4 << 10; const uintptr_t ioapic_page = 10; const uintptr_t guest_mem_size = 24 * page_size; const uintptr_t guest_mem = 0; (void)text_count; int text_type = 0; const void* text = 0; uintptr_t text_size = 0; NONFAILING(text_type = text_array_ptr[0].typ); NONFAILING(text = text_array_ptr[0].text); NONFAILING(text_size = text_array_ptr[0].size); uintptr_t i; for (i = 0; i < guest_mem_size / page_size; i++) { struct kvm_userspace_memory_region memreg; memreg.slot = i; memreg.flags = 0; memreg.guest_phys_addr = guest_mem + i * page_size; if (i == ioapic_page) memreg.guest_phys_addr = 0xfec00000; memreg.memory_size = page_size; memreg.userspace_addr = (uintptr_t)host_mem + i * page_size; ioctl(vmfd, KVM_SET_USER_MEMORY_REGION, &memreg); } struct kvm_userspace_memory_region memreg; memreg.slot = 1 + (1 << 16); memreg.flags = 0; memreg.guest_phys_addr = 0x30000; memreg.memory_size = 64 << 10; memreg.userspace_addr = (uintptr_t)host_mem; ioctl(vmfd, KVM_SET_USER_MEMORY_REGION, &memreg); struct kvm_sregs sregs; if (ioctl(cpufd, KVM_GET_SREGS, &sregs)) return -1; struct kvm_regs regs; memset(&regs, 0, sizeof(regs)); regs.rip = guest_mem + ADDR_TEXT; regs.rsp = ADDR_STACK0; sregs.gdt.base = guest_mem + ADDR_GDT; sregs.gdt.limit = 256 * sizeof(uint64_t) - 1; uint64_t* gdt = (uint64_t*)(host_mem + sregs.gdt.base); struct kvm_segment seg_ldt; seg_ldt.selector = SEL_LDT; seg_ldt.type = 2; seg_ldt.base = guest_mem + ADDR_LDT; seg_ldt.limit = 256 * sizeof(uint64_t) - 1; seg_ldt.present = 1; seg_ldt.dpl = 0; seg_ldt.s = 0; seg_ldt.g = 0; seg_ldt.db = 1; seg_ldt.l = 0; sregs.ldt = seg_ldt; uint64_t* ldt = (uint64_t*)(host_mem + sregs.ldt.base); struct kvm_segment seg_cs16; seg_cs16.selector = SEL_CS16; seg_cs16.type = 11; seg_cs16.base = 0; seg_cs16.limit = 0xfffff; seg_cs16.present = 1; seg_cs16.dpl = 0; seg_cs16.s = 1; seg_cs16.g = 0; seg_cs16.db = 0; seg_cs16.l = 0; struct kvm_segment seg_ds16 = seg_cs16; seg_ds16.selector = SEL_DS16; seg_ds16.type = 3; struct kvm_segment seg_cs16_cpl3 = seg_cs16; seg_cs16_cpl3.selector = SEL_CS16_CPL3; seg_cs16_cpl3.dpl = 3; struct kvm_segment seg_ds16_cpl3 = seg_ds16; seg_ds16_cpl3.selector = SEL_DS16_CPL3; seg_ds16_cpl3.dpl = 3; struct kvm_segment seg_cs32 = seg_cs16; seg_cs32.selector = SEL_CS32; seg_cs32.db = 1; struct kvm_segment seg_ds32 = seg_ds16; seg_ds32.selector = SEL_DS32; seg_ds32.db = 1; struct kvm_segment seg_cs32_cpl3 = seg_cs32; seg_cs32_cpl3.selector = SEL_CS32_CPL3; seg_cs32_cpl3.dpl = 3; struct kvm_segment seg_ds32_cpl3 = seg_ds32; seg_ds32_cpl3.selector = SEL_DS32_CPL3; seg_ds32_cpl3.dpl = 3; struct kvm_segment seg_cs64 = seg_cs16; seg_cs64.selector = SEL_CS64; seg_cs64.l = 1; struct kvm_segment seg_ds64 = seg_ds32; seg_ds64.selector = SEL_DS64; struct kvm_segment seg_cs64_cpl3 = seg_cs64; seg_cs64_cpl3.selector = SEL_CS64_CPL3; seg_cs64_cpl3.dpl = 3; struct kvm_segment seg_ds64_cpl3 = seg_ds64; seg_ds64_cpl3.selector = SEL_DS64_CPL3; seg_ds64_cpl3.dpl = 3; struct kvm_segment seg_tss32; seg_tss32.selector = SEL_TSS32; seg_tss32.type = 9; seg_tss32.base = ADDR_VAR_TSS32; seg_tss32.limit = 0x1ff; seg_tss32.present = 1; seg_tss32.dpl = 0; seg_tss32.s = 0; seg_tss32.g = 0; seg_tss32.db = 0; seg_tss32.l = 0; struct kvm_segment seg_tss32_2 = seg_tss32; seg_tss32_2.selector = SEL_TSS32_2; seg_tss32_2.base = ADDR_VAR_TSS32_2; struct kvm_segment seg_tss32_cpl3 = seg_tss32; seg_tss32_cpl3.selector = SEL_TSS32_CPL3; seg_tss32_cpl3.base = ADDR_VAR_TSS32_CPL3; struct kvm_segment seg_tss32_vm86 = seg_tss32; seg_tss32_vm86.selector = SEL_TSS32_VM86; seg_tss32_vm86.base = ADDR_VAR_TSS32_VM86; struct kvm_segment seg_tss16 = seg_tss32; seg_tss16.selector = SEL_TSS16; seg_tss16.base = ADDR_VAR_TSS16; seg_tss16.limit = 0xff; seg_tss16.type = 1; struct kvm_segment seg_tss16_2 = seg_tss16; seg_tss16_2.selector = SEL_TSS16_2; seg_tss16_2.base = ADDR_VAR_TSS16_2; seg_tss16_2.dpl = 0; struct kvm_segment seg_tss16_cpl3 = seg_tss16; seg_tss16_cpl3.selector = SEL_TSS16_CPL3; seg_tss16_cpl3.base = ADDR_VAR_TSS16_CPL3; seg_tss16_cpl3.dpl = 3; struct kvm_segment seg_tss64 = seg_tss32; seg_tss64.selector = SEL_TSS64; seg_tss64.base = ADDR_VAR_TSS64; seg_tss64.limit = 0x1ff; struct kvm_segment seg_tss64_cpl3 = seg_tss64; seg_tss64_cpl3.selector = SEL_TSS64_CPL3; seg_tss64_cpl3.base = ADDR_VAR_TSS64_CPL3; seg_tss64_cpl3.dpl = 3; struct kvm_segment seg_cgate16; seg_cgate16.selector = SEL_CGATE16; seg_cgate16.type = 4; seg_cgate16.base = SEL_CS16 | (2 << 16); seg_cgate16.limit = ADDR_VAR_USER_CODE2; seg_cgate16.present = 1; seg_cgate16.dpl = 0; seg_cgate16.s = 0; seg_cgate16.g = 0; seg_cgate16.db = 0; seg_cgate16.l = 0; seg_cgate16.avl = 0; struct kvm_segment seg_tgate16 = seg_cgate16; seg_tgate16.selector = SEL_TGATE16; seg_tgate16.type = 3; seg_cgate16.base = SEL_TSS16_2; seg_tgate16.limit = 0; struct kvm_segment seg_cgate32 = seg_cgate16; seg_cgate32.selector = SEL_CGATE32; seg_cgate32.type = 12; seg_cgate32.base = SEL_CS32 | (2 << 16); struct kvm_segment seg_tgate32 = seg_cgate32; seg_tgate32.selector = SEL_TGATE32; seg_tgate32.type = 11; seg_tgate32.base = SEL_TSS32_2; seg_tgate32.limit = 0; struct kvm_segment seg_cgate64 = seg_cgate16; seg_cgate64.selector = SEL_CGATE64; seg_cgate64.type = 12; seg_cgate64.base = SEL_CS64; int kvmfd = open("/dev/kvm", O_RDWR); char buf[sizeof(struct kvm_cpuid2) + 128 * sizeof(struct kvm_cpuid_entry2)]; memset(buf, 0, sizeof(buf)); struct kvm_cpuid2* cpuid = (struct kvm_cpuid2*)buf; cpuid->nent = 128; ioctl(kvmfd, KVM_GET_SUPPORTED_CPUID, cpuid); ioctl(cpufd, KVM_SET_CPUID2, cpuid); close(kvmfd); const char* text_prefix = 0; int text_prefix_size = 0; char* host_text = host_mem + ADDR_TEXT; if (text_type == 8) { if (flags & KVM_SETUP_SMM) { if (flags & KVM_SETUP_PROTECTED) { sregs.cs = seg_cs16; sregs.ds = sregs.es = sregs.fs = sregs.gs = sregs.ss = seg_ds16; sregs.cr0 |= CR0_PE; } else { sregs.cs.selector = 0; sregs.cs.base = 0; } NONFAILING(*(host_mem + ADDR_TEXT) = 0xf4); host_text = host_mem + 0x8000; ioctl(cpufd, KVM_SMI, 0); } else if (flags & KVM_SETUP_VIRT86) { sregs.cs = seg_cs32; sregs.ds = sregs.es = sregs.fs = sregs.gs = sregs.ss = seg_ds32; sregs.cr0 |= CR0_PE; sregs.efer |= EFER_SCE; setup_syscall_msrs(cpufd, SEL_CS32, SEL_CS32_CPL3); setup_32bit_idt(&sregs, host_mem, guest_mem); if (flags & KVM_SETUP_PAGING) { uint64_t pd_addr = guest_mem + ADDR_PD; uint64_t* pd = (uint64_t*)(host_mem + ADDR_PD); NONFAILING(pd[0] = PDE32_PRESENT | PDE32_RW | PDE32_USER | PDE32_PS); sregs.cr3 = pd_addr; sregs.cr4 |= CR4_PSE; text_prefix = kvm_asm32_paged_vm86; text_prefix_size = sizeof(kvm_asm32_paged_vm86) - 1; } else { text_prefix = kvm_asm32_vm86; text_prefix_size = sizeof(kvm_asm32_vm86) - 1; } } else { sregs.cs.selector = 0; sregs.cs.base = 0; } } else if (text_type == 16) { if (flags & KVM_SETUP_CPL3) { sregs.cs = seg_cs16; sregs.ds = sregs.es = sregs.fs = sregs.gs = sregs.ss = seg_ds16; text_prefix = kvm_asm16_cpl3; text_prefix_size = sizeof(kvm_asm16_cpl3) - 1; } else { sregs.cr0 |= CR0_PE; sregs.cs = seg_cs16; sregs.ds = sregs.es = sregs.fs = sregs.gs = sregs.ss = seg_ds16; } } else if (text_type == 32) { sregs.cr0 |= CR0_PE; sregs.efer |= EFER_SCE; setup_syscall_msrs(cpufd, SEL_CS32, SEL_CS32_CPL3); setup_32bit_idt(&sregs, host_mem, guest_mem); if (flags & KVM_SETUP_SMM) { sregs.cs = seg_cs32; sregs.ds = sregs.es = sregs.fs = sregs.gs = sregs.ss = seg_ds32; NONFAILING(*(host_mem + ADDR_TEXT) = 0xf4); host_text = host_mem + 0x8000; ioctl(cpufd, KVM_SMI, 0); } else if (flags & KVM_SETUP_PAGING) { sregs.cs = seg_cs32; sregs.ds = sregs.es = sregs.fs = sregs.gs = sregs.ss = seg_ds32; uint64_t pd_addr = guest_mem + ADDR_PD; uint64_t* pd = (uint64_t*)(host_mem + ADDR_PD); NONFAILING(pd[0] = PDE32_PRESENT | PDE32_RW | PDE32_USER | PDE32_PS); sregs.cr3 = pd_addr; sregs.cr4 |= CR4_PSE; text_prefix = kvm_asm32_paged; text_prefix_size = sizeof(kvm_asm32_paged) - 1; } else if (flags & KVM_SETUP_CPL3) { sregs.cs = seg_cs32_cpl3; sregs.ds = sregs.es = sregs.fs = sregs.gs = sregs.ss = seg_ds32_cpl3; } else { sregs.cs = seg_cs32; sregs.ds = sregs.es = sregs.fs = sregs.gs = sregs.ss = seg_ds32; } } else { sregs.efer |= EFER_LME | EFER_SCE; sregs.cr0 |= CR0_PE; setup_syscall_msrs(cpufd, SEL_CS64, SEL_CS64_CPL3); setup_64bit_idt(&sregs, host_mem, guest_mem); sregs.cs = seg_cs32; sregs.ds = sregs.es = sregs.fs = sregs.gs = sregs.ss = seg_ds32; uint64_t pml4_addr = guest_mem + ADDR_PML4; uint64_t* pml4 = (uint64_t*)(host_mem + ADDR_PML4); uint64_t pdpt_addr = guest_mem + ADDR_PDP; uint64_t* pdpt = (uint64_t*)(host_mem + ADDR_PDP); uint64_t pd_addr = guest_mem + ADDR_PD; uint64_t* pd = (uint64_t*)(host_mem + ADDR_PD); NONFAILING(pml4[0] = PDE64_PRESENT | PDE64_RW | PDE64_USER | pdpt_addr); NONFAILING(pdpt[0] = PDE64_PRESENT | PDE64_RW | PDE64_USER | pd_addr); NONFAILING(pd[0] = PDE64_PRESENT | PDE64_RW | PDE64_USER | PDE64_PS); sregs.cr3 = pml4_addr; sregs.cr4 |= CR4_PAE; if (flags & KVM_SETUP_VM) { sregs.cr0 |= CR0_NE; NONFAILING(*((uint64_t*)(host_mem + ADDR_VAR_VMXON_PTR)) = ADDR_VAR_VMXON); NONFAILING(*((uint64_t*)(host_mem + ADDR_VAR_VMCS_PTR)) = ADDR_VAR_VMCS); NONFAILING(memcpy(host_mem + ADDR_VAR_VMEXIT_CODE, kvm_asm64_vm_exit, sizeof(kvm_asm64_vm_exit) - 1)); NONFAILING(*((uint64_t*)(host_mem + ADDR_VAR_VMEXIT_PTR)) = ADDR_VAR_VMEXIT_CODE); text_prefix = kvm_asm64_init_vm; text_prefix_size = sizeof(kvm_asm64_init_vm) - 1; } else if (flags & KVM_SETUP_CPL3) { text_prefix = kvm_asm64_cpl3; text_prefix_size = sizeof(kvm_asm64_cpl3) - 1; } else { text_prefix = kvm_asm64_enable_long; text_prefix_size = sizeof(kvm_asm64_enable_long) - 1; } } struct tss16 tss16; memset(&tss16, 0, sizeof(tss16)); tss16.ss0 = tss16.ss1 = tss16.ss2 = SEL_DS16; tss16.sp0 = tss16.sp1 = tss16.sp2 = ADDR_STACK0; tss16.ip = ADDR_VAR_USER_CODE2; tss16.flags = (1 << 1); tss16.cs = SEL_CS16; tss16.es = tss16.ds = tss16.ss = SEL_DS16; tss16.ldt = SEL_LDT; struct tss16* tss16_addr = (struct tss16*)(host_mem + seg_tss16_2.base); NONFAILING(memcpy(tss16_addr, &tss16, sizeof(tss16))); memset(&tss16, 0, sizeof(tss16)); tss16.ss0 = tss16.ss1 = tss16.ss2 = SEL_DS16; tss16.sp0 = tss16.sp1 = tss16.sp2 = ADDR_STACK0; tss16.ip = ADDR_VAR_USER_CODE2; tss16.flags = (1 << 1); tss16.cs = SEL_CS16_CPL3; tss16.es = tss16.ds = tss16.ss = SEL_DS16_CPL3; tss16.ldt = SEL_LDT; struct tss16* tss16_cpl3_addr = (struct tss16*)(host_mem + seg_tss16_cpl3.base); NONFAILING(memcpy(tss16_cpl3_addr, &tss16, sizeof(tss16))); struct tss32 tss32; memset(&tss32, 0, sizeof(tss32)); tss32.ss0 = tss32.ss1 = tss32.ss2 = SEL_DS32; tss32.sp0 = tss32.sp1 = tss32.sp2 = ADDR_STACK0; tss32.ip = ADDR_VAR_USER_CODE; tss32.flags = (1 << 1) | (1 << 17); tss32.ldt = SEL_LDT; tss32.cr3 = sregs.cr3; tss32.io_bitmap = offsetof(struct tss32, io_bitmap); struct tss32* tss32_addr = (struct tss32*)(host_mem + seg_tss32_vm86.base); NONFAILING(memcpy(tss32_addr, &tss32, sizeof(tss32))); memset(&tss32, 0, sizeof(tss32)); tss32.ss0 = tss32.ss1 = tss32.ss2 = SEL_DS32; tss32.sp0 = tss32.sp1 = tss32.sp2 = ADDR_STACK0; tss32.ip = ADDR_VAR_USER_CODE; tss32.flags = (1 << 1); tss32.cr3 = sregs.cr3; tss32.es = tss32.ds = tss32.ss = tss32.gs = tss32.fs = SEL_DS32; tss32.cs = SEL_CS32; tss32.ldt = SEL_LDT; tss32.cr3 = sregs.cr3; tss32.io_bitmap = offsetof(struct tss32, io_bitmap); struct tss32* tss32_cpl3_addr = (struct tss32*)(host_mem + seg_tss32_2.base); NONFAILING(memcpy(tss32_cpl3_addr, &tss32, sizeof(tss32))); struct tss64 tss64; memset(&tss64, 0, sizeof(tss64)); tss64.rsp[0] = ADDR_STACK0; tss64.rsp[1] = ADDR_STACK0; tss64.rsp[2] = ADDR_STACK0; tss64.io_bitmap = offsetof(struct tss64, io_bitmap); struct tss64* tss64_addr = (struct tss64*)(host_mem + seg_tss64.base); NONFAILING(memcpy(tss64_addr, &tss64, sizeof(tss64))); memset(&tss64, 0, sizeof(tss64)); tss64.rsp[0] = ADDR_STACK0; tss64.rsp[1] = ADDR_STACK0; tss64.rsp[2] = ADDR_STACK0; tss64.io_bitmap = offsetof(struct tss64, io_bitmap); struct tss64* tss64_cpl3_addr = (struct tss64*)(host_mem + seg_tss64_cpl3.base); NONFAILING(memcpy(tss64_cpl3_addr, &tss64, sizeof(tss64))); if (text_size > 1000) text_size = 1000; if (text_prefix) { NONFAILING(memcpy(host_text, text_prefix, text_prefix_size)); void* patch = 0; NONFAILING(patch = memmem(host_text, text_prefix_size, "\xde\xc0\xad\x0b", 4)); if (patch) NONFAILING(*((uint32_t*)patch) = guest_mem + ADDR_TEXT + ((char*)patch - host_text) + 6); uint16_t magic = PREFIX_SIZE; patch = 0; NONFAILING(patch = memmem(host_text, text_prefix_size, &magic, sizeof(magic))); if (patch) NONFAILING(*((uint16_t*)patch) = guest_mem + ADDR_TEXT + text_prefix_size); } NONFAILING(memcpy((void*)(host_text + text_prefix_size), text, text_size)); NONFAILING(*(host_text + text_prefix_size + text_size) = 0xf4); NONFAILING(memcpy(host_mem + ADDR_VAR_USER_CODE, text, text_size)); NONFAILING(*(host_mem + ADDR_VAR_USER_CODE + text_size) = 0xf4); NONFAILING(*(host_mem + ADDR_VAR_HLT) = 0xf4); NONFAILING(memcpy(host_mem + ADDR_VAR_SYSRET, "\x0f\x07\xf4", 3)); NONFAILING(memcpy(host_mem + ADDR_VAR_SYSEXIT, "\x0f\x35\xf4", 3)); NONFAILING(*(uint64_t*)(host_mem + ADDR_VAR_VMWRITE_FLD) = 0); NONFAILING(*(uint64_t*)(host_mem + ADDR_VAR_VMWRITE_VAL) = 0); if (opt_count > 2) opt_count = 2; for (i = 0; i < opt_count; i++) { uint64_t typ = 0; uint64_t val = 0; NONFAILING(typ = opt_array_ptr[i].typ); NONFAILING(val = opt_array_ptr[i].val); switch (typ % 9) { case 0: sregs.cr0 ^= val & (CR0_MP | CR0_EM | CR0_ET | CR0_NE | CR0_WP | CR0_AM | CR0_NW | CR0_CD); break; case 1: sregs.cr4 ^= val & (CR4_VME | CR4_PVI | CR4_TSD | CR4_DE | CR4_MCE | CR4_PGE | CR4_PCE | CR4_OSFXSR | CR4_OSXMMEXCPT | CR4_UMIP | CR4_VMXE | CR4_SMXE | CR4_FSGSBASE | CR4_PCIDE | CR4_OSXSAVE | CR4_SMEP | CR4_SMAP | CR4_PKE); break; case 2: sregs.efer ^= val & (EFER_SCE | EFER_NXE | EFER_SVME | EFER_LMSLE | EFER_FFXSR | EFER_TCE); break; case 3: val &= ((1 << 8) | (1 << 9) | (1 << 10) | (1 << 12) | (1 << 13) | (1 << 14) | (1 << 15) | (1 << 18) | (1 << 19) | (1 << 20) | (1 << 21)); regs.rflags ^= val; NONFAILING(tss16_addr->flags ^= val); NONFAILING(tss16_cpl3_addr->flags ^= val); NONFAILING(tss32_addr->flags ^= val); NONFAILING(tss32_cpl3_addr->flags ^= val); break; case 4: seg_cs16.type = val & 0xf; seg_cs32.type = val & 0xf; seg_cs64.type = val & 0xf; break; case 5: seg_cs16_cpl3.type = val & 0xf; seg_cs32_cpl3.type = val & 0xf; seg_cs64_cpl3.type = val & 0xf; break; case 6: seg_ds16.type = val & 0xf; seg_ds32.type = val & 0xf; seg_ds64.type = val & 0xf; break; case 7: seg_ds16_cpl3.type = val & 0xf; seg_ds32_cpl3.type = val & 0xf; seg_ds64_cpl3.type = val & 0xf; break; case 8: NONFAILING(*(uint64_t*)(host_mem + ADDR_VAR_VMWRITE_FLD) = (val & 0xffff)); NONFAILING(*(uint64_t*)(host_mem + ADDR_VAR_VMWRITE_VAL) = (val >> 16)); break; default: exit(1); } } regs.rflags |= 2; fill_segment_descriptor(gdt, ldt, &seg_ldt); fill_segment_descriptor(gdt, ldt, &seg_cs16); fill_segment_descriptor(gdt, ldt, &seg_ds16); fill_segment_descriptor(gdt, ldt, &seg_cs16_cpl3); fill_segment_descriptor(gdt, ldt, &seg_ds16_cpl3); fill_segment_descriptor(gdt, ldt, &seg_cs32); fill_segment_descriptor(gdt, ldt, &seg_ds32); fill_segment_descriptor(gdt, ldt, &seg_cs32_cpl3); fill_segment_descriptor(gdt, ldt, &seg_ds32_cpl3); fill_segment_descriptor(gdt, ldt, &seg_cs64); fill_segment_descriptor(gdt, ldt, &seg_ds64); fill_segment_descriptor(gdt, ldt, &seg_cs64_cpl3); fill_segment_descriptor(gdt, ldt, &seg_ds64_cpl3); fill_segment_descriptor(gdt, ldt, &seg_tss32); fill_segment_descriptor(gdt, ldt, &seg_tss32_2); fill_segment_descriptor(gdt, ldt, &seg_tss32_cpl3); fill_segment_descriptor(gdt, ldt, &seg_tss32_vm86); fill_segment_descriptor(gdt, ldt, &seg_tss16); fill_segment_descriptor(gdt, ldt, &seg_tss16_2); fill_segment_descriptor(gdt, ldt, &seg_tss16_cpl3); fill_segment_descriptor_dword(gdt, ldt, &seg_tss64); fill_segment_descriptor_dword(gdt, ldt, &seg_tss64_cpl3); fill_segment_descriptor(gdt, ldt, &seg_cgate16); fill_segment_descriptor(gdt, ldt, &seg_tgate16); fill_segment_descriptor(gdt, ldt, &seg_cgate32); fill_segment_descriptor(gdt, ldt, &seg_tgate32); fill_segment_descriptor_dword(gdt, ldt, &seg_cgate64); if (ioctl(cpufd, KVM_SET_SREGS, &sregs)) return -1; if (ioctl(cpufd, KVM_SET_REGS, &regs)) return -1; return 0; } static void setup_common() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) { } } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setsid(); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (200 << 20); setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 32 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 136 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); if (unshare(CLONE_NEWNS)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } typedef struct { const char* name; const char* value; } sysctl_t; static const sysctl_t sysctls[] = { {"/proc/sys/kernel/shmmax", "16777216"}, {"/proc/sys/kernel/shmall", "536870912"}, {"/proc/sys/kernel/shmmni", "1024"}, {"/proc/sys/kernel/msgmax", "8192"}, {"/proc/sys/kernel/msgmni", "1024"}, {"/proc/sys/kernel/msgmnb", "1024"}, {"/proc/sys/kernel/sem", "1024 1048576 500 1024"}, }; unsigned i; for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++) write_file(sysctls[i].name, sysctls[i].value); } int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid != 0) return wait_for_loop(pid); setup_common(); sandbox_common(); initialize_netdevices_init(); if (unshare(CLONE_NEWNET)) { } initialize_tun(); initialize_netdevices(); loop(); exit(1); } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void loop(void) { int i, call, thread; int collide = 0; again: for (call = 0; call < 6; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); if (collide && (call % 2) == 0) break; event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); if (!collide) { collide = 1; goto again; } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { long res; switch (call) { case 0: NONFAILING(memcpy((void*)0x20000040, "/dev/kvm\000", 9)); res = syscall(__NR_openat, 0xffffffffffffff9c, 0x20000040, 0, 0); if (res != -1) r[0] = res; break; case 1: res = syscall(__NR_ioctl, r[0], 0xae01, 0); if (res != -1) r[1] = res; break; case 2: res = syscall(__NR_ioctl, r[1], 0xae41, 0); if (res != -1) r[2] = res; break; case 3: syz_kvm_setup_cpu(-1, r[2], 0x20fe8000, 0, 0, 0, 0, 0); break; case 4: NONFAILING(*(uint16_t*)0x20008400 = 0); NONFAILING(*(uint16_t*)0x20008402 = 0); NONFAILING(*(uint32_t*)0x20008404 = 0x2409); NONFAILING(*(uint64_t*)0x20008408 = 0); NONFAILING(*(uint64_t*)0x20008410 = 0x2000000); NONFAILING(*(uint16_t*)0x20008418 = 0); NONFAILING(*(uint8_t*)0x20008420 = 0); NONFAILING(*(uint8_t*)0x20008421 = 0); NONFAILING(*(uint8_t*)0x20008422 = 0); NONFAILING(*(uint8_t*)0x20008423 = 0); NONFAILING(*(uint8_t*)0x20008424 = 0); NONFAILING(*(uint8_t*)0x20008425 = 0); NONFAILING(*(uint8_t*)0x20008426 = 0); NONFAILING(*(uint8_t*)0x20008427 = 0); NONFAILING(*(uint8_t*)0x20008428 = 0); NONFAILING(*(uint8_t*)0x20008429 = 0); NONFAILING(*(uint8_t*)0x2000842a = 0); NONFAILING(*(uint8_t*)0x2000842b = 0); NONFAILING(*(uint8_t*)0x2000842c = 0); NONFAILING(*(uint8_t*)0x2000842d = 0); NONFAILING(*(uint8_t*)0x2000842e = 0); NONFAILING(*(uint8_t*)0x2000842f = 0); NONFAILING(*(uint8_t*)0x20008430 = 0); NONFAILING(*(uint8_t*)0x20008431 = 0); NONFAILING(*(uint8_t*)0x20008432 = 0); NONFAILING(*(uint8_t*)0x20008433 = 0); NONFAILING(*(uint8_t*)0x20008434 = 0); NONFAILING(*(uint8_t*)0x20008435 = 0); NONFAILING(*(uint8_t*)0x20008436 = 0); NONFAILING(*(uint8_t*)0x20008437 = 0); NONFAILING(*(uint8_t*)0x20008438 = 0); NONFAILING(*(uint8_t*)0x20008439 = 0); NONFAILING(*(uint8_t*)0x2000843a = 0); NONFAILING(*(uint8_t*)0x2000843b = 0); NONFAILING(*(uint8_t*)0x2000843c = 0); NONFAILING(*(uint8_t*)0x2000843d = 0); NONFAILING(*(uint8_t*)0x2000843e = 0); NONFAILING(*(uint8_t*)0x2000843f = 0); NONFAILING(*(uint8_t*)0x20008440 = 0); NONFAILING(*(uint8_t*)0x20008441 = 0); NONFAILING(*(uint8_t*)0x20008442 = 0); NONFAILING(*(uint8_t*)0x20008443 = 0); NONFAILING(*(uint8_t*)0x20008444 = 0); NONFAILING(*(uint8_t*)0x20008445 = 0); NONFAILING(*(uint8_t*)0x20008446 = 0); NONFAILING(*(uint8_t*)0x20008447 = 0); NONFAILING(*(uint8_t*)0x20008448 = 0); NONFAILING(*(uint8_t*)0x20008449 = 0); NONFAILING(*(uint8_t*)0x2000844a = 0); NONFAILING(*(uint8_t*)0x2000844b = 0); NONFAILING(*(uint8_t*)0x2000844c = 0); NONFAILING(*(uint8_t*)0x2000844d = 0); NONFAILING(*(uint8_t*)0x2000844e = 0); NONFAILING(*(uint8_t*)0x2000844f = 0); NONFAILING(*(uint8_t*)0x20008450 = 0); NONFAILING(*(uint8_t*)0x20008451 = 0); NONFAILING(*(uint8_t*)0x20008452 = 0); NONFAILING(*(uint8_t*)0x20008453 = 0); NONFAILING(*(uint8_t*)0x20008454 = 0); NONFAILING(*(uint8_t*)0x20008455 = 0); NONFAILING(*(uint8_t*)0x20008456 = 0); NONFAILING(*(uint8_t*)0x20008457 = 0); NONFAILING(*(uint8_t*)0x20008458 = 0); NONFAILING(*(uint8_t*)0x20008459 = 0); NONFAILING(*(uint8_t*)0x2000845a = 0); NONFAILING(*(uint8_t*)0x2000845b = 0); NONFAILING(*(uint8_t*)0x2000845c = 0); NONFAILING(*(uint8_t*)0x2000845d = 0); NONFAILING(*(uint8_t*)0x2000845e = 0); NONFAILING(*(uint8_t*)0x2000845f = 0); NONFAILING(*(uint8_t*)0x20008460 = 0); NONFAILING(*(uint8_t*)0x20008461 = 0); NONFAILING(*(uint8_t*)0x20008462 = 0); NONFAILING(*(uint8_t*)0x20008463 = 0); NONFAILING(*(uint8_t*)0x20008464 = 0); NONFAILING(*(uint8_t*)0x20008465 = 0); NONFAILING(*(uint8_t*)0x20008466 = 0); NONFAILING(*(uint8_t*)0x20008467 = 0); NONFAILING(*(uint8_t*)0x20008468 = 0); NONFAILING(*(uint8_t*)0x20008469 = 0); NONFAILING(*(uint8_t*)0x2000846a = 0); NONFAILING(*(uint8_t*)0x2000846b = 0); NONFAILING(*(uint8_t*)0x2000846c = 0); NONFAILING(*(uint8_t*)0x2000846d = 0); NONFAILING(*(uint8_t*)0x2000846e = 0); NONFAILING(*(uint8_t*)0x2000846f = 0); NONFAILING(*(uint8_t*)0x20008470 = 0); NONFAILING(*(uint8_t*)0x20008471 = 0); NONFAILING(*(uint8_t*)0x20008472 = 0); NONFAILING(*(uint8_t*)0x20008473 = 0); NONFAILING(*(uint8_t*)0x20008474 = 0); NONFAILING(*(uint8_t*)0x20008475 = 0); NONFAILING(*(uint8_t*)0x20008476 = 0); NONFAILING(*(uint8_t*)0x20008477 = 0); NONFAILING(*(uint8_t*)0x20008478 = 0); NONFAILING(*(uint8_t*)0x20008479 = 0); NONFAILING(*(uint8_t*)0x2000847a = 0); NONFAILING(*(uint8_t*)0x2000847b = 0); NONFAILING(*(uint8_t*)0x2000847c = 0); NONFAILING(*(uint8_t*)0x2000847d = 0); NONFAILING(*(uint8_t*)0x2000847e = 0); NONFAILING(*(uint8_t*)0x2000847f = 0); NONFAILING(memcpy( (void*)0x20008480, "\x4b\xa4\x22\x97\xc6\x6f\xd3\x5e\xa9\x7f\x89\x63\xa9\x19\xb0\x0d\xd1" "\x08\x99\x16\x3a\xe2\x12\xb4\x68\xc2\xd4\x8d\x07\x5d\x43\x63\x17\x34" "\xc9\x3b\x72\xf1\xc7\xc2\xb7\x34\x5c\x8e\xf5\x0a\xde\x2e\x0b\x65\x95" "\x31\x30\x07\x3c\x0d\x31\xb9\xc1\xb8\xab\x2f\xb2\xb2\xb6\xa1\xa0\x64" "\x50\x88\xdc\x16\xc7\xfa\xc1\x21\x86\xb4\xb6\x35\xb0\xac\x83\x30\x50" "\xa3\x58\xb6\x89\x57\xcd\xaf\xb4\xc9\xae\xa5\xbc\x76\x08\x26\x6a\xca" "\x2f\xb3\x8e\x57\x67\x36\x91\x02\x18\x67\x1d\x4f\xda\x08\x97\xe1\x8f" "\x0c\x70\xec\x97\x37\x75\xe6\xde\xe8\x20\x4f\xb1\x55\x80\x54\x74\x39" "\xb7\x75\xc4\x31\x54\x15\x64\x12\xb8\xd7\x5f\x9f\xde\x4c\xcf\x7d\x2b" "\xbe\xb2\x8d\x8c\xab\x59\x2b\xe8\x98\x00\x09\xaf\x40\xe3\xdd\x84\xf8" "\xb8\xfa\xcd\x6d\xfa\x70\x6c\xf7\xc1\xb6\x45\x5e\xe2\xbb\xf2\x47\xae" "\x4b\x4b\x7f\x40\x3f\x63\x8d\xf0\x1e\x7b\x4c\x67\x03\xd8\x42\x46\xeb" "\xbd\x78\xe5\x8d\x46\x17\x0b\x38\xa3\xb7\x1b\x5e\xbf\x7a\xc8\x31\xe0" "\xe1\xaa\xff\x1a\x0c\xf8\xdd\x3a\xfb\xdc\x42\x3f\xde\x82\xe3\xd1\x25" "\xc3\xc1\xa2\x2e\x32\x59\x32\x09\xe4\x67\xc7\xf5\xcc\xdf\xa6\x3c\x33" "\x44\xec\x02\xac\x43\x44\x03\x28\xb8\x3c\x1d\x75\x04\xa5\x44\x61\x72" "\x19\xe2\x78\x46\xd7\x9c\x45\x2e\xfc\x03\x6f\xfc\xf7\xec\xdd\x0b\xb2" "\x85\xbc\xc4\x04\x2f\xef\xaa\x7e\xc6\x4f\x39\x4d\x2a\x5e\xd0\x1c\xb3" "\xac\x27\x4a\xa0\x63\x80\xbf\x03\xe2\x2b\x41\x2d\x0a\x39\xc0\xd4\x9b" "\x89\x0a\x24\xaa\x22\x4e\xab\xba\x5d\x84\x7f\xea\x10\x28\x40\xdc\xfd" "\xd7\x35\x8a\xf5\xe8\xec\xf3\x78\x74\xb1\x87\x11\x8c\xc5\x72\x6d\xee" "\x50\x8e\x98\xea\x4f\x7f\xe2\x66\xb3\x2b\x01\xb1\xa0\xcc\x4e\xb2\x08" "\x2b\xa9\xde\x78\x3d\xbc\xf1\x8b\x8b\x60\x1d\x7f\x67\xe8\x45\x0c\x6c" "\xac\x9b\x73\x69\x3b\x05\x60\x8e\xc7\xc1\x43\xc7\xdf\x7b\x57\xd4\xe9" "\x51\x1e\x8b\xa7\xb2\xa8\x46\x89\xe3\xcc\x48\xed\xfc\xad\x1a\x22\x24" "\x22\xa6\x04\xa2\x49\xe7\x3e\x33\x62\x9e\xf3\xa0\x0f\xea\x1f\xa3\xc7" "\xdc\x36\xdc\xa4\x44\x6f\x52\x62\xf9\xb8\x7c\x91\x23\xe9\x3b\xfc\xcd" "\xb8\x9f\x66\x37\x0c\x69\x48\x2d\xbd\x70\xa0\x99\x5f\x07\xff\x29\xa8" "\xfd\x7a\xe1\x56\x9a\x10\xae\x15\x85\x17\x9e\xdf\xdb\xe8\xc7\x27\xee" "\x91\x4b\x96\x50\xed\x6d\x5f\x4c\x57\xd3\x63\x59\xbb\x14\x02\x46\xa0" "\xc7\xee\x91\xb7\x70\xcc\xe5\xd5\xd4\x1b\x9b\xb7\x86\x93\x57\x51\x5f" "\x3e\xc2\x89\x76\x6b\xfd\xf8\x83\xa5\xda\x35\xe4\x50\x15\xea\x40\xc5" "\xee\xeb\x0d\x98\x93\xc9\x88\x19\x32\x68\x6f\x9f\x69\x42\x42\x9e\xa7" "\x00\xc5\x48\x92\x53\x13\xc7\xf3\x30\x63\xfc\x3a\xcf\x49\xf9\x07\xaf" "\x83\x23\x2c\x4c\x57\xdc\x53\x92\xc1\x33\x90\xb4\x77\xa4\x6f\xd1\xf9" "\xcf\x01\x6f\x52\x2c\xbb\xfa\x77\x93\x3f\x1c\x43\x35\xb4\x4a\xd8\xa2" "\x6d\xab\x93\x33\x75\x72\x50\x9d\x91\x24\xbf\x58\x1a\x26\xdb\xac\x50" "\x00\x05\xf6\x5b\xbe\xdd\x87\x3f\xa9\x16\x42\x35\x7b\xdc\x3e\x3f\x7a" "\xca\xe2\xde\x3b\x07\x32\xc6\xcf\xb9\x96\xc6\xb3\xb0\x98\xef\x82\x1a" "\x9d\x66\x5c\x2b\x15\x6a\xb7\x12\x44\x69\x61\xa7\x18\x67\x58\x6d\x9b" "\xe3\x12\x40\x12\x5c\x68\xdd\xf7\x35\x67\xfd\x98\x91\x54\x64\xa4\x7a" "\xf1\xd2\x5b\xcd\x50\xee\xa3\xb4\x3c\x88\x08\xbd\xd0\xc2\x78\x77\x0a" "\xfe\x6d\x38\xf5\x0c\x62\xbe\x2d\x6a\x90\x99\x0b\x9e\x94\xd6\xd2\x33" "\x42\x9f\x7d\x4e\x58\x5b\x1a\x9e\xae\x12\xe5\xda\x51\xd5\xcc\x31\x7d" "\xbe\x62\x8c\x9a\x2e\xfa\xaf\x8d\x62\x54\x95\xc9\x9e\x8d\x75\x54\xd2" "\x48\xbd\x34\x2f\x51\xf7\x1d\xa0\x2f\x34\x58\x5b\x11\xb5\xe2\x70\x40" "\x11\x33\xe6\x53\x6d\xb5\x2b\xc7\x91\xc7\x63\x49\x03\xd1\x12\x98\x91" "\xc3\xcb\xb2\xa8\xf1\xb7\x65\xfc\x5b\xe7\x21\x20\xa2\xc8\xfb\x78\x87" "\xdd\xf9\x23\xb0\x50\xaf\x27\x47\x93\xfa\x99\x50\x81\x13\x42\x5d\xab" "\x9f\xdd\xff\x43\x6e\x96\x53\xa5\x76\x13\x34\x21\xfd\x90\xeb\x27\x39" "\x08\xb6\x2c\x10\xb3\x1f\xd2\x20\x71\x67\x70\xc4\xf8\x63\xa6\x1b\x15" "\x3d\xd2\x2a\x1f\x8e\x4a\x30\xff\x1d\xd8\xa1\x8f\x5d\x18\x2d\x91\xaf" "\x3f\xb2\xd9\x90\x36\xe5\x6e\x47\x89\x6e\x30\x72\xdd\xd6\xeb\xe0\xdb" "\x3f\xaa\x83\xbc\xaa\xf8\x2b\xb1\x9d\x7a\x33\xf5\xe2\xa2\x26\xdf\xa3" "\xfa\x8a\xe5\xc0\x66\x49\x5f\xd0\x08\x79\x6a\x62\x3c\xba\xbc\x9a\xa4" "\x68\x49\x20\xb9\xaf\x94\x54\xc7\x3b\x85\x45\x5e\x7f\x4d\xf1\x4e\x55" "\x88\xd7\x8a\xb4\xc4\xe4\x79\x6a\xbc\xa7\xd5\xeb\xe9\x1f\xec\x4e\xf3" "\xfa\xd3\x38\x0e\xf9\x51\xa0\x44\x81\x8a\x3a\x10\xe9\x7a\xa0\xf1\xb4" "\xc7\xef\xf8\xc3\x56\x29\xe1\x26\x15\xb0\x9d\x06\xb8\x39\x07\x3f\x0d" "\x39\xa3\x2d\x45\x0f\x9b\x23\xfa\x1a\x05\xe7\xce\x2b\x6f\x60\x74\xe3" "\x25\x04\xeb\x70\x66\x77\xe8\xab\x3a\x7c\x77\xb9\xec\x45\x92\x18\x9e" "\xba\x86\xf0\x96\xcd\x44\x98\x2c\x8b\x4f\xd8\x20\x37\x47\x92\x86\xb4" "\xaf\x64\x96\xdf\x0b\xe9\x47\x4f\xb1\xcd\xc3\x30\x02\xa2\x38\x4a\xa4" "\xfa\x0c\xf9\x6f\x19\x92\x51\xc4\x03\x5b\x10\xca\x1e\x1d\xaa\x52\x13" "\x97\x8b\x0f\xa9\xc7\xee\x8f\x03\x30\x5b\x22\x87\xe1\xcd\xaa\x92\x4a" "\x19\xff\x29\x57\x17\xd2\xef\x0e\xba\x78\x59\xd5\xe9\xec\x21\xa3\x97" "\x05\xee\x8b\x00\x2b\x4e\xd6\x58\xb4\xc9\xb9\xd0\x02\xba\xed\x1c\x86" "\x13\x36\x55\xcf\xfa\xc3\x2f\x81\x14\x08\x19\x66\x7d\x49\x25\xc6\x24" "\x79\xc7\xcb\x0c\xf8\xa6\x84\xd8\x8a\xcc\x0d\xd8\x72\xa3\x1f\x7e\x34" "\xee\x07\x9e\xb4\x20\xa7\x32\xfa\xfb\x96\x81\xe2\x79\x05\xcf\x72\x36" "\x80\x4e\x1d\xa6\xf4\xf7\xfd\xd6\x74\x78\x4b\x63\x31\x3e\x2a\x0e\xc7" "\x60\x62\xc1\xb3\xf9\xcc\xd7\x8a\x7c\x85\x5d\xe7\xcb\x2b\xe1\x25\xc3" "\xc8\xd8\x74\x1c\xd9\x83\x3c\x94\x91\x98\x53\x25\xeb\xee\x15\x47\x0c" "\xd1\x81\x12\xe2\x25\x3c\x87\x1b\x20\xc0\xca\xb4\xdb\xcb\x58\xdc\xf9" "\xe6\x8d\xbf\xb2\x5a\x1d\xdd\x92\xbf\x04\x32\xb7\xa4\x1e\x96\x33\x54" "\x78\xf0\xb6\x72\xae\x70\x43\x3c\x61\x72\x73\x83\xb2\x3e\xb0\x73\xd0" "\x4c\x03\xfb\x20\xd8\x64\x10\x79\xff\x9e\x20\xf2\xaa\xbe\xa0\x60\x68" "\x8d\x5e\x3b\x2c\x1e\xd6\x01\x68\xee\x03\xc6\xe3\x1e\xa5\x80\x87\x92" "\x17\x6e\x92\x00\x70\xa5\xf5\xe6\xe3\x88\xa0\xf7\x73\xa1\x20\x87\xa2" "\x00\x15\xab\xa7\x82\xfe\x6d\xa3\x99\xd0\x8d\x8e\x88\x80\xaa\x44\x80" "\x0e\x46\x19\x71\xfe\x5c\xb8\x2d\x91\xa6\xb0\xf4\xd0\x9e\x01\xd9\xe3" "\x42\x36\x9f\x59\x8c\x70\x2d\x01\xc4\x9c\xe9\x99\xe7\x1d\xd3\x75\x11" "\x4d\x31\xb6\x1d\xc8\x8e\x98\xd9\x2a\xc7\x61\x4a\x94\xce\x6c\x96\x0e" "\x3e\x78\x32\xb1\xb7\x1b\xe4\xd2\x49\x0f\x81\xa0\x44\x77\x6d\xd5\x16" "\xd4\xa0\x0f\x5e\x07\x91\xf6\x06\xec\xcc\x29\xb9\x77\x50\xa3\x62\xed" "\xca\x41\xac\x14\xc7\x55\xc9\x30\x8b\xe7\xbe\xbb\xeb\x2f\x32\xdf\x26" "\x55\x53\x6f\x8f\x0e\x64\xbb\xf5\x3a\x1a\x93\x60\xa1\x03\x68\x49\x9d" "\x11\x91\x62\xde\x8c\x9a\x5b\x35\xa2\xaa\x16\x0d\x27\x7d\x05\x71\x5c" "\xa8\x36\x20\xfe\x8b\x09\xf6\x1a\x6a\x7c\x79\x2e\x65\x96\x72\xd2\xf2" "\x05\xfc\x33\xb0\x5c\x58\x31\x6a\xbe\x47\xa0\x6d\xaf\x66\xb1\x19\x43" "\x42\x46\x5d\xc8\x2c\xc4\x7f\x19\x4d\x7c\x9f\xd7\x20\xed\x3e\x50\xe3" "\xe9\xcd\xb8\xf1\xf7\xf4\xcf\xc3\x8a\x53\xc0\xc9\x0b\x8a\xc9\x64\x37" "\xb4\xc5\x6e\xb8\xc7\xae\x4f\xf9\x98\xec\xed\x14\xec\x7d\xf6\xae\x59" "\xba\x2d\xa2\xbc\xb7\x59\xe6\xea\xe3\x8f\xf5\x7b\xaa\x0d\x9e\x44\xde" "\xbc\xf8\x95\xa7\xb0\x0e\xac\xad\x1f\xeb\xc8\xae\x30\x16\xce\x65\x97" "\x3e\x24\x0f\xc6\xac\x69\xcd\x99\x12\xfa\x44\x70\xb4\x8c\x6b\x1b\xab" "\xf7\xf6\xf1\x53\xee\x75\x16\xa5\x73\x23\xbe\x4e\xaf\x56\x8f\x97\xa6" "\x27\xdb\x62\x2a\xa8\x64\x90\x65\x49\x56\x22\x9d\x49\x4b\xb3\xb2\x80" "\xfb\x95\x80\x67\xea\x8b\xbf\x9a\x7c\x62\x11\x06\x45\xa0\xc7\xdc\xaf" "\xa0\x90\x3d\x36\x0d\xc7\xe5\x02\xef\xf3\x61\x94\x37\xcf\x86\x16\x9d" "\x05\x63\xa4\x3f\xba\x29\x19\xd8\xd3\x96\x5e\x74\xd2\x77\x7a\xfb\x7a" "\xbf\xba\x4f\x67\x8d\x21\x2b\xb2\x1d\xac\x8a\x55\xc0\xd9\xbb\x33\x0b" "\x74\x2c\xab\x23\x58\xc7\x34\xbe\xaf\x28\x36\x1a\x74\xd7\x59\x38\x43" "\x61\x41\x12\x76\xe7\xa5\x01\xd8\x7e\xc8\x70\x3b\x86\xee\x49\x11\x6a" "\x02\x2d\x0e\xab\xca\x99\xe2\x69\xbd\x89\xfa\xad\x1c\x6c\x34\x26\xf3" "\x9a\x38\xf6\x2f\x47\xde\x3a\xab\x6f\x8d\xba\xd6\xee\xfe\x83\x58\x0d" "\x3a\x3f\x1d\xd2\x40\x77\x28\xb0\x57\x77\x8a\x66\x38\x83\xae\xf2\x49" "\xaf\xc1\x58\x35\x77\x55\xdc\x9a\xee\x6b\x78\x84\x91\xe4\xfe\xe5\x3e" "\xbb\xf1\x59\xff\x51\x1b\xd4\x3b\xe7\xae\x33\xfa\xe5\x6e\x90\xd8\xd4" "\x95\x42\x48\xc2\x7d\x81\x0e\xc2\xb6\x3b\x6c\xee\x62\x37\xcd\x50\x9f" "\xfb\x99\x8b\x54\xac\xe3\xc6\x50\xcb\xb5\x1f\x1d\x26\x21\xcd\x41\x14" "\x07\x82\x60\x70\x39\x20\xec\x80\xd7\xc3\x6e\x15\xbc\xb8\x88\x8b\xf3" "\x0f\x07\x6f\xf0\xf2\x0e\x68\xc0\x63\x13\x84\x26\xdc\x0d\x92\xbc\xb6" "\x7d\x29\x44\x51\x2e\x6f\x48\xae\x0b\xca\xde\xb5\xb5\xb7\xdd\xb3\x23" "\x26\xf0\x7b\x64\xf0\x8a\x83\x33\x3b\x9c\xe9\xb4\x06\x5a\x4c\x6e\x5e" "\xae\x0e\x33\xd6\x06\x9a\x55\x6e\x82\x99\x38\xe2\xa3\x7d\xe9\xf8\x14" "\xfa\xbe\x91\x35\xe5\x6a\x1e\xe9\x77\xd5\x6f\x42\xb6\x09\x17\xd4\x87" "\xea\xed\xbc\x13\x03\x76\xbb\x12\xd0\xf0\x22\x9c\xa3\xf2\x8f\xd8\xfb" "\x9a\x0d\x06\xd5\xea\xb9\x12\xc8\x8c\x1c\xbe\x45\x58\xec\x09\x0b\xef" "\x5f\x45\x13\x5c\x86\x68\x45\x45\x50\xeb\x9d\x86\x0f\x27\xfe\xa8\x18" "\xfb\xf9\x33\xfa\x77\xf3\x52\x59\xb9\x61\xec\xe8\x78\x5e\x19\x48\xee" "\x48\x63\x69\x82\x16\x05\x99\x25\xdb\xa2\x6c\xe0\x2c\x41\x6e\x12\x67" "\x72\xf6\x35\x57\xec\xd3\xd8\xc9\xb4\xc0\xc0\x28\x78\xc9\xe5\x8d\x7e" "\xe4\x0b\xf6\xfa\xdf\x8d\x63\x03\x18\xf3\xdd\xd4\x2c\xc7\x05\xfd\x71" "\x48\xb1\x0b\xc4\x7c\xca\x49\x39\xd1\x5a\x81\x26\xff\xe2\xa2\x41\x35" "\x2c\xc7\xac\x06\x0a\x1d\xef\xbe\x28\x68\x54\xaf\x31\xa8\x95\x95\x7c" "\x63\x7a\xb2\xd8\xd0\x4b\xba\xe6\x3e\x0a\x05\x03\x06\xf4\xd9\xbe\x39" "\xce\x9f\x65\x81\xc3\xf9\xe9\xf8\x0a\xa0\x27\xa5\xc9\x82\x26\x41\x53" "\xa1\x5f\x01\x07\xdc\xe0\x23\x55\x3e\x5a\xc2\xde\xe1\x0a\xaf\x4e\x73" "\x10\x63\x14\x27\xe1\x24\xea\xf2\xbc\xa9\x0e\xbc\x71\xae\x4c\x85\x64" "\x32\xd3\x9e\x9a\x4f\xb8\x38\xb3\x4a\x0a\x02\x80\xf2\x2a\x6a\x12\x1b" "\xc8\x7b\xa7\x46\xd1\x4a\x0b\x0a\xfa\xed\xb4\xe3\xd9\x99\x6f\x3c\xe6" "\x89\x10\x63\x04\x59\xa3\xb9\xcd\x40\x06\x6d\x16\x6a\x92\x6c\x42\x7c" "\xec\x7a\x53\x05\x6a\x26\x14\x04\x5e\x83\xa3\xa3\x97\x38\x72\xf7\xc3" "\x87\x59\xa7\x82\x38\xfc\xbf\x58\x69\x53\xf9\x6e\xe5\xe9\x29\x40\x19" "\xb7\x45\x47\x03\x50\xe8\xfc\x7d\x15\xd6\x02\x3a\x8c\x73\xcc\x3d\x62" "\x41\x14\xd2\x07\x91\xd6\x67\x25\xd1\x34\x5c\x67\xa7\x33\xae\x80\xd6" "\x0f\x73\x16\x86\x2e\xa1\x5b\x5a\xff\x97\xd5\x78\x55\x59\xec\x91\x6a" "\x2e\xa6\xb4\xe5\x80\x23\xed\x4c\xa1\x0d\xf8\x04\x8a\xb9\xdc\x5c\x74" "\x24\xe5\xe3\x75\xc3\x50\xc9\xea\xf2\x61\x05\x47\xd7\x59\xd6\xb0\xc7" "\x0a\x2a\x1a\xc9\x4e\x77\x78\x66\xa5\x06\x80\x74\xc0\x37\xd9\xd1\x88" "\x13\x67\x73\x1c\x94\xc4\xf3\xdd\xbd\xac\xc1\x62\xea\x71\xc6\x67\xd5" "\xf4\x8c\x2b\x0a\x50\x5b\xb1\xf3\x69\xed\xfc\x4f\xb2\xc7\x4c\x0f\x35" "\x8f\xe6\x71\x34\x56\x3c\x7e\x7a\xdc\x09\x86\x65\x61\xbb\xdc\x26\x92" "\x6e\x76\x9a\xe9\xb6\x10\xda\x09\xc3\xce\x32\x97\x74\x23\x53\x72\xcb" "\xf4\x1f\x26\xcb\x62\x4d\x13\x4c\x2a\x89\xfa\xad\xb8\x0a\x39\xa1\x32" "\x47\xf8\x24\x6a\x50\x6f\xd5\x5f\xd4\x17\x4c\x17\x88\x74\x8b\xdb\x4c" "\x3b\xb4\xfb\x7e\x09\x3f\x60\xc8\xc2\x83\x79\xa8\xf2\xe1\x09\x5f\x2f" "\xf5\xf2\xd0\xc6\x18\xde\xca\x95\xda\xd2\xc3\x23\x93\x93\xd6\xbd\x71" "\xec\x34\x29\x5e\xcf\x48\xdb\xc9\xbc\x3c\x37\xc7\xc9\x88\xb3\xd6\xe7" "\x4e\x0a\x8c\xe3\x1f\x22\xb0\xc6\xb3\xb6\xc2\x58\x1c\xf3\x1c\x00\x46" "\xb4\x0d\xb3\xca\x9c\x88\xca\x9f\xfb\xfe\xcf\x16\x34\x4a\x04\x02\x23" "\xcc\x60\xfe\x49\xdc\x00\x18\x1e\x2e\xe8\x08\xe4\x51\x95\xef\xc1\x83" "\x4c\xca\x86\xe6\x77\x50\x3d\xfe\x4c\x8f\x6f\xd1\x12\x62\x60\xc2\x7c" "\x24\x41\x6f\x41\x01\x3e\x68\x46\x39\xab\x19\xe8\x63\xd0\xcd\x39\xe2" "\xdc\x6a\x2b\x34\x61\x60\xd7\xd9\x11\xf0\x09\x1d\x43\xd0\x8d\xd0\x27" "\xbb\x5d\x84\xd4\x2a\x3b\x5f\xf0\xc4\xbe\x4f\x6e\xbd\x24\xa0\x5b\xe8" "\x8e\xad\x8d\x4e\xbe\x00\xa4\x20\x1f\x2b\xbe\x28\xd4\xe0\xa6\x1e\x54" "\xa8\xcc\x55\xdf\xca\x10\x83\x2a\xbc\x4f\x7a\x7a\x34\xbd\xbd\x47\xee" "\xc3\xf2\xe9\x8a\x28\x34\x10\xaa\x42\xe2\x06\xf8\xad\x12\xc6\xa1\xa3" "\x5d\xb8\xaf\x6b\x43\x37\x36\xda\xeb\x65\x10\x68\xc3\x3b\xcf\x5a\x7c" "\xe8\xe4\xdd\x4e\x34\xb7\xfd\x44\xf5\xbf\x1e\x77\x11\x33\xbd\x12\x71" "\x7e\x02\xdf\x62\x74\x56\x72\xdb\x54\xae\xd5\x85\x20\x60\xba\x76\x9f" "\x46\x25\xac\x06\x1f\x31\xe5\x2a\x4b\xe9\xc4\xcd\x4a\x51\xe2\x11\x3c" "\x10\x18\x47\x0e\x20\xdb\xbc\xac\x9f\x8a\x21\x37\x34\xf7\xa8\xfd\x9f" "\x95\xd6\x27\xe6\x08\xde\x05\x4c\x77\x09\xc2\x9c\xf9\x9d\x26\x4e\x26" "\xa0\x87\xbe\xd6\xee\x21\xa3\xa2\xf1\x1d\xc9\xde\x20\x98\x9b\x62\xd2" "\x91\xbf\x17\xae\xb8\x51\x6c\xa4\x39\x6a\x3b\xb5\xa0\x45\xad\x09\x5b" "\xc7\x85\x2d\x3e\x50\x49\x17\x82\xb0\x9a\x2a\x85\xd0\xcc\xe8\xf5\x2c" "\xa9\x60\xcf\xe4\x6a\x1a\xf3\xd4\x37\xbe\x87\x33\x58\x6b\x09\xe2\xfa" "\x78\xe4\x99\xd9\x94\xfa\xac\x4e\x2f\x63\xeb\x32\x9f\xa9\x18\xd0\x89" "\xca\xd9\xe7\x40\x0b\x63\x9b\x63\x4c\xde\x2e\x6c\x5f\x58\xa3\x94\x61" "\xfd\x23\x82\x55\x08\x87\xa2\x06\x23\x72\x3f\x25\x7e\x31\x3b\x27\x8a" "\x89\xe9\x07\x8d\xe5\x94\x79\xf9\x7a\x0c\xbd\x29\x57\x7b\x95\x8b\x9e" "\x78\x96\x19\xf7\xed\xc3\x15\x0d\xe3\x99\xab\xef\x9e\x19\xa1\x33\x0a" "\x3f\x8d\xdc\xdc\xec\x2d\x7c\xe8\x03\x18\x92\xcd\x02\xd8\x2d\x90\xef" "\x1a\xd5\x1f\x54\x72\xc4\xab\xf7\x11\xc4\x37\x98\x7b\x2b\xae\xeb\xee" "\x41\xdc\xc1\x9a\xfa\xf5\x19\xe8\xb5\xbb\x27\xf4\x6b\x9d\x5e\xc8\x62" "\xcc\x30\xf5\x49\x4f\x70\xa6\x25\xa2\xa0\xbd\x0b\x14\x06\xd1\xee\xcc" "\xdb\xc4\x9f\x89\x0f\xa6\x96\x47\xe5\x28\x0f\x57\x3c\xc0\xec\xcb\xc7" "\x4d\xea\x22\x0a\xdd\x53\x72\x30\xcf\xf2\xfc\xec\x2b\x53\x1d\x73\x5f" "\xed\xa8\x23\x51\x70\x02\x8c\xbd\x57\xb0\xaa\xf4\xe4\xf2\xc1\x90\x9f" "\x95\x75\xe6\x92\xed\x3a\x39\x2b\x16\x7c\xf8\x15\x19\xd4\x93\x19\x6b" "\x12\xf1\x88\xd9\x31\x31\xfa\x5e\x85\x42\xca\x6b\xaa\x92\x15\x74\x21" "\x3a\x91\x1b\x08\x10\x13\x6d\xaa\x15\x87\x58\x9b\x71\x05\xf6\x47\xc5" "\x74\x85\x29\x8c\x21\xa2\xe2\xbd\x5c\xeb\x95\x6f\x81\x62\xf8\xed\x02" "\x1c\x28\xaa\x4d\x8f\x57\x52\xc8\x42\x4c\x63\x31\xe6\xad\x5c\xe2\x6d" "\x12\x94\x79\xe2\x3e\xda\x7a\xd0\xad\x51\xe0\x52\x38\xbf\x56\xec\x70" "\x62\x16\x41\xb0\x3d\x11\x6b\xf4\x9b\x13\x34\xc2\x71\x49\xb7\x21\x9e" "\xdb\xc6\xe8\x53\x1c\x55\x65\x8b\x5c\xda\xce\x3a\x4e\x98\xea\xd6\x8d" "\xdc\xe0\xdd\x52\xa2\x06\xac\x79\xdd\xb1\xd2\x8d\xcc\x08\x45\xd5\x94" "\x6b\x16\x66\xee\xcd\xf5\x4b\xbf\xb9\x90\xe8\xba\x88\x60\x5c\x01\xbb" "\x2a\x79\xc6\xe3\x13\xc1\x33\x69\x1c\xb2\x1f\x1f\x27\x28\xb8\xfd\xaa" "\xef\xe6\xfd\xe1\xc6\xb9\x1d\xed\xc8\x5c\xda\x7b\x9d\x38\xf3\x3e\x93" "\x73\x50\x5a\xb2\x98\xca\xeb\xda\xe3\x60\xe8\xac\xcf\x06\xf0\x5c\x17" "\x01\xec\x6e\xe1\x6b\x15\x9e\x44\x5a\xac\xc9\xb3\xb5\xf4\x6f\x58\x0f" "\xfe\x84\xc4\x0d\x70\xed\xbb\x35\x6c\x9f\x4c\x78\xd5\x10\x31\x6c\xa7" "\x16\xeb\xec\x19\x10\x8f\x7a\x9e\xf1\x15\xc2\x1c\x73\xe6\xd1\x23\x04" "\xf5\x08\x50\x3a\x41\xc3\xbf\x59\x8c\xd1\xf2\x97\x5b\x3f\x81\x9a\x39" "\x9c\xf8\x1b\xd3\xc2\xf6\xff\x44\xb0\x68\x53\x06\x7b\xc3\xd9\x24\x95" "\xfc\xf6\x3d\xba\x92\x31\x4a\xa1\xa2\xbe\x84\xf7\x31\x48\x2c\xdd\x4f" "\xa4\x79\xd2\xa1\x96\xe3\x3e\xdb\x5a\x83\x3a\xbc\x0f\x08\x21\xce\xdb" "\x24\xbf\xcb\x9c\x6a\x58\x35\x73\x60\xdd\xae\x36\xc3\xa6\xc4\x0b\x9a" "\xbf\x7e\x39\xb2\x4d\x79\x8f\x1a\x15\x5b\x5a\x3c\x19\xbe\xed\x95\x3c" "\xba\x79\x98\xf2\x4a\x68\x97\x3b\xc0\x84\x08\x60\x6c\xd2\x19\x9c\x8c" "\xb9\xcf\x9b\x20\x12\xa4\x88\xbd\xf6\x65\xbd\xc9\xb2\x32\x32\xc3\x6b" "\x88\x88\x2f\x0c\xb5\x8e\x39\x4c\x22\xf5\x82\x5b\x58\xa5\xf0\x85\xe1" "\xf8\x06\x79\xb3\xcd\xfc\x62\xab\x17\x5c\x24\x4a\xb8\xab\xe2\xb1\x0a" "\x42\xcd\x80\xea\x56\x52\xe7\xb1\x9a\x57\xda\xa9\xa8\x11\x30\x45\xe2" "\x3e\x68\xe0\x77\xed\x83\xe3\x74\x68\x5e\xe8\x78\xf3\x33\x52\xea\x2b" "\x57\x88\x5e\x3e\x4b\x44\xba\x8a\xf4\x84\x93\xf3\xeb\x5c\xe3\xcd\x48" "\x44\x7d\xd4\x71\xf9\xfe\xe2\xa1\x1c\x87\x3c\xb8\xce\x8a\x13\xc4\xca" "\xd3\xaa\x7b\xd6\xd1\xa8\x86\x37\x61\x1b\x8b\x3a\xba\xb2\xd2\xcb\x66" "\x9d\x2f\xd3\xa2\xd5\x37\x83\xe6\x3b\x4f\xdd\x25\xe8\xa3\xdc\x1b\x73" "\x75\x9c\x2d\xf2\xdb\xfe\xcf\xd3\x60\x5d\xbf\xbf\x73\x1f\xde\x0b\xa9" "\xdf\x33\x3f\x00\xfb\xd2\x4d\x3b\x05\x9c\x34\x1a\x53\x65\xe5\xe4\x01" "\xe9\x6e\x26\x0d\xad\x8e\x1e\x76\xf5\xbf\x32\xe4\xe5\xd9\x6b\x7d\x4d" "\x52\x30\x37\x29\x51\x40\xd8\x22\xcd\x1c\x13\xd9\x52\x84\xef\xb3\xbc" "\x15\x5d\xeb\xe2\x19\x63\x6e\x4f\x47\xf4\xf7\x1a\x48\xb4\x2f\x9d\x3c" "\xcc\xb9\xdd\xbe\xf5\x17\xe5\x3a\xad\x2b\xd0\x7c\x76\xaa\xd9\xf5\xa6" "\x50\x27\x24\xae\x7a\xa2\x04\x08\x40\xb7\xcb\xce\xd5\xf2\xfc\xa5\xbd" "\x2e\x9b\x8c\xf7\x0b\xa7\x14\x0a\x20\xef\x52\xbf\xe6\xdb\xdd\x7f\x53" "\xc2\xdb\x51\x72\x59\x19\xbf\x20\xf9\x7f\xd8\xef\x6d\xed\x1f\xd3\xc4" "\xbb\x72\xd6\x27\x05\xad\x4e\x9b\x6a\x6e\x48\x95\xad\xce\xed\x92\xef" "\x1c\xad\xc1\x1c\xfd\x8b\x15\x59\xfa\x52\x79\x78\x84\x6f\xfa\x83\x62" "\x38\xa3\xf3\x3c\x51\xbc\xbd\x31\x0d\x52\x34\x75\x54\xd4\x10\xa5\x8d" "\x32\x03\x01\x3c\xef\x1e\xd2\x86\x93\x39\x5a\x28\x5e\x01\xc3\xd2\x9a" "\x3e\x90\x3d\x8d\x02\xe2\xb9\x6b\x01\x79\x89\xf7\xe3\x47\x51\xf7\xd8" "\x8c\x06\x14\x98\x89\xf1\xc7\xad\x60\x19\x18\x35\x29\xa0\xb0\xb3\x91" "\x20\xbb\x1d\x9c\xfe\xaf\xb3\x20\x1e\x2f\x8e\x70\x98\x38\xfd\x8f\xb3" "\x3e\x61\x76\x10\x53\xc4\xab\x9e\xda\x51\xba\xd7\xc0\x5f\x8d\xc0\x77" "\xbe\x7e\x78\x99\xac\xc5\x85\x03\x30\x74\xf5\x43\x19\xd7\x2a\xf3\x55" "\xee\xa5\xa4\x93\xac\xf9\x07\xf4\x86\x26\x2b\xda\xfa\xd0\xc6\x85\x8d" "\xdc\xcc\xce\x28\x3e\x14\x5d\x4b\x09\x9f\x3f\x18\xcf\x5a\xd5\x2a\xf5" "\x80\xd5\xb7\x77\xb3\x0c\xfb\xc9\x8e\xc9\x8f\x30\xb7\x40\xd0\x03\x60" "\x33\xcb\xfe\x8d\x27\x48\x1d\x60\xfe\x86\x4f\x65\x78\x6c\xe8\x94\x87" "\xd7\x9b\xc9\xc6\x6c\xfe\x9a\x36\x50\x6d\x94\x1a\x72\x4f\xc4\x9d\x3b" "\xa1\x6c\x76\xe7\x7a\x45\x64\x23\x12\x41\xbd\x2e\xe3\xa6\xa7\x79\xea" "\xac\xf7\x4e\xb2\x4f\x07\x4f\x83\xc7\xbe\x8a\x72\xaf\xec\x26\xd1\x20" "\x3e\x4b\x8d\xec\x82\x5f\xe9\x67\x59\x58\x03\x85\x4f\x26\x67\xe0\xdd" "\x58\xb3\xe8\x82\xa1\x06\xec\x82\x2b\x14\xee\x05\x31\x53\x0a\x1a", 4096)); NONFAILING(memcpy( (void*)0x20009480, "\x61\xea\xa2\x0e\x86\x70\x63\x40\x16\xa0\xfd\xdd\x04\x1d\x5b\x1b\x6b" "\x50\x23\x32\x71\x79\x2a\x2c\x83\xbe\x3c\x20\x64\x7b\x76\x9f\x96\xa0" "\x3b\x55\xea\x27\x2d\x72\x17\xe4\x2a\x94\x39\xb0\xc8\x3b\x4e\x2a\x73" "\xb8\xae\xef\x63\x9b\x70\xbf\x90\x5f\xfb\x73\x92\x80\x28\xa1\x15\x03" "\x2f\x85\xfa\xe7\x27\xa6\x54\x71\x1a\xb9\xc7\x20\x96\x3c\xdb\xf7\xf9" "\xeb\x6b\x95\xe6\xb7\x96\xfa\xbe\x1e\x02\x1c\x3e\x34\xff\xba\x75\xa1" "\x1f\x95\x21\xe9\x7d\x53\x8d\x44\x39\xbf\x17\xc4\x53\x01\xc5\xfd\x75" "\xdc\x05\xae\x37\x34\xc1\xa7\x58\xf2\x92\x77\x2a\xa4\x69\x5a\xc5\x60" "\xb2\x0a\x78\x1c\x39\x45\xee\xe5\xba\xb3\x8d\x6b\x87\xc7\x06\xf3\x4f" "\xa9\x18\xd5\x73\xcb\x6e\xe9\x6d\xd4\x38\x10\xeb\x7f\xd1\xff\x32\x81" "\x07\x03\x2a\x5c\x63\x71\xc6\xe4\x6b\x50\x4f\xe7\x93\xf5\x41\x15\xf6" "\x11\xbe\x86\x9e\xe2\x80\x0f\xbc\xea\xe2\x6c\xa2\x87\xed\xef\x7c\x79" "\x8e\x44\x03\x8e\x1f\xb6\xa8\x02\xf5\x7a\x44\x41\x92\x89\x92\x4e\x1a" "\x46\x96\xa7\x47\x22\x98\x38\xf6\x5c\xc7\x3f\x69\xc9\xe5\xc6\x37\x23" "\x85\x3a\x17\x52\xdc\x5f\x11\x33\x4d\xa9\xd6\x77\x4a\x15\x5a\x80\x5c" "\xbc\x29\x3a\x6c\xd5\xc2\x74\x28\xb9\xac\x33\xcd\xe0\x01\x26\x3e\x1b" "\xcb\x81\xd9\xf5\xce\x6c\x4c\x40\xc0\x69\x62\xd8\x2f\x76\x76\x74\xdb" "\x8c\x4a\xa2\x0a\x61\xe7\x18\x4b\x57\x83\xf7\x92\x3b\xa2\x7c\x4c\xe5" "\x3b\xa6\xc3\x33\xbc\xda\x40\x05\x77\x19\xb1\xe6\x72\xe5\x39\xda\x40" "\xcc\xb3\x01\x68\xdc\x1f\xdf\xb9\x14\xc2\x33\x17\x85\xbc\x7a\x5d\xd2" "\x34\x3d\xd8\x2f\x5c\x7b\x7b\x64\x16\xa7\xec\xcb\x21\xd2\x2b\xf9\xca" "\x80\x7f\xa4\xf0\x0e\x15\x98\xbe\x91\xb9\x40\xac\x7b\xc2\x02\x9d\x2f" "\x0d\x21\x0e\xab\xe1\x61\x9b\xde\x3c\x11\x4c\x1d\xd8\xeb\x8b\xb7\xc5" "\x22\x3d\x1f\xc6\x6d\x5e\x62\x58\x0c\x84\xb3\x32\x47\x40\x68\x09\x79" "\x80\xd1\x39\x07\x8c\xd1\x7e\xec\x83\x6e\xf2\xef\xe2\x98\x1a\xca\x9f" "\xee\x84\x69\x8f\x4a\x8c\xce\x77\x2d\x4b\xf7\x8e\x64\x19\x7e\xc4\xb8" "\x84\x38\x78\x1f\x9f\x7c\x49\xf1\xd7\xc0\x3f\xf4\x8b\x26\xa2\x3b\x1d" "\xeb\x98\xe5\xb2\x79\xdd\x50\xd6\x41\x78\xbe\x38\x71\xb0\x2c\x04\xd9" "\xc4\x97\xe4\x43\xa6\xef\x10\x7d\x2c\xea\xfa\x19\xf9\x0a\x3d\x9e\x49" "\xe4\xd4\x5f\x36\x78\xda\xd8\x08\xf9\xbc\xfa\x0b\x67\x57\x0d\x0f\x55" "\x83\x84\xc1\x66\xb8\x54\xcb\xfa\xc7\xd4\x81\x71\x40\x11\x82\x59\x1b" "\x92\x0c\x97\xce\x87\x47\x11\x38\xc6\xf5\x4e\xa0\x44\xc8\x7c\x6c\xa2" "\x3e\xde\xc2\x97\x23\xb2\x13\xf3\xba\xab\x16\x5a\x26\xe1\xc6\x7e\xc4" "\x5f\x53\x08\x2d\x7d\x10\xd3\x3e\x1d\x77\xc1\x42\x1f\x27\x25\xdb\x36" "\x4c\x95\xfe\xc7\xb9\x0c\x01\xa8\xe5\x54\x72\x64\xcf\xf5\x86\x3f\xc6" "\xc2\xf8\xc7\xf0\x6e\x0e\x73\xe9\xd4\xab\xc9\xf4\x78\x6f\x5f\x89\xe4" "\x43\x98\x7d\xef\xcf\x5a\x59\x7f\x82\x71\xc3\x57\x1b\x45\x04\x9d\x73" "\xf4\xac\x03\x63\x2c\x2f\x7a\x13\x35\x31\x50\xe0\xe7\xd0\xac\x29\xca" "\xa1\x24\x05\x39\x3f\x1a\x12\x64\x1a\x8b\x3c\xbf\xd6\x86\xdb\xef\x52" "\x35\xe2\xce\x7f\xc1\xe0\xf0\xe2\x80\xad\x99\xb6\x62\xcd\x3a\x4f\x31" "\x1f\xd4\x42\x53\xc0\x54\xf2\x15\x29\x50\x66\xeb\xdb\x4d\x2e\x01\x81" "\x35\xe9\x42\x88\x91\x66\xca\x02\x76\xe8\xc1\x98\xae\xf9\x3b\x67\x42" "\x0c\x12\x7d\xb1\xdf\xb7\x40\x9d\xf3\x9d\xbe\xb4\xd1\x91\xd4\xd9\x6f" "\xdf\x93\xf1\xd7\x44\xf0\x08\xf4\x3f\x9b\x3e\x1f\xeb\x7c\x29\x48\x3e" "\x1f\xb3\x7d\x9e\xf7\x34\x5a\x98\x45\x32\xde\x4a\xc2\x11\xdf\xb1\x6a" "\xb8\xcd\x41\x34\x6f\x88\xc5\x58\xda\xf8\xef\x7c\x12\x6a\x81\x69\x72" "\xc7\x49\x68\x2c\xb7\x07\x3c\x5f\xf0\x09\xea\x78\x83\xff\x97\x21\x3b" "\x9b\xa2\xc9\x81\xb0\xf3\xea\x98\x26\xb6\x72\xc7\x2f\x89\xcc\x0a\x8b" "\x58\xe7\xe0\xb8\x12\x67\xf3\xa5\x7d\x4d\xf9\x30\xa0\xbd\x89\x0d\xa1" "\x5c\x97\x49\x64\xf4\xbc\x7a\x9d\x24\xe4\xae\xe4\xc8\x5a\x3f\x77\xb7" "\x95\x5e\xc9\x4b\x71\x8f\x83\x4b\xbd\x40\xd5\xcf\x20\xf9\x2f\xf3\x15" "\x89\x36\x21\x80\x9c\xa2\xdb\x54\xeb\xfa\xe9\xe5\xc0\xf9\x49\x54\x57" "\x51\x8f\xd9\x3d\x59\x32\x32\x88\xf5\xf8\xe6\x9f\xe4\x65\xe7\x0f\xfe" "\x5a\x0c\xf8\x5a\xe6\x23\xc2\xb5\xb6\xb1\x7d\x35\x1c\x8e\x94\xdf\xe6" "\xa5\xe2\x29\x7c\x53\xf0\x01\x85\x4a\x53\x65\x7c\x8c\x89\x87\x43\xcb" "\x72\x15\x9b\xe2\x41\xf5\xf8\x75\x9f\xfa\x0b\x6c\xeb\x9f\xa5\x6a\xab" "\x07\x9b\x39\x58\xfb\xad\x1f\x13\xe8\x54\x49\x30\x6c\x5a\xf1\x1e\x10" "\x96\xce\xa7\xd4\x41\xd2\x13\x46\xc4\x79\x85\xf0\xa5\xcf\x08\xe6\x48" "\xa3\xa8\xf1\xb9\xc3\x2b\xd4\x18\x89\x7e\x54\x83\xd7\x0e\xb0\x9b\x46" "\xcd\x41\xec\xfd\x5c\xf8\x23\x4f\x35\xa7\xa5\xb7\x9f\xbc\xb5\x30\xd5" "\x10\x9e\xa0\xf2\x0d\xea\x23\x3d\x31\x5f\xfc\x7d\x38\x46\x7b\x6f\xfb" "\xf7\x86\x44\x6f\x7f\x66\x17\x29\x72\x58\xbc\xa8\x00\x4b\xe3\xa1\x09" "\xef\x10\x3b\x09\x00\x00\x00\x00\x00\x00\x00\x08\x64\x1b\xe5\x49\x9a" "\x19\xeb\x79\x0a\xfa\x6f\x2c\x5c\x48\x52\xbb\x4c\x8c\xc7\x6d\x10\xb1" "\x7a\x69\x64\x0c\xa2\x0d\x80\xec\xaf\xbb\xeb\x43\x14\x75\x1c\xc0\x85" "\x7b\x35\xa0\x43\x21\xef\xc7\xe1\xf4\x31\xf3\x04\x68\x4c\x1b\xa5\x30" "\x0c\x61\x58\x91\x20\xf2\x00\xc4\x5d\x3f\x99\xf0\x62\x2d\x90\xfd\x7a" "\x5c\x9a\x6e\xe7\x76\xea\x42\x1f\x1c\x68\x66\x8b\x24\x9e\xbc\xe1\x77" "\x09\x64\x83\x93\xe8\x6f\x8c\x59\x6a\xbb\x77\xaa\xfe\x37\x6e\x15\x8c" "\x0f\x2e\x4b\x16\xd1\xa7\x66\xe2\xdd\xdb\x8c\xb4\x81\xb2\x8c\x5c\x98" "\xf2\xa6\x8a\x0f\xd1\xc5\x55\xd1\x7a\xd0\x93\x2c\x3e\x85\x50\x78\xb2" "\xd9\xe5\xff\x6f\x8d\x0b\xea\x70\xe5\xfe\x83\xf0\xb0\x83\x1d\x95\x3a" "\x05\x06\x1a\xbb\xca\xbe\x04\x3b\x59\xed\xf1\xbc\x25\x19\x5d\x55\x4b" "\x3f\x11\xe2\xdc\x05\x91\xb2\xfb\x17\x71\xa2\x50\x92\xca\xd4\x42\x26" "\x63\xb6\x0d\x0b\x45\xff\xeb\xaa\x9f\x64\x6d\xa6\xb9\xb9\xdc\x2f\x5d" "\x27\xbd\x23\x6c\xab\xf6\xae\x85\x1d\x70\xf7\xd6\xd7\x74\xfe\x09\xf1" "\x2a\x02\xb3\xc9\x42\x73\xd6\xfe\x8b\x5f\x61\x7e\xb3\x22\x89\x03\x01" "\x62\xc2\x89\xbb\x57\x40\xfe\xc5\x23\xad\xc0\xfe\xb5\x12\xc8\x94\x81" "\xc0\x30\xae\x2e\xde\xab\xab\xcc\x59\x5a\x6b\xb3\xe7\xf8\x0d\xbd\x8e" "\x8a\x21\xe0\xb8\xa6\x38\x8e\x18\xd8\x71\x9b\xf9\x6c\x40\x44\x0c\x07" "\xe5\xd5\x01\xa9\x3f\x81\x57\x43\xfe\x8f\x6c\x56\xfb\xe1\xb7\x50\x2f" "\x0e\x41\x8e\x7a\x3b\x11\x6b\xda\x4c\x75\x9a\x65\xcb\xb2\xb5\x47\x5c" "\x37\x48\xc0\x48\x9a\x0b\x6b\x84\xc3\xf4\x61\xd5\x8b\x04\xf6\x12\xae" "\x6e\x46\x33\x94\x9e\xe8\xb2\x71\xa8\xe8\x73\xf2\xe4\x0b\x7f\x75\xf3" "\xdf\xfd\x09\x00\xe0\xe2\x9f\x2d\x16\xf3\xc9\x19\x07\x95\x81\xd2\x09" "\x49\x89\xcb\x6f\xfa\x80\x8c\x2e\x3c\x1c\x53\x44\x49\xe0\x7b\xd8\xcd" "\x28\x76\xf2\x48\x50\xa6\x94\x75\xcb\xa9\xc4\xa8\xb5\x74\xa7\xd1\x14" "\x54\xb4\x39\xeb\x6a\x77\xf0\xaa\x6a\x2f\x52\xdb\x41\x3f\x5d\x5a\xee" "\x6c\x38\x8e\x10\xb4\xb0\x5e\xe9\xa1\x41\xfc\xf0\x17\x32\x11\xb8\x3b" "\x6f\x01\xc6\x98\x8d\x83\xc7\xcf\x89\xac\x51\x88\xf5\x75\xf4\x51\x95" "\x17\x65\x3b\x57\x5e\xab\x7b\x78\x34\x27\xa8\x39\x18\xcf\x55\xbf\x71" "\x52\x1f\x33\xc3\x67\xb7\x63\x9a\x25\xc3\xda\xa2\x83\x72\xad\x57\x05" "\x9e\x4a\x16\x9c\x1e\x8c\xa3\x42\x59\x7d\x7e\x71\x14\x82\xc9\x5d\x45" "\xd3\x75\x08\x4d\x34\xdd\x31\xa4\x94\x2c\x93\x09\xa2\x5d\x03\x82\x58" "\xad\x95\x48\x37\xac\x32\x2e\x83\xdb\x09\xf6\xb2\x81\x28\xe4\x0a\x19" "\x86\xae\x71\x16\x60\x4c\xef\x2e\xd4\x8d\xa1\x71\x0a\x0a\xe0\x37\x19" "\xf2\x09\x13\x32\x09\x3c\xff\x90\x89\x79\xff\x68\x4d\x82\x26\x26\xd0" "\x95\x25\x6a\x00\xd3\xf8\xb9\x6c\x26\x2f\x17\xa3\x55\xdb\xed\xf6\x34" "\x53\x33\x10\x46\xdb\xde\x13\xcf\x9f\xa9\x3e\xfb\xef\x77\x7e\x01\x0c" "\x1e\x9b\xa2\x7b\xe7\x59\x34\x3e\x38\x16\xf9\x24\x6d\x4d\x70\x8c\x17" "\x00\x5f\xea\xb9\xbb\xcc\x25\xb4\xa3\x33\xb4\x4f\x94\x3d\x35\xc5\xf4" "\xf9\x11\x6b\xbf\xa1\xed\x84\xf4\x7b\x57\xc2\x83\x51\xaa\x38\x0c\xf8" "\xc0\x29\x3a\x4f\x88\xea\x96\xf6\xa3\x5c\xa7\x3e\x04\x50\xe3\x8f\x47" "\xff\x96\xd4\x56\x53\xd1\x03\x15\x49\x27\x10\xca\xe5\xa5\xc2\xf1\x43" "\x5d\xf9\x92\xf9\xcb\x2c\x5b\x5c\x21\x0f\x56\x89\x00\x46\x7d\x27\x8a" "\xe3\xd5\xe3\xa4\x74\x1a\x37\x48\x81\x16\x08\xe9\x7b\x9b\xff\x03\x22" "\x5a\x6c\x37\xb5\x28\xf2\xd7\xb9\xfe\x84\x9f\x5a\x12\xfe\xce\xc5\x4c" "\x7c\x3d\x90\x19\xc2\xeb\xa7\x13\x1d\x42\x58\x14\xa8\x8a\x8c\x69\x21" "\xc4\xa3\x85\x6f\x89\x10\x48\xc9\x5b\xb6\xd2\xc9\xb1\x25\x64\xa5\x63" "\xd7\x86\x70\x20\xbf\xd6\x2d\xc4\x6e\x69\x6e\xba\x6c\x58\x6b\x0f\xc7" "\x57\x99\x40\xe8\x9b\x1a\xd9\xe8\x3c\xb7\x39\x53\xda\x3f\x4c\x50\xb6" "\x0f\x35\x33\x8e\x86\x57\x23\xc7\xa3\xd3\x97\x92\x9b\x0c\xbe\xaa\x7a" "\x8d\xc8\x08\x9e\x92\x6a\xba\xb2\xb2\x13\x7d\x00\xca\x10\x0b\xe1\x7e" "\x11\x94\xea\x8e\xae\x93\xf7\x6e\x7e\xee\xc4\x99\x63\x85\x8a\x1b\xd4" "\xe0\xff\x00\x6a\xa1\x46\x92\xfa\xc8\xad\x66\xcc\x86\x10\x58\x36\xa7" "\x45\xad\xb3\x7a\xed\x83\x52\xa0\x7e\x7d\x22\x01\x0a\x43\x4f\x19\xcb" "\x99\x58\xa3\xe9\x48\x28\x23\x21\x95\x5a\x84\xe3\x5d\xd5\xcb\xb0\x00" "\x05\x64\xeb\xb7\x35\x3b\x53\x50\xa6\x30\x9f\x1f\xbb\x9a\x6b\x81\xa6" "\x04\x2b\xad\xfe\x44\xe9\xc0\x22\xfb\x99\x6e\x55\xad\x4b\x83\x78\x2d" "\x30\xb2\x08\x7d\x3e\xc6\xc3\xe7\x20\xc8\x9c\x03\xa9\xe3\xaf\xc3\xd2" "\x25\xfd\x27\xa9\xed\x95\x45\x62\xf1\xa2\xe2\x5f\xd2\x89\x11\xed\x22" "\x0a\x70\x04\x20\xc1\xc7\x5f\x80\x28\xfc\xee\xd5\x12\xf1\x8e\x48\x54" "\xc9\xef\xe2\x02\x5e\xec\x9a\x8d\x2e\xa5\x55\xb4\xae\xc7\x38\xba\x2f" "\xc4\x6d\xe8\xfa\x48\x15\xc6\xe8\x53\x7b\x9c\x46\x81\xe1\x19\x9c\x1d" "\xd1\x22\x8c\x27\xb0\x86\x00\x60\xfb\x6d\x6e\x0e\x38\xb3\xec\xfd\x33" "\xe6\x9e\x55\xfa\xcc\x10\x5f\x23\x39\x62\xba\x03\xd1\xd2\x94\xc2\x6d" "\x73\xd2\x12\x74\x0f\x44\x53\xf2\xb7\x92\x77\xaa\xa6\xfa\x72\x0f\xb8" "\x6d\x73\xcf\x58\x52\x60\xfa\xa7\x39\x50\x2a\x9c\x31\xe6\x23\x5a\xc8" "\x06\x31\x0b\x61\x1b\x10\xdc\xcf\x34\x7c\x71\xc2\xd4\x40\x18\x59\x15" "\x5c\x42\x38\x7f\xba\x41\x9c\x99\xcc\x82\x71\x1c\x47\xf8\xce\xc1\xc8" "\x07\x0f\x82\xdc\x73\x97\xf9\x13\x22\xac\xb7\x7f\x52\x34\x82\x6e\x97" "\xf4\x35\xdc\x87\x08\x8f\xf5\x5c\xab\x5f\xb4\x3c\xf3\x13\x56\x82\x23" "\x07\x98\xe8\x2d\x62\x47\x90\x71\xa3\xbb\x81\x54\x79\x83\x40\xcc\x83" "\xf9\xbf\xd0\x11\xe7\x4d\xdf\xa8\x2c\x93\x26\xd3\x72\xee\xab\xb2\x5c" "\x85\x17\xfb\x4c\xa7\x82\xe4\xaf\x99\x79\x9a\x7b\x74\x48\xee\xfe\x60" "\x86\x64\xf1\x40\x93\x37\xeb\x31\x35\x90\x54\xb4\x04\x09\xcd\x68\x7f" "\x9e\x4b\xb1\xca\xdd\xa1\xe4\xda\xa0\x27\x67\xd7\x58\xe3\xf4\xd1\x8e" "\x0f\x8f\x65\x7f\x77\x83\x4a\xb0\x2b\x61\x08\xe7\x96\x3b\x2c\xdd\xd0" "\x3e\x60\xe6\x85\x5e\x05\x2b\x9f\xde\x11\x35\x9d\xb4\x44\x9b\x8e\x0d" "\x00\xc7\x82\x31\x22\x58\xe0\xab\x8d\x16\x6c\xe0\xa4\x7a\x73\x12\x68" "\x4a\x2c\x7e\xad\x37\x07\x10\x00\xa6\x78\x95\xf9\xf2\x0d\x97\x91\x71" "\x4d\x1e\xe7\xd6\x10\xd4\xfa\xda\xbf\x39\x66\xdd\x5e\x3d\x09\x49\xeb" "\x60\x4b\x8b\x10\xf8\xaf\x9e\x66\xf1\x86\x57\xc3\x26\xe3\x8a\x8b\xd2" "\xa3\x14\x86\xed\x9b\xaa\x75\xa3\x31\xc6\xba\x4b\x60\xd4\x6b\x93\xe4" "\xd8\x4f\xfa\x66\x18\xed\xd9\x8e\xf5\x99\x21\xd4\x99\x5a\xb1\x39\x18" "\xec\x8a\x06\xa7\xe8\x29\xfb\x09\xf2\x37\x91\x39\x73\xe0\x38\xb6\x5d" "\xe2\xe0\xf7\xbf\x94\xac\xeb\xd3\x53\x6e\xfd\x6e\x8f\x88\x68\x11\xf4" "\xee\x17\xfc\x7f\x5a\xa0\x22\x91\x69\x69\x09\x2e\xc9\xbc\x1b\xf4\x14" "\x8d\xc1\x4b\x9b\x40\xdf\x48\x5b\x81\xaf\x9d\x00\x65\x0d\x6e\xcf\x7a" "\x16\xf0\x2e\x4f\x00\xac\xe7\x42\x2e\xb6\xaf\xfb\xb4\x72\xef\x15\x54" "\xa3\x17\x11\xc3\xfa\x0d\x4f\x6a\xc0\xf1\xb0\x42\xc0\x22\xfb\x69\xec" "\xe4\xd9\x05\x70\xbd\xb5\x38\xf5\x75\x84\xaa\x20\x4d\x5c\xac\xb7\xb1" "\xa7\xc2\x6c\x47\x25\x61\x85\x42\xaf\x6c\xd8\x68\xdc\xbd\xcf\xac\x07" "\xca\x63\xdf\x0b\xb0\x16\xa2\x05\x4b\x97\xe3\xaf\xeb\xc1\xe8\x2a\x22" "\xb9\xff\x82\xe2\x1f\xcd\x5b\xd8\xeb\x61\x89\x62\xcd\x66\x4d\x18\xcc" "\xd4\xc4\xae\xa3\xf9\xbe\x5c\x89\x8e\x3d\xd9\x3e\x05\xa1\xa2\x1d\x00" "\xfd\x8f\x8f\x70\x50\x1a\x66\xe2\x8a\xb8\x66\xb7\x03\x62\x12\xb7\x52" "\x38\xac\x9f\x0f\xd3\xfe\xaa\x0c\xcc\x4d\x81\xba\xa7\x4e\x20\x0b\xa8" "\xd7\xfa\xd8\xb9\xb6\x4e\x64\x4d\x2d\x29\x40\x86\x88\x94\xcb\x85\xd4" "\xe8\x69\xfd\xd9\x68\x38\xf1\xf6\x84\x4a\x63\xd8\x1d\x82\x60\x93\x44" "\x6b\xd9\xb0\xf5\xd4\x86\xfb\x12\x41\xe1\x96\x54\xbb\x37\xb0\xab\x05" "\x28\x4b\xad\x40\x0a\xa3\x2c\xcd\xdb\x86\xfa\xff\xac\x46\xf2\xac\xc6" "\xa1\x36\xd3\xae\x51\x0b\x57\x91\xcd\xc6\x7e\xb5\xdc\x02\x57\xc0\x63" "\x54\xe9\xbe\x36\xd0\x85\x3d\x53\x77\x8d\xc4\xd1\x35\xfa\xc7\x7c\x10" "\x24\x6a\x91\x7f\x17\xb1\xa2\x1c\x9b\x9a\x08\xb2\x5c\xa8\x46\xed\x8a" "\xbc\xb3\x8a\xfa\xd2\x71\xc8\x2e\x3b\xfc\x77\x77\x02\xc3\xf4\xcb\x89" "\xec\x9d\x2b\x33\x6f\xb1\x8d\xa2\x9f\x43\x60\x47\x37\xf5\xfe\x83\x71" "\x7b\xd9\x36\xb0\xcf\x72\xf1\x2c\x08\xcb\x06\xcd\x28\xe5\x45\xd9\x19" "\xf9\x37\x33\x10\x03\xa7\xb6\xfe\xc6\xf0\x38\x5b\x62\x9b\x8e\xe1\x94" "\x55\xa9\x0c\x0b\x9f\xd7\xea\x15\xf4\xf6\x4a\x40\x34\x03\xbd\x35\xd2" "\xa4\x9d\xae\x1c\x5c\xb9\x49\xd0\x20\xd9\x60\xe9\xe9\x31\x57\x8d\xab" "\x04\xbf\xf6\xe4\x34\x4e\x72\x61\x93\x5c\xa6\x58\xdd\x50\x52\x6c\xfa" "\xa1\xe2\x69\x2f\x97\xb7\xf1\xbf\xc6\x7f\x8a\xf4\xc7\x93\xc7\x92\x2f" "\xd5\x83\x5d\xcb\x71\xdc\xe6\x40\x47\xf8\x2b\x51\xf9\x07\x34\xa5\x6a" "\xad\x03\x9a\xb6\xcb\xeb\xeb\x18\x91\xc9\xb7\x4e\x87\x4f\x17\xfd\xa7" "\x2d\xc8\x14\x8a\xef\xd4\x18\x95\x71\xf8\x5d\xcc\x22\x49\x01\x0d\xca" "\x4b\x7b\xd9\x56\x6e\x69\x7f\xee\x20\xd8\x73\x1c\xa2\xd9\x1f\x87\xbb" "\xda\x22\x26\x6c\x79\x70\x80\x8b\x0a\xe4\xd0\xe5\x5f\xf7\xd2\x03\xa5" "\x76\x40\x9c\xc4\x34\xa8\xcf\x7d\x75\x58\x52\x51\x58\xf0\x88\x44\x5c" "\x0e\xc9\x8c\xf0\xfc\x8a\xd0\x9d\x27\xe3\x20\xa8\xaa\x85\xf5\x2e\x94" "\xfd\xfe\xf8\x86\x18\x39\x86\x3c\x77\x4c\xd3\x21\x9e\xe6\xaf\xee\xd6" "\xb3\xb8\xbc\x7d\x32\x63\xab\x3c\x0e\x73\xb3\xd5\x5a\xe3\xcb\xb3\x5f" "\x35\xd7\x71\x7f\xa2\x6c\x20\x1c\x2a\x07\x54\x54\x36\x4e\xf2\x7d\xde" "\x12\x9d\x6b\xa0\x1a\xd9\xa1\xbb\xe8\x24\xc0\x1a\x5b\xea\x31\xe0\x1a" "\xf9\x42\x92\xb5\xbf\xa0\xa7\x1c\x0c\x34\xc0\xb3\x72\x53\xc9\xde\xe1" "\x40\x3c\xeb\x3a\xc1\x4e\xd2\x9e\x87\xe4\x0c\x9e\xe4\x4c\x14\x80\x2f" "\xe0\xf3\x08\x6f\x0e\x0c\xfc\x09\xf2\x1c\x42\x4c\xcd\xc2\x37\xc8\x4b" "\x61\x3d\xb4\x6b\x68\xde\x6e\xbf\xbd\x3f\x13\x57\xff\x9f\xbd\x9a\x91" "\x5c\x26\x24\x19\x9c\x6f\x20\xce\x7d\x95\x2c\x92\xbf\x2a\x72\xd3\x42" "\x45\x78\x88\xa8\x62\x54\x8b\xd2\x02\x30\x23\x4d\x0a\xf8\x8a\x17\xc4" "\x38\x09\xdb\x85\x18\x54\x4e\xb8\x7f\xde\xe1\x84\x23\x4c\xfe\xbb\xf6" "\x65\x8a\x51\xa3\xc8\xc9\x12\x1e\x36\x13\x15\x5d\xca\xb1\xd9\x71\x5e" "\xe5\xb2\x5e\x64\x0f\xd4\x21\x83\x50\x32\x90\xc5\x3f\x4e\x78\x2e\x5a" "\xba\x85\x2f\xf2\xba\xfa\x2b\x27\xd9\x2a\xf0\x78\xbd\x5a\xd0\x8b\xb9" "\xf3\xda\x8d\xca\xed\x75\x2f\x57\x12\x41\xdd\x26\x39\xc2\xed\x62\xac" "\x94\xff\xc0\x11\x3a\x60\x62\xed\x1f\x87\x77\x65\x13\x83\x35\xea\x02" "\x1b\xf9\x10\x3a\x68\xaf\x8e\x41\x74\x28\xf7\xd9\x49\xe9\x94\xef\xf8" "\x79\xdf\x85\x97\x04\x2d\x63\x57\x83\x01\x20\x7a\x77\x90\xb6\x69\x05" "\x6a\x8c\x69\x3e\x45\x21\x22\xfc\x1e\x81\xc8\xb7\xa9\x20\x0d\x28\x4d" "\x63\x4f\xf1\xe2\x2d\xde\xaa\xd7\xb6\xaf\xa0\xd1\x3f\xc6\x7b\xb0\xf7" "\xcb\x9c\x5e\x2e\x4f\xc8\x52\x04\xc4\x53\x22\x4a\x70\x25\xdd\xc4\xb0" "\x53\x09\x6b\x27\x37\x39\xc6\xd4\x62\x7b\xaf\x95\x8a\x81\x78\x48\xf0" "\xe1\x6d\x95\xa7\xb2\x6e\x54\x33\xff\xf0\xa0\xb4\xc8\xa7\xf9\xe8\x97" "\xbe\x53\x69\xbd\x37\x6e\xac\x96\xa5\x02\x19\x2d\x51\x37\xd3\xcd\x9d" "\x39\x12\x25\xea\x0a\xd5\xcb\x83\x69\x0c\x77\xc0\xe7\x68\x37\x7e\x73" "\x19\x30\x8e\x7d\x9f\xac\x95\xc0\xd5\xbf\x65\xf6\xf1\xa8\xa7\xa7\x73" "\x7e\x81\xd9\xfc\x5e\x78\x3e\x37\xea\xd7\x6c\x8d\x89\xe2\x42\xe2\xef" "\x45\xd8\xeb\xe4\xff\x6e\x21\xef\x6e\x89\x7f\x10\xfe\xac\x1b\x09\x08" "\x16\xd6\x72\x24\xe4\x99\xc9\xe8\x16\x18\xc4\xbf\x9b\xc2\xac\x43\xa0" "\x37\xa0\xc6\x76\xeb\xe5\x4b\x24\x2f\x0e\xd0\x5b\x26\xc0\xf5\x87\x57" "\xa5\xde\xf2\x1f\x93\xa5\xc3\xb7\xa6\x29\x3e\x85\x53\x01\xd7\x78\x52" "\x81\xac\x94\x31\x09\x98\x2c\x84\x37\x21\x95\x41\xb0\x8f\x5d\x8c\x59" "\x6c\x9b\xe8\x30\x12\xdb\xb6\x30\x1b\x93\xaf\xb3\xb3\x6c\x0f\x01\x68" "\x69\xf9\x6b\x90\x7c\xd4\x12\xc3\x4f\x55\x04\xc6\xf0\xb7\x2d\x7b\x9d" "\xad\x39\x0a\xdf\x97\x97\x72\x7b\xed\xa7\xc5\x24\xc6\x73\xac\xfd\x25" "\xd8\x34\xed\x18\xc6\x4e\x87\x54\x5c\xab\xdd\x35\xcf\x3d\xbe\x01\xc9" "\x31\x52\xd8\xd6\x7b\x23\xe9\xf1\xeb\x73\x41\xf9\xfd\x28\xe2\x5b\xf7" "\x14\xfe\x45\x79\x9b\xea\x0f\x20\xb7\x1c\x2f\x0f\xcb\x62\xf2\xf7\xea" "\x5d\x01\x89\xbf\xae\x06\xc3\x8b\x82\xf2\x6e\x7e\xc6\x66\x12\x99\x02" "\x70\x5f\x0e\x52\xe1\xf7\x89\x07\x81\xd6\xe3\x33\x27\x93\xca\x88\x8d" "\x3d\xe0\x2e\x32\x1f\xca\x88\x3e\xd6\x33\xea\x58\x00\x24\x54\x71\x40" "\xc2\xec\xcf\x15\x62\xac\x4b\x79\x0d\xe9\x40\x94\xd6\xe5\xb0\x16\xb5" "\x80\x7a\x8b\xcb\x19\xa1\xc5\x0c\xfa\x21\x9f\xb8\xef\xc6\x97\xae\x4b" "\xce\xb4\x98\xa8\x24\x13\xc6\x21\x8f\x2c\x23\x11\x6c\x25\xd1\x35\xa5" "\x78\x36\xa4\xef\xba\x10\x2b\x88\x13\x89\xeb\x07\x04\x14\x4b\x54\xa6" "\xf5\xc3\x72\xc8\xa6\x0f\x33\x55\x1d\xb9\x25\x94\x93\x2f\x9c\x7a\x9f" "\xab\xf3\x96\x72\xfe\x75\x29\xe6\x04\xa4\xe5\x35\xeb\xdd\x52\x7a\x41" "\x1b\x93\xca\xcb\x44\x1f\xf5\xf6\x36\x11\x92\xf4\x27\x62\xed\xc1\x9b" "\x2e\x8d\x1f\x38\x63\xa2\xa0\xf5\x7f\x93\xc1\x0a\x6d\x39\x9b\x02\xbb" "\x62\x94\x21\x44\xbb\x6c\x4d\xd0\x1e\x1f\xe1\xbe\xb9\xcb\x45\xf7\x69" "\x12\xdd\x90\x1d\x20\x75\xbd\xab\x3d\xdb\x0a\x72\xb8\xc5\x33\xbe\x38" "\x85\x3a\x22\x0d\xa0\x3d\xb3\x9a\xd8\x92\x96\xe0\x51\xc9\x4e\xf9\x69" "\x79\xbf\x93\x4c\xfe\x72\xfc\x33\xdb\x7f\x63\x39\x72\xdd\xae\x79\x5f" "\x24\x78\x56\xc9\x7a\xbb\x65\x86\xb1\x6e\x85\x34\x7a\x58\xcb\x31\x3d" "\x0c\x7f\xfe\xa8\x41\x77\xbe\x6c\xab\x90\x1a\xbc\xe2\x16\x57\xf5\xc7" "\xe1\x1b\x36\xc4\x01\x82\xc8\xc9\xcd\xfc\x87\xda\xff\xc3\xf2\xf9\xd8" "\x56\x90\xe4\xf2\x85\x42\x15\xf9\x63\xb4\xf8\x9a\xac\x09\x8f\x7b\xa9" "\x79\x88\xc1\x31\x91\x12\x41\xd6\xfa\x86\x32\x30\x76\x44\x7b\x58\xc8" "\x24\xd4\xae\x8a\xbc\xb9\x55\x8d\xb3\xf3\x09\x36\x76\x42\x30\x55\xe5" "\xba\x7a\x4b\x3d\xaa\x3e\x41\x17\x59\x62\xfa\xc1\x4a\x7e\x4b\xbc\x3f" "\x7a\x44\xb9\x0e\xfb\x31\xd0\x13\xf1\x4a\x08\x5f\x21\x35\xa2\xc9", 4096)); syscall(__NR_ioctl, r[2], 0x4080aebf, 0x20008400); break; case 5: syscall(__NR_ioctl, r[2], 0xc080aebe, 0x20002280); break; } } int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); install_segv_handler(); do_sandbox_none(); return 0; }
the_stack_data/218893903.c
/*===-- X86DisassemblerDecoder.c - Disassembler decoder ------------*- C -*-===* * * The LLVM Compiler Infrastructure * * This file is distributed under the University of Illinois Open Source * License. See LICENSE.TXT for details. * *===----------------------------------------------------------------------===* * * This file is part of the X86 Disassembler. * It contains the implementation of the instruction decoder. * Documentation for the disassembler can be found in X86Disassembler.h. * *===----------------------------------------------------------------------===*/ /* Capstone Disassembly Engine */ /* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */ #ifdef CAPSTONE_HAS_X86 #include <stdarg.h> /* for va_*() */ #if defined(CAPSTONE_HAS_OSXKERNEL) #include <libkern/libkern.h> #else #include <stdlib.h> /* for exit() */ #endif #include <string.h> #include "../../cs_priv.h" #include "../../utils.h" #include "X86DisassemblerDecoder.h" #include "X86Mapping.h" /// Specifies whether a ModR/M byte is needed and (if so) which /// instruction each possible value of the ModR/M byte corresponds to. Once /// this information is known, we have narrowed down to a single instruction. struct ModRMDecision { uint8_t modrm_type; uint16_t instructionIDs; }; /// Specifies which set of ModR/M->instruction tables to look at /// given a particular opcode. struct OpcodeDecision { struct ModRMDecision modRMDecisions[256]; }; /// Specifies which opcode->instruction tables to look at given /// a particular context (set of attributes). Since there are many possible /// contexts, the decoder first uses CONTEXTS_SYM to determine which context /// applies given a specific set of attributes. Hence there are only IC_max /// entries in this table, rather than 2^(ATTR_max). struct ContextDecision { struct OpcodeDecision opcodeDecisions[IC_max]; }; #ifdef CAPSTONE_X86_REDUCE #include "X86GenDisassemblerTables_reduce.inc" #include "X86GenDisassemblerTables_reduce2.inc" #include "X86Lookup16_reduce.inc" #else #include "X86GenDisassemblerTables.inc" #include "X86GenDisassemblerTables2.inc" #include "X86Lookup16.inc" #endif /* * contextForAttrs - Client for the instruction context table. Takes a set of * attributes and returns the appropriate decode context. * * @param attrMask - Attributes, from the enumeration attributeBits. * @return - The InstructionContext to use when looking up an * an instruction with these attributes. */ static InstructionContext contextForAttrs(uint16_t attrMask) { return CONTEXTS_SYM[attrMask]; } /* * modRMRequired - Reads the appropriate instruction table to determine whether * the ModR/M byte is required to decode a particular instruction. * * @param type - The opcode type (i.e., how many bytes it has). * @param insnContext - The context for the instruction, as returned by * contextForAttrs. * @param opcode - The last byte of the instruction's opcode, not counting * ModR/M extensions and escapes. * @return - true if the ModR/M byte is required, false otherwise. */ static int modRMRequired(OpcodeType type, InstructionContext insnContext, uint16_t opcode) { const struct OpcodeDecision *decision = NULL; const uint8_t *indextable = NULL; unsigned int index; switch (type) { default: break; case ONEBYTE: decision = ONEBYTE_SYM; indextable = index_x86DisassemblerOneByteOpcodes; break; case TWOBYTE: decision = TWOBYTE_SYM; indextable = index_x86DisassemblerTwoByteOpcodes; break; case THREEBYTE_38: decision = THREEBYTE38_SYM; indextable = index_x86DisassemblerThreeByte38Opcodes; break; case THREEBYTE_3A: decision = THREEBYTE3A_SYM; indextable = index_x86DisassemblerThreeByte3AOpcodes; break; #ifndef CAPSTONE_X86_REDUCE case XOP8_MAP: decision = XOP8_MAP_SYM; indextable = index_x86DisassemblerXOP8Opcodes; break; case XOP9_MAP: decision = XOP9_MAP_SYM; indextable = index_x86DisassemblerXOP9Opcodes; break; case XOPA_MAP: decision = XOPA_MAP_SYM; indextable = index_x86DisassemblerXOPAOpcodes; break; case THREEDNOW_MAP: // 3DNow instructions always have ModRM byte return true; #endif } // return decision->opcodeDecisions[insnContext].modRMDecisions[opcode].modrm_type != MODRM_ONEENTRY; index = indextable[insnContext]; if (index) return decision[index - 1].modRMDecisions[opcode].modrm_type != MODRM_ONEENTRY; else return false; } /* * decode - Reads the appropriate instruction table to obtain the unique ID of * an instruction. * * @param type - See modRMRequired(). * @param insnContext - See modRMRequired(). * @param opcode - See modRMRequired(). * @param modRM - The ModR/M byte if required, or any value if not. * @return - The UID of the instruction, or 0 on failure. */ static InstrUID decode(OpcodeType type, InstructionContext insnContext, uint8_t opcode, uint8_t modRM) { const struct ModRMDecision *dec = NULL; unsigned int index; static const struct OpcodeDecision emptyDecision = { 0 }; switch (type) { default: break; // never reach case ONEBYTE: // dec = &ONEBYTE_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode]; index = index_x86DisassemblerOneByteOpcodes[insnContext]; if (index) dec = &ONEBYTE_SYM[index - 1].modRMDecisions[opcode]; else dec = &emptyDecision.modRMDecisions[opcode]; break; case TWOBYTE: //dec = &TWOBYTE_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode]; index = index_x86DisassemblerTwoByteOpcodes[insnContext]; if (index) dec = &TWOBYTE_SYM[index - 1].modRMDecisions[opcode]; else dec = &emptyDecision.modRMDecisions[opcode]; break; case THREEBYTE_38: // dec = &THREEBYTE38_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode]; index = index_x86DisassemblerThreeByte38Opcodes[insnContext]; if (index) dec = &THREEBYTE38_SYM[index - 1].modRMDecisions[opcode]; else dec = &emptyDecision.modRMDecisions[opcode]; break; case THREEBYTE_3A: //dec = &THREEBYTE3A_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode]; index = index_x86DisassemblerThreeByte3AOpcodes[insnContext]; if (index) dec = &THREEBYTE3A_SYM[index - 1].modRMDecisions[opcode]; else dec = &emptyDecision.modRMDecisions[opcode]; break; #ifndef CAPSTONE_X86_REDUCE case XOP8_MAP: // dec = &XOP8_MAP_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode]; index = index_x86DisassemblerXOP8Opcodes[insnContext]; if (index) dec = &XOP8_MAP_SYM[index - 1].modRMDecisions[opcode]; else dec = &emptyDecision.modRMDecisions[opcode]; break; case XOP9_MAP: // dec = &XOP9_MAP_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode]; index = index_x86DisassemblerXOP9Opcodes[insnContext]; if (index) dec = &XOP9_MAP_SYM[index - 1].modRMDecisions[opcode]; else dec = &emptyDecision.modRMDecisions[opcode]; break; case XOPA_MAP: // dec = &XOPA_MAP_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode]; index = index_x86DisassemblerXOPAOpcodes[insnContext]; if (index) dec = &XOPA_MAP_SYM[index - 1].modRMDecisions[opcode]; else dec = &emptyDecision.modRMDecisions[opcode]; break; case THREEDNOW_MAP: // dec = &THREEDNOW_MAP_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode]; index = index_x86Disassembler3DNowOpcodes[insnContext]; if (index) dec = &THREEDNOW_MAP_SYM[index - 1].modRMDecisions[opcode]; else dec = &emptyDecision.modRMDecisions[opcode]; break; #endif } switch (dec->modrm_type) { default: // debug("Corrupt table! Unknown modrm_type"); return 0; case MODRM_ONEENTRY: return modRMTable[dec->instructionIDs]; case MODRM_SPLITRM: if (modFromModRM(modRM) == 0x3) return modRMTable[dec->instructionIDs + 1]; return modRMTable[dec->instructionIDs]; case MODRM_SPLITREG: if (modFromModRM(modRM) == 0x3) return modRMTable[dec->instructionIDs+((modRM & 0x38) >> 3) + 8]; return modRMTable[dec->instructionIDs+((modRM & 0x38) >> 3)]; case MODRM_SPLITMISC: if (modFromModRM(modRM) == 0x3) return modRMTable[dec->instructionIDs+(modRM & 0x3f) + 8]; return modRMTable[dec->instructionIDs+((modRM & 0x38) >> 3)]; case MODRM_FULL: return modRMTable[dec->instructionIDs+modRM]; } } /* * specifierForUID - Given a UID, returns the name and operand specification for * that instruction. * * @param uid - The unique ID for the instruction. This should be returned by * decode(); specifierForUID will not check bounds. * @return - A pointer to the specification for that instruction. */ static const struct InstructionSpecifier *specifierForUID(InstrUID uid) { return &INSTRUCTIONS_SYM[uid]; } /* * consumeByte - Uses the reader function provided by the user to consume one * byte from the instruction's memory and advance the cursor. * * @param insn - The instruction with the reader function to use. The cursor * for this instruction is advanced. * @param byte - A pointer to a pre-allocated memory buffer to be populated * with the data read. * @return - 0 if the read was successful; nonzero otherwise. */ static int consumeByte(struct InternalInstruction* insn, uint8_t* byte) { int ret = insn->reader(insn->readerArg, byte, insn->readerCursor); if (!ret) ++(insn->readerCursor); return ret; } /* * lookAtByte - Like consumeByte, but does not advance the cursor. * * @param insn - See consumeByte(). * @param byte - See consumeByte(). * @return - See consumeByte(). */ static int lookAtByte(struct InternalInstruction* insn, uint8_t* byte) { return insn->reader(insn->readerArg, byte, insn->readerCursor); } static void unconsumeByte(struct InternalInstruction* insn) { insn->readerCursor--; } #define CONSUME_FUNC(name, type) \ static int name(struct InternalInstruction* insn, type* ptr) { \ type combined = 0; \ unsigned offset; \ for (offset = 0; offset < sizeof(type); ++offset) { \ uint8_t byte; \ int ret = insn->reader(insn->readerArg, \ &byte, \ insn->readerCursor + offset); \ if (ret) \ return ret; \ combined = combined | ((uint64_t)byte << (offset * 8)); \ } \ *ptr = combined; \ insn->readerCursor += sizeof(type); \ return 0; \ } /* * consume* - Use the reader function provided by the user to consume data * values of various sizes from the instruction's memory and advance the * cursor appropriately. These readers perform endian conversion. * * @param insn - See consumeByte(). * @param ptr - A pointer to a pre-allocated memory of appropriate size to * be populated with the data read. * @return - See consumeByte(). */ CONSUME_FUNC(consumeInt8, int8_t) CONSUME_FUNC(consumeInt16, int16_t) CONSUME_FUNC(consumeInt32, int32_t) CONSUME_FUNC(consumeUInt16, uint16_t) CONSUME_FUNC(consumeUInt32, uint32_t) CONSUME_FUNC(consumeUInt64, uint64_t) static bool isREX(struct InternalInstruction *insn, uint8_t prefix) { if (insn->mode == MODE_64BIT) return prefix >= 0x40 && prefix <= 0x4f; return false; } /* * setPrefixPresent - Marks that a particular prefix is present as mandatory * * @param insn - The instruction to be marked as having the prefix. * @param prefix - The prefix that is present. */ static void setPrefixPresent(struct InternalInstruction *insn, uint8_t prefix) { uint8_t nextByte; switch (prefix) { case 0xf0: // LOCK insn->hasLockPrefix = true; insn->repeatPrefix = 0; break; case 0xf2: // REPNE/REPNZ case 0xf3: // REP or REPE/REPZ if (lookAtByte(insn, &nextByte)) break; // TODO: // 1. There could be several 0x66 // 2. if (nextByte == 0x66) and nextNextByte != 0x0f then // it's not mandatory prefix // 3. if (nextByte >= 0x40 && nextByte <= 0x4f) it's REX and we need // 0x0f exactly after it to be mandatory prefix if (isREX(insn, nextByte) || nextByte == 0x0f || nextByte == 0x66) // The last of 0xf2 /0xf3 is mandatory prefix insn->mandatoryPrefix = prefix; insn->repeatPrefix = prefix; insn->hasLockPrefix = false; break; case 0x66: if (lookAtByte(insn, &nextByte)) break; // 0x66 can't overwrite existing mandatory prefix and should be ignored if (!insn->mandatoryPrefix && (nextByte == 0x0f || isREX(insn, nextByte))) insn->mandatoryPrefix = prefix; break; } } /* * readPrefixes - Consumes all of an instruction's prefix bytes, and marks the * instruction as having them. Also sets the instruction's default operand, * address, and other relevant data sizes to report operands correctly. * * @param insn - The instruction whose prefixes are to be read. * @return - 0 if the instruction could be read until the end of the prefix * bytes, and no prefixes conflicted; nonzero otherwise. */ static int readPrefixes(struct InternalInstruction* insn) { bool isPrefix = true; uint8_t byte = 0; uint8_t nextByte; while (isPrefix) { if (insn->mode == MODE_64BIT) { // eliminate consecutive redundant REX bytes in front if (consumeByte(insn, &byte)) return -1; if ((byte & 0xf0) == 0x40) { while(true) { if (lookAtByte(insn, &byte)) // out of input code return -1; if ((byte & 0xf0) == 0x40) { // another REX prefix, but we only remember the last one if (consumeByte(insn, &byte)) return -1; } else break; } // recover the last REX byte if next byte is not a legacy prefix switch (byte) { case 0xf2: /* REPNE/REPNZ */ case 0xf3: /* REP or REPE/REPZ */ case 0xf0: /* LOCK */ case 0x2e: /* CS segment override -OR- Branch not taken */ case 0x36: /* SS segment override -OR- Branch taken */ case 0x3e: /* DS segment override */ case 0x26: /* ES segment override */ case 0x64: /* FS segment override */ case 0x65: /* GS segment override */ case 0x66: /* Operand-size override */ case 0x67: /* Address-size override */ break; default: /* Not a prefix byte */ unconsumeByte(insn); break; } } else { unconsumeByte(insn); } } /* If we fail reading prefixes, just stop here and let the opcode reader deal with it */ if (consumeByte(insn, &byte)) return -1; if (insn->readerCursor - 1 == insn->startLocation && (byte == 0xf2 || byte == 0xf3)) { // prefix requires next byte if (lookAtByte(insn, &nextByte)) return -1; /* * If the byte is 0xf2 or 0xf3, and any of the following conditions are * met: * - it is followed by a LOCK (0xf0) prefix * - it is followed by an xchg instruction * then it should be disassembled as a xacquire/xrelease not repne/rep. */ if (((nextByte == 0xf0) || ((nextByte & 0xfe) == 0x86 || (nextByte & 0xf8) == 0x90))) { insn->xAcquireRelease = byte; } /* * Also if the byte is 0xf3, and the following condition is met: * - it is followed by a "mov mem, reg" (opcode 0x88/0x89) or * "mov mem, imm" (opcode 0xc6/0xc7) instructions. * then it should be disassembled as an xrelease not rep. */ if (byte == 0xf3 && (nextByte == 0x88 || nextByte == 0x89 || nextByte == 0xc6 || nextByte == 0xc7)) { insn->xAcquireRelease = byte; } if (isREX(insn, nextByte)) { uint8_t nnextByte; // Go to REX prefix after the current one if (consumeByte(insn, &nnextByte)) return -1; // We should be able to read next byte after REX prefix if (lookAtByte(insn, &nnextByte)) return -1; unconsumeByte(insn); } } switch (byte) { case 0xf0: /* LOCK */ case 0xf2: /* REPNE/REPNZ */ case 0xf3: /* REP or REPE/REPZ */ // only accept the last prefix setPrefixPresent(insn, byte); insn->prefix0 = byte; break; case 0x2e: /* CS segment override -OR- Branch not taken */ case 0x36: /* SS segment override -OR- Branch taken */ case 0x3e: /* DS segment override */ case 0x26: /* ES segment override */ case 0x64: /* FS segment override */ case 0x65: /* GS segment override */ switch (byte) { case 0x2e: insn->segmentOverride = SEG_OVERRIDE_CS; insn->prefix1 = byte; break; case 0x36: insn->segmentOverride = SEG_OVERRIDE_SS; insn->prefix1 = byte; break; case 0x3e: insn->segmentOverride = SEG_OVERRIDE_DS; insn->prefix1 = byte; break; case 0x26: insn->segmentOverride = SEG_OVERRIDE_ES; insn->prefix1 = byte; break; case 0x64: insn->segmentOverride = SEG_OVERRIDE_FS; insn->prefix1 = byte; break; case 0x65: insn->segmentOverride = SEG_OVERRIDE_GS; insn->prefix1 = byte; break; default: // debug("Unhandled override"); return -1; } setPrefixPresent(insn, byte); break; case 0x66: /* Operand-size override */ insn->hasOpSize = true; setPrefixPresent(insn, byte); insn->prefix2 = byte; break; case 0x67: /* Address-size override */ insn->hasAdSize = true; setPrefixPresent(insn, byte); insn->prefix3 = byte; break; default: /* Not a prefix byte */ isPrefix = false; break; } } insn->vectorExtensionType = TYPE_NO_VEX_XOP; if (byte == 0x62) { uint8_t byte1, byte2; if (consumeByte(insn, &byte1)) { // dbgprintf(insn, "Couldn't read second byte of EVEX prefix"); return -1; } if (lookAtByte(insn, &byte2)) { // dbgprintf(insn, "Couldn't read third byte of EVEX prefix"); unconsumeByte(insn); /* unconsume byte1 */ unconsumeByte(insn); /* unconsume byte */ } else { if ((insn->mode == MODE_64BIT || (byte1 & 0xc0) == 0xc0) && ((~byte1 & 0xc) == 0xc) && ((byte2 & 0x4) == 0x4)) { insn->vectorExtensionType = TYPE_EVEX; } else { unconsumeByte(insn); /* unconsume byte1 */ unconsumeByte(insn); /* unconsume byte */ } } if (insn->vectorExtensionType == TYPE_EVEX) { insn->vectorExtensionPrefix[0] = byte; insn->vectorExtensionPrefix[1] = byte1; if (consumeByte(insn, &insn->vectorExtensionPrefix[2])) { // dbgprintf(insn, "Couldn't read third byte of EVEX prefix"); return -1; } if (consumeByte(insn, &insn->vectorExtensionPrefix[3])) { // dbgprintf(insn, "Couldn't read fourth byte of EVEX prefix"); return -1; } /* We simulate the REX prefix for simplicity's sake */ if (insn->mode == MODE_64BIT) { insn->rexPrefix = 0x40 | (wFromEVEX3of4(insn->vectorExtensionPrefix[2]) << 3) | (rFromEVEX2of4(insn->vectorExtensionPrefix[1]) << 2) | (xFromEVEX2of4(insn->vectorExtensionPrefix[1]) << 1) | (bFromEVEX2of4(insn->vectorExtensionPrefix[1]) << 0); } // dbgprintf(insn, "Found EVEX prefix 0x%hhx 0x%hhx 0x%hhx 0x%hhx", // insn->vectorExtensionPrefix[0], insn->vectorExtensionPrefix[1], // insn->vectorExtensionPrefix[2], insn->vectorExtensionPrefix[3]); } } else if (byte == 0xc4) { uint8_t byte1; if (lookAtByte(insn, &byte1)) { // dbgprintf(insn, "Couldn't read second byte of VEX"); return -1; } if (insn->mode == MODE_64BIT || (byte1 & 0xc0) == 0xc0) insn->vectorExtensionType = TYPE_VEX_3B; else unconsumeByte(insn); if (insn->vectorExtensionType == TYPE_VEX_3B) { insn->vectorExtensionPrefix[0] = byte; consumeByte(insn, &insn->vectorExtensionPrefix[1]); consumeByte(insn, &insn->vectorExtensionPrefix[2]); /* We simulate the REX prefix for simplicity's sake */ if (insn->mode == MODE_64BIT) insn->rexPrefix = 0x40 | (wFromVEX3of3(insn->vectorExtensionPrefix[2]) << 3) | (rFromVEX2of3(insn->vectorExtensionPrefix[1]) << 2) | (xFromVEX2of3(insn->vectorExtensionPrefix[1]) << 1) | (bFromVEX2of3(insn->vectorExtensionPrefix[1]) << 0); // dbgprintf(insn, "Found VEX prefix 0x%hhx 0x%hhx 0x%hhx", // insn->vectorExtensionPrefix[0], insn->vectorExtensionPrefix[1], // insn->vectorExtensionPrefix[2]); } } else if (byte == 0xc5) { uint8_t byte1; if (lookAtByte(insn, &byte1)) { // dbgprintf(insn, "Couldn't read second byte of VEX"); return -1; } if (insn->mode == MODE_64BIT || (byte1 & 0xc0) == 0xc0) insn->vectorExtensionType = TYPE_VEX_2B; else unconsumeByte(insn); if (insn->vectorExtensionType == TYPE_VEX_2B) { insn->vectorExtensionPrefix[0] = byte; consumeByte(insn, &insn->vectorExtensionPrefix[1]); if (insn->mode == MODE_64BIT) insn->rexPrefix = 0x40 | (rFromVEX2of2(insn->vectorExtensionPrefix[1]) << 2); switch (ppFromVEX2of2(insn->vectorExtensionPrefix[1])) { default: break; case VEX_PREFIX_66: insn->hasOpSize = true; break; } // dbgprintf(insn, "Found VEX prefix 0x%hhx 0x%hhx", // insn->vectorExtensionPrefix[0], // insn->vectorExtensionPrefix[1]); } } else if (byte == 0x8f) { uint8_t byte1; if (lookAtByte(insn, &byte1)) { // dbgprintf(insn, "Couldn't read second byte of XOP"); return -1; } if ((byte1 & 0x38) != 0x0) /* 0 in these 3 bits is a POP instruction. */ insn->vectorExtensionType = TYPE_XOP; else unconsumeByte(insn); if (insn->vectorExtensionType == TYPE_XOP) { insn->vectorExtensionPrefix[0] = byte; consumeByte(insn, &insn->vectorExtensionPrefix[1]); consumeByte(insn, &insn->vectorExtensionPrefix[2]); /* We simulate the REX prefix for simplicity's sake */ if (insn->mode == MODE_64BIT) insn->rexPrefix = 0x40 | (wFromXOP3of3(insn->vectorExtensionPrefix[2]) << 3) | (rFromXOP2of3(insn->vectorExtensionPrefix[1]) << 2) | (xFromXOP2of3(insn->vectorExtensionPrefix[1]) << 1) | (bFromXOP2of3(insn->vectorExtensionPrefix[1]) << 0); switch (ppFromXOP3of3(insn->vectorExtensionPrefix[2])) { default: break; case VEX_PREFIX_66: insn->hasOpSize = true; break; } // dbgprintf(insn, "Found XOP prefix 0x%hhx 0x%hhx 0x%hhx", // insn->vectorExtensionPrefix[0], insn->vectorExtensionPrefix[1], // insn->vectorExtensionPrefix[2]); } } else if (isREX(insn, byte)) { if (lookAtByte(insn, &nextByte)) return -1; insn->rexPrefix = byte; // dbgprintf(insn, "Found REX prefix 0x%hhx", byte); } else unconsumeByte(insn); if (insn->mode == MODE_16BIT) { insn->registerSize = (insn->hasOpSize ? 4 : 2); insn->addressSize = (insn->hasAdSize ? 4 : 2); insn->displacementSize = (insn->hasAdSize ? 4 : 2); insn->immediateSize = (insn->hasOpSize ? 4 : 2); insn->immSize = (insn->hasOpSize ? 4 : 2); } else if (insn->mode == MODE_32BIT) { insn->registerSize = (insn->hasOpSize ? 2 : 4); insn->addressSize = (insn->hasAdSize ? 2 : 4); insn->displacementSize = (insn->hasAdSize ? 2 : 4); insn->immediateSize = (insn->hasOpSize ? 2 : 4); insn->immSize = (insn->hasOpSize ? 2 : 4); } else if (insn->mode == MODE_64BIT) { if (insn->rexPrefix && wFromREX(insn->rexPrefix)) { insn->registerSize = 8; insn->addressSize = (insn->hasAdSize ? 4 : 8); insn->displacementSize = 4; insn->immediateSize = 4; insn->immSize = 4; } else { insn->registerSize = (insn->hasOpSize ? 2 : 4); insn->addressSize = (insn->hasAdSize ? 4 : 8); insn->displacementSize = (insn->hasOpSize ? 2 : 4); insn->immediateSize = (insn->hasOpSize ? 2 : 4); insn->immSize = (insn->hasOpSize ? 4 : 8); } } return 0; } static int readModRM(struct InternalInstruction* insn); /* * readOpcode - Reads the opcode (excepting the ModR/M byte in the case of * extended or escape opcodes). * * @param insn - The instruction whose opcode is to be read. * @return - 0 if the opcode could be read successfully; nonzero otherwise. */ static int readOpcode(struct InternalInstruction* insn) { uint8_t current; // dbgprintf(insn, "readOpcode()"); insn->opcodeType = ONEBYTE; if (insn->vectorExtensionType == TYPE_EVEX) { switch (mmFromEVEX2of4(insn->vectorExtensionPrefix[1])) { default: // dbgprintf(insn, "Unhandled mm field for instruction (0x%hhx)", // mmFromEVEX2of4(insn->vectorExtensionPrefix[1])); return -1; case VEX_LOB_0F: insn->opcodeType = TWOBYTE; return consumeByte(insn, &insn->opcode); case VEX_LOB_0F38: insn->opcodeType = THREEBYTE_38; return consumeByte(insn, &insn->opcode); case VEX_LOB_0F3A: insn->opcodeType = THREEBYTE_3A; return consumeByte(insn, &insn->opcode); } } else if (insn->vectorExtensionType == TYPE_VEX_3B) { switch (mmmmmFromVEX2of3(insn->vectorExtensionPrefix[1])) { default: // dbgprintf(insn, "Unhandled m-mmmm field for instruction (0x%hhx)", // mmmmmFromVEX2of3(insn->vectorExtensionPrefix[1])); return -1; case VEX_LOB_0F: //insn->twoByteEscape = 0x0f; insn->opcodeType = TWOBYTE; return consumeByte(insn, &insn->opcode); case VEX_LOB_0F38: //insn->twoByteEscape = 0x0f; insn->opcodeType = THREEBYTE_38; return consumeByte(insn, &insn->opcode); case VEX_LOB_0F3A: //insn->twoByteEscape = 0x0f; insn->opcodeType = THREEBYTE_3A; return consumeByte(insn, &insn->opcode); } } else if (insn->vectorExtensionType == TYPE_VEX_2B) { //insn->twoByteEscape = 0x0f; insn->opcodeType = TWOBYTE; return consumeByte(insn, &insn->opcode); } else if (insn->vectorExtensionType == TYPE_XOP) { switch (mmmmmFromXOP2of3(insn->vectorExtensionPrefix[1])) { default: // dbgprintf(insn, "Unhandled m-mmmm field for instruction (0x%hhx)", // mmmmmFromVEX2of3(insn->vectorExtensionPrefix[1])); return -1; case XOP_MAP_SELECT_8: insn->opcodeType = XOP8_MAP; return consumeByte(insn, &insn->opcode); case XOP_MAP_SELECT_9: insn->opcodeType = XOP9_MAP; return consumeByte(insn, &insn->opcode); case XOP_MAP_SELECT_A: insn->opcodeType = XOPA_MAP; return consumeByte(insn, &insn->opcode); } } if (consumeByte(insn, &current)) return -1; // save this first byte for MOVcr, MOVdr, MOVrc, MOVrd insn->firstByte = current; if (current == 0x0f) { // dbgprintf(insn, "Found a two-byte escape prefix (0x%hhx)", current); insn->twoByteEscape = current; if (consumeByte(insn, &current)) return -1; if (current == 0x38) { // dbgprintf(insn, "Found a three-byte escape prefix (0x%hhx)", current); if (consumeByte(insn, &current)) return -1; insn->opcodeType = THREEBYTE_38; } else if (current == 0x3a) { // dbgprintf(insn, "Found a three-byte escape prefix (0x%hhx)", current); if (consumeByte(insn, &current)) return -1; insn->opcodeType = THREEBYTE_3A; } else if (current == 0x0f) { // dbgprintf(insn, "Found a 3dnow escape prefix (0x%hhx)", current); // Consume operands before the opcode to comply with the 3DNow encoding if (readModRM(insn)) return -1; if (consumeByte(insn, &current)) return -1; insn->opcodeType = THREEDNOW_MAP; } else { // dbgprintf(insn, "Didn't find a three-byte escape prefix"); insn->opcodeType = TWOBYTE; } } else if (insn->mandatoryPrefix) // The opcode with mandatory prefix must start with opcode escape. // If not it's legacy repeat prefix insn->mandatoryPrefix = 0; /* * At this point we have consumed the full opcode. * Anything we consume from here on must be unconsumed. */ insn->opcode = current; return 0; } // Hacky for FEMMS #define GET_INSTRINFO_ENUM #ifndef CAPSTONE_X86_REDUCE #include "X86GenInstrInfo.inc" #else #include "X86GenInstrInfo_reduce.inc" #endif /* * getIDWithAttrMask - Determines the ID of an instruction, consuming * the ModR/M byte as appropriate for extended and escape opcodes, * and using a supplied attribute mask. * * @param instructionID - A pointer whose target is filled in with the ID of the * instruction. * @param insn - The instruction whose ID is to be determined. * @param attrMask - The attribute mask to search. * @return - 0 if the ModR/M could be read when needed or was not * needed; nonzero otherwise. */ static int getIDWithAttrMask(uint16_t *instructionID, struct InternalInstruction* insn, uint16_t attrMask) { bool hasModRMExtension; InstructionContext instructionClass = contextForAttrs(attrMask); hasModRMExtension = modRMRequired(insn->opcodeType, instructionClass, insn->opcode); if (hasModRMExtension) { if (readModRM(insn)) return -1; *instructionID = decode(insn->opcodeType, instructionClass, insn->opcode, insn->modRM); } else { *instructionID = decode(insn->opcodeType, instructionClass, insn->opcode, 0); } return 0; } /* * is16BitEquivalent - Determines whether two instruction names refer to * equivalent instructions but one is 16-bit whereas the other is not. * * @param orig - The instruction ID that is not 16-bit * @param equiv - The instruction ID that is 16-bit */ static bool is16BitEquivalent(unsigned orig, unsigned equiv) { size_t i; uint16_t idx; if ((idx = x86_16_bit_eq_lookup[orig]) != 0) { for (i = idx - 1; i < ARR_SIZE(x86_16_bit_eq_tbl) && x86_16_bit_eq_tbl[i].first == orig; i++) { if (x86_16_bit_eq_tbl[i].second == equiv) return true; } } return false; } /* * is64Bit - Determines whether this instruction is a 64-bit instruction. * * @param name - The instruction that is not 16-bit */ static bool is64Bit(uint16_t id) { unsigned int i = find_insn(id); if (i != -1) { return insns[i].is64bit; } // not found?? return false; } /* * getID - Determines the ID of an instruction, consuming the ModR/M byte as * appropriate for extended and escape opcodes. Determines the attributes and * context for the instruction before doing so. * * @param insn - The instruction whose ID is to be determined. * @return - 0 if the ModR/M could be read when needed or was not needed; * nonzero otherwise. */ static int getID(struct InternalInstruction *insn) { uint16_t attrMask; uint16_t instructionID; attrMask = ATTR_NONE; if (insn->mode == MODE_64BIT) attrMask |= ATTR_64BIT; if (insn->vectorExtensionType != TYPE_NO_VEX_XOP) { attrMask |= (insn->vectorExtensionType == TYPE_EVEX) ? ATTR_EVEX : ATTR_VEX; if (insn->vectorExtensionType == TYPE_EVEX) { switch (ppFromEVEX3of4(insn->vectorExtensionPrefix[2])) { case VEX_PREFIX_66: attrMask |= ATTR_OPSIZE; break; case VEX_PREFIX_F3: attrMask |= ATTR_XS; break; case VEX_PREFIX_F2: attrMask |= ATTR_XD; break; } if (zFromEVEX4of4(insn->vectorExtensionPrefix[3])) attrMask |= ATTR_EVEXKZ; if (bFromEVEX4of4(insn->vectorExtensionPrefix[3])) attrMask |= ATTR_EVEXB; if (aaaFromEVEX4of4(insn->vectorExtensionPrefix[3])) attrMask |= ATTR_EVEXK; if (lFromEVEX4of4(insn->vectorExtensionPrefix[3])) attrMask |= ATTR_EVEXL; if (l2FromEVEX4of4(insn->vectorExtensionPrefix[3])) attrMask |= ATTR_EVEXL2; } else if (insn->vectorExtensionType == TYPE_VEX_3B) { switch (ppFromVEX3of3(insn->vectorExtensionPrefix[2])) { case VEX_PREFIX_66: attrMask |= ATTR_OPSIZE; break; case VEX_PREFIX_F3: attrMask |= ATTR_XS; break; case VEX_PREFIX_F2: attrMask |= ATTR_XD; break; } if (lFromVEX3of3(insn->vectorExtensionPrefix[2])) attrMask |= ATTR_VEXL; } else if (insn->vectorExtensionType == TYPE_VEX_2B) { switch (ppFromVEX2of2(insn->vectorExtensionPrefix[1])) { case VEX_PREFIX_66: attrMask |= ATTR_OPSIZE; break; case VEX_PREFIX_F3: attrMask |= ATTR_XS; break; case VEX_PREFIX_F2: attrMask |= ATTR_XD; break; } if (lFromVEX2of2(insn->vectorExtensionPrefix[1])) attrMask |= ATTR_VEXL; } else if (insn->vectorExtensionType == TYPE_XOP) { switch (ppFromXOP3of3(insn->vectorExtensionPrefix[2])) { case VEX_PREFIX_66: attrMask |= ATTR_OPSIZE; break; case VEX_PREFIX_F3: attrMask |= ATTR_XS; break; case VEX_PREFIX_F2: attrMask |= ATTR_XD; break; } if (lFromXOP3of3(insn->vectorExtensionPrefix[2])) attrMask |= ATTR_VEXL; } else { return -1; } } else if (!insn->mandatoryPrefix) { // If we don't have mandatory prefix we should use legacy prefixes here if (insn->hasOpSize && (insn->mode != MODE_16BIT)) attrMask |= ATTR_OPSIZE; if (insn->hasAdSize) attrMask |= ATTR_ADSIZE; if (insn->opcodeType == ONEBYTE) { if (insn->repeatPrefix == 0xf3 && (insn->opcode == 0x90)) // Special support for PAUSE attrMask |= ATTR_XS; } else { if (insn->repeatPrefix == 0xf2) attrMask |= ATTR_XD; else if (insn->repeatPrefix == 0xf3) attrMask |= ATTR_XS; } } else { switch (insn->mandatoryPrefix) { case 0xf2: attrMask |= ATTR_XD; break; case 0xf3: attrMask |= ATTR_XS; break; case 0x66: if (insn->mode != MODE_16BIT) attrMask |= ATTR_OPSIZE; break; case 0x67: attrMask |= ATTR_ADSIZE; break; } } if (insn->rexPrefix & 0x08) { attrMask |= ATTR_REXW; attrMask &= ~ATTR_ADSIZE; } /* * JCXZ/JECXZ need special handling for 16-bit mode because the meaning * of the AdSize prefix is inverted w.r.t. 32-bit mode. */ if (insn->mode == MODE_16BIT && insn->opcodeType == ONEBYTE && insn->opcode == 0xE3) attrMask ^= ATTR_ADSIZE; /* * In 64-bit mode all f64 superscripted opcodes ignore opcode size prefix * CALL/JMP/JCC instructions need to ignore 0x66 and consume 4 bytes */ if ((insn->mode == MODE_64BIT) && insn->hasOpSize) { switch (insn->opcode) { case 0xE8: case 0xE9: // Take care of psubsb and other mmx instructions. if (insn->opcodeType == ONEBYTE) { attrMask ^= ATTR_OPSIZE; insn->immediateSize = 4; insn->displacementSize = 4; } break; case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: case 0x88: case 0x89: case 0x8A: case 0x8B: case 0x8C: case 0x8D: case 0x8E: case 0x8F: // Take care of lea and three byte ops. if (insn->opcodeType == TWOBYTE) { attrMask ^= ATTR_OPSIZE; insn->immediateSize = 4; insn->displacementSize = 4; } break; } } if (getIDWithAttrMask(&instructionID, insn, attrMask)) { return -1; } /* The following clauses compensate for limitations of the tables. */ if (insn->mode != MODE_64BIT && insn->vectorExtensionType != TYPE_NO_VEX_XOP) { /* * The tables can't distinquish between cases where the W-bit is used to * select register size and cases where its a required part of the opcode. */ if ((insn->vectorExtensionType == TYPE_EVEX && wFromEVEX3of4(insn->vectorExtensionPrefix[2])) || (insn->vectorExtensionType == TYPE_VEX_3B && wFromVEX3of3(insn->vectorExtensionPrefix[2])) || (insn->vectorExtensionType == TYPE_XOP && wFromXOP3of3(insn->vectorExtensionPrefix[2]))) { uint16_t instructionIDWithREXW; if (getIDWithAttrMask(&instructionIDWithREXW, insn, attrMask | ATTR_REXW)) { insn->instructionID = instructionID; insn->spec = specifierForUID(instructionID); return 0; } // If not a 64-bit instruction. Switch the opcode. if (!is64Bit(instructionIDWithREXW)) { insn->instructionID = instructionIDWithREXW; insn->spec = specifierForUID(instructionIDWithREXW); return 0; } } } /* * Absolute moves, umonitor, and movdir64b need special handling. * -For 16-bit mode because the meaning of the AdSize and OpSize prefixes are * inverted w.r.t. * -For 32-bit mode we need to ensure the ADSIZE prefix is observed in * any position. */ if ((insn->opcodeType == ONEBYTE && ((insn->opcode & 0xFC) == 0xA0)) || (insn->opcodeType == TWOBYTE && (insn->opcode == 0xAE)) || (insn->opcodeType == THREEBYTE_38 && insn->opcode == 0xF8)) { /* Make sure we observed the prefixes in any position. */ if (insn->hasAdSize) attrMask |= ATTR_ADSIZE; if (insn->hasOpSize) attrMask |= ATTR_OPSIZE; /* In 16-bit, invert the attributes. */ if (insn->mode == MODE_16BIT) { attrMask ^= ATTR_ADSIZE; /* The OpSize attribute is only valid with the absolute moves. */ if (insn->opcodeType == ONEBYTE && ((insn->opcode & 0xFC) == 0xA0)) attrMask ^= ATTR_OPSIZE; } if (getIDWithAttrMask(&instructionID, insn, attrMask)) { return -1; } insn->instructionID = instructionID; insn->spec = specifierForUID(instructionID); return 0; } if ((insn->mode == MODE_16BIT || insn->hasOpSize) && !(attrMask & ATTR_OPSIZE)) { /* * The instruction tables make no distinction between instructions that * allow OpSize anywhere (i.e., 16-bit operations) and that need it in a * particular spot (i.e., many MMX operations). In general we're * conservative, but in the specific case where OpSize is present but not * in the right place we check if there's a 16-bit operation. */ const struct InstructionSpecifier *spec; uint16_t instructionIDWithOpsize; spec = specifierForUID(instructionID); if (getIDWithAttrMask(&instructionIDWithOpsize, insn, attrMask | ATTR_OPSIZE)) { /* * ModRM required with OpSize but not present; give up and return version * without OpSize set */ insn->instructionID = instructionID; insn->spec = spec; return 0; } if (is16BitEquivalent(instructionID, instructionIDWithOpsize) && (insn->mode == MODE_16BIT) ^ insn->hasOpSize) { insn->instructionID = instructionIDWithOpsize; insn->spec = specifierForUID(instructionIDWithOpsize); } else { insn->instructionID = instructionID; insn->spec = spec; } return 0; } if (insn->opcodeType == ONEBYTE && insn->opcode == 0x90 && insn->rexPrefix & 0x01) { /* * NOOP shouldn't decode as NOOP if REX.b is set. Instead * it should decode as XCHG %r8, %eax. */ const struct InstructionSpecifier *spec; uint16_t instructionIDWithNewOpcode; const struct InstructionSpecifier *specWithNewOpcode; spec = specifierForUID(instructionID); /* Borrow opcode from one of the other XCHGar opcodes */ insn->opcode = 0x91; if (getIDWithAttrMask(&instructionIDWithNewOpcode, insn, attrMask)) { insn->opcode = 0x90; insn->instructionID = instructionID; insn->spec = spec; return 0; } specWithNewOpcode = specifierForUID(instructionIDWithNewOpcode); /* Change back */ insn->opcode = 0x90; insn->instructionID = instructionIDWithNewOpcode; insn->spec = specWithNewOpcode; return 0; } insn->instructionID = instructionID; insn->spec = specifierForUID(insn->instructionID); return 0; } /* * readSIB - Consumes the SIB byte to determine addressing information for an * instruction. * * @param insn - The instruction whose SIB byte is to be read. * @return - 0 if the SIB byte was successfully read; nonzero otherwise. */ static int readSIB(struct InternalInstruction* insn) { SIBBase sibBaseBase = SIB_BASE_NONE; uint8_t index, base; // dbgprintf(insn, "readSIB()"); if (insn->consumedSIB) return 0; insn->consumedSIB = true; switch (insn->addressSize) { case 2: // dbgprintf(insn, "SIB-based addressing doesn't work in 16-bit mode"); return -1; case 4: insn->sibIndexBase = SIB_INDEX_EAX; sibBaseBase = SIB_BASE_EAX; break; case 8: insn->sibIndexBase = SIB_INDEX_RAX; sibBaseBase = SIB_BASE_RAX; break; } if (consumeByte(insn, &insn->sib)) return -1; index = indexFromSIB(insn->sib) | (xFromREX(insn->rexPrefix) << 3); if (index == 0x4) { insn->sibIndex = SIB_INDEX_NONE; } else { insn->sibIndex = (SIBIndex)(insn->sibIndexBase + index); } insn->sibScale = 1 << scaleFromSIB(insn->sib); base = baseFromSIB(insn->sib) | (bFromREX(insn->rexPrefix) << 3); switch (base) { case 0x5: case 0xd: switch (modFromModRM(insn->modRM)) { case 0x0: insn->eaDisplacement = EA_DISP_32; insn->sibBase = SIB_BASE_NONE; break; case 0x1: insn->eaDisplacement = EA_DISP_8; insn->sibBase = (SIBBase)(sibBaseBase + base); break; case 0x2: insn->eaDisplacement = EA_DISP_32; insn->sibBase = (SIBBase)(sibBaseBase + base); break; case 0x3: // debug("Cannot have Mod = 0b11 and a SIB byte"); return -1; } break; default: insn->sibBase = (SIBBase)(sibBaseBase + base); break; } return 0; } /* * readDisplacement - Consumes the displacement of an instruction. * * @param insn - The instruction whose displacement is to be read. * @return - 0 if the displacement byte was successfully read; nonzero * otherwise. */ static int readDisplacement(struct InternalInstruction* insn) { int8_t d8; int16_t d16; int32_t d32; // dbgprintf(insn, "readDisplacement()"); if (insn->consumedDisplacement) return 0; insn->consumedDisplacement = true; insn->displacementOffset = insn->readerCursor - insn->startLocation; switch (insn->eaDisplacement) { case EA_DISP_NONE: insn->consumedDisplacement = false; break; case EA_DISP_8: if (consumeInt8(insn, &d8)) return -1; insn->displacement = d8; break; case EA_DISP_16: if (consumeInt16(insn, &d16)) return -1; insn->displacement = d16; break; case EA_DISP_32: if (consumeInt32(insn, &d32)) return -1; insn->displacement = d32; break; } return 0; } /* * readModRM - Consumes all addressing information (ModR/M byte, SIB byte, and * displacement) for an instruction and interprets it. * * @param insn - The instruction whose addressing information is to be read. * @return - 0 if the information was successfully read; nonzero otherwise. */ static int readModRM(struct InternalInstruction* insn) { uint8_t mod, rm, reg, evexrm; // dbgprintf(insn, "readModRM()"); if (insn->consumedModRM) return 0; insn->modRMOffset = (uint8_t)(insn->readerCursor - insn->startLocation); if (consumeByte(insn, &insn->modRM)) return -1; insn->consumedModRM = true; // save original ModRM for later reference insn->orgModRM = insn->modRM; // handle MOVcr, MOVdr, MOVrc, MOVrd by pretending they have MRM.mod = 3 if ((insn->firstByte == 0x0f && insn->opcodeType == TWOBYTE) && (insn->opcode >= 0x20 && insn->opcode <= 0x23 )) insn->modRM |= 0xC0; mod = modFromModRM(insn->modRM); rm = rmFromModRM(insn->modRM); reg = regFromModRM(insn->modRM); /* * This goes by insn->registerSize to pick the correct register, which messes * up if we're using (say) XMM or 8-bit register operands. That gets fixed in * fixupReg(). */ switch (insn->registerSize) { case 2: insn->regBase = MODRM_REG_AX; insn->eaRegBase = EA_REG_AX; break; case 4: insn->regBase = MODRM_REG_EAX; insn->eaRegBase = EA_REG_EAX; break; case 8: insn->regBase = MODRM_REG_RAX; insn->eaRegBase = EA_REG_RAX; break; } reg |= rFromREX(insn->rexPrefix) << 3; rm |= bFromREX(insn->rexPrefix) << 3; evexrm = 0; if (insn->vectorExtensionType == TYPE_EVEX && insn->mode == MODE_64BIT) { reg |= r2FromEVEX2of4(insn->vectorExtensionPrefix[1]) << 4; evexrm = xFromEVEX2of4(insn->vectorExtensionPrefix[1]) << 4; } insn->reg = (Reg)(insn->regBase + reg); switch (insn->addressSize) { case 2: { EABase eaBaseBase = EA_BASE_BX_SI; switch (mod) { case 0x0: if (rm == 0x6) { insn->eaBase = EA_BASE_NONE; insn->eaDisplacement = EA_DISP_16; if (readDisplacement(insn)) return -1; } else { insn->eaBase = (EABase)(eaBaseBase + rm); insn->eaDisplacement = EA_DISP_NONE; } break; case 0x1: insn->eaBase = (EABase)(eaBaseBase + rm); insn->eaDisplacement = EA_DISP_8; insn->displacementSize = 1; if (readDisplacement(insn)) return -1; break; case 0x2: insn->eaBase = (EABase)(eaBaseBase + rm); insn->eaDisplacement = EA_DISP_16; if (readDisplacement(insn)) return -1; break; case 0x3: insn->eaBase = (EABase)(insn->eaRegBase + rm); if (readDisplacement(insn)) return -1; break; } break; } case 4: case 8: { EABase eaBaseBase = (insn->addressSize == 4 ? EA_BASE_EAX : EA_BASE_RAX); switch (mod) { default: break; case 0x0: insn->eaDisplacement = EA_DISP_NONE; /* readSIB may override this */ // In determining whether RIP-relative mode is used (rm=5), // or whether a SIB byte is present (rm=4), // the extension bits (REX.b and EVEX.x) are ignored. switch (rm & 7) { case 0x4: // SIB byte is present insn->eaBase = (insn->addressSize == 4 ? EA_BASE_sib : EA_BASE_sib64); if (readSIB(insn) || readDisplacement(insn)) return -1; break; case 0x5: // RIP-relative insn->eaBase = EA_BASE_NONE; insn->eaDisplacement = EA_DISP_32; if (readDisplacement(insn)) return -1; break; default: insn->eaBase = (EABase)(eaBaseBase + rm); break; } break; case 0x1: insn->displacementSize = 1; /* FALLTHROUGH */ case 0x2: insn->eaDisplacement = (mod == 0x1 ? EA_DISP_8 : EA_DISP_32); switch (rm & 7) { case 0x4: // SIB byte is present insn->eaBase = EA_BASE_sib; if (readSIB(insn) || readDisplacement(insn)) return -1; break; default: insn->eaBase = (EABase)(eaBaseBase + rm); if (readDisplacement(insn)) return -1; break; } break; case 0x3: insn->eaDisplacement = EA_DISP_NONE; insn->eaBase = (EABase)(insn->eaRegBase + rm + evexrm); break; } break; } } /* switch (insn->addressSize) */ return 0; } #define GENERIC_FIXUP_FUNC(name, base, prefix, mask) \ static uint16_t name(struct InternalInstruction *insn, \ OperandType type, \ uint8_t index, \ uint8_t *valid) { \ *valid = 1; \ switch (type) { \ default: \ *valid = 0; \ return 0; \ case TYPE_Rv: \ return base + index; \ case TYPE_R8: \ index &= mask; \ if (index > 0xf) \ *valid = 0; \ if (insn->rexPrefix && \ index >= 4 && index <= 7) { \ return prefix##_SPL + (index - 4); \ } else { \ return prefix##_AL + index; \ } \ case TYPE_R16: \ index &= mask; \ if (index > 0xf) \ *valid = 0; \ return prefix##_AX + index; \ case TYPE_R32: \ index &= mask; \ if (index > 0xf) \ *valid = 0; \ return prefix##_EAX + index; \ case TYPE_R64: \ index &= mask; \ if (index > 0xf) \ *valid = 0; \ return prefix##_RAX + index; \ case TYPE_ZMM: \ return prefix##_ZMM0 + index; \ case TYPE_YMM: \ return prefix##_YMM0 + index; \ case TYPE_XMM: \ return prefix##_XMM0 + index; \ case TYPE_VK: \ index &= 0xf; \ if (index > 7) \ *valid = 0; \ return prefix##_K0 + index; \ case TYPE_MM64: \ return prefix##_MM0 + (index & 0x7); \ case TYPE_SEGMENTREG: \ if ((index & 7) > 5) \ *valid = 0; \ return prefix##_ES + (index & 7); \ case TYPE_DEBUGREG: \ return prefix##_DR0 + index; \ case TYPE_CONTROLREG: \ return prefix##_CR0 + index; \ case TYPE_BNDR: \ if (index > 3) \ *valid = 0; \ return prefix##_BND0 + index; \ case TYPE_MVSIBX: \ return prefix##_XMM0 + index; \ case TYPE_MVSIBY: \ return prefix##_YMM0 + index; \ case TYPE_MVSIBZ: \ return prefix##_ZMM0 + index; \ } \ } /* * fixup*Value - Consults an operand type to determine the meaning of the * reg or R/M field. If the operand is an XMM operand, for example, an * operand would be XMM0 instead of AX, which readModRM() would otherwise * misinterpret it as. * * @param insn - The instruction containing the operand. * @param type - The operand type. * @param index - The existing value of the field as reported by readModRM(). * @param valid - The address of a uint8_t. The target is set to 1 if the * field is valid for the register class; 0 if not. * @return - The proper value. */ GENERIC_FIXUP_FUNC(fixupRegValue, insn->regBase, MODRM_REG, 0x1f) GENERIC_FIXUP_FUNC(fixupRMValue, insn->eaRegBase, EA_REG, 0xf) /* * fixupReg - Consults an operand specifier to determine which of the * fixup*Value functions to use in correcting readModRM()'ss interpretation. * * @param insn - See fixup*Value(). * @param op - The operand specifier. * @return - 0 if fixup was successful; -1 if the register returned was * invalid for its class. */ static int fixupReg(struct InternalInstruction *insn, const struct OperandSpecifier *op) { uint8_t valid; switch ((OperandEncoding)op->encoding) { default: // debug("Expected a REG or R/M encoding in fixupReg"); return -1; case ENCODING_VVVV: insn->vvvv = (Reg)fixupRegValue(insn, (OperandType)op->type, insn->vvvv, &valid); if (!valid) return -1; break; case ENCODING_REG: insn->reg = (Reg)fixupRegValue(insn, (OperandType)op->type, insn->reg - insn->regBase, &valid); if (!valid) return -1; break; CASE_ENCODING_RM: if (insn->eaBase >= insn->eaRegBase) { insn->eaBase = (EABase)fixupRMValue(insn, (OperandType)op->type, insn->eaBase - insn->eaRegBase, &valid); if (!valid) return -1; } break; } return 0; } /* * readOpcodeRegister - Reads an operand from the opcode field of an * instruction and interprets it appropriately given the operand width. * Handles AddRegFrm instructions. * * @param insn - the instruction whose opcode field is to be read. * @param size - The width (in bytes) of the register being specified. * 1 means AL and friends, 2 means AX, 4 means EAX, and 8 means * RAX. * @return - 0 on success; nonzero otherwise. */ static int readOpcodeRegister(struct InternalInstruction* insn, uint8_t size) { if (size == 0) size = insn->registerSize; switch (size) { case 1: insn->opcodeRegister = (Reg)(MODRM_REG_AL + ((bFromREX(insn->rexPrefix) << 3) | (insn->opcode & 7))); if (insn->rexPrefix && insn->opcodeRegister >= MODRM_REG_AL + 0x4 && insn->opcodeRegister < MODRM_REG_AL + 0x8) { insn->opcodeRegister = (Reg)(MODRM_REG_SPL + (insn->opcodeRegister - MODRM_REG_AL - 4)); } break; case 2: insn->opcodeRegister = (Reg)(MODRM_REG_AX + ((bFromREX(insn->rexPrefix) << 3) | (insn->opcode & 7))); break; case 4: insn->opcodeRegister = (Reg)(MODRM_REG_EAX + ((bFromREX(insn->rexPrefix) << 3) | (insn->opcode & 7))); break; case 8: insn->opcodeRegister = (Reg)(MODRM_REG_RAX + ((bFromREX(insn->rexPrefix) << 3) | (insn->opcode & 7))); break; } return 0; } /* * readImmediate - Consumes an immediate operand from an instruction, given the * desired operand size. * * @param insn - The instruction whose operand is to be read. * @param size - The width (in bytes) of the operand. * @return - 0 if the immediate was successfully consumed; nonzero * otherwise. */ static int readImmediate(struct InternalInstruction* insn, uint8_t size) { uint8_t imm8; uint16_t imm16; uint32_t imm32; uint64_t imm64; if (insn->numImmediatesConsumed == 2) { // debug("Already consumed two immediates"); return -1; } if (size == 0) size = insn->immediateSize; else insn->immediateSize = size; insn->immediateOffset = insn->readerCursor - insn->startLocation; switch (size) { case 1: if (consumeByte(insn, &imm8)) return -1; insn->immediates[insn->numImmediatesConsumed] = imm8; break; case 2: if (consumeUInt16(insn, &imm16)) return -1; insn->immediates[insn->numImmediatesConsumed] = imm16; break; case 4: if (consumeUInt32(insn, &imm32)) return -1; insn->immediates[insn->numImmediatesConsumed] = imm32; break; case 8: if (consumeUInt64(insn, &imm64)) return -1; insn->immediates[insn->numImmediatesConsumed] = imm64; break; } insn->numImmediatesConsumed++; return 0; } /* * readVVVV - Consumes vvvv from an instruction if it has a VEX prefix. * * @param insn - The instruction whose operand is to be read. * @return - 0 if the vvvv was successfully consumed; nonzero * otherwise. */ static int readVVVV(struct InternalInstruction* insn) { int vvvv; if (insn->vectorExtensionType == TYPE_EVEX) vvvv = (v2FromEVEX4of4(insn->vectorExtensionPrefix[3]) << 4 | vvvvFromEVEX3of4(insn->vectorExtensionPrefix[2])); else if (insn->vectorExtensionType == TYPE_VEX_3B) vvvv = vvvvFromVEX3of3(insn->vectorExtensionPrefix[2]); else if (insn->vectorExtensionType == TYPE_VEX_2B) vvvv = vvvvFromVEX2of2(insn->vectorExtensionPrefix[1]); else if (insn->vectorExtensionType == TYPE_XOP) vvvv = vvvvFromXOP3of3(insn->vectorExtensionPrefix[2]); else return -1; if (insn->mode != MODE_64BIT) vvvv &= 0xf; // Can only clear bit 4. Bit 3 must be cleared later. insn->vvvv = (Reg)vvvv; return 0; } /* * readMaskRegister - Reads an mask register from the opcode field of an * instruction. * * @param insn - The instruction whose opcode field is to be read. * @return - 0 on success; nonzero otherwise. */ static int readMaskRegister(struct InternalInstruction* insn) { if (insn->vectorExtensionType != TYPE_EVEX) return -1; insn->writemask = (Reg)(aaaFromEVEX4of4(insn->vectorExtensionPrefix[3])); return 0; } /* * readOperands - Consults the specifier for an instruction and consumes all * operands for that instruction, interpreting them as it goes. * * @param insn - The instruction whose operands are to be read and interpreted. * @return - 0 if all operands could be read; nonzero otherwise. */ static int readOperands(struct InternalInstruction* insn) { int hasVVVV, needVVVV; int sawRegImm = 0; int i; /* If non-zero vvvv specified, need to make sure one of the operands uses it. */ hasVVVV = !readVVVV(insn); needVVVV = hasVVVV && (insn->vvvv != 0); for (i = 0; i < X86_MAX_OPERANDS; ++i) { const OperandSpecifier *op = &x86OperandSets[insn->spec->operands][i]; switch (op->encoding) { case ENCODING_NONE: case ENCODING_SI: case ENCODING_DI: break; CASE_ENCODING_VSIB: // VSIB can use the V2 bit so check only the other bits. if (needVVVV) needVVVV = hasVVVV & ((insn->vvvv & 0xf) != 0); if (readModRM(insn)) return -1; // Reject if SIB wasn't used. if (insn->eaBase != EA_BASE_sib && insn->eaBase != EA_BASE_sib64) return -1; // If sibIndex was set to SIB_INDEX_NONE, index offset is 4. if (insn->sibIndex == SIB_INDEX_NONE) insn->sibIndex = (SIBIndex)(insn->sibIndexBase + 4); // If EVEX.v2 is set this is one of the 16-31 registers. if (insn->vectorExtensionType == TYPE_EVEX && insn->mode == MODE_64BIT && v2FromEVEX4of4(insn->vectorExtensionPrefix[3])) insn->sibIndex = (SIBIndex)(insn->sibIndex + 16); // Adjust the index register to the correct size. switch (op->type) { default: // debug("Unhandled VSIB index type"); return -1; case TYPE_MVSIBX: insn->sibIndex = (SIBIndex)(SIB_INDEX_XMM0 + (insn->sibIndex - insn->sibIndexBase)); break; case TYPE_MVSIBY: insn->sibIndex = (SIBIndex)(SIB_INDEX_YMM0 + (insn->sibIndex - insn->sibIndexBase)); break; case TYPE_MVSIBZ: insn->sibIndex = (SIBIndex)(SIB_INDEX_ZMM0 + (insn->sibIndex - insn->sibIndexBase)); break; } // Apply the AVX512 compressed displacement scaling factor. if (op->encoding != ENCODING_REG && insn->eaDisplacement == EA_DISP_8) insn->displacement *= 1 << (op->encoding - ENCODING_VSIB); break; case ENCODING_REG: CASE_ENCODING_RM: if (readModRM(insn)) return -1; if (fixupReg(insn, op)) return -1; // Apply the AVX512 compressed displacement scaling factor. if (op->encoding != ENCODING_REG && insn->eaDisplacement == EA_DISP_8) insn->displacement *= 1 << (op->encoding - ENCODING_RM); break; case ENCODING_IB: if (sawRegImm) { /* Saw a register immediate so don't read again and instead split the previous immediate. FIXME: This is a hack. */ insn->immediates[insn->numImmediatesConsumed] = insn->immediates[insn->numImmediatesConsumed - 1] & 0xf; ++insn->numImmediatesConsumed; break; } if (readImmediate(insn, 1)) return -1; if (op->type == TYPE_XMM || op->type == TYPE_YMM) sawRegImm = 1; break; case ENCODING_IW: if (readImmediate(insn, 2)) return -1; break; case ENCODING_ID: if (readImmediate(insn, 4)) return -1; break; case ENCODING_IO: if (readImmediate(insn, 8)) return -1; break; case ENCODING_Iv: if (readImmediate(insn, insn->immediateSize)) return -1; break; case ENCODING_Ia: if (readImmediate(insn, insn->addressSize)) return -1; /* Direct memory-offset (moffset) immediate will get mapped to memory operand later. We want the encoding info to reflect that as well. */ insn->displacementOffset = insn->immediateOffset; insn->consumedDisplacement = true; insn->displacementSize = insn->immediateSize; insn->displacement = insn->immediates[insn->numImmediatesConsumed - 1]; insn->immediateOffset = 0; insn->immediateSize = 0; break; case ENCODING_IRC: insn->RC = (l2FromEVEX4of4(insn->vectorExtensionPrefix[3]) << 1) | lFromEVEX4of4(insn->vectorExtensionPrefix[3]); break; case ENCODING_RB: if (readOpcodeRegister(insn, 1)) return -1; break; case ENCODING_RW: if (readOpcodeRegister(insn, 2)) return -1; break; case ENCODING_RD: if (readOpcodeRegister(insn, 4)) return -1; break; case ENCODING_RO: if (readOpcodeRegister(insn, 8)) return -1; break; case ENCODING_Rv: if (readOpcodeRegister(insn, 0)) return -1; break; case ENCODING_FP: break; case ENCODING_VVVV: if (!hasVVVV) return -1; needVVVV = 0; /* Mark that we have found a VVVV operand. */ if (insn->mode != MODE_64BIT) insn->vvvv = (Reg)(insn->vvvv & 0x7); if (fixupReg(insn, op)) return -1; break; case ENCODING_WRITEMASK: if (readMaskRegister(insn)) return -1; break; case ENCODING_DUP: break; default: // dbgprintf(insn, "Encountered an operand with an unknown encoding."); return -1; } } /* If we didn't find ENCODING_VVVV operand, but non-zero vvvv present, fail */ if (needVVVV) return -1; return 0; } // return True if instruction is illegal to use with prefixes // This also check & fix the isPrefixNN when a prefix is irrelevant. static bool checkPrefix(struct InternalInstruction *insn) { // LOCK prefix if (insn->hasLockPrefix) { switch(insn->instructionID) { default: // invalid LOCK return true; // nop dword [rax] case X86_NOOPL: // DEC case X86_DEC16m: case X86_DEC32m: case X86_DEC64m: case X86_DEC8m: // ADC case X86_ADC16mi: case X86_ADC16mi8: case X86_ADC16mr: case X86_ADC32mi: case X86_ADC32mi8: case X86_ADC32mr: case X86_ADC64mi32: case X86_ADC64mi8: case X86_ADC64mr: case X86_ADC8mi: case X86_ADC8mi8: case X86_ADC8mr: case X86_ADC8rm: case X86_ADC16rm: case X86_ADC32rm: case X86_ADC64rm: // ADD case X86_ADD16mi: case X86_ADD16mi8: case X86_ADD16mr: case X86_ADD32mi: case X86_ADD32mi8: case X86_ADD32mr: case X86_ADD64mi32: case X86_ADD64mi8: case X86_ADD64mr: case X86_ADD8mi: case X86_ADD8mi8: case X86_ADD8mr: case X86_ADD8rm: case X86_ADD16rm: case X86_ADD32rm: case X86_ADD64rm: // AND case X86_AND16mi: case X86_AND16mi8: case X86_AND16mr: case X86_AND32mi: case X86_AND32mi8: case X86_AND32mr: case X86_AND64mi32: case X86_AND64mi8: case X86_AND64mr: case X86_AND8mi: case X86_AND8mi8: case X86_AND8mr: case X86_AND8rm: case X86_AND16rm: case X86_AND32rm: case X86_AND64rm: // BTC case X86_BTC16mi8: case X86_BTC16mr: case X86_BTC32mi8: case X86_BTC32mr: case X86_BTC64mi8: case X86_BTC64mr: // BTR case X86_BTR16mi8: case X86_BTR16mr: case X86_BTR32mi8: case X86_BTR32mr: case X86_BTR64mi8: case X86_BTR64mr: // BTS case X86_BTS16mi8: case X86_BTS16mr: case X86_BTS32mi8: case X86_BTS32mr: case X86_BTS64mi8: case X86_BTS64mr: // CMPXCHG case X86_CMPXCHG16B: case X86_CMPXCHG16rm: case X86_CMPXCHG32rm: case X86_CMPXCHG64rm: case X86_CMPXCHG8rm: case X86_CMPXCHG8B: // INC case X86_INC16m: case X86_INC32m: case X86_INC64m: case X86_INC8m: // NEG case X86_NEG16m: case X86_NEG32m: case X86_NEG64m: case X86_NEG8m: // NOT case X86_NOT16m: case X86_NOT32m: case X86_NOT64m: case X86_NOT8m: // OR case X86_OR16mi: case X86_OR16mi8: case X86_OR16mr: case X86_OR32mi: case X86_OR32mi8: case X86_OR32mr: case X86_OR64mi32: case X86_OR64mi8: case X86_OR64mr: case X86_OR8mi8: case X86_OR8mi: case X86_OR8mr: case X86_OR8rm: case X86_OR16rm: case X86_OR32rm: case X86_OR64rm: // SBB case X86_SBB16mi: case X86_SBB16mi8: case X86_SBB16mr: case X86_SBB32mi: case X86_SBB32mi8: case X86_SBB32mr: case X86_SBB64mi32: case X86_SBB64mi8: case X86_SBB64mr: case X86_SBB8mi: case X86_SBB8mi8: case X86_SBB8mr: // SUB case X86_SUB16mi: case X86_SUB16mi8: case X86_SUB16mr: case X86_SUB32mi: case X86_SUB32mi8: case X86_SUB32mr: case X86_SUB64mi32: case X86_SUB64mi8: case X86_SUB64mr: case X86_SUB8mi8: case X86_SUB8mi: case X86_SUB8mr: case X86_SUB8rm: case X86_SUB16rm: case X86_SUB32rm: case X86_SUB64rm: // XADD case X86_XADD16rm: case X86_XADD32rm: case X86_XADD64rm: case X86_XADD8rm: // XCHG case X86_XCHG16rm: case X86_XCHG32rm: case X86_XCHG64rm: case X86_XCHG8rm: // XOR case X86_XOR16mi: case X86_XOR16mi8: case X86_XOR16mr: case X86_XOR32mi: case X86_XOR32mi8: case X86_XOR32mr: case X86_XOR64mi32: case X86_XOR64mi8: case X86_XOR64mr: case X86_XOR8mi8: case X86_XOR8mi: case X86_XOR8mr: case X86_XOR8rm: case X86_XOR16rm: case X86_XOR32rm: case X86_XOR64rm: // this instruction can be used with LOCK prefix return false; } } #if 0 // REPNE prefix if (insn->repeatPrefix) { // 0xf2 can be a part of instruction encoding, but not really a prefix. // In such a case, clear it. if (insn->twoByteEscape == 0x0f) { insn->prefix0 = 0; } } #endif // no invalid prefixes return false; } /* * decodeInstruction - Reads and interprets a full instruction provided by the * user. * * @param insn - A pointer to the instruction to be populated. Must be * pre-allocated. * @param reader - The function to be used to read the instruction's bytes. * @param readerArg - A generic argument to be passed to the reader to store * any internal state. * @param startLoc - The address (in the reader's address space) of the first * byte in the instruction. * @param mode - The mode (real mode, IA-32e, or IA-32e in 64-bit mode) to * decode the instruction in. * @return - 0 if instruction is valid; nonzero if not. */ int decodeInstruction(struct InternalInstruction *insn, byteReader_t reader, const void *readerArg, uint64_t startLoc, DisassemblerMode mode) { insn->reader = reader; insn->readerArg = readerArg; insn->startLocation = startLoc; insn->readerCursor = startLoc; insn->mode = mode; insn->numImmediatesConsumed = 0; if (readPrefixes(insn) || readOpcode(insn) || getID(insn) || insn->instructionID == 0 || checkPrefix(insn) || readOperands(insn)) return -1; insn->length = (size_t)(insn->readerCursor - insn->startLocation); // instruction length must be <= 15 to be valid if (insn->length > 15) return -1; if (insn->operandSize == 0) insn->operandSize = insn->registerSize; insn->operands = &x86OperandSets[insn->spec->operands][0]; return 0; } #endif
the_stack_data/90302.c
#include <stdio.h> #include <string.h> #include <stdlib.h> int main(int argc, const char *argv[]) { char *msg = "Hello world!"; char *ptr = NULL; ptr = malloc(strlen(msg)); strcpy(ptr, msg); printf("%s\n", ptr); return 0; }
the_stack_data/411262.c
/** ****************************************************************************** * @file stm32l4xx_ll_rcc.c * @author MCD Application Team * @brief RCC LL module driver. ****************************************************************************** * @attention * * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2> * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ #if defined(USE_FULL_LL_DRIVER) /* Includes ------------------------------------------------------------------*/ #include "stm32l4xx_ll_rcc.h" #ifdef USE_FULL_ASSERT #include "stm32_assert.h" #else #define assert_param(expr) ((void)0U) #endif /** @addtogroup STM32L4xx_LL_Driver * @{ */ #if defined(RCC) /** @addtogroup RCC_LL * @{ */ /* Private types -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /* Private macros ------------------------------------------------------------*/ /** @addtogroup RCC_LL_Private_Macros * @{ */ #if defined(RCC_CCIPR_USART3SEL) #define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE) \ || ((__VALUE__) == LL_RCC_USART2_CLKSOURCE) \ || ((__VALUE__) == LL_RCC_USART3_CLKSOURCE)) #else #define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE) \ || ((__VALUE__) == LL_RCC_USART2_CLKSOURCE)) #endif /* RCC_CCIPR_USART3SEL */ #if defined(RCC_CCIPR_UART4SEL) && defined(RCC_CCIPR_UART5SEL) #define IS_LL_RCC_UART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_UART4_CLKSOURCE) \ || ((__VALUE__) == LL_RCC_UART5_CLKSOURCE)) #elif defined(RCC_CCIPR_UART4SEL) #define IS_LL_RCC_UART_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_UART4_CLKSOURCE) #elif defined(RCC_CCIPR_UART5SEL) #define IS_LL_RCC_UART_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_UART5_CLKSOURCE) #endif /* RCC_CCIPR_UART4SEL && RCC_CCIPR_UART5SEL*/ #define IS_LL_RCC_LPUART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_LPUART1_CLKSOURCE)) #if defined(RCC_CCIPR_I2C2SEL) && defined(RCC_CCIPR_I2C3SEL) && defined(RCC_CCIPR2_I2C4SEL) #define IS_LL_RCC_I2C_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_I2C1_CLKSOURCE) \ || ((__VALUE__) == LL_RCC_I2C2_CLKSOURCE) \ || ((__VALUE__) == LL_RCC_I2C3_CLKSOURCE) \ || ((__VALUE__) == LL_RCC_I2C4_CLKSOURCE)) #elif defined(RCC_CCIPR_I2C2SEL) && defined(RCC_CCIPR_I2C3SEL) #define IS_LL_RCC_I2C_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_I2C1_CLKSOURCE) \ || ((__VALUE__) == LL_RCC_I2C2_CLKSOURCE) \ || ((__VALUE__) == LL_RCC_I2C3_CLKSOURCE)) #elif !defined(RCC_CCIPR_I2C2SEL) && defined(RCC_CCIPR_I2C3SEL) #define IS_LL_RCC_I2C_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_I2C1_CLKSOURCE) \ || ((__VALUE__) == LL_RCC_I2C3_CLKSOURCE)) #else #define IS_LL_RCC_I2C_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_I2C1_CLKSOURCE) #endif /* RCC_CCIPR_I2C2SEL && RCC_CCIPR_I2C3SEL && RCC_CCIPR2_I2C4SEL */ #define IS_LL_RCC_LPTIM_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_LPTIM1_CLKSOURCE) \ || ((__VALUE__) == LL_RCC_LPTIM2_CLKSOURCE)) #if defined(RCC_CCIPR_SAI2SEL) || defined(RCC_CCIPR2_SAI2SEL) #define IS_LL_RCC_SAI_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_SAI1_CLKSOURCE) \ || ((__VALUE__) == LL_RCC_SAI2_CLKSOURCE)) #elif defined(RCC_CCIPR_SAI1SEL) || defined(RCC_CCIPR2_SAI1SEL) #define IS_LL_RCC_SAI_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_SAI1_CLKSOURCE) #endif /* RCC_CCIPR_SAI2SEL RCC_CCIPR2_SAI2SEL ||*/ #if defined(SDMMC1) #if defined(RCC_CCIPR2_SDMMCSEL) #define IS_LL_RCC_SDMMC_KERNELCLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_SDMMC1_KERNELCLKSOURCE)) #endif /* RCC_CCIPR2_SDMMCSEL */ #define IS_LL_RCC_SDMMC_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_SDMMC1_CLKSOURCE)) #endif /* SDMMC1 */ #define IS_LL_RCC_RNG_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_RNG_CLKSOURCE)) #if defined(USB_OTG_FS) || defined(USB) #define IS_LL_RCC_USB_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USB_CLKSOURCE)) #endif /* USB_OTG_FS || USB */ #define IS_LL_RCC_ADC_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_ADC_CLKSOURCE)) #if defined(SWPMI1) #define IS_LL_RCC_SWPMI_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_SWPMI1_CLKSOURCE)) #endif /* SWPMI1 */ #if defined(DFSDM1_Channel0) #define IS_LL_RCC_DFSDM_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_DFSDM1_CLKSOURCE)) #if defined(RCC_CCIPR2_DFSDM1SEL) #define IS_LL_RCC_DFSDM_AUDIO_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_DFSDM1_AUDIO_CLKSOURCE)) #endif /* RCC_CCIPR2_DFSDM1SEL */ #endif /* DFSDM1_Channel0 */ #if defined(DSI) #define IS_LL_RCC_DSI_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_DSI_CLKSOURCE)) #endif /* DSI */ #if defined(LTDC) #define IS_LL_RCC_LTDC_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_LTDC_CLKSOURCE)) #endif /* LTDC */ #if defined(OCTOSPI1) #define IS_LL_RCC_OCTOSPI_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_OCTOSPI_CLKSOURCE)) #endif /* OCTOSPI */ /** * @} */ /* Private function prototypes -----------------------------------------------*/ /** @defgroup RCC_LL_Private_Functions RCC Private functions * @{ */ uint32_t RCC_GetSystemClockFreq(void); uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency); uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency); uint32_t RCC_GetPCLK2ClockFreq(uint32_t HCLK_Frequency); uint32_t RCC_PLL_GetFreqDomain_SYS(void); uint32_t RCC_PLL_GetFreqDomain_SAI(void); uint32_t RCC_PLL_GetFreqDomain_48M(void); #if defined(RCC_PLLSAI1_SUPPORT) uint32_t RCC_PLLSAI1_GetFreqDomain_SAI(void); uint32_t RCC_PLLSAI1_GetFreqDomain_48M(void); uint32_t RCC_PLLSAI1_GetFreqDomain_ADC(void); #endif /* RCC_PLLSAI1_SUPPORT */ #if defined(RCC_PLLSAI2_SUPPORT) uint32_t RCC_PLLSAI2_GetFreqDomain_SAI(void); #if defined(LTDC) uint32_t RCC_PLLSAI2_GetFreqDomain_LTDC(void); #else uint32_t RCC_PLLSAI2_GetFreqDomain_ADC(void); #endif /* LTDC */ #if defined(DSI) uint32_t RCC_PLLSAI2_GetFreqDomain_DSI(void); #endif /* DSI */ #endif /*RCC_PLLSAI2_SUPPORT*/ /** * @} */ /* Exported functions --------------------------------------------------------*/ /** @addtogroup RCC_LL_Exported_Functions * @{ */ /** @addtogroup RCC_LL_EF_Init * @{ */ /** * @brief Reset the RCC clock configuration to the default reset state. * @note The default reset state of the clock configuration is given below: * - MSI ON and used as system clock source * - HSE, HSI, PLL, PLLSAI1 and PLLSAI2 OFF * - AHB, APB1 and APB2 prescaler set to 1. * - CSS, MCO OFF * - All interrupts disabled * @note This function doesn't modify the configuration of the * - Peripheral clocks * - LSI, LSE and RTC clocks * @retval An ErrorStatus enumeration value: * - SUCCESS: RCC registers are de-initialized * - ERROR: not applicable */ ErrorStatus LL_RCC_DeInit(void) { uint32_t vl_mask; /* Set MSION bit */ LL_RCC_MSI_Enable(); /* Insure MSIRDY bit is set before writing default MSIRANGE value */ while (LL_RCC_MSI_IsReady() == 0U) { } /* Set MSIRANGE default value */ LL_RCC_MSI_SetRange(LL_RCC_MSIRANGE_6); /* Set MSITRIM bits to the reset value*/ LL_RCC_MSI_SetCalibTrimming(0); /* Set HSITRIM bits to the reset value*/ LL_RCC_HSI_SetCalibTrimming(0x10U); /* Reset CFGR register */ LL_RCC_WriteReg(CFGR, 0x00000000U); vl_mask = 0xFFFFFFFFU; /* Reset HSION, HSIKERON, HSIASFS, HSEON, PLLON bits */ CLEAR_BIT(vl_mask, (RCC_CR_HSION | RCC_CR_HSIASFS | RCC_CR_HSIKERON | RCC_CR_HSEON | RCC_CR_PLLON)); #if defined(RCC_PLLSAI1_SUPPORT) /* Reset PLLSAI1ON bit */ CLEAR_BIT(vl_mask, RCC_CR_PLLSAI1ON); #endif /*RCC_PLLSAI1_SUPPORT*/ #if defined(RCC_PLLSAI2_SUPPORT) /* Reset PLLSAI2ON bit */ CLEAR_BIT(vl_mask, RCC_CR_PLLSAI2ON); #endif /*RCC_PLLSAI2_SUPPORT*/ /* Write new mask in CR register */ LL_RCC_WriteReg(CR, vl_mask); #if defined(RCC_PLLSAI2_SUPPORT) /* Wait for PLLRDY, PLLSAI1RDY and PLLSAI2RDY bits to be reset */ while(READ_BIT(RCC->CR, RCC_CR_PLLRDY | RCC_CR_PLLSAI1RDY | RCC_CR_PLLSAI2RDY) != 0U) { } #elif defined(RCC_PLLSAI1_SUPPORT) /* Wait for PLLRDY and PLLSAI1RDY to be reset */ while(READ_BIT(RCC->CR, RCC_CR_PLLRDY | RCC_CR_PLLSAI1RDY) != 0U) { } #else /* Wait for PLLRDY bit to be reset */ while(READ_BIT(RCC->CR, RCC_CR_PLLRDY) != 0U) { } #endif /* Reset PLLCFGR register */ LL_RCC_WriteReg(PLLCFGR, 16U << RCC_PLLCFGR_PLLN_Pos); #if defined(RCC_PLLSAI1_SUPPORT) /* Reset PLLSAI1CFGR register */ LL_RCC_WriteReg(PLLSAI1CFGR, 16U << RCC_PLLSAI1CFGR_PLLSAI1N_Pos); #endif /*RCC_PLLSAI1_SUPPORT*/ #if defined(RCC_PLLSAI2_SUPPORT) /* Reset PLLSAI2CFGR register */ LL_RCC_WriteReg(PLLSAI2CFGR, 16U << RCC_PLLSAI2CFGR_PLLSAI2N_Pos); #endif /*RCC_PLLSAI2_SUPPORT*/ /* Reset HSEBYP bit */ LL_RCC_HSE_DisableBypass(); /* Disable all interrupts */ LL_RCC_WriteReg(CIER, 0x00000000U); /* Clear all interrupt flags */ vl_mask = RCC_CICR_LSIRDYC | RCC_CICR_LSERDYC | RCC_CICR_MSIRDYC | RCC_CICR_HSIRDYC | RCC_CICR_HSERDYC | RCC_CICR_PLLRDYC | \ RCC_CICR_CSSC | RCC_CICR_LSECSSC; #if defined(RCC_HSI48_SUPPORT) vl_mask |= RCC_CICR_HSI48RDYC; #endif #if defined(RCC_PLLSAI1_SUPPORT) vl_mask |= RCC_CICR_PLLSAI1RDYC; #endif #if defined(RCC_PLLSAI2_SUPPORT) vl_mask |= RCC_CICR_PLLSAI2RDYC; #endif LL_RCC_WriteReg(CICR, vl_mask); /* Clear reset flags */ LL_RCC_ClearResetFlags(); return SUCCESS; } /** * @} */ /** @addtogroup RCC_LL_EF_Get_Freq * @brief Return the frequencies of different on chip clocks; System, AHB, APB1 and APB2 buses clocks * and different peripheral clocks available on the device. * @note If SYSCLK source is MSI, function returns values based on MSI_VALUE(*) * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(**) * @note If SYSCLK source is HSE, function returns values based on HSE_VALUE(***) * @note If SYSCLK source is PLL, function returns values based on HSE_VALUE(***) * or HSI_VALUE(**) or MSI_VALUE(*) multiplied/divided by the PLL factors. * @note (*) MSI_VALUE is a constant defined in this file (default value * 4 MHz) but the real value may vary depending on the variations * in voltage and temperature. * @note (**) HSI_VALUE is a constant defined in this file (default value * 16 MHz) but the real value may vary depending on the variations * in voltage and temperature. * @note (***) HSE_VALUE is a constant defined in this file (default value * 8 MHz), user has to ensure that HSE_VALUE is same as the real * frequency of the crystal used. Otherwise, this function may * have wrong result. * @note The result of this function could be incorrect when using fractional * value for HSE crystal. * @note This function can be used by the user application to compute the * baud-rate for the communication peripherals or configure other parameters. * @{ */ /** * @brief Return the frequencies of different on chip clocks; System, AHB, APB1 and APB2 buses clocks * @note Each time SYSCLK, HCLK, PCLK1 and/or PCLK2 clock changes, this function * must be called to update structure fields. Otherwise, any * configuration based on this function will be incorrect. * @param RCC_Clocks pointer to a @ref LL_RCC_ClocksTypeDef structure which will hold the clocks frequencies * @retval None */ void LL_RCC_GetSystemClocksFreq(LL_RCC_ClocksTypeDef *RCC_Clocks) { /* Get SYSCLK frequency */ RCC_Clocks->SYSCLK_Frequency = RCC_GetSystemClockFreq(); /* HCLK clock frequency */ RCC_Clocks->HCLK_Frequency = RCC_GetHCLKClockFreq(RCC_Clocks->SYSCLK_Frequency); /* PCLK1 clock frequency */ RCC_Clocks->PCLK1_Frequency = RCC_GetPCLK1ClockFreq(RCC_Clocks->HCLK_Frequency); /* PCLK2 clock frequency */ RCC_Clocks->PCLK2_Frequency = RCC_GetPCLK2ClockFreq(RCC_Clocks->HCLK_Frequency); } /** * @brief Return USARTx clock frequency * @param USARTxSource This parameter can be one of the following values: * @arg @ref LL_RCC_USART1_CLKSOURCE * @arg @ref LL_RCC_USART2_CLKSOURCE * @arg @ref LL_RCC_USART3_CLKSOURCE (*) * * (*) value not defined in all devices. * @retval USART clock frequency (in Hz) * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready */ uint32_t LL_RCC_GetUSARTClockFreq(uint32_t USARTxSource) { uint32_t usart_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_USART_CLKSOURCE(USARTxSource)); if (USARTxSource == LL_RCC_USART1_CLKSOURCE) { /* USART1CLK clock frequency */ switch (LL_RCC_GetUSARTClockSource(USARTxSource)) { case LL_RCC_USART1_CLKSOURCE_SYSCLK: /* USART1 Clock is System Clock */ usart_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_USART1_CLKSOURCE_HSI: /* USART1 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady() != 0U) { usart_frequency = HSI_VALUE; } break; case LL_RCC_USART1_CLKSOURCE_LSE: /* USART1 Clock is LSE Osc. */ if (LL_RCC_LSE_IsReady() != 0U) { usart_frequency = LSE_VALUE; } break; case LL_RCC_USART1_CLKSOURCE_PCLK2: /* USART1 Clock is PCLK2 */ usart_frequency = RCC_GetPCLK2ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; default: break; } } else if (USARTxSource == LL_RCC_USART2_CLKSOURCE) { /* USART2CLK clock frequency */ switch (LL_RCC_GetUSARTClockSource(USARTxSource)) { case LL_RCC_USART2_CLKSOURCE_SYSCLK: /* USART2 Clock is System Clock */ usart_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_USART2_CLKSOURCE_HSI: /* USART2 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady() != 0U) { usart_frequency = HSI_VALUE; } break; case LL_RCC_USART2_CLKSOURCE_LSE: /* USART2 Clock is LSE Osc. */ if (LL_RCC_LSE_IsReady() != 0U) { usart_frequency = LSE_VALUE; } break; case LL_RCC_USART2_CLKSOURCE_PCLK1: /* USART2 Clock is PCLK1 */ usart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; default: break; } } else { #if defined(RCC_CCIPR_USART3SEL) if (USARTxSource == LL_RCC_USART3_CLKSOURCE) { /* USART3CLK clock frequency */ switch (LL_RCC_GetUSARTClockSource(USARTxSource)) { case LL_RCC_USART3_CLKSOURCE_SYSCLK: /* USART3 Clock is System Clock */ usart_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_USART3_CLKSOURCE_HSI: /* USART3 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady() != 0U) { usart_frequency = HSI_VALUE; } break; case LL_RCC_USART3_CLKSOURCE_LSE: /* USART3 Clock is LSE Osc. */ if (LL_RCC_LSE_IsReady() != 0U) { usart_frequency = LSE_VALUE; } break; case LL_RCC_USART3_CLKSOURCE_PCLK1: /* USART3 Clock is PCLK1 */ usart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; default: break; } } #endif /* RCC_CCIPR_USART3SEL */ } return usart_frequency; } #if defined(RCC_CCIPR_UART4SEL) || defined(RCC_CCIPR_UART5SEL) /** * @brief Return UARTx clock frequency * @param UARTxSource This parameter can be one of the following values: * @arg @ref LL_RCC_UART4_CLKSOURCE * @arg @ref LL_RCC_UART5_CLKSOURCE * @retval UART clock frequency (in Hz) * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready */ uint32_t LL_RCC_GetUARTClockFreq(uint32_t UARTxSource) { uint32_t uart_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_UART_CLKSOURCE(UARTxSource)); #if defined(RCC_CCIPR_UART4SEL) if (UARTxSource == LL_RCC_UART4_CLKSOURCE) { /* UART4CLK clock frequency */ switch (LL_RCC_GetUARTClockSource(UARTxSource)) { case LL_RCC_UART4_CLKSOURCE_SYSCLK: /* UART4 Clock is System Clock */ uart_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_UART4_CLKSOURCE_HSI: /* UART4 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady() != 0U) { uart_frequency = HSI_VALUE; } break; case LL_RCC_UART4_CLKSOURCE_LSE: /* UART4 Clock is LSE Osc. */ if (LL_RCC_LSE_IsReady() != 0U) { uart_frequency = LSE_VALUE; } break; case LL_RCC_UART4_CLKSOURCE_PCLK1: /* UART4 Clock is PCLK1 */ uart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; default: break; } } #endif /* RCC_CCIPR_UART4SEL */ #if defined(RCC_CCIPR_UART5SEL) if (UARTxSource == LL_RCC_UART5_CLKSOURCE) { /* UART5CLK clock frequency */ switch (LL_RCC_GetUARTClockSource(UARTxSource)) { case LL_RCC_UART5_CLKSOURCE_SYSCLK: /* UART5 Clock is System Clock */ uart_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_UART5_CLKSOURCE_HSI: /* UART5 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady() != 0U) { uart_frequency = HSI_VALUE; } break; case LL_RCC_UART5_CLKSOURCE_LSE: /* UART5 Clock is LSE Osc. */ if (LL_RCC_LSE_IsReady() != 0U) { uart_frequency = LSE_VALUE; } break; case LL_RCC_UART5_CLKSOURCE_PCLK1: /* UART5 Clock is PCLK1 */ uart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; default: break; } } #endif /* RCC_CCIPR_UART5SEL */ return uart_frequency; } #endif /* RCC_CCIPR_UART4SEL || RCC_CCIPR_UART5SEL */ /** * @brief Return I2Cx clock frequency * @param I2CxSource This parameter can be one of the following values: * @arg @ref LL_RCC_I2C1_CLKSOURCE * @arg @ref LL_RCC_I2C2_CLKSOURCE (*) * @arg @ref LL_RCC_I2C3_CLKSOURCE * @arg @ref LL_RCC_I2C4_CLKSOURCE (*) * * (*) value not defined in all devices. * @retval I2C clock frequency (in Hz) * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that HSI oscillator is not ready */ uint32_t LL_RCC_GetI2CClockFreq(uint32_t I2CxSource) { uint32_t i2c_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_I2C_CLKSOURCE(I2CxSource)); if (I2CxSource == LL_RCC_I2C1_CLKSOURCE) { /* I2C1 CLK clock frequency */ switch (LL_RCC_GetI2CClockSource(I2CxSource)) { case LL_RCC_I2C1_CLKSOURCE_SYSCLK: /* I2C1 Clock is System Clock */ i2c_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_I2C1_CLKSOURCE_HSI: /* I2C1 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady() != 0U) { i2c_frequency = HSI_VALUE; } break; case LL_RCC_I2C1_CLKSOURCE_PCLK1: /* I2C1 Clock is PCLK1 */ i2c_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; default: break; } } #if defined(RCC_CCIPR_I2C2SEL) else if (I2CxSource == LL_RCC_I2C2_CLKSOURCE) { /* I2C2 CLK clock frequency */ switch (LL_RCC_GetI2CClockSource(I2CxSource)) { case LL_RCC_I2C2_CLKSOURCE_SYSCLK: /* I2C2 Clock is System Clock */ i2c_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_I2C2_CLKSOURCE_HSI: /* I2C2 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady() != 0U) { i2c_frequency = HSI_VALUE; } break; case LL_RCC_I2C2_CLKSOURCE_PCLK1: /* I2C2 Clock is PCLK1 */ i2c_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; default: break; } } #endif /*RCC_CCIPR_I2C2SEL*/ else { if (I2CxSource == LL_RCC_I2C3_CLKSOURCE) { /* I2C3 CLK clock frequency */ switch (LL_RCC_GetI2CClockSource(I2CxSource)) { case LL_RCC_I2C3_CLKSOURCE_SYSCLK: /* I2C3 Clock is System Clock */ i2c_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_I2C3_CLKSOURCE_HSI: /* I2C3 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady() != 0U) { i2c_frequency = HSI_VALUE; } break; case LL_RCC_I2C3_CLKSOURCE_PCLK1: /* I2C3 Clock is PCLK1 */ i2c_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; default: break; } } #if defined(RCC_CCIPR2_I2C4SEL) else { if (I2CxSource == LL_RCC_I2C4_CLKSOURCE) { /* I2C4 CLK clock frequency */ switch (LL_RCC_GetI2CClockSource(I2CxSource)) { case LL_RCC_I2C4_CLKSOURCE_SYSCLK: /* I2C4 Clock is System Clock */ i2c_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_I2C4_CLKSOURCE_HSI: /* I2C4 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady() != 0U) { i2c_frequency = HSI_VALUE; } break; case LL_RCC_I2C4_CLKSOURCE_PCLK1: /* I2C4 Clock is PCLK1 */ i2c_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; default: break; } } } #endif /*RCC_CCIPR2_I2C4SEL*/ } return i2c_frequency; } /** * @brief Return LPUARTx clock frequency * @param LPUARTxSource This parameter can be one of the following values: * @arg @ref LL_RCC_LPUART1_CLKSOURCE * @retval LPUART clock frequency (in Hz) * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready */ uint32_t LL_RCC_GetLPUARTClockFreq(uint32_t LPUARTxSource) { uint32_t lpuart_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_LPUART_CLKSOURCE(LPUARTxSource)); /* LPUART1CLK clock frequency */ switch (LL_RCC_GetLPUARTClockSource(LPUARTxSource)) { case LL_RCC_LPUART1_CLKSOURCE_SYSCLK: /* LPUART1 Clock is System Clock */ lpuart_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_LPUART1_CLKSOURCE_HSI: /* LPUART1 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady() != 0U) { lpuart_frequency = HSI_VALUE; } break; case LL_RCC_LPUART1_CLKSOURCE_LSE: /* LPUART1 Clock is LSE Osc. */ if (LL_RCC_LSE_IsReady() != 0U) { lpuart_frequency = LSE_VALUE; } break; case LL_RCC_LPUART1_CLKSOURCE_PCLK1: /* LPUART1 Clock is PCLK1 */ lpuart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; default: break; } return lpuart_frequency; } /** * @brief Return LPTIMx clock frequency * @param LPTIMxSource This parameter can be one of the following values: * @arg @ref LL_RCC_LPTIM1_CLKSOURCE * @arg @ref LL_RCC_LPTIM2_CLKSOURCE * @retval LPTIM clock frequency (in Hz) * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI, LSI or LSE) is not ready */ uint32_t LL_RCC_GetLPTIMClockFreq(uint32_t LPTIMxSource) { uint32_t lptim_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_LPTIM_CLKSOURCE(LPTIMxSource)); if (LPTIMxSource == LL_RCC_LPTIM1_CLKSOURCE) { /* LPTIM1CLK clock frequency */ switch (LL_RCC_GetLPTIMClockSource(LPTIMxSource)) { case LL_RCC_LPTIM1_CLKSOURCE_LSI: /* LPTIM1 Clock is LSI Osc. */ if (LL_RCC_LSI_IsReady() != 0U) { lptim_frequency = LSI_VALUE; } break; case LL_RCC_LPTIM1_CLKSOURCE_HSI: /* LPTIM1 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady() != 0U) { lptim_frequency = HSI_VALUE; } break; case LL_RCC_LPTIM1_CLKSOURCE_LSE: /* LPTIM1 Clock is LSE Osc. */ if (LL_RCC_LSE_IsReady() != 0U) { lptim_frequency = LSE_VALUE; } break; case LL_RCC_LPTIM1_CLKSOURCE_PCLK1: /* LPTIM1 Clock is PCLK1 */ lptim_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; default: break; } } else { if (LPTIMxSource == LL_RCC_LPTIM2_CLKSOURCE) { /* LPTIM2CLK clock frequency */ switch (LL_RCC_GetLPTIMClockSource(LPTIMxSource)) { case LL_RCC_LPTIM2_CLKSOURCE_LSI: /* LPTIM2 Clock is LSI Osc. */ if (LL_RCC_LSI_IsReady() != 0U) { lptim_frequency = LSI_VALUE; } break; case LL_RCC_LPTIM2_CLKSOURCE_HSI: /* LPTIM2 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady() != 0U) { lptim_frequency = HSI_VALUE; } break; case LL_RCC_LPTIM2_CLKSOURCE_LSE: /* LPTIM2 Clock is LSE Osc. */ if (LL_RCC_LSE_IsReady() != 0U) { lptim_frequency = LSE_VALUE; } break; case LL_RCC_LPTIM2_CLKSOURCE_PCLK1: /* LPTIM2 Clock is PCLK1 */ lptim_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; default: break; } } } return lptim_frequency; } #if defined(RCC_CCIPR_SAI1SEL) || defined(RCC_CCIPR_SAI2SEL) || defined(RCC_CCIPR2_SAI1SEL) || defined(RCC_CCIPR2_SAI2SEL) /** * @brief Return SAIx clock frequency * @param SAIxSource This parameter can be one of the following values: * @arg @ref LL_RCC_SAI1_CLKSOURCE * @arg @ref LL_RCC_SAI2_CLKSOURCE (*) * * (*) value not defined in all devices. * @retval SAI clock frequency (in Hz) * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that PLL is not ready */ uint32_t LL_RCC_GetSAIClockFreq(uint32_t SAIxSource) { uint32_t sai_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_SAI_CLKSOURCE(SAIxSource)); if (SAIxSource == LL_RCC_SAI1_CLKSOURCE) { /* SAI1CLK clock frequency */ switch (LL_RCC_GetSAIClockSource(SAIxSource)) { case LL_RCC_SAI1_CLKSOURCE_PLLSAI1: /* PLLSAI1 clock used as SAI1 clock source */ if (LL_RCC_PLLSAI1_IsReady() != 0U) { sai_frequency = RCC_PLLSAI1_GetFreqDomain_SAI(); } break; #if defined(RCC_PLLSAI2_SUPPORT) case LL_RCC_SAI1_CLKSOURCE_PLLSAI2: /* PLLSAI2 clock used as SAI1 clock source */ if (LL_RCC_PLLSAI2_IsReady() != 0U) { sai_frequency = RCC_PLLSAI2_GetFreqDomain_SAI(); } break; #endif /* RCC_PLLSAI2_SUPPORT */ case LL_RCC_SAI1_CLKSOURCE_PLL: /* PLL clock used as SAI1 clock source */ if (LL_RCC_PLL_IsReady() != 0U) { sai_frequency = RCC_PLL_GetFreqDomain_SAI(); } break; case LL_RCC_SAI1_CLKSOURCE_PIN: /* External input clock used as SAI1 clock source */ sai_frequency = EXTERNAL_SAI1_CLOCK_VALUE; break; default: break; } } else { #if defined(RCC_CCIPR_SAI2SEL) || defined(RCC_CCIPR2_SAI2SEL) if (SAIxSource == LL_RCC_SAI2_CLKSOURCE) { /* SAI2CLK clock frequency */ switch (LL_RCC_GetSAIClockSource(SAIxSource)) { case LL_RCC_SAI2_CLKSOURCE_PLLSAI1: /* PLLSAI1 clock used as SAI2 clock source */ if (LL_RCC_PLLSAI1_IsReady() != 0U) { sai_frequency = RCC_PLLSAI1_GetFreqDomain_SAI(); } break; #if defined(RCC_PLLSAI2_SUPPORT) case LL_RCC_SAI2_CLKSOURCE_PLLSAI2: /* PLLSAI2 clock used as SAI2 clock source */ if (LL_RCC_PLLSAI2_IsReady() != 0U) { sai_frequency = RCC_PLLSAI2_GetFreqDomain_SAI(); } break; #endif /* RCC_PLLSAI2_SUPPORT */ case LL_RCC_SAI2_CLKSOURCE_PLL: /* PLL clock used as SAI2 clock source */ if (LL_RCC_PLL_IsReady() != 0U) { sai_frequency = RCC_PLL_GetFreqDomain_SAI(); } break; case LL_RCC_SAI2_CLKSOURCE_PIN: /* External input clock used as SAI2 clock source */ sai_frequency = EXTERNAL_SAI2_CLOCK_VALUE; break; default: break; } } #endif /* RCC_CCIPR_SAI2SEL || RCC_CCIPR2_SAI2SEL */ } return sai_frequency; } #endif /* RCC_CCIPR_SAI1SEL || RCC_CCIPR_SAI2SEL || RCC_CCIPR2_SAI1SEL || RCC_CCIPR2_SAI2SEL*/ #if defined(SDMMC1) #if defined(RCC_CCIPR2_SDMMCSEL) /** * @brief Return SDMMCx kernel clock frequency * @param SDMMCxSource This parameter can be one of the following values: * @arg @ref LL_RCC_SDMMC1_KERNELCLKSOURCE * @retval SDMMC clock frequency (in Hz) * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (MSI) or PLL is not ready * - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected */ uint32_t LL_RCC_GetSDMMCKernelClockFreq(uint32_t SDMMCxSource) { uint32_t sdmmc_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_SDMMC_KERNELCLKSOURCE(SDMMCxSource)); /* SDMMC1CLK kernel clock frequency */ switch (LL_RCC_GetSDMMCKernelClockSource(SDMMCxSource)) { case LL_RCC_SDMMC1_KERNELCLKSOURCE_48CLK: /* 48MHz clock from internal multiplexor used as SDMMC1 clock source */ sdmmc_frequency = LL_RCC_GetSDMMCClockFreq(LL_RCC_SDMMC1_CLKSOURCE); break; case LL_RCC_SDMMC1_KERNELCLKSOURCE_PLLP: /* PLL "P" output (PLLSAI3CLK) clock used as SDMMC1 clock source */ if (LL_RCC_PLL_IsReady() != 0U) { sdmmc_frequency = RCC_PLL_GetFreqDomain_SAI(); } break; default: sdmmc_frequency = LL_RCC_PERIPH_FREQUENCY_NA; break; } return sdmmc_frequency; } #endif /** * @brief Return SDMMCx clock frequency * @param SDMMCxSource This parameter can be one of the following values: * @arg @ref LL_RCC_SDMMC1_CLKSOURCE * @retval SDMMC clock frequency (in Hz) * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (MSI) or PLL is not ready * - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected */ uint32_t LL_RCC_GetSDMMCClockFreq(uint32_t SDMMCxSource) { uint32_t sdmmc_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_SDMMC_CLKSOURCE(SDMMCxSource)); /* SDMMC1CLK clock frequency */ switch (LL_RCC_GetSDMMCClockSource(SDMMCxSource)) { #if defined(LL_RCC_SDMMC1_CLKSOURCE_PLLSAI1) case LL_RCC_SDMMC1_CLKSOURCE_PLLSAI1: /* PLLSAI1 clock used as SDMMC1 clock source */ if (LL_RCC_PLLSAI1_IsReady() != 0U) { sdmmc_frequency = RCC_PLLSAI1_GetFreqDomain_48M(); } break; #endif case LL_RCC_SDMMC1_CLKSOURCE_PLL: /* PLL clock used as SDMMC1 clock source */ if (LL_RCC_PLL_IsReady() != 0U) { sdmmc_frequency = RCC_PLL_GetFreqDomain_48M(); } break; #if defined(LL_RCC_SDMMC1_CLKSOURCE_MSI) case LL_RCC_SDMMC1_CLKSOURCE_MSI: /* MSI clock used as SDMMC1 clock source */ if (LL_RCC_MSI_IsReady() != 0U) { sdmmc_frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); } break; #endif #if defined(RCC_HSI48_SUPPORT) case LL_RCC_SDMMC1_CLKSOURCE_HSI48: /* HSI48 used as SDMMC1 clock source */ if (LL_RCC_HSI48_IsReady() != 0U) { sdmmc_frequency = HSI48_VALUE; } break; #else case LL_RCC_SDMMC1_CLKSOURCE_NONE: /* No clock used as SDMMC1 clock source */ #endif default: sdmmc_frequency = LL_RCC_PERIPH_FREQUENCY_NA; break; } return sdmmc_frequency; } #endif /* SDMMC1 */ /** * @brief Return RNGx clock frequency * @param RNGxSource This parameter can be one of the following values: * @arg @ref LL_RCC_RNG_CLKSOURCE * @retval RNG clock frequency (in Hz) * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (MSI) or PLL is not ready * - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected */ uint32_t LL_RCC_GetRNGClockFreq(uint32_t RNGxSource) { uint32_t rng_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_RNG_CLKSOURCE(RNGxSource)); /* RNGCLK clock frequency */ switch (LL_RCC_GetRNGClockSource(RNGxSource)) { #if defined(RCC_PLLSAI1_SUPPORT) case LL_RCC_RNG_CLKSOURCE_PLLSAI1: /* PLLSAI1 clock used as RNG clock source */ if (LL_RCC_PLLSAI1_IsReady() != 0U) { rng_frequency = RCC_PLLSAI1_GetFreqDomain_48M(); } break; #endif /* RCC_PLLSAI1_SUPPORT */ case LL_RCC_RNG_CLKSOURCE_PLL: /* PLL clock used as RNG clock source */ if (LL_RCC_PLL_IsReady() != 0U) { rng_frequency = RCC_PLL_GetFreqDomain_48M(); } break; case LL_RCC_RNG_CLKSOURCE_MSI: /* MSI clock used as RNG clock source */ if (LL_RCC_MSI_IsReady() != 0U) { rng_frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); } break; #if defined(RCC_HSI48_SUPPORT) case LL_RCC_RNG_CLKSOURCE_HSI48: /* HSI48 used as RNG clock source */ if (LL_RCC_HSI48_IsReady() != 0U) { rng_frequency = HSI48_VALUE; } break; #else case LL_RCC_RNG_CLKSOURCE_NONE: /* No clock used as RNG clock source */ #endif default: rng_frequency = LL_RCC_PERIPH_FREQUENCY_NA; break; } return rng_frequency; } #if defined(USB_OTG_FS)||defined(USB) /** * @brief Return USBx clock frequency * @param USBxSource This parameter can be one of the following values: * @arg @ref LL_RCC_USB_CLKSOURCE * @retval USB clock frequency (in Hz) * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (MSI) or PLL is not ready * - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected */ uint32_t LL_RCC_GetUSBClockFreq(uint32_t USBxSource) { uint32_t usb_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_USB_CLKSOURCE(USBxSource)); /* USBCLK clock frequency */ switch (LL_RCC_GetUSBClockSource(USBxSource)) { #if defined(RCC_PLLSAI1_SUPPORT) case LL_RCC_USB_CLKSOURCE_PLLSAI1: /* PLLSAI1 clock used as USB clock source */ if (LL_RCC_PLLSAI1_IsReady() != 0U) { usb_frequency = RCC_PLLSAI1_GetFreqDomain_48M(); } break; #endif /* RCC_PLLSAI1_SUPPORT */ case LL_RCC_USB_CLKSOURCE_PLL: /* PLL clock used as USB clock source */ if (LL_RCC_PLL_IsReady() != 0U) { usb_frequency = RCC_PLL_GetFreqDomain_48M(); } break; case LL_RCC_USB_CLKSOURCE_MSI: /* MSI clock used as USB clock source */ if (LL_RCC_MSI_IsReady() != 0U) { usb_frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); } break; #if defined(RCC_HSI48_SUPPORT) case LL_RCC_USB_CLKSOURCE_HSI48: /* HSI48 used as USB clock source */ if (LL_RCC_HSI48_IsReady() != 0U) { usb_frequency = HSI48_VALUE; } break; #else case LL_RCC_USB_CLKSOURCE_NONE: /* No clock used as USB clock source */ #endif default: usb_frequency = LL_RCC_PERIPH_FREQUENCY_NA; break; } return usb_frequency; } #endif /* USB_OTG_FS || USB */ /** * @brief Return ADCx clock frequency * @param ADCxSource This parameter can be one of the following values: * @arg @ref LL_RCC_ADC_CLKSOURCE * @retval ADC clock frequency (in Hz) * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (MSI) or PLL is not ready * - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected */ uint32_t LL_RCC_GetADCClockFreq(uint32_t ADCxSource) { uint32_t adc_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_ADC_CLKSOURCE(ADCxSource)); /* ADCCLK clock frequency */ switch (LL_RCC_GetADCClockSource(ADCxSource)) { #if defined(RCC_PLLSAI1_SUPPORT) case LL_RCC_ADC_CLKSOURCE_PLLSAI1: /* PLLSAI1 clock used as ADC clock source */ if (LL_RCC_PLLSAI1_IsReady() != 0U) { adc_frequency = RCC_PLLSAI1_GetFreqDomain_ADC(); } break; #endif /* RCC_PLLSAI1_SUPPORT */ #if defined(RCC_PLLSAI2_SUPPORT) && defined(LL_RCC_ADC_CLKSOURCE_PLLSAI2) case LL_RCC_ADC_CLKSOURCE_PLLSAI2: /* PLLSAI2 clock used as ADC clock source */ if (LL_RCC_PLLSAI2_IsReady() != 0U) { adc_frequency = RCC_PLLSAI2_GetFreqDomain_ADC(); } break; #endif /* RCC_PLLSAI2_SUPPORT && LL_RCC_ADC_CLKSOURCE_PLLSAI2 */ case LL_RCC_ADC_CLKSOURCE_SYSCLK: /* SYSCLK clock used as ADC clock source */ adc_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_ADC_CLKSOURCE_NONE: /* No clock used as ADC clock source */ default: adc_frequency = LL_RCC_PERIPH_FREQUENCY_NA; break; } return adc_frequency; } #if defined(SWPMI1) /** * @brief Return SWPMIx clock frequency * @param SWPMIxSource This parameter can be one of the following values: * @arg @ref LL_RCC_SWPMI1_CLKSOURCE * @retval SWPMI clock frequency (in Hz) * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI) is not ready */ uint32_t LL_RCC_GetSWPMIClockFreq(uint32_t SWPMIxSource) { uint32_t swpmi_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_SWPMI_CLKSOURCE(SWPMIxSource)); /* SWPMI1CLK clock frequency */ switch (LL_RCC_GetSWPMIClockSource(SWPMIxSource)) { case LL_RCC_SWPMI1_CLKSOURCE_HSI: /* SWPMI1 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady()) { swpmi_frequency = HSI_VALUE; } break; case LL_RCC_SWPMI1_CLKSOURCE_PCLK1: /* SWPMI1 Clock is PCLK1 */ swpmi_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; default: break; } return swpmi_frequency; } #endif /* SWPMI1 */ #if defined(DFSDM1_Channel0) /** * @brief Return DFSDMx clock frequency * @param DFSDMxSource This parameter can be one of the following values: * @arg @ref LL_RCC_DFSDM1_CLKSOURCE * @retval DFSDM clock frequency (in Hz) */ uint32_t LL_RCC_GetDFSDMClockFreq(uint32_t DFSDMxSource) { uint32_t dfsdm_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_DFSDM_CLKSOURCE(DFSDMxSource)); /* DFSDM1CLK clock frequency */ switch (LL_RCC_GetDFSDMClockSource(DFSDMxSource)) { case LL_RCC_DFSDM1_CLKSOURCE_SYSCLK: /* DFSDM1 Clock is SYSCLK */ dfsdm_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_DFSDM1_CLKSOURCE_PCLK2: /* DFSDM1 Clock is PCLK2 */ dfsdm_frequency = RCC_GetPCLK2ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; default: break; } return dfsdm_frequency; } #if defined(RCC_CCIPR2_DFSDM1SEL) /** * @brief Return DFSDMx Audio clock frequency * @param DFSDMxSource This parameter can be one of the following values: * @arg @ref LL_RCC_DFSDM1_AUDIO_CLKSOURCE * @retval DFSDM clock frequency (in Hz) * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator is not ready */ uint32_t LL_RCC_GetDFSDMAudioClockFreq(uint32_t DFSDMxSource) { uint32_t dfsdm_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_DFSDM_AUDIO_CLKSOURCE(DFSDMxSource)); /* DFSDM1CLK clock frequency */ switch (LL_RCC_GetDFSDMAudioClockSource(DFSDMxSource)) { case LL_RCC_DFSDM1_AUDIO_CLKSOURCE_SAI1: /* SAI1 clock used as DFSDM1 audio clock */ dfsdm_frequency = LL_RCC_GetSAIClockFreq(LL_RCC_SAI1_CLKSOURCE); break; case LL_RCC_DFSDM1_AUDIO_CLKSOURCE_MSI: /* MSI clock used as DFSDM1 audio clock */ if (LL_RCC_MSI_IsReady() != 0U) { dfsdm_frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); } break; case LL_RCC_DFSDM1_AUDIO_CLKSOURCE_HSI: /* HSI clock used as DFSDM1 audio clock */ default: if (LL_RCC_HSI_IsReady() != 0U) { dfsdm_frequency = HSI_VALUE; } break; } return dfsdm_frequency; } #endif /* RCC_CCIPR2_DFSDM1SEL */ #endif /* DFSDM1_Channel0 */ #if defined(DSI) /** * @brief Return DSI clock frequency * @param DSIxSource This parameter can be one of the following values: * @arg @ref LL_RCC_DSI_CLKSOURCE * @retval DSI clock frequency (in Hz) * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator is not ready * - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that external clock is used */ uint32_t LL_RCC_GetDSIClockFreq(uint32_t DSIxSource) { uint32_t dsi_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_DSI_CLKSOURCE(DSIxSource)); /* DSICLK clock frequency */ switch (LL_RCC_GetDSIClockSource(DSIxSource)) { case LL_RCC_DSI_CLKSOURCE_PLL: /* DSI Clock is PLLSAI2 Osc. */ if (LL_RCC_PLLSAI2_IsReady() != 0U) { dsi_frequency = RCC_PLLSAI2_GetFreqDomain_DSI(); } break; case LL_RCC_DSI_CLKSOURCE_PHY: /* DSI Clock is DSI physical clock. */ default: dsi_frequency = LL_RCC_PERIPH_FREQUENCY_NA; break; } return dsi_frequency; } #endif /* DSI */ #if defined(LTDC) /** * @brief Return LTDC clock frequency * @param LTDCxSource This parameter can be one of the following values: * @arg @ref LL_RCC_LTDC_CLKSOURCE * @retval LTDC clock frequency (in Hz) * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator PLLSAI is not ready */ uint32_t LL_RCC_GetLTDCClockFreq(uint32_t LTDCxSource) { uint32_t ltdc_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_LTDC_CLKSOURCE(LTDCxSource)); if (LL_RCC_PLLSAI2_IsReady() != 0U) { ltdc_frequency = RCC_PLLSAI2_GetFreqDomain_LTDC(); } return ltdc_frequency; } #endif /* LTDC */ #if defined(OCTOSPI1) /** * @brief Return OCTOSPI clock frequency * @param OCTOSPIxSource This parameter can be one of the following values: * @arg @ref LL_RCC_OCTOSPI_CLKSOURCE * @retval OCTOSPI clock frequency (in Hz) * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator PLLSAI is not ready */ uint32_t LL_RCC_GetOCTOSPIClockFreq(uint32_t OCTOSPIxSource) { uint32_t octospi_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_OCTOSPI_CLKSOURCE(OCTOSPIxSource)); /* OCTOSPI clock frequency */ switch (LL_RCC_GetOCTOSPIClockSource(OCTOSPIxSource)) { case LL_RCC_OCTOSPI_CLKSOURCE_SYSCLK: /* OCTOSPI clock is SYSCLK */ octospi_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_OCTOSPI_CLKSOURCE_MSI: /* MSI clock used as OCTOSPI clock */ if (LL_RCC_MSI_IsReady() != 0U) { octospi_frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); } break; case LL_RCC_OCTOSPI_CLKSOURCE_PLL: /* PLL clock used as OCTOSPI source */ if (LL_RCC_PLL_IsReady() != 0U) { octospi_frequency = RCC_PLL_GetFreqDomain_48M(); } break; default: octospi_frequency = LL_RCC_PERIPH_FREQUENCY_NO; break; } return octospi_frequency; } #endif /* OCTOSPI1 */ /** * @} */ /** * @} */ /** @addtogroup RCC_LL_Private_Functions * @{ */ /** * @brief Return SYSTEM clock frequency * @retval SYSTEM clock frequency (in Hz) */ uint32_t RCC_GetSystemClockFreq(void) { uint32_t frequency; /* Get SYSCLK source -------------------------------------------------------*/ switch (LL_RCC_GetSysClkSource()) { case LL_RCC_SYS_CLKSOURCE_STATUS_MSI: /* MSI used as system clock source */ frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; case LL_RCC_SYS_CLKSOURCE_STATUS_HSI: /* HSI used as system clock source */ frequency = HSI_VALUE; break; case LL_RCC_SYS_CLKSOURCE_STATUS_HSE: /* HSE used as system clock source */ frequency = HSE_VALUE; break; case LL_RCC_SYS_CLKSOURCE_STATUS_PLL: /* PLL used as system clock source */ frequency = RCC_PLL_GetFreqDomain_SYS(); break; default: frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; } return frequency; } /** * @brief Return HCLK clock frequency * @param SYSCLK_Frequency SYSCLK clock frequency * @retval HCLK clock frequency (in Hz) */ uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency) { /* HCLK clock frequency */ return __LL_RCC_CALC_HCLK_FREQ(SYSCLK_Frequency, LL_RCC_GetAHBPrescaler()); } /** * @brief Return PCLK1 clock frequency * @param HCLK_Frequency HCLK clock frequency * @retval PCLK1 clock frequency (in Hz) */ uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency) { /* PCLK1 clock frequency */ return __LL_RCC_CALC_PCLK1_FREQ(HCLK_Frequency, LL_RCC_GetAPB1Prescaler()); } /** * @brief Return PCLK2 clock frequency * @param HCLK_Frequency HCLK clock frequency * @retval PCLK2 clock frequency (in Hz) */ uint32_t RCC_GetPCLK2ClockFreq(uint32_t HCLK_Frequency) { /* PCLK2 clock frequency */ return __LL_RCC_CALC_PCLK2_FREQ(HCLK_Frequency, LL_RCC_GetAPB2Prescaler()); } /** * @brief Return PLL clock frequency used for system domain * @retval PLL clock frequency (in Hz) */ uint32_t RCC_PLL_GetFreqDomain_SYS(void) { uint32_t pllinputfreq, pllsource; /* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN SYSCLK = PLL_VCO / PLLR */ pllsource = LL_RCC_PLL_GetMainSource(); switch (pllsource) { case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLL clock source */ pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */ pllinputfreq = HSI_VALUE; break; case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */ pllinputfreq = HSE_VALUE; break; default: pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; } return __LL_RCC_CALC_PLLCLK_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(), LL_RCC_PLL_GetN(), LL_RCC_PLL_GetR()); } #if defined(SAI1) /** * @brief Return PLL clock frequency used for SAI domain * @retval PLL clock frequency (in Hz) */ uint32_t RCC_PLL_GetFreqDomain_SAI(void) { uint32_t pllinputfreq, pllsource; /* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE / PLLM) * PLLN SAI Domain clock = PLL_VCO / PLLP */ pllsource = LL_RCC_PLL_GetMainSource(); switch (pllsource) { case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLL clock source */ pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */ pllinputfreq = HSI_VALUE; break; case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */ pllinputfreq = HSE_VALUE; break; default: pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; } return __LL_RCC_CALC_PLLCLK_SAI_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(), LL_RCC_PLL_GetN(), LL_RCC_PLL_GetP()); } #endif /* SAI1 */ /** * @brief Return PLL clock frequency used for 48 MHz domain * @retval PLL clock frequency (in Hz) */ uint32_t RCC_PLL_GetFreqDomain_48M(void) { uint32_t pllinputfreq, pllsource; /* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN 48M Domain clock = PLL_VCO / PLLQ */ pllsource = LL_RCC_PLL_GetMainSource(); switch (pllsource) { case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLL clock source */ pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */ pllinputfreq = HSI_VALUE; break; case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */ pllinputfreq = HSE_VALUE; break; default: pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; } return __LL_RCC_CALC_PLLCLK_48M_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(), LL_RCC_PLL_GetN(), LL_RCC_PLL_GetQ()); } #if defined(DSI) /** * @brief Return PLL clock frequency used for DSI clock * @retval PLL clock frequency (in Hz) */ uint32_t RCC_PLLSAI2_GetFreqDomain_DSI(void) { uint32_t pllinputfreq, pllsource; /* PLLSAI2_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLSAI2M) * PLLSAI2N */ /* DSICLK = PLLSAI2_VCO / PLLSAI2R */ pllsource = LL_RCC_PLL_GetMainSource(); switch (pllsource) { case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI2 clock source */ pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI2 clock source */ pllinputfreq = HSI_VALUE; break; case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI2 clock source */ pllinputfreq = HSE_VALUE; break; default: pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; } return __LL_RCC_CALC_PLLSAI2_DSI_FREQ(pllinputfreq, LL_RCC_PLLSAI2_GetDivider(), LL_RCC_PLLSAI2_GetN(), LL_RCC_PLLSAI2_GetR()); } #endif /* DSI */ #if defined(RCC_PLLSAI1_SUPPORT) /** * @brief Return PLLSAI1 clock frequency used for SAI domain * @retval PLLSAI1 clock frequency (in Hz) */ uint32_t RCC_PLLSAI1_GetFreqDomain_SAI(void) { uint32_t pllinputfreq, pllsource; #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT) /* PLLSAI1_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLSAI1M) * PLLSAI1N */ #else /* PLLSAI1_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLSAI1N */ #endif /* SAI Domain clock = PLLSAI1_VCO / PLLSAI1P */ pllsource = LL_RCC_PLL_GetMainSource(); switch (pllsource) { case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI1 clock source */ pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI1 clock source */ pllinputfreq = HSI_VALUE; break; case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI1 clock source */ pllinputfreq = HSE_VALUE; break; default: pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; } return __LL_RCC_CALC_PLLSAI1_SAI_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(), LL_RCC_PLLSAI1_GetN(), LL_RCC_PLLSAI1_GetP()); } /** * @brief Return PLLSAI1 clock frequency used for 48Mhz domain * @retval PLLSAI1 clock frequency (in Hz) */ uint32_t RCC_PLLSAI1_GetFreqDomain_48M(void) { uint32_t pllinputfreq, pllsource; #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT) /* PLLSAI1_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLSAI1M) * PLLSAI1N */ #else /* PLLSAI1_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLSAI1N */ #endif /* 48M Domain clock = PLLSAI1_VCO / PLLSAI1Q */ pllsource = LL_RCC_PLL_GetMainSource(); switch (pllsource) { case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI1 clock source */ pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI1 clock source */ pllinputfreq = HSI_VALUE; break; case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI1 clock source */ pllinputfreq = HSE_VALUE; break; default: pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; } return __LL_RCC_CALC_PLLSAI1_48M_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(), LL_RCC_PLLSAI1_GetN(), LL_RCC_PLLSAI1_GetQ()); } /** * @brief Return PLLSAI1 clock frequency used for ADC domain * @retval PLLSAI1 clock frequency (in Hz) */ uint32_t RCC_PLLSAI1_GetFreqDomain_ADC(void) { uint32_t pllinputfreq, pllsource; #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT) /* PLLSAI1_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLSAI1M) * PLLSAI1N */ #else /* PLLSAI1_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLSAI1N */ #endif /* 48M Domain clock = PLLSAI1_VCO / PLLSAI1R */ pllsource = LL_RCC_PLL_GetMainSource(); switch (pllsource) { case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI1 clock source */ pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI1 clock source */ pllinputfreq = HSI_VALUE; break; case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI1 clock source */ pllinputfreq = HSE_VALUE; break; default: pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; } return __LL_RCC_CALC_PLLSAI1_ADC_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(), LL_RCC_PLLSAI1_GetN(), LL_RCC_PLLSAI1_GetR()); } #endif /* RCC_PLLSAI1_SUPPORT */ #if defined(RCC_PLLSAI2_SUPPORT) /** * @brief Return PLLSAI2 clock frequency used for SAI domain * @retval PLLSAI2 clock frequency (in Hz) */ uint32_t RCC_PLLSAI2_GetFreqDomain_SAI(void) { uint32_t pllinputfreq, pllsource; #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT) /* PLLSAI2_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLSAI2M) * PLLSAI2N */ #else /* PLLSAI2_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLSAI2N */ #endif /* SAI Domain clock = PLLSAI2_VCO / PLLSAI2P */ pllsource = LL_RCC_PLL_GetMainSource(); switch (pllsource) { case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI2 clock source */ pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI2 clock source */ pllinputfreq = HSI_VALUE; break; case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI2 clock source */ pllinputfreq = HSE_VALUE; break; default: pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; } #if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT) return __LL_RCC_CALC_PLLSAI2_SAI_FREQ(pllinputfreq, LL_RCC_PLLSAI2_GetDivider(), LL_RCC_PLLSAI2_GetN(), LL_RCC_PLLSAI2_GetP()); #else return __LL_RCC_CALC_PLLSAI2_SAI_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(), LL_RCC_PLLSAI2_GetN(), LL_RCC_PLLSAI2_GetP()); #endif } #if defined(LTDC) /** * @brief Return PLLSAI2 clock frequency used for LTDC domain * @retval PLLSAI2 clock frequency (in Hz) */ uint32_t RCC_PLLSAI2_GetFreqDomain_LTDC(void) { uint32_t pllinputfreq, pllsource; /* PLLSAI2_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLSAI2M) * PLLSAI2N */ /* LTDC Domain clock = (PLLSAI2_VCO / PLLSAI2R) / PLLSAI2DIVR */ pllsource = LL_RCC_PLL_GetMainSource(); switch (pllsource) { case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI2 clock source */ pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI2 clock source */ pllinputfreq = HSI_VALUE; break; case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI2 clock source */ pllinputfreq = HSE_VALUE; break; default: pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; } return __LL_RCC_CALC_PLLSAI2_LTDC_FREQ(pllinputfreq, LL_RCC_PLLSAI2_GetDivider(), LL_RCC_PLLSAI2_GetN(), LL_RCC_PLLSAI2_GetR(), LL_RCC_PLLSAI2_GetDIVR()); } #else /** * @brief Return PLLSAI2 clock frequency used for ADC domain * @retval PLLSAI2 clock frequency (in Hz) */ uint32_t RCC_PLLSAI2_GetFreqDomain_ADC(void) { uint32_t pllinputfreq = 0U, pllsource = 0U; /* PLLSAI2_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLSAI2N */ /* 48M Domain clock = PLLSAI2_VCO / PLLSAI2R */ pllsource = LL_RCC_PLL_GetMainSource(); switch (pllsource) { case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI2 clock source */ pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI2 clock source */ pllinputfreq = HSI_VALUE; break; case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI2 clock source */ pllinputfreq = HSE_VALUE; break; default: pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(), ((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ? LL_RCC_MSI_GetRange() : LL_RCC_MSI_GetRangeAfterStandby())); break; } return __LL_RCC_CALC_PLLSAI2_ADC_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(), LL_RCC_PLLSAI2_GetN(), LL_RCC_PLLSAI2_GetR()); } #endif /* LTDC */ #endif /*RCC_PLLSAI2_SUPPORT*/ /** * @} */ /** * @} */ #endif /* defined(RCC) */ /** * @} */ #endif /* USE_FULL_LL_DRIVER */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
the_stack_data/518217.c
/* Author: Lucas Pacheco. Description: A test exercise from "The Audio Programming Book", modifying Listing 1.2. Date: 09/05/2020. */ /* listing 1.2. Calculate frequency of a MIDI Note number */ #include <stdio.h> #include <math.h> int main() { double semitone_ratio; double c0; /* for frequency of MIDI Note 0 */ double c5; /* for frequency of Middle C */ double frequency; /* . . . which we want to find, */ int midinote; /* . . . given this note. */ /* calculate required numbers */ semitone_ratio = pow(2.0, 1.0 / 12.0); /* approx. 1.0594631 */ /* find Middle C, three semitones above low A = 220 */ c5 = 220.0 * pow(semitone_ratio, 3.0); /* MIDI Note 0 is C, 5 octaves below Middle C */ c0 = c5 * pow(0.5, 5.0); /* calculate a frequency for a given MIDI Note Number */ midinote = 73; /* C# above A = 440 */ frequency = c0 * pow(semitone_ratio,(double) midinote); printf("MIDI Note %d has frequency %f\n", midinote, frequency); return 0; } /* OUTPUT SAMPLE: MIDI Note 73 has frequency 554.365262 */
the_stack_data/206392144.c
#include<stdio.h> #include<stdlib.h> int main(){ char a,b; printf("enter two char :\n"); scanf("%c",&a); int f = fflush(stdin); scanf("%c",&b); printf("a=%d \t b=%d\n",a,b); printf("%d\n",f); return 1; }
the_stack_data/732.c
#include<stdio.h> int main() { int n, count=0; float x, avarage, sum = 0; printf("How many numbers :"); scanf("%d", &n); do { printf("x = "); scanf("%f", &x); sum = sum + x; count++; } while(count<n); avarage = sum/n; printf("Avarage is %f\n", avarage); return 0; }
the_stack_data/57102.c
/* { dg-do assemble } */ static inline unsigned long rdfpcr(void) { unsigned long tmp, ret; __asm__ ("" : "=r"(tmp), "=r"(ret)); return ret; } static inline unsigned long swcr_update_status(unsigned long swcr, unsigned long fpcr) { swcr &= ~0x7e0000ul; swcr |= (fpcr >> 3) & 0x7e0000ul; return swcr; } unsigned long osf_getsysinfo(unsigned long flags) { unsigned long w; w = swcr_update_status(flags, rdfpcr()); return w; }
the_stack_data/70644.c
#include <stdio.h> #include <stdlib.h> void printArray(int a[], int dim); int main() { /* 1) Array statici: memorizzati nello Stack */ int a[] = {1, 2, 3, 4, 5 }; int dimA = 5; printf("Array statico di %d elementi:", dimA); printArray(a, dimA); /* 2) Array dinamici */ int numElem = 10; /* MALLOC ➝ malloc(numByte); */ int *p1; p1 = (int*) malloc(numElem * sizeof(int)); if(p1 == NULL) printf("Errore durante l'allocazione di memoria con malloc"); for(int i=0; i<numElem; i++) p1[i] = i; printf("Array dinamico (allocato con malloc) di %d elementi:", numElem); printArray(p1,numElem); /* CALLOC ➝ calloc(numElem, dimSingolo); */ p1 = (int*) calloc(numElem, sizeof(int)); if(p1 == NULL) printf("Errore durante l'allocazione di memoria con calloc"); for(int i=0; i<numElem; i++) p1[i] = i; printf("Array dinamico (allocato con calloc) di %d elementi:", numElem); printArray(p1,numElem); /* REALLOC ➝ realloc(arrDinamico, newNumByte); */ numElem = 12; p1 = realloc(p1, numElem * sizeof(int)); //numElementi aumenta di 2 for(int i=0; i<numElem; i++) p1[i] = i; printf("Array dinamico di %d elementi:", numElem); printArray(p1,numElem); numElem = 8; p1 = realloc(p1, (numElem) * sizeof(int)); for(int i=0; i<numElem; i++) p1[i] = i; printf("Array dinamico di %d elementi:", numElem); printArray(p1,numElem); /* FREE ➝ free(puntatore); */ free(p1); /* 3) Array a lunghezza variabile */ int size; printf("Array a Lunghezza Variabile, dimensione: "); scanf("%d", &size); int b[size]; //Metto dei valori nell'array for(int i=0; i<size; i++) b[i] = i; printf("Array statico di %d elementi (dichiarati run-time):", size); printArray(b, size); return 0; } void printArray(int a[], int dim){ printf("\n\t[ "); for (int i = 0; i < dim; ++i) printf("%d ",a[i]); printf("] \n\n"); }
the_stack_data/141677.c
/* C implementation */ #include <stdint.h> #include <stdlib.h> #include <stdio.h> #include <memory.h> #include <math.h> #include <float.h> #include <assert.h> #include <time.h> // Quicksort algorithm void swap(int* a, int* b); int partition (int arr[], int low, int high); int * quickSort(int arr[], int low, int high); double lowpass (double *x, double *y, int M, double xm1); /* C function implementing the simplest lowpass: * * y(n) = x(n) + x(n-1) * */ double lowpass (double *x, double *y, int M, double xm1) { int n; y[0] = x[0] + xm1; for (n=1; n < M ; n++) { y[n] = x[n] + x[n-1]; } return x[M-1]; } // A utility function to swap two elements inline void swap(int* a, int* b) { int t = *a; *a = *b; *b = t; } /* This function takes last element as pivot, places the pivot element at its correct position in sorted array, and places all smaller (smaller than pivot) to left of pivot and all greater elements to right of pivot */ inline int partition (int arr[], int low, int high) { int pivot = arr[high]; // pivot int i = (low - 1); // Index of smaller element for (int j = low; j <= high- 1; j++) { // If current element is smaller than the pivot if (arr[j] < pivot) { i++; // increment index of smaller element swap(&arr[i], &arr[j]); } } swap(&arr[i + 1], &arr[high]); return (i + 1); } /* The main function that implements QuickSort arr[] --> Array to be sorted, low --> Starting index, high --> Ending index */ int * quickSort(int arr[], int low, int high) { if (low < high) { /* pi is partitioning index, arr[p] is now at right place */ int pi = partition(arr, low, high); // Separately sort elements before // partition and after partition quickSort(arr, low, pi - 1); quickSort(arr, pi + 1, high); } return arr; } float f_max(float arr[], int element) { int i = 1; float maximum = fabs(arr[0]); for (i;i<element;i++) { if (fabs(arr[i]) > maximum) { maximum = fabs(arr[i]);} } return maximum; } int main(){ double x[10] = {1,2,3,4,5,6,7,8,9,10}; double y[10]; int i; int N=10; int M=N/2; /* block size */ double xm1 = 0; xm1 = lowpass(x, y, M, xm1); xm1 = lowpass(&x[M], &y[M], M, xm1); for (i=0;i<N;i++) { printf("x[%d]=%f\ty[%d]=%f\n",i,x[i],i,y[i]); } float z[10] = {10,-8000000,150,400,250,13.5,8000001,523,-15.054,100.0}; printf("RESULT : %f ", f_max(z, 10)); return 0; }
the_stack_data/326363.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> struct chunk { int size; int in_use; struct chunk *next; }; struct chunk *flist = NULL; void *malloc (size_t size) { if (size == 0){ return NULL; } struct chunk *next = flist; struct chunk *prev = NULL; while(next != NULL){ if(next -> size >= size){ next->in_use = size; if(prev != NULL){ prev->next = next->next; }else{ flist = next->next; } return (void*)(next + 1); }else{ prev = next; next = next -> next; } } void *memory = sbrk(size + sizeof(struct chunk)); if(memory == (void *) - 1){ return NULL; }else{ struct chunk *cnk = (struct chunk*)memory; cnk -> size = size; cnk -> in_use = size; return (void *)(cnk + 1); } } void free(void *memory) { if(memory != NULL){ struct chunk *cnk = (struct chunk*)((struct chunk*)memory -1); cnk -> next = flist; flist = cnk; } return; } //Computes: // the total number of free chunks allocated // the total number of in-use chunks allocated // the largest, smallest, and average unused memory across all used chunks // the total unused memory across all used chunks // the largest, smallest, and average sizes of all free chunks void fragstats(void* buffers[], int len) { struct chunk *freed_loc = flist; int in_use_chunks = 0; int free_chunks = 0; double unused_bytes = 0; double total_free_bytes = 0; int smallest_unused = 0; int smallest_freed = 0; int largest_unused = 0; int largest_freed = 0; double average_unused; double average_freed; for(int i = 0; i < len; i++){ if(buffers[i] != NULL){ struct chunk *ch = (struct chunk*)(buffers[i] - 1); int unused = ch->size - ch->in_use; unused_bytes += unused; if(unused < smallest_unused || smallest_unused == 0){ smallest_unused = unused; } if(unused > largest_unused){ largest_unused = unused; } in_use_chunks++; } } while(freed_loc != NULL){ free_chunks++; total_free_bytes += freed_loc->size; if(freed_loc->size < smallest_freed || smallest_freed == 0){ smallest_freed = freed_loc->size; } if(freed_loc->size > largest_freed){ largest_freed = freed_loc->size; } freed_loc = freed_loc -> next; } average_unused = unused_bytes / in_use_chunks; average_freed = total_free_bytes / free_chunks; printf("Total chunks: %d Free: %d Used: %d\n", in_use_chunks+free_chunks, free_chunks, in_use_chunks); printf("Internal unusued: total: %.0f average: %.1f smallest: %d largest: %d\n", unused_bytes, average_unused, smallest_unused, largest_unused); printf("External unused: total: %.0f average: %.1f smallest: %d largest: %d\n", total_free_bytes, average_freed, smallest_freed, largest_freed); }
the_stack_data/190766869.c
/* A program using hashing, using chaining for collision resolution * Stores "data" * Key is "score" */ #include <stdio.h> #include <stdlib.h> #define SIZE 7 typedef struct data { char name[16]; int age; int score; struct data *next; }data; data *ht[SIZE]; int hash(int key) { return key % 7; } data *search(int score) { int h = hash(score); data *p = ht[h]; while(p) { if(p->score == score) { return p; } p = p->next; } /* Not found */ return NULL; } void store(data x) { int h = hash(x.score); data *tmp; /* store record x in the linked list at index h */ tmp = (data *)malloc(sizeof(data)); *tmp = x; tmp->next = ht[h]; ht[h] = tmp; } void initht() { int i; for(i = 0; i < SIZE; i++) ht[i] = NULL; } void printht() { int i; data *p; for(i = 0; i < SIZE; i++) { printf("%d : ", i); p = ht[i]; while(p) { printf("%s %d %d\t", p->name, p->age, p->score); p = p->next; } printf("\n"); } } int main() { /* Store data */ data d, *p; int score; initht(); while(scanf("%s%d%d", d.name, &d.age, &d.score) && d.score != -1) { store(d); printht(); } /* Many search operations */ while(scanf("%d", &score) != -1) { p = search(score); if(p) printf("%s %d %d \n", p->name, p->age, p->score); else printf("Not found \n"); } return 0; }
the_stack_data/22012086.c
#include <stdio.h> int main(void) { float f_number; printf("Enter float\n"); scanf("%f",&f_number); printf("The input is %.1f or %.1e\n", f_number,f_number); printf("The input is %+.3f or %.3E\n", f_number,f_number); return 0; }
the_stack_data/21984.c
#include <stdio.h> #include <string.h> int main() { char mohammad[512]; char * find; printf("I will collect everything you type BUT new-line: \n"); fgets(mohammad, 512, stdin); find = strchr(mohammad, '\n'); if (find) { *find = '\0'; } else { while (getchar() != '\n') { continue; } } printf("\"%s\"", mohammad); getchar(); return 0; }
the_stack_data/175144285.c
// // Created by xp10rd on 4/22/19. // #include <stdio.h> #include <ctype.h> int main() { int symbol; while((symbol = getc(stdin)) != EOF) { putc(toupper(symbol), stdout); } return 0; }
the_stack_data/855523.c
/* * Copy string s2 to s1. s1 must be large enough. * return s1 */ char *strcpy(char *s1, const char *s2) { char *os1; os1 = s1; while (*s1++ = *s2++) ; return(os1); }
the_stack_data/93888700.c
// Copyright (c) 2015 MIT License by 6.172 Staff #include <stdint.h> #include <stdlib.h> #include <math.h> #define SIZE (1L << 16) void test(uint8_t * restrict a, uint8_t * restrict b) { a = __builtin_assume_aligned(a, 16); b = __builtin_assume_aligned(b, 16); // Find the (row-wise) max of both arrays for (uint64_t i = 0; i < SIZE; i++) { a[i] = (b[i] > a[i]) ? b[i] : a[i]; } }
the_stack_data/247954.c
#include<stdio.h> #include<math.h> int parent(int i) { return (i-1)/2; } int left(int i) { return 2*i+1; } int right(int i) { return 2*i+2; } void maxheapify(int arr[], int n, int i) { int l, r,largest,temp; l = left(i); r = right(i); if(l<n && arr[l] > arr[i]) largest = l; else largest = i; if(r<n && arr[r] > arr[largest]) largest = r; //printf("\ni=%d l=%d r=%d largest=%d",i,l,r,largest); if(largest != i) { temp = arr[i]; arr[i] = arr[largest]; arr[largest] = temp; maxheapify(arr,n,largest); } } void minheapify(int arr[], int n, int i) { int l, r,smallest,temp; l = left(i); r = right(i); if(l<n && arr[l] < arr[i]) smallest = l; else smallest = i; if(r<n && arr[r] < arr[smallest]) smallest = r; //printf("\ni=%d l=%d r=%d smallest=%d",i,l,r,smallest); if(smallest != i) { temp = arr[i]; arr[i] = arr[smallest]; arr[smallest] = temp; minheapify(arr,n,smallest); } } void main() { int arr[20],brr[20]; int i=0,n; printf("Enter the number of elements in array : "); scanf("%d",&n); printf("\nEnter the elements : "); for(i=0;i<n;i++){ scanf("%d",&arr[i]); brr[i]=arr[i]; } printf("\n\tArray before max heap \n\n"); for(i=0;i<n;i++) printf("%d ",arr[i]); for(i=(n-1)/2;i>=0;i--) maxheapify(arr,n,i); printf("\n\n\tArray after Max-heap \n\n"); for(i=0;i<n;i++) printf("%d ",arr[i]); for(i=(n-1)/2;i>=0;i--) minheapify(brr,n,i); printf("\n\n\tArray after Min-heap \n\n"); for(i=0;i<n;i++) printf("%d ",brr[i]); }
the_stack_data/237644282.c
#include <stdio.h> int main() { int n, x; char s[2333]; scanf("%d", &n); while(n--){ scanf("%d", &x); int top = 0; if(x == 0){ printf("0\n"); }else{ while(x){ if(x % 3 == 2){ s[++top] = '-'; x = x / 3 + 1; }else if(x % 3 == 1){ s[++top] = '1'; x /= 3; }else{ s[++top] = '0'; x /= 3; } } for(int i = top; i > 0; i--) putchar(s[i]); putchar('\n'); } } return 0; }
the_stack_data/181392290.c
/* $OpenBSD: malloc-wrapper.c,v 1.7 2018/05/13 13:49:04 jsing Exp $ */ /* * Copyright (c) 2014 Bob Beck * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <stdio.h> #include <stdlib.h> #include <string.h> int CRYPTO_set_mem_functions(void *(*m)(size_t), void *(*r)(void *, size_t), void (*f)(void *)) { return 0; } int CRYPTO_set_mem_ex_functions(void *(*m)(size_t, const char *, int), void *(*r)(void *, size_t, const char *, int), void (*f)(void *)) { return 0; } int CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*f)(void *)) { return 0; } int CRYPTO_set_locked_mem_ex_functions(void *(*m)(size_t, const char *, int), void (*f)(void *)) { return 0; } int CRYPTO_set_mem_debug_functions(void (*m)(void *, int, const char *, int, int), void (*r)(void *, void *, int, const char *, int, int), void (*f)(void *, int), void (*so)(long), long (*go)(void)) { return 0; } void CRYPTO_get_mem_functions(void *(**m)(size_t), void *(**r)(void *, size_t), void (**f)(void *)) { if (m != NULL) *m = malloc; if (r != NULL) *r = realloc; if (f != NULL) *f = free; } void CRYPTO_get_mem_ex_functions(void *(**m)(size_t, const char *, int), void *(**r)(void *, size_t, const char *, int), void (**f)(void *)) { if (m != NULL) *m = NULL; if (r != NULL) *r = NULL; if (f != NULL) *f = free; } void CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *)) { if (m != NULL) *m = malloc; if (f != NULL) *f = free; } void CRYPTO_get_locked_mem_ex_functions(void *(**m)(size_t, const char *, int), void (**f)(void *)) { if (m != NULL) *m = NULL; if (f != NULL) *f = free; } void CRYPTO_get_mem_debug_functions(void (**m)(void *, int, const char *, int, int), void (**r)(void *, void *, int, const char *, int, int), void (**f)(void *, int), void (**so)(long), long (**go)(void)) { if (m != NULL) *m = NULL; if (r != NULL) *r = NULL; if (f != NULL) *f = NULL; if (so != NULL) *so = NULL; if (go != NULL) *go = NULL; } void * CRYPTO_malloc_locked(int num, const char *file, int line) { if (num <= 0) return NULL; return malloc(num); } void CRYPTO_free_locked(void *ptr) { free(ptr); } void * CRYPTO_malloc(int num, const char *file, int line) { if (num <= 0) return NULL; return malloc(num); } char * CRYPTO_strdup(const char *str, const char *file, int line) { return strdup(str); } void * CRYPTO_realloc(void *ptr, int num, const char *file, int line) { if (num <= 0) return NULL; return realloc(ptr, num); } void * CRYPTO_realloc_clean(void *ptr, int old_len, int num, const char *file, int line) { if (num <= 0) return NULL; /* Original does not support shrinking. */ if (num < old_len) return NULL; return recallocarray(ptr, old_len, num, 1); } void CRYPTO_free(void *ptr) { free(ptr); } void * CRYPTO_remalloc(void *a, int num, const char *file, int line) { free(a); return malloc(num); } void CRYPTO_set_mem_debug_options(long bits) { return; } long CRYPTO_get_mem_debug_options(void) { return 0; }
the_stack_data/624726.c
#define maxmn '~'-'0' #define bufsize 128 \ /*1:*/ #line 23 "./sat-oss.w" #include <stdio.h> #include <stdlib.h> int m,n,t; int w[maxmn][maxmn]; char buf[bufsize]; main(int argc,char*argv[]){ register int i,j,ii,jj,k,l; /*2:*/ #line 37 "./sat-oss.w" if(argc!=4|| sscanf(argv[1],"%d",&m)!=1|| sscanf(argv[2],"%d",&n)!=1|| sscanf(argv[3],"%d",&t)!=1){ fprintf(stderr,"Usage: %s m n t < w[m][n]\n",argv[0]); exit(-1); } if(m> maxmn){ fprintf(stderr,"Sorry, m (%d) must not exceed %d!\n",m,maxmn); exit(-2); } if(n> maxmn){ fprintf(stderr,"Sorry, n (%d) must not exceed %d!\n",n,maxmn); exit(-3); } /*:2*/ #line 31 "./sat-oss.w" ; /*3:*/ #line 56 "./sat-oss.w" while(1){ i= getc(stdin);ungetc(i,stdin); if(i!='~')break; fgets(buf,bufsize,stdin); printf("%s", buf); } for(i= 0;i<m;i++){ for(j= 0;j<n;j++){ if(fscanf(stdin,"%d",&w[i][j])!=1){ fprintf(stderr,"Oops, I had trouble reading w%d%d!\n",i,j); exit(-4); } if(w[i][j]<0||w[i][j]> t){ fprintf(stderr,"Oops, w%d%d should be between 0 and %d, not %d!\n", i,j,t,w[i][j]); exit(-5); } } } for(i= 0;i<m;i++){ for(k= 0,j= 0;j<n;j++)k+= w[i][j]; if(k> t){ fprintf(stderr,"Unsatisfiable (machine %d needs %d)!\n",i,k); exit(-10); } } for(j= 0;j<n;j++){ for(k= 0,i= 0;i<m;i++)k+= w[i][j]; if(k> t){ fprintf(stderr,"Unsatisfiable (job %d needs %d)!\n",j,k); exit(-11); } } printf("~ sat-oss %d %d %d\n",m,n,t); for(i= 0;i<m;i++){ printf("~ "); for(j= 0;j<n;j++)printf("%4d",w[i][j]); printf("\n"); } /*:3*/ #line 32 "./sat-oss.w" ; /*4:*/ #line 102 "./sat-oss.w" for(i= 0;i<m;i++)for(j= 0;j<n;j++)if(w[i][j]) for(l= 1;l<t-w[i][j];l++) printf("~%c%c<%d %c%c<%d\n",'0'+i,'0'+j,l,'0'+i,'0'+j,l+1); /*:4*/ #line 33 "./sat-oss.w" ; /*5:*/ #line 107 "./sat-oss.w" for(i= 0;i<m;i++)for(j= 0;j<n;j++)if(w[i][j]){ for(ii= 0;ii<m;ii++)for(jj= 0;jj<n;jj++) if(((ii==i&&jj!=j)||(ii!=i&&jj==j))&&w[ii][jj]){ for(l= 0;l+w[i][j]<=t+1-w[ii][jj];l++){ if(i<ii||j<jj)printf("~!%c%c%c%c",'0'+i,'0'+j,'0'+ii,'0'+jj); else printf("!%c%c%c%c",'0'+ii,'0'+jj,'0'+i,'0'+j); if(l> 0)printf(" %c%c<%d",'0'+i,'0'+j,l); if(l+w[i][j]<t+1-w[ii][jj])printf(" ~%c%c<%d",'0'+ii,'0'+jj,l+w[i][j]); printf("\n"); } } } /*:5*/ #line 34 "./sat-oss.w" ; } /*:1*/
the_stack_data/198581253.c
/* { dg-options "-O2 -fdump-tree-ivopts -fkeep-gc-roots-live" } */ /* Only integer ivopts here when using -fkeep-gc-roots-live. */ void foo (char *pstart, int n) { char *p; char *pend = pstart + n; for (p = pstart; p < pend; p++) *p = 1; } void foo1 (char *pstart, int n) { char *p; char *pend = pstart + n; for (p = pstart; p != pend; p++) *p = 1; } /* { dg-final { scan-tree-dump-times "ivtmp.\[0-9_\]* = PHI <\[^0\]\[^,\]*, \[^0\]" 0 "ivopts"} } */
the_stack_data/182952028.c
#include "stdio.h" long long x = 1; long long y = 2; long long r; int main() { if (x > y) { r = x; } printf("%d\n", r); return 0; }
the_stack_data/22614.c
/* select_client.c */ #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <string.h> #include <netdb.h> #include <sys/types.h> #include <netinet/in.h> #include <sys/socket.h> #include <arpa/inet.h> #include <unistd.h> #define PORT 3490 /* 서버 포트 */ #define MAXDATASIZE 100 int main(int argc, char *argv[]) { int csock, numbytes; char buf[MAXDATASIZE]; struct sockaddr_in serv_addr; int len; if (argc != 3) { fprintf(stderr, "usage: tcp_client <SERVER IP> <ECHO STRING>\n"); exit(1); } /* 클라이언트 소켓 생성 */ if ((csock = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); exit(1); } /* 서버 주소 설정 */ memset(&serv_addr, 0, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = inet_addr(argv[1]); serv_addr.sin_port = htons(PORT); /* 서버 연결 */ if (connect(csock, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr )) == -1) { perror ("connect"); exit (1); } /* 메시지 송수신 */ memset(buf, 0, MAXDATASIZE); strcpy(buf, argv[2]); len = strlen(buf); if (send(csock, buf, len, 0) != len) { fprintf(stderr, "send failed... \n"); exit (1); } memset(buf, 0, MAXDATASIZE); if ((numbytes = recv(csock, buf, MAXDATASIZE, 0)) == -1) { perror ("recv"); exit (1); } sprintf(buf, "Hello, server\n"); if ((numbytes=send (csock, buf, MAXDATASIZE, 0)) == -1) { perror("send"); exit(1); } if((numbytes=recv (csock, buf, MAXDATASIZE, 0)) == -1) { perror("recv"); exit(1); } buf[numbytes] = '\0'; printf("Received: %s\n", buf); close(csock); return 0; }
the_stack_data/181393118.c
/********************************************************************** * * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful but, except * as otherwise stated in writing, without any warranty; without even the * implied warranty of merchantability or fitness for a particular purpose. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. * * The full GNU General Public License is included in this distribution in * the file called "COPYING". * * Contact Information: * Imagination Technologies Ltd. <[email protected]> * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK * ******************************************************************************/ #ifndef MEM_DEBUG_C #define MEM_DEBUG_C #if defined(PVRSRV_DEBUG_OS_MEMORY) #include "img_types.h" #include "services_headers.h" #if defined (__cplusplus) extern "C" { #endif #define STOP_ON_ERROR 0 IMG_BOOL MemCheck(const IMG_PVOID pvAddr, const IMG_UINT8 ui8Pattern, IMG_SIZE_T uSize) { IMG_UINT8 *pui8Addr; for (pui8Addr = (IMG_UINT8*)pvAddr; uSize > 0; uSize--, pui8Addr++) { if (*pui8Addr != ui8Pattern) { return IMG_FALSE; } } return IMG_TRUE; } IMG_VOID OSCheckMemDebug(IMG_PVOID pvCpuVAddr, IMG_SIZE_T uSize, const IMG_CHAR *pszFileName, const IMG_UINT32 uLine) { OSMEM_DEBUG_INFO const *psInfo = (OSMEM_DEBUG_INFO *)((IMG_UINT32)pvCpuVAddr - TEST_BUFFER_PADDING_STATUS); if (pvCpuVAddr == IMG_NULL) { PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%X : null pointer" " - referenced %s:%d - allocated %s:%d", pvCpuVAddr, pszFileName, uLine, psInfo->sFileName, psInfo->uLineNo)); while (STOP_ON_ERROR); } if (((IMG_UINT32)pvCpuVAddr&3) != 0) { PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%X : invalid alignment" " - referenced %s:%d - allocated %s:%d", pvCpuVAddr, pszFileName, uLine, psInfo->sFileName, psInfo->uLineNo)); while (STOP_ON_ERROR); } if (!MemCheck((IMG_PVOID)psInfo->sGuardRegionBefore, 0xB1, sizeof(psInfo->sGuardRegionBefore))) { PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%X : guard region before overwritten" " - referenced %s:%d - allocated %s:%d", pvCpuVAddr, pszFileName, uLine, psInfo->sFileName, psInfo->uLineNo)); while (STOP_ON_ERROR); } if (uSize != psInfo->uSize) { PVR_DPF((PVR_DBG_WARNING, "Pointer 0x%X : supplied size was different to stored size (0x%X != 0x%X)" " - referenced %s:%d - allocated %s:%d", pvCpuVAddr, uSize, psInfo->uSize, pszFileName, uLine, psInfo->sFileName, psInfo->uLineNo)); while (STOP_ON_ERROR); } if ((0x01234567 ^ psInfo->uSizeParityCheck) != psInfo->uSize) { PVR_DPF((PVR_DBG_WARNING, "Pointer 0x%X : stored size parity error (0x%X != 0x%X)" " - referenced %s:%d - allocated %s:%d", pvCpuVAddr, psInfo->uSize, 0x01234567 ^ psInfo->uSizeParityCheck, pszFileName, uLine, psInfo->sFileName, psInfo->uLineNo)); while (STOP_ON_ERROR); } else { uSize = psInfo->uSize; } if (uSize) { if (!MemCheck((IMG_VOID*)((IMG_UINT32)pvCpuVAddr + uSize), 0xB2, TEST_BUFFER_PADDING_AFTER)) { PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%X : guard region after overwritten" " - referenced from %s:%d - allocated from %s:%d", pvCpuVAddr, pszFileName, uLine, psInfo->sFileName, psInfo->uLineNo)); } } if (psInfo->eValid != isAllocated) { PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%X : not allocated (freed? %d)" " - referenced %s:%d - freed %s:%d", pvCpuVAddr, psInfo->eValid == isFree, pszFileName, uLine, psInfo->sFileName, psInfo->uLineNo)); while (STOP_ON_ERROR); } } IMG_VOID debug_strcpy(IMG_CHAR *pDest, const IMG_CHAR *pSrc) { IMG_SIZE_T i = 0; for (; i < 128; i++) { *pDest = *pSrc; if (*pSrc == '\0') break; pDest++; pSrc++; } } PVRSRV_ERROR OSAllocMem_Debug_Wrapper(IMG_UINT32 ui32Flags, IMG_UINT32 ui32Size, IMG_PVOID *ppvCpuVAddr, IMG_HANDLE *phBlockAlloc, IMG_CHAR *pszFilename, IMG_UINT32 ui32Line) { OSMEM_DEBUG_INFO *psInfo; PVRSRV_ERROR eError; eError = OSAllocMem_Debug_Linux_Memory_Allocations(ui32Flags, ui32Size + TEST_BUFFER_PADDING, ppvCpuVAddr, phBlockAlloc, pszFilename, ui32Line); if (eError != PVRSRV_OK) { return eError; } OSMemSet((IMG_CHAR *)(*ppvCpuVAddr) + TEST_BUFFER_PADDING_STATUS, 0xBB, ui32Size); OSMemSet((IMG_CHAR *)(*ppvCpuVAddr) + ui32Size + TEST_BUFFER_PADDING_STATUS, 0xB2, TEST_BUFFER_PADDING_AFTER); psInfo = (OSMEM_DEBUG_INFO *)(*ppvCpuVAddr); OSMemSet(psInfo->sGuardRegionBefore, 0xB1, sizeof(psInfo->sGuardRegionBefore)); debug_strcpy(psInfo->sFileName, pszFilename); psInfo->uLineNo = ui32Line; psInfo->eValid = isAllocated; psInfo->uSize = ui32Size; psInfo->uSizeParityCheck = 0x01234567 ^ ui32Size; *ppvCpuVAddr = (IMG_PVOID) ((IMG_UINT32)*ppvCpuVAddr)+TEST_BUFFER_PADDING_STATUS; #ifdef PVRSRV_LOG_MEMORY_ALLOCS PVR_TRACE(("Allocated pointer (after debug info): 0x%X from %s:%d", *ppvCpuVAddr, pszFilename, ui32Line)); #endif return PVRSRV_OK; } PVRSRV_ERROR OSFreeMem_Debug_Wrapper(IMG_UINT32 ui32Flags, IMG_UINT32 ui32Size, IMG_PVOID pvCpuVAddr, IMG_HANDLE hBlockAlloc, IMG_CHAR *pszFilename, IMG_UINT32 ui32Line) { OSMEM_DEBUG_INFO *psInfo; OSCheckMemDebug(pvCpuVAddr, ui32Size, pszFilename, ui32Line); OSMemSet(pvCpuVAddr, 0xBF, ui32Size + TEST_BUFFER_PADDING_AFTER); psInfo = (OSMEM_DEBUG_INFO *)((IMG_UINT32) pvCpuVAddr - TEST_BUFFER_PADDING_STATUS); psInfo->uSize = 0; psInfo->uSizeParityCheck = 0; psInfo->eValid = isFree; psInfo->uLineNo = ui32Line; debug_strcpy(psInfo->sFileName, pszFilename); return OSFreeMem_Debug_Linux_Memory_Allocations(ui32Flags, ui32Size + TEST_BUFFER_PADDING, psInfo, hBlockAlloc, pszFilename, ui32Line); } #if defined (__cplusplus) } #endif #endif #endif
the_stack_data/218893848.c
/* * Copyright (C) 2019-2021 Intel Corporation. * SPDX-License-Identifier: MIT */ #include <string.h> #include <stdio.h> int main(int argc, char* argv[]) { if (argc != 4) { fprintf(stderr, "Usage: <arg> \"\" <arg2>\n"); return 1; } if (strlen(argv[1]) == 0 || strlen(argv[2]) != 0 || strlen(argv[3]) == 0) { fprintf(stderr, "Usage: <arg> \"\" <arg2>"); return 1; } printf("ok\n"); return 0; }
the_stack_data/134161.c
/* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ struct data { int flag; }; static struct data d; int f(int x) { struct data* p = x ? &d : 0; return (p && p->flag); } int f_error(int x) { struct data* p = x ? &d : 0; return p->flag && p; // NULL_DEREF } int g(int x) { struct data* p = x ? &d : 0; return !(p && p->flag); // OK } int h(int x) { struct data* p = x ? &d : 0; return !(p && p->flag); // OK } int g_error(int x) { struct data* p = x ? &d : 0; return !(p->flag && p); // NULL_DEREF } int k(int x) { struct data* p = x ? &d : 0; return !(p && p->flag); // OK } int l(int x) { struct data* p = x ? &d : 0; return !p || p->flag; // OK } int l_error(int x) { struct data* p = x ? &d : 0; return p || p->flag; // NULL_DEREF } int m(int x) { struct data* p = x ? &d : 0; return (!p || p->flag) && !(p && p->flag); ; // OK } int n(int x) { struct data* p = x ? &d : 0; return p && (p->flag || !(p->flag)); // OK }
the_stack_data/113627.c
#include <stdio.h> #include <string.h> int main(void) { // your code goes here int a[5] = {-9, 10, -11, 12, -15}; int len =5; int previousMax = a[0], currentMax = a[0], i; for(i = 1; i< len; i++) { if(currentMax + a[i] > currentMax) { currentMax = currentMax + a[i]; if(a[i] > currentMax) { currentMax = a[i]; } } else { if(previousMax < currentMax) { previousMax = currentMax; } currentMax = a[i]; } } if(previousMax < currentMax) { previousMax = currentMax; } printf("previousmax: %d", previousMax); return 1; }
the_stack_data/176705964.c
/* $title: 'DLLSUBS.C ===== Try out DLLs in OS/2 =====' */ /* $subtitle: 'Elipse Ltd. [jms] Revised: 1995 May 06' */ #include <stdio.h> #include <string.h> void dll_init( void ); void dll_get( char *buf, int len ); void dll_put( const char *buf ); static char string[2048]; /* DLL_INIT ===== Initialization ===== $pageif:6 */ void dll_init( void ) { /* dll_init */ memset( string, '\0', sizeof( string ) ); } /* dll_init */ /* DLL_PUT ===== Save string ===== $pageif:6 */ void dll_put( const char *buf ) { /* dll_put */ strncpy( string, buf, sizeof( string ) ); } /* dll_put */ /* DLL_GET ===== Return string ===== $pageif:6 */ void dll_get( char *buf, int len ) { /* dll_get */ strncpy( buf, string, len ); } /* dll_get */
the_stack_data/45449286.c
/* ** my_putstr.c for in /home/habi/Piscine1/C/Jour03/my_putstr ** ** Made by HABI Acal ** Login <[email protected]> ** ** Started on Wed Sep 27 09:47:18 2017 HABI Acal ** Last update Wed Sep 27 09:47:21 2017 HABI Acal */ void my_putchar(char c); void my_putstr(char *str) { int i; i = 0; while (*(str + i) != '\0') { my_putchar(*(str + i)); ++i; } }
the_stack_data/820235.c
/* ############### c-color-names License MIT License Copyright (c) 2022 Abhishek Mishra <https://github.com/abhishekmishra> 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. ############### color-names License MIT License Copyright (c) 2017 David Aerne Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include <ctype.h> #define COLOR_NAMES_DIST_CSV_FILE "color-names/dist/colornames.bestof.csv" #define COLOR_NAMES_FILE_HAS_HEADER 1 #define COLOR_HEX_LEN 7 #define COLOR_NAMES_TEMPLATE_FNAME "color_names.template.c" #define COLOR_NAMES_C_FNAME "color_names.c" #define COLOR_NAMES_TEMPLATE_MARKER_BEGIN "// generated color names begin" #define COLOR_NAMES_TEMPLATE_MARKER_END "// generated color names end" #define MAX_TEMPLATE_LINE_LEN 1024 typedef enum { COLOR_NAMES = 1, COLOR_HEX_STR, COLOR_HEX_NUM } out_col_t; int csv_counts(size_t *rows, size_t *maxlen_colorname); void color_hex_to_triple(char *hex, uint8_t *r, uint8_t *g, uint8_t *b); int csv_color_names_write(FILE *c_file, size_t total_rows, out_col_t type); int write_color_names_c_program(); int main(int argc, char *argv[]) { int res = write_color_names_c_program(); return res; } int csv_counts(size_t *rows, size_t *maxlen_colorname) { FILE *color_names_file; size_t col = 0, col_len = 0; *rows = 0; *maxlen_colorname = 0; color_names_file = fopen(COLOR_NAMES_DIST_CSV_FILE, "r"); if (color_names_file == NULL) { printf("FATAL: unable to open colornames file at %s!" "Have you checked out the submodule?\n", COLOR_NAMES_DIST_CSV_FILE); return 1; } else { int prev = 0, c = 0; while ((c = getc(color_names_file)) != EOF) { // putchar(c); if (c == '\n') { *rows += 1; col = 0; col_len = 0; } else if (c == ',') { // if the first column (color name column is ending) // check if its length is greater than the largest yet. if (col == 0) { if (col_len > *maxlen_colorname) { *maxlen_colorname = col_len; } } col += 1; col_len = 0; } else { col_len += 1; } prev = c; } if (prev != 0) { *rows += 1; } fclose(color_names_file); } // account for the header row if (*rows > 0) { *rows -= 1; } return 0; } // int count = 0; uint8_t getNumFromHexStr(char *inp) { // if (count < 3) // { // printf("%s = %d, %hu\n", inp, strtoul(inp, NULL, 16), (uint8_t)strtoul(inp, NULL, 16)); // } return (uint8_t)strtoul(inp, NULL, 16); } void color_hex_to_triple(char *hex, uint8_t *r, uint8_t *g, uint8_t *b) { char rstr[3], gstr[3], bstr[3]; rstr[0] = hex[1]; rstr[1] = hex[2]; gstr[0] = hex[3]; gstr[1] = hex[4]; bstr[0] = hex[5]; bstr[1] = hex[6]; rstr[2] = '\0'; gstr[2] = '\0'; bstr[2] = '\0'; *r = getNumFromHexStr(rstr); *g = getNumFromHexStr(gstr); *b = getNumFromHexStr(bstr); // if (count < 3) // { // printf("%s -> [%hu, %hu, %hu]\n", // hex, r, g, b); // count += 1; // } } int csv_color_names_write(FILE *c_file, size_t total_rows, out_col_t type) { FILE *color_names_file; size_t col = 0, col_len = 0; size_t rows = 0; color_names_file = fopen(COLOR_NAMES_DIST_CSV_FILE, "r"); if (color_names_file == NULL) { printf("FATAL: unable to open colornames file at %s!" "Have you checked out the submodule?\n", COLOR_NAMES_DIST_CSV_FILE); return 1; } else { int c; char colval[1024]; memset(colval, 0, 1024); uint8_t r, g, b; while ((c = getc(color_names_file)) != EOF) { // putchar(c); if (c == '\n') { // if the second column if (col == 1) { if (type == COLOR_HEX_STR && rows > 0) { fprintf(c_file, "\"%s\"%s\n", colval, (rows != total_rows) ? "," : ""); } if (type == COLOR_HEX_NUM && rows > 0) { color_hex_to_triple(colval, &r, &g, &b); fprintf(c_file, "{%hu, %hu, %hu}%s\n", r, g, b, (rows != total_rows) ? "," : ""); } } rows += 1; col = 0; col_len = 0; memset(colval, 0, 1024); } else if (c == ',') { // if the first column if (col == 0) { if (type == COLOR_NAMES && rows > 0) { for(int i = 0; i < strlen(colval); i++){ colval[i] = tolower(colval[i]); } fprintf(c_file, "\"%s\"%s\n", colval, (rows != total_rows) ? "," : ""); } } col += 1; col_len = 0; memset(colval, 0, 1024); } else { colval[col_len] = c; col_len += 1; } } // if the second column if (col == 1) { if (type == COLOR_HEX_STR && rows > 0) { fprintf(c_file, "\"%s\"%s\n", colval, (rows != total_rows) ? "," : ""); } if (type == COLOR_HEX_NUM && rows > 0) { color_hex_to_triple(colval, &r, &g, &b); fprintf(c_file, "{%hu, %hu, %hu}%s\n", r, g, b, (rows != total_rows) ? "," : ""); } } fclose(color_names_file); } return 0; } int write_color_names_c_program() { int res; size_t rows, maxlen_colorname; FILE *template_file, *c_file; // Step 1: get the row count and max color name length res = csv_counts(&rows, &maxlen_colorname); if (res == 0) { printf("Num rows (excluding header) = %zd, longest color name length = %zd.\n", rows, maxlen_colorname); } else { printf("FATAL: error processing color names csv file.\n"); return res; } // Step 2: open template file for reading template_file = fopen(COLOR_NAMES_TEMPLATE_FNAME, "r"); if (template_file == NULL) { printf("FATAL: unable to open template file at %s!\n", COLOR_NAMES_TEMPLATE_FNAME); return 1; } // open c file for writing c_file = fopen(COLOR_NAMES_C_FNAME, "w"); if (c_file == NULL) { printf("FATAL: unable to open c file at %s for writing!\n", COLOR_NAMES_C_FNAME); return 1; } char line[MAX_TEMPLATE_LINE_LEN + 1]; memset(line, 0, MAX_TEMPLATE_LINE_LEN + 1); size_t line_count = 0, line_pos = 0; int c, in_gen_region = 0, wrote_colors = 0; while ((c = getc(template_file)) != EOF) { // putchar(c); if (c == '\n' || c == '\r') { if (strcmp(line, COLOR_NAMES_TEMPLATE_MARKER_END) == 0) { printf("MARKER END\n"); in_gen_region = 0; } if (in_gen_region == 0) { printf("%3zd: %s\n", line_count, line); fprintf(c_file, "%s\n", line); } else { if (wrote_colors == 0) { fprintf(c_file, "#define NUM_COLORS\t%zd\n\n", rows); fprintf(c_file, "static const char COLOR_NAMES[%zd][%zd] = {\n", rows, maxlen_colorname + 1); csv_color_names_write(c_file, rows, COLOR_NAMES); fprintf(c_file, "};\n\n"); fprintf(c_file, "static const char COLOR_RGB_HEXSTR[%zd][%d] = {\n", rows, COLOR_HEX_LEN + 1); csv_color_names_write(c_file, rows, COLOR_HEX_STR); fprintf(c_file, "};\n\n"); fprintf(c_file, "static const char COLOR_RGB_TRIPLE[%zd][3] = {\n", rows); csv_color_names_write(c_file, rows, COLOR_HEX_NUM); fprintf(c_file, "};\n\n"); wrote_colors = 1; } } if (strcmp(line, COLOR_NAMES_TEMPLATE_MARKER_BEGIN) == 0) { printf("MARKER BEGIN\n"); in_gen_region = 1; } line_count += 1; memset(line, 0, MAX_TEMPLATE_LINE_LEN + 1); line_pos = 0; } else { line[line_pos] = c; line_pos += 1; if (line_pos > (MAX_TEMPLATE_LINE_LEN + 1)) { printf("Fatal: no more space in buffer!\n"); return 2; } } } // handle the last line if there was no newline printf("%3zd: %s\n", line_count, line); if (in_gen_region == 0) { fprintf(c_file, "%s\n", line); } fclose(c_file); fclose(template_file); return 0; }
the_stack_data/75138759.c
/*===-- timeit.c - LLVM Test Suite Timing Tool ------------------*- C++ -*-===*\ |* *| |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| |* Exceptions. *| |* See https://llvm.org/LICENSE.txt for license information. *| |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| |* *| \*===----------------------------------------------------------------------===*/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <signal.h> #include <unistd.h> #include <sys/resource.h> #include <sys/time.h> #include <sys/wait.h> /* Enumeration for our exit status codes. */ enum ExitCode { /* \brief Indicates a failure monitoring the target. */ EXITCODE_MONITORING_FAILURE = 66, /* \brief Indicates a failure in exec() which usually means an invalid program * name. */ EXITCODE_EXEC_FAILURE = 67, EXITCODE_EXEC_NOENTRY = 127, EXITCODE_EXEC_NOPERMISSION = 126, /* \brief Indicates that we were unexpectedly signalled(). */ EXITCODE_SIGNALLED = 68, /* \brief Indicates the child was signalled. */ EXITCODE_CHILD_SIGNALLED = 69 }; /* \brief Record our own program name, for error messages. */ static const char *g_program_name = 0; /* \brief Record the child command name, for error messages. */ static const char *g_target_program = 0; /* \brief If given, report output in POSIX mode format. */ static int g_posix_mode = 0; /* \brief If non-zero, execute the program with a timeout of the given number * of seconds. */ static int g_timeout_in_seconds = 0; /* \brief If non-zero, the PID of the process being monitored. */ static pid_t g_monitored_pid = 0; /* \brief If non-zero, the path to attempt to chdir() to before executing the * target. */ static const char *g_target_exec_directory = 0; /* \brief If non-zero, the path to write the summary information to (exit status * and timing). */ static const char *g_summary_file = 0; /* \brief If non-zero, the path to redirect the target standard input to. */ static const char *g_target_redirect_input = 0; /* \brief If non-zero, the path to redirect the target stdout to. */ static const char *g_target_redirect_stdout = 0; /* \brief If non-zero, the path to redirect the target stderr to. */ static const char *g_target_redirect_stderr = 0; /* \brief If non-zero, append exit status at end of output file. */ static int g_append_exitstats = 0; /* @name Resource Limit Variables */ /* @{ */ /* \brief If non-sentinel, the CPU time limit to set for the target. */ static rlim_t g_target_cpu_limit = ~(rlim_t) 0; /* \brief If non-sentinel, the stack size limit to set for the target. */ static rlim_t g_target_stack_size_limit = ~(rlim_t) 0; /* \brief If non-sentinel, the data size limit to set for the target. */ static rlim_t g_target_data_size_limit = ~(rlim_t) 0; /* \brief If non-sentinel, the RSS size limit to set for the target. */ static rlim_t g_target_rss_size_limit = ~(rlim_t) 0; /* \brief If non-sentinel, the file size limit to set for the target. */ static rlim_t g_target_file_size_limit = ~(rlim_t) 0; /* \brief If non-sentinel, the core limit to set for the target. */ static rlim_t g_target_core_limit = ~(rlim_t) 0; /* \brief If non-sentinel, the file count limit to set for the target. */ static rlim_t g_target_file_count_limit = ~(rlim_t) 0; /* \brief If non-sentinel, the subprocess count limit to set for the target. */ static rlim_t g_target_subprocess_count_limit = ~(rlim_t) 0; /* @} */ static double sample_wall_time(void) { struct timeval t; gettimeofday(&t, NULL); return (double) t.tv_sec + t.tv_usec * 1.e-6; } static void terminate_handler(int signal) { /* If we are monitoring a process, kill its process group and assume we will * complete normally. */ if (g_monitored_pid) { fprintf(stderr, ("%s: error: received signal %d. " "killing monitored process(es): %s\n"), g_program_name, signal, g_target_program); /* Kill the process group of monitored_pid. */ kill(-g_monitored_pid, SIGKILL); return; } fprintf(stderr, "%s: error: received signal %d. exiting.\n", g_program_name, signal); /* Otherwise, we received a signal we should treat as for ourselves, and exit * quickly. */ _exit(EXITCODE_SIGNALLED); } static void timeout_handler(int signal) { (void)signal; fprintf(stderr, "%s: TIMING OUT PROCESS: %s\n", g_program_name, g_target_program); /* We should always be monitoring a process when we receive an alarm. Kill its * process group and assume we will terminate normally. */ kill(-g_monitored_pid, SIGKILL); } static int monitor_child_process(pid_t pid, double start_time) { double real_time, user_time, sys_time; struct rusage usage; int res, status; /* Record the PID we are monitoring, for use in the signal handlers. */ g_monitored_pid = pid; /* If we are running with a timeout, set up an alarm now. */ if (g_timeout_in_seconds) { sigset_t masked; sigemptyset(&masked); sigaddset(&masked, SIGALRM); alarm(g_timeout_in_seconds); } /* Wait for the process to terminate. */ do { res = waitpid(pid, &status, 0); } while (res < 0 && errno == EINTR); if (res < 0) { perror("waitpid"); return EXITCODE_MONITORING_FAILURE; } /* Record the real elapsed time as soon as we can. */ real_time = sample_wall_time() - start_time; /* Just in case, kill the child process group. */ kill(-pid, SIGKILL); /* Collect the other resource data on the children. */ if (getrusage(RUSAGE_CHILDREN, &usage) < 0) { perror("getrusage"); return EXITCODE_MONITORING_FAILURE; } user_time = (double) usage.ru_utime.tv_sec + usage.ru_utime.tv_usec/1000000.0; sys_time = (double) usage.ru_stime.tv_sec + usage.ru_stime.tv_usec/1000000.0; /* If the process was signalled, report a more interesting status. */ int exit_status; if (WIFSIGNALED(status)) { fprintf(stderr, "%s: error: child terminated by signal %d\n", g_program_name, WTERMSIG(status)); /* Propagate the signalled status to the caller. */ exit_status = 128 + WTERMSIG(status); } else if (WIFEXITED(status)) { exit_status = WEXITSTATUS(status); } else { /* This should never happen, but if it does assume some kind of failure. */ exit_status = EXITCODE_MONITORING_FAILURE; } // If we are not using a summary file, report the information as /usr/bin/time // would. if (!g_summary_file) { if (g_posix_mode) { fprintf(stderr, "real %12.4f\nuser %12.4f\nsys %12.4f\n", real_time, user_time, sys_time); } else { fprintf(stderr, "%12.4f real %12.4f user %12.4f sys\n", real_time, user_time, sys_time); } } else { /* Otherwise, write the summary data in a simple parsable format. */ FILE *fp = fopen(g_summary_file, "w"); if (!fp) { perror("fopen"); return EXITCODE_MONITORING_FAILURE; } fprintf(fp, "exit %d\n", exit_status); fprintf(fp, "%-10s %.4f\n", "real", real_time); fprintf(fp, "%-10s %.4f\n", "user", user_time); fprintf(fp, "%-10s %.4f\n", "sys", sys_time); fclose(fp); } if (g_append_exitstats && g_target_program) { FILE *fp_stdout = fopen(g_target_redirect_stdout, "a"); if (!fp_stdout) { perror("fopen"); return EXITCODE_MONITORING_FAILURE; } fprintf(fp_stdout, "exit %d\n", exit_status); fclose(fp_stdout); /* let timeit itself report success */ exit_status = 0; } return exit_status; } #define set_resource_limit(resource, value) \ set_resource_limit_actual(#resource, resource, value) static void set_resource_limit_actual(const char *resource_name, int resource, rlim_t value) { /* Get the current limit. */ struct rlimit current; getrlimit(resource, &current); /* Set the limits to as close as requested, assuming we are not super-user. */ struct rlimit requested; requested.rlim_cur = requested.rlim_max = \ (value < current.rlim_max) ? value : current.rlim_max; if (setrlimit(resource, &requested) < 0) { fprintf(stderr, "%s: warning: unable to set limit for %s (to {%lu, %lu})\n", g_program_name, resource_name, (unsigned long) requested.rlim_cur, (unsigned long) requested.rlim_max); } } static int streq(const char *a, const char *b) { return strcmp(a, b) == 0; } static int execute_target_process(char * const argv[]) { /* Create a new process group for pid, and the process tree it may spawn. We * do this, because later on we might want to kill pid _and_ all processes * spawned by it and its descendants. */ setpgid(0, 0); /* Redirect the standard input, if requested. */ if (g_target_redirect_input) { FILE *fp = fopen(g_target_redirect_input, "r"); if (!fp) { perror("fopen"); return EXITCODE_MONITORING_FAILURE; } int fd = fileno(fp); if (dup2(fd, 0) < 0) { perror("dup2"); return EXITCODE_MONITORING_FAILURE; } fclose(fp); } /* Redirect the standard output, if requested. */ FILE *fp_stdout = NULL; if (g_target_redirect_stdout) { fp_stdout = fopen(g_target_redirect_stdout, "w"); if (!fp_stdout) { perror("fopen"); return EXITCODE_MONITORING_FAILURE; } int fd = fileno(fp_stdout); if (dup2(fd, STDOUT_FILENO) < 0) { perror("dup2"); return EXITCODE_MONITORING_FAILURE; } } if (g_target_redirect_stderr) { FILE *fp_stderr = NULL; int fd; if (streq(g_target_redirect_stdout, g_target_redirect_stderr)) fd = fileno(fp_stdout); else { fp_stderr = fopen(g_target_redirect_stderr, "w"); if (!fp_stderr) { perror("fopen"); return EXITCODE_MONITORING_FAILURE; } fd = fileno(fp_stderr); } if (dup2(fd, STDERR_FILENO) < 0) { perror("dup2"); return EXITCODE_MONITORING_FAILURE; } if (fp_stderr != NULL) fclose(fp_stderr); } if (fp_stdout != NULL) fclose(fp_stdout); /* Honor any requested resource limits. */ if (g_target_cpu_limit != ~(rlim_t) 0) { set_resource_limit(RLIMIT_CPU, g_target_cpu_limit); } if (g_target_stack_size_limit != ~(rlim_t) 0) { set_resource_limit(RLIMIT_STACK, g_target_stack_size_limit); } if (g_target_data_size_limit != ~(rlim_t) 0) { set_resource_limit(RLIMIT_DATA, g_target_data_size_limit); } #if !defined(__APPLE__) // On Apple platforms, RLIMIT_RSS is mapped to RLIMIT_AS and setting RLIMIT_AS // to a value smaller than the current virtual memory size will fail, This is // incompatible with the current usage in timeit and can cause issues on // platforms enforcing strict virtual memory size limits. Ignore RLIMIT_RSS on // Apple platforms for now. if (g_target_rss_size_limit != ~(rlim_t) 0) { set_resource_limit(RLIMIT_RSS, g_target_rss_size_limit); } #endif if (g_target_file_size_limit != ~(rlim_t) 0) { set_resource_limit(RLIMIT_FSIZE, g_target_file_size_limit); } if (g_target_core_limit != ~(rlim_t) 0) { set_resource_limit(RLIMIT_CORE, g_target_core_limit); } if (g_target_file_count_limit != ~(rlim_t) 0) { set_resource_limit(RLIMIT_NOFILE, g_target_file_count_limit); } if (g_target_subprocess_count_limit != ~(rlim_t) 0) { set_resource_limit(RLIMIT_NPROC, g_target_subprocess_count_limit); } /* Honor the desired target execute directory. */ if (g_target_exec_directory) { if (chdir(g_target_exec_directory) < 0) { perror("chdir"); return EXITCODE_MONITORING_FAILURE; } } execvp(argv[0], argv); perror("execv"); if (errno == ENOENT) { return EXITCODE_EXEC_NOENTRY; } else if (errno == EACCES) { return EXITCODE_EXEC_NOPERMISSION; } return EXITCODE_EXEC_FAILURE; } static int execute(char * const argv[]) { double start_time; pid_t pid; /* Set up signal handlers so we can terminate the monitored process(es) on * SIGINT or SIGTERM. */ signal(SIGINT, terminate_handler); signal(SIGTERM, terminate_handler); /* Set up a signal handler to terminate the process on timeout. */ signal(SIGALRM, timeout_handler); start_time = sample_wall_time(); /* Fork the child process. */ pid = fork(); if (pid < 0) { perror("fork"); return EXITCODE_MONITORING_FAILURE; } /* If we are in the context of the child process, spawn it. */ if (pid == 0) { /* Setup and execute the target process. This never returns except on * failure. */ return execute_target_process(argv); } /* Otherwise, we are in the context of the monitoring process. */ return monitor_child_process(pid, start_time); } static void usage(int is_error) { #define WRAPPED "\n " fprintf(stderr, "usage: %s [options] command ... arguments ...\n", g_program_name); fprintf(stderr, "Options:\n"); fprintf(stderr, " %-20s %s", "-h, --help", "Show this help text.\n"); fprintf(stderr, " %-20s %s", "-p, --posix", "Report time in /usr/bin/time POSIX format.\n"); fprintf(stderr, " %-20s %s", "-t, --timeout <N>", "Execute the subprocess with a timeout of N seconds.\n"); fprintf(stderr, " %-20s %s", "-c, --chdir <PATH>", "Execute the subprocess in the given working directory.\n"); fprintf(stderr, " %-20s %s", "--summary <PATH>", "Write monitored process summary (exit code and time) to PATH.\n"); fprintf(stderr, " %-20s %s", "--redirect-output <PATH>", WRAPPED "Redirect stdout and stderr for the target to PATH.\n"); fprintf(stderr, " %-20s %s", "--redirect-stdout <PATH>", WRAPPED "Redirect stdout for the target to PATH.\n"); fprintf(stderr, " %-20s %s", "--redirect-stderr <PATH>", WRAPPED "Redirect stderr for the target to PATH.\n"); fprintf(stderr, " %-20s %s", "--redirect-input <PATH>", WRAPPED "Redirect stdin for the target to PATH.\n"); fprintf(stderr, " %-20s %s", "--limit-cpu <N>", WRAPPED "Limit the target to N seconds of CPU time.\n"); fprintf(stderr, " %-20s %s", "--limit-stack-size <N>", WRAPPED "Limit the target to N bytes of stack space.\n"); fprintf(stderr, " %-20s %s", "--limit-data-size <N>", WRAPPED "Limit the target to N bytes of data.\n"); fprintf(stderr, " %-20s %s", "--limit-rss-size <N>", WRAPPED "Limit the target to N bytes of resident memory.\n"); fprintf(stderr, " %-20s %s", "--limit-file-size <N>", WRAPPED "Limit the target to creating files no more than N bytes.\n"); fprintf(stderr, " %-20s %s", "--limit-core <N>", WRAPPED "Limit the size for which core files will be generated.\n"); fprintf(stderr, " %-20s %s", "--limit-file-count <N>", (WRAPPED "Limit the maximum number of open files the target can have.\n")); fprintf(stderr, " %-20s %s", "--limit-subprocess-count <N>", (WRAPPED "Limit the maximum number of simultaneous processes " "the target can use.\n")); _exit(is_error); } int main(int argc, char * const argv[]) { int i; g_program_name = argv[0]; for (i = 1; i != argc; ++i) { const char *arg = argv[i]; if (arg[0] != '-') break; if (streq(arg, "-h") || streq(arg, "--help")) { usage(/*is_error=*/0); } if (streq(arg, "-p") || streq(arg, "--posix")) { g_posix_mode = 1; continue; } if (streq(arg, "-t") || streq(arg, "--timeout")) { if (i + 1 == argc) { fprintf(stderr, "error: %s argument requires an option\n", arg); usage(/*is_error=*/1); } g_timeout_in_seconds = atoi(argv[++i]); continue; } if (streq(arg, "--summary")) { if (i + 1 == argc) { fprintf(stderr, "error: %s argument requires an option\n", arg); usage(/*is_error=*/1); } g_summary_file = argv[++i]; continue; } if (streq(arg, "--redirect-input")) { if (i + 1 == argc) { fprintf(stderr, "error: %s argument requires an option\n", arg); usage(/*is_error=*/1); } g_target_redirect_input = argv[++i]; continue; } if (streq(arg, "--redirect-output")) { if (i + 1 == argc) { fprintf(stderr, "error: %s argument requires an option\n", arg); usage(/*is_error=*/1); } g_target_redirect_stdout = argv[++i]; g_target_redirect_stderr = g_target_redirect_stdout; continue; } if (streq(arg, "--redirect-stdout")) { if (i + 1 == argc) { fprintf(stderr, "error: %s argument requires an option\n", arg); usage(/*is_error=*/1); } g_target_redirect_stdout = argv[++i]; continue; } if (streq(arg, "--redirect-stderr")) { if (i + 1 == argc) { fprintf(stderr, "error: %s argument requires an option\n", arg); usage(/*is_error=*/1); } g_target_redirect_stderr = argv[++i]; continue; } if (streq(arg, "--append-exitstatus")) { g_append_exitstats = 1; continue; } if (streq(arg, "-c") || streq(arg, "--chdir")) { if (i + 1 == argc) { fprintf(stderr, "error: %s argument requires an option\n", arg); usage(/*is_error=*/1); } g_target_exec_directory = argv[++i]; continue; } if (strncmp(arg, "--limit-", 8) == 0) { rlim_t value; if (i + 1 == argc) { fprintf(stderr, "error: %s argument requires an option\n", arg); usage(/*is_error=*/1); } value = atoi(argv[++i]); if (streq(arg, "--limit-cpu")) { g_target_cpu_limit = value; } else if (streq(arg, "--limit-stack-size")) { g_target_stack_size_limit = value; } else if (streq(arg, "--limit-data-size")) { g_target_data_size_limit = value; } else if (streq(arg, "--limit-rss-size")) { g_target_rss_size_limit = value; } else if (streq(arg, "--limit-file-size")) { g_target_file_size_limit = value; } else if (streq(arg, "--limit-core")) { g_target_core_limit = value; } else if (streq(arg, "--limit-file-count")) { g_target_file_count_limit = value; } else if (streq(arg, "--limit-subprocess-count")) { g_target_subprocess_count_limit = value; } else { fprintf(stderr, "error: invalid limit argument '%s'\n", arg); usage(/*is_error=*/1); } continue; } fprintf(stderr, "error: invalid argument '%s'\n", arg); usage(/*is_error=*/1); } if (i == argc) { fprintf(stderr, "error: no command (or arguments) was given\n"); usage(/*is_error=*/1); } g_target_program = argv[i]; return execute(&argv[i]); }
the_stack_data/759286.c
/* * Phoenix-RTOS * * libphoenix * * string/string (generic implementation of string functions) * * Copyright 2017 Phoenix Systems * Author: Pawel Pisarczyk * * This file is part of Phoenix-RTOS. * * %LICENSE% */ #include <string.h> #include <stdlib.h> char *strdup(const char *s1) { int len; char *result; len = strlen(s1) + 1; result = malloc(len); if (result) memcpy(result, s1, len); return result; } char *strndup(const char *s, size_t n) { int len; char *result; len = strlen(s); if (len > n) len = n; result = malloc(len + 1); if (result) { memcpy(result, s, len); result[len] = '\0'; } return result; }
the_stack_data/206393387.c
/* De-obfuscating the Banks flight simulator from IOCCC 1998. Not finished, I haven’t tracked down all the math though author has mentioned he used orthogonal matrices. Stdin is lists of 3d point coordinates. Each list is an object drawn connect-a-dot and terminated with 0 0 0. Z upward is negative. Compile: gcc -ansi banks.c -lm -lX11 -o banks Run: cat horizon.scene pittsburgh.scene | ./banks Get the .scene data files from the IOCCC site. http://www0.us.ioccc.org/years.html#1998 Controls: Arrow keys are the flight stick. Enter re-centers stick left-right, but not forward-back. PageUp, PageDn = throttle HUD on bottom-left: speed, heading (0 = North), altitude Math note: Angles There are 3 angles in the math. Your compass heading, your front-back tilt, and your sideways tilt = Tait-Bryan angles typical in aerospace math. Also called yaw, pitch, and roll. The Z axis is negative upward. That’s called left-handed coordinates. The rotation matrix assumes that. The rotation matrix is not shown in final form in the wiki article I cite, so let’s derive it: cx = cos(x) and so on. x=sideTilt, y=forwardTilt, z=compass 1 0 0 cy 0 -sy cz sz 0 0 cx sx * 0 1 0 * -sz cz 0 0 -sx cx sy 0 cy 0 0 1 cy 0 -sy cz sz 0 sx*sy cx sx*cy * -sz cz 0 cx*sy -sx cx*cy 0 0 1 cy*cz cy*sz -sy sx*sy*cz-cx*sz sx*sy*sz+cx*cz sx*cy cx*sy*cz+sx*sz cx*sy*sz-sx*cz cx*cy It is shown in section 2.2.1 “Euler Angles” of banks1 references wiki1 = en.wikipedia.org/wiki/Perspective_transform#Perspective_projection wiki2 = https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix banks1 = “A DISCUSSION OF METHODS OF REAL-TIME AIRPLANE FLIGHT SIMULATION” http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.510.7499&rep=rep1&type=pdf Obfuscation notes. The original program has some tricky syntax. Forms like –*(DN -N? N-DT ?N== RT?&u: & W:&h:&J ) are nested x ? y :z that return the address of a variable that gets de-referenced by the * and finally decremented. A comma like in c += (I = M / l, l * H + I * M + a * X) * _; makes a sequence of statements. The last one is the value of the (…) list. */ #include <stdio.h> #include <math.h> #include <sys/time.h> #include <X11/Xlib.h> #include <X11/keysym.h> /* Keyboard symbols we accept. Originally were -D defines on compile line. */ #define Throttle_Up XK_Page_Up #define Throttle_Down XK_Page_Down #define Up XK_Up #define Down XK_Down #define Left XK_Left #define Right XK_Right #define Enter XK_Return /* Update every 0.02 seconds. */ #define dt 0.02 /* Variables renamed from original program. _ -> timeDelta A -> gravityAccel a -> R32, a still used in another case. B -> sin_forwardTilt C -> y and integerConvert. c -> airplaneY. CS -> Enter D -> worldX_rel and cos_sideTilt and Dz, D still used for other cases. DN -> Down DT -> Throttle_Down E -> worldY_rel and sin_sideTilt, E still used for other cases. H -> R12, H still used in another case. h -> speed. I -> R22, I still used in another case. i -> airplaneZ. IT -> Throttle_Up J -> up_down. j -> forwardTiltRadians. Airplane’s front-back tilt angle in radians. 0 if plane is level, increases negative if dive or positive if climb. K -> accel and cos_forwardTilt and Dx. L -> airplaneX. l -> speedFeet. LT -> Left. m -> R11, m still used in another case. N -> prevX, N still used for other cases. n -> worldX. O -> compassRadians o -> sideTiltRadians. Airplane’s sideways tilt angle in radians. It’s 0 if plane is level, increases positive if plane spins right or negative if spin left. Keeps growing beyond 2pi if plane keeps spinning. P -> R21, P still used in another case. p -> idx and speedKnots. q -> x. r -> R23. RT -> Right s -> worldZ. T -> worldZ_rel and sin_compass, T still used for other cases. t -> R31, t still used in another case. U -> prevY. u -> left_right. UP -> Up W -> cos_compass and Dy, W still used for other cases. w -> worldY. y -> num_pts. Z -> R33. */ double airplaneX, sideTiltRadians, P, timeDelta = dt, T, Z, D = 1, d, worldZ[999], E, speed = 8, I, up_down, accel, worldY[999], M, m, compassRadians; double worldX[999], forwardTiltRadians = 33e-3, airplaneZ = 1E3, t, left_right, v, W, S = 74.5, speedFeet = 221, X = 7.26; double a, gravityAccel = 32.2 /*ft/sec^2*/, airplaneY, F, H; double cos_compass, cos_forwardTilt, cos_sideTilt = 1, Dx, Dy, Dz, R11, R12, R13, R21, R22, R23, R31, R32, R33, worldX_rel, worldY_rel, worldZ_rel, sin_compass, sin_forwardTilt, sin_sideTilt; int N, x, integerConvert, num_pts, speedKnots, idx; int prevX, prevY, y; Window win; char infoStr[52]; GC gc; main(){ /* X windows set up. */ Display *disp = XOpenDisplay(0); win = RootWindow(disp, 0); gc = XCreateGC(disp, win, 0, 0); XSetForeground(disp, gc, BlackPixel(disp, 0)); win = XCreateSimpleWindow(disp, win, 0, 0, 400, 400, 0, 0, WhitePixel(disp, 0)); XSelectInput(disp, win, KeyPressMask); XMapWindow(disp, win); /*Load map files from stdin into arrays. */ for (; scanf("%lf%lf%lf", worldX + num_pts, worldY + num_pts, worldZ + num_pts) + 1; num_pts++); /* Infinite loop, though plane can drop and ruin the calculations. */ for (;;) { /* Sleep */ /*dt is 0.02. timeval is in bits/time.h and gives secs and usecs. This becomes 0.02 * 1000000 = 20000 usecs = 0.02 seconds. Need it here to reset it since the select call wipes it out. */ struct timeval sleeptime = {0, dt * 1e6}; select(0, 0, 0, 0, &sleeptime); /* Angle calculations. */ cos_forwardTilt = cos(forwardTiltRadians); sin_forwardTilt = sin(forwardTiltRadians); cos_compass = cos(compassRadians); F += timeDelta * P; compassRadians += cos_sideTilt * timeDelta * F / cos_forwardTilt + d / cos_forwardTilt * sin_sideTilt * timeDelta; forwardTiltRadians += d * timeDelta * cos_sideTilt - timeDelta * F * sin_sideTilt; sideTiltRadians += (sin_sideTilt * d / cos_forwardTilt * sin_forwardTilt + v + sin_forwardTilt / cos_forwardTilt * F * cos_sideTilt) * timeDelta; /* Next 9 values make up a rotation matrix for a camera transform. See wiki1. */ R11 = cos_forwardTilt * cos_compass; R12 = cos_forwardTilt * sin_compass; R13 = -sin_forwardTilt; /* Original code didn’t put this in a variable. */ R21 = cos_compass * sin_sideTilt * sin_forwardTilt - sin_compass * cos_sideTilt; R22 = cos_sideTilt * cos_compass + sin_sideTilt * sin_compass * sin_forwardTilt; R23 = sin_sideTilt * cos_forwardTilt; R31 = sin_compass * sin_sideTilt + cos_sideTilt * sin_forwardTilt * cos_compass; R32 = sin_forwardTilt * sin_compass * cos_sideTilt - sin_sideTilt * cos_compass; R33 = cos_sideTilt * cos_forwardTilt; cos_sideTilt = cos(sideTiltRadians); sin_sideTilt = sin(sideTiltRadians); sin_compass = sin(compassRadians); /* Update the display. */ XClearWindow(disp, win); /*Loop over points and draw lines.*/ for (idx = 0, prevX = 1E4; idx < num_pts;) { /*The world point must be moved so the airplane is the 0,0,0 origin. Then the point must be rotated by all 3 angles. Finally the 3D point must be projected onto the 2D plane of the display. All this is the camera transform in en.wikipedia.org/wiki/Perspective_transform#Perspective_projection.*/ /*Shift world object vertex x,y,z relative to airplane as origin. The Z line uses + because airplaneZ is upward positive. It has to be negated because world Z is upward negative: worldZ – -airplaneZ = worldZ + airplaneZ. */ worldX_rel = worldX[idx] - airplaneX; worldY_rel = worldY[idx] - airplaneY; worldZ_rel = worldZ[idx] + airplaneZ; /* Apply the 3 angle rotation matrix. */ Dx = R11 * worldX_rel + R12 * worldY_rel + R13 * worldZ_rel; Dy = R21 * worldX_rel + R22 * worldY_rel + R23 * worldZ_rel; Dz = R31 * worldX_rel + R32 * worldY_rel + R33 * worldZ_rel; /* Point D is now a shifted and rotated world vertex. We are looking along the Dx axis, I think. */ /*0,0,0 signals end of an object. Dy or Dz larger than Dx means point is out of range of view (assuming a square display). */ if (worldX[idx] + worldY[idx] + worldZ[idx] == 0 || Dx < fabs(Dy) || Dx < fabs(Dz)) /* Don’t draw this point and set flag to not draw it next time through loop. */ prevX = 1e4; else { /* Project 3D point onto 2D plane to be displayed. This will make distant objects look smaller. The rotation has us looking along the Dx axis, I think. So the farther out Dx is, the smaller Dy and Dz become. The wiki1 article has Dz as the denominator. Why? Is the article wrong? This code is working. */ /* Window is 400 x 400. */ x = Dy / Dx * 4E2 + 2E2; y = Dz / Dx * 4E2 + 2E2; /* 1E4 flag prevents drawing first point since we don’t have a line until 2nd point is read. It also skips points that fall out of range of view. */ if (prevX - 1E4) /* Draw line from (prevX, prevY) to (x, y). Flickers since we’re not using double buffering. */ XDrawLine(disp, win, gc, prevX, prevY, x, y); prevX = x; prevY = y; } ++idx; } /*HUD. infoStr = 3 values: speed in knots, heading 0=N 90=E 180=S 270=W, altimeter in feet.*/ XDrawString(disp, win, gc, 20, 380, infoStr, 17); /*Get key press.*/ for (; XPending(disp);) { XEvent z; XNextEvent(disp, &z); /* Original code has nested x ? y : z forms that made an interesting puzzle. They reduce to the simple switch below. */ N = XLookupKeysym(&z.xkey, 0); switch (N) { case Up: ++up_down; break; case Left: ++left_right; break; case Throttle_Up: ++speed; break; case Right: --left_right; break; case Throttle_Down: --speed; break; case Down: --up_down; break; case Enter: left_right = 0; break; /* re-center from turning */ } } /* Airplane position and physics: gravity, no wind. */ M += H * timeDelta; I = M / speedFeet; /* Update airplane position. */ airplaneX += (R11 * speedFeet + R21 * M + R31 * X) * timeDelta; airplaneY += (R12 * speedFeet + I * M + R32 * X) * timeDelta; /* airplaneZ is positive upward, rotation matrix is negative upward Z. */ airplaneZ += (-R13 * speedFeet - R23 * M - R33 * X) * timeDelta; m = 15 * F / speedFeet; E = .1 + X * 4.9 / speedFeet; T = X * X + speedFeet * speedFeet + M * M; t = T * m / 32 - I * T / 24; H = gravityAccel * R23 + v * X - F * speedFeet + t / S; accel = F * M + (speed * 1e4 / speedFeet - (T + E * 5 * T * E) / 3e2) / S - X * d - sin_forwardTilt * gravityAccel; speedFeet += accel * timeDelta; speedKnots = speedFeet / 1.7; /*infoStr = 3 values: speed in knots, heading 0=N 90=E 180=S 270=W, altimeter in feet.*/ sprintf(infoStr, "% 5d % 3d" "% 7d", speedKnots, (integerConvert = 9E3 + compassRadians * 57.3) % 0550, (int)airplaneZ); a = 2.63 / speedFeet * d; X += (d * speedFeet - T / S * (.19 * E + a * .64 + up_down / 1e3) - M * v + gravityAccel * R33) * timeDelta; W = d; d += T * (.45 - 14 / speedFeet * X - a * 130 - up_down * .14) * timeDelta / 125e2 + F * timeDelta * v; D = v / speedFeet * 15; P = (T * (47 * I - m * 52 + E * 94 * D - t * .38 + left_right * .21 * E) / 1e2 + W * 179 * v) / 2312; v -= (W * F - T * (.63 * m - I * .086 + m * E * 19 - D * 25 - .11 * left_right) / 107e2) * timeDelta; } }
the_stack_data/231099.c
#include <stdlib.h> #include <string.h> int getsubopt(char** opt, char* const* keys, char** val) { char* s = *opt; int i; *val = NULL; *opt = strchr(s, ','); if (*opt) *(*opt)++ = 0; else *opt = s + strlen(s); for (i = 0; keys[i]; i++) { size_t l = strlen(keys[i]); if (strncmp(keys[i], s, l)) continue; if (s[l] == '=') *val = s + l + 1; else if (s[l]) continue; return i; } return -1; }
the_stack_data/18888706.c
// // Sample Code: // #include <stdio.h> #include <stdlib.h> #include <string.h> //#define DEBUG_CORRECTNESS void pre_Initializing_Input_Tensors(); void post_Correctness(); // // #abc-adec-ebd // t3 [a,16,b,16,c,16] += sum(e,16,d,16) * t2 [a,d,e,c] * v2 [e,b,d]; // int main(int argc, char** argv) { // for sd2 double *host_C, *host_C_chk; double *host_A; double *host_B; int size_idx_a, size_idx_b, size_idx_c, size_idx_d, size_idx_e; // Problem Size size_idx_a = 16; size_idx_b = 16; size_idx_c = 16; size_idx_d = 16; size_idx_e = 16; // if (argc == 6) { size_idx_a = atoi(argv[1]); size_idx_b = atoi(argv[2]); size_idx_c = atoi(argv[3]); size_idx_d = atoi(argv[4]); size_idx_e = atoi(argv[5]); } int size_C; int size_A; int size_B; int size_internal; // #abc-adec-ebd // t3 [a,16,b,16,c,16] += sum(e,16,d,16) * t2 [a,d,e,c] * v2 [e,b,d]; size_internal = size_idx_e * size_idx_d; size_C = size_idx_a * size_idx_b * size_idx_c; size_A = size_idx_a * size_idx_d * size_idx_e * size_idx_c; size_B = size_idx_e * size_idx_b * size_idx_d; // host_C = (double*)malloc(sizeof(double) * size_C); host_C_chk = (double*)malloc(sizeof(double) * size_C); host_A = (double*)malloc(sizeof(double) * size_A); host_B = (double*)malloc(sizeof(double) * size_B); printf ("==========================================================================================================\n"); printf (">>> abc-adec-ebd\n"); printf (">>> t3 [a,16,b,16,c,16] += sum(e,16,d,16) * t2 [a,d,e,c] * v2 [e,b,d];\n"); printf (">>> Problem Size (a,b,c) and (d,e): (%2d,%2d,%2d) and (%2d, %2d)\n", size_idx_a, size_idx_b, size_idx_c, size_idx_d, size_idx_e); printf ("==========================================================================================================\n"); // Initialze "1" Output and "2 x 9" Inputs pre_Initializing_Input_Tensors(host_C, host_C_chk, size_C, host_A, size_A, host_B, size_B); // Run the Kernels sd_t_d2_fusion_(size_idx_a, size_idx_b, size_idx_c, size_idx_d, size_idx_e, host_C, host_A, host_B, 1, -1); #ifdef DEBUG_CORRECTNESS // Correctness-Check post_Correctness(host_C, host_C_chk, host_A, host_B, size_idx_a, size_idx_b, size_idx_c, size_idx_d, size_idx_e); #endif // Free free(host_C); free(host_C_chk); free(host_A); free(host_B); return 0; } // Initialize t3 (t3_temp), 9 t2 and 9 v2. void pre_Initializing_Input_Tensors(double* h_C, double* h_C_chk, int size_C, double* h_A, int size_A, double* h_B, int size_B) { // t3 int i, j; for (i = 0; i < size_C; i++) { h_C[i] = 0.0; h_C_chk[i] = 0.0; } for (j = 0; j < size_A; j++) { h_A[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_B; j++) { h_B[j] = ((double)rand() / RAND_MAX); } } // void post_Correctness(double* h_C, double* h_C_chk, double* h_A, double* h_B, int size_idx_a, int size_idx_b, int size_idx_c, int size_idx_d, int size_idx_e) { // t3 [a,16,b,16,c,16] += sum(e,16,d,16) * t2 [a,d,e,c] * v2 [e,b,d]; int size_C = size_idx_a * size_idx_b * size_idx_c; long long int tmp_ops = 0; int ops = 0; int idx_a, idx_b, idx_c, idx_d, idx_e, idx_f; for (idx_a = 0; idx_a < size_idx_a; idx_a++) for (idx_b = 0; idx_b < size_idx_b; idx_b++) for (idx_c = 0; idx_c < size_idx_c; idx_c++) { int tmp_r_idx = idx_a + (idx_b + (idx_c) * size_idx_b) * size_idx_a; ops = 0; for (idx_d = 0; idx_d < size_idx_d; idx_d++) { for (idx_e = 0; idx_e < size_idx_e; idx_e++) { h_C_chk[tmp_r_idx] += h_A[idx_a + (idx_d + (idx_e + (idx_c) * size_idx_e) * size_idx_d) * size_idx_a] * h_B[idx_e + (idx_b + (idx_d) * size_idx_b) * size_idx_e]; ops++; } } tmp_ops = tmp_ops + ops; } printf ("======================================= Correctness Check ==========================================\n"); double epsilon = 0.00000001; int diff = 0; int same = 0; int i; for (i = 0; i < size_C; i++) { double check = h_C_chk[i] - h_C[i]; if (check < 0) check *= -1; if (check > epsilon) { diff++; if (diff < 8) printf ("Index: %5d, (Host) %8.4f, (Dev.) %8.4f >> (Diff.) %8.4f\n", i, h_C_chk[i], h_C[i], check); } else { same++; } } printf (" >>> PASSED: %'10d among %'10d in t3\n", same, size_C); printf (" >>> ERROR : %'10d among %'10d in t3\n", diff, size_C); printf (" >>> Total Operations: %'lld\n", tmp_ops * 2); printf ("====================================================================================================\n"); }
the_stack_data/679.c
#include <stdio.h> int main() { printf("only time will tell\n"); printf("fit as a fiddle\n"); printf("the quick brown fox jumped over the lazy dogs\n"); printf("hello world\n"); printf("the early bird catches the worm\n"); return 0; }
the_stack_data/57049.c
#define _GNU_SOURCE #include <math.h> #include "features.h" double exp10(double x) { static const double p10[] = { 1e-15, 1e-14, 1e-13, 1e-12, 1e-11, 1e-10, 1e-9, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15 }; double n, y = modf(x, &n); if (fabs(n) < 16) { if (!y) return p10[(int)n+15]; y = exp2(3.32192809488736234787031942948939 * y); return y * p10[(int)n+15]; } return pow(10.0, x); } weak_alias(exp10, pow10);
the_stack_data/20449675.c
/** * This file has no copyright assigned and is placed in the Public Domain. * This file is part of the mingw-w64 runtime package. * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #include <fenv.h> /* 7.6.4.4 The feupdateenv function saves the currently raised exceptions in its automatic storage, installs the floating-point environment represented by the object pointed to by envp, and then raises the saved exceptions. The argument envp shall point to an object set by a call to feholdexcept or fegetenv, or equal the macro FE_DFL_ENV or an implementation-defined environment macro. */ /* FIXME: this works but surely there must be a better way. */ int feupdateenv (const fenv_t * envp) { unsigned int _fexcept = fetestexcept (FE_ALL_EXCEPT); /*save excepts */ fesetenv (envp); /* install the env */ feraiseexcept (_fexcept); /* raise the except */ return 0; }
the_stack_data/71487.c
#ifdef __cplusplus #if __cplusplus extern "C"{ #endif #endif /* __cplusplus */ #define LOCK_PREFIX "lock;" static inline long __cmpxchg(volatile void *ptr, long old, long new, int size) { long prev; switch (size) { case 1: asm volatile(LOCK_PREFIX "cmpxchgb %b1,%2" : "=a"(prev) : "q"(new), "m"(*(char *)(ptr)), "0"(old) : "memory"); return prev; case 2: asm volatile(LOCK_PREFIX "cmpxchgw %w1,%2" : "=a"(prev) : "r"(new), "m"(*(short *)(ptr)), "0"(old) : "memory"); return prev; case 4: asm volatile(LOCK_PREFIX "cmpxchgl %k1,%2" : "=a"(prev) : "r"(new), "m"(*(int *)(ptr)), "0"(old) : "memory"); return prev; case 8: asm volatile(LOCK_PREFIX "cmpxchgq %1,%2" : "=a"(prev) : "r"(new), "m"(*(long *)(ptr)), "0"(old) : "memory"); return prev; } return old; } int ss_atomic_add(int * pAddr, int value) { int oldvalue; int ret; do { oldvalue = *pAddr; ret = (int)__cmpxchg(pAddr, oldvalue, oldvalue + value, sizeof(int)); } while ( ret != oldvalue ); return 1; } int ss_atomic_sub(int * pAddr, int value) { int oldvalue; int ret; do { oldvalue = *pAddr; ret = (int)__cmpxchg(pAddr, oldvalue, oldvalue - value, sizeof(int)); } while ( ret != oldvalue ); return 1; } int ss_atomic_inc(int * pAddr) { int oldvalue; int ret; do { oldvalue = *pAddr; ret = (int)__cmpxchg(pAddr, oldvalue, oldvalue + 1, sizeof(int)); } while ( ret != oldvalue ); return 1; } int ss_atomic_dec(int * pAddr) { int oldvalue; int ret; do { oldvalue = *pAddr; ret = (int)__cmpxchg(pAddr, oldvalue, oldvalue - 1, sizeof(int)); } while ( ret != oldvalue ); return 1; } int ss_atomic_cas(int * pAddr , int valueOld , int valueNew) { int ret = (int)__cmpxchg(pAddr, valueOld, valueNew, sizeof(int)); return ( ret == valueOld ) ? 1 : 0; } int ss_atomic64_add(long * pAddr, long value) { long oldvalue; long ret; do { oldvalue = *pAddr; ret = __cmpxchg(pAddr, oldvalue, oldvalue + value, sizeof(long)); } while ( ret != oldvalue ); return 1; } int ss_atomic64_sub(long * pAddr, long value) { long oldvalue; long ret; do { oldvalue = *pAddr; ret = __cmpxchg(pAddr, oldvalue, oldvalue - value, sizeof(long)); } while ( ret != oldvalue ); return 1; } int ss_atomic64_inc(long * pAddr) { long oldvalue; long ret; do { oldvalue = *pAddr; ret = __cmpxchg(pAddr, oldvalue, oldvalue - 1, sizeof(long)); } while ( ret != oldvalue ); return 1; } int ss_atomic64_dec(long * pAddr) { long oldvalue; long ret; do { oldvalue = *pAddr; ret = __cmpxchg(pAddr, oldvalue, oldvalue - 1, sizeof(long)); } while ( ret != oldvalue ); return 1; } int ss_atomic64_cas(long * pAddr, long valueold, long valuenew) { long ret = __cmpxchg(pAddr, valueold, valuenew, sizeof(long)); return ( ret == valueold ) ? 1 : 0; } #ifdef __cplusplus #if __cplusplus } #endif #endif /* __cplusplus */
the_stack_data/103264898.c
#if defined(__GNUC__) && \ !(defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)) void THIS_IS_GNU(); #endif #ifdef __MINGW32__ void THIS_IS_MINGW(); #endif #ifdef __CYGWIN__ void THIS_IS_CYGWIN(); #endif
the_stack_data/90249.c
/* K.N.King "C Programming. A Modern Approach." Programming project 5 p.96 In one state, single residents are subject to the following income tax: Income: Amount of tax: Not over $750 1% of income $750-$2,250 $7.50 plus 2% of the amount $2,250-$3,750 $37.50 plus 3% of the amount $3,750-$5,250 $82.50 plus 4% of the amount $5,250-$7,000 $142.50 plus 5% of the amount Over $7,000 $230.00 plus 6% of the amount Write a program that asks the user to enter the amount of taxable income, then displays the tax due. */ #include <stdlib.h> #include <stdio.h> double CalculateTaxDue(double taxableIncome); int main(void) { double income = 0.0; double taxdue = 0.0; int isInputValid = 0; while (!isInputValid) { printf("Please enter the amount of taxable income: "); if ( scanf("%lf", &income) == 1) { if (income < 0.0) { puts("Income cannot be negative. Please try again."); } else { isInputValid = 1; } } else { puts("Invalid input. Please try again."); } // discard trailing input left by scanf char c = '\0'; while ( (c = getchar()) != '\n' && c != EOF) continue; } taxdue = CalculateTaxDue(income); printf("Income: $%.2lf\n", income); printf("Tax due: $%.2lf\n", taxdue); getchar(); return EXIT_SUCCESS; } /* The tax is calculated based on the following table: Income: Amount of tax: Not over $750 1% of income $750-$2,250 $7.50 plus 2% of the amount $2,250-$3,750 $37.50 plus 3% of the amount $3,750-$5,250 $82.50 plus 4% of the amount $5,250-$7,000 $142.50 plus 5% of the amount Over $7,000 $230.00 plus 6% of the amount */ double CalculateTaxDue(double taxableIncome) { if (taxableIncome < 0.0) { return 0.0; } double taxdue = 0.0; if (taxableIncome < 750.0) { taxdue = taxableIncome * 0.01; } else if (taxableIncome < 2250.0) { taxdue = 7.5 + taxableIncome * 0.02; } else if (taxableIncome < 3750.0) { taxdue = 37.5 + taxableIncome * 0.03; } else if (taxableIncome < 5250.0) { taxdue = 82.5 + taxableIncome * 0.04; } else if (taxableIncome < 7000.0) { taxdue = 142.5 + taxableIncome * 0.05; } else { taxdue = 230.0 + taxableIncome * 0.06; } return taxdue; }
the_stack_data/984751.c
/*@ begin PerfTuning ( def build { arg build_command = 'gcc -O3 -fopenmp '; arg libs = '-lm -lrt'; } def performance_counter { arg repetitions = 35; } def performance_params { param T1_I[] = [1,16,32,64,128,256,512]; param T1_J[] = [1,16,32,64,128,256,512]; param T2_I[] = [1,64,128,256,512,1024,2048]; param T2_J[] = [1,64,128,256,512,1024,2048]; param U_I[] = range(1,31); param U_J[] = range(1,31); (T1_I if T1_I>1 else T2_I)*(T1_J if T1_J>1 else T2_J) <= 512*512)); } def search { arg algorithm = 'Randomsearch'; arg total_runs = 10000; } let SIZE = 5000; def input_params { param MSIZE = SIZE; param NSIZE = SIZE; param M = SIZE; param N = SIZE; } def input_vars { decl static double a[M][N] = random; decl static double y_1[N] = random; decl static double y_2[M] = random; decl static double x1[M] = 0; decl static double x2[N] = 0; } ) @*/ int i, j; int ii, jj; int iii, jjj; #define max(x,y) ((x) > (y)? (x) : (y)) #define min(x,y) ((x) < (y)? (x) : (y)) /*@ begin Loop( transform Composite( tile = [('i',T1_I,'ii'),('j',T1_J,'jj'),(('ii','i'),T2_I,'iii'),(('jj','j'),T2_J,'jjj')], unrolljam = (['i','j'],[U_I,U_J]) ) for (i=0;i<=N-1;i++) for (j=0;j<=N-1;j++) { x1[i]=x1[i]+a[i][j]*y_1[j]; x2[j]=x2[j]+a[i][j]*y_2[i]; } ) @*/ /*@ end @*/ /*@ end @*/
the_stack_data/281997.c
#include <stdio.h> int main(){ int sum=0, i=100; while(i<=200){ (i%9==0)?printf("%d\n",i),sum+=i,i++:i++;} printf("Sum=%d", sum); }
the_stack_data/22013245.c
int numDistinct(char* s, char* t) { int **dp; int i,j; int len_s,len_t; int ret; len_s = strlen(s); len_t = strlen(t); dp = (int **)malloc(sizeof(int *) * (len_s+1)); for(i = 0; i <= len_s; ++i){ dp[i] = (int *)malloc(sizeof(int) * (len_t+1)); memset(dp[i],0,sizeof(int) * (len_t + 1)); } for(i = 0; i <= len_s; ++i) dp[i][0] = 1; for(i = 1; i <= len_s; ++i){ for(j = 1; j <= len_t; ++j){ dp[i][j] = dp[i-1][j]; if(s[i-1] == t[j-1]) dp[i][j] += dp[i-1][j-1]; } } ret = dp[len_s][len_t]; for(i = 0; i <= len_s; ++i) free(dp[i]); free(dp); return ret; }
the_stack_data/209693.c
/* fast_sqrt.c Copyright (c) 2021, [email protected] Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <stdint.h> #define INPUT_COMMA 15 #define INPUT_ONE (1UL<<INPUT_COMMA) #define INTERNAL_COMMA 14 #define INTERNAL_ONE (1UL<<INTERNAL_COMMA) #define SQRT_START_BITS 4 #define SQRT_START_CNT (1<<SQRT_START_BITS) #ifdef __GNUC__ #define USE_BUILDIN_CLZ #endif /* this table is generated by calculate_start_values.c */ static uint16_t sqrt_start_values[16] = {24241, 31925, 45989, 38100, 33294, 29975, 27506, 25577, 24017, 22720, 21621, 20674, 19846, 19115, 18463, 17876}; #ifndef USE_BUILDIN_CLZ // find the log base 2 of 32-bit v int get_highest_1_bit_position(uint32_t v) { // source: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn static const uint8_t MultiplyDeBruijnBitPosition[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 }; v |= v >> 1; // first round down to one less than a power of 2 v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; return MultiplyDeBruijnBitPosition[(uint32_t)(v * 0x07C4ACDDU) >> 27]; } #endif /* Prototype: uint16_t fast_sqrt(int16_t number) Description: Calculate the square root for a 1.15 fix point value Valid input values are from 0 to 0x7fff (0 to .9999694824). Arg number: A 1.15 fix point value from which the square root is calculated Returns The square root of "number" or 0 if the "number" is negative */ int16_t fast_sqrt(int16_t n) { uint32_t temp; uint32_t x; int number_up_shift = 0; int highest_bit_position; uint16_t number = n; /* Check whether the input is negative. If so, return 0. */ if ( number < 0 ) return 0; /* The following block increases accuracy by shifting up small values. Idea: sqrt(n) == sqrt(4*n/4) == sqrt(4*n)/2 Instead of calculating sqrt(n), calculate sqrt(4*n) and divide by 2 at the end. For the implementation a more general approach is used: sqrt(2^(2*s) * n) / 2^s In the first step, calculate the position of the highest one-bit. Some architectures provide a "count left zeros" function, which could be used to get the highest one bit.- */ #ifndef USE_BUILDIN_CLZ highest_bit_position = get_highest_1_bit_position(number); #else highest_bit_position = INPUT_COMMA; if ( number > 0 ) highest_bit_position = 31-__builtin_clz(number); else highest_bit_position = 31; #endif /* Upshift is only possible if the highes one bit is more than 2 bit positions below the comma of the input value */ if ( INPUT_COMMA >= highest_bit_position + 2 ) { number_up_shift = INPUT_COMMA - highest_bit_position - 2; /* Calculate the number of left shifts */ number_up_shift &= 0x0fe; /* Ensure that the number is even, so that we can fix the left shift of the result later */ number <<= number_up_shift; /* Do the upshift */ number_up_shift /= 2; /* Calculate the value for the down shift of the result: Downshift is half of the upshift */ } /* Find a suitable starting point for the approximation process defined by x := x + x*(1-d*x*x)/2 This iterative approximation will calculate the inverse square root of x (1/sqrt(x)) The initial 16 values for x are the following values: 0 0000 000 00000000 0 0001 000 00000000 0 0011 000 00000000 ... 0 1111 000 00000000 The lookup table sqrt_start_values will return the precalculated result (inverse square root). The following iteration process will use a different fix point format 2.14. Values within sqrt_start_values are already in 2.14 format. */ x = sqrt_start_values[number >> (INPUT_COMMA - SQRT_START_BITS)]; /* fix-point 2.14 */ /* Calculate the ivnerse square root by using the following iterative approximation: x := x + x*(1-d*x*x)/2 (https://www.jjj.de/fxt/fxtbook.pdf, page 568) By restructuring the expression, we can remove one add operation: x := x + x*(1-d*x*x)/2 x := x * ( 1 + (1-d*x*x)/2 ) x := x * ( 1 + 0.5 - d*x*x/2 ) */ /* iteration 1 */ temp = x; /* x is already in 2.14 format */ temp *= x; /* 2.14 * 2.14 */ temp >>= INTERNAL_COMMA; /* shift by 14 to get 2.14 format */ temp *= number; /* d*x*x/2: 1.15 * 2.14 */ temp >>= INPUT_COMMA+1; /* to get the 2.14 format, shift by 15 (1.15) and additionally divide by 2 ("+1") */ temp = INTERNAL_ONE + (INTERNAL_ONE>>1) - temp; /* 1 + 0.5 - d*x*x/2 */ x *= temp; /* 2.14 * 2.14 */ x >>= INTERNAL_COMMA; /* shift by 14 to get 2.14 format */ /* iteration 2 */ temp = x; temp *= x; temp >>= INTERNAL_COMMA; temp *= number; temp >>= INPUT_COMMA+1; temp = INTERNAL_ONE + (INTERNAL_ONE>>1) - temp; x *= temp; x >>= INTERNAL_COMMA; /* iteration 3 */ temp = x; temp *= x; temp >>= INTERNAL_COMMA; temp *= number; temp >>= INPUT_COMMA+1; temp = INTERNAL_ONE + (INTERNAL_ONE>>1) - temp; x *= temp; x >>= INTERNAL_COMMA; /* "x" contains the inverse root 1/sqrt(number). x = 1/sqrt(number) If we multiple both sides with "number", then we get sqrt(number): x*number = 1/sqrt(number)*number = sqrt(number) */ x *= number; /* fix-point: 1.15 * 2.14 */ /* The previous multiplication has to be corrected by the internal 2.14 fix point to get the 1.15 format. Additionally undo the initial up shift of the input value. */ x >>= INTERNAL_COMMA+number_up_shift; /* At this point the error might be up to two bits. Perform a final increase in the precision, by comparing the quadric value with the original number. For this purpose we store the square in temp and the difference in "n". This section is optional, but will increase precision of the result a little bit. */ temp = x; temp *= x; /* square value of x */ temp >>= INPUT_COMMA; /* square value of x in 1.15 format */ n -= temp; /* reuse n to store the signed difference */ if ( n > 1 || n < -1 ) /* update result only if the current difference is larger than 1 */ x += n>>1; /* finally return the square root of the input value */ return x; }
the_stack_data/48105.c
/* Copyright (c) 2010 Red Hat Incorporated. 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. The name of Red Hat Incorporated may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED 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. */ /* These definitions are for the RL78/G13, which the simulator simulates. */ typedef unsigned char UQI __attribute__((mode(QI))); typedef unsigned int UHI __attribute__((mode(HI))); #define s8(x) (*(volatile UQI *)(x)) #define s16(x) (*(volatile UHI *)(x)) #define P(x) s8(0xfff00+(x)) #define PM(x) s8(0xfff20+(x)) #define PER0 s8(0xf00f0) #define SSR00 s16(0xf0100) #define SMR00 s16(0xf0110) #define SCR00 s16(0xf0118) #define SS0 s16(0xf0122) #define SPS0 s16(0xf0126) #define SO0 s16(0xf0128) #define SOE0 s16(0xf012a) #define SOL0 s16(0xf0134) #define SDR00 s16(0xfff10) static int initted = 0; static void init_uart0 () { initted = 1; PER0 = 0xff; SPS0 = 0x0011; /* 16 MHz */ SMR00 = 0x0022; /* uart mode */ SCR00 = 0x8097; /* 8-N-1 */ SDR00 = 0x8a00; /* baud in MSB - 115200 */ SOL0 = 0x0000; /* not inverted */ SO0 = 0x000f; /* initial value */ SOE0 = 0x0001; /* enable TxD0 */ P(1) |= 0b00000100; PM(1) &= 0b11111011; SS0 = 0x0001; } static void tputc (char c) { /* Wait for transmit buffer to be empty. */ while (SSR00 & 0x0020) asm(""); /* Transmit that byte. */ SDR00 = c; } /* defaults to 0 unless open() is linked in */ int _open_present; int _write(int fd, char *ptr, int len) { int rv = len; if (_open_present && fd > 2) return _SYS_write (fd, ptr, len); if (!initted) init_uart0 (); while (len != 0) { tputc (*ptr); ptr ++; len --; } return rv; } char * write (int) __attribute__((weak, alias ("_write")));
the_stack_data/125139917.c
/* * MUL and DIV implies that the ALU must change. Before, the top of the ALU was: * * ___ * pre_cmb_aluF ---------------------------------|I0 | __ * Q[31] ------------+---------------------------|I1 |-- wcmb_aluF ----------| |-- raluF * | +-------------------------|I2 | >__| * | | +-----|I3_| * | | | * | | | alu_carryout * | | /y\ * | | ||| ___ * | | isWrinst -(((----|I0 | * | | 1 -+((----|I1 |-- alu_minstretofl ... * | | 0 --(+----|I2 | * | | +-----|I3_| * | | | * | | | alucy[32] * | | /y\ * ___ | | ||| ___ * ADR_O[31] --|I0 | | | A[31] s_alu[2] --(((----|I0 | * s_alu[0] --|I1 |-(-+------------------+((----|I1 |-- B[31] * Di[31] --|I2 | +---------------------(+----|I2 | * s_alu[1] --|I3_| +-----|I3_| * | * | alucy[31] * * We need to extend the accumulator to 33 bits. I call the new msb: signP. * * Observation 1: * cmb_signP need only be correct during MUL/MULHS instructions. alu_carryout is irrelevant during MUL/MULHS instructions. * signP must be conserved accross other microcode cycles, it is effectively ADR_O[32]. * * Observation 2: * alu_carryout need only be correct during: MULHU, SLT[[I]U], BEQ/BNE/BLT/BGE/BLTU/BGEU * * Observation 3: * alu_minstretofl can be performed a later cycle than when rinst is incremented. * * Observationm 4: * Use of E and R of the FF for signP will conflict with the FF for raluF. * * * ___ wcmb_aluF = pre_cmb_aluF ? ~alu_carryout : ((~alu_carryout&(A31^QQ[31])) | (A31&QQ[31])) * pre_cmb_aluF -----------------------------------|I0 | __ * Q[31] ------------+-----------------------------|I1 |---(wcmb_aluF)---------| |---------- raluF ( == ~alu_carryout when MULHU) * | +---------------------------|I2 | > | * | | +-----|I3_| enaQ ---------------E__| * | | | * | | | alu_carryout * | | /y\ ___ * | | sp0 -(((----|I0 | __ * | | sp1 -+((----|I1 |-- cmb_signP ----------| |-- signP * | | sp2 --(+----|I0 | > | * | | +-----|I3_| enaQ ---------------E__| * | | | * | | | alucy[33] * | | /y\ * | | ||| ___ * | | isWrinst -(((----|I0 | * | | 1 -+((----|I1 |-- alu_minstretofl = isWrinst & alucy[32] * | | 0 --(+----|I2 | * | | +-----|I3_| * | | | * | | | alucy[32] * | | /y\ * ___ | | ||| ___ * ADR_O[31] --|I0 | | | A[31] s_alu[2] --(((----|I0 | * s_alu[0] --|I1 |-(-+--------------------+((----|I1 |-- B[31] * Di[31] --|I2 | +-----------------------(+----|I2 | * s_alu[1] --|I3_| +-----|I3_| * | * | alucy[31] * * What I really want: * signP <= alucy[33] when we have MULHU. This will simplify sra_msb * also when we do SHLQ. For DIV[U]/REM[U] shift operations. * cmb_signP=signP^ alucy[33] ^ (rA[0] ? DAT_O[31] : 0) when we have add ucodecycle in DIV[U]/REM[U]. Combinatoric output determine if * ADR_O is to be updated. This is really the subtraction ((sub)) in routine divu(). * rA[0] is always 0 here, so we can use the same equation as for the line below. * To be strictly right, we should have: cmb_signP=signP^alucy[33]^1, the 33-bit * subtrahend B always have msb set. But the resulting msb is only tested, not stored, * so we may cheat and only do cmb_signP=signP^alucy[33]. * This may easily be the critical path of midgetv. * signP <= signP ^ alucy[33] ^ (rA[0] ? DAT_O[31] : 0) when we have add ucodecycle in MULH/MULHSU, Here we add sign extended B and P * signP <= signP when we have shift right ucodecycle in MULH/MULHSU. Here we shift P arithmetic. * signP <= 0 when sa14 (ADR_O cleared). When P is cleared, the msb of P should also be cleared. * This can be done somewhat better - signP can be cleared when rA is loaded: s_shlr[1]. * I do not need to conserve alu_carryout for this case. * alu_carryout = alucy[33] at least when SLT[[I]U], BEQ/BNE/BLT/BGE/BLTU/BGEU. Because then the proven exiting code will still work. * * s_shlr[1] * | INSTR[25] * | | INSTR[6:5] * | | || FUNC3[1:0] alu_carryout must be valid * | | || || s_shlr[0] Covers | sp[2:1] sp[0] cmb_signP * 0 x 00 SLTU/SLTIU 1 01 x x * 0 x 01 00 MUL x xx x x * 0 x 01 01 0 MULH add ucodecycle x 01 signP^(rA[0] ? DAT_O[31] : 0 alucy[33] ^ signP ^ (rA[0] ? DAT_O[31] : 0) * 0 x 01 01 1 MULH shift ucodecycle x 10 signP signP * 0 x 01 10 0 MULHSU/SLT add ucodecycle 1 01 signP^(rA[0] ? DAT_O[31] : 0 alucy[33] ^ signP ^ (rA[0] ? DAT_O[31] : 0) * 0 x 01 10 1 MULHSU/SLT shift ucodecycle 1 10 signP signP * 0 0 01 11 SLTU 1 01 x x * 0 1 01 11 MULHU x 11 x alucy[33] * 0 x 10 x x 01 x x * 0 x 11 BEQ/BNE/BLT/BGE/BLTU/BGEU 1 01 x x * 1 Clear signP x 00 x 0 * * sp[0] = (s_shlr[0] & signP) | (~s_shlr[0] & (signP^(rA[0]&DAT_O[31]))) * sp[1] = ~s_shlr[1] & ~s_shlr[0]; * sp[2] = ~s_shlr[1] & (s_shlr[0] | (INSTR[25] & FUNC3[1] & FUNC3[0]) // 5-inp * cmb_signP = (~sp[2] & sp[1] & ( sp[0] ^ alucy[33]) ) | * ( sp[2] & ~sp[1] & sp[0] ) | * ( sp[2] & sp[1] & alucy[33] ) | * * Then, for shift right operand: * * is_MULHU * |FUNC7[5] * ||FUNC7[0] * ||| sra_msb * x00 0 SRL/SRLI, logical shift right. * 101 signP MULHU, shifts carry out into msb * x10 ADR_O[31] SRA/SRAI, arithmetic shift right, * 001 signP MULH/MULSU shifts sign of P into msb * * Simplifies to: * * FUNC7[5] * |FUNC7[0] * || sra_msb * 00 0 * 01 signP * 10 ADR_O[31] * 11 x * * * * AGAIN: * ====== * ___ * pre_cmb_aluF ---------------------------------|I0 | __ * Q[31] ------------+---------------------------|I1 |-- wcmb_aluF ----------| |-- raluF * | +-------------------------|I2 | enaQ ---------------E | (enaQ perhaps not needed) * | | +-----|I3_| >__| * | | | * | | | alu_carryout * | | /y\ * | | ||| ___ * | | sp[0] -(((----|I0 | __ * | | sp[1] -+((----|I1 |-- cmb_cysignP --------| |- rcysignP * | | sp[2] --(+----|I2 | enaQ ---------------E | (enaQ perhaps not needed) * | | +-----|I3_| >__| * | | | * | | | alucy[33] * | | /y\ * | | ||| ___ * | | isWrinst -(((----|I0 | * | | 1 -+((----|I1 |-- alu_minstretofl ... * | | 0 --(+----|I2 | * | | +-----|I3_| * | | | * | | | alucy[32] * | | /y\ * ___ | | ||| ___ * ADR_O[31] --|I0 | | | A[31] s_alu[2] --(((----|I0 | * s_alu[0] --|I1 |-(-+------------------+((----|I1 |-- B[31] * Di[31] --|I2 | +---------------------(+----|I2 | * s_alu[1] --|I3_| +-----|I3_| * | * | alucy[31] * * rcysignP ci to adder * a. When MULHU add cycle alucy[33] 0 * When MULHU SLR don't care rcysignP * b. When MULH/MULHSU add cycles alucy[33]^rcysignP^( (A[0] & signB) | ~A[0] ) 0 * c. When MULH/MULHSU SAR rcysignP rcysignP * d. When MULH last add cycle alucy[33]^rcysignP^( (A[0] & signB) | ~A[0] ) 1 May be eliminated see note (a) * e. When DIV[U]/REM[U] sub cycle: alucy[33]^rcysignP^1 1 for divu_restoring * f. When DIV[u]/REM[U] SLL: alucy[33] A[31] for divu_restoring * * (a) When doing MULH, I will first do one shift without looping to get the shift counter from 0x1f to 0x1e. * operand B that resides in register x[rs1] is stored inverted in Rjj. Rjj = ~B * I load the constant 1 into Ryy. Ryy = 1 * Then follows 31 loops of add/shifts. * The last add is done in two operations as follows: * rcysignP ci to adder * (A[0] & (signB^rcysignP) | (~A[0] & rcysignP))^alucy[33] 0 With Rjj as B (we add in ~B) * (A[0] & (signB^rcysignP) | (~A[0] & rcysignP))^alucy[33] 0 With Ryy as B (we add in 1) * For the cost of 2 to 3 cycles I get a sligtly easier logic in carry in to the adder? * * * sp[0] = (isSAR || DIV/REM subcycle) ? rcysignP^1 : rcysignP^( (A[0] & signB) | ~A[0]) * sp[2:1] = 00 cmb_cysignP = alucy[33] Covers a. and f. * 01 cmb_cysignP = sp[0]^alucy[33] Covers b. d. and e. * 10 cmb_cysignP = sp[0]^1 Covers c. * 11 not used * * Make it simpler. * ___ * pre_cmb_aluF ---------------------------------|I0 | __ * Q[31] ------------+---------------------------|I1 |-- wcmb_aluF ----------| |-- raluF * | +-------------------------|I2 | enaQ ---------------E | (enaQ perhaps not needed) * | | +-----|I3_| >__| * | | | * | | | alu_carryout * | | /y\ * | | ||| ___ * | | -(((----|I0 | * | | 1 -+((----|I1 |-- alutap * | | 0 --(+----|I2 | * | | +-----|I3_| * | | | * | | | alucy[32] * | | /y\ * ___ | | ||| ___ * ADR_O[31] --|I0 | | | A[31] s_alu[2] --(((----|I0 | * s_alu[0] --|I1 |-(-+------------------+((----|I1 |-- B[31] * Di[31] --|I2 | +---------------------(+----|I2 | * s_alu[1] --|I3_| +-----|I3_| * | * | alucy[31] * * wire isWrinst = {sa27,sa26,sa25,sa24} == 4'b1001, * Code for write halfword: {sa27,sa26,sa25,sa24} == 4'b0001, here the input to the ALU is D and Q==0, the carry chain is dead, * alutap is guaranteed to be 0. * Hence the old construction * aaa = write_to_minstreth = ctrlreg_we & ADR_O[14] * bbb = alu_minstretofl = isWrinst & alucy[32] * * _ * ___ ctrlreg_we --|&| ___ * s24 --|I0 | ||| ___ ADR_O[14] ---|_|--o| | _ * s25 --|I1 |- isWrinst -(((----|I0 | __ | & |---| |-+ * s26 --|I2 | 1 -+((----|I1 |-- bbb -------------|or|--|___| >_| | * s27 --|I3_| 0 --(+----|I2 | +-|__| | * +-----|I3_| | | * | +-------------------+ * | alucy[32] * * is replaced by same cost (but more delay): _ * ctrlreg_we --|&| ___ * ||| ___ ___ ADR_O[14] ---|_|--o| | _ * (((----|I0 |- alutap ------|I0 | __ | & |---| |-+ * +((----|I1 | sa24 ------|I1 |-- bbb -------------|or|--|___| >_| | * -(+----|I2 | sa25 ------|I2 | +-|__| | * +-----|I3_| sa26 ------|I3_| | | * | +-------------------+ * * If this becomes the critical path, 1 LUT for isWrinst, add one LUT for write_to_minstret, and: * * write_to_minstret -----------+ * ||| ___ _ | _ _ * (((----|I0 |- alutap ----------|&| __ +-o|&|--| |-+ * +((----|I1 | isWrinst ---------|_|---|or|----|_| >_| | * -(+----|I2 | +-|__| | * +-----|I3_| | | * | +------------------+ * * We now have a bit more liberty to construct cmb_cysignP. * ___ * alutap ------|I0 | __ * sp[0] ------|I1 |-- cmb_cysignP --------| |- rcysignP * sp[1] ------|I2 | enaQ ---------------E | (enaQ perhaps not needed) * sp[2] ------|I3_| >__| * * * Or I colud go all the way, and build raluF differently. * * * EVEN AGAIN. LETS REQIRE raluF. * * I have merged in alu_minstretofl with raluF: assign alu_minstretofl = ~raluF & r_isWrinst; * * * MYSTERY ___ * ----- xxxxxxx --------------|I0 | __ * +---- xxxxxxx --------------|I1 |-- cmb_rF ----------| |-- rF * | +-- xxxxxxx --------------|I2 | | | * | | +-----|I3_| >__| * | | | * | | | acy * | | /y\ * ___ | | ||| ___ * ADR_O[31] --|I0 | | | A[31] s_alu[2] --(((----|I0 | * s_alu[0] --|I1 |-(-+------------------+((----|I1 |-- B[31] * Di[31] --|I2 | +---------------------(+----|I2 | * s_alu[1] --|I3_| | +-----|I3_| * | | * Q[31] ------------+ | alucy[31] * * * Below: * acy is carry out of bit 31 of adder * rF is effectively bit 32 of adder * M0 is bit 0 in bidirectional shifter * E31 is DAT_O[31] * Q31 is ADR_O[31] * * * INSTR[25] * | INSTR[6] * | | FUNC3 cmb_rF is_brcond * | | ||| s_shlr[0] | | * | | ||| | OpCode | | Comment * x 0 000 x mul lb addi add sub sb fence x x We have no interrest in upper 32 bits of the product * x 0 001 0 mulh lh sll slli sh fence.i acy^rF^(M0&E31) x mulh add ucodecycle * x 0 001 1 mulh lh sll slli sh fence.i rF x mulh sar ucodecycle * 0 0 010 x slti lw slt sw (E31&Q31)|((E31^Q31)&~acy) x slt(i) need a compare bit * 1 0 010 0 mulhsu acy^rF^(M0&E31) x mulhsu add ucodecycle * 1 0 010 1 mulhsu rF x mulhsu sar ucodecycle * 0 0 011 x sltiu sltu ~acy x slt(i)u need a compare bit * 1 0 011 0 mulhu acy x mulhu add ucodecycle * 1 0 011 1 mulhu x x mulhu slr ucodecycle * x 0 100 0 div lbu xori xor acy^rF^M0 x div add ucodecycle * x 0 100 1 div lbu xori xor acy x div sll ucodecycle * x 0 101 0 divu lhu srl sra srli srai acy^rF^M0 x divu add ucodecycle * x 0 101 1 divu lhu srl sra srli srai acy x divu sll ucodecycle * x 0 110 0 rem ori or acy^rF^M0 x rem add ucodecycle * x 0 110 1 rem ori or acy x rem sll ucodecycle * x 0 111 0 remu andi and acy^rF^M0 x remu add ucodecycle * x 0 111 1 remu andi and acy x remu sll ucodecycle * x 1 000 x beq ecall ebreak uret sret wfi mret jalr x ~rzcy32 * x 1 001 x bne csrrw x rzcy32 * x 1 010 csrrs x x * x 1 011 csrrc x x * x 1 100 blt (E31&Q31)|((E31^Q31)&~acy) rF * x 1 101 bge csrrwi (E31&Q31)|((E31^Q31)&~acy) ~rF * x 1 110 bltu csrrsi ~acy rF * x 1 111 bgeu csrrci ~acy ~rF * * * During mulh add, we do either rF <= rF if M0 == 0 (passd in ALU). Then we also know acy == 0 * or rF <= E31^rF^acy if M0 == 1 (ALU adds). * The full equation is rF <= (~M0&rF) | (M0&(E31^rF^acy) but because acy == 0 when M0 = 0 we can write * rF <= acy^rF^(M0&E31) * * During DIV(U)/REM(U), we do either rF <= rF^acy^0 if M0 == 0 * or rF <= rF^acy^1 if M0 == 1 * Hence we write rF <= rF^acy^M0 * * Initiation: All DIV(U)/REM(U), first do shift, so rF gets to a known value * No branches and slt uses rF, so the value is don't care * For MULH and MULHSU we need that rF == 0 before operation. This should be relatively easy * to ensure in ucode.h */ /* * 111 // 3322222 22222 11111 11 6 432 // 1098765 43210 98765 10987 543210 0 000, I( 'I', immL11_0J, rs1, rd, 000011, lb ) 0 000, I( 'I', immL11_0J, rs1, rd, 010011, addi ) 0 000, R( 'R', 0000000, rs2, rs1, rd, 110011, add ) 0 000, R( 'R', 0000001, rs2, rs1, rd, 110011, mul ) 0 000, R( 'R', 0100000, rs2, rs1, rd, 110011, sub ) 0 000, S( 'S', immL11_5J, rs2, rs1, immL4_0J, 100011, sb ) 0 000, r( 'Q', 0000, pred, succ, 00000, 00000, 001111, fence ) 0 001, I( 'I', immL11_0J, rs1, rd, 000011, lh ) 0 001, R( 'R', 0000000, rs2, rs1, rd, 110011, sll ) 0 001, R( 'R', 0000001, rs2, rs1, rd, 110011, mulh ) 0 001, R( 'h', 0000000, shamt, rs1, rd, 010011, slli ) 0 001, S( 'S', immL11_5J, rs2, rs1, immL4_0J, 100011, sh ) 0 001, r( 'Q', 0000, 0000, 0000, 00000, 00000, 001111, fence_i ) 0 010, I( 'I', immL11_0J, rs1, rd, 010011, slti ) 0 010, I( 'a', immL11_0J, rs1, rd, 000011, lw ) 0 010, R( 'R', 0000000, rs2, rs1, rd, 110011, slt ) 0 010, R( 'R', 0000001, rs2, rs1, rd, 110011, mulhsu ) 0 010, S( 'S', immL11_5J, rs2, rs1, immL4_0J, 100011, sw ) 0 011, I( 'I', immL11_0J, rs1, rd, 010011, sltiu ) 0 011, R( 'R', 0000000, rs2, rs1, rd, 110011, sltu ) 0 011, R( 'R', 0000001, rs2, rs1, rd, 110011, mulhu ) 0 100, I( 'I', immL11_0J, rs1, rd, 000011, lbu ) 0 100, I( 'I', immL11_0J, rs1, rd, 010011, xori ) 0 100, R( 'R', 0000000, rs2, rs1, rd, 110011, xor ) 0 100, R( 'R', 0000001, rs2, rs1, rd, 110011, div ) 0 101, I( 'I', immL11_0J, rs1, rd, 000011, lhu ) 0 101, R( 'R', 0000000, rs2, rs1, rd, 110011, srl ) 0 101, R( 'R', 0000001, rs2, rs1, rd, 110011, divu ) 0 101, R( 'R', 0100000, rs2, rs1, rd, 110011, sra ) 0 101, R( 'h', 0000000, shamt, rs1, rd, 010011, srli ) 0 101, R( 'h', 0100000, shamt, rs1, rd, 010011, srai ) 0 110, I( 'I', immL11_0J, rs1, rd, 010011, ori ) 0 110, R( 'R', 0000000, rs2, rs1, rd, 110011, or ) 0 110, R( 'R', 0000001, rs2, rs1, rd, 110011, rem ) 0 111, I( 'I', immL11_0J, rs1, rd, 010011, andi ) 0 111, R( 'R', 0000000, rs2, rs1, rd, 110011, and ) 0 111, R( 'R', 0000001, rs2, rs1, rd, 110011, remu ) 0 xxx U( 'U', immL31_12J, rd, 010111, auipc ) 0 xxx U( 'U', immL31_12J, rd, 110111, lui ) 1 000, B( 'B', immL12v10_5J, rs2, rs1, immL4_1v11J, 100011, beq ) 1 000, E( 'E', 0000000, 00000, 00000, 00000, 110011, ecall ) 1 000, E( 'E', 0000000, 00001, 00000, 00000, 110011, ebreak ) 1 000, E( 'E', 0000000, 00010, 00000, 00000, 110011, uret ) 1 000, E( 'E', 0001000, 00010, 00000, 00000, 110011, sret ) 1 000, E( 'E', 0001000, 00101, 00000, 00000, 110011, wfi ) 1 000, E( 'E', 0011000, 00010, 00000, 00000, 110011, mret ) 1 000, I( 'j', immL11_0J, rs1, rd, 100111, jalr ) 1 001, B( 'B', immL12v10_5J, rs2, rs1, immL4_1v11J, 100011, bne ) 1 001, C( 'C', csr, rs1, rd, 110011, csrrw ) 1 010, C( 'C', csr, rs1, rd, 110011, csrrs ) 1 011, C( 'C', csr, rs1, rd, 110011, csrrc ) 1 100, B( 'B', immL12v10_5J, rs2, rs1, immL4_1v11J, 100011, blt ) 1 101, B( 'B', immL12v10_5J, rs2, rs1, immL4_1v11J, 100011, bge ) 1 101, C( 'C', csr, zimm, rd, 110011, csrrwi ) 1 110, B( 'B', immL12v10_5J, rs2, rs1, immL4_1v11J, 100011, bltu ) 1 110, C( 'C', csr, zimm, rd, 110011, csrrsi ) 1 111, B( 'B', immL12v10_5J, rs2, rs1, immL4_1v11J, 100011, bgeu ) 1 111, C( 'C', csr, zimm, rd, 110011, csrrci ) 1 xxx J( 'J', immL20v10_1v11v19_12J, rd, 101111, jal ) */ #include <stdio.h> #include <stdint.h> ///////////////////////////////////////////////////////////////////////////// uint16_t divu_restoring( uint8_t A, uint8_t B) { uint8_t P = 0; uint16_t tmp; // Accumulator 9 bits in simulation 33 bits on target. uint16_t cy; // u8: Write rs1 to A // u9: invert rs2 (B), write to Rjj. Setup read source Rjj. Clear Q. Next u10a. uint8_t invB = B^255; for ( int i = 0; i < 8; i++ ) { // u12b. Shift left. Setup read source Rjj. Next u11. cy = (P >>7); P = (P<<1) | (A>>7); A = (A<<1); // u11. ADD_1. Write to Ryy, Setup Read source Ryy. hold Q. Branch to u12a or u12b CAN NOT WORK. raluF not ready before next cycle tmp = (cy<<8) | P; tmp += invB + 0x101; cy = (tmp >> 8) & 1; // u12a. Read Ryy to Q. Set lsb A. Loopbranch to u10a or u10b // If positive if ( cy^1 ) { A |= 1; P = tmp; } } // u10a. Shift. Setup read source Rjj. Next u11. (Duplicate instruction) // u10b. Cleanup, // if DIVU: copy A to Wdst // if REMU: copy P to Wdst // if DIV: if original B != 0 and signresult == 1, invert A. Write to Wdst // if REM: if original A negative, invert P. Write to Wdst // return ( P<<8) | A; } ///////////////////////////////////////////////////////////////////////////// uint16_t works_divu_restoring( uint8_t A, uint8_t B) { uint8_t P = 0; uint16_t cy,tmp; // Accumulator 9 bits uint16_t invB = B^511; // In 9 bits for ( int i = 0; i < 8; i++ ) { // Shift: cy = (P >>7); P = (P<<1) | (A>>7); A <<= 1; // Subtract ((sub)) tmp = (cy<<8) | P; tmp += invB + 1; tmp &= 511; // If positive if ( tmp < 256 ) { A |= 1; P = tmp; } } return ( P<<8) | A; } ///////////////////////////////////////////////////////////////////////////// uint16_t works_nonrestoring( uint8_t A, uint8_t B) { uint16_t tmp; // Accumulator 9 bits int extra; uint8_t invB = B^255; uint8_t P = 0; int cy = 0; for ( int i = 0; i < 8; i++ ) { // Shift left, remember sign in extra. extra = cy; // 1a: Shift ucode instruction. Set readsource Rjj, Cond to either 2a or 2b below cy = (P >>7) & 1; P = (P << 1) | (A>>7); A = (A << 1); // Add or subtract tmp = (cy<<8) | P; if ( extra ) { // 2a. Set readsource B tmp = tmp + B; // 3. Do this, then 4 } else { tmp = tmp + invB + 0x101; // 2b. Do this, then 4 } P = tmp; cy = (tmp>>8) & 1; // Record result A |= (cy^1); // 4. Do this, then loop to 1a or 1b } // Potentially restore remainder. // 1b. Test cy, go to 5a or 5b if ( cy ) P += B; // 5a. Do this go to 5b // 5b. ?? return ( P<<8) | A; } ///////////////////////////////////////////////////////////////////////////// uint16_t divu_nonrestoring( uint8_t A, uint8_t B) { // THE ONE WE WILL USE. uint16_t tmp; // Accumulator 9 bits uint8_t invB = B^255; uint8_t P = 0; int cy = 0; int extra = 0; for ( int i = 0; i < 8; i++ ) { // Shift left, remember sign. // extra = cy; // 1a: Shift ucode instruction. Set readsource Rjj, Cond to either 2a or 2b below cy = (P >>7) & 1; // P = (P << 1) | (A>>7); // A = (A << 1) | (extra^1); // // // // Add or subtract // tmp = (cy<<8) | P; // if ( extra ) { // 2a: set readsource B. tmp = tmp + B; // 3: Do this, then Loop control to 1a or 1b // } else { // tmp = tmp + invB + 0x101; // 2b: Do this, then Loop control to 1a or 1b // tmp = tmp + invB + 1; // 2b: Do this, then Loop control to 1a or 1b // tmp = tmp + 0xff + 1; // } // P = tmp; // cy = (tmp>>8) & 1; // } // // Record last result // extra = cy; //1b: Shift ucode instr. Go to 4a or 4b. // cy = (P >>7) & 1; // // P = (P << 1) | (A>>7); // A = (A << 1) | (extra^1); // 4: Get last result for A. Cond to either 5a or 5b // P = (cy<<7) | (P>>1); // // Potentially restore remainder. // if ( extra ) // P += B; //5a: Add //5b: ... return ( P<<8) | A; // // 1a: Shift ucode instruction. Set readsource Rjj, Cond to either 2a or 2b below // 1b: Compensate shift. Cond to 4a or 4b below // 2a: set readsource B. Next 3 // 2b: subtract then loop to 1a or 1b // // 3: add then loop to 1a or 1b // // 4: Last result for A then cond to either 5a or 5b // // 5a: Restore remainder // 5b: ... store P to destination register /* I will run out of ucode space. The loop above is a minimum of 8 ucode instruction, and I need 4 of them... * What to do? I have 47 ucode locations. I estimate that the 4 MUL instructions use 15 locations. Hence it rests 32 for DIV/REM.. If I assume I can tailmerge DIV/DIVU and tailmerge REM/REMU, these have 16 ucode instructions each. This may just be possible. Just now multiply uses 33 locations... */ } ///////////////////////////////////////////////////////////////////////////// int main( void ) { int ia,ib,facit; int iterations = 0; printf( "Multiplication: Unsigned * Unsigned: ia*ib" ); for ( ia = 0; ia < 0x100; ia++ ) { // for ( ib = 0; ib < 0x100; ib++ ) { iterations++; // Loading uint16_t tmp; uint8_t P = 0; uint8_t B = ib; uint8_t A = ia; int cy; // Routine for ( int i = 0; i < 8; i++ ) { tmp = (P + ((A & 1) ? B : 0)); cy = (tmp>>8) & 1; P = tmp; A = ((P & 1)<<7) | (A>>1); P = (cy<<7) | (P>>1); } // Testing int32_t calc = ((P & 0xff)<<8) | A; facit = ia * ib; if ( facit != calc ) { printf( "No luck. ia=%d ib=%d facit=%d calc=%d\n", ia, ib, facit,calc); return 1; } } } printf( " Ok\n" ); printf( "Multiplication: Unsigned * Signed: ia*sb " ); // The one we will use. for ( ia = 0; ia < 0x100; ia++ ) { for ( ib = 0; ib < 0x100; ib++ ) { iterations++; // Loading uint16_t tmp; uint8_t P = 0; uint8_t B = ib; uint8_t A = ia; int signB = (B >>7) & 1; int cy; // uint8_t lastinch = 0; // uint8_t modB = B ? B-1 : 0; // uint8_t modlastinch = B ? 1 : 0; // // // Routine // for ( int i = 0; i < 8; i++ ) { // // if ( i == 7) { // B = modB; // lastinch = modlastinch; // } // // int signP = (P >> 7) & 1; // tmp = (A & 1) ? P+B+lastinch : P+0; // cy = (tmp >> 8) & 1; // P = tmp; // int newsignP = (A & 1) ? signB^signP^cy : signP; // A = ((P & 1)<<7) | (A>>1); // P = ( (newsignP<<7) | (P >> 1)); // } // Routine. int signP; int newsignP; uint8_t modB = B ? B-1 : 0; uint8_t modlastinch = B ? 1 : 0; for ( int i = 1; i < 8; i++ ) { signP= (P >> 7) & 1; tmp = (A & 1) ? P+B : P+0; cy = (tmp >> 8) & 1; newsignP = (A & 1) ? signB^signP^cy : signP; P = tmp; A = ((P & 1)<<7) | (A>>1); P = ( (newsignP<<7) | (P >> 1)); } // This curious last mul cycle is there for merging with s*s signP = (P >> 7) & 1; tmp = (A & 1) ? P+modB+modlastinch : P+0; cy = (tmp >> 8) & 1; P = tmp; newsignP = (A & 1) ? signB^signP^cy : signP; A = ((P & 1)<<7) | (A>>1); P = ( (newsignP<<7) | (P >> 1)); // Checking int32_t calc = ((P & 0xff)<<8) | A; //facit = ((int8_t)ia) * ((int8_t)ib); int8_t sb = ib; facit = ia*sb; facit &= 0xffff; if ( facit != calc ) { printf( "No luck. ia=%d ib=%d facit=%d calc=%d\n", ia, ib, facit,calc); return 1; } } } printf( "variant 1 Ok\n" ); printf( "Multiplication: Unsigned * Signed: ia*sb " ); for ( ia = 0; ia < 0x100; ia++ ) { for ( ib = 0; ib < 0x100; ib++ ) { iterations++; // Loading uint16_t P = 0; // P is 9 bits uint16_t B = ((ib&0x80)<<1) | ib; // Sign extend to 9 bits uint8_t A = ia; // Routine for ( int i = 0; i < 8; i++ ) { P = (P + ((A & 1) ? B : 0)) & 0x1ff; A = ((P & 1)<<7) | (A>>1); P = ((P&0x100) | (P >> 1)) & 0x1ff; } // Checking int32_t calc = ((P & 0xff)<<8) | A; int8_t sb = ib; facit = ia*sb; facit &= 0xffff; if ( facit != calc ) { printf( "No luck. ia=%d ib=%d facit=%d calc=%d\n", ia, ib, facit,calc); return 1; } } } printf( "variant 2 Ok\n" ); printf( "Multiplication: Signed * Signed: sa*sb " ); for ( ia = 0; ia < 0x100; ia++ ) { for ( ib = 0; ib < 0x100; ib++ ) { iterations++; // Loading uint16_t tmp; uint8_t P = 0; uint8_t A = ia; uint8_t B = ib; int signB; int cy; int newsignP,signP; int lastinch = 0; // ia = -1 = 0xff, // ib = 1 // modib = fe // modlastinch = 1; // Routine for ( int i = 0; i < 8; i++ ) { if ( i == 7 ) { B = (B^0xffu); lastinch = 1; } signP = (P >> 7) & 1; signB = (B >> 7) & 1; tmp = (P + ((A & 1) ? B+lastinch : 0)); cy = (tmp >> 8) & 1; P = tmp; newsignP = (A & 1) ? (signB^signP^cy) : signP; A = ((P & 1)<<7) | (A>>1); P = ( (newsignP<<7) | (P >> 1)); } // Checking int32_t calc = ((P & 0xff)<<8) | A; int rawfacit = ((int8_t)ia) * ((int8_t)ib); facit = rawfacit & 0xffff; if ( facit != calc ) { printf( "No luck... ia=%d ib=%d facit=%d=%x calc=%d=%x\n", ia, ib, rawfacit, facit, calc, calc); return 1; } } } printf( "variant 1 Ok\n" ); printf( "Multiplication: Signed * Signed: sa*sb " ); for ( ia = 0; ia < 0x100; ia++ ) { for ( ib = 0; ib < 0x100; ib++ ) { iterations++; // Loading uint16_t P = 0; // P is 9 bits uint16_t B = ((ib&0x80)<<1) | ib; // Sign extend to 9 bits uint8_t A = ia; uint8_t invb = (ib^255); // Routine for ( int i = 0; i < 8; i++ ) { if ( i == 7 && (A & 1) ) { if ( invb & 0x80 ) P ^= 0x100; P += invb+1; } else { P = (P + ((A & 1) ? B : 0)) & 0x1ff; } A = ((P & 1)<<7) | (A>>1); P = ((P&0x100) | (P >> 1)) & 0x1ff; } // Checking int32_t calc = ((P & 0xff)<<8) | A; facit = ((int8_t)ia) * ((int8_t)ib); facit &= 0xffff; if ( facit != calc ) { printf( "No luck. ia=%d ib=%d facit=%d calc=%d\n", ia, ib, facit,calc); return 1; } } } printf( "variant 2 Ok\n" ); for ( int j = 0; j < 2; j++ ) { if ( j == 0 ) printf( "Restoring division: Unsigned/Unsigned: ia/ib " ); else printf( "Non-restoring division: Unsigned/Unsigned: ia/ib " ); for ( ia = 0; ia < 0x100; ia += 1 ) { for ( ib = 0; ib < 0x100; ib++ ) { iterations++; uint16_t tmp; if ( j == 0 ) tmp = divu_restoring( ia, ib ); else tmp = divu_nonrestoring( ia, ib ); uint8_t P = tmp >> 8; uint8_t A = tmp; int facit; if ( ib == 0 ) { facit = 0xff; } else { facit = ia/ib; } if ( facit != A ) { printf( "Error. facit=%d A=%d\n", facit, A ); return 1; } // ib is divisor, // ia is dividend. // A is quotient // P is remainder if ( ia != ib * A + P ) { printf( "pError, does not follow RISCV spec\n" ); return 3; } } } printf( " Ok\n" ); if ( j == 0 ) printf( "Restoring division: Signed/Signed: sa/sb " ); else printf( "Non-restoring division: Signed/Signed: sa/sb " ); for ( ia = 0x0; ia < 0x100; ia += 1 ) { for ( ib = 0; ib < 0x100; ib++ ) { iterations++; // Preliminaries int signA = ia>>7; int signB = ib>>7; int signresult = signA ^ signB; uint8_t A = signA ? (ia^0xff)+1 : ia; uint8_t B = signB ? (ib^0xff)+1 : ib; // The real routine, unsigned divide. uint16_t tmp; if ( j == 0 ) tmp = divu_restoring( A, B ); else tmp = divu_nonrestoring( A, B ); uint8_t P = tmp >> 8; A = tmp; // Adjustments if ( signresult && ib != 0) A = (A^255)+1; if ( signA ) P = (P^255)+1; // // The rest is checking // int8_t sia = ia; int8_t sib = ib; int sA = (int8_t)A; int8_t sP = P; //printf( "%3d / %3d = %3d Remainder = %3d\n", sia, sib, sA, sP ); int facit; if ( ib == 0 ) { // Division by zero. Spec say: n/0 = -1 remainder = n facit = -1; } else if ( ib == 0xff && ia == 0x80 ) { // Special case, division overflow. Spec say: -128/-1 = -128 remainder = 0 facit = -128; } else { facit = sia/sib; } if ( facit != sA ) { printf( "%3d / %3d = %3d Remainder = %3d signresult=%d ", sia, sib, sA, sP, signresult ); printf( "Facit %d/%d = %d Reaminder = %d\n", sia, sib, facit, sia - facit * sib ); printf( "tError. facit=%d A=%d\n", facit, A ); return 1; } // ib is divisor, // ia is dividend. // A is quotient // P is remainder if ( ib == 0xff && ia == 0x80 ) { // Special case, division overflow. Spec say: -128/-1 = -128 remainer = 0 if ( sA != -128 || sP != 0 ) { printf( "Division overflow failed\n" ); return 0; } } else if ( sia != sib * sA + sP ) { //printf( "ia=%3d / ib=%3d = sA = %3d Remainder = sP = %3d signresult=%d\n", ia, ib, sA, sP, signresult ); printf( "Calc %d/%d = %d Reminder = %d\n", sia, sib, sA, sP ); printf( "Facit %d/%d = %d Reminder = %d\n", sia, sib, facit, sia - facit * sib ); printf( "xError, does not follow RISCV spec\n" ); return 1; } } } printf( " Ok\n" ); } if ( iterations != 0x90000 ) printf( "Not all tests done. 0x%x iterations\n", iterations ); return 0; } /* * isMULHU * | A[0] * | | Di[31] == DAT_O[31] == signB * | | | rcysign = signP * | | | | sp2 sp1 sp0 * 0 0 x 0 0 1 0 * 0 0 x 1 0 1 1 * 0 1 0 0 1 0 0 * 0 1 0 1 1 0 1 * 0 1 1 0 1 0 1 * 0 1 1 1 1 0 0 * 1 x x x 1 1 x * * cmb_cysignP = (~sp2 & sp1 & sp0) | (sp2 & ~sp1 & (sp0^alucy[33])) | (sp2 & sp1 & alucy[33]) * * Idea. For unsigned division, nonrestoring. * Prepare invB to Rjj. * Wwhen SHLQ, shift signP inverted into A[0], shift Q[31] into signP, shift A[31] into Q[0] * Test on A[0] to either subtract B (add invB+1 in 33 bits) * or to add B zero-extended in 33 bits * * alu_carryout correct * sp[2:1] | cmb_cysignP * 00 0 * 01/10 1 A[0]^signP^alucy[33] P <= P+{A[0],B} in 33 bits for add B zero-extended OR | For DIV[U]/REM[U] * P <= P+{A[0],Rjj}+1 in 33 bits to subtract B | * signP P <= P+0 in 33 bits when A[0] == 0. | For MULH/MULHSU * signB^signP^alucy[33] P <= P+signext(B) in 33 bits when A[0] == 1. | * 11 0 alucy[33] For MULHU and microcode SHLQ * * sp2 = A[0] | isMULHU * sp1 = ~A[0] | isMULHU * sp0 = ~isDIVREM * ((~A[0] & rcysign) | (A[0] & (DAT_O[31]^rcysign))) * | isDIVREM * (A[0]^rcysign) * isMULHU = INSTR[25] & ~INSTR[6] & INSTR[5] & ~FUNC3[2] & FUNC3[1] & FUNC3[0] * isDIVREM= INSTR[25] & ~INSTR[6] & INSTR[5] & FUNC3[2] * isMULHU and isDIVREM are also active for certain LUI instructions. * * The ouput rcysignP is used by sra_msb: * * FUNC7[5] * |FUNC7[0] * || sra_msb * 00 0 SRL/SRLI, logical shift right * 01 signP MULHU/MULH/MULSU * 10 ADR_O[31] SRA/SRAI * 11 x * */
the_stack_data/151704888.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. * * Neither the name of Google, Inc. nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include <dirent.h> #include <errno.h> #include <fcntl.h> #include <libgen.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <pwd.h> #include <sys/stat.h> #define BUF_MAX 1024 #define CMD_DISPLAY_MAX (9 + 1) #define USER_DISPLAY_MAX (10 + 1) struct pid_info_t { pid_t pid; char user[USER_DISPLAY_MAX]; char cmdline[CMD_DISPLAY_MAX]; char path[PATH_MAX]; ssize_t parent_length; }; static void print_header() { printf("%-9s %5s %10s %4s %9s %18s %9s %10s %s\n", "COMMAND", "PID", "USER", "FD", "TYPE", "DEVICE", "SIZE/OFF", "NODE", "NAME"); } static void print_type(char *type, struct pid_info_t* info) { static ssize_t link_dest_size; static char link_dest[PATH_MAX]; strlcat(info->path, type, sizeof(info->path)); if ((link_dest_size = readlink(info->path, link_dest, sizeof(link_dest)-1)) < 0) { if (errno == ENOENT) goto out; snprintf(link_dest, sizeof(link_dest), "%s (readlink: %s)", info->path, strerror(errno)); } else { link_dest[link_dest_size] = '\0'; } // Things that are just the root filesystem are uninteresting (we already know) if (!strcmp(link_dest, "/")) goto out; printf("%-9s %5d %10s %4s %9s %18s %9s %10s %s\n", info->cmdline, info->pid, info->user, type, "???", "???", "???", "???", link_dest); out: info->path[info->parent_length] = '\0'; } // Prints out all file that have been memory mapped static void print_maps(struct pid_info_t* info) { FILE *maps; size_t offset; char device[10]; long int inode; char file[PATH_MAX]; strlcat(info->path, "maps", sizeof(info->path)); maps = fopen(info->path, "r"); if (!maps) goto out; while (fscanf(maps, "%*x-%*x %*s %zx %5s %ld %4096s\n", &offset, device, &inode, file) == 4) { // We don't care about non-file maps if (inode == 0 || !strcmp(device, "00:00")) continue; printf("%-9s %5d %10s %4s %9s %18s %9zd %10ld %s\n", info->cmdline, info->pid, info->user, "mem", "???", device, offset, inode, file); } fclose(maps); out: info->path[info->parent_length] = '\0'; } // Prints out all open file descriptors static void print_fds(struct pid_info_t* info) { static char* fd_path = "fd/"; strlcat(info->path, fd_path, sizeof(info->path)); int previous_length = info->parent_length; info->parent_length += strlen(fd_path); DIR *dir = opendir(info->path); if (dir == NULL) { char msg[BUF_MAX]; snprintf(msg, sizeof(msg), "%s (opendir: %s)", info->path, strerror(errno)); printf("%-9s %5d %10s %4s %9s %18s %9s %10s %s\n", info->cmdline, info->pid, info->user, "FDS", "", "", "", "", msg); goto out; } struct dirent* de; while ((de = readdir(dir))) { if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) continue; print_type(de->d_name, info); } closedir(dir); out: info->parent_length = previous_length; info->path[info->parent_length] = '\0'; } static void lsof_dumpinfo(pid_t pid) { int fd; struct pid_info_t info; struct stat pidstat; struct passwd *pw; info.pid = pid; snprintf(info.path, sizeof(info.path), "/proc/%d/", pid); info.parent_length = strlen(info.path); // Get the UID by calling stat on the proc/pid directory. if (!stat(info.path, &pidstat)) { pw = getpwuid(pidstat.st_uid); if (pw) { strlcpy(info.user, pw->pw_name, sizeof(info.user)); } else { snprintf(info.user, USER_DISPLAY_MAX, "%d", (int)pidstat.st_uid); } } else { strcpy(info.user, "???"); } // Read the command line information; each argument is terminated with NULL. strlcat(info.path, "cmdline", sizeof(info.path)); fd = open(info.path, O_RDONLY); if (fd < 0) { fprintf(stderr, "Couldn't read %s\n", info.path); return; } char cmdline[PATH_MAX]; int numRead = read(fd, cmdline, sizeof(cmdline) - 1); close(fd); if (numRead < 0) { fprintf(stderr, "Error reading cmdline: %s: %s\n", info.path, strerror(errno)); return; } cmdline[numRead] = '\0'; // We only want the basename of the cmdline strlcpy(info.cmdline, basename(cmdline), sizeof(info.cmdline)); // Read each of these symlinks print_type("cwd", &info); print_type("exe", &info); print_type("root", &info); print_fds(&info); print_maps(&info); } int lsof_main(int argc, char *argv[]) { long int pid = 0; char* endptr; if (argc == 2) { pid = strtol(argv[1], &endptr, 10); } print_header(); if (pid) { lsof_dumpinfo(pid); } else { DIR *dir = opendir("/proc"); if (dir == NULL) { fprintf(stderr, "Couldn't open /proc\n"); return -1; } struct dirent* de; while ((de = readdir(dir))) { if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) continue; // Only inspect directories that are PID numbers pid = strtol(de->d_name, &endptr, 10); if (*endptr != '\0') continue; lsof_dumpinfo(pid); } closedir(dir); } return 0; }