file
stringlengths
18
26
data
stringlengths
2
1.05M
the_stack_data/178264913.c
/* PR rtl-optimization/17027 */ /* Origin: dbk <[email protected]> */ /* Testcase by Christian Ehrhardt <[email protected]> */ int bar(void); void baz (void) __attribute__ ((noreturn)); /* noreturn is required */ void foo (void) { while (bar ()) { switch (1) { default: baz (); } } }
the_stack_data/117328228.c
#include <stdio.h> int main() { int i, j; int n, m, x, y; int a[100005], b[100005]; int u[100005], v[100005]; scanf("%d%d%d%d", &n, &m, &x, &y); for ( i = 0; i < n; i++ ) scanf("%d", &a[i]); for ( i = 0; i < m; i++ ) scanf("%d", &b[i]); int ans = 0; i = j = 0; while ( i < n && j < m ) { if ( a[i]-x > b[j] ) j++; else if ( a[i]+y < b[j] ) i++; else { u[ans] = ++i; v[ans++] = ++j; } } printf("%d\n", ans); for ( i = 0; i < ans; i++ ) printf("%d %d\n", u[i], v[i]); return 0; }
the_stack_data/67325321.c
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s void clang_analyzer_eval(int); void clang_analyzer_checkInlined(int); int test1_f1(void) { int y = 1; y++; clang_analyzer_checkInlined(1); // expected-warning{{TRUE}} return y; } void test1_f2(void) { int x = 1; x = test1_f1(); if (x == 1) { int *p = 0; *p = 3; // no-warning } if (x == 2) { int *p = 0; *p = 3; // expected-warning{{Dereference of null pointer (loaded from variable 'p')}} } } // Test that inlining works when the declared function has less arguments // than the actual number in the declaration. void test2_f1() {} int test2_f2(void); void test2_f3(void) { test2_f1(test2_f2()); // expected-warning{{too many arguments in call to 'test2_f1'}} } // Test that inlining works with recursive functions. unsigned factorial(unsigned x) { if (x <= 1) return 1; return x * factorial(x - 1); } void test_factorial(void) { if (factorial(3) == 6) { int *p = 0; *p = 0xDEADBEEF; // expected-warning {{null}} } else { int *p = 0; *p = 0xDEADBEEF; // no-warning } } void test_factorial_2(void) { unsigned x = factorial(3); if (x == factorial(3)) { int *p = 0; *p = 0xDEADBEEF; // expected-warning {{null}} } else { int *p = 0; *p = 0xDEADBEEF; // no-warning } } // Test that returning stack memory from a parent stack frame does // not trigger a warning. static char *return_buf(char *buf) { return buf + 10; } void test_return_stack_memory_ok(void) { char stack_buf[100]; char *pos = return_buf(stack_buf); (void) pos; } char *test_return_stack_memory_bad(void) { char stack_buf[100]; char *x = stack_buf; return x; // expected-warning {{stack memory associated}} } // Test that passing a struct value with an uninitialized field does // not trigger a warning if we are inlining and the body is available. struct rdar10977037 { int x, y; }; int test_rdar10977037_aux(struct rdar10977037 v) { return v.y; } int test_rdar10977037_aux_2(struct rdar10977037 v); int test_rdar10977037(void) { struct rdar10977037 v; v.y = 1; v. y += test_rdar10977037_aux(v); // no-warning return test_rdar10977037_aux_2(v); // expected-warning {{Passed-by-value struct argument contains uninitialized data}} } // Test inlining a forward-declared function. // This regressed when CallEvent was first introduced. int plus1(int x); void test(void) { clang_analyzer_eval(plus1(2) == 3); // expected-warning{{TRUE}} } int plus1(int x) { return x + 1; } void never_called_by_anyone(void) { clang_analyzer_checkInlined(0); // no-warning } void knr_one_argument(a) int a; { } void call_with_less_arguments(void) { knr_one_argument(); // expected-warning{{too few arguments}} expected-warning{{Function taking 1 argument is called with fewer (0)}} }
the_stack_data/916968.c
#include<stdio.h> int main() { printf("Hello World!"); return 0; }
the_stack_data/165769497.c
/* D:\C\dnamrna.c Avinal Kumar January 30, 2019 DNA RNA strand creating simulation */ #include <stdio.h> #include <malloc.h> enum dna_base { A, T, G, C }; struct node { enum dna_base base1; enum dna_base base2; struct node *next; struct node *prev; }; typedef struct node nucleotide; nucleotide *start = NULL; nucleotide *polymerisation(nucleotide *); nucleotide *add_nucleotide(nucleotide *); nucleotide *display(nucleotide *); int main(int argc, char const *argv[]) { int option; printf("#### DNA ####\n"); printf("1. Enter one strand of DNA\n"); printf("2. Add new nucleotide\n"); scanf("%d", &option); switch (option) { case 1: start = polymerisation(start); break; case 2: display(start); break; default: break; } return 0; } nucleotide *polymerisation(nucleotide *first) { nucleotide *new_nucleotide, *var_nucleotide; int size; printf("Enter the length of the DNA strand\n"); scanf("%d", &size); char strand[size]; printf("Enter the half strand DNA code\n"); fgets(strand, size, stdin); for (int i = 0; i < size; i++) { new_nucleotide = (nucleotide *)malloc(sizeof(nucleotide)); if (strand[i] == 'A') { (*new_nucleotide).base1 = A; } else if (strand[i] == 'G') { (*new_nucleotide).base1 = G; } else if (strand[i] == 'T') { (*new_nucleotide).base1 = T; } else if (strand[i] == 'C') { (*new_nucleotide).base1 = C; } (*new_nucleotide).next = NULL; if (first == NULL) { (*new_nucleotide).prev = NULL; first = new_nucleotide; } else { var_nucleotide = first; while ((*var_nucleotide).next != NULL) { var_nucleotide = (*new_nucleotide).next; } (*var_nucleotide).next = new_nucleotide; (*new_nucleotide).prev = var_nucleotide; (*new_nucleotide).next = NULL; } } return (first); } nucleotide *display(nucleotide *first) { nucleotide *var_nucleotide; var_nucleotide = first; while ((*var_nucleotide).next != NULL) { printf("%d____%d\n", &(*var_nucleotide).base1, &(*var_nucleotide).base2); printf(" | |\n"); } printf("%d____%d\n"); return (first); }
the_stack_data/897619.c
#include <wchar.h> float wcstof(const wchar_t * restrict nptr, wchar_t ** restrict endptr) { (void)nptr; (void)endptr; return 0; } /* STDC(199901) */
the_stack_data/43887711.c
#include <stdio.h> #define sq(x) (x * x) int main() { int num; printf("Enter a num: "); scanf("%d", &num); printf("The sq of the num is - %d", sq(num)); return 0; }
the_stack_data/220454791.c
#include <stdio.h> void main () { }
the_stack_data/52038.c
#include <stdio.h> #include <stdlib.h> #include <assert.h> #ifndef CS #define CS 4098 #endif #define CacheSZ CS*1024/sizeof(double) #include <stdlib.h> #include <sys/time.h> #include <sys/resource.h> double GetWallTime(void) { struct timeval tp; static long start=0, startu; if (!start) { gettimeofday(&tp, NULL); start = tp.tv_sec; startu = tp.tv_usec; return(0.0); } gettimeofday(&tp, NULL); return( ((double) (tp.tv_sec - start)) + (tp.tv_usec-startu)/1000000.0 ); } /* Collect multiple timing samples */ #ifndef MT #define MT 10 #endif #ifndef RANDSEED #define RANDSEED 1 #endif /* routine to measure performance of*/ void strmm(int m,int n,float alpha,int lda,int ldb,float beta,float* a,float* b) ; /* macro for the value of routien parameter */ #ifndef MS #define MS 200 #endif /* macro for the value of routien parameter */ #ifndef NS #define NS 200 #endif int main(int argc, char **argv) { /* arrays for storing results of multiple timings */ double __timer_diff[MT]; /* induction variable for Multiple timing */ int __pt_MT_ivar; double __timer_min,__timer_avg,__timer_max; /* variables to support cache flushing */ double* __pt_flush_buffer; double __pt_flush_bufferVal; /* variable for computing MFLOPS */ double __pt_flops; /* induction variables */ int __pt_i0, __pt_i1, __pt_i2; /*variables to store starting and ending of timing */ double __timer_begin, __timer_end; /* Declaring parameters of the routine */ int m; int n; float alpha; int lda; int ldb; float beta; float* a; float* b; float* a_buf; int a_size; float* b_buf; int b_size; /* parameter initializations */ srand(RANDSEED); m = MS; n = NS; lda = m; ldb = n; alpha = 1.0; a_size=16*((15+m*m)/16); a_buf = calloc(a_size, sizeof(float)); b_size=16*((15+m*n)/16); b_buf = calloc(b_size, sizeof(float)); #define DO_FLUSH 1 __pt_flush_buffer = malloc(CacheSZ * sizeof(double)); for(__pt_i0=0; __pt_i0 < CacheSZ; ++__pt_i0) { __pt_flush_buffer[__pt_i0] = ((__pt_i0 % 3) == 2) ? -1 : __pt_i0 % 2; } /* Multiple Timings */ for (__pt_MT_ivar=0; __pt_MT_ivar<MT; ++__pt_MT_ivar) { srand(RANDSEED); for (__pt_i0=0; __pt_i0<a_size ; ++__pt_i0) { a_buf[__pt_i0] = rand();; } a = a_buf; for (__pt_i0=0; __pt_i0<b_size ; ++__pt_i0) { b_buf[__pt_i0] = rand();; } b = b_buf; /* code to flush the cache */ __pt_flush_bufferVal = 0; for (__pt_i0=0; __pt_i0 < CacheSZ; ++__pt_i0) __pt_flush_bufferVal += __pt_flush_buffer[__pt_i0]; assert(__pt_flush_bufferVal < 10); /* Timer start */ __timer_begin = GetWallTime(); strmm (m,n,alpha,lda,ldb,beta,a,b); /* Timer end */ __timer_end = GetWallTime(); /* result of a single timing */ __timer_diff[__pt_MT_ivar] = __timer_end-__timer_begin; } /* flops of computation */ __pt_flops = m*n+m*m*m/2+m*m; /* Compute minimum of multiple timings */ __timer_min=__timer_diff[0]; __timer_max=__timer_diff[0]; __timer_avg=__timer_diff[0]; for (__pt_MT_ivar=1; __pt_MT_ivar<MT; ++__pt_MT_ivar) { if (__timer_min > __timer_diff[__pt_MT_ivar]) __timer_min = __timer_diff[__pt_MT_ivar]; if (__timer_max < __timer_diff[__pt_MT_ivar]) __timer_max = __timer_diff[__pt_MT_ivar]; __timer_avg += __timer_diff[__pt_MT_ivar]; } __timer_avg /= MT; /* output timing results */ for (__pt_MT_ivar=0; __pt_MT_ivar < MT; ++__pt_MT_ivar) { printf("time in seconds [%d]: %.15f\n", __pt_MT_ivar, __timer_diff[__pt_MT_ivar]); } printf("Minimum time in seconds: %.15f\n", __timer_min); printf("Maximum time in seconds: %.15f\n", __timer_max); printf("Average time in seconds: %.15f\n", __timer_avg); printf("Maximum MFLOPS: %.15f\n", __pt_flops/__timer_min/1000000); printf("Minimum MFLOPS: %.15f\n", __pt_flops/__timer_max/1000000); printf("Average MFLOPS: %.15f\n", __pt_flops/__timer_avg/1000000); printf("Configuration\n" "-------------\n"); printf("CPU MHZ: 2160\n"); printf("Cache Size: %d\n", CS); #ifdef DO_FLUSH printf("Cache Flush Method: generic\n"); #else printf("Cache Flush Method: none\n"); #endif printf("ARCH: generic\n"); printf("mt: %d\n", MT); printf("Random Seed: %d\n", RANDSEED); return(0); }
the_stack_data/95238.c
// 編號 : L3_20-1106N1v0_Loop_實心圓繪製_unF.c // 程式類別 : C語言 // 基礎題 : 迴圈練習 ( 難度 ★★★☆☆ ) // 題目 : 實心圓繪製 // 時間:NULL ( 不限 ) //最佳 3s內 // 內存大小 : 128MB // 題目內容 : // 繪製一個實心圓 // 輸入 : Null(無) // 輸出 : 實心圓 // Sample input : Null(無) // Sample output : 實心圓 #include <stdio.h> #include <stdlib.h> //圓形半徑 const int R = 20; //副程式宣告 int circle(int x, int y); //主程式 int main(void) { for(int y = 0; y <= 2*R; ++y) { for(int x = 0; x <= 2*R; ++x) { //判斷是否繪製實心圓 if (circle(x, y)) { printf(" "); } else { printf(" *"); } } printf("\n"); } return 0; } //座標檢查,繪製判斷 int circle(int x, int y) { //大於 則繪製實心圓 return (((x-R)*(x-R) + (y-R)*(y-R)) > R*R) ? 1 : 0; //三目運算法則 }
the_stack_data/220455419.c
// // Created by weibin on 2022-03-06. // #include "stdio.h" int main() { int b[5] = {1, 2, 3, 4, 5}; int *p = b; printf("p->%p, p+1 -> %p,p+2 -> %p \n", p, p + 1, p + 2); printf("p:%d,*(p+1):%d,*(p+2):%d \n", *p, *(p + 1), *(p + 2)); printf("b:%d,*(b+1):%d,*(b+2):%d \n", *b, *(b + 1), *(b + 2)); return 0; }
the_stack_data/43886499.c
#include <stdio.h> #include <stdlib.h> #include <time.h> int i, j, p = 0, a = 1, jogador, proximo, vez = 0, player1 = 0, player2 = 0; char x[30] = {'O', 'X', 'O', 'X', 'O', 'X', 'O', 'X', 'O', 'X', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, o[30] = {'X', 'O', 'X', 'O', 'X', 'O', 'X', 'O', 'X', 'O', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, m[30], pe, ope; void Senet(){ printf("\n\t\t\t\t\t------------------------------------"); printf("\n\t\t\t\t\t---------------Senet----------------"); printf("\n\t\t\t\t\t------------------------------------"); } int sorteiaEstilete(){ //Sorteio do estiletes int s; srand(time(NULL) * a); s = rand() % 2 + rand() % 2 + rand() % 2 + rand() % 2; a++; if(s == 0) s = 6; return s; } int escolhePeca(){ //O jogador sorteado escolhe a peca que deseja usar char peca; printf("Escolha uma peca [x/o]: "); do{ scanf("%c", &peca); getchar(); if(peca != 'x' && peca != 'o') printf("\nPeca invalida\n"); }while(peca != 'x' && peca != 'o'); if(peca == 'x'){ for (i = 0; i < 30; i++){ m[i] = x[i]; p = 1; } }else{ for (i = 0; i < 30; i++) m[i] = o[i]; } return p; } void tabuleiro(){ //Printa o tabuleiro system("cls"); printf("\n"); printf(" 0 1 2 3 4 5 6 7 8 9\n"); for(i = 0; i < 10; i++) printf(" [ %c ] ", m[i]); printf("\n"); printf(" 19 18 17 16 15 14 13 12 11 10\n"); for(i = 19; i >= 10; i--) printf(" [ %c ] ", m[i]); printf("\n"); printf(" 20 21 22 23 24 25 26 27 28 29\n"); for(i = 20; i < 25; i++) printf(" [ %c ] ", m[i]); for(i = 25; i < 30; i++){ //Printa as letras das casas especiais if(m[i] == ' ') printf(" [ %c ] ", 40 + i); else printf(" [ %c ] ", m[i]); } printf("\n\n"); printf("\nJogador 1 = %c\tJogador 2 = %c\n\n", pe, ope); printf("\n\t\t\t\t Placar\n\n"); printf("\t\t\tJogador 1 = %d\tJogador 2 = %d\n\n", player1, player2); } int conferePri(char peca){ //Confere se tem peca na primeira fileira for(i = 0; i < 10; i++){ if(m[i] == peca) return 1; } return 0; } int verificaMovimento(int peca, int sorteio){ if(peca < 0 || peca > 29) //Verifica se a peca escolhida esta no tabuleiro return 1; if((jogador == 1 && m[peca] != pe) || (jogador == 2 && m[peca] != ope)) //Verifica se a peca escolhida e uma peca do jogador return 1; if((jogador == 1 && m[peca + sorteio] == pe) || (jogador == 2 && m[peca + sorteio] == ope)) //Verifica se a casa destino nao possui uma peca do jogador return 1; if((jogador == 1 && m[peca + sorteio] == ope && (m[peca + sorteio - 1] == ope || m[peca + sorteio + 1] == ope)) || //Verifica se a casa destino possui uma peca protegida (jogador == 2 && m[peca + sorteio] == pe && (m[peca + sorteio - 1] == pe || m[peca + sorteio + 1] == pe))) return 1; if((peca + sorteio == 25 || peca + sorteio == 27 || peca + sorteio == 28) && m[peca + sorteio] != ' ') //Verifica se a casa destino e uma casa especial e possui uma peca return 1; if(peca + sorteio > 29 && m[29] == m[peca] && conferePri(m[peca]) == 1) //Verifica se tem peca na primeira fileira return 1; return 0; } int testaMovimento(int sorteio){ //Verifica se tem algum movimento possivel para o jogador for(i = 0; i < 30; i++){ if(((jogador == 1 && m[i] == pe) || (jogador == 2 && m[i] == ope)) && verificaMovimento(i, sorteio) == 0) return 0; } return 1; } void move(int peca, int sorteio){ char aux; if(peca + sorteio == 26){ //Se a peca cair na casa 26 ela volta pra casa 14, caso jc esteja ocupada a peca volta para o inicio do jogo e anda a quantidade tirada nos estiletes if (m[14] == ' ') m[14] = m[peca]; else{ j = sorteio; while(m[j] != ' ') j++; m[j] = m[peca]; } m[peca] = ' '; } if(peca + sorteio >= 29){ //Se o jogador retirar uma peca do jogo o placar aumenta em 1, senao a peca fica na casa 29 if(conferePri(m[peca]) == 0){ m[peca] = ' '; if (jogador == 1) player1++; if (jogador == 2) player2++; }else if(m[29] != m[peca]){ aux = m[peca]; m[peca] = m[29]; m[29] = aux; } } if(peca + sorteio < 29 && peca + sorteio != 26){ //Move as pecas aux = m[peca]; m[peca] = m[peca + sorteio]; m[peca + sorteio] = aux; } } void movimento(){ int aux, peca, sorteio; sorteio = sorteiaEstilete(); if(vez == 1){ //A primeira jogada do segundo jogador deve ser a sua ultima peca for(i = 9; i >= 0; i--){ if((jogador == 1 && m[i] == pe) || (jogador == 2 && m[i] == ope)){ move(i, sorteio); tabuleiro(); break; } } vez++; return; } if(testaMovimento(sorteio) == 1){ //Se nao ha jogadas possiveis para um jogador, a vez e passada para o outro printf("\nNao ha jogadas possiveis\n"); if(jogador == 1) jogador = 2; else jogador = 1; printf("\njogador = %d vez=%d", jogador, vez); return; } while((sorteio == 1 || sorteio == 4 || sorteio == 6) && player1 < 5 && player2 < 5){ //Enquanto o jogador tirar 1,4 ou 6 nos estiletes ele continua jogando printf("\n\nVez do jogador %d", jogador); printf("\n\nEstilete = %d\n\n", sorteio); printf("\nQual peca deseja mover? "); scanf("%d", &peca); while(verificaMovimento(peca, sorteio) == 1){ //Verifica se o movimento e valido tabuleiro(); printf("\n\nVez do jogador %d", jogador); printf("\n\nEstilete = %d\n\n", sorteio); printf("\nMovimento invalido\n\nDigite novamente:"); scanf("%d", &peca); } move(peca, sorteio); //Move a peca tabuleiro(); sorteio = sorteiaEstilete(); } if(player1 >= 5 || player2 >= 5) //Se o placar chegar a 5, sai do looping return; printf("\n\nVez do jogador %d", jogador); //Se o jogador tirar 2 ou 3 nos estiletes, ele move a peca mais uma vez printf("\n\nEstilete = %d\n\n", sorteio); printf("\nQual peca deseja mover? "); scanf("%d", &peca); while(verificaMovimento(peca, sorteio) == 1){ //Verifica se o movimento e valido tabuleiro(); printf("\n\nVez do jogador %d", jogador); printf("\n\nEstilete = %d\n\n", sorteio); printf("\nMovimento invalido\n\nDigite novamente:"); scanf("%d", &peca); } move(peca, sorteio); //Move a peca pela ultima vez tabuleiro(); vez++; if(jogador == 1) //Passa a vez jogador = 2; else jogador = 1; } int main(int argc, char *argv[]){ int p, sorteio; system("color 0A"); Senet(); printf("\n\n\n\n\t\t\t\tSorteando o primeiro a jogar...\n\n"); while(sorteio != 1){ //O primeiro jogador a tirar 1 comeca jogando sorteio = sorteiaEstilete(); if(sorteio == 1){ printf("\nJogador 1 comeca!\n"); jogador = 1; break; } sorteio = sorteiaEstilete(); if(sorteio == 1){ printf("\nJogador 2 comeca!\n"); jogador = 2; break; } } p = escolhePeca(); if(p == 1 && jogador == 1){ //Salva a peca de cada jogador pe = 'X'; ope = 'O'; }else if(p == 1 && jogador == 2){ pe = 'O'; ope = 'X'; }else if(p == 0 && jogador == 1){ pe = 'O'; ope = 'X'; }else if(p == 0 && jogador == 2){ pe = 'X'; ope = 'O'; } tabuleiro(); while(player1 < 5 && player2 < 5) //Enquanto os pontos sao menores que 5, continua a movimentacao movimento(); system("cls"); if (player1 == 5) //Quando um dos jogadores atinge os 5 pontos o jogo encerra printf("\n\n\n\t\t\t\tJOGADOR 1 GANHOU!!!!\n\n\n"); else printf("\n\n\n\t\t\t\tJOGADOR 2 GANHOU!!!!\n\n\n"); return 0; }
the_stack_data/156392032.c
/* Autor: jorgeaah Compilador: gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Compilado: gcc ExamenFinal.c -lm Fecha: jue 13 may 2021 10:34:08 CST Librerias: stdio, math, stdlib Resumen: El programa simula el movimiento de 3 cohetes. Entrada: Conjunto de constantes para cada cohete. Salida: Un archivo .dat para cada cohete con los datos necesarios para graficar y la información básica de la simulación. */ //Librerias #include <stdio.h> #include <math.h> #include <stdlib.h> //Constantes "universales" const float G = 6.693e-11F; const float R_T = 6.378e6F; const float M_T = 5.9736e24F; const float R = 287.06F; const float L = 6.5e-3F; const float g_0 = 9.81F; const float T_0 = 288.15F; const float P_0 = 101325.0F; //Método único de simulación para los tres cohetes. void simulacion_cohete(char *nombre, float E_0, float TSFC, float CD, float A, float m_0, float m_f0); //Método para calcular la masa del cohete. float masa_cohete(float t, float m_0, float m_f0, float TSFC, float E_0); //Método para calcular la gravedad. float gravedad(float y); //Método para calcular la fuerza de fricción. float friccion(float y, float derivative_y, float CD, float A); //Método para calcular la densidad del aire. float densidad(float y); int main() { printf("Bienvenido!!!\n"); char nombre1[20] = "Ah Mun"; char nombre2[20] = "Ahua Kin"; char nombre3[20] = "Chac"; simulacion_cohete(nombre1, 3e7F, 3.248e-4F, 61.27F, 201.06F, 1.1e5F, 1.5e6F); simulacion_cohete(nombre2, 2.7e7F, 2.248e-4F, 61.27F, 201.06F, 1.1e5F, 1.5e6F); simulacion_cohete(nombre3, 2.5e7F, 2.248e-4F, 70.25F, 215.00F, 1.8e5F, 2.1e6F); return 0; } //Código función para calcular la densidad del aire. float densidad(float y) { if (y > (T_0/L)) { return 0.0F; } return (P_0/(R*T_0))*pow(1.0F-L*y/T_0, g_0/(R*L)); } //Código función para calcular la fuerza de fricción. float friccion(float y, float derivative_y, float CD, float A) { return 0.5F*densidad(y)*CD*A*derivative_y*abs(derivative_y); } //Código función para calcular la gravedad. float gravedad(float y) { return G*M_T/pow(R_T+y, 2.0F); } //Código para calcular la masa del cohete. float masa_cohete(float t, float m_0, float m_f0, float TSFC, float E_0) { //Se calcula la masa del combustible con una integral. float masa_combustible = m_f0 - TSFC*E_0*t; //Comprobación de que no sea una masa negativa. if (masa_combustible < 0.0F) { masa_combustible = 0.0F; } return masa_combustible + m_0; } void simulacion_cohete(char *nombre, float E_0, float TSFC, float CD, float A, float m_0, float m_f0) { //Valores iniciales en el método de Euler. float derivative_y = 0.0F; //O velocidad... float y = 0.57F; float t = 0.0F; //Apertura del fichero para mostrar resultados. FILE *fp; fp = fopen(nombre, "w+"); //Guardando los datos iniciales. fprintf(fp, "%.10ef %.10ef %.10ef\n", t, y, derivative_y); //Duración del empuje (Calculado mediante integracion): float t_empuje = m_f0/(TSFC*E_0); //Variable para almacenar la altura máxima. float altura_maxima = 0.0F; //Presentación de los datos del cohete en consola. printf("-------------------------------------------------------------------\n"); printf("Nombre del cohete: %s\n", nombre); printf("Empuje del cohete [N]: %.2ef\n", E_0); printf("Consumo especifico del empuje [kg/N*s]: %.2ef\n", TSFC); printf("Coeficiente de forma: %.2f\n", CD); printf("Sección transversal del cohete [m^2]: %.2f\n", A); printf("Masa del cohete vacío [kg]: %.2ef\n", m_0); printf("Masa inicial del combustible [kg]: %.2ef\n", m_f0); //Comienzo del bucle del Euler. for(;;) { //La fuerza total según la ecuación de las leyes de Newton. float fuerza = -friccion(y, derivative_y, CD, A); fuerza -= masa_cohete(t, m_0, m_f0, TSFC, E_0)*gravedad(y); //Agregando el término del empuje. ¡Debe ser condicional al combustible! if (t < t_empuje) { fuerza += E_0; } //Calculando la aceleración. float aceleracion = fuerza/masa_cohete(t, m_0, m_f0, TSFC, E_0); //Calculando los nuevos valores. Este es el paso de Euler. float promedio_derivative_y = derivative_y; //Nueva velocidad. derivative_y += aceleracion*0.1F; promedio_derivative_y += derivative_y; promedio_derivative_y = promedio_derivative_y*0.5F; //Nueva altura, para ser más exactos usamos el promedio de la velocidad. y += promedio_derivative_y*0.1F; //Condición para mejorar la "altura maxima". if (y > altura_maxima) { altura_maxima = y; } //Nuevo tiempo. t += 0.1F; //Almacenamiento de los nuevos datos. fprintf(fp, "%.10ef %.10ef %.10ef", t, y, derivative_y); //Condición de regreso a tierra. if (y < 0.0F) { printf("Altura máxima [m]: %.2ef\n", altura_maxima); printf("Tiempo de empuje [s]: %.2ef\n", t_empuje); printf("Tiempo hasta impacto [min]: %i\n", (int) (t/60.0F)); fclose(fp); return; } else { fprintf(fp,"\n"); //Esto se hace para evitar un problema con una linea vacía en gnuplot. //Solo se corre sino es el final de la simulación. } } }
the_stack_data/38662.c
/* DO NOT EDIT THIS FILE -- it is automagically generated. -*- C -*- */ #define _MALLOC_INTERNAL /* The malloc headers and source files from the C library follow here. */ /* Declarations for `malloc' and friends. Copyright 1990, 91, 92, 93, 95, 96 Free Software Foundation, Inc. Written May 1989 by Mike Haertel. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. The author may be reached (Email) at the address [email protected], or (US mail) as Mike Haertel c/o Free Software Foundation. */ #ifndef _MALLOC_H #define _MALLOC_H 1 #ifdef _MALLOC_INTERNAL #ifdef HAVE_CONFIG_H #include <config.h> #endif #if defined(_LIBC) || defined(STDC_HEADERS) || defined(USG) #include <string.h> #else #ifndef memset #define memset(s, zero, n) bzero ((s), (n)) #endif #ifndef memcpy #define memcpy(d, s, n) bcopy ((s), (d), (n)) #endif #endif #if defined (__GNU_LIBRARY__) || (defined (__STDC__) && __STDC__) #include <limits.h> #else #ifndef CHAR_BIT #define CHAR_BIT 8 #endif #endif #ifdef HAVE_UNISTD_H #include <unistd.h> #endif #endif /* _MALLOC_INTERNAL. */ #ifdef __cplusplus extern "C" { #endif #if defined (__cplusplus) || (defined (__STDC__) && __STDC__) #undef __P #define __P(args) args #undef __ptr_t #define __ptr_t void * #else /* Not C++ or ANSI C. */ #undef __P #define __P(args) () #undef const #define const #undef __ptr_t #define __ptr_t char * #endif /* C++ or ANSI C. */ #if defined (__STDC__) && __STDC__ #include <stddef.h> #define __malloc_size_t size_t #define __malloc_ptrdiff_t ptrdiff_t #else #define __malloc_size_t unsigned int #define __malloc_ptrdiff_t int #endif #ifndef NULL #define NULL 0 #endif /* Allocate SIZE bytes of memory. */ extern __ptr_t malloc __P ((__malloc_size_t __size)); /* Re-allocate the previously allocated block in __ptr_t, making the new block SIZE bytes long. */ extern __ptr_t realloc __P ((__ptr_t __ptr, __malloc_size_t __size)); /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */ extern __ptr_t calloc __P ((__malloc_size_t __nmemb, __malloc_size_t __size)); /* Free a block allocated by `malloc', `realloc' or `calloc'. */ extern void free __P ((__ptr_t __ptr)); /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */ #if ! (defined (_MALLOC_INTERNAL) && __DJGPP__ - 0 == 1) /* Avoid conflict. */ extern __ptr_t memalign __P ((__malloc_size_t __alignment, __malloc_size_t __size)); #endif /* Allocate SIZE bytes on a page boundary. */ #if ! (defined (_MALLOC_INTERNAL) && defined (emacs)) /* Avoid conflict. */ extern __ptr_t valloc __P ((__malloc_size_t __size)); #endif #ifdef _MALLOC_INTERNAL /* The allocator divides the heap into blocks of fixed size; large requests receive one or more whole blocks, and small requests receive a fragment of a block. Fragment sizes are powers of two, and all fragments of a block are the same size. When all the fragments in a block have been freed, the block itself is freed. */ #define INT_BIT (CHAR_BIT * sizeof(int)) #define BLOCKLOG (INT_BIT > 16 ? 12 : 9) #define BLOCKSIZE (1 << BLOCKLOG) #define BLOCKIFY(SIZE) (((SIZE) + BLOCKSIZE - 1) / BLOCKSIZE) /* Determine the amount of memory spanned by the initial heap table (not an absolute limit). */ #define HEAP (INT_BIT > 16 ? 4194304 : 65536) /* Number of contiguous free blocks allowed to build up at the end of memory before they will be returned to the system. */ #define FINAL_FREE_BLOCKS 8 /* Data structure giving per-block information. */ typedef union { /* Heap information for a busy block. */ struct { /* Zero for a large (multiblock) object, or positive giving the logarithm to the base two of the fragment size. */ int type; union { struct { __malloc_size_t nfree; /* Free frags in a fragmented block. */ __malloc_size_t first; /* First free fragment of the block. */ } frag; /* For a large object, in its first block, this has the number of blocks in the object. In the other blocks, this has a negative number which says how far back the first block is. */ __malloc_ptrdiff_t size; } info; } busy; /* Heap information for a free block (that may be the first of a free cluster). */ struct { __malloc_size_t size; /* Size (in blocks) of a free cluster. */ __malloc_size_t next; /* Index of next free cluster. */ __malloc_size_t prev; /* Index of previous free cluster. */ } free; } malloc_info; /* Pointer to first block of the heap. */ extern char *_heapbase; /* Table indexed by block number giving per-block information. */ extern malloc_info *_heapinfo; /* Address to block number and vice versa. */ #define BLOCK(A) (((char *) (A) - _heapbase) / BLOCKSIZE + 1) #define ADDRESS(B) ((__ptr_t) (((B) - 1) * BLOCKSIZE + _heapbase)) /* Current search index for the heap table. */ extern __malloc_size_t _heapindex; /* Limit of valid info table indices. */ extern __malloc_size_t _heaplimit; /* Doubly linked lists of free fragments. */ struct list { struct list *next; struct list *prev; }; /* Free list headers for each fragment size. */ extern struct list _fraghead[]; /* List of blocks allocated with `memalign' (or `valloc'). */ struct alignlist { struct alignlist *next; __ptr_t aligned; /* The address that memaligned returned. */ __ptr_t exact; /* The address that malloc returned. */ }; extern struct alignlist *_aligned_blocks; /* Instrumentation. */ extern __malloc_size_t _chunks_used; extern __malloc_size_t _bytes_used; extern __malloc_size_t _chunks_free; extern __malloc_size_t _bytes_free; /* Internal versions of `malloc', `realloc', and `free' used when these functions need to call each other. They are the same but don't call the hooks. */ extern __ptr_t _malloc_internal __P ((__malloc_size_t __size)); extern __ptr_t _realloc_internal __P ((__ptr_t __ptr, __malloc_size_t __size)); extern void _free_internal __P ((__ptr_t __ptr)); #endif /* _MALLOC_INTERNAL. */ /* Given an address in the middle of a malloc'd object, return the address of the beginning of the object. */ extern __ptr_t malloc_find_object_address __P ((__ptr_t __ptr)); /* Underlying allocation function; successive calls should return contiguous pieces of memory. */ extern __ptr_t (*__morecore) __P ((__malloc_ptrdiff_t __size)); /* Default value of `__morecore'. */ extern __ptr_t __default_morecore __P ((__malloc_ptrdiff_t __size)); /* If not NULL, this function is called after each time `__morecore' is called to increase the data size. */ extern void (*__after_morecore_hook) __P ((void)); /* Number of extra blocks to get each time we ask for more core. This reduces the frequency of calling `(*__morecore)'. */ extern __malloc_size_t __malloc_extra_blocks; /* Nonzero if `malloc' has been called and done its initialization. */ extern int __malloc_initialized; /* Function called to initialize malloc data structures. */ extern int __malloc_initialize __P ((void)); /* Hooks for debugging versions. */ extern void (*__malloc_initialize_hook) __P ((void)); extern void (*__free_hook) __P ((__ptr_t __ptr)); extern __ptr_t (*__malloc_hook) __P ((__malloc_size_t __size)); extern __ptr_t (*__realloc_hook) __P ((__ptr_t __ptr, __malloc_size_t __size)); extern __ptr_t (*__memalign_hook) __P ((__malloc_size_t __size, __malloc_size_t __alignment)); /* Return values for `mprobe': these are the kinds of inconsistencies that `mcheck' enables detection of. */ enum mcheck_status { MCHECK_DISABLED = -1, /* Consistency checking is not turned on. */ MCHECK_OK, /* Block is fine. */ MCHECK_FREE, /* Block freed twice. */ MCHECK_HEAD, /* Memory before the block was clobbered. */ MCHECK_TAIL /* Memory after the block was clobbered. */ }; /* Activate a standard collection of debugging hooks. This must be called before `malloc' is ever called. ABORTFUNC is called with an error code (see enum above) when an inconsistency is detected. If ABORTFUNC is null, the standard function prints on stderr and then calls `abort'. */ extern int mcheck __P ((void (*__abortfunc) __P ((enum mcheck_status)))); /* Check for aberrations in a particular malloc'd block. You must have called `mcheck' already. These are the same checks that `mcheck' does when you free or reallocate a block. */ extern enum mcheck_status mprobe __P ((__ptr_t __ptr)); /* Activate a standard collection of tracing hooks. */ extern void mtrace __P ((void)); extern void muntrace __P ((void)); /* Statistics available to the user. */ struct mstats { __malloc_size_t bytes_total; /* Total size of the heap. */ __malloc_size_t chunks_used; /* Chunks allocated by the user. */ __malloc_size_t bytes_used; /* Byte total of user-allocated chunks. */ __malloc_size_t chunks_free; /* Chunks in the free list. */ __malloc_size_t bytes_free; /* Byte total of chunks in the free list. */ }; /* Pick up the current statistics. */ extern struct mstats mstats __P ((void)); /* Call WARNFUN with a warning message when memory usage is high. */ extern void memory_warnings __P ((__ptr_t __start, void (*__warnfun) __P ((const char *)))); /* Relocating allocator. */ /* Allocate SIZE bytes, and store the address in *HANDLEPTR. */ extern __ptr_t r_alloc __P ((__ptr_t *__handleptr, __malloc_size_t __size)); /* Free the storage allocated in HANDLEPTR. */ extern void r_alloc_free __P ((__ptr_t *__handleptr)); /* Adjust the block at HANDLEPTR to be SIZE bytes long. */ extern __ptr_t r_re_alloc __P ((__ptr_t *__handleptr, __malloc_size_t __size)); #ifdef __cplusplus } #endif #endif /* malloc.h */ /* Memory allocator `malloc'. Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. Written May 1989 by Mike Haertel. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. The author may be reached (Email) at the address [email protected], or (US mail) as Mike Haertel c/o Free Software Foundation. */ #ifndef _MALLOC_INTERNAL #define _MALLOC_INTERNAL #include <malloc.h> #endif #include <errno.h> /* How to really get more memory. */ __ptr_t (*__morecore) __P ((ptrdiff_t __size)) = __default_morecore; /* Debugging hook for `malloc'. */ __ptr_t (*__malloc_hook) __P ((__malloc_size_t __size)); /* Pointer to the base of the first block. */ char *_heapbase; /* Block information table. Allocated with align/__free (not malloc/free). */ malloc_info *_heapinfo; /* Number of info entries. */ static __malloc_size_t heapsize; /* Search index in the info table. */ __malloc_size_t _heapindex; /* Limit of valid info table indices. */ __malloc_size_t _heaplimit; /* Free lists for each fragment size. */ struct list _fraghead[BLOCKLOG]; /* Instrumentation. */ __malloc_size_t _chunks_used; __malloc_size_t _bytes_used; __malloc_size_t _chunks_free; __malloc_size_t _bytes_free; /* Are you experienced? */ int __malloc_initialized; __malloc_size_t __malloc_extra_blocks; void (*__malloc_initialize_hook) __P ((void)); void (*__after_morecore_hook) __P ((void)); /* Aligned allocation. */ static __ptr_t align __P ((__malloc_size_t)); static __ptr_t align (size) __malloc_size_t size; { __ptr_t result; unsigned long int adj; result = (*__morecore) (size); adj = (unsigned long int) ((unsigned long int) ((char *) result - (char *) NULL)) % BLOCKSIZE; if (adj != 0) { __ptr_t new; adj = BLOCKSIZE - adj; new = (*__morecore) (adj); result = (char *) result + adj; } if (__after_morecore_hook) (*__after_morecore_hook) (); return result; } /* Get SIZE bytes, if we can get them starting at END. Return the address of the space we got. If we cannot get space at END, fail and return -1. */ static __ptr_t get_contiguous_space __P ((__malloc_ptrdiff_t, __ptr_t)); static __ptr_t get_contiguous_space (size, position) __malloc_ptrdiff_t size; __ptr_t position; { __ptr_t before; __ptr_t after; before = (*__morecore) (0); /* If we can tell in advance that the break is at the wrong place, fail now. */ if (before != position) return 0; /* Allocate SIZE bytes and get the address of them. */ after = (*__morecore) (size); if (!after) return 0; /* It was not contiguous--reject it. */ if (after != position) { (*__morecore) (- size); return 0; } return after; } /* This is called when `_heapinfo' and `heapsize' have just been set to describe a new info table. Set up the table to describe itself and account for it in the statistics. */ static void register_heapinfo __P ((void)); #ifdef __GNUC__ __inline__ #endif static void register_heapinfo () { __malloc_size_t block, blocks; block = BLOCK (_heapinfo); blocks = BLOCKIFY (heapsize * sizeof (malloc_info)); /* Account for the _heapinfo block itself in the statistics. */ _bytes_used += blocks * BLOCKSIZE; ++_chunks_used; /* Describe the heapinfo block itself in the heapinfo. */ _heapinfo[block].busy.type = 0; _heapinfo[block].busy.info.size = blocks; /* Leave back-pointers for malloc_find_address. */ while (--blocks > 0) _heapinfo[block + blocks].busy.info.size = -blocks; } /* Set everything up and remember that we have. */ int __malloc_initialize () { if (__malloc_initialized) return 0; if (__malloc_initialize_hook) (*__malloc_initialize_hook) (); heapsize = HEAP / BLOCKSIZE; _heapinfo = (malloc_info *) align (heapsize * sizeof (malloc_info)); if (_heapinfo == NULL) return 0; memset (_heapinfo, 0, heapsize * sizeof (malloc_info)); _heapinfo[0].free.size = 0; _heapinfo[0].free.next = _heapinfo[0].free.prev = 0; _heapindex = 0; _heapbase = (char *) _heapinfo; _heaplimit = BLOCK (_heapbase + heapsize * sizeof (malloc_info)); register_heapinfo (); __malloc_initialized = 1; return 1; } static int morecore_recursing; /* Get neatly aligned memory, initializing or growing the heap info table as necessary. */ static __ptr_t morecore __P ((__malloc_size_t)); static __ptr_t morecore (size) __malloc_size_t size; { __ptr_t result; malloc_info *newinfo, *oldinfo; __malloc_size_t newsize; if (morecore_recursing) /* Avoid recursion. The caller will know how to handle a null return. */ return NULL; result = align (size); if (result == NULL) return NULL; /* Check if we need to grow the info table. */ if ((__malloc_size_t) BLOCK ((char *) result + size) > heapsize) { /* Calculate the new _heapinfo table size. We do not account for the added blocks in the table itself, as we hope to place them in existing free space, which is already covered by part of the existing table. */ newsize = heapsize; do newsize *= 2; while ((__malloc_size_t) BLOCK ((char *) result + size) > newsize); /* We must not reuse existing core for the new info table when called from realloc in the case of growing a large block, because the block being grown is momentarily marked as free. In this case _heaplimit is zero so we know not to reuse space for internal allocation. */ if (_heaplimit != 0) { /* First try to allocate the new info table in core we already have, in the usual way using realloc. If realloc cannot extend it in place or relocate it to existing sufficient core, we will get called again, and the code above will notice the `morecore_recursing' flag and return null. */ int save = errno; /* Don't want to clobber errno with ENOMEM. */ morecore_recursing = 1; newinfo = (malloc_info *) _realloc_internal (_heapinfo, newsize * sizeof (malloc_info)); morecore_recursing = 0; if (newinfo == NULL) errno = save; else { /* We found some space in core, and realloc has put the old table's blocks on the free list. Now zero the new part of the table and install the new table location. */ memset (&newinfo[heapsize], 0, (newsize - heapsize) * sizeof (malloc_info)); _heapinfo = newinfo; heapsize = newsize; goto got_heap; } } /* Allocate new space for the malloc info table. */ while (1) { newinfo = (malloc_info *) align (newsize * sizeof (malloc_info)); /* Did it fail? */ if (newinfo == NULL) { (*__morecore) (-size); return NULL; } /* Is it big enough to record status for its own space? If so, we win. */ if ((__malloc_size_t) BLOCK ((char *) newinfo + newsize * sizeof (malloc_info)) < newsize) break; /* Must try again. First give back most of what we just got. */ (*__morecore) (- newsize * sizeof (malloc_info)); newsize *= 2; } /* Copy the old table to the beginning of the new, and zero the rest of the new table. */ memcpy (newinfo, _heapinfo, heapsize * sizeof (malloc_info)); memset (&newinfo[heapsize], 0, (newsize - heapsize) * sizeof (malloc_info)); oldinfo = _heapinfo; _heapinfo = newinfo; heapsize = newsize; register_heapinfo (); /* Reset _heaplimit so _free_internal never decides it can relocate or resize the info table. */ _heaplimit = 0; _free_internal (oldinfo); /* The new heap limit includes the new table just allocated. */ _heaplimit = BLOCK ((char *) newinfo + heapsize * sizeof (malloc_info)); return result; } got_heap: _heaplimit = BLOCK ((char *) result + size); return result; } /* Allocate memory from the heap. */ __ptr_t _malloc_internal (size) __malloc_size_t size; { __ptr_t result; __malloc_size_t block, blocks, lastblocks, start; register __malloc_size_t i; struct list *next; /* ANSI C allows `malloc (0)' to either return NULL, or to return a valid address you can realloc and free (though not dereference). It turns out that some extant code (sunrpc, at least Ultrix's version) expects `malloc (0)' to return non-NULL and breaks otherwise. Be compatible. */ #if 0 if (size == 0) return NULL; #endif if (size < sizeof (struct list)) size = sizeof (struct list); #ifdef SUNOS_LOCALTIME_BUG if (size < 16) size = 16; #endif /* Determine the allocation policy based on the request size. */ if (size <= BLOCKSIZE / 2) { /* Small allocation to receive a fragment of a block. Determine the logarithm to base two of the fragment size. */ register __malloc_size_t log = 1; --size; while ((size /= 2) != 0) ++log; /* Look in the fragment lists for a free fragment of the desired size. */ next = _fraghead[log].next; if (next != NULL) { /* There are free fragments of this size. Pop a fragment out of the fragment list and return it. Update the block's nfree and first counters. */ result = (__ptr_t) next; next->prev->next = next->next; if (next->next != NULL) next->next->prev = next->prev; block = BLOCK (result); if (--_heapinfo[block].busy.info.frag.nfree != 0) _heapinfo[block].busy.info.frag.first = (unsigned long int) ((unsigned long int) ((char *) next->next - (char *) NULL) % BLOCKSIZE) >> log; /* Update the statistics. */ ++_chunks_used; _bytes_used += 1 << log; --_chunks_free; _bytes_free -= 1 << log; } else { /* No free fragments of the desired size, so get a new block and break it into fragments, returning the first. */ result = malloc (BLOCKSIZE); if (result == NULL) return NULL; /* Link all fragments but the first into the free list. */ next = (struct list *) ((char *) result + (1 << log)); next->next = NULL; next->prev = &_fraghead[log]; _fraghead[log].next = next; for (i = 2; i < (__malloc_size_t) (BLOCKSIZE >> log); ++i) { next = (struct list *) ((char *) result + (i << log)); next->next = _fraghead[log].next; next->prev = &_fraghead[log]; next->prev->next = next; next->next->prev = next; } /* Initialize the nfree and first counters for this block. */ block = BLOCK (result); _heapinfo[block].busy.type = log; _heapinfo[block].busy.info.frag.nfree = i - 1; _heapinfo[block].busy.info.frag.first = i - 1; _chunks_free += (BLOCKSIZE >> log) - 1; _bytes_free += BLOCKSIZE - (1 << log); _bytes_used -= BLOCKSIZE - (1 << log); } } else { /* Large allocation to receive one or more blocks. Search the free list in a circle starting at the last place visited. If we loop completely around without finding a large enough space we will have to get more memory from the system. */ blocks = BLOCKIFY (size); start = block = _heapindex; while (_heapinfo[block].free.size < blocks) { block = _heapinfo[block].free.next; if (block == start) { /* Need to get more from the system. Get a little extra. */ __malloc_size_t wantblocks = blocks + __malloc_extra_blocks; block = _heapinfo[0].free.prev; lastblocks = _heapinfo[block].free.size; /* Check to see if the new core will be contiguous with the final free block; if so we don't need to get as much. */ if (_heaplimit != 0 && block + lastblocks == _heaplimit && /* We can't do this if we will have to make the heap info table bigger to accomodate the new space. */ block + wantblocks <= heapsize && get_contiguous_space ((wantblocks - lastblocks) * BLOCKSIZE, ADDRESS (block + lastblocks))) { /* We got it contiguously. Which block we are extending (the `final free block' referred to above) might have changed, if it got combined with a freed info table. */ block = _heapinfo[0].free.prev; _heapinfo[block].free.size += (wantblocks - lastblocks); _bytes_free += (wantblocks - lastblocks) * BLOCKSIZE; _heaplimit += wantblocks - lastblocks; continue; } result = morecore (wantblocks * BLOCKSIZE); if (result == NULL) return NULL; block = BLOCK (result); /* Put the new block at the end of the free list. */ _heapinfo[block].free.size = wantblocks; _heapinfo[block].free.prev = _heapinfo[0].free.prev; _heapinfo[block].free.next = 0; _heapinfo[0].free.prev = block; _heapinfo[_heapinfo[block].free.prev].free.next = block; ++_chunks_free; /* Now loop to use some of that block for this allocation. */ } } /* At this point we have found a suitable free list entry. Figure out how to remove what we need from the list. */ result = ADDRESS (block); if (_heapinfo[block].free.size > blocks) { /* The block we found has a bit left over, so relink the tail end back into the free list. */ _heapinfo[block + blocks].free.size = _heapinfo[block].free.size - blocks; _heapinfo[block + blocks].free.next = _heapinfo[block].free.next; _heapinfo[block + blocks].free.prev = _heapinfo[block].free.prev; _heapinfo[_heapinfo[block].free.prev].free.next = _heapinfo[_heapinfo[block].free.next].free.prev = _heapindex = block + blocks; } else { /* The block exactly matches our requirements, so just remove it from the list. */ _heapinfo[_heapinfo[block].free.next].free.prev = _heapinfo[block].free.prev; _heapinfo[_heapinfo[block].free.prev].free.next = _heapindex = _heapinfo[block].free.next; --_chunks_free; } _heapinfo[block].busy.type = 0; _heapinfo[block].busy.info.size = blocks; ++_chunks_used; _bytes_used += blocks * BLOCKSIZE; _bytes_free -= blocks * BLOCKSIZE; /* Mark all the blocks of the object just allocated except for the first with a negative number so you can find the first block by adding that adjustment. */ while (--blocks > 0) _heapinfo[block + blocks].busy.info.size = -blocks; } return result; } __ptr_t malloc (size) __malloc_size_t size; { if (!__malloc_initialized && !__malloc_initialize ()) return NULL; return (__malloc_hook != NULL ? *__malloc_hook : _malloc_internal) (size); } #ifndef _LIBC /* On some ANSI C systems, some libc functions call _malloc, _free and _realloc. Make them use the GNU functions. */ __ptr_t _malloc (size) __malloc_size_t size; { return malloc (size); } void _free (ptr) __ptr_t ptr; { free (ptr); } __ptr_t _realloc (ptr, size) __ptr_t ptr; __malloc_size_t size; { return realloc (ptr, size); } #endif /* Free a block of memory allocated by `malloc'. Copyright 1990, 1991, 1992, 1994, 1995 Free Software Foundation, Inc. Written May 1989 by Mike Haertel. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. The author may be reached (Email) at the address [email protected], or (US mail) as Mike Haertel c/o Free Software Foundation. */ #ifndef _MALLOC_INTERNAL #define _MALLOC_INTERNAL #include <malloc.h> #endif /* Cope with systems lacking `memmove'. */ #ifndef memmove #if (defined (MEMMOVE_MISSING) || \ !defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG)) #ifdef emacs #undef __malloc_safe_bcopy #define __malloc_safe_bcopy safe_bcopy #endif /* This function is defined in realloc.c. */ extern void __malloc_safe_bcopy __P ((__ptr_t, __ptr_t, __malloc_size_t)); #define memmove(to, from, size) __malloc_safe_bcopy ((from), (to), (size)) #endif #endif /* Debugging hook for free. */ void (*__free_hook) __P ((__ptr_t __ptr)); /* List of blocks allocated by memalign. */ struct alignlist *_aligned_blocks = NULL; /* Return memory to the heap. Like `free' but don't call a __free_hook if there is one. */ void _free_internal (ptr) __ptr_t ptr; { int type; __malloc_size_t block, blocks; register __malloc_size_t i; struct list *prev, *next; __ptr_t curbrk; const __malloc_size_t lesscore_threshold /* Threshold of free space at which we will return some to the system. */ = FINAL_FREE_BLOCKS + 2 * __malloc_extra_blocks; register struct alignlist *l; if (ptr == NULL) return; for (l = _aligned_blocks; l != NULL; l = l->next) if (l->aligned == ptr) { l->aligned = NULL; /* Mark the slot in the list as free. */ ptr = l->exact; break; } block = BLOCK (ptr); type = _heapinfo[block].busy.type; switch (type) { case 0: /* Get as many statistics as early as we can. */ --_chunks_used; _bytes_used -= _heapinfo[block].busy.info.size * BLOCKSIZE; _bytes_free += _heapinfo[block].busy.info.size * BLOCKSIZE; /* Find the free cluster previous to this one in the free list. Start searching at the last block referenced; this may benefit programs with locality of allocation. */ i = _heapindex; if (i > block) while (i > block) i = _heapinfo[i].free.prev; else { do i = _heapinfo[i].free.next; while (i > 0 && i < block); i = _heapinfo[i].free.prev; } /* Determine how to link this block into the free list. */ if (block == i + _heapinfo[i].free.size) { /* Coalesce this block with its predecessor. */ _heapinfo[i].free.size += _heapinfo[block].busy.info.size; block = i; } else { /* Really link this block back into the free list. */ _heapinfo[block].free.size = _heapinfo[block].busy.info.size; _heapinfo[block].free.next = _heapinfo[i].free.next; _heapinfo[block].free.prev = i; _heapinfo[i].free.next = block; _heapinfo[_heapinfo[block].free.next].free.prev = block; ++_chunks_free; } /* Now that the block is linked in, see if we can coalesce it with its successor (by deleting its successor from the list and adding in its size). */ if (block + _heapinfo[block].free.size == _heapinfo[block].free.next) { _heapinfo[block].free.size += _heapinfo[_heapinfo[block].free.next].free.size; _heapinfo[block].free.next = _heapinfo[_heapinfo[block].free.next].free.next; _heapinfo[_heapinfo[block].free.next].free.prev = block; --_chunks_free; } /* How many trailing free blocks are there now? */ blocks = _heapinfo[block].free.size; /* Where is the current end of accessible core? */ curbrk = (*__morecore) (0); if (_heaplimit != 0 && curbrk == ADDRESS (_heaplimit)) { /* The end of the malloc heap is at the end of accessible core. It's possible that moving _heapinfo will allow us to return some space to the system. */ __malloc_size_t info_block = BLOCK (_heapinfo); __malloc_size_t info_blocks = _heapinfo[info_block].busy.info.size; __malloc_size_t prev_block = _heapinfo[block].free.prev; __malloc_size_t prev_blocks = _heapinfo[prev_block].free.size; __malloc_size_t next_block = _heapinfo[block].free.next; __malloc_size_t next_blocks = _heapinfo[next_block].free.size; if (/* Win if this block being freed is last in core, the info table is just before it, the previous free block is just before the info table, and the two free blocks together form a useful amount to return to the system. */ (block + blocks == _heaplimit && info_block + info_blocks == block && prev_block != 0 && prev_block + prev_blocks == info_block && blocks + prev_blocks >= lesscore_threshold) || /* Nope, not the case. We can also win if this block being freed is just before the info table, and the table extends to the end of core or is followed only by a free block, and the total free space is worth returning to the system. */ (block + blocks == info_block && ((info_block + info_blocks == _heaplimit && blocks >= lesscore_threshold) || (info_block + info_blocks == next_block && next_block + next_blocks == _heaplimit && blocks + next_blocks >= lesscore_threshold))) ) { malloc_info *newinfo; __malloc_size_t oldlimit = _heaplimit; /* Free the old info table, clearing _heaplimit to avoid recursion into this code. We don't want to return the table's blocks to the system before we have copied them to the new location. */ _heaplimit = 0; _free_internal (_heapinfo); _heaplimit = oldlimit; /* Tell malloc to search from the beginning of the heap for free blocks, so it doesn't reuse the ones just freed. */ _heapindex = 0; /* Allocate new space for the info table and move its data. */ newinfo = (malloc_info *) _malloc_internal (info_blocks * BLOCKSIZE); memmove (newinfo, _heapinfo, info_blocks * BLOCKSIZE); _heapinfo = newinfo; /* We should now have coalesced the free block with the blocks freed from the old info table. Examine the entire trailing free block to decide below whether to return some to the system. */ block = _heapinfo[0].free.prev; blocks = _heapinfo[block].free.size; } /* Now see if we can return stuff to the system. */ if (block + blocks == _heaplimit && blocks >= lesscore_threshold) { register __malloc_size_t bytes = blocks * BLOCKSIZE; _heaplimit -= blocks; (*__morecore) (-bytes); _heapinfo[_heapinfo[block].free.prev].free.next = _heapinfo[block].free.next; _heapinfo[_heapinfo[block].free.next].free.prev = _heapinfo[block].free.prev; block = _heapinfo[block].free.prev; --_chunks_free; _bytes_free -= bytes; } } /* Set the next search to begin at this block. */ _heapindex = block; break; default: /* Do some of the statistics. */ --_chunks_used; _bytes_used -= 1 << type; ++_chunks_free; _bytes_free += 1 << type; /* Get the address of the first free fragment in this block. */ prev = (struct list *) ((char *) ADDRESS (block) + (_heapinfo[block].busy.info.frag.first << type)); if (_heapinfo[block].busy.info.frag.nfree == (BLOCKSIZE >> type) - 1) { /* If all fragments of this block are free, remove them from the fragment list and free the whole block. */ next = prev; for (i = 1; i < (__malloc_size_t) (BLOCKSIZE >> type); ++i) next = next->next; prev->prev->next = next; if (next != NULL) next->prev = prev->prev; _heapinfo[block].busy.type = 0; _heapinfo[block].busy.info.size = 1; /* Keep the statistics accurate. */ ++_chunks_used; _bytes_used += BLOCKSIZE; _chunks_free -= BLOCKSIZE >> type; _bytes_free -= BLOCKSIZE; free (ADDRESS (block)); } else if (_heapinfo[block].busy.info.frag.nfree != 0) { /* If some fragments of this block are free, link this fragment into the fragment list after the first free fragment of this block. */ next = (struct list *) ptr; next->next = prev->next; next->prev = prev; prev->next = next; if (next->next != NULL) next->next->prev = next; ++_heapinfo[block].busy.info.frag.nfree; } else { /* No fragments of this block are free, so link this fragment into the fragment list and announce that it is the first free fragment of this block. */ prev = (struct list *) ptr; _heapinfo[block].busy.info.frag.nfree = 1; _heapinfo[block].busy.info.frag.first = (unsigned long int) ((unsigned long int) ((char *) ptr - (char *) NULL) % BLOCKSIZE >> type); prev->next = _fraghead[type].next; prev->prev = &_fraghead[type]; prev->prev->next = prev; if (prev->next != NULL) prev->next->prev = prev; } break; } } /* Return memory to the heap. */ void free (ptr) __ptr_t ptr; { if (__free_hook != NULL) (*__free_hook) (ptr); else _free_internal (ptr); } /* Define the `cfree' alias for `free'. */ #ifdef weak_alias weak_alias (free, cfree) #else void cfree (ptr) __ptr_t ptr; { free (ptr); } #endif /* Change the size of a block allocated by `malloc'. Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. Written May 1989 by Mike Haertel. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. The author may be reached (Email) at the address [email protected], or (US mail) as Mike Haertel c/o Free Software Foundation. */ #ifndef _MALLOC_INTERNAL #define _MALLOC_INTERNAL #include <malloc.h> #endif /* Cope with systems lacking `memmove'. */ #if (defined (MEMMOVE_MISSING) || \ !defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG)) #ifdef emacs #undef __malloc_safe_bcopy #define __malloc_safe_bcopy safe_bcopy #else /* Snarfed directly from Emacs src/dispnew.c: XXX Should use system bcopy if it handles overlap. */ /* Like bcopy except never gets confused by overlap. */ void __malloc_safe_bcopy (afrom, ato, size) __ptr_t afrom; __ptr_t ato; __malloc_size_t size; { char *from = afrom, *to = ato; if (size <= 0 || from == to) return; /* If the source and destination don't overlap, then bcopy can handle it. If they do overlap, but the destination is lower in memory than the source, we'll assume bcopy can handle that. */ if (to < from || from + size <= to) bcopy (from, to, size); /* Otherwise, we'll copy from the end. */ else { register char *endf = from + size; register char *endt = to + size; /* If TO - FROM is large, then we should break the copy into nonoverlapping chunks of TO - FROM bytes each. However, if TO - FROM is small, then the bcopy function call overhead makes this not worth it. The crossover point could be about anywhere. Since I don't think the obvious copy loop is too bad, I'm trying to err in its favor. */ if (to - from < 64) { do *--endt = *--endf; while (endf != from); } else { for (;;) { endt -= (to - from); endf -= (to - from); if (endt < to) break; bcopy (endf, endt, to - from); } /* If SIZE wasn't a multiple of TO - FROM, there will be a little left over. The amount left over is (endt + (to - from)) - to, which is endt - from. */ bcopy (from, to, endt - from); } } } #endif /* emacs */ #ifndef memmove extern void __malloc_safe_bcopy __P ((__ptr_t, __ptr_t, __malloc_size_t)); #define memmove(to, from, size) __malloc_safe_bcopy ((from), (to), (size)) #endif #endif #define min(A, B) ((A) < (B) ? (A) : (B)) /* Debugging hook for realloc. */ __ptr_t (*__realloc_hook) __P ((__ptr_t __ptr, __malloc_size_t __size)); /* Resize the given region to the new size, returning a pointer to the (possibly moved) region. This is optimized for speed; some benchmarks seem to indicate that greater compactness is achieved by unconditionally allocating and copying to a new region. This module has incestuous knowledge of the internals of both free and malloc. */ __ptr_t _realloc_internal (ptr, size) __ptr_t ptr; __malloc_size_t size; { __ptr_t result; int type; __malloc_size_t block, blocks, oldlimit; if (size == 0) { _free_internal (ptr); return _malloc_internal (0); } else if (ptr == NULL) return _malloc_internal (size); block = BLOCK (ptr); type = _heapinfo[block].busy.type; switch (type) { case 0: /* Maybe reallocate a large block to a small fragment. */ if (size <= BLOCKSIZE / 2) { result = _malloc_internal (size); if (result != NULL) { memcpy (result, ptr, size); _free_internal (ptr); return result; } } /* The new size is a large allocation as well; see if we can hold it in place. */ blocks = BLOCKIFY (size); if (blocks < _heapinfo[block].busy.info.size) { /* The new size is smaller; return excess memory to the free list. */ _heapinfo[block + blocks].busy.type = 0; _heapinfo[block + blocks].busy.info.size = _heapinfo[block].busy.info.size - blocks; _heapinfo[block].busy.info.size = blocks; /* We have just created a new chunk by splitting a chunk in two. Now we will free this chunk; increment the statistics counter so it doesn't become wrong when _free_internal decrements it. */ ++_chunks_used; _free_internal (ADDRESS (block + blocks)); result = ptr; } else if (blocks == _heapinfo[block].busy.info.size) /* No size change necessary. */ result = ptr; else { /* Won't fit, so allocate a new region that will. Free the old region first in case there is sufficient adjacent free space to grow without moving. */ blocks = _heapinfo[block].busy.info.size; /* Prevent free from actually returning memory to the system. */ oldlimit = _heaplimit; _heaplimit = 0; _free_internal (ptr); result = _malloc_internal (size); if (_heaplimit == 0) _heaplimit = oldlimit; if (result == NULL) { /* Now we're really in trouble. We have to unfree the thing we just freed. Unfortunately it might have been coalesced with its neighbors. */ if (_heapindex == block) (void) _malloc_internal (blocks * BLOCKSIZE); else { __ptr_t previous = _malloc_internal ((block - _heapindex) * BLOCKSIZE); (void) _malloc_internal (blocks * BLOCKSIZE); _free_internal (previous); } return NULL; } if (ptr != result) memmove (result, ptr, blocks * BLOCKSIZE); } break; default: /* Old size is a fragment; type is logarithm to base two of the fragment size. */ if (size > (__malloc_size_t) (1 << (type - 1)) && size <= (__malloc_size_t) (1 << type)) /* The new size is the same kind of fragment. */ result = ptr; else { /* The new size is different; allocate a new space, and copy the lesser of the new size and the old. */ result = _malloc_internal (size); if (result == NULL) return NULL; memcpy (result, ptr, min (size, (__malloc_size_t) 1 << type)); _free_internal (ptr); } break; } return result; } __ptr_t realloc (ptr, size) __ptr_t ptr; __malloc_size_t size; { if (!__malloc_initialized && !__malloc_initialize ()) return NULL; return (__realloc_hook != NULL ? *__realloc_hook : _realloc_internal) (ptr, size); } /* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. The author may be reached (Email) at the address [email protected], or (US mail) as Mike Haertel c/o Free Software Foundation. */ #ifndef _MALLOC_INTERNAL #define _MALLOC_INTERNAL #include <malloc.h> #endif /* Allocate an array of NMEMB elements each SIZE bytes long. The entire array is initialized to zeros. */ __ptr_t calloc (nmemb, size) register __malloc_size_t nmemb; register __malloc_size_t size; { register __ptr_t result = malloc (nmemb * size); if (result != NULL) (void) memset (result, 0, nmemb * size); return result; } /* Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library 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, or (at your option) any later version. The GNU C Library 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 the GNU C Library; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #ifndef _MALLOC_INTERNAL #define _MALLOC_INTERNAL #include <malloc.h> #endif #ifndef __GNU_LIBRARY__ #define __sbrk sbrk #endif #ifdef __GNU_LIBRARY__ /* It is best not to declare this and cast its result on foreign operating systems with potentially hostile include files. */ #include <stddef.h> extern __ptr_t __sbrk __P ((ptrdiff_t increment)); #endif #ifndef NULL #define NULL 0 #endif /* Allocate INCREMENT more bytes of data space, and return the start of data space, or NULL on errors. If INCREMENT is negative, shrink data space. */ __ptr_t __default_morecore (increment) __malloc_ptrdiff_t increment; { __ptr_t result = (__ptr_t) __sbrk (increment); if (result == (__ptr_t) -1) return NULL; return result; } /* Copyright (C) 1991, 92, 93, 94, 95, 96 Free Software Foundation, Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #ifndef _MALLOC_INTERNAL #define _MALLOC_INTERNAL #include <malloc.h> #endif #if __DJGPP__ - 0 == 1 /* There is some problem with memalign in DJGPP v1 and we are supposed to omit it. Noone told me why, they just told me to do it. */ #else __ptr_t (*__memalign_hook) __P ((size_t __size, size_t __alignment)); __ptr_t memalign (alignment, size) __malloc_size_t alignment; __malloc_size_t size; { __ptr_t result; unsigned long int adj, lastadj; if (__memalign_hook) return (*__memalign_hook) (alignment, size); /* Allocate a block with enough extra space to pad the block with up to (ALIGNMENT - 1) bytes if necessary. */ result = malloc (size + alignment - 1); if (result == NULL) return NULL; /* Figure out how much we will need to pad this particular block to achieve the required alignment. */ adj = (unsigned long int) ((char *) result - (char *) NULL) % alignment; do { /* Reallocate the block with only as much excess as it needs. */ free (result); result = malloc (adj + size); if (result == NULL) /* Impossible unless interrupted. */ return NULL; lastadj = adj; adj = (unsigned long int) ((char *) result - (char *) NULL) % alignment; /* It's conceivable we might have been so unlucky as to get a different block with weaker alignment. If so, this block is too short to contain SIZE after alignment correction. So we must try again and get another block, slightly larger. */ } while (adj > lastadj); if (adj != 0) { /* Record this block in the list of aligned blocks, so that `free' can identify the pointer it is passed, which will be in the middle of an allocated block. */ struct alignlist *l; for (l = _aligned_blocks; l != NULL; l = l->next) if (l->aligned == NULL) /* This slot is free. Use it. */ break; if (l == NULL) { l = (struct alignlist *) malloc (sizeof (struct alignlist)); if (l == NULL) { free (result); return NULL; } l->next = _aligned_blocks; _aligned_blocks = l; } l->exact = result; result = l->aligned = (char *) result + alignment - adj; } return result; } #endif /* Not DJGPP v1 */
the_stack_data/117495.c
#include<stdio.h> int main(){ double area, raio; scanf("%lf",&raio); area=((raio*raio)*3.14159); printf("A=%.4lf\n",area); return 0; }
the_stack_data/23574268.c
/* * Test: SPARC/Solaris 8 64-bit kernel mode * gcc -Wall -pipe -g -o sigbus2 sigbus2.c */ #include <stdio.h> #include <stdlib.h> int main ( int argc, char * argv[] ) { unsigned int i = 0x12345678; unsigned short int j = 0x0000; j = *( ( unsigned short int * )( ( ( unsigned char * )&i ) + 1 ) ); return( EXIT_SUCCESS ); } /* end of main */
the_stack_data/802449.c
/* Copyright (c) 2019, Miguel Mendez. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 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> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #define BUFFER_SIZE 320 * 180 #define TILE_SIZE 256 * 256 #define TILE_NUM_COLS 16.0f static void resample(uint8_t *src, uint8_t *dst) { float delta = 320.0f / 256.0f; for (uint32_t y = 0; y < 180; y++) { float xorig = 0.0f; for (uint32_t x = 0; x < 255; x++) { dst[x + (y * 256)] = src[(int)xorig + (y * 320)]; xorig += delta; } } } static float compute_color_scale(uint8_t *buffer) { uint32_t max_value = 0; for (uint32_t i = 0; i < TILE_SIZE; i++) { if (((uint32_t)buffer[i]) > max_value) { max_value = (uint32_t)buffer[i]; } } float scale = TILE_NUM_COLS / (float)max_value; return scale; } static void downscale_colour(uint8_t *buffer, float scale) { for (uint32_t i = 0; i < TILE_SIZE; i++) { buffer[i] = (uint8_t)((float)buffer[i] * scale); } } int main(int argc, char **argv) { if (argc != 3) { fprintf(stderr, "Usage: %s buffer.raw tile.raw\n", argv[0]); exit(EXIT_FAILURE); } FILE *in = fopen(argv[1], "r"); if (!in) { fprintf(stderr, "FATAL - Could not open <%s> for reading.\n", argv[1]); exit(EXIT_FAILURE); } FILE *out = fopen(argv[2], "w"); if (!out) { fprintf(stderr, "FATAL - Could not open <%s> for writing.\n", argv[2]); exit(EXIT_FAILURE); } uint8_t *src = calloc(BUFFER_SIZE, 1); uint8_t *dst = calloc(TILE_SIZE, 1); size_t read = fread(src, BUFFER_SIZE, 1, in); if (!read) { fprintf(stderr, "FATAL - Could no read data from <%s>.\n", argv[1]); exit(EXIT_FAILURE); } fclose(in); resample(src, dst); float scale = compute_color_scale(dst); downscale_colour(dst, scale); size_t written = fwrite(dst, TILE_SIZE, 1, out); if (!written) { fprintf(stderr, "FATAL - Could no write data to <%s>.\n", argv[2]); exit(EXIT_FAILURE); } fclose(out); free(src); free(dst); exit(EXIT_SUCCESS); }
the_stack_data/132951762.c
#include <assert.h> #include <limits.h> #include <math.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> char* readline(); typedef struct SinglyLinkedListNode SinglyLinkedListNode; typedef struct SinglyLinkedList SinglyLinkedList; struct SinglyLinkedListNode { int data; SinglyLinkedListNode* next; }; struct SinglyLinkedList { SinglyLinkedListNode* head; SinglyLinkedListNode* tail; }; SinglyLinkedListNode* create_singly_linked_list_node(int node_data) { SinglyLinkedListNode* node = malloc(sizeof(SinglyLinkedListNode)); node->data = node_data; node->next = NULL; return node; } void insert_node_into_singly_linked_list(SinglyLinkedList** singly_linked_list, int node_data) { SinglyLinkedListNode* node = create_singly_linked_list_node(node_data); if (!(*singly_linked_list)->head) { (*singly_linked_list)->head = node; } else { (*singly_linked_list)->tail->next = node; } (*singly_linked_list)->tail = node; } void print_singly_linked_list(SinglyLinkedListNode* node, char* sep, FILE* fptr) { while (node) { fprintf(fptr, "%d", node->data); node = node->next; if (node) { fprintf(fptr, "%s", sep); } } } void free_singly_linked_list(SinglyLinkedListNode* node) { while (node) { SinglyLinkedListNode* temp = node; node = node->next; free(temp); } } // Complete the mergeLists function below. /* * For your reference: * * SinglyLinkedListNode { * int data; * SinglyLinkedListNode* next; * }; * */ SinglyLinkedListNode* mergeLists(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) { SinglyLinkedListNode* fake = (SinglyLinkedListNode*) malloc(sizeof(SinglyLinkedListNode)); SinglyLinkedListNode* last = fake; while(head1 != NULL && head2 != NULL) { if (head1->data <= head2->data) { last->next = head1; last = head1; head1 = head1->next; } else { last->next = head2; last = head2; head2 = head2->next; } } if (head1 != NULL) { last->next = head1; } if (head2 != NULL) { last->next = head2; } return fake->next; } int main() { FILE* fptr = fopen(getenv("OUTPUT_PATH"), "w"); char* tests_endptr; char* tests_str = readline(); int tests = strtol(tests_str, &tests_endptr, 10); if (tests_endptr == tests_str || *tests_endptr != '\0') { exit(EXIT_FAILURE); } for (int tests_itr = 0; tests_itr < tests; tests_itr++) { SinglyLinkedList* llist1 = malloc(sizeof(SinglyLinkedList)); llist1->head = NULL; llist1->tail = NULL; char* llist1_count_endptr; char* llist1_count_str = readline(); int llist1_count = strtol(llist1_count_str, &llist1_count_endptr, 10); if (llist1_count_endptr == llist1_count_str || *llist1_count_endptr != '\0') { exit(EXIT_FAILURE); } for (int i = 0; i < llist1_count; i++) { char* llist1_item_endptr; char* llist1_item_str = readline(); int llist1_item = strtol(llist1_item_str, &llist1_item_endptr, 10); if (llist1_item_endptr == llist1_item_str || *llist1_item_endptr != '\0') { exit(EXIT_FAILURE); } insert_node_into_singly_linked_list(&llist1, llist1_item); } SinglyLinkedList* llist2 = malloc(sizeof(SinglyLinkedList)); llist2->head = NULL; llist2->tail = NULL; char* llist2_count_endptr; char* llist2_count_str = readline(); int llist2_count = strtol(llist2_count_str, &llist2_count_endptr, 10); if (llist2_count_endptr == llist2_count_str || *llist2_count_endptr != '\0') { exit(EXIT_FAILURE); } for (int i = 0; i < llist2_count; i++) { char* llist2_item_endptr; char* llist2_item_str = readline(); int llist2_item = strtol(llist2_item_str, &llist2_item_endptr, 10); if (llist2_item_endptr == llist2_item_str || *llist2_item_endptr != '\0') { exit(EXIT_FAILURE); } insert_node_into_singly_linked_list(&llist2, llist2_item); } SinglyLinkedListNode* llist3 = mergeLists(llist1->head, llist2->head); char *sep = " "; print_singly_linked_list(llist3, sep, fptr); fprintf(fptr, "\n"); free_singly_linked_list(llist3); } fclose(fptr); return 0; } char* readline() { size_t alloc_length = 1024; size_t data_length = 0; char* data = malloc(alloc_length); while (true) { char* cursor = data + data_length; char* line = fgets(cursor, alloc_length - data_length, stdin); if (!line) { break; } data_length += strlen(cursor); if (data_length < alloc_length - 1 || data[data_length - 1] == '\n') { break; } size_t new_length = alloc_length << 1; data = realloc(data, new_length); if (!data) { break; } alloc_length = new_length; } if (data[data_length - 1] == '\n') { data[data_length - 1] = '\0'; } data = realloc(data, data_length); return data; }
the_stack_data/150143348.c
/* Example code for Exercises in C. This program shows a way to represent a BigInt type (arbitrary length integers) using C strings, with numbers represented as a string of decimal digits in reverse order. Follow these steps to get this program working: 1) Read through the whole program so you understand the design. 2) Compile and run the program. It should run three tests, and they should fail. 3) Fill in the body of reverse_string(). When you get it working, the first test should pass. 4) Fill in the body of itoc(). When you get it working, the second test should pass. 5) Fill in the body of add_digits(). When you get it working, the third test should pass. 6) Uncomment the last test in main. If your three previous tests pass, this one should, too. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <assert.h> /* reverse_string: Returns a new string with the characters reversed. It is the caller's responsibility to free the result. s: string returns: string */ char *reverse_string(char *s) { //TODO: Fill this in. return ""; } /* ctoi: Converts a character to integer. c: one of the characters '0' to '9' returns: integer 0 to 9 */ int ctoi(char c) { assert(isdigit(c)); return c - '0'; } /* itoc: Converts an integer to character. i: integer 0 to 9 returns: character '0' to '9' */ char itoc(int i) { //TODO: Fill this in, with an appropriate assertion. return '0'; } /* add_digits: Adds two decimal digits, returns the total and carry. For example, if a='5', b='6', and carry='1', the sum is 12, so the output value of total should be '2' and carry should be '1' a: character '0' to '9' b: character '0' to '9' c: character '0' to '9' total: pointer to char carry: pointer to char */ void add_digits(char a, char b, char c, char *total, char *carry) { //TODO: Fill this in. } /* Define a type to represent a BigInt. Internally, a BigInt is a string of digits, with the digits in reverse order. */ typedef char * BigInt; /* add_bigint: Adds two BigInts Stores the result in z. x: BigInt y: BigInt carry_in: char z: empty buffer */ void add_bigint(BigInt x, BigInt y, char carry_in, BigInt z) { char total, carry_out; int dx=1, dy=1, dz=1; char a, b; /* OPTIONAL TODO: Modify this function to allocate and return z * rather than taking an empty buffer as a parameter. * Hint: you might need a helper function. */ if (*x == '\0') { a = '0'; dx = 0; }else{ a = *x; } if (*y == '\0') { b = '0'; dy = 0; }else{ b = *y; } // printf("%c %c %c\n", a, b, carry_in); add_digits(a, b, carry_in, &total, &carry_out); // printf("%c %c\n", carry_out, total); // if total and carry are 0, we're done if (total == '0' && carry_out == '0') { *z = '\0'; return; } // otherwise store the digit we just computed *z = total; // and make a recursive call to fill in the rest. add_bigint(x+dx, y+dy, carry_out, z+dz); } /* print_bigint: Prints the digits of BigInt in the normal order. big: BigInt */ void print_bigint(BigInt big) { char c = *big; if (c == '\0') return; print_bigint(big+1); printf("%c", c); } /* make_bigint: Creates and returns a BigInt. Caller is responsible for freeing. s: string of digits in the usual order returns: BigInt */ BigInt make_bigint(char *s) { char *r = reverse_string(s); return (BigInt) r; } void test_reverse_string() { char *s = "123"; char *t = reverse_string(s); if (strcmp(t, "321") == 0) { printf("reverse_string passed\n"); } else { printf("reverse_string failed\n"); } } void test_itoc() { char c = itoc(3); if (c == '3') { printf("itoc passed\n"); } else { printf("itoc failed\n"); } } void test_add_digits() { char total, carry; add_digits('7', '4', '1', &total, &carry); if (total == '2' && carry == '1') { printf("add_digits passed\n"); } else { printf("add_digits failed\n"); } } void test_add_bigint() { char *s = "1"; char *t = "99999999999999999999999999999999999999999999"; char *res = "000000000000000000000000000000000000000000001"; BigInt big1 = make_bigint(s); BigInt big2 = make_bigint(t); BigInt big3 = malloc(100); add_bigint(big1, big2, '0', big3); if (strcmp(big3, res) == 0) { printf("add_bigint passed\n"); } else { printf("add_bigint failed\n"); } } int main (int argc, char *argv[]) { test_reverse_string(); test_itoc(); test_add_digits(); //TODO: When you have the first three functions working, // uncomment the following, and it should work. // test_add_bigint(); return 0; }
the_stack_data/40763522.c
#include<stdio.h> int func_intro(),funcdef(),retrn(),typefunc(),call(); func_intro() { FILE *qa; qa=fopen("src/text_src/func intro.txt","r+"); if(qa==NULL) { printf("file cant be opened"); } printf("\n\n"); while(!feof(qa)) { printf("%c",fgetc(qa)); } } funcdef() { FILE *qb; qb=fopen("src/text_src/funcdef.txt","r+"); if(qb==NULL) { printf("file cant be opened"); } printf("\n\n"); while(!feof(qb)) { printf("%c",fgetc(qb)); } } retrn() { FILE *qc; qc=fopen("src/text_src/retrn.txt","r+"); if(qc==NULL) { printf("file cant be opened"); } printf("\n\n"); while(!feof(qc)) { printf("%c",fgetc(qc)); } } typefunc() { FILE *qd; qd=fopen("src/text_src/typefunc.txt","r+"); if(qd==NULL) { printf("file cant be opened"); } printf("\n\n"); while(!feof(qd)) { printf("%c",fgetc(qd)); } } call() { FILE *qe; qe=fopen("src/text_src/call.txt","r+"); if(qe==NULL) { printf("file cant be opened"); } printf("\n\n"); while(!feof(qe)) { printf("%c",fgetc(qe)); } }
the_stack_data/1207225.c
#include<stdio.h> int main(){ int first,second,third; printf("enter 3 digit number\n"); scanf("%1d%1d%1d",&first,&second,&third); switch(first%10) { case 1: printf(" One hundred"); break; case 2: printf(" Two hundred"); break; case 3: printf(" Three hundred"); break; case 4: printf(" Four hundred"); break; case 5: printf(" Five hundred"); break; case 6: printf(" Six hundred"); break; case 7: printf(" Seven hundred"); break; case 8: printf(" Eight hundred"); break; case 9: printf(" Nine hundred"); break; } switch(second%10){ case 0:break; case 1: switch(third%10){ printf("and"); case 0: printf(" ten");break; case 1: printf(" eleven");break; case 2: printf(" twelve"); break; case 3: printf("thirteen"); break; case 4: printf(" fourteen"); break; case 5: printf(" fifteen"); break; case 6: printf(" sixteen"); break; case 7: printf(" seventeen"); break; case 8: printf(" eighteen"); break; case 9: printf(" nineteen"); break; } return 0; break; case 2: printf(" tewnty"); break; case 3: printf(" thirty"); break; case 4: printf(" fourty"); break; case 5: printf(" fifty"); break; case 6: printf(" sixty"); break; case 7: printf(" seventy"); break; case 8: printf(" eighty"); break; case 9: printf(" ninety"); break; } switch(third%10){ case 0:break; printf("and"); case 1: printf(" one"); break; case 2: printf(" two"); break; case 3: printf(" three"); break; case 4: printf(" four"); break; case 5: printf(" five"); break; case 6: printf(" six"); break; case 7: printf(" seven"); break; case 8: printf(" eight"); break; case 9: printf(" nine"); break; } }
the_stack_data/1177580.c
/***************************** lucifer ************************* * LUCIFER: encrypt/decrypt bytes using IBM's LUCIFER algorithm. * Programmed by R.W.Outerbridge * * Usage: lucifer (+|-)([ecb]|<cbc|cks>) key1 <ivec> * EN/DE MODES KEYS * * + : ENcrypt (default if MODE specified) * - : DEcrypt (presumes encrypted input) * * Modes of Operation (choose ONE): * * ecb : (default) Electronic Code Book. Only uses one key. * If simply "+" or "-" is specified, ecb is used. * cbc : Cipher Block Chaining. Uses two keys. * cks : ChecKSum. Generates a 128-bit checksum using two keys. * * Both keys may be up to 16 characters long. NON-ASCII MACHINES * MAY GET DIFFERENT RESULTS. Any character may be used in keys, * but the one letter key "@", when used as "key1", will cause * lucifer to use a preset default key for "key1". This is used * for verification and testing. Failing to specify "ivec", if * required, will result in "key1" being used for both keys. It * is an error to omit "key1". There is no provision for specifying * arbitrary, absolute, bit-valued keys. * * As painful as they are to use, long keys are MUCH safer. * * ~~ Graven Cyphers, 8404.16 * University of Toronto */ #include <stdio.h> #define toascii(a) ((a)&0177) #define EN 0 #define DE 1 #define CKS 2 #define MODS 3 typedef char BYTE; /* BYTE = (VAX) ? int : char; */ /* typedef int void; /* void = ("void") ? N/A : int; YYYY */ /* cryptographic declarations */ void copy16(), xor16(), getkey(), loadkey(), lucifer(); BYTE Block[16], Link[16], Temp[16], IV[16]; BYTE DFLTKY[16] = { 1,35,69,103,137,171,205,239,254,220,186,152,118,84,50,16 }; /* DO NOT ALTER! => 0x0123456789abcdeffedcba9876543210 <= */ /* I/O declarations */ void ruderr(), put16(), vraiput(), initio(); int IOedf, End, Once; BYTE Last[16]; int Ecb(), Cbc(), Cks(); struct modes { char *name; int (*func)(); }; struct modes ModsOp[MODS] = { /* CAPS for CP/M - sorry! */ { "ECB", Ecb }, { "CBC", Cbc }, { "CKS", Cks } }; char *prog_name; int main(argc, argv) int argc; char **argv; { int (*xeqtr)(); int step, ende, edio, ok, i; BYTE kv[16]; prog_name = *argv; argv++; argc--; if(argc > 3 || argc < 2) ruderr(); for(step=0; argc > 0; step++) { switch(step) { case 0: /* set en/de and/or default mode */ if(*argv[0] == '+' || *argv[0] == '-') { ende = (*argv[0] == '+') ? EN : DE; *argv[0]++ = NULL; if(*argv[0] == NULL) { xeqtr = Ecb; /* default mode */ edio = ende; argv++; argc--; break; } } else ende = EN; for(i=ok=0; i < MODS && !ok; i++) { if(strcmp(argv[0], ModsOp[i].name) == 0) { xeqtr = ModsOp[i].func; ok = 1; } } if(!ok) { fprintf(stderr,"%s: unknown mode %s\n",prog_name,argv[0]); ruderr(); } while(*argv[0]) *argv[0]++ = NULL; argv++; argc--; /* set appropriate IO modes */ if(xeqtr == Cks) edio = CKS; else edio = ende; /* falling through.... */ case 1: /* get the key and IV, if needed and present */ if(strcmp(argv[0], "@") == 0) copy16(DFLTKY, kv); else getkey(argv[0], kv); argv++; argc--; /* if nothing left, but an IV needed, use the key */ if(argc == 0) { if(xeqtr != Ecb) copy16(kv, IV); break; } else if(xeqtr == Ecb) { fprintf(stderr,"%s: ivec ignored\n",prog_name); while(*argv[0]) *argv[0]++ = NULL; argv++; argc--; break; } else getkey(argv[0], IV); argv++; argc--; break; default: fprintf(stderr,"%s: warning, programming error!\n",prog_name); exit(1); break; } /* switch */ } /* argument parsing */ initio(edio); loadkey(kv, ende); (*xeqtr)(ende); /* ta-da! Take it away xeqtr! */ exit(0); } /* end of main */ void ruderr() { fprintf(stderr,"Usage:\n\t%s (+|-)([ecb]|<cbc|cks>) key1 <ivec>\n",prog_name); fprintf(stderr,"\n\t+ - Encode\n\t- - Decode\n\tecb - Electronic Code Book (default)\n"); fprintf(stderr,"\tcbc - Cipher Block Chaining (ivec required)\n"); fprintf(stderr,"\tcks - Generate 128 bit checksum\n"); exit(1); } Cbc(e_d) /* Cipher Block Chaining */ int e_d; /* Ciphertext errors are self-healing. */ { copy16(IV, Link); while(get16(Block) != EOF) { if(e_d == DE) copy16(Block, Temp); else xor16(Block, Link); lucifer(Block); if(e_d == DE) { xor16(Block, Link); copy16(Temp, Link); } else copy16(Block, Link); put16(Block); } return; } Cks(dummy) /* CBC authentication checksum generator */ int dummy; /* The banks use this for verifications. */ { int i, j, k; long count = 0; copy16(IV, Link); while(get16(Block) != EOF) { xor16(Block, Link); lucifer(Block); copy16(Block, Link); count += 16L; } fprintf(stdout, ": %0ld bytes\t: ", count); for(i=j=0; i < 4; i++) { for(k=0; k < 4; k++, j++) fprintf(stdout, "%02x", Link[j]&0377); putc(' ', stdout); } fprintf(stdout, ":\n"); return; } Ecb(dummy) /* Electronic Code Book : simple substitution */ int dummy; /* Yawn. For static data and random access. */ { while(get16(Block) != EOF) { lucifer(Block); put16(Block); } return; } void copy16(from, to) register BYTE *from, *to; { register BYTE *ep; ep = &to[16]; while(to < ep) *to++ = *from++; return; } void xor16(to, with) register BYTE *to, *with; { register BYTE *ep; ep = &to[16]; while(to < ep) *to++ ^= *with++; return; } void put16(block) register BYTE *block; { if(IOedf == DE) copy16(block, Last); else vraiput(block, &block[16]); return; } get16(input) register char *input; { register int i, j; if(End == 1) return(EOF); /* no more input */ for(i=0; i < 16 && ((j = getc(stdin)) != EOF); i++) *input++ = j; if(IOedf == DE) { /* DECRYPTION */ if(i == 16 && (Once > 0)) vraiput(Last, &Last[16]); else if(j == EOF) { End = 1; if(Once > 0) { if(i != 0) i = 0; /* no NULLs */ else { i = Last[15]&037; if(i > 16) i = 0; /* huh? */ } vraiput(Last, &Last[16-i]); } return(EOF); } } else if(j == EOF) { /* ENCRYPTION */ End = 1; if(i == 0 && (IOedf == EN || (Once > 0))) { if(IOedf == EN && (Once > 0)) putc('0', stdout); return(EOF); } for(j=i; j < 15; j++) *input++ = NULL; *input = 16-i; } Once = 1; return(0); } void vraiput(cp, ep) register char *cp, *ep; { while(cp < ep) putc(*cp++, stdout); return; } void initio(edf) int edf; { IOedf = edf; End = Once = 0; return; } /* LUCIFER is a cryptographic algorithm developed by IBM in the early * seventies. It was a predecessor of the DES, and is much simpler * than that algorithm. In particular, it has only two substitution * boxes and just one permutation box. The permutation box is only * eight bits wide. It does, however, use a 128 bit key and operates * on sixteen byte data blocks... * * This implementation of LUCIFER was crafted by Graven Cyphers at the * University of Toronto, Canada, with programming assistance from * Richard Outerbridge. It is based on the FORTRAN routines which * concluded Arthur Sorkin's article "LUCIFER: A Cryptographic Algorithm", * CRYPTOLOGIA, Volume 8, Number 1, January 1984, pp22-42. The interested * reader should refer to that article rather than this program for more * details on LUCIFER. * * These routines bear little resemblance to the actual LUCIFER algorithm, * which has been severely twisted in the interests of speed. They do * perform the same transformations, and are believed to be UNIX portable. * The package was developed for use on UNIX-like systems lacking crypto * facilities. They are not very fast, but the cipher is very strong. * The routines in this file are suitable for use as a subroutine library * after the fashion of crypt(3). When linked together with applications * routines they can also provide a high-level cryptographic system. */ static BYTE Dps[64] = { /* Diffusion Pattern schedule */ 4,16,32,2,1,8,64,128, 128,4,16,32,2,1,8,64, 64,128,4,16,32,2,1,8, 8,64,128,4,16,32,2,1, 1,8,64,128,4,16,32,2, 2,1,8,64,128,4,16,32, 32,2,1,8,64,128,4,16, 16,32,2,1,8,64,128,4 }; /* Precomputed S&P Boxes, Two Varieties */ static char TCB0[256] = { /* NB: char to save space. */ 87, 21,117, 54, 23, 55, 20, 84,116,118, 22, 53, 85,119, 52, 86, 223,157,253,190,159,191,156,220,252,254,158,189,221,255,188,222, 207,141,237,174,143,175,140,204,236,238,142,173,205,239,172,206, 211,145,241,178,147,179,144,208,240,242,146,177,209,243,176,210, 215,149,245,182,151,183,148,212,244,246,150,181,213,247,180,214, 95, 29,125, 62, 31, 63, 28, 92,124,126, 30, 61, 93,127, 60, 94, 219,153,249,186,155,187,152,216,248,250,154,185,217,251,184,218, 67, 1, 97, 34, 3, 35, 0, 64, 96, 98, 2, 33, 65, 99, 32, 66, 195,129,225,162,131,163,128,192,224,226,130,161,193,227,160,194, 199,133,229,166,135,167,132,196,228,230,134,165,197,231,164,198, 203,137,233,170,139,171,136,200,232,234,138,169,201,235,168,202, 75, 9,105, 42, 11, 43, 8, 72,104,106, 10, 41, 73,107, 40, 74, 91, 25,121, 58, 27, 59, 24, 88,120,122, 26, 57, 89,123, 56, 90, 71, 5,101, 38, 7, 39, 4, 68,100,102, 6, 37, 69,103, 36, 70, 79, 13,109, 46, 15, 47, 12, 76,108,110, 14, 45, 77,111, 44, 78, 83, 17,113, 50, 19, 51, 16, 80,112,114, 18, 49, 81,115, 48, 82 }; static char TCB1[256] = { 87,223,207,211,215, 95,219, 67,195,199,203, 75, 91, 71, 79, 83, 21,157,141,145,149, 29,153, 1,129,133,137, 9, 25, 5, 13, 17, 117,253,237,241,245,125,249, 97,225,229,233,105,121,101,109,113, 54,190,174,178,182, 62,186, 34,162,166,170, 42, 58, 38, 46, 50, 23,159,143,147,151, 31,155, 3,131,135,139, 11, 27, 7, 15, 19, 55,191,175,179,183, 63,187, 35,163,167,171, 43, 59, 39, 47, 51, 20,156,140,144,148, 28,152, 0,128,132,136, 8, 24, 4, 12, 16, 84,220,204,208,212, 92,216, 64,192,196,200, 72, 88, 68, 76, 80, 116,252,236,240,244,124,248, 96,224,228,232,104,120,100,108,112, 118,254,238,242,246,126,250, 98,226,230,234,106,122,102,110,114, 22,158,142,146,150, 30,154, 2,130,134,138, 10, 26, 6, 14, 18, 53,189,173,177,181, 61,185, 33,161,165,169, 41, 57, 37, 45, 49, 85,221,205,209,213, 93,217, 65,193,197,201, 73, 89, 69, 77, 81, 119,255,239,243,247,127,251, 99,227,231,235,107,123,103,111,115, 52,188,172,176,180, 60,184, 32,160,164,168, 40, 56, 36, 44, 48, 86,222,206,210,214, 94,218, 66,194,198,202, 74, 90, 70, 78, 82 }; static BYTE Key[16],Pkey[128]; static int P[8] = { 3,5,0,4,2,1,7,6 }; static int Smask[16] = { 128,64,32,16,8,4,2,1 }; void lucifer(bytes) BYTE *bytes; /* points to a 16-byte array */ { register BYTE *cp, *sp, *dp; register int *sbs, tcb, val, j, i; BYTE *h0, *h1, *kc, *ks; h0 = &bytes[0]; /* the "lower" half */ h1 = &bytes[8]; /* the "upper" half */ kc = Pkey; ks = Key; for(i=0; i<16; i++) { tcb = *ks++; sbs = Smask; dp = Dps; for(j=0; j<8; j++) { /* nibbles are selected by the bits of ks */ if(tcb&*sbs++) val = TCB1[h1[j]&0377]; else val = TCB0[h1[j]&0377]; val ^= *kc++; /* fiddle bits in the "lower" half */ for(cp=h0, sp = &h0[8]; cp<sp; cp++) *cp ^= (val&*dp++); } /* swap (virtual) halves */ cp = h0; h0 = h1; h1 = cp; } /* REALLY swap halves */ dp = &bytes[0]; cp = &bytes[8]; for(sp=cp; dp<sp; dp++, cp++) { val = *dp; *dp = *cp; *cp = val; } return; } void loadkey(keystr, edf) /* sets master key */ BYTE *keystr; register int edf; { register BYTE *ep, *cp, *pp; register int kc, i, j; BYTE kk[16], pk[16]; cp = kk; pp = pk; ep = &kk[16]; while(cp < ep) { *cp++ = *keystr; for(*pp=i=0; i<8; i++) if(*keystr&Smask[i]) *pp |= Smask[P[i]]; keystr++; pp++; } cp = Key; pp = Pkey; kc = (edf == DE) ? 8 : 0; for(i=0; i<16; i++) { if(edf == DE) kc = (++kc)&017; *cp++ = kk[kc]; for(j=0; j<8; j++) { *pp++ = pk[kc]; if(j<7 || (edf == DE)) kc = (++kc)&017; } } return; } /* getkey: using up to 16 bytes of aptr, makeup a 16 byte key in savp. aptr must be NULL terminated, savp 16 bytes long. The key returned in savp is aptr encrypted with itself ONCE. */ void getkey(aptr, savp) register char *aptr; register BYTE *savp; { register BYTE *store, *cp; register int i; store = savp; /* copy aptr into savp; NULL aptr */ for(i=0; i<16 && (*aptr != NULL); i++) { *savp++ = toascii(*aptr); *aptr++ = NULL; } while(*aptr) *aptr++ = NULL; if(i == 0) savp++; /* aptr could have been NULL */ /* expand savp out to 16 bytes of "something" and encrypt it */ for(cp=store, savp--; i<16;) store[i++] = (*cp++ + *savp++)&0377; loadkey(store); lucifer(store); return; }
the_stack_data/173577175.c
#include <stdio.h> #include <stdint.h> int suma(int dato, int dato2){ int salida; // en C un dato de tipo int ocupa 32 bits (4 bytes) asm volatile ( // esta instruccion nos permite colocar codigo ensamblador // en el programa c "addl %%ebx, %%eax;" // codigo ensamblador Gnu Assembler, soportado // por el compilador gcc existente en Gnu/Linux : "=a" (salida) // la letra a hace referencia // al operando destino que en la sintaxis at&t, refiere al registro eax // el simbolo = indica que se copiara el valor del regitro eax a una // variable, en este caso salida; una vez se haya ejecutado la //instruccion : "a" (dato), "b" (dato2) // esta instruccion indica que se copiara // el contenido de la variable dato al operando destino (eax), y el // contenido de la variable dato2 se copiara al operando fuente (ebx) ); return salida; } int main(){ int resultado = 0; resultado = suma(5,2); // invocacion de la funcion suma printf("resultado = %d\n", resultado); // impresion en pantalla de la // variable resultado return 0; }
the_stack_data/153269526.c
#include <stdio.h> #include<stdlib.h> #include <sys/ipc.h> #include<sys/types.h> #include<sys/msg.h> struct msgbuf{ long mtype; char msgtxt[200]; }; int main(void){ struct msgbuf msg; int msgid; key_t key; if((key=ftok("sender.c", 'b'))==-1){ perror("key"); exit(1); } if((msgid=msgget(key,0644|IPC_CREAT))==-1){ perror("msgid"); exit(1); } printf("enter the text"); msg.mtype=1; while(gets(msg.msgtxt),!feof(stdin)){ if(msgsnd(msgid,&msg,sizeof(msg),0)==-1){ perror("msgsnd"); exit(1); } } return 0; }
the_stack_data/248580051.c
#ifndef lint static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; #endif #define YYBYACC 1 #define YYMAJOR 1 #define YYMINOR 9 #define YYEMPTY (-1) #define yyclearin (yychar = YYEMPTY) #define yyerrok (yyerrflag = 0) #define YYRECOVERING() (yyerrflag != 0) #ifndef yyparse #define yyparse quote_calc3_parse #endif /* yyparse */ #ifndef yylex #define yylex quote_calc3_lex #endif /* yylex */ #ifndef yyerror #define yyerror quote_calc3_error #endif /* yyerror */ #ifndef yychar #define yychar quote_calc3_char #endif /* yychar */ #ifndef yyval #define yyval quote_calc3_val #endif /* yyval */ #ifndef yylval #define yylval quote_calc3_lval #endif /* yylval */ #ifndef yydebug #define yydebug quote_calc3_debug #endif /* yydebug */ #ifndef yynerrs #define yynerrs quote_calc3_nerrs #endif /* yynerrs */ #ifndef yyerrflag #define yyerrflag quote_calc3_errflag #endif /* yyerrflag */ #ifndef yylhs #define yylhs quote_calc3_lhs #endif /* yylhs */ #ifndef yylen #define yylen quote_calc3_len #endif /* yylen */ #ifndef yydefred #define yydefred quote_calc3_defred #endif /* yydefred */ #ifndef yydgoto #define yydgoto quote_calc3_dgoto #endif /* yydgoto */ #ifndef yysindex #define yysindex quote_calc3_sindex #endif /* yysindex */ #ifndef yyrindex #define yyrindex quote_calc3_rindex #endif /* yyrindex */ #ifndef yygindex #define yygindex quote_calc3_gindex #endif /* yygindex */ #ifndef yytable #define yytable quote_calc3_table #endif /* yytable */ #ifndef yycheck #define yycheck quote_calc3_check #endif /* yycheck */ #ifndef yyname #define yyname quote_calc3_name #endif /* yyname */ #ifndef yyrule #define yyrule quote_calc3_rule #endif /* yyrule */ #define YYPREFIX "quote_calc3_" #define YYPURE 0 #line 2 "quote_calc3.y" # include <stdio.h> # include <ctype.h> int regs[26]; int base; int yylex(void); static void yyerror(const char *s); #line 109 "quote_calc3-s.tab.c" #ifndef YYSTYPE typedef int YYSTYPE; #endif /* compatibility with bison */ #ifdef YYPARSE_PARAM /* compatibility with FreeBSD */ # ifdef YYPARSE_PARAM_TYPE # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) # else # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) # endif #else # define YYPARSE_DECL() yyparse(void) #endif /* Parameters sent to lex. */ #ifdef YYLEX_PARAM # define YYLEX_DECL() yylex(void *YYLEX_PARAM) # define YYLEX yylex(YYLEX_PARAM) #else # define YYLEX_DECL() yylex(void) # define YYLEX yylex() #endif /* Parameters sent to yyerror. */ #ifndef YYERROR_DECL #define YYERROR_DECL() yyerror(const char *s) #endif #ifndef YYERROR_CALL #define YYERROR_CALL(msg) yyerror(msg) #endif extern int YYPARSE_DECL(); #define OP_ADD 257 #define OP_SUB 259 #define OP_MUL 261 #define OP_DIV 263 #define OP_MOD 265 #define OP_AND 267 #define DIGIT 269 #define LETTER 270 #define UMINUS 271 #define YYERRCODE 256 static const short quote_calc3_lhs[] = { -1, 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, }; static const short quote_calc3_len[] = { 2, 0, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 1, 2, }; static const short quote_calc3_defred[] = { 1, 0, 0, 0, 17, 0, 0, 0, 0, 0, 3, 15, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 18, 0, 6, 0, 0, 0, 0, 0, 0, 0, }; static const short quote_calc3_dgoto[] = { 1, 7, 8, 9, }; static const short quote_calc3_sindex[] = { 0, -38, 5, -36, 0, -51, -36, 7, -121, -248, 0, 0, -243, -36, -22, 0, -36, -36, -36, -36, -36, -36, -36, 0, -121, 0, -121, -121, -121, -121, -121, -121, -243, }; static const short quote_calc3_rindex[] = { 0, 0, 0, 0, 0, -9, 0, 0, 13, -10, 0, 0, -5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, -3, -2, -1, 1, 2, 3, -4, }; static const short quote_calc3_gindex[] = { 0, 0, 42, 0, }; #define YYTABLESIZE 258 static const short quote_calc3_table[] = { 16, 15, 6, 22, 6, 14, 13, 7, 8, 9, 13, 10, 11, 12, 16, 10, 17, 15, 18, 25, 19, 23, 20, 4, 21, 5, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 14, 13, 7, 8, 9, 0, 10, 11, 12, 12, 0, 0, 14, 0, 0, 0, 0, 0, 0, 24, 0, 0, 26, 27, 28, 29, 30, 31, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 15, 0, 0, 0, 14, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 3, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 11, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, }; static const short quote_calc3_check[] = { 10, 10, 40, 124, 40, 10, 10, 10, 10, 10, 61, 10, 10, 10, 257, 10, 259, 10, 261, 41, 263, 269, 265, 10, 267, 10, -1, -1, -1, -1, -1, 41, -1, -1, -1, -1, 41, 41, 41, 41, 41, -1, 41, 41, 41, 3, -1, -1, 6, -1, -1, -1, -1, -1, -1, 13, -1, -1, 16, 17, 18, 19, 20, 21, 22, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 124, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 124, 124, -1, -1, -1, 124, 124, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 257, -1, 259, -1, 261, -1, 263, -1, 265, -1, 267, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 256, -1, -1, 259, -1, 259, -1, -1, -1, -1, -1, -1, -1, 269, 270, 269, 270, 257, -1, 259, -1, 261, -1, 263, -1, 265, -1, 267, -1, 257, 257, 259, 259, 261, 261, 263, 263, 265, 265, 267, 267, }; #define YYFINAL 1 #ifndef YYDEBUG #define YYDEBUG 0 #endif #define YYMAXTOKEN 271 #if YYDEBUG static const char *yyname[] = { "end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0, 0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,"OP_ADD","\"ADD-operator\"","OP_SUB","\"SUB-operator\"","OP_MUL", "\"MUL-operator\"","OP_DIV","\"DIV-operator\"","OP_MOD","\"MOD-operator\"", "OP_AND","\"AND-operator\"","DIGIT","LETTER","UMINUS", }; static const char *yyrule[] = { "$accept : list", "list :", "list : list stat '\\n'", "list : list error '\\n'", "stat : expr", "stat : LETTER '=' expr", "expr : '(' expr ')'", "expr : expr OP_ADD expr", "expr : expr OP_SUB expr", "expr : expr OP_MUL expr", "expr : expr OP_DIV expr", "expr : expr OP_MOD expr", "expr : expr OP_AND expr", "expr : expr '|' expr", "expr : OP_SUB expr", "expr : LETTER", "expr : number", "number : DIGIT", "number : number DIGIT", }; #endif int yydebug; int yynerrs; int yyerrflag; int yychar; YYSTYPE yyval; YYSTYPE yylval; /* define the initial stack-sizes */ #ifdef YYSTACKSIZE #undef YYMAXDEPTH #define YYMAXDEPTH YYSTACKSIZE #else #ifdef YYMAXDEPTH #define YYSTACKSIZE YYMAXDEPTH #else #define YYSTACKSIZE 500 #define YYMAXDEPTH 500 #endif #endif #define YYINITSTACKSIZE 500 typedef struct { unsigned stacksize; short *s_base; short *s_mark; short *s_last; YYSTYPE *l_base; YYSTYPE *l_mark; } YYSTACKDATA; /* variables for the parser stack */ static YYSTACKDATA yystack; #line 73 "quote_calc3.y" /* start of programs */ int main (void) { while(!feof(stdin)) { yyparse(); } return 0; } static void yyerror(const char *s) { fprintf(stderr, "%s\n", s); } int yylex(void) { /* lexical analysis routine */ /* returns LETTER for a lower case letter, yylval = 0 through 25 */ /* return DIGIT for a digit, yylval = 0 through 9 */ /* all other characters are returned immediately */ int c; while( (c=getchar()) == ' ' ) { /* skip blanks */ } /* c is now nonblank */ if( islower( c )) { yylval = c - 'a'; return ( LETTER ); } if( isdigit( c )) { yylval = c - '0'; return ( DIGIT ); } return( c ); } #line 362 "quote_calc3-s.tab.c" #if YYDEBUG #include <stdio.h> /* needed for printf */ #endif #include <stdlib.h> /* needed for malloc, etc */ #include <string.h> /* needed for memset */ /* allocate initial stack or double stack size, up to YYMAXDEPTH */ static int yygrowstack(YYSTACKDATA *data) { int i; unsigned newsize; short *newss; YYSTYPE *newvs; if ((newsize = data->stacksize) == 0) newsize = YYINITSTACKSIZE; else if (newsize >= YYMAXDEPTH) return -1; else if ((newsize *= 2) > YYMAXDEPTH) newsize = YYMAXDEPTH; i = (int) (data->s_mark - data->s_base); newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); if (newss == 0) return -1; data->s_base = newss; data->s_mark = newss + i; newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); if (newvs == 0) return -1; data->l_base = newvs; data->l_mark = newvs + i; data->stacksize = newsize; data->s_last = data->s_base + newsize - 1; return 0; } #if YYPURE || defined(YY_NO_LEAKS) static void yyfreestack(YYSTACKDATA *data) { free(data->s_base); free(data->l_base); memset(data, 0, sizeof(*data)); } #else #define yyfreestack(data) /* nothing */ #endif #define YYABORT goto yyabort #define YYREJECT goto yyabort #define YYACCEPT goto yyaccept #define YYERROR goto yyerrlab int YYPARSE_DECL() { int yym, yyn, yystate; #if YYDEBUG const char *yys; if ((yys = getenv("YYDEBUG")) != 0) { yyn = *yys; if (yyn >= '0' && yyn <= '9') yydebug = yyn - '0'; } #endif yynerrs = 0; yyerrflag = 0; yychar = YYEMPTY; yystate = 0; #if YYPURE memset(&yystack, 0, sizeof(yystack)); #endif if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; yystack.s_mark = yystack.s_base; yystack.l_mark = yystack.l_base; yystate = 0; *yystack.s_mark = 0; yyloop: if ((yyn = yydefred[yystate]) != 0) goto yyreduce; if (yychar < 0) { if ((yychar = YYLEX) < 0) yychar = 0; #if YYDEBUG if (yydebug) { yys = 0; if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; if (!yys) yys = "illegal-symbol"; printf("%sdebug: state %d, reading %d (%s)\n", YYPREFIX, yystate, yychar, yys); } #endif } if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) { #if YYDEBUG if (yydebug) printf("%sdebug: state %d, shifting to state %d\n", YYPREFIX, yystate, yytable[yyn]); #endif if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) { goto yyoverflow; } yystate = yytable[yyn]; *++yystack.s_mark = yytable[yyn]; *++yystack.l_mark = yylval; yychar = YYEMPTY; if (yyerrflag > 0) --yyerrflag; goto yyloop; } if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) { yyn = yytable[yyn]; goto yyreduce; } if (yyerrflag) goto yyinrecovery; yyerror("syntax error"); goto yyerrlab; yyerrlab: ++yynerrs; yyinrecovery: if (yyerrflag < 3) { yyerrflag = 3; for (;;) { if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) { #if YYDEBUG if (yydebug) printf("%sdebug: state %d, error recovery shifting\ to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); #endif if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) { goto yyoverflow; } yystate = yytable[yyn]; *++yystack.s_mark = yytable[yyn]; *++yystack.l_mark = yylval; goto yyloop; } else { #if YYDEBUG if (yydebug) printf("%sdebug: error recovery discarding state %d\n", YYPREFIX, *yystack.s_mark); #endif if (yystack.s_mark <= yystack.s_base) goto yyabort; --yystack.s_mark; --yystack.l_mark; } } } else { if (yychar == 0) goto yyabort; #if YYDEBUG if (yydebug) { yys = 0; if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; if (!yys) yys = "illegal-symbol"; printf("%sdebug: state %d, error recovery discards token %d (%s)\n", YYPREFIX, yystate, yychar, yys); } #endif yychar = YYEMPTY; goto yyloop; } yyreduce: #if YYDEBUG if (yydebug) printf("%sdebug: state %d, reducing by rule %d (%s)\n", YYPREFIX, yystate, yyn, yyrule[yyn]); #endif yym = yylen[yyn]; if (yym) yyval = yystack.l_mark[1-yym]; else memset(&yyval, 0, sizeof yyval); switch (yyn) { case 3: #line 35 "quote_calc3.y" { yyerrok ; } break; case 4: #line 39 "quote_calc3.y" { printf("%d\n",yystack.l_mark[0]);} break; case 5: #line 41 "quote_calc3.y" { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; } break; case 6: #line 45 "quote_calc3.y" { yyval = yystack.l_mark[-1]; } break; case 7: #line 47 "quote_calc3.y" { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; } break; case 8: #line 49 "quote_calc3.y" { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; } break; case 9: #line 51 "quote_calc3.y" { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; } break; case 10: #line 53 "quote_calc3.y" { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; } break; case 11: #line 55 "quote_calc3.y" { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; } break; case 12: #line 57 "quote_calc3.y" { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; } break; case 13: #line 59 "quote_calc3.y" { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; } break; case 14: #line 61 "quote_calc3.y" { yyval = - yystack.l_mark[0]; } break; case 15: #line 63 "quote_calc3.y" { yyval = regs[yystack.l_mark[0]]; } break; case 17: #line 68 "quote_calc3.y" { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; } break; case 18: #line 70 "quote_calc3.y" { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; } break; #line 628 "quote_calc3-s.tab.c" } yystack.s_mark -= yym; yystate = *yystack.s_mark; yystack.l_mark -= yym; yym = yylhs[yyn]; if (yystate == 0 && yym == 0) { #if YYDEBUG if (yydebug) printf("%sdebug: after reduction, shifting from state 0 to\ state %d\n", YYPREFIX, YYFINAL); #endif yystate = YYFINAL; *++yystack.s_mark = YYFINAL; *++yystack.l_mark = yyval; if (yychar < 0) { if ((yychar = YYLEX) < 0) yychar = 0; #if YYDEBUG if (yydebug) { yys = 0; if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; if (!yys) yys = "illegal-symbol"; printf("%sdebug: state %d, reading %d (%s)\n", YYPREFIX, YYFINAL, yychar, yys); } #endif } if (yychar == 0) goto yyaccept; goto yyloop; } if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yystate) yystate = yytable[yyn]; else yystate = yydgoto[yym]; #if YYDEBUG if (yydebug) printf("%sdebug: after reduction, shifting from state %d \ to state %d\n", YYPREFIX, *yystack.s_mark, yystate); #endif if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) { goto yyoverflow; } *++yystack.s_mark = (short) yystate; *++yystack.l_mark = yyval; goto yyloop; yyoverflow: yyerror("yacc stack overflow"); yyabort: yyfreestack(&yystack); return (1); yyaccept: yyfreestack(&yystack); return (0); }
the_stack_data/287676.c
#include<stdio.h> #include<math.h> int main(void) { int n1, n2, qd; printf("Primeiro valor: "); scanf("%i", &n1); printf("Segundo valor: "); scanf("%i", &n2); qd = pow(n1, 2) - pow(n2, 2); printf("O quadrado da diferenca entre %i e %i e %i.", n1, n2, qd); return 0; }
the_stack_data/109651.c
void foo(void); void foo(void) { char p = 1; char c = 0; c = 2 & p; }
the_stack_data/1176608.c
#include <stdio.h> struct test { int a; long b; }; int main() { struct test s1[2] = { { 4, 5 }, { 7, 8 } }; struct test s2[2] = { { 6, 2 }, { 1, 3 } }; s1[0] = s2[1]; s2[1].a = 9; s2[1].b = 3; printf("%d %ld %d %ld\n", s1[0].a, s1[0].b, s1[1].a, s1[1].b); printf("%d %ld %d %ld\n", s2[0].a, s2[0].b, s2[1].a, s2[1].b); }
the_stack_data/86074626.c
typedef int size_t; extern struct _iobuf { int _cnt; unsigned char *_ptr; unsigned char *_base; int _bufsiz; short _flag; char _file; } _iob[]; typedef struct _iobuf FILE; extern struct _iobuf *fopen(const char *, const char *); extern struct _iobuf *fdopen(int, const char *); extern struct _iobuf *freopen(const char *, const char *, FILE *); extern struct _iobuf *popen(const char *, const char *); extern struct _iobuf *tmpfile(void); extern long ftell(FILE *); extern char *fgets(char *, int, FILE *); extern char *gets(char *); extern char *sprintf(char *, const char *, ...); extern char *ctermid(char *); extern char *cuserid(char *); extern char *tempnam(const char *, const char *); extern char *tmpnam(char *); typedef struct sm_element_struct sm_element; typedef struct sm_row_struct sm_row; typedef struct sm_col_struct sm_col; typedef struct sm_matrix_struct sm_matrix; struct sm_element_struct { int row_num; int col_num; sm_element *next_row; sm_element *prev_row; sm_element *next_col; sm_element *prev_col; char *user_word; }; struct sm_row_struct { int row_num; int length; int flag; sm_element *first_col; sm_element *last_col; sm_row *next_row; sm_row *prev_row; char *user_word; }; struct sm_col_struct { int col_num; int length; int flag; sm_element *first_row; sm_element *last_row; sm_col *next_col; sm_col *prev_col; char *user_word; }; struct sm_matrix_struct { sm_row **rows; int rows_size; sm_col **cols; int cols_size; sm_row *first_row; sm_row *last_row; int nrows; sm_col *first_col; sm_col *last_col; int ncols; char *user_word; }; extern sm_matrix *sm_alloc(), *sm_alloc_size(), *sm_dup(); extern void sm_free(), sm_delrow(), sm_delcol(), sm_resize(); extern void sm_write(), sm_print(), sm_dump(), sm_cleanup(); extern void sm_copy_row(), sm_copy_col(); extern void sm_remove(), sm_remove_element(); extern sm_element *sm_insert(), *sm_find(); extern sm_row *sm_longest_row(); extern sm_col *sm_longest_col(); extern int sm_read(), sm_read_compressed(); extern sm_row *sm_row_alloc(), *sm_row_dup(), *sm_row_and(); extern void sm_row_free(), sm_row_remove(), sm_row_print(); extern sm_element *sm_row_insert(), *sm_row_find(); extern int sm_row_contains(), sm_row_intersects(); extern int sm_row_compare(), sm_row_hash(); extern sm_col *sm_col_alloc(), *sm_col_dup(), *sm_col_and(); extern void sm_col_free(), sm_col_remove(), sm_col_print(); extern sm_element *sm_col_insert(), *sm_col_find(); extern int sm_col_contains(), sm_col_intersects(); extern int sm_col_compare(), sm_col_hash(); extern int sm_row_dominance(), sm_col_dominance(), sm_block_partition(); extern sm_row *sm_minimum_cover(); extern char _ctype_[]; extern struct _iobuf *popen(const char *, const char *), *tmpfile(void); extern int pclose(FILE *); extern void rewind(FILE *); extern void abort(void), free(void *), exit(int), perror(const char *); extern char *getenv(const char *), *malloc(size_t), *realloc(void *, size_t); extern int system(const char *); extern double atof(const char *); extern char *strcpy(char *, const char *), *strncpy(char *, const char *, size_t), *strcat(char *, const char *), *strncat(char *, const char *, size_t), *strerror(int); extern char *strpbrk(const char *, const char *), *strtok(char *, const char *), *strchr(const char *, int), *strrchr(const char *, int), *strstr(const char *, const char *); extern int strcoll(const char *, const char *), strxfrm(char *, const char *, size_t), strncmp(const char *, const char *, size_t), strlen(const char *), strspn(const char *, const char *), strcspn(const char *, const char *); extern char *memmove(void *, const void *, size_t), *memccpy(void *, const void *, int, size_t), *memchr(const void *, int, size_t), *memcpy(void *, const void *, size_t), *memset(void *, int, size_t); extern int memcmp(const void *, const void *, size_t), strcmp(const char *, const char *); extern long util_cpu_time(); extern int util_getopt(); extern void util_getopt_reset(); extern char *util_path_search(); extern char *util_file_search(); extern int util_pipefork(); extern void util_print_cpu_stats(); extern char *util_print_time(); extern int util_save_image(); extern char *util_strsav(); extern char *util_tilde_expand(); extern void util_restart(); extern int util_optind; extern char *util_optarg; typedef unsigned int *pset; typedef struct set_family { int wsize; int sf_size; int capacity; int count; int active_count; pset data; struct set_family *next; } set_family_t, *pset_family; extern int bit_count[256]; typedef struct cost_struct { int cubes; int in; int out; int mv; int total; int primes; } cost_t, *pcost; typedef struct pair_struct { int cnt; int *var1; int *var2; } pair_t, *ppair; typedef struct symbolic_list_struct { int variable; int pos; struct symbolic_list_struct *next; } symbolic_list_t; typedef struct symbolic_label_struct { char *label; struct symbolic_label_struct *next; } symbolic_label_t; typedef struct symbolic_struct { symbolic_list_t *symbolic_list; int symbolic_list_length; symbolic_label_t *symbolic_label; int symbolic_label_length; struct symbolic_struct *next; } symbolic_t; typedef struct { pset_family F, D, R; char *filename; int pla_type; pset phase; ppair pair; char **label; symbolic_t *symbolic; symbolic_t *symbolic_output; } PLA_t, *pPLA; extern unsigned int debug; extern int verbose_debug; extern char *total_name[16]; extern long total_time[16]; extern int total_calls[16]; extern int echo_comments; extern int echo_unknown_commands; extern int force_irredundant; extern int skip_make_sparse; extern int kiss; extern int pos; extern int print_solution; extern int recompute_onset; extern int remove_essential; extern int single_expand; extern int summary; extern int trace; extern int unwrap_onset; extern int use_random_order; extern int use_super_gasp; extern char *filename; extern int debug_exact_minimization; struct pla_types_struct { char *key; int value; }; struct cube_struct { int size; int num_vars; int num_binary_vars; int *first_part; int *last_part; int *part_size; int *first_word; int *last_word; pset binary_mask; pset mv_mask; pset *var_mask; pset *temp; pset fullset; pset emptyset; unsigned int inmask; int inword; int *sparse; int num_mv_vars; int output; }; struct cdata_struct { int *part_zeros; int *var_zeros; int *parts_active; int *is_unate; int vars_active; int vars_unate; int best; }; extern struct pla_types_struct pla_types[]; extern struct cube_struct cube, temp_cube_save; extern struct cdata_struct cdata, temp_cdata_save; extern int binate_split_select(); extern pset_family cubeunlist(); extern pset *cofactor(); extern pset *cube1list(); extern pset *cube2list(); extern pset *cube3list(); extern pset *scofactor(); extern void massive_count(); extern pset_family complement(); extern pset_family simplify(); extern void simp_comp(); extern int d1_rm_equal(); extern int rm2_contain(); extern int rm2_equal(); extern int rm_contain(); extern int rm_equal(); extern int rm_rev_contain(); extern pset *sf_list(); extern pset *sf_sort(); extern pset_family d1merge(); extern pset_family dist_merge(); extern pset_family sf_contain(); extern pset_family sf_dupl(); extern pset_family sf_ind_contain(); extern pset_family sf_ind_unlist(); extern pset_family sf_merge(); extern pset_family sf_rev_contain(); extern pset_family sf_union(); extern pset_family sf_unlist(); extern void cube_setup(); extern void restore_cube_struct(); extern void save_cube_struct(); extern void setdown_cube(); extern PLA_labels(); extern char *get_word(); extern int label_index(); extern int read_pla(); extern int read_symbolic(); extern pPLA new_PLA(); extern void PLA_summary(); extern void free_PLA(); extern void parse_pla(); extern void read_cube(); extern void skip_line(); extern foreach_output_function(); extern int cubelist_partition(); extern int so_both_do_espresso(); extern int so_both_do_exact(); extern int so_both_save(); extern int so_do_espresso(); extern int so_do_exact(); extern int so_save(); extern pset_family cof_output(); extern pset_family lex_sort(); extern pset_family mini_sort(); extern pset_family random_order(); extern pset_family size_sort(); extern pset_family sort_reduce(); extern pset_family uncof_output(); extern pset_family unravel(); extern pset_family unravel_range(); extern void so_both_espresso(); extern void so_espresso(); extern char *fmt_cost(); extern char *print_cost(); extern char *util_strsav(); extern void copy_cost(); extern void cover_cost(); extern void fatal(); extern void print_trace(); extern void size_stamp(); extern void totals(); extern char *fmt_cube(); extern char *fmt_expanded_cube(); extern char *pc1(); extern char *pc2(); extern char *pc3(); extern int makeup_labels(); extern kiss_output(); extern kiss_print_cube(); extern output_symbolic_constraints(); extern void cprint(); extern void debug1_print(); extern void debug_print(); extern void eqn_output(); extern void fpr_header(); extern void fprint_pla(); extern void pls_group(); extern void pls_label(); extern void pls_output(); extern void print_cube(); extern void print_expanded_cube(); extern void sf_debug_print(); extern find_equiv_outputs(); extern int check_equiv(); extern pset_family espresso(); extern int essen_cube(); extern pset_family cb_consensus(); extern pset_family cb_consensus_dist0(); extern pset_family essential(); extern pset_family minimize_exact(); extern pset_family minimize_exact_literals(); extern int feasibly_covered(); extern int most_frequent(); extern pset_family all_primes(); extern pset_family expand(); extern pset_family find_all_primes(); extern void elim_lowering(); extern void essen_parts(); extern void essen_raising(); extern void expand1(); extern void mincov(); extern void select_feasible(); extern void setup_BB_CC(); extern pset_family expand_gasp(); extern pset_family irred_gasp(); extern pset_family last_gasp(); extern pset_family super_gasp(); extern void expand1_gasp(); extern int util_getopt(); extern find_dc_inputs(); extern find_inputs(); extern form_bitvector(); extern map_dcset(); extern map_output_symbolic(); extern map_symbolic(); extern pset_family map_symbolic_cover(); extern symbolic_hack_labels(); extern int cube_is_covered(); extern int taut_special_cases(); extern int tautology(); extern pset_family irredundant(); extern void mark_irredundant(); extern void irred_split_cover(); extern sm_matrix *irred_derive_table(); extern pset minterms(); extern void explode(); extern void map(); extern output_phase_setup(); extern pPLA set_phase(); extern pset_family opo(); extern pset find_phase(); extern pset_family find_covers(); extern pset_family form_cover_table(); extern pset_family opo_leaf(); extern pset_family opo_recur(); extern void opoall(); extern void phase_assignment(); extern void repeated_phase_assignment(); extern generate_all_pairs(); extern int **find_pairing_cost(); extern int find_best_cost(); extern int greedy_best_cost(); extern int minimize_pair(); extern int pair_free(); extern pair_all(); extern pset_family delvar(); extern pset_family pairvar(); extern ppair pair_best_cost(); extern ppair pair_new(); extern ppair pair_save(); extern print_pair(); extern void find_optimal_pairing(); extern void set_pair(); extern void set_pair1(); extern pset_family primes_consensus(); extern int sccc_special_cases(); extern pset_family reduce(); extern pset reduce_cube(); extern pset sccc(); extern pset sccc_cube(); extern pset sccc_merge(); extern int set_andp(); extern int set_orp(); extern int setp_disjoint(); extern int setp_empty(); extern int setp_equal(); extern int setp_full(); extern int setp_implies(); extern char *pbv1(); extern char *ps1(); extern int *sf_count(); extern int *sf_count_restricted(); extern int bit_index(); extern int set_dist(); extern int set_ord(); extern void set_adjcnt(); extern pset set_and(); extern pset set_clear(); extern pset set_copy(); extern pset set_diff(); extern pset set_fill(); extern pset set_merge(); extern pset set_or(); extern pset set_xor(); extern pset sf_and(); extern pset sf_or(); extern pset_family sf_active(); extern pset_family sf_addcol(); extern pset_family sf_addset(); extern pset_family sf_append(); extern pset_family sf_bm_read(); extern pset_family sf_compress(); extern pset_family sf_copy(); extern pset_family sf_copy_col(); extern pset_family sf_delc(); extern pset_family sf_delcol(); extern pset_family sf_inactive(); extern pset_family sf_join(); extern pset_family sf_new(); extern pset_family sf_permute(); extern pset_family sf_read(); extern pset_family sf_save(); extern pset_family sf_transpose(); extern void set_write(); extern void sf_bm_print(); extern void sf_cleanup(); extern void sf_delset(); extern void sf_free(); extern void sf_print(); extern void sf_write(); extern int ccommon(); extern int cdist0(); extern int full_row(); extern int ascend(); extern int cactive(); extern int cdist(); extern int cdist01(); extern int cvolume(); extern int d1_order(); extern int d1_order_size(); extern int desc1(); extern int descend(); extern int lex_order(); extern int lex_order1(); extern pset force_lower(); extern void consensus(); extern pset_family cb1_dsharp(); extern pset_family cb_dsharp(); extern pset_family cb_recur_dsharp(); extern pset_family cb_recur_sharp(); extern pset_family cb_sharp(); extern pset_family cv_dsharp(); extern pset_family cv_intersect(); extern pset_family cv_sharp(); extern pset_family dsharp(); extern pset_family make_disjoint(); extern pset_family sharp(); pset do_sm_minimum_cover(pset_family A); extern pset_family make_sparse(); extern pset_family mv_reduce(); extern qsort(void *, size_t, size_t, int (*) (const void *, const void *)); extern qst(); extern pset_family find_all_minimal_covers_petrick(); extern pset_family map_cover_to_unate(); extern pset_family map_unate_to_cover(); extern pset_family exact_minimum_cover(); extern pset_family gen_primes(); extern pset_family unate_compl(); extern pset_family unate_complement(); extern pset_family unate_intersect(); extern PLA_permute(); extern int PLA_verify(); extern int check_consistency(); extern int verify(); pset do_sm_minimum_cover(pset_family A) { sm_matrix *M; sm_row *sparse_cover; sm_element *pe; pset cover; register int i, base, rownum; register unsigned val; register pset last, p; M = sm_alloc(); rownum = 0; for( p=A->data, last= p+A->count*A->wsize; p< last; p+=A->wsize) { for( i = (p[0] & 0x03ff); i > 0; ) for( val = p[ i], base = -- i << 5; val != 0; base++, val >>= 1) if ( val & 1) { (void) sm_insert(M, rownum, base); } rownum++; } sparse_cover = sm_minimum_cover(M, ((int *) 0), 1, 0); sm_free(M); cover = set_clear(((unsigned int *) malloc(sizeof(unsigned int) * ( ((A->sf_size) <= 32 ? 2 : (((((A->sf_size)-1) >> 5) + 1) + 1))))), A->sf_size); for( pe = sparse_cover->first_col; pe != 0; pe = pe->next_col) { (cover[((( pe->col_num) >> 5) + 1)] |= 1 << (( pe->col_num) & (32-1))); } sm_row_free(sparse_cover); return cover; }
the_stack_data/26700598.c
/*---------------------------------------------------------------------------* * <RCS keywords> * * C++ Library * * Copyright 1992-1994, David Gottner * * All Rights Reserved * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, * provided that the above copyright notice, this permission notice and * the following disclaimer notice appear unmodified in all copies. * * I DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL I * BE LIABLE FOR ANY SPECIAL, 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. * * Nevertheless, I would like to know about bugs in this library or * suggestions for improvment. Send bug reports and feedback to * [email protected]. *---------------------------------------------------------------------------*/ #include <stdio.h> #include <string.h> int _PyOS_opterr = 1; /* generate error messages */ int _PyOS_optind = 1; /* index into argv array */ char *_PyOS_optarg = NULL; /* optional argument */ int _PyOS_GetOpt(int argc, char **argv, char *optstring) { static char *opt_ptr = ""; char *ptr; int option; if (*opt_ptr == '\0') { if (_PyOS_optind >= argc || argv[_PyOS_optind][0] != '-' || argv[_PyOS_optind][1] == '\0' /* lone dash */ ) return -1; else if (strcmp(argv[_PyOS_optind], "--") == 0) { ++_PyOS_optind; return -1; } opt_ptr = &argv[_PyOS_optind++][1]; } if ( (option = *opt_ptr++) == '\0') return -1; if ((ptr = strchr(optstring, option)) == NULL) { if (_PyOS_opterr) fprintf(stderr, "Unknown option: -%c\n", option); return '?'; } if (*(ptr + 1) == ':') { if (*opt_ptr != '\0') { _PyOS_optarg = opt_ptr; opt_ptr = ""; } else { if (_PyOS_optind >= argc) { if (_PyOS_opterr) fprintf(stderr, "Argument expected for the -%c option\n", option); return '?'; } _PyOS_optarg = argv[_PyOS_optind++]; } } return option; }
the_stack_data/144606.c
/* * PCbO: Parallel Close-by-One (AMAI Version; http://fcalgs.sourceforge.net/) * * Copyright (C) 2007-2009 * Petr Krajca, <[email protected]> * Jan Outrata, <[email protected]> * Vilem Vychodil, <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ****************************************************************************** * * Users in academia are kindly asked to cite the following resources if the * program is used to pursue any research activities which may result in * publications: * * Krajca P., Outrata J., Vychodil V.: Parallel Recursive Algorithm for FCA. * In: Proc. CLA 2008, CEUR WS, 433(2008), 71-82. ISBN 978-80-244-2111-7. * http://sunsite.informatik.rwth-aachen.de/Publications/CEUR-WS/Vol-433/ * */ #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef WINNT #include <windows.h> #include <process.h> #else #include <pthread.h> #endif #define BIT ((unsigned long) 1) #define NULL_LONG ((unsigned long) 0) #define INT_SIZE (sizeof (int)) #define LONG_SIZE (sizeof (unsigned long)) #define ARCHBIT ((LONG_SIZE * 8) - 1) #define BYTE_COUNT_A (LONG_SIZE * int_count_a) #define BYTE_COUNT_O (LONG_SIZE * int_count_o) #define BUFFER_BLOCK 1024 #define MAX_DECIMAL_INT_SIZE (8) #define OUTPUT_BUF_CAPACITY (32 * MAX_DECIMAL_INT_SIZE) struct str_int { char str[MAX_DECIMAL_INT_SIZE]; int length; } *table_of_ints; int attributes = 0; int objects = 0; int int_count_a = 0; int int_count_o = 0; int table_entries = 0; int min_support = 0; unsigned long *context; unsigned long *(*cols)[ARCHBIT + 1]; int (*supps)[ARCHBIT + 1]; unsigned long upto_bit[ARCHBIT + 1]; int attr_offset = 0; FILE *in_file; FILE *out_file; int cpus = 1; int threads; int para_level = 2; int verbosity_level = 1; #ifdef WINNT typedef HANDLE thread_id_t; #else typedef pthread_t thread_id_t; #endif thread_id_t *thread_id; int *thread_i; unsigned char **thread_queue; unsigned char **thread_queue_head; unsigned char **thread_queue_limit; unsigned long **thread_intents; #ifdef WINNT HANDLE output_lock; #else pthread_mutex_t output_lock = PTHREAD_MUTEX_INITIALIZER; #endif struct thread_stat { int closures; int computed; int queue_length; }; struct thread_stat *counts; struct thread_stat initial_thr_stat; int get_next_integer (file, value) FILE *file; int *value; { int ch = ' '; *value = -1; while ((ch != EOF) && ((ch < '0') || (ch > '9'))) { ch = fgetc (file); if (ch == '\n') return 1; } if (ch == EOF) return 0; *value = 0; while ((ch >= '0') && (ch <= '9')) { *value *= 10; *value += ch - '0'; ch = fgetc (file); } ungetc (ch, file); *value -= attr_offset; if (*value < 0) { fprintf (stderr, "Invalid input value: %i (minimum value is %i), quitting.\n", *value + attr_offset, attr_offset); exit (1); } return 1; } #define PUSH_NEW_INTEGER(__value) \ { \ if (index >= buff_size) { \ buff_size += BUFFER_BLOCK; \ buff = (int *) realloc (buff, INT_SIZE * buff_size); \ if (! buff) { \ fprintf (stderr, "Cannot reallocate buffer, quitting.\n"); \ exit (4); \ } \ } \ buff [index] = (__value); \ index ++; \ } void table_of_ints_init (max) int max; { int i; table_of_ints = malloc (sizeof (struct str_int) * max); for (i = 0; i < max; i++) { sprintf (table_of_ints[i].str, "%i", i); table_of_ints[i].length = strlen (table_of_ints[i].str); } } void read_context (file) FILE *file; { int last_value = -1, value = 0, last_attribute = -1, last_object = -1; int *buff, i, index = 0, row = 0; size_t buff_size = BUFFER_BLOCK; if (attr_offset < 0) attr_offset = 0; buff = (int *) malloc (INT_SIZE * buff_size); if (!buff) { fprintf (stderr, "Cannot allocate buffer, quitting.\n"); exit (3); } while (get_next_integer (file, &value)) { if ((value < 0) && (last_value < 0)) continue; if (value < 0) { last_object++; PUSH_NEW_INTEGER (-1); } else { if (value > last_attribute) last_attribute = value; PUSH_NEW_INTEGER (value); table_entries++; } last_value = value; } if (last_value >= 0) { last_object++; PUSH_NEW_INTEGER (-1); } objects = last_object + 1; attributes = last_attribute + 1; int_count_a = (attributes / (ARCHBIT + 1)) + 1; int_count_o = (objects / (ARCHBIT + 1)) + 1; context = (unsigned long *) malloc (LONG_SIZE * int_count_a * objects); if (!context) { fprintf (stderr, "Cannot allocate bitcontext, quitting.\n"); exit (5); } memset (context, 0, LONG_SIZE * int_count_a * objects); for (i = 0; i < index; i++) { if (buff[i] < 0) { row++; continue; } context[row * int_count_a + (buff[i] / (ARCHBIT + 1))] |= (BIT << (ARCHBIT - (buff[i] % (ARCHBIT + 1)))); } free (buff); } void print_attributes (set) const unsigned long *set; { int i, j, c, first = 1; char buf[OUTPUT_BUF_CAPACITY + MAX_DECIMAL_INT_SIZE + 2]; int buf_ptr = 0; int locked = 0; if (verbosity_level <= 0) return; for (c = j = 0; j < int_count_a; j++) { for (i = ARCHBIT; i >= 0; i--) { if (set[j] & (BIT << i)) { if (!first) buf[buf_ptr++] = ' '; strcpy (buf + buf_ptr, table_of_ints[c].str); buf_ptr += table_of_ints[c].length; if (buf_ptr >= OUTPUT_BUF_CAPACITY) { buf[buf_ptr] = '\0'; buf_ptr = 0; if (!locked) { #ifdef WINNT WaitForSingleObject (output_lock, INFINITE); #else pthread_mutex_lock (&output_lock); #endif locked = 1; } fputs (buf, out_file); } first = 0; } c++; if (c >= attributes) goto out; } } out: buf[buf_ptr++] = '\n'; buf[buf_ptr] = '\0'; if (!locked) { #ifdef WINNT WaitForSingleObject (output_lock, INFINITE); #else pthread_mutex_lock (&output_lock); #endif } fputs (buf, out_file); #ifdef WINNT ReleaseMutex (output_lock); #else pthread_mutex_unlock (&output_lock); #endif } void print_context_info (void) { if (verbosity_level >= 2) fprintf (stderr, "(:objects %6i :attributes %4i :entries %8i)\n", objects, attributes, table_entries); } void print_thread_info (id, stat) int id; struct thread_stat stat; { if (verbosity_level >= 2) fprintf (stderr, "(:proc %3i :closures %7i :computed %7i :queue-length %3i)\n", id, stat.closures, stat.computed, stat.queue_length); } void print_initial_thread_info (levels, stat, last_level_concepts) int levels; struct thread_stat stat; int last_level_concepts; { if (verbosity_level >= 2) fprintf (stderr, "(:proc %3i :closures %7i :computed %7i :levels %i :last-level-concepts %i)\n", 0, stat.closures, stat.computed, levels + 1, last_level_concepts); } void initialize_algorithm (void) { int i, j, x, y; unsigned long *ptr; unsigned long mask; unsigned long *cols_buff; for (i = 0; i <= ARCHBIT; i++) { upto_bit[i] = NULL_LONG; for (j = ARCHBIT; j > i; j--) upto_bit[i] |= (BIT << j); } cols_buff = (unsigned long *) malloc (LONG_SIZE * int_count_o * (ARCHBIT + 1) * int_count_a); memset (cols_buff, 0, LONG_SIZE * int_count_o * (ARCHBIT + 1) * int_count_a); cols = (unsigned long *(*)[ARCHBIT + 1]) malloc (sizeof (unsigned long *) * (ARCHBIT + 1) * int_count_a); supps = (int (*)[ARCHBIT + 1]) malloc (sizeof (int) * (ARCHBIT + 1) * int_count_a); ptr = cols_buff; for (j = 0; j < int_count_a; j++) for (i = ARCHBIT; i >= 0; i--) { mask = (BIT << i); cols[j][i] = ptr; supps[j][i] = 0; for (x = 0, y = j; x < objects; x++, y += int_count_a) if (context[y] & mask) { ptr[x / (ARCHBIT + 1)] |= BIT << (x % (ARCHBIT + 1)); supps[j][i]++; } ptr += int_count_o; } table_of_ints_init (attributes); } void compute_closure (intent, extent, prev_extent, atr_extent, supp) unsigned long *intent, *extent, *prev_extent, *atr_extent; size_t *supp; { int i, j, k, l; memset (intent, 0xFF, BYTE_COUNT_A); if (atr_extent) { *supp = 0; for (k = 0; k < int_count_o; k++) { extent[k] = prev_extent[k] & atr_extent[k]; if (extent[k]) for (l = 0; l <= ARCHBIT; l++) if (extent[k] & (BIT << l)) { for (i = 0, j = int_count_a * (k * (ARCHBIT + 1) + l); i < int_count_a; i++, j++) intent[i] &= context[j]; (*supp)++; } } } else { memset (extent, 0xFF, BYTE_COUNT_O); for (j = 0; j < objects; j++) { for (i = 0; i < int_count_a; i++) intent[i] &= context[int_count_a * j + i]; } } } void generate_from_node (intent, extent, start_int, start_bit, id) unsigned long *intent; unsigned long *extent; int start_int, start_bit; int id; { int i, total; size_t supp = 0; unsigned long *new_extent; unsigned long *new_intent; new_intent = extent + int_count_o; new_extent = new_intent + int_count_a; total = start_int * (ARCHBIT + 1) + (ARCHBIT - start_bit); for (; start_int < int_count_a; start_int++) { for (; start_bit >= 0; start_bit--) { if (total >= attributes) return; total++; if ((intent[start_int] & (BIT << start_bit)) || (supps[start_int][start_bit] < min_support)) continue; compute_closure (new_intent, new_extent, extent, cols[start_int][start_bit], &supp); counts[id].closures++; if ((new_intent[start_int] ^ intent[start_int]) & upto_bit[start_bit]) goto skip; for (i = 0; i < start_int; i++) if (new_intent[i] ^ intent[i]) goto skip; if (supp < min_support) goto skip; counts[id].computed++; print_attributes (new_intent); if (new_intent[int_count_a - 1] & BIT) goto skip; if (start_bit == 0) generate_from_node (new_intent, new_extent, start_int + 1, ARCHBIT, id); else generate_from_node (new_intent, new_extent, start_int, start_bit - 1, id); skip: ; } start_bit = ARCHBIT; } return; } #ifdef WINNT unsigned __stdcall #else void * #endif thread_func (params) void *params; { int id; id = *(int *) params; for (; thread_queue_head[id] < thread_queue[id];) { memcpy (thread_intents[id], thread_queue_head[id], BYTE_COUNT_A + BYTE_COUNT_O); thread_queue_head[id] += BYTE_COUNT_A + BYTE_COUNT_O; generate_from_node (thread_intents[id], thread_intents[id] + int_count_a, *(int *) thread_queue_head[id], *(int *) (thread_queue_head[id] + INT_SIZE), id); thread_queue_head[id] += INT_SIZE << 1; } #ifdef WINNT return 0; #else return NULL; #endif } void parallel_generate_from_node (intent, extent, start_int, start_bit, rec_level, id) unsigned long *intent; unsigned long *extent; int start_int, start_bit, rec_level; int id; { int i, total; static int num = 0; size_t supp = 0; unsigned long *new_extent; unsigned long *new_intent; if (rec_level == para_level) { i = num % threads; memcpy ((unsigned long *) thread_queue[i], intent, BYTE_COUNT_A + BYTE_COUNT_O); thread_queue[i] += BYTE_COUNT_A + BYTE_COUNT_O; *(int *) thread_queue[i] = start_int; thread_queue[i] += INT_SIZE; *(int *) thread_queue[i] = start_bit; thread_queue[i] += INT_SIZE; counts[i].queue_length++; if (thread_queue[i] == thread_queue_limit[i]) { total = thread_queue_limit[i] - thread_queue_head[i]; thread_queue_head[i] = (unsigned char *) realloc (thread_queue_head[i], total << 1); thread_queue[i] = thread_queue_head[i] + total; thread_queue_limit[i] = thread_queue_head[i] + (total << 1); } num++; return; } new_intent = extent + int_count_o; new_extent = new_intent + int_count_a; total = start_int * (ARCHBIT + 1) + (ARCHBIT - start_bit); for (; start_int < int_count_a; start_int++) { for (; start_bit >= 0; start_bit--) { if (total >= attributes) goto out; total++; if ((intent[start_int] & (BIT << start_bit)) || (supps[start_int][start_bit] < min_support)) continue; compute_closure (new_intent, new_extent, extent, cols[start_int][start_bit], &supp); counts[id].closures++; if ((new_intent[start_int] ^ intent[start_int]) & upto_bit[start_bit]) goto skip; for (i = 0; i < start_int; i++) if (new_intent[i] ^ intent[i]) goto skip; if (supp < min_support) goto skip; counts[id].computed++; print_attributes (new_intent); if (new_intent[int_count_a - 1] & BIT) goto skip; if (start_bit == 0) parallel_generate_from_node (new_intent, new_extent, start_int + 1, ARCHBIT, rec_level + 1, id); else parallel_generate_from_node (new_intent, new_extent, start_int, start_bit - 1, rec_level + 1, id); skip: ; } start_bit = ARCHBIT; } out: if (rec_level == 0) { print_initial_thread_info (para_level, counts[0], num); initial_thr_stat = counts[0]; counts[0].closures = 0; counts[0].computed = 0; for (i = 1; i < threads; i++) if (thread_queue_head[i] != thread_queue[i]) #ifdef WINNT thread_id[i] = (HANDLE) _beginthreadex (NULL, 0, thread_func, &thread_i[i], 0, NULL); #else pthread_create (&thread_id[i], NULL, thread_func, &thread_i[i]); #endif for (; thread_queue_head[id] < thread_queue[id];) { memcpy (thread_intents[id], thread_queue_head[id], BYTE_COUNT_A + BYTE_COUNT_O); thread_queue_head[id] += BYTE_COUNT_A + BYTE_COUNT_O; generate_from_node (thread_intents[id], thread_intents[id] + int_count_a, *(int *) thread_queue_head[id], *(int *) (thread_queue_head[id] + INT_SIZE), id); thread_queue_head[id] += INT_SIZE << 1; } } return; } void find_all_intents (void) { int i, queue_size, attrs; if (para_level <= 0) para_level = 1; if (para_level > attributes) para_level = attributes; threads = cpus; if (threads <= 0) threads = 1; if (verbosity_level >= 3) fprintf (stderr, "INFO: running in %i threads\n", threads); counts = (struct thread_stat *) calloc (threads, sizeof (struct thread_stat)); thread_id = (thread_id_t *) malloc (sizeof (thread_id_t) * threads); memset (thread_id, 0, sizeof (thread_id_t) * threads); thread_i = (int *) malloc (sizeof (int) * threads); thread_queue = (unsigned char **) malloc (sizeof (unsigned char *) * threads); thread_queue_head = (unsigned char **) malloc (sizeof (unsigned char *) * threads); thread_queue_limit = (unsigned char **) malloc (sizeof (unsigned char *) * threads); thread_intents = (unsigned long **) malloc (sizeof (unsigned long *) * threads); queue_size = attributes; queue_size = queue_size / threads + 1; attrs = attributes - para_level + 1; for (i = 0; i < threads; i++) { thread_i[i] = i; thread_queue_head[i] = thread_queue[i] = (unsigned char *) malloc ((BYTE_COUNT_A + BYTE_COUNT_O + (INT_SIZE << 1)) * queue_size); thread_queue_limit[i] = thread_queue_head[i] + (BYTE_COUNT_A + BYTE_COUNT_O + (INT_SIZE << 1)) * queue_size; thread_intents[i] = (unsigned long *) malloc ((BYTE_COUNT_A + BYTE_COUNT_O) * attrs); } compute_closure (thread_intents[0], thread_intents[0] + int_count_a, NULL, NULL, NULL); counts[0].closures++; counts[0].computed++; print_attributes (thread_intents[0]); if (thread_intents[0][int_count_a - 1] & BIT) return; parallel_generate_from_node (thread_intents[0], thread_intents[0] + int_count_a, 0, ARCHBIT, 0, 0); print_thread_info (1, counts[0]); for (i = 1; i < threads; i++) { if (thread_id[i]) { #ifdef WINNT WaitForSingleObject (thread_id[i], INFINITE); CloseHandle (thread_id[i]); #else pthread_join (thread_id[i], NULL); #endif } print_thread_info (i + 1, counts[i]); counts[0].computed += counts[i].computed; counts[0].closures += counts[i].closures; } counts[0].computed += initial_thr_stat.computed; counts[0].closures += initial_thr_stat.closures; if (verbosity_level >= 3) fprintf (stderr, "INFO: total %7i closures\n", counts[0].closures); if (verbosity_level >= 3) fprintf (stderr, "INFO: total %7i concepts\n", counts[0].computed); } int main (argc, argv) int argc; char **argv; { in_file = stdin; out_file = stdout; if (argc > 1) { int index = 1; for (; (index < argc && argv[index][0] == '-' && argv[index][1] != 0); index++) { switch (argv[index][1]) { case 'S': min_support = atoi (argv[index] + 2); break; case 'P': cpus = atoi (argv[index] + 2); break; case 'L': para_level = atoi (argv[index] + 2) - 1; break; case 'V': verbosity_level = atoi (argv[index] + 2); break; default: attr_offset = atoi (argv[index] + 1); } } if ((argc > index) && (argv[index][0] != '-')) in_file = fopen (argv[index], "rb"); if ((argc > index + 1) && (argv[index + 1][0] != '-')) out_file = fopen (argv[index + 1], "wb"); } if (!in_file) { fprintf (stderr, "%s: cannot open input data stream\n", argv[0]); return 1; } if (!out_file) { fprintf (stderr, "%s: open output data stream\n", argv[0]); return 2; } #ifdef WINNT output_lock = CreateMutex (NULL, FALSE, NULL); #endif read_context (in_file); fclose (in_file); print_context_info (); initialize_algorithm (); find_all_intents (); fclose (out_file); return 0; }
the_stack_data/850552.c
#include <stdio.h> #include <string.h> #define BUFSIZE 10 void checkString(char s1[], char s2[], char name[], char joker[]) { if (strstr(name, joker) != NULL) { printf("%s", s1); } else { printf("%s", s2); } } void bufferOverflowAttack(){ char B[BUFSIZE]; char s1[16] = "I owe you $1000"; char s2[17] = "I don't know you"; char expectedName[] = "joker"; printf("What's your name?\n"); gets(B); checkString(s1, s2, B, expectedName); printf("\n"); } int main() { bufferOverflowAttack(); return 0; }
the_stack_data/165768654.c
#ifndef TH_GENERIC_FILE #define TH_GENERIC_FILE "generic/Tanh.c" #else void THNN_(Tanh_updateOutput)( THNNState *state, THTensor *input, THTensor *output) { THTensor_(tanh)(output, input); } void THNN_(Tanh_updateGradInput)( THNNState *state, THTensor *gradOutput, THTensor *gradInput, THTensor *output) { THNN_CHECK_SHAPE(output, gradOutput); THTensor_(resizeAs)(gradInput, output); if (THTensor_nDimensionLegacyAll(output) == 1 || !THTensor_(isContiguous)(output) || !THTensor_(isContiguous)(gradOutput) || !THTensor_(isContiguous)(gradInput)) { TH_TENSOR_APPLY3(real, gradInput, real, gradOutput, real, output, real z = *output_data; \ *gradInput_data = *gradOutput_data * (1. - z*z); ); } else { real* ptr_gradOutput = THTensor_(data)(gradOutput); real* ptr_gradInput = THTensor_(data)(gradInput); real* ptr_output = THTensor_(data)(output); int64_t i; #pragma omp parallel for private(i) for (i = 0; i < THTensor_(nElement)(gradInput); i++) { real z = ptr_output[i]; ptr_gradInput[i] = ptr_gradOutput[i] * (1. - z*z); } } } #endif
the_stack_data/117328363.c
/* The Computer Language Benchmarks Game * http://benchmarksgame.alioth.debian.org/ * * Contributed by Sebastien Loisel */ #ifdef STATIC #undef STATIC #define STATIC static #else #define STATIC #endif #ifdef PRINTF #define PRINTF2(a,b) printf(a,b) #else #define PRINTF2(a,b) b #endif #ifdef TIMER #define TIMER_START() intrinsic_label(TIMER_START) #define TIMER_STOP() intrinsic_label(TIMER_STOP) #else #define TIMER_START() #define TIMER_STOP() #endif #ifdef __Z88DK #include <intrinsic.h> #endif #include <stdio.h> #include <stdlib.h> #include <math.h> #define NUM 100 double eval_A(int i, int j) { #ifdef __MATH_MATH32 return inv((i+j)*(i+j+1)/2+i+1); #else return 1.0/((i+j)*(i+j+1)/2+i+1); #endif } void eval_A_times_u(const double u[], double Au[]) { STATIC int i,j; for(i=0;i<NUM;i++) { Au[i]=0; for(j=0;j<NUM;j++) Au[i]+=eval_A(i,j)*u[j]; } } void eval_At_times_u(const double u[], double Au[]) { STATIC int i,j; for(i=0;i<NUM;i++) { Au[i]=0; for(j=0;j<NUM;j++) Au[i]+=eval_A(j,i)*u[j]; } } void eval_AtA_times_u(const double u[], double AtAu[]) { static double v[NUM]; eval_A_times_u(u,v); eval_At_times_u(v,AtAu); } int main(void) { STATIC int i; STATIC double u[NUM],v[NUM],vBv,vv; TIMER_START(); for(i=0;i<NUM;i++) u[i]=1; for(i=0;i<10;i++) { eval_AtA_times_u(u,v); eval_AtA_times_u(v,u); } vBv=vv=0; for(i=0;i<NUM;i++) { vBv+=u[i]*v[i]; vv+=v[i]*v[i]; } PRINTF2("%0.9f\n",sqrt(vBv/vv)); TIMER_STOP(); return 0; }
the_stack_data/178264858.c
#include <math.h> #include <stdio.h> #include <stdlib.h> #define D(d) (((d ^ d >> 1) & 1) * 2 - 1) int main(int argc, char **argv) { if (argc < 3) return 0; int w = atoi(argv[1]), h = atoi(argv[ 2]), m = log10(w * h * 100), *g = malloc(w * h * sizeof (int)), d = 1, v = 1, p[] = {0, 0, 0, 0, 0, 0, w - d, h - v, 7, 4, 5, 6}; while (p[0] >= p[4] && p[6] >= p[0] && p[1] >= p[ 5] && p[ 7] >= p[1] ) { g[(p[ 3] = p[1 ]) * w + ( p[2] = p[ 0] )] = v++; p[(~d & 1) + 2] += D(d); if (p[2] >= p[4] && p[6] >= p[2] && p[3] >= p[ 5] && p[ 7] >= p[3]) { p[0] = p[2]; p[1] = p[3]; } else {d = d + 1 & 3; p[p[d + 8]] += D(d); p[p[d + 8] & 1] += D(d); } } for (v = 0; v < h; v++) for ( d = 0; d < w; d++) printf("%*d", m, g[v * w + d ]) && !(w - d - 1) && printf("\n"); return 0; }
the_stack_data/26701610.c
#include <math.h> extern double x; void kermom(double w[], double y, int m) { double d,df,clog,x2,x3,x4,y2; if (y >= x) { d=y-x; df=2.0*sqrt(d)*d; w[1]=df/3.0; w[2]=df*(x/3.0+d/5.0); w[3]=df*((x/3.0 + 0.4*d)*x + d*d/7.0); w[4]=df*(((x/3.0 + 0.6*d)*x + 3.0*d*d/7.0)*x+d*d*d/9.0); } else { x3=(x2=x*x)*x; x4=x2*x2; y2=y*y; d=x-y; w[1]=d*((clog=log(d))-1.0); w[2] = -0.25*(3.0*x+y-2.0*clog*(x+y))*d; w[3]=(-11.0*x3+y*(6.0*x2+y*(3.0*x+2.0*y)) +6.0*clog*(x3-y*y2))/18.0; w[4]=(-25.0*x4+y*(12.0*x3+y*(6.0*x2+y* (4.0*x+3.0*y)))+12.0*clog*(x4-(y2*y2)))/48.0; } } /* (C) Copr. 1986-92 Numerical Recipes Software 9.1-5i. */
the_stack_data/156392179.c
void main() { int i; while (i >= 0) { i++; i = i - 2; } }
the_stack_data/59512950.c
/* BIBLIOTECAS A SEREM UTILIZADAS */ #include <stdio.h> /* CORPO DO PROGRAMA */ int main() { int Numero = 0; printf("================== PROGRAMA DOBRO E QUADRADO =================="); printf("\n\n Insira um numero\n "); fflush(stdin); scanf("%i",&Numero); printf("\n\n O dobro desse numero: %i \n O quadrado desse numero: %i ",Numero * 2, Numero * Numero); getch(); return 0; }
the_stack_data/68888677.c
#include<stdio.h> int main(int argc, char const *argv[]) { int yas; char onay = 'e'; do { if(onay != 'e') { printf("e yada h giriniz: "); scanf("%s",onay); } else { printf("lütfen yasinizi giriniz: "); scanf("%d",&yas); if( yas < 18) { printf("18 yas alti ehliyet alamaz"); printf("sorguya devam etmek için e iptal için h tusuna basiniz"); printf("\n onay:"); scanf("%s",onay); } else if( yas == 40) { printf("yasin %d oldu icin en yakin ehliyet kursuna gidiniz",yas); printf("sorguya devam etmek için e iptal için h tusuna basiniz"); printf("\n onay:"); scanf("%s",onay); } else if(yas >= 65) { printf("65 ve üzeri ehiyet alamaz"); printf("sorguya devam etmek için e iptal için h tusuna basiniz"); printf("\n onay:"); scanf("%s",onay); } } } while (onay != 'h'); printf("sorgu bitmiştir"); }
the_stack_data/95373.c
/*Exercise 3 - Repetition Write a C program to calculate the sum of the numbers from 1 to n. Where n is a keyboard input. e.g. n -> 100 sum = 1+2+3+....+ 99+100 = 5050 n -> 1- sum = 1+2+3+...+10 = 55 */ #include <stdio.h> int main() { int i,n,sum=0; //Get the value from user printf("Enter the number-"); scanf("%d",&n); //Repetition for(i=0;i<=n;i++) { sum=sum+i; } printf("sum is=%d",sum); return 0; }
the_stack_data/433555.c
struct Input { int a; }; struct Output { int x; }; void outsource(struct Input *input, struct Output *output) { switch (input->a) { case 1: output->x = 111; break; case 4: output->x = 444; break; case 9: output->x = 990; break; default: output->x = input->a; break; } }
the_stack_data/220455552.c
// KMSAN: uninit-value in tipc_nl_compat_link_set // https://syzkaller.appspot.com/bug?id=68e9146b9a72baa2b026d9d8599b02f7edf153e7 // status:invalid // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include <arpa/inet.h> #include <dirent.h> #include <endian.h> #include <errno.h> #include <fcntl.h> #include <net/if_arp.h> #include <netinet/in.h> #include <pthread.h> #include <sched.h> #include <setjmp.h> #include <signal.h> #include <stdarg.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <sys/mman.h> #include <sys/mount.h> #include <sys/prctl.h> #include <sys/resource.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/time.h> #include <sys/types.h> #include <sys/uio.h> #include <sys/wait.h> #include <time.h> #include <unistd.h> #include <linux/capability.h> #include <linux/futex.h> #include <linux/if.h> #include <linux/if_ether.h> #include <linux/if_tun.h> #include <linux/ip.h> #include <linux/net.h> #include <linux/tcp.h> unsigned long long procid; static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ { \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); if (pthread_create(&th, &attr, fn, arg)) exit(1); pthread_attr_destroy(&attr); } 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 void vsnprintf_check(char* str, size_t size, const char* format, va_list args) { int rv; rv = vsnprintf(str, size, format, args); if (rv < 0) exit(1); if ((size_t)rv >= size) exit(1); } #define COMMAND_MAX_LEN 128 #define PATH_PREFIX \ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin " #define PATH_PREFIX_LEN (sizeof(PATH_PREFIX) - 1) static void execute_command(bool panic, const char* format, ...) { va_list args; char command[PATH_PREFIX_LEN + COMMAND_MAX_LEN]; int rv; va_start(args, format); memcpy(command, PATH_PREFIX, PATH_PREFIX_LEN); vsnprintf_check(command + PATH_PREFIX_LEN, COMMAND_MAX_LEN, format, args); va_end(args); rv = system(command); if (rv) { if (panic) exit(1); } } static int tunfd = -1; static int tun_frags_enabled; #define SYZ_TUN_MAX_PACKET_SIZE 1000 #define TUN_IFACE "syz_tun" #define LOCAL_MAC "aa:aa:aa:aa:aa:aa" #define REMOTE_MAC "aa:aa:aa:aa:aa:bb" #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; execute_command(0, "sysctl -w net.ipv6.conf.%s.accept_dad=0", TUN_IFACE); execute_command(0, "sysctl -w net.ipv6.conf.%s.router_solicitations=0", TUN_IFACE); execute_command(1, "ip link set dev %s address %s", TUN_IFACE, LOCAL_MAC); execute_command(1, "ip addr add %s/24 dev %s", LOCAL_IPV4, TUN_IFACE); execute_command(1, "ip neigh add %s lladdr %s dev %s nud permanent", REMOTE_IPV4, REMOTE_MAC, TUN_IFACE); execute_command(0, "ip -6 addr add %s/120 dev %s", LOCAL_IPV6, TUN_IFACE); execute_command(0, "ip -6 neigh add %s lladdr %s dev %s nud permanent", REMOTE_IPV6, REMOTE_MAC, TUN_IFACE); execute_command(1, "ip link set dev %s up", TUN_IFACE); } #define DEV_IPV4 "172.20.20.%d" #define DEV_IPV6 "fe80::%02hx" #define DEV_MAC "aa:aa:aa:aa:aa:%02hx" static void snprintf_check(char* str, size_t size, const char* format, ...) { va_list args; va_start(args, format); vsnprintf_check(str, size, format, args); va_end(args); } static void initialize_netdevices(void) { unsigned i; const char* devtypes[] = {"ip6gretap", "bridge", "vcan", "bond", "team"}; const char* devnames[] = {"lo", "sit0", "bridge0", "vcan0", "tunl0", "gre0", "gretap0", "ip_vti0", "ip6_vti0", "ip6tnl0", "ip6gre0", "ip6gretap0", "erspan0", "bond0", "veth0", "veth1", "team0", "veth0_to_bridge", "veth1_to_bridge", "veth0_to_bond", "veth1_to_bond", "veth0_to_team", "veth1_to_team"}; const char* devmasters[] = {"bridge", "bond", "team"}; for (i = 0; i < sizeof(devtypes) / (sizeof(devtypes[0])); i++) execute_command(0, "ip link add dev %s0 type %s", devtypes[i], devtypes[i]); execute_command(0, "ip link add type veth"); for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) { execute_command( 0, "ip link add name %s_slave_0 type veth peer name veth0_to_%s", devmasters[i], devmasters[i]); execute_command( 0, "ip link add name %s_slave_1 type veth peer name veth1_to_%s", devmasters[i], devmasters[i]); execute_command(0, "ip link set %s_slave_0 master %s0", devmasters[i], devmasters[i]); execute_command(0, "ip link set %s_slave_1 master %s0", devmasters[i], devmasters[i]); execute_command(0, "ip link set veth0_to_%s up", devmasters[i]); execute_command(0, "ip link set veth1_to_%s up", devmasters[i]); } execute_command(0, "ip link set bridge_slave_0 up"); execute_command(0, "ip link set bridge_slave_1 up"); for (i = 0; i < sizeof(devnames) / (sizeof(devnames[0])); i++) { char addr[32]; snprintf_check(addr, sizeof(addr), DEV_IPV4, i + 10); execute_command(0, "ip -4 addr add %s/24 dev %s", addr, devnames[i]); snprintf_check(addr, sizeof(addr), DEV_IPV6, i + 10); execute_command(0, "ip -6 addr add %s/120 dev %s", addr, devnames[i]); snprintf_check(addr, sizeof(addr), DEV_MAC, i + 10); execute_command(0, "ip link set dev %s address %s", devnames[i], addr); execute_command(0, "ip link set dev %s up", devnames[i]); } } static int read_tun(char* data, int size) { if (tunfd < 0) return -1; int rv = read(tunfd, data, size); if (rv < 0) { if (errno == EAGAIN) return -1; if (errno == EBADFD) return -1; exit(1); } return rv; } static void flush_tun() { char data[SYZ_TUN_MAX_PACKET_SIZE]; while (read_tun(&data[0], sizeof(data)) != -1) { } } static bool write_file(const char* file, const char* what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } #define XT_TABLE_SIZE 1536 #define XT_MAX_ENTRIES 10 struct xt_counters { uint64_t pcnt, bcnt; }; struct ipt_getinfo { char name[32]; unsigned int valid_hooks; unsigned int hook_entry[5]; unsigned int underflow[5]; unsigned int num_entries; unsigned int size; }; struct ipt_get_entries { char name[32]; unsigned int size; void* entrytable[XT_TABLE_SIZE / sizeof(void*)]; }; struct ipt_replace { char name[32]; unsigned int valid_hooks; unsigned int num_entries; unsigned int size; unsigned int hook_entry[5]; unsigned int underflow[5]; unsigned int num_counters; struct xt_counters* counters; char entrytable[XT_TABLE_SIZE]; }; struct ipt_table_desc { const char* name; struct ipt_getinfo info; struct ipt_replace replace; }; static struct ipt_table_desc ipv4_tables[] = { {.name = "filter"}, {.name = "nat"}, {.name = "mangle"}, {.name = "raw"}, {.name = "security"}, }; static struct ipt_table_desc ipv6_tables[] = { {.name = "filter"}, {.name = "nat"}, {.name = "mangle"}, {.name = "raw"}, {.name = "security"}, }; #define IPT_BASE_CTL 64 #define IPT_SO_SET_REPLACE (IPT_BASE_CTL) #define IPT_SO_GET_INFO (IPT_BASE_CTL) #define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1) struct arpt_getinfo { char name[32]; unsigned int valid_hooks; unsigned int hook_entry[3]; unsigned int underflow[3]; unsigned int num_entries; unsigned int size; }; struct arpt_get_entries { char name[32]; unsigned int size; void* entrytable[XT_TABLE_SIZE / sizeof(void*)]; }; struct arpt_replace { char name[32]; unsigned int valid_hooks; unsigned int num_entries; unsigned int size; unsigned int hook_entry[3]; unsigned int underflow[3]; unsigned int num_counters; struct xt_counters* counters; char entrytable[XT_TABLE_SIZE]; }; struct arpt_table_desc { const char* name; struct arpt_getinfo info; struct arpt_replace replace; }; static struct arpt_table_desc arpt_tables[] = { {.name = "filter"}, }; #define ARPT_BASE_CTL 96 #define ARPT_SO_SET_REPLACE (ARPT_BASE_CTL) #define ARPT_SO_GET_INFO (ARPT_BASE_CTL) #define ARPT_SO_GET_ENTRIES (ARPT_BASE_CTL + 1) static void checkpoint_iptables(struct ipt_table_desc* tables, int num_tables, int family, int level) { struct ipt_get_entries entries; socklen_t optlen; int fd, i; fd = socket(family, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < num_tables; i++) { struct ipt_table_desc* table = &tables[i]; strcpy(table->info.name, table->name); strcpy(table->replace.name, table->name); optlen = sizeof(table->info); if (getsockopt(fd, level, IPT_SO_GET_INFO, &table->info, &optlen)) { switch (errno) { case EPERM: case ENOENT: case ENOPROTOOPT: continue; } exit(1); } if (table->info.size > sizeof(table->replace.entrytable)) exit(1); if (table->info.num_entries > XT_MAX_ENTRIES) exit(1); memset(&entries, 0, sizeof(entries)); strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size; if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen)) exit(1); table->replace.valid_hooks = table->info.valid_hooks; table->replace.num_entries = table->info.num_entries; table->replace.size = table->info.size; memcpy(table->replace.hook_entry, table->info.hook_entry, sizeof(table->replace.hook_entry)); memcpy(table->replace.underflow, table->info.underflow, sizeof(table->replace.underflow)); memcpy(table->replace.entrytable, entries.entrytable, table->info.size); } close(fd); } static void reset_iptables(struct ipt_table_desc* tables, int num_tables, int family, int level) { struct xt_counters counters[XT_MAX_ENTRIES]; struct ipt_get_entries entries; struct ipt_getinfo info; socklen_t optlen; int fd, i; fd = socket(family, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < num_tables; i++) { struct ipt_table_desc* table = &tables[i]; if (table->info.valid_hooks == 0) continue; memset(&info, 0, sizeof(info)); strcpy(info.name, table->name); optlen = sizeof(info); if (getsockopt(fd, level, IPT_SO_GET_INFO, &info, &optlen)) exit(1); if (memcmp(&table->info, &info, sizeof(table->info)) == 0) { memset(&entries, 0, sizeof(entries)); strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size; if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen)) exit(1); if (memcmp(table->replace.entrytable, entries.entrytable, table->info.size) == 0) continue; } table->replace.num_counters = info.num_entries; table->replace.counters = counters; optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) + table->replace.size; if (setsockopt(fd, level, IPT_SO_SET_REPLACE, &table->replace, optlen)) exit(1); } close(fd); } static void checkpoint_arptables(void) { struct arpt_get_entries entries; socklen_t optlen; unsigned i; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) { struct arpt_table_desc* table = &arpt_tables[i]; strcpy(table->info.name, table->name); strcpy(table->replace.name, table->name); optlen = sizeof(table->info); if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &table->info, &optlen)) { switch (errno) { case EPERM: case ENOENT: case ENOPROTOOPT: continue; } exit(1); } if (table->info.size > sizeof(table->replace.entrytable)) exit(1); if (table->info.num_entries > XT_MAX_ENTRIES) exit(1); memset(&entries, 0, sizeof(entries)); strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size; if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen)) exit(1); table->replace.valid_hooks = table->info.valid_hooks; table->replace.num_entries = table->info.num_entries; table->replace.size = table->info.size; memcpy(table->replace.hook_entry, table->info.hook_entry, sizeof(table->replace.hook_entry)); memcpy(table->replace.underflow, table->info.underflow, sizeof(table->replace.underflow)); memcpy(table->replace.entrytable, entries.entrytable, table->info.size); } close(fd); } static void reset_arptables() { struct xt_counters counters[XT_MAX_ENTRIES]; struct arpt_get_entries entries; struct arpt_getinfo info; socklen_t optlen; unsigned i; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) { struct arpt_table_desc* table = &arpt_tables[i]; if (table->info.valid_hooks == 0) continue; memset(&info, 0, sizeof(info)); strcpy(info.name, table->name); optlen = sizeof(info); if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &info, &optlen)) exit(1); if (memcmp(&table->info, &info, sizeof(table->info)) == 0) { memset(&entries, 0, sizeof(entries)); strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size; if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen)) exit(1); if (memcmp(table->replace.entrytable, entries.entrytable, table->info.size) == 0) continue; } else { } table->replace.num_counters = info.num_entries; table->replace.counters = counters; optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) + table->replace.size; if (setsockopt(fd, SOL_IP, ARPT_SO_SET_REPLACE, &table->replace, optlen)) exit(1); } close(fd); } #define NF_BR_NUMHOOKS 6 #define EBT_TABLE_MAXNAMELEN 32 #define EBT_CHAIN_MAXNAMELEN 32 #define EBT_BASE_CTL 128 #define EBT_SO_SET_ENTRIES (EBT_BASE_CTL) #define EBT_SO_GET_INFO (EBT_BASE_CTL) #define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO + 1) #define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES + 1) #define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO + 1) struct ebt_replace { char name[EBT_TABLE_MAXNAMELEN]; unsigned int valid_hooks; unsigned int nentries; unsigned int entries_size; struct ebt_entries* hook_entry[NF_BR_NUMHOOKS]; unsigned int num_counters; struct ebt_counter* counters; char* entries; }; struct ebt_entries { unsigned int distinguisher; char name[EBT_CHAIN_MAXNAMELEN]; unsigned int counter_offset; int policy; unsigned int nentries; char data[0] __attribute__((aligned(__alignof__(struct ebt_replace)))); }; struct ebt_table_desc { const char* name; struct ebt_replace replace; char entrytable[XT_TABLE_SIZE]; }; static struct ebt_table_desc ebt_tables[] = { {.name = "filter"}, {.name = "nat"}, {.name = "broute"}, }; static void checkpoint_ebtables(void) { socklen_t optlen; unsigned i; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) { struct ebt_table_desc* table = &ebt_tables[i]; strcpy(table->replace.name, table->name); optlen = sizeof(table->replace); if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_INFO, &table->replace, &optlen)) { switch (errno) { case EPERM: case ENOENT: case ENOPROTOOPT: continue; } exit(1); } if (table->replace.entries_size > sizeof(table->entrytable)) exit(1); table->replace.num_counters = 0; table->replace.entries = table->entrytable; optlen = sizeof(table->replace) + table->replace.entries_size; if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_ENTRIES, &table->replace, &optlen)) exit(1); } close(fd); } static void reset_ebtables() { struct ebt_replace replace; char entrytable[XT_TABLE_SIZE]; socklen_t optlen; unsigned i, j, h; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) { struct ebt_table_desc* table = &ebt_tables[i]; if (table->replace.valid_hooks == 0) continue; memset(&replace, 0, sizeof(replace)); strcpy(replace.name, table->name); optlen = sizeof(replace); if (getsockopt(fd, SOL_IP, EBT_SO_GET_INFO, &replace, &optlen)) exit(1); replace.num_counters = 0; table->replace.entries = 0; for (h = 0; h < NF_BR_NUMHOOKS; h++) table->replace.hook_entry[h] = 0; if (memcmp(&table->replace, &replace, sizeof(table->replace)) == 0) { memset(&entrytable, 0, sizeof(entrytable)); replace.entries = entrytable; optlen = sizeof(replace) + replace.entries_size; if (getsockopt(fd, SOL_IP, EBT_SO_GET_ENTRIES, &replace, &optlen)) exit(1); if (memcmp(table->entrytable, entrytable, replace.entries_size) == 0) continue; } for (j = 0, h = 0; h < NF_BR_NUMHOOKS; h++) { if (table->replace.valid_hooks & (1 << h)) { table->replace.hook_entry[h] = (struct ebt_entries*)table->entrytable + j; j++; } } table->replace.entries = table->entrytable; optlen = sizeof(table->replace) + table->replace.entries_size; if (setsockopt(fd, SOL_IP, EBT_SO_SET_ENTRIES, &table->replace, optlen)) exit(1); } close(fd); } static void checkpoint_net_namespace(void) { checkpoint_ebtables(); checkpoint_arptables(); checkpoint_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]), AF_INET, SOL_IP); checkpoint_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]), AF_INET6, SOL_IPV6); } static void reset_net_namespace(void) { reset_ebtables(); reset_arptables(); reset_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]), AF_INET, SOL_IP); reset_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]), AF_INET6, SOL_IPV6); } static void setup_cgroups() { if (mkdir("/syzcgroup", 0777)) { } if (mkdir("/syzcgroup/unified", 0777)) { } if (mount("none", "/syzcgroup/unified", "cgroup2", 0, NULL)) { } if (chmod("/syzcgroup/unified", 0777)) { } if (!write_file("/syzcgroup/unified/cgroup.subtree_control", "+cpu +memory +io +pids +rdma")) { } if (mkdir("/syzcgroup/cpu", 0777)) { } if (mount("none", "/syzcgroup/cpu", "cgroup", 0, "cpuset,cpuacct,perf_event,hugetlb")) { } if (!write_file("/syzcgroup/cpu/cgroup.clone_children", "1")) { } if (chmod("/syzcgroup/cpu", 0777)) { } if (mkdir("/syzcgroup/net", 0777)) { } if (mount("none", "/syzcgroup/net", "cgroup", 0, "net_cls,net_prio,devices,freezer")) { } if (chmod("/syzcgroup/net", 0777)) { } } static void setup_binfmt_misc() { if (mount(0, "/proc/sys/fs/binfmt_misc", "binfmt_misc", 0, 0)) { } if (!write_file("/proc/sys/fs/binfmt_misc/register", ":syz0:M:0:\x01::./file0:")) { } if (!write_file("/proc/sys/fs/binfmt_misc/register", ":syz1:M:1:\x02::./file0:POC")) { } } static void setup_common() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) { } setup_cgroups(); setup_binfmt_misc(); } 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)) { } } 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 real_uid; static int real_gid; __attribute__((aligned(64 << 10))) static char sandbox_stack[1 << 20]; static int namespace_sandbox_proc(void* arg) { sandbox_common(); write_file("/proc/self/setgroups", "deny"); if (!write_file("/proc/self/uid_map", "0 %d 1\n", real_uid)) exit(1); if (!write_file("/proc/self/gid_map", "0 %d 1\n", real_gid)) exit(1); if (unshare(CLONE_NEWNET)) exit(1); initialize_tun(); initialize_netdevices(); if (mkdir("./syz-tmp", 0777)) exit(1); if (mount("", "./syz-tmp", "tmpfs", 0, NULL)) exit(1); if (mkdir("./syz-tmp/newroot", 0777)) exit(1); if (mkdir("./syz-tmp/newroot/dev", 0700)) exit(1); unsigned bind_mount_flags = MS_BIND | MS_REC | MS_PRIVATE; if (mount("/dev", "./syz-tmp/newroot/dev", NULL, bind_mount_flags, NULL)) exit(1); if (mkdir("./syz-tmp/newroot/proc", 0700)) exit(1); if (mount(NULL, "./syz-tmp/newroot/proc", "proc", 0, NULL)) exit(1); if (mkdir("./syz-tmp/newroot/selinux", 0700)) exit(1); const char* selinux_path = "./syz-tmp/newroot/selinux"; if (mount("/selinux", selinux_path, NULL, bind_mount_flags, NULL)) { if (errno != ENOENT) exit(1); if (mount("/sys/fs/selinux", selinux_path, NULL, bind_mount_flags, NULL) && errno != ENOENT) exit(1); } if (mkdir("./syz-tmp/newroot/sys", 0700)) exit(1); if (mount("/sys", "./syz-tmp/newroot/sys", 0, bind_mount_flags, NULL)) exit(1); if (mkdir("./syz-tmp/newroot/syzcgroup", 0700)) exit(1); if (mkdir("./syz-tmp/newroot/syzcgroup/unified", 0700)) exit(1); if (mkdir("./syz-tmp/newroot/syzcgroup/cpu", 0700)) exit(1); if (mkdir("./syz-tmp/newroot/syzcgroup/net", 0700)) exit(1); if (mount("/syzcgroup/unified", "./syz-tmp/newroot/syzcgroup/unified", NULL, bind_mount_flags, NULL)) { } if (mount("/syzcgroup/cpu", "./syz-tmp/newroot/syzcgroup/cpu", NULL, bind_mount_flags, NULL)) { } if (mount("/syzcgroup/net", "./syz-tmp/newroot/syzcgroup/net", NULL, bind_mount_flags, NULL)) { } if (mkdir("./syz-tmp/pivot", 0777)) exit(1); if (syscall(SYS_pivot_root, "./syz-tmp", "./syz-tmp/pivot")) { if (chdir("./syz-tmp")) exit(1); } else { if (chdir("/")) exit(1); if (umount2("./pivot", MNT_DETACH)) exit(1); } if (chroot("./newroot")) exit(1); if (chdir("/")) exit(1); struct __user_cap_header_struct cap_hdr = {}; struct __user_cap_data_struct cap_data[2] = {}; cap_hdr.version = _LINUX_CAPABILITY_VERSION_3; cap_hdr.pid = getpid(); if (syscall(SYS_capget, &cap_hdr, &cap_data)) exit(1); cap_data[0].effective &= ~(1 << CAP_SYS_PTRACE); cap_data[0].permitted &= ~(1 << CAP_SYS_PTRACE); cap_data[0].inheritable &= ~(1 << CAP_SYS_PTRACE); if (syscall(SYS_capset, &cap_hdr, &cap_data)) exit(1); loop(); exit(1); } #define SYZ_HAVE_SANDBOX_NAMESPACE 1 static int do_sandbox_namespace(void) { int pid; setup_common(); real_uid = getuid(); real_gid = getgid(); mprotect(sandbox_stack, 4096, PROT_NONE); pid = clone(namespace_sandbox_proc, &sandbox_stack[sizeof(sandbox_stack) - 64], CLONE_NEWUSER | CLONE_NEWPID, 0); return wait_for_loop(pid); } #define FS_IOC_SETFLAGS _IOW('f', 2, long) static void remove_dir(const char* dir) { DIR* dp; struct dirent* ep; int iter = 0; retry: while (umount2(dir, MNT_DETACH) == 0) { } dp = opendir(dir); if (dp == NULL) { if (errno == EMFILE) { exit(1); } exit(1); } while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); while (umount2(filename, MNT_DETACH) == 0) { } struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } int i; for (i = 0;; i++) { if (unlink(filename) == 0) break; if (errno == EPERM) { int fd = open(filename, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) close(fd); continue; } } if (errno == EROFS) { break; } if (errno != EBUSY || i > 100) exit(1); if (umount2(filename, MNT_DETACH)) exit(1); } } closedir(dp); int i; for (i = 0;; i++) { if (rmdir(dir) == 0) break; if (i < 100) { if (errno == EPERM) { int fd = open(dir, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) close(fd); continue; } } if (errno == EROFS) { break; } if (errno == EBUSY) { if (umount2(dir, MNT_DETACH)) exit(1); continue; } if (errno == ENOTEMPTY) { if (iter < 100) { iter++; goto retry; } } } exit(1); } } static void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); int i; for (i = 0; i < 100; i++) { if (waitpid(-1, status, WNOHANG | __WALL) == pid) return; usleep(1000); } DIR* dir = opendir("/sys/fs/fuse/connections"); if (dir) { for (;;) { struct dirent* ent = readdir(dir); if (!ent) break; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; char abort[300]; snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", ent->d_name); int fd = open(abort, O_WRONLY); if (fd == -1) { continue; } if (write(fd, abort, 1) < 0) { } close(fd); } closedir(dir); } else { } while (waitpid(-1, status, __WALL) != pid) { } } #define SYZ_HAVE_SETUP_LOOP 1 static void setup_loop() { int pid = getpid(); char cgroupdir[64]; char file[128]; snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/pids.max", cgroupdir); if (!write_file(file, "32")) { } snprintf(file, sizeof(file), "%s/memory.low", cgroupdir); if (!write_file(file, "%d", 298 << 20)) { } snprintf(file, sizeof(file), "%s/memory.high", cgroupdir); if (!write_file(file, "%d", 299 << 20)) { } snprintf(file, sizeof(file), "%s/memory.max", cgroupdir); if (!write_file(file, "%d", 300 << 20)) { } snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); if (!write_file(file, "%d", pid)) { } snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); if (!write_file(file, "%d", pid)) { } snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); if (!write_file(file, "%d", pid)) { } checkpoint_net_namespace(); } #define SYZ_HAVE_RESET_LOOP 1 static void reset_loop() { reset_net_namespace(); } #define SYZ_HAVE_SETUP_TEST 1 static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); char cgroupdir[64]; snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid); if (symlink(cgroupdir, "./cgroup")) { } snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid); if (symlink(cgroupdir, "./cgroup.cpu")) { } snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid); if (symlink(cgroupdir, "./cgroup.net")) { } if (!write_file("/proc/self/oom_score_adj", "1000")) { } flush_tun(); } #define SYZ_HAVE_RESET_TEST 1 static void reset_test() { int fd; for (fd = 3; fd < 30; fd++) close(fd); } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; int collide = 0; again: for (call = 0; call < 2; 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; } } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { setup_loop(); int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); reset_loop(); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); setup_test(); execute_one(); reset_test(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[1] = {0xffffffffffffffff}; void execute_call(int call) { long res; switch (call) { case 0: res = syscall(__NR_socket, 0x10, 3, 0x10); if (res != -1) r[0] = res; break; case 1: NONFAILING(*(uint64_t*)0x20000100 = 0x20000040); NONFAILING(*(uint16_t*)0x20000040 = 0x10); NONFAILING(*(uint16_t*)0x20000042 = 0x4000); NONFAILING(*(uint32_t*)0x20000044 = 0); NONFAILING(*(uint32_t*)0x20000048 = 0); NONFAILING(*(uint32_t*)0x20000108 = 0xc); NONFAILING(*(uint64_t*)0x20000110 = 0x20000080); NONFAILING(*(uint64_t*)0x20000080 = 0x200000c0); NONFAILING(memcpy((void*)0x200000c0, "\x2c\x00\x00\x00\x29\x00\x01\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x01\x00\x00\x00\x18\x00\x00\x00\x09\x41\x00\x00" "\x00\x00\x00\x18\x00\x00\x00\x6b\x6e\x67\x80\x3e\x65\xc6" "\x65\xa9\x6e\x00\x00\x00\xff\xff\xac\x14\x14\xbb", 54)); NONFAILING(*(uint64_t*)0x20000088 = 1); NONFAILING(*(uint64_t*)0x20000118 = 1); NONFAILING(*(uint64_t*)0x20000120 = 0); NONFAILING(*(uint64_t*)0x20000128 = 0); NONFAILING(*(uint32_t*)0x20000130 = 0); syscall(__NR_sendmsg, r[0], 0x20000100, 0); break; } } int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); install_segv_handler(); for (procid = 0; procid < 6; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_namespace(); } } sleep(1000000); return 0; }
the_stack_data/161080731.c
# 1 "D:/opt/source/Vivado/Vivado_HLS_Tutorial/Interface_Synthesis/lab1/adders_prj/solution2/.autopilot/db/adders.pragma.1.c" # 1 "D:/opt/source/Vivado/Vivado_HLS_Tutorial/Interface_Synthesis/lab1/adders_prj/solution2/.autopilot/db/adders.pragma.1.c" 1 # 1 "<built-in>" 1 # 1 "<built-in>" 3 # 147 "<built-in>" 3 # 1 "<command line>" 1 # 1 "C:/opt/winprog/Xilinx/Vivado_HLS/2015.2/common/technology/autopilot\\etc/autopilot_ssdm_op.h" 1 /* autopilot_ssdm_op.h*/ /* #- (c) Copyright 2011-2015 Xilinx, Inc. All rights reserved. #- #- This file contains confidential and proprietary information #- of Xilinx, Inc. and is protected under U.S. and #- international copyright and other intellectual property #- laws. #- #- DISCLAIMER #- This disclaimer is not a license and does not grant any #- rights to the materials distributed herewith. Except as #- otherwise provided in a valid license issued to you by #- Xilinx, and to the maximum extent permitted by applicable #- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND #- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES #- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING #- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- #- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and #- (2) Xilinx shall not be liable (whether in contract or tort, #- including negligence, or under any other theory of #- liability) for any loss or damage of any kind or nature #- related to, arising under or in connection with these #- materials, including for any direct, or any indirect, #- special, incidental, or consequential loss or damage #- (including loss of data, profits, goodwill, or any type of #- loss or damage suffered as a result of any action brought #- by a third party) even if such damage or loss was #- reasonably foreseeable or Xilinx had been advised of the #- possibility of the same. #- #- CRITICAL APPLICATIONS #- Xilinx products are not designed or intended to be fail- #- safe, or for use in any application requiring fail-safe #- performance, such as life-support or safety devices or #- systems, Class III medical devices, nuclear facilities, #- applications related to the deployment of airbags, or any #- other applications that could lead to death, personal #- injury, or severe property or environmental damage #- (individually and collectively, "Critical #- Applications"). Customer assumes the sole risk and #- liability of any use of Xilinx products in Critical #- Applications, subject only to applicable laws and #- regulations governing limitations on product liability. #- #- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS #- PART OF THIS FILE AT ALL TIMES. #- ************************************************************************ * * $Id$ */ # 280 "C:/opt/winprog/Xilinx/Vivado_HLS/2015.2/common/technology/autopilot\\etc/autopilot_ssdm_op.h" /*#define AP_SPEC_ATTR __attribute__ ((pure))*/ /****** SSDM Intrinsics: OPERATIONS ***/ // Interface operations //typedef unsigned int __attribute__ ((bitwidth(1))) _uint1_; void _ssdm_op_IfRead() __attribute__ ((nothrow)); void _ssdm_op_IfWrite() __attribute__ ((nothrow)); //_uint1_ _ssdm_op_IfNbRead() SSDM_OP_ATTR; //_uint1_ _ssdm_op_IfNbWrite() SSDM_OP_ATTR; //_uint1_ _ssdm_op_IfCanRead() SSDM_OP_ATTR; //_uint1_ _ssdm_op_IfCanWrite() SSDM_OP_ATTR; // Stream Intrinsics void _ssdm_StreamRead() __attribute__ ((nothrow)); void _ssdm_StreamWrite() __attribute__ ((nothrow)); //_uint1_ _ssdm_StreamNbRead() SSDM_OP_ATTR; //_uint1_ _ssdm_StreamNbWrite() SSDM_OP_ATTR; //_uint1_ _ssdm_StreamCanRead() SSDM_OP_ATTR; //_uint1_ _ssdm_StreamCanWrite() SSDM_OP_ATTR; // Misc void _ssdm_op_MemShiftRead() __attribute__ ((nothrow)); void _ssdm_op_Wait() __attribute__ ((nothrow)); void _ssdm_op_Poll() __attribute__ ((nothrow)); void _ssdm_op_Return() __attribute__ ((nothrow)); /* SSDM Intrinsics: SPECIFICATIONS */ void _ssdm_op_SpecSynModule() __attribute__ ((nothrow)); void _ssdm_op_SpecTopModule() __attribute__ ((nothrow)); void _ssdm_op_SpecProcessDecl() __attribute__ ((nothrow)); void _ssdm_op_SpecProcessDef() __attribute__ ((nothrow)); void _ssdm_op_SpecPort() __attribute__ ((nothrow)); void _ssdm_op_SpecConnection() __attribute__ ((nothrow)); void _ssdm_op_SpecChannel() __attribute__ ((nothrow)); void _ssdm_op_SpecSensitive() __attribute__ ((nothrow)); void _ssdm_op_SpecModuleInst() __attribute__ ((nothrow)); void _ssdm_op_SpecPortMap() __attribute__ ((nothrow)); void _ssdm_op_SpecReset() __attribute__ ((nothrow)); void _ssdm_op_SpecPlatform() __attribute__ ((nothrow)); void _ssdm_op_SpecClockDomain() __attribute__ ((nothrow)); void _ssdm_op_SpecPowerDomain() __attribute__ ((nothrow)); int _ssdm_op_SpecRegionBegin() __attribute__ ((nothrow)); int _ssdm_op_SpecRegionEnd() __attribute__ ((nothrow)); void _ssdm_op_SpecLoopName() __attribute__ ((nothrow)); void _ssdm_op_SpecLoopTripCount() __attribute__ ((nothrow)); int _ssdm_op_SpecStateBegin() __attribute__ ((nothrow)); int _ssdm_op_SpecStateEnd() __attribute__ ((nothrow)); void _ssdm_op_SpecInterface() __attribute__ ((nothrow)); void _ssdm_op_SpecPipeline() __attribute__ ((nothrow)); void _ssdm_op_SpecDataflowPipeline() __attribute__ ((nothrow)); void _ssdm_op_SpecLatency() __attribute__ ((nothrow)); void _ssdm_op_SpecParallel() __attribute__ ((nothrow)); void _ssdm_op_SpecProtocol() __attribute__ ((nothrow)); void _ssdm_op_SpecOccurrence() __attribute__ ((nothrow)); void _ssdm_op_SpecResource() __attribute__ ((nothrow)); void _ssdm_op_SpecResourceLimit() __attribute__ ((nothrow)); void _ssdm_op_SpecCHCore() __attribute__ ((nothrow)); void _ssdm_op_SpecFUCore() __attribute__ ((nothrow)); void _ssdm_op_SpecIFCore() __attribute__ ((nothrow)); void _ssdm_op_SpecIPCore() __attribute__ ((nothrow)); void _ssdm_op_SpecKeepValue() __attribute__ ((nothrow)); void _ssdm_op_SpecMemCore() __attribute__ ((nothrow)); void _ssdm_op_SpecExt() __attribute__ ((nothrow)); /*void* _ssdm_op_SpecProcess() SSDM_SPEC_ATTR; void* _ssdm_op_SpecEdge() SSDM_SPEC_ATTR; */ /* Presynthesis directive functions */ void _ssdm_SpecArrayDimSize() __attribute__ ((nothrow)); void _ssdm_RegionBegin() __attribute__ ((nothrow)); void _ssdm_RegionEnd() __attribute__ ((nothrow)); void _ssdm_Unroll() __attribute__ ((nothrow)); void _ssdm_UnrollRegion() __attribute__ ((nothrow)); void _ssdm_InlineAll() __attribute__ ((nothrow)); void _ssdm_InlineLoop() __attribute__ ((nothrow)); void _ssdm_Inline() __attribute__ ((nothrow)); void _ssdm_InlineSelf() __attribute__ ((nothrow)); void _ssdm_InlineRegion() __attribute__ ((nothrow)); void _ssdm_SpecArrayMap() __attribute__ ((nothrow)); void _ssdm_SpecArrayPartition() __attribute__ ((nothrow)); void _ssdm_SpecArrayReshape() __attribute__ ((nothrow)); void _ssdm_SpecStream() __attribute__ ((nothrow)); void _ssdm_SpecExpr() __attribute__ ((nothrow)); void _ssdm_SpecExprBalance() __attribute__ ((nothrow)); void _ssdm_SpecDependence() __attribute__ ((nothrow)); void _ssdm_SpecLoopMerge() __attribute__ ((nothrow)); void _ssdm_SpecLoopFlatten() __attribute__ ((nothrow)); void _ssdm_SpecLoopRewind() __attribute__ ((nothrow)); void _ssdm_SpecFuncInstantiation() __attribute__ ((nothrow)); void _ssdm_SpecFuncBuffer() __attribute__ ((nothrow)); void _ssdm_SpecFuncExtract() __attribute__ ((nothrow)); void _ssdm_SpecConstant() __attribute__ ((nothrow)); void _ssdm_DataPack() __attribute__ ((nothrow)); void _ssdm_SpecDataPack() __attribute__ ((nothrow)); void _ssdm_op_SpecBitsMap() __attribute__ ((nothrow)); void _ssdm_op_SpecLicense() __attribute__ ((nothrow)); /*#define _ssdm_op_WaitUntil(X) while (!(X)) _ssdm_op_Wait(1); #define _ssdm_op_Delayed(X) X */ # 7 "<command line>" 2 # 1 "<built-in>" 2 # 1 "D:/opt/source/Vivado/Vivado_HLS_Tutorial/Interface_Synthesis/lab1/adders_prj/solution2/.autopilot/db/adders.pragma.1.c" 2 # 1 "adders.c" # 1 "adders.c" 1 # 1 "<built-in>" 1 # 1 "<built-in>" 3 # 147 "<built-in>" 3 # 1 "<command line>" 1 # 1 "C:/opt/winprog/Xilinx/Vivado_HLS/2015.2/common/technology/autopilot\\etc/autopilot_ssdm_op.h" 1 /* autopilot_ssdm_op.h*/ /* #- (c) Copyright 2011-2015 Xilinx, Inc. All rights reserved. #- #- This file contains confidential and proprietary information #- of Xilinx, Inc. and is protected under U.S. and #- international copyright and other intellectual property #- laws. #- #- DISCLAIMER #- This disclaimer is not a license and does not grant any #- rights to the materials distributed herewith. Except as #- otherwise provided in a valid license issued to you by #- Xilinx, and to the maximum extent permitted by applicable #- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND #- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES #- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING #- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- #- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and #- (2) Xilinx shall not be liable (whether in contract or tort, #- including negligence, or under any other theory of #- liability) for any loss or damage of any kind or nature #- related to, arising under or in connection with these #- materials, including for any direct, or any indirect, #- special, incidental, or consequential loss or damage #- (including loss of data, profits, goodwill, or any type of #- loss or damage suffered as a result of any action brought #- by a third party) even if such damage or loss was #- reasonably foreseeable or Xilinx had been advised of the #- possibility of the same. #- #- CRITICAL APPLICATIONS #- Xilinx products are not designed or intended to be fail- #- safe, or for use in any application requiring fail-safe #- performance, such as life-support or safety devices or #- systems, Class III medical devices, nuclear facilities, #- applications related to the deployment of airbags, or any #- other applications that could lead to death, personal #- injury, or severe property or environmental damage #- (individually and collectively, "Critical #- Applications"). Customer assumes the sole risk and #- liability of any use of Xilinx products in Critical #- Applications, subject only to applicable laws and #- regulations governing limitations on product liability. #- #- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS #- PART OF THIS FILE AT ALL TIMES. #- ************************************************************************ * * $Id$ */ # 280 "C:/opt/winprog/Xilinx/Vivado_HLS/2015.2/common/technology/autopilot\\etc/autopilot_ssdm_op.h" /*#define AP_SPEC_ATTR __attribute__ ((pure))*/ /****** SSDM Intrinsics: OPERATIONS ***/ // Interface operations //typedef unsigned int __attribute__ ((bitwidth(1))) _uint1_; void _ssdm_op_IfRead() __attribute__ ((nothrow)); void _ssdm_op_IfWrite() __attribute__ ((nothrow)); //_uint1_ _ssdm_op_IfNbRead() SSDM_OP_ATTR; //_uint1_ _ssdm_op_IfNbWrite() SSDM_OP_ATTR; //_uint1_ _ssdm_op_IfCanRead() SSDM_OP_ATTR; //_uint1_ _ssdm_op_IfCanWrite() SSDM_OP_ATTR; // Stream Intrinsics void _ssdm_StreamRead() __attribute__ ((nothrow)); void _ssdm_StreamWrite() __attribute__ ((nothrow)); //_uint1_ _ssdm_StreamNbRead() SSDM_OP_ATTR; //_uint1_ _ssdm_StreamNbWrite() SSDM_OP_ATTR; //_uint1_ _ssdm_StreamCanRead() SSDM_OP_ATTR; //_uint1_ _ssdm_StreamCanWrite() SSDM_OP_ATTR; // Misc void _ssdm_op_MemShiftRead() __attribute__ ((nothrow)); void _ssdm_op_Wait() __attribute__ ((nothrow)); void _ssdm_op_Poll() __attribute__ ((nothrow)); void _ssdm_op_Return() __attribute__ ((nothrow)); /* SSDM Intrinsics: SPECIFICATIONS */ void _ssdm_op_SpecSynModule() __attribute__ ((nothrow)); void _ssdm_op_SpecTopModule() __attribute__ ((nothrow)); void _ssdm_op_SpecProcessDecl() __attribute__ ((nothrow)); void _ssdm_op_SpecProcessDef() __attribute__ ((nothrow)); void _ssdm_op_SpecPort() __attribute__ ((nothrow)); void _ssdm_op_SpecConnection() __attribute__ ((nothrow)); void _ssdm_op_SpecChannel() __attribute__ ((nothrow)); void _ssdm_op_SpecSensitive() __attribute__ ((nothrow)); void _ssdm_op_SpecModuleInst() __attribute__ ((nothrow)); void _ssdm_op_SpecPortMap() __attribute__ ((nothrow)); void _ssdm_op_SpecReset() __attribute__ ((nothrow)); void _ssdm_op_SpecPlatform() __attribute__ ((nothrow)); void _ssdm_op_SpecClockDomain() __attribute__ ((nothrow)); void _ssdm_op_SpecPowerDomain() __attribute__ ((nothrow)); int _ssdm_op_SpecRegionBegin() __attribute__ ((nothrow)); int _ssdm_op_SpecRegionEnd() __attribute__ ((nothrow)); void _ssdm_op_SpecLoopName() __attribute__ ((nothrow)); void _ssdm_op_SpecLoopTripCount() __attribute__ ((nothrow)); int _ssdm_op_SpecStateBegin() __attribute__ ((nothrow)); int _ssdm_op_SpecStateEnd() __attribute__ ((nothrow)); void _ssdm_op_SpecInterface() __attribute__ ((nothrow)); void _ssdm_op_SpecPipeline() __attribute__ ((nothrow)); void _ssdm_op_SpecDataflowPipeline() __attribute__ ((nothrow)); void _ssdm_op_SpecLatency() __attribute__ ((nothrow)); void _ssdm_op_SpecParallel() __attribute__ ((nothrow)); void _ssdm_op_SpecProtocol() __attribute__ ((nothrow)); void _ssdm_op_SpecOccurrence() __attribute__ ((nothrow)); void _ssdm_op_SpecResource() __attribute__ ((nothrow)); void _ssdm_op_SpecResourceLimit() __attribute__ ((nothrow)); void _ssdm_op_SpecCHCore() __attribute__ ((nothrow)); void _ssdm_op_SpecFUCore() __attribute__ ((nothrow)); void _ssdm_op_SpecIFCore() __attribute__ ((nothrow)); void _ssdm_op_SpecIPCore() __attribute__ ((nothrow)); void _ssdm_op_SpecKeepValue() __attribute__ ((nothrow)); void _ssdm_op_SpecMemCore() __attribute__ ((nothrow)); void _ssdm_op_SpecExt() __attribute__ ((nothrow)); /*void* _ssdm_op_SpecProcess() SSDM_SPEC_ATTR; void* _ssdm_op_SpecEdge() SSDM_SPEC_ATTR; */ /* Presynthesis directive functions */ void _ssdm_SpecArrayDimSize() __attribute__ ((nothrow)); void _ssdm_RegionBegin() __attribute__ ((nothrow)); void _ssdm_RegionEnd() __attribute__ ((nothrow)); void _ssdm_Unroll() __attribute__ ((nothrow)); void _ssdm_UnrollRegion() __attribute__ ((nothrow)); void _ssdm_InlineAll() __attribute__ ((nothrow)); void _ssdm_InlineLoop() __attribute__ ((nothrow)); void _ssdm_Inline() __attribute__ ((nothrow)); void _ssdm_InlineSelf() __attribute__ ((nothrow)); void _ssdm_InlineRegion() __attribute__ ((nothrow)); void _ssdm_SpecArrayMap() __attribute__ ((nothrow)); void _ssdm_SpecArrayPartition() __attribute__ ((nothrow)); void _ssdm_SpecArrayReshape() __attribute__ ((nothrow)); void _ssdm_SpecStream() __attribute__ ((nothrow)); void _ssdm_SpecExpr() __attribute__ ((nothrow)); void _ssdm_SpecExprBalance() __attribute__ ((nothrow)); void _ssdm_SpecDependence() __attribute__ ((nothrow)); void _ssdm_SpecLoopMerge() __attribute__ ((nothrow)); void _ssdm_SpecLoopFlatten() __attribute__ ((nothrow)); void _ssdm_SpecLoopRewind() __attribute__ ((nothrow)); void _ssdm_SpecFuncInstantiation() __attribute__ ((nothrow)); void _ssdm_SpecFuncBuffer() __attribute__ ((nothrow)); void _ssdm_SpecFuncExtract() __attribute__ ((nothrow)); void _ssdm_SpecConstant() __attribute__ ((nothrow)); void _ssdm_DataPack() __attribute__ ((nothrow)); void _ssdm_SpecDataPack() __attribute__ ((nothrow)); void _ssdm_op_SpecBitsMap() __attribute__ ((nothrow)); void _ssdm_op_SpecLicense() __attribute__ ((nothrow)); /*#define _ssdm_op_WaitUntil(X) while (!(X)) _ssdm_op_Wait(1); #define _ssdm_op_Delayed(X) X */ # 7 "<command line>" 2 # 1 "<built-in>" 2 # 1 "adders.c" 2 /******************************************************************************* Vendor: Xilinx Associated Filename: adders.c Purpose: Vivado HLS tutorial example Device: All Revision History: March 1, 2013 - initial release ******************************************************************************* Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. This file contains confidential and proprietary information of Xilinx, Inc. and is protected under U.S. and international copyright and other intellectual property laws. DISCLAIMER This disclaimer is not a license and does not grant any rights to the materials distributed herewith. Except as otherwise provided in a valid license issued to you by Xilinx, and to the maximum extent permitted by applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and (2) Xilinx shall not be liable (whether in contract or tort, including negligence, or under any other theory of liability) for any loss or damage of any kind or nature related to, arising under or in connection with these materials, including for any direct, or any indirect, special, incidental, or consequential loss or damage (including loss of data, profits, goodwill, or any type of loss or damage suffered as a result of any action brought by a third party) even if such damage or loss was reasonably foreseeable or Xilinx had been advised of the possibility of the same. CRITICAL APPLICATIONS Xilinx products are not designed or intended to be fail-safe, or for use in any application requiring fail-safe performance, such as life-support or safety devices or systems, Class III medical devices, nuclear facilities, applications related to the deployment of airbags, or any other applications that could lead to death, personal injury, or severe property or environmental damage (individually and collectively, "Critical Applications"). Customer asresultes the sole risk and liability of any use of Xilinx products in Critical Applications, subject only to applicable laws and regulations governing limitations on product liability. THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE AT ALL TIMES. *******************************************************************************/ # 1 "./adders.h" 1 /******************************************************************************* Vendor: Xilinx Associated Filename: adders.h Purpose: Vivado HLS tutorial example Device: All Revision History: March 1, 2013 - initial release ******************************************************************************* Copyright 2008 - 2013 Xilinx, Inc. All rights reserved. This file contains confidential and proprietary information of Xilinx, Inc. and is protected under U.S. and international copyright and other intellectual property laws. DISCLAIMER This disclaimer is not a license and does not grant any rights to the materials distributed herewith. Except as otherwise provided in a valid license issued to you by Xilinx, and to the maximum extent permitted by applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and (2) Xilinx shall not be liable (whether in contract or tort, including negligence, or under any other theory of liability) for any loss or damage of any kind or nature related to, arising under or in connection with these materials, including for any direct, or any indirect, special, incidental, or consequential loss or damage (including loss of data, profits, goodwill, or any type of loss or damage suffered as a result of any action brought by a third party) even if such damage or loss was reasonably foreseeable or Xilinx had been advised of the possibility of the same. CRITICAL APPLICATIONS Xilinx products are not designed or intended to be fail-safe, or for use in any application requiring fail-safe performance, such as life-support or safety devices or systems, Class III medical devices, nuclear facilities, applications related to the deployment of airbags, or any other applications that could lead to death, personal injury, or severe property or environmental damage (individually and collectively, "Critical Applications"). Customer asresultes the sole risk and liability of any use of Xilinx products in Critical Applications, subject only to applicable laws and regulations governing limitations on product liability. THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE AT ALL TIMES. *******************************************************************************/ int adders(int in1, int in2, int in3); # 47 "adders.c" 2 int adders(int in1, int in2, int in3) { _ssdm_op_SpecInterface(0, "ap_ctrl_none", 0, 0, 0, 0, "", "", ""); // Prevent IO protocols on all input ports _ssdm_op_SpecInterface(in3, "ap_none", 0, 0, 0, 0, "", "", ""); _ssdm_op_SpecInterface(in2, "ap_none", 0, 0, 0, 0, "", "", ""); _ssdm_op_SpecInterface(in1, "ap_none", 0, 0, 0, 0, "", "", ""); int sum; sum = in1 + in2 + in3; return sum; }
the_stack_data/40761871.c
#include<stdio.h> long sum(int n,int *a,int low,int high,long *pref) { if(low==0) return *(pref+high); else return(*(pref+high)-*(pref+low-1)); } long long dp(int n,int *a,long long *b,int low,int high,long *pref) { long long min,smoke,p1,p2; long s1,s2; int j; if(*(b+(n*low)+high)!=-1) return *(b+(n*low)+high); if(low==high) return 0; min=1000000000000000000; for(j=low;j<high;j++) { p1=dp(n,a,b,low,j,pref); p2=dp(n,a,b,j+1,high,pref); s1=sum(n,a,low,j,pref); s2=sum(n,a,j+1,high,pref); smoke=p1+p2+((s1%100)*(s2%100)); if(smoke<min) min=smoke; } *(b+(n*low)+high)=min; return min; } int main() { int n,i,j; while(scanf("%d",&n)!=EOF) { int a[n]; long pref[n]; long long b[n][n]; for(i=0;i<n;i++) { for(j=0;j<n;j++) b[i][j]=-1; } for(i=0;i<n;i++) scanf("%d",&a[i]); pref[0]=a[0]; for(i=1;i<n;i++) pref[i]=pref[i-1]+a[i]; dp(n,a,b[0],0,n-1,pref); if(n==1) printf("0\n"); else printf("%lld\n",b[0][n-1]); } }
the_stack_data/218894421.c
#include<stdio.h> int main(void) { int ary[] = { 10,20,30,40,50 }; int size = sizeof(ary) / sizeof(ary[0]); int *pa = ary; int *pb = ary + (size - 1); int temp, i; while (pa < pb) { temp = *pa; *pa = *pb; *pb = temp; pa++; pb--; } for (i = 0; i < size; i++) { printf("%d", ary[i]); } system("pause"); return 0; }
the_stack_data/179831770.c
//test1 int meow() { int i,s; i=0; s = 0; while(i<10) { s = s + i; i = i + 1; if(i%5==0) break; } s = s + 1 - 2 - 3; return s; }
the_stack_data/170451696.c
#include "stdio.h" #include "stdlib.h" #include "unistd.h" void output(char *msg) { printf("%s\n", msg); } int main() { int k = 13; for (int i = 0; i < 100; i++) { if (k % 2 == 0) { output("if"); k = k ^ 17 + 31; } else { output("else"); for (int j = 0; j < 31; j++) { k++; } } } access("/tmp/1", F_OK); printf("%d", k); }
the_stack_data/75635.c
#include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <string.h> #include <sys/mman.h> #include <elf.h> #include <strings.h> #include <stdlib.h> extern int _crc32(void *mem, unsigned int len); void *_encrypt_zone(unsigned char *zone, size_t size, unsigned char *new_zone, unsigned char *key); size_t file_size(int fd) { off_t off; if (fd < 0) return (0); lseek(fd, 0, SEEK_SET); off = lseek(fd, 0, SEEK_END); lseek(fd, 0, SEEK_SET); if (off == -1) return (0); return ((size_t)off); } void patch_checksum_infos(void *mmaped) { Elf64_Ehdr *header; Elf64_Shdr *sec; unsigned char *text_sec; unsigned int text_size; unsigned int i; char *file_content; unsigned int checksum; header = mmaped; sec = mmaped + header->e_shoff; file_content = mmaped + sec[header->e_shstrndx].sh_offset; i = 0; while (i < header->e_shnum) { if (sec->sh_type == SHT_PROGBITS && !strcmp(file_content + sec->sh_name, ".text")) { text_sec = mmaped + sec->sh_offset; text_size = sec->sh_size; break ; } sec++; i++; } checksum = _crc32(text_sec, text_size - 4); *(unsigned int*)(text_sec + text_size - 4) = checksum; } void patch_table_offset(void *mmaped) { Elf64_Ehdr *header; Elf64_Shdr *sec; Elf64_Shdr *sec_sym; Elf64_Sym *sym; unsigned char *text_sec; unsigned int text_size; unsigned int i; unsigned long _table; unsigned long _o_entry; unsigned long _start; unsigned long _table_offset; char *file_content; char *strtab; int nb; header = mmaped; sec = mmaped + header->e_shoff; file_content = mmaped + sec[header->e_shstrndx].sh_offset; i = 0; while (i < header->e_shnum) { if (sec->sh_type == SHT_SYMTAB) { sec_sym = sec; sym = mmaped + sec->sh_offset; } else if (sec->sh_type == SHT_STRTAB && !strcmp(file_content + sec->sh_name, ".strtab")) { strtab = mmaped + sec->sh_offset; } else if (sec->sh_type == SHT_PROGBITS && !strcmp(file_content + sec->sh_name, ".text")) { text_sec = mmaped + sec->sh_offset; text_size = sec->sh_size; } sec++; i++; } i = 0; while (i < sec_sym->sh_size) { if (!strcmp(strtab + sym->st_name, "_table_offset")) { _table = sym->st_value; } else if (!strcmp(strtab + sym->st_name, "_o_entry")) { _o_entry = sym->st_value; } else if (!strcmp(strtab + sym->st_name, "_start")) { _start = sym->st_value; } i += sym->st_size + sizeof(Elf64_Sym); sym = (void*)sym + sym->st_size + sizeof(Elf64_Sym); } _table_offset = _table - _o_entry; _table_offset += (unsigned long)text_sec; _start = _start - _o_entry; _start += (unsigned long)text_sec; i = _start - (unsigned long)text_sec; text_size -= 4; nb = 0; while (i < text_size) { if (text_sec[i] == 0x90 && (*((unsigned int*)(text_sec + i + 1)) == 0x90909090)) { *(int*)_table_offset = (int)((unsigned long)(text_sec + i) - _start); _table_offset += 4; i += 4; nb++; if (nb == 32) break ; } i++; } } void patch_jmp_table_offset(void *mmaped) { Elf64_Ehdr *header; Elf64_Shdr *sec; Elf64_Shdr *sec_sym; Elf64_Sym *sym; unsigned char *text_sec; unsigned int i; unsigned long _table; unsigned long _o_entry; unsigned long _start; unsigned long _checkproc; unsigned long _checkdbg; unsigned long _crc32; unsigned long _checkdbg_by_status_file; unsigned long _table_offset; char *file_content; char *strtab; header = mmaped; sec = mmaped + header->e_shoff; file_content = mmaped + sec[header->e_shstrndx].sh_offset; i = 0; while (i < header->e_shnum) { if (sec->sh_type == SHT_SYMTAB) { sec_sym = sec; sym = mmaped + sec->sh_offset; } else if (sec->sh_type == SHT_STRTAB && !strcmp(file_content + sec->sh_name, ".strtab")) { strtab = mmaped + sec->sh_offset; } else if (sec->sh_type == SHT_PROGBITS && !strcmp(file_content + sec->sh_name, ".text")) { text_sec = mmaped + sec->sh_offset; } sec++; i++; } i = 0; while (i < sec_sym->sh_size) { if (!strcmp(strtab + sym->st_name, "_functions_offset_from_start")) { _table = sym->st_value; } else if (!strcmp(strtab + sym->st_name, "_o_entry")) { _o_entry = sym->st_value; } else if (!strcmp(strtab + sym->st_name, "_start")) { _start = sym->st_value; } else if (!strcmp(strtab + sym->st_name, "_checkproc")) { _checkproc = sym->st_value; } else if (!strcmp(strtab + sym->st_name, "_checkdbg")) { _checkdbg = sym->st_value; } else if (!strcmp(strtab + sym->st_name, "_crc32")) { _crc32 = sym->st_value; } else if (!strcmp(strtab + sym->st_name, "_checkdbg_by_status_file")) { _checkdbg_by_status_file = sym->st_value; } i += sym->st_size + sizeof(Elf64_Sym); sym = (void*)sym + sym->st_size + sizeof(Elf64_Sym); } _table_offset = _table - _o_entry; _table_offset += (unsigned long)text_sec; _checkproc = _checkproc - _start; _checkdbg = _checkdbg - _start; _crc32 = _crc32 - _start; _checkdbg_by_status_file = _checkdbg_by_status_file - _start; *(unsigned long*)(_table_offset + 0) = (unsigned long)_checkproc; *(unsigned long*)(_table_offset + 8) = (unsigned long)_checkdbg; *(unsigned long*)(_table_offset + 16) = (unsigned long)_crc32; *(unsigned long*)(_table_offset + 24) = (unsigned long)_checkdbg_by_status_file; } void encrypt_pestilence_infection_routine(void *mmaped) { Elf64_Ehdr *header; Elf64_Shdr *sec; Elf64_Shdr *sec_sym; Elf64_Sym *sym; unsigned char *text_sec; unsigned int i; unsigned long _encrypted_part_start; unsigned long _table_offset; unsigned long _padding; unsigned long _o_entry; unsigned long _start; char *file_content; char *strtab; unsigned char *key; unsigned long start_to_encrypt; size_t size_to_encrypt; header = mmaped; sec = mmaped + header->e_shoff; file_content = mmaped + sec[header->e_shstrndx].sh_offset; i = 0; while (i < header->e_shnum) { if (sec->sh_type == SHT_SYMTAB) { sec_sym = sec; sym = mmaped + sec->sh_offset; } else if (sec->sh_type == SHT_STRTAB && !strcmp(file_content + sec->sh_name, ".strtab")) { strtab = mmaped + sec->sh_offset; } else if (sec->sh_type == SHT_PROGBITS && !strcmp(file_content + sec->sh_name, ".text")) { text_sec = mmaped + sec->sh_offset; } sec++; i++; } i = 0; while (i < sec_sym->sh_size) { if (!strcmp(strtab + sym->st_name, "_encrypted_part_start")) { _encrypted_part_start = sym->st_value; } else if (!strcmp(strtab + sym->st_name, "_o_entry")) { _o_entry = sym->st_value; } else if (!strcmp(strtab + sym->st_name, "_start")) { _start = sym->st_value; } else if (!strcmp(strtab + sym->st_name, "_table_offset")) { _table_offset = sym->st_value; } else if (!strcmp(strtab + sym->st_name, "_padding")) { _padding = sym->st_value; } i += sym->st_size + sizeof(Elf64_Sym); sym = (void*)sym + sym->st_size + sizeof(Elf64_Sym); } start_to_encrypt = (_encrypted_part_start - _o_entry) + (unsigned long)text_sec; size_to_encrypt = _table_offset - _encrypted_part_start; key = _encrypt_zone((void*)start_to_encrypt, size_to_encrypt, (void*)start_to_encrypt, NULL); start_to_encrypt = (_table_offset - _o_entry) + (unsigned long)text_sec; size_to_encrypt = 128; _encrypt_zone((void*)start_to_encrypt, size_to_encrypt, (void*)start_to_encrypt, key); start_to_encrypt = (_table_offset - _o_entry) + (unsigned long)text_sec + 128; size_to_encrypt = _padding - (_table_offset + 128); _encrypt_zone((void*)start_to_encrypt, size_to_encrypt, (void*)start_to_encrypt, key); memcpy((void*)(text_sec + (_padding - _o_entry)), key, 256); munmap(key, 256); } int main(void) { int fd; size_t fd_size; void *mmaped; fd = open("./pestilence", O_RDWR); if (fd <= 0) return (0); fd_size = file_size(fd); mmaped = mmap(0, fd_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if (!mmap) { close(fd); return (0); } patch_table_offset(mmaped); patch_jmp_table_offset(mmaped); encrypt_pestilence_infection_routine(mmaped); patch_checksum_infos(mmaped); munmap(mmaped, fd_size); close(fd); }
the_stack_data/52173.c
extern float __VERIFIER_nondet_float(void); extern int __VERIFIER_nondet_int(void); typedef enum {false, true} bool; bool __VERIFIER_nondet_bool(void) { return __VERIFIER_nondet_int() != 0; } int main() { float x_2, _x_x_2; float x_8, _x_x_8; bool _EL_X_518, _x__EL_X_518; float x_11, _x_x_11; bool _EL_U_516, _x__EL_U_516; float x_9, _x_x_9; float x_3, _x_x_3; float x_0, _x_x_0; float x_10, _x_x_10; float x_4, _x_x_4; float x_7, _x_x_7; float x_5, _x_x_5; float x_1, _x_x_1; float x_6, _x_x_6; int __steps_to_fair = __VERIFIER_nondet_int(); x_2 = __VERIFIER_nondet_float(); x_8 = __VERIFIER_nondet_float(); _EL_X_518 = __VERIFIER_nondet_bool(); x_11 = __VERIFIER_nondet_float(); _EL_U_516 = __VERIFIER_nondet_bool(); x_9 = __VERIFIER_nondet_float(); x_3 = __VERIFIER_nondet_float(); x_0 = __VERIFIER_nondet_float(); x_10 = __VERIFIER_nondet_float(); x_4 = __VERIFIER_nondet_float(); x_7 = __VERIFIER_nondet_float(); x_5 = __VERIFIER_nondet_float(); x_1 = __VERIFIER_nondet_float(); x_6 = __VERIFIER_nondet_float(); bool __ok = (1 && ( !((12.0 <= (x_3 + (-1.0 * x_11))) || _EL_X_518))); while (__steps_to_fair >= 0 && __ok) { if ((( !((x_4 + (-1.0 * x_5)) <= -11.0)) || ( !(( !((x_4 + (-1.0 * x_5)) <= -11.0)) || _EL_U_516)))) { __steps_to_fair = __VERIFIER_nondet_int(); } else { __steps_to_fair--; } _x_x_2 = __VERIFIER_nondet_float(); _x_x_8 = __VERIFIER_nondet_float(); _x__EL_X_518 = __VERIFIER_nondet_bool(); _x_x_11 = __VERIFIER_nondet_float(); _x__EL_U_516 = __VERIFIER_nondet_bool(); _x_x_9 = __VERIFIER_nondet_float(); _x_x_3 = __VERIFIER_nondet_float(); _x_x_0 = __VERIFIER_nondet_float(); _x_x_10 = __VERIFIER_nondet_float(); _x_x_4 = __VERIFIER_nondet_float(); _x_x_7 = __VERIFIER_nondet_float(); _x_x_5 = __VERIFIER_nondet_float(); _x_x_1 = __VERIFIER_nondet_float(); _x_x_6 = __VERIFIER_nondet_float(); __ok = ((((((((((((((((x_11 + (-1.0 * _x_x_0)) <= -14.0) && (((x_10 + (-1.0 * _x_x_0)) <= -6.0) && (((x_7 + (-1.0 * _x_x_0)) <= -17.0) && (((x_4 + (-1.0 * _x_x_0)) <= -8.0) && (((x_0 + (-1.0 * _x_x_0)) <= -15.0) && ((x_2 + (-1.0 * _x_x_0)) <= -16.0)))))) && (((x_11 + (-1.0 * _x_x_0)) == -14.0) || (((x_10 + (-1.0 * _x_x_0)) == -6.0) || (((x_7 + (-1.0 * _x_x_0)) == -17.0) || (((x_4 + (-1.0 * _x_x_0)) == -8.0) || (((x_0 + (-1.0 * _x_x_0)) == -15.0) || ((x_2 + (-1.0 * _x_x_0)) == -16.0))))))) && ((((x_11 + (-1.0 * _x_x_1)) <= -15.0) && (((x_10 + (-1.0 * _x_x_1)) <= -3.0) && (((x_9 + (-1.0 * _x_x_1)) <= -1.0) && (((x_6 + (-1.0 * _x_x_1)) <= -13.0) && (((x_1 + (-1.0 * _x_x_1)) <= -14.0) && ((x_5 + (-1.0 * _x_x_1)) <= -8.0)))))) && (((x_11 + (-1.0 * _x_x_1)) == -15.0) || (((x_10 + (-1.0 * _x_x_1)) == -3.0) || (((x_9 + (-1.0 * _x_x_1)) == -1.0) || (((x_6 + (-1.0 * _x_x_1)) == -13.0) || (((x_1 + (-1.0 * _x_x_1)) == -14.0) || ((x_5 + (-1.0 * _x_x_1)) == -8.0)))))))) && ((((x_11 + (-1.0 * _x_x_2)) <= -17.0) && (((x_9 + (-1.0 * _x_x_2)) <= -13.0) && (((x_8 + (-1.0 * _x_x_2)) <= -6.0) && (((x_6 + (-1.0 * _x_x_2)) <= -5.0) && (((x_0 + (-1.0 * _x_x_2)) <= -11.0) && ((x_4 + (-1.0 * _x_x_2)) <= -7.0)))))) && (((x_11 + (-1.0 * _x_x_2)) == -17.0) || (((x_9 + (-1.0 * _x_x_2)) == -13.0) || (((x_8 + (-1.0 * _x_x_2)) == -6.0) || (((x_6 + (-1.0 * _x_x_2)) == -5.0) || (((x_0 + (-1.0 * _x_x_2)) == -11.0) || ((x_4 + (-1.0 * _x_x_2)) == -7.0)))))))) && ((((x_10 + (-1.0 * _x_x_3)) <= -13.0) && (((x_9 + (-1.0 * _x_x_3)) <= -20.0) && (((x_8 + (-1.0 * _x_x_3)) <= -17.0) && (((x_4 + (-1.0 * _x_x_3)) <= -7.0) && (((x_1 + (-1.0 * _x_x_3)) <= -8.0) && ((x_2 + (-1.0 * _x_x_3)) <= -7.0)))))) && (((x_10 + (-1.0 * _x_x_3)) == -13.0) || (((x_9 + (-1.0 * _x_x_3)) == -20.0) || (((x_8 + (-1.0 * _x_x_3)) == -17.0) || (((x_4 + (-1.0 * _x_x_3)) == -7.0) || (((x_1 + (-1.0 * _x_x_3)) == -8.0) || ((x_2 + (-1.0 * _x_x_3)) == -7.0)))))))) && ((((x_11 + (-1.0 * _x_x_4)) <= -6.0) && (((x_10 + (-1.0 * _x_x_4)) <= -1.0) && (((x_6 + (-1.0 * _x_x_4)) <= -20.0) && (((x_3 + (-1.0 * _x_x_4)) <= -4.0) && (((x_0 + (-1.0 * _x_x_4)) <= -4.0) && ((x_1 + (-1.0 * _x_x_4)) <= -14.0)))))) && (((x_11 + (-1.0 * _x_x_4)) == -6.0) || (((x_10 + (-1.0 * _x_x_4)) == -1.0) || (((x_6 + (-1.0 * _x_x_4)) == -20.0) || (((x_3 + (-1.0 * _x_x_4)) == -4.0) || (((x_0 + (-1.0 * _x_x_4)) == -4.0) || ((x_1 + (-1.0 * _x_x_4)) == -14.0)))))))) && ((((x_11 + (-1.0 * _x_x_5)) <= -9.0) && (((x_9 + (-1.0 * _x_x_5)) <= -18.0) && (((x_4 + (-1.0 * _x_x_5)) <= -14.0) && (((x_3 + (-1.0 * _x_x_5)) <= -17.0) && (((x_1 + (-1.0 * _x_x_5)) <= -7.0) && ((x_2 + (-1.0 * _x_x_5)) <= -19.0)))))) && (((x_11 + (-1.0 * _x_x_5)) == -9.0) || (((x_9 + (-1.0 * _x_x_5)) == -18.0) || (((x_4 + (-1.0 * _x_x_5)) == -14.0) || (((x_3 + (-1.0 * _x_x_5)) == -17.0) || (((x_1 + (-1.0 * _x_x_5)) == -7.0) || ((x_2 + (-1.0 * _x_x_5)) == -19.0)))))))) && ((((x_10 + (-1.0 * _x_x_6)) <= -6.0) && (((x_8 + (-1.0 * _x_x_6)) <= -3.0) && (((x_7 + (-1.0 * _x_x_6)) <= -11.0) && (((x_6 + (-1.0 * _x_x_6)) <= -11.0) && (((x_1 + (-1.0 * _x_x_6)) <= -2.0) && ((x_3 + (-1.0 * _x_x_6)) <= -6.0)))))) && (((x_10 + (-1.0 * _x_x_6)) == -6.0) || (((x_8 + (-1.0 * _x_x_6)) == -3.0) || (((x_7 + (-1.0 * _x_x_6)) == -11.0) || (((x_6 + (-1.0 * _x_x_6)) == -11.0) || (((x_1 + (-1.0 * _x_x_6)) == -2.0) || ((x_3 + (-1.0 * _x_x_6)) == -6.0)))))))) && ((((x_11 + (-1.0 * _x_x_7)) <= -13.0) && (((x_9 + (-1.0 * _x_x_7)) <= -11.0) && (((x_7 + (-1.0 * _x_x_7)) <= -9.0) && (((x_6 + (-1.0 * _x_x_7)) <= -20.0) && (((x_1 + (-1.0 * _x_x_7)) <= -19.0) && ((x_3 + (-1.0 * _x_x_7)) <= -16.0)))))) && (((x_11 + (-1.0 * _x_x_7)) == -13.0) || (((x_9 + (-1.0 * _x_x_7)) == -11.0) || (((x_7 + (-1.0 * _x_x_7)) == -9.0) || (((x_6 + (-1.0 * _x_x_7)) == -20.0) || (((x_1 + (-1.0 * _x_x_7)) == -19.0) || ((x_3 + (-1.0 * _x_x_7)) == -16.0)))))))) && ((((x_11 + (-1.0 * _x_x_8)) <= -18.0) && (((x_8 + (-1.0 * _x_x_8)) <= -20.0) && (((x_7 + (-1.0 * _x_x_8)) <= -19.0) && (((x_6 + (-1.0 * _x_x_8)) <= -3.0) && (((x_0 + (-1.0 * _x_x_8)) <= -12.0) && ((x_3 + (-1.0 * _x_x_8)) <= -17.0)))))) && (((x_11 + (-1.0 * _x_x_8)) == -18.0) || (((x_8 + (-1.0 * _x_x_8)) == -20.0) || (((x_7 + (-1.0 * _x_x_8)) == -19.0) || (((x_6 + (-1.0 * _x_x_8)) == -3.0) || (((x_0 + (-1.0 * _x_x_8)) == -12.0) || ((x_3 + (-1.0 * _x_x_8)) == -17.0)))))))) && ((((x_8 + (-1.0 * _x_x_9)) <= -3.0) && (((x_7 + (-1.0 * _x_x_9)) <= -9.0) && (((x_5 + (-1.0 * _x_x_9)) <= -2.0) && (((x_4 + (-1.0 * _x_x_9)) <= -14.0) && (((x_0 + (-1.0 * _x_x_9)) <= -20.0) && ((x_1 + (-1.0 * _x_x_9)) <= -8.0)))))) && (((x_8 + (-1.0 * _x_x_9)) == -3.0) || (((x_7 + (-1.0 * _x_x_9)) == -9.0) || (((x_5 + (-1.0 * _x_x_9)) == -2.0) || (((x_4 + (-1.0 * _x_x_9)) == -14.0) || (((x_0 + (-1.0 * _x_x_9)) == -20.0) || ((x_1 + (-1.0 * _x_x_9)) == -8.0)))))))) && ((((x_10 + (-1.0 * _x_x_10)) <= -20.0) && (((x_7 + (-1.0 * _x_x_10)) <= -16.0) && (((x_6 + (-1.0 * _x_x_10)) <= -20.0) && (((x_5 + (-1.0 * _x_x_10)) <= -14.0) && (((x_1 + (-1.0 * _x_x_10)) <= -18.0) && ((x_2 + (-1.0 * _x_x_10)) <= -9.0)))))) && (((x_10 + (-1.0 * _x_x_10)) == -20.0) || (((x_7 + (-1.0 * _x_x_10)) == -16.0) || (((x_6 + (-1.0 * _x_x_10)) == -20.0) || (((x_5 + (-1.0 * _x_x_10)) == -14.0) || (((x_1 + (-1.0 * _x_x_10)) == -18.0) || ((x_2 + (-1.0 * _x_x_10)) == -9.0)))))))) && ((((x_10 + (-1.0 * _x_x_11)) <= -18.0) && (((x_9 + (-1.0 * _x_x_11)) <= -6.0) && (((x_8 + (-1.0 * _x_x_11)) <= -12.0) && (((x_6 + (-1.0 * _x_x_11)) <= -12.0) && (((x_1 + (-1.0 * _x_x_11)) <= -1.0) && ((x_5 + (-1.0 * _x_x_11)) <= -17.0)))))) && (((x_10 + (-1.0 * _x_x_11)) == -18.0) || (((x_9 + (-1.0 * _x_x_11)) == -6.0) || (((x_8 + (-1.0 * _x_x_11)) == -12.0) || (((x_6 + (-1.0 * _x_x_11)) == -12.0) || (((x_1 + (-1.0 * _x_x_11)) == -1.0) || ((x_5 + (-1.0 * _x_x_11)) == -17.0)))))))) && ((_EL_U_516 == (_x__EL_U_516 || ( !((_x_x_4 + (-1.0 * _x_x_5)) <= -11.0)))) && (_EL_X_518 == ( !(_x__EL_U_516 || ( !((_x_x_4 + (-1.0 * _x_x_5)) <= -11.0))))))); x_2 = _x_x_2; x_8 = _x_x_8; _EL_X_518 = _x__EL_X_518; x_11 = _x_x_11; _EL_U_516 = _x__EL_U_516; x_9 = _x_x_9; x_3 = _x_x_3; x_0 = _x_x_0; x_10 = _x_x_10; x_4 = _x_x_4; x_7 = _x_x_7; x_5 = _x_x_5; x_1 = _x_x_1; x_6 = _x_x_6; } }
the_stack_data/159515804.c
#include <stdio.h> int main() { //Declaração de variaveis int t1; int t2; int t3; int t4; int total; //Criação do ponteiro e leitura do arquivo FILE *entrada; entrada = fopen("entrada.txt", "r"); //Lendo dados do arquivo if(entrada == NULL){ printf("Erro ao abrir o arquivo!"); }else{ fscanf(entrada, "%d %d %d %d", &t1, &t2, &t3, &t4); if((t1>1 && t1<7) && (t2>1 && t2<7) && (t3>1 && t3<7) && (t4>1 && t4<7)){ total = (t1+t2+t3+t4) - 3; printf("Tomadas que podem ser usadas: %d", total); } else{ printf("Input Invalido! Insira elementos entre o intervalo [2,6]"); } fclose(entrada); } return 0; }
the_stack_data/795222.c
#include <stdio.h> void swap(int * a, int* b){ int t = *a; *a = *b; *b = t; } /* A utility function to print array of size n */ void printArray(int* arr, int size) { int i; for (i = 0; i < size; ++i) printf("%d ", arr[i]); printf("\n"); } void heapify(int arr[], int n, int i) { int largest = i; // Initialize largest as root int l = 2*i + 1; // left = 2*i + 1 int r = 2*i + 2; // right = 2*i + 2 // If left child is larger than root if (l < n && arr[l] > arr[largest]) largest = l; // If right child is larger than largest so far if (r < n && arr[r] > arr[largest]) largest = r; // If largest is not root if (largest != i) { swap(&arr[i], &arr[largest]); // Recursively heapify the affected sub-tree heapify(arr, n, largest); } }
the_stack_data/5062.c
/* Reset terminal line settings (stty sane) * * Copyright (c) 2016-2017 Joachim Nilsson <[email protected]> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include <errno.h> #include <stdlib.h> #include <unistd.h> /* _POSIX_VDISABLE */ #include <sys/ttydefaults.h> /* Not included by default in musl libc */ #include <termios.h> speed_t stty_parse_speed(char *baud) { char *ptr; size_t i; unsigned long val; struct { unsigned long val; speed_t speed; } v2s[] = { { 0, B0 }, { 50, B50 }, { 75, B75 }, { 110, B110 }, { 134, B134 }, { 150, B150 }, { 200, B200 }, { 300, B300 }, { 600, B600 }, { 1200, B1200 }, { 1800, B1800 }, { 2400, B2400 }, { 4800, B4800 }, { 9600, B9600 }, { 19200, B19200 }, { 38400, B38400 }, { 57600, B57600 }, { 115200, B115200 }, { 230400, B230400 }, { 460800, B460800 }, { 500000, B500000 }, { 576000, B576000 }, { 921600, B921600 }, { 1000000, B1000000 }, { 1152000, B1152000 }, { 1500000, B1500000 }, { 2000000, B2000000 }, { 2500000, B2500000 }, { 3000000, B3000000 }, { 3500000, B3500000 }, { 4000000, B4000000 }, }; errno = 0; val = strtoul(baud, &ptr, 10); if (errno || ptr == baud) return B0; for (i = 0; i < sizeof(v2s) / sizeof(v2s[0]); i++) { if (v2s[i].val == val) return v2s[i].speed; } return B0; } void stty(int fd, speed_t speed) { struct termios term; tcdrain(fd); if (tcgetattr(fd, &term)) return; if (speed != B0) { cfsetispeed(&term, speed); cfsetospeed(&term, speed); tcsetattr(fd, TCSAFLUSH, &term); } tcflush(fd, TCIOFLUSH); /* Disable modem specific flags */ term.c_cflag &= ~(0|CSTOPB|PARENB|PARODD|CBAUDEX); term.c_cflag &= ~CRTSCTS; term.c_cflag |= CLOCAL; /* Timeouts, minimum chars and default flags */ term.c_cc[VTIME] = 0; term.c_cc[VMIN] = 1; term.c_iflag = ICRNL|IXON|IXOFF; term.c_oflag = OPOST|ONLCR; term.c_cflag |= CS8|CREAD|HUPCL; term.c_lflag |= ICANON|ISIG|ECHO|ECHOE|ECHOK|ECHOKE; /* Reset special characters to defaults */ term.c_cc[VINTR] = CTRL('C'); term.c_cc[VQUIT] = CTRL('\\'); term.c_cc[VEOF] = CTRL('D'); term.c_cc[VEOL] = '\n'; term.c_cc[VKILL] = CTRL('U'); term.c_cc[VERASE] = CERASE; tcsetattr(fd, TCSANOW, &term); /* Show cursor again, if it was hidden previously */ write(fd, "\033[?25h", 6); /* Enable line wrap, if disabled previously */ write(fd, "\033[7h", 4); } /** * Local Variables: * indent-tabs-mode: t * c-file-style: "linux" * End: */
the_stack_data/3261572.c
#include <stdio.h> #include <stdlib.h> #include <string.h> void dangerZONE(){ printf("sucess\n"); char *name[] = {"/bin/bash", NULL}; setuid(0); execvp(name[0], name); } void vuln(char* string){ char buffer[20] = {0}; strcpy(buffer, string); printf(buffer); } int main(int argc, char *argv[]){ printf("Hello \n"); if(argc > 1){ vuln(argv[1]); }else{ printf("Enter data...\n"); } return 0; }
the_stack_data/172392.c
int m = 0; int value(int x,int y){ int z = x + y; m = 10; return z; } int add(){ int a = 1; int b = 1; int c = value(a,b); return (m + c); }
the_stack_data/140766925.c
/* common_test_1_v2.c -- test common symbol sorting Copyright (C) 2008-2020 Free Software Foundation, Inc. Written by Ian Lance Taylor <[email protected]> This file is part of gold. 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, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. This is a test of a common symbol in the main program and a versioned symbol in a shared library. The common symbol in the main program should override the shared library symbol. */ #include <assert.h> /* Common symbols should be sorted by size, largest first, and then by alignment, largest first. We mix up the names, because gas seems to sort common symbols roughly by name. */ int c9[90]; int c8[80]; int c7[70]; int c6[60]; int c5[10]; int c4[20]; int c3[30]; int c2[40]; int c1[50]; int a1 __attribute__ ((aligned (1 << 9))); int a2 __attribute__ ((aligned (1 << 8))); int a3 __attribute__ ((aligned (1 << 7))); int a4 __attribute__ ((aligned (1 << 6))); int a5 __attribute__ ((aligned (1 << 1))); int a6 __attribute__ ((aligned (1 << 2))); int a7 __attribute__ ((aligned (1 << 3))); int a8 __attribute__ ((aligned (1 << 4))); int a9 __attribute__ ((aligned (1 << 5))); int main (int argc __attribute__ ((unused)), char** argv __attribute__ ((unused))) { // After an incremental update, all guarantees about ordering // are null. assert (c5 != c4); assert (c4 != c3); assert (c3 != c2); assert (c2 != c1); assert (c1 != c6); assert (c6 != c7); assert (c7 != c8); assert (c8 != c9); assert (&a1 != &a2); assert (&a2 != &a3); assert (&a3 != &a4); assert (&a4 != &a9); assert (&a9 != &a8); assert (&a8 != &a7); assert (&a7 != &a6); assert (&a6 != &a5); return 0; }
the_stack_data/68887661.c
void _in_dbg_master() {} void acpi_evaluate_object() {} void acpi_format_exception() {} void atomic_cas_ptr() {} void atomic_dec_int() {} void atomic_inc_int() {} void atomic_swap_ptr() {} void atop() {} void betoh32() {} void bus_space_barrier() {} void bus_space_map() {} void bus_space_mmap() {} void bus_space_read_4() {} void bus_space_unmap() {} void bus_space_vaddr() {} void bus_space_write_4() {} void config_activate_children() {} void config_detach() {} void copyin() {} void copyout() {} void cpu_ecxfeature() {} void CTASSERT() {} void curproc() {} void dma_fence_wait() {} void drm_can_sleep() {} void drm_legacy_lock_master_cleanup() {} void fls() {} void i2c_bitbang_initiate_xfer() {} void i2c_bitbang_read_byte() {} void i2c_bitbang_send_start() {} void i2c_bitbang_send_stop() {} void i2c_bitbang_write_byte() {} void init_waitqueue_head() {} void iowrite8() {} void ISA_HOLE_VADDR() {} void jiffies() {} void KASSERT() {} void ktime_get() {} void lemtoh32() {} void msleep() {} void MUTEX_ASSERT_LOCKED() {} void pci_conf_read() {} void pci_conf_write() {} void pci_intr_disestablish() {} void pci_probe_device() {} void PCI_ROM_ADDR() {} void PCI_ROM_SIZE() {} void pool_get() {} void power_supply_is_system_supplied() {} void rasops_alloc_screen() {} void rasops_free_screen() {} void READ_ONCE() {} void register_acpi_notifier() {} void roundup() {} void rw_enter_read() {} void rw_status() {} void sch_mtx() {} void static_cpu_has() {} void systq() {} void task_add() {} void task_del() {} void timeout_add() {} void timeout_del_barrier() {} void ttm_bo_clean_mm() {} void ttm_bo_device_init() {} void ttm_bo_device_release() {} void ttm_bo_dma_acc_size() {} void ttm_bo_evict_mm() {} void ttm_bo_eviction_valuable() {} void ttm_bo_init_mm() {} void ttm_bo_kmap() {} void ttm_bo_kunmap() {} void ttm_bo_lock_delayed_workqueue() {} void ttm_bo_manager_func() {} void ttm_bo_mem_put() {} void ttm_bo_mem_space() {} void ttm_bo_move_memcpy() {} void ttm_bo_move_ttm() {} void ttm_bo_put() {} void ttm_bo_unlock_delayed_workqueue() {} void ttm_bo_unmap_virtual() {} void ttm_bo_unreserve() {} void ttm_bo_validate() {} void ttm_bo_wait() {} void ttm_dma_tt_fini() {} void ttm_populate_and_map_pages() {} void ttm_tt_bind() {} void ttm_tt_set_placement_caching() {} void ttm_unmap_and_unpopulate_pages() {} void unregister_acpi_notifier() {} void uvm_page_physload() {} void vprintf() {} void wake_up() {} void wakeup() {} void WRITE_ONCE() {}
the_stack_data/1005036.c
#include <stdlib.h> #include <stdbool.h> /* ***************************** * VISITAR * ****************************/ // Verfica si un vertice fue visitado o no. bool visitado(bool* visitados, char* vertice) { return visitados[atoi(vertice)]; } // Verifica si ya se visitaron todos los vertices del grafo. bool todos_visitados(bool* visitados, size_t tam) { size_t i = 0; while (i < tam) { if (!visitados[i]) return false; i++; } return true; }
the_stack_data/51699553.c
#include <stdio.h> #include <string.h> int main(){ char assinatura[10], painel[300001]; int instancia = 1, cont = 1, cont2; while(cont!= 0){ scanf("%s",&assinatura); if(assinatura[0]=='0'){ cont=0; break; } if (instancia > 1){ printf("\n");} scanf("%s",&painel); if(strstr(painel, assinatura)){ printf("Instancia %d\n", instancia); printf("verdadeira\n"); }else{ printf("Instancia %d\n", instancia); printf("falsa\n"); } instancia++; } return 0; }
the_stack_data/72012136.c
// constante // #define VARIBLE valor #include <stdio.h> int main(void){ const float pi = 3.14; float r, a; printf("Radio: "); scanf("%f", &r); a = pi * r * r; printf("Area: %f\n", a); return 0; }
the_stack_data/165767642.c
#include <stdio.h> #include <omp.h> int main() { int n; #pragma omp parallel private(n) { n = omp_get_thread_num(); printf("Before critical %i \n", n); #pragma omp critical { printf("Thread %i is working \n", n); }; printf("After critical %i \n", n); } return 0; }
the_stack_data/117327375.c
#include <stdio.h> #include <stdlib.h> typedef struct node* iterator; typedef struct node { int coef; int expo; struct node* next; }Node; iterator create_singly_linked_list(int coef, int expo) { iterator head = (iterator)malloc(sizeof(Node)); head->coef = coef; head->expo = expo; head->next = 0; return head; } iterator insert_inorder(int coef, int expo, iterator head) { iterator it = head; iterator prev = 0; if(head->expo < expo) { iterator new = (iterator)malloc(sizeof(Node)); new->coef = coef; new->expo = expo; new->next = head; head = new; return head; } while(it->expo > expo) { if(it->next == 0) { if(it->coef == coef) { it->coef += coef; return head; } iterator new = (iterator)malloc(sizeof(Node)); new->coef = coef; new->expo = expo; new->next = 0; it->next = new; return head; } prev = it; it = it->next; } if(it->expo == expo) { it->coef += coef; return head; } iterator new = (iterator)malloc(sizeof(Node)); new->coef = coef; new->expo = expo; new->next = it; prev->next = new; return head; } iterator insert_at_end(int coef, int expo, iterator head) { iterator it = head; while(it->next != 0) it = it->next; iterator new = (iterator)malloc(sizeof(Node)); new->coef = coef; new->expo = expo; new->next = 0; it->next = new; return head; } iterator add_polynomials(iterator head1, iterator head2) { iterator temp1 = head1; iterator temp2 = head2; iterator head3 = 0; while(temp1 != 0 && temp2 != 0) { if(temp1->expo < temp2->expo) { if(head3 == 0){ head3 = create_singly_linked_list(temp2->coef, temp2->expo); } else{ head3 = insert_at_end(temp2->coef, temp2->expo, head3); } temp2 = temp2->next; } else if(temp1->expo > temp2->expo) { if(head3 == 0){ head3 = create_singly_linked_list(temp1->coef, temp1->expo); } else{ head3 = insert_at_end(temp1->coef, temp1->expo, head3); } temp1 = temp1->next; } else { if(head3 == 0){ head3 = create_singly_linked_list(temp1->coef + temp2->coef, temp1->expo); } else{ head3 = insert_at_end(temp1->coef + temp2->coef, temp1->expo, head3); } temp1 = temp1->next; temp2 = temp2->next; } } iterator it = head3; while(it->next != 0) it = it->next; if(temp1 == 0 && temp2 != 0) it->next = temp2; else if(temp2 == 0 && temp1 != 0) it->next = temp1; return head3; } void display_sll(iterator head) { iterator it = head; while(it->next != 0) { printf("%d * x^%d + ", it->coef, it->expo); it = it->next; } printf("%d * x^%d", it->coef, it->expo); printf("\n"); } int main() { iterator head1 = 0; iterator head2 = 0; int terms1, terms2; printf("Enter the number of terms in first polynomial: "); scanf("%d", &terms1); printf("Enter the coeficient and exponent for all terms of first polynomial: "); for(int i=0;i<terms1;i++) { int coef, expo; scanf("%d%d", &coef, &expo); if(head1 == 0) head1 = create_singly_linked_list(coef, expo); else head1 = insert_inorder(coef, expo, head1); } display_sll(head1); printf("Enter the number of terms in second polynomial: "); scanf("%d", &terms2); printf("Enter the coeficient and exponent for all terms of second polynomial: "); for(int i=0;i<terms2;i++) { int coef, expo; scanf("%d%d", &coef, &expo); if(head2 == 0) head2 = create_singly_linked_list(coef, expo); else head2 = insert_inorder(coef, expo, head2); } display_sll(head2); iterator head3 = add_polynomials(head1, head2); display_sll(head3); }
the_stack_data/231393904.c
void foo() { void foobar(union union_tag_2 *xxx); }
the_stack_data/107954250.c
//Ultra simple http server based on //Echoserv by Paul Griffiths, 1999 #include <sys/socket.h> #include <sys/types.h> #include <sys/wait.h> #include <arpa/inet.h> #include <signal.h> #include <unistd.h> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <errno.h> /* Global constants */ #define HTTP_PORT (31337) #define MAX_LINE (1000) #define LISTENQ (1024) #define HTTP_RECVHDR_LEN (1024) #define MARGIN (512) const char httphdr[] = "Server: Granelver\r\n" "Content-Type: text/html; charset=UTF-8\r\n"; const char http400msg[] = "It is your fault."; const char http404msg[] = "Here is Invisible Pink Unicorn."; //Embedded HTML in ELF extern int _binary_pwned_gz_start; extern int _binary_pwned_gz_size; void reaper(int sig); void handle_error(char *msg) { fprintf(stderr, "[-] %s\n", msg); fprintf(stderr, "[-] errno = %d\n", errno); exit(EXIT_FAILURE); } void send_http_header(int fd, int code, char *message, char *encoding, int bodylen) { char buf[1024]; snprintf(buf, 1024, "HTTP/1.0 %d %s\r\n", code, message); write(fd, buf, strlen(buf)); snprintf(buf, 1024, "Content-Length: %d\r\n", bodylen); write(fd, buf, strlen(buf)); snprintf(buf, 1024, "Content-Encoding: %s\r\n", encoding); write(fd, buf, strlen(buf)); write(fd, httphdr, strlen(httphdr)); write(fd, "\r\n", 2); } int main(int argc, char *argv[]) { int list_s; /* listening socket */ int conn_s; /* connection socket */ struct sockaddr_in servaddr; /* socket address structure */ char httprecvhdr[HTTP_RECVHDR_LEN]; printf("%d, %s\n", argc, argv[1]); if (argc > 1 && strncmp("hijack", argv[1], 7) == 0) { printf("Hijack!!\n"); system ("iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 31337"); } //Daemonize. if (fork() != 0) { exit(0); } setsid(); signal(SIGHUP, SIG_IGN); /* Create the listening socket */ if ((list_s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { handle_error("Error creating listening socket."); } /* Set all bytes in socket address structure to zero, and fill in the relevant data members */ memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(HTTP_PORT); /* Bind our socket addresss to the listening socket, and call listen() */ if (bind(list_s, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) { handle_error("Error calling bind()"); } if (listen(list_s, LISTENQ) < 0) { handle_error("Error calling listen()"); } fprintf(stderr, "[+] Successfully initialized web server\n"); //Corpse reaper signal(SIGCHLD, reaper); /* Enter an infinite loop to respond to client requests and dirty HTTP impl */ for (;;) { /* Wait for a connection, then accept() it */ if ((conn_s = accept(list_s, NULL, NULL)) < 0) { handle_error("Error calling accept()"); } if (0 != fork()) { close(conn_s); fprintf(stderr, "[+] Parent closed socket\n"); continue; } else { fprintf(stderr, "[+] Child spawned successfully\n"); } char c; int cnt = 0; int recvsz = 0; char *httprecvhdr_off = httprecvhdr; for (;;) { read(conn_s, &c, 1); if (recvsz > HTTP_RECVHDR_LEN + 2) { // It's your fault but I'll not throw 400 because I'm // too lazy to implement 400 send_http_header(conn_s, 400, "Bad Request", "identity", strlen(http400msg)); write(conn_s, http400msg, strlen(http400msg)); close(conn_s); exit(0); } if (c == 0x0D || c == 0x0A) { cnt++; } else { *httprecvhdr_off = c; httprecvhdr_off++; } if (cnt >= 2) { fprintf(stderr, "[+] Detect end of HTTP verb and URI\n"); *httprecvhdr_off = 0x00; break; } } char method[HTTP_RECVHDR_LEN]; char uri[HTTP_RECVHDR_LEN]; char version[HTTP_RECVHDR_LEN]; sscanf(httprecvhdr, "%s %s %s\n", method, uri, version); fprintf(stderr, "[+] HTTP VERB: %s, HTTP URI: %s\n", method, uri); cnt = 0; for (;;) { read(conn_s, &c, 1); if (c == 0x0D || c == 0x0A) { cnt++; } else { cnt = 0; } if (cnt >= 4) { break; } } fprintf(stderr, "[+] Detect end of HTTP request. Sending data...\n"); if (strcmp(uri, "/favicon.ico") == 0) { send_http_header(conn_s, 404, "Not found", "identify", strlen(http404msg)); send(conn_s, http404msg, strlen(http404msg), 0); } else { send_http_header(conn_s, 200, "OK", "gzip", (int) (intptr_t) & _binary_pwned_gz_size); send(conn_s, (char *) &_binary_pwned_gz_start, (int) (intptr_t) & _binary_pwned_gz_size, 0); } fprintf(stderr, "[+] Data sent!\n"); /* Close the connected socket */ if (shutdown(conn_s, SHUT_WR) < 0) { handle_error("Error calling shutdown()"); } else { fprintf(stderr, "[+] socket shutted down\n"); } if (close(conn_s) < 0) { handle_error("Error calling close()"); } else { fprintf(stderr, "[+] Socket closed\n"); } exit(0); } } void reaper(int sig) { while (waitpid(-1, 0, WNOHANG) >= 0); }
the_stack_data/42029.c
/*C Program to implement linked queue*/ #include<stdio.h> //preprocessor directive #include<stdlib.h> typedef struct node //defining node { int data; struct node *next; }node; void enque(node**,node**,int); //function declaration int deque(node**,node**,int*); int peek(node*,int*); void display(node*); int main() { int n,item;node *front=NULL,*rear=NULL; //variable declaration do //main menu { printf("\n----------MAIN MENU----------\n"); printf("\n1.ENQUEUE"); printf("\n2.DEQUEUE"); printf("\n3.PEEK"); printf("\n4.Display"); printf("\n5.Exit\n"); printf("\nEnter Choice: "); scanf("%d",&n); switch(n) { case 1:{ //enqueue printf("\nEnter Element: "); scanf("%d",&item); enque(&front,&rear,item); printf("\n%d Added\n",item); break; } case 2:{ //dequeue if(deque(&front,&rear,&item)) printf("\n%d Deleted\n",item); break; } case 3:{ //peek if(peek(front,&item)) printf("\nPEEK = %d\n",item); break; } case 4:{ //display printf("\nDispalying Queue............\n"); display(front); break; } case 5: break; //exit default: printf("\nWRONG CHOICE\n"); } }while(n!=5); //end of do-while loop printf("\n"); return 0; } //end of program void enque(node **front,node **rear,int item) //enqueue { node *new_node=(node*)malloc(sizeof(node)); //memory allocation new_node->data=item; new_node->next=NULL; if(*front==NULL) //if front is null { *front=new_node; *rear=new_node; return; } (*rear)->next=new_node; *rear=new_node; //update rear return; } //end of enqueue int deque(node **front,node **rear,int *item) //dequeue { if(*front==NULL) //underflow checking { printf("\nUNDERFLOW\n"); return 0; } node *ptr=*front; *item=(*front)->data; if(*front==*rear) //if only 1 node exists { *front=*rear=NULL; free(*front); return 1; } *front=(*front)->next; //update front free(ptr); return 1; } //end of dequeue int peek(node *front,int *item) //peek { if(front==NULL) { printf("\nQUEUE IS EMPTY\n"); return 0; } *item=front->data; return 1; } //end of peek void display(node *front) //display { if(front==NULL) { printf("\nQUEUE IS EMPTY\n"); return; } printf("\n"); for(;front!=NULL;front=front->next) printf(" %d",front->data); //output printf("\n"); return; } //end of display
the_stack_data/956531.c
#include <stdio.h> #include <stdlib.h> int main() { //variable declaration char name[100]; int n1,n2,sum,product,diff; float quot; printf("simple calculator!/n"); //input printf("enter your name;"); gets(name); printf("enter two integers;"); scanf("%d,%d",&n1,&n2); //computations sum=n1+n2; diff=n1-n2; product=n1*n2; quot=(float)n1/n2; //output printf("hey %s, here are the results;/n",name); printf("%d+%d/n",n1,n2,sum); printf("%d-%d/n",n1,n2,diff); printf("%d*%d/n",n1,n2,product); printf("%d/%d=%f/n",n1,n2,quot); return 0; }
the_stack_data/225371.c
#include <assert.h> int array [4] = {0, 1, 2, 3}; int f00 (int *pointer) { int i; for (i = 0; i < *pointer; ++i) { assert(i < 10); } return 0; } int main (void) { f00(&(array[0])); return 0; }
the_stack_data/150139503.c
// Program to write to a condition one line at a time to index.js file with C. The file reached 100 MB exactly with the maximum count of 2,226,043. #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int i; FILE *fp; fp = fopen("index.js","w"); fprintf(fp,"function isEven(number) {\n"); fprintf(fp,"\t if(number === %d) return false;\n",1); for(i=2;i<=2226043;i++) { if(i%2==0) { fprintf(fp,"\t else if(number === %d) return true;\n",i); } else { fprintf(fp,"\t else if(number === %d) return false;\n",i); } } fprintf(fp,"\t else return true;\n"); fprintf(fp,"} \nmodule.exports = isEven;"); fclose(fp); }
the_stack_data/57949389.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> //#define MAX_SYMBOLS 255 #define MAX_SYMBOLS 255 #define MAX_LEN 20 struct tnode { struct tnode* left; /*used when in tree*/ struct tnode*right; /*used when in tree*/ struct tnode*parent;/*used when in tree*/ struct tnode* next; /*used when in list*/ float freq; int isleaf; char symbol; }; /*global variables*/ char code[MAX_SYMBOLS][MAX_LEN]; struct tnode* root=NULL; /*tree of symbols*/ struct tnode* qhead=NULL; /*list of current symbols*/ struct cnode* chead=NULL;/*list of code*/ /* @function talloc @desc allocates new node */ struct tnode* talloc(int symbol,float freq) { struct tnode* p=(struct tnode*)malloc(sizeof(struct tnode)); if(p!=NULL) { p->left=p->right=p->parent=p->next=NULL; p->symbol=symbol; p->freq=freq; p->isleaf=1; } return p; } /* @function display_tnode_list @desc displays the list of tnodes during code construction */ void pq_display(struct tnode* head) { struct tnode* p=NULL; printf("list:"); for(p=head;p!=NULL;p=p->next) { printf("(%c,%f) ",p->symbol,p->freq); } printf("\n"); } /* * parse_file function. * * desc:: * This function takes a filepointer as input, and an float pointer. * The function will generate frequency array information for each symbol. */ void parse_file ( FILE *infp, float *freqp ) { unsigned long uniq_cnt = 0; unsigned long scnt[MAX_SYMBOLS]; char c; //Initialize array to 0 memset(scnt,0,sizeof(scnt)); //Keep track of occurance per symbol. //Keep track of totals while ( (c = fgetc(infp)) != EOF ) { scnt[c] += 1; uniq_cnt++; printf("Found %c, %lu times\n",c,scnt[c-'a']); } for(int i=0; i<MAX_SYMBOLS; i++) *(freqp+i) = ((float) scnt[i])/uniq_cnt; } /* @function pq_insert @desc inserts an element into the priority queue NOTE: makes use of global variable qhead */ void pq_insert(struct tnode* p) { struct tnode* curr=NULL; struct tnode* prev=NULL; printf("inserting:%c,%f\n",p->symbol,p->freq); if(qhead==NULL) { //First element added. qhead=p; } else { for(curr=qhead; curr!=NULL; curr=curr->next) { if( curr->freq > p->freq ) { //We've gone too far, insert it at previous position. //Prevous could be NULL, // If !NULL // Insert p between previous and current. // else // Insert p at root, followed by curr. if(prev) { prev->next = p; p->next=curr; return; } else { qhead = p; p->next = curr; return; } } prev = curr; } //Searched all elements, and no insertion was done, //insert at end prev->next = p; } } /* @function pq_pop @desc removes the first element NOTE: makes use of global variable qhead */ struct tnode* pq_pop() { struct tnode* p=NULL; if(qhead) { p = qhead; qhead = qhead->next; printf("popped:%c,%f\n",p->symbol,p->freq); } return p; } /* @function build_code @desc generates the string codes given the tree NOTE: makes use of the global variable root */ void generate_code(struct tnode* root,int depth) { char symbol; int len; /*length of code*/ struct tnode *cur = NULL; struct tnode *prev = root; if(root->isleaf) { symbol=root->symbol; len =depth; if(depth > MAX_LEN) { printf("Too deep. Limit is %d",MAX_LEN); exit(1); } /*start backwards*/ code[symbol][len]=0; //Search backwards, and stop when parent == NULL // When parrent == NULL, then we're at the top of the tree. for(cur=root->parent; cur != NULL; cur=cur->parent) { len--; if(prev == cur->right) code[symbol][len] = '1'; else if ( prev == cur->left) code[symbol][len] = '0'; else exit(1); //Keep track of previous prev=cur; } printf("built code:%c,%s\n",symbol,code[symbol]); } else { generate_code(root->left,depth+1); generate_code(root->right,depth+1); } } /* @func dump_code @desc output code file */ void dump_code(FILE* fp) { int i=0; for(i=0;i<MAX_SYMBOLS;i++) { if(code[i][0]) /*non empty*/ fprintf(fp,"<tag>%c</tag>,%s\n",i,code[i]); } } void encode_fp(FILE *fin, FILE *fout) { char c; while ( (c = fgetc(fin)) != EOF ) { fprintf(fout,"%s",code[c]); } } /* @func encode @desc outputs compressed stream */ void encode(char* str,FILE* fout) { while(*str) { fprintf(fout,"%s",code[*str]); str++; } } /* * @function cleanall */ void cleanall(struct tnode *root) { if(root->isleaf) { free(root); } else { cleanall(root->right); cleanall(root->left); //All children are not clean, clean parent free(root); } } /* @function main */ void usage(void) { printf("Usage for encoder::\ encode -i FILENAME -o FILENAME\ -i FILENAME, input filename for txt file to compress\ -o FILENAME, output filename for txt file to compress\ "); } int main(int argc, char *argv[]) { /*test pq*/ struct tnode* p=NULL; struct tnode* lc,*rc; float freq[MAX_SYMBOLS]; int i=0; int opt; int ucnt=0; const char *CODE_FILE = "code.txt"; const char *IN_FILE; const char *OUT_FILE; FILE *fin=NULL; FILE* fout=NULL; /*zero out code*/ memset(code,0,sizeof(code)); memset(freq,0,sizeof(freq)); //Parse commandline args to get input file from commandline. while( ( opt = (getopt(argc,argv,"i:o:h")) ) != -1 ) { switch(opt) { case 'h': usage(); break; case 'i': IN_FILE = optarg; printf("Filename:: %s\n",IN_FILE); break; case 'o': OUT_FILE = optarg; printf("Compressed file:: %s\n",OUT_FILE); break; } } if(!IN_FILE) { printf("Error! Input file must be provided by user.\n"); usage(); exit(1); } /* fin = fopen(IN_FILE,'r'); */ /* fout = fopen(OUT_FILE,'r'); */ fin = fopen(IN_FILE,"r"); //populate freq parse_file(fin,freq); fclose(fin); qhead=NULL; /*initialize with freq*/ for(i=0;i<MAX_SYMBOLS;i++) { if(freq[i] != 0) { pq_insert(talloc(i,freq[i])); ucnt++; } } /*build tree*/ for(i=0;i<ucnt-1;i++) { lc=pq_pop(); rc=pq_pop(); /*create parent*/ p=talloc(0,lc->freq+rc->freq); /*set parent link*/ lc->parent=rc->parent=p; /*set child link*/ p->right=rc; p->left=lc; /*make it non-leaf*/ p->isleaf=0; /*add the new node to the queue*/ pq_insert(p); } /*get root*/ root=pq_pop(); if(root==NULL) { printf("Error! tree could not be created\n"); exit(1); } generate_code(root,0); /*output code*/ puts("code:"); fout=fopen(CODE_FILE,"w"); dump_code(stdout); dump_code(fout); fclose(fout); /*encode a sample string*/ fout=fopen(OUT_FILE,"w"); fin=fopen(IN_FILE,"r"); encode_fp(fin,fout); fclose(fout); getchar(); cleanall(root); return 0; }
the_stack_data/919835.c
/* Factorial Write a program that prompts the user for an integer n (n>0) and prints the factorial of the number on the screen. For example, the factorial of n is designated n!, which means the number calculated as follows: 1*2*3...*n */ #include<stdio.h> int main() { int c,n,fact=1; printf("Enter an integer: "); scanf("%d",&n); for(c=1; c<=n ; c++){ fact = fact * c; } printf("The factorial of %d is %d",n,fact); return 0; }
the_stack_data/85229.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/shm.h> //Needed for shared memory #include <unistd.h> #include <time.h> #include <sys/types.h> // Needed for system defined identifiers. #include <netinet/in.h> // Needed for internet address structure. #include <sys/socket.h> // Needed for socket(), bind(), etc... #include <arpa/inet.h> // Needed for inet_ntoa() #include <fcntl.h> // Needed for sockets stuff #include <netdb.h> // Needed for sockets stuff #include <pthread.h> //#define PORT_NUM 2016 // Port number used #define IP_ADDR "127.0.0.1" // IP address of server1 (*** HARDWIRED ***) #define IP_PORT 2016 #define BACKLOG 10 #define MAX_THREADS 10 pthread_t threads[MAX_THREADS]; // Estructura de datos del sensor typedef struct { unsigned char ID; /* Identificación de sensor 0 – 255 */ int temperatura; /* Valor de temperatura multiplicado por 10 */ int RH; /* Valor de Humedad Relativa Ambiente */ } dato_t; // Estructura interna del sensor typedef struct { dato_t dato; time_t seconds; } datos_t; char *parser(char *buf, const char *delimiter) { char *path = NULL; //dirección de retorno if(strtok(buf, delimiter)) //agarro una cadena y limita { path = strtok(NULL, delimiter); if(path) { path = strdup(path); // Copia el String } } return(path); } void *thr_request(int *clientId) { int client = *clientId; char strBuffer[3000]; int cont = recv(client, strBuffer, sizeof(strBuffer), 0); strBuffer[cont] = '\0'; //printf("Pidiendo: %s (%d)\n",strBuffer, cont); char *strRequest = parser(strBuffer, " "); strcpy(strBuffer, "HTTP/1.1 200 OK\nConnection: Closed\nContent-Type: text/html\n\n"); //Envía Protocolo TCP send(client, strBuffer, (strlen(strBuffer) + 1), 0); //printf("%s\n", strRequest ); // char line[256]; //char sensores char strTable[2048]; // if( strRequest && strcmp(strRequest, "/") == 0 ) //pagina de inicio { datos_t sensores[256]; FILE *file = fopen("datos.txt", "r"); //abre el archivo de los datos while (fgets(line, sizeof(line), file)) { //printf("%s", line); //Armo cuadro char *timestr = strtok(line, ","); if( !timestr ) continue; //si no hay mas cosas en la linea char *idstr = strtok(NULL, "," ); if( !idstr ) continue; char *tempstr = strtok(NULL, ","); if( !tempstr ) continue; char *rhstr = strtok(NULL, "," ); if( !rhstr ) continue; int id = atoi(idstr); sensores[id].dato.ID = id; sensores[id].seconds = strtoul(timestr, NULL, 10); sensores[id].dato.temperatura = atoi(tempstr); sensores[id].dato.RH = atoi(rhstr); //printf("%s %s\n", timestr, idstr ); } sprintf(strTable, "<table border=1 style=width:100%%><tr><th>ID</th><th>Temp</th><th>RH</th><th>Time</th></tr>"); for( int i = 0; i < 256; i++ ) { if( sensores[i].seconds != 0 ) { char timBuff[26]; struct tm* tm_info; tm_info = localtime(&sensores[i].seconds); strftime(timBuff, 26, "%Y-%m-%d %H:%M:%S", tm_info); sprintf(strTable, "%s<tr><td><a href=\"sensor/%i\">%i</a></td><td>%.1f</td><td>%i</td><td>%s</td></tr>", strTable, i, i, sensores[i].dato.temperatura / 10.0f, sensores[i].dato.RH, timBuff ); //printf("Sensor: %i %lu\n", i, sensores[i].seconds ); } } sprintf(strTable, "%s</table>", strTable); sprintf(strBuffer, "<html><head><title>Home</title></head><body>%s<div><a href=\"/\">Home</a> <a href=\"/prom\">Prom 1Hora</a> <a href=\"/prom/6\">Prom 6Horas</a> <a href=\"/prom/12\">Prom 12Horas</a> <a href=\"/prom/24\">Prom 24Hora</a></div></body></html>", strTable); send(client, strBuffer, (strlen(strBuffer) + 1), 0); } else if( strRequest ) { //char *path = parser(strRequest, "/" ); char *opc = strtok(strRequest, "/" ); printf("%s\n", opc ); if( strcmp(opc, "sensor") == 0 ) { char *path = strtok(NULL, "/" ); int sensorId = 0; if( path ) sensorId = atoi(path); int tempMax = -550; int tempMin = 1399; int tempAct; int rhMax = 0; int rhMin = 100; int rhAct; struct { int cant; long long sumTemp; long long sumRH; } prom[4]; for( int j = 0; j < 4 ; j++ ) { prom[j].cant = 0; prom[j].sumTemp = 0; prom[j].sumRH = 0; } //printf("%s\n", path); size_t horaactual = time(NULL); FILE *file = fopen("datos.txt", "r"); while (fgets(line, sizeof(line), file)) { //printf("%s", line); char *timestr = strtok(line, ","); if( !timestr ) continue; char *idstr = strtok(NULL, "," ); if( !idstr ) continue; char *tempstr = strtok(NULL, ","); if( !tempstr ) continue; char *rhstr = strtok(NULL, "," ); if( !rhstr ) continue; int id = atoi(idstr); size_t hora = strtoul(timestr, NULL, 10); int temp = atoi(tempstr); int rh = atoi(rhstr); if( id == sensorId ) { tempAct = temp; rhAct = rh; if( temp > tempMax ) { tempMax = temp; } if( temp < tempMin ) { tempMin = temp; } if( rh > rhMax ) { rhMax = rh; } if( rh < rhMin ) { rhMin = rh; } if( (horaactual - hora) <= 3600 ) { prom[0].cant++; prom[0].sumTemp += temp; prom[0].sumRH += rh; } if( (horaactual - hora) <= 21600 ) { prom[1].cant++; prom[1].sumTemp += temp; prom[1].sumRH += rh; } if( (horaactual - hora) <= 43200 ) { prom[2].cant++; prom[2].sumTemp += temp; prom[2].sumRH += rh; } if( (horaactual - hora) <= 86400 ) { prom[3].cant++; prom[3].sumTemp += temp; prom[3].sumRH += rh; } } } fclose(file); sprintf(strTable, "<table border=1 style=width:100%%><tr><th>Dato:</th><th>Temp</th><th>RH</th></tr>"); sprintf(strTable, "%s<tr><td>Actual</td><td>%.1f</td><td>%i</td></tr>", strTable, tempAct/10.0f, rhAct ); sprintf(strTable, "%s<tr><td>Minima</td><td>%.1f</td><td>%i</td></tr>", strTable, tempMin/10.0f, rhMin ); sprintf(strTable, "%s<tr><td>Maxima</td><td>%.1f</td><td>%i</td></tr>", strTable, tempMax/10.0f, rhMax ); sprintf(strTable, "%s<tr><td>Ultima Hora</td><td>%.1f</td><td>%lli</td></tr>", strTable, (prom[0].sumTemp/(float)prom[0].cant) /10.0f, prom[0].sumRH/prom[0].cant ); sprintf(strTable, "%s<tr><td>Ultimas 6 Horas</td><td>%.1f</td><td>%lli</td></tr>", strTable, (prom[1].sumTemp/(float)prom[1].cant) /10.0f, prom[1].sumRH/prom[1].cant ); sprintf(strTable, "%s<tr><td>Ultimas 12 Horas</td><td>%.1f</td><td>%lli</td></tr>", strTable, (prom[2].sumTemp/(float)prom[2].cant) /10.0f, prom[2].sumRH/prom[2].cant ); sprintf(strTable, "%s<tr><td>Ultimas 24 Horas</td><td>%.1f</td><td>%lli</td></tr>", strTable, (prom[3].sumTemp/(float)prom[3].cant) /10.0f, prom[3].sumRH/prom[3].cant ); sprintf(strTable, "%s</table>", strTable); sprintf(strBuffer, "<html><head><title>Datos Sensor: %i</title></head><body>%s<div><a href=\"/\">Home</a> <a href=\"/prom\">Prom 1Hora</a> <a href=\"/prom/6\">Prom 6Horas</a> <a href=\"/prom/12\">Prom 12Horas</a> <a href=\"/prom/24\">Prom 24Hora</a></div></body></html>", sensorId, strTable); send(client, strBuffer, (strlen(strBuffer) + 1), 0); } else if( strcmp(opc, "prom") == 0 ) { char *path = strtok(NULL, "/" ); int promHora = 1; if( path ) promHora = atoi(path); promHora = promHora * 3600; size_t horaactual = time(NULL); struct { int cant; long long sumTemp; long long sumRH; } prom[256]; for( int j = 0; j < 256 ; j++ ) { prom[j].cant = 0; prom[j].sumTemp = 0; prom[j].sumRH = 0; } FILE *file = fopen("datos.txt", "r"); while (fgets(line, sizeof(line), file)) { //printf("%s", line); char *timestr = strtok(line, ","); if( !timestr ) continue; char *idstr = strtok(NULL, "," ); if( !idstr ) continue; char *tempstr = strtok(NULL, ","); if( !tempstr ) continue; char *rhstr = strtok(NULL, "," ); if( !rhstr ) continue; int id = atoi(idstr); size_t hora = strtoul(timestr, NULL, 10); int temp = atoi(tempstr); int rh = atoi(rhstr); if( (horaactual - hora) <= promHora ) { prom[id].cant++; prom[id].sumTemp += temp; prom[id].sumRH += rh; } } fclose(file); sprintf(strTable, "<table border=1 style=width:100%%><tr><th>ID</th><th>Temp</th><th>RH</th></tr>"); for( int i = 0; i < 256; i++ ) { if( prom[i].cant != 0 ) { sprintf(strTable, "%s<tr><td><a href=\"/sensor/%i\">%i</a></td><td>%.1f</td><td>%lli</td></tr>", strTable, i, i, prom[i].sumTemp/(float)prom[i].cant / 10.0f, prom[i].sumRH/prom[i].cant ); } } sprintf(strTable, "%s</table>", strTable); sprintf(strBuffer, "<html><head><title>Promedios de %i Horas</title></head><body>%s<div><a href=\"/\">Home</a> <a href=\"/prom\">Prom 1Hora</a> <a href=\"/prom/6\">Prom 6Horas</a> <a href=\"/prom/12\">Prom 12Horas</a> <a href=\"/prom/24\">Prom 24Hora</a></div></body></html>", promHora/3600, strTable); send(client, strBuffer, (strlen(strBuffer) + 1), 0); } } if( strRequest ) { strcpy(strBuffer, "\r\n\r\n"); send(client, strBuffer, (strlen(strBuffer) + 1), 0); } free(strRequest); // Prevent Memory Leek!! close(client); return NULL; } void *thr_filewrite( void *nada) { // // Memoria compartida // key_t key; // Variables para la Llave int idMemoria; // Identificador de la memoria datos_t *memoria; // bloque de memoria compartida // Creamos la llave a partir de un archivo existente. printf("Creando Llave\n"); key = ftok("/bin/bash", '5'); // Creamos el identificador de memoria y le asignamos la cantidad a alocar y // los permisos necesarios de lectura/escritura/ejecucion -- Borramos el IPC_CREAT printf("Creando Identificador...\n"); idMemoria = shmget(key, sizeof(datos_t) * 129, 0777 ); // Alocamos la memoria printf("Alocando Memoria Compartida...\n"); memoria = shmat( idMemoria, NULL, 0 ); //Valores para saber si se completo el buffer time_t seconds1 = memoria[63].seconds; time_t seconds2 = memoria[127].seconds; while(1) { //Si es distinta al valor que tomamos significa que llenó la primer parte del buffer if( memoria[63].seconds != seconds1 ) { FILE *file = fopen("datos.txt", "a"); //abro el archivo y arranco desde el final del archivo printf("Cambio de Buffer 2\n"); //Escribo valores del buffer en el archivo for( int i = 0; i < 64; i++ ) { fprintf(file, "%lu,%i,%d,%d\n", memoria[i].seconds, memoria[i].dato.ID, memoria[i].dato.temperatura, memoria[i].dato.RH); } fclose(file); //Cierro para guardar en disco seconds1 = memoria[63].seconds; //Vuelvo a actualizar el valor 64 del buffer } //Hacemos lo mismo que para la primer parte del buffer else if( memoria[127].seconds != seconds2 ) { FILE *file = fopen("datos.txt", "a"); printf("Cambio de Buffer 1\n"); for( int i = 64; i < 128; i++ ) { fprintf(file, "%lu,%i,%d,%d\n", memoria[i].seconds, memoria[i].dato.ID, memoria[i].dato.temperatura, memoria[i].dato.RH); } fclose(file); seconds2 = memoria[127].seconds; } sleep( 1 ); } } void main() { int i = 0; unsigned int server_s; // Descriptor de socket struct sockaddr_in server_addr; // Direccion del servidor struct sockaddr_in client_addr; // Direccion del cliente server_s = socket(AF_INET, SOCK_STREAM, 0); //crea el socket server_addr.sin_family = AF_INET; // Address family to use server_addr.sin_port = htons(IP_PORT); // Port number to use server_addr.sin_addr.s_addr = htonl(INADDR_ANY); // Listen on any IP address memset(&(server_addr.sin_zero),'\0',8); bind(server_s, (struct sockaddr *)&server_addr, sizeof(server_addr)); //Abrir puerto disponible listen(server_s,BACKLOG); //Escucho el puerto int sin_size = sizeof(struct sockaddr_in); pthread_t asd; pthread_create(&asd, NULL, (void *)&thr_filewrite,(void *)0); //Crea el hilo para guardar datos a un archivo while(1) { printf("Servidor esperando conexion\n\n"); int clientId = accept(server_s,(struct sockaddr *)&client_addr, &sin_size ); //Nueva conexion printf("%d New Request...\n", i); pthread_create(&threads[i], NULL, (void *)&thr_request,(void *)&clientId); //crea hilo que maneja la conexion i++; if( i >= MAX_THREADS ) //seguridad { i = 0; } } close(server_s); }
the_stack_data/14199737.c
#include <stdio.h> int f[110][110][110]; int x[4]; int max(int a,int b) {return a>b?a:b; } int main(){ for (int i=0; i<=100; ++i) for (int j=0; j<=100-i; ++j) for (int k=0; k<=100-i-j; ++k) { if (f[i][j][k] >= f[i+4][j][k]) f[i+4][j][k] = f[i][j][k] + 1; if (f[i][j][k] >= f[i][j+2][k]) f[i][j+2][k] = f[i][j][k] + 1; if (f[i][j][k] >= f[i+4][j][k]) f[i+4][j][k] = f[i][j][k] + 1; if (f[i][j][k] >= f[i+1][j][k+1]) f[i+1][j][k+1] = f[i][j][k] + 1; if (f[i][j][k] >= f[i+4][j][k]) f[i+4][j][k] = f[i][j][k] + 1; if (f[i][j][k] >= f[i+2][j+1][k]) f[i+2][j+1][k] = f[i][j][k] + 1; if (f[i][j][k] >= f[i][j+1][k+2]) f[i][j+1][k+2] = f[i][j][k] + 1; } int t; scanf("%d",&t); for (int i=1; i<=t; ++i) { int n,d; scanf("%d%d",&n,&d); x[0]=x[1]=x[2]=x[3]=0; for(int j=1; j<=n; ++j) { int p; scanf("%d",&p); x[p%d]++; } printf("Case #%d: ",i); int ans=0; if (d==2) ans = x[0]+(x[1]+1)/2; else if (d==3) { ans = x[0]; if (x[1]>=x[2]) ans += x[2] + (x[1]-x[2]+2)/3; else ans += x[1] + (x[2]-x[1]+2)/3; } else { if (x[1] > 0) ans = 1 + f[x[1]-1][x[2]][x[3]]; if (x[2] > 0) ans = max(ans, 1 + f[x[1]-1][x[2]][x[3]]); if (x[3] > 0) ans = 1 + max(ans, f[x[1]][x[2]][x[3]-1]); ans += x[0]; } printf("%d\n",ans); } }
the_stack_data/106647.c
#include <stdio.h> #include <string.h> #define SIZE 80 #define LIM 100 void remove_whitespace(char *); int main(void) { char input[LIM][SIZE]; int ct=0; int index=0; printf("Enter up to %d lines: \n", LIM); while(ct<LIM && gets(input[ct])!=0 && input[ct][0]!='\0' && input[ct][0]!=EOF) ct++; printf("Input end\n"); for(index=0; index<ct; index++) { remove_whitespace(input[index]); puts(input[index]); } return 0; } void remove_whitespace(char * ptr) { char * find; while(find=strchr(ptr,32)) { while(*find!='\0') { *find=*(find+1); find++; } } }
the_stack_data/121101.c
#include "stdio.h" long long x = 1; long long y = 2; long long z = 3; long long r; int main() { if (x > y) { if (x > z) r = x; else r = z; } else { if (y > z) r = y; else r = z; } printf("%d\n", r); return 0; }
the_stack_data/9512846.c
/* program to extract individual email messages from a Thunderbird */ /* message-store, found at various locations therein. */ /* */ /* THIS SOFTWARE IS PRESENTED "AS-IS", AND MAKES NO CLAIM OF */ /* ACCURATE OPERATION, APPLICABILITY TO YOUR NEEDS, SUCCESSFUL */ /* OUTCOME, SAFE MANIPULATION OF DATA. -> USE AT YOUR OWN RISK <- */ /* */ /* The author is in no way responsible for what happens when you */ /* use this program or apply its concepts. */ /* */ /* FULL DOCUMENTATION IS CONTAINED IN THE 'README' file */ /* */ /* June 2017 R. Magnuson [email protected] */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> #define CMDSTRLEN 256 #define PROCGOOD 0 #define PROCERROR -1 #define OUTEXTEN ".eml" #define GREPSENT "grep -b \"From -\" \"Sent Messages\" > " #define STAGE2 "/tmp/stage2" #define STAGE3 "/tmp/stage3" int main(int, char *[]); int create_grep_out(void); int process_stage2(void); int gen_emails(void); int main(int argc, char *argv[]) { printf("\nProgram begin.\n\n"); create_grep_out(); process_stage2(); gen_emails(); printf("Done.\n\n"); return(0); } int create_grep_out() { char cmdstr[CMDSTRLEN]; int retval; sprintf(cmdstr, "%s%s.sent", GREPSENT, STAGE2); printf("\nExecuting \"%s\"\n", cmdstr); retval = system(cmdstr); return(retval); } int process_stage2() { char *cptr; char i_filestr[CMDSTRLEN]; char o_filestr[CMDSTRLEN]; char instr[128]; int retval; unsigned int q_strfound; FILE *ifp; FILE *ofp; sprintf(i_filestr, "%s.sent", STAGE2); sprintf(o_filestr, "%s.sent", STAGE3); printf("\nFiltering \"%s\" into \"%s\"\n\n", i_filestr, o_filestr); ifp = fopen(i_filestr, "r"); ofp = fopen(o_filestr, "w"); if (ifp == (FILE *) NULL) { printf("\nFile \"%s\" open for read, error: %s\n\n", i_filestr, strerror(errno)); return(-1); } if (ofp == (FILE *) NULL) { printf("\nFile \"%s\" open for write, error: %s\n\n", o_filestr, strerror(errno)); return(-1); } q_strfound = 0; while ((fgets(instr, 128, ifp)) != (char *) NULL) { if (ferror(ifp)) puts("I/O error when reading"); else if (feof(ifp) != 0) break; cptr = strchr(instr, (int) ':'); *cptr = (char) '\0'; fprintf(ofp, "%s\n", instr); q_strfound++; } fclose(ifp); fflush(ofp); fclose(ofp); printf("Lines processed: %u\n\n", q_strfound); return(0); } int gen_emails() { char *cptr; char in_fname[CMDSTRLEN]; char out_fname[CMDSTRLEN]; char data_fname[CMDSTRLEN]; char instr[128]; int ich; int retval; int filecntr; unsigned int endloc; unsigned int curloc; FILE *ifp; FILE *datainfp; FILE *emloutfp; sprintf(in_fname, "%s.sent", STAGE3); strcpy(data_fname, "Sent\x20Messages"); /* filename has embedded space */ printf("\nBegin email files extraction\n\n"); ifp = fopen(in_fname, "r"); /* open file of byte offsets */ if (ifp == (FILE *) NULL) { printf("\nFile \"%s\" open for read, error: %s\n\n", in_fname, strerror(errno)); fclose(ifp); return(-1); } fgets(instr, 128, ifp); /* all stage3 files will have first line with "0", step past it */ curloc = 0; datainfp = fopen(data_fname, "r"); /* open big data file to read through, byte-at-a-time */ if (datainfp == (FILE *) NULL) { printf("\nFile %s open for read, error: %s\n\n", data_fname, strerror(errno)); fclose(ifp); return(-2); } filecntr = 1; while ((fgets(instr, 128, ifp)) != (char *) NULL) { if (ferror(ifp)) puts("I/O error when reading"); else if (feof(ifp) != 0) break; cptr = strchr(instr, (int) '\n'); *cptr = (char) '\0'; endloc = (unsigned int) atol(instr); /* scan through the chosen one, and write out bytes to multiple .eml files */ sprintf(out_fname, "sentmsg%d%s", filecntr, OUTEXTEN); emloutfp = fopen(out_fname, "w"); if (emloutfp == (FILE *) NULL) { printf("\nFile \"%s\" open for write, error: %s\n\n", out_fname, strerror(errno)); fclose(ifp); fclose(datainfp); return(-3); } while ((ich = fgetc(datainfp)) != EOF) { if (ferror(datainfp)) puts("I/O error when reading"); else if (feof(datainfp) != 0) break; if (ich != 0x0d) fputc(ich, emloutfp); if (++curloc == endloc - 1) break; } fflush(emloutfp); fclose(emloutfp); filecntr++; } /* one more file to be written out, but we don't know its endloc, because that endloc = EOF */ sprintf(out_fname, "sentmsg%d%s", filecntr, OUTEXTEN); emloutfp = fopen(out_fname, "w"); if (emloutfp == (FILE *) NULL) { printf("\nFile \"%s\" open for write, error: %s\n\n", out_fname, strerror(errno)); fclose(ifp); fclose(datainfp); return(-4); } while ((ich = fgetc(datainfp)) != EOF) { if (ferror(datainfp)) puts("I/O error when reading"); else if (feof(datainfp) != 0) break; if (ich != 0x0d) fputc(ich, emloutfp); } fflush(emloutfp); fclose(emloutfp); fclose(datainfp); fclose(ifp); printf("\nCreated %d email files\n\n", filecntr); return(0); }
the_stack_data/120289.c
// RUN: rm -rf %t* // RUN: 3c -base-dir=%S -alltypes -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s // RUN: 3c -base-dir=%S -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s // RUN: 3c -base-dir=%S -addcr %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null - // RUN: 3c -base-dir=%S -alltypes -output-dir=%t.checked %s -- // RUN: 3c -base-dir=%t.checked -alltypes %t.checked/fptrarrstructprotosafe.c -- | diff %t.checked/fptrarrstructprotosafe.c - /******************************************************************************/ /*This file tests three functions: two callers bar and foo, and a callee sus*/ /*In particular, this file tests: using a function pointer and an array as fields of a struct that interact with each other*/ /*For robustness, this test is identical to fptrarrstructsafe.c except in that a prototype for sus is available, and is called by foo and bar, while the definition for sus appears below them*/ /*In this test, foo, bar, and sus will all treat their return values safely*/ /******************************************************************************/ #include <stddef.h> #include <stdlib.h> #include <stdio.h> #include <string.h> struct general { int data; struct general *next; //CHECK: _Ptr<struct general> next; }; struct warr { int data1[5]; //CHECK_NOALL: int data1[5]; //CHECK_ALL: int data1 _Checked[5]; char *name; //CHECK: _Ptr<char> name; }; struct fptrarr { int *values; //CHECK_NOALL: int *values; //CHECK_ALL: _Array_ptr<int> values : count(5); char *name; //CHECK: char *name; int (*mapper)(int); //CHECK: _Ptr<int (int)> mapper; }; struct fptr { int *value; //CHECK: _Ptr<int> value; int (*func)(int); //CHECK: _Ptr<int (int)> func; }; struct arrfptr { int args[5]; //CHECK_NOALL: int args[5]; //CHECK_ALL: int args _Checked[5]; int (*funcs[5])(int); //CHECK_NOALL: int (*funcs[5])(int); //CHECK_ALL: _Ptr<int (int)> funcs _Checked[5]; }; int add1(int x) { //CHECK: int add1(int x) _Checked { return x + 1; } int sub1(int x) { //CHECK: int sub1(int x) _Checked { return x - 1; } int fact(int n) { //CHECK: int fact(int n) _Checked { if (n == 0) { return 1; } return n * fact(n - 1); } int fib(int n) { //CHECK: int fib(int n) _Checked { if (n == 0) { return 0; } if (n == 1) { return 1; } return fib(n - 1) + fib(n - 2); } int zerohuh(int n) { //CHECK: int zerohuh(int n) _Checked { return !n; } int *mul2(int *x) { //CHECK: _Ptr<int> mul2(_Ptr<int> x) _Checked { *x *= 2; return x; } struct fptrarr *sus(struct fptrarr *, struct fptrarr *); //CHECK: _Ptr<struct fptrarr> sus(struct fptrarr *x : itype(_Ptr<struct fptrarr>), _Ptr<struct fptrarr> y); struct fptrarr *foo() { //CHECK: _Ptr<struct fptrarr> foo(void) { char name[20]; struct fptrarr *x = malloc(sizeof(struct fptrarr)); //CHECK: _Ptr<struct fptrarr> x = malloc<struct fptrarr>(sizeof(struct fptrarr)); struct fptrarr *y = malloc(sizeof(struct fptrarr)); //CHECK: _Ptr<struct fptrarr> y = malloc<struct fptrarr>(sizeof(struct fptrarr)); int *yvals = calloc(5, sizeof(int)); //CHECK_NOALL: int *yvals = calloc<int>(5, sizeof(int)); //CHECK_ALL: _Array_ptr<int> yvals : count(5) = calloc<int>(5, sizeof(int)); int i; for (i = 0; i < 5; i++) { //CHECK_NOALL: for (i = 0; i < 5; i++) { //CHECK_ALL: for (i = 0; i < 5; i++) _Checked { yvals[i] = i + 1; } y->values = yvals; y->name = name; y->mapper = NULL; strcpy(y->name, "Example"); struct fptrarr *z = sus(x, y); //CHECK: _Ptr<struct fptrarr> z = sus(x, y); return z; } struct fptrarr *bar() { //CHECK: _Ptr<struct fptrarr> bar(void) { char name[20]; struct fptrarr *x = malloc(sizeof(struct fptrarr)); //CHECK: _Ptr<struct fptrarr> x = malloc<struct fptrarr>(sizeof(struct fptrarr)); struct fptrarr *y = malloc(sizeof(struct fptrarr)); //CHECK: _Ptr<struct fptrarr> y = malloc<struct fptrarr>(sizeof(struct fptrarr)); int *yvals = calloc(5, sizeof(int)); //CHECK_NOALL: int *yvals = calloc<int>(5, sizeof(int)); //CHECK_ALL: _Array_ptr<int> yvals : count(5) = calloc<int>(5, sizeof(int)); int i; for (i = 0; i < 5; i++) { //CHECK_NOALL: for (i = 0; i < 5; i++) { //CHECK_ALL: for (i = 0; i < 5; i++) _Checked { yvals[i] = i + 1; } y->values = yvals; y->name = name; y->mapper = NULL; strcpy(y->name, "Example"); struct fptrarr *z = sus(x, y); //CHECK: _Ptr<struct fptrarr> z = sus(x, y); return z; } struct fptrarr *sus(struct fptrarr *x, struct fptrarr *y) { //CHECK: _Ptr<struct fptrarr> sus(struct fptrarr *x : itype(_Ptr<struct fptrarr>), _Ptr<struct fptrarr> y) { x = (struct fptrarr *)5; //CHECK: x = (struct fptrarr *)5; char name[30]; struct fptrarr *z = malloc(sizeof(struct fptrarr)); //CHECK: _Ptr<struct fptrarr> z = malloc<struct fptrarr>(sizeof(struct fptrarr)); z->values = y->values; z->name = strcpy(name, "Hello World"); z->mapper = fact; int i; for (i = 0; i < 5; i++) { z->values[i] = z->mapper(z->values[i]); } return z; }
the_stack_data/76699737.c
/* * name: scheduler * autor: Daniel Franze * * source 1: http://stackoverflow.com/questions/17877368/getopt-passing-string-parameter-for-argument * source 2: http://www.jbox.dk/sanos/source/include/pthread.h.html * source 3: http://stackoverflow.com/questions/3219393/stdlib-and-colored-output-in-c * source 4: http://stackoverflow.com/questions/2509679/how-to-generate-a-random-number-from-within-a-range * source 5: http://stackoverflow.com/questions/11573974/write-to-txt-file * source 6: http://stackoverflow.com/questions/6154539/how-can-i-wait-for-any-all-pthreads-to-complete * source 7: http://stackoverflow.com/questions/26900122/c-program-to-print-current-time * source 8: http://stackoverflow.com/questions/3930363/implement-time-delay-in-c * source 9: http://stackoverflow.com/questions/5248915/execution-time-of-c-program */ #include <stdio.h> #include <stdlib.h> #include <getopt.h> #include <string.h> #include <time.h> #include <pthread.h> #include <semaphore.h> #define RED "\x1b[31m" #define GREEN "\x1b[32m" #define YELLOW "\x1b[33m" #define BLUE "\x1b[34m" #define MAGENTA "\x1b[35m" #define CYAN "\x1b[36m" #define RESET "\x1b[0m" struct animal_parameters { int id; char species; // cat = c, dog = d, mouse = m int feeding_counter; // 0 will end the thread int eating_time; int statisfied_time; }; typedef struct animal_parameters animal_params; struct start_parameters { int number_of_cats; int number_of_dogs; int number_of_mice; int time_a_cat_is_statisfied; int time_a_dog_is_statisfied; int time_a_mouse_is_statisfied; int how_many_times_a_cat_wants_to_eat; int how_many_times_a_dog_wants_to_eat; int how_many_times_a_mouse_wants_to_eat; int number_of_food_dishes; int eating_time_interval_lower_boundary; int eating_time_interval_upper_boundary; char *output_file; int verbose_print; }; typedef struct start_parameters start_params; struct statistics_of_species { double cats_min; double cats_max; double cats_avg; double dogs_min; double dogs_max; double dogs_avg; double mice_min; double mice_max; double mice_avg; char *output_file; char cats_values_empty; char dogs_values_empty; char mice_values_empty; }; typedef struct statistics_of_species statistics; // Global variables int finished_animals = 0; char current_species = '0'; char change_species_mode = 'f'; // f = false, t = true int all_food_dishes_area_busy = 'f'; // f = false, t = true // Food dishes int number_of_food_dishes; int current_value_of_food_dishes_semaphore; // No output file, if to many animals exists char write_output_file = 't'; // f = false, t = true // Global statistics statistics stats; // Global mutex and semaphore pthread_mutex_t logger_mutex; pthread_mutex_t finished_animals_mutex; pthread_mutex_t feeding_machine_mutex; pthread_mutex_t statistics_mutex; sem_t food_dishes_semaphore; // Global condition variable pthread_cond_t feeding_machine_cv = PTHREAD_COND_INITIALIZER; void printHelp() { printf(YELLOW"****************************************************************************\n"); printf("* HELP *\n"); printf("****************************************************************************\n"); printf("* --cn #arg: number of cats (Default 6) *\n"); printf("* --dn #arg: number of dogs (Default 4) *\n"); printf("* --mn #arg: number of mice (Default 2) *\n"); printf("* --ct #arg: time a cat is satisfied (Default 15) *\n"); printf("* --dt #arg: time a dog is satisfied (Default 10) *\n"); printf("* --mt #arg: time a mouse is satisfied (Default 1) *\n"); printf("* --ce #arg: how many times a cat wants to eat (Default 5) *\n"); printf("* --de #arg: how many times a dog wants to eat (Default 5) *\n"); printf("* --me #arg: how many times a mouse wants to eat (Default 5) *\n"); printf("* --dish #arg: number of Food Dishes (Default 2) *\n"); printf("* --e #arg: eating time interval lower boundary (Default 1) *\n"); printf("* --E #arg: eating time interval upper boundary (Default 1) *\n"); printf("* *\n"); printf("* --file #arg: file to flush data into. *\n"); printf("* --v Verbose print Statements *\n"); printf("* --h Help output *\n"); printf("****************************************************************************\n"RESET); exit(0); } void printParams(start_params params) { printf(YELLOW"****************************************************************************\n"); printf("* PARAMS *\n"); printf("****************************************************************************\n"); printf("* Number of cats (Default: 6, Current: %d) \n", params.number_of_cats); printf("* Number of dogs (Default: 4, Current: %d) \n", params.number_of_dogs); printf("* Number of mice (Default: 2, Current: %d) \n", params.number_of_mice); printf("* Time a cat is satisfied (Default: 15, Current: %d) \n", params.time_a_cat_is_statisfied); printf("* Time a dog is satisfied (Default: 10, Current: %d) \n", params.time_a_dog_is_statisfied); printf("* Time a mouse is satisfied (Default: 1, Current: %d) \n", params.time_a_mouse_is_statisfied); printf("* How many times a cat wants to eat (Default: 5, Current: %d) \n", params.how_many_times_a_cat_wants_to_eat); printf("* How many times a dog wants to eat (Default: 5, Current: %d) \n", params.how_many_times_a_dog_wants_to_eat); printf("* How many times a mouse wants to eat (Default: 5, Current: %d) \n", params.how_many_times_a_mouse_wants_to_eat); printf("* Number of Food Dishes (Default: 2, Current: %d) \n", params.number_of_food_dishes); printf("* Eating time interval lower boundary (Default: 1, Current: %d) \n", params.eating_time_interval_lower_boundary); printf("* Eating time interval upper boundary (Default: 1, Current: %d) \n", params.eating_time_interval_upper_boundary); printf("* Output file (Default: output_file.txt, Current: %s) \n", params.output_file); printf("****************************************************************************\n"RESET); } void initMutexAndSemaphore(start_params params) { // Init mutex pthread_mutex_init(&logger_mutex, NULL); pthread_mutex_init(&finished_animals_mutex, NULL); pthread_mutex_init(&feeding_machine_mutex, NULL); pthread_mutex_init(&statistics_mutex, NULL); // Init Semaphore sem_init(&food_dishes_semaphore, 0, (unsigned int)params.number_of_food_dishes); } void destroyMutexAndSemaphore() { // Destroy mutex pthread_mutex_destroy(&logger_mutex); pthread_mutex_destroy(&finished_animals_mutex); pthread_mutex_destroy(&feeding_machine_mutex); pthread_mutex_destroy(&statistics_mutex); // Destroy semaphore sem_destroy(&food_dishes_semaphore); // Destroy condition variable pthread_cond_destroy(&feeding_machine_cv); } int randomTime(int min, int max) { srand((unsigned int)time(NULL)); return rand()%(max-min + 1) + min; } void writeToFile(char *output_file, char *text_for_file) { FILE *f = fopen(output_file, "a"); if (f == NULL) { printf("Error opening file!\n"); exit(1); } fprintf(f, "%s\n", text_for_file); fclose(f); } char* getTime() { time_t current_time; char* c_time_string; current_time = time(NULL); c_time_string = ctime(&current_time); return c_time_string; } void wait(int secs) { unsigned int retTime = (unsigned int)(time(0) + secs); while (time(0) < retTime); } void statisticsOfAllSpeciesHandler(char species, double min, double max, double avg){ pthread_mutex_lock(&statistics_mutex); if((stats.cats_values_empty == 'f') && (species == 'c')){ if(min < stats.cats_min) stats.cats_min = min; if(max > stats.cats_max) stats.cats_max = max; stats.cats_avg = stats.cats_avg + avg; } else if((stats.dogs_values_empty == 'f') && (species == 'd')){ if(min < stats.dogs_min) stats.dogs_min = min; if(max > stats.dogs_max) stats.dogs_max = max; stats.dogs_avg = stats.dogs_avg + avg; } else if((stats.mice_values_empty == 'f') && (species == 'm')){ if(min < stats.mice_min) stats.mice_min = min; if(max > stats.mice_max) stats.mice_max = max; stats.mice_avg = stats.mice_avg + avg; } else if((stats.cats_values_empty == 't') && (species == 'c')){ stats.cats_min = min; stats.cats_max = max; stats.cats_avg = avg; stats.cats_values_empty = 'f'; } else if((stats.dogs_values_empty == 't') && (species == 'd')){ stats.dogs_min = min; stats.dogs_max = max; stats.dogs_avg = avg; stats.dogs_values_empty = 'f'; } else if((stats.mice_values_empty == 't') && (species == 'm')){ stats.mice_min = min; stats.mice_max = max; stats.mice_avg = avg; stats.mice_values_empty = 'f'; } pthread_mutex_unlock(&statistics_mutex); } void printStatisticsOfAllSpecies(start_params params){ pthread_mutex_lock(&statistics_mutex); stats.cats_avg = stats.cats_avg / (double)params.number_of_cats; stats.dogs_avg = stats.dogs_avg / (double)params.number_of_dogs; stats.mice_avg = stats.mice_avg / (double)params.number_of_mice; printf("**************************************************\n"); printf("* Statistics *\n"); printf("**************************************************\n"); printf("| "MAGENTA"Cats"RESET" | "BLUE"Dogs"RESET" | "CYAN"Mice"RESET" |\n"); printf("|--------------|----------------|----------------|\n"); printf("| "GREEN"Min"RESET": %04.1f | "GREEN"Min"RESET": %04.1f | "GREEN"Min"RESET": %04.1f |\n", stats.cats_min, stats.dogs_min, stats.mice_min); printf("| "RED"Max"RESET": %04.1f | "RED"Max"RESET": %04.1f | "RED"Max"RESET": %04.1f |\n", stats.cats_max, stats.dogs_max, stats.mice_max); printf("| "CYAN"Avg"RESET": %04.1f | "CYAN"Avg"RESET": %04.1f | "CYAN"Avg"RESET": %04.1f |\n", stats.cats_avg, stats.dogs_avg, stats.mice_avg); printf("**************************************************\n"); pthread_mutex_unlock(&statistics_mutex); } void statisticsHandler(char species, int id, double min, double max, double avg) { char *text_to_output_file = malloc(100 * sizeof(char)); sprintf(text_to_output_file, "Species: %c | ID: %d | Min: %3.1f | Max: %3.1f | Avg: %3.1f\n", species, id, min, max, avg); writeToFile(stats.output_file, text_to_output_file); free(text_to_output_file); } void printHelper(char species, int id, char* text) { time_t rawtime; struct tm * timeinfo; int current_value_of_food_dishes_semaphore_lokal; pthread_mutex_lock(&logger_mutex); time ( &rawtime ); timeinfo = localtime ( &rawtime ); printf("["GREEN"%02d"RESET":"GREEN"%02d"RESET":"GREEN"%02d"RESET"] [", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); sem_getvalue(&food_dishes_semaphore, &current_value_of_food_dishes_semaphore_lokal); int free_food_dishes = number_of_food_dishes - current_value_of_food_dishes_semaphore_lokal; int count_used_prints_of_free_food_dishes = 0; for (int i = 0; i < number_of_food_dishes; i++) { if(i){ if(free_food_dishes - count_used_prints_of_free_food_dishes){ printf(":"RED"x"RESET); count_used_prints_of_free_food_dishes++; } else printf(":-"); } else{ if(free_food_dishes - count_used_prints_of_free_food_dishes){ printf(RED"x"RESET); count_used_prints_of_free_food_dishes++; } else printf("-"); } } if(species == 'c'){ printf("] "MAGENTA"Cat"RESET" (id %03d) %s\n", id, text); }else if(species == 'd'){ printf("] "BLUE"Dog"RESET" (id %03d) %s\n", id, text); }else if(species == 'm'){ printf("] "CYAN"Mouse"RESET" (id %03d) %s\n", id, text); } pthread_mutex_unlock(&logger_mutex); } void *feedingMachineScheduler(start_params *params) { while(finished_animals != (params->number_of_cats + params->number_of_dogs + params->number_of_mice)){ pthread_mutex_lock(&feeding_machine_mutex); change_species_mode = 't'; if(current_species == '0'){ current_species = 'c'; // Set cat }else if(current_species == 'c'){ current_species = '0'; sem_getvalue(&food_dishes_semaphore, &current_value_of_food_dishes_semaphore); while(current_value_of_food_dishes_semaphore != number_of_food_dishes){ pthread_cond_wait(&feeding_machine_cv, &feeding_machine_mutex); sem_getvalue(&food_dishes_semaphore, &current_value_of_food_dishes_semaphore); } current_species = 'd'; // Set dog }else if(current_species == 'd'){ current_species = '0'; sem_getvalue(&food_dishes_semaphore, &current_value_of_food_dishes_semaphore); while(current_value_of_food_dishes_semaphore != number_of_food_dishes){ pthread_cond_wait(&feeding_machine_cv, &feeding_machine_mutex); sem_getvalue(&food_dishes_semaphore, &current_value_of_food_dishes_semaphore); } current_species = 'm'; // Set mouse }else if(current_species == 'm'){ current_species = '0'; sem_getvalue(&food_dishes_semaphore, &current_value_of_food_dishes_semaphore); while(current_value_of_food_dishes_semaphore != number_of_food_dishes){ pthread_cond_wait(&feeding_machine_cv, &feeding_machine_mutex); sem_getvalue(&food_dishes_semaphore, &current_value_of_food_dishes_semaphore); } current_species = 'c'; // Set cat } change_species_mode = 'f'; pthread_mutex_unlock(&feeding_machine_mutex); pthread_cond_broadcast(&feeding_machine_cv); // Time to dispatch if((params->number_of_cats != 0 && current_species == 'c') || (params->number_of_dogs != 0 && current_species == 'd') || (params->number_of_mice != 0 && current_species == 'm')) wait(params->eating_time_interval_lower_boundary); } return NULL; } void *animal(animal_params *animal_args) { // Measuring vars time_t start_time, end_time; double waiting_time, min, max, avg; char first_round_init = 't'; // t = true, f = false int total_number_of_rounds = animal_args->feeding_counter; while(animal_args->feeding_counter != 0){ // Feeding machine scheduling condition check pthread_mutex_lock(&feeding_machine_mutex); sem_getvalue(&food_dishes_semaphore, &current_value_of_food_dishes_semaphore); // Measure the waiting time (start) time(&start_time); while(current_species != animal_args->species || current_value_of_food_dishes_semaphore == 0){ pthread_cond_wait(&feeding_machine_cv, &feeding_machine_mutex); sem_getvalue(&food_dishes_semaphore, &current_value_of_food_dishes_semaphore); } // --> Food dishes area <-- sem_wait(&food_dishes_semaphore); printHelper(animal_args->species, animal_args->id, "eating from a dish"); pthread_mutex_unlock(&feeding_machine_mutex); pthread_cond_broadcast(&feeding_machine_cv); // Measure the waiting time (end) time(&end_time); waiting_time = difftime(end_time, start_time); if(first_round_init == 'f'){ if(waiting_time < min) min = waiting_time; if(waiting_time > max) max = waiting_time; avg = avg + waiting_time; }else if(first_round_init == 't'){ min = waiting_time; max = waiting_time; avg = waiting_time; first_round_init = 'f'; } // A animal eat wait(animal_args->eating_time); pthread_mutex_lock(&feeding_machine_mutex); sem_post(&food_dishes_semaphore); printHelper(animal_args->species, animal_args->id, "finished eating from a dish"); pthread_mutex_unlock(&feeding_machine_mutex); pthread_cond_broadcast(&feeding_machine_cv); animal_args->feeding_counter--; if(animal_args->feeding_counter == 0) break; // A animal is statisfied wait(animal_args->statisfied_time); } // Calc avg avg = avg / total_number_of_rounds; if(write_output_file == 't') statisticsHandler(animal_args->species, animal_args->id, min, max, avg); statisticsOfAllSpeciesHandler(animal_args->species, min, max, avg); pthread_mutex_lock(&finished_animals_mutex); finished_animals++; pthread_mutex_unlock(&finished_animals_mutex); return NULL; } void threadHandler(start_params params) { char cat_specific_char = 'c'; char dog_specific_char = 'd'; char mouse_specific_char = 'm'; int number_of_threads = params.number_of_cats + params.number_of_dogs + params.number_of_mice; int number_of_feeding_machines = 1; pthread_t animal_threads[number_of_threads]; animal_params animal_args[number_of_threads]; pthread_t feeding_machines[number_of_feeding_machines]; // Init variable before starting number_of_food_dishes = params.number_of_food_dishes; sem_getvalue(&food_dishes_semaphore, &current_value_of_food_dishes_semaphore); stats.output_file = params.output_file; stats.cats_values_empty = 't'; stats.dogs_values_empty = 't'; stats.mice_values_empty = 't'; // Starts all Animal-Threads: // Feeding machine for(int i=0;i<number_of_feeding_machines;i++){ pthread_create(&feeding_machines[i],NULL, (void *(*)(void *)) feedingMachineScheduler, (void *) &params); } // Cats for(int i=0;i<params.number_of_cats;i++){ // Init parameters animal_args[i].id = i; animal_args[i].species = cat_specific_char; animal_args[i].feeding_counter = params.how_many_times_a_cat_wants_to_eat; animal_args[i].eating_time = randomTime(params.eating_time_interval_lower_boundary, params.eating_time_interval_upper_boundary); animal_args[i].statisfied_time = params.time_a_cat_is_statisfied; // Start thread pthread_create(&animal_threads[i],NULL, (void *(*)(void *)) animal, (void *) &animal_args[i]) ; } // Dogs for(int i=params.number_of_cats;i<params.number_of_cats + params.number_of_dogs;i++){ // Init parameters animal_args[i].id = i; animal_args[i].species = dog_specific_char; animal_args[i].feeding_counter = params.how_many_times_a_dog_wants_to_eat; animal_args[i].eating_time = randomTime(params.eating_time_interval_lower_boundary, params.eating_time_interval_upper_boundary); animal_args[i].statisfied_time = params.time_a_dog_is_statisfied; // Start thread pthread_create(&animal_threads[i],NULL, (void *(*)(void *)) animal, (void *) &animal_args[i]) ; } // Mice for(int i=params.number_of_cats + params.number_of_dogs;i<number_of_threads;i++){ // Init parameters animal_args[i].id = i; animal_args[i].species = mouse_specific_char; animal_args[i].feeding_counter = params.how_many_times_a_mouse_wants_to_eat; animal_args[i].eating_time = randomTime(params.eating_time_interval_lower_boundary, params.eating_time_interval_upper_boundary); animal_args[i].statisfied_time = params.time_a_mouse_is_statisfied; // Start thread pthread_create(&animal_threads[i],NULL, (void *(*)(void *)) animal, (void *) &animal_args[i]) ; } // Cleaning: // Animals for(int i=0;i<number_of_threads;i++){ long *statusp; pthread_join(animal_threads[i],(void *)&statusp); } // Feeding machine for(int i=0;i<number_of_feeding_machines;i++){ long *statusp; pthread_join(feeding_machines[i],(void *)&statusp); } } void runSequence(start_params params) { // Init mutex and semaphore initMutexAndSemaphore(params); // Debug output (console) if(params.verbose_print == 1) printParams(params); // Starts threads threadHandler(params); // Print statistics printStatisticsOfAllSpecies(params); // Clean up mutex and semaphore destroyMutexAndSemaphore(); } // Program start int main (int argc, char *argv[]) { start_params params; // Init defaults params.number_of_cats = 6; params.number_of_dogs = 4; params.number_of_mice = 2; params.time_a_cat_is_statisfied = 15; params.time_a_dog_is_statisfied = 10; params.time_a_mouse_is_statisfied = 1; params.how_many_times_a_cat_wants_to_eat = 5; params.how_many_times_a_dog_wants_to_eat = 5; params.how_many_times_a_mouse_wants_to_eat = 5; params.number_of_food_dishes = 2; params.eating_time_interval_lower_boundary = 1; params.eating_time_interval_upper_boundary = 1; params.output_file = "output_file.txt"; params.verbose_print = 0; // 1=true struct option long_options[] = { {"cn", required_argument, NULL, 'a'}, {"dn", required_argument, NULL, 'b'}, {"mn", required_argument, NULL, 'c'}, {"ct", required_argument, NULL, 'd'}, {"dt", required_argument, NULL, 'x'}, {"mt", required_argument, NULL, 'f'}, {"ce", required_argument, NULL, 'g'}, {"de", required_argument, NULL, 'z'}, {"me", required_argument, NULL, 'i'}, {"e", required_argument, NULL, 'e'}, {"E", required_argument, NULL, 'E'}, {"dish", required_argument, NULL, 'j'}, {"file", required_argument, NULL, 'k'}, {"v", no_argument, NULL, 'v'}, {"h", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0} }; int opt; while ((opt = getopt_long(argc, argv, "a:b:c:d:x:f:g:z:i:j:k:e:E:vh", long_options, NULL)) != -1) { switch (opt) { case 'a': params.number_of_cats = atoi(optarg); break; case 'b': params.number_of_dogs = atoi(optarg); break; case 'c': params.number_of_mice = atoi(optarg); break; case 'd': params.time_a_cat_is_statisfied = atoi(optarg); break; case 'x': params.time_a_dog_is_statisfied = atoi(optarg); break; case 'f': params.time_a_mouse_is_statisfied = atoi(optarg); break; case 'g': params.how_many_times_a_cat_wants_to_eat = atoi(optarg); break; case 'z': params.how_many_times_a_dog_wants_to_eat = atoi(optarg); break; case 'i': params.how_many_times_a_mouse_wants_to_eat = atoi(optarg); break; case 'j': params.number_of_food_dishes = atoi(optarg); break; case 'k': params.output_file = optarg; break; case 'e': params.eating_time_interval_lower_boundary = atoi(optarg); break; case 'E': params.eating_time_interval_upper_boundary = atoi(optarg); break; case 'v': params.verbose_print = 1; break; case 'h': printHelp(); break; } } // Set global var false if((params.number_of_cats > 10) || (params.number_of_dogs > 10) || (params.number_of_mice > 10)) write_output_file = 'f'; runSequence(params); // End of Program return 0; }
the_stack_data/95449281.c
#include<stdio.h> int main(void) { int n, fatorial; fatorial = 1; printf("Digite o numero: "); scanf("%d", &n); for(int i = n; i >= 1; i--) { printf("%d\n", i); fatorial *= i; } printf("Resultado: %d", fatorial); }
the_stack_data/28738.c
#include <stdio.h> int printf(const char* format, ...) { va_list list; va_start(list, format); int ret = vfprintf(stdout, format, list); va_end(list); return ret; }
the_stack_data/173578163.c
/* $NetBSD: wrtvid.c,v 1.6 2002/03/24 18:15:03 scw Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Steve C. Woodford. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the NetBSD * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> /* mvme68k's boot block is 512 bytes long */ #define SIZEOF_VID 0x200 /* The first field is effectively the vendor string, in this case NBSD */ #define VID_ID_OFF 0x000 #define VID_ID "NBSD" #define VID_ID_LEN 4 /* Start block for the 1st stage bootstrap code */ #define VID_OSS_OFF 0x014 #define VID_OSS_TAPE 1 #define VID_OSS_DISK 2 /* Length, in 256-byte logical blocks, of the 1st stage bootstrap */ #define VID_OSL_OFF 0x018 /* Start address of the bootstrap */ #define VID_OSA_OFF 0x01e #define VID_OSA 0x003f0000 /* Block number of config area */ #define VID_CAS_OFF 0x093 #define VID_CAS 1 /* Length, in 256-byte logical blocks, of config area */ #define VID_CAL_OFF 0x094 #define VID_CAL 1 /* Magic `MOTOROLA' string */ #define VID_MOT_OFF 0x0f8 #define VID_MOT "MOTOROLA" #define VID_MOT_LEN 8 /* Logical block size, in bytes */ #define CFG_REC_OFF 0x10a #define CFG_REC 0x100 /* Physical sector size, in bytes */ #define CFG_PSM_OFF 0x11e #define CFG_PSM 0x200 /* * Write a big-endian 32-bit value at the specified address */ static void write32(u_int8_t *vp, u_int32_t value) { *vp++ = (u_int8_t) ((value >> 24) & 0xff); *vp++ = (u_int8_t) ((value >> 16) & 0xff); *vp++ = (u_int8_t) ((value >> 8) & 0xff); *vp = (u_int8_t) (value & 0xff); } /* * Write a big-endian 16-bit value at the specified address */ static void write16(u_int8_t *vp, u_int16_t value) { *vp++ = (u_int8_t) ((value >> 8) & 0xff); *vp = (u_int8_t) (value & 0xff); } int main(int argc, char **argv) { struct stat st; u_int16_t len; u_int8_t *vid; char *fn; int is_disk; int fd; if (argc != 2) { usage: fprintf(stderr, "%s: <bootsd|bootst>\n", argv[0]); exit(1); } if (strcmp(argv[1], "bootsd") == 0) { is_disk = 1; fn = "sdboot"; } else if (strcmp(argv[1], "bootst") == 0) { is_disk = 0; fn = "stboot"; } else goto usage; if (stat(argv[1], &st) < 0) { perror(argv[1]); exit(1); } /* How many 256-byte logical blocks (rounded up) */ len = (u_int16_t) ((st.st_size + 255) / 256); /* For tapes, round up to 8k */ if (is_disk == 0) { len += (8192 / 256) - 1; len &= ~((8192 / 256) -1); } if ((vid = malloc(SIZEOF_VID)) == NULL) { perror(argv[0]); exit(1); } /* Generate the VID and CFG data */ memset(vid, 0, SIZEOF_VID); memcpy(&vid[VID_ID_OFF], VID_ID, VID_ID_LEN); write32(&vid[VID_OSS_OFF], is_disk ? VID_OSS_DISK : VID_OSS_TAPE); write16(&vid[VID_OSL_OFF], len); write32(&vid[VID_OSA_OFF], VID_OSA); vid[VID_CAS_OFF] = VID_CAS; vid[VID_CAL_OFF] = VID_CAL; memcpy(&vid[VID_MOT_OFF], VID_MOT, VID_MOT_LEN); write16(&vid[CFG_REC_OFF], CFG_REC); write16(&vid[CFG_PSM_OFF], CFG_PSM); /* Create and write it out */ if ((fd = open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) { perror(fn); exit(1); } if (write(fd, vid, SIZEOF_VID) != SIZEOF_VID) { perror(fn); exit(1); } close(fd); free(vid); return(0); }
the_stack_data/82950046.c
// http://blog.ioactive.com/2012/05/enter-dragonbook-pt-2.html // This example is to concisely explaine the C specification attack // I really liked this bug since it's an abuse of the "undefined operation" of a C compiler // There is no actual flaw in the code here, if examined by a human (and those 0x7fff values obfuscated with #define's) // there bug is injected when the compiler ignore's it's own eviropnment limits (this code should not build, but it does) // with the right massaging there are no warnings, no way to know that there is a gaping security hole in the code (except if you do binary analysis/dissassembly) // // I call this copper since the bug manifests itself in the abuse of a struct field (Copperfield being some magic guy right;)? typedef struct _copper { char field1[0x7fffffff]; char field2[0x7fffffff]; char pad0; char pad1; } copper, *pcopper; int main(int argc, char **argv) { copper david; printf("sizeof david = %x\n", sizeof(david)); printf("sizeof david’s copper.field1 = %x\n", sizeof(david.field1)); if(argc > 1 && strlen(argv[argc-1]) < sizeof(david.field1)) strncpy_s(david.field1, argv[argc-1], sizeof(david.field1)); return 0; }
the_stack_data/165764899.c
/* text version of maze 'mazefiles/binary/map-y5-3.maz' generated by mazetool (c) Peter Harrison 2018 o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o | | o o---o---o---o o---o---o o---o---o---o o---o---o---o o | | | | | o o---o---o---o o o---o o---o---o---o---o o---o o o | | | | | | | o o o---o---o---o---o o---o---o---o---o---o---o---o o o | | | | | | o o o o---o---o---o---o---o---o---o---o---o---o---o o o | | | | | | | o o o---o---o---o---o o o---o---o o o o o---o o | | | | | | | | | o o o o---o---o---o---o o---o---o o o o o o---o | | | | | | | | | | | o o o---o o---o---o o---o o---o o o o o o o | | | | | | | | | | o---o o---o o o o o o o o o o o o o o | | | | | | | | | | | | | | | o o o o o o o o---o---o o o o o o o o | | | | | | | | | | | | | | o o---o o o o o o---o---o---o o o o o o o | | | | | | | o o---o o o o o---o---o---o o---o---o---o---o o o | | | | | | | o o o o o o---o o o---o---o---o---o o o---o o | | | | | | | | | | | | o o o o o---o---o---o o o o o o o o o o | | | | | | | | | | | | o o o o---o---o o o---o---o o---o o o o o o | | | | | | | | o o o---o---o---o o---o---o---o o---o---o---o---o o o | | | | o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o */ int map_y5_3_maz[] ={ 0x0E, 0x0A, 0x0A, 0x0A, 0x08, 0x08, 0x0A, 0x0B, 0x0E, 0x0A, 0x08, 0x0A, 0x0A, 0x0A, 0x08, 0x09, 0x0C, 0x0A, 0x0A, 0x0A, 0x03, 0x05, 0x0E, 0x0A, 0x08, 0x0A, 0x02, 0x0A, 0x0A, 0x09, 0x05, 0x05, 0x05, 0x0C, 0x08, 0x0A, 0x0A, 0x02, 0x0A, 0x0B, 0x05, 0x0C, 0x09, 0x0C, 0x09, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04, 0x0A, 0x08, 0x0A, 0x0A, 0x0A, 0x02, 0x01, 0x05, 0x05, 0x05, 0x07, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0C, 0x02, 0x0A, 0x0A, 0x0A, 0x09, 0x05, 0x05, 0x05, 0x05, 0x0C, 0x02, 0x01, 0x04, 0x02, 0x03, 0x05, 0x0C, 0x0A, 0x0A, 0x0A, 0x03, 0x07, 0x05, 0x05, 0x05, 0x04, 0x09, 0x05, 0x05, 0x0C, 0x09, 0x06, 0x01, 0x0C, 0x08, 0x0A, 0x0A, 0x0B, 0x06, 0x03, 0x04, 0x03, 0x05, 0x05, 0x05, 0x05, 0x06, 0x0A, 0x01, 0x05, 0x05, 0x0C, 0x09, 0x0C, 0x0A, 0x09, 0x05, 0x0C, 0x00, 0x01, 0x07, 0x05, 0x0E, 0x09, 0x07, 0x05, 0x05, 0x06, 0x02, 0x01, 0x0D, 0x05, 0x05, 0x05, 0x05, 0x05, 0x0C, 0x00, 0x0A, 0x01, 0x0C, 0x01, 0x06, 0x0A, 0x09, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x07, 0x0C, 0x03, 0x05, 0x04, 0x0A, 0x0A, 0x00, 0x02, 0x02, 0x01, 0x07, 0x05, 0x05, 0x05, 0x05, 0x0C, 0x02, 0x0B, 0x05, 0x04, 0x0A, 0x0A, 0x02, 0x0A, 0x0A, 0x01, 0x0D, 0x05, 0x06, 0x01, 0x05, 0x04, 0x0A, 0x0A, 0x01, 0x04, 0x0A, 0x0A, 0x08, 0x0A, 0x0A, 0x03, 0x05, 0x04, 0x09, 0x05, 0x05, 0x06, 0x0A, 0x0A, 0x01, 0x04, 0x0A, 0x0A, 0x02, 0x0A, 0x0A, 0x09, 0x05, 0x07, 0x05, 0x05, 0x04, 0x0A, 0x0A, 0x09, 0x06, 0x02, 0x0A, 0x08, 0x0A, 0x0A, 0x09, 0x06, 0x02, 0x0A, 0x03, 0x05, 0x06, 0x0A, 0x0A, 0x02, 0x0A, 0x0A, 0x0A, 0x02, 0x0A, 0x0B, 0x06, 0x0A, 0x0A, 0x0A, 0x0A, 0x03, }; /* end of mazefile */
the_stack_data/157987.c
/* No manual changes in this file */ #include <stdio.h> #include <string.h> static const char rcsid[] = "$Id$"; static char atoprevision[] = "$Revision: 1.16 $"; static char atopdate[] = "$Date: 2006/04/03 08:39:37 $"; char * getversion(void) { static char vers[256]; atoprevision[sizeof atoprevision - 3] = '\0'; atopdate [sizeof atopdate - 3] = '\0'; snprintf(vers, sizeof vers, "Version:%s -%s < [email protected] >", strchr(atoprevision, ' '), strchr(atopdate , ' ')); return vers; }
the_stack_data/3263821.c
#include <stdio.h> #define duzina 10 /* Napisati program koji učitava matricu cijelih brojeva dimenzija 10x10 te pronalazi najmanji element na glavnoj dijagonali. */ int main() { int i, j; int mat[duzina][duzina]; int min; for(i=0;i<duzina;i++) { for(j=0;j<duzina;j++) { scanf("%d", &mat[i][j]); } } min = mat[0][0]; //printf("%d", min); for(i=0;i<duzina;i++) { for(j=0;j<duzina;j++) { if(i==j && mat[i][j]<min) min=mat[i][j]; } } printf("%d", min); return 0; }
the_stack_data/243893902.c
struct X {}; // original code: // typeof(struct X) X_array[42]; typeof(struct X) X_array[42];
the_stack_data/10132.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #define TOTAL 67 #define ROW 11 #define COL 20 /* get the ascii-art line from file */ static int getAsciiArt(FILE *fp, long bufsize) { long base, count; int i, j, k; char *buf = calloc(bufsize + 1, sizeof(char)); /* Read the entire file into memory. */ size_t newLen = fread(buf, sizeof(char), bufsize, fp); buf[++newLen] = '\0'; /* Just to be safe. */ count = 0; /* get the ascii-art, convert vertical to horizontal. */ for(i = 0; i < ROW; i++) /* each row */ { for (j = 0; j < TOTAL; j++) /* for the nth char */ { base = (j * ROW * (COL + 1)) + i * (COL + 1); for (k = 0; k < COL; k++) /* for each column */ { printf("0x%02X, ", buf[base++]); count++; if (count % 20 == 0) { printf("\n"); count= 0; } } } printf("0x0A, "); count++; } /* end outer for */ /* add terminator */ printf("0x0"); free(buf); return 0; } static int getProperties(FILE *fp, long bufsize) { char properties[256]; fgets(properties, sizeof(properties), fp); fgets(properties, sizeof(properties), fp); fgets(properties, sizeof(properties), fp); /* The left line is our ascii-art characters */ getAsciiArt(fp, bufsize); return 0; } int main() { FILE *fp = NULL; long bufsize = 0L; fp = fopen("./Blocks.art", "r"); /* Get file size */ /* Go to the end of the file. */ fseek(fp, 0L, SEEK_END); /* Get the size of the file. */ bufsize = ftell(fp); /* Go back to the start of the file. */ fseek(fp, 0L, SEEK_SET); getProperties(fp, bufsize); fclose(fp); return 0; }
the_stack_data/97012539.c
#include <stdio.h> int main() { int x1=3; if (3 != *&x1) return 1; int x2=3; int *y2=&x2; int **z2=&y2; if (3 != **z2) return 2; int x3=3; int y3=5; if (5 != *(&x3+1)) return 3; int x4=3; int y4=5; if (3 != *(&y4-1)) return 4; int x5=3; int y5=5; if (5 != *(&x5-(-1))) return 5; int x6=3; int *y6=&x6; *y6=5; if (5 != x6) return 6; int x7=3; int y7=5; *(&x7+1)=7; if (7 != y7) return 7; int x8=3; int y8=5; *(&y8-2+1)=7; if (7 != x8) return 8; int x9=3; if (5 != (&x9+2)-&x9+3) return 9; int x10, y10; x10=3; y10=5; if (8 != x10+y10) return 10; int x11=3, y11=5; if (8 != x11+y11) return 11; int x12[2]; int *y12=(int*)&x12; *y12=3; if (3 != *x12) return 12; int x13[3]; *x13=3; *(x13+1)=4; *(x13+2)=5; if (3 != *x13) return 13; if (4 != *(x13+1)) return 14; if (5 != *(x13+2)) return 15; int x16[2][3]; int *y16=(int*)x16; *y16=0; if (0 != **x16) return 16; *(y16+1)=1; if (1 != *(*x16+1)) return 17; *(y16+2)=2; if (2 != *(*x16+2)) return 18; *(y16+3)=3; if (3 != **(x16+1)) return 19; *(y16+4)=4; if (4 != *(*(x16+1)+1)) return 20; *(y16+5)=5; if (5 != *(*(x16+1)+2)) return 21; int x22[3]; *x22=3; x22[1]=4; x22[2]=5; if (3 != *x22) return 22; if (4 != *(x22+1)) return 23; if (5 != *(x22+2)) return 24; if (5 != *(x22+2)) return 25; 2[x22]=6; if (6 != *(x22+2)) return 26; int x23[2][3]; int *y23=(int *)x23; y23[0]=0; if (0 != x23[0][0]) return 23; y23[1]=1; if (1 != x23[0][1]) return 24; y23[2]=2; if (2 != x23[0][2]) return 25; y23[3]=3; if (3 != x23[1][0]) return 26; y23[4]=4; if (4 != x23[1][1]) return 27; y23[5]=5; if (5 != x23[1][2]) return 28; printf("OK\n"); return 0; }
the_stack_data/118483.c
/* HAL raised several warnings, ignore them */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" #ifdef STM32F0xx #include "stm32f0xx_hal_i2c.c" #elif STM32F1xx #include "stm32f1xx_hal_i2c.c" #elif STM32F2xx #include "stm32f2xx_hal_i2c.c" #elif STM32F3xx #include "stm32f3xx_hal_i2c.c" #elif STM32F4xx #include "stm32f4xx_hal_i2c.c" #elif STM32F7xx #include "stm32f7xx_hal_i2c.c" #elif STM32G0xx #include "stm32g0xx_hal_i2c.c" #elif STM32G4xx #include "stm32g4xx_hal_i2c.c" #elif STM32H7xx #include "stm32h7xx_hal_i2c.c" #elif STM32L0xx #include "stm32l0xx_hal_i2c.c" #elif STM32L1xx #include "stm32l1xx_hal_i2c.c" #elif STM32L4xx #include "stm32l4xx_hal_i2c.c" #elif STM32L5xx #include "stm32l5xx_hal_i2c.c" #elif STM32MP1xx #include "stm32mp1xx_hal_i2c.c" #elif STM32WBxx #include "stm32wbxx_hal_i2c.c" #elif STM32WLxx #include "stm32wlxx_hal_i2c.c" #endif #pragma GCC diagnostic pop
the_stack_data/37674.c
#include <stdlib.h> #include <stdio.h> int main() { int N,i=0,inf=10000000,tmp; scanf("%d", &N); int power[N]; while (i< N) { scanf("%d", &tmp); power[i] = tmp; i++; } inline int more (void const *a, void const *b){return ( *(int*)a - *(int*)b );} qsort(power, N, sizeof(int), more); for (i = 0; i < N-1; i++) { tmp = ( power[i+1] - power[i] ); if (tmp < inf) { inf = tmp; } } printf("%d\n",inf); return 0; }
the_stack_data/242330255.c
static const unsigned char File15_array[900] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xdd, 0xdd, 0xdd, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xcf, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; const int File15_array_length = 900; unsigned char *File15 = (unsigned char *)File15_array;
the_stack_data/537865.c
/* PR rtl-optimization/65401 */ struct S { unsigned short s[64]; }; __attribute__((noinline, noclone)) void foo (struct S *x) { unsigned int i; unsigned char *s; s = (unsigned char *) x->s; for (i = 0; i < 64; i++) x->s[i] = s[i * 2] | (s[i * 2 + 1] << 8); } __attribute__((noinline, noclone)) void bar (struct S *x) { unsigned int i; unsigned char *s; s = (unsigned char *) x->s; for (i = 0; i < 64; i++) x->s[i] = (s[i * 2] << 8) | s[i * 2 + 1]; } int main () { unsigned int i; struct S s; if (sizeof (unsigned short) != 2) return 0; for (i = 0; i < 64; i++) s.s[i] = i + ((64 - i) << 8); foo (&s); #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ for (i = 0; i < 64; i++) if (s.s[i] != (64 - i) + (i << 8)) __builtin_abort (); #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ for (i = 0; i < 64; i++) if (s.s[i] != i + ((64 - i) << 8)) __builtin_abort (); #endif for (i = 0; i < 64; i++) s.s[i] = i + ((64 - i) << 8); bar (&s); #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ for (i = 0; i < 64; i++) if (s.s[i] != (64 - i) + (i << 8)) __builtin_abort (); #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ for (i = 0; i < 64; i++) if (s.s[i] != i + ((64 - i) << 8)) __builtin_abort (); #endif return 0; }
the_stack_data/140764476.c
#include <stdio.h> #include <string.h> typedef struct lens{ float foclen; float fstop; char brand[30]; } LENS; int main(void) { LENS lens[10] = { [2]={ 500, 2.0, "Remarkatar" } }; lens[1]=(LENS){400, 1.8, "Canon"}; strcpy(lens[0].brand , "Nikon"); printf("%.2f\n", lens[1].foclen); return 0; }
the_stack_data/911211.c
#include <stdio.h> int main (void) { int a = 42, i; float b = 3.141592f; char c[17] = "Hello World!"; printf("LOCAL VAR ADDRESSES:\na -> %p\nb -> %p\n", &a, &b); for (i = 0; i < 17; i++) printf("Char %d: %p\n", i, &c[i]); return 0; }
the_stack_data/181393743.c
/* * Created by gt on 10/22/21 - 10:23 AM. * Copyright (c) 2021 GTXC. All rights reserved. * * * setjmp : try * longjmp: throw * * not as like as goto, with goto it can only be possible to jump * in the same function, setjmp and longjmp make possible to jump * to another functions, anywhere in the program * * setjmp saves a copy of the program counter and the current pointer to the top of the stack * * int setjmp(jmp_buf j) * use the variable j to remember where you are now * must be called first * * longjmp is then invoked after setjmp (longjmp(jmp_buf j, int i)) * says go back to the place that the j is remembering * restores the process in the state that it exited when it called setjmp * returns the value of i so the code can tell when you actually got back here via longjmp() * the content of the j are destroyed when it used in a longjmp() * * often referred to as "unwinding the stack" because you unroll activation records from the stack * until you get to the saved one * * the header file <setjmp.h> need to be included in any source file that uses setjmp or longjmp * */ #include <stdio.h> #include <setjmp.h> #include <stdlib.h> jmp_buf buf; void myFunction() { printf("myFunction() called.\n"); longjmp(buf, 0); /* NOT REACHED */ printf("You will never see this, because I longjmp'd\n"); } int main() { //below block comment another example for setjmp-longjmp /* int i = setjmp(buf); printf("i = %i\node_", i); if (i != 0) exit(0); longjmp(buf, 42); printf("Does this line get printed?\node_"); */ if (setjmp(buf)) { printf("setjmp(buf) = %i\n", setjmp(buf)); printf("Back in main.\n"); } else { printf("First time through.\n"); myFunction(); } return 0; }
the_stack_data/484669.c
// SysTick.h // Runs on LM4F120 // Provide functions that initialize the SysTick module, wait at least a // designated number of clock cycles, and wait approximately a multiple // of 10 milliseconds using busy wait. After a power-on-reset, the // LM4F120 gets its clock from the 16 MHz precision internal oscillator, // which can vary by +/- 1% at room temperature and +/- 3% across all // temperature ranges. If you are using this module, you may need more // precise timing, so it is assumed that you are using the PLL to set // the system clock to 50 MHz. This matters for the function // SysTick_Wait10ms(), which will wait longer than 10 ms if the clock is // slower. // Daniel Valvano // October 25, 2012 /* This example accompanies the book "Embedded Systems: Real Time Interfacing to Arm Cortex M Microcontrollers", ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2012 Program 2.11, Section 2.6 Copyright 2012 by Jonathan W. Valvano, [email protected] You may use, edit, run or distribute this file as long as the above copyright notice remains THIS SOFTWARE IS PROVIDED "AS IS". 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. VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. For more information about my classes, my research, and my books, see http://users.ece.utexas.edu/~valvano/ */ // Initialize SysTick with busy wait running at bus clock. #define NVIC_ST_CTRL_R (*((volatile unsigned long *)0xE000E010)) #define NVIC_ST_RELOAD_R (*((volatile unsigned long *)0xE000E014)) #define NVIC_ST_CURRENT_R (*((volatile unsigned long *)0xE000E018)) void SysTick_Init(void){ NVIC_ST_CTRL_R = 0; // disable SysTick during setup NVIC_ST_CTRL_R = 0x00000005; // enable SysTick with core clock } // The delay parameter is in units of the 80 MHz core clock. (12.5 ns) void SysTick_Wait(unsigned long delay){ NVIC_ST_RELOAD_R = delay-1; // number of counts to wait NVIC_ST_CURRENT_R = 0; // any value written to CURRENT clears while((NVIC_ST_CTRL_R&0x00010000)==0){ // wait for count flag } } // 10000us equals 10ms void SysTick_Wait10ms(unsigned long delay){ unsigned long i; for(i=0; i<delay; i++){ SysTick_Wait(800000); // wait 10ms } }
the_stack_data/151706380.c
/* Compilar gcc: gcc -o Trab3_SemOtimizacao Trab3_SemOtimizacao.c -fopenmp Compilar PGI: pgcc -mp -Minfo=all -o Trab3_SemOtimizacao Trab3_SemOtimizacao.c Compilar icc: icc -o Trab3_SemOtimizacao Trab3_SemOtimizacao.c -openmp Executar: ./Trab3_SemOtimizacao 2000 OBS: 2000 representa o tamanho da matriz. */ #include<stdio.h> #include<stdlib.h> #include<time.h> #include<omp.h> int main(int argc, char *argv[]){ int i,j,k,N; double **a, **b, **c; double t_final, t_inicial; srand(time(NULL)); if(argc < 2){ perror("Número de argumentos insuficiente, insira a dimensão da matriz quadrada"); return 0; }else{ N = atoi(argv[1]); } /*Alocação da Matrizes*/ a = (double**) malloc(sizeof(double*)*N); b = (double**) malloc(sizeof(double*)*N); c = (double**) malloc(sizeof(double*)*N); for(i=0; i<N; i++){ a[i] = (double*) malloc(sizeof(double)*N); b[i] = (double*) malloc(sizeof(double)*N); c[i] = (double*) malloc(sizeof(double)*N); } /*Inicialização das matrizes*/ for(i=0; i<N; i++){ for(j=0; j<N; j++){ a[i][j] = rand()%N; b[i][j] = rand()%N; c[i][j] = 0.0; } } t_inicial = omp_get_wtime(); for(i=0; i<N; i++) for (j=0; j<N; j++) for (k=0; k<N; k++) c[i][j] += a[i][k] * b[k][j]; t_final = omp_get_wtime(); printf("Tempo de execução: %lf\n", t_final-t_inicial); /*Libera memória utilizada*/ for(i=0; i<N; i++){ free(a[i]); free(b[i]); free(c[i]); } free(a); free(b); free(c); return 0; }
the_stack_data/936557.c
#include <stdio.h> #include <string.h> int main() { char dna[100] = ""; scanf("%99s", dna); char compress [100] = ""; categorize(dna,compress); if(strlen(compress) < strlen(dna)) { for(int i = 0; i < strlen(compress); i++){ printf("%c",compress[i]); } } else { for(int i = 0; i < strlen(dna); i++){ printf("%c",dna[i]); } } return 0; }
the_stack_data/818264.c
// RUN: %clang -target armv8a-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8A %s // CHECK-V8A: #define __ARMEL__ 1 // CHECK-V8A: #define __ARM_ARCH 8 // CHECK-V8A: #define __ARM_ARCH_8A__ 1 // CHECK-V8A: #define __ARM_FEATURE_CRC32 1 // CHECK-V8A: #define __ARM_FEATURE_DIRECTED_ROUNDING 1 // CHECK-V8A: #define __ARM_FEATURE_NUMERIC_MAXMIN 1 // CHECK-V8A-NOT: #define __ARM_FP 0x // CHECK-V8A-NOT: #define __ARM_FEATURE_DOTPROD // RUN: %clang -target armv8a-none-linux-gnueabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8A-ALLOW-FP-INSTR %s // RUN: %clang -target armv8a-none-linux-gnueabihf -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8A-ALLOW-FP-INSTR %s // CHECK-V8A-ALLOW-FP-INSTR: #define __ARMEL__ 1 // CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_ARCH 8 // CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_ARCH_8A__ 1 // CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FEATURE_CRC32 1 // CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FEATURE_DIRECTED_ROUNDING 1 // CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FEATURE_NUMERIC_MAXMIN 1 // CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FP 0xe // CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FP16_ARGS 1 // CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FP16_FORMAT_IEEE 1 // CHECK-V8A-ALLOW-FP-INSTR-V8A-NOT: #define __ARM_FEATURE_DOTPROD // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2-a+nofp16fml+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2-a+nofp16+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2-a+fp16+nofp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8-a+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8-a+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.4-a+nofp16fml+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.4-a+nofp16+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.4-a+fp16+nofp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.4-a+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.4-a+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s // CHECK-FULLFP16-VECTOR-SCALAR: #define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1 // CHECK-FULLFP16-VECTOR-SCALAR: #define __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 1 // CHECK-FULLFP16-VECTOR-SCALAR: #define __ARM_FP 0xe // CHECK-FULLFP16-VECTOR-SCALAR: #define __ARM_FP16_FORMAT_IEEE 1 // +fp16fml without neon doesn't make sense as the fp16fml instructions all require SIMD. // However, as +fp16fml implies +fp16 there is a set of defines that we would expect. // RUN: %clang -target arm-none-linux-gnueabi -march=armv8-a+fp16fml -mfpu=vfp4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8-a+fp16 -mfpu=vfp4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.4-a+fp16fml -mfpu=vfp4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.4-a+fp16 -mfpu=vfp4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-SCALAR %s // CHECK-FULLFP16-SCALAR: #define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1 // CHECK-FULLFP16-SCALAR-NOT: #define __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 1 // CHECK-FULLFP16-SCALAR: #define __ARM_FP 0xe // CHECK-FULLFP16-SCALAR: #define __ARM_FP16_FORMAT_IEEE 1 // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2-a -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2-a+nofp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2-a+nofp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2-a+fp16fml+nofp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.4-a -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.4-a+nofp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.4-a+nofp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML-VECTOR-SCALAR %s // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.4-a+fp16fml+nofp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-NOFML-VECTOR-SCALAR %s // CHECK-FULLFP16-NOFML-VECTOR-SCALAR-NOT: #define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1 // CHECK-FULLFP16-NOFML-VECTOR-SCALAR-NOT: #define __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 1 // CHECK-FULLFP16-NOFML-VECTOR-SCALAR: #define __ARM_FP 0xe // CHECK-FULLFP16-NOFML-VECTOR-SCALAR: #define __ARM_FP16_FORMAT_IEEE 1 // RUN: %clang -target arm -march=armv8-a+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-SOFT %s // RUN: %clang -target arm -march=armv8-a+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-SOFT %s // RUN: %clang -target arm -march=armv8-a+fp16+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-SOFT %s // RUN: %clang -target arm -march=armv8-a+fp16fml+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-SOFT %s // RUN: %clang -target arm -march=armv8.4-a+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-SOFT %s // RUN: %clang -target arm -march=armv8.4-a+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-SOFT %s // RUN: %clang -target arm -march=armv8.4-a+fp16+fp16fml -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-SOFT %s // RUN: %clang -target arm -march=armv8.4-a+fp16fml+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-SOFT %s // CHECK-FULLFP16-SOFT-NOT: #define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC // CHECK-FULLFP16-SOFT-NOT: #define __ARM_FEATURE_FP16_VECTOR_ARITHMETIC // CHECK-FULLFP16-SOFT-NOT: #define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC // CHECK-FULLFP16-SOFT-NOT: #define __ARM_FEATURE_FP16_VECTOR_ARITHMETIC // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2a+dotprod -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-DOTPROD %s // CHECK-DOTPROD: #define __ARM_FEATURE_DOTPROD 1 // RUN: %clang -target armv8r-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8R %s // CHECK-V8R: #define __ARMEL__ 1 // CHECK-V8R: #define __ARM_ARCH 8 // CHECK-V8R: #define __ARM_ARCH_8R__ 1 // CHECK-V8R: #define __ARM_FEATURE_CRC32 1 // CHECK-V8R: #define __ARM_FEATURE_DIRECTED_ROUNDING 1 // CHECK-V8R: #define __ARM_FEATURE_NUMERIC_MAXMIN 1 // CHECK-V8R-NOT: #define __ARM_FP 0x // RUN: %clang -target armv8r-none-linux-gnueabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8R-ALLOW-FP-INSTR %s // RUN: %clang -target armv8r-none-linux-gnueabihf -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8R-ALLOW-FP-INSTR %s // CHECK-V8R-ALLOW-FP-INSTR: #define __ARMEL__ 1 // CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_ARCH 8 // CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_ARCH_8R__ 1 // CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_FEATURE_CRC32 1 // CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_FEATURE_DIRECTED_ROUNDING 1 // CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_FEATURE_NUMERIC_MAXMIN 1 // CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_FP 0xe // RUN: %clang -target armv7a-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7 %s // CHECK-V7: #define __ARMEL__ 1 // CHECK-V7: #define __ARM_ARCH 7 // CHECK-V7: #define __ARM_ARCH_7A__ 1 // CHECK-V7-NOT: __ARM_FEATURE_CRC32 // CHECK-V7-NOT: __ARM_FEATURE_NUMERIC_MAXMIN // CHECK-V7-NOT: __ARM_FEATURE_DIRECTED_ROUNDING // CHECK-V7-NOT: #define __ARM_FP 0x // RUN: %clang -target armv7a-none-linux-gnueabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7-ALLOW-FP-INSTR %s // RUN: %clang -target armv7a-none-linux-gnueabihf -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7-ALLOW-FP-INSTR %s // CHECK-V7-ALLOW-FP-INSTR: #define __ARMEL__ 1 // CHECK-V7-ALLOW-FP-INSTR: #define __ARM_ARCH 7 // CHECK-V7-ALLOW-FP-INSTR: #define __ARM_ARCH_7A__ 1 // CHECK-V7-ALLOW-FP-INSTR-NOT: __ARM_FEATURE_CRC32 // CHECK-V7-ALLOW-FP-INSTR-NOT: __ARM_FEATURE_NUMERIC_MAXMIN // CHECK-V7-ALLOW-FP-INSTR-NOT: __ARM_FEATURE_DIRECTED_ROUNDING // CHECK-V7-ALLOW-FP-INSTR: #define __ARM_FP 0xc // RUN: %clang -target armv7ve-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7VE %s // CHECK-V7VE: #define __ARMEL__ 1 // CHECK-V7VE: #define __ARM_ARCH 7 // CHECK-V7VE: #define __ARM_ARCH_7VE__ 1 // CHECK-V7VE: #define __ARM_ARCH_EXT_IDIV__ 1 // CHECK-V7VE-NOT: #define __ARM_FP 0x // RUN: %clang -target armv7ve-none-linux-gnueabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7VE-DEFAULT-ABI-SOFT %s // RUN: %clang -target armv7ve-none-linux-gnueabihf -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7VE-DEFAULT-ABI-SOFT %s // CHECK-V7VE-DEFAULT-ABI-SOFT: #define __ARMEL__ 1 // CHECK-V7VE-DEFAULT-ABI-SOFT: #define __ARM_ARCH 7 // CHECK-V7VE-DEFAULT-ABI-SOFT: #define __ARM_ARCH_7VE__ 1 // CHECK-V7VE-DEFAULT-ABI-SOFT: #define __ARM_ARCH_EXT_IDIV__ 1 // CHECK-V7VE-DEFAULT-ABI-SOFT: #define __ARM_FP 0xc // RUN: %clang -target x86_64-apple-macosx10.10 -arch armv7s -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7S %s // CHECK-V7S: #define __ARMEL__ 1 // CHECK-V7S: #define __ARM_ARCH 7 // CHECK-V7S: #define __ARM_ARCH_7S__ 1 // CHECK-V7S-NOT: __ARM_FEATURE_CRC32 // CHECK-V7S-NOT: __ARM_FEATURE_NUMERIC_MAXMIN // CHECK-V7S-NOT: __ARM_FEATURE_DIRECTED_ROUNDING // CHECK-V7S: #define __ARM_FP 0xe // RUN: %clang -target armv8a -mfloat-abi=hard -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-V8-BAREHF %s // CHECK-V8-BAREHF: #define __ARMEL__ 1 // CHECK-V8-BAREHF: #define __ARM_ARCH 8 // CHECK-V8-BAREHF: #define __ARM_ARCH_8A__ 1 // CHECK-V8-BAREHF: #define __ARM_FEATURE_CRC32 1 // CHECK-V8-BAREHF: #define __ARM_FEATURE_DIRECTED_ROUNDING 1 // CHECK-V8-BAREHF: #define __ARM_FEATURE_NUMERIC_MAXMIN 1 // CHECK-V8-BAREHP: #define __ARM_FP 0xe // CHECK-V8-BAREHF: #define __ARM_NEON__ 1 // CHECK-V8-BAREHF: #define __ARM_PCS_VFP 1 // CHECK-V8-BAREHF: #define __VFP_FP__ 1 // RUN: %clang -target armv8a -mfloat-abi=hard -mfpu=fp-armv8 -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-V8-BAREHF-FP %s // CHECK-V8-BAREHF-FP-NOT: __ARM_NEON__ 1 // CHECK-V8-BAREHP-FP: #define __ARM_FP 0xe // CHECK-V8-BAREHF-FP: #define __VFP_FP__ 1 // RUN: %clang -target armv8a -mfloat-abi=hard -mfpu=neon-fp-armv8 -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-V8-BAREHF-NEON-FP %s // RUN: %clang -target armv8a -mfloat-abi=hard -mfpu=crypto-neon-fp-armv8 -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-V8-BAREHF-NEON-FP %s // CHECK-V8-BAREHP-NEON-FP: #define __ARM_FP 0xe // CHECK-V8-BAREHF-NEON-FP: #define __ARM_NEON__ 1 // CHECK-V8-BAREHF-NEON-FP: #define __VFP_FP__ 1 // RUN: %clang -target armv8a -mnocrc -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-V8-NOCRC %s // CHECK-V8-NOCRC-NOT: __ARM_FEATURE_CRC32 1 // Check that -mhwdiv works properly for armv8/thumbv8 (enabled by default). // RUN: %clang -target armv8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8 %s // RUN: %clang -target armv8 -mthumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8 %s // RUN: %clang -target armv8-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8 %s // RUN: %clang -target armv8-eabi -mthumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8 %s // V8:#define __ARM_ARCH_EXT_IDIV__ 1 // RUN: %clang -target armv8 -mhwdiv=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV-V8 %s // RUN: %clang -target armv8 -mthumb -mhwdiv=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV-V8 %s // RUN: %clang -target armv8 -mhwdiv=thumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV-V8 %s // RUN: %clang -target armv8 -mthumb -mhwdiv=arm -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV-V8 %s // NOHWDIV-V8-NOT:#define __ARM_ARCH_EXT_IDIV__ // RUN: %clang -target armv8a -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8A %s // RUN: %clang -target armv8a -mthumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8A %s // V8A:#define __ARM_ARCH_EXT_IDIV__ 1 // V8A-NOT:#define __ARM_FP 0x // RUN: %clang -target armv8a-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8A-ALLOW-FP-INSTR %s // RUN: %clang -target armv8a-eabi -mthumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8A-ALLOW-FP-INSTR %s // RUN: %clang -target armv8a-eabihf -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8A-ALLOW-FP-INSTR %s // RUN: %clang -target armv8a-eabihf -mthumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8A-ALLOW-FP-INSTR %s // V8A-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1 // V8A-ALLOW-FP-INSTR:#define __ARM_FP 0xe // RUN: %clang -target armv8m.base-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M_BASELINE %s // V8M_BASELINE: #define __ARM_ARCH 8 // V8M_BASELINE: #define __ARM_ARCH_8M_BASE__ 1 // V8M_BASELINE: #define __ARM_ARCH_EXT_IDIV__ 1 // V8M_BASELINE-NOT: __ARM_ARCH_ISA_ARM // V8M_BASELINE: #define __ARM_ARCH_ISA_THUMB 1 // V8M_BASELINE: #define __ARM_ARCH_PROFILE 'M' // V8M_BASELINE-NOT: __ARM_FEATURE_CRC32 // V8M_BASELINE: #define __ARM_FEATURE_CMSE 1 // V8M_BASELINE-NOT: __ARM_FEATURE_DSP // V8M_BASELINE-NOT: __ARM_FP 0x{{.*}} // V8M_BASELINE-NOT: __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 // RUN: %clang -target armv8m.main-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M_MAINLINE %s // V8M_MAINLINE: #define __ARM_ARCH 8 // V8M_MAINLINE: #define __ARM_ARCH_8M_MAIN__ 1 // V8M_MAINLINE: #define __ARM_ARCH_EXT_IDIV__ 1 // V8M_MAINLINE-NOT: __ARM_ARCH_ISA_ARM // V8M_MAINLINE: #define __ARM_ARCH_ISA_THUMB 2 // V8M_MAINLINE: #define __ARM_ARCH_PROFILE 'M' // V8M_MAINLINE-NOT: __ARM_FEATURE_CRC32 // V8M_MAINLINE: #define __ARM_FEATURE_CMSE 1 // V8M_MAINLINE-NOT: __ARM_FEATURE_DSP // V8M_MAINLINE-NOT: #define __ARM_FP 0x // V8M_MAINLINE: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 // RUN: %clang -target armv8m.main-none-linux-gnueabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M-MAINLINE-ALLOW-FP-INSTR %s // RUN: %clang -target armv8m.main-none-linux-gnueabihf -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M-MAINLINE-ALLOW-FP-INSTR %s // V8M-MAINLINE-ALLOW-FP-INSTR: #define __ARM_ARCH 8 // V8M-MAINLINE-ALLOW-FP-INSTR: #define __ARM_ARCH_8M_MAIN__ 1 // V8M-MAINLINE-ALLOW-FP-INSTR: #define __ARM_ARCH_EXT_IDIV__ 1 // V8M-MAINLINE-ALLOW-FP-INSTR-NOT: __ARM_ARCH_ISA_ARM // V8M-MAINLINE-ALLOW-FP-INSTR: #define __ARM_ARCH_ISA_THUMB 2 // V8M-MAINLINE-ALLOW-FP-INSTR: #define __ARM_ARCH_PROFILE 'M' // V8M-MAINLINE-ALLOW-FP-INSTR-NOT: __ARM_FEATURE_CRC32 // V8M-MAINLINE-ALLOW-FP-INSTR-NOT: __ARM_FEATURE_DSP // V8M-MAINLINE-ALLOW-FP-INSTR: #define __ARM_FP 0xe // V8M-MAINLINE-ALLOW-FP-INSTR: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 // RUN: %clang -target arm-none-linux-gnu -march=armv8-m.main+dsp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M_MAINLINE_DSP %s // V8M_MAINLINE_DSP: #define __ARM_ARCH 8 // V8M_MAINLINE_DSP: #define __ARM_ARCH_8M_MAIN__ 1 // V8M_MAINLINE_DSP: #define __ARM_ARCH_EXT_IDIV__ 1 // V8M_MAINLINE_DSP-NOT: __ARM_ARCH_ISA_ARM // V8M_MAINLINE_DSP: #define __ARM_ARCH_ISA_THUMB 2 // V8M_MAINLINE_DSP: #define __ARM_ARCH_PROFILE 'M' // V8M_MAINLINE_DSP-NOT: __ARM_FEATURE_CRC32 // V8M_MAINLINE_DSP: #define __ARM_FEATURE_DSP 1 // V8M_MAINLINE_DSP-NOT: #define __ARM_FP 0x // V8M_MAINLINE_DSP: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 // RUN: %clang -target arm-none-linux-gnueabi -march=armv8-m.main+dsp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M-MAINLINE-DSP-ALLOW-FP-INSTR %s // V8M-MAINLINE-DSP-ALLOW-FP-INSTR: #define __ARM_ARCH 8 // V8M-MAINLINE-DSP-ALLOW-FP-INSTR: #define __ARM_ARCH_8M_MAIN__ 1 // V8M-MAINLINE-DSP-ALLOW-FP-INSTR: #define __ARM_ARCH_EXT_IDIV__ 1 // V8M-MAINLINE-DSP-ALLOW-FP-INSTR-NOT: __ARM_ARCH_ISA_ARM // V8M-MAINLINE-DSP-ALLOW-FP-INSTR: #define __ARM_ARCH_ISA_THUMB 2 // V8M-MAINLINE-DSP-ALLOW-FP-INSTR: #define __ARM_ARCH_PROFILE 'M' // V8M-MAINLINE-DSP-ALLOW-FP-INSTR-NOT: __ARM_FEATURE_CRC32 // V8M-MAINLINE-DSP-ALLOW-FP-INSTR: #define __ARM_FEATURE_DSP 1 // V8M-MAINLINE-DSP-ALLOW-FP-INSTR: #define __ARM_FP 0xe // V8M-MAINLINE-DSP-ALLOW-FP-INSTR: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 // RUN: %clang -target arm-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-DEFS %s // CHECK-DEFS:#define __ARM_PCS 1 // CHECK-DEFS:#define __ARM_SIZEOF_MINIMAL_ENUM 4 // CHECK-DEFS:#define __ARM_SIZEOF_WCHAR_T 4 // RUN: %clang -target arm-none-linux-gnu -fno-math-errno -fno-signed-zeros\ // RUN: -fno-trapping-math -fassociative-math -freciprocal-math\ // RUN: -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FASTMATH %s // RUN: %clang -target arm-none-linux-gnu -ffast-math -x c -E -dM %s -o -\ // RUN: | FileCheck -match-full-lines --check-prefix=CHECK-FASTMATH %s // CHECK-FASTMATH: #define __ARM_FP_FAST 1 // RUN: %clang -target arm-none-linux-gnu -fshort-wchar -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-SHORTWCHAR %s // CHECK-SHORTWCHAR:#define __ARM_SIZEOF_WCHAR_T 2 // RUN: %clang -target arm-none-linux-gnu -fshort-enums -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-SHORTENUMS %s // CHECK-SHORTENUMS:#define __ARM_SIZEOF_MINIMAL_ENUM 1 // Test that -mhwdiv has the right effect for a target CPU which has hwdiv enabled by default. // RUN: %clang -target armv7 -mcpu=cortex-a15 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=HWDIV %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-a15 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=HWDIV %s // RUN: %clang -target armv7 -mcpu=cortex-a15 -mhwdiv=arm -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=HWDIV %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-a15 -mhwdiv=thumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=HWDIV %s // HWDIV:#define __ARM_ARCH_EXT_IDIV__ 1 // RUN: %clang -target arm -mcpu=cortex-a15 -mhwdiv=thumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV %s // RUN: %clang -target arm -mthumb -mcpu=cortex-a15 -mhwdiv=arm -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV %s // RUN: %clang -target arm -mcpu=cortex-a15 -mhwdiv=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV %s // RUN: %clang -target arm -mthumb -mcpu=cortex-a15 -mhwdiv=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV %s // NOHWDIV-NOT:#define __ARM_ARCH_EXT_IDIV__ // Check that -mfpu works properly for Cortex-A7 (enabled by default). // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A7 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A7 %s // RUN: %clang -target armv7-none-linux-gnueabihf -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A7 %s // RUN: %clang -target armv7-none-linux-gnueabihf -mthumb -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A7 %s // DEFAULTFPU-A7:#define __ARM_FP 0xe // DEFAULTFPU-A7:#define __ARM_NEON__ 1 // DEFAULTFPU-A7:#define __ARM_VFPV4__ 1 // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a7 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A7 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a7 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A7 %s // FPUNONE-A7-NOT:#define __ARM_FP 0x{{.*}} // FPUNONE-A7-NOT:#define __ARM_NEON__ 1 // FPUNONE-A7-NOT:#define __ARM_VFPV4__ 1 // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a7 -mfpu=vfp4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NONEON-A7 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a7 -mfpu=vfp4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NONEON-A7 %s // NONEON-A7:#define __ARM_FP 0xe // NONEON-A7-NOT:#define __ARM_NEON__ 1 // NONEON-A7:#define __ARM_VFPV4__ 1 // Check that -mfpu works properly for Cortex-A5 (enabled by default). // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A5 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A5 %s // DEFAULTFPU-A5:#define __ARM_FP 0xe // DEFAULTFPU-A5:#define __ARM_NEON__ 1 // DEFAULTFPU-A5:#define __ARM_VFPV4__ 1 // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a5 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A5 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a5 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A5 %s // FPUNONE-A5-NOT:#define __ARM_FP 0x{{.*}} // FPUNONE-A5-NOT:#define __ARM_NEON__ 1 // FPUNONE-A5-NOT:#define __ARM_VFPV4__ 1 // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a5 -mfpu=vfp4-d16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NONEON-A5 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a5 -mfpu=vfp4-d16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NONEON-A5 %s // NONEON-A5:#define __ARM_FP 0xe // NONEON-A5-NOT:#define __ARM_NEON__ 1 // NONEON-A5:#define __ARM_VFPV4__ 1 // FIXME: add check for further predefines // Test whether predefines are as expected when targeting ep9312. // RUN: %clang -target armv4t -mcpu=ep9312 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A4T %s // A4T-NOT:#define __ARM_FEATURE_DSP // A4T-NOT:#define __ARM_FP 0x{{.*}} // Test whether predefines are as expected when targeting arm10tdmi. // RUN: %clang -target armv5 -mcpu=arm10tdmi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A5T %s // A5T-NOT:#define __ARM_FEATURE_DSP // A5T-NOT:#define __ARM_FP 0x{{.*}} // Test whether predefines are as expected when targeting cortex-a5i (soft FP ABI as default). // RUN: %clang -target armv7 -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A5 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A5 %s // A5:#define __ARM_ARCH 7 // A5:#define __ARM_ARCH_7A__ 1 // A5-NOT:#define __ARM_ARCH_EXT_IDIV__ // A5:#define __ARM_ARCH_PROFILE 'A' // A5-NOT:#define __ARM_DWARF_EH__ 1 // A5-NOT: #define __ARM_FEATURE_DIRECTED_ROUNDING // A5:#define __ARM_FEATURE_DSP 1 // A5-NOT: #define __ARM_FEATURE_NUMERIC_MAXMIN // A5-NOT:#define __ARM_FP 0x // Test whether predefines are as expected when targeting cortex-a5 (softfp FP ABI as default). // RUN: %clang -target armv7-eabi -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A5-ALLOW-FP-INSTR %s // RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A5-ALLOW-FP-INSTR %s // A5-ALLOW-FP-INSTR:#define __ARM_ARCH 7 // A5-ALLOW-FP-INSTR:#define __ARM_ARCH_7A__ 1 // A5-ALLOW-FP-INSTR-NOT:#define __ARM_ARCH_EXT_IDIV__ // A5-ALLOW-FP-INSTR:#define __ARM_ARCH_PROFILE 'A' // A5-ALLOW-FP-INSTR-NOT: #define __ARM_FEATURE_DIRECTED_ROUNDING // A5-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1 // A5-ALLOW-FP-INSTR-NOT: #define __ARM_FEATURE_NUMERIC_MAXMIN // A5-ALLOW-FP-INSTR:#define __ARM_FP 0xe // Test whether predefines are as expected when targeting cortex-a7 (soft FP ABI as default). // RUN: %clang -target armv7k -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A7 %s // RUN: %clang -target armv7k -mthumb -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A7 %s // A7:#define __ARM_ARCH 7 // A7:#define __ARM_ARCH_EXT_IDIV__ 1 // A7:#define __ARM_ARCH_PROFILE 'A' // A7-NOT:#define __ARM_DWARF_EH__ 1 // A7:#define __ARM_FEATURE_DSP 1 // A7-NOT:#define __ARM_FP 0x // Test whether predefines are as expected when targeting cortex-a7 (softfp FP ABI as default). // RUN: %clang -target armv7k-eabi -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A7-ALLOW-FP-INSTR %s // RUN: %clang -target armv7k-eabi -mthumb -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A7-ALLOW-FP-INSTR %s // A7-ALLOW-FP-INSTR:#define __ARM_ARCH 7 // A7-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1 // A7-ALLOW-FP-INSTR:#define __ARM_ARCH_PROFILE 'A' // A7-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1 // A7-ALLOW-FP-INSTR:#define __ARM_FP 0xe // Test whether predefines are as expected when targeting cortex-a7. // RUN: %clang -target x86_64-apple-darwin -arch armv7k -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV7K %s // ARMV7K:#define __ARM_ARCH 7 // ARMV7K:#define __ARM_ARCH_EXT_IDIV__ 1 // ARMV7K:#define __ARM_ARCH_PROFILE 'A' // ARMV7K:#define __ARM_DWARF_EH__ 1 // ARMV7K:#define __ARM_FEATURE_DSP 1 // ARMV7K:#define __ARM_FP 0xe // ARMV7K:#define __ARM_PCS_VFP 1 // Test whether predefines are as expected when targeting cortex-a8 (soft FP ABI as default). // RUN: %clang -target armv7 -mcpu=cortex-a8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A8 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-a8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A8 %s // A8-NOT:#define __ARM_ARCH_EXT_IDIV__ // A8:#define __ARM_FEATURE_DSP 1 // A8-NOT:#define __ARM_FP 0x // Test whether predefines are as expected when targeting cortex-a8 (softfp FP ABI as default). // RUN: %clang -target armv7-eabi -mcpu=cortex-a8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A8-ALLOW-FP-INSTR %s // RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-a8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A8-ALLOW-FP-INSTR %s // A8-ALLOW-FP-INSTR-NOT:#define __ARM_ARCH_EXT_IDIV__ // A8-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1 // A8-ALLOW-FP-INSTR:#define __ARM_FP 0xc // Test whether predefines are as expected when targeting cortex-a9 (soft FP as default). // RUN: %clang -target armv7 -mcpu=cortex-a9 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A9 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-a9 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A9 %s // A9-NOT:#define __ARM_ARCH_EXT_IDIV__ // A9:#define __ARM_FEATURE_DSP 1 // A9-NOT:#define __ARM_FP 0x // Test whether predefines are as expected when targeting cortex-a9 (softfp FP as default). // RUN: %clang -target armv7-eabi -mcpu=cortex-a9 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A9-ALLOW-FP-INSTR %s // RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-a9 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A9-ALLOW-FP-INSTR %s // A9-ALLOW-FP-INSTR-NOT:#define __ARM_ARCH_EXT_IDIV__ // A9-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1 // A9-ALLOW-FP-INSTR:#define __ARM_FP 0xe // Check that -mfpu works properly for Cortex-A12 (enabled by default). // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a12 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A12 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a12 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A12 %s // DEFAULTFPU-A12:#define __ARM_FP 0xe // DEFAULTFPU-A12:#define __ARM_NEON__ 1 // DEFAULTFPU-A12:#define __ARM_VFPV4__ 1 // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a12 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A12 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a12 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A12 %s // FPUNONE-A12-NOT:#define __ARM_FP 0x{{.*}} // FPUNONE-A12-NOT:#define __ARM_NEON__ 1 // FPUNONE-A12-NOT:#define __ARM_VFPV4__ 1 // Test whether predefines are as expected when targeting cortex-a12 (soft FP ABI as default). // RUN: %clang -target armv7 -mcpu=cortex-a12 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A12 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-a12 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A12 %s // A12:#define __ARM_ARCH 7 // A12:#define __ARM_ARCH_7A__ 1 // A12:#define __ARM_ARCH_EXT_IDIV__ 1 // A12:#define __ARM_ARCH_PROFILE 'A' // A12:#define __ARM_FEATURE_DSP 1 // A12-NOT:#define __ARM_FP 0x // Test whether predefines are as expected when targeting cortex-a12 (soft FP ABI as default). // RUN: %clang -target armv7-eabi -mcpu=cortex-a12 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A12-ALLOW-FP-INSTR %s // RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-a12 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A12-ALLOW-FP-INSTR %s // A12-ALLOW-FP-INSTR:#define __ARM_ARCH 7 // A12-ALLOW-FP-INSTR:#define __ARM_ARCH_7A__ 1 // A12-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1 // A12-ALLOW-FP-INSTR:#define __ARM_ARCH_PROFILE 'A' // A12-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1 // A12-ALLOW-FP-INSTR:#define __ARM_FP 0xe // Test whether predefines are as expected when targeting cortex-a15 (soft FP ABI as default). // RUN: %clang -target armv7 -mcpu=cortex-a15 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A15 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-a15 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A15 %s // A15:#define __ARM_ARCH_EXT_IDIV__ 1 // A15:#define __ARM_FEATURE_DSP 1 // A15-NOT:#define __ARM_FP 0x // Test whether predefines are as expected when targeting cortex-a15 (softfp ABI as default). // RUN: %clang -target armv7-eabi -mcpu=cortex-a15 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A15-ALLOW-FP-INSTR %s // RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-a15 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A15-ALLOW-FP-INSTR %s // A15-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1 // A15-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1 // A15-ALLOW-FP-INSTR:#define __ARM_FP 0xe // Check that -mfpu works properly for Cortex-A17 (enabled by default). // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a17 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A17 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a17 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A17 %s // DEFAULTFPU-A17:#define __ARM_FP 0xe // DEFAULTFPU-A17:#define __ARM_NEON__ 1 // DEFAULTFPU-A17:#define __ARM_VFPV4__ 1 // RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a17 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A17 %s // RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a17 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A17 %s // FPUNONE-A17-NOT:#define __ARM_FP 0x{{.*}} // FPUNONE-A17-NOT:#define __ARM_NEON__ 1 // FPUNONE-A17-NOT:#define __ARM_VFPV4__ 1 // Test whether predefines are as expected when targeting cortex-a17 (soft FP ABI as default). // RUN: %clang -target armv7 -mcpu=cortex-a17 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A17 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-a17 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A17 %s // A17:#define __ARM_ARCH 7 // A17:#define __ARM_ARCH_7A__ 1 // A17:#define __ARM_ARCH_EXT_IDIV__ 1 // A17:#define __ARM_ARCH_PROFILE 'A' // A17:#define __ARM_FEATURE_DSP 1 // A17-NOT:#define __ARM_FP 0x // Test whether predefines are as expected when targeting cortex-a17 (softfp FP ABI as default). // RUN: %clang -target armv7-eabi -mcpu=cortex-a17 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A17-ALLOW-FP-INSTR %s // RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-a17 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A17-ALLOW-FP-INSTR %s // A17-ALLOW-FP-INSTR:#define __ARM_ARCH 7 // A17-ALLOW-FP-INSTR:#define __ARM_ARCH_7A__ 1 // A17-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1 // A17-ALLOW-FP-INSTR:#define __ARM_ARCH_PROFILE 'A' // A17-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1 // A17-ALLOW-FP-INSTR:#define __ARM_FP 0xe // Test whether predefines are as expected when targeting swift (soft FP ABI as default). // RUN: %clang -target armv7s -mcpu=swift -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=SWIFT %s // RUN: %clang -target armv7s -mthumb -mcpu=swift -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=SWIFT %s // SWIFT:#define __ARM_ARCH_EXT_IDIV__ 1 // SWIFT:#define __ARM_FEATURE_DSP 1 // SWIFT-NOT:#define __ARM_FP 0xxE // Test whether predefines are as expected when targeting swift (softfp FP ABI as default). // RUN: %clang -target armv7s-eabi -mcpu=swift -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=SWIFT-ALLOW-FP-INSTR %s // RUN: %clang -target armv7s-eabi -mthumb -mcpu=swift -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=SWIFT-ALLOW-FP-INSTR %s // SWIFT-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1 // SWIFT-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1 // SWIFT-ALLOW-FP-INSTR:#define __ARM_FP 0xe // Test whether predefines are as expected when targeting ARMv8-A Cortex implementations (soft FP ABI as default) // RUN: %clang -target armv8 -mcpu=cortex-a32 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mthumb -mcpu=cortex-a32 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mcpu=cortex-a35 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mthumb -mcpu=cortex-a35 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mcpu=cortex-a53 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mthumb -mcpu=cortex-a53 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mcpu=cortex-a57 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mthumb -mcpu=cortex-a57 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mcpu=cortex-a72 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mthumb -mcpu=cortex-a72 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mcpu=cortex-a73 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mthumb -mcpu=cortex-a73 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // // RUN: %clang -target armv8 -mcpu=exynos-m3 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mthumb -mcpu=exynos-m3 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mcpu=exynos-m4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mthumb -mcpu=exynos-m4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mcpu=exynos-m5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // RUN: %clang -target armv8 -mthumb -mcpu=exynos-m5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s // ARMV8:#define __ARM_ARCH_EXT_IDIV__ 1 // ARMV8:#define __ARM_FEATURE_DSP 1 // ARMV8-NOT:#define __ARM_FP 0x // Test whether predefines are as expected when targeting ARMv8-A Cortex implementations (softfp FP ABI as default) // RUN: %clang -target armv8-eabi -mcpu=cortex-a32 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // RUN: %clang -target armv8-eabi -mthumb -mcpu=cortex-a32 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // RUN: %clang -target armv8-eabi -mcpu=cortex-a35 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // RUN: %clang -target armv8-eabi -mthumb -mcpu=cortex-a35 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // RUN: %clang -target armv8-eabi -mcpu=cortex-a53 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // RUN: %clang -target armv8-eabi -mthumb -mcpu=cortex-a53 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // RUN: %clang -target armv8-eabi -mcpu=cortex-a57 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // RUN: %clang -target armv8-eabi -mthumb -mcpu=cortex-a57 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // RUN: %clang -target armv8-eabi -mcpu=cortex-a72 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // RUN: %clang -target armv8-eabi -mthumb -mcpu=cortex-a72 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // RUN: %clang -target armv8-eabi -mcpu=cortex-a73 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // RUN: %clang -target armv8-eabi -mthumb -mcpu=cortex-a73 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // // RUN: %clang -target armv8-eabi -mcpu=exynos-m3 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // RUN: %clang -target armv8-eabi -mthumb -mcpu=exynos-m3 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // RUN: %clang -target armv8-eabi -mcpu=exynos-m4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // RUN: %clang -target armv8-eabi -mthumb -mcpu=exynos-m4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // RUN: %clang -target armv8-eabi -mcpu=exynos-m5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // RUN: %clang -target armv8-eabi -mthumb -mcpu=exynos-m5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s // ARMV8-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1 // ARMV8-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1 // ARMV8-ALLOW-FP-INSTR:#define __ARM_FP 0xe // Test whether predefines are as expected when targeting cortex-r4. // RUN: %clang -target armv7 -mcpu=cortex-r4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R4-ARM %s // R4-ARM-NOT:#define __ARM_ARCH_EXT_IDIV__ // R4-ARM:#define __ARM_FEATURE_DSP 1 // R4-ARM-NOT:#define __ARM_FP 0x{{.*}} // RUN: %clang -target armv7 -mthumb -mcpu=cortex-r4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R4-THUMB %s // R4-THUMB:#define __ARM_ARCH_EXT_IDIV__ 1 // R4-THUMB:#define __ARM_FEATURE_DSP 1 // R4-THUMB-NOT:#define __ARM_FP 0x{{.*}} // Test whether predefines are as expected when targeting cortex-r4f (soft FP ABI as default). // RUN: %clang -target armv7 -mcpu=cortex-r4f -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R4F-ARM %s // R4F-ARM-NOT:#define __ARM_ARCH_EXT_IDIV__ // R4F-ARM:#define __ARM_FEATURE_DSP 1 // R4F-ARM-NOT:#define __ARM_FP 0x // Test whether predefines are as expected when targeting cortex-r4f (softfp FP ABI as default). // RUN: %clang -target armv7-eabi -mcpu=cortex-r4f -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R4F-ARM-ALLOW-FP-INSTR %s // R4F-ARM-ALLOW-FP-INSTR-NOT:#define __ARM_ARCH_EXT_IDIV__ // R4F-ARM-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1 // R4F-ARM-ALLOW-FP-INSTR:#define __ARM_FP 0xc // RUN: %clang -target armv7 -mthumb -mcpu=cortex-r4f -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R4F-THUMB %s // R4F-THUMB:#define __ARM_ARCH_EXT_IDIV__ 1 // R4F-THUMB:#define __ARM_FEATURE_DSP 1 // R4F-THUMB-NOT:#define __ARM_FP 0x // RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-r4f -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R4F-THUMB-ALLOW-FP-INSTR %s // R4F-THUMB-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1 // R4F-THUMB-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1 // R4F-THUMB-ALLOW-FP-INSTR:#define __ARM_FP 0xc // Test whether predefines are as expected when targeting cortex-r5 (soft FP ABI as default). // RUN: %clang -target armv7 -mcpu=cortex-r5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R5 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-r5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R5 %s // R5:#define __ARM_ARCH_EXT_IDIV__ 1 // R5:#define __ARM_FEATURE_DSP 1 // R5-NOT:#define __ARM_FP 0x // Test whether predefines are as expected when targeting cortex-r5 (softfp FP ABI as default). // RUN: %clang -target armv7-eabi -mcpu=cortex-r5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R5-ALLOW-FP-INSTR %s // RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-r5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R5-ALLOW-FP-INSTR %s // R5-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1 // R5-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1 // R5-ALLOW-FP-INSTR:#define __ARM_FP 0xc // Test whether predefines are as expected when targeting cortex-r7 and cortex-r8 (soft FP ABI as default). // RUN: %clang -target armv7 -mcpu=cortex-r7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-r7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8 %s // RUN: %clang -target armv7 -mcpu=cortex-r8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8 %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-r8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8 %s // R7-R8:#define __ARM_ARCH_EXT_IDIV__ 1 // R7-R8:#define __ARM_FEATURE_DSP 1 // R7-R8-NOT:#define __ARM_FP 0x // Test whether predefines are as expected when targeting cortex-r7 and cortex-r8 (softfp FP ABI as default). // RUN: %clang -target armv7-eabi -mcpu=cortex-r7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8-ALLOW-FP-INSTR %s // RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-r7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8-ALLOW-FP-INSTR %s // RUN: %clang -target armv7-eabi -mcpu=cortex-r8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8-ALLOW-FP-INSTR %s // RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-r8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8-ALLOW-FP-INSTR %s // R7-R8-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1 // R7-R8-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1 // R7-R8-ALLOW-FP-INSTR:#define __ARM_FP 0xe // Test whether predefines are as expected when targeting cortex-m0. // RUN: %clang -target armv7 -mthumb -mcpu=cortex-m0 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M0-THUMB %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-m0plus -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M0-THUMB %s // RUN: %clang -target armv7 -mthumb -mcpu=cortex-m1 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M0-THUMB %s // RUN: %clang -target armv7 -mthumb -mcpu=sc000 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M0-THUMB %s // M0-THUMB-NOT:#define __ARM_ARCH_EXT_IDIV__ // M0-THUMB-NOT:#define __ARM_FEATURE_DSP // M0-THUMB-NOT:#define __ARM_FP 0x{{.*}} // Test whether predefines are as expected when targeting cortex-m3. // RUN: %clang -target armv7 -mthumb -mcpu=cortex-m3 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M3-THUMB %s // RUN: %clang -target armv7 -mthumb -mcpu=sc300 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M3-THUMB %s // M3-THUMB:#define __ARM_ARCH_EXT_IDIV__ 1 // M3-THUMB-NOT:#define __ARM_FEATURE_DSP // M3-THUMB-NOT:#define __ARM_FP 0x{{.*}} // Test whether predefines are as expected when targeting cortex-m4 (soft FP ABI as default). // RUN: %clang -target armv7 -mthumb -mcpu=cortex-m4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M4-THUMB %s // M4-THUMB:#define __ARM_ARCH_EXT_IDIV__ 1 // M4-THUMB:#define __ARM_FEATURE_DSP 1 // M4-THUMB-NOT:#define __ARM_FP 0x // Test whether predefines are as expected when targeting cortex-m4 (softfp ABI as default). // RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-m4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M4-THUMB-ALLOW-FP-INSTR %s // M4-THUMB-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1 // M4-THUMB-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1 // M4-THUMB-ALLOW-FP-INSTR:#define __ARM_FP 0x6 // Test whether predefines are as expected when targeting cortex-m7 (soft FP ABI as default). // RUN: %clang -target armv7 -mthumb -mcpu=cortex-m7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M7-THUMB %s // M7-THUMB:#define __ARM_ARCH_EXT_IDIV__ 1 // M7-THUMB:#define __ARM_FEATURE_DSP 1 // M7-THUMB-NOT:#define __ARM_FP 0x // M7-THUMB-NOT:#define __ARM_FPV5__ // Test whether predefines are as expected when targeting cortex-m7 (softfp FP ABI as default). // RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-m7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M7-THUMB-ALLOW-FP-INSTR %s // M7-THUMB-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1 // M7-THUMB-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1 // M7-THUMB-ALLOW-FP-INSTR:#define __ARM_FP 0xe // M7-THUMB-ALLOW-FP-INSTR:#define __ARM_FPV5__ 1 // Check that -mcmse (security extension) option works correctly for v8-M targets // RUN: %clang -target armv8m.base-none-linux-gnu -mcmse -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M_CMSE %s // RUN: %clang -target armv8m.main-none-linux-gnu -mcmse -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M_CMSE %s // RUN: %clang -target arm-none-linux-gnu -mcpu=cortex-m33 -mcmse -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M_CMSE %s // RUN: %clang -target arm -mcpu=cortex-m23 -mcmse -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M_CMSE %s // RUN: %clang -target arm-none-linux-gnu -mcpu=cortex-m55 -mcmse -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M_CMSE %s // V8M_CMSE-NOT: __ARM_FEATURE_CMSE 1 // V8M_CMSE: #define __ARM_FEATURE_CMSE 3 // Check that CMSE is not defined on architectures w/o support for security extension // RUN: %clang -target arm-arm-none-gnueabi -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOTV8M_CMSE %s // RUN: %clang -target armv8a-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOTV8M_CMSE %s // RUN: %clang -target armv8.1a-none-none-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOTV8M_CMSE %s // NOTV8M_CMSE-NOT: __ARM_FEATURE_CMSE // Check that -mcmse option gives error on non v8-M targets // RUN: not %clang -target arm-arm-none-eabi -mthumb -mcmse -mcpu=cortex-m7 -x c -E -dM %s -o - 2>&1 | FileCheck -match-full-lines --check-prefix=NOTV8MCMSE_OPT %s // NOTV8MCMSE_OPT: error: -mcmse is not supported for cortex-m7 // Test whether predefines are as expected when targeting v8m cores // RUN: %clang -target arm -mcpu=cortex-m23 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M23 %s // M23: #define __ARM_ARCH 8 // M23: #define __ARM_ARCH_8M_BASE__ 1 // M23: #define __ARM_ARCH_EXT_IDIV__ 1 // M23-NOT: __ARM_ARCH_ISA_ARM // M23: #define __ARM_ARCH_ISA_THUMB 1 // M23: #define __ARM_ARCH_PROFILE 'M' // M23-NOT: __ARM_FEATURE_CRC32 // M23-NOT: __ARM_FEATURE_DSP // M23-NOT: __ARM_FP 0x{{.*}} // M23-NOT: __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 // Test whether predefines are as expected when targeting m33 (soft FP ABI as default). // RUN: %clang -target arm -mcpu=cortex-m33 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M33 %s // M33: #define __ARM_ARCH 8 // M33: #define __ARM_ARCH_8M_MAIN__ 1 // M33: #define __ARM_ARCH_EXT_IDIV__ 1 // M33-NOT: __ARM_ARCH_ISA_ARM // M33: #define __ARM_ARCH_ISA_THUMB 2 // M33: #define __ARM_ARCH_PROFILE 'M' // M33-NOT: __ARM_FEATURE_CRC32 // M33: #define __ARM_FEATURE_DSP 1 // M33-NOT: #define __ARM_FP 0x // M33: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 // Test whether predefines are as expected when targeting m33 (softfp FP ABI as default). // RUN: %clang -target arm-eabi -mcpu=cortex-m33 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M33-ALLOW-FP-INSTR %s // M33-ALLOW-FP-INSTR: #define __ARM_ARCH 8 // M33-ALLOW-FP-INSTR: #define __ARM_ARCH_8M_MAIN__ 1 // M33-ALLOW-FP-INSTR: #define __ARM_ARCH_EXT_IDIV__ 1 // M33-ALLOW-FP-INSTR-NOT: __ARM_ARCH_ISA_ARM // M33-ALLOW-FP-INSTR: #define __ARM_ARCH_ISA_THUMB 2 // M33-ALLOW-FP-INSTR: #define __ARM_ARCH_PROFILE 'M' // M33-ALLOW-FP-INSTR-NOT: __ARM_FEATURE_CRC32 // M33-ALLOW-FP-INSTR: #define __ARM_FEATURE_DSP 1 // M33-ALLOW-FP-INSTR: #define __ARM_FP 0x6 // M33-ALLOW-FP-INSTR: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 // Test whether predefines are as expected when targeting cortex-m55 (softfp FP ABI as default). // RUN: %clang -target arm-eabi -mcpu=cortex-m55 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M55 %s // M55: #define __ARM_ARCH 8 // M55: #define __ARM_ARCH_8_1M_MAIN__ 1 // M55: #define __ARM_ARCH_EXT_IDIV__ 1 // M55-NOT: __ARM_ARCH_ISA_ARM // M55: #define __ARM_ARCH_ISA_THUMB 2 // M55: #define __ARM_ARCH_PROFILE 'M' // M55-NOT: __ARM_FEATURE_CRC32 // M55: #define __ARM_FEATURE_DSP 1 // M55: #define __ARM_FEATURE_MVE 3 // M55: #define __ARM_FP 0xe // M55: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 // Test whether predefines are as expected when targeting krait (soft FP as default). // RUN: %clang -target armv7 -mcpu=krait -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=KRAIT %s // RUN: %clang -target armv7 -mthumb -mcpu=krait -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=KRAIT %s // KRAIT:#define __ARM_ARCH_EXT_IDIV__ 1 // KRAIT:#define __ARM_FEATURE_DSP 1 // KRAIT-NOT:#define __ARM_VFPV4__ // Test whether predefines are as expected when targeting krait (softfp FP as default). // RUN: %clang -target armv7-eabi -mcpu=krait -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=KRAIT-ALLOW-FP-INSTR %s // RUN: %clang -target armv7-eabi -mthumb -mcpu=krait -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=KRAIT-ALLOW-FP-INSTR %s // KRAIT-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1 // KRAIT-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1 // KRAIT-ALLOW-FP-INSTR:#define __ARM_VFPV4__ 1 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M %s // CHECK-V81M: #define __ARM_ARCH 8 // CHECK-V81M: #define __ARM_ARCH_8_1M_MAIN__ 1 // CHECK-V81M: #define __ARM_ARCH_ISA_THUMB 2 // CHECK-V81M: #define __ARM_ARCH_PROFILE 'M' // CHECK-V81M-NOT: #define __ARM_FEATURE_DSP // CHECK-V81M-NOT: #define __ARM_FEATURE_MVE // CHECK-V81M-NOT: #define __ARM_FEATURE_SIMD32 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVE %s // CHECK-V81M-MVE: #define __ARM_FEATURE_DSP 1 // CHECK-V81M-MVE: #define __ARM_FEATURE_MVE 1 // CHECK-V81M-MVE: #define __ARM_FEATURE_SIMD32 1 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve.fp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVEFP %s // CHECK-V81M-MVEFP: #define __ARM_FEATURE_DSP 1 // CHECK-V81M-MVEFP: #define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1 // CHECK-V81M-MVEFP: #define __ARM_FEATURE_MVE 3 // CHECK-V81M-MVEFP: #define __ARM_FEATURE_SIMD32 1 // CHECK-V81M-MVEFP: #define __ARM_FPV5__ 1 // fpu=none/nofp discards mve.fp, but not mve/dsp // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve.fp+nofp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVEFP-NOFP %s // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve.fp -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVEFP-NOFP %s // CHECK-V81M-MVEFP-NOFP: #define __ARM_FEATURE_DSP 1 // CHECK-V81M-MVEFP-NOFP: #define __ARM_FEATURE_MVE 1 // nomve discards mve.fp // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve.fp+nomve -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVEFP-NOMVE %s // CHECK-V81M-MVEFP-NOMVE-NOT: #define __ARM_FEATURE_MVE // mve+fp doesn't imply mve.fp // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve+fp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVE-FP %s // CHECK-V81M-MVE-FP: #define __ARM_FEATURE_MVE 1 // nodsp discards both dsp and mve ... // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve+nodsp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVE-NODSP %s // CHECK-V81M-MVE-NODSP-NOT: #define __ARM_FEATURE_MVE // CHECK-V81M-MVE-NODSP-NOT: #define __ARM_FEATURE_DSP // ... and also mve.fp // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve.fp+nodsp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVE-NODSP %s // CHECK-V81M-MVE-NODSP-NOT: #define __ARM_FEATURE_MVE // CHECK-V81M-MVE-NODSP-NOT: #define __ARM_FEATURE_DSP // Test CDE (Custom Datapath Extension) feature test macros // RUN: %clang -target arm-arm-none-eabi -march=armv8m.main -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-V8M-NOCDE %s // CHECK-V8M-NOCDE-NOT: #define __ARM_FEATURE_CDE // CHECK-V8M-NOCDE-NOT: #define __ARM_FEATURE_CDE_COPROC // RUN: %clang -target arm-arm-none-eabi -march=armv8m.main+cdecp0+cdecp1+cdecp7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8M-CDE-MASK1 %s // CHECK-V8M-CDE-MASK1: #define __ARM_FEATURE_CDE 1 // CHECK-V8M-CDE-MASK1: #define __ARM_FEATURE_CDE_COPROC 0x83 // RUN: %clang -target arm-arm-none-eabi -march=armv8m.main+cdecp0+cdecp1+cdecp2+cdecp3+cdecp4+cdecp5+cdecp6+cdecp7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8M-CDE-MASK2 %s // CHECK-V8M-CDE-MASK2: #define __ARM_FEATURE_CDE 1 // CHECK-V8M-CDE-MASK2: #define __ARM_FEATURE_CDE_COPROC 0xff // RUN: %clang -target armv8.1a-none-none-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81A %s // CHECK-V81A: #define __ARM_ARCH 8 // CHECK-V81A: #define __ARM_ARCH_8_1A__ 1 // CHECK-V81A: #define __ARM_ARCH_PROFILE 'A' // CHECK-V81A: #define __ARM_FEATURE_QRDMX 1 // CHECK-V81A: #define __ARM_FP 0xe // RUN: %clang -target armv8.2a-none-none-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V82A %s // CHECK-V82A: #define __ARM_ARCH 8 // CHECK-V82A: #define __ARM_ARCH_8_2A__ 1 // CHECK-V82A: #define __ARM_ARCH_PROFILE 'A' // CHECK-V82A: #define __ARM_FEATURE_QRDMX 1 // CHECK-V82A: #define __ARM_FP 0xe // RUN: %clang -target armv8.3a-none-none-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V83A %s // CHECK-V83A: #define __ARM_ARCH 8 // CHECK-V83A: #define __ARM_ARCH_8_3A__ 1 // CHECK-V83A: #define __ARM_ARCH_PROFILE 'A' // RUN: %clang -target armv8.4a-none-none-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V84A %s // CHECK-V84A: #define __ARM_ARCH 8 // CHECK-V84A: #define __ARM_ARCH_8_4A__ 1 // CHECK-V84A: #define __ARM_ARCH_PROFILE 'A' // RUN: %clang -target armv8.5a-none-none-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V85A %s // CHECK-V85A: #define __ARM_ARCH 8 // CHECK-V85A: #define __ARM_ARCH_8_5A__ 1 // CHECK-V85A: #define __ARM_ARCH_PROFILE 'A' // RUN: %clang -target armv8.6a-none-none-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V86A %s // CHECK-V86A: #define __ARM_ARCH 8 // CHECK-V86A: #define __ARM_ARCH_8_6A__ 1 // CHECK-V86A: #define __ARM_ARCH_PROFILE 'A' // RUN: %clang -target arm-none-none-eabi -march=armv7-m -mfpu=softvfp -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SOFTVFP %s // CHECK-SOFTVFP-NOT: #define __ARM_FP 0x
the_stack_data/282117.c
/**************************************************************************** This is a filter that accepts text and some IBM/Epson print codes and produces output suitable for an HP laserjet printer. Author B.Blatchley ****************************************************************************/ #include <stdio.h> #include <fcntl.h> #include <string.h> #define FALSE 0 #define TRUE (!FALSE) static float cpi = 10.0; static lines = 66; static int n, m; static int feed = 0; static int wide = 0; static int DECI = 7416; static int envelope = 0; static int bottomtray = 0; #define FF 12 #define LF 10 #define RELATIVE 0 #define ABSOLUTE 1 #define TAB '\011' #define LINE_FEED '\012' #define FORM_FEED '\014' #define CTRL_O '\017' #define CTRL_R '\022' #define ESCAPE '\033' #define S_START 1 #define S_START1 11 #define S_START2 12 #define S_ESCAPE 2 #define S_ESCAPE1 21 #define S_ESCAPE2 22 #define S_ESCAPE3 23 #define S_ESCAPE4 24 #define S_ESCAPE5 25 #define REMCHAR *rl++ = c; *rl = 0 static char rline[100]; static char *rl; static top_margin = 0; static page_feed = FALSE; /****************************************************************************** A shell around the getc function. ******************************************************************************/ int nextc() { return(getchar()); } /****************************************************************************** Line feed ******************************************************************************/ line_feed() { if ( feed == 1) { /* Feed only if there are more chars */ feed = 0; if ( n >= lines || page_feed) { putchar('\f'); page_feed = FALSE; } n %= lines; m = n * (DECI / (lines + 1)); printf("\033&a0h%dV", (m + top_margin)); } } /****************************************************************************** Print Unrecognized text... ******************************************************************************/ int dot() { if ( feof(stdin)) return; line_feed(); rl = rline; while ( *rl != 0) { putchar(*rl++); if ( wide == 1) putchar(' '); } rl = rline; *rl = 0; } /****************************************************************************** An IBM Print Code Recognizer, with Brett's imaging extentions. At EOF when everything has been recognized. ******************************************************************************/ int translate_and_print() { static int state = S_START; int done = FALSE; int c = nextc(); while ( !done) { switch (state) { case S_START: rl = rline; switch (c) { case LINE_FEED: feed = 1; n++; break; case FORM_FEED: n = 0; putchar(FF); break; case CTRL_R: printf("\033(s10H"); /* cpi = 10 normal */ state = S_START; break; case CTRL_O: printf("\033(s16H"); /* cpi = 16 condensed */ state = S_START; break; case ESCAPE: REMCHAR; state = S_ESCAPE; break; default: REMCHAR; dot(); break; } break; case S_ESCAPE: switch (c) { case '0': lines = 88; state = S_START; break; case '2': lines = 66; state = S_START; break; case 'E': printf("\033(s3B"); /* Boldface on */ state = S_START; break; case 'F': printf("\033(s0B"); /* Boldface off */ state = S_START; break; case 'P': REMCHAR; state = S_ESCAPE1; break; case 'M': printf("\033(s12H"); /* cpi = 12.0 */ state = S_START; break; case 'W': REMCHAR; state = S_ESCAPE2; break; case '-': REMCHAR; state = S_ESCAPE3; break; case '\176': REMCHAR; state = S_ESCAPE4; break; default: REMCHAR; dot(); state = S_START; break; } break; case S_ESCAPE1: switch (c) { case CTRL_O: printf("\033(s16H"); /* cpi = 16 condensed */ state = S_START; break; case CTRL_R: printf("\033(s10H"); /* cpi = 10 normal */ state = S_START; break; default: REMCHAR; dot(); state = S_START; break; } break; case S_ESCAPE2: switch (c) { case 0: wide = 0; printf("\033(s%2.2fH", cpi); /* Double wide off */ state = S_START; break; case 1: wide = 1; printf("\033(s%2.2fH", (cpi/2.0)); /* Double wide off */ state = S_START; break; default: REMCHAR; dot(); state = S_START; break; } break; case S_ESCAPE3: switch (c) { case '0': printf("\033&d@D"); /* Underline Off */ state = S_START; break; case '1': printf("\033&d0D"); /* Underline On */ state = S_START; break; default: REMCHAR; dot(); state = S_START; break; } break; case S_ESCAPE4: REMCHAR; if ( c == '2') state = S_ESCAPE5; else { dot(); state = S_START; } break; case S_ESCAPE5: switch (c) { case 0: printf("\033(s0S"); /* Reverse off (italics) */ state = S_START; break; case 1: printf("\033(s1S"); /* Reverse on (italics) */ state = S_START; break; default: REMCHAR; dot(); state = S_START; break; } } if ( (c = nextc()) == EOF) done = TRUE; } dot(); } main( argc, argv) int argc; char *argv[]; { int nn, n, list = 0, reset = 0; for ( nn = 1; nn < argc; nn++) { if ( !strncmp( "-b", argv[nn], 2)) bottomtray = 1; else if ( !strncmp( "-B", argv[nn], 2)) bottomtray = 1; else if ( !strncmp( "-e", argv[nn], 2)) envelope = 1; else if ( !strncmp( "-E", argv[nn], 2)) envelope = 1; } if (bottomtray == 1) printf("\033&l4H"); /* Feed from BOTTOM tray */ else printf("\033&l1H"); /* Feed from TOP tray */ if (envelope == 1) { printf("\033&l81A"); /* Select Envelopes */ printf("\033&l1O"); /* Landscape Mode */ lines = 21; DECI = 2510; } else { printf("\033&12A"); /* Select Normal Paper */ printf("\033&l0O"); /* Portrait Mode */ lines = 66; DECI = 7416; } n = 0; /* line counter */ m = n * (DECI / (lines + 1)); printf("\033&a0h%dV", m); /* Home HP cursor */ printf("\033(11U"); /* PC-8 font (11U is Danish) */ printf("\033(s0B"); /* Lightweight stroke */ feed = 1; translate_and_print(); printf("\033&a0v0H \f\033E"); printf("\033&l0O"); /* Portrait Mode */ printf("\033&12A"); /* Select Normal Paper */ printf("\033*c1F"); /* Delete ALL temporary soft fonts */ }
the_stack_data/198580780.c
#include <openssl/ssl.h> #include <openssl/opensslv.h> int main() { long ver; /* check openssl version */ SSL_SESSION_new(); if (OPENSSL_VERSION_NUMBER < 0x00907000L) { printf("OpenSSL version 0.9.7 or better is required!\n"); return 1; } /* test linking to crypto */ ver = SSLeay(); return 0; }
the_stack_data/151707008.c
#include <sys/time.h> #include <sys/resource.h> #include <stdio.h> int main() { int ret; ret = getpriority(PRIO_PROCESS, 0); printf("nice value is %d\n", ret); return 0; }