file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/148578948.c | /* gcc -m32 flush.c -o flush -fno-stack-protector -Wno-deprecated-declarations -std=c90 -D_FORTIFY_SOURCE=0 -no-pie -fno-pic
Arch: i386-32-little
RELRO: Partial RELRO
Stack: No canary found
NX: NX enabled
PIE: No PIE (0x8048000)
*/
#include <stdio.h>
#include <stdlib.h>
void win(unsigned int pipe0, unsigned int pipe1, unsigned int pipe2)
{
char flag[48];
FILE *file = fopen("flag.txt", "r");
if (file == NULL) {
puts("Flag File is Missing.");
exit(0);
}
fgets(flag, sizeof(flag), file);
if (pipe0 == 0xE91C && pipe1 == 0xB055 && pipe2 == 0xBA771E)
{
fputs("\nCongrats Mario! You navigated the pipes correctly to find the princess!\n", stdout);
fputs("Here's your flag: ", stdout);
fputs(flag, stdout);
}
}
/* NOTE: A good plumber always cleans up. */
void vuln()
{
char buf[8];
fputs("Where to? : ", stdout);
fflush(stdout);
gets(buf);
}
int main(void)
{
setvbuf(stdout, NULL, _IOFBF, 0);
puts("Hello Mario - Navigate the pipes to find the princess... IF YOU DARE!");
fflush(stdout);
vuln();
return 0;
} |
the_stack_data/197719.c | // RUN: %clang_cc1 -no-opaque-pointers -emit-llvm-bc -disable-llvm-passes -o %t.bc %s
// RUN: llvm-dis %t.bc -o - | FileCheck %s
// Test case for PR45426. Make sure we do not crash while writing bitcode
// containing a simplify-able fneg constant expression. Check that the created
// bitcode file can be disassembled and has the constant expressions simplified.
//
// CHECK-LABEL define i32 @main()
// CHECK: entry:
// CHECK-NEXT: %retval = alloca i32
// CHECK-NEXT: store i32 0, i32* %retval
// CHECK-NEXT: [[LV:%.*]] = load float*, float** @c
// CHECK-NEXT: store float 1.000000e+00, float* [[LV]], align 4
// CHECK-NEXT: ret i32 -1
int a[], b;
float *c;
int main(void) {
return -(*c = &b != a);
}
|
the_stack_data/125140170.c | /* { dg-do compile { target { powerpc*-*-* } } } */
/* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
/* { dg-require-effective-target powerpc_vsx_ok } */
/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power7" } } */
/* { dg-options "-O1 -mvsx -mlra -mcpu=power7 -mlong-double-128" } */
/* PR 67808: LRA ICEs on simple double to long double conversion test case */
void
dfoo (long double *ldb1, double *db1)
{
*ldb1 = *db1;
}
long double
dfoo2 (double *db1)
{
return *db1;
}
long double
dfoo3 (double x)
{
return x;
}
void
ffoo (long double *ldb1, float *db1)
{
*ldb1 = *db1;
}
long double
ffoo2 (float *db1)
{
return *db1;
}
long double
ffoo3 (float x)
{
return x;
}
/* { dg-final { scan-assembler "xxlxor" } } */
|
the_stack_data/1227.c | #include<stdio.h>
void main(){
int n,i,marks,count;
printf("Enter the total no of students in the class :");
scanf("%d",&n);
count=0;
i=1;
while(i>n){
}
}
|
the_stack_data/151691.c | #include <stdio.h>
#include <stdlib.h>
/*
Escreva um programa para ler as notas da primeira e segunda avaliacao de um aluno. Calcule e imprima a media semestral. O programa deverá aceitar apenas as notas no intervalo de 0 ate 10. Cada nota deve ser validada separadamente. Ao final, deve ser impressa a mensagem "novo calculo? (1-sim 2-nao)", solicitando ao usuario que informe um cdigo de ( 1 ou 2), indicando se ele deseja ou nao executar o programa novamente. Se for informado o codigo 1, deve ser repetida a execucao de todo o programa para permitir um novo calculo, se for informado o codigo 2 o programa deve ser encerrado.
*/
int main(int argc, char const *argv[])
{
float n1=0, n2=0, media=0;
int opcao;
printf("\n###########################################");
printf("\n############# MEDIA DO ALUNO ##############");
printf("\n###########################################");
do
{
do
{
printf("\nDigite a 1a. nota (0 ate 10): ");
scanf("%f", &n1);
if(n1 <0 || n1 >10){
printf("NOTA INCORRETA!");
}
} while (n1 <0 || n1 >10 );
do
{
printf("\nDigite a 2a. nota (0 ate 10): ");
scanf("%f", &n2);
if(n2 <0 || n2 >10){
printf("NOTA INCORRETA!");
}
} while (n2 <0 || n2 >10 );
media = (n1 + n2) / 2;
printf("\n\nMedia semestral do aluno: %.2f", media);
do
{
printf("\nNovo calclulo? (1-sim 2-nao): ");
scanf("%d", &opcao);
if(opcao !=1 && opcao !=2){
printf("\nOPCAO INVALIDA!");
}
} while (opcao !=1 && opcao !=2);
} while (opcao == 1);
printf("\n\nFIM DO PROGRAMA!!!");
return 0;
}
|
the_stack_data/59320.c | /*
El uso de funciones aumenta la velocidad del programa.
En este programa usaremos las llamadas funciones en linea.
Aunque su nombre no adecuado ya que el preprocesador expande o
sustiye la expresion cada vez que es llamada.
El compilador inserta el codigo en el
punto en que esta funcion en linea o macros con argumentos se llama.
*/
/*
En estas lineas definimos la funcion creada por el usuario. La forma general es:
#define NOMBRE_MACRO(parametros_NO_tipo) expresion-texto
*/
/*
El ejercicio del estudiante consiste en implementar, al menos, cinco funciones en línea y
posteriormente, implementarlas como funciones creadas por el usuario.
*/
#include <stdio.h>
#define fesp(x) (x*x +2*x - 1)
void main(){
float x;
for (x =0.0; x<= 6.5; x +=0.5)
{
printf("f(%.1f) = %6.2f\n", x, fesp(x));
}
}
/*
El problema con este tipo de macros es que se consume
mucha memoria ya que la toda invocacion del macro
representa una copia de la expresion completa que
representa.
*/
|
the_stack_data/29826772.c |
// A simple example showing some comparison operators
#include <stdio.h>
int main()
{
int number1 , number2;
printf("Enter the number1 number to compare.\n");
scanf("%d",&number1);
printf("Enter the number2 number to compare.\n");
scanf("%d",&number2);
printf("number1 > number2 has the value %d\n", number1 > number2);
printf("number1 < number2 has the value %d\n", number1 < number2);
printf("number1 == number2 has the value %d\n", number1 == number2);
return 0;
}
|
the_stack_data/76700594.c | /*
AUTHOR: FABER BERNARDO JUNIOR
DATE: 11/30/2021
PROGRAM SYNOPSIS: Compute the imput of a parallel series of resistors
ENTRY DATA: pararellelSeries
OUTPUT DATA: result
*/
#include <math.h>
#include <stdio.h>
int main(void) {
float resistor1, resistor2, parallelSeries, iterar;
double result, parallelResult;
printf("Enter the number at series that you want\n");
scanf("%f", ¶llelSeries);
while (parallelSeries <= 0) {
printf("Enter the number greatest them 0\n");
scanf("%f", ¶llelSeries);
}
printf("\nEnter the first resistor value\n");
scanf("%f", &resistor1);
for (iterar = 1; iterar <= parallelSeries; iterar++) {
printf("\nEnter the second resistor value\n");
scanf("%f", &resistor2);
parallelResult = (resistor1 + resistor2) / (resistor1 * resistor2);
printf("\nThe value at parallel until now is %f\n", parallelResult);
resistor1 = parallelResult;
printf("\nThe new value at the resistor is %f\n", resistor1);
}
result = parallelResult;
if (result <= 0.009) {
result = result * 1000;
printf("\nThe result is %.3f mΩ \n", result);
} else if (result >= 1000) {
result = result / 1000;
printf("\nThe result is %.3f KΩ \n", result);
} else {
printf("\nThe result is %.3f Ω \n", result);
}
return 0;
} |
the_stack_data/247018855.c | #include<stdio.h>
int main(void)
{
int row, col, cnt=1;
/*
for(row=1; row<=10; row++)
{
for(col=1; col<=10; col++)
{
//printf("\nrow=%d col=%d", row, col);
//printf("%5d", row*col); // print table
printf("%5d", row+(col-1)*10);
}
printf("\n");// go to next row
//getchar();
}
*/
for(row=1; row<=5; row++)
{
for(col=1; col<=row; col++)
{
//printf("%5d", row);
//printf("%5d", col);
//printf("%5c", 64+col);
//printf("%5c", 64+row);
//printf(" %c ", '*');
//printf(" * ");
printf("%5d", cnt++);
}
printf("\n");// go to next row
}
return 0;
}
|
the_stack_data/150519.c | /* $FreeBSD: src/tools/test/malloc/main.c,v 1.2 2002/01/02 06:42:34 kbyanc Exp $ */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
u_long NBUCKETS = 2000;
u_long NOPS = 200000;
u_long NSIZE = (16*1024);
char **foo;
int
main(int argc, char **argv)
{
int i,j,k;
if (argc > 1) NOPS = strtoul(argv[1],0,0);
if (argc > 2) NBUCKETS = strtoul(argv[2],0,0);
if (argc > 3) NSIZE = strtoul(argv[3],0,0);
printf("BRK(0)=%x ",sbrk(0));
foo = malloc (sizeof *foo * NBUCKETS);
memset(foo,0,sizeof *foo * NBUCKETS);
for (i = 1; i <= 4096; i *= 2) {
for (j = 0 ; j < 40960/i && j < NBUCKETS; j++) {
foo[j] = malloc(i);
}
for (j = 0 ; j < 40960/i && j < NBUCKETS; j++) {
free(foo[j]);
foo[j] = 0;
}
}
for (i = 0 ; i < NOPS ; i++) {
j = random() % NBUCKETS;
k = random() % NSIZE;
foo[j] = realloc(foo[j], k & 1 ? 0 : k);
if (k & 1 || k == 0) {
/*
* Workaround because realloc return bogus pointer rather than
* NULL if passed zero length.
*/
foo[j] = 0;
}
if (foo[j])
foo[j][0] = 1;
}
printf("BRK(1)=%x ",sbrk(0));
for (j = 0 ; j < NBUCKETS ; j++) {
if (foo[j]) {
free(foo[j]);
foo[j] = 0;
}
}
printf("BRK(2)=%x NOPS=%lu NBUCKETS=%lu NSIZE=%lu\n",
sbrk(0),NOPS,NBUCKETS,NSIZE);
return 0;
}
|
the_stack_data/31962.c | #include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#define COUNT_TRIGGER 10
#define COUNT_LIMIT 12
int count = 0;
int thread_ids[3] = { 0, 1, 2 };
pthread_mutex_t count_mutex;
pthread_cond_t count_cv;
void* add_count(void* t) {
int tid = (long)t;
for (int i = 0; i < COUNT_TRIGGER; ++i) {
pthread_mutex_lock(&count_mutex);
++count;
if (COUNT_LIMIT == count)
pthread_cond_signal(&count_cv);
pthread_mutex_unlock(&count_mutex);
sleep(1);
}
pthread_exit(0);
}
void* watch_count(void* t) {
int tid = (long)t;
pthread_mutex_lock(&count_mutex);
if (count < COUNT_LIMIT) {
pthread_cond_wait(&count_cv, &count_mutex);
}
pthread_mutex_unlock(&count_mutex);
pthread_exit(0);
}
int main(int argc, char** argv) {
int tid1 = 1, tid2 = 2, tid3 = 3;
pthread_t threads[3];
pthread_attr_t attr;
pthread_mutex_init(&count_mutex, 0);
pthread_cond_init(&count_cv, 0);
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
pthread_create(&threads[0], &attr, watch_count, (void *)tid1);
pthread_create(&threads[1], &attr, add_count, (void *)tid2);
pthread_create(&threads[2], &attr, add_count, (void *)tid3);
for (int i = 0; i < 3; ++i)
pthread_join(threads[i], 0);
pthread_attr_destroy(&attr);
pthread_mutex_destroy(&count_mutex);
pthread_cond_destroy(&count_cv);
return 0;
} |
the_stack_data/54826678.c | /*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2013 Blender Foundation
* All rights reserved.
*/
/** \file
* \ingroup bli
*/
#include <stdlib.h>
#if defined(__GLIBC__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 8))
/* do nothing! */
#else
# include "BLI_utildefines.h"
# include "BLI_sort.h"
# ifdef min /* for msvc */
# undef min
# endif
/* Maintained by FreeBSD. */
/* clang-format off */
/**
* qsort, copied from FreeBSD source.
* with only very minor edits, see:
* http://github.com/freebsd/freebsd/blob/master/sys/libkern/qsort.c
*
* \note modified to use glibc arg order for callbacks.
*/
BLI_INLINE char *med3(char *, char *, char *, BLI_sort_cmp_t, void *);
BLI_INLINE void swapfunc(char *, char *, int, int);
#define min(a, b) (a) < (b) ? (a) : (b)
#define swapcode(TYPE, parmi, parmj, n) \
{ \
long i = (n) / sizeof(TYPE); \
TYPE *pi = (TYPE *) (parmi); \
TYPE *pj = (TYPE *) (parmj); \
do { \
TYPE t = *pi; \
*pi++ = *pj; \
*pj++ = t; \
} while (--i > 0); \
}
#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \
es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;
BLI_INLINE void swapfunc(char *a, char *b, int n, int swaptype)
{
if (swaptype <= 1)
swapcode(long, a, b, n)
else
swapcode(char, a, b, n)
}
#define swap(a, b) \
if (swaptype == 0) { \
long t = *(long *)(a); \
*(long *)(a) = *(long *)(b);\
*(long *)(b) = t; \
} else \
swapfunc(a, b, es, swaptype)
#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype)
#define CMP(t, x, y) (cmp((x), (y), (t)))
BLI_INLINE char *med3(char *a, char *b, char *c, BLI_sort_cmp_t cmp, void *thunk)
{
return CMP(thunk, a, b) < 0 ?
(CMP(thunk, b, c) < 0 ? b : (CMP(thunk, a, c) < 0 ? c : a )) :
(CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c ));
}
/**
* Quick sort re-entrant.
*/
void BLI_qsort_r(void *a, size_t n, size_t es, BLI_sort_cmp_t cmp, void *thunk)
{
char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
int d, r, swaptype, swap_cnt;
loop:
SWAPINIT(a, es);
swap_cnt = 0;
if (n < 7) {
for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es) {
for (pl = pm;
pl > (char *)a && CMP(thunk, pl - es, pl) > 0;
pl -= es)
{
swap(pl, pl - es);
}
}
return;
}
pm = (char *)a + (n / 2) * es;
if (n > 7) {
pl = (char *)a;
pn = (char *)a + (n - 1) * es;
if (n > 40) {
d = (n / 8) * es;
pl = med3(pl, pl + d, pl + 2 * d, cmp, thunk);
pm = med3(pm - d, pm, pm + d, cmp, thunk);
pn = med3(pn - 2 * d, pn - d, pn, cmp, thunk);
}
pm = med3(pl, pm, pn, cmp, thunk);
}
swap((char *)a, pm);
pa = pb = (char *)a + es;
pc = pd = (char *)a + (n - 1) * es;
for (;;) {
while (pb <= pc && (r = CMP(thunk, pb, a)) <= 0) {
if (r == 0) {
swap_cnt = 1;
swap(pa, pb);
pa += es;
}
pb += es;
}
while (pb <= pc && (r = CMP(thunk, pc, a)) >= 0) {
if (r == 0) {
swap_cnt = 1;
swap(pc, pd);
pd -= es;
}
pc -= es;
}
if (pb > pc) {
break;
}
swap(pb, pc);
swap_cnt = 1;
pb += es;
pc -= es;
}
if (swap_cnt == 0) { /* Switch to insertion sort */
for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es) {
for (pl = pm;
pl > (char *)a && CMP(thunk, pl - es, pl) > 0;
pl -= es)
{
swap(pl, pl - es);
}
}
return;
}
pn = (char *)a + n * es;
r = min(pa - (char *)a, pb - pa);
vecswap((char *)a, pb - r, r);
r = min(pd - pc, pn - pd - es);
vecswap(pb, pn - r, r);
if ((r = pb - pa) > es) {
BLI_qsort_r(a, r / es, es, cmp, thunk);
}
if ((r = pd - pc) > es) {
/* Iterate rather than recurse to save stack space */
a = pn - r;
n = r / es;
goto loop;
}
}
/* clang-format on */
#endif /* __GLIBC__ */
|
the_stack_data/531773.c | void mensagem(){
printf("Bem vindo\n");
}
int soma(int num1, int num2){
return num1+num2;
}
int multiplicacao(int num1, int num2){
return num1 * num2;
} |
the_stack_data/32950920.c | /*@ begin PerfTuning (
def build
{
arg build_command = 'gcc -O3 -fopenmp ';
arg libs = '-lm -lrt';
}
def performance_counter
{
arg repetitions = 35;
}
def performance_params
{
# param PERM[] = [
# ['i','j'],
# ['j','i'],
# ];
param T2_I[] = [1,16,32,64,128,256,512];
param T2_J[] = [1,16,32,64,128,256,512];
param T2_Ia[] = [1,64,128,256,512,1024,2048];
param T2_Ja[] = [1,64,128,256,512,1024,2048];
param U2_I[] = range(1,31);
param U2_J[] = range(1,31);
param RT2_I[] = [1,8,32];
param RT2_J[] = [1,8,32];
param SCR[] = [False,True];
param VEC2[] = [False,True];
param OMP[] = [False,True];
param U1_J[] = range(1,31);
param VEC1[] = [False,True];
constraint tileI2 = ((T2_Ia == 1) or (T2_Ia % T2_I == 0));
constraint tileJ2 = ((T2_Ja == 1) or (T2_Ja % T2_J == 0));
constraint reg_capacity = (RT2_I*RT2_J <= 150);
constraint unroll_limit = ((U2_I == 1) or (U2_J == 1));
}
def search
{
arg algorithm = 'Randomsearch';
arg total_runs = 10000;
}
def input_params
{
param N[] = [1000];
}
def input_vars
{
arg decl_file = 'decl_code.h';
arg init_file = 'init_code.c';
}
) @*/
int i,j, k,t;
int it, jt, kt;
int ii, jj, kk;
int iii, jjj, kkk;
#define max(x,y) ((x) > (y)? (x) : (y))
#define min(x,y) ((x) < (y)? (x) : (y))
/*@ begin Loop (
for (k=0; k<=N-1; k++) {
transform Composite(
unrolljam = (['j'],[U1_J]),
scalarreplace = (SCR, 'double'),
vector = (VEC1, ['ivdep','vector always'])
)
for (j=k+1; j<=N-1; j++)
A[k][j] = A[k][j]/A[k][k];
transform Composite(
tile = [('i',T2_I,'ii'),('j',T2_J,'jj'),
(('ii','i'),T2_Ia,'iii'),(('jj','j'),T2_Ja,'jjj')],
unrolljam = (['i','j'],[U2_I,U2_J]),
scalarreplace = (SCR, 'double'),
regtile = (['i','j'],[RT2_I,RT2_J]),
vector = (VEC2, ['ivdep','vector always']),
openmp = (OMP, 'omp parallel for private(iii,jjj,ii,jj,i,j)')
)
for(i=k+1; i<=N-1; i++)
for (j=k+1; j<=N-1; j++)
A[i][j] = A[i][j] - A[i][k]*A[k][j];
}
) @*/
/*@ end @*/
/*@ end @*/
|
the_stack_data/437710.c | /*
APPLE.C
Tile Source File.
Info:
Form : All tiles as one unit.
Format : Gameboy 4 color.
Compression : None.
Counter : None.
Tile size : 8 x 8
Tiles : 0 to 0
Palette colors : None.
SGB Palette : None.
CGB Palette : None.
Convert to metatiles : No.
This file was generated by GBTD v2.2
*/
/* Start of tile array. */
unsigned char Apple[] =
{
0x00,0x3E,0x3E,0x41,0x7C,0x82,0x78,0x84,
0x78,0x84,0x7C,0x82,0x3E,0x41,0x00,0x3E
};
/* End of APPLE.C */
|
the_stack_data/91136.c | #include <stdio.h>
#include <string.h>
#define MAXLINES 5000
#define MAXLEN 1000
#define MAXLINE 1000
#define ALLOCSIZE 10000
int getline02 (char *, int);
char *alloc(int);
char *lineptr[MAXLINES];
int readlines(char *lineptr[], int maxlines);
void writelines (char *lineptr[], int nlines);
void swap(char *v[], int i, int j);
int getline01(char s[], int lin);
void qsort(char *v[], int left, int right);
int main ()
{
int nlines;
if((nlines = readlines(lineptr, MAXLINES)) >= 0)
{
qsort(lineptr,0, nlines -1);
writelines(lineptr, nlines);
return 0;
}
else {
printf("error: input too big to sort\n");
return 1;
}
}
int readlines(char *lineptr[], int maxlines)
{
int len, nlines;
char *p, line[MAXLEN];
nlines = 0;
while ((len = getline01(line, MAXLINE)) > 0)
{
if (nlines >= maxlines || (p = alloc(len)) == NULL)
{
return -1;
}
else {
line[len - 1] = '\0';
strcpy(p, line);
lineptr[nlines++] = p;
}
return nlines;
}
}
void writelines (char *lineptr[], int nlines)
{
int i;
for(i = 0; i < nlines; i++)
{
printf("%s\n", lineptr[i]);
}
}
int getline01(char s[], int lim)
{
int c,i;
for (i = 0; i < lim -1 && (c = getchar()) != EOF && c!= '\n'; ++i)
{
s[i] = c;
}
if (c == '\n')
{
s[i] = c;
++i;
}
s[i] = '\0';
return i;
}
void qsort(char *v[], int left, int right)
{
int i, last;
void swap(char *v[], int i, int j);
if (left >= right)
{
return;
}
swap(v,left, (left+ right) / 2);
last = left;
for(i = left + 1; i <= right; i++)
{
if (strcmp(v[i],v[left]) < 0)
{
swap(v, ++last,i);
}
}
swap(v,left,last);
qsort(v,left, last -1);
qsort(v,last+1,right );
}
void swap(char *v[], int i, int j)
{
char *temp;
temp = v[i];
v[i] = v[j];
v[j] = temp;
}
static char allocbuf[ALLOCSIZE];
static char *allocp = allocbuf;
char *alloc (int n)
{
if (allocbuf + ALLOCSIZE - allocp >= n)
{
allocp += n;
return allocp - n;
}
else
{
return 0;
}
}
|
the_stack_data/247017843.c | /*
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 2^1000?
*/
#include <stdio.h>
#include <stdbool.h>
#define N 1000
int main(){
int v[N], i, count, sum = 0, num2 = 2;
bool carryOver;
// Array initialization
for(i = 0; i < N; i++)
v[i] = 0;
v[0] = 2;
// Compute the number
for(count = 1; count < N; count++){
i = 0;
carryOver = false;
while(i < N){
v[i] *= num2;
if(carryOver) v[i] += 1;
if(v[i] > 9){
v[i] -= 10;
carryOver = true;
}
else carryOver = false;
i++;
}
}
// Sum the digits
for(i = 0; i < N; i++)
sum += v[i];
printf("sum = %d\n\n", sum);
return 0;
} |
the_stack_data/206393370.c | #include <stdio.h>
#include <stdlib.h>
int main()
{
int p;
int d;
float r;
printf("Enter Principal: ");
scanf("%d",&p);
printf("Enter rate: ");
scanf("%f",&r);
printf("Enter no of days: ");
scanf("%d",&d);
printf("Interest : %.2f: ",(p*d*r/365));
return 0;
}
|
the_stack_data/519023.c | #include <fcntl.h>
#include <unistd.h>
#include <sys/prctl.h>
#include <sys/socket.h>
#include <linux/bpf_common.h>
#include <linux/seccomp.h>
#include <linux/audit.h>
void sandbox_so_you_cannot_shellcode(void);
int vuln() {
char buff[8];
read(0, buff, 100); // Is it enough for ROP... hmm...?
// HAHA! Good luck with trying to getting flag!
shutdown(0, SHUT_RDWR);
close(0);
close(1);
close(2);
}
int main() {
sandbox_so_you_cannot_shellcode();
vuln();
}
|
the_stack_data/216728.c | #include <ncurses.h>
int main()
{
initscr();
printw("Upper left corner "); addch(ACS_ULCORNER); printw("\n");
printw("Lower left corner "); addch(ACS_LLCORNER); printw("\n");
printw("Lower right corner "); addch(ACS_LRCORNER); printw("\n");
printw("Tee pointing right "); addch(ACS_LTEE); printw("\n");
printw("Tee pointing left "); addch(ACS_RTEE); printw("\n");
printw("Tee pointing up "); addch(ACS_BTEE); printw("\n");
printw("Tee pointing down "); addch(ACS_TTEE); printw("\n");
printw("Horizontal line "); addch(ACS_HLINE); printw("\n");
printw("Vertical line "); addch(ACS_VLINE); printw("\n");
printw("Large Plus or cross over "); addch(ACS_PLUS); printw("\n");
printw("Scan Line 1 "); addch(ACS_S1); printw("\n");
printw("Scan Line 3 "); addch(ACS_S3); printw("\n");
printw("Scan Line 7 "); addch(ACS_S7); printw("\n");
printw("Scan Line 9 "); addch(ACS_S9); printw("\n");
printw("Diamond "); addch(ACS_DIAMOND); printw("\n");
printw("Checker board (stipple) "); addch(ACS_CKBOARD); printw("\n");
printw("Degree Symbol "); addch(ACS_DEGREE); printw("\n");
printw("Plus/Minus Symbol "); addch(ACS_PLMINUS); printw("\n");
printw("Bullet "); addch(ACS_BULLET); printw("\n");
printw("Arrow Pointing Left "); addch(ACS_LARROW); printw("\n");
printw("Arrow Pointing Right "); addch(ACS_RARROW); printw("\n");
printw("Arrow Pointing Down "); addch(ACS_DARROW); printw("\n");
printw("Arrow Pointing Up "); addch(ACS_UARROW); printw("\n");
printw("Board of squares "); addch(ACS_BOARD); printw("\n");
printw("Lantern Symbol "); addch(ACS_LANTERN); printw("\n");
printw("Solid Square Block "); addch(ACS_BLOCK); printw("\n");
printw("Less/Equal sign "); addch(ACS_LEQUAL); printw("\n");
printw("Greater/Equal sign "); addch(ACS_GEQUAL); printw("\n");
printw("Pi "); addch(ACS_PI); printw("\n");
printw("Not equal "); addch(ACS_NEQUAL); printw("\n");
printw("UK pound sign "); addch(ACS_STERLING); printw("\n");
refresh();
getch();
endwin();
return 0;
}
|
the_stack_data/56336.c | /* libev interface */
#define EV_MINPRI ...
#define EV_MAXPRI ...
#define EV_VERSION_MAJOR ...
#define EV_VERSION_MINOR ...
#define EV_UNDEF ...
#define EV_NONE ...
#define EV_READ ...
#define EV_WRITE ...
#define EV__IOFDSET ...
#define EV_TIMER ...
#define EV_PERIODIC ...
#define EV_SIGNAL ...
#define EV_CHILD ...
#define EV_STAT ...
#define EV_IDLE ...
#define EV_PREPARE ...
#define EV_CHECK ...
#define EV_EMBED ...
#define EV_FORK ...
#define EV_CLEANUP ...
#define EV_ASYNC ...
#define EV_CUSTOM ...
#define EV_ERROR ...
#define EVFLAG_AUTO ...
#define EVFLAG_NOENV ...
#define EVFLAG_FORKCHECK ...
#define EVFLAG_NOINOTIFY ...
#define EVFLAG_SIGNALFD ...
#define EVFLAG_NOSIGMASK ...
#define EVBACKEND_SELECT ...
#define EVBACKEND_POLL ...
#define EVBACKEND_EPOLL ...
#define EVBACKEND_KQUEUE ...
#define EVBACKEND_DEVPOLL ...
#define EVBACKEND_PORT ...
/* #define EVBACKEND_IOCP ... */
#define EVBACKEND_ALL ...
#define EVBACKEND_MASK ...
#define EVRUN_NOWAIT ...
#define EVRUN_ONCE ...
#define EVBREAK_CANCEL ...
#define EVBREAK_ONE ...
#define EVBREAK_ALL ...
/* markers for the CFFI parser. Replaced when the string is read. */
#define GEVENT_STRUCT_DONE int
#define GEVENT_ST_NLINK_T int
struct ev_loop {
int backend_fd;
int activecnt;
GEVENT_STRUCT_DONE _;
};
// Watcher types
// base for all watchers
struct ev_watcher{
GEVENT_STRUCT_DONE _;
};
struct ev_io {
int fd;
int events;
void* data;
GEVENT_STRUCT_DONE _;
};
struct ev_timer {
double at;
void* data;
GEVENT_STRUCT_DONE _;
};
struct ev_signal {
void* data;
GEVENT_STRUCT_DONE _;
};
struct ev_idle {
void* data;
GEVENT_STRUCT_DONE _;
};
struct ev_prepare {
void* data;
GEVENT_STRUCT_DONE _;
};
struct ev_check {
void* data;
GEVENT_STRUCT_DONE _;
};
struct ev_fork {
void* data;
GEVENT_STRUCT_DONE _;
};
struct ev_async {
void* data;
GEVENT_STRUCT_DONE _;
};
struct ev_child {
int pid;
int rpid;
int rstatus;
void* data;
GEVENT_STRUCT_DONE _;
};
struct stat {
GEVENT_ST_NLINK_T st_nlink;
GEVENT_STRUCT_DONE _;
};
struct ev_stat {
struct stat attr;
const char* path;
struct stat prev;
double interval;
void* data;
GEVENT_STRUCT_DONE _;
};
typedef double ev_tstamp;
int ev_version_major();
int ev_version_minor();
unsigned int ev_supported_backends (void);
unsigned int ev_recommended_backends (void);
unsigned int ev_embeddable_backends (void);
ev_tstamp ev_time (void);
void ev_set_syserr_cb(void *);
int ev_priority(void*);
void ev_set_priority(void*, int);
int ev_is_pending(void*);
int ev_is_active(void*);
void ev_io_init(struct ev_io*, void* callback, int fd, int events);
void ev_io_start(struct ev_loop*, struct ev_io*);
void ev_io_stop(struct ev_loop*, struct ev_io*);
void ev_feed_event(struct ev_loop*, void*, int);
void ev_timer_init(struct ev_timer*, void *callback, double, double);
void ev_timer_start(struct ev_loop*, struct ev_timer*);
void ev_timer_stop(struct ev_loop*, struct ev_timer*);
void ev_timer_again(struct ev_loop*, struct ev_timer*);
void ev_signal_init(struct ev_signal*, void* callback, int);
void ev_signal_start(struct ev_loop*, struct ev_signal*);
void ev_signal_stop(struct ev_loop*, struct ev_signal*);
void ev_idle_init(struct ev_idle*, void* callback);
void ev_idle_start(struct ev_loop*, struct ev_idle*);
void ev_idle_stop(struct ev_loop*, struct ev_idle*);
void ev_prepare_init(struct ev_prepare*, void* callback);
void ev_prepare_start(struct ev_loop*, struct ev_prepare*);
void ev_prepare_stop(struct ev_loop*, struct ev_prepare*);
void ev_check_init(struct ev_check*, void* callback);
void ev_check_start(struct ev_loop*, struct ev_check*);
void ev_check_stop(struct ev_loop*, struct ev_check*);
void ev_fork_init(struct ev_fork*, void* callback);
void ev_fork_start(struct ev_loop*, struct ev_fork*);
void ev_fork_stop(struct ev_loop*, struct ev_fork*);
void ev_async_init(struct ev_async*, void* callback);
void ev_async_start(struct ev_loop*, struct ev_async*);
void ev_async_stop(struct ev_loop*, struct ev_async*);
void ev_async_send(struct ev_loop*, struct ev_async*);
int ev_async_pending(struct ev_async*);
void ev_child_init(struct ev_child*, void* callback, int, int);
void ev_child_start(struct ev_loop*, struct ev_child*);
void ev_child_stop(struct ev_loop*, struct ev_child*);
void ev_stat_init(struct ev_stat*, void* callback, char*, double);
void ev_stat_start(struct ev_loop*, struct ev_stat*);
void ev_stat_stop(struct ev_loop*, struct ev_stat*);
struct ev_loop *ev_default_loop (unsigned int flags);
struct ev_loop* ev_loop_new(unsigned int flags);
void ev_loop_destroy(struct ev_loop*);
void ev_loop_fork(struct ev_loop*);
int ev_is_default_loop (struct ev_loop *);
unsigned int ev_iteration(struct ev_loop*);
unsigned int ev_depth(struct ev_loop*);
unsigned int ev_backend(struct ev_loop*);
void ev_verify(struct ev_loop*);
void ev_run(struct ev_loop*, int flags);
ev_tstamp ev_now (struct ev_loop *);
void ev_now_update (struct ev_loop *); /* update event loop time */
void ev_ref(struct ev_loop*);
void ev_unref(struct ev_loop*);
void ev_break(struct ev_loop*, int);
unsigned int ev_pending_count(struct ev_loop*);
struct ev_loop* gevent_ev_default_loop(unsigned int flags);
void gevent_install_sigchld_handler();
void gevent_reset_sigchld_handler();
void (*gevent_noop)(struct ev_loop *_loop, struct ev_timer *w, int revents);
void ev_sleep (ev_tstamp delay); /* sleep for a while */
/* gevent callbacks */
static int (*python_callback)(void* handle, int revents);
static void (*python_handle_error)(void* handle, int revents);
static void (*python_stop)(void* handle);
/*
* We use a single C callback for every watcher type, which in turn calls the
* Python callbacks. The ev_watcher pointer type can be used for every watcher type
* because they all start with the same members---libev itself relies on this. Each
* watcher types has a 'void* data' that stores the CFFI handle to the Python watcher
* object.
*/
static void _gevent_generic_callback(struct ev_loop* loop, struct ev_watcher* watcher, int revents);
|
the_stack_data/71470.c | #include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <errno.h>
#define RUN(s, junk) check(s junk, sizeof(s) - 1)
#define OVERFLOW(condition) do { \
errno = 0; \
assert(condition); \
assert(errno == ERANGE); \
} while (0)
static float check(const char s[static 1], long length)
{
char* end;
float x = strtof(s, &end);
assert(end == s + length);
return x;
}
int main(void)
{
assert(RUN("inf", "") == INFINITY);
assert(RUN("+inf", "ini") == INFINITY);
assert(RUN("infinity", "") == INFINITY);
assert(isnan(RUN("nan", "")));
assert(isnan(RUN("nan()", "")));
assert(isnan(RUN("nan(314159)", "")));
assert(isnan(RUN("nan(0xabcd)", "")));
assert(isnan(RUN("nan", "(abcd)")));
assert(signbit(RUN("-0", "x")));
assert(RUN("", "-") == 0);
assert(RUN("0", "x") == 0);
assert(RUN("3", "") == 3);
assert(RUN("-.003", "f") == -0.003f);
assert(RUN("0x3", "") == 3);
assert(RUN("0x1.8p1", "") == 3);
assert(RUN("-0x2.345", "p+") == -0x2.345p0f);
assert(RUN("0x945380.8", "") == 0x945380);
assert(RUN("0x945380.800000000000", "") == 0x945380);
assert(RUN("0x945380.800000000001", "") == 0x945381);
assert(RUN("0x945381.8", "") == 0x945382);
assert(RUN("0x945380.800000000000p-107", "") == 0x945380p-107f);
assert(RUN("0x945380.800000000001p-107", "") == 0x945381p-107f);
assert(RUN("-0x945380.800000000000p+3", ".14") == -0x945380p+3);
assert(RUN("-0x945380.800000000001p+3", ".14") == -0x945381p+3);
assert(!errno);
}
|
the_stack_data/215767649.c | /*
mbrwrite.c - writes out the MBR to a disk image
SPDX-License-Identifier: ISC
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <libgen.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
char* progname = NULL;
#define SECTSZ 512
int main(int argc, char** argv)
{
progname = basename(argv[0]);
// Check arguments
if(argc < 5)
{
printf("%s: not enough arguments passed\n", progname);
return 1;
}
// Grab the VBR sector start
int vbrstart = atoi(argv[4]);
if(!vbrstart)
{
printf("%s: sector start must be a number\n", progname);
return 1;
}
// Open up the MBR
int mbrfd = open(argv[1], O_RDONLY);
if(!mbrfd)
{
printf("%s: %s: %s\n", progname, argv[1], strerror(errno));
return 1;
}
// Open up the VBR
int vbrfd = open(argv[3], O_RDONLY);
if(!vbrfd)
{
printf("%s: %s: %s\n", progname, argv[3], strerror(errno));
close(vbrfd);
return 1;
}
// Open up the disk image
int imgfd = open(argv[2], O_RDWR);
if(!imgfd)
{
printf("%s: %s: %s\n", progname, argv[2], strerror(errno));
close(mbrfd);
close(vbrfd);
return 1;
}
uint8_t buf[1024];
read(mbrfd, buf, 446);
close(mbrfd);
write(imgfd, buf, 446);
read(vbrfd, buf, 1024);
lseek(imgfd, vbrstart * 512, SEEK_SET);
read(imgfd, buf, 90);
uint32_t* partbase = (uint32_t*)&buf[52];
*partbase = vbrstart;
lseek(imgfd, vbrstart * 512, SEEK_SET);
write(imgfd, buf, 1024);
close(vbrfd);
close(imgfd);
return 0;
}
|
the_stack_data/20449682.c | #include <stdio.h>
main(){printf("Hello, world!\n");}
|
the_stack_data/176706748.c | #include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
char *string = NULL;
if (argc > 1) {
const size_t len = strlen(argv[1]) + 1;
string = (char *) malloc(sizeof(char)*len);
if (string == NULL)
errx(EXIT_FAILURE, "can't allocate string\n");
strncpy(string, argv[1], len);
}
if (strlen(string) > 0 && string != NULL)
printf("hello %s!\n", string);
return EXIT_SUCCESS;
}
|
the_stack_data/98575937.c | #define CATCH_CONFIG_RUNNER
#if defined(_MSC_VER) && defined(MEMORY_LEAK_DETECT)
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif
#include <stdlib.h>
#include <check.h>
extern Suite *main_suite();
int main( int argc, char* argv[] ) {
int ret;
#if defined(_MSC_VER) && defined(MEMORY_LEAK_DETECT)
_CrtMemState _checkpoint_start;
_CrtMemState _checkpoint_end;
_CrtMemState _checkpoint_diff;
int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
flag |= _CRTDBG_LEAK_CHECK_DF;
flag |= _CRTDBG_ALLOC_MEM_DF;
_CrtSetDbgFlag ( flag );
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG );
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR );
_CrtMemCheckpoint(&_checkpoint_start);
#endif
/**NOTICE: Исключаем влияние Check на анализ памяти */
{
Suite *suite;
SRunner *runner;
int failed;
suite = main_suite();
runner = srunner_create(suite);
srunner_run_all(runner, CK_NORMAL);
failed = srunner_ntests_failed(runner);
srunner_free(runner);
ret = failed == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
#if defined(_MSC_VER) && defined(MEMORY_LEAK_DETECT)
_CrtMemCheckpoint(&_checkpoint_end);
if (_CrtMemDifference(&_checkpoint_diff, &_checkpoint_start, &_checkpoint_end))
_CrtMemDumpStatistics( &_checkpoint_diff );
_CrtDumpMemoryLeaks();
#endif
return ret;
}
|
the_stack_data/28263900.c | //===-- SystemZInstPrinter.cpp - Convert SystemZ MCInst to assembly syntax --------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This class prints an SystemZ MCInst to a .s file.
//
//===----------------------------------------------------------------------===//
/* Capstone Disassembly Engine */
/* By Nguyen Anh Quynh <[email protected]>, 2013-2014 */
#ifdef CAPSTONE_HAS_SYSZ
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <platform.h>
#include "SystemZInstPrinter.h"
#include "../../MCInst.h"
#include "../../utils.h"
#include "../../SStream.h"
#include "../../MCRegisterInfo.h"
#include "../../MathExtras.h"
#include "SystemZMapping.h"
static const char *getRegisterName(unsigned RegNo);
void SystemZ_post_printer(csh ud, cs_insn *insn, char *insn_asm, MCInst *mci) {
/*
if (((cs_struct *)ud)->detail != CS_OPT_ON)
return;
*/
}
static void printAddress(MCInst *MI, unsigned Base, int64_t Disp, unsigned Index, SStream *O) {
if (Disp >= 0) {
if (Disp > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, Disp);
else
SStream_concat(O, "%"PRIu64, Disp);
} else {
if (Disp < -HEX_THRESHOLD)
SStream_concat(O, "-0x%"PRIx64, -Disp);
else
SStream_concat(O, "-%"PRIu64, -Disp);
}
if (Base) {
SStream_concat0(O, "(");
if (Index)
SStream_concat(O, "%%%s, ", getRegisterName(Index));
SStream_concat(O, "%%%s)", getRegisterName(Base));
if (MI->csh->detail) {
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_MEM;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].mem.base = (uint8_t)SystemZ_map_register(Base);
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].mem.index = (uint8_t)SystemZ_map_register(Index);
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].mem.disp = Disp;
MI->flat_insn->detail->sysz.op_count++;
}
} else if (!Index) {
if (MI->csh->detail) {
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].imm = Disp;
MI->flat_insn->detail->sysz.op_count++;
}
}
}
static void _printOperand(MCInst *MI, MCOperand *MO, SStream *O) {
if (MCOperand_isReg(MO)) {
unsigned reg;
reg = MCOperand_getReg(MO);
SStream_concat(O, "%%%s", getRegisterName(reg));
reg = SystemZ_map_register(reg);
if (MI->csh->detail) {
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_REG;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].reg = reg;
MI->flat_insn->detail->sysz.op_count++;
}
} else if (MCOperand_isImm(MO)) {
int64_t Imm = MCOperand_getImm(MO);
if (Imm >= 0) {
if (Imm > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, Imm);
else
SStream_concat(O, "%"PRIu64, Imm);
} else {
if (Imm < -HEX_THRESHOLD)
SStream_concat(O, "-0x%"PRIx64, -Imm);
else
SStream_concat(O, "-%"PRIu64, -Imm);
}
if (MI->csh->detail) {
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].imm = Imm;
MI->flat_insn->detail->sysz.op_count++;
}
}
}
static void printU4ImmOperand(MCInst *MI, int OpNum, SStream *O) {
int64_t Value = MCOperand_getImm(MCInst_getOperand(MI, OpNum));
// assert(isUInt<4>(Value) && "Invalid u4imm argument");
if (Value >= 0) {
if (Value > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, Value);
else
SStream_concat(O, "%"PRIu64, Value);
} else {
if (Value < -HEX_THRESHOLD)
SStream_concat(O, "-0x%"PRIx64, -Value);
else
SStream_concat(O, "-%"PRIu64, -Value);
}
if (MI->csh->detail) {
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].imm = Value;
MI->flat_insn->detail->sysz.op_count++;
}
}
static void printU6ImmOperand(MCInst *MI, int OpNum, SStream *O) {
uint32_t Value = (uint32_t)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
// assert(isUInt<6>(Value) && "Invalid u6imm argument");
if (Value > HEX_THRESHOLD)
SStream_concat(O, "0x%x", Value);
else
SStream_concat(O, "%u", Value);
if (MI->csh->detail) {
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].imm = (int64_t)Value;
MI->flat_insn->detail->sysz.op_count++;
}
}
static void printS8ImmOperand(MCInst *MI, int OpNum, SStream *O) {
int8_t Value = (int8_t)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
// assert(isInt<8>(Value) && "Invalid s8imm argument");
if (Value >= 0) {
if (Value > HEX_THRESHOLD)
SStream_concat(O, "0x%x", Value);
else
SStream_concat(O, "%u", Value);
} else {
if (Value < -HEX_THRESHOLD)
SStream_concat(O, "-0x%x", -Value);
else
SStream_concat(O, "-%u", -Value);
}
if (MI->csh->detail) {
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].imm = (int64_t)Value;
MI->flat_insn->detail->sysz.op_count++;
}
}
static void printU8ImmOperand(MCInst *MI, int OpNum, SStream *O) {
uint8_t Value = (uint8_t)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
// assert(isUInt<8>(Value) && "Invalid u8imm argument");
if (Value > HEX_THRESHOLD)
SStream_concat(O, "0x%x", Value);
else
SStream_concat(O, "%u", Value);
if (MI->csh->detail) {
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].imm = (int64_t)Value;
MI->flat_insn->detail->sysz.op_count++;
}
}
static void printS16ImmOperand(MCInst *MI, int OpNum, SStream *O) {
int16_t Value = (int16_t)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
// assert(isInt<16>(Value) && "Invalid s16imm argument");
if (Value >= 0) {
if (Value > HEX_THRESHOLD)
SStream_concat(O, "0x%x", Value);
else
SStream_concat(O, "%u", Value);
} else {
if (Value < -HEX_THRESHOLD)
SStream_concat(O, "-0x%x", -Value);
else
SStream_concat(O, "-%u", -Value);
}
if (MI->csh->detail) {
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].imm = (int64_t)Value;
MI->flat_insn->detail->sysz.op_count++;
}
}
static void printU16ImmOperand(MCInst *MI, int OpNum, SStream *O) {
uint16_t Value = (uint16_t)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
// assert(isUInt<16>(Value) && "Invalid u16imm argument");
if (Value > HEX_THRESHOLD)
SStream_concat(O, "0x%x", Value);
else
SStream_concat(O, "%u", Value);
if (MI->csh->detail) {
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].imm = (int64_t)Value;
MI->flat_insn->detail->sysz.op_count++;
}
}
static void printS32ImmOperand(MCInst *MI, int OpNum, SStream *O) {
int32_t Value = (int32_t)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
// assert(isInt<32>(Value) && "Invalid s32imm argument");
if (Value >= 0) {
if (Value > HEX_THRESHOLD)
SStream_concat(O, "0x%x", Value);
else
SStream_concat(O, "%u", Value);
} else {
if (Value < -HEX_THRESHOLD)
SStream_concat(O, "-0x%x", -Value);
else
SStream_concat(O, "-%u", -Value);
}
if (MI->csh->detail) {
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].imm = (int64_t)Value;
MI->flat_insn->detail->sysz.op_count++;
}
}
static void printU32ImmOperand(MCInst *MI, int OpNum, SStream *O) {
uint32_t Value = (uint32_t)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
// assert(isUInt<32>(Value) && "Invalid u32imm argument");
if (Value > HEX_THRESHOLD)
SStream_concat(O, "0x%x", Value);
else
SStream_concat(O, "%u", Value);
if (MI->csh->detail) {
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].imm = (int64_t)Value;
MI->flat_insn->detail->sysz.op_count++;
}
}
static void printAccessRegOperand(MCInst *MI, int OpNum, SStream *O) {
int64_t Value = MCOperand_getImm(MCInst_getOperand(MI, OpNum));
// assert(Value < 16 && "Invalid access register number");
SStream_concat(O, "%%a%u", (unsigned int)Value);
if (MI->csh->detail) {
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_ACREG;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].reg = (unsigned int)Value;
MI->flat_insn->detail->sysz.op_count++;
}
}
static void printPCRelOperand(MCInst *MI, int OpNum, SStream *O) {
MCOperand *MO = MCInst_getOperand(MI, OpNum);
int32_t imm;
if (MCOperand_isImm(MO)) {
imm = (int32_t)MCOperand_getImm(MO);
if (imm >= 0) {
if (imm > HEX_THRESHOLD)
SStream_concat(O, "0x%x", imm);
else
SStream_concat(O, "%u", imm);
} else {
if (imm < -HEX_THRESHOLD)
SStream_concat(O, "-0x%x", -imm);
else
SStream_concat(O, "-%u", -imm);
}
if (MI->csh->detail) {
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].imm = (int64_t)imm;
MI->flat_insn->detail->sysz.op_count++;
}
}
}
static void printOperand(MCInst *MI, int OpNum, SStream *O) {
_printOperand(MI, MCInst_getOperand(MI, OpNum), O);
}
static void printBDAddrOperand(MCInst *MI, int OpNum, SStream *O) {
printAddress(MI, MCOperand_getReg(MCInst_getOperand(MI, OpNum)),
MCOperand_getImm(MCInst_getOperand(MI, OpNum + 1)), 0, O);
}
static void printBDXAddrOperand(MCInst *MI, int OpNum, SStream *O) {
printAddress(MI, MCOperand_getReg(MCInst_getOperand(MI, OpNum)),
MCOperand_getImm(MCInst_getOperand(MI, OpNum + 1)),
MCOperand_getReg(MCInst_getOperand(MI, OpNum + 2)), O);
}
static void printBDLAddrOperand(MCInst *MI, int OpNum, SStream *O) {
unsigned Base = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
uint64_t Disp = (uint64_t)MCOperand_getImm(MCInst_getOperand(MI, OpNum + 1));
uint64_t Length = (uint64_t)MCOperand_getImm(MCInst_getOperand(MI, OpNum + 2));
if (Disp > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, Disp);
else
SStream_concat(O, "%"PRIu64, Disp);
if (Length > HEX_THRESHOLD)
SStream_concat(O, "(0x%"PRIx64, Length);
else
SStream_concat(O, "(%"PRIu64, Length);
if (Base)
SStream_concat(O, ", %%%s", getRegisterName(Base));
SStream_concat0(O, ")");
if (MI->csh->detail) {
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_MEM;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].mem.base = (uint8_t)SystemZ_map_register(Base);
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].mem.length = Length;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].mem.disp = (int64_t)Disp;
MI->flat_insn->detail->sysz.op_count++;
}
}
static void printCond4Operand(MCInst *MI, int OpNum, SStream *O) {
static char *const CondNames[] = {
"o", "h", "nle", "l", "nhe", "lh", "ne",
"e", "nlh", "he", "nl", "le", "nh", "no"
};
uint64_t Imm = MCOperand_getImm(MCInst_getOperand(MI, OpNum));
// assert(Imm > 0 && Imm < 15 && "Invalid condition");
SStream_concat0(O, CondNames[Imm - 1]);
if (MI->csh->detail)
MI->flat_insn->detail->sysz.cc = (sysz_cc)Imm;
}
#define PRINT_ALIAS_INSTR
#include "SystemZGenAsmWriter.inc"
void SystemZ_printInst(MCInst *MI, SStream *O, void *Info) {
printInstruction(MI, O, Info);
}
#endif
|
the_stack_data/21838.c | #include <stdio.h>
int main (void)
{
int sum;
sum = 50 + 25;
printf ("The sum of 50 and 25 is %i\n", sum);
return 0;
}
|
the_stack_data/140443.c | /*#include <stdio.h>
int main()
{
int n,i,sum=0;
printf("enter the value of n:");
scanf("%d",&n);
for(i=1;i<n;i++)
{
if(n%i==0)
{
sum=sum+i;
}
}
if(n==sum)
printf("Perfect number");
else
printf("Not perfect number");
}*/
#include <stdio.h>
int main()
{
int n,m,j,i,r,limit,fact,sum;
printf("enter limit:");
scanf ("%d",&limit);
for(n=1;n<=limit;n++)
{
m=n;
j=n;
sum=0;
while(j>0)
{
r=n%10;
fact=1;
for(i=r;i>=1;i--)
{
fact=fact*i;
}
sum=sum+fact;
j=j/10;
}
if(m==sum)
printf("%d is strong \n",m);
else
printf("%d is not strong \n",m);
}
return 0;
} |
the_stack_data/175144339.c | /*numPass=0, numTotal=6
Verdict:WRONG_ANSWER, Visibility:1, Input:"4", ExpOutput:"Number of possible triangles is 13", Output:"13"
Verdict:WRONG_ANSWER, Visibility:1, Input:"1", ExpOutput:"Number of possible triangles is 1", Output:"1"
Verdict:WRONG_ANSWER, Visibility:1, Input:"3", ExpOutput:"Number of possible triangles is 7", Output:"7"
Verdict:WRONG_ANSWER, Visibility:0, Input:"5", ExpOutput:"Number of possible triangles is 22", Output:"22"
Verdict:WRONG_ANSWER, Visibility:0, Input:"7", ExpOutput:"Number of possible triangles is 50", Output:"50"
Verdict:WRONG_ANSWER, Visibility:0, Input:"2", ExpOutput:"Number of possible triangles is 3", Output:"3"
*/
#include<stdio.h>
int main()
{
int N,i,j,k,x,y,m;
x=0;N=0;y=0;m=0;
i=1;
scanf("%d",&N);
for(i=1;i<=N;i++)
{
for(j=1;j<=N;j++)
{
for(k=1;k<=N;k++)
{
if((i+j>k)&&(i+k>j)&&(j+k>i))
{
x++;
if(((i==j)&&j!=k)||((i==k)&&k!=j)||((j==k)&&k!=i))
y++;
if((i!=j)&&(j!=k)&&(k!=i))
m++;
}
}
}
}
printf("%d",x-y+(y/3)-m+(m/6));
return 0;
} |
the_stack_data/11076077.c | /*
* Copyright (C) 2015 University of Oregon
*
* You may distribute under the terms of either the GNU General Public
* License or the Apache License, as specified in the LICENSE file.
*
* For more information, see the LICENSE file.
*/
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#define MAXSTR 512
#define MAXFILES 10000
typedef char string[MAXSTR];
int debug = 0;
string flag ; /* -l generate a list, -v validate the list, -x validate and report extra files*/
void validFileList(string root, string name, string* files, int nfiles, int* nextra);
main(int argc, char *argv[])
{
FILE* fp;
FILE* fptmp;
int i, nfiles;
string files[MAXFILES];
string str, path, listfile, buf;
int nextra, nmiss;
if(argc > 3 && argv[1][0] == '-') {
strcpy(flag, argv[1]);
strcpy(path, argv[2]);
strcpy(listfile, argv[3]);
} else if(argc > 2 && strcmp(argv[1], "-l") == 0) {
strcpy(flag, argv[1]);
strcpy(path, argv[2]);
strcpy(listfile, "");
} else if(argc > 2) {
strcpy(flag, argv[1]);
strcpy(listfile, argv[2]);
strcpy(path, "/vnmr");
} else if(argc > 1 && strcmp(argv[1], "-l") == 0) {
strcpy(flag, argv[1]);
strcpy(path, "/vnmr");
strcpy(listfile, "");
} else if(argc > 1 && argv[1][0] != '-') {
strcpy(flag, "-l");
strcpy(path, argv[1]);
strcpy(listfile, "");
} else if(argc > 1) {
strcpy(flag, argv[1]);
strcpy(path, "/vnmr");
strcpy(listfile, "/vnmr/adm/p11/sysListAll");
} else {
fprintf(stderr, " Usage: chVJlist <-l/v> <path> <listfile> <-x>\n");
fprintf(stderr, " -l: make a list of (max 9999) files of given path,\n");
fprintf(stderr, " and write the list to listfile if specified.\n");
fprintf(stderr, " -v: validate (max 9999) files in given path from given listfile.\n");
fprintf(stderr, " -x: validate. report extra files when validating.\n");
fprintf(stderr, "defualt: -l /vnmr /vnmr/adm/p11/sysListAll.\n");
return(-1);
}
if(debug)
fprintf(stderr, "%s %s %s\n", flag, path, listfile);
if(path[strlen(path)-1] != '/') strcat(path,"/");
if(strcmp(flag, "-l") == 0) {
nfiles = 0;
/* getFilenames() adds a '/' to path, beware when testing below */
getFilenames(path, "", files, &nfiles, MAXFILES);
if(strlen(listfile) == 0 || !(fp = fopen(listfile, "w")))
fp = stdout;
/* Allow /vnmr with or without a trailing '/' */
/* This section is to skip directories that change in normal use */
if(strncmp(path, "/vnmr", 5) == 0) {
for(i=0; i<nfiles; i++) {
if( (strstr(files[i], "adm/users/profiles/") == NULL) &&
(strstr(files[i], "adm/patch/") == NULL) &&
(strstr(files[i], "acqqueue/") == NULL) &&
(strstr(files[i], "tmp/") == NULL) &&
(strstr(files[i], "pgsql/data/") == NULL) &&
(strstr(files[i], "pgsql/persistence/") == NULL) )
{
char tmpFile[1024];
sprintf(tmpFile,"%s%s",path,files[i]);
if ( strcmp(tmpFile,"/vnmr/bin/convert") )
fprintf(fp, "%s%s\n", path, files[i]);
}
}
}
else {
for(i=0; i<nfiles; i++) {
sprintf(str, "%s%s", path, files[i]);
if((fptmp = fopen(str, "r")) != NULL) {
fprintf(fp, "%s\n", str);
fclose(fptmp);
}
}
}
fclose(fp);
}
else if(strcmp(flag, "-v") == 0 && strlen(listfile) > 0 && (fp = fopen(listfile, "r"))){
struct stat fstat;
while (fgets(buf,sizeof(buf),fp) && i < MAXFILES) {
if(strlen(buf) > 1 && buf[0] != '#' && buf[0] != '%' && buf[0] != '@') {
buf[strlen(buf)-1]='\0';
if (stat(buf, &fstat) != 0)
fprintf(stdout, "%s is missing.\n",buf);
}
}
fclose(fp);
}
else if(strlen(listfile) > 0 && (fp = fopen(listfile, "r"))){
i = 0;
while (fgets(buf,sizeof(buf),fp) && i < MAXFILES) {
if(strlen(buf) > 1 && buf[0] != '#' && buf[0] != '%' && buf[0] != '@') {
strcpy(files[i], "");
strncat(files[i], buf, strlen(buf)-1);
i++;
}
}
fclose(fp);
nfiles = i;
nextra = 0;
validFileList(path, "", files, nfiles, &nextra);
nmiss = 0;
for(i=0; i<nfiles; i++) {
if(strlen(files[i]) > 0) {
fprintf(stdout, "%s is missing.\n", files[i]);
nmiss++;
}
}
if(debug) fprintf(stderr, "extra, miss %d %d\n", nextra, nmiss);
if(nextra == 0 && nmiss == 0)
fprintf(stdout, "chVJlist: all files in %s matched.\n", path);
}
return(0);
}
void validFileList(string rootpath, string name, string* files, int nfiles, int* nextra) {
DIR *dirp;
struct dirent *dp;
string dir, child;
int i, ind;
if(rootpath[strlen(rootpath)-1] != '/') strcat(rootpath,"/");
sprintf(dir, "%s%s", rootpath, name);
if(strlen(dir) == 0 || !fileExist(dir)) return;
if(!isAdirectory(dir)) {
ind = -1;
for(i=0; i<nfiles; i++) {
if(strlen(files[i]) > 0 && strcmp(files[i], dir) == 0) {
strcpy(files[i], "");
ind = i;
break;
}
}
if(strcmp(flag, "-x") == 0 && ind == -1) {
fprintf(stdout, "%s is not in the list.\n", dir);
(*nextra)++;
}
} else {
if (dirp = opendir(dir)) {
if(strlen(name) > 0 && name[strlen(name)-1] != '/')
strcat(name,"/");
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
if(debug)
fprintf(stderr," dir %s %s\n", dir, dp->d_name);
if (*dp->d_name != '.') {
sprintf(child,"%s%s",name,dp->d_name);
validFileList(rootpath, child, files, nfiles, nextra);
}
}
closedir(dirp);
}
}
return;
}
|
the_stack_data/187643.c | #include <stdio.h>
/*Faça um programa que dado um n, calcule a somatoria dos n elementos da seguinte sequencia*/
int main(void) {
int n, i, s = 0;
printf("Digite um número\t");
scanf("%d",&n);
for (i = 1; i <= n; i++){
s+=i;
}
printf("o somatorio dos números inteiros entre 1 e %d é %d", n, s);
return 0;
}
|
the_stack_data/15761518.c | void fence() { asm("sync"); }
void lwfence() { asm("lwsync"); }
void isync() { asm("isync"); }
int __unbuffered_cnt=0;
int __unbuffered_p2_EAX=0;
int __unbuffered_p2_EBX=0;
int x=0;
int y=0;
int z=0;
void * P0(void * arg) {
z = 1;
x = 1;
// Instrumentation for CPROVER
fence();
__unbuffered_cnt++;
}
void * P1(void * arg) {
x = 2;
y = 1;
// Instrumentation for CPROVER
fence();
__unbuffered_cnt++;
}
void * P2(void * arg) {
y = 2;
__unbuffered_p2_EAX = y;
__unbuffered_p2_EBX = z;
// Instrumentation for CPROVER
fence();
__unbuffered_cnt++;
}
int main() {
__CPROVER_ASYNC_0: P0(0);
__CPROVER_ASYNC_1: P1(0);
__CPROVER_ASYNC_2: P2(0);
__CPROVER_assume(__unbuffered_cnt==3);
fence();
// EXPECT:exists
__CPROVER_assert(!(x==2 && y==2 && __unbuffered_p2_EAX==2 && __unbuffered_p2_EBX==0), "Program proven to be relaxed for X86, model checker says YES.");
return 0;
}
|
the_stack_data/819740.c | /*
* These hash functions were developed by Thomas Wang.
*
* http://www.concentric.net/~ttwang/tech/inthash.htm
*/
#include <stdint.h>
uint32_t hashable_wang_32(uint32_t a)
{
a = (a ^ 61) ^ (a >> 16);
a = a + (a << 3);
a = a ^ (a >> 4);
a = a * 0x27d4eb2d;
a = a ^ (a >> 15);
return a;
}
uint64_t hashable_wang_64(uint64_t key)
{
key = (~key) + (key << 21); // key = (key << 21) - key - 1;
key = key ^ ((key >> 24) | (key << 40));
key = (key + (key << 3)) + (key << 8); // key * 265
key = key ^ ((key >> 14) | (key << 50));
key = (key + (key << 2)) + (key << 4); // key * 21
key = key ^ ((key >> 28) | (key << 36));
key = key + (key << 31);
return key;
}
|
the_stack_data/142910.c | /**
* Workaround for lack of snprintf(3) in Visual Studio. See
* http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010/8712996#8712996
* It's a trivial wrapper around the builtin _vsnprintf_s and
* _vscprintf functions.
*/
#ifdef _MSC_VER
#include <stdio.h>
#include <stdarg.h>
#include "libport.h"
int _TIFF_vsnprintf_f(char* str, size_t size, const char* format, va_list ap)
{
int count = -1;
if (size != 0)
#if _MSC_VER <= 1310
count = _vsnprintf(str, size, format, ap);
#else
count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
#endif
if (count == -1)
count = _vscprintf(format, ap);
return count;
}
int _TIFF_snprintf_f(char* str, size_t size, const char* format, ...)
{
int count;
va_list ap;
va_start(ap, format);
count = vsnprintf(str, size, format, ap);
va_end(ap);
return count;
}
#endif // _MSC_VER
|
the_stack_data/104828820.c | int f1() { return 0;}
void f(int X) {
#pragma spf transform inline
{
switch(X) {
case 1: {f1();} break;
case 2: f1(); break;
default: f1(); break;
}
}
}
|
the_stack_data/181392267.c | /*
* ========================================================================
* Copyright 2006-2009 University of Washington
* Copyright 2013-2020 Eduardo Chappa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* ========================================================================
*/
#define VER_MAJOR 5
#define VER_MINOR 10
extern char datestamp[];
/*
* Return major version number...
*/
int
mswin_majorver()
{
return(VER_MAJOR);
}
/*
* Return minor version number...
*/
int
mswin_minorver()
{
return(VER_MINOR);
}
/*
* Return compilation number...
*/
char *
mswin_compilation_date()
{
return(datestamp);
}
/*
* Return special remarks...
*/
char *
mswin_compilation_remarks()
{
return("");
}
/*
* Return specific windows version...
*/
char *
mswin_specific_winver()
{
return("");
}
|
the_stack_data/92328330.c | /*--------------------------------------------------------------------------
File : Vector_nRF52.c
Author : Hoang Nguyen Hoan July 6, 2015
Desc : Interrupt Vectors table for ARM Cortex-M4 specific nRF52
CMSIS & GCC compiler
linker section name .Vectors is used for the table
Copyright (c) 2015, I-SYST inc., all rights reserved
Permission to use, copy, modify, and distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright
notice and this permission notice appear in all copies, and none of the
names : I-SYST or its contributors may be used to endorse or
promote products derived from this software without specific prior written
permission.
For info or contributing contact : hnhoan at i-syst dot com
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------------
Modified by Date Description
----------------------------------------------------------------------------*/
#include <stdint.h>
extern unsigned long __StackTop;
extern void ResetEntry(void);
void DEF_IRQHandler(void) { while(1); }
__attribute__((weak, alias("DEF_IRQHandler"))) void NMI_Handler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void HardFault_Handler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void SVC_Handler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void PendSV_Handler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void SysTick_Handler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void POWER_CLOCK_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void RADIO_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void UARTE0_UART0_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void NFCT_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void GPIOTE_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void SAADC_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void TIMER0_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void TIMER1_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void TIMER2_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void RTC0_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void TEMP_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void RNG_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void ECB_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void CCM_AAR_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void WDT_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void RTC1_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void QDEC_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void COMP_LPCOMP_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void SWI0_EGU0_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void SWI1_EGU1_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void SWI2_EGU2_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void SWI3_EGU3_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void SWI4_EGU4_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void SWI5_EGU5_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void TIMER3_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void TIMER4_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void PWM0_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void PDM_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void MWU_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void PWM1_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void PWM2_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void SPIM2_SPIS2_SPI2_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void RTC2_IRQHandler(void);
__attribute__((weak, alias("DEF_IRQHandler"))) void I2S_IRQHandler(void);
/**
* This interrupt vector is by default located in FLASH. Though it can not be
* changed at runtime. All fcuntions in the vector are weak. it can be
* overloaded by application function
*
*/
__attribute__ ((section(".intvect"), used))
void (* const g_Vectors[])(void) =
{
/*(void (*) )((int32_t)&__StackTop), This stack pointer address is hnadled in ld script*/
ResetEntry,
NMI_Handler,
HardFault_Handler,
0,
0,
0,
0, 0, 0, 0,
SVC_Handler,
0,
0,
PendSV_Handler,
SysTick_Handler,
/* External Interrupts */
POWER_CLOCK_IRQHandler,
RADIO_IRQHandler,
UARTE0_UART0_IRQHandler,
SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler,
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler,
NFCT_IRQHandler,
GPIOTE_IRQHandler,
SAADC_IRQHandler,
TIMER0_IRQHandler,
TIMER1_IRQHandler,
TIMER2_IRQHandler,
RTC0_IRQHandler,
TEMP_IRQHandler,
RNG_IRQHandler,
ECB_IRQHandler,
CCM_AAR_IRQHandler,
WDT_IRQHandler,
RTC1_IRQHandler,
QDEC_IRQHandler,
COMP_LPCOMP_IRQHandler,
SWI0_EGU0_IRQHandler,
SWI1_EGU1_IRQHandler,
SWI2_EGU2_IRQHandler,
SWI3_EGU3_IRQHandler,
SWI4_EGU4_IRQHandler,
SWI5_EGU5_IRQHandler,
TIMER3_IRQHandler,
TIMER4_IRQHandler,
PWM0_IRQHandler,
PDM_IRQHandler,
0,
0,
MWU_IRQHandler,
PWM1_IRQHandler,
PWM2_IRQHandler,
SPIM2_SPIS2_SPI2_IRQHandler,
RTC2_IRQHandler,
I2S_IRQHandler,
0,
0
};
|
the_stack_data/603097.c | #ifdef CONFIG_EVM_MODULE_EVENTS
#include "evm_module.h"
static evm_hash_t _hashname_events;
//emitter.addListener(event, listener)
static evm_val_t evm_module_events_emitter_addListener(evm_t *e, evm_val_t *p, int argc, evm_val_t *v) {
if( argc < 2 || !evm_is_string(v) || !evm_is_script(v + 1) )
return EVM_VAL_UNDEFINED;
evm_val_t *events = evm_prop_get_by_key(e, p, _hashname_events, 0);
if( events ) {
evm_prop_append(e, events, evm_2_string(v), *(v + 1));
}
return EVM_VAL_UNDEFINED;
}
//emitter.on(event, listener)
static evm_val_t evm_module_events_emitter_on(evm_t *e, evm_val_t *p, int argc, evm_val_t *v) {
return evm_module_events_emitter_addListener(e, p, argc, v);
}
//emitter.emit(event[, args..])
static evm_val_t evm_module_events_emitter_emit(evm_t *e, evm_val_t *p, int argc, evm_val_t *v) {
if( argc < 1 || !evm_is_string(v) )
return EVM_VAL_UNDEFINED;
evm_module_event_emit(e, p, evm_2_string(v), argc - 1, v + 1);
return EVM_VAL_UNDEFINED;
}
//emitter.once(event, listener)
static evm_val_t evm_module_events_emitter_once(evm_t *e, evm_val_t *p, int argc, evm_val_t *v) {
return evm_module_events_emitter_addListener(e, p, argc, v);
}
//emitter.removeListener(event, listener)
static evm_val_t evm_module_events_emitter_removeListener(evm_t *e, evm_val_t *p, int argc, evm_val_t *v) {
evm_val_t *events = evm_prop_get_by_key(e, p, _hashname_events, 0);
if( events ) {
evm_prop_append(e, events, evm_2_string(v), EVM_VAL_UNDEFINED);
}
return EVM_VAL_UNDEFINED;
}
//emitter.removeAllListeners([event])
static evm_val_t evm_module_events_emitter_removeAllListeners(evm_t *e, evm_val_t *p, int argc, evm_val_t *v) {
evm_val_t *events = evm_object_create(e, GC_OBJECT, 0, 0);
if( events )
evm_prop_push_with_key(e, p, _hashname_events, events);
return EVM_VAL_UNDEFINED;
}
//emitter.EventEmitter
static evm_val_t evm_module_events_emitter_EventEmitter(evm_t *e, evm_val_t *p, int argc, evm_val_t *v) {
evm_val_t *obj = evm_object_create(e, GC_OBJECT, 7, 0);
if( obj ) {
evm_prop_append(e, obj, "addListener", evm_mk_native((intptr_t)evm_module_events_emitter_addListener));
evm_prop_append(e, obj, "on", evm_mk_native((intptr_t)evm_module_events_emitter_on));
evm_prop_append(e, obj, "emit", evm_mk_native((intptr_t)evm_module_events_emitter_emit));
evm_prop_append(e, obj, "once", evm_mk_native((intptr_t)evm_module_events_emitter_once));
evm_prop_append(e, obj, "removeListener", evm_mk_native((intptr_t)evm_module_events_emitter_removeListener));
evm_prop_append(e, obj, "removeAllListeners", evm_mk_native((intptr_t)evm_module_events_emitter_removeAllListeners));
evm_val_t *events = evm_object_create(e, GC_OBJECT, 0, 0);
if( events )
evm_prop_push_with_key(e, obj, _hashname_events, events);
return *obj;
}
return EVM_VAL_UNDEFINED;
}
evm_err_t evm_module_events(evm_t *e) {
_hashname_events = evm_str_insert(e, "_events", 0);
evm_builtin_t builtin[] = {
{"EventEmitter", evm_mk_native((intptr_t)evm_module_events_emitter_EventEmitter)},
{NULL, EVM_VAL_UNDEFINED}
};
evm_module_create(e, "events", builtin);
return e->err;
}
#endif
|
the_stack_data/182953357.c | a;
struct b {
long c;
long d
} e() {
struct b *f = 0;
long g;
for (; f->d;)
;
for (; g < f->d; g++)
if (a)
h();
}
|
the_stack_data/37637632.c | extern void __VERIFIER_error() __attribute__ ((__noreturn__));
void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } }
#define size 100
int main( )
{
int a[size];
int b[size];
int i = 1;
int j = 0;
while( i < size )
{
a[j] = b[i];
i = i+4;
j = j+1;
}
i = 1;
j = 0;
while( i < size )
{
__VERIFIER_assert( a[j] == b[4*j+1] );
i = i+4;
j = j+1;
}
return 0;
}
|
the_stack_data/176705993.c | /*
Author: One Developer Army
*/
/*
Output:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
*/
#include "stdio.h"
int main(){
for(int i = 1; i<=5;i++){
for(int j=1;j<=i;j++){
printf("%d ", i);
}
printf("\n");
}
return (0);
} |
the_stack_data/12636955.c | /*
* Copyright (C) 2011-2016 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
/*
* Find first set bit in Long
*/
int ffsl(long int mask)
{
return __builtin_ffsl(mask);
}
|
the_stack_data/134196.c | #include <stdio.h>
int main(void)
{
int a[10];
int i;
} |
the_stack_data/45449271.c | #include <stdio.h>
void compiled_function(int a, double b)
{
printf("a is %d and b is %f\n", a, b);
}
|
the_stack_data/200142141.c | /*
* Generated by util/mkerr.pl DO NOT EDIT
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <openssl/err.h>
#include <openssl/esserr.h>
#ifndef OPENSSL_NO_ERR
static const ERR_STRING_DATA ESS_str_functs[] = {
{ERR_PACK(ERR_LIB_ESS, ESS_F_ESS_CERT_ID_NEW_INIT, 0),
"VR_ESS_CERT_ID_new_init"},
{ERR_PACK(ERR_LIB_ESS, ESS_F_ESS_CERT_ID_V2_NEW_INIT, 0),
"VR_ESS_CERT_ID_V2_new_init"},
{ERR_PACK(ERR_LIB_ESS, ESS_F_ESS_SIGNING_CERT_ADD, 0),
"VR_ESS_SIGNING_CERT_add"},
{ERR_PACK(ERR_LIB_ESS, ESS_F_ESS_SIGNING_CERT_NEW_INIT, 0),
"VR_ESS_SIGNING_CERT_new_init"},
{ERR_PACK(ERR_LIB_ESS, ESS_F_ESS_SIGNING_CERT_V2_ADD, 0),
"VR_ESS_SIGNING_CERT_V2_add"},
{ERR_PACK(ERR_LIB_ESS, ESS_F_ESS_SIGNING_CERT_V2_NEW_INIT, 0),
"VR_ESS_SIGNING_CERT_V2_new_init"},
{0, NULL}
};
static const ERR_STRING_DATA ESS_str_reasons[] = {
{ERR_PACK(ERR_LIB_ESS, 0, ESS_R_ESS_SIGNING_CERTIFICATE_ERROR),
"ess signing certificate error"},
{ERR_PACK(ERR_LIB_ESS, 0, ESS_R_ESS_SIGNING_CERT_ADD_ERROR),
"ess signing cert add error"},
{ERR_PACK(ERR_LIB_ESS, 0, ESS_R_ESS_SIGNING_CERT_V2_ADD_ERROR),
"ess signing cert v2 add error"},
{0, NULL}
};
#endif
int VR_ERR_load_ESS_strings(void)
{
#ifndef OPENSSL_NO_ERR
if (VR_ERR_func_error_string(ESS_str_functs[0].error) == NULL) {
VR_ERR_load_strings_const(ESS_str_functs);
VR_ERR_load_strings_const(ESS_str_reasons);
}
#endif
return 1;
}
|
the_stack_data/36076213.c | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <omp.h>
double f(double x) {
double return_val;
return_val = x*x;
return return_val;
}
void Trap(double a, double b, int n, double* global_result_p);
int main(int argc, char* argv[]){
double global_result = 0;
double a, b;
int n;
int thread_count;
thread_count = strtol(argv[1], NULL, 10);
printf("Enter a, b and n\n");
scanf("%lf %lf %d", &a, &b, &n);
#pragma omp parallel num_threads(thread_count)
Trap(a, b, n, &global_result);
printf("With n = %d trapezoids, our estimate\n", n);
printf("of the integral from %lf to %lf = %.14e\n", a, b, global_result);
return 0;
}
void Trap(double a, double b, int n, double* global_result_p) {
double h, x, my_result;
double local_a, local_b;
int i, local_n;
int my_rank = omp_get_thread_num();
int thread_count = omp_get_num_threads();
h = (b - a) / n;
local_n = n / thread_count;
local_a = a + my_rank * local_n * h;
local_b = local_a + local_n * h;
my_result = (f(local_a) + f(local_b)) / 2.0;
for (i = 1; i < local_n; i++) {
x = local_a + i * h;
my_result += f(x);
}
my_result = my_result * h;
#pragma omp critical
*global_result_p += my_result;
} |
the_stack_data/28261453.c | // Check the presense of interface symbols in compiled file.
// RUN: %clang_asan -O2 %s -o %t.exe
// RUN: nm -D %t.exe | grep " T " | sed "s/.* T //" \
// RUN: | grep "__asan_" | sed "s/___asan_/__asan_/" \
// RUN: | grep -v "__asan_malloc_hook" \
// RUN: | grep -v "__asan_free_hook" \
// RUN: | grep -v "__asan_default_options" \
// RUN: | grep -v "__asan_stack_" \
// RUN: | grep -v "__asan_on_error" > %t.symbols
// RUN: cat %p/../../../asan_interface_internal.h \
// RUN: | sed "s/\/\/.*//" | sed "s/typedef.*//" \
// RUN: | grep -v "OPTIONAL" \
// RUN: | grep "__asan_.*(" | sed "s/.* __asan_/__asan_/;s/(.*//" \
// RUN: > %t.interface
// RUN: echo __asan_report_load1 >> %t.interface
// RUN: echo __asan_report_load2 >> %t.interface
// RUN: echo __asan_report_load4 >> %t.interface
// RUN: echo __asan_report_load8 >> %t.interface
// RUN: echo __asan_report_load16 >> %t.interface
// RUN: echo __asan_report_store1 >> %t.interface
// RUN: echo __asan_report_store2 >> %t.interface
// RUN: echo __asan_report_store4 >> %t.interface
// RUN: echo __asan_report_store8 >> %t.interface
// RUN: echo __asan_report_store16 >> %t.interface
// RUN: echo __asan_report_load_n >> %t.interface
// RUN: echo __asan_report_store_n >> %t.interface
// RUN: cat %t.interface | sort -u | diff %t.symbols -
// FIXME: nm -D on powerpc somewhy shows ASan interface symbols residing
// in "initialized data section".
// REQUIRES: x86_64-supported-target,i386-supported-target
int main() { return 0; }
|
the_stack_data/807584.c | #include <stdio.h>
/* gcc -shared -fPIC -nostartfiles openimage.c -o openimage.so */
int openimage(const char *s,const char * b)
{
static int handle = 100;
printf("the foyouage need to tagtagtagtaged is %s:%s\n", s,b);
return handle++;
}
|
the_stack_data/112558.c | #include <stdio.h>
int cumsum(int a, int b){ // returns the sum_{i=a}^{b} i
int val = 0;
for(int i = a; i < b+1; i++){
val += i;
}
return val;
}
int main(void){
printf("The sum of all integers from %d to %d is %d\n", 3, 10, cumsum(3,10));
printf("The sum of all integers from %d to %d is %d\n", 6, 17, cumsum(6,17));
}
//function components
// a return type
// a fileName
// an argument List
// a function body list
//the name must be unique
//pass arguments by values
//define a local scope
|
the_stack_data/73923.c | char *usage_msg[] = {
#ifdef RIPEMSIG
"ripemsig: {Riordan's|RSAREF-based} Internet Privacy Enhanced Mail, v.1.2a",
"*** Exportable signature-only version ***",
"Signs/verifies mail messages using RSA and MD5, and generates keys.",
#else
"ripem: {Riordan's | RSAREF-based} Internet Privacy Enhanced Mail, v.1.2a",
"Encrypts/decrypts mail messages using RSA and DES, and generates keys.",
#endif
"ripem is in the public domain, but requires agreeing to the RSAREF license ",
"from RSA Data Security; contact [email protected]. It's free but limited.",
"ripem was written by Mark Riordan ([email protected]). See doc for credits. ",
"Usage: ripem {-e | -d | -g | -c} <in >out",
#ifdef RIPEMSIG
" [-r recipient] [-m {mic-only | mic-clear}]",
#else
" [-r recipient] [-m {encrypted | mic-only | mic-clear}]",
#endif
" [-u myusername] [-h head] [-b #_of_bits_in_gen_key]",
" [-p publickey_infile(s)] [-s privatekey_infile] [-k key_to_private_key or -]",
" [-P publickey_outfile] [-S privatekey_outfile] [-A enc_alg]",
" [-y pub_key_server_name] [-Y key_sources] [-T recip_opts]",
" [-i infile] [-o outfile] [-D debug_level] [-Z debug_out_file] ",
" [-R random_sources] [-F random_input_file] [-C random_string] ",
" [-v #_of_validity_months] [-K new_key_to_private_key] [-H home_dir] ",
"where:",
" enc_alg is the encryption algorithm: des-cbc (default) or des-ede-cbc.",
" key_sources is a string of one or more of \"fgs\", which tell ripem to look",
" for public keys from a File, finGer, or Server, in the order specified.",
" head is one or more of \"ipr\", for Include headers in msg; Prepend headers",
" to output; get Recipients from headers. ",
" random_sources is one or more of \"cefkms\", specifying \"random\" input from",
" Command line, Entire command, File, Keyboard, Message, or running System.",
" recip_opts is one or more of \"amn\", for Abort if can't find keys for",
" all users; include Me as a recipient if encrypting; None of the above.",
"Relevant environment variables: RIPEM_HOME_DIR,",
" RIPEM_PUBLIC_KEY_FILE, RIPEM_PRIVATE_KEY_FILE, RIPEM_KEY_TO_PRIVATE_KEY,",
" RIPEM_USER_NAME, RIPEM_RANDOM_FILE, RIPEM_SERVER_NAME, RIPEM_ARGS",
(char *)0
};
|
the_stack_data/176706603.c | #include<stdio.h>
int main()
{
int n,a=0,g=0,d=0;
printf("MUITO OBRIGADO\n");
while(1){
scanf("%d",&n);
if(n>0 && n<4){
if(n==1)a++;
else if(n==2)g++;
else d++;
}
else if(n==4)break;
}
printf("Alcool: %d\n",a);
printf("Gasolina: %d\n",g);
printf("Diesel: %d\n",d);
return 0;
}
|
the_stack_data/103264924.c | void memstore(void *dest,void *src,int sz)
{
my_memcpy(dest,src,sz);
}
void caram()
{
int i,j[4],k[4];
for(i=0;i<10;i++) {
my_memcpy(&k[0],&j[0],4*sizeof(int));
memstore(&j[0],&k[0],4*sizeof(int));
}
}
|
the_stack_data/215767702.c | long long
foo (a, b)
long long a, b;
{
return a * b;
}
|
the_stack_data/110940.c | /* --- File task_depend.c --- */
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv) {
int N = 8;
int x[N][N];
int i,j;
/* Initialize x */
for(i=0;i<N;i++)
for(j=0;j<N;j++)
x[i][j]=i+j;
/* Serial computation */
for(i=1;i<N;i++){
for(j=1;j<N;j++)
x[i][j] = x[i-1][j] + x[i][j-1];
}
printf("Serial result:\n");
for(i=1;i<N;i++){
for(j=1;j<N;j++)
printf("%8d ",x[i][j]);
printf("\n");
}
/* Reset x */
for(i=0;i<N;i++)
for(j=0;j<N;j++)
x[i][j]=i+j;
/* Parallel computation */
#pragma omp parallel
/* Generate parallel tasks */
for(i=1;i<N;i++){
for(j=1;j<N;j++)
x[i][j] = x[i-1][j] + x[i][j-1];
}
printf("Parallel result:\n");
for(i=1;i<N;i++){
for(j=1;j<N;j++)
printf("%8d ",x[i][j]);
printf("\n");
}
}
|
the_stack_data/100139444.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <CL/cl.h>
unsigned char *read_buffer(char *file_name, size_t *size_ptr)
{
FILE *f;
unsigned char *buf;
size_t size;
/* Open file */
f = fopen(file_name, "rb");
if (!f)
return NULL;
/* Obtain file size */
fseek(f, 0, SEEK_END);
size = ftell(f);
fseek(f, 0, SEEK_SET);
/* Allocate and read buffer */
buf = malloc(size + 1);
fread(buf, 1, size, f);
buf[size] = '\0';
/* Return size of buffer */
if (size_ptr)
*size_ptr = size;
/* Return buffer */
return buf;
}
void write_buffer(char *file_name, const char *buffer, size_t buffer_size)
{
FILE *f;
/* Open file */
f = fopen(file_name, "w+");
/* Write buffer */
if(buffer)
fwrite(buffer, 1, buffer_size, f);
/* Close file */
fclose(f);
}
int main(int argc, char const *argv[])
{
/* Get platform */
cl_platform_id platform;
cl_uint num_platforms;
cl_int ret = clGetPlatformIDs(1, &platform, &num_platforms);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clGetPlatformIDs' failed\n");
exit(1);
}
printf("Number of platforms: %d\n", num_platforms);
printf("platform=%p\n", platform);
/* Get platform name */
char platform_name[100];
ret = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(platform_name), platform_name, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clGetPlatformInfo' failed\n");
exit(1);
}
printf("platform.name='%s'\n\n", platform_name);
/* Get device */
cl_device_id device;
cl_uint num_devices;
ret = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, &num_devices);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clGetDeviceIDs' failed\n");
exit(1);
}
printf("Number of devices: %d\n", num_devices);
printf("device=%p\n", device);
/* Get device name */
char device_name[100];
ret = clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(device_name),
device_name, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clGetDeviceInfo' failed\n");
exit(1);
}
printf("device.name='%s'\n", device_name);
printf("\n");
/* Create a Context Object */
cl_context context;
context = clCreateContext(NULL, 1, &device, NULL, NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clCreateContext' failed\n");
exit(1);
}
printf("context=%p\n", context);
/* Create a Command Queue Object*/
cl_command_queue command_queue;
command_queue = clCreateCommandQueue(context, device, 0, &ret);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clCreateCommandQueue' failed\n");
exit(1);
}
printf("command_queue=%p\n", command_queue);
printf("\n");
/* Program source */
unsigned char *source_code;
size_t source_length;
/* Read program from 'fabs_float8.cl' */
source_code = read_buffer("fabs_float8.cl", &source_length);
/* Create a program */
cl_program program;
program = clCreateProgramWithSource(context, 1, (const char **)&source_code, &source_length, &ret);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clCreateProgramWithSource' failed\n");
exit(1);
}
printf("program=%p\n", program);
/* Build program */
ret = clBuildProgram(program, 1, &device, NULL, NULL, NULL);
if (ret != CL_SUCCESS )
{
size_t size;
char *log;
/* Get log size */
clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,0, NULL, &size);
/* Allocate log and print */
log = malloc(size);
clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,size, log, NULL);
printf("error: call to 'clBuildProgram' failed:\n%s\n", log);
/* Free log and exit */
free(log);
exit(1);
}
printf("program built\n");
printf("\n");
/* Create a Kernel Object */
cl_kernel kernel;
kernel = clCreateKernel(program, "fabs_float8", &ret);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clCreateKernel' failed\n");
exit(1);
}
/* Create and allocate host buffers */
size_t num_elem = 10;
/* Create and init host side src buffer 0 */
cl_float8 *src_0_host_buffer;
src_0_host_buffer = malloc(num_elem * sizeof(cl_float8));
for (int i = 0; i < num_elem; i++)
src_0_host_buffer[i] = (cl_float8){{2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0}};
/* Create and init device side src buffer 0 */
cl_mem src_0_device_buffer;
src_0_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_float8), NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: could not create source buffer\n");
exit(1);
}
ret = clEnqueueWriteBuffer(command_queue, src_0_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_float8), src_0_host_buffer, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueWriteBuffer' failed\n");
exit(1);
}
/* Create host dst buffer */
cl_float8 *dst_host_buffer;
dst_host_buffer = malloc(num_elem * sizeof(cl_float8));
memset((void *)dst_host_buffer, 1, num_elem * sizeof(cl_float8));
/* Create device dst buffer */
cl_mem dst_device_buffer;
dst_device_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, num_elem *sizeof(cl_float8), NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: could not create dst buffer\n");
exit(1);
}
/* Set kernel arguments */
ret = CL_SUCCESS;
ret |= clSetKernelArg(kernel, 0, sizeof(cl_mem), &src_0_device_buffer);
ret |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &dst_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clSetKernelArg' failed\n");
exit(1);
}
/* Launch the kernel */
size_t global_work_size = num_elem;
size_t local_work_size = num_elem;
ret = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &global_work_size, &local_work_size, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueNDRangeKernel' failed\n");
exit(1);
}
/* Wait for it to finish */
clFinish(command_queue);
/* Read results from GPU */
ret = clEnqueueReadBuffer(command_queue, dst_device_buffer, CL_TRUE,0, num_elem * sizeof(cl_float8), dst_host_buffer, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueReadBuffer' failed\n");
exit(1);
}
/* Dump dst buffer to file */
char dump_file[100];
sprintf((char *)&dump_file, "%s.result", argv[0]);
write_buffer(dump_file, (const char *)dst_host_buffer, num_elem * sizeof(cl_float8));
printf("Result dumped to %s\n", dump_file);
/* Free host dst buffer */
free(dst_host_buffer);
/* Free device dst buffer */
ret = clReleaseMemObject(dst_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseMemObject' failed\n");
exit(1);
}
/* Free host side src buffer 0 */
free(src_0_host_buffer);
/* Free device side src buffer 0 */
ret = clReleaseMemObject(src_0_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseMemObject' failed\n");
exit(1);
}
/* Release kernel */
ret = clReleaseKernel(kernel);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseKernel' failed\n");
exit(1);
}
/* Release program */
ret = clReleaseProgram(program);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseProgram' failed\n");
exit(1);
}
/* Release command queue */
ret = clReleaseCommandQueue(command_queue);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseCommandQueue' failed\n");
exit(1);
}
/* Release context */
ret = clReleaseContext(context);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseContext' failed\n");
exit(1);
}
return 0;
} |
the_stack_data/397912.c | #include<stdio.h>
int main(){
printf("hello world\n");
return 0;
}
|
the_stack_data/247017908.c | #include "stdio.h"
#include "omp.h"
void main() {
#pragma omp parallel
{
printf("Hello World from Thread %d!\n", omp_get_thread_num());
}
}
|
the_stack_data/22012071.c | // tan_ex.c : tan() example
// -------------------------------------------------------------
#include <math.h> // double tan( double x );
// float tanf( float x );
// long double tanl( long double x );
#include <stdio.h>
int main()
{
const double pi = 4.0L * atan( 1.0 ); // Because tan(pi/4) = 1
double shadow_length = 85.5,
angle = 36.2; // Sun's elevation from the horizon, in
// degrees
double height = shadow_length *tan ( angle * pi/180);
printf("The tower is %.2f meters high.\n", height);
return 0;
}
|
the_stack_data/15761453.c | /* Paolo Nenzi 2002 - This program tests some machine
* dependent variables.
*/
/* Nota:
*
* Compilare due volte nel seguente modo:
*
* gcc test_accuracy.c -o test_64accuracy -lm
* gcc -DIEEEDOUBLE test_accuracy.c -o test_53accuracy -lm
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <fpu_control.h>
int main (void)
{
fpu_control_t prec;
double acc=1.0;
double xl = 0.0;
double xu = 1.0;
double xh, x1, x2;
double xhold =0.0;
#ifdef IEEEDOUBLE
_FPU_GETCW(prec);
prec &= ~_FPU_EXTENDED;
prec |= _FPU_DOUBLE;
_FPU_SETCW(prec);
#endif
for( ; (acc + 1.0) > 1.0 ; ) {
acc *= 0.5;
}
acc *= 2.0;
printf("Accuracy: %e\n", acc);
printf("------------------------------------------------------------------\n");
xh = 0.5 * (xl + xu);
for( ; (xu-xl > (2.0 * acc * (xu + xl))); ) {
x1 = 1.0 / ( 1.0 + (0.5 * xh) );
x2 = xh / ( exp(xh) - 1.0 );
if( (x1 - x2) <= (acc * (x1 + x2))) {
xl = xh;
xhold = xh;
} else {
xu = xh;
xhold = xh;
}
xh = 0.5 * (xl + xu);
/* if (xhold == xh) break; */
}
printf("xu-xl: %e \t cond: %e \t xh: %e\n", (xu-xl), (2.0 * acc * (xu + xl)), xh);
exit(1);
}
|
the_stack_data/141680.c | #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv) {
char **args = malloc(sizeof(char*) * (argc + 1));
size_t i;
for(i = 1; i < argc; ++i) {
args[i] = argv[i];
}
args[argc] = 0;
execv("/opt/reprounzip/reprounzip-qt", args);
perror("execv failed");
return 1;
}
|
the_stack_data/49331.c | #ifdef STM32H7xx
#include "stm32h7xx_ll_mdma.c"
#endif
|
the_stack_data/326394.c | // RUN: %clang_cc1 %s -fsyntax-only -fdouble-square-bracket-attributes -verify
void __attribute__((annotate("foo"))) foo(float *a) {
__attribute__((annotate("bar"))) int x;
[[clang::annotate("bar")]] int x2;
__attribute__((annotate(1))) int y; // expected-error {{'annotate' attribute requires a string}}
[[clang::annotate(1)]] int y2; // expected-error {{'annotate' attribute requires a string}}
__attribute__((annotate("bar", 1))) int z;
[[clang::annotate("bar", 1)]] int z2;
int u = __builtin_annotation(z, (char*) 0); // expected-error {{second argument to __builtin_annotation must be a non-wide string constant}}
int v = __builtin_annotation(z, (char*) L"bar"); // expected-error {{second argument to __builtin_annotation must be a non-wide string constant}}
int w = __builtin_annotation(z, "foo");
float b = __builtin_annotation(*a, "foo"); // expected-error {{first argument to __builtin_annotation must be an integer}}
__attribute__((annotate())) int c; // expected-error {{'annotate' attribute takes at least 1 argument}}
[[clang::annotate()]] int c2; // expected-error {{'annotate' attribute takes at least 1 argument}}
}
|
the_stack_data/151704934.c | // 5.2 -- prints numbers from the entered to +10
#include <stdio.h>
int main(void)
{
int num, sum;
printf("Please, enter the number: ");
scanf("%d", &num);
sum = num + 10;
while(num <= sum)
{
printf("%-4d", num);
++num;
}
printf("\n");
return 0;
}
|
the_stack_data/175144272.c | // RUN: clang -x c-header -o %t.pch %s
// RUN: echo > %t.empty.c
// RUN: clang -include %t -x c %t.empty.c -emit-llvm -S -o -
// PR 4489: Crash with PCH
// PR 4492: Crash with PCH (round two)
// PR 4509: Crash with PCH (round three)
typedef struct _IO_FILE FILE;
extern int fprintf (struct _IO_FILE *__restrict __stream,
__const char *__restrict __format, ...);
int x(void)
{
switch (1) {
case 2: ;
int y = 0;
}
}
void y(void) {
extern char z;
fprintf (0, "a");
}
struct y0 { int i; } y0[1] = {};
void x0(void)
{
extern char z0;
fprintf (0, "a");
}
void x1(void)
{
fprintf (0, "asdf");
}
void y1(void)
{
extern char e;
fprintf (0, "asdf");
}
|
the_stack_data/237644275.c | #include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv)
{
float num1, num2, result;
char op;
char* op_string = malloc(5 * sizeof(char));
printf("Entre com os dois valores separados por espaco: ");
scanf("%f %f", &num1, &num2);
printf("Entre com a operacao (som, sub, mult, div): ");
scanf("%s", op_string);
if (!strcmp(op_string, "sum")){
result = num1 + num2;
op = '+';
}
else if(!strcmp(op_string, "sub")){
result = num1 - num2;
op = '-';
}
else if(!strcmp(op_string, "mult")){
result = num1 * num2;
op = 'x';
}
else if (!strcmp(op_string, "div")){
result = num1 / num2;
op = '/';
} else{
printf("Sua operação não foi identificada.\n");
exit(-1);
}
printf("%.2f %c %.2f = %.2f\n", num1, op, num2, result);
}
|
the_stack_data/148577815.c | /* Test for constant expressions: const variable with value 0 is not a
null pointer constant so the conditional expression should have
type void * and the assignment is OK. */
/* Origin: Joseph Myers <[email protected]> */
/* { dg-do compile } */
/* { dg-options "-std=iso9899:1990 -O2" } */
int *p;
long *q;
static void *const n = 0;
int j;
void f(void) { q = j ? p : n; }
|
the_stack_data/21973.c | /*Exercício 10 seção 5.: Faça um programa que calcule e mostre a soma dos 50 primeiros números pares.*/
#include <stdio.h>
int main (){
int i, j, soma = 0 ;
int vetor[51];
for( i = 0; i < 51; i++ ){
if( i % 2 == 0 ){
soma = soma + i;
printf("[%2d]", i);
}//if for
}//for i
printf("\n");
/*
for( j = 0; j < 50; j++ ){
printf("%d", vetor[j]);
}//for printf
*/
printf("\nA soma dos 50 primeiros numeros pares é:[%d ]\n\n", soma);
return 0 ;
}//main
|
the_stack_data/1118217.c | /*
* Exercise 1-14. Write a program to print a histogram of the frequences of
* different characters in ints input.
*/
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#define DIM 10
int main() {
int digitcounters[DIM];
for (int i = 0; i < DIM; ++i)
digitcounters[i] = 0;
char c;
while ((c = getchar()) != EOF)
if (isdigit(c))
++digitcounters[c - '0'];
putchar('\n');
for (int i = 0; i < DIM; ++i)
printf(" %d", i);
putchar('\n');
for (int i = 0; i < DIM; ++i)
printf(" ");
bool end;
int row = 1;
do {
putchar('\n');
end = true;
for (int i = 0; i < DIM; ++i) {
putchar(' ');
if (digitcounters[i] >= row) {
putchar('*');
end = false;
} else
putchar(' ');
}
++row;
} while (!end);
putchar('\n');
}
|
the_stack_data/140508.c | int getint();
int putchar(int x);
int putint(int x);
int fa[4400066];
int a[200003];
int dep[200003];
int n;
int pos[200003];
int m;
int _2(int x, int a[40])
{
int l;
l = 0;
while (x != 0) {
a[l] = x % 2;
l = l + 1;
x = x / 2;
}
int i;
i = l;
while (i < 40) {
a[i] = 0;
i = i + 1;
}
return l;
}
int _xor(int x, int y)
{
int ax[40];
int ay[40];
_2(x, ax);
_2(y, ay);
int i;
i = 40 - 1;
int ans;
ans = 0;
while (i != -1) {
if (ax[i] + ay[i] == 1)
ans = ans * 2 + 1;
else
ans = ans * 2;
i = i - 1;
}
return ans;
}
int calcfa(int x)
{
int i;
i = 1;
while (i < 22) {
fa[x * 22 + i] = fa[fa[x * 22 + i - 1] * 22 + i - 1];
i = i + 1;
}
return 0;
}
int query(int x, int p)
{
int i;
i = 21;
int pi;
pi = 2097152;
while (p) {
while (pi > p) {
i = i - 1;
pi = pi / 2;
}
p = p - pi;
x = fa[x * 22 + i];
}
return a[x];
}
int main()
{
int T;
T = getint();
while (T != 0) {
T = T - 1;
n = getint();
int lastans;
lastans = 0;
m = 1;
int j;
j = 1;
int i;
i = 1;
while (i < n + 1) {
int op;
int x;
op = getint();
x = getint();
op = _xor(op, lastans);
x = _xor(x, lastans);
if (op == 1) {
pos[j] = m;
a[m] = x;
fa[m * 22] = pos[j - 1];
dep[m] = dep[pos[j - 1]] + 1;
calcfa(m);
m = m + 1;
j = j + 1;
}
else if (op == 2) {
pos[j] = pos[j - 1 - x];
j = j + 1;
}
else { // op == 3
lastans = query(pos[j - 1], dep[pos[j - 1]] - x);
putint(lastans);
putchar(10);
}
i = i + 1;
}
}
return 0;
}
|
the_stack_data/37637779.c | // PARAM: --set solver td3 --set ana.base.arrays.domain partitioned --set ana.activated "['base','threadid','threadflag','escape','expRelation','mallocWrapper']" --set ana.base.privatization none --enable annotation.int.enabled --set ana.int.refinement fixpoint
void example1(void) __attribute__((goblint_precision("no-def_exc","interval")));
void example2(void) __attribute__((goblint_precision("no-def_exc","interval")));
int main(void) {
example1();
example2();
return 0;
}
// Two-dimensional array
void example1(void) {
int a[10][10];
int i=0;
int j=0;
while(i < 9) {
j = 0;
while(j < 10) {
a[i][j] = 42;
j++;
}
assert(a[i][0] == 42);
assert(a[i][9] == 42);
assert(a[3][9] == 42); // UNKNOWN
i++;
}
assert(a[0][0] == 42);
assert(a[2][5] == 42);
assert(a[8][9] == 42);
assert(a[3][7] == 42);
assert(a[9][9] == 42); // UNKNOWN
assert(a[9][2] == 42); // UNKNOWN
}
// Combines backwards- and forwards-iteration
void example2(void) {
int array[10][10];
int i = 9;
while(i >= 0) {
int j =0;
while(j < 10) {
array[i][j] = 4711;
assert(array[i-1][j+1] == 4711); //UNKNOWN
j++;
}
i--;
}
assert(array[2][3] == 4711);
assert(array[0][9] == 4711);
assert(array[8][5] == 4711);
assert(array[2][1] == 4711);
assert(array[0][0] == 4711);
assert(array[7][5] == 4711);
}
|
the_stack_data/151706467.c | #include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
int main (int argc, char** argv) {
struct timeval tvalBefore, tvalAfter;
long delta;
gettimeofday (&tvalBefore, NULL);
sleep(2);
gettimeofday (&tvalAfter, NULL);
// Changed format to long int (%ld), changed time calculation
delta = (tvalAfter.tv_sec - tvalBefore.tv_sec)*1000000L
+(tvalAfter.tv_usec - tvalBefore.tv_usec);
printf("Time in microseconds: %ld microseconds\n", delta);
if(delta > 0)
return 0;
return 1;
}
|
the_stack_data/198580067.c | /* Copyright (c) Microsoft Corporation.
Licensed under the MIT License. */
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
extern int errno;
extern int _end;
caddr_t _sbrk(int incr);
int _close(int file);
int _fstat(int file, struct stat *st);
int _isatty(int file);
int _lseek(int file, int ptr, int dir);
void _exit(int status);
void _kill(int pid, int sig);
int _getpid(void);
caddr_t _sbrk(int incr)
{
static unsigned char* heap = NULL;
unsigned char* prev_heap;
if (heap == NULL)
{
heap = (unsigned char*)&_end;
}
prev_heap = heap;
heap += incr;
return (caddr_t)prev_heap;
}
int _close(int file)
{
return -1;
}
int _fstat(int file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}
int _isatty(int file)
{
return 1;
}
int _lseek(int file, int ptr, int dir)
{
return 0;
}
void _exit(int status)
{
printf("Exiting with status %d.\n", status);
while (1);
}
void _kill(int pid, int sig)
{
(void)pid;
(void)sig;
return;
}
int _getpid(void)
{
return -1;
} |
the_stack_data/15763900.c | a, b, c, d, e, f, g, h, i, j;
k() {
if (i || h && b)
l();
if ((i || h) && b)
l();
if ((j || h) && b)
l();
if ((j || h) && b)
l();
if ((i || h) && f)
l();
if ((i || h) && f)
l();
if ((j || h) && f)
l();
if ((j || h) && f)
l();
if ((i || h) && g)
l();
if ((i || h) && g)
l();
if ((j || h) && g)
l();
if ((j || h) && g)
l();
if ((i || h) && c)
l();
if ((i || h) && c)
l();
if ((j || h) && c)
l();
if ((j || h) && c)
l();
if ((i || h) && a)
l();
if ((i || h) && a)
l();
if ((j || h) && a)
l();
if ((j || h) && a)
l();
if (h && d)
l();
if (h && d)
l();
if (h && e)
l();
if (h && e)
l();
}
|
the_stack_data/818583.c | int main() {
double arr[3];
arr[0] = 1;
arr[1] = 2.0;
arr[2] = arr - arr;
return (int)(arr[0] + arr[1] + arr[2]);
}
|
the_stack_data/23420.c | #include <stdlib.h>
#include <stdio.h>
#include <xcb/xcb.h>
int main ()
{
/* geometric objects */
xcb_point_t points[] = {
{10, 10},
{10, 20},
{20, 10},
{20, 20}};
xcb_point_t polyline[] = {
{50, 10},
{ 5, 20}, /* rest of points are relative */
{25,-20},
{10, 10}};
xcb_segment_t segments[] = {
{100, 10, 140, 30},
{110, 25, 130, 60}};
xcb_rectangle_t rectangles[] = {
{ 10, 50, 40, 20},
{ 80, 50, 10, 40}};
xcb_arc_t arcs[] = {
{10, 100, 60, 40, 0, 90 << 6},
{90, 100, 55, 40, 0, 270 << 6}};
/* Open the connection to the X server */
xcb_connection_t *connection = xcb_connect (NULL, NULL);
/* Get the first screen */
xcb_screen_t *screen = xcb_setup_roots_iterator (xcb_get_setup (connection)).data;
/* Create black (foreground) graphic context */
xcb_drawable_t window = screen->root;
xcb_gcontext_t foreground = xcb_generate_id (connection);
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
uint32_t values[2] = {screen->black_pixel, 0};
xcb_create_gc (connection, foreground, window, mask, values);
/* Create a window */
window = xcb_generate_id (connection);
mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
values[0] = screen->white_pixel;
values[1] = XCB_EVENT_MASK_EXPOSURE;
xcb_create_window (connection, /* connection */
XCB_COPY_FROM_PARENT, /* depth */
window, /* window Id */
screen->root, /* parent window */
0, 0, /* x, y */
150, 150, /* width, height */
10, /* border_width */
XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
screen->root_visual, /* visual */
mask, values ); /* masks */
/* Map the window on the screen and flush*/
xcb_map_window (connection, window);
xcb_flush (connection);
/* draw primitives */
xcb_generic_event_t *event;
while (event = xcb_wait_for_event (connection)) {
switch (event->response_type & ~0x80) {
case XCB_EXPOSE:
/* We draw the points */
xcb_poly_point (connection, XCB_COORD_MODE_ORIGIN, window, foreground, 4, points);
/* We draw the polygonal line */
xcb_poly_line (connection, XCB_COORD_MODE_PREVIOUS, window, foreground, 4, polyline);
/* We draw the segements */
xcb_poly_segment (connection, window, foreground, 2, segments);
/* draw the rectangles */
xcb_poly_rectangle (connection, window, foreground, 2, rectangles);
/* draw the arcs */
xcb_poly_arc (connection, window, foreground, 2, arcs);
/* flush the request */
xcb_flush (connection);
break;
default:
/* Unknown event type, ignore it */
break;
}
free (event);
}
return 0;
}
|
the_stack_data/485206.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Matriz_ Matriz;
Matriz* matriz_crear(size_t numFilas, size_t numColumnas);
void matriz_destruir(Matriz* matriz);
double matriz_leer(Matriz* matriz, size_t fil, size_t col);
void matriz_escribir(Matriz* matriz, size_t fil, size_t col, double val);
size_t matriz_num_filas(Matriz* matriz);
size_t matriz_num_columnas(Matriz* matriz);
void matriz_cero(Matriz* matriz);
void matriz_imprimir(Matriz* matriz);
void matriz_intercambiar_filas(Matriz* matriz, size_t fil, size_t nfil);
int main(){
Matriz *matriz = matriz_crear(5,5);
matriz_cero(matriz);
size_t cols = matriz_num_columnas(matriz);
size_t fils = matriz_num_filas(matriz);
printf("%d\n", cols);
printf("%d\n", fils);
matriz_escribir(matriz, 2, 2, 6.0);
double resp = matriz_leer(matriz, 2, 2);
printf("%.2f\n", resp);
matriz_imprimir(matriz);
matriz_intercambiar_filas(matriz, 2, 4);
matriz_imprimir(matriz);
matriz_destruir(matriz);
return 0;
}
struct Matriz_ {
double **direccion;
size_t columnas;
size_t filas;
};
Matriz* matriz_crear(size_t numFilas, size_t numColumnas) {
Matriz *matriz = malloc(sizeof(Matriz));
matriz->direccion = malloc(sizeof(double)*numFilas);
int i;
for(i = 0; i < numFilas; i++)
*(matriz->direccion+i) = malloc(sizeof(double)*numColumnas);
matriz->columnas = numColumnas;
matriz->filas = numFilas;
return matriz;
}
void matriz_destruir(Matriz* matriz) {
int i;
for(i = 0; i < matriz_num_filas(matriz); i++)
free(*(matriz->direccion+i));
free(matriz->direccion);
free(matriz);
}
double matriz_leer(Matriz* matriz, size_t fil, size_t col) {
return *(*(matriz->direccion+fil)+col);
}
void matriz_escribir(Matriz* matriz, size_t fil, size_t col, double val) {
*(*(matriz->direccion+fil)+col) = val;
}
size_t matriz_num_filas(Matriz* matriz) {
return matriz->filas;
}
size_t matriz_num_columnas(Matriz* matriz) {
return matriz->columnas;
}
void matriz_cero(Matriz* matriz){
int i,j;
for(i = 0; i < matriz->filas; i++)
for(j = 0; j < matriz->columnas; j++)
matriz->direccion[i][j] = 0;
}
void matriz_imprimir(Matriz* matriz){
int i,j;
printf("\n");
for(i = 0; i < matriz->filas; i++){
for(j = 0; j < matriz->columnas; j++)
printf("%.2f ", matriz->direccion[i][j]);
printf("\n");
}
printf("\n");
}
void matriz_intercambiar_filas(Matriz* matriz, size_t fil, size_t nfil){
double *temp = matriz->direccion[fil];
matriz->direccion[fil] = matriz->direccion[nfil];
matriz->direccion[nfil] = temp;
}
|
the_stack_data/182952194.c | // PARAM: --set exp.structs.domain "keyed" --disable exp.structs.key.forward --disable exp.structs.key.avoid-ints
#include<assert.h>
#include<stdio.h>
struct FunctionInfo {
void* ptr;
int id;
};
struct Task {
struct FunctionInfo f;
int taskId;
int arg;
};
struct Task task;
/// Finds the factorial of given number
int factorial(int n) {
int acc = 1;
for (int i = 1; i <= n; i++) {
acc *= i;
}
return acc;
}
/// Finds the "n" given a "n!".
/// In case an integer "n" cannot be calculated, return the upper (ceil) number.
int inverseFactorial(int fac) {
int product = 1;
int n = 1;
while (product < fac) {
n++;
product *= n;
}
printf("Inverse found!\n"); // create a side effect and prevent optimizations
return n;
}
int example1() {
int choice; // Which function to run
int size; // Size / difficulty of algorithm
if (size == 0) {
if (choice == 1) {
task.f.id = 1;
task.f.ptr = factorial;
task.arg = 3;
} else {
task.f.id = 2;
task.f.ptr = inverseFactorial;
task.arg = 6;
}
task.taskId = 0;
} else if (size == 2) {
if (choice == 1) {;
task.f.id = 1;
task.f.ptr = factorial;
task.arg = 5;
} else {
task.f.id = 2;
task.f.ptr = inverseFactorial;
task.arg = 120;
}
task.taskId = 1;
} else {
if (choice == 1) {
task.f.id = 1;
task.f.ptr = factorial;
task.arg = 10;
} else {
task.f.id = 2;
task.f.ptr = inverseFactorial;
task.arg = 3628800;
}
task.taskId = 2;
}
typedef int (*fun)(int);
// if (task.f.id == 1) {
// fun f = task.f.ptr;
// assert(f == factorial);
// if (task.taskId == 0) {
// assert(task.arg == 3);
// } else if (task.taskId == 1) {
// assert(task.arg == 5);
// } else if (task.taskId == 2) {
// assert(task.arg == 10);
// }
// int result = f(task.arg);
// printf("Factorial of %d is %d\n", task.arg, result);
// }
if (task.f.id == 1) {
fun f = task.f.ptr;
assert(f == factorial);
if (task.taskId == 0) {
assert(task.arg == 3);
} else if (task.taskId == 1) {
assert(task.arg == 5);
} else if (task.taskId == 2) {
assert(task.arg == 10);
}
int result = f(task.arg);
printf("Factorial of %d is %d\n", task.arg, result);
} else if (task.f.id == 2) {
fun f = task.f.ptr;
assert(f == inverseFactorial);
if (task.taskId == 0) {
assert(task.arg == 6);
} else if (task.taskId == 1) {
assert(task.arg == 120);
} else if (task.taskId == 2) {
assert(task.arg == 3628800);
}
int result = f(task.arg);
printf("Factorial of %d is %d\n", result, task.arg);
} else {
fun f = task.f.ptr;
printf("Exiting with code %d...\n", task.arg);
int result = f(task.arg);
}
return 0;
}
int example2() {
int choice; // Which function to run
int size; // Size / difficulty of algorithm
if (size == 0) {
struct FunctionInfo functionToRun;
if (choice == 1) {
functionToRun.id = 1;
functionToRun.ptr = factorial;
task.arg = 3;
} else {
functionToRun.id = 2;
functionToRun.ptr = inverseFactorial;
task.arg = 6;
}
// Holds two variants for functionToRun and two for task!
task.f = functionToRun;
// Adds the functionToRun variants to both task variants -> connection lost!
task.taskId = 0;
} else if (size == 2) {
struct FunctionInfo functionToRun;
if (choice == 1) {
functionToRun.id = 1;
functionToRun.ptr = factorial;
task.arg = 5;
} else {
functionToRun.id = 2;
functionToRun.ptr = inverseFactorial;
task.arg = 120;
}
task.f = functionToRun;
task.taskId = 1;
} else {
struct FunctionInfo functionToRun;
if (choice == 1) {
functionToRun.id = 1;
functionToRun.ptr = factorial;
task.arg = 10;
} else {
functionToRun.id = 2;
functionToRun.ptr = inverseFactorial;
task.arg = 3628800;
}
task.f = functionToRun;
task.taskId = 2;
}
typedef int (*fun)(int);
if (task.f.id == 1) {
fun f = task.f.ptr;
assert(f == factorial);
if (task.taskId == 0) {
assert(task.arg == 3); // UNKNOWN
} else if (task.taskId == 1) {
assert(task.arg == 5); // UNKNOWN
} else if (task.taskId == 2) {
assert(task.arg == 10); // UNKNOWN
}
int result = f(task.arg);
printf("Factorial of %d is %d\n", task.arg, result);
} else if (task.f.id == 2) {
fun f = task.f.ptr;
assert(f == inverseFactorial);
if (task.taskId == 0) {
assert(task.arg == 6); // UNKNOWN
} else if (task.taskId == 1) {
assert(task.arg == 120); // UNKNOWN
} else if (task.taskId == 2) {
assert(task.arg == 3628800); // UNKNOWN
}
int result = f(task.arg);
printf("Factorial of %d is %d\n", result, task.arg);
} else {
fun f = task.f.ptr;
printf("Exiting with code %d...\n", task.arg);
int result = f(task.arg);
}
return 0;
}
int main() {
example1();
example2();
return 0;
}
|
the_stack_data/135355.c | #include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
#include <sys/stat.h>
#include <unistd.h>
#define ERR(source) (perror(source),\
fprintf(stderr,"%s:%d\n",__FILE__,__LINE__),\
exit(EXIT_FAILURE))
#define MAX_PATH 60
void scan_dir (){
DIR *dirp;
struct dirent *dp;
struct stat filestat;
int dirs=0,files=0,links=0,other=0;
if(NULL == (dirp = opendir("."))) ERR("opendir");
do {
errno = 0;
if ((dp = readdir(dirp)) != NULL) {
if (lstat(dp->d_name, &filestat)) ERR("lstat");
if (S_ISDIR(filestat.st_mode)) dirs++;
else if (S_ISREG(filestat.st_mode)) files++;
else if (S_ISLNK(filestat.st_mode)) links++;
else other++;
}
} while (dp != NULL);
if (errno != 0) ERR("readdir");
if(closedir(dirp)) ERR("closedir");
printf("Files: %d, Dirs: %d, Links: %d, Other: %d\n",files,dirs,links,other);
}
int main(int argc, char** argv) {
char path[MAX_PATH];
int i;
if(getcwd(path, MAX_PATH)==NULL) ERR("getcwd");
for(i=1;i<argc;i++){
if(chdir(argv[i]))ERR("chdir");
printf("%s:\n",argv[i]);
scan_dir();
if(chdir(path))ERR("chdir");
}
return EXIT_SUCCESS;
}
|
the_stack_data/112413.c | #include <stdio.h>
int main(int argc, char **argv)
{
printf("Trimble meta layer saying: Hello World!\n");
return 0;
}
|
the_stack_data/103266477.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXTAM 100
typedef struct ItemL {
char frase[MAXTAM];
}ItemL;
typedef struct ItemP {
char chave;
}ItemP;
typedef struct Lista {
ItemL item[MAXTAM];
int tam;
}Lista;
typedef struct Pilha {
ItemP item[MAXTAM];
int topo;
}Pilha;
Pilha * cria_pilha_vazia()
{
Pilha *p = malloc(sizeof(Pilha));
p->topo = -1;
return p;
}
int verifica_pilha_cheia(Pilha *p)
{
return p->topo == MAXTAM - 1;
}
void empilha(Pilha *p, int chave)
{
if(verifica_pilha_cheia(p)){
printf("Erro: a pilha está cheia.\n");
return;
}
else {
ItemP novo_item;
novo_item.chave = chave;
p->topo++;
p->item[p->topo] = novo_item;
}
}
int verifica_pilha_vazia(Pilha *p)
{
return p->topo == -1;
}
void desempilha(Pilha *p)
{
if (verifica_pilha_vazia(p)) {
printf("Erro: a pilha está vazia.\n");
return;
}
else {
p->topo--;
}
}
void libera_pilha(Pilha *p)
{
free(p);
}
void verificaParenteses( int n)
{
Lista *l;
int i;
l = (Lista*) malloc (sizeof(Lista));
l->tam = n;
i=0;
while( i < n )
{
scanf("%s", &l->item[i].frase);
i++;
}
int tam;
for (i=0;i<n;i++)
{
tam = parenteses(l->item[i].frase);
if(tam==0)
printf("incorrect\n");
else
printf("correct\n");
}
}
int parenteses (char s[])
{
Pilha *pilha = cria_pilha_vazia();
int n, i, t;
n = strlen (s);
t = 0;
i = 0;
while (s[i] != '\0')
{
if(s[i] == ')')
{
if (t != 0 && pilha->item[t-1].chave == '(')
{
--t;
desempilha(pilha);
}
else
return 0;
}
else if(s[i] == '(')
{
t++;
empilha(pilha, s[i]);
}
++i;
}
libera_pilha(pilha);
if (t == 0)
return 1;
else
return 0;
}
int main ()
{
int n;
scanf("%d", &n);
verificaParenteses(n);
}
|
the_stack_data/73868.c | /*
* ashldi3.c extracted from gcc-2.7.2.3/libgcc2.c and
* gcc-2.7.2.3/longlong.h
*
* Copyright (C) 1989-2015 Free Software Foundation, Inc.
*
* SPDX-License-Identifier: GPL-2.0+
*/
#define BITS_PER_UNIT 8
typedef int SItype __attribute__ ((mode (SI)));
typedef unsigned int USItype __attribute__ ((mode (SI)));
typedef int DItype __attribute__ ((mode (DI)));
typedef int word_type __attribute__ ((mode (__word__)));
struct DIstruct {SItype high, low;};
typedef union
{
struct DIstruct s;
DItype ll;
} DIunion;
DItype __ashldi3 (DItype u, word_type b)
{
DIunion w;
word_type bm;
DIunion uu;
if (b == 0)
return u;
uu.ll = u;
bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
if (bm <= 0)
{
w.s.low = 0;
w.s.high = (USItype)uu.s.low << -bm;
}
else
{
USItype carries = (USItype)uu.s.low >> bm;
w.s.low = (USItype)uu.s.low << b;
w.s.high = ((USItype)uu.s.high << b) | carries;
}
return w.ll;
} |
the_stack_data/26699670.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 n ,sum=0;
int i;
printf("input int N value: ");
scanf("%d" ,&n);
for(i= 0 ; i<=n ; i++){
sum =sum + i;
}
printf("Total sum of %d numbers = %d " ,n,sum);
return 0;
}
|
the_stack_data/28261518.c | #include <stdio.h>
#define N 5 //Number of STUDENTS
#define M 5 //Number of SUBJECTS
int main(){
/*N ROWS because N Students,
M COLUMNS because M Subjects
also, M low scores for M SUBJECTS*/
int rowSums[N], colSums[M], lowScores[M];
int i, j, x;
double avg;
//INITIALIZATION
for (i = 0; i < N; i++)
rowSums[i] = 0;
for (i = 0; i < M; i++){
colSums[i] = 0;
lowScores[i] = -1; //We put -1 in low scores because otherwise, it will be always be 0
}
for (i = 0; i < N; i++){
//NUMBERS OF i'th student
printf("Enter row %d: ", i+1);
for (j = 0; j < M; j++){
scanf("%d", &x); //NUMBER OF i'th student of j'th subject
rowSums[i] += x; //UPDATE THE SUMS OF i'th ROW & j'th COLUMN
colSums[j] += x;
if (x < lowScores[j] || lowScores[j] < 0) //UPDATE THE LOW SCORE of j'th SUBJECT
lowScores[j] = x;
}
printf("\n");
}
printf("ROW TOTALS and AVERAGES:\n");
for (i = 0; i < N; i++){
/* Row average = average number of a single student = TOTAL number of that student/ #of subjects(M) */
avg = (double)rowSums[i]/M;
printf("Student #%d: Total= %d, Avg= %.2lf\n", i+1, rowSums[i], avg);
}
printf("COLUMN TOTALS and AVERAGES:\n");
for (i = 0; i < M; i++){
/* Column average = average number of a different subjects = TOTAL number in that subject/ #of students(N) */
avg = (double)colSums[i]/N;
printf("Subject #%d: Total= %d, Avg= %.2lf, Lowest= %d\n", i+1, colSums[i], avg, lowScores[i]);
}
}
|
the_stack_data/36076358.c | /* posix */
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
/* bsd extensions */
#include <sys/uio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/un.h>
char*
inet_ntoa(struct in_addr in)
{
static char s[18];
unsigned char *p;
p = (unsigned char*)&in.s_addr;
snprintf(s, sizeof s, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
return s;
}
|
the_stack_data/200143382.c |
/*
* Given the actual number of the function calls, count, and the total cpu
* time spent, time, estimate the number of function calls required so
* that the total cpu time consumed by the function, is between tmin and tmax.
* All times - time, tmin, and tmax - must be in the same units, e.g. secs,
* usecs, mins, etc)
*/
int adjust_rep_count (int count, double time, double tmin, double tmax);
int adjust_rep_count (int count, double time, double tmin, double tmax)
{
if (time > tmax)
{
count /= time/tmax;
count = count < 1 ? 1 : count;
}
else if (time < tmin)
{
count /= time/tmin;
}
return count;
}
|
the_stack_data/34512101.c | #include "check.h"
int main(void)
{
check("n*m+m*n", "nm(1+1)");
}
|
the_stack_data/89201077.c | #include <stdio.h>
#include <stdint.h>
struct s1 {
uint32_t i0;
uint32_t i1;
uint32_t i2;
uint32_t i3;
};
struct s2 {
uint8_t b;
uint64_t l;
};
int main(void) {
struct s1 v1;
printf("&v1 = %p\n", &v1);
printf("&(v1.i0) = %p\n", &(v1.i0));
printf("&(v1.i1) = %p\n", &(v1.i1));
printf("&(v1.i2) = %p\n", &(v1.i2));
printf("&(v1.i3) = %p\n", &(v1.i3));
printf("\nThis shows struct padding\n");
struct s2 v2;
printf("&v2 = %p\n", &v2);
printf("&(v2.b) = %p\n", &(v2.b));
printf("&(v2.l) = %p\n", &(v2.l));
}
|
the_stack_data/152901.c | int main(){
int a = 7;
return 0;
} |
the_stack_data/193893934.c | #include <stdio.h>
int main()
{
long long int N,p,a,sum,j;
while(scanf("%lld",&N)!=EOF)
{
if(N<0)
break;
p=1;
sum=0;
for(j=1;N!=0;j++)
{
a=N%3;
sum=sum + (a*p);
N=N/3;
p=p*10;
}
printf("%lld\n",sum);
}
return 0;
}
|
the_stack_data/192330263.c | #include<stdio.h>
/*
* a 097 01100001 A 065 01000001
b 098 01100010 B 066 01000010
c 099 01100011 C 067 01000011
d 100 01100100 D 068 01000100
e 101 01100101 E 069 01000101
f 102 01100110 F 070 01000110
g 103 01100111 G 071 01000111
h 104 01101000 H 072 01001000
i 105 01101001 I 073 01001001
j 106 01101010 J 074 01001010
k 107 01101011 K 075 01001011
l 108 01101100 L 076 01001100
m 109 01101101 M 077 01001101
n 110 01101110 N 078 01001110
o 111 01101111 O 079 01001111
p 112 01110000 P 080 01010000
q 113 01110001 Q 081 01010001
r 114 01110010 R 082 01010010
s 115 01110011 S 083 01010011
t 116 01110100 T 084 01010100
u 117 01110101 U 085 01010101
v 118 01110110 V 086 01010110
w 119 01110111 W 087 01010111
x 120 01111000 X 088 01011000
y 121 01111001 Y 089 01011001
z 122 01111010 Z 090 01011010
*/
int main()
{
int i,j;
int a = 97;
for(i=0;i<5;i++)
{
for (j=0;j<5;j++)
{
if(i==j || i<=j)
{
printf("%c",a);
a++;
}
else
{
printf(" ");
}
}
printf("\n");
}
return 0;
}
|
the_stack_data/34513289.c | #include <stdio.h>
#include <stdint.h>
static void hacks(char *file)
{
FILE *ihacku;
char buffer[128 / 3 - 3];
int n = 0, k = 0;
int next = 0;
if((ihacku = fopen(file, "r")) == NULL)
return;
while((n = fread(buffer, sizeof(char), 128 / 3 - 3, ihacku)) != 0)
{
int i =0;
for(i = 0; i < n; i++)
{
k++;
printf("\\x%02x", (uint8_t)buffer[i]);
}
}
printf("\n");
printf("%d\n", k);
return;
}
int main(int argc, char **args)
{
if(argc < 2)
{
printf("%s binary\n", args[0]);
return 0;
}
hacks(args[1]);
}
|
the_stack_data/273164.c | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
void findWord(char *s, int start, int *realStart, int *length)
{
while (s[start] != '\0' && s[start] == ' ')
{
start++;
}
*realStart = start;
int count = 1;
while (s[start + 1] != '\0' && s[start + 1] != ' ')
{
start++;
count++;
}
*length = count;
return;
}
void reverseStr(char *s, int start, int last)
{
char t;
while (start < last)
{
t = s[start];
s[start] = s[last];
s[last] = t;
start++;
last--;
}
}
void moveStr(char *s, int start, int length, int step)
{
if (step <= 0)
{
return;
}
int last = start + length - 1;
while (start <= last)
{
s[start - step] = s[start];
start++;
}
}
void reverseWords(char *s)
{
if (s == NULL)
{
return;
}
int last = strlen(s) - 1;
if (last < 0)
{
return;
}
int i = 0;
int j = last;
while (i <= last && s[i] == ' ')
i++;
while (j > i && s[j] == ' ')
j--;
int n = i;
if (n > 0 || j < last)
{
for (; i <= j; i++)
s[i - n] = s[i];
}
if (j - n + 1 <= last)
{
s[j - n + 1] = '\0';
}
last = j - n;
int count = 0;
int start, length;
reverseStr(s, 0, last);
i = 0;
while (i <= last)
{
//find consecutive space
while (i <= last && s[i] == ' ')
{
i++;
count++;
}
if (i > last)
{
s[i - count] = '\0';
return;
}
findWord(s, i, &start, &length);
i = start + length - 1;
reverseStr(s, start, i);
moveStr(s, start, length, count);
int nextSpace = i - count + 1;
if (nextSpace < last)
{
s[nextSpace] = ' ';
}
i += 2;
}
if (count > 0)
{
s[last - count + 1] = '\0';
}
}
int main(int argc, char const *argv[])
{
// int len = strlen(argv[1]);
// char *data = (char *)malloc(len + 1);
// strcpy(data, argv[1]);
// char *s = data;
// reverseWords(s);
// printf("%s\n", s);
char data[] = " a b ";
char *s = data;
reverseWords(s);
printf("%s %lu\n", s, strlen(s));
return 0;
}
|
the_stack_data/51701533.c | /* UNIX V7 source code: see /COPYRIGHT or www.tuhs.org for details. */
/* Changes: Copyright (c) 2007 Robert Nordier. All rights reserved. */
int bflg;
int dflg;
int tflg;
int iflg;
int aflg;
int sflg;
struct
{
char name[8];
int type;
unsigned value;
} nl[] = {
"_dk_busy", 0, 0,
"_dk_time", 0, 0,
"_dk_numb", 0, 0,
"_dk_wds", 0, 0,
"_tk_nin", 0, 0,
"_tk_nout", 0, 0,
"_io_info", 0, 0,
"\0\0\0\0\0\0\0\0", 0, 0
};
struct
{
int busy;
long etime[32];
long numb[3];
long wds[3];
long tin;
long tout;
} s, s1;
struct iostat {
int nbuf;
long nread;
long nreada;
long ncache;
long nwrite;
long bufcount[50];
} io_info, io_delta;
double etime;
int mf;
main(argc, argv)
char *argv[];
{
extern char *ctime();
register i;
int iter;
double f1, f2;
long t;
nlist("/unix", nl);
if(nl[0].type == -1) {
printf("dk_busy not found in /unix namelist\n");
exit(1);
}
mf = open("/dev/kmem", 0);
if(mf < 0) {
printf("cannot open /dev/kmem\n");
exit(1);
}
iter = 0;
while (argc>1&&argv[1][0]=='-') {
if (argv[1][1]=='d')
dflg++;
else if (argv[1][1]=='s')
sflg++;
else if (argv[1][1]=='a')
aflg++;
else if (argv[1][1]=='t')
tflg++;
else if (argv[1][1]=='i')
iflg++;
else if (argv[1][1]=='b')
bflg++;
argc--;
argv++;
}
if(argc > 2)
iter = atoi(argv[2]);
if (!(sflg|iflg)) {
if(tflg)
printf(" TTY");
if (bflg==0)
printf(" HD FD CD PERCENT\n");
if(tflg)
printf(" tin tout");
if (bflg==0)
printf(" tpm msps mspt tpm msps mspt tpm msps mspt user nice systm idle\n");
}
loop:
lseek(mf, (long)nl[0].value, 0);
read(mf, (char *)&s.busy, sizeof s.busy);
lseek(mf, (long)nl[1].value, 0);
read(mf, (char *)s.etime, sizeof s.etime);
lseek(mf, (long)nl[2].value, 0);
read(mf, (char *)s.numb, sizeof s.numb);
lseek(mf, (long)nl[3].value, 0);
read(mf, (char *)s.wds, sizeof s.wds);
lseek(mf, (long)nl[4].value, 0);
read(mf, (char *)&s.tin, sizeof s.tin);
lseek(mf, (long)nl[5].value, 0);
read(mf, (char *)&s.tout, sizeof s.tout);
for(i=0; i<40; i++) {
t = s.etime[i];
s.etime[i] -= s1.etime[i];
s1.etime[i] = t;
}
t = 0;
for(i=0; i<32; i++)
t += s.etime[i];
etime = t;
if(etime == 0.)
etime = 1.;
if (bflg) {
biostats();
goto contin;
}
if (dflg) {
long tm;
time(&tm);
printf("%s", ctime(&tm));
}
if (aflg)
printf("%.2f minutes total\n", etime/3600);
if (sflg) {
stats2(etime);
goto contin;
}
if (iflg) {
stats3(etime);
goto contin;
}
etime /= 60.;
if(tflg) {
f1 = s.tin;
f2 = s.tout;
printf("%6.1f", f1/etime);
printf("%6.1f", f2/etime);
}
for(i=0; i<3; i++)
stats(i);
for(i=0; i<4; i++)
stat1(i*8);
printf("\n");
contin:
--iter;
if(iter)
if(argc > 1) {
sleep(atoi(argv[1]));
goto loop;
}
}
/* usec per word for the various disks */
double xf[] = {
1.0, /* RF */
1.0, /* RK03/05 */
1.0, /* RP06 */
};
stats(dn)
{
register i;
double f1, f2, f3;
double f4, f5, f6;
long t;
t = 0;
for(i=0; i<32; i++)
if(i & (1<<dn))
t += s.etime[i];
f1 = t;
f1 = f1/60.;
f2 = s.numb[dn];
if(f2 == 0.) {
printf("%6.0f%6.1f%6.1f", 0.0, 0.0, 0.0);
return;
}
f3 = s.wds[dn];
f3 = f3*32.;
f4 = xf[dn];
f4 = f4*1.0e-6;
f5 = f1 - f4*f3;
f6 = f1 - f5;
printf("%6.0f", f2*60./etime);
printf("%6.1f", f5*1000./f2);
printf("%6.1f", f6*1000./f2);
}
stat1(o)
{
register i;
long t;
double f1, f2;
t = 0;
for(i=0; i<32; i++)
t += s.etime[i];
f1 = t;
if(f1 == 0.)
f1 = 1.;
t = 0;
for(i=0; i<8; i++)
t += s.etime[o+i];
f2 = t;
printf("%6.2f", f2*100./f1);
}
stats2(t)
double t;
{
register i, j;
for (i=0; i<4; i++) {
for (j=0; j<8; j++)
printf("%6.2f\n", s.etime[8*i+j]/(t/100));
printf("\n");
}
}
stats3(t)
double t;
{
register i;
double sum;
t /= 100;
printf("%6.2f idle\n", s.etime[24]/t);
sum = 0;
for (i=0; i<8; i++)
sum += s.etime[i];
printf("%6.2f user\n", sum/t);
sum = 0;
for (i=0; i<8; i++)
sum += s.etime[8+i];
printf("%6.2f nice\n", sum/t);
sum = 0;
for (i=0; i<8; i++)
sum += s.etime[16+i];
printf("%6.2f system\n", sum/t);
sum = 0;
for (i=1; i<8; i++)
sum += s.etime[24+i];
printf("%6.2f IO wait\n", sum/t);
sum = 0;
for (i=1; i<8; i++)
sum += s.etime[i]+s.etime[i+8]+s.etime[i+16]+s.etime[i+24];
printf("%6.2f IO active\n", sum/t);
sum = 0;
for (i=0; i<32; i++)
if (i&01)
sum += s.etime[i];
printf("%6.2f HD active\n", sum/t);
sum = 0;
for (i=0; i<32; i++)
if (i&02)
sum += s.etime[i];
printf("%6.2f FD active\n", sum/t);
sum = 0;
for (i=0; i<32; i++)
if (i&04)
sum += s.etime[i];
printf("%6.2f CD active\n", sum/t);
}
biostats()
{
register i;
lseek(mf,(long)nl[6].value, 0);
read(mf, (char *)&io_info, sizeof(io_info));
printf("%D\t%D\t%D\t%D\n",
io_info.nread-io_delta.nread, io_info.nreada-io_delta.nreada,
io_info.ncache-io_delta.ncache, io_info.nwrite-io_delta.nwrite);
for(i=0; i<30; ) {
printf("%D\t",(long)io_info.bufcount[i]-io_delta.bufcount[i]);
i++;
if (i % 10 == 0)
printf("\n");
}
io_delta = io_info;
}
|
the_stack_data/124187.c | #define _GNU_SOURCE
#include <fcntl.h>
#include <unistd.h>
int daemon(int nochdir, int noclose)
{
if (!nochdir && chdir("/"))
return -1;
if (!noclose) {
int fd, failed = 0;
if ((fd = open("/dev/null", O_RDWR)) < 0) return -1;
if (dup2(fd, 0) < 0 || dup2(fd, 1) < 0 || dup2(fd, 2) < 0)
failed++;
if (fd > 2) close(fd);
if (failed) return -1;
}
switch(fork()) {
case 0: break;
case -1: return -1;
default: _exit(0);
}
if (setsid() < 0) return -1;
switch(fork()) {
case 0: break;
case -1: return -1;
default: _exit(0);
}
return 0;
}
|
the_stack_data/1132814.c | #include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
int main() {
int input_fd = open("/etc/passwd", O_RDONLY);
int output_fd = open("saida.txt", O_CREAT | O_TRUNC | O_WRONLY, 0666);
int error_fd = open("erros.txt", O_CREAT | O_TRUNC | O_WRONLY, 0666);
int stdout_fd_backup = dup(STDOUT_FILENO);
int stdin_fd = dup2(input_fd, STDIN_FILENO);
int stdout_fd = dup2(output_fd, STDOUT_FILENO);
int stderr_fd = dup2(error_fd, STDERR_FILENO);
if (stdin_fd < 0 || stdout_fd < 0 || stderr_fd < 0 || stdout_fd_backup < 0) return -1;
close(input_fd);
close(output_fd);
close(error_fd);
if (!fork()) {
char buffer;
char line[1024];
int i = 0;
while ((read(STDIN_FILENO, &buffer, 1)) > 0) {
line[i++] = buffer;
if (buffer == '\n') {
write(STDOUT_FILENO, line, i);
write(STDERR_FILENO, line, i);
i = 0;
}
}
_exit(0);
} else {
int status;
wait(&status);
dup2(stdout_fd_backup, STDOUT_FILENO);
close(stdout_fd_backup);
char str[1024];
WIFEXITED(status) ? sprintf(str, "child process returned %d\n", WEXITSTATUS(status))
: sprintf(str, "child process didnt terminate\n");
write(STDOUT_FILENO, str, strlen(str) + 1);
}
return 0;
}
|
the_stack_data/162642187.c |
#include <stdio.h>
#include <pthread.h>
pthread_mutex_t mutex_value;
int a = 1;
int myglobal;
pthread_mutex_t mymutex=PTHREAD_MUTEX_INITIALIZER;
void *thread_function(void *arg)
{
int i,j;
for ( i=0; i<20; i++)
{
pthread_mutex_lock(&mymutex);
j=myglobal; j=j+1;
printf(".");
fflush(stdout);
sleep(1);
myglobal=j;
pthread_mutex_unlock(&mymutex);
}
return NULL;
}
int main(void)
{
pthread_t mythread;
int i;
if ( pthread_create( &mythread, NULL, thread_function, NULL) )
{
printf("error creating thread.");
abort();
}
for ( i=0; i<20; i++)
{
pthread_mutex_lock(&mymutex);
myglobal=myglobal+1;
pthread_mutex_unlock(&mymutex);
printf("o");
fflush(stdout);
sleep(1);
}
if ( pthread_join ( mythread, NULL ) )
{
printf("error joining thread.");
abort();
}
printf("\nmyglobal equals %d\n",myglobal);
exit(0);
}
|
the_stack_data/232954669.c | //MAYANK AGRAWAL
//ROLL NO. 150101033
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int count = 0;
//defining the struct node which consist of key and pointer to left and right child
struct node
{
int key;
struct node *left;
struct node *right;
};
//Creates new node ,puts the data into it and initializes left and right to NULL.
struct node *newNode(int item)
{
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp->key = item;
temp->left = temp->right = NULL;
return temp;
}
/* Inserts the element in correct position i.e. if data < node->data insert it into right subtree
and if it is less then insert it in left subtree. */
/* A utility function to insert a new node with given key in BST */
struct node* insert(struct node* node, int key)
{
if (node == NULL) return newNode(key);
if (key < node->key)
node->left = insert(node->left, key);
else if (key > node->key)
node->right = insert(node->right, key);
return node;
}
//function to do inorder traversal of BST
void inorder(struct node *root)
{
if (root != NULL)
{
inorder(root->left);
printf("%d ", root->key);
inorder(root->right);
}
}
//creating tree using rand() function
struct node *randomtree(){
struct node *temp_root = NULL;
srand(time(NULL)+count);
count++;
int t;
temp_root = insert(temp_root, 1); /* initializing the tree */
for(int i=0;i<99;i++){
t=rand()%1000;
insert(temp_root, t); //using numbers from random function to insert
}
return temp_root;
}
/* It is a bottom up approach for finding LCA. We traverse from the bottom,
and once we reach a node which matches one of the two nodes, we pass it up to its parent.
The parent would then test its left and right subtree if each contain one of the two nodes.
If yes, then the parent must be the LCA and we pass its parent up to the root.
If not, we pass the lower node which contains either one of the two nodes
(if the left or right subtree contains either p or q), or NULL
(if both the left and right subtree does not contain either p or q) up.*/
struct node *LCA(struct node *root, int p, int q) {
if (!root) return NULL;
if (root->key == p || root->key == q) return root;
struct node *left = LCA(root->left, p, q);
struct node *right = LCA(root->right, p, q);
if (left && right) return root; // if p and q are on both sides
return left ? left : right; // either one of p,q is on one side OR p,q is not in L&R subtrees
// Time Complexity : O(n) ,because all the nodes are visited exactly once.
}
int main(){
struct node *root,*temp;
printf("sample tree for this question is \n");
root = randomtree();
inorder(root);
int p,q;
printf("\nenter the numbers whose common ancestor you want to find: ");
scanf("%d %d",&p,&q);
temp=LCA(root,p,q);
printf("the common ancestor is %d",temp->key);
return 0;
}
// Time Complexity : O(n)
// as the recursion function created visits each and every node once and takes time proportional to n where n is the number of nodes
//hence the time complexity is linear |
the_stack_data/90763499.c | #include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <pthread.h>
#include <stdatomic.h>
#include <assert.h>
// futex.h
//
static atomic_int sig;
static inline void __futex_wait(atomic_int *m, int v)
{
int s = atomic_load_explicit(&sig, memory_order_acquire);
if (atomic_load_explicit(m, memory_order_acquire) != v)
return;
while (atomic_load_explicit(&sig, memory_order_acquire) == s)
;
}
static inline void __futex_wake(atomic_int *m, int v)
{
atomic_fetch_add_explicit(&sig, 1, memory_order_release);
}
// mutex_musl.h
//
typedef struct {
atomic_int lock;
atomic_int waiters;
} mutex_t;
static inline void mutex_init(mutex_t *m);
static inline int mutex_lock_fastpath(mutex_t *m);
static inline int mutex_lock_slowpath_check(mutex_t *m);
static inline void mutex_lock(mutex_t *m);
static inline void mutex_unlock(mutex_t *m);
// mutex_musl.c
//
static inline void mutex_init(mutex_t *m)
{
atomic_init(&m->lock, 0);
atomic_init(&m->waiters, 0);
}
static inline int mutex_lock_fastpath(mutex_t *m)
{
int r = 0;
return atomic_compare_exchange_strong_explicit(&m->lock, &r, 1,
memory_order_acquire,
memory_order_acquire);
}
static inline int mutex_lock_slowpath_check(mutex_t *m)
{
int r = 0;
return atomic_compare_exchange_strong_explicit(&m->lock, &r, 1,
memory_order_acquire,
memory_order_acquire);
}
static inline void mutex_lock(mutex_t *m)
{
if (mutex_lock_fastpath(m))
return;
atomic_thread_fence(memory_order_relaxed);
while (mutex_lock_slowpath_check(m) == 0) {
atomic_thread_fence(memory_order_relaxed);
atomic_fetch_add_explicit(&m->waiters, 1, memory_order_relaxed);
int r = 1;
if (!atomic_compare_exchange_strong_explicit(&m->lock, &r, 2,
memory_order_relaxed,
memory_order_relaxed))
atomic_thread_fence(memory_order_relaxed);
__futex_wait(&m->lock, 2);
atomic_fetch_sub_explicit(&m->waiters, 1, memory_order_relaxed);
}
}
static inline void mutex_unlock(mutex_t *m)
{
int old = atomic_exchange_explicit(&m->lock, 0, memory_order_relaxed);
if (atomic_load_explicit(&m->waiters, memory_order_relaxed) > 0 || old != 1)
__futex_wake(&m->lock, 1);
}
// main.c
//
int shared;
mutex_t* mutex;
void *thread_n(void *arg)
{
intptr_t index = ((intptr_t) arg);
mutex_lock(mutex);
shared = index;
int r = shared;
assert(r == index);
mutex_unlock(mutex);
return NULL;
}
// variant
//
int main()
{
pthread_t t0, t1, t2;
mutex = malloc(sizeof(mutex_t));
mutex_init(mutex);
pthread_create(&t0, NULL, thread_n, (void *) 0);
pthread_create(&t1, NULL, thread_n, (void *) 1);
pthread_create(&t2, NULL, thread_n, (void *) 2);
return 0;
}
|
the_stack_data/115764854.c | #include<stdio.h>
extern int add(int, int);
extern int start_run_time_system(int, char**);
int main(int argc,char **argv) {
start_run_time_system(argc, argv);
printf("Result: %d\n", add(1337, 42));
return 1;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.