file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/1059930.c |
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int val_global = 11;
int main(int argc, char *argv[])
{
pid_t pid;
pid = vfork();
if (pid < 0)
{
perror("v_fork");
}
if(pid == 0)
{
val_global++;
printf("son val_global = %d\n",val_global);
_exit(1);
}
else
{
printf("father val_flobal = %d\n",val_global);
sleep(1);
}
return 0;
}
|
the_stack_data/895182.c | #include <stdio.h>
#include <string.h>
char A[10][100];
char Sup[1000];
int overlap (int str1, int str2)
{
int i, j;
j = 0;
i = 0;
while (i < strlen (A[str1]))
{
if (A[str1][i] == A[str2][j])
++j;
else if (j >= 1 && A[str1][i] != A[str2][j])
{
--i;
j = 0;
}
else
j = 0;
++i;
}
return j;
}
char cut (int a, int b, int maxoverlap)
{
A[a][strlen (A[a]) - maxoverlap] = 0;
strcat (A[a], A[b]);
strcpy (A[b], A[a]);
A[a][0] = '\0';
}
int main(int argc, char **argv)
{
int n, i, j, maxi, maxj, k;
int maxoverlap;
int curoverlap;
n = 0;
scanf ("%d", &n);
for (i = 0; i < n; ++i)
scanf ("%s", &A[i][0]);
if (n == 1)
{
printf ("%d", strlen (A[0]));
return 0;
}
for (k = 0; k < n; ++k)
{
maxoverlap = -1;
for (i = 0; i < n; ++i)
for (j = 0; j < n; ++j)
{
if (i == j)
continue;
if (strlen (A[i]) > 0 && strlen (A[j]) > 0)
{
curoverlap = overlap (i, j);
if (curoverlap > maxoverlap)
{
maxoverlap = curoverlap;
maxi = i;
maxj = j;
}
}
}
cut (maxi, maxj, maxoverlap);
}
for (i = 0; i < n; ++i)
if (strlen (A[i]) > 0)
printf ("%d", strlen (A[i]));
return 0;
} |
the_stack_data/170453046.c | #include <stdio.h>
int count; //variavel global
void func1(void);
void func2(void);
int main(){
count=100;
func1();
return 0;
}
void func1(void){
int temp;
temp = count;
printf("o valor de count vale %d", count);
func2();
printf("\nCount vale %d no escopo global", count);
printf("\n");
}
void func2(void){
int count;
for (count=1; count<10; count++)
putchar('.');
printf("\nO valor de count nesta função passou a ser %d", count);
}
|
the_stack_data/130850.c | /**
* UMB-CS240-2016S: Programming in C
* Copyright 2016 Pejman Ghorbanzade <[email protected]>
* More info: https://github.com/ghorbanzade/UMB-CS240-2016S
*/
#include <stdio.h>
#define START_NUM 16
int main(void)
{
int num = START_NUM;
while (num) {
printf("%d ", num);
num >>= 1;
}
putchar('\n');
}
|
the_stack_data/156393972.c | /*
* PSP Software Development Kit - http://www.pspdev.org
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* font.c - Debug Font.
*
* Copyright (c) 2005 Marcus R. Brown <[email protected]>
* Copyright (c) 2005 James Forshaw <[email protected]>
* Copyright (c) 2005 John Kelley <[email protected]>
*
* $Id: font.c 540 2005-07-08 19:35:10Z warren $
*/
// #include "debugScreen.h"
// PsvDebugScreenFont psvDebugScreenFont = { glyphs:(unsigned char*)
// "\x00\x00\x00\x00\x00\x00\x00\x00\x3c\x42\xa5\x81\xa5\x99\x42\x3c"
// "\x3c\x7e\xdb\xff\xff\xdb\x66\x3c\x6c\xfe\xfe\xfe\x7c\x38\x10\x00"
// "\x10\x38\x7c\xfe\x7c\x38\x10\x00\x10\x38\x54\xfe\x54\x10\x38\x00"
// "\x10\x38\x7c\xfe\xfe\x10\x38\x00\x00\x00\x00\x30\x30\x00\x00\x00"
// "\xff\xff\xff\xe7\xe7\xff\xff\xff\x38\x44\x82\x82\x82\x44\x38\x00"
// "\xc7\xbb\x7d\x7d\x7d\xbb\xc7\xff\x0f\x03\x05\x79\x88\x88\x88\x70"
// "\x38\x44\x44\x44\x38\x10\x7c\x10\x30\x28\x24\x24\x28\x20\xe0\xc0"
// "\x3c\x24\x3c\x24\x24\xe4\xdc\x18\x10\x54\x38\xee\x38\x54\x10\x00"
// "\x10\x10\x10\x7c\x10\x10\x10\x10\x10\x10\x10\xff\x00\x00\x00\x00"
// "\x00\x00\x00\xff\x10\x10\x10\x10\x10\x10\x10\xf0\x10\x10\x10\x10"
// "\x10\x10\x10\x1f\x10\x10\x10\x10\x10\x10\x10\xff\x10\x10\x10\x10"
// "\x10\x10\x10\x10\x10\x10\x10\x10\x00\x00\x00\xff\x00\x00\x00\x00"
// "\x00\x00\x00\x1f\x10\x10\x10\x10\x00\x00\x00\xf0\x10\x10\x10\x10"
// "\x10\x10\x10\x1f\x00\x00\x00\x00\x10\x10\x10\xf0\x00\x00\x00\x00"
// "\x81\x42\x24\x18\x18\x24\x42\x81\x01\x02\x04\x08\x10\x20\x40\x80"
// "\x80\x40\x20\x10\x08\x04\x02\x01\x00\x10\x10\xff\x10\x10\x00\x00"
// "\x00\x00\x00\x00\x00\x00\x00\x00\x20\x20\x20\x20\x00\x00\x20\x00"
// "\x50\x50\x50\x00\x00\x00\x00\x00\x50\x50\xf8\x50\xf8\x50\x50\x00"
// "\x20\x78\xa0\x70\x28\xf0\x20\x00\xc0\xc8\x10\x20\x40\x98\x18\x00"
// "\x40\xa0\x40\xa8\x90\x98\x60\x00\x10\x20\x40\x00\x00\x00\x00\x00"
// "\x10\x20\x40\x40\x40\x20\x10\x00\x40\x20\x10\x10\x10\x20\x40\x00"
// "\x20\xa8\x70\x20\x70\xa8\x20\x00\x00\x20\x20\xf8\x20\x20\x00\x00"
// "\x00\x00\x00\x00\x00\x20\x20\x40\x00\x00\x00\x78\x00\x00\x00\x00"
// "\x00\x00\x00\x00\x00\x60\x60\x00\x00\x00\x08\x10\x20\x40\x80\x00"
// "\x70\x88\x98\xa8\xc8\x88\x70\x00\x20\x60\xa0\x20\x20\x20\xf8\x00"
// "\x70\x88\x08\x10\x60\x80\xf8\x00\x70\x88\x08\x30\x08\x88\x70\x00"
// "\x10\x30\x50\x90\xf8\x10\x10\x00\xf8\x80\xe0\x10\x08\x10\xe0\x00"
// "\x30\x40\x80\xf0\x88\x88\x70\x00\xf8\x88\x10\x20\x20\x20\x20\x00"
// "\x70\x88\x88\x70\x88\x88\x70\x00\x70\x88\x88\x78\x08\x10\x60\x00"
// "\x00\x00\x20\x00\x00\x20\x00\x00\x00\x00\x20\x00\x00\x20\x20\x40"
// "\x18\x30\x60\xc0\x60\x30\x18\x00\x00\x00\xf8\x00\xf8\x00\x00\x00"
// "\xc0\x60\x30\x18\x30\x60\xc0\x00\x70\x88\x08\x10\x20\x00\x20\x00"
// "\x70\x88\x08\x68\xa8\xa8\x70\x00\x20\x50\x88\x88\xf8\x88\x88\x00"
// "\xf0\x48\x48\x70\x48\x48\xf0\x00\x30\x48\x80\x80\x80\x48\x30\x00"
// "\xe0\x50\x48\x48\x48\x50\xe0\x00\xf8\x80\x80\xf0\x80\x80\xf8\x00"
// "\xf8\x80\x80\xf0\x80\x80\x80\x00\x70\x88\x80\xb8\x88\x88\x70\x00"
// "\x88\x88\x88\xf8\x88\x88\x88\x00\x70\x20\x20\x20\x20\x20\x70\x00"
// "\x38\x10\x10\x10\x90\x90\x60\x00\x88\x90\xa0\xc0\xa0\x90\x88\x00"
// "\x80\x80\x80\x80\x80\x80\xf8\x00\x88\xd8\xa8\xa8\x88\x88\x88\x00"
// "\x88\xc8\xc8\xa8\x98\x98\x88\x00\x70\x88\x88\x88\x88\x88\x70\x00"
// "\xf0\x88\x88\xf0\x80\x80\x80\x00\x70\x88\x88\x88\xa8\x90\x68\x00"
// "\xf0\x88\x88\xf0\xa0\x90\x88\x00\x70\x88\x80\x70\x08\x88\x70\x00"
// "\xf8\x20\x20\x20\x20\x20\x20\x00\x88\x88\x88\x88\x88\x88\x70\x00"
// "\x88\x88\x88\x88\x50\x50\x20\x00\x88\x88\x88\xa8\xa8\xd8\x88\x00"
// "\x88\x88\x50\x20\x50\x88\x88\x00\x88\x88\x88\x70\x20\x20\x20\x00"
// "\xf8\x08\x10\x20\x40\x80\xf8\x00\x70\x40\x40\x40\x40\x40\x70\x00"
// "\x00\x00\x80\x40\x20\x10\x08\x00\x70\x10\x10\x10\x10\x10\x70\x00"
// "\x20\x50\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf8\x00"
// "\x40\x20\x10\x00\x00\x00\x00\x00\x00\x00\x70\x08\x78\x88\x78\x00"
// "\x80\x80\xb0\xc8\x88\xc8\xb0\x00\x00\x00\x70\x88\x80\x88\x70\x00"
// "\x08\x08\x68\x98\x88\x98\x68\x00\x00\x00\x70\x88\xf8\x80\x70\x00"
// "\x10\x28\x20\xf8\x20\x20\x20\x00\x00\x00\x68\x98\x98\x68\x08\x70"
// "\x80\x80\xf0\x88\x88\x88\x88\x00\x20\x00\x60\x20\x20\x20\x70\x00"
// "\x10\x00\x30\x10\x10\x10\x90\x60\x40\x40\x48\x50\x60\x50\x48\x00"
// "\x60\x20\x20\x20\x20\x20\x70\x00\x00\x00\xd0\xa8\xa8\xa8\xa8\x00"
// "\x00\x00\xb0\xc8\x88\x88\x88\x00\x00\x00\x70\x88\x88\x88\x70\x00"
// "\x00\x00\xb0\xc8\xc8\xb0\x80\x80\x00\x00\x68\x98\x98\x68\x08\x08"
// "\x00\x00\xb0\xc8\x80\x80\x80\x00\x00\x00\x78\x80\xf0\x08\xf0\x00"
// "\x40\x40\xf0\x40\x40\x48\x30\x00\x00\x00\x90\x90\x90\x90\x68\x00"
// "\x00\x00\x88\x88\x88\x50\x20\x00\x00\x00\x88\xa8\xa8\xa8\x50\x00"
// "\x00\x00\x88\x50\x20\x50\x88\x00\x00\x00\x88\x88\x98\x68\x08\x70"
// "\x00\x00\xf8\x10\x20\x40\xf8\x00\x18\x20\x20\x40\x20\x20\x18\x00"
// "\x20\x20\x20\x00\x20\x20\x20\x00\xc0\x20\x20\x10\x20\x20\xc0\x00"
// "\x40\xa8\x10\x00\x00\x00\x00\x00\x00\x00\x20\x50\xf8\x00\x00\x00"
// "\x70\x88\x80\x80\x88\x70\x20\x60\x90\x00\x00\x90\x90\x90\x68\x00"
// "\x10\x20\x70\x88\xf8\x80\x70\x00\x20\x50\x70\x08\x78\x88\x78\x00"
// "\x48\x00\x70\x08\x78\x88\x78\x00\x20\x10\x70\x08\x78\x88\x78\x00"
// "\x20\x00\x70\x08\x78\x88\x78\x00\x00\x70\x80\x80\x80\x70\x10\x60"
// "\x20\x50\x70\x88\xf8\x80\x70\x00\x50\x00\x70\x88\xf8\x80\x70\x00"
// "\x20\x10\x70\x88\xf8\x80\x70\x00\x50\x00\x00\x60\x20\x20\x70\x00"
// "\x20\x50\x00\x60\x20\x20\x70\x00\x40\x20\x00\x60\x20\x20\x70\x00"
// "\x50\x00\x20\x50\x88\xf8\x88\x00\x20\x00\x20\x50\x88\xf8\x88\x00"
// "\x10\x20\xf8\x80\xf0\x80\xf8\x00\x00\x00\x6c\x12\x7e\x90\x6e\x00"
// "\x3e\x50\x90\x9c\xf0\x90\x9e\x00\x60\x90\x00\x60\x90\x90\x60\x00"
// "\x90\x00\x00\x60\x90\x90\x60\x00\x40\x20\x00\x60\x90\x90\x60\x00"
// "\x40\xa0\x00\xa0\xa0\xa0\x50\x00\x40\x20\x00\xa0\xa0\xa0\x50\x00"
// "\x90\x00\x90\x90\xb0\x50\x10\xe0\x50\x00\x70\x88\x88\x88\x70\x00"
// "\x50\x00\x88\x88\x88\x88\x70\x00\x20\x20\x78\x80\x80\x78\x20\x20"
// "\x18\x24\x20\xf8\x20\xe2\x5c\x00\x88\x50\x20\xf8\x20\xf8\x20\x00"
// "\xc0\xa0\xa0\xc8\x9c\x88\x88\x8c\x18\x20\x20\xf8\x20\x20\x20\x40"
// "\x10\x20\x70\x08\x78\x88\x78\x00\x10\x20\x00\x60\x20\x20\x70\x00"
// "\x20\x40\x00\x60\x90\x90\x60\x00\x20\x40\x00\x90\x90\x90\x68\x00"
// "\x50\xa0\x00\xa0\xd0\x90\x90\x00\x28\x50\x00\xc8\xa8\x98\x88\x00"
// "\x00\x70\x08\x78\x88\x78\x00\xf8\x00\x60\x90\x90\x90\x60\x00\xf0"
// "\x20\x00\x20\x40\x80\x88\x70\x00\x00\x00\x00\xf8\x80\x80\x00\x00"
// "\x00\x00\x00\xf8\x08\x08\x00\x00\x84\x88\x90\xa8\x54\x84\x08\x1c"
// "\x84\x88\x90\xa8\x58\xa8\x3c\x08\x20\x00\x00\x20\x20\x20\x20\x00"
// "\x00\x00\x24\x48\x90\x48\x24\x00\x00\x00\x90\x48\x24\x48\x90\x00"
// "\x28\x50\x20\x50\x88\xf8\x88\x00\x28\x50\x70\x08\x78\x88\x78\x00"
// "\x28\x50\x00\x70\x20\x20\x70\x00\x28\x50\x00\x20\x20\x20\x70\x00"
// "\x28\x50\x00\x70\x88\x88\x70\x00\x50\xa0\x00\x60\x90\x90\x60\x00"
// "\x28\x50\x00\x88\x88\x88\x70\x00\x50\xa0\x00\xa0\xa0\xa0\x50\x00"
// "\xfc\x48\x48\x48\xe8\x08\x50\x20\x00\x50\x00\x50\x50\x50\x10\x20"
// "\xc0\x44\xc8\x54\xec\x54\x9e\x04\x10\xa8\x40\x00\x00\x00\x00\x00"
// "\x00\x20\x50\x88\x50\x20\x00\x00\x88\x10\x20\x40\x80\x28\x00\x00"
// "\x7c\xa8\xa8\x68\x28\x28\x28\x00\x38\x40\x30\x48\x48\x30\x08\x70"
// "\x00\x00\x00\x00\x00\x00\xff\xff\xf0\xf0\xf0\xf0\x0f\x0f\x0f\x0f"
// "\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00"
// "\x00\x00\x00\x3c\x3c\x00\x00\x00\xff\xff\xff\xff\xff\xff\x00\x00"
// "\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\x0f\x0f\x0f\x0f\xf0\xf0\xf0\xf0"
// "\xfc\xfc\xfc\xfc\xfc\xfc\xfc\xfc\x03\x03\x03\x03\x03\x03\x03\x03"
// "\x3f\x3f\x3f\x3f\x3f\x3f\x3f\x3f\x11\x22\x44\x88\x11\x22\x44\x88"
// "\x88\x44\x22\x11\x88\x44\x22\x11\xfe\x7c\x38\x10\x00\x00\x00\x00"
// "\x00\x00\x00\x00\x10\x38\x7c\xfe\x80\xc0\xe0\xf0\xe0\xc0\x80\x00"
// "\x01\x03\x07\x0f\x07\x03\x01\x00\xff\x7e\x3c\x18\x18\x3c\x7e\xff"
// "\x81\xc3\xe7\xff\xff\xe7\xc3\x81\xf0\xf0\xf0\xf0\x00\x00\x00\x00"
// "\x00\x00\x00\x00\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x00\x00\x00\x00"
// "\x00\x00\x00\x00\xf0\xf0\xf0\xf0\x33\x33\xcc\xcc\x33\x33\xcc\xcc"
// "\x00\x20\x20\x50\x50\x88\xf8\x00\x20\x20\x70\x20\x70\x20\x20\x00"
// "\x00\x00\x00\x50\x88\xa8\x50\x00\xff\xff\xff\xff\xff\xff\xff\xff"
// "\x00\x00\x00\x00\xff\xff\xff\xff\xf0\xf0\xf0\xf0\xf0\xf0\xf0\xf0"
// "\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\xff\xff\xff\xff\x00\x00\x00\x00"
// "\x00\x00\x68\x90\x90\x90\x68\x00\x30\x48\x48\x70\x48\x48\x70\xc0"
// "\xf8\x88\x80\x80\x80\x80\x80\x00\xf8\x50\x50\x50\x50\x50\x98\x00"
// "\xf8\x88\x40\x20\x40\x88\xf8\x00\x00\x00\x78\x90\x90\x90\x60\x00"
// "\x00\x50\x50\x50\x50\x68\x80\x80\x00\x50\xa0\x20\x20\x20\x20\x00"
// "\xf8\x20\x70\xa8\xa8\x70\x20\xf8\x20\x50\x88\xf8\x88\x50\x20\x00"
// "\x70\x88\x88\x88\x50\x50\xd8\x00\x30\x40\x40\x20\x50\x50\x50\x20"
// "\x00\x00\x00\x50\xa8\xa8\x50\x00\x08\x70\xa8\xa8\xa8\x70\x80\x00"
// "\x38\x40\x80\xf8\x80\x40\x38\x00\x70\x88\x88\x88\x88\x88\x88\x00"
// "\x00\xf8\x00\xf8\x00\xf8\x00\x00\x20\x20\xf8\x20\x20\x00\xf8\x00"
// "\xc0\x30\x08\x30\xc0\x00\xf8\x00\x18\x60\x80\x60\x18\x00\xf8\x00"
// "\x10\x28\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\xa0\x40"
// "\x00\x20\x00\xf8\x00\x20\x00\x00\x00\x50\xa0\x00\x50\xa0\x00\x00"
// "\x00\x18\x24\x24\x18\x00\x00\x00\x00\x30\x78\x78\x30\x00\x00\x00"
// "\x00\x00\x00\x00\x30\x00\x00\x00\x3e\x20\x20\x20\xa0\x60\x20\x00"
// "\xa0\x50\x50\x50\x00\x00\x00\x00\x40\xa0\x20\x40\xe0\x00\x00\x00"
// "\x00\x38\x38\x38\x38\x38\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00",
// width :8, height:8, first:0, last:255, size_w:8, size_h:8};
|
the_stack_data/150141598.c | #include <stdio.h>
int main(){
int x, y;
while(1){
scanf("%d%d", &x, &y);
if(x==y){
return 0;
}
else{
if(x>y){
printf("Decrescente\n");
}
else{
printf("Crescente\n");
}
}
}
return 0;
}
|
the_stack_data/150140610.c | #include <stdint.h>
const uint8_t __emoji_u1F624[4856] = {
0x00, 0x00, 0x00, 0x00, // uint32_t id
0x28, 0x00, 0x00, 0x00, // int32_t width
0x28, 0x00, 0x00, 0x00, // int32_t height
0x08, 0x00, 0x00, 0x00, // ui_pixel_format_t pf
0x38, 0x00, 0x00, 0x00, // uint32_t header_size
0x00, 0x19, 0x00, 0x00, // uint32_t data_size
0x00, 0x00, 0x00, 0x00, // int32_t reserved[0]
0x00, 0x00, 0x00, 0x00, // int32_t reserved[1]
0x00, 0x00, 0x00, 0x00, // int32_t reserved[2]
0x00, 0x00, 0x00, 0x00, // int32_t reserved[3]
0x00, 0x00, 0x00, 0x00, // int32_t reserved[4]
0x00, 0x00, 0x00, 0x00, // int32_t reserved[5]
0x00, 0x00, 0x00, 0x00, // int32_t reserved[6]
0x00, 0x00, 0x00, 0x00, // int32_t reserved[7]
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x66, 0x16, 0xf4, 0xc4, 0x5b, 0xf5, 0x03, 0x95, 0xfd, 0x43, 0xc0, 0xfd, 0x83, 0xdd, 0xfd, 0x83, 0xe9, 0xfd, 0x83, 0xe9, 0xfd, 0x83, 0xdd, 0xfd, 0x43, 0xc2, 0xf5, 0x23, 0x97,
0xf4, 0xc3, 0x5e, 0xdc, 0x66, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x47, 0x02, 0xec, 0x83, 0x4c, 0xf5, 0x02, 0xb7, 0xfd, 0x62, 0xfa, 0xfe, 0x02, 0xff,
0xfe, 0x62, 0xff, 0xfe, 0xc3, 0xff, 0xff, 0x05, 0xff, 0xff, 0x27, 0xff, 0xff, 0x27, 0xff, 0xff, 0x05, 0xff, 0xfe, 0xc3, 0xff, 0xfe, 0x62, 0xff, 0xfe, 0x02, 0xff, 0xfd, 0x82, 0xfb, 0xf5, 0x02, 0xbb, 0xec, 0x83, 0x50, 0xb4, 0x28, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0x63, 0x3e, 0xf4, 0xe2, 0xcb, 0xfd, 0x81, 0xff, 0xfe, 0x42, 0xff, 0xfe, 0xe6, 0xff, 0xff, 0x6f, 0xff, 0xff, 0xd6, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xd7, 0xff,
0xff, 0x70, 0xff, 0xfe, 0xe7, 0xff, 0xfe, 0x42, 0xff, 0xfd, 0x81, 0xff, 0xfc, 0xe2, 0xd0, 0xe4, 0x43, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x05, 0x08, 0xf4, 0x82, 0x92, 0xfd, 0x41, 0xfd, 0xfe, 0x01, 0xff, 0xfe, 0xe8, 0xff, 0xff, 0xb4, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xfa, 0xff,
0xff, 0xfb, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xb5, 0xff, 0xff, 0x0a, 0xff, 0xfe, 0x01, 0xff, 0xfd, 0x41, 0xfe, 0xf4, 0x82, 0x9a, 0xcc, 0x06, 0x0a,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x04, 0x16,
0xf4, 0x81, 0xc6, 0xfd, 0x61, 0xff, 0xfe, 0x43, 0xff, 0xff, 0x4f, 0xff, 0xff, 0xd7, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xf9, 0xff,
0xff, 0xf9, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xd7, 0xff, 0xff, 0x71, 0xff, 0xfe, 0x64, 0xff, 0xfd, 0x81, 0xff, 0xf4, 0x81, 0xcc, 0xdc, 0x04, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x04, 0x19, 0xf4, 0x81, 0xd7, 0xfd, 0x81, 0xff, 0xfe, 0x86, 0xff, 0xe6, 0x4f, 0xff, 0x7a, 0x62, 0xff, 0x93, 0x44, 0xff, 0xc5, 0x0b, 0xff, 0xf7, 0x53, 0xff, 0xff, 0xd7, 0xff,
0xff, 0xd8, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xd8, 0xff, 0xff, 0xd7, 0xff, 0xf7, 0x12, 0xff, 0xbc, 0xa9, 0xff, 0x8b, 0x04, 0xff, 0x7a, 0x62, 0xff, 0xee, 0xd1, 0xff, 0xfe, 0xa8, 0xff, 0xfd, 0x81, 0xff,
0xfc, 0xa1, 0xdc, 0xdc, 0x03, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xe5, 0x0c, 0xf4, 0x61, 0xcd, 0xfd, 0x61, 0xff,
0xfe, 0x66, 0xff, 0xff, 0x93, 0xff, 0xff, 0xd4, 0xff, 0xde, 0x51, 0xff, 0x9b, 0x87, 0xff, 0x71, 0xc0, 0xff, 0x7a, 0x42, 0xff, 0xd5, 0xac, 0xff, 0xff, 0xd5, 0xff, 0xff, 0xd6, 0xff, 0xff, 0xd6, 0xff, 0xff, 0xd7, 0xff, 0xff, 0xd7, 0xff, 0xff, 0xd6, 0xff, 0xff, 0xd6, 0xff, 0xff, 0xb5, 0xff,
0xc5, 0x4b, 0xff, 0x72, 0x01, 0xff, 0x71, 0xe0, 0xff, 0xa3, 0xe8, 0xff, 0xe6, 0xd2, 0xff, 0xff, 0xd4, 0xff, 0xff, 0x93, 0xff, 0xfe, 0xa9, 0xff, 0xfd, 0x60, 0xff, 0xf4, 0x61, 0xd4, 0xcb, 0xe4, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf4, 0x41, 0xa3, 0xfd, 0x20, 0xff, 0xfe, 0x25, 0xff, 0xff, 0x51, 0xff, 0xff, 0x91, 0xff, 0xff, 0xb2, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xd3, 0xff, 0xd6, 0x2f, 0xff, 0x8a, 0xa2, 0xff, 0x71, 0xe0, 0xff,
0xc5, 0x09, 0xff, 0xff, 0xd4, 0xff, 0xff, 0xd4, 0xff, 0xff, 0xd5, 0xff, 0xff, 0xd5, 0xff, 0xff, 0xd4, 0xff, 0xff, 0xb3, 0xff, 0xb4, 0x88, 0xff, 0x71, 0xe0, 0xff, 0x92, 0xe3, 0xff, 0xe6, 0x90, 0xff, 0xff, 0xd3, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xb2, 0xff, 0xff, 0x91, 0xff, 0xff, 0x51, 0xff,
0xfe, 0x67, 0xff, 0xfd, 0x20, 0xff, 0xf4, 0x41, 0xad, 0xac, 0x29, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0x02, 0x54, 0xfc, 0xc0, 0xff, 0xfd, 0xc2, 0xff, 0xff, 0x0e, 0xff,
0xff, 0x4f, 0xff, 0xff, 0x90, 0xff, 0xff, 0xb0, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xd1, 0xff, 0xef, 0x31, 0xff, 0x93, 0x03, 0xff, 0x7a, 0x00, 0xff, 0xde, 0x4d, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xd2, 0xff, 0xd5, 0xcb, 0xff, 0x71, 0xe0, 0xff,
0x9b, 0x64, 0xff, 0xf7, 0x71, 0xff, 0xff, 0xd1, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xb0, 0xff, 0xff, 0x90, 0xff, 0xff, 0x4f, 0xff, 0xff, 0x0f, 0xff, 0xfd, 0xe3, 0xff, 0xfc, 0xc0, 0xff, 0xe4, 0x02, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb3, 0xa5, 0x0a, 0xf4, 0x40, 0xe1, 0xfd, 0x40, 0xff, 0xfe, 0x89, 0xff, 0xff, 0x0d, 0xff, 0xff, 0x4e, 0xff, 0xff, 0x6e, 0xff, 0xff, 0x8e, 0xff, 0xff, 0xae, 0xff, 0xff, 0xaf, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xcf, 0xff, 0xef, 0x2f, 0xff,
0x8a, 0xa2, 0xff, 0xa3, 0xa5, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xb0, 0xff, 0x93, 0x23, 0xff, 0x93, 0x03, 0xff, 0xf7, 0x90, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xaf, 0xff, 0xff, 0xae, 0xff, 0xff, 0x8e, 0xff, 0xff, 0x6e, 0xff, 0xff, 0x4e, 0xff,
0xff, 0x0d, 0xff, 0xfe, 0xab, 0xff, 0xfd, 0x41, 0xff, 0xf4, 0x40, 0xe7, 0xc3, 0xe5, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0xe1, 0x6e, 0xfc, 0xc0, 0xff, 0xfd, 0xc3, 0xff, 0xfe, 0xcb, 0xff, 0xfe, 0xec, 0xff,
0xff, 0x2c, 0xff, 0xff, 0x4c, 0xff, 0xff, 0x6c, 0xff, 0xff, 0x8d, 0xff, 0xff, 0xad, 0xff, 0xff, 0xad, 0xff, 0xff, 0xad, 0xff, 0xff, 0xce, 0xff, 0xde, 0x4b, 0xff, 0x9b, 0xc5, 0xff, 0xff, 0xce, 0xff, 0xff, 0xae, 0xff, 0xff, 0xae, 0xff, 0xff, 0xce, 0xff, 0x93, 0x64, 0xff, 0xe6, 0xac, 0xff,
0xff, 0xad, 0xff, 0xff, 0xad, 0xff, 0xff, 0xad, 0xff, 0xff, 0xad, 0xff, 0xff, 0x8d, 0xff, 0xff, 0x6c, 0xff, 0xff, 0x4c, 0xff, 0xff, 0x2c, 0xff, 0xfe, 0xec, 0xff, 0xfe, 0xcb, 0xff, 0xfd, 0xe5, 0xff, 0xfc, 0xc0, 0xff, 0xe3, 0xe1, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x86, 0x03, 0xec, 0x21, 0xda, 0xfd, 0x00, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0xaa, 0xff, 0xfe, 0xea, 0xff, 0xff, 0x0a, 0xff, 0xff, 0x2b, 0xff, 0xff, 0x4b, 0xff, 0xff, 0x6b, 0xff, 0xff, 0x8b, 0xff, 0xff, 0x8b, 0xff, 0xff, 0xab, 0xff, 0xff, 0xac, 0xff,
0xff, 0xcc, 0xff, 0xff, 0xcd, 0xff, 0xff, 0xac, 0xff, 0xff, 0xac, 0xff, 0xff, 0xac, 0xff, 0xff, 0xac, 0xff, 0xff, 0xcd, 0xff, 0xff, 0xac, 0xff, 0xff, 0xac, 0xff, 0xff, 0xab, 0xff, 0xff, 0x8b, 0xff, 0xff, 0x6b, 0xff, 0xff, 0x6b, 0xff, 0xff, 0x4b, 0xff, 0xff, 0x2b, 0xff, 0xff, 0x0a, 0xff,
0xfe, 0xea, 0xff, 0xfe, 0xaa, 0xff, 0xfe, 0x48, 0xff, 0xfd, 0x21, 0xff, 0xec, 0x20, 0xe3, 0xb4, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcb, 0xc2, 0x39, 0xf4, 0x40, 0xff, 0xfd, 0x42, 0xff, 0xfe, 0x48, 0xff, 0xfe, 0x88, 0xff, 0xfe, 0xa9, 0xff,
0xfe, 0xe9, 0xff, 0xff, 0x09, 0xff, 0xff, 0x29, 0xff, 0xff, 0x49, 0xff, 0xff, 0x6a, 0xff, 0xff, 0x6a, 0xff, 0xff, 0x8a, 0xff, 0xff, 0x8a, 0xff, 0xff, 0xaa, 0xff, 0xff, 0xaa, 0xff, 0xff, 0xaa, 0xff, 0xff, 0xaa, 0xff, 0xff, 0xaa, 0xff, 0xff, 0xaa, 0xff, 0xff, 0xaa, 0xff, 0xff, 0xaa, 0xff,
0xff, 0x8a, 0xff, 0xff, 0x8a, 0xff, 0xff, 0x6a, 0xff, 0xff, 0x6a, 0xff, 0xff, 0x49, 0xff, 0xff, 0x29, 0xff, 0xff, 0x09, 0xff, 0xfe, 0xe9, 0xff, 0xfe, 0xc9, 0xff, 0xfe, 0x88, 0xff, 0xfe, 0x48, 0xff, 0xfd, 0x63, 0xff, 0xf4, 0x60, 0xff, 0xd3, 0xc2, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0xc1, 0x89, 0xf4, 0x80, 0xff, 0xfd, 0x83, 0xff, 0xfe, 0x26, 0xff, 0xfe, 0x67, 0xff, 0xfe, 0x88, 0xff, 0xfe, 0xc8, 0xff, 0xdd, 0x65, 0xff, 0xee, 0x06, 0xff, 0xfe, 0xc7, 0xff, 0xff, 0x08, 0xff, 0xff, 0x28, 0xff, 0xff, 0x28, 0xff, 0xff, 0x08, 0xff,
0xee, 0x87, 0xff, 0xd5, 0x85, 0xff, 0xff, 0x48, 0xff, 0xff, 0x89, 0xff, 0xff, 0x89, 0xff, 0xff, 0x69, 0xff, 0xdd, 0xc6, 0xff, 0xee, 0x46, 0xff, 0xff, 0x08, 0xff, 0xff, 0x28, 0xff, 0xff, 0x28, 0xff, 0xff, 0x08, 0xff, 0xfe, 0xc7, 0xff, 0xee, 0x26, 0xff, 0xd5, 0x25, 0xff, 0xfe, 0x87, 0xff,
0xfe, 0xa7, 0xff, 0xfe, 0x67, 0xff, 0xfe, 0x27, 0xff, 0xfd, 0xa4, 0xff, 0xf4, 0xa0, 0xff, 0xe3, 0xc1, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0xe1, 0xc7, 0xf4, 0xa0, 0xff, 0xfd, 0x84, 0xff, 0xfe, 0x06, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x66, 0xff,
0xfe, 0xa7, 0xff, 0x93, 0x63, 0xff, 0x69, 0xa0, 0xff, 0x7a, 0x20, 0xff, 0x82, 0x81, 0xff, 0x8a, 0xa1, 0xff, 0x8a, 0x81, 0xff, 0x7a, 0x20, 0xff, 0x69, 0xc0, 0xff, 0x7a, 0x82, 0xff, 0xff, 0x48, 0xff, 0xff, 0x68, 0xff, 0xff, 0x68, 0xff, 0xff, 0x68, 0xff, 0x93, 0x63, 0xff, 0x69, 0xa0, 0xff,
0x7a, 0x20, 0xff, 0x82, 0x81, 0xff, 0x8a, 0xa1, 0xff, 0x82, 0x81, 0xff, 0x7a, 0x20, 0xff, 0x69, 0xc0, 0xff, 0x7a, 0x82, 0xff, 0xfe, 0x87, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x06, 0xff, 0xfd, 0xa4, 0xff, 0xf4, 0xc1, 0xff, 0xe3, 0xe1, 0xd1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xb4, 0x08, 0x04, 0xe3, 0xe0, 0xf0, 0xf4, 0xc1, 0xff, 0xfd, 0x84, 0xff, 0xfd, 0xe5, 0xff, 0xfe, 0x25, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0xe7, 0xff, 0xbc, 0xe5, 0xff, 0x8a, 0x81, 0xff, 0x8a, 0x60, 0xff, 0x8a, 0x80, 0xff, 0x8a, 0x80, 0xff, 0x8a, 0x60, 0xff,
0xac, 0x23, 0xff, 0xf7, 0x27, 0xff, 0xff, 0x47, 0xff, 0xff, 0x47, 0xff, 0xff, 0x47, 0xff, 0xff, 0x47, 0xff, 0xff, 0x67, 0xff, 0xb4, 0xa4, 0xff, 0x8a, 0x60, 0xff, 0x8a, 0x80, 0xff, 0x8a, 0x80, 0xff, 0x8a, 0x80, 0xff, 0x8a, 0x60, 0xff, 0xb4, 0x64, 0xff, 0xfe, 0xc7, 0xff, 0xfe, 0x86, 0xff,
0xfe, 0x66, 0xff, 0xfe, 0x25, 0xff, 0xfd, 0xe5, 0xff, 0xfd, 0x84, 0xff, 0xf4, 0xc1, 0xff, 0xe3, 0xe0, 0xf6, 0xb3, 0xe7, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0xc6, 0x18, 0xe3, 0xe0, 0xff, 0xf4, 0xc1, 0xff, 0xfd, 0x83, 0xff, 0xfd, 0xc4, 0xff, 0xfe, 0x05, 0xff, 0xfe, 0x45, 0xff,
0xfe, 0x65, 0xff, 0xfe, 0x85, 0xff, 0xfe, 0xc6, 0xff, 0xf6, 0xe7, 0xff, 0xd5, 0xa5, 0xff, 0xc5, 0x04, 0xff, 0xcd, 0x65, 0xff, 0xee, 0xa7, 0xff, 0xff, 0x46, 0xff, 0xff, 0x06, 0xff, 0xff, 0x26, 0xff, 0xff, 0x26, 0xff, 0xff, 0x26, 0xff, 0xff, 0x26, 0xff, 0xff, 0x06, 0xff, 0xff, 0x26, 0xff,
0xf6, 0xe7, 0xff, 0xcd, 0x85, 0xff, 0xc5, 0x04, 0xff, 0xcd, 0x65, 0xff, 0xf6, 0xc7, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0x85, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0x45, 0xff, 0xfe, 0x05, 0xff, 0xfd, 0xc4, 0xff, 0xfd, 0x83, 0xff, 0xf4, 0xc1, 0xff, 0xe3, 0xe0, 0xff, 0xbb, 0xc5, 0x20, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xc3, 0xa4, 0x26, 0xe3, 0xe0, 0xff, 0xf4, 0xc1, 0xff, 0xfd, 0x62, 0xff, 0xfd, 0xc4, 0xff, 0xfd, 0xe5, 0xff, 0xfe, 0x25, 0xff, 0xfe, 0x45, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0x85, 0xff, 0xfe, 0xa5, 0xff, 0xfe, 0xc5, 0xff, 0xfe, 0xc5, 0xff, 0xfe, 0xc5, 0xff, 0xfe, 0xe5, 0xff,
0xfe, 0xe5, 0xff, 0xff, 0x06, 0xff, 0xff, 0x06, 0xff, 0xff, 0x06, 0xff, 0xff, 0x06, 0xff, 0xff, 0x06, 0xff, 0xff, 0x06, 0xff, 0xfe, 0xe5, 0xff, 0xfe, 0xe5, 0xff, 0xfe, 0xc5, 0xff, 0xfe, 0xc5, 0xff, 0xfe, 0xc5, 0xff, 0xfe, 0xa5, 0xff, 0xfe, 0x85, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0x45, 0xff,
0xfe, 0x25, 0xff, 0xfe, 0x05, 0xff, 0xfd, 0xc4, 0xff, 0xfd, 0x62, 0xff, 0xf4, 0xc1, 0xff, 0xe3, 0xe0, 0xff, 0xc3, 0x83, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x84, 0x2a, 0xdb, 0xc0, 0xff, 0xec, 0xa0, 0xff, 0xfd, 0x42, 0xff, 0xfd, 0xa4, 0xff, 0xfd, 0xe5, 0xff, 0xfe, 0x25, 0xff,
0xfe, 0x45, 0xff, 0xfe, 0x45, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0x85, 0xff, 0xfe, 0xa5, 0xff, 0xfe, 0xa5, 0xff, 0xfe, 0xc5, 0xff, 0xfe, 0xc5, 0xff, 0xfe, 0xe5, 0xff, 0xfe, 0xe6, 0xff, 0xfe, 0xe6, 0xff, 0xfe, 0xe6, 0xff, 0xfe, 0xe6, 0xff, 0xfe, 0xe6, 0xff, 0xfe, 0xe6, 0xff, 0xfe, 0xc5, 0xff,
0xfe, 0xc5, 0xff, 0xfe, 0xc5, 0xff, 0xfe, 0xa5, 0xff, 0xfe, 0xa5, 0xff, 0xfe, 0x85, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0x45, 0xff, 0xfe, 0x25, 0xff, 0xfd, 0xe5, 0xff, 0xfd, 0xa4, 0xff, 0xfd, 0x62, 0xff, 0xec, 0xa1, 0xff, 0xdb, 0xe0, 0xff, 0xc3, 0x63, 0x34, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xb3, 0x85, 0x21, 0xdb, 0xc0, 0xff, 0xec, 0x80, 0xff, 0xf5, 0x21, 0xff, 0xfd, 0xa3, 0xff, 0xfd, 0xe5, 0xff, 0xfe, 0x05, 0xff, 0xfe, 0x25, 0xff, 0xfe, 0x45, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0x85, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xc6, 0xff,
0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xe6, 0xff, 0xfe, 0xe6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa5, 0xff, 0xfe, 0x85, 0xff, 0xfe, 0x85, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0x45, 0xff, 0xfe, 0x25, 0xff,
0xfe, 0x05, 0xff, 0xfd, 0xe5, 0xff, 0xfd, 0xa3, 0xff, 0xf5, 0x41, 0xff, 0xec, 0xa1, 0xff, 0xdb, 0xc0, 0xff, 0xbb, 0x84, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb3, 0xc7, 0x0e, 0xd3, 0xa0, 0xfb, 0xe4, 0x60, 0xff, 0xf5, 0x01, 0xff, 0xfd, 0x83, 0xff, 0xfd, 0xc4, 0xff, 0xfd, 0xe5, 0xff,
0xfe, 0x25, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0xe6, 0x6c, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xa8, 0xff, 0xee, 0x8b, 0xff,
0xfe, 0x86, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x25, 0xff, 0xfd, 0xe5, 0xff, 0xfd, 0xc5, 0xff, 0xfd, 0x83, 0xff, 0xf5, 0x21, 0xff, 0xec, 0x81, 0xff, 0xd3, 0xa0, 0xfe, 0xb3, 0xc6, 0x16, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xb3, 0xe7, 0x01, 0xd3, 0x81, 0xe0, 0xe4, 0x40, 0xff, 0xf4, 0xe1, 0xff, 0xfd, 0x62, 0xff, 0xfd, 0xa4, 0xff, 0xfd, 0xe5, 0xff, 0xfe, 0x06, 0xff, 0xfe, 0x26, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xf6, 0x67, 0xff,
0xc6, 0x14, 0xff, 0xed, 0xa4, 0xff, 0xe5, 0x64, 0xff, 0xd4, 0xe3, 0xff, 0xd4, 0xe3, 0xff, 0xe5, 0x64, 0xff, 0xed, 0xc4, 0xff, 0xde, 0x95, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x26, 0xff, 0xfe, 0x06, 0xff,
0xfd, 0xe5, 0xff, 0xfd, 0xa4, 0xff, 0xfd, 0x62, 0xff, 0xf5, 0x01, 0xff, 0xe4, 0x40, 0xff, 0xd3, 0x80, 0xe8, 0xb4, 0x08, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcb, 0x61, 0xab, 0xdc, 0x00, 0xff, 0xec, 0xc1, 0xff, 0xf5, 0x42, 0xff, 0xfd, 0x83, 0xff, 0xfd, 0xc4, 0xff,
0xfd, 0xe6, 0xff, 0xfe, 0x06, 0xff, 0xfe, 0x26, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x46, 0xff, 0xed, 0xa5, 0xff, 0xbc, 0x02, 0xff, 0xbd, 0xb5, 0xff, 0x8b, 0xac, 0xff, 0x69, 0xa0, 0xff, 0x69, 0xa0, 0xff, 0x71, 0xc0, 0xff, 0x71, 0xc0, 0xff, 0x69, 0xc0, 0xff, 0x69, 0xa0, 0xff, 0xa4, 0x90, 0xff,
0xbd, 0x51, 0xff, 0xbc, 0x03, 0xff, 0xed, 0xa5, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x26, 0xff, 0xfe, 0x06, 0xff, 0xfd, 0xe6, 0xff, 0xfd, 0xc4, 0xff, 0xfd, 0x83, 0xff, 0xf5, 0x42, 0xff, 0xec, 0xc1, 0xff, 0xdc, 0x00, 0xff, 0xcb, 0x61, 0xb5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x41, 0x67, 0xd3, 0xc0, 0xff, 0xe4, 0x81, 0xff, 0xf5, 0x01, 0xff, 0xfd, 0x62, 0xff, 0xfd, 0xa3, 0xff, 0xfd, 0xc5, 0xff, 0xfd, 0xe6, 0xff, 0xfe, 0x06, 0xff, 0xed, 0x65, 0xff, 0xa3, 0x22, 0xff, 0x71, 0xc0, 0xff, 0x83, 0x29, 0xff, 0xdf, 0x5f, 0xff,
0xac, 0x07, 0xff, 0xbc, 0xa5, 0xff, 0xcd, 0x46, 0xff, 0xd5, 0xa6, 0xff, 0xd5, 0x86, 0xff, 0xcd, 0x46, 0xff, 0xbc, 0xc5, 0xff, 0xb4, 0x8a, 0xff, 0xdf, 0x5f, 0xff, 0x7a, 0xa6, 0xff, 0x71, 0xc0, 0xff, 0xa3, 0x22, 0xff, 0xed, 0x85, 0xff, 0xfe, 0x06, 0xff, 0xfd, 0xe6, 0xff, 0xfd, 0xc5, 0xff,
0xfd, 0xa3, 0xff, 0xfd, 0x62, 0xff, 0xf5, 0x02, 0xff, 0xe4, 0x81, 0xff, 0xd3, 0xc0, 0xff, 0xc3, 0x41, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb3, 0x84, 0x17, 0xcb, 0x80, 0xf9, 0xdc, 0x21, 0xff, 0xec, 0xc1, 0xff, 0xf5, 0x42, 0xff, 0xfd, 0x82, 0xff,
0xfd, 0xa4, 0xff, 0xfd, 0xc5, 0xff, 0xdc, 0xa4, 0xff, 0x71, 0xe0, 0xff, 0x8a, 0xa2, 0xff, 0xbc, 0xc7, 0xff, 0xd6, 0xfc, 0xff, 0xde, 0xfb, 0xff, 0xf5, 0xa5, 0xff, 0xfe, 0x26, 0xff, 0xfe, 0x67, 0xff, 0xfe, 0x67, 0xff, 0xfe, 0x67, 0xff, 0xfe, 0x67, 0xff, 0xfe, 0x46, 0xff, 0xf5, 0xa6, 0xff,
0xe7, 0x5e, 0xff, 0xc6, 0x7b, 0xff, 0xbc, 0xc6, 0xff, 0x82, 0xa2, 0xff, 0x71, 0xe0, 0xff, 0xdc, 0xa4, 0xff, 0xfd, 0xc5, 0xff, 0xfd, 0xa4, 0xff, 0xfd, 0x82, 0xff, 0xf5, 0x42, 0xff, 0xec, 0xe1, 0xff, 0xdc, 0x41, 0xff, 0xd3, 0x80, 0xfc, 0xbb, 0x64, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcb, 0x61, 0xab, 0xd3, 0xe0, 0xff, 0xe4, 0x81, 0xff, 0xed, 0x02, 0xff, 0xfd, 0x42, 0xff, 0xfd, 0x83, 0xff, 0xe4, 0xe3, 0xff, 0x82, 0x82, 0xff, 0xd5, 0x26, 0xff, 0xfe, 0x48, 0xff, 0xde, 0x96, 0xff, 0xf7, 0xdf, 0xff, 0xd6, 0x33, 0xff,
0xf5, 0x65, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x27, 0xff, 0xf5, 0x65, 0xff, 0xde, 0x77, 0xff, 0xef, 0xbf, 0xff, 0xce, 0x13, 0xff, 0xfe, 0x48, 0xff, 0xd5, 0x26, 0xff, 0x82, 0x82, 0xff, 0xe4, 0xe3, 0xff, 0xfd, 0x83, 0xff,
0xfd, 0x42, 0xff, 0xf5, 0x02, 0xff, 0xe4, 0x81, 0xff, 0xd3, 0xe0, 0xff, 0xcb, 0x61, 0xb5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0x63, 0x34, 0xcb, 0x80, 0xfd, 0xdc, 0x21, 0xff, 0xe4, 0xa1, 0xff, 0xf5, 0x22, 0xff,
0xfd, 0x42, 0xff, 0xf5, 0x63, 0xff, 0xfd, 0xe5, 0xff, 0xfd, 0xc5, 0xff, 0xe6, 0x0d, 0xff, 0xef, 0x9f, 0xff, 0xef, 0x9f, 0xff, 0xdd, 0x4c, 0xff, 0xf5, 0x65, 0xff, 0xfe, 0x07, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x07, 0xff, 0xf5, 0x45, 0xff,
0xd5, 0x8f, 0xff, 0xf7, 0xdf, 0xff, 0xce, 0xff, 0xff, 0xe5, 0xca, 0xff, 0xfd, 0xc5, 0xff, 0xfd, 0xe5, 0xff, 0xed, 0x43, 0xff, 0xfd, 0x42, 0xff, 0xf5, 0x22, 0xff, 0xec, 0xc1, 0xff, 0xdc, 0x21, 0xff, 0xd3, 0x80, 0xfe, 0xc3, 0x62, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcb, 0x41, 0xa6, 0xd3, 0xc0, 0xff, 0xdc, 0x41, 0xff, 0xec, 0xc2, 0xff, 0xf5, 0x22, 0xff, 0xfd, 0x42, 0xff, 0xfd, 0x62, 0xff, 0xf5, 0x85, 0xff, 0xd6, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xd7, 0x1e, 0xff, 0xe4, 0xa5, 0xff,
0xf5, 0x66, 0xff, 0xfd, 0xe7, 0xff, 0xfe, 0x07, 0xff, 0xfe, 0x07, 0xff, 0xfe, 0x07, 0xff, 0xfe, 0x07, 0xff, 0xfd, 0xe7, 0xff, 0xf5, 0x25, 0xff, 0xdc, 0xc7, 0xff, 0xe7, 0x7f, 0xff, 0xf7, 0xdf, 0xff, 0xb6, 0x3a, 0xff, 0xfd, 0x84, 0xff, 0xfd, 0xe8, 0xff, 0xf5, 0xa9, 0xff, 0xf5, 0x22, 0xff,
0xec, 0xe2, 0xff, 0xdc, 0x61, 0xff, 0xd3, 0xc0, 0xff, 0xcb, 0x41, 0xb0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x82, 0x19, 0xcb, 0x60, 0xeb, 0xd3, 0xe0, 0xff, 0xe4, 0x61, 0xff,
0xed, 0x04, 0xff, 0xe5, 0x8a, 0xff, 0xee, 0x94, 0xff, 0xd6, 0x77, 0xff, 0xf7, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xd6, 0x37, 0xff, 0xe4, 0x63, 0xff, 0xf5, 0x44, 0xff, 0xfd, 0xa5, 0xff, 0xfd, 0xc6, 0xff, 0xfd, 0xc6, 0xff, 0xfd, 0xc6, 0xff, 0xfd, 0xc6, 0xff, 0xfd, 0xa5, 0xff, 0xed, 0x04, 0xff,
0xe4, 0x43, 0xff, 0xce, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xe7, 0x7f, 0xff, 0xd6, 0xbb, 0xff, 0xf7, 0xbe, 0xff, 0xdf, 0x5f, 0xff, 0xcd, 0x6e, 0xff, 0xe4, 0x61, 0xff, 0xd3, 0xe1, 0xff, 0xcb, 0x60, 0xef, 0xc3, 0x82, 0x1f, 0xfd, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0xc3, 0x61, 0x4b, 0xcb, 0xc3, 0xfc, 0xe6, 0xfa, 0xff, 0xf7, 0xbe, 0xff, 0xef, 0x9f, 0xff, 0xef, 0xbf, 0xff, 0xf7, 0xbf, 0xff, 0xf7, 0xbf, 0xff, 0xf7, 0xdf, 0xff, 0xdd, 0xb0, 0xff, 0xe4, 0x42, 0xff,
0xf5, 0x03, 0xff, 0xfd, 0x64, 0xff, 0xfd, 0x84, 0xff, 0xfd, 0xa4, 0xff, 0xfd, 0xa4, 0xff, 0xfd, 0x84, 0xff, 0xfd, 0x64, 0xff, 0xec, 0xc3, 0xff, 0xe4, 0x23, 0xff, 0xd6, 0x57, 0xff, 0xf7, 0xdf, 0xff, 0xff, 0xdf, 0xff, 0xf7, 0xdf, 0xff, 0xff, 0xdf, 0xff, 0xe7, 0x9f, 0xff, 0xc6, 0x9c, 0xff,
0xd4, 0x86, 0xff, 0xcb, 0x80, 0xfd, 0xc3, 0x61, 0x55, 0xfd, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x02, 0xad, 0x97, 0x90, 0xd7, 0x3f, 0xff,
0xf7, 0xdf, 0xff, 0xff, 0xdf, 0xff, 0xff, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0xff, 0xff, 0xdf, 0xff, 0xd6, 0x78, 0xff, 0xe4, 0x43, 0xff, 0xec, 0xa2, 0xff, 0xf5, 0x02, 0xff, 0xfd, 0x43, 0xff, 0xfd, 0x63, 0xff, 0xfd, 0x43, 0xff, 0xfd, 0x23, 0xff, 0xf5, 0x02, 0xff, 0xec, 0x62, 0xff,
0xde, 0x55, 0xff, 0xf7, 0xbe, 0xff, 0xf7, 0xdf, 0xff, 0xff, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0xff, 0xdf, 0x7f, 0xff, 0xbd, 0x32, 0xa0, 0xfd, 0x00, 0x02, 0xfd, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0xbe, 0x9c, 0x7d, 0xe7, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xdf, 0xff, 0xdf, 0x7f, 0xff, 0xae, 0x5e, 0xff, 0xce, 0x37, 0xff,
0xe4, 0x41, 0xff, 0xec, 0xa2, 0xff, 0xf5, 0x02, 0xff, 0xfd, 0x22, 0xff, 0xf5, 0x02, 0xff, 0xf4, 0xe2, 0xff, 0xec, 0x82, 0xff, 0xe4, 0x01, 0xff, 0xd6, 0xfc, 0xff, 0xef, 0x9f, 0xff, 0xef, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xdf, 0xff,
0xe7, 0x7f, 0xff, 0xb6, 0x9e, 0xcd, 0xfd, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb6, 0x7d, 0x1a, 0xdf, 0x7f, 0xf5, 0xff, 0xdf, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xdf, 0xff, 0xd7, 0x1f, 0xff, 0xb5, 0xb7, 0xff, 0xdb, 0xe1, 0xff, 0xe4, 0x42, 0xff, 0xec, 0xa2, 0xff, 0xf4, 0xe2, 0xff, 0xec, 0xc2, 0xff, 0xec, 0x82, 0xff, 0xe4, 0x22, 0xff, 0xd4, 0x24, 0xff,
0xae, 0x1c, 0xff, 0xc6, 0xdf, 0xff, 0xef, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xdf, 0xff, 0xd7, 0x3f, 0xff, 0xa6, 0x5e, 0xb7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xae, 0x5e, 0x54, 0xcf, 0x1f, 0xff, 0xef, 0xbf, 0xff, 0xf7, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0xbf, 0xff, 0xc5, 0x31, 0xff,
0xd3, 0xa1, 0xff, 0xdc, 0x01, 0xff, 0xe4, 0x61, 0xff, 0xe4, 0x82, 0xff, 0xe4, 0x82, 0xff, 0xdc, 0x41, 0xff, 0xd3, 0xc1, 0xff, 0xcc, 0xab, 0xff, 0xb6, 0x9f, 0xff, 0xdf, 0x5f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0xbf, 0xff,
0xb6, 0x7e, 0xff, 0x85, 0x5b, 0x9a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9d, 0xfd, 0x22, 0xb6, 0x9f, 0xf9, 0xdf, 0x5f, 0xff,
0xf7, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0x9f, 0xff, 0xb6, 0x1b, 0xff, 0xcb, 0x20, 0xff, 0xd3, 0xa1, 0xff, 0xdc, 0x01, 0xff, 0xdc, 0x21, 0xff, 0xdc, 0x01, 0xff, 0xd3, 0xc1, 0xff, 0xcb, 0x61, 0xff, 0xc3, 0x21, 0xff,
0xad, 0x13, 0xff, 0xef, 0x9f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xdf, 0xff, 0x9d, 0xfc, 0xff, 0x8d, 0x7c, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8d, 0x9c, 0x57, 0x9d, 0xfd, 0xff, 0xd7, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0x9f, 0xff, 0xdf, 0x7f, 0xff, 0xdf, 0x5f, 0xff, 0xbe, 0xbf, 0xff, 0x9c, 0x93, 0xf0,
0xb2, 0xa0, 0xfe, 0xc3, 0x20, 0xff, 0xcb, 0x60, 0xff, 0xcb, 0x80, 0xff, 0xcb, 0x80, 0xff, 0xcb, 0x40, 0xff, 0xba, 0xc0, 0xff, 0xb2, 0x60, 0xff, 0xab, 0xcb, 0xf2, 0xd7, 0x3f, 0xff, 0xef, 0xdf, 0xff, 0xf7, 0xdf, 0xff, 0xe7, 0x7f, 0xff, 0xdf, 0x5f, 0xff, 0xef, 0x9f, 0xff, 0xcf, 0x1f, 0xff,
0x95, 0xdd, 0xa0, 0x84, 0xf8, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8d, 0x7c, 0x13, 0x85, 0x7b, 0xdb,
0xa6, 0x3d, 0xfe, 0xdf, 0x5f, 0xff, 0xe7, 0x7f, 0xff, 0xbe, 0x9e, 0xff, 0xae, 0x7f, 0xff, 0x8d, 0xdd, 0xff, 0x85, 0x19, 0x5c, 0xcc, 0xe9, 0x09, 0xcb, 0xe3, 0x21, 0xbb, 0x22, 0x49, 0xbb, 0x01, 0x62, 0xbb, 0x01, 0x6f, 0xbb, 0x01, 0x70, 0xb3, 0x01, 0x64, 0xb3, 0x02, 0x4d, 0xc3, 0xc4, 0x24,
0xad, 0x96, 0x1a, 0x9e, 0x1e, 0xe4, 0xbe, 0x9f, 0xff, 0xae, 0x7e, 0xff, 0xae, 0x7f, 0xff, 0x9d, 0xdd, 0xff, 0xae, 0x5e, 0xe0, 0x95, 0xbd, 0xa5, 0x7d, 0x3a, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0xf9, 0x03, 0x8d, 0x7b, 0x3f, 0x95, 0xdd, 0xb9, 0x9d, 0xfd, 0xca, 0x8d, 0x7c, 0x89, 0x95, 0xbd, 0xd1, 0x8d, 0x9c, 0x90, 0xec, 0xe3, 0x02, 0xfd, 0x00, 0x02,
0xfd, 0x00, 0x02, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x02, 0xfd, 0x00, 0x02, 0x95, 0x37, 0x14, 0x7d, 0x1a, 0x3c, 0x85, 0x3a, 0x82, 0x95, 0xdd, 0xed, 0x8d, 0x9d, 0x8d, 0x7d, 0x1a, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8d, 0x17, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
|
the_stack_data/1063269.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/30 08:27:21 by sbecker #+# #+# */
/* Updated: 2018/12/12 17:18:57 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
void ft_striteri(char *s, void (*f)(unsigned int, char*))
{
unsigned int i;
i = -1;
if (s && f)
while (s[++i])
f(i, &s[i]);
}
|
the_stack_data/64201359.c | /* Taxonomy Classification: 0000000100000151000010 */
/*
* WRITE/READ 0 write
* WHICH BOUND 0 upper
* DATA TYPE 0 char
* MEMORY LOCATION 0 stack
* SCOPE 0 same
* CONTAINER 0 no
* POINTER 0 no
* INDEX COMPLEXITY 1 variable
* ADDRESS COMPLEXITY 0 constant
* LENGTH COMPLEXITY 0 N/A
* ADDRESS ALIAS 0 none
* INDEX ALIAS 0 none
* LOCAL CONTROL FLOW 0 none
* SECONDARY CONTROL FLOW 1 if
* LOOP STRUCTURE 5 non-standard do-while
* LOOP COMPLEXITY 1 zero
* ASYNCHRONY 0 no
* TAINT 0 no
* RUNTIME ENV. DEPENDENCE 0 no
* MAGNITUDE 0 no overflow
* CONTINUOUS/DISCRETE 1 continuous
* SIGNEDNESS 0 no
*/
/*
Copyright 2005 Massachusetts Institute of Technology
All rights reserved.
Redistribution and use of software 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 set of conditions and the disclaimer below.
- Redistributions in binary form must reproduce the copyright notice, this
set of conditions, and the disclaimer below in the documentation and/or
other materials provided with the distribution.
- Neither the name of the Massachusetts Institute of Technology 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".
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.
*/
int main(int argc, char *argv[])
{
int loop_counter;
char buf[10];
loop_counter = 0;
do
{
/* OK */
buf[loop_counter] = 'A';
loop_counter++;
if (loop_counter > 9) break;
}
while(1);
return 0;
}
|
the_stack_data/53978.c | _Bool nondet_bool();
void main()
{
int i=2, j;
if(nondet_bool())
i++;
j=(i/=2);
assert(i==1);
assert(j==1);
}
|
the_stack_data/115245.c | #include <stdio.h>
#include <stdlib.h>
void fun(int, int);
int ex010(void)
{
int a, b;
a=10;
b=15;
printf("Outside the function: \na=%d, \tb=%d\n", a, b);
printf("The memory address: a=%d, b=%d\n", &a, &b );
fun(a,b);
printf("==========================================\n");
printf("After calling the function: \na=%d, \tb=%d\n", a, b);
system("pause");
return 0;
}
void fun(int a, int b){
printf("=========================================\n");
printf("Inside the function\n");
printf("Entered parameters: a=%d, b=%d\n", a, b);
printf("The memory address of a=%d, b=%d\n", &a, &b);
/* Reset the variables */
a=20;
b=30;
printf("Parameter after changed by the function is a=%d, b=%d\n", a, b);
} |
the_stack_data/132503.c | /*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifdef __ICCARM__
#include <stdarg.h>
#include <sys/types.h>
#include <time.h>
#include <stdio.h>
#include <hal/hal.h>
int errno;
extern void *aos_malloc(unsigned int size);
extern void aos_alloc_trace(void *addr, size_t allocator);
extern void aos_free(void *mem);
extern void *aos_realloc(void *mem, unsigned int size);
extern long long aos_now_ms(void);
__ATTRIBUTES void *malloc(unsigned int size)
{
void *mem;
#if (RHINO_CONFIG_MM_DEBUG > 0u && RHINO_CONFIG_GCC_RETADDR > 0u)
mem = aos_malloc(size | AOS_UNSIGNED_INT_MSB);
#else
mem = aos_malloc(size);
#endif
return mem;
}
__ATTRIBUTES void *realloc(void *old, unsigned int newlen)
{
void *mem;
#if (RHINO_CONFIG_MM_DEBUG > 0u && RHINO_CONFIG_GCC_RETADDR > 0u)
mem = aos_realloc(old, newlen | AOS_UNSIGNED_INT_MSB);
#else
mem = aos_realloc(old, newlen);
#endif
return mem;
}
__ATTRIBUTES void *calloc(size_t len, size_t elsize)
{
void *mem;
#if (RHINO_CONFIG_MM_DEBUG > 0u && RHINO_CONFIG_GCC_RETADDR > 0u)
mem = aos_malloc((elsize * len) | AOS_UNSIGNED_INT_MSB);
#else
mem = aos_malloc(elsize * len);
#endif
if (mem) {
memset(mem, 0, elsize * len);
}
return mem;
}
__ATTRIBUTES void free(void *mem)
{
aos_free(mem);
}
__ATTRIBUTES time_t time(time_t *tod)
{
uint64_t t = aos_now_ms();
return (time_t)(t / 1000);
}
int *__errno _PARAMS ((void))
{
return 0;
}
void __assert_func(const char * a, int b, const char * c, const char *d)
{
while (1);
}
/*TO DO*/
#pragma weak __write
size_t __write(int handle, const unsigned char *buffer, size_t size)
{
uart_dev_t uart_stdio;
int i;
memset(&uart_stdio, 0, sizeof(uart_stdio));
uart_stdio.port = 0;
if (buffer == 0)
{
/*
* This means that we should flush internal buffers. Since we don't we just return.
* (Remember, "handle" == -1 means that all handles should be flushed.)
*/
return 0;
}
/* This function only writes to "standard out" and "standard err" for all other file handles it returns failure. */
if ((handle != 1) && (handle != 2))
{
return ((size_t)-1);
}
/* Send data. */
for (i = 0; i < size; i++) {
if (buffer[i] == '\n') {
hal_uart_send(&uart_stdio, (void *)"\r", 1, 0);
}
hal_uart_send(&uart_stdio, &buffer[i], 1, 0);
}
return size;
}
void bzero()
{
}
void __lseek()
{
}
void __close()
{
}
int remove(char const *p)
{
return 0;
}
void gettimeofday()
{
}
void getopt()
{
}
void optarg()
{
}
#endif
|
the_stack_data/175141977.c | /* This testcase is part of GDB, the GNU debugger.
Copyright 2009-2021 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
static const char *image;
static pthread_barrier_t barrier;
static char *argv1 = "go away";
static void *
thread_execler (void *arg)
{
int i;
pthread_barrier_wait (&barrier);
/* Exec ourselves again. */
if (execl (image, image, argv1, NULL) == -1) /* break-here */
{
perror ("execl");
abort ();
}
return NULL;
}
static void *
just_loop (void *arg)
{
unsigned int i;
pthread_barrier_wait (&barrier);
for (i = 1; i > 0; i++)
usleep (1);
return NULL;
}
#define THREADS 5
pthread_t loop_thread[THREADS];
int
main (int argc, char **argv)
{
pthread_t thread;
int i, t;
image = argv[0];
/* Pass "inf" as argument to keep re-execing ad infinitum, which can
be useful for manual testing. Passing any other argument exits
immediately (and that's what the execl above does by
default). */
if (argc == 2 && strcmp (argv[1], "inf") == 0)
argv1 = argv[1];
else if (argc > 1)
exit (0);
pthread_barrier_init (&barrier, NULL, 2 + THREADS);
i = pthread_create (&thread, NULL, thread_execler, NULL);
assert (i == 0);
for (t = 0; t < THREADS; t++)
{
i = pthread_create (&loop_thread[t], NULL, just_loop, NULL);
assert (i == 0);
}
pthread_barrier_wait (&barrier);
pthread_join (thread, NULL);
return 0;
}
|
the_stack_data/237641970.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *duplicate(char *str);
int main() {
char *str = "hello world!!";
char *new_str = duplicate(str);
printf("str address: %p new_str address: %p\n%s\n", str, new_str, new_str);
return 0;
}
char *duplicate(char *str) {
char *p = (char *)malloc(strlen(str));
if (p == NULL) {
printf("Error: malloc failed!\n");
return NULL;
}
strcpy(p, str);
return p;
} |
the_stack_data/1014967.c | #include <stdio.h>
int main()
{
int ara[5] = {50, 60, 70, 80, 90};
printf("%d, %d, %d, %d, %d\n", ara[0], ara[1], ara[2], ara[3], ara[4]);
printf("%u\n", ara);
printf("%u\n", &ara[0]);
printf("%u\n", &ara[1]);
return 0;
}
|
the_stack_data/24276.c | /* This testcase is part of GDB, the GNU debugger.
Copyright 1996-2015 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <signal.h>
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
enum tests {
code_entry_point, code_descriptor, data_read, data_write
};
static volatile enum tests test;
/* Some basic types and zero buffers. */
typedef long data_t;
typedef long code_t (void);
data_t *volatile data;
code_t *volatile code;
/* "desc" is intentionally initialized to a data object. This is
needed to test function descriptors on arches like ia64. */
data_t zero[10];
code_t *volatile desc = (code_t *) (void *) zero;
sigjmp_buf env;
extern void
keeper (int sig)
{
siglongjmp (env, 0);
}
extern long
bowler (void)
{
switch (test)
{
case data_read:
/* Try to read address zero. */
return (*data);
case data_write:
/* Try to write (the assignment) to address zero. */
return (*data) = 1;
case code_entry_point:
/* For typical architectures, call a function at address
zero. */
return (*code) ();
case code_descriptor:
/* For atypical architectures that use function descriptors,
call a function descriptor, the code field of which is zero
(which has the effect of jumping to address zero). */
return (*desc) ();
}
}
int
main ()
{
static volatile int i;
struct sigaction act;
memset (&act, 0, sizeof act);
act.sa_handler = keeper;
sigaction (SIGSEGV, &act, NULL);
sigaction (SIGBUS, &act, NULL);
for (i = 0; i < 10; i++)
{
sigsetjmp (env, 1);
bowler ();
}
}
|
the_stack_data/45451420.c | /*
Markov chain sentence generator
Written in 2021 by Lukas Holzbeierlein (Captain4LK) email: captain4lk [at] tutanota [dot] com
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
//External includes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <time.h>
//-------------------------------------
//Internal includes
//-------------------------------------
//#defines
//Universal dynamic array
#define dyn_array_init(type, array, space) \
do { ((dyn_array *)(array))->size = (space); ((dyn_array *)(array))->used = 0; ((dyn_array *)(array))->data = malloc(sizeof(type)*(((dyn_array *)(array))->size)); } while(0)
#define dyn_array_free(type, array) \
do { if(((dyn_array *)(array))->data) { free(((dyn_array *)(array))->data); ((dyn_array *)(array))->data = NULL; ((dyn_array *)(array))->used = 0; ((dyn_array *)(array))->size = 0; }} while(0)
#define dyn_array_add(type, array, grow, element) \
do { ((type *)((dyn_array *)(array)->data))[((dyn_array *)(array))->used] = (element); ((dyn_array *)(array))->used++; if(((dyn_array *)(array))->used==((dyn_array *)(array))->size) { ((dyn_array *)(array))->size+=grow; ((dyn_array *)(array))->data = realloc(((dyn_array *)(array))->data,sizeof(type)*(((dyn_array *)(array))->size)); } } while(0)
#define dyn_array_element(type, array, index) \
(((type *)((dyn_array *)(array)->data))[index])
#define EXPAND 128
#define SIZE 128
#define READ_ARG(I) \
((++(I))<argc?argv[(I)]:NULL)
#define FNV_64_PRIME ((uint64_t)0x100000001b3ULL)
//-------------------------------------
//Typedefs
typedef struct
{
unsigned used;
unsigned size;
void *data;
}dyn_array;
typedef struct
{
dyn_array prefix;
dyn_array suffix;
}Markov_entry;
typedef struct
{
int32_t entry;
int32_t weight;
}Suffix;
typedef struct
{
uint64_t hash;
char *word;
}Word;
//-------------------------------------
//Variables
dyn_array words = {0};
dyn_array markov_chain = {0};
dyn_array markov_chain_start = {0};
//-------------------------------------
//Function prototypes
static void print_help(char **argv);
static void dump_model(const char *path);
static void generate_chain(int state_size, dyn_array sentences);
static void load_model(int state_size, const char *path);
static int add_word(const char *word);
static void add_entry(dyn_array prefix,int32_t suffix, int start);
static void generate_sentence(char *input, int state_size);
static int find_prefix(dyn_array prefix);
static char *file_read(const char *path);
static dyn_array string_split_sentence(char *input);
static dyn_array string_split_line(char *input);
static void string_split_free(dyn_array *sp);
static int is_abbreviation(const char *word);
static char *HLH_strtok(char *s, const char *sep, char *t);
static uint64_t fnv64a(const char *str);
//-------------------------------------
//Function implementations
int main(int argc, char **argv)
{
//Parse cmd arguments
const char *path = NULL;
const char *path_model = NULL;
const char *path_out = NULL;
int state_size = 2;
int sentence_mode = 0;
int sentence_count = 1;
for(int i = 1;i<argc;i++)
{
if(strcmp(argv[i],"--help")==0||
strcmp(argv[i],"-help")==0||
strcmp(argv[i],"-h")==0||
strcmp(argv[i],"?")==0)
print_help(argv);
else if(strcmp(argv[i],"-i")==0)
path = READ_ARG(i);
else if(strcmp(argv[i],"-m")==0)
path_model = READ_ARG(i);
else if(strcmp(argv[i],"-o")==0)
path_out = READ_ARG(i);
else if(strcmp(argv[i],"-sz")==0)
state_size = atoi(READ_ARG(i));
else if(strcmp(argv[i],"-sm")==0)
sentence_mode = atoi(READ_ARG(i));
else if(strcmp(argv[i],"-s")==0)
sentence_count = atoi(READ_ARG(i));
}
if(path==NULL)
{
printf("No input file specified, try %s --help\n",argv[0]);
return -1;
}
srand(time(NULL));
if(path_model==NULL)
{
char *input = file_read(path);
dyn_array sentences;
if(sentence_mode==0)
sentences = string_split_sentence(input);
else if(sentence_mode==1)
sentences = string_split_line(input);
free(input);
generate_chain(state_size,sentences);
string_split_free(&sentences);
dump_model("out.bin");
//Print stats
printf("Stats:\n-------------------------------\n");
printf("Unique words: %d\n",words.used);
printf("Prefixes: %d\n",markov_chain.used);
int64_t count = 0;
int32_t max = INT32_MIN;
int32_t min = INT32_MAX;
for(int i = 0;i<markov_chain.used;i++)
{
int32_t num = dyn_array_element(Markov_entry,&markov_chain,i).suffix.used;
if(num>max) max = num;
if(num<min) min = num;
count+=num;
}
printf("Average suffixes: %lf\n",(double)count/(double)markov_chain.used);
printf("Max suffixes: %d\n",max);
printf("Min suffixes: %d\n",min);
printf("-------------------------------\n");
}
else
{
load_model(state_size,path_model);
}
char *input = file_read(path);
for(int i = 0;i<sentence_count;i++)
generate_sentence(input,state_size);
free(input);
return 0;
}
static void print_help(char **argv)
{
printf("%s usage:\n"
"%s -i filename [-o filename] [-sz state_size]\n"
" -i\tfile to generate chain from\n"
" -o\tfile to write output to (stdout if not provided)\n"
" -sz\tstate size, number of words to consider, 2 by default\n",
argv[0],argv[0]);
}
static void dump_model(const char *path)
{
FILE *f = fopen(path,"wb");
//Dump words
fwrite(&words.used,sizeof(int32_t),1,f);
for(int i = 0;i<words.used;i++)
{
char *word = dyn_array_element(Word,&words,i).word;
int32_t len = strlen(word);
fwrite(&len,sizeof(int32_t),1,f);
fwrite(word,len,1,f);
}
//Dump markov chain start
fwrite(&markov_chain_start.used,sizeof(int32_t),1,f);
for(int i = 0;i<markov_chain_start.used;i++)
fwrite(&dyn_array_element(int32_t,&markov_chain_start,i),sizeof(int32_t),1,f);
//Dump markov chain
fwrite(&markov_chain.used,sizeof(int32_t),1,f);
for(int i = 0;i<markov_chain.used;i++)
{
Markov_entry *e = &dyn_array_element(Markov_entry,&markov_chain,i);
fwrite(&e->prefix.used,sizeof(int32_t),1,f);
for(int j = 0;j<e->prefix.used;j++)
fwrite(&dyn_array_element(int32_t,&e->prefix,j),sizeof(int32_t),1,f);
fwrite(&e->suffix.used,sizeof(int32_t),1,f);
for(int j = 0;j<e->suffix.used;j++)
{
fwrite(&dyn_array_element(Suffix,&e->suffix,j).entry,sizeof(int32_t),1,f);
fwrite(&dyn_array_element(Suffix,&e->suffix,j).weight,sizeof(int32_t),1,f);
}
}
fclose(f);
}
static void generate_chain(int state_size, dyn_array sentences)
{
dyn_array_init(Markov_entry,&markov_chain,SIZE);
dyn_array_init(int32_t,&markov_chain_start,SIZE);
for(int i = 0;i<sentences.used;i++)
{
if(dyn_array_element(dyn_array,&sentences,i).used<state_size)
continue;
int max = dyn_array_element(dyn_array,&sentences,i).used;
for(int j = 0;j<max;j++)
{
if(j+state_size>max)
continue;
int32_t pos = 0;
dyn_array prefix;
dyn_array_init(int32_t,&prefix,state_size);
for(int s = j;s<j+state_size;s++)
{
char *word = dyn_array_element(char *,&dyn_array_element(dyn_array,&sentences,i),s);
pos = add_word(word);
dyn_array_add(int32_t,&prefix,EXPAND,pos);
}
char *suffix = NULL;
pos = -1;
if(j+state_size<max)
{
suffix = dyn_array_element(char *,&dyn_array_element(dyn_array,&sentences,i),j+state_size);
pos = add_word(suffix);
}
//Add to markov chain
add_entry(prefix,pos,j==0);
dyn_array_free(int32_t,&prefix);
}
}
}
static int add_word(const char *word)
{
uint64_t hash = fnv64a(word);
if(words.size==0)
dyn_array_init(Word,&words,SIZE);
//Check if in array
for(int i = 0;i<words.used;i++)
if(dyn_array_element(Word,&words,i).hash==hash)
return i;
//Add to array
Word nword;
nword.hash = hash;
nword.word = malloc(strlen(word)+1);
strcpy(nword.word,word);
dyn_array_add(Word,&words,EXPAND,nword);
return words.used-1;
}
static void add_entry(dyn_array prefix, int32_t suffix, int start)
{
for(int i = 0;i<markov_chain.used;i++)
{
Markov_entry *entry = &dyn_array_element(Markov_entry,&markov_chain,i);
int found = 1;
for(int j = 0;j<prefix.used;j++)
{
if(dyn_array_element(int32_t,&prefix,j)!=dyn_array_element(int32_t,&entry->prefix,j))
{
found = 0;
break;
}
}
if(found)
{
found = 0;
for(int j = 0;j<entry->suffix.used;j++)
{
Suffix *s = &dyn_array_element(Suffix,&entry->suffix,j);
if(s->entry==suffix)
{
found = 1;
s->weight++;
break;
}
}
if(!found)
{
Suffix suff = {.entry = suffix, .weight = 1};
dyn_array_add(Suffix,&entry->suffix,EXPAND,suff);
}
return;
}
}
Markov_entry entry = {0};
dyn_array_init(int32_t,&entry.prefix,SIZE);
for(int i = 0;i<prefix.used;i++)
dyn_array_add(int32_t,&entry.prefix,EXPAND,dyn_array_element(int32_t,&prefix,i));
dyn_array_init(Suffix,&entry.suffix,SIZE);
Suffix suff = {.entry = suffix, .weight = 1};
dyn_array_add(Suffix,&entry.suffix,SIZE,suff);
dyn_array_add(Markov_entry,&markov_chain,SIZE,entry);
if(start)
dyn_array_add(int32_t,&markov_chain_start,EXPAND,markov_chain.used-1);
}
static void generate_sentence(char *input, int state_size)
{
dyn_array last_arr;
dyn_array sentence;
dyn_array_init(int32_t,&last_arr,state_size);
dyn_array_init(char,&sentence,SIZE);
last_arr.used = state_size;
int32_t *last = (int32_t *)last_arr.data;
//Try to generate valid sentence ten times
for(int t = 0;t<10;t++)
{
sentence.used = 0;
//Generate starting words
int prefix = dyn_array_element(int32_t,&markov_chain_start,rand()%markov_chain_start.used);
Markov_entry *e = &dyn_array_element(Markov_entry,&markov_chain,prefix);
for(int i = 0;i<e->prefix.used;i++)
{
last[i] = dyn_array_element(int32_t,&e->prefix,i);
if(last[i]!=-1)
{
char *word = dyn_array_element(Word,&words,last[i]).word;
for(;*word;word++)
dyn_array_add(char,&sentence,EXPAND,*word);
dyn_array_add(char,&sentence,EXPAND,' ');
}
}
while(last[state_size-1]!=-1)
{
e = &dyn_array_element(Markov_entry,&markov_chain,find_prefix(last_arr));
prefix = dyn_array_element(Suffix,&e->suffix,rand()%e->suffix.used).entry;
if(prefix!=-1)
{
char *word = dyn_array_element(Word,&words,prefix).word;
for(;*word;word++)
dyn_array_add(char,&sentence,EXPAND,*word);
dyn_array_add(char,&sentence,EXPAND,' ');
}
for(int i = 0;i<state_size-1;i++)
last[i] = last[i+1];
last[state_size-1] = prefix;
}
//Remove last charecter --> will always be whitespace, but is not desired for strstr
sentence.used--;
dyn_array_add(char,&sentence,EXPAND,'\n');
//Add two to make sure there is enough space in string
//to correctly replace when checking
dyn_array_add(char,&sentence,EXPAND,'\0');
dyn_array_add(char,&sentence,EXPAND,'\0');
//Check sentence
const char *breakset = ".!?\n";
char *text = (char *)sentence.data;
char replaced = '\0';
char *text_start = text;
char *text_end = text;
int found = 0;
do
{
text_end = strpbrk(text_end,breakset);
if(text_end!=NULL)
{
replaced = *(text_end);
*(text_end) = '\0';
if(strstr(input,text_start)!=NULL)
found = 1;
*(text_end) = replaced;
}
if(text_end!=NULL)
text_end+=strspn(text_end,breakset);
text_start = text_end;
}
while(text_end!=NULL&&*text_end!='\0');
if(!found)
break;
if(t==9)
printf("NU!:");
}
printf("%s",((char *)sentence.data));
dyn_array_free(int32_t,&last_arr);
dyn_array_free(char,&sentence);
}
static int find_prefix(dyn_array prefix)
{
for(int i = 0;i<markov_chain.used;i++)
{
Markov_entry *entry = &dyn_array_element(Markov_entry,&markov_chain,i);
int found = 1;
for(int j = 0;j<prefix.used;j++)
{
if(dyn_array_element(int32_t,&prefix,j)!=dyn_array_element(int32_t,&entry->prefix,j))
{
found = 0;
break;
}
}
if(found)
return i;
}
return -1;
}
static void load_model(int state_size, const char *path)
{
FILE *f = fopen(path,"rb");
int32_t word_count = 0;
fread(&word_count,sizeof(int32_t),1,f);
for(int i = 0;i<word_count;i++)
{
int32_t len = 0;
fread(&len,sizeof(int32_t),1,f);
char *nword = malloc(len+1);
fread(nword,len,1,f);
nword[len] = '\0';
add_word(nword);
}
int32_t entry_count = 0;
fread(&entry_count,sizeof(int32_t),1,f);
dyn_array_init(int32_t,&markov_chain_start,entry_count);
for(int i = 0;i<entry_count;i++)
{
int32_t en = 0;
fread(&en,sizeof(int32_t),1,f);
dyn_array_add(int32_t,&markov_chain_start,EXPAND,en);
}
entry_count = 0;
fread(&entry_count,sizeof(int32_t),1,f);
dyn_array_init(Markov_entry,&markov_chain,entry_count);
for(int i = 0;i<entry_count;i++)
{
Markov_entry e;
int32_t used = 0;
fread(&used,sizeof(int32_t),1,f);
dyn_array_init(int32_t,&e.prefix,used);
for(int j = 0;j<used;j++)
{
int32_t el = 0;
fread(&el,sizeof(int32_t),1,f);
dyn_array_add(int32_t,&e.prefix,EXPAND,el);
}
fread(&used,sizeof(int32_t),1,f);
dyn_array_init(Suffix,&e.suffix,used);
for(int j = 0;j<used;j++)
{
Suffix s;
int32_t el = 0;
fread(&el,sizeof(int32_t),1,f);
s.entry = el;
fread(&el,sizeof(int32_t),1,f);
s.weight = el;
dyn_array_add(Suffix,&e.suffix,EXPAND,s);
}
dyn_array_add(Markov_entry,&markov_chain,EXPAND,e);
}
fclose(f);
}
static char *file_read(const char *path)
{
FILE *f = fopen(path,"rb");
int32_t size = 0;
fseek(f,0,SEEK_END);
size = ftell(f);
fseek(f,0,SEEK_SET);
char *text = malloc(size+1);
fread(text,size,1,f);
text[size] = 0;
fclose(f);
return text;
}
static dyn_array string_split_sentence(char *input)
{
dyn_array sp;
dyn_array sentence;
const char *token = " \n";
const char *punctuation = ".!?";
int current = 0;
dyn_array_init(dyn_array,&sp,SIZE);
dyn_array_init(char *,&sentence,SIZE);
dyn_array_add(dyn_array,&sp,EXPAND,sentence);
char *word = strtok(input,token);
while(word!=NULL)
{
char *nword = malloc(strlen(word)+1);
strcpy(nword,word);
dyn_array_add(char *,&dyn_array_element(dyn_array,&sp,current),EXPAND,nword);
if(strchr(punctuation,word[strlen(word)-1])!=NULL&&!is_abbreviation(word))
{
current++;
sentence.used = 0;
sentence.size = 0;
sentence.data = NULL;
dyn_array_init(char *,&sentence,SIZE);
dyn_array_add(dyn_array,&sp,EXPAND,sentence);
}
word = strtok(NULL,token);
}
return sp;
}
static dyn_array string_split_line(char *input)
{
dyn_array sp;
dyn_array sentence;
const char *token = " \n";
char t;
int current = 0;
dyn_array_init(dyn_array,&sp,SIZE);
dyn_array_init(char *,&sentence,SIZE);
dyn_array_add(dyn_array,&sp,EXPAND,sentence);
char *word = HLH_strtok(input,token,&t);
while(word!=NULL)
{
char *nword = malloc(strlen(word)+1);
strcpy(nword,word);
dyn_array_add(char *,&dyn_array_element(dyn_array,&sp,current),EXPAND,nword);
if(t=='\n')
{
current++;
sentence.used = 0;
sentence.size = 0;
sentence.data = NULL;
dyn_array_init(char *,&sentence,SIZE);
dyn_array_add(dyn_array,&sp,EXPAND,sentence);
}
word = HLH_strtok(NULL,token,&t);
}
return sp;
}
static void string_split_free(dyn_array *sp)
{
for(int i = 0;i<sp->used;i++)
{
dyn_array *s = &dyn_array_element(dyn_array,sp,i);
for(int j = 0;j<s->used;j++)
free(dyn_array_element(char *,s,j));
dyn_array_free(char *,s);
}
dyn_array_free(dyn_array,sp);
}
static int is_abbreviation(const char *word)
{
if(strcmp(word,"Mr.")==0)
return 1;
if(strcmp(word,"Ms.")==0)
return 1;
if(strcmp(word,"Mrs.")==0)
return 1;
if(strcmp(word,"Dr.")==0)
return 1;
if(strcmp(word,"Inc.")==0)
return 1;
if(strcmp(word,"Ltd.")==0)
return 1;
if(strcmp(word,"Jr.")==0)
return 1;
if(strcmp(word,"Sr.")==0)
return 1;
if(strcmp(word,"Co.")==0)
return 1;
return 0;
}
//Essentially standard strtok, but stores the token
//the text was separated by in a variable.
static char *HLH_strtok(char *s, const char *sep, char *t)
{
static char *src = NULL;
char *p;
if(s==NULL)
s = src;
while(*s&&strchr(sep,*s)!=NULL)
s++;
if(!*s)
return NULL;
for(p = s;*s&&!strchr(sep,*s);s++);
if(*s&&s[1])
{
if(t!=NULL)
*t = *s;
*(s++) = 0;
}
src = s;
return p;
}
static uint64_t fnv64a(const char *str)
{
uint64_t hval = 0xcbf29ce484222325ULL;
unsigned char *s = (unsigned char *)str;
while(*s)
{
hval^=(uint64_t)*s++;
hval*=FNV_64_PRIME;
}
return hval;
}
//-------------------------------------
|
the_stack_data/838493.c | /*
NrrdIO: stand-alone code for basic nrrd functionality
Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann
Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
|
the_stack_data/178265053.c | /*
* Incrementing main and thread variable inifinitely
*/
#include<stdio.h>
#include<pthread.h>
void *thread_function(void *args);
int main(void){
int main_count=0;
pthread_t a_thread;
if(pthread_create(&a_thread,NULL,thread_function,NULL)!=0){
perror("\nThread Creation Failed!!");
}
while(1)
printf("\nMain Count is %d",main_count++);
pthread_join(a_thread,NULL);
return 0;
}
void *thread_function(void *args){
int thread_count=0;
while(1)
printf("\nThread Count is %d",thread_count++);
pthread_exit(NULL);
}
|
the_stack_data/323891.c | #define OK 0
#define NOK 1
void It_dynlink_dowhile(int cnt, int *out)
{
int outParam = 0;
cnt += 1;
do {
++outParam;
--cnt;
} while (cnt);
*out = outParam;
}
void It_dynlink_while(int cnt, int *out)
{
int index = 0;
int outParam = 0;
cnt += 1;
while ((index++) < cnt) {
outParam += 1;
}
*out = outParam;
}
void It_dynlink_for(int cnt, int *out)
{
int index = 0;
int outParam = 0;
cnt += 1;
for (; index < cnt; ++index) {
++outParam;
}
*out = outParam;
}
void It_dynlink_ifelse(int inVal, int *outVal)
{
int outParam;
if (inVal <= 101) {
outParam = 101;
} else if (inVal == 102) {
outParam = inVal;
} else if (inVal == 103) {
outParam = inVal;
} else if (inVal == 104) {
outParam = inVal;
} else if (inVal == 105) {
outParam = inVal;
} else if (inVal == 106) {
outParam = inVal;
} else if (inVal == 107) {
outParam = inVal;
} else if (inVal == 108) {
outParam = inVal + 1;
} else if (inVal == 109) {
outParam = 45;
} else {
outParam = 45;
}
*outVal = outParam;
}
void It_dynlink_continue(int cnt, int *out)
{
int index = 0;
int outParam = 0;
cnt += 2;
for (; index < cnt; ++index) {
if (index % 2) {
continue;
} else {
++outParam;
}
}
*out = outParam;
}
void It_dynlink_switch(char *inVal, char *outVal)
{
int i;
char outParam;
for (i = 0; i < 3; ++i) {
switch (inVal[i]) {
case 'A':
case 'a':
outParam = 'b';
break;
case 'B':
case 'b':
outParam = 'c';
break;
case 'C':
case 'c':
outParam = 'd';
break;
case 'D':
case 'd':
outParam = 'e';
break;
case 'E':
case 'e':
outParam = 'f';
break;
case 'F':
case 'f':
outParam = 'g';
break;
case 'G':
case 'g':
outParam = 'h';
break;
case 'H':
case 'h':
outParam = 'i';
break;
default:
outParam = 'z';
break;
}
outVal[i] = outParam;
}
}
|
the_stack_data/67326679.c | #include<stdio.h>
int main(){
int n,t;
scanf("%d",&n);
for(n+=1;n<=100030;n++){
t=isprimer(n);
if(t==1) break;
}
printf("%d\n",n);
return 0;
}
int isprimer(int x){
int ret=1;
int i;
if(x==1) ret=0;
for(i=2;i<x;i++){
if(x%i==0){
ret=0;
break;
}
}
return ret;
} |
the_stack_data/20451198.c | #include <stdio.h>
int main (void)
{
// printf("Hello,world\x");
} |
the_stack_data/237643568.c | /* 圆周率的估算 */
#include <stdio.h>
//#include <stdlib.h> //Windows操作系统下请务必将这一行注释"//"去掉!!!
#include <math.h>
int main(void)
{
printf("圆周率的估算\n");
printf("按下Enter键开始运行\n");
getchar();
int s;
float n,t,pi;
t=1,pi=0;n=1.0;s=1;
while(fabs(t)>1e-6)
{
pi=pi+t;
n=n+2;
s=-s;
t=s/n;
}
pi=pi*4;
printf("pi=%10.6f\n",pi);
//system("pause"); Windows操作系统下请务必将这一行注释"//"去掉!!!
return 0;
} |
the_stack_data/248581911.c | /***
* This code is a part of EvoApproxLib library (ehw.fit.vutbr.cz/approxlib) distributed under The MIT License.
* When used, please cite the following article(s): V. Mrazek, L. Sekanina, Z. Vasicek "Libraries of Approximate Circuits: Automated Design and Application in CNN Accelerators" IEEE Journal on Emerging and Selected Topics in Circuits and Systems, Vol 10, No 4, 2020
* This file contains a circuit from a sub-set of pareto optimal circuits with respect to the pwr and wce parameters
***/
// MAE% = 0.00076 %
// MAE = 0.5
// WCE% = 0.0015 %
// WCE = 1.0
// WCRE% = 100.00 %
// EP% = 50.00 %
// MRE% = 0.017 %
// MSE = 0.5
// PDK45_PWR = 0.071 mW
// PDK45_AREA = 138.0 um2
// PDK45_DELAY = 1.25 ns
#include <stdint.h>
#include <stdlib.h>
uint64_t add16se_26Q(const uint64_t B,const uint64_t A)
{
uint64_t dout_34, dout_35, dout_36, dout_37, dout_38, dout_39, dout_40, dout_41, dout_42, dout_43, dout_44, dout_45, dout_46, dout_47, dout_48, dout_49, dout_50, dout_51, dout_52, dout_53, dout_54, dout_55, dout_56, dout_57, dout_58, dout_59, dout_60, dout_61, dout_62, dout_63, dout_64, dout_65, dout_66, dout_67, dout_68, dout_69, dout_70, dout_71, dout_72, dout_73, dout_74, dout_75, dout_76, dout_77, dout_78, dout_79, dout_80, dout_81, dout_82, dout_83, dout_84, dout_85, dout_86, dout_87, dout_88, dout_89, dout_90, dout_91, dout_92, dout_93, dout_94, dout_95, dout_96, dout_97, dout_98, dout_99, dout_100, dout_101, dout_102, dout_103, dout_104, dout_105, dout_106, dout_107, dout_108, dout_109, dout_110;
uint64_t O;
dout_34=((A >> 1)&1)^((B >> 1)&1);
dout_35=((A >> 1)&1)&((B >> 1)&1);
dout_36=dout_34&((A >> 0)&1);
dout_37=dout_34^((A >> 0)&1);
dout_38=dout_35|dout_36;
dout_39=((A >> 2)&1)^((B >> 2)&1);
dout_40=((A >> 2)&1)&((B >> 2)&1);
dout_41=dout_39&dout_38;
dout_42=dout_39^dout_38;
dout_43=dout_40|dout_41;
dout_44=((A >> 3)&1)^((B >> 3)&1);
dout_45=((A >> 3)&1)&((B >> 3)&1);
dout_46=dout_44&dout_43;
dout_47=dout_44^dout_43;
dout_48=dout_45|dout_46;
dout_49=((A >> 4)&1)^((B >> 4)&1);
dout_50=((A >> 4)&1)&((B >> 4)&1);
dout_51=dout_49&dout_48;
dout_52=dout_49^dout_48;
dout_53=dout_50|dout_51;
dout_54=((A >> 5)&1)^((B >> 5)&1);
dout_55=((A >> 5)&1)&((B >> 5)&1);
dout_56=dout_54&dout_53;
dout_57=dout_54^dout_53;
dout_58=dout_55|dout_56;
dout_59=((A >> 6)&1)^((B >> 6)&1);
dout_60=((A >> 6)&1)&((B >> 6)&1);
dout_61=dout_59&dout_58;
dout_62=dout_59^dout_58;
dout_63=dout_60|dout_61;
dout_64=((A >> 7)&1)^((B >> 7)&1);
dout_65=((A >> 7)&1)&((B >> 7)&1);
dout_66=dout_64&dout_63;
dout_67=dout_64^dout_63;
dout_68=dout_65|dout_66;
dout_69=((A >> 8)&1)^((B >> 8)&1);
dout_70=((A >> 8)&1)&((B >> 8)&1);
dout_71=dout_69&dout_68;
dout_72=dout_69^dout_68;
dout_73=dout_70|dout_71;
dout_74=((A >> 9)&1)^((B >> 9)&1);
dout_75=((A >> 9)&1)&((B >> 9)&1);
dout_76=dout_74&dout_73;
dout_77=dout_74^dout_73;
dout_78=dout_75|dout_76;
dout_79=((A >> 10)&1)^((B >> 10)&1);
dout_80=((A >> 10)&1)&((B >> 10)&1);
dout_81=dout_79&dout_78;
dout_82=dout_79^dout_78;
dout_83=dout_80|dout_81;
dout_84=((A >> 11)&1)^((B >> 11)&1);
dout_85=((A >> 11)&1)&((B >> 11)&1);
dout_86=dout_84&dout_83;
dout_87=dout_84^dout_83;
dout_88=dout_85|dout_86;
dout_89=((A >> 12)&1)^((B >> 12)&1);
dout_90=((A >> 12)&1)&((B >> 12)&1);
dout_91=dout_89&dout_88;
dout_92=dout_89^dout_88;
dout_93=dout_90|dout_91;
dout_94=((A >> 13)&1)^((B >> 13)&1);
dout_95=((A >> 13)&1)&((B >> 13)&1);
dout_96=dout_94&dout_93;
dout_97=dout_94^dout_93;
dout_98=dout_95|dout_96;
dout_99=((A >> 14)&1)^((B >> 14)&1);
dout_100=((A >> 14)&1)&((B >> 14)&1);
dout_101=dout_99&dout_98;
dout_102=dout_99^dout_98;
dout_103=dout_100|dout_101;
dout_104=((A >> 15)&1)^((B >> 15)&1);
dout_105=((A >> 15)&1)&((B >> 15)&1);
dout_106=dout_104&dout_103;
dout_107=dout_104^dout_103;
dout_108=dout_105|dout_106;
dout_109=((A >> 15)&1)^((B >> 15)&1);
dout_110=dout_109^dout_108;
O = 0;
O |= (0&1) << 0;
O |= (dout_37&1) << 1;
O |= (dout_42&1) << 2;
O |= (dout_47&1) << 3;
O |= (dout_52&1) << 4;
O |= (dout_57&1) << 5;
O |= (dout_62&1) << 6;
O |= (dout_67&1) << 7;
O |= (dout_72&1) << 8;
O |= (dout_77&1) << 9;
O |= (dout_82&1) << 10;
O |= (dout_87&1) << 11;
O |= (dout_92&1) << 12;
O |= (dout_97&1) << 13;
O |= (dout_102&1) << 14;
O |= (dout_107&1) << 15;
O |= (dout_110&1) << 16;
return O;
}
|
the_stack_data/20450210.c | double snippet(double a, double b) {
if (b < a)//change
return a;//change
else
return b;//change
} |
the_stack_data/173576835.c | /*
* Written by J.T. Conklin, Apr 10, 1995
* Public domain.
*/
#include <float.h>
static const int map[] = {
1, /* round to nearest */
3, /* round to zero */
2, /* round to negative infinity */
0 /* round to positive infinity */
};
int
__flt_rounds(void)
{
int x;
/* Assume that the x87 and the SSE unit agree on the rounding mode. */
__asm("fnstcw %0" : "=m" (x));
return (map[(x >> 10) & 0x03]);
}
|
the_stack_data/147215.c | // RUN: %clang_cc1 -triple armv7-unknown-nacl-gnueabi \
// RUN: -ffreestanding -mfloat-abi hard -target-cpu cortex-a8 \
// RUN: -emit-llvm -w -o - %s | FileCheck %s
// Test that functions with pnaclcall attribute generate portable bitcode
// like the le32 arch target
typedef struct {
int a;
int b;
} s1;
// CHECK-LABEL: define i32 @f48(%struct.s1* byval %s)
int __attribute__((pnaclcall)) f48(s1 s) { return s.a; }
// CHECK-LABEL: define void @f49(%struct.s1* noalias sret %agg.result)
s1 __attribute__((pnaclcall)) f49() { s1 s; s.a = s.b = 1; return s; }
union simple_union {
int a;
char b;
};
// Unions should be passed as byval structs
// CHECK-LABEL: define void @f50(%union.simple_union* byval %s)
void __attribute__((pnaclcall)) f50(union simple_union s) {}
typedef struct {
int b4 : 4;
int b3 : 3;
int b8 : 8;
} bitfield1;
// Bitfields should be passed as byval structs
// CHECK-LABEL: define void @f51(%struct.bitfield1* byval %bf1)
void __attribute__((pnaclcall)) f51(bitfield1 bf1) {}
|
the_stack_data/1046937.c | #include <stdio.h>
void a(void)
{
printf("a() called\n");
}
|
the_stack_data/799627.c | /*Exercise 4 - Functions
Implement the three functions minimum(), maximum() and multiply() below the main() function.
Do not change the code given in the main() function when you are implementing your solution.*/
#include <stdio.h>
#include<math.h>
int minimum(int no1, int no2);
int maximum(int no1, int no2);
int multiply(int no1, int no2);
int main() {
int no1, no2;
printf("Enter a value for no 1 : ");
scanf("%d", &no1);
printf("Enter a value for no 2 : ");
scanf("%d", &no2);
printf("%d ", minimum(no1, no2));
printf("%d ", maximum(no1, no2));
printf("%d ", multiply(no1, no2));
return 0;
}
int minimum(int no1, int no2){
if(no1<no2){
return no1;
}
else{
return no2;
}
}
int maximum(int no1, int no2){
if(no1<no2){
return no2;
}
else{
return no1;
}
}
int multiply(int no1,int no2){
int mult= no1*no2;
return mult;
}
|
the_stack_data/711923.c | int main() {
// variable declarations
int c;
int n;
// pre-conditions
(c = 0);
assume((n > 0));
// loop body
while (unknown()) {
{
if ( unknown() ) {
if ( (c != n) )
{
(c = (c + 1));
}
} else {
if ( (c == n) )
{
(c = 1);
}
}
}
}
// post-condition
if ( (c == n) )
assert( (n > -1) );
}
|
the_stack_data/9467.c | /*
Output: for n =3
1
2 2
3 3 3
*/
#include <stdio.h>
int main()
{
int n, i, j;
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
{
printf("%d ", i);
}
printf("\n");
}
} |
the_stack_data/170452285.c | #include<stdio.h>
main()
{
int c;
while ((c = getchar()) != EOF)
if (c == '\t')
printf("\\t");
else if (c == '\b')
printf("\\b");
else if (c == '\\')
printf("\\\\");
else
printf("%c", c);
return 0;
}
|
the_stack_data/76226.c | #include <unistd.h>
#include <omp.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int N_BUCKETS;
struct Bucket {
int* array;
size_t n_elem;
size_t max_elem;
};
struct Bucket* make(size_t max){
struct Bucket* block_arr = malloc(sizeof(struct Bucket));
block_arr->array = malloc(sizeof(int) * max);
block_arr->n_elem = 0;
block_arr->max_elem = max;
return block_arr;
}
void free_bucket(struct Bucket* b){
free(b->array);
free(b);
}
__inline__
void buckets_to_arr(size_t size, struct Bucket* arr, int* res) {
memcpy(res, arr->array, arr->n_elem * sizeof(int));
}
void insert(struct Bucket* arr, int elem){
if(arr->n_elem >= arr->max_elem){
arr->array = realloc(arr->array, sizeof(int) * arr->max_elem * 2);
arr->max_elem *= 2;
}
arr->array[arr->n_elem] = elem;
arr->n_elem++;
}
int cmpfunc (const void * a, const void * b) {
return ( *(int*)a - *(int*)b );
}
void bucket_sort(size_t size, int* arr){
if (!size){
fprintf(stderr, "Can't calculate max of empty array");
_exit(1);
}
int max = arr[0];
int min = arr[0];
for(size_t i = 1; i < size; i++) { //vectorized
if(arr[i] > max) max = arr[i];
if(arr[i] < min) min = arr[i];
}
#ifdef NDEBUG
fprintf(stderr, "max: %d, min: %d\n", max, min);
#endif
struct Bucket* buckets[N_BUCKETS];
for (size_t i = 0; i < N_BUCKETS; i++)
buckets[i] = make(size);
#pragma omp parallel
{
#pragma omp for
for (size_t i = 0; i < N_BUCKETS; i++) {
for (size_t j = 0; j < size; j++){
size_t n_bucket = (arr[j] + abs(min)) * N_BUCKETS / (abs(max + abs(min)));
n_bucket = n_bucket >= N_BUCKETS ? N_BUCKETS - 1 : n_bucket;
if(n_bucket == i) {
#ifdef NDEBUG
fprintf(stderr, "%zu<- %d\n", i, arr[j]);
#endif
buckets[i]->array[buckets[i]->n_elem++] = arr[j];
}
}
}
size_t i = 0, j;
#pragma omp for
for(j = 0; j < N_BUCKETS; j++) {
qsort(buckets[j]->array, buckets[j]->n_elem, sizeof(int), cmpfunc);
memcpy(arr + i, buckets[j]->array, buckets[j]->n_elem * sizeof(int));
i += buckets[j]->n_elem;
free_bucket(buckets[j]);
}
}
}
void print_arr(int* arr, size_t size){
for(size_t i = 0; i < size; i++) {
arr[i] = arr[i];
printf("%d\n", arr[i]);
}
}
int main(int argc, char** argv){
N_BUCKETS = 10;
struct Bucket* b = make(100);
FILE* file = fopen (argv[1], "r");
int v;
while (!feof (file)){
fscanf (file, "%d\n", &v);
insert(b, v);
}
size_t size = b->n_elem;
#ifdef NDEBUG
print_arr(b->array, size);
#endif
double time = omp_get_wtime();
bucket_sort(size, b->array);
fprintf(stderr, "Time=%f\n", omp_get_wtime()-time);
print_arr(b->array, size);
free_bucket(b);
}
|
the_stack_data/7949857.c | #include <stdio.h> /* Cabecera llamada al sistema printf */
#include <sys/types.h> /* Cabeceras llamada al sistema open */
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h> /* Cabecera llamadas al sistema read, write y close */
#include <string.h> //Biblioteca para uso de strings
#include <stdlib.h>
#define BUF 1024
int main(int argc, char const *argv[]) {
//crear los ficheros y la pipe
int fd[2];
pipe(fd);
int pid = fork();
int file_fd;
if (pid < 0){
printf("ERROR");
exit(0);
}
else if (pid > 0){
//PADRE
close(fd[0]);
file_fd = open(argv[1], O_RDONLY);
if (file_fd < 0) {
printf("Couldn't open the file");
exit(0);
}
char buffer[BUF];
int read_bytes = read(file_fd, buffer, BUF);
while (read_bytes > 0) {
write (fd[1], buffer, read_bytes);
read_bytes = read(file_fd, buffer, BUF);
}
close(fd[1]);
wait(NULL);
}
else{
//HIJO
close(fd[1]);
dup2(fd[0], STDIN_FILENO); //cerramos y reasignampos la pipe a lectura
close(fd[0]);
execlp("grep", "grep", "hola", NULL);
exit(1);
}
return 0;
}
|
the_stack_data/51560.c | #include <stdio.h>
#include <string.h>
#include <assert.h>
int main() {
int sum = 0;
char buffer[256];
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
for (int k = 0; k < 35; k++) {
for (int t = 0; t < 256; t++) buffer[t] = t;
char *dest = buffer + i;
char *src = buffer + j;
if (dest == src) continue;
// printf("%d, %d, %d\n", i, j, k);
assert(memmove(dest, src, k) == dest);
for (int t = 0; t < 256; t++) sum += buffer[t];
}
}
}
printf("final: %d.\n", sum);
return 1;
}
|
the_stack_data/236638.c | #include <stdio.h>
int main()
{
int n,i,j,p;
scanf("%d %d",&n,&i);
p=1;
for(j=1;j<=i;j++)
{
p=p*n;
}
printf("%d",p);
}
|
the_stack_data/150143980.c | #include <stdio.h>
int binarySort(int arr[], int l, int r, int x)
{
if (r >= l)
{
int mid = l + (r - l) / 2;
if (arr[mid] == x)
return mid;
if (arr[mid] > x)
return binarySearch(arr, l, mid - 1, x);
return binarySearch(arr, mid + 1, r, x);
}
return -1;
} |
the_stack_data/167331677.c | #include <stdio.h>
int vet[10010];
int main(){
int n, contador = 0;
scanf("%d", &n);
for(int i = 1; i <= n; i++){
scanf("%d", &vet[i]);
}
for(int i = 1; i <= n; i++){
if(vet[i] == 0){
if(vet[i+1] == 0 && vet[i-1] == 0){
contador++;
}
}
}
printf("%d", contador);
return 0;
} |
the_stack_data/206394526.c | /**
* Write a program to print the information of student using structure.
*/
#include <stdio.h>
struct student
{
char name[50];
int roll;
int age;
char grade;
} s;
int main()
{
printf("Enter name, roll, age, grade:\n");
scanf("%s%d%d%s", &s.name, &s.roll, &s.age, &s.grade);
printf("%s\n%d\n%d\n%s", s.name, s.roll, s.age, s.grade);
return 0;
}
|
the_stack_data/212643987.c | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
FILE * in = fopen("input.txt", "r");
FILE * out = fopen("output.txt", "w");
int c, i;
char * chr1, * chr2, * str = calloc(4008, sizeof(char));
str[0] = ' ';
while (fgets(&(str[1]), 4004, in))
{
for(i = 0; str[i] != '\0'; ++i)
1;
if (str[i - 1] == '\n') --i;
str[i + 2] = str[i + 1];
str[i + 1] = str[i];
str[i] = ' ';
chr1 = strstr(str, " the ");
chr2 = strstr(str, " a ");
for(i = 0; str[i] != '\0'; ++i)
{
if (&(str[i]) == chr1)
{
fprintf(out, "%s", " THE");
i += 3;
chr1 = strstr(&(str[i]), " the ");
continue;
}
if (&(str[i]) == chr2)
{
fprintf(out, "%s", " ANY");
i += 1;
chr2 = strstr(&(str[i]), " a ");
continue;
}
fputc(str[i], out);
}
free(str);
str = calloc(4008, sizeof(char));
str[0] = ' ';
}
fclose(in);
fclose(out);
return 0;
}
|
the_stack_data/220456141.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
#include <pthread.h>
typedef struct {
int dim;
float *data;
} Vector;
void CreateVector(Vector *vec, int dim);
void DeleteVector(Vector *vec);
void DisplayVector(Vector *vec, char *mesg);
void FillVectorIncreasing(Vector *vec);
void FillVectorDecreasing(Vector *vec);
void VectorAdd(Vector *vec1, Vector *vec2, Vector *res);
int main(int argc, char *argv[])
{
if(argc < 3){
printf("Usage: %s <dim> <# of threads>\n", argv[0]);
return -1;
}
int dim = atoi(argv[1]);
int no_thread = atoi(argv[2]);
printf("Addtipying %d-dim vectors using %d threads\n", dim, no_thread);
Vector vecA = { 0 };
Vector vecB = { 0 };
Vector sum = { 0 };
CreateVector(&vecA, dim);
FillVectorIncreasing(&vecA);
if(dim < 20)
DisplayVector(&vecA, "A = ");
CreateVector(&vecB, dim);
FillVectorDecreasing(&vecB);
if(dim < 20)
DisplayVector(&vecB, "B = ");
CreateVector(&sum, dim);
struct timeval start_time, end_time;
gettimeofday(&start_time, NULL);
VectorAdd(&vecA, &vecB, &sum);
gettimeofday(&end_time, NULL);
end_time.tv_sec -= start_time.tv_sec;
end_time.tv_usec -= start_time.tv_usec;
if(end_time.tv_usec < 0){ // handle carry --> seconds
end_time.tv_sec--;
end_time.tv_usec += 1000000;
}
if(dim < 20)
DisplayVector(&sum, "A + B = ");
printf("computing time = %ld sec %ld microsec\n", end_time.tv_sec, end_time.tv_usec);
DeleteVector(&vecA);
DeleteVector(&vecB);
DeleteVector(&sum);
return 0;
}
void CreateVector(Vector *vec, int dim)
{
if(vec->data)
free(vec->data);
vec->data = malloc(dim * sizeof(float));
if(vec->data == NULL){
printf("Failed to allocate memory in %s.\n", __FUNCTION__);
vec->dim = 0;
return;
}
memset(vec->data, 0, dim * sizeof(float));
vec->dim = dim;
}
void DeleteVector(Vector *vec)
{
if(vec){
free(vec->data);
vec->dim = 0;
}
}
void DisplayVector(Vector *vec, char *mesg)
{
if(mesg != NULL)
printf("%s\n", mesg);
printf("%d-dim vector:\n", vec->dim);
for(int i = 0; i < vec->dim; i++)
printf("%5.1f ", vec->data[i]);
printf("\n");
}
void FillVectorIncreasing(Vector *vec)
{
for(int i = 0; i < vec->dim; i++)
vec->data[i] = i + 1;
}
void FillVectorDecreasing(Vector *vec)
{
for(int i = 0; i < vec->dim; i++)
vec->data[i] = vec->dim - i;
}
void VectorAdd(Vector *vec1, Vector *vec2, Vector *res)
{
for(int i = 0; i < vec1->dim; i++)
res->data[i] = vec1->data[i] + vec2->data[i];
}
|
the_stack_data/62637193.c | /*
* Copyright (c) 1996 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/*
* Portions copyright (c) 1999, 2000
* 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:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
*
* This product includes software developed by Intel Corporation and
* its contributors.
*
* 4. Neither the name of Intel Corporation or its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION 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 INTEL CORPORATION 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.
*
*/
#ifndef lint
static char rcsid[] = "$Id: ns_ttl.c $";
#endif
/* Import. */
#include <arpa/nameser.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#define SPRINTF(x) ((size_t)sprintf x)
/* Forward. */
static int fmt1(int t, char s, char **buf, size_t *buflen);
/* Macros. */
#define T(x) if ((x) < 0) return (-1); else (void)NULL
/* Public. */
int
ns_format_ttl(u_long src, char *dst, size_t dstlen) {
char *odst = dst;
int secs, mins, hours, days, weeks, x;
char *p;
secs = (int)(src % 60); src /= 60;
mins = (int)(src % 60); src /= 60;
hours = (int)(src % 24); src /= 24;
days = (int)(src % 7); src /= 7;
weeks = (int)src; src = 0;
x = 0;
if (weeks) {
T(fmt1(weeks, 'W', &dst, &dstlen));
x++;
}
if (days) {
T(fmt1(days, 'D', &dst, &dstlen));
x++;
}
if (hours) {
T(fmt1(hours, 'H', &dst, &dstlen));
x++;
}
if (mins) {
T(fmt1(mins, 'M', &dst, &dstlen));
x++;
}
if (secs || !(weeks || days || hours || mins)) {
T(fmt1(secs, 'S', &dst, &dstlen));
x++;
}
if (x > 1) {
int ch;
for (p = odst; (ch = *p) != '\0'; p++)
if (isascii(ch) && isupper(ch))
*p = (char)( tolower(ch));
}
return ((int)(dst - odst));
}
int
ns_parse_ttl(const char *src, u_long *dst) {
u_long ttl, tmp;
int ch, digits, dirty;
ttl = 0;
tmp = 0;
digits = 0;
dirty = 0;
while ((ch = *src++) != '\0') {
if (!isascii(ch) || !isprint(ch))
goto einval;
if (isdigit(ch)) {
tmp *= 10;
tmp += (ch - '0');
digits++;
continue;
}
if (digits == 0)
goto einval;
if (islower(ch))
ch = toupper(ch);
switch (ch) {
case 'W': tmp *= 7;
case 'D': tmp *= 24;
case 'H': tmp *= 60;
case 'M': tmp *= 60;
case 'S': break;
default: goto einval;
}
ttl += tmp;
tmp = 0;
digits = 0;
dirty = 1;
}
if (digits > 0) {
if (dirty)
goto einval;
else
ttl += tmp;
}
*dst = ttl;
return (0);
einval:
errno = EINVAL;
return (-1);
}
/* Private. */
static int
fmt1(int t, char s, char **buf, size_t *buflen) {
char tmp[50];
size_t len;
len = SPRINTF((tmp, "%d%c", t, s));
if (len + 1 > *buflen)
return (-1);
strcpy(*buf, tmp);
*buf += len;
*buflen -= len;
return (0);
}
|
the_stack_data/657452.c | /*
* Exercise 5-19. Modify undcl so that it does not add redundant parentheses to declarations.
* undcl: convert word description to declaration
*
* e.g.
* x * int -> int *x
* argv * * char -> char **argv
* daytab * [] int -> int (*daytab)[]
* daytab [] * int -> int *daytab[]
* comp () * void -> void *comp()
* comp * () void -> void (*comp)()
* x () * [] * () char -> char (*(*x())[])()
* x [] * () * [] char -> char (*(*x[])())[]
*/
#include <stdio.h>
#include <string.h>
#define MAXTOKEN 100
enum { NAME, PARENS, BRACKETS };
int gettoken(void);
int tokentype; // type of last token
char token[MAXTOKEN]; // last token string
char out[1000]; // output string
// gcc 44.undcl.c getch.c
// cat 44.undcl.test | ./a.out
main()
{
int type;
char temp[MAXTOKEN];
while (gettoken() != EOF) {
strcpy(out, token);
while ((type = gettoken()) != '\n') {
if (type == PARENS) {
if (out[0] == '*') {
sprintf(temp, "(%s)", out);
strcpy(out, temp);
}
strcat(out, token);
} else if (type == BRACKETS) {
if (out[0] == '*' || strstr(out, "()") != NULL) {
sprintf(temp, "(%s)", out);
strcpy(out, temp);
}
strcat(out, token);
} else if (type == '*') {
sprintf(temp, "*%s", out);
strcpy(out, temp);
} else if (type == NAME) {
sprintf(temp, "%s %s", token, out);
strcpy(out, temp);
} else
printf("invalid input at %s\n", token);
}
printf("%s\n", out);
}
return 0;
}
int gettoken(void)
{
int c, getch(void);
void ungetch(int);
char *p = token;
while ((c = getch()) == ' ' || c == '\t')
;
if (c == '(') {
if ((c = getch()) == ')') {
strcpy(token, "()");
return tokentype = PARENS;
} else {
ungetch(c);
return tokentype = '(';
}
} else if (c == '[') {
for (*p++ = c; (*p++ = getch()) != ']'; )
;
*p = '\0';
return tokentype = BRACKETS;
} else if (isalpha(c)) {
for (*p++ = c; isalnum(c = getch()); )
*p++ = c;
*p = '\0';
ungetch(c);
return tokentype = NAME;
} else {
return tokentype = c;
}
}
|
the_stack_data/96760.c | // PROGRAMA p1.c
#include <unistd.h>
#include <stdio.h>
int global=1;
int main(void) {
int local = 2;
if(fork() > 0) {
printf("PID = %d; PPID = %d\n", getpid(), getppid());
global++;
local--;
} else {
printf("PID = %d; PPID = %d\n", getpid(), getppid());
global--;
local++;
}
printf("PID = %d - global = %d ; local = %d\n", getpid(), global, local);
return 0;
}
|
the_stack_data/53833.c | /* { dg-do compile } */
/* { dg-options "-O" } */
int foo(int i)
{
return (1LL >> 128 * i) && i;
}
|
the_stack_data/87636614.c | /*
* NETtel IP-Redirection
*
* Redirects packets to an ip address - see README for full
* explanation
*/
//#include <stdio.h>
//#include <stdlib.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h> /* req by optarg */
#include <getopt.h>
#include <syslog.h>
#define DEBUG 1
#define OUT 0
#define VERSION "0.2.2"
#define FALSE 0
#define TRUE 1
#define CONFIG_FILE "/etc/config/config"
#define MAX_CONFIG_LINE_SIZE 128
/* prototypes */
int inSocket(long listen_addr,short listen_port, int protocol);
int outSocket (long send_from_addr, short send_from_port, long send_addr, short send_port, int protocol);
int outSocket2 (long send_from_addr, short send_from_port, int protocol);
int outSocket3 (int protocol);
int parseIp(char *ipstring, long *addr, short *port );
void usage();
int main(int argc, char *argv[]) {
char value[MAX_CONFIG_LINE_SIZE];
int socket_in;
int socket_out;
#if DEBUG
struct in_addr ina_tmp;
#endif
struct sockaddr_in sin_from;
int int_from;
int len = 255;
int out = FALSE;
int ourpacket = FALSE;
int rc,flag;
unsigned char msg[255];
//these will be set later by command line options or a config file
int protocol = IPPROTO_UDP;
long listen_addr = INADDR_ANY;
/*short listen_port = 1238;*/
short listen_port = 0xaa;
long send_addr = inet_addr("192.168.0.255");
short send_port = 55;
long send_from_addr = INADDR_ANY;
short send_from_port = 0;
long ignore_addr = INADDR_ANY;
short ignore_port = 0;
while ((rc = getopt(argc, argv, "vho?l:s:f:i:")) > 0) {
switch (rc) {
case 'v':
printf("NETtel IP-Redirection (v%s)\n", VERSION);
exit(0);
break;
case 'l':
parseIp(optarg, &listen_addr, &listen_port );
break;
case 's':
parseIp(optarg, &send_addr, &send_port );
break;
case 'f':
parseIp(optarg, &send_from_addr, &send_from_port );
break;
case 'i':
parseIp(optarg, &ignore_addr, &ignore_port );
break;
case 'o':
out = 1;
break;
case '?':
usage();
exit(0);
break;
case 'h':
usage();
exit(0);
break;
}
}
openlog("ipredirect", 0, 0);
syslog(LOG_INFO, "NETtel IP-Redirection (v%s) started", VERSION);
#if DEBUG
printf("NETtel IP-Redirection (v%s) started\n", VERSION);
#endif
socket_out = outSocket(send_from_addr,send_from_port,send_addr,send_port,protocol);
if (!out) {
socket_in = inSocket(listen_addr,listen_port,protocol);
}
while(1) { /* loop until your dizzy */
if (!out) {
printf("Waiting for packet...\n");
if ((len = recvfrom(socket_in,msg,sizeof(msg),0,(struct sockaddr*)&sin_from,&int_from)) == -1) {
syslog(LOG_ERR, "couldnt recv packet");
#if DEBUG
perror("couldnt recv packet\n");
#endif
}
#if DEBUG
printf("recieved\n");
ina_tmp.s_addr = sin_from.sin_addr.s_addr;
printf("packet from %s\n",inet_ntoa(ina_tmp));
#endif
}
if (ignore_addr != sin_from.sin_addr.s_addr) {
printf("Packet accepted!!!!\n");
//ina_tmp.s_addr = ignore_addr;
//printf("ignoring %s != ",inet_ntoa(ina_tmp));
//ina_tmp.s_addr = sin_from.sin_addr.s_addr;
//printf("packet from %s\n",inet_ntoa(ina_tmp));
#if DEBUG
printf("Sending..len = %d\n",len);
#endif
if (send(socket_out,msg,len,0) == -1) {
//syslog(LOG_ERR, "couldnt send packet");
#if DEBUG
perror("couldnt send packet");
#endif
}
#if DEBUG
printf("Sent\n");
#endif
#if DEBUG
}
else { //if we ignore it
printf("Packet ignored\n");
}
#endif
}
close(socket_out);
if (!out) {
close(socket_in);
}
closelog();
return 0;
}
int inSocket(long listen_addr,short listen_port, int protocol) {
int n = 1;
int socket_in;
struct sockaddr_in sin;
socket_in = socket(PF_INET, SOCK_DGRAM, protocol);
if(socket_in == -1) {
syslog(LOG_ERR, "server socket error");
#if DEBUG
printf("server socket error\n");
#endif
exit(0);
}
if (setsockopt(socket_in, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1) {
printf("couldnt set option\n");
}
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(listen_port);
sin.sin_addr.s_addr = listen_addr;
if(bind(socket_in, (struct sockaddr *)&sin, sizeof(struct sockaddr)) == -1) {
syslog(LOG_ERR, "sock_listen bind error");
#if DEBUG
perror("sock_listen bind error -");
#endif
exit(0);
}
return socket_in;
}
int outSocket (long send_from_addr, short send_from_port, long send_addr, short send_port, int protocol) {
int n = 2;
int send_socket;
struct sockaddr_in sin;
send_socket = socket(PF_INET, SOCK_DGRAM, protocol);
if(send_socket == -1) {
syslog(LOG_ERR, "send socket err");
#if DEBUG
printf("snd socket error\n");
#endif
exit(0);
}
if (setsockopt(send_socket, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1) {
syslog(LOG_ERR, "Couldnt set socket option");
#if DEBUG
printf("couldnt set option\n");
#endif
}
if (setsockopt(send_socket, SOL_SOCKET, SO_BROADCAST, (char *) &n, sizeof(n)) == -1) {
syslog(LOG_ERR, "Couldnt set socket option");
#if DEBUG
printf("couldnt set option\n");
#endif
}
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(send_from_port);
sin.sin_addr.s_addr = send_from_addr;
if(bind(send_socket,(struct sockaddr *)&sin, sizeof(struct sockaddr))==-1)
{
syslog(LOG_ERR, "send bind error");
#if DEBUG
perror("sock_send bind error -");
#endif
exit(0);
}
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(send_port);
sin.sin_addr.s_addr = send_addr; /*INADDR_BROADCAST*/
if(connect(send_socket, (struct sockaddr *)&sin, sizeof(struct sockaddr)) == -1) {
syslog(LOG_ERR, "send connect error");
#if DEBUG
perror("send connect error\n");
#endif
exit(0);
}
return send_socket;
}
int outSocket2 (long send_from_addr, short send_from_port, int protocol) {
int n = 2;
int send_socket;
struct sockaddr_in sin;
send_socket = socket(PF_INET, SOCK_DGRAM, protocol);
if(send_socket == -1) {
syslog(LOG_ERR, "send socket err");
#if DEBUG
printf("snd socket error\n");
#endif
exit(0);
}
if (setsockopt(send_socket, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1) {
syslog(LOG_ERR, "Couldnt set socket option");
#if DEBUG
printf("couldnt set option\n");
#endif
}
if (setsockopt(send_socket, SOL_SOCKET, SO_BROADCAST, (char *) &n, sizeof(n)) == -1) {
syslog(LOG_ERR, "Couldnt set socket option");
#if DEBUG
printf("couldnt set option\n");
#endif
}
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(send_from_port);
sin.sin_addr.s_addr = send_from_addr;
if(bind(send_socket,(struct sockaddr *)&sin, sizeof(struct sockaddr))==-1)
{
syslog(LOG_ERR, "send bind error");
#if DEBUG
perror("sock_send bind error -");
#endif
exit(0);
}
return send_socket;
}
/////////////////////////////////////////////////////
int outSocket3 (int protocol) {
int n = 2;
int send_socket;
struct sockaddr_in sin;
send_socket = socket(PF_INET, SOCK_DGRAM, protocol);
if(send_socket == -1) {
syslog(LOG_ERR, "send socket err");
#if DEBUG
printf("snd socket error\n");
#endif
exit(0);
}
if (setsockopt(send_socket, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1) {
syslog(LOG_ERR, "Couldnt set socket option");
#if DEBUG
printf("couldnt set option\n");
#endif
}
if (setsockopt(send_socket, SOL_SOCKET, SO_BROADCAST, (char *) &n, sizeof(n)) == -1) {
syslog(LOG_ERR, "Couldnt set socket option");
#if DEBUG
printf("couldnt set option\n");
#endif
}
return send_socket;
}
////////////////////////////////////////////////////
int parseIp(char *ipstring, long *addr, short *port ) {
int i = 0;
struct in_addr inaddr;
char *addrPtr;
*port = 0; //defaults
*addr = INADDR_ANY; //defaults
addrPtr = ipstring;
while ((ipstring[i] != '\0') && (ipstring[i] != ':')) {
i++;
}
/* Parse Port */
if (ipstring[i] = ':') { /* see if there is a port field */
ipstring[i] = '\0';
i++;
ipstring += i; /* change the ptr */
*port = atoi(ipstring);
}
/* Parse Address */
if (addrPtr[0] != '0') { /* see if they typed an address */
if (inet_aton(addrPtr,&inaddr) == 0) {
syslog(LOG_ERR, "Parse error - exiting");
#if DEBUG
printf("Parse error - exiting\n");
#endif
exit(-1);
}
*addr = inaddr.s_addr;
}
}
void usage() {
printf("ipredirect [-ovh] -l listen_addr -s send_addr [-f send_from_address]\n");
}
/*
* search_config_file
*
* This function opens up the file specified 'filename' and searches
* through the file for 'keyword'. If 'keyword' is found any string
* following it is stored in 'value'.. If 'value' is NULL we assume
* the function was called simply to determing if the keyword exists
* in the file.
*
* args: filename (IN) - config filename
* keyword (IN) - word to search for in config file
* value (OUT) - value of keyword (if value not NULL)
*
* retn: -1 on error,
* 0 if keyword not found,
* 1 if found
*/
|
the_stack_data/132448.c | /* Copyright (C) 2003-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <[email protected]>, 2003.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
extern int val;
static void
prepare (void)
{
++val;
}
static void
parent (void)
{
val *= 4;
}
static void
child (void)
{
val *= 8;
}
static void
__attribute__ ((constructor))
init (void)
{
extern void *__dso_handle;
printf ("dsohandle = %p\n", __dso_handle);
if (pthread_atfork (prepare, parent, child) != 0)
{
puts ("init: atfork failed");
exit (1);
}
}
|
the_stack_data/59512398.c | #include <stdio.h>
#include <math.h> // book wants us to use the fabs function
// Uses Newton's method to calculate the square roots.
int main(void)
{
double x, tmp, y, avg;
printf("Enter a positive number: ");
scanf("%lf", &x);
for (y = 1; (fabs(tmp - y)) >= (0.0001 * y);)
{
tmp = y; // Using tmp to store the good ol y.
avg = ((x / y) + y) / 2.0;
y = avg;
printf("y after is %lf\n", y);
}
return 0;
}
|
the_stack_data/64201212.c | #include<stdio.h>
int main()
{
int a,b,c,t,sum=0;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&a,&b,&c);
if(c<41)
{
sum = a*b*c;
printf("%d\n",sum);
sum =0;
}
}
return 0;
}
|
the_stack_data/132952371.c | // Portable, standalone implementation of moreutils-style sponge
// This is free and unencumbered software released into the public domain.
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static char *
slurp(FILE *f, size_t *len)
{
char *buf = 0;
size_t cap = 1 << 11;
for (*len = 0;;) {
cap *= 2;
if (!cap) {
free(buf);
return 0;
}
void *tmp = realloc(buf, cap);
if (!tmp) {
free(buf);
return 0;
}
buf = tmp;
size_t in = fread(buf+*len, 1, cap-*len, f);
*len += in;
if (in < cap-*len) {
if (feof(f)) {
return buf;
}
free(buf);
return 0;
}
}
}
static int xoptind = 1;
static int xopterr = 1;
static int xoptopt;
static char *xoptarg;
static int
xgetopt(int argc, char * const argv[], const char *optstring)
{
static int optpos = 1;
const char *arg;
(void)argc;
arg = argv[xoptind];
if (arg && strcmp(arg, "--") == 0) {
xoptind++;
return -1;
} else if (!arg || arg[0] != '-' || !isalnum(arg[1])) {
return -1;
} else {
const char *opt = strchr(optstring, arg[optpos]);
xoptopt = arg[optpos];
if (!opt) {
if (xopterr && *optstring != ':')
fprintf(stderr, "%s: illegal option: %c\n", argv[0], xoptopt);
return '?';
} else if (opt[1] == ':') {
if (arg[optpos + 1]) {
xoptarg = (char *)arg + optpos + 1;
xoptind++;
optpos = 1;
return xoptopt;
} else if (argv[xoptind + 1]) {
xoptarg = (char *)argv[xoptind + 1];
xoptind += 2;
optpos = 1;
return xoptopt;
} else {
if (xopterr && *optstring != ':')
fprintf(stderr,
"%s: option requires an argument: %c\n",
argv[0], xoptopt);
return *optstring == ':' ? ':' : '?';
}
} else {
if (!arg[++optpos]) {
xoptind++;
optpos = 1;
}
return xoptopt;
}
}
}
static void
usage(FILE *f)
{
fprintf(f, "usage: sponge [-ah] FILE\n");
}
int
main(int argc, char **argv)
{
int option;
const char *mode = "wb";
while ((option = xgetopt(argc, argv, "ah")) != -1) {
switch (option) {
case 'a': mode = "ab"; break;
case 'h': usage(stdout); return 0;
default : usage(stderr); return 1;
}
}
if (!argv[xoptind] || argv[xoptind+1]) {
usage(stderr);
return 1;
}
#ifdef _WIN32
int _setmode(int, int); // set stdin to binary mode
_setmode(0, 0x8000);
#endif
size_t len;
char *buf = slurp(stdin, &len);
if (!buf) {
if (ferror(stdin)) {
fprintf(stderr, "sponge: read error\n");
return 1;
}
fprintf(stderr, "sponge: out of memory\n");
return 1;
}
char *path = argv[xoptind];
FILE *f = fopen(path, mode);
if (!f) {
fprintf(stderr, "sponge: failed to open file: %s\n", path);
free(buf);
return 1;
}
if (len && (!fwrite(buf, len, 1, f) || fflush(f))) {
fprintf(stderr, "sponge: write error: %s\n", path);
free(buf);
fclose(f);
return 1;
}
free(buf);
fclose(f);
return 0;
}
|
the_stack_data/114086.c | #include<stdio.h>
#include<string.h>
int na(int,int);
int ma(int,int);
int ha(int,int);
int a[105];
int min(int,int);
int max(int,int);
int n,m;
int main()
{
int l,r;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&l,&r);
printf("%d\n",ha( min(na(l,r),ma(l,r)) , max(na(l,r),ma(l,r))));
}
}
int na(int l,int r)
{
int ans=0;
for(int i=l;i<=r;i++)
ans+=a[i]%n;
ans%=n;
return ans;
}
int ma(int l,int r)
{
int ans=1;
for(int i=l;i<=r;i++)
{
ans*=a[i]%n;
ans%=n;
}
return ans;
}
int ha(int l,int r)
{
int ans=a[l];
for(int i=l+1;i<=r;i++)
ans^=a[i];
return ans;
}
int min(int a,int b)
{
if(a>b)return b;
else return a;
}
int max(int a,int b)
{
if(a>b)return a;
return b;
} |
the_stack_data/373592.c | //
// CountOccurances.c
//
//
// Created by Raj Aggrawal on 9/21/19.
//
/*
Write a function that counts the number of times a given int occurs in a Linked List
*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
struct Node{
int data;
struct Node *next;
} typedef Node;
void printList (Node * head){
Node *temp = head;
printf("Items in list is ");
while (temp != NULL){
printf ("%d ", temp->data);
temp = temp->next;
}
}
Node *createLinkedList (int numberOfNodes){
Node *head = NULL;
Node *currentNode = NULL;
for (int i = 0; i < numberOfNodes; i++){
Node *temp = (Node *) malloc (sizeof (Node));
temp->data = i;
if (head == NULL){
head = temp;
currentNode = temp;
}
else{
currentNode->next = temp;
currentNode = temp;
}
}
return head;
}
//Return the nth element in linked list
int countOccurance(int item, Node *head){
Node *temp = head;
int count = 0;
while(temp->next != NULL){
if (temp->data == item){
count++;
}
temp = temp->next;
}
return count;
}
int main (){
Node *head = createLinkedList (11);
printList(head);
printf("\ncount the occurance of element = %d", countOccurance(15, head));
}
|
the_stack_data/156393839.c | //
// main.c
// MaratonIME returns home
//
// Created by MacBook on 19/03/17.
// Copyright © 2017 Bruno Botelho. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char * argv[]) {
// insert code here...
int r,c;
scanf("%d %d",&r,&c);
char linha[r][c];
for(int i=0;i<r;i++){
gets(linha[i]);
}
int maior_soma=0;
int temp_soma=0;
for(int i=0;i<r;i++){
int c=0;
if(i%2==0){
c=0;
char atual =linha[i][c++];
if(atual=='_');
else if(atual=='.')temp_soma++;
else if(atual=='L'){
if(maior_soma<temp_soma){
maior_soma=temp_soma;
}
temp_soma=0;
}
}
else{
}
}
return 0;
}
|
the_stack_data/59513010.c | #include <stdarg.h>
#include <stdio.h>
int ext1;
int *ext2;
int ext3 = 5;
int char_fn() { return 257; }
int static_fn() { return 5; }
int false_fn() { return 512; }
int true_fn() { return 513; }
int add_all1(int x, ...) {
va_list ap;
va_start(ap, x);
for (;;) {
int y = va_arg(ap, int);
if (y == 0)
return x;
x += y;
}
}
int add_all3(int x, int y, int z, ...) {
va_list ap;
va_start(ap, z);
x = x + y + z;
for (;;) {
int y = va_arg(ap, int);
if (y == 0)
return x;
x += y;
}
}
float ret_float(float x) {
return x;
}
float add_float(float x, float y) {
return x + y;
}
double add_double(double x, double y) {
return x + y;
}
int add10_int(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10) {
return x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10;
}
int add10_double(double x1, double x2, double x3, double x4, double x5, double x6, double x7, double x8, double x9, double x10) {
return x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10;
}
|
the_stack_data/178265118.c | /* Copyright (c) 2016, Matthew Morris
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "stdio.h"
#include "string.h"
int main(void) {
int num;
for (num = 1; num <= 100; num++) {
char text[16] = "";
if (num % 3 == 0) {
strcat(text, "fizz");
}
if (num % 5 == 0) {
strcat(text, "buzz");
}
text[0] != '\0'
? printf("%s\n", text)
: printf("%d\n", num);
}
return 0;
}
|
the_stack_data/623187.c | #include <stdio.h>
#define OUT 0
#define IN 1
int main() {
int c, status;
status = OUT;
while((c = getchar()) != EOF) {
if (c == '\n' || c == '\t' || c == ' ') {
if (status == IN) {
putchar('\n');
}
status = OUT;
}
else {
status = IN;
putchar(c);
}
}
printf("success");
} |
the_stack_data/178264290.c | #include <stdio.h>
int ft_str_is_uppercase(char *str)
{
while (*str != '\0')
{
if ((*str < 'A' || *str > 'Z'))
return ('0');
str++;
}
return ('1');
}
int main(void)
{
char write;
write = ft_str_is_printable("aB");
printf("%c", write);
}
|
the_stack_data/48574087.c | #include <stdio.h>
int main(int argc, char* argv[]){
int lines, limit;
int count = 0;
printf("Input the number of lines: \n");
scanf("%d", &lines);
printf("Input the number of elements per line: \n");
scanf("%d", &limit);
for(int i = 0; i < lines; i++){
for(int j= 1; j <= limit; j++){
count++;
printf("%d ", count);
}
printf("\n");
}
return 0;
} |
the_stack_data/90764384.c | // Test strict_string_checks option in strtol function
// RUN: %clang_asan -D_CRT_SECURE_NO_WARNINGS -DTEST1 %s -o %t
// RUN: %run %t test1 2>&1
// RUN: %env_asan_opts=strict_string_checks=false %run %t test1 2>&1
// RUN: %env_asan_opts=strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1
// RUN: %run %t test2 2>&1
// RUN: %env_asan_opts=strict_string_checks=false %run %t test2 2>&1
// RUN: %env_asan_opts=strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2
// RUN: %run %t test3 2>&1
// RUN: %env_asan_opts=strict_string_checks=false %run %t test3 2>&1
// RUN: %env_asan_opts=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
// RUN: %run %t test4 2>&1
// RUN: %env_asan_opts=strict_string_checks=false %run %t test4 2>&1
// RUN: %env_asan_opts=strict_string_checks=true not %run %t test4 2>&1 | FileCheck %s --check-prefix=CHECK4
// RUN: %run %t test5 2>&1
// RUN: %env_asan_opts=strict_string_checks=false %run %t test5 2>&1
// RUN: %env_asan_opts=strict_string_checks=true not %run %t test5 2>&1 | FileCheck %s --check-prefix=CHECK5
// RUN: %run %t test6 2>&1
// RUN: %env_asan_opts=strict_string_checks=false %run %t test6 2>&1
// RUN: %env_asan_opts=strict_string_checks=true not %run %t test6 2>&1 | FileCheck %s --check-prefix=CHECK6
// RUN: %run %t test7 2>&1
// RUN: %env_asan_opts=strict_string_checks=false %run %t test7 2>&1
// RUN: %env_asan_opts=strict_string_checks=true not %run %t test7 2>&1 | FileCheck %s --check-prefix=CHECK7
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sanitizer/asan_interface.h>
void test1(char *array, char *endptr) {
// Buffer overflow if there is no terminating null (depends on base)
long r = strtol(array, &endptr, 3);
assert(array + 2 == endptr);
assert(r == 5);
}
void test2(char *array, char *endptr) {
// Buffer overflow if there is no terminating null (depends on base)
array[2] = 'z';
long r = strtol(array, &endptr, 35);
assert(array + 2 == endptr);
assert(r == 37);
}
void test3(char *array, char *endptr) {
#ifdef _MSC_VER
// Using -1 for a strtol base causes MSVC to abort. Print the expected lines
// to make the test pass.
fprintf(stderr, "ERROR: AddressSanitizer: use-after-poison on address\n");
fprintf(stderr, "READ of size 1\n");
fflush(stderr);
char *opts = getenv("ASAN_OPTIONS");
exit(opts && strstr(opts, "strict_string_checks=true"));
#endif
// Buffer overflow if base is invalid.
memset(array, 0, 8);
ASAN_POISON_MEMORY_REGION(array, 8);
long r = strtol(array + 1, NULL, -1);
assert(r == 0);
ASAN_UNPOISON_MEMORY_REGION(array, 8);
}
void test4(char *array, char *endptr) {
#ifdef _MSC_VER
// Using -1 for a strtol base causes MSVC to abort. Print the expected lines
// to make the test pass.
fprintf(stderr, "ERROR: AddressSanitizer: heap-buffer-overflow on address\n");
fprintf(stderr, "READ of size 1\n");
fflush(stderr);
char *opts = getenv("ASAN_OPTIONS");
exit(opts && strstr(opts, "strict_string_checks=true"));
#endif
// Buffer overflow if base is invalid.
long r = strtol(array + 3, NULL, 1);
assert(r == 0);
}
void test5(char *array, char *endptr) {
// Overflow if no digits are found.
array[0] = ' ';
array[1] = '+';
array[2] = '-';
long r = strtol(array, NULL, 0);
assert(r == 0);
}
void test6(char *array, char *endptr) {
// Overflow if no digits are found.
array[0] = ' ';
array[1] = array[2] = 'z';
long r = strtol(array, &endptr, 0);
assert(array == endptr);
assert(r == 0);
}
void test7(char *array, char *endptr) {
// Overflow if no digits are found.
array[2] = 'z';
long r = strtol(array + 2, NULL, 0);
assert(r == 0);
}
int main(int argc, char **argv) {
char *array0 = (char*)malloc(11);
char* array = array0 + 8;
char *endptr = NULL;
array[0] = '1';
array[1] = '2';
array[2] = '3';
if (argc != 2) return 1;
if (!strcmp(argv[1], "test1")) test1(array, endptr);
// CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
// CHECK1: READ of size 4
if (!strcmp(argv[1], "test2")) test2(array, endptr);
// CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
// CHECK2: READ of size 4
if (!strcmp(argv[1], "test3")) test3(array0, endptr);
// CHECK3: {{.*ERROR: AddressSanitizer: use-after-poison on address}}
// CHECK3: READ of size 1
if (!strcmp(argv[1], "test4")) test4(array, endptr);
// CHECK4: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
// CHECK4: READ of size 1
if (!strcmp(argv[1], "test5")) test5(array, endptr);
// CHECK5: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
// CHECK5: READ of size 4
if (!strcmp(argv[1], "test6")) test6(array, endptr);
// CHECK6: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
// CHECK6: READ of size 4
if (!strcmp(argv[1], "test7")) test7(array, endptr);
// CHECK7: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
// CHECK7: READ of size 2
free(array0);
return 0;
}
|
the_stack_data/404981.c | #include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main( int argc, char *argv[] )
{
setreuid(0,0);
execve("/bin/sh", NULL, NULL);
}
|
the_stack_data/162644512.c |
int glui_img_radiobutton_0[] = { 14, 14, /* width, height */
192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
192,192,192, 192,192,192, 192,192,192, 192,192,192, 255,255,255,
255,255,255, 255,255,255, 255,255,255, 192,192,192, 192,192,192,
192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
192,192,192, 255,255,255, 255,255,255, 192,192,192, 192,192,192,
192,192,192, 192,192,192, 255,255,255, 255,255,255, 192,192,192,
192,192,192, 192,192,192, 192,192,192, 192,192,192, 128,128,128,
192,192,192, 192,192,192, 255,255,255, 255,255,255, 255,255,255,
255,255,255, 192,192,192, 192,192,192, 255,255,255, 192,192,192,
192,192,192, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
255,255,255, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
192,192,192, 128,128,128, 0, 0, 0, 255,255,255, 255,255,255,
255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
255,255,255, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
128,128,128, 0, 0, 0, 255,255,255, 255,255,255, 255,255,255,
255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
192,192,192, 255,255,255, 192,192,192, 192,192,192, 128,128,128,
0, 0, 0, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
255,255,255, 255,255,255, 255,255,255, 255,255,255, 192,192,192,
255,255,255, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
255,255,255, 255,255,255, 255,255,255, 192,192,192, 255,255,255,
192,192,192, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
255,255,255, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
192,192,192, 192,192,192, 128,128,128, 0, 0, 0, 0, 0, 0,
255,255,255, 255,255,255, 255,255,255, 255,255,255, 0, 0, 0,
0, 0, 0, 255,255,255, 192,192,192, 192,192,192, 192,192,192,
192,192,192, 192,192,192, 128,128,128, 128,128,128, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 128,128,128, 128,128,128,
192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
192,192,192, 192,192,192, 192,192,192, 128,128,128, 128,128,128,
128,128,128, 128,128,128, 192,192,192, 192,192,192, 192,192,192,
192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
192,192,192,
};
|
the_stack_data/105254.c | /*
* Copyright 2016 The Emscripten Authors. All rights reserved.
* Emscripten is available under two separate licenses, the MIT license and the
* University of Illinois/NCSA Open Source License. Both these licenses can be
* found in the LICENSE file.
*/
#include <setjmp.h>
#include <stdio.h>
typedef struct {
jmp_buf* jmp;
} jmp_state;
void second_func(jmp_state* s);
void first_func(jmp_state* s) {
jmp_buf* prev_jmp = s->jmp;
jmp_buf c_jmp;
volatile int once = 0;
if (setjmp(c_jmp) == 0) {
printf("Normal execution path of first function!\n");
s->jmp = &c_jmp;
second_func(s);
} else {
printf("Exception execution path of first function! %d\n", once);
if (!once) {
printf("Calling longjmp the second time!\n");
once = 1;
longjmp(*(s->jmp), 1);
}
}
}
void second_func(jmp_state* s) { longjmp(*(s->jmp), 1); }
int main(int argc, char* argv[]) {
jmp_state s;
s.jmp = NULL;
first_func(&s);
return 0;
}
|
the_stack_data/122512.c | // RUN: %clam -m32 --crab-inter --crab-track=sing-mem --crab-dom=int --crab-check=assert --crab-sanity-checks --lower-unsigned-icmp "%s" 2>&1 | OutputCheck %s
// RUN: %clam -m64 --crab-inter --crab-track=sing-mem --crab-dom=int --crab-check=assert --crab-sanity-checks --lower-unsigned-icmp "%s" 2>&1 | OutputCheck %s
// CHECK: ^2 Number of total safe checks$
// CHECK: ^0 Number of total warning checks$
//#include <stdio.h>
extern int int_nd(void);
extern void __CRAB_assert(int);
extern void __CRAB_assume(int);
typedef struct __attribute__((packed)) {
char *name;
int id;
} S1;
S1 devices[4] = { {"name1", 0}, {"name2", 1}, {"name3", 2}, {"name4", 4} };
extern void avoid_opt(S1 *);
int main(){
avoid_opt(&devices[0]);
for (unsigned i=0; i<4; ++i) {
printf("id=%d\n", devices[i].id);
}
int x = int_nd();
__CRAB_assume(x >= 0);
__CRAB_assume(x < 4);
__CRAB_assert(devices[x].id >= 0);
__CRAB_assert(devices[x].id <= 4);
return 0;
}
|
the_stack_data/43969.c | /* Variable definition */
int var_non_init;
char var_c = 'k';
char var_a, Var_b = 100;
static unsigned int var_s_uint = 555;
char var_c;
unsigned char var_uc;
signed char var_sc;
short var_s;
unsigned short var_us;
signed short var_ss;
int var_i;
unsigned int var_ui;
signed int var_si;
long var_l;
unsigned long var_ul;
signed long var_sl;
long long var_ll;
unsigned long long var_ull;
signed long long var_sll;
float var_f;
double var_d;
signed long long var_sll;
char *var_p;
char **var_pp;
char ***var_ppp;
static int var_sti;
const int var_consi;
volatile int var_voli;
/* Struct */
struct St_tag {
int menber_i;
char menber_c;
};
struct St_tag str_var;
typedef struct St_tag St;
St str_var2;
/* Expression Initializer */
int var_exp = 100;
int var_exp2 = 1 + 1;
int var_exp3 = ((1 + 2) + (3 - 4)) * ((5 + 6) - (7 - 8));
/* Function definition */
void func(void) {}
int add(int a, int b) {
int result;
result = a + b;
return result;
}
#define TRUE (1)
#define FALSE (0)
unsigned int func_if(int arg) {
int res = FALSE;
if (arg == 0) {
res = 0;
} else if (arg > 0) {
res = 1;
} else {
res = 2;
}
return res;
}
int func_switch(int arg) {
switch (arg) {
case 0:
break;
default:
break;
}
return 0;
}
|
the_stack_data/1073278.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_toupper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: knfonda <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/28 09:22:00 by knfonda #+# #+# */
/* Updated: 2020/10/29 17:52:15 by knfonda ### ########.fr */
/* */
/* ************************************************************************** */
int ft_toupper(int ch)
{
if (ch >= 'a' && ch <= 'z')
return (ch - 32);
return (ch);
}
|
the_stack_data/57949941.c | typedef int size_t;
extern struct _iobuf {
int _cnt;
unsigned char *_ptr;
unsigned char *_base;
int _bufsiz;
short _flag;
char _file; } _iob[];
typedef struct _iobuf FILE;
extern struct _iobuf *fopen(const char *, const char *);
extern struct _iobuf *fdopen(int, const char *);
extern struct _iobuf *freopen(const char *, const char *, FILE *);
extern struct _iobuf *popen(const char *, const char *);
extern struct _iobuf *tmpfile(void);
extern long ftell(FILE *);
extern char *fgets(char *, int, FILE *);
extern char *gets(char *);
extern char *sprintf(char *, const char *, ...);
extern char *ctermid(char *);
extern char *cuserid(char *);
extern char *tempnam(const char *, const char *);
extern char *tmpnam(char *);
typedef struct sm_element_struct sm_element;
typedef struct sm_row_struct sm_row;
typedef struct sm_col_struct sm_col;
typedef struct sm_matrix_struct sm_matrix;
struct sm_element_struct {
int row_num; int col_num; sm_element *next_row; sm_element *prev_row; sm_element *next_col; sm_element *prev_col; char *user_word; };
struct sm_row_struct {
int row_num; int length; int flag; sm_element *first_col; sm_element *last_col; sm_row *next_row; sm_row *prev_row; char *user_word; };
struct sm_col_struct {
int col_num; int length; int flag; sm_element *first_row; sm_element *last_row; sm_col *next_col; sm_col *prev_col; char *user_word; };
struct sm_matrix_struct {
sm_row **rows; int rows_size; sm_col **cols; int cols_size; sm_row *first_row; sm_row *last_row; int nrows; sm_col *first_col; sm_col *last_col; int ncols; char *user_word; };
extern sm_matrix *sm_alloc(), *sm_alloc_size(), *sm_dup();
extern void sm_free(), sm_delrow(), sm_delcol(), sm_resize();
extern void sm_write(), sm_print(), sm_dump(), sm_cleanup();
extern void sm_copy_row(), sm_copy_col();
extern void sm_remove(), sm_remove_element();
extern sm_element *sm_insert(), *sm_find();
extern sm_row *sm_longest_row();
extern sm_col *sm_longest_col();
extern int sm_read(), sm_read_compressed();
extern sm_row *sm_row_alloc(), *sm_row_dup(), *sm_row_and();
extern void sm_row_free(), sm_row_remove(), sm_row_print();
extern sm_element *sm_row_insert(), *sm_row_find();
extern int sm_row_contains(), sm_row_intersects();
extern int sm_row_compare(), sm_row_hash();
extern sm_col *sm_col_alloc(), *sm_col_dup(), *sm_col_and();
extern void sm_col_free(), sm_col_remove(), sm_col_print();
extern sm_element *sm_col_insert(), *sm_col_find();
extern int sm_col_contains(), sm_col_intersects();
extern int sm_col_compare(), sm_col_hash();
extern int sm_row_dominance(), sm_col_dominance(), sm_block_partition();
extern sm_row *sm_minimum_cover();
extern char _ctype_[];
extern struct _iobuf *popen(const char *, const char *), *tmpfile(void);
extern int pclose(FILE *);
extern void rewind(FILE *);
extern void abort(void), free(void *), exit(int), perror(const char *);
extern char *getenv(const char *), *malloc(size_t), *realloc(void *, size_t);
extern int system(const char *);
extern double atof(const char *);
extern char *strcpy(char *, const char *), *strncpy(char *, const char *, size_t), *strcat(char *, const char *), *strncat(char *, const char *, size_t), *strerror(int);
extern char *strpbrk(const char *, const char *), *strtok(char *, const char *), *strchr(const char *, int), *strrchr(const char *, int), *strstr(const char *, const char *);
extern int strcoll(const char *, const char *), strxfrm(char *, const char *, size_t), strncmp(const char *, const char *, size_t), strlen(const char *), strspn(const char *, const char *), strcspn(const char *, const char *);
extern char *memmove(void *, const void *, size_t), *memccpy(void *, const void *, int, size_t), *memchr(const void *, int, size_t), *memcpy(void *, const void *, size_t), *memset(void *, int, size_t);
extern int memcmp(const void *, const void *, size_t), strcmp(const char *, const char *);
extern long util_cpu_time();
extern int util_getopt();
extern void util_getopt_reset();
extern char *util_path_search();
extern char *util_file_search();
extern int util_pipefork();
extern void util_print_cpu_stats();
extern char *util_print_time();
extern int util_save_image();
extern char *util_strsav();
extern char *util_tilde_expand();
extern void util_restart();
extern int util_optind;
extern char *util_optarg;
typedef unsigned int *pset;
typedef struct set_family {
int wsize; int sf_size; int capacity; int count; int active_count; pset data; struct set_family *next; } set_family_t, *pset_family;
extern int bit_count[256];
typedef struct cost_struct {
int cubes; int in; int out; int mv; int total; int primes; } cost_t, *pcost;
typedef struct pair_struct {
int cnt;
int *var1;
int *var2;
} pair_t, *ppair;
typedef struct symbolic_list_struct {
int variable;
int pos;
struct symbolic_list_struct *next;
} symbolic_list_t;
typedef struct symbolic_label_struct {
char *label;
struct symbolic_label_struct *next;
} symbolic_label_t;
typedef struct symbolic_struct {
symbolic_list_t *symbolic_list; int symbolic_list_length; symbolic_label_t *symbolic_label; int symbolic_label_length; struct symbolic_struct *next;
} symbolic_t;
typedef struct {
pset_family F, D, R; char *filename; int pla_type; pset phase; ppair pair; char **label; symbolic_t *symbolic; symbolic_t *symbolic_output;
} PLA_t, *pPLA;
extern unsigned int debug; extern int verbose_debug; extern char *total_name[16]; extern long total_time[16]; extern int total_calls[16]; extern int echo_comments; extern int echo_unknown_commands; extern int force_irredundant; extern int skip_make_sparse;
extern int kiss; extern int pos; extern int print_solution; extern int recompute_onset; extern int remove_essential; extern int single_expand; extern int summary; extern int trace; extern int unwrap_onset; extern int use_random_order; extern int use_super_gasp; extern char *filename; extern int debug_exact_minimization; struct pla_types_struct {
char *key;
int value;
};
struct cube_struct {
int size; int num_vars; int num_binary_vars; int *first_part; int *last_part; int *part_size; int *first_word; int *last_word; pset binary_mask; pset mv_mask; pset *var_mask; pset *temp; pset fullset; pset emptyset; unsigned int inmask; int inword; int *sparse; int num_mv_vars; int output; };
struct cdata_struct {
int *part_zeros; int *var_zeros; int *parts_active; int *is_unate; int vars_active; int vars_unate; int best; };
extern struct pla_types_struct pla_types[];
extern struct cube_struct cube, temp_cube_save;
extern struct cdata_struct cdata, temp_cdata_save;
extern int binate_split_select();
extern pset_family cubeunlist();
extern pset *cofactor();
extern pset *cube1list();
extern pset *cube2list();
extern pset *cube3list();
extern pset *scofactor();
extern void massive_count();
extern pset_family complement();
extern pset_family simplify();
extern void simp_comp();
extern int d1_rm_equal();
extern int rm2_contain();
extern int rm2_equal();
extern int rm_contain();
extern int rm_equal();
extern int rm_rev_contain();
extern pset *sf_list();
extern pset *sf_sort();
extern pset_family d1merge();
extern pset_family dist_merge();
extern pset_family sf_contain();
extern pset_family sf_dupl();
extern pset_family sf_ind_contain();
extern pset_family sf_ind_unlist();
extern pset_family sf_merge();
extern pset_family sf_rev_contain();
extern pset_family sf_union();
extern pset_family sf_unlist();
extern void cube_setup();
extern void restore_cube_struct();
extern void save_cube_struct();
extern void setdown_cube();
extern PLA_labels();
extern char *get_word();
extern int label_index();
extern int read_pla();
extern int read_symbolic();
extern pPLA new_PLA();
extern void PLA_summary();
extern void free_PLA();
extern void parse_pla();
extern void read_cube();
extern void skip_line();
extern foreach_output_function();
extern int cubelist_partition();
extern int so_both_do_espresso();
extern int so_both_do_exact();
extern int so_both_save();
extern int so_do_espresso();
extern int so_do_exact();
extern int so_save();
extern pset_family cof_output();
extern pset_family lex_sort();
extern pset_family mini_sort();
extern pset_family random_order();
extern pset_family size_sort();
extern pset_family sort_reduce();
extern pset_family uncof_output();
extern pset_family unravel();
extern pset_family unravel_range();
extern void so_both_espresso();
extern void so_espresso();
extern char *fmt_cost();
extern char *print_cost();
extern char *util_strsav();
extern void copy_cost();
extern void cover_cost();
extern void fatal();
extern void print_trace();
extern void size_stamp();
extern void totals();
extern char *fmt_cube();
extern char *fmt_expanded_cube();
extern char *pc1();
extern char *pc2();
extern char *pc3();
extern int makeup_labels();
extern kiss_output();
extern kiss_print_cube();
extern output_symbolic_constraints();
extern void cprint();
extern void debug1_print();
extern void debug_print();
extern void eqn_output();
extern void fpr_header();
extern void fprint_pla();
extern void pls_group();
extern void pls_label();
extern void pls_output();
extern void print_cube();
extern void print_expanded_cube();
extern void sf_debug_print();
extern find_equiv_outputs();
extern int check_equiv();
extern pset_family espresso();
extern int essen_cube();
extern pset_family cb_consensus();
extern pset_family cb_consensus_dist0();
extern pset_family essential();
extern pset_family minimize_exact();
extern pset_family minimize_exact_literals();
extern int feasibly_covered();
extern int most_frequent();
extern pset_family all_primes();
extern pset_family expand();
extern pset_family find_all_primes();
extern void elim_lowering();
extern void essen_parts();
extern void essen_raising();
extern void expand1();
extern void mincov();
extern void select_feasible();
extern void setup_BB_CC();
extern pset_family expand_gasp();
extern pset_family irred_gasp();
extern pset_family last_gasp();
extern pset_family super_gasp();
extern void expand1_gasp();
extern int util_getopt();
extern find_dc_inputs();
extern find_inputs();
extern form_bitvector();
extern map_dcset();
extern map_output_symbolic();
extern map_symbolic();
extern pset_family map_symbolic_cover();
extern symbolic_hack_labels();
extern int cube_is_covered();
extern int taut_special_cases();
extern int tautology();
extern pset_family irredundant();
extern void mark_irredundant();
extern void irred_split_cover();
extern sm_matrix *irred_derive_table();
extern pset minterms();
extern void explode();
extern void map();
extern output_phase_setup();
extern pPLA set_phase();
extern pset_family opo();
extern pset find_phase();
extern pset_family find_covers();
extern pset_family form_cover_table();
extern pset_family opo_leaf();
extern pset_family opo_recur();
extern void opoall();
extern void phase_assignment();
extern void repeated_phase_assignment();
extern generate_all_pairs();
extern int **find_pairing_cost();
extern int find_best_cost();
extern int greedy_best_cost();
extern int minimize_pair();
extern int pair_free();
extern pair_all();
extern pset_family delvar();
extern pset_family pairvar();
extern ppair pair_best_cost();
extern ppair pair_new();
extern ppair pair_save();
extern print_pair();
extern void find_optimal_pairing();
extern void set_pair();
extern void set_pair1();
extern pset_family primes_consensus();
extern int sccc_special_cases();
extern pset_family reduce();
extern pset reduce_cube();
extern pset sccc();
extern pset sccc_cube();
extern pset sccc_merge();
extern int set_andp(register pset r, register pset a, register pset b);
extern int set_orp(register pset r, register pset a, register pset b);
extern int setp_disjoint(register pset a, register pset b);
extern int setp_empty(register pset a);
extern int setp_equal(register pset a, register pset b);
extern int setp_full(register pset a, register int size);
extern int setp_implies(register pset a, register pset b);
extern char *pbv1(pset s, int n);
extern char *ps1(register pset a);
extern int *sf_count(pset_family A);
extern int *sf_count_restricted(pset_family A, register pset r);
extern int bit_index(register unsigned int a);
extern int set_dist(register pset a, register pset b);
extern int set_ord(register pset a);
extern void set_adjcnt(register pset a, register int *count, register int weight);
extern pset set_and(register pset r, register pset a, register pset b);
extern pset set_clear(register pset r, int size);
extern pset set_copy(register pset r, register pset a);
extern pset set_diff(register pset r, register pset a, register pset b);
extern pset set_fill(register pset r, register int size);
extern pset set_merge(register pset r, register pset a, register pset b, register pset mask);
extern pset set_or(register pset r, register pset a, register pset b);
extern pset set_xor(register pset r, register pset a, register pset b);
extern pset sf_and(pset_family A);
extern pset sf_or(pset_family A);
extern pset_family sf_active(pset_family A);
extern pset_family sf_addcol(pset_family A, int firstcol, int n);
extern pset_family sf_addset(pset_family A, pset s);
extern pset_family sf_append(pset_family A, pset_family B);
extern pset_family sf_bm_read(FILE *fp);
extern pset_family sf_compress(pset_family A, register pset c);
extern pset_family sf_copy(pset_family R, pset_family A);
extern pset_family sf_copy_col(pset_family dst, int dstcol, pset_family src, int srccol);
extern pset_family sf_delc(pset_family A, int first, int last);
extern pset_family sf_delcol(pset_family A, register int firstcol, register int n);
extern pset_family sf_inactive(pset_family A);
extern pset_family sf_join(pset_family A, pset_family B);
extern pset_family sf_new(int num, int size);
extern pset_family sf_permute(pset_family A, register int *permute, register int npermute);
extern pset_family sf_read(FILE *fp);
extern pset_family sf_save(register pset_family A);
extern pset_family sf_transpose(pset_family A);
extern void set_write(register FILE *fp, register pset a);
extern void sf_bm_print(pset_family A);
extern void sf_cleanup(void);
extern void sf_delset(pset_family A, int i);
extern void sf_free(pset_family A);
extern void sf_print(pset_family A);
extern void sf_write(FILE *fp, pset_family A);
extern int ccommon();
extern int cdist0();
extern int full_row();
extern int ascend();
extern int cactive();
extern int cdist();
extern int cdist01();
extern int cvolume();
extern int d1_order();
extern int d1_order_size();
extern int desc1();
extern int descend();
extern int lex_order();
extern int lex_order1();
extern pset force_lower();
extern void consensus();
extern pset_family cb1_dsharp();
extern pset_family cb_dsharp();
extern pset_family cb_recur_dsharp();
extern pset_family cb_recur_sharp();
extern pset_family cb_sharp();
extern pset_family cv_dsharp();
extern pset_family cv_intersect();
extern pset_family cv_sharp();
extern pset_family dsharp();
extern pset_family make_disjoint();
extern pset_family sharp();
pset do_sm_minimum_cover();
extern pset_family make_sparse();
extern pset_family mv_reduce();
extern qsort(void *, size_t, size_t, int (*) (const void *, const void *));
extern qst();
extern pset_family find_all_minimal_covers_petrick();
extern pset_family map_cover_to_unate();
extern pset_family map_unate_to_cover();
extern pset_family exact_minimum_cover();
extern pset_family gen_primes();
extern pset_family unate_compl();
extern pset_family unate_complement();
extern pset_family unate_intersect();
extern PLA_permute();
extern int PLA_verify();
extern int check_consistency();
extern int verify();
static pset_family set_family_garbage = 0;
static int intcpy(register unsigned int *d, register unsigned int *s, register long int n)
{
register int i;
for(i = 0; i < n; i++) {
*d++ = *s++;
}
}
int bit_index(register unsigned int a)
{
register int i;
if (a == 0)
return -1;
for(i = 0; (a & 1) == 0; a >>= 1, i++)
;
return i;
}
int set_ord(register pset a)
{
register int i, sum = 0;
register unsigned int val;
for(i = (a[0] & 0x03ff); i > 0; i--)
if ((val = a[i]) != 0)
sum += (bit_count[val & 255] + bit_count[(val >> 8) & 255] + bit_count[(val >> 16) & 255] + bit_count[(val >> 24) & 255]);
return sum;
}
int set_dist(register pset a, register pset b)
{
register int i, sum = 0;
register unsigned int val;
for(i = (a[0] & 0x03ff); i > 0; i--)
if ((val = a[i] & b[i]) != 0)
sum += (bit_count[val & 255] + bit_count[(val >> 8) & 255] + bit_count[(val >> 16) & 255] + bit_count[(val >> 24) & 255]);
return sum;
}
pset set_clear(register pset r, int size)
{
register int i = ((size <= 32) ? 1 : ((((size)-1) >> 5) + 1));
*r = i; do r[i] = 0; while (--i > 0);
return r;
}
pset set_fill(register pset r, register int size)
{
register int i = ((size <= 32) ? 1 : ((((size)-1) >> 5) + 1));
*r = i;
r[i] = ~ (unsigned) 0;
r[i] >>= i * 32 - size;
while (--i > 0)
r[i] = ~ (unsigned) 0;
return r;
}
pset set_copy(register pset r, register pset a)
{
register int i = (a[0] & 0x03ff);
do r[i] = a[i]; while (--i >= 0);
return r;
}
pset set_and(register pset r, register pset a, register pset b)
{
register int i = (a[0] & 0x03ff);
(r[0] &= ~0x03ff, r[0] |= (i)); do r[i] = a[i] & b[i]; while (--i > 0);
return r;
}
pset set_or(register pset r, register pset a, register pset b)
{
register int i = (a[0] & 0x03ff);
(r[0] &= ~0x03ff, r[0] |= (i)); do r[i] = a[i] | b[i]; while (--i > 0);
return r;
}
pset set_diff(register pset r, register pset a, register pset b)
{
register int i = (a[0] & 0x03ff);
(r[0] &= ~0x03ff, r[0] |= (i)); do r[i] = a[i] & ~b[i]; while (--i > 0);
return r;
}
pset set_xor(register pset r, register pset a, register pset b)
{
register int i = (a[0] & 0x03ff);
(r[0] &= ~0x03ff, r[0] |= (i)); do r[i] = a[i] ^ b[i]; while (--i > 0);
return r;
}
pset set_merge(register pset r, register pset a, register pset b, register pset mask)
{
register int i = (a[0] & 0x03ff);
(r[0] &= ~0x03ff, r[0] |= (i)); do r[i] = (a[i]&mask[i]) | (b[i]&~mask[i]); while (--i > 0);
return r;
}
int set_andp(register pset r, register pset a, register pset b)
{
register int i = (a[0] & 0x03ff);
register unsigned int x = 0;
(r[0] &= ~0x03ff, r[0] |= (i)); do {r[i] = a[i] & b[i]; x |= r[i];} while (--i > 0);
return x != 0;
}
int set_orp(register pset r, register pset a, register pset b)
{
register int i = (a[0] & 0x03ff);
register unsigned int x = 0;
(r[0] &= ~0x03ff, r[0] |= (i)); do {r[i] = a[i] | b[i]; x |= r[i];} while (--i > 0);
return x != 0;
}
int setp_empty(register pset a)
{
register int i = (a[0] & 0x03ff);
do if (a[i]) return 0; while (--i > 0);
return 1;
}
int setp_full(register pset a, register int size)
{
register int i = (a[0] & 0x03ff);
register unsigned int test;
test = ~ (unsigned) 0;
test >>= i * 32 - size;
if (a[i] != test)
return 0;
while (--i > 0)
if (a[i] != (~(unsigned) 0))
return 0;
return 1;
}
int setp_equal(register pset a, register pset b)
{
register int i = (a[0] & 0x03ff);
do if (a[i] != b[i]) return 0; while (--i > 0);
return 1;
}
int setp_disjoint(register pset a, register pset b)
{
register int i = (a[0] & 0x03ff);
do if (a[i] & b[i]) return 0; while (--i > 0);
return 1;
}
int setp_implies(register pset a, register pset b)
{
register int i = (a[0] & 0x03ff);
do if (a[i] & ~b[i]) return 0; while (--i > 0);
return 1;
}
pset sf_or(pset_family A)
{
register pset or, last, p;
or = set_clear(((unsigned int *) malloc(sizeof(unsigned int) * ( ((A->sf_size) <= 32 ? 2 : (((((A->sf_size)-1) >> 5) + 1) + 1))))), A->sf_size);
for( p=A->data, last= p+A->count*A->wsize; p< last; p+=A->wsize)
{register int i_=( or[0] & 0x03ff); (or[0] &= ~0x03ff, or[0] |= (i_)); do or[i_] = or[i_] | p[i_]; while (--i_>0);};
return or;
}
pset sf_and(pset_family A)
{
register pset and, last, p;
and = set_fill(set_clear(((unsigned int *) malloc(sizeof(unsigned int) * ( ((A->sf_size) <= 32 ? 2 : (((((A->sf_size)-1) >> 5) + 1) + 1))))), A->sf_size), A->sf_size);
for( p=A->data, last= p+A->count*A->wsize; p< last; p+=A->wsize)
{register int i_=( and[0] & 0x03ff); (and[0] &= ~0x03ff, and[0] |= (i_)); do and[i_] = and[i_] & p[i_]; while (--i_>0);};
return and;
}
pset_family sf_active(pset_family A)
{
register pset p, last;
for( p=A->data, last= p+A->count*A->wsize; p< last; p+=A->wsize) {
(p[0] |= ( 0x2000));
}
A->active_count = A->count;
return A;
}
pset_family sf_inactive(pset_family A)
{
register pset p, last, pdest;
pdest = A->data;
for( p=A->data, last= p+A->count*A->wsize; p< last; p+=A->wsize) {
if ((p[0] & ( 0x2000))) {
if (pdest != p) {
{register int i_=( p[0] & 0x03ff); do pdest[i_]= p[i_]; while (--i_>=0);};
}
pdest += A->wsize;
} else {
A->count--;
}
}
return A;
}
pset_family sf_copy(pset_family R, pset_family A)
{
R->sf_size = A->sf_size;
R->wsize = A->wsize;
R->count = A->count;
R->active_count = A->active_count;
intcpy(R->data, A->data, (long) A->wsize * A->count);
return R;
}
pset_family sf_join(pset_family A, pset_family B)
{
pset_family R;
long asize = A->count * A->wsize;
long bsize = B->count * B->wsize;
if (A->sf_size != B->sf_size) fatal("sf_join: sf_size mismatch");
R = sf_new(A->count + B->count, A->sf_size);
R->count = A->count + B->count;
R->active_count = A->active_count + B->active_count;
intcpy(R->data, A->data, asize);
intcpy(R->data + asize, B->data, bsize);
return R;
}
pset_family sf_append(pset_family A, pset_family B)
{
long asize = A->count * A->wsize;
long bsize = B->count * B->wsize;
if (A->sf_size != B->sf_size) fatal("sf_append: sf_size mismatch");
A->capacity = A->count + B->count;
A->data = ( A->data) ? ((unsigned int *) realloc((char *) A->data, sizeof(unsigned int) * ( (long) A->capacity * A->wsize))) : ((unsigned int *) malloc(sizeof(unsigned int) * ( (long) A->capacity * A->wsize)));
intcpy(A->data + asize, B->data, bsize);
A->count += B->count;
A->active_count += B->active_count;
sf_free(B);
return A;
}
pset_family sf_new(int num, int size)
{
pset_family A;
if (set_family_garbage == 0) {
A = ((set_family_t *) malloc(sizeof(set_family_t) * ( 1)));
} else {
A = set_family_garbage;
set_family_garbage = A->next;
}
A->sf_size = size;
A->wsize = ((size) <= 32 ? 2 : (((((size)-1) >> 5) + 1) + 1));
A->capacity = num;
A->data = ((unsigned int *) malloc(sizeof(unsigned int) * ( (long) A->capacity * A->wsize)));
A->count = 0;
A->active_count = 0;
return A;
}
pset_family sf_save(register pset_family A)
{
return sf_copy(sf_new(A->count, A->sf_size), A);
}
void sf_free(pset_family A)
{
((A->data) ? (free((char *) (A->data)), (A->data) = 0) : 0);
A->next = set_family_garbage;
set_family_garbage = A;
}
void sf_cleanup(void)
{
register pset_family p, pnext;
for(p = set_family_garbage; p != (pset_family) 0; p = pnext) {
pnext = p->next;
((p) ? (free((char *) (p)), (p) = 0) : 0);
}
set_family_garbage = (pset_family) 0;
}
pset_family sf_addset(pset_family A, pset s)
{
register pset p;
if (A->count >= A->capacity) {
A->capacity = A->capacity + A->capacity/2 + 1;
A->data = ( A->data) ? ((unsigned int *) realloc((char *) A->data, sizeof(unsigned int) * ( (long) A->capacity * A->wsize))) : ((unsigned int *) malloc(sizeof(unsigned int) * ( (long) A->capacity * A->wsize)));
}
p = ((A)->data + (A)->wsize * ( A->count++));
{register int i_=( s[0] & 0x03ff); do p[i_]= s[i_]; while (--i_>=0);};
return A;
}
void sf_delset(pset_family A, int i)
{ (void) set_copy(((A)->data + (A)->wsize * (i)), ((A)->data + (A)->wsize * ( --A->count)));}
void sf_print(pset_family A)
{
char *ps1(register pset a);
register pset p;
register int i;
for( p=A->data, i=0; i<A->count; p+=A->wsize, i++)
printf("A[%d] = %s\n", i, ps1(p));
}
void sf_bm_print(pset_family A)
{
char *pbv1(pset s, int n);
register pset p;
register int i;
for( p=A->data, i=0; i<A->count; p+=A->wsize, i++)
printf("[%4d] %s\n", i, pbv1(p, A->sf_size));
}
void sf_write(FILE *fp, pset_family A)
{
register pset p, last;
fprintf(fp, "%d %d\n", A->count, A->sf_size);
for( p=A->data, last= p+A->count*A->wsize; p< last; p+=A->wsize)
set_write(fp, p);
(void) fflush(fp);
}
pset_family sf_read(FILE *fp)
{
int i, j;
register pset p, last;
pset_family A;
(void) fscanf(fp, "%d %d\n", &i, &j);
A = sf_new(i, j);
A->count = i;
for( p=A->data, last= p+A->count*A->wsize; p< last; p+=A->wsize) {
(void) fscanf(fp, "%x", p);
for(j = 1; j <= (p[0] & 0x03ff); j++)
(void) fscanf(fp, "%x", p+j);
}
return A;
}
void set_write(register FILE *fp, register pset a)
{
register int n = (a[0] & 0x03ff), j;
for(j = 0; j <= n; j++) {
fprintf(fp, "%x ", a[j]);
if ((j+1) % 8 == 0 && j != n)
fprintf(fp, "\n\t");
}
fprintf(fp, "\n");
}
pset_family sf_bm_read(FILE *fp)
{
int i, j, rows, cols;
register pset pdest;
pset_family A;
(void) fscanf(fp, "%d %d\n", &rows, &cols);
A = sf_new(rows, cols);
for(i = 0; i < rows; i++) {
pdest = ((A)->data + (A)->wsize * ( A->count++));
(void) set_clear(pdest, A->sf_size);
for(j = 0; j < cols; j++) {
switch((--(fp)->_cnt>=0? ((int)*(fp)->_ptr++):_filbuf(fp))) {
case '0':
break;
case '1':
(pdest[((( j) >> 5) + 1)] |= 1 << (( j) & (32-1)));
break;
default:
fatal("Error reading set family");
}
}
if ((--(fp)->_cnt>=0? ((int)*(fp)->_ptr++):_filbuf(fp)) != '\n') {
fatal("Error reading set family (at end of line)");
}
}
return A;
}
static char s1[120];
char *ps1(register pset a)
{
register int i, num, l, len = 0, n = (32 * (a[0] & 0x03ff));
char temp[20];
int first = 1;
s1[len++] = '[';
for(i = 0; i < n; i++)
if ((a[(((i) >> 5) + 1)] & (1 << ((i) & (32-1))))) {
if (! first)
s1[len++] = ',';
first = 0; num = i;
l = 0; do temp[l++] = num % 10 + '0'; while ((num /= 10) > 0);
do s1[len++] = temp[--l]; while (l > 0);
if (len > 120-15) {
s1[len++] = '.'; s1[len++] = '.'; s1[len++] = '.';
break;
}
}
s1[len++] = ']';
s1[len++] = '\0';
return s1;
}
char *pbv1(pset s, int n)
{
register int i;
for(i = 0; i < n; i++)
s1[i] = (s[(((i) >> 5) + 1)] & (1 << ((i) & (32-1)))) ? '1' : '0';
s1[n] = '\0';
return s1;
}
void
set_adjcnt(register pset a, register int *count, register int weight)
{
register int i, base;
register unsigned int val;
for(i = (a[0] & 0x03ff); i > 0; ) {
for(val = a[i], base = --i << 5; val != 0; base++, val >>= 1) {
if (val & 1) {
count[base] += weight;
}
}
}
}
int *sf_count(pset_family A)
{
register pset p, last;
register int i, base, *count;
register unsigned int val;
count = ((int *) malloc(sizeof(int) * ( A->sf_size)));
for(i = A->sf_size - 1; i >= 0; i--) {
count[i] = 0;
}
for( p=A->data, last= p+A->count*A->wsize; p< last; p+=A->wsize) {
for(i = (p[0] & 0x03ff); i > 0; ) {
for(val = p[i], base = --i << 5; val != 0; base++, val >>= 1) {
if (val & 1) {
count[base]++;
}
}
}
}
return count;
}
int *sf_count_restricted(pset_family A, register pset r)
{
register pset p;
register int i, base, *count;
register unsigned int val;
int weight;
pset last;
count = ((int *) malloc(sizeof(int) * ( A->sf_size)));
for(i = A->sf_size - 1; i >= 0; i--) {
count[i] = 0;
}
for( p=A->data, last= p+A->count*A->wsize; p< last; p+=A->wsize) {
weight = 1024 / (set_ord(p) - 1);
for(i = (p[0] & 0x03ff); i > 0; ) {
for(val=p[i]&r[i], base= --i<<5; val!=0; base++, val >>= 1) {
if (val & 1) {
count[base] += weight;
}
}
}
}
return count;
}
pset_family sf_delc(pset_family A, int first, int last)
{
return sf_delcol(A, first, last-first + 1);
}
pset_family sf_addcol(pset_family A, int firstcol, int n)
{
int maxsize;
if (firstcol == A->sf_size) {
maxsize = 32 * ((A->sf_size <= 32) ? 1 : ((((A->sf_size)-1) >> 5) + 1));
if ((A->sf_size + n) <= maxsize) {
A->sf_size += n;
return A;
}
}
return sf_delcol(A, firstcol, -n);
}
pset_family sf_delcol(pset_family A, register int firstcol, register int n)
{
register pset p, last, pdest;
register int i;
pset_family B;
B = sf_new(A->count, A->sf_size - n);
for( p=A->data, last= p+A->count*A->wsize; p< last; p+=A->wsize) {
pdest = ((B)->data + (B)->wsize * ( B->count++));
{register int i_=(( B->sf_size <= 32) ? 1 : (((( B->sf_size)-1) >> 5) + 1)); *pdest=i_; do pdest[i_] = 0; while (--i_ > 0);};
for(i = 0; i < firstcol; i++)
if ((p[((( i) >> 5) + 1)] & (1 << (( i) & (32-1)))))
(pdest[((( i) >> 5) + 1)] |= 1 << (( i) & (32-1)));
for(i = n > 0 ? firstcol + n : firstcol; i < A->sf_size; i++)
if ((p[((( i) >> 5) + 1)] & (1 << (( i) & (32-1)))))
(pdest[((( i - n) >> 5) + 1)] |= 1 << (( i - n) & (32-1)));
}
sf_free(A);
return B;
}
pset_family sf_copy_col(pset_family dst, int dstcol, pset_family src, int srccol)
{
register pset last, p, pdest;
register int word_test, word_set;
unsigned int bit_set, bit_test;
word_test = (((srccol) >> 5) + 1);
bit_test = 1 << ((srccol) & (32-1));
word_set = (((dstcol) >> 5) + 1);
bit_set = 1 << ((dstcol) & (32-1));
pdest = dst->data;
for( p=src->data, last= p+src->count*src->wsize; p< last; p+=src->wsize) {
if ((p[word_test] & bit_test) != 0)
pdest[word_set] |= bit_set;
pdest += dst->wsize;
}
return dst;
}
pset_family sf_compress(pset_family A, register pset c)
{
register pset p;
register int i, bcol;
pset_family B;
B = sf_new(A->count, set_ord(c));
for(i = 0; i < A->count; i++) {
p = ((B)->data + (B)->wsize * ( B->count++));
{register int i_=(( B->sf_size <= 32) ? 1 : (((( B->sf_size)-1) >> 5) + 1)); *p=i_; do p[i_] = 0; while (--i_ > 0);};
}
bcol = 0;
for(i = 0; i < A->sf_size; i++) {
if ((c[((( i) >> 5) + 1)] & (1 << (( i) & (32-1))))) {
(void) sf_copy_col(B, bcol++, A, i);
}
}
sf_free(A);
return B;
}
pset_family sf_transpose(pset_family A)
{
pset_family B;
register pset p;
register int i, j;
B = sf_new(A->sf_size, A->count);
B->count = A->sf_size;
for( p=B->data, i=0; i<B->count; p+=B->wsize, i++) {
{register int i_=(( B->sf_size <= 32) ? 1 : (((( B->sf_size)-1) >> 5) + 1)); *p=i_; do p[i_] = 0; while (--i_ > 0);};
}
for( p=A->data, i=0; i<A->count; p+=A->wsize, i++) {
for(j = 0; j < A->sf_size; j++) {
if ((p[((( j) >> 5) + 1)] & (1 << (( j) & (32-1))))) {
(((B)->data + (B)->wsize * ( j))[((( i) >> 5) + 1)] |= 1 << (( i) & (32-1)));
}
}
}
sf_free(A);
return B;
}
pset_family sf_permute(pset_family A, register int *permute, register int npermute)
{
pset_family B;
register pset p, last, pdest;
register int j;
B = sf_new(A->count, npermute);
B->count = A->count;
for( p=B->data, last= p+B->count*B->wsize; p< last; p+=B->wsize)
{register int i_=(( npermute <= 32) ? 1 : (((( npermute)-1) >> 5) + 1)); *p=i_; do p[i_] = 0; while (--i_ > 0);};
pdest = B->data;
for( p=A->data, last= p+A->count*A->wsize; p< last; p+=A->wsize) {
for(j = 0; j < npermute; j++)
if ((p[((( permute[j]) >> 5) + 1)] & (1 << (( permute[j]) & (32-1)))))
(pdest[((( j) >> 5) + 1)] |= 1 << (( j) & (32-1)));
pdest += B->wsize;
}
sf_free(A);
return B;
}
|
the_stack_data/231392044.c | /*
* Copyright (c) 2018, 2019, 2020 Antti Tiihala
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* dy-iso.c
* Program for creating bootable dancy.iso image
*/
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#if CHAR_BIT != 8 || INT_MAX < 2147483647
#error "Unsupported implementation-defined characteristics"
#endif
/*
* file_name: ELTORITO.BIN
* file_size: 2048
*/
extern const unsigned char eltorito_bin[2048];
#define PROGRAM_CMDNAME "dy-iso"
#define W_LE16(a,d) ( \
*((a) + 0) = (unsigned char)(((unsigned)(d) >> 0) & 0xFFu), \
*((a) + 1) = (unsigned char)(((unsigned)(d) >> 8) & 0xFFu))
#define W_LE32(a,d) ( \
*((a) + 0) = (unsigned char)(((unsigned long)(d) >> 0) & 0xFFul), \
*((a) + 1) = (unsigned char)(((unsigned long)(d) >> 8) & 0xFFul), \
*((a) + 2) = (unsigned char)(((unsigned long)(d) >> 16) & 0xFFul), \
*((a) + 3) = (unsigned char)(((unsigned long)(d) >> 24) & 0xFFul))
#define W_BE16(a,d) ( \
*((a) + 1) = (unsigned char)(((unsigned)(d) >> 0) & 0xFFu), \
*((a) + 0) = (unsigned char)(((unsigned)(d) >> 8) & 0xFFu))
#define W_BE32(a,d) ( \
*((a) + 3) = (unsigned char)(((unsigned long)(d) >> 0) & 0xFFul), \
*((a) + 2) = (unsigned char)(((unsigned long)(d) >> 8) & 0xFFul), \
*((a) + 1) = (unsigned char)(((unsigned long)(d) >> 16) & 0xFFul), \
*((a) + 0) = (unsigned char)(((unsigned long)(d) >> 24) & 0xFFul))
static const char readme_txt[] =
"Dancy Operating System\n"
"";
static size_t dancy_file_size;
static unsigned char *dancy_file;
static struct tm iso_tm_arg;
static struct tm *iso_tm;
struct options {
char **operands;
const char *error;
const char *arg_o;
const char *arg_t;
int uefi;
int verbose;
};
static void write_timestamp(int version, unsigned char *out)
{
if (version == 1) {
sprintf((char *)out + 0, "%04i", iso_tm->tm_year + 1900);
sprintf((char *)out + 4, "%02i", iso_tm->tm_mon + 1);
sprintf((char *)out + 6, "%02i", iso_tm->tm_mday);
sprintf((char *)out + 8, "%02i", iso_tm->tm_hour);
sprintf((char *)out + 10, "%02i", iso_tm->tm_min);
sprintf((char *)out + 12, "%02i", iso_tm->tm_sec);
sprintf((char *)out + 14, "%02i", 0);
*(out + 16) = 0x00;
return;
}
if (version == 2) {
if (iso_tm->tm_year <= UCHAR_MAX)
*(out + 0) = (unsigned char)iso_tm->tm_year;
else
*(out + 0) = 0xFF;
*(out + 1) = (unsigned char)(iso_tm->tm_mon + 1);
*(out + 2) = (unsigned char)iso_tm->tm_mday;
*(out + 3) = (unsigned char)iso_tm->tm_hour;
*(out + 4) = (unsigned char)iso_tm->tm_min;
*(out + 5) = (unsigned char)iso_tm->tm_sec;
*(out + 6) = 0x00;
return;
}
}
static int create_iso(int uefi)
{
size_t size = dancy_file_size;
unsigned char *ptr;
if (size < 0x0800) {
fputs("Error: too small dancy-image-file\n", stderr);
return 1;
}
if (size > (0xFFFF * 0x0800)) {
fputs("Error: too big dancy-image-file\n", stderr);
return 1;
}
if ((size & 0x07FF) != 0) {
fputs("Error: alignment of dancy-image-file\n", stderr);
return 1;
}
if (dancy_file[0] != 0xEB || dancy_file[12] != 0x08) {
fputs("Error: format of dancy-image-file\n", stderr);
return 1;
}
size += 0x00280000;
size &= 0xFFF00000;
ptr = realloc(dancy_file, size);
if (!ptr) {
fputs("Error: not enough memory\n", stderr);
return 1;
}
dancy_file = ptr;
memset(&dancy_file[dancy_file_size], 0, (size - dancy_file_size));
memmove(&dancy_file[0x80000], &dancy_file[0], dancy_file_size);
memset(&dancy_file[0], 0, 0x80000);
/*
* ECMA-119 Second Edition
* Primary Volume Descriptor
*
* Volume Descriptor Type
*/
ptr[0x8000] = 0x01;
/*
* Standard Identifier
*/
memcpy(&ptr[0x8001], "CD001", 5);
/*
* Volume Descriptor Version
*/
ptr[0x8006] = 0x01;
/*
* System Identifier and Volume Identifier
*/
memcpy(&ptr[0x8008], "DANCY ", 8);
memset(&ptr[0x8010], ' ', 24);
memcpy(&ptr[0x8028], "CDROM ", 8);
memset(&ptr[0x8030], ' ', 24);
/*
* Volume Space Size (LSB and MSB)
*/
W_LE32(&ptr[0x8050], size);
W_BE32(&ptr[0x8054], size);
/*
* Volume Set Size (LSB and MSB)
*/
W_LE16(&ptr[0x8078], 0x0001);
W_BE16(&ptr[0x807A], 0x0001);
/*
* Volume Sequence Number (LSB and MSB)
*/
W_LE16(&ptr[0x807C], 0x0001);
W_BE16(&ptr[0x807E], 0x0001);
/*
* Logical Block Size (LSB and MSB)
*/
W_LE16(&ptr[0x8080], 0x0800);
W_BE16(&ptr[0x8082], 0x0800);
/*
* Path Table Size (LSB and MSB)
*/
W_LE32(&ptr[0x8084], 0x0000000A);
W_BE32(&ptr[0x8088], 0x0000000A);
/*
* Location of Occurrence of Type L Path Table
*/
W_LE32(&ptr[0x808C], 0x00000014);
/*
* Location of Occurrence of Type M Path Table
*/
W_BE32(&ptr[0x8094], 0x00000018);
/*
* Directory Record for Root Directory
*
* Length of Directory Record
*/
ptr[0x809C] = 0x22;
/*
* Location of Extent (LSB and MSB)
*/
W_LE32(&ptr[0x809E], 0x00000020);
W_BE32(&ptr[0x80A2], 0x00000020);
/*
* Data Length (LSB and MSB)
*/
W_LE32(&ptr[0x80A6], 0x00000800);
W_BE32(&ptr[0x80AA], 0x00000800);
/*
* Recording Date and Time
*/
write_timestamp(2, &ptr[0x80AE]);
/*
* Recording Date and Time
*/
ptr[0x80B5] = 0x02;
/*
* Volume Sequence Number (LSB and MSB)
*/
W_LE16(&ptr[0x80B8], 0x0001);
W_BE16(&ptr[0x80BA], 0x0001);
/*
* Length of File Identifier
*/
ptr[0x80BC] = 0x01;
/*
* Volume Set Identifier, etc.
*/
memset(&ptr[0x80BE], ' ', 623);
/*
* Volume Creation Date and Time
*/
write_timestamp(1, &ptr[0x832D]);
/*
* Volume Modification Date and Time
*/
write_timestamp(1, &ptr[0x833E]);
/*
* Volume Expiration Date and Time
*/
memset(&ptr[0x834F], '0', 16);
/*
* Volume Effective Date and Time
*/
write_timestamp(1, &ptr[0x8360]);
/*
* File Structure Version
*/
ptr[0x8371] = 0x01;
/*
* "El Torito" Bootable CD-ROM Specification Version 1.0
*/
ptr[0x8800] = 0x00;
memcpy(&ptr[0x8801], "CD001", 5);
ptr[0x8806] = 0x01;
memcpy(&ptr[0x8807], "EL TORITO SPECIFICATION", 23);
/*
* Pointer to first sector of Boot Catalog
*/
W_LE32(&ptr[0x8847], 0x00000080);
/*
* Volume Descriptor Set Terminator
*/
ptr[0x9000] = 0xFF;
memcpy(&ptr[0x9001], "CD001", 5);
ptr[0x9006] = 0x01;
/*
* Type L Path Table
*/
ptr[0xA000] = 0x01;
W_LE32(&ptr[0xA002], 0x00000020);
W_LE16(&ptr[0xA006], 0x0001);
/*
* Type M Path Table
*/
ptr[0xC000] = 0x01;
W_BE32(&ptr[0xC002], 0x00000020);
W_BE16(&ptr[0xC006], 0x0001);
/*
* Root directory
*
* "00" Directory
*/
ptr = dancy_file + 0x10000;
ptr[0x00] = 0x22;
W_LE32(&ptr[0x02], 0x00000020);
W_BE32(&ptr[0x06], 0x00000020);
W_LE32(&ptr[0x0A], 0x00000800);
W_BE32(&ptr[0x0E], 0x00000800);
write_timestamp(2, &ptr[0x12]);
ptr[0x19] = 0x02;
W_LE16(&ptr[0x1C], 0x0001);
W_BE16(&ptr[0x1E], 0x0001);
ptr[0x20] = 0x01;
ptr[0x21] = 0x00;
ptr += ptr[0x00];
/*
* "01" Directory
*/
ptr[0x00] = 0x22;
W_LE32(&ptr[0x02], 0x00000020);
W_BE32(&ptr[0x06], 0x00000020);
W_LE32(&ptr[0x0A], 0x00000800);
W_BE32(&ptr[0x0E], 0x00000800);
write_timestamp(2, &ptr[0x12]);
ptr[0x19] = 0x02;
W_LE16(&ptr[0x1C], 0x0001);
W_BE16(&ptr[0x1E], 0x0001);
ptr[0x20] = 0x01;
ptr[0x21] = 0x01;
ptr += ptr[0x00];
/*
* "BOOT.CAT" File
*/
ptr[0x00] = 0x2C;
W_LE32(&ptr[0x02], 0x00000080);
W_BE32(&ptr[0x06], 0x00000080);
W_LE32(&ptr[0x0A], 0x00000800);
W_BE32(&ptr[0x0E], 0x00000800);
write_timestamp(2, &ptr[0x12]);
ptr[0x19] = 0x01;
W_LE16(&ptr[0x1C], 0x0001);
W_BE16(&ptr[0x1E], 0x0001);
ptr[0x20] = 0x0A;
memcpy(&ptr[0x21], "BOOT.CAT;1", 0x0A);
ptr += ptr[0x00];
/*
* "DANCY.IMG" File
*/
ptr[0x00] = 0x2C;
W_LE32(&ptr[0x02], 0x00000100);
W_BE32(&ptr[0x06], 0x00000100);
W_LE32(&ptr[0x0A], dancy_file_size);
W_BE32(&ptr[0x0E], dancy_file_size);
write_timestamp(2, &ptr[0x12]);
ptr[0x19] = 0x00;
W_LE16(&ptr[0x1C], 0x0001);
W_BE16(&ptr[0x1E], 0x0001);
ptr[0x20] = 0x0B;
memcpy(&ptr[0x21], "DANCY.IMG;1", 0x0B);
ptr += ptr[0x00];
/*
* "ELTORITO.BIN" File
*/
ptr[0x00] = 0x30;
W_LE32(&ptr[0x02], 0x000000A0);
W_BE32(&ptr[0x06], 0x000000A0);
W_LE32(&ptr[0x0A], 0x00000800);
W_BE32(&ptr[0x0E], 0x00000800);
write_timestamp(2, &ptr[0x12]);
ptr[0x19] = 0x01;
W_LE16(&ptr[0x1C], 0x0001);
W_BE16(&ptr[0x1E], 0x0001);
ptr[0x20] = 0x0E;
memcpy(&ptr[0x21], "ELTORITO.BIN;1", 0x0E);
ptr += ptr[0x00];
/*
* "README.TXT" File
*/
ptr[0x00] = 0x2E;
W_LE32(&ptr[0x02], 0x000000C0);
W_BE32(&ptr[0x06], 0x000000C0);
W_LE32(&ptr[0x0A], (sizeof(readme_txt) - 1));
W_BE32(&ptr[0x0E], (sizeof(readme_txt) - 1));
write_timestamp(2, &ptr[0x12]);
ptr[0x19] = 0x00;
W_LE16(&ptr[0x1C], 0x0001);
W_BE16(&ptr[0x1E], 0x0001);
ptr[0x20] = 0x0C;
memcpy(&ptr[0x21], "README.TXT;1", 0x0C);
ptr += ptr[0x00];
/*
* El Torito Bootable CD-ROM Specification Version 1.0
* Validation Entry and Default Entry
*/
ptr = dancy_file + 0x40000;
ptr[0x00] = 0x01;
ptr[0x1C] = 0xAA, ptr[0x1D] = 0x55;
ptr[0x1E] = 0x55, ptr[0x1F] = 0xAA;
ptr[0x20] = 0x88;
ptr[0x26] = 0x04;
W_LE32(&ptr[0x28], 0x000000A0);
if (uefi) {
size_t efi_size = dancy_file_size / 512;
ptr[0x40] = 0x91, ptr[0x41] = 0xEF, ptr[0x42] = 0x01;
ptr[0x60] = 0x88;
W_LE16(&ptr[0x66], efi_size);
W_LE32(&ptr[0x68], 0x00000100);
}
/*
* "ELTORITO.BIN" Data
*/
ptr = dancy_file + 0x50000;
memcpy(&ptr[0], &eltorito_bin[0], 2048);
/*
* "README.TXT" Data
*/
ptr = dancy_file + 0x60000;
memcpy(&ptr[0], &readme_txt[0], (sizeof(readme_txt) - 1));
dancy_file_size = size;
return 0;
}
static int read_file(const char *name, unsigned char **out, size_t *size)
{
const size_t chunk = 0x100000;
const size_t size_max = ~((size_t)0);
FILE *fp = stdin;
int is_stdin = 1;
unsigned char *ptr;
if (strcmp(name, "-")) {
fp = (errno = 0, fopen(name, "rb"));
if (!fp) {
const char *fmt = "Error: reading file \"%s\" (%s)\n";
fprintf(stderr, fmt, name, strerror(errno));
return 1;
}
is_stdin = 0;
}
*size = 0;
ptr = malloc(chunk);
for (;;) {
size_t bytes_read;
int my_errno;
int stop;
if (!ptr) {
fputs("Error: not enough memory\n", stderr);
return !is_stdin ? ((void)fclose(fp), 1) : 1;
}
*out = ptr;
ptr += *size;
bytes_read = (errno = 0, fread(ptr, 1, chunk, fp));
my_errno = errno;
stop = feof(fp);
if (ferror(fp) || (!stop && bytes_read != chunk)) {
const char *fmt = "Error: reading file \"%s\" (%s)\n";
fprintf(stderr, fmt, name, strerror(my_errno));
return !is_stdin ? ((void)fclose(fp), 1) : 1;
}
*size += ((bytes_read <= chunk) ? bytes_read : chunk);
if (stop)
break;
if (!(*size < size_max - chunk)) {
const char *fmt = "Error: reading file \"%s\" (%s)\n";
fprintf(stderr, fmt, name, "size_t overflow");
return !is_stdin ? ((void)fclose(fp), 1) : 1;
}
ptr = realloc(*out, *size + chunk);
}
return !is_stdin ? ((void)fclose(fp), 0) : 0;
}
static int end(const char *name, unsigned char *out, size_t size)
{
FILE *fp = stdout;
int is_stdout = 1;
if (!out || !size)
return 1;
if (strcmp(name, "-")) {
fp = (errno = 0, fopen(name, "wb"));
if (!fp) {
const char *fmt = "Error: output \"%s\" (%s)\n";
fprintf(stderr, fmt, name, strerror(errno));
return free(out), 1;
}
is_stdout = 0;
}
if ((errno = 0, fwrite(out, 1, size, fp)) != size) {
perror("Error");
if (!is_stdout)
(void)fclose(fp);
return free(out), 1;
}
free(out);
errno = 0;
if (is_stdout)
return fflush(fp) ? perror("Error"), 1 : 0;
return fclose(fp) ? perror("Error"), 1 : 0;
}
static int parse_time(const char *time_str, struct tm *out)
{
static const char *e = "Error: wrong timestamp format\n";
char buf[32];
int i;
/*
* "YYYY-MM-DDThh:mm:ss"
*/
memset(out, 0, sizeof(struct tm));
if (strlen(time_str) != 19)
return fputs(e, stderr), 1;
memcpy(&buf[0], &time_str[0], 20);
if (buf[4] != '-' || buf[7] != '-' || buf[10] != 'T')
return fputs(e, stderr), 1;
if (buf[13] != ':' || buf[16] != ':')
return fputs(e, stderr), 1;
buf[4] = buf[7] = buf[10] = buf[13] = buf[16] = '\0';
for (i = 0; i < 19; i++) {
if (buf[i] != '\0' && !isdigit(buf[i]))
return fputs(e, stderr), 1;
}
out->tm_year = atoi(&buf[0]) - 1900;
out->tm_mon = atoi(&buf[5]) - 1;
out->tm_mday = atoi(&buf[8]);
out->tm_hour = atoi(&buf[11]);
out->tm_min = atoi(&buf[14]);
out->tm_sec = atoi(&buf[17]);
i = (out->tm_year >= 0) ? 0 : 1;
i |= (out->tm_mon >= 0 && out->tm_mon <= 11) ? 0 : 1;
i |= (out->tm_mday >= 1 && out->tm_mday <= 31) ? 0 : 1;
i |= (out->tm_hour >= 0 && out->tm_hour <= 23) ? 0 : 1;
i |= (out->tm_min >= 0 && out->tm_min <= 59) ? 0 : 1;
i |= (out->tm_sec >= 0 && out->tm_sec <= 59) ? 0 : 1;
if (i)
return fputs(e, stderr), 1;
return 0;
}
static int program(struct options *opt)
{
if (opt->arg_t) {
if (parse_time(opt->arg_t, &iso_tm_arg))
return 1;
iso_tm = &iso_tm_arg;
} else {
time_t t = time(NULL);
iso_tm = gmtime(&t);
}
if (!opt->arg_o)
return opt->error = "missing output", 1;
if (!opt->operands[0])
return opt->error = "missing dancy-image-file", 1;
if (opt->operands[1])
return opt->error = "too many operands", 1;
if (read_file(opt->operands[0], &dancy_file, &dancy_file_size))
return 1;
if (create_iso(opt->uefi))
return free(dancy_file), 1;
return end(opt->arg_o, dancy_file, dancy_file_size);
}
static const char *help_str =
"Usage: " PROGRAM_CMDNAME
" -o output [-t timestamp] dancy-image-file\n"
"\nOptions:\n"
" -o output output file\n"
" -t timestamp YYYY-MM-DDThh:mm:ss\n"
" --uefi EFI System Partition\n"
"\nGeneral:\n"
" --help, -h help text\n"
" --verbose, -v additional information\n"
" --version, -V version information\n"
"\n";
static void help(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
if (fmt) {
fputs("Error: ", stderr);
vfprintf(stderr, fmt, va);
fputs("\n\n", stderr);
}
va_end(va);
fputs(help_str, (fmt) ? stderr : stdout);
exit((fmt) ? EXIT_FAILURE : EXIT_SUCCESS);
}
static void version(void)
{
#if defined(DANCY_MAJOR) && defined(DANCY_MINOR)
printf(PROGRAM_CMDNAME " (Dancy) %i.%i\n", DANCY_MAJOR, DANCY_MINOR);
#else
fputs(PROGRAM_CMDNAME " (Dancy)\n", stdout);
#endif
exit(EXIT_SUCCESS);
}
int main(int argc, char *argv[])
{
static struct options opts;
char **argv_i = (argc > 1) ? argv : NULL;
if (!argc + 495 - 'D' - 'a' - 'n' - 'c' - 'y')
return EXIT_FAILURE;
{
size_t null_test = sizeof(&argv[argc]);
while (null_test) {
if (*((unsigned char *)&argv[argc] + (--null_test)))
return EXIT_FAILURE;
}
}
while (argv_i && *++argv_i) {
const char *arg = *argv_i;
if (arg[0] != '-' || arg[1] == '\0')
continue;
*argv_i = NULL;
if (arg[1] == '-') {
if (arg[2] == '\0') {
argv_i = &argv[argc];
break;
}
if (!strcmp(arg + 2, "help"))
help(NULL);
if (!strcmp(arg + 2, "version"))
version();
if (!strcmp(arg + 2, "verbose")) {
opts.verbose = 1;
continue;
}
if (!strcmp(arg + 2, "uefi")) {
opts.uefi = 1;
continue;
}
help("unknown long option \"%s\"", arg);
}
do {
const char **optarg = NULL;
switch (*++arg) {
case '\0':
arg = NULL;
break;
case 'h':
help(NULL);
break;
case 'o':
optarg = &opts.arg_o;
break;
case 't':
optarg = &opts.arg_t;
break;
case 'v':
opts.verbose = 1;
break;
case 'V':
version();
break;
default:
help("unknown option \"-%c\"", *arg);
break;
}
if (optarg) {
const char *next;
next = (arg[1]) ? &arg[1] : *++argv_i;
if (next) {
if (optarg)
*optarg = next;
arg = *argv_i = NULL;
break;
}
help("-%c <option-argument> missing", *arg);
}
} while (arg);
}
if (argv_i) {
int i = argc = 1;
while (argv + i < argv_i)
if ((argv[argc] = argv[i++]) != NULL)
argc++;
argv[argc] = NULL;
}
opts.operands = (!argv[0]) ? &argv[0] : &argv[1];
if (program(&opts)) {
if (opts.error)
help(opts.error);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
|
the_stack_data/72013876.c | /* { dg-do compile } */
/* { dg-options "-O1 -funsafe-math-optimizations" } */
void
Q (double *s, double h)
{
int i;
if (h > 1)
h = h - 1;
for (i = 1; i < 3; i++)
if (s[i] / h > 0)
s[0] = h, s[i] = s[i] / h;
}
|
the_stack_data/13521.c | #include <stdio.h>
#include <ctype.h>
#include <string.h>
#define MAXWORD 100
struct key {
char *word;
int count;
} keytab[] = {
"auto", 0,
"break", 0,
"case", 0,
"char", 0,
"const", 0,
"continue", 0,
"default", 0,
"unsigned", 0,
"void", 0,
"volatile", 0,
"while", 0,
"printf", 0, /* Figure out why printf is a special case */
};
#define NKEYS (sizeof keytab / sizeof(struct key))
int mgetword(char *, int);
int binsearch(char *, struct key *, int);
/* count C keywords */
int main(int argc, char *argv[])
{
int n;
char word[MAXWORD];
while (mgetword(word, MAXWORD) != EOF)
if (isalpha(word[0]))
if ((n = binsearch(word, keytab, NKEYS)) >= 0)
keytab[n].count++;
for (n = 0; n < NKEYS; n++)
if (keytab[n].count > 0)
printf("%4d %s\n", keytab[n].count, keytab[n].word);
return 0;
}
/* binsearch: find word in tab[0]...tab[n-1] */
int binsearch(char *word, struct key tab[], int n)
{
int cond;
int low, high, mid;
low = 0;
high = n - 1;
while (low <= high) {
mid = (low+high) / 2;
if ((cond = strcmp(word, tab[mid].word)) < 0)
high = mid - 1;
else if (cond > 0)
low = mid + 1;
else
return mid;
}
return -1;
}
/* getword: get next word or character from input */
int mgetword(char *word, int lim)
{
int c, getch(void);
void ungetch(int);
char *w = word;
while (isspace(c = getch()))
;
if (c != EOF)
*w++ = c;
if (!isalpha(c)) {
*w = '\0';
return c;
}
for ( ; --lim > 0; w++)
if (!isalnum(*w = getch())) {
ungetch(*w);
break;
}
*w = '\0';
return word[0];
}
#define BUFSIZE 100
char buf[BUFSIZE]; /* buffer for ungetch */
int bufp = 0; /* next free position in buf */
int getch(void) /* get a (possibly pushed back) character */
{
return ( bufp > 0)? buf[--bufp] : getchar();
}
void ungetch(int c) /* push a character back on input */
{
if(bufp >= BUFSIZE)
printf("ungetch: too many characters \n");
else
buf[bufp++] = c;
}
|
the_stack_data/34267.c |
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
// Traditional vertical calculation like algorithm, O(n^2)
/*
* Input:
* int *a, int *b: ptr to multicands
* int *c: ptr to result array
* int m, int n: length of mlticands
*
*/
void multiply(int *a, int *b, int *c, int m, int n)
{
int i, j;
// Multiply digit by digit
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
c[i + j] += a[i] * b[j];
}
}
// Handles carries
for (i = 0; i < n + m; i++)
{
if (c[i] >= 10)
{
c[i + 1] += c[i] / 10;
c[i] %= 10;
}
}
}
void bigadd(int *a, int *b, int *c, int lengthA, int lengthB)
{
int i;
int carry = 0;
// Copy A to C
memcpy(c, a, lengthA * sizeof(int));
// Add B to C digit by digit
for (i = 0; i < lengthB; i++)
{
c[i] = (a[i] + b[i] + carry);
carry = c[i] / 10;
c[i] %= 10;
}
// Handles the last carry
c[lengthB] += carry;
}
void bigsub(int *a, int *b, int *c, int lengthA, int lengthB)
{
int i;
// Copy a to c
memcpy(c, a, lengthA * sizeof(int));
// Substract digit by digit
for (i = 0; i < lengthB; ++i)
{
c[i] = c[i] - b[i];
if (c[i] < 0)
{
c[i + 1] -= 1;
c[i] += 10;
}
}
// Handles borrows
for (i = lengthB; i < lengthA; ++i)
{
if (c[i] < 0)
{
c[i + 1] -= 1;
c[i] += 10;
}
}
}
void bigjoin(int *var, int *result, int length)
{
int i;
int carry = 0;
for (i = 0; i < length; ++i)
{
result[i] += var[i] + carry;
carry = result[i] / 10;
result[i] %= 10;
}
// Handles the last carry
result[length] += carry;
}
// Traditional vertical calculation like algorithm,
// With openmp
void multiplyMP(int *a, int *b, int *c, int m, int n)
{
int i, j;
// Multiply digit by digit
#pragma omp parallel for num_threads(4)
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
c[i + j] += a[i] * b[j];
}
}
// Handles carries
for (i = 0; i < n + m; i++)
{
if (c[i] >= 10)
{
c[i + 1] += c[i] / 10;
c[i] %= 10;
}
}
}
|
the_stack_data/1004976.c | #include <unistd.h>
#include <stddef.h> //definition of NULL
//forward declaration
int __startThread();
void __onAppExit();
//global vars
int threadID;
int updateStreamsEnabled = -1; //-1 = auto activate on registering a callback
int updateInterval = 500; //in ms
//definition and variable for callback
typedef int (*intCallback)(void);
intCallback updateStreamManagerCallback;
//register cleanup function
//this is called when the calling programme exits
atexit( __onAppExit );
// === FUNCTIONS ===
void __onAppExit() {
stopThread();
}
int stopThread() {
updateStreamsEnabled = 0;
return 1;
}
int startThread(){
updateStreamsEnabled = 1;
return __startThread();
};
int RegisterUpdateStreamManagerCallback ( intCallback callback ) {
updateStreamManagerCallback = callback;
if (updateStreamsEnabled == -1)
startThread();
return 1;
}
void *updateStreamManager(void *v) {
while(updateStreamsEnabled == 1) {
//call the blitzmax function which updates the streams buffers
if(updateStreamManagerCallback != NULL)
updateStreamManagerCallback();
//wait some milliseconds till next update
usleep(updateInterval * 1000);
}
return NULL;
}
// === WINDOWS THREADS ===
#ifdef _WIN32
#include <windows.h>
HANDLE thread;
int __startThread(){
thread = CreateThread(0, 0, updateStreamManager, NULL, 0, &threadID);
return 0;
};
// === POSIX THREADS ===
// Linux, Mac
#else
#include <pthread.h>
pthread_t thread;
int __startThread(){
threadID = pthread_create(&thread, NULL, updateStreamManager, NULL);
return 0;
};
#endif |
the_stack_data/4922.c | #include <stdlib.h>
__attribute__((optimize(0)))
int main(void) {
void *p = malloc(16);
if (!p) {
return 1;
}
void *q = malloc(16);
if (!q) {
return 1;
}
free(p);
free(q);
free(p);
return 0;
}
|
the_stack_data/6386472.c | #include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
//Closing the file descriptor in the parent
int main() {
int fd1,fd2,s;
fd1=open("foo.txt", O_RDONLY | O_CREAT);
pid_t pid;
pid=fork();
char *c = (char *) calloc(100, sizeof(char));
if(pid==0) {
printf("\n\nHello from the child process: %d\n!!!!!!!!!!!\n\n",getpid());
s = read(fd1, c, 10);
printf("File descriptor : %d, No. of bytes read : %d\n", fd1, s);
c[s] = '\0';
printf("Those bytes are as follows: %s\n", c);
}
else if(pid>0) {
printf("\n\nHello from the parent process: %d!!!!!!!!!!!\n\n",getpid());
s = read(fd1, c, 10);
printf("File descriptor : %d, No. of bytes read : %d\n", fd1, s);
c[s] = '\0';
printf("Those bytes are as follows: %s\n", c);
close(fd1);
}
}
|
the_stack_data/1142407.c | #include <stdio.h>
#include <stdlib.h>
int powShort(int m, int n){
if(n==0){
return 1;
}
if(n%2==0){
return powShort(m*m, n/2);
}
else
{
return m*powShort(m*m, (n-1)/2);
}
}
int main(){
printf("%d", powShort(2, 9));
}
|
the_stack_data/599967.c | /**
* @file lv_port_indev_templ.c
*
*/
/*Copy this file as "lv_port_indev.c" and set this value to "1" to enable content*/
#if 0
/*********************
* INCLUDES
*********************/
#include "lv_port_indev_templ.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void touchpad_init(void);
static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
static bool touchpad_is_pressed(void);
static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y);
static void mouse_init(void);
static bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
static bool mouse_is_pressed(void);
static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y);
static void keypad_init(void);
static bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
static uint32_t keypad_get_key(void);
static void encoder_init(void);
static bool encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
static void encoder_handler(void);
static void button_init(void);
static bool button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
static int8_t button_get_pressed_id(void);
static bool button_is_pressed(uint8_t id);
/**********************
* STATIC VARIABLES
**********************/
lv_indev_t * indev_touchpad;
lv_indev_t * indev_mouse;
lv_indev_t * indev_keypad;
lv_indev_t * indev_encoder;
lv_indev_t * indev_button;
static int32_t encoder_diff;
static lv_indev_state_t encoder_state;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_port_indev_init(void)
{
/* Here you will find example implementation of input devices supported by LittelvGL:
* - Touchpad
* - Mouse (with cursor support)
* - Keypad (supports GUI usage only with key)
* - Encoder (supports GUI usage only with: left, right, push)
* - Button (external buttons to press points on the screen)
*
* The `..._read()` function are only examples.
* You should shape them according to your hardware
*/
lv_indev_drv_t indev_drv;
/*------------------
* Touchpad
* -----------------*/
/*Initialize your touchpad if you have*/
touchpad_init();
/*Register a touchpad input device*/
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = touchpad_read;
indev_touchpad = lv_indev_drv_register(&indev_drv);
/*------------------
* Mouse
* -----------------*/
/*Initialize your touchpad if you have*/
mouse_init();
/*Register a mouse input device*/
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = mouse_read;
indev_mouse = lv_indev_drv_register(&indev_drv);
/*Set cursor. For simplicity set a HOME symbol now.*/
lv_obj_t * mouse_cursor = lv_img_create(lv_disp_get_scr_act(NULL), NULL);
lv_img_set_src(mouse_cursor, LV_SYMBOL_HOME);
lv_indev_set_cursor(indev_mouse, mouse_cursor);
/*------------------
* Keypad
* -----------------*/
/*Initialize your keypad or keyboard if you have*/
keypad_init();
/*Register a keypad input device*/
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_KEYPAD;
indev_drv.read_cb = keypad_read;
indev_keypad = lv_indev_drv_register(&indev_drv);
/* Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
* add objects to the group with `lv_group_add_obj(group, obj)`
* and assign this input device to group to navigate in it:
* `lv_indev_set_group(indev_keypad, group);` */
/*------------------
* Encoder
* -----------------*/
/*Initialize your encoder if you have*/
encoder_init();
/*Register a encoder input device*/
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_KEYPAD;
indev_drv.read_cb = encoder_read;
indev_encoder = lv_indev_drv_register(&indev_drv);
/* Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
* add objects to the group with `lv_group_add_obj(group, obj)`
* and assign this input device to group to navigate in it:
* `lv_indev_set_group(indev_keypad, group);` */
/*------------------
* Button
* -----------------*/
/*Initialize your button if you have*/
button_init();
/*Register a button input device*/
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_BUTTON;
indev_drv.read_cb = button_read;
indev_button = lv_indev_drv_register(&indev_drv);
/*Assign buttons to points on the screen*/
static const lv_point_t btn_points[2] = {
{10, 10}, /*Button 0 -> x:10; y:10*/
{40, 100}, /*Button 1 -> x:40; y:100*/
};
lv_indev_set_button_points(indev_button, btn_points);
}
/**********************
* STATIC FUNCTIONS
**********************/
/*------------------
* Touchpad
* -----------------*/
/*Initialize your touchpad*/
static void touchpad_init(void)
{
/*Your code comes here*/
}
/* Will be called by the library to read the touchpad */
static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
static lv_coord_t last_x = 0;
static lv_coord_t last_y = 0;
/*Save the pressed coordinates and the state*/
if(touchpad_is_pressed()) {
touchpad_get_xy(&last_x, &last_y);
data->state = LV_INDEV_STATE_PR;
} else {
data->state = LV_INDEV_STATE_REL;
}
/*Set the last pressed coordinates*/
data->point.x = last_x;
data->point.y = last_y;
/*Return `false` because we are not buffering and no more data to read*/
return false;
}
/*Return true is the touchpad is pressed*/
static bool touchpad_is_pressed(void)
{
/*Your code comes here*/
return false;
}
/*Get the x and y coordinates if the touchpad is pressed*/
static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y)
{
/*Your code comes here*/
(*x) = 0;
(*y) = 0;
}
/*------------------
* Mouse
* -----------------*/
/* Initialize your mouse */
static void mouse_init(void)
{
/*Your code comes here*/
}
/* Will be called by the library to read the mouse */
static bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
/*Get the current x and y coordinates*/
mouse_get_xy(&data->point.x, &data->point.y);
/*Get whether the mouse button is pressed or released*/
if(mouse_is_pressed()) {
data->state = LV_INDEV_STATE_PR;
} else {
data->state = LV_INDEV_STATE_REL;
}
/*Return `false` because we are not buffering and no more data to read*/
return false;
}
/*Return true is the mouse button is pressed*/
static bool mouse_is_pressed(void)
{
/*Your code comes here*/
return false;
}
/*Get the x and y coordinates if the mouse is pressed*/
static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y)
{
/*Your code comes here*/
(*x) = 0;
(*y) = 0;
}
/*------------------
* Keypad
* -----------------*/
/* Initialize your keypad */
static void keypad_init(void)
{
/*Your code comes here*/
}
/* Will be called by the library to read the mouse */
static bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
static uint32_t last_key = 0;
/*Get the current x and y coordinates*/
mouse_get_xy(&data->point.x, &data->point.y);
/*Get whether the a key is pressed and save the pressed key*/
uint32_t act_key = keypad_get_key();
if(act_key != 0) {
data->state = LV_INDEV_STATE_PR;
/*Translate the keys to LittlevGL control characters according to your key definitions*/
switch(act_key) {
case 1:
act_key = LV_KEY_NEXT;
break;
case 2:
act_key = LV_KEY_PREV;
break;
case 3:
act_key = LV_KEY_LEFT;
break;
case 4:
act_key = LV_KEY_RIGHT;
break;
case 5:
act_key = LV_KEY_ENTER;
break;
}
last_key = act_key;
} else {
data->state = LV_INDEV_STATE_REL;
}
data->key = last_key;
/*Return `false` because we are not buffering and no more data to read*/
return false;
}
/*Get the currently being pressed key. 0 if no key is pressed*/
static uint32_t keypad_get_key(void)
{
/*Your code comes here*/
return 0;
}
/*------------------
* Encoder
* -----------------*/
/* Initialize your keypad */
static void encoder_init(void)
{
/*Your code comes here*/
}
/* Will be called by the library to read the encoder */
static bool encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
data->enc_diff = encoder_diff;
data->state = encoder_state;
/*Return `false` because we are not buffering and no more data to read*/
return false;
}
/*Call this function in an interrupt to process encoder events (turn, press)*/
static void encoder_handler(void)
{
/*Your code comes here*/
encoder_diff += 0;
encoder_state = LV_INDEV_STATE_REL;
}
/*------------------
* Button
* -----------------*/
/* Initialize your buttons */
static void button_init(void)
{
/*Your code comes here*/
}
/* Will be called by the library to read the button */
static bool button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
static uint8_t last_btn = 0;
/*Get the pressed button's ID*/
int8_t btn_act = button_get_pressed_id();
if(btn_act >= 0) {
data->state = LV_INDEV_STATE_PR;
last_btn = btn_act;
} else {
data->state = LV_INDEV_STATE_REL;
}
/*Save the last pressed button's ID*/
data->btn_id = last_btn;
/*Return `false` because we are not buffering and no more data to read*/
return false;
}
/*Get ID (0, 1, 2 ..) of the pressed button*/
static int8_t button_get_pressed_id(void)
{
uint8_t i;
/*Check to buttons see which is being pressed (assume there are 2 buttons)*/
for(i = 0; i < 2; i++) {
/*Return the pressed button's ID*/
if(button_is_pressed(i)) {
return i;
}
}
/*No button pressed*/
return -1;
}
/*Test if `id` button is pressed or not*/
static bool button_is_pressed(uint8_t id)
{
/*Your code comes here*/
return false;
}
#else /* Enable this file at the top */
/* This dummy typedef exists purely to silence -Wpedantic. */
typedef int keep_pedantic_happy;
#endif
|
the_stack_data/11872.c | #include <unistd.h>
#define EVEN(N) (N % 2) == (0)
//#XXXX SUCCESS XXXXXX
#define EVEN_MSG "I have an even number of arguments."
#define ODD_MSG "I have an odd number of arguments."
typedef enum s_bool
{
TRUE,
FALSE
} t_bool;
void my_putchar(char c)
{
write(1, &c, 1);
}
void my_putstr(char *str)
{
int index;
index = 0;
while (str[index] != '\0') {
my_putchar(str[index]);
index++;
}
}
t_bool my_is_even(int nbr)
{
return ((EVEN(nbr)) ? TRUE : FALSE);
}
void my_define(int argc)
{
if (my_is_even(argc) == TRUE) {
my_putstr(EVEN_MSG);
my_putchar('\n');
}
else {
my_putstr(ODD_MSG);
my_putchar('\n');
}
}
|
the_stack_data/99776.c | //Classification: p/BO/AE/dA/D(A(v))/fr/rp
//Written by: Sergey Pomelov
//Reviewed by:
//Comment:
#include <stdio.h>
#include <malloc.h>
int *func(int *q) {
int i;
for(i=0;i<32;i++) {
q[i] = i;
}
return q;
}
int main(void)
{
int* a;
if((a = (int*)malloc(32*sizeof(int)))==NULL) {
printf("malloc error");
return 1;
}
printf("%d",*(func(a)+31));
free(a);
return 0;
}
|
the_stack_data/72011525.c | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
int a[200];
int mm(int l,int r,int n)
{
int sum=0;
for(int j=l;j<=r;j++)
sum+=a[j];
sum=sum%n;
return sum;
}
int nn(int l,int r,int n)
{
int sum=1;
for(int j=l;j<=r;j++)
sum=(sum*a[j])%n;
return sum;
}
int hh(int l,int r)
{
int sum=0;
for(int j=l;j<=r;j++)
sum=sum^a[j];
return sum;
}
int main()
{
int n,k,i,j,m,l[200],r[200],p;
scanf("%d%d",&n,&k);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<k;i++)
scanf("%d%d",&l[i],&r[i]);
for(i=0;i<k;i++)
{
m=mm(l[i],r[i],n);
p=nn(l[i],r[i],n);
if(m>p)
printf("%d\n",hh(p,m));
else
printf("%d\n",hh(m,p));
}
return 0;
} |
the_stack_data/62638185.c | // Fig. 5.18: fig05_18.c
// Recursive factorial function.
#include <stdio.h>
unsigned long long int factorial(unsigned int number);
int main(int argc, char const *argv[]) {
unsigned int i;
// during each iteration, calculate
// factorial(i) and display result
for (i = 0; i <= 21; i++) {
printf("%u! = %llu\n", i, factorial(i));
}
}
// recursive definition of function factorial
unsigned long long int factorial(unsigned int number) {
// base case
if (number <= 0) {
return 1;
} else {
return number * factorial(number -1);
}
}
|
the_stack_data/243892042.c | /* Example: C program to find area of a circle */
#include <stdio.h>
#define PI 3.14159
int main()
{
float r, a, m, c;
while(0 == 0){
printf("Enter radius (in mm):\n");
scanf("%f", &m);
if(m == 0){
printf("Exit\n");
break;
}
r = m/25.4;
c = 2 * PI * r;
a = PI * r * r;
printf("Circle's area is %3.2f (sq in).\n", a);
printf("Its circumference is %3.2f (in).\n", c);
}
}
|
the_stack_data/79230.c | #define _Noreturn
#undef __BLOCKS__
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#if defined(__GNUC__) || defined(__WATCOMC__) || defined(__WIN32__)
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#define __USE_LARGEFILE64
#include <fcntl.h>
#if defined(__linux__) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__) && !defined(__i386__)
// From https://stackoverflow.com/questions/58472958/how-to-force-linkage-to-older-libc-fcntl-instead-of-fcntl64
asm(".symver fcntl64,fcntl@GLIBC_2.2.5");
asm(".symver __xstat,__xstat@GLIBC_2.2.5");
asm(".symver __fxstat,__fxstat@GLIBC_2.2.5");
int __xstat (int __ver, const char *__filename, struct stat *__stat_buf);
int __fxstat (int __ver, int fd, struct stat *__stat_buf);
#define stat(a, b) stat_glibcwrapper(a, b)
#define fstat(a, b) fstat_glibcwrapper(a, b)
__attribute__((visibility("default"))) int stat_glibcwrapper(const char *fn, struct stat * buf)
{ // 1 for 64 bit, 3 for 32 bit
return __xstat(1, fn, buf);
}
__attribute__((visibility("default"))) int fstat_glibcwrapper(int fd, struct stat * buf)
{ // 1 for 64 bit, 3 for 32 bit
return __fxstat(1, fd, buf);
}
__attribute__((visibility("default"))) int __wrap_fcntl64(int fd, int cmd, ...)
{
int result;
va_list va;
va_start(va, cmd);
switch (cmd) {
//
// File descriptor flags
//
case F_GETFD: goto takes_void;
case F_SETFD: goto takes_int;
// File status flags
//
case F_GETFL: goto takes_void;
case F_SETFL: goto takes_int;
// File byte range locking, not held across fork() or clone()
//
case F_SETLK: goto takes_flock_ptr_INCOMPATIBLE;
case F_SETLKW: goto takes_flock_ptr_INCOMPATIBLE;
case F_GETLK: goto takes_flock_ptr_INCOMPATIBLE;
#if 0
// File byte range locking, held across fork()/clone() -- Not POSIX
//
case F_OFD_SETLK: goto takes_flock_ptr_INCOMPATIBLE;
case F_OFD_SETLKW: goto takes_flock_ptr_INCOMPATIBLE;
case F_OFD_GETLK: goto takes_flock_ptr_INCOMPATIBLE;
// Managing I/O availability signals
//
case F_GETOWN: goto takes_void;
case F_SETOWN: goto takes_int;
case F_GETOWN_EX: goto takes_f_owner_ex_ptr;
case F_SETOWN_EX: goto takes_f_owner_ex_ptr;
case F_GETSIG: goto takes_void;
case F_SETSIG: goto takes_int;
// Notified when process tries to open or truncate file (Linux 2.4+)
//
case F_SETLEASE: goto takes_int;
case F_GETLEASE: goto takes_void;
// File and directory change notification
//
case F_NOTIFY: goto takes_int;
// Changing pipe capacity (Linux 2.6.35+)
//
case F_SETPIPE_SZ: goto takes_int;
case F_GETPIPE_SZ: goto takes_void;
// File sealing (Linux 3.17+)
//
case F_ADD_SEALS: goto takes_int;
case F_GET_SEALS: goto takes_void;
// File read/write hints (Linux 4.13+)
//
case F_GET_RW_HINT: goto takes_uint64_t_ptr;
case F_SET_RW_HINT: goto takes_uint64_t_ptr;
case F_GET_FILE_RW_HINT: goto takes_uint64_t_ptr;
case F_SET_FILE_RW_HINT: goto takes_uint64_t_ptr;
#endif
default:
fprintf(stderr, "fcntl64 workaround got unknown F_XXX constant");
}
takes_void:
va_end(va);
return fcntl64(fd, cmd);
takes_int:
result = fcntl64(fd, cmd, va_arg(va, int));
va_end(va);
return result;
takes_flock_ptr_INCOMPATIBLE:
//
// !!! This is the breaking case: the size of the flock
// structure changed to accommodate larger files. If you
// need this, you'll have to define a compatibility struct
// with the older glibc and make your own entry point using it,
// then call fcntl64() with it directly (bear in mind that has
// been remapped to the old fcntl())
//
fprintf(stderr, "fcntl64 hack can't use glibc flock directly");
exit(1);
#if 0
takes_f_owner_ex_ptr:
result = fcntl64(fd, cmd, va_arg(va, struct f_owner_ex*));
va_end(va);
return result;
takes_uint64_t_ptr:
result = fcntl64(fd, cmd, va_arg(va, uint64_t*));
va_end(va);
return result;
#endif
}
#endif
#endif
#if defined(__unix__) || defined(__APPLE__)
#include <utime.h>
#endif
#if defined(__WIN32__)
#define WIN32_LEAN_AND_MEAN
#define UNICODE
#include <windows.h>
#include <io.h>
#else
#include <unistd.h>
#endif
typedef int bool;
typedef unsigned char byte;
typedef unsigned short uint16;
typedef unsigned int uint;
typedef unsigned int FileSize;
typedef long long int64;
typedef unsigned long long uint64;
#define false 0
#define true 1
#define null ((void *)0)
#define MAX_LOCATION 797
#define MAX_FILENAME 274
void __ecereNameSpace__ecere__com__eSystem_Delete(void * memory);
void * __ecereNameSpace__ecere__com__eSystem_New0(unsigned int size);
void * __ecereNameSpace__ecere__com__eSystem_Renew(void * memory, unsigned int size);
void * __ecereNameSpace__ecere__com__eSystem_Renew0(void * memory, unsigned int size);
unsigned short * __ecereNameSpace__ecere__sys__UTF8toUTF16(const char * source, int * wordCount);
unsigned short * __ecereNameSpace__ecere__sys__UTF8toUTF16Buffer(const char * source, uint16 * dest, int max);
char * __ecereNameSpace__ecere__sys__UTF16toUTF8(const uint16 * source);
void __ecereNameSpace__ecere__sys__ChangeCh(char * string, char ch1, char ch2);
#if defined(__WIN32__) || defined(__WATCOMC__)
#include <direct.h>
__declspec(dllimport) BOOL WINAPI GetVolumePathName(LPCTSTR lpszFileName,LPTSTR lpszVolumePathName,DWORD cchBufferLength);
#else
#include <dirent.h>
#endif
typedef unsigned int FileAttribs;
typedef int64 SecSince1970;
typedef SecSince1970 TimeStamp;
typedef enum
{
FOM_read = 1,
FOM_write,
FOM_append,
FOM_readWrite,
FOM_writeRead,
FOM_appendRead
} FileOpenMode;
typedef enum
{
unlocked = 0, // LOCK_UN _SH_DENYNO
shared = 1, // LOCK_SH _SH_DENYWR
exclusive = 2 // LOCK_EX _SH_DENYRW
} FileLock;
#define isFile 0x0001
#define isArchive 0x0002
#define isHidden 0x0004
#define isReadOnly 0x0008
#define isSystem 0x0010
#define isTemporary 0x0020
#define isDirectory 0x0040
#define isDrive 0x0080
#define isCDROM 0x0100
#define isRemote 0x0200
#define isRemovable 0x0400
#define isServer 0x0800
#define isShare 0x1000
typedef struct
{
FileAttribs attribs;
uint64 size;
SecSince1970 accessed;
SecSince1970 modified;
SecSince1970 created;
} FileStats;
char * __ecereNameSpace__ecere__sys__GetLastDirectory(const char * string, char * output);
bool __ecereNameSpace__ecere__sys__SplitArchivePath(const char * fileName, char * archiveName, char ** archiveFile);
#if defined(__WIN32__) && !defined(ECERE_BOOTSTRAP)
void __ecereMethod___ecereNameSpace__ecere__sys__EARFileSystem_FixCase(const char * archive, char * name);
#if !defined(__UWP__)
static BOOL CALLBACK EnumThreadWindowsProc(HWND hwnd, LPARAM lParam)
{
DWORD pid;
if(IsWindowVisible(hwnd) && GetWindowThreadProcessId(hwnd, &pid) && pid == GetCurrentProcessId())
{
*(void **)lParam = hwnd;
return FALSE;
}
return TRUE;
}
bool WinReviveNetworkResource(uint16 * _wfileName)
{
bool result = false;
HWND windowHandle = null;
NETRESOURCE nr = { 0 };
nr.dwType = RESOURCETYPE_DISK;
nr.lpRemoteName = _wfileName;
if(_wfileName[0] != '\\' || _wfileName[1] == '\\')
{
uint16 volumePathName[MAX_LOCATION];
if(GetVolumePathName(_wfileName, volumePathName, MAX_LOCATION))
{
uint16 remoteName[MAX_LOCATION];
DWORD size = MAX_LOCATION;
volumePathName[wcslen(volumePathName)-1] = 0;
if(WNetGetConnection(volumePathName, remoteName, &size) == ERROR_CONNECTION_UNAVAIL)
{
nr.lpRemoteName = remoteName;
nr.lpLocalName = volumePathName;
}
else
return false;
}
else
return false;
}
EnumThreadWindows(GetCurrentThreadId(), EnumThreadWindowsProc, (LPARAM)&windowHandle);
if(!windowHandle)
{
EnumWindows(EnumThreadWindowsProc, (LPARAM)&windowHandle);
}
if(WNetAddConnection3(windowHandle, &nr, null, null, CONNECT_INTERACTIVE|CONNECT_PROMPT) == NO_ERROR)
result = true;
return result;
}
#endif
TimeStamp Win32FileTimeToTimeStamp(FILETIME * fileTime);
void TimeStampToWin32FileTime(TimeStamp t, FILETIME * fileTime);
#endif
uint FILE_GetSize(FILE * input)
{
if(input)
{
struct stat s;
int fd = fileno(input);
if(!fstat(fd, &s))
return s.st_size;
}
return 0;
}
bool FILE_Lock(FILE * input, FILE * output, FileLock type, uint64 start, uint64 length, bool wait)
{
if(!output && !input)
return true;
else
{
#if defined(__WIN32__)
int handle = fileno(output ? output : input);
HANDLE hFile = (HANDLE)_get_osfhandle(handle);
OVERLAPPED overlapped = { 0 };
overlapped.Offset = (uint)(start & 0xFFFFFFFF);
overlapped.OffsetHigh = (uint)((start & 0xFFFFFFFF00000000LL) >> 32);
if(type == unlocked)
return UnlockFileEx(hFile, 0,
(uint)(length ? (length & 0xFFFFFFFF) : 0xFFFFFFFF),
(uint)(length ? ((length & 0xFFFFFFFF00000000LL) >> 32) : 0xFFFFFFFF),
&overlapped) != 0;
else
return LockFileEx(hFile, ((type == exclusive) ? LOCKFILE_EXCLUSIVE_LOCK : 0) | (wait ? 0 : LOCKFILE_FAIL_IMMEDIATELY), 0,
(uint)(length ? (length & 0xFFFFFFFF) : 0xFFFFFFFF),
(uint)(length ? ((length & 0xFFFFFFFF00000000LL) >> 32) : 0xFFFFFFFF),
&overlapped) != 0;
#else
struct flock fl;
int fd;
fl.l_type = (type == unlocked) ? F_UNLCK : ((type == exclusive) ? F_WRLCK : F_RDLCK);
fl.l_whence = SEEK_SET;
fl.l_start = start;
fl.l_len = length;
fl.l_pid = getpid();
fd = fileno(output ? output : input);
return fcntl(fd, wait ? F_SETLKW : F_SETLK, &fl) != -1;
#endif
}
}
void FILE_set_buffered(FILE * input, FILE * output, bool value)
{
#if !defined(__WIN32__) && !defined(ECERE_BOOTSTRAP)
if(input)
setvbuf(input, null, value ? _IOFBF : _IONBF, 0);
if(output && output != input)
setvbuf(output, null, value ? _IOFBF : _IONBF, 0);
#endif
}
FileAttribs FILE_FileExists(const char * fileName)
{
#ifdef __WIN32__
FileAttribs result = 0;
uint attribute = 0; // Initialization isn't actually required here but GCC complains about it.
uint16 * _wfileName = __ecereNameSpace__ecere__sys__UTF8toUTF16(fileName, null);
if(!strcmp(fileName, "/") || !strcmp(fileName, "\\\\"))
{
result = (FileAttribs)(isDirectory);
}
else
attribute = GetFileAttributes(_wfileName);
#if !defined(ECERE_BOOTSTRAP) && !defined(__UWP__)
if(!result && attribute == 0xFFFFFFFF)
{
if(WinReviveNetworkResource(_wfileName))
attribute = GetFileAttributes(_wfileName);
if(attribute == 0xFFFFFFFF)
{
if(fileName[0] == '\\' && fileName[1] == '\\')
{
NETRESOURCE nr = { 0 };
NETRESOURCE * buffer = null;
unsigned int size = sizeof(NETRESOURCE);
uint16 * dir;
nr.dwScope = RESOURCE_GLOBALNET;
nr.dwType = RESOURCETYPE_DISK;
nr.lpRemoteName = _wfileName;
nr.lpProvider = L"Microsoft Windows Network";
buffer = (NETRESOURCE *)__ecereNameSpace__ecere__com__eSystem_New0(size);
while(true)
{
int returnCode = WNetGetResourceInformationW(&nr, buffer, (DWORD *)&size, &dir);
if(returnCode == WN_MORE_DATA)
buffer = (NETRESOURCE *)__ecereNameSpace__ecere__com__eSystem_Renew0(buffer, size);
else
{
if(returnCode == WN_SUCCESS)
{
if(!_wcsicmp(buffer->lpRemoteName, _wfileName))
result = (FileAttribs)( isDirectory | isServer );
}
break;
}
}
__ecereNameSpace__ecere__com__eSystem_Delete(buffer);
}
}
}
#endif
if(!result && attribute != 0xFFFFFFFF)
{
if(attribute & FILE_ATTRIBUTE_DIRECTORY)
result = (FileAttribs)( isDirectory );
else
result = (FileAttribs)(isFile);
}
__ecereNameSpace__ecere__com__eSystem_Delete(_wfileName);
return result;
#else
if(!access(fileName, F_OK))
{
struct stat s;
stat(fileName, &s);
return S_ISDIR(s.st_mode) ? (FileAttribs) ( isDirectory ) : (FileAttribs) ( isFile );
}
else
{
// TODO: Check this
return (FileAttribs) 0;
}
#endif
}
bool FILE_FileGetSize(const char * fileName, FileSize * size)
{
bool result = false;
#if defined(__WIN32__)
struct _stat s;
uint16 * _wfileName = __ecereNameSpace__ecere__sys__UTF8toUTF16(fileName, null);
if(!_wstat(_wfileName, &s))
#else
struct stat s;
if(!stat(fileName, &s))
#endif
{
*size = s.st_size;
result = true;
}
#if defined(__WIN32__)
__ecereNameSpace__ecere__com__eSystem_Delete(_wfileName);
#endif
return result;
}
bool FILE_FileGetStats(const char * fileName, FileStats * stats)
{
bool result = false;
#if defined(__WIN32__)
uint16 * _wfileName = __ecereNameSpace__ecere__sys__UTF8toUTF16(fileName, null);
struct _stat s;
if(!_wstat(_wfileName, &s))
#else
struct stat s;
if(!stat(fileName, &s))
#endif
{
stats->size = s.st_size;
stats->attribs = (s.st_mode & S_IFDIR) ? ((FileAttribs) (isDirectory)): ((FileAttribs) 0);
#if defined(__WIN32__) && !defined(__UWP__)
{
HANDLE hFile = CreateFile(_wfileName, 0, FILE_SHARE_READ, null,
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, null);
if(hFile != INVALID_HANDLE_VALUE)
{
#if defined(ECERE_BOOTSTRAP)
stats->created = 0;
stats->accessed = 0;
stats->modified = 0;
#else
FILETIME c, a, m;
GetFileTime(hFile, &c, &a, &m);
stats->created = Win32FileTimeToTimeStamp(&c);
stats->accessed = Win32FileTimeToTimeStamp(&a);
stats->modified = Win32FileTimeToTimeStamp(&m);
#endif
CloseHandle(hFile);
}
}
#else
stats->accessed = s.st_atime;
// UNIX st_ctime is 'status change' time, not creation time
// Marking created as 0, as ctime changes cause unreproducible builds
stats->created = 0;
stats->modified = s.st_mtime;
#endif
/*
stats->attribs.isArchive = (winFile.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) ? true : false;
stats->attribs.isHidden = (winFile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ? true : false;
stats->attribs.isReadOnly = (winFile.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? true : false;
stats->attribs.isSystem = (winFile.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) ? true : false;
stats->attribs.isTemporary = (winFile.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) ? true : false;
stats->attribs.isDirectory = (winFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? true : false;
*/
result = true;
}
#if defined(__WIN32__)
__ecereNameSpace__ecere__com__eSystem_Delete(_wfileName);
#endif
return result;
}
void FILE_FileFixCase(char * file)
{
#if defined(__WIN32__)
#ifndef ECERE_BOOTSTRAP
char archive[MAX_LOCATION], * name;
if(__ecereNameSpace__ecere__sys__SplitArchivePath(file, archive, &name))
{
char fileName[MAX_LOCATION];
strcpy(fileName, name);
__ecereMethod___ecereNameSpace__ecere__sys__EARFileSystem_FixCase(archive, fileName);
if(archive[0] != ':')
FILE_FileFixCase(archive);
sprintf(file, "<%s>%s", archive, fileName);
}
else
#endif
{
int c = 0;
char parent[MAX_LOCATION] = "";
// Skip network protocols
if(strstr(file, "http://") == file || strstr(file, "https://") == file || strstr(file, "wfs://") == file || strstr(file, "wfs3://") == file || strstr(file, "wfs3s://") == file) return;
// Copy drive letter to new path
if(file[0] && file[1] == ':')
{
parent[0] = (char)toupper(file[0]);
parent[1] = ':';
parent[2] = '\0';
c = 2;
}
// Copy Microsoft Network string to new path
else if(file[0] == '\\' && file[1] == '\\')
{
parent[0] = parent[1] = '\\';
parent[2] = '\0';
c = 2;
}
else if(file[0] == '/' && file[1] == '/')
{
parent[0] = parent[1] = '\\';
parent[2] = '\0';
c = 2;
}
// Copy Entire Computer to new path
else if(file[0] == '/' && !file[1])
{
parent[0] = '/';
parent[1] = '\0';
c = 1;
}
while(file[c])
{
// Get next directory
char directory[MAX_FILENAME];
int len = 0;
char ch;
for(;(ch = file[c]) && (ch == '/' || ch == '\\'); c++);
for(;(ch = file[c]) && (ch != '/' && ch != '\\'); c++)
{
if(len < MAX_FILENAME)
directory[len++] = ch;
}
directory[len] = '\0';
// Normal file
if(parent[0] != '\\' || parent[1] != '\\' || strstr(parent+2, "\\"))
{
if(strcmp(directory, "..") && strcmp(directory, "."))
{
WIN32_FIND_DATA winFile;
uint16 dir[MAX_PATH];
HANDLE handle;
__ecereNameSpace__ecere__sys__UTF8toUTF16Buffer(parent, dir, MAX_PATH);
if(dir[0]) wcscat(dir, L"\\");
{
uint16 * _wdirectory = __ecereNameSpace__ecere__sys__UTF8toUTF16(directory, null);
wcscat(dir, _wdirectory);
__ecereNameSpace__ecere__com__eSystem_Delete(_wdirectory);
}
handle = FindFirstFile(dir, &winFile);
if(parent[0] || (file[0] == '\\' || file[0] == '/'))
strcat(parent, "\\");
if(handle != INVALID_HANDLE_VALUE)
{
char * utf8 = __ecereNameSpace__ecere__sys__UTF16toUTF8(winFile.cFileName);
strcat(parent, utf8);
__ecereNameSpace__ecere__com__eSystem_Delete(utf8);
FindClose(handle);
}
else
strcat(parent, directory);
}
else
{
if(parent[0] || (file[0] == '\\' || file[0] == '/'))
strcat(parent, "\\");
strcat(parent, directory);
}
}
#if !defined(ECERE_BOOTSTRAP) && !defined(__UWP__)
else
{
// Network server
if(parent[2])
{
HANDLE handle = 0;
DWORD count = 0xFFFFFFFF;
DWORD size = 512 * sizeof(NETRESOURCE);
NETRESOURCE * buffer = (NETRESOURCE *)__ecereNameSpace__ecere__com__eSystem_New0(size);
NETRESOURCE nr = {0};
int c;
nr.dwScope = RESOURCE_GLOBALNET;
nr.dwType = RESOURCETYPE_DISK;
// UNICODE FIX
nr.lpRemoteName = __ecereNameSpace__ecere__sys__UTF8toUTF16(parent, null);
nr.lpProvider = L"Microsoft Windows Network";
// Server
WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, 0, &nr, &handle);
if(handle)
{
while(true)
{
int returnCode = WNetEnumResource(handle, &count, buffer, &size);
if(returnCode != ERROR_MORE_DATA)
break;
count = 0xFFFFFFFF;
buffer = (NETRESOURCE *)__ecereNameSpace__ecere__com__eSystem_Renew0(buffer, size);
}
WNetCloseEnum(handle);
}
else
count = 0;
for(c = 0; c<count; c++)
{
char shareName[MAX_FILENAME];
char * remoteName = __ecereNameSpace__ecere__sys__UTF16toUTF8(buffer[c].lpRemoteName);
__ecereNameSpace__ecere__sys__GetLastDirectory(remoteName, shareName);
__ecereNameSpace__ecere__com__eSystem_Delete(remoteName);
if(!strcmpi(directory, shareName))
{
strcpy(directory, shareName);
break;
}
}
if(c == count)
strlwr(directory);
__ecereNameSpace__ecere__com__eSystem_Delete(nr.lpRemoteName);
__ecereNameSpace__ecere__com__eSystem_Delete(buffer);
strcat(parent, "\\");
strcat(parent, directory);
}
// Network share
else
{
strlwr(directory);
directory[0] = (char)toupper(directory[0]);
strcat(parent, directory);
}
}
#endif
}
strcpy(file, parent);
}
#else
__ecereNameSpace__ecere__sys__ChangeCh(file, '\\', '/');
#endif
}
void FILE_FileOpen(const char * fileName, FileOpenMode mode, FILE ** input, FILE **output)
{
#if defined(__WIN32__) && !defined(ECERE_BOOTSTRAP)
uint16 * _wfileName = __ecereNameSpace__ecere__sys__UTF8toUTF16(fileName, null);
/*
struct WinFile { HANDLE handle; } file;
file.handle = CreateFile(_wfileName,
((mode == FOM_read || mode == FOM_readWrite || mode == FOM_writeRead || mode == FOM_appendRead) ? GENERIC_READ : 0) |
((mode == FOM_write || mode == FOM_append || mode == FOM_readWrite || mode == FOM_writeRead || mode == FOM_appendRead) ? GENERIC_WRITE: 0),
FILE_SHARE_READ|FILE_SHARE_WRITE,
null,
(mode == FOM_write || mode == FOM_writeRead) ? TRUNCATE_EXISTING : ((mode == FOM_read || mode == FOM_readWrite) ? OPEN_EXISTING : OPEN_ALWAYS), 0, null);
if(file.handle)
{
int flags;
int handle = -1;
switch(mode)
{
case FOM_read: handle = _open_osfhandle((intptr_t)file.handle, _O_RDONLY); break;
case FOM_write: handle = _open_osfhandle((intptr_t)file.handle, _O_WRONLY | _O_CREAT | _O_TRUNC); break;
case FOM_append: handle = _open_osfhandle((intptr_t)file.handle, _O_WRONLY | _O_CREAT | _O_APPEND); break;
case FOM_readWrite: handle = _open_osfhandle((intptr_t)file.handle, _O_RDWR); break;
case FOM_writeRead: handle = _open_osfhandle((intptr_t)file.handle, _O_RDWR | _O_CREAT | _O_TRUNC); break;
case FOM_appendRead: handle = _open_osfhandle((intptr_t)file.handle, _O_RDWR | _O_APPEND | _O_CREAT); break;
}
if(handle != -1)
{
switch(mode)
{
case FOM_read: *input = _fdopen(handle, "rb"); break;
case FOM_write: *output = _fdopen(handle, "wb"); break;
case FOM_append: *output = _fdopen(handle, "ab"); break;
case FOM_readWrite: *input = *output = _fdopen(handle, "r+b"); break;
case FOM_writeRead: *input = *output = _fdopen(handle, "w+b"); break;
case FOM_appendRead: *input = *output = _fdopen(handle, "a+b"); break;
}
}
}
*/
switch(mode)
{
case FOM_read: *input = _wfopen(_wfileName, L"rb"); break;
case FOM_write: *output = _wfopen(_wfileName, L"wb"); break;
case FOM_append: *output = _wfopen(_wfileName, L"ab"); break;
case FOM_readWrite: *input = *output = _wfopen(_wfileName, L"r+b"); break;
case FOM_writeRead: *input = *output = _wfopen(_wfileName, L"w+b"); break;
case FOM_appendRead: *input = *output = _wfopen(_wfileName, L"a+b"); break;
}
#if !defined(__UWP__)
if(!mode && WinReviveNetworkResource(_wfileName))
{
switch(mode)
{
case FOM_read: *input = _wfopen(_wfileName, L"rb"); break;
case FOM_write: *output = _wfopen(_wfileName, L"wb"); break;
case FOM_append: *output = _wfopen(_wfileName, L"ab"); break;
case FOM_readWrite: *input = *output = _wfopen(_wfileName, L"r+b"); break;
case FOM_writeRead: *input = *output = _wfopen(_wfileName, L"w+b"); break;
case FOM_appendRead: *input = *output = _wfopen(_wfileName, L"a+b"); break;
}
}
#endif
__ecereNameSpace__ecere__com__eSystem_Delete(_wfileName);
#else
switch(mode)
{
case FOM_read: *input = fopen(fileName, "rb"); break;
case FOM_write: *output = fopen(fileName, "wb"); break;
case FOM_append: *output = fopen(fileName, "ab"); break;
case FOM_readWrite: *input = *output = fopen(fileName, "r+b"); break;
case FOM_writeRead: *input = *output = fopen(fileName, "w+b"); break;
case FOM_appendRead: *input = *output = fopen(fileName, "a+b"); break;
}
#endif
}
int FILE_Seek64(FILE * f, int64 offset, int origin)
{
#if defined(__WIN32__)
#if 1 //!defined(_WIN64) // _fseeki64 is not working well with SEEK_CUR?
if(origin == SEEK_CUR) // fseek with -1, SEEK_CUR failing in 32-bit with MinGW-w64 ?
return fseek(f, offset, origin);
#endif
return _fseeki64(f, offset, origin);
#else
return fseek(f, offset, origin);
#endif
}
|
the_stack_data/6471.c | /*
* Copyright (C) 2009 Gabor Juhos <[email protected]>
*
* This tool was based on:
* TP-Link WR941 V2 firmware checksum fixing tool.
* Copyright (C) 2008,2009 Wang Jian <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h> /* for unlink() */
#include <libgen.h>
#include <getopt.h> /* for getopt() */
#include <stdarg.h>
#include <errno.h>
#include <stdbool.h>
#include <endian.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include "md5.h"
#define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
#define MD5SUM_LEN 16
struct file_info {
char *file_name; /* name of the file */
uint32_t file_size; /* length of the file */
};
struct fw_header {
uint32_t version; /* 0x00: header version */
char fw_version[48]; /* 0x04: fw version string */
uint32_t hw_id; /* 0x34: hardware id */
uint32_t hw_rev; /* 0x38: FIXME: hardware revision? */
uint32_t unk1; /* 0x3c: 0x00000000 */
uint8_t md5sum1[MD5SUM_LEN]; /* 0x40 */
uint32_t unk2; /* 0x50: 0x00000000 */
uint8_t md5sum2[MD5SUM_LEN]; /* 0x54 */
uint32_t unk3; /* 0x64: 0xffffffff */
uint32_t kernel_la; /* 0x68: kernel load address */
uint32_t kernel_ep; /* 0x6c: kernel entry point */
uint32_t fw_length; /* 0x70: total length of the image */
uint32_t kernel_ofs; /* 0x74: kernel data offset */
uint32_t kernel_len; /* 0x78: kernel data length */
uint32_t rootfs_ofs; /* 0x7c: rootfs data offset */
uint32_t rootfs_len; /* 0x80: rootfs data length */
uint32_t boot_ofs; /* 0x84: FIXME: seems to be unused */
uint32_t boot_len; /* 0x88: FIXME: seems to be unused */
uint16_t unk4; /* 0x8c: 0x55aa */
uint8_t sver_hi; /* 0x8e */
uint8_t sver_lo; /* 0x8f */
uint8_t unk5; /* 0x90: magic: 0xa5 */
uint8_t ver_hi; /* 0x91 */
uint8_t ver_mid; /* 0x92 */
uint8_t ver_lo; /* 0x93 */
uint8_t pad[364];
} __attribute__ ((packed));
struct flash_layout {
char *id;
uint32_t fw_max_len;
uint32_t kernel_la;
uint32_t kernel_ep;
uint32_t rootfs_ofs;
};
struct board_info {
char *id;
uint32_t hw_id;
uint32_t hw_rev;
char *layout_id;
uint32_t hdr_ver;
bool endian_swap;
};
/*
* Globals
*/
static char *ofname;
static char *progname;
static char *vendor = "TP-LINK Technologies";
static char *version = "ver. 1.0";
static char *fw_ver = "0.0.0";
static char *sver = "1.0";
static uint32_t hdr_ver = 2;
static char *board_id;
static struct board_info *board;
static char *layout_id;
static struct flash_layout *layout;
static char *opt_hw_id;
static uint32_t hw_id;
static char *opt_hw_rev;
static uint32_t hw_rev;
static int fw_ver_lo;
static int fw_ver_mid;
static int fw_ver_hi;
static int sver_lo;
static int sver_hi;
static struct file_info kernel_info;
static uint32_t kernel_la = 0;
static uint32_t kernel_ep = 0;
static uint32_t kernel_len = 0;
static struct file_info rootfs_info;
static uint32_t rootfs_ofs = 0;
static uint32_t rootfs_align;
static struct file_info boot_info;
static int combined;
static int strip_padding;
static int add_jffs2_eof;
static unsigned char jffs2_eof_mark[4] = {0xde, 0xad, 0xc0, 0xde};
static struct file_info inspect_info;
static int extract = 0;
static bool endian_swap = false;
char md5salt_normal[MD5SUM_LEN] = {
0xdc, 0xd7, 0x3a, 0xa5, 0xc3, 0x95, 0x98, 0xfb,
0xdc, 0xf9, 0xe7, 0xf4, 0x0e, 0xae, 0x47, 0x37,
};
char md5salt_boot[MD5SUM_LEN] = {
0x8c, 0xef, 0x33, 0x5b, 0xd5, 0xc5, 0xce, 0xfa,
0xa7, 0x9c, 0x28, 0xda, 0xb2, 0xe9, 0x0f, 0x42,
};
static struct flash_layout layouts[] = {
{
.id = "8Mltq",
.fw_max_len = 0x7a0000,
.kernel_la = 0x80002000,
.kernel_ep = 0x80002000,
.rootfs_ofs = 0x140000,
}, {
.id = "16Mltq",
.fw_max_len = 0xf90000,
.kernel_la = 0x80002000,
.kernel_ep = 0x800061b0,
.rootfs_ofs = 0x140000,
}, {
.id = "8Mmtk",
.fw_max_len = 0x7a0000,
.kernel_la = 0x80000000,
.kernel_ep = 0x80000000,
.rootfs_ofs = 0x140000,
}, {
/* terminating entry */
}
};
static struct board_info boards[] = {
{
.id = "TD-W8970v1",
.hw_id = 0x89700001,
.hw_rev = 1,
.layout_id = "8Mltq",
}, {
.id = "TD-W8980v1",
.hw_id = 0x89800001,
.hw_rev = 14,
.layout_id = "8Mltq",
}, {
.id = "ArcherC20i",
.hw_id = 0xc2000001,
.hw_rev = 58,
.layout_id = "8Mmtk",
.hdr_ver = 3,
.endian_swap = true,
}, {
.id = "ArcherVR200V",
.hw_id = 0x73b70801,
.hw_rev = 0x2f,
.layout_id = "16Mltq",
.hdr_ver = 2,
}, {
.id = "ArcherC50",
.hw_id = 0xc7500001,
.hw_rev = 69,
.layout_id = "8Mmtk",
.hdr_ver = 3,
.endian_swap = true,
}, {
/* terminating entry */
}
};
/*
* Message macros
*/
#define ERR(fmt, ...) do { \
fflush(0); \
fprintf(stderr, "[%s] *** error: " fmt "\n", \
progname, ## __VA_ARGS__ ); \
} while (0)
#define ERRS(fmt, ...) do { \
int save = errno; \
fflush(0); \
fprintf(stderr, "[%s] *** error: " fmt ": %s\n", \
progname, ## __VA_ARGS__, strerror(save)); \
} while (0)
#define DBG(fmt, ...) do { \
fprintf(stderr, "[%s] " fmt "\n", progname, ## __VA_ARGS__ ); \
} while (0)
static struct board_info *find_board(char *id)
{
struct board_info *ret;
struct board_info *board;
ret = NULL;
for (board = boards; board->id != NULL; board++){
if (strcasecmp(id, board->id) == 0) {
ret = board;
break;
}
};
return ret;
}
static struct board_info *find_board_by_hwid(uint32_t hw_id)
{
struct board_info *board;
for (board = boards; board->id != NULL; board++) {
if (hw_id == board->hw_id)
return board;
};
return NULL;
}
static struct flash_layout *find_layout(char *id)
{
struct flash_layout *ret;
struct flash_layout *l;
ret = NULL;
for (l = layouts; l->id != NULL; l++){
if (strcasecmp(id, l->id) == 0) {
ret = l;
break;
}
};
return ret;
}
static void usage(int status)
{
FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;
struct board_info *board;
fprintf(stream, "Usage: %s [OPTIONS...]\n", progname);
fprintf(stream,
"\n"
"Options:\n"
" -B <board> create image for the board specified with <board>\n"
" -c use combined kernel image\n"
" -E <ep> overwrite kernel entry point with <ep> (hexval prefixed with 0x)\n"
" -L <la> overwrite kernel load address with <la> (hexval prefixed with 0x)\n"
" -H <hwid> use hardware id specified with <hwid>\n"
" -W <hwrev> use hardware revision specified with <hwrev>\n"
" -F <id> use flash layout specified with <id>\n"
" -k <file> read kernel image from the file <file>\n"
" -r <file> read rootfs image from the file <file>\n"
" -a <align> align the rootfs start on an <align> bytes boundary\n"
" -R <offset> overwrite rootfs offset with <offset> (hexval prefixed with 0x)\n"
" -o <file> write output to the file <file>\n"
" -s strip padding from the end of the image\n"
" -j add jffs2 end-of-filesystem markers\n"
" -V <version> set image version to <version>\n"
" -v <version> set firmware version to <version>\n"
" -y <version> set secondary version to <version>\n"
" -i <file> inspect given firmware file <file>\n"
" -x extract kernel and rootfs while inspecting (requires -i)\n"
" -h show this screen\n"
);
exit(status);
}
static int get_md5(char *data, int size, char *md5)
{
MD5_CTX ctx;
MD5_Init(&ctx);
MD5_Update(&ctx, data, size);
MD5_Final(md5, &ctx);
}
static int get_file_stat(struct file_info *fdata)
{
struct stat st;
int res;
if (fdata->file_name == NULL)
return 0;
res = stat(fdata->file_name, &st);
if (res){
ERRS("stat failed on %s", fdata->file_name);
return res;
}
fdata->file_size = st.st_size;
return 0;
}
static int read_to_buf(struct file_info *fdata, char *buf)
{
FILE *f;
int ret = EXIT_FAILURE;
f = fopen(fdata->file_name, "r");
if (f == NULL) {
ERRS("could not open \"%s\" for reading", fdata->file_name);
goto out;
}
errno = 0;
fread(buf, fdata->file_size, 1, f);
if (errno != 0) {
ERRS("unable to read from file \"%s\"", fdata->file_name);
goto out_close;
}
ret = EXIT_SUCCESS;
out_close:
fclose(f);
out:
return ret;
}
static int check_options(void)
{
int ret;
if (inspect_info.file_name) {
ret = get_file_stat(&inspect_info);
if (ret)
return ret;
return 0;
} else if (extract) {
ERR("no firmware for inspection specified");
return -1;
}
if (board_id == NULL && opt_hw_id == NULL) {
ERR("either board or hardware id must be specified");
return -1;
}
if (board_id) {
board = find_board(board_id);
if (board == NULL) {
ERR("unknown/unsupported board id \"%s\"", board_id);
return -1;
}
if (layout_id == NULL)
layout_id = board->layout_id;
hw_id = board->hw_id;
hw_rev = board->hw_rev;
if (board->hdr_ver)
hdr_ver = board->hdr_ver;
endian_swap = board->endian_swap;
} else {
if (layout_id == NULL) {
ERR("flash layout is not specified");
return -1;
}
hw_id = strtoul(opt_hw_id, NULL, 0);
if (opt_hw_rev)
hw_rev = strtoul(opt_hw_rev, NULL, 0);
else
hw_rev = 1;
}
layout = find_layout(layout_id);
if (layout == NULL) {
ERR("unknown flash layout \"%s\"", layout_id);
return -1;
}
if (!kernel_la)
kernel_la = layout->kernel_la;
if (!kernel_ep)
kernel_ep = layout->kernel_ep;
if (!rootfs_ofs)
rootfs_ofs = layout->rootfs_ofs;
if (kernel_info.file_name == NULL) {
ERR("no kernel image specified");
return -1;
}
ret = get_file_stat(&kernel_info);
if (ret)
return ret;
kernel_len = kernel_info.file_size;
if (combined) {
if (kernel_info.file_size >
layout->fw_max_len - sizeof(struct fw_header)) {
ERR("kernel image is too big");
return -1;
}
} else {
if (rootfs_info.file_name == NULL) {
ERR("no rootfs image specified");
return -1;
}
ret = get_file_stat(&rootfs_info);
if (ret)
return ret;
if (rootfs_align) {
kernel_len += sizeof(struct fw_header);
kernel_len = ALIGN(kernel_len, rootfs_align);
kernel_len -= sizeof(struct fw_header);
DBG("kernel length aligned to %u", kernel_len);
if (kernel_len + rootfs_info.file_size >
layout->fw_max_len - sizeof(struct fw_header)) {
ERR("images are too big");
return -1;
}
} else {
if (kernel_info.file_size >
rootfs_ofs - sizeof(struct fw_header)) {
ERR("kernel image is too big");
return -1;
}
if (rootfs_info.file_size >
(layout->fw_max_len - rootfs_ofs)) {
ERR("rootfs image is too big");
return -1;
}
}
}
if (ofname == NULL) {
ERR("no output file specified");
return -1;
}
ret = sscanf(fw_ver, "%d.%d.%d", &fw_ver_hi, &fw_ver_mid, &fw_ver_lo);
if (ret != 3) {
ERR("invalid firmware version '%s'", fw_ver);
return -1;
}
ret = sscanf(sver, "%d.%d", &sver_hi, &sver_lo);
if (ret != 2) {
ERR("invalid secondary version '%s'", sver);
return -1;
}
return 0;
}
static void fill_header(char *buf, int len)
{
struct fw_header *hdr = (struct fw_header *)buf;
unsigned ver_len;
memset(hdr, '\xff', sizeof(struct fw_header));
hdr->version = htonl(bswap_32(hdr_ver));
ver_len = strlen(version);
if (ver_len > (sizeof(hdr->fw_version) - 1))
ver_len = sizeof(hdr->fw_version) - 1;
memcpy(hdr->fw_version, version, ver_len);
hdr->fw_version[ver_len] = 0;
hdr->hw_id = htonl(hw_id);
hdr->hw_rev = htonl(hw_rev);
if (boot_info.file_size == 0) {
memcpy(hdr->md5sum1, md5salt_normal, sizeof(hdr->md5sum1));
hdr->boot_ofs = htonl(0);
hdr->boot_len = htonl(0);
} else {
memcpy(hdr->md5sum1, md5salt_boot, sizeof(hdr->md5sum1));
hdr->boot_ofs = htonl(rootfs_ofs + rootfs_info.file_size);
hdr->boot_len = htonl(rootfs_info.file_size);
}
hdr->kernel_la = htonl(kernel_la);
hdr->kernel_ep = htonl(kernel_ep);
hdr->fw_length = htonl(layout->fw_max_len);
hdr->kernel_ofs = htonl(sizeof(struct fw_header));
hdr->kernel_len = htonl(kernel_len);
if (!combined) {
hdr->rootfs_ofs = htonl(rootfs_ofs);
hdr->rootfs_len = htonl(rootfs_info.file_size);
}
hdr->boot_ofs = htonl(0);
hdr->boot_len = htonl(boot_info.file_size);
hdr->unk1 = htonl(0);
hdr->unk2 = htonl(0);
hdr->unk3 = htonl(0xffffffff);
hdr->unk4 = htons(0x55aa);
hdr->unk5 = 0xa5;
hdr->sver_hi = sver_hi;
hdr->sver_lo = sver_lo;
hdr->ver_hi = fw_ver_hi;
hdr->ver_mid = fw_ver_mid;
hdr->ver_lo = fw_ver_lo;
if (endian_swap) {
hdr->kernel_la = bswap_32(hdr->kernel_la);
hdr->kernel_ep = bswap_32(hdr->kernel_ep);
}
get_md5(buf, len, hdr->md5sum1);
}
static int pad_jffs2(char *buf, int currlen)
{
int len;
uint32_t pad_mask;
len = currlen;
pad_mask = (64 * 1024);
while ((len < layout->fw_max_len) && (pad_mask != 0)) {
uint32_t mask;
int i;
for (i = 10; i < 32; i++) {
mask = 1 << i;
if (pad_mask & mask)
break;
}
len = ALIGN(len, mask);
for (i = 10; i < 32; i++) {
mask = 1 << i;
if ((len & (mask - 1)) == 0)
pad_mask &= ~mask;
}
for (i = 0; i < sizeof(jffs2_eof_mark); i++)
buf[len + i] = jffs2_eof_mark[i];
len += sizeof(jffs2_eof_mark);
}
return len;
}
static int write_fw(char *data, int len)
{
FILE *f;
int ret = EXIT_FAILURE;
f = fopen(ofname, "w");
if (f == NULL) {
ERRS("could not open \"%s\" for writing", ofname);
goto out;
}
errno = 0;
fwrite(data, len, 1, f);
if (errno) {
ERRS("unable to write output file");
goto out_flush;
}
DBG("firmware file \"%s\" completed", ofname);
ret = EXIT_SUCCESS;
out_flush:
fflush(f);
fclose(f);
if (ret != EXIT_SUCCESS) {
unlink(ofname);
}
out:
return ret;
}
static int build_fw(void)
{
int buflen;
char *buf;
char *p;
int ret = EXIT_FAILURE;
int writelen = 0;
buflen = layout->fw_max_len;
buf = malloc(buflen);
if (!buf) {
ERR("no memory for buffer\n");
goto out;
}
memset(buf, 0xff, buflen);
p = buf + sizeof(struct fw_header);
ret = read_to_buf(&kernel_info, p);
if (ret)
goto out_free_buf;
writelen = sizeof(struct fw_header) + kernel_len;
if (!combined) {
if (rootfs_align)
p = buf + writelen;
else
p = buf + rootfs_ofs;
ret = read_to_buf(&rootfs_info, p);
if (ret)
goto out_free_buf;
if (rootfs_align)
writelen += rootfs_info.file_size;
else
writelen = rootfs_ofs + rootfs_info.file_size;
if (add_jffs2_eof)
writelen = pad_jffs2(buf, writelen);
}
if (!strip_padding)
writelen = buflen;
fill_header(buf, writelen);
ret = write_fw(buf, writelen);
if (ret)
goto out_free_buf;
ret = EXIT_SUCCESS;
out_free_buf:
free(buf);
out:
return ret;
}
/* Helper functions to inspect_fw() representing different output formats */
static inline void inspect_fw_pstr(char *label, char *str)
{
printf("%-23s: %s\n", label, str);
}
static inline void inspect_fw_phex(char *label, uint32_t val)
{
printf("%-23s: 0x%08x\n", label, val);
}
static inline void inspect_fw_phexpost(char *label,
uint32_t val, char *post)
{
printf("%-23s: 0x%08x (%s)\n", label, val, post);
}
static inline void inspect_fw_phexdef(char *label,
uint32_t val, uint32_t defval)
{
printf("%-23s: 0x%08x ", label, val);
if (val == defval)
printf("(== OpenWrt default)\n");
else
printf("(OpenWrt default: 0x%08x)\n", defval);
}
static inline void inspect_fw_phexexp(char *label,
uint32_t val, uint32_t expval)
{
printf("%-23s: 0x%08x ", label, val);
if (val == expval)
printf("(ok)\n");
else
printf("(expected: 0x%08x)\n", expval);
}
static inline void inspect_fw_phexdec(char *label, uint32_t val)
{
printf("%-23s: 0x%08x / %8u bytes\n", label, val, val);
}
static inline void inspect_fw_phexdecdef(char *label,
uint32_t val, uint32_t defval)
{
printf("%-23s: 0x%08x / %8u bytes ", label, val, val);
if (val == defval)
printf("(== OpenWrt default)\n");
else
printf("(OpenWrt default: 0x%08x)\n", defval);
}
static inline void inspect_fw_pmd5sum(char *label, uint8_t *val, char *text)
{
int i;
printf("%-23s:", label);
for (i=0; i<MD5SUM_LEN; i++)
printf(" %02x", val[i]);
printf(" %s\n", text);
}
static int inspect_fw(void)
{
char *buf;
struct fw_header *hdr;
uint8_t md5sum[MD5SUM_LEN];
struct board_info *board;
int ret = EXIT_FAILURE;
buf = malloc(inspect_info.file_size);
if (!buf) {
ERR("no memory for buffer!\n");
goto out;
}
ret = read_to_buf(&inspect_info, buf);
if (ret)
goto out_free_buf;
hdr = (struct fw_header *)buf;
inspect_fw_pstr("File name", inspect_info.file_name);
inspect_fw_phexdec("File size", inspect_info.file_size);
switch(bswap_32(ntohl(hdr->version))) {
case 2:
case 3:
break;
default:
ERR("file does not seem to have V2/V3 header!\n");
goto out_free_buf;
}
inspect_fw_phexdec("Version 2 Header size", sizeof(struct fw_header));
if (ntohl(hdr->unk1) != 0)
inspect_fw_phexdec("Unknown value 1", hdr->unk1);
memcpy(md5sum, hdr->md5sum1, sizeof(md5sum));
if (ntohl(hdr->boot_len) == 0)
memcpy(hdr->md5sum1, md5salt_normal, sizeof(md5sum));
else
memcpy(hdr->md5sum1, md5salt_boot, sizeof(md5sum));
get_md5(buf, inspect_info.file_size, hdr->md5sum1);
if (memcmp(md5sum, hdr->md5sum1, sizeof(md5sum))) {
inspect_fw_pmd5sum("Header MD5Sum1", md5sum, "(*ERROR*)");
inspect_fw_pmd5sum(" --> expected", hdr->md5sum1, "");
} else {
inspect_fw_pmd5sum("Header MD5Sum1", md5sum, "(ok)");
}
if (ntohl(hdr->unk2) != 0)
inspect_fw_phexdec("Unknown value 2", hdr->unk2);
inspect_fw_pmd5sum("Header MD5Sum2", hdr->md5sum2,
"(purpose yet unknown, unchecked here)");
if (ntohl(hdr->unk3) != 0xffffffff)
inspect_fw_phexdec("Unknown value 3", hdr->unk3);
if (ntohs(hdr->unk4) != 0x55aa)
inspect_fw_phexdec("Unknown value 4", hdr->unk4);
if (hdr->unk5 != 0xa5)
inspect_fw_phexdec("Unknown value 5", hdr->unk5);
printf("\n");
inspect_fw_pstr("Firmware version", hdr->fw_version);
board = find_board_by_hwid(ntohl(hdr->hw_id));
if (board) {
layout = find_layout(board->layout_id);
inspect_fw_phexpost("Hardware ID",
ntohl(hdr->hw_id), board->id);
inspect_fw_phexexp("Hardware Revision",
ntohl(hdr->hw_rev), board->hw_rev);
} else {
inspect_fw_phexpost("Hardware ID",
ntohl(hdr->hw_id), "unknown");
inspect_fw_phex("Hardware Revision",
ntohl(hdr->hw_rev));
}
printf("%-23s: %d.%d.%d-%d.%d\n", "Software version",
hdr->ver_hi, hdr->ver_mid, hdr->ver_lo,
hdr->sver_hi, hdr->sver_lo);
printf("\n");
inspect_fw_phexdec("Kernel data offset",
ntohl(hdr->kernel_ofs));
inspect_fw_phexdec("Kernel data length",
ntohl(hdr->kernel_len));
if (board) {
inspect_fw_phexdef("Kernel load address",
ntohl(hdr->kernel_la),
layout ? layout->kernel_la : 0xffffffff);
inspect_fw_phexdef("Kernel entry point",
ntohl(hdr->kernel_ep),
layout ? layout->kernel_ep : 0xffffffff);
inspect_fw_phexdecdef("Rootfs data offset",
ntohl(hdr->rootfs_ofs),
layout ? layout->rootfs_ofs : 0xffffffff);
} else {
inspect_fw_phex("Kernel load address",
ntohl(hdr->kernel_la));
inspect_fw_phex("Kernel entry point",
ntohl(hdr->kernel_ep));
inspect_fw_phexdec("Rootfs data offset",
ntohl(hdr->rootfs_ofs));
}
inspect_fw_phexdec("Rootfs data length",
ntohl(hdr->rootfs_len));
inspect_fw_phexdec("Boot loader data offset",
ntohl(hdr->boot_ofs));
inspect_fw_phexdec("Boot loader data length",
ntohl(hdr->boot_len));
inspect_fw_phexdec("Total firmware length",
ntohl(hdr->fw_length));
if (extract) {
FILE *fp;
char *filename;
printf("\n");
filename = malloc(strlen(inspect_info.file_name) + 8);
sprintf(filename, "%s-kernel", inspect_info.file_name);
printf("Extracting kernel to \"%s\"...\n", filename);
fp = fopen(filename, "w");
if (fp) {
if (!fwrite(buf + ntohl(hdr->kernel_ofs),
ntohl(hdr->kernel_len), 1, fp)) {
ERR("error in fwrite(): %s", strerror(errno));
}
fclose(fp);
} else {
ERR("error in fopen(): %s", strerror(errno));
}
free(filename);
filename = malloc(strlen(inspect_info.file_name) + 8);
sprintf(filename, "%s-rootfs", inspect_info.file_name);
printf("Extracting rootfs to \"%s\"...\n", filename);
fp = fopen(filename, "w");
if (fp) {
if (!fwrite(buf + ntohl(hdr->rootfs_ofs),
ntohl(hdr->rootfs_len), 1, fp)) {
ERR("error in fwrite(): %s", strerror(errno));
}
fclose(fp);
} else {
ERR("error in fopen(): %s", strerror(errno));
}
free(filename);
}
out_free_buf:
free(buf);
out:
return ret;
}
int main(int argc, char *argv[])
{
int ret = EXIT_FAILURE;
int err;
FILE *outfile;
progname = basename(argv[0]);
while ( 1 ) {
int c;
c = getopt(argc, argv, "a:B:H:E:F:L:V:N:W:ci:k:r:R:o:xhsjv:y:T:e");
if (c == -1)
break;
switch (c) {
case 'a':
sscanf(optarg, "0x%x", &rootfs_align);
break;
case 'B':
board_id = optarg;
break;
case 'H':
opt_hw_id = optarg;
break;
case 'E':
sscanf(optarg, "0x%x", &kernel_ep);
break;
case 'F':
layout_id = optarg;
break;
case 'W':
opt_hw_rev = optarg;
break;
case 'L':
sscanf(optarg, "0x%x", &kernel_la);
break;
case 'V':
version = optarg;
break;
case 'v':
fw_ver = optarg;
break;
case 'y':
sver = optarg;
break;
case 'N':
vendor = optarg;
break;
case 'c':
combined++;
break;
case 'k':
kernel_info.file_name = optarg;
break;
case 'r':
rootfs_info.file_name = optarg;
break;
case 'R':
sscanf(optarg, "0x%x", &rootfs_ofs);
break;
case 'o':
ofname = optarg;
break;
case 's':
strip_padding = 1;
break;
case 'i':
inspect_info.file_name = optarg;
break;
case 'j':
add_jffs2_eof = 1;
break;
case 'x':
extract = 1;
break;
case 'T':
hdr_ver = atoi(optarg);
break;
case 'e':
endian_swap = true;
break;
case 'h':
usage(EXIT_SUCCESS);
break;
default:
usage(EXIT_FAILURE);
break;
}
}
ret = check_options();
if (ret)
goto out;
if (!inspect_info.file_name)
ret = build_fw();
else
ret = inspect_fw();
out:
return ret;
}
|
the_stack_data/3262161.c | /*
This file is part of MAMBO, a low-overhead dynamic binary modification tool:
https://github.com/beehive-lab/mambo
Copyright 2013-2016 Cosmin Gorgovan <cosmin at linux-geek dot org>
Copyright 2017 The University of Manchester
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifdef __arm__
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
#include <limits.h>
#include <string.h>
#include "dbm.h"
#include "common.h"
#include "scanner_common.h"
#include "pie/pie-thumb-decoder.h"
#include "pie/pie-thumb-encoder.h"
#include "pie/pie-thumb-field-decoder.h"
#include "pie/pie-arm-decoder.h"
#include "pie/pie-arm-encoder.h"
#include "pie/pie-arm-field-decoder.h"
#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
#define MIN_FSPACE (60)
#define IHL_FSPACE (76)
#define copy_thumb_16() *(write_p++) = *read_address;
#define copy_thumb_32() *(write_p++) = *read_address;\
*(write_p++) = *(read_address + 1)
#define get_original_pc() (((uint32_t)read_address + 4) & 0xFFFFFFFC)
#define modify_in_it_pre(skip_size) \
if (it_state.cond_inst_after_it > 0) { \
debug("LDR_PC_16 in IT block\n"); \
if (write_p == it_state.it_inst_addr + 1) { \
write_p--; \
} else { \
debug("LDR_PC_16 in middle of IT block\n"); \
int inst_to_keep = it_get_no_of_inst(it_state.it_initial_mask) - it_state.cond_inst_after_it; \
debug("inst to keep in pre: %d\n", inst_to_keep);\
switch (inst_to_keep) { \
case 1: \
it_state.it_initial_mask = 0x8; \
break; \
case 2: \
it_state.it_initial_mask = it_state.it_initial_mask & 0x8 | 0x4; \
break; \
case 3: \
it_state.it_initial_mask = it_state.it_initial_mask & 0xc | 0x2; \
break; \
case 4: \
it_state.it_initial_mask = it_state.it_initial_mask & 0xe | 0x1; \
break; \
default: \
fprintf(stderr, "check me\n"); \
while(1); \
} \
debug("inst to keep: %d\n", inst_to_keep); \
thumb_it16 (&it_state.it_inst_addr, it_state.it_cond, it_state.it_initial_mask); \
} \
/* Encode as: \
B OP_COND +5 \
STUFF \
IT samecond, len -1*/ \
bool same_cond = (((it_state.it_mask >> 5) & 0x1) == (it_state.it_cond & 1)); \
debug("it_mask: 0x%x, it_cond: %d, same_cond: %d\n", it_state.it_mask, it_state.it_cond, same_cond); \
thumb_cond_branch_16 (&write_p, same_cond ? arm_inverse_cond_code[it_state.it_cond] : it_state.it_cond, skip_size); \
write_p++; \
}
#define modify_in_it_post() \
/* Insert IT after the translated instruction */\
if (it_state.cond_inst_after_it > 1) { \
debug("cond inst following: %d\n", it_state.cond_inst_after_it-1); \
it_state.it_initial_mask = it_state.it_mask & 0xF; \
bool same_cond = (((it_state.it_mask >> 4) & 0x1) == (it_state.it_cond & 1)); \
if (!same_cond) { \
assert(it_state.it_cond < 14); \
switch (it_state.cond_inst_after_it-1) { \
case 3: \
it_state.it_initial_mask = it_state.it_initial_mask & 0xC | 0x2; \
break; \
case 2: \
it_state.it_initial_mask = it_state.it_initial_mask & 0x8 | 0x4; \
break; \
case 1: \
it_state.it_initial_mask = it_state.it_initial_mask & 0x0 | 0x8; \
break; \
} \
it_state.it_cond = arm_inverse_cond_code[it_state.it_cond]; \
} \
thumb_it16 (&write_p, it_state.it_cond, it_state.it_initial_mask); \
it_state.it_inst_addr = write_p; \
write_p++; \
}
typedef struct {
int cond_inst_after_it;
uint16_t *it_inst_addr;
uint32_t it_cond;
uint32_t it_mask;
uint32_t it_initial_mask;
bool is_overwritten;
} thumb_it_state;
int it_get_no_of_inst(uint32_t mask) {
int cond_inst_after_it = 1;
if (mask & 1) {
cond_inst_after_it = 4;
} else if (mask & 2) {
cond_inst_after_it = 3;
} else if (mask & 4) {
cond_inst_after_it = 2;
}
return cond_inst_after_it;
}
void it_clip_len(uint16_t *write_p, uint32_t cond, uint32_t mask, int it_len) {
switch (it_len) {
case 1:
mask = 0x8;
break;
case 2:
mask = mask & 0x8 | 0x4;
break;
case 3:
mask = mask & 0xc | 0x2;
break;
case 4:
mask = mask & 0xe | 0x1;
break;
default:
fprintf(stderr, "check me\n");
while(1);
}
thumb_it16 (&write_p, cond, mask);
}
void it_clip_from_offset(uint16_t *write_p, uint32_t *cond, uint32_t *mask, int offset) {
int initial_len = it_get_no_of_inst(*mask);
while (offset < 0 || offset >= initial_len);
assert(offset >= 0 && offset < initial_len);
if (offset > 0) {
/* The first condition in the IT block always executes when the condition is true. If the
instruction at the new offset has the opposite condition, switch the block to the opposite
condition, which also flips the 'then'/'else' flags for each subsequent instruction. */
bool same_cond = ((*mask >> (4 - offset)) & 1) == ((*cond) & 1);
if (!same_cond) {
*cond = arm_inverse_cond_code[*cond];
}
*mask = (*mask << offset) & 0xF;
}
thumb_it16 (&write_p, *cond, *mask);
}
bool create_it_gap(uint16_t **write_p, thumb_it_state *it_state) {
if (it_state->cond_inst_after_it > 0 && it_state->is_overwritten == false) {
if ((it_get_no_of_inst(it_state->it_initial_mask) - it_state->cond_inst_after_it) > 0) {
it_clip_len(it_state->it_inst_addr, it_state->it_cond, it_state->it_initial_mask,
it_get_no_of_inst(it_state->it_initial_mask) - it_state->cond_inst_after_it);
} else {
assert(it_state->it_inst_addr == *write_p - 1);
*write_p = it_state->it_inst_addr;
it_state->is_overwritten = true;
}
return true;
}
return false;
}
bool close_it_gap(uint16_t **write_p, thumb_it_state *it_state) {
if (it_state->cond_inst_after_it > 0) {
it_clip_from_offset(*write_p, &it_state->it_cond, &it_state->it_initial_mask,
it_get_no_of_inst(it_state->it_initial_mask) - it_state->cond_inst_after_it);
it_state->it_inst_addr = *write_p;
it_state->is_overwritten = false;
*write_p += 1;
return true;
}
return false;
}
void thumb_check_free_space(dbm_thread *thread_data, uint16_t **o_write_p, uint32_t **o_data_p,
thumb_it_state *it_state, uint32_t *addr_prev_block, bool handle_it,
size_t size, int cur_block) {
uint16_t *write_p = *o_write_p;
uint32_t *data_p = *o_data_p;
if ((uint16_t *)data_p <= (write_p + 2)) {
fprintf(stderr, "Thumb fragment overflowed: limit %p, write_p: %p\n", data_p, write_p);
while(1);
}
if ((((uint32_t)write_p + size) >= (uint32_t)data_p)) {
int new_block = allocate_bb(thread_data);
thread_data->code_cache_meta[new_block].actual_id = cur_block;
if ((uint32_t *)&thread_data->code_cache->blocks[new_block] != data_p) {
if (handle_it && it_state->cond_inst_after_it > 0) {
create_it_gap(&write_p, it_state);
}
thumb_b32_helper(write_p, (uint32_t)&thread_data->code_cache->blocks[new_block]);
write_p = (uint16_t *)&thread_data->code_cache->blocks[new_block];
if (handle_it && it_state->cond_inst_after_it > 0) {
close_it_gap(&write_p, it_state);
}
}
*addr_prev_block = (uint32_t)write_p;
data_p = (uint32_t *)&thread_data->code_cache->blocks[new_block + 1];
}
*o_write_p = write_p;
*o_data_p = data_p;
}
void copy_to_reg_16bit(uint16_t **write_p, enum reg reg, uint32_t value) {
thumb_movwi32 (write_p, (value >> 11) & 0x1, (value >> 12) & 0xF, (value >> 8) & 0x7, reg, (value >> 0) & 0xFF);
*write_p += 2;
}
void copy_to_reg_32bit(uint16_t **write_p, enum reg reg, uint32_t value) {
thumb_movwi32 (write_p, (value >> 11) & 0x1, (value >> 12) & 0xF, (value >> 8) & 0x7, reg, (value >> 0) & 0xFF);
*write_p += 2;
thumb_movti32 (write_p, (value >> 27) & 0x1, (value >> 28) & 0xF, (value >> 24) & 0x7, reg, (value >> 16) & 0xFF);
*write_p += 2;
}
void thumb_push_regs(uint16_t **write_p, uint32_t regs) {
if (regs & 0xFFFFA000 || regs == 0) {
fprintf(stderr, "Trying to push invalid reglist\n");
while(1);
} else if (regs & 0xBF00) {
thumb_stmfd32(write_p, 1, sp, regs);
*write_p += 2;
} else {
if (regs & (1 << lr)) {
regs &= 0xFF;
regs |= (1 << 8);
}
thumb_push16(write_p, regs);
*write_p += 1;
}
}
void thumb_pop_regs(uint16_t **write_p, uint32_t regs) {
if (regs & 0xFFFFA000 || regs == 0) {
fprintf(stderr, "Trying to pop invalid reglist\n");
while(1);
} else if (regs & 0x7F00) {
thumb_ldmfd32(write_p, 1, sp, regs);
*write_p += 2;
} else {
if (regs & (1 << pc)) {
regs &= 0xFF;
regs |= (1 << 8);
}
thumb_pop16(write_p, regs);
*write_p += 1;
}
}
enum arm_cond_codes arm_inverse_cond_code[] = {NE, EQ, CC, CS, PL, MI, VC, VS, LS, HI, LT, GE, LE, GT, AL, AL};
void thumb_b_bl_helper(uint16_t *write_p, uint32_t dest_addr, bool link, bool to_arm) {
int difference = dest_addr - ((uint32_t)write_p & (to_arm ? ~2 : ~0)) - 4;
if (difference < -(16*1024*1024) || difference >= (16*1024*1024)) {
fprintf(stderr, "Branch out of range\n");
while(1);
}
uint32_t sign_bit = (difference & 0x80000000) ? 1 : 0;
uint32_t i1 = ~((difference >> 23) ^ sign_bit) & 0x1;
uint32_t i2 = ~((difference >> 22) ^ sign_bit) & 0x1;
uint32_t offset_high = (difference >> 12) & 0x3FF;
uint32_t offset_low = (difference >> 1) & 0x7FF;
if (link) {
if (to_arm) {
thumb_bl_arm32 (&write_p, sign_bit, offset_high, i1, i2, offset_low);
} else {
thumb_bl32 (&write_p, sign_bit, offset_high, i1, i2, offset_low);
}
} else {
thumb_b32 (&write_p, sign_bit, offset_high, i1, i2, offset_low);
}
}
void thumb_adjust_b_bl_target(dbm_thread *thread_data, uint16_t *write_p, uint32_t dest_addr) {
thumb_instruction inst = thumb_decode(write_p);
if (inst != THUMB_BL32 && inst != THUMB_BL_ARM32 && inst != THUMB_B32) {
fprintf(stderr, "Thumb: Trying to adjust target of invalid branch instruction.\n");
while(1);
}
if (inst == THUMB_BL32) {
dest_addr -= 4;
} else if (inst == THUMB_BL_ARM32) {
dest_addr -= 8;
}
thumb_b_bl_helper(write_p, dest_addr, inst != THUMB_B32, inst == THUMB_BL_ARM32);
}
void thumb_b16_cond_helper(uint16_t *write_p, uint32_t dest_addr, mambo_cond cond) {
int difference = dest_addr -(uint32_t)write_p - 4;
assert(difference >= -256 && difference < 256);
thumb_b_cond16(&write_p, cond, (difference >> 1) & 0xFF);
}
void thumb_b32_helper(uint16_t *write_p, uint32_t dest_addr) {
thumb_b_bl_helper(write_p, dest_addr, false, false);
}
void thumb_cc_branch(dbm_thread *thread_data, uint16_t *write_p, uint32_t dest_addr) {
thumb_b32_helper(write_p, dest_addr);
record_cc_link(thread_data, (uint32_t)write_p|THUMB, dest_addr);
}
void thumb_bl32_helper(uint16_t *write_p, uint32_t dest_addr) {
thumb_b_bl_helper(write_p, dest_addr, true, false);
}
void thumb_blx32_helper(uint16_t *write_p, uint32_t dest_addr) {
thumb_b_bl_helper(write_p, dest_addr, true, true);
}
void thumb_b32_cond_helper(uint16_t **write_p, uint32_t dest_addr, enum arm_cond_codes condition) {
int difference = dest_addr -(uint32_t)(*write_p) - 4;
if (difference < -(1*1024*1024) || difference >= (1*1024*1024)) {
assert(condition < 14);
thumb_b_cond16(write_p, arm_inverse_cond_code[condition], 1);
(*write_p)++;
thumb_b32_helper(*write_p, dest_addr);
(*write_p) += 2;
} else {
uint32_t sign_bit = (difference & 0x80000000) ? 1 : 0;
uint32_t j2 = (difference >> 19) & 0x1;
uint32_t j1 = (difference >> 18) & 0x1;
uint32_t offset_high = (difference >> 12) & 0x3F;
uint32_t offset_low = (difference >> 1) & 0x7FF;
thumb_b_cond32 (write_p, sign_bit, condition, offset_high, j1, j2, offset_low);
(*write_p) += 2;
}
}
void thumb_b16_helper(uint16_t *write_p, uint32_t dest_addr, enum arm_cond_codes cond) {
int difference = dest_addr -(uint32_t)write_p - 4;
if (cond >= EQ && cond < AL) {
// Use encoding T1 (conditional with 8b imm)
assert(difference >= -256 && difference <= 254);
thumb_b_cond16(&write_p, cond, (difference >> 1) & 0xFF);
write_p++;
} else if (cond == AL) {
// Use encoding T2 (unconditional with 11b imm)
assert(difference >= -2048 && difference <= 2046);
thumb_b16(&write_p, (difference >> 1) & 0x7FF);
write_p++;
while(1); // Check me
} else {
fprintf(stderr, "Requested invalid B16 condition\n");
while(1);
}
}
int thumb_cbz_cbnz_helper(uint16_t *write_p, uint32_t target, enum reg reg, bool cbz) {
int difference = target - (uintptr_t)write_p - 4;
if (difference < 0 || difference >= 127) return -1;
thumb_misc_cbz_16(&write_p, cbz ? 0 : 1, difference >> 6, difference >> 1, reg);
return 0;
}
void thumb_cbz_helper(uint16_t *write_p, uint32_t target, enum reg reg) {
int ret = thumb_cbz_cbnz_helper(write_p, target, reg, true);
assert(ret == 0);
}
void thumb_cbnz_helper(uint16_t *write_p, uint32_t target, enum reg reg) {
int ret = thumb_cbz_cbnz_helper(write_p, target, reg, false);
assert(ret == 0);
}
#define DISP_CALL_SIZE 76
void branch_save_context(dbm_thread *thread_data, uint16_t **o_write_p, bool late_app_sp) {
uint16_t *write_p = *o_write_p;
thumb_sub_sp_i16(&write_p, DISP_RES_WORDS);
write_p++;
thumb_push16(&write_p, (1 << r0) | (1 << r1) | (1 << r2) | (1 << r3));
write_p++;
if (!late_app_sp) {
thumb_addi32(&write_p, 0, 0, sp, 0, r3, DISP_SP_OFFSET);
write_p += 2;
}
*o_write_p = write_p;
}
#define SETUP (1 << 0)
#define REPLACE_TARGET (1 << 1)
#define INSERT_BRANCH (1 << 2)
void branch_jump(dbm_thread *thread_data, uint16_t **o_write_p, int bb_index, uint32_t target, uint32_t flags) {
uint16_t *write_p = *o_write_p;
uint32_t offset;
if (flags & SETUP) {
copy_to_reg_32bit(&write_p, r1, bb_index);
}
if (flags & REPLACE_TARGET) {
copy_to_reg_32bit(&write_p, r0, target);
}
if (flags & INSERT_BRANCH) {
if (flags & LATE_APP_SP) {
thumb_addi32(&write_p, 0, 0, sp, 0, r3, DISP_SP_OFFSET);
write_p += 2;
}
thumb_b32_helper(write_p, (uint32_t)thread_data->dispatcher_addr-4);
write_p += 2;
}
*o_write_p = write_p;
}
void set_cc_imm_links(dbm_thread *thread_data,
int16_t *write_p,
int basic_block,
uint32_t address_taken,
uint32_t address_skipped,
bool taken_in_cache,
bool skipped_in_cache
) {
uint32_t offset;
if ((taken_in_cache || skipped_in_cache) &&
thread_data->code_cache_meta[basic_block].branch_cache_status == 0) {
thread_data->code_cache_meta[basic_block].branch_cache_status = taken_in_cache ? BRANCH_LINKED : FALLTHROUGH_LINKED;
offset = ((uint32_t)write_p + 2) | THUMB;
if (taken_in_cache) {
record_cc_link(thread_data, offset, address_taken);
} else {
record_cc_link(thread_data, offset, address_skipped);
}
}
if (taken_in_cache && skipped_in_cache &&
(thread_data->code_cache_meta[basic_block].branch_cache_status & BOTH_LINKED) == 0) {
thread_data->code_cache_meta[basic_block].branch_cache_status |= BOTH_LINKED;
offset = ((uint32_t)write_p + 4 + 2) | THUMB;
if (thread_data->code_cache_meta[basic_block].branch_cache_status & BRANCH_LINKED) {
record_cc_link(thread_data, offset, address_skipped);
} else {
record_cc_link(thread_data, offset, address_taken);
}
}
}
#define IMM_SIZE 102
void thumb_encode_cond_imm_branch(dbm_thread *thread_data,
uint16_t **o_write_p,
int basic_block,
uint32_t address_taken,
uint32_t address_skipped,
enum arm_cond_codes condition,
bool taken_in_cache,
bool skipped_in_cache,
bool update) {
uint16_t *write_p = *o_write_p;
if (taken_in_cache && skipped_in_cache) {
if (update && (thread_data->code_cache_meta[basic_block].branch_cache_status & FALLTHROUGH_LINKED)) {
thumb_it16(&write_p, arm_inverse_cond_code[condition], 0x8);
write_p++;
thumb_b32_helper(write_p, address_skipped);
write_p += 2;
thumb_b32_helper(write_p, address_taken);
} else {
thumb_it16(&write_p, condition, 0x8);
write_p++;
thumb_b32_helper(write_p, address_taken);
write_p += 2;
thumb_b32_helper(write_p, address_skipped);
}
write_p += 2;
} else {
if (taken_in_cache) {
thumb_it16(&write_p, condition, 0x8);
write_p++;
thumb_b32_helper(write_p, address_taken);
write_p += 2;
}
if (skipped_in_cache) {
assert(condition < 14);
thumb_it16(&write_p, arm_inverse_cond_code[condition], 0x8);
write_p++;
thumb_b32_helper(write_p, address_skipped);
write_p += 2;
}
if (!update) {
if (!taken_in_cache && !skipped_in_cache) {
// Here we reserve space for one conditional branch, either 2 or 3 halfwords depending on offset
thumb_nop16(&write_p);
write_p++;
thumb_nop16(&write_p);
write_p++;
thumb_nop16(&write_p);
write_p++;
}
branch_save_context(thread_data, &write_p, false);
branch_jump(thread_data, &write_p, basic_block, 0, SETUP);
if (!taken_in_cache && !skipped_in_cache) {
debug("Writing cond branch at: %p\n", write_p);
// Branch to branch taken trampoline
thumb_b_cond16(&write_p, condition, 0x05);
write_p++;
}
if (!skipped_in_cache) {
// Branch not taken trampoline
branch_jump(thread_data, &write_p, basic_block, address_skipped, REPLACE_TARGET|INSERT_BRANCH);
}
if (!taken_in_cache) {
// Branch taken trampoline
branch_jump(thread_data, &write_p, basic_block, address_taken, REPLACE_TARGET|INSERT_BRANCH);
}
}
}
set_cc_imm_links(thread_data, *o_write_p, basic_block, address_taken, address_skipped, taken_in_cache, skipped_in_cache);
*o_write_p = write_p;
}
#define CBZ_SIZE 124
void thumb_encode_cbz_branch(dbm_thread *thread_data,
uint32_t rn,
uint16_t **o_write_p,
int basic_block,
uint32_t address_taken,
uint32_t address_skipped,
bool taken_in_cache,
bool skipped_in_cache,
bool update) {
uint16_t *write_p = *o_write_p;
if (taken_in_cache && skipped_in_cache) {
if (update && (thread_data->code_cache_meta[basic_block].branch_cache_status & FALLTHROUGH_LINKED)) {
thumb_cbz16(&write_p, 0, 0x01, rn);
write_p++;
thumb_b32_helper(write_p, address_skipped);
write_p += 2;
thumb_b32_helper(write_p, address_taken);
write_p += 2;
} else {
thumb_cbnz16(&write_p, 0, 0x01, rn);
write_p++;
thumb_b32_helper(write_p, address_taken);
write_p += 2;
thumb_b32_helper(write_p, address_skipped);
write_p += 2;
}
} else {
if (taken_in_cache) {
thumb_cbnz16(&write_p, 0, 0x01, rn);
write_p++;
thumb_b32_helper(write_p, address_taken);
write_p += 2;
}
if (skipped_in_cache) {
thumb_cbz16(&write_p, 0, 0x01, rn);
write_p++;
thumb_b32_helper(write_p, address_skipped);
write_p += 2;
}
if (!update) {
if (!taken_in_cache && !skipped_in_cache) {
thumb_nop16(&write_p);
write_p++;
thumb_nop16(&write_p);
write_p++;
thumb_nop16(&write_p);
write_p++;
}
assert(rn != sp);
branch_save_context(thread_data, &write_p, true);
if (!taken_in_cache && !skipped_in_cache) {
debug("Writing C(N)BZ at: %p\n", write_p);
// Branch to branch taken trampoline
thumb_cbz16(&write_p, 0, 0xb, rn);
write_p++;
}
if (!skipped_in_cache) {
// Branch not taken trampoline
branch_jump(thread_data, &write_p, basic_block, address_skipped,
SETUP|REPLACE_TARGET|INSERT_BRANCH|LATE_APP_SP);
}
if (!taken_in_cache) {
// Branch taken trampoline
branch_jump(thread_data, &write_p, basic_block, address_taken,
SETUP|REPLACE_TARGET|INSERT_BRANCH|LATE_APP_SP);
}
}
} // not both in cache
set_cc_imm_links(thread_data, *o_write_p, basic_block, address_taken, address_skipped, taken_in_cache, skipped_in_cache);
*o_write_p = write_p;
}
void thumb_inline_hash_lookup(dbm_thread *thread_data, uint16_t **o_write_p, int basic_block, int r_target) {
uint16_t *loop_start;
uint16_t *branch_miss;
uint16_t *write_p = *o_write_p;
bool target_reg_clean = (r_target >= r0);
int target = target_reg_clean ? r_target : r5;
int r_tmp = target_reg_clean ? r5 : r4;
thread_data->code_cache_meta[basic_block].rn = target;
// MOVW+MOVT r_tmp, hash_mask
copy_to_reg_32bit(&write_p, r_tmp, CODE_CACHE_HASH_SIZE);
// MOVW+MOVT r6, hash_table
copy_to_reg_32bit(&write_p, r6, (uint32_t)thread_data->entry_address.entries);
// AND r_tmp, target, r_tmp
thumb_and32(&write_p, 0, target, 0, r_tmp, 0, 0, r_tmp);
write_p += 2;
// ADD r_tmp, r6, r_tmp, LSL #3
thumb_add32(&write_p, 0, r6, 0, r_tmp, 3, 0, r_tmp);
write_p += 2;
// loop:
loop_start = write_p;
// LDR r6, [r_tmp], #8
thumb_ldri32(&write_p, r6, r_tmp, 8, 0, 1, 1);
write_p += 2;
// CMP r6, target
thumb_cmp32(&write_p, r6, 0, 0, 0, target);
write_p += 2;
// BNE miss
branch_miss = write_p++;
// jump:
// LDR r6, [r_tmp, #-4]
thumb_ldri32(&write_p, r6, r_tmp, 4, 1, 0, 0);
write_p += 2;
if (!target_reg_clean) {
// POP {R4}
thumb_pop16(&write_p, (1 << r4));
write_p++;
}
// BX r6
thumb_bx16(&write_p, r6);
write_p++;
// miss:
thumb_b16_helper(branch_miss, (uint32_t)write_p, NE);
// CMP r6, #0
thumb_cmpri16(&write_p, r6, 0);
write_p++;
// BNE loop
thumb_b16_helper(write_p, (uint32_t)loop_start, NE);
write_p++;
// SUB sp, sp, #8
// PUSH {R0 - R3}
branch_save_context(thread_data, &write_p, true);
// MOV R0, target
thumb_movh16(&write_p, r0 >> 3, target, r0);
write_p++;
// ADD r3, sp, #24
thumb_addi32(&write_p, 0, 0, sp, 0, r3, DISP_SP_OFFSET);
write_p += 2;
// LDMFD r3!, {r4-r6}
if (target_reg_clean) {
thumb_ldmfd32(&write_p, 1, r3, (1 << r5) | (1 << r6));
} else {
thumb_ldmfd32(&write_p, 1, r3, (1 << r4) | (1 << r5) | (1 << r6));
}
write_p += 2;
// MOV r1, #bb_id
// B dispatcher
branch_jump(thread_data, &write_p, basic_block, 0, SETUP | INSERT_BRANCH);
*o_write_p = write_p;
}
bool link_bx_alt(dbm_thread *thread_data, uint16_t **write_p, int cond_inst_after_it, uint32_t alt_addr) {
#ifdef LINK_BX_ALT
if (cond_inst_after_it > 0) {
assert(cond_inst_after_it == 1);
thumb_b16(write_p, 1);
(*write_p)++;
uint32_t block_address = lookup_or_stub(thread_data, (uint32_t)alt_addr);
thumb_cc_branch(thread_data, *write_p, block_address);
*write_p += 2;
return true;
}
#endif
return false;
}
void pass1_thumb(dbm_thread *thread_data, uint16_t *read_address, branch_type *bb_type) {
uint32_t null, reglist, rd, dn, imm;
int32_t branch_offset;
*bb_type = unknown;
while(*bb_type == unknown) {
thumb_instruction inst = thumb_decode(read_address);
switch(inst) {
case THUMB_ADDH16:
case THUMB_CMPH16:
case THUMB_MOVH16:
thumb_special_data_proc_16_decode_fields(read_address, &null, &dn, &null, &rd);
rd |= dn << 3;
if (rd == pc) {
*bb_type = uncond_reg_thumb;
}
break;
case THUMB_BX16:
case THUMB_BLX16:
*bb_type = uncond_reg_thumb;
break;
case THUMB_CBZ16:
case THUMB_CBNZ16:
*bb_type = cbz_thumb;
break;
case THUMB_POP16:
thumb_pop16_decode_fields(read_address, ®list);
if(reglist & (1<<8)) {
*bb_type = uncond_reg_thumb;
}
break;
case THUMB_B_COND16:
*bb_type = cond_imm_thumb;
break;
case THUMB_B16:
#ifdef DBM_INLINE_UNCOND_IMM
thumb_b16_decode_fields(read_address, &imm);
branch_offset = (imm & 0x400) ? 0xFFFFF000 : 0;
branch_offset |= imm << 1;
read_address = (uint16_t *)((uint32_t)read_address + 4 -2 + branch_offset);
#else
*bb_type = uncond_imm_thumb;
#endif
break;
case THUMB_LDRI32:
case THUMB_LDRHI32:
case THUMB_LDRBI32:
thumb_load_store_single_reg_imm12_32_decode_fields(read_address, &null, &null, &null,
&null, &null, &rd, &null);
if (rd == pc) {
*bb_type = uncond_reg_thumb;
}
break;
case THUMB_LDR32:
case THUMB_LDRH32:
case THUMB_LDRB32:
thumb_load_store_single_reg_off_32_decode_fields(read_address, &null, &null, &null, &null, &rd, &null, &null);
if (rd == pc) {
*bb_type = uncond_reg_thumb;
}
break;
case THUMB_B32:
case THUMB_BL32:
*bb_type = uncond_imm_thumb;
break;
case THUMB_BL_ARM32:
*bb_type = uncond_blxi_thumb;
break;
case THUMB_B_COND32:
*bb_type = cond_imm_thumb;
break;
case THUMB_TBB32:
case THUMB_TBH32:
*bb_type = tb_indirect;
break;
case THUMB_LDMFD32:
case THUMB_LDMEA32:
thumb_load_store_multiple32_decode_fields(read_address, &null, &null, &null, &null, ®list);
if(reglist & (1<<pc)) {
*bb_type = uncond_reg_thumb;
}
break;
}
if (inst < THUMB_ADC32) {
read_address++;
} else {
read_address+= 2;
}
}
}
void do_it_iter(thumb_it_state *state) {
if (state->cond_inst_after_it > 0) {
state->cond_inst_after_it--;
state->it_mask = (state->it_mask << 1) & 0x3F;
}
}
bool thumb_scanner_deliver_callbacks(dbm_thread *thread_data, mambo_cb_idx cb_id, thumb_it_state *state,
uint16_t *read_address, thumb_instruction inst, uint16_t **o_write_p,
uint32_t **o_data_p, int basic_block, cc_type type,
uint32_t *set_addr_prev_block, bool allow_write) {
bool replaced = false;
void *prev_write_p;
#ifdef PLUGINS_NEW
if (global_data.free_plugin > 0) {
uint16_t *write_p = *o_write_p;
uint32_t *data_p = *o_data_p;
mambo_cond cond;
uint32_t tmp;
switch(inst) {
case THUMB_B_COND16:
thumb_b_cond16_decode_fields(read_address, &cond, &tmp);
break;
case THUMB_B_COND32:
thumb_b_cond32_decode_fields(read_address, &tmp, &cond, &tmp, &tmp, &tmp, &tmp);
break;
default:
if (state->cond_inst_after_it > 0) {
cond = (((state->it_mask >> 5) & 1) == (state->it_cond & 1))
? state->it_cond : arm_inverse_cond_code[state->it_cond];
} else {
cond = AL;
}
}
/* If the previous instruction was IT, allow the plugins to overwrite it */
if (allow_write && state->cond_inst_after_it > 0) {
if (state->it_inst_addr == (write_p -1)) {
write_p--;
state->is_overwritten = true;
}
}
mambo_context ctx;
set_mambo_context_code(&ctx, thread_data, PRE_INST_C, type, basic_block, THUMB_INST, inst, cond, read_address, write_p);
for (int i = 0; i < global_data.free_plugin; i++) {
if (global_data.plugins[i].cbs[cb_id] != NULL) {
ctx.plugin_id = i;
ctx.code.replace = false;
ctx.code.available_regs = ctx.code.pushed_regs;
prev_write_p = ctx.code.write_p;
global_data.plugins[i].cbs[cb_id](&ctx);
if (allow_write) {
if (replaced && (prev_write_p != ctx.code.write_p || ctx.code.replace)) {
fprintf(stderr, "MAMBO API WARNING: plugin %d added code for overridden "
"instruction (at %p).\n", i, read_address);
}
if (ctx.code.replace) {
if (cb_id == PRE_INST_C) {
replaced = true;
} else {
fprintf(stderr, "MAMBO API WARNING: plugin %d set replace_inst for "
"a disallowed event (at %p).\n", i, read_address);
}
}
assert(count_bits(ctx.code.pushed_regs) == ctx.code.plugin_pushed_reg_count);
if (allow_write && ctx.code.pushed_regs) {
thumb_pop_regs((uint16_t **)&ctx.code.write_p, ctx.code.pushed_regs);
}
thumb_check_free_space(thread_data, (uint16_t **)&ctx.code.write_p, &data_p, state,
set_addr_prev_block, false, MIN_FSPACE, basic_block);
} else {
assert(ctx.code.write_p == write_p);
}
} // global_data.plugins[i].cbs[cb_id] != NULL
} // plugin iterator
if (allow_write && state->cond_inst_after_it > 0) {
if (ctx.code.write_p != write_p) {
// Code was inserted.
// Reduce the length of the IT block
create_it_gap((uint16_t **)&ctx.code.write_p, state);
if (replaced) {
// If the instruction was replaced by a plugin, remove its
// condition from the head of the IT block
do_it_iter(state);
}
// Insert an IT instruction for the remaining instructions
close_it_gap((uint16_t **)&ctx.code.write_p, state);
} else {
// If no code was inserted, keep the IT instruction
if (state->is_overwritten) {
ctx.code.write_p += 2;
state->is_overwritten = false;
}
}
}
write_p = ctx.code.write_p;
*o_write_p = write_p;
*o_data_p = data_p;
}
#endif
return replaced;
}
size_t scan_thumb(dbm_thread *thread_data, uint16_t *read_address, int basic_block, cc_type type, uint16_t *write_p) {
bool stop = false;
uint16_t *start_scan = read_address;
if (write_p == NULL) {
write_p = (uint16_t *)&thread_data->code_cache->blocks[basic_block];
}
uint32_t start_address = (uint32_t)write_p;
uint32_t *data_p;
if (type == mambo_bb) {
data_p = (uint32_t *)write_p + BASIC_BLOCK_SIZE;
} else {
data_p = (uint32_t *)&thread_data->code_cache->traces + (TRACE_CACHE_SIZE/4);
}
debug("write_p: %p\n", write_p);
// Todo: check that the compiler can optimize the fact that only
// a small number of these variables is alive per iteration
uint32_t rm;
uint32_t rn;
uint32_t dn;
uint32_t rdn;
uint32_t rt;
uint32_t rdlo;
uint32_t rdhi;
uint32_t racc;
uint32_t imm1;
uint32_t imm2;
uint32_t imm3;
uint32_t imm4;
uint32_t imm5;
uint32_t imm8;
uint32_t set_flags;
uint32_t sign_ext;
uint32_t sign_bit;
uint32_t upwards;
uint32_t original_pc;
uint32_t offset_high;
uint32_t offset_low;
uint32_t j1;
uint32_t j2;
uint32_t reglist;
uint32_t shift_type;
uint32_t condition;
uint32_t writeback;
uint32_t mask;
uint32_t pre_index;
uint32_t shift;
uint32_t opcode;
uint32_t opcode2;
uint32_t byteword;
uint32_t loadstore;
uint32_t datasize;
uint32_t rotate;
uint32_t rt2;
uint32_t m;
uint32_t vm;
uint32_t to_arm;
uint32_t thumb_arm;
uint32_t d;
uint32_t vd;
uint32_t load_store;
uint32_t double_reg;
uint32_t p;
uint32_t double_single;
uint32_t n;
uint32_t vn;
uint32_t f2;
uint32_t n_high;
uint32_t m_swap;
uint32_t link;
uint32_t size;
uint32_t sz;
uint32_t element_size;
uint32_t align;
uint32_t opc1;
uint32_t crn;
uint32_t coproc;
uint32_t opc2;
uint32_t crm;
uint32_t target;
uint32_t *scratch_data;
uint32_t offset;
uint32_t scratch_reg;
uint32_t scratch_reg2;
uint32_t sr[3];
int32_t branch_offset;
uint32_t block_address;
uint32_t branch_taken_address;
uint32_t branch_skipped_address;
uint32_t branch_taken_cached;
uint32_t branch_skipped_cached;
uint32_t *saved_data_p;
int lowest_reg;
uint32_t to_push;
uint32_t return_addr;
bool it_cond_handled = false;
thumb_it_state it_state;
it_state.cond_inst_after_it = 0;
it_state.is_overwritten = false;
bool ldrex = false;
bool insert_inline = false;
uint16_t *inst_pop_regs;
uint16_t *set_inst_pop_regs = NULL;
uint32_t *inst_pop_regs_data;
uint32_t poped_regs = 0;
bool is_valid;
uint32_t addr_prev_block = 0;
uint32_t set_addr_prev_block = 0;
#ifdef DBM_INLINE_UNCOND_IMM
int inline_back_count = 0;
#endif
if (type != mambo_trace) {
thumb_pop16(&write_p, (1 << r5) | (1 << r6));
write_p++;
}
#ifdef DBM_TRACES
branch_type bb_type;
pass1_thumb(thread_data, read_address, &bb_type);
if (type == mambo_bb && (bb_type == uncond_imm_thumb || bb_type == cond_imm_thumb || bb_type == cbz_thumb
#ifdef BLXI_AS_TRACE_HEAD
|| bb_type == uncond_blxi_thumb
#endif
#ifdef TB_AS_TRACE_HEAD
|| bb_type == tb_indirect
#endif
)) {
thumb_sub_sp_i16(&write_p, 2);
write_p++;
thumb_push16(&write_p, (1 << r0) | (1 << r1) | (1 << r2) | (1 << 8));
write_p++;
copy_to_reg_32bit(&write_p, r0, basic_block);
thumb_bl32_helper(write_p, thread_data->trace_head_incr_addr);
write_p += 2;
}
#endif
thumb_scanner_deliver_callbacks(thread_data, PRE_FRAGMENT_C, &it_state, read_address, -1,
&write_p, &data_p, basic_block, type, &set_addr_prev_block, true);
thumb_scanner_deliver_callbacks(thread_data, PRE_BB_C, &it_state, read_address, -1,
&write_p, &data_p, basic_block, type, &set_addr_prev_block, true);
while(!stop) {
debug("thumb scan read_address: %p\n", read_address);
thumb_instruction inst = thumb_decode(read_address);
debug("Instruction enum: %d\n", (inst == THUMB_INVALID) ? -1 : inst);
debug("instruction word: 0x%x\n", (inst < THUMB_ADC32) ? *read_address : ((*read_address) << 16) |*(read_address+1));
it_cond_handled = false;
#ifdef PLUGINS_NEW
bool skip_inst = thumb_scanner_deliver_callbacks(thread_data, PRE_INST_C, &it_state, read_address,
inst, &write_p, &data_p, basic_block, type, &set_addr_prev_block, true);
#endif
addr_prev_block = set_addr_prev_block;
set_addr_prev_block = 0;
// Check if the previous instruction is a POP
if (set_inst_pop_regs) {
inst_pop_regs = set_inst_pop_regs;
set_inst_pop_regs = NULL;
} else {
inst_pop_regs = NULL;
}
#ifdef PLUGINS_NEW
if (skip_inst) {
it_cond_handled = true;
} else {
#endif
switch(inst) {
case THUMB_MOVI16:
case THUMB_LSLI16:
case THUMB_LSRI16:
case THUMB_ASRI16:
thumb_shift_i_mov_16_decode_fields(read_address, &opcode, &imm5, &rm, &rdn);
assert(rm != pc && rdn != pc);
copy_thumb_16();
it_cond_handled = true;
break;
case THUMB_ADD16:
case THUMB_SUB16:
thumb_add_sub_16_decode_fields(read_address, &opcode, &rm, &rn, &rdn);
assert(rm != pc && rn != pc && rdn != pc);
copy_thumb_16();
it_cond_handled = true;
break;
case THUMB_ADDI16:
case THUMB_SUBI16:
thumb_add_sub_i_16_decode_fields(read_address, &opcode, &imm3, &rn, &rdn);
assert(rn != pc && rdn != pc);
copy_thumb_16();
it_cond_handled = true;
break;
case THUMB_MOVRI16:
case THUMB_CMPRI16:
case THUMB_ADDRI16:
case THUMB_SUBRI16:
thumb_add_sub_comp_mov_i_16_decode_fields(read_address, &opcode, &rdn, &imm8);
assert(rdn != pc);
copy_thumb_16();
it_cond_handled = true;
break;
case THUMB_AND16:
case THUMB_EOR16:
case THUMB_LSL16:
case THUMB_LSR16:
case THUMB_ASR16:
case THUMB_ADC16:
case THUMB_SBC16:
case THUMB_TST16:
case THUMB_ROR16:
case THUMB_RSBI16:
case THUMB_CMP16:
case THUMB_CMN16:
case THUMB_ORR16:
case THUMB_BIC16:
case THUMB_MUL16:
case THUMB_MVN16:
thumb_data_proc_16_decode_fields(read_address, &opcode, &rm, &rdn);
assert(rm != pc && rdn != pc);
copy_thumb_16();
it_cond_handled = true;
break;
case THUMB_ADDH16:
case THUMB_CMPH16:
case THUMB_MOVH16:
thumb_special_data_proc_16_decode_fields(read_address, &opcode, &dn, &rm, &rdn);
rdn |= dn << 3;
debug("ADD/CMP/MOVH16 rm: %d, rdn: %d\n", rm, rdn);
if (rdn != pc && rm != pc) {
copy_thumb_16();
it_cond_handled = true;
break;
}
assert(!(rdn == pc && rm == pc));
if (rdn == pc) {
assert(rm != sp);
thread_data->code_cache_meta[basic_block].exit_branch_type = uncond_reg_thumb;
thread_data->code_cache_meta[basic_block].exit_branch_addr = write_p;
uint32_t r_target = r0;
#ifdef DBM_INLINE_HASH
thumb_push16(&write_p, (1 << r4) | (1 << r5) | (1 << r6));
write_p++;
r_target = r5;
#else
branch_save_context(thread_data, &write_p, true);
#endif
switch(inst) {
case THUMB_MOVH16:
if (rm != r_target) {
thumb_movh16(&write_p, r_target >> 3, rm, r_target);
write_p++;
}
break;
default:
fprintf(stderr, "Unsupported encoding\n");
while(1);
}
// ORR Rtarget, Rtarget, #1 - to mark as thumb insts
thumb_orri32(&write_p, 0, 0, r_target, 0, r_target, 1);
write_p += 2;
#ifdef DBM_INLINE_HASH
thumb_check_free_space(thread_data, &write_p, &data_p, &it_state,
&set_addr_prev_block, true, IHL_FSPACE, basic_block);
thumb_inline_hash_lookup(thread_data, &write_p, basic_block, -1);
#else
branch_jump(thread_data, &write_p, basic_block, 0, SETUP|INSERT_BRANCH|LATE_APP_SP);
#endif
stop = true;
} else { // rm == pc
assert(rdn != pc);
scratch_reg = (rdn == r0) ? r1 : r0;
thumb_push16(&write_p, 1 << scratch_reg);
write_p++;
copy_to_reg_32bit(&write_p, scratch_reg, (uint32_t)read_address + 4);
switch(inst) {
case THUMB_ADDH16:
thumb_addh16(&write_p, dn, scratch_reg, rdn & 0x7);
break;
case THUMB_CMPH16:
thumb_cmph16(&write_p, dn, rm, rdn);
fprintf(stderr, "Untested CMPH16\n");
while(1);
break;
case THUMB_MOVH16:
thumb_movh16(&write_p, dn, scratch_reg, rdn & 0x7);
break;
}
write_p++;
thumb_pop16(&write_p, 1 << scratch_reg);
write_p++;
}
break;
case THUMB_BX16:
case THUMB_BLX16:
thumb_bx_16_decode_fields(read_address, &link, &rm);
assert(rm != sp && (rm != pc || inst == THUMB_BX16));
/* Handle conditional execution: either a direct branch to the basic block for
read_address + 2 or a call to the dispatcher */
thread_data->code_cache_meta[basic_block].exit_branch_type = uncond_reg_thumb;
thread_data->code_cache_meta[basic_block].exit_branch_addr = write_p;
if (it_state.cond_inst_after_it == 1) {
#ifdef LINK_BX_ALT
/* If the previous instruction was POP, we'll overwrite it and place a copy:
- on the code path where the branch wasn't taken
- on the code path where the branch was taken
This allows following code (e.g. the inline hash lookup) to use the dead
registers as scratch registers.
*/
if (inst_pop_regs) {
write_p = inst_pop_regs;
data_p = inst_pop_regs_data;
thumb_check_free_space(thread_data, &write_p, &data_p, &it_state,
&set_addr_prev_block, true, 8, basic_block);
thumb_b16(&write_p, 3);
write_p++;
thumb_ldmfd32(&write_p, 1, sp, poped_regs);
write_p += 2;
} else {
thumb_b16(&write_p, 1);
write_p++;
}
target = lookup_or_stub(thread_data, (uint32_t)read_address + 2 + 1);
thumb_cc_branch(thread_data, write_p, target);
write_p += 2;
if (inst_pop_regs) {
/* If the inline hash lookup is going to use the dead registers, it needs
to replace the following instruction from the branch-taken path.
*/
inst_pop_regs = write_p;
inst_pop_regs_data = data_p;
thumb_ldmfd32(&write_p, 1, sp, poped_regs);
write_p += 2;
while(1);
}
#else
assert(0); // incorrect range
thumb_b16(&write_p, (((uint32_t)write_p) & 2) ? 29 : 28);
write_p++;
// This is branch not taken
branch_save_context(thread_data, &write_p, false);
branch_jump(thread_data, &write_p, basic_block, (uint32_t)read_address+2+1, SETUP|REPLACE_TARGET|INSERT_BRANCH);
#endif
it_cond_handled = true;
it_state.cond_inst_after_it = 0; // allows check_free_space to insert branches
} else if (it_state.cond_inst_after_it > 1) {
fprintf(stderr, "BL in middle of IT block\n");
while(1);
}
/* BX PC can be handled as an immediate branch to ARM mode*/
if (inst == THUMB_BX16 && rm == pc) {
target = lookup_or_stub(thread_data, get_original_pc());
if (((uint32_t)write_p) & 2) {
thumb_ldrl32(&write_p, pc, 4, 1);
write_p += 3;
} else {
thumb_ldrl32(&write_p, pc, 0, 1);
write_p += 2;
}
*(uint32_t *)write_p = target;
record_cc_link(thread_data, (uint32_t)write_p|FULLADDR, target);
write_p += 2;
stop = true;
break;
}
#ifdef DBM_INLINE_HASH
assert(rm != sp && rm != pc);
int r_target = -1;
if (rm != r5 && rm != r6 && (inst != THUMB_BLX16 || rm != lr)) {
r_target = rm;
thumb_push16(&write_p, (1 << r5) | (1 << r6));
} else {
thumb_push16(&write_p, (1 << r4) | (1 << r5) | (1 << r6));
}
write_p++;
if (r_target < r0) {
thumb_movh16(&write_p, 0, rm, r5);
write_p++;
}
if (inst == THUMB_BLX16) {
copy_to_reg_32bit(&write_p, lr, ((uint32_t)read_address) + 2 + 1);
}
thumb_check_free_space(thread_data, &write_p, &data_p, &it_state,
&set_addr_prev_block, true, IHL_FSPACE, basic_block);
thumb_inline_hash_lookup(thread_data, &write_p, basic_block, r_target);
#else
branch_save_context(thread_data, &write_p, true);
if (rm == pc) {
copy_to_reg_32bit(&write_p, r0, get_original_pc());
} else {
thumb_movh16(&write_p, 0, rm, 0);
write_p++;
if (inst == THUMB_BLX16) {
copy_to_reg_32bit(&write_p, lr, ((uint32_t)read_address) + 2 + 1);
}
}
branch_jump(thread_data, &write_p, basic_block, 0, SETUP|INSERT_BRANCH|LATE_APP_SP);
#endif
stop = true;
break;
case THUMB_LDR_PC_16:
// needs rewriting
thumb_ldr_pc_16_decode_fields(read_address, &rdn, &imm8);
original_pc = get_original_pc();
offset = imm8 << 2;
modify_in_it_pre(5);
copy_to_reg_32bit(&write_p, rdn, original_pc);
thumb_ldrwi32(&write_p, rdn, rdn, offset);
write_p += 2;
modify_in_it_post();
it_cond_handled = true;
break;
case THUMB_STR16:
case THUMB_STRH16:
case THUMB_STRB16:
case THUMB_LDRSB16:
case THUMB_LDR16:
case THUMB_LDRH16:
case THUMB_LDRB16:
case THUMB_LDRSH16:
// only low 8 regs
copy_thumb_16();
it_cond_handled = true;
break;
case THUMB_STRI16:
case THUMB_LDRI16:
case THUMB_STRBI16:
case THUMB_LDRBI16:
// only low 8 regs
// thumb_load_store_byte_word_i_16_decode_fields(read_address, &byteword, &loadstore, &imm5, &rn, &rdn);
copy_thumb_16();
it_cond_handled = true;
break;
case THUMB_LDRHI16:
case THUMB_STRHI16:
// only low 8 regs
// thumb_load_store_halfword_i_16_decode_fields(read_address, &loadstore, &imm5, &rn, &rt);
copy_thumb_16();
it_cond_handled = true;
break;
case THUMB_STR_SP16:
// check that source isn't pc
thumb_str_sp16_decode_fields(read_address, &rdn, &imm8);
assert(rdn != pc);
copy_thumb_16();
it_cond_handled = true;
break;
case THUMB_LDR_SP16:
// check that dest isn't pc
thumb_ldr_sp16_decode_fields(read_address, &rdn, &imm8);
assert(rdn != pc);
copy_thumb_16();
it_cond_handled = true;
break;
case THUMB_ADD_FROM_SP16:
copy_thumb_16();
it_cond_handled = true;
break;
case THUMB_ADD_FROM_PC16:
thumb_add_from_pc16_decode_fields(read_address, &rdn, &imm8);
modify_in_it_pre(3);
copy_to_reg_32bit(&write_p, rdn, get_original_pc() + (imm8 << 2));
modify_in_it_post();
it_cond_handled = true;
break;
// Only affects the SP, safe to copy
case THUMB_ADD_SP_I16:
case THUMB_SUB_SP_I16:
copy_thumb_16();
it_cond_handled = true;
break;
case THUMB_SXTH16:
case THUMB_SXTB16:
case THUMB_UXTH16:
case THUMB_UXTB16:
// Operand fields are 3 bits in width
copy_thumb_16();
it_cond_handled = true;
break;
case THUMB_CBZ16:
case THUMB_CBNZ16:
thumb_misc_cbz_16_decode_fields(read_address, &n, &imm1, &imm5, &rn);
assert(rn != pc);
branch_offset = (imm1 << 6) | (imm5 << 1);
debug("Branch offset: %d\n", branch_offset);
// Seems ok, but keep an eye on this
target = (uint32_t)read_address + branch_offset + 4 + 1;
debug("Branch taken: 0x%x\n", target);
thumb_check_free_space(thread_data, &write_p, &data_p, &it_state,
&set_addr_prev_block, true, CBZ_SIZE, basic_block);
// Mark this as the beggining of code emulating B
thread_data->code_cache_meta[basic_block].exit_branch_type = cbz_thumb;
thread_data->code_cache_meta[basic_block].exit_branch_addr = write_p;
thread_data->code_cache_meta[basic_block].branch_taken_addr = (inst == THUMB_CBZ16) ? target : ((uint32_t)read_address + 2 + 1);
thread_data->code_cache_meta[basic_block].branch_skipped_addr = (inst == THUMB_CBZ16) ? ((uint32_t)read_address + 2 + 1) : target;
thread_data->code_cache_meta[basic_block].rn = rn;
#ifdef DBM_LINK_CBZ
if (type == mambo_bb) {
branch_taken_address = cc_lookup(thread_data, thread_data->code_cache_meta[basic_block].branch_taken_addr);
branch_taken_cached = (branch_taken_address != UINT_MAX);
branch_skipped_address = cc_lookup(thread_data, thread_data->code_cache_meta[basic_block].branch_skipped_addr);
branch_skipped_cached = (branch_skipped_address != UINT_MAX);
thumb_encode_cbz_branch(thread_data, rn, &write_p, basic_block,
(branch_taken_cached) ? branch_taken_address : thread_data->code_cache_meta[basic_block].branch_taken_addr,
(branch_skipped_cached) ? branch_skipped_address : thread_data->code_cache_meta[basic_block].branch_skipped_addr,
branch_taken_cached,
branch_skipped_cached,
false);
} else {
#endif
thumb_encode_cbz_branch(thread_data, rn, &write_p, basic_block,
(inst == THUMB_CBZ16) ? target : ((uint32_t)read_address + 2 + 1),
(inst == THUMB_CBZ16) ? ((uint32_t)read_address + 2 + 1) : target,
false,
false,
false);
#ifdef DBM_LINK_CBZ
}
#endif
stop = true;
break;
case THUMB_PUSH16:
copy_thumb_16();
break;
case THUMB_POP16:
thumb_pop16_decode_fields(read_address, ®list);
if ((reglist & (1<<8)) == 0) {
set_inst_pop_regs = write_p;
inst_pop_regs_data = data_p;
poped_regs = reglist;
copy_thumb_16();
} else { // PC is POPed
thread_data->code_cache_meta[basic_block].exit_branch_type = uncond_reg_thumb;
thread_data->code_cache_meta[basic_block].exit_branch_addr = write_p;
if (link_bx_alt(thread_data, &write_p, it_state.cond_inst_after_it, (uint32_t)read_address + 3)) {
it_cond_handled = true;
}
#ifdef DBM_INLINE_HASH
if (reglist != ((1 << r4) | (1 << r5) | (1 << 8))) {
if (reglist & 0xFF) {
thumb_pop16(&write_p, reglist & 0xFF);
write_p++;
}
thumb_push16(&write_p, (1 << r4) | (1 << r5));
write_p++;
}
thumb_ldr_sp16(&write_p, r5, 2);
write_p++;
thumb_str_sp16(&write_p, r6, 2);
write_p++;
thumb_check_free_space(thread_data, &write_p, &data_p, &it_state,
&set_addr_prev_block, true, IHL_FSPACE, basic_block);
thumb_inline_hash_lookup(thread_data, &write_p, basic_block, -1);
#else
thumb_pop16(&write_p, reglist & 0xFF);
write_p++;
branch_save_context(thread_data, &write_p, false);
#ifndef LINK_BX_ALT
if (it_state.cond_inst_after_it == 1 && type == mambo_bb) {
fprintf(stderr, "Cond POP16, check if BX PC is marked conditional\n");
thumb_it16 (&write_p, arm_inverse_cond_code[it_state.it_cond], (arm_inverse_cond_code[it_state.it_cond] & 1) ? 0xa : 0x6 );
write_p++;
copy_to_reg_32bit(&write_p, r0, get_original_pc() + 1);
it_cond_handled = true;
while(1);
}
#endif
thumb_ldri32(&write_p, r0, APP_SP, 4, 0, 1, 1);
write_p += 2;
branch_jump(thread_data, &write_p, basic_block, 0, SETUP|INSERT_BRANCH);
#endif
stop = true;
}
break;
case THUMB_REV16:
case THUMB_REV1616:
case THUMB_REVSH16:
copy_thumb_16();
it_cond_handled = true;
break;
case THUMB_IT16:
thumb_it16_decode_fields(read_address, &condition, &mask);
it_state.cond_inst_after_it = it_get_no_of_inst(mask) + 1;
debug("No of cond instructions following from %p: %d\n", read_address, it_state.cond_inst_after_it);
it_cond_handled = true;
it_state.it_inst_addr = write_p;
it_state.it_cond = condition;
it_state.it_mask = mask | (it_state.it_cond & 0x1) << 4;
it_state.it_initial_mask = mask;
debug("initial it mask: 0x%x\n", mask);
copy_thumb_16();
break;
case THUMB_NOP16:
case THUMB_BKPT16:
case THUMB_UDF16:
copy_thumb_16();
it_cond_handled = true;
break;
case THUMB_LDMFD16:
case THUMB_STMEA16:
copy_thumb_16();
it_cond_handled = true;
break;
case THUMB_B_COND16:
thumb_b_cond16_decode_fields(read_address, &condition, &imm8);
branch_offset = ((int8_t)imm8) << 1;
debug("Branch offset: %d\n", branch_offset);
// Seems ok, but keep an eye on this
target = (uint32_t)read_address + 4 + 1 + branch_offset;
debug("Branch taken: 0x%x\n", target);
thumb_check_free_space(thread_data, &write_p, &data_p, &it_state,
&set_addr_prev_block, true, IMM_SIZE, basic_block);
// Mark this as the beggining of code emulating B
thread_data->code_cache_meta[basic_block].exit_branch_type = cond_imm_thumb;
thread_data->code_cache_meta[basic_block].exit_branch_addr = write_p;
thread_data->code_cache_meta[basic_block].branch_taken_addr = target;
thread_data->code_cache_meta[basic_block].branch_skipped_addr = (uint32_t)read_address + 2 + 1;
thread_data->code_cache_meta[basic_block].branch_condition = condition;
#ifdef DBM_LINK_COND_IMM
if (type == mambo_bb) {
branch_taken_address = cc_lookup(thread_data, target);
branch_taken_cached = (branch_taken_address != UINT_MAX);
branch_skipped_address = cc_lookup(thread_data, (uint32_t)read_address + 2 + 1);
branch_skipped_cached = (branch_skipped_address != UINT_MAX);
thumb_encode_cond_imm_branch(thread_data, &write_p, basic_block,
branch_taken_cached ? branch_taken_address : target,
branch_skipped_cached ? branch_skipped_address : ((uint32_t)read_address + 2 + 1),
condition, branch_taken_cached, branch_skipped_cached, false);
} else {
#endif
thumb_encode_cond_imm_branch(thread_data, &write_p, basic_block,
target,
((uint32_t)read_address + 2 + 1),
condition, false, false, false);
#ifdef DBM_LINK_COND_IMM
}
#endif
stop = true;
break;
case THUMB_SVC16:
thumb_sub_sp_i16(&write_p, 2);
write_p++;
// PUSH {R0-R12, R14}
thumb_push_regs(&write_p, 0x5FFF);
copy_to_reg_32bit(&write_p, r8, (uint32_t)read_address + 2 + 1);
thumb_blx32_helper(write_p, thread_data->syscall_wrapper_addr);
write_p += 2;
thumb_scanner_deliver_callbacks(thread_data, POST_BB_C, &it_state, read_address, -1,
&write_p, &data_p, basic_block, type, &set_addr_prev_block, false);
thumb_scanner_deliver_callbacks(thread_data, PRE_BB_C, &it_state, read_address + 1, -1,
&write_p, &data_p, basic_block, type, &set_addr_prev_block, true);
break;
case THUMB_B16:
thumb_b16_decode_fields(read_address, &imm1);
branch_offset = (imm1 & 0x400) ? 0xFFFFF000 : 0;
branch_offset |= imm1 << 1;
debug("offset: %d\n", branch_offset);
target = (uint32_t)read_address + 4 + 1 + branch_offset;
debug("target : 0x%x\n", target);
#ifdef DBM_INLINE_UNCOND_IMM
if ((target - 1) <= (uint32_t)read_address) {
if (inline_back_count >= MAX_BACK_INLINE) {
block_address = lookup_or_stub(thread_data, target);
thumb_cc_branch(thread_data, write_p, block_address);
write_p += 2;
thread_data->code_cache_meta[basic_block].exit_branch_type = trace_inline_max;
stop = true;
break;
} else {
inline_back_count++;
}
}
/* TODO: handle branches to unmapped addresses cleanly
This is a hack to avoid trying to elide the b.n 0x7e8c instruction in
in some versions of ld.so */
if ((uint32_t)target >= 0x8000) {
thumb_scanner_deliver_callbacks(thread_data, POST_BB_C, &it_state, read_address, -1,
&write_p, &data_p, basic_block, type, &set_addr_prev_block, false);
thumb_scanner_deliver_callbacks(thread_data, PRE_BB_C, &it_state, (uint16_t *)(target -1), -1,
&write_p, &data_p, basic_block, type, &set_addr_prev_block, true);
read_address = (uint16_t *)(target - 2 - 1);
break;
}
#endif
// Mark this as the beggining of code emulating B
thread_data->code_cache_meta[basic_block].exit_branch_type = uncond_imm_thumb;
thread_data->code_cache_meta[basic_block].exit_branch_addr = write_p;
#ifdef DBM_LINK_UNCOND_IMM
block_address = cc_lookup(thread_data, target);
if (type == mambo_bb && block_address != UINT_MAX && (target & 0x1)) {
thumb_cc_branch(thread_data, write_p, block_address);
} else {
#endif
branch_save_context(thread_data, &write_p, false);
branch_jump(thread_data, &write_p, basic_block, target, SETUP|REPLACE_TARGET|INSERT_BRANCH);
#ifdef DBM_LINK_UNCOND_IMM
}
#endif
stop = true;
break;
// thumb_data_proc_12bit_i_32 instructions that use rn and rd
case THUMB_ADCI32:
case THUMB_ADDI32:
case THUMB_ANDI32:
case THUMB_BICI32:
case THUMB_EORI32:
case THUMB_ORNI32:
case THUMB_ORRI32:
case THUMB_RSBI32:
case THUMB_SBCI32:
case THUMB_SUBI32:
thumb_data_proc_12bit_i_32_decode_fields(read_address, &imm1, &opcode, &set_flags, &rn, &imm3, &rdn, &imm8);
assert(rn != pc && rdn != pc);
copy_thumb_32();
it_cond_handled = true;
break;
// thumb_data_proc_12bit_i_32 instructions that only use rn
case THUMB_CMNI32:
case THUMB_CMPI32:
case THUMB_TEQI32:
case THUMB_TSTI32:
thumb_data_proc_12bit_i_32_decode_fields(read_address, &imm1, &opcode, &set_flags, &rn, &imm3, &rdn, &imm8);
assert(rn != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_MOVI32:
// check if dest is pc
thumb_movi32_decode_fields(read_address, &imm1, &set_flags, &imm3, &rdn, &imm8);
debug("MOVI32 rdn: %d, imm: %d\n", rdn, (imm1 << 11) | (imm3) | (imm8));
assert(rdn != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_MVNI32:
thumb_mvni32_decode_fields(read_address, &imm1, &set_flags, &imm3, &rdn, &imm8);
debug("MVNI32 rdn: %d, imm: %d\n", rdn, (imm1 << 11) | (imm3) | (imm8));
assert(rdn != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_MOVTI32:
// check if dest is pc
thumb_movti32_decode_fields(read_address, &imm1, &imm4, &imm3, &rdn, &imm8);
assert(rdn != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_MOVWI32:
// check that dest isn't pc
thumb_movwi32_decode_fields(read_address, &imm1, &imm4, &imm3, &rdn, &imm8);
assert(rdn != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_BFC32:
thumb_bfc32_decode_fields(read_address, &imm3, &rdn, &imm2, &imm5);
assert(rdn != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_BFI32:
case THUMB_SBFX32:
case THUMB_SSAT_LSL32:
case THUMB_SSAT_ASR32:
case THUMB_SSAT1632:
case THUMB_UBFX32:
case THUMB_USAT_LSL32:
case THUMB_USAT_ASR32:
case THUMB_USAT1632:
thumb_data_proc_bit_field_decode_fields(read_address, &opcode, &rn, &imm3, &rdn, &imm2, &imm5);
assert(rn != pc && rdn != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_NOP32:
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_ADDWI32:
thumb_addwi32_decode_fields(read_address, &imm1, &rn, &imm3, &rdn, &imm8);
assert(rdn != pc);
if (rn == pc) {
copy_to_reg_32bit(&write_p, rdn, get_original_pc() + ((imm1 << 11) | (imm3 << 8) | imm8 ));
} else {
copy_thumb_32();
it_cond_handled = true;
}
break;
case THUMB_SUBWI32:
thumb_subwi32_decode_fields(read_address, &imm1, &rn, &imm3, &rdn, &imm8);
assert(rdn != pc);
if (rn == pc) {
modify_in_it_pre(3);
copy_to_reg_32bit(&write_p, rdn, get_original_pc() - ((imm1 << 11) | (imm3 << 8) | imm8 ));
modify_in_it_post();
} else {
copy_thumb_32();
}
it_cond_handled = true;
break;
case THUMB_LDRI32:
case THUMB_LDRHI32:
case THUMB_LDRSHI32:
case THUMB_LDRBI32:
case THUMB_LDRSBI32:
case THUMB_LDRT32:
case THUMB_LDRBT32:
case THUMB_LDRHT32:
case THUMB_LDRSBT32:
case THUMB_LDRSHT32:
thumb_ldri32_decode_fields(read_address, &rdn, &rn, &imm8, &pre_index, &upwards, &writeback);
assert(rn != pc);
if (rdn == pc) {
thread_data->code_cache_meta[basic_block].exit_branch_type = uncond_reg_thumb;
thread_data->code_cache_meta[basic_block].exit_branch_addr = write_p;
}
if (rdn != pc) {
copy_thumb_32();
it_cond_handled = true;
} else {
if (rdn == pc) {
assert(inst == THUMB_LDRI32);
#ifdef DBM_INLINE_HASH
if (rn == sp) {
if (writeback) {
assert(upwards && pre_index == 0 && (imm8 & 3) == 0 && imm8 >= 4);
if (imm8 == 4) {
thumb_push16(&write_p, (1 << r4) | (1 << r5));
write_p++;
thumb_ldr_sp16(&write_p, r5, 2);
write_p++;
thumb_str_sp16(&write_p, r6, 2);
write_p++;
} else { // imm8 > 4
thumb_str_sp16(&write_p, r6, (imm8 >> 2) - 1);
write_p++;
thumb_ldri32(&write_p, r6, sp, imm8 - 4, 0, 1, 1);
write_p += 2;
thumb_push16(&write_p, (1 << r4) | (1 << r5));
write_p++;
thumb_movh16(&write_p, r5 >> 4, r6, r5);
write_p++;
}
} else { // !writeback
assert(pre_index);
int offset = (int)imm8;
if (upwards == 0) {
offset = -offset;
}
offset += 12;
upwards = (offset >= 0);
imm8 = (uint32_t)abs(offset);
assert(imm8 <= 0xFF);
thumb_push16(&write_p, (1 << r4) | (1 << r5) | (1 << r6));
write_p++;
thumb_ldri32(&write_p, rdn, rn, imm8, pre_index, upwards, writeback);
write_p += 2;
while(1);
}
} else { // rn != sp
while(1);
}
thumb_check_free_space(thread_data, &write_p, &data_p, &it_state,
&set_addr_prev_block, true, IHL_FSPACE, basic_block);
thumb_inline_hash_lookup(thread_data, &write_p, basic_block, -1);
#else
scratch_reg = (rn == r0) ? 1 : 0;
branch_save_context(thread_data, &write_p, false);
assert(rn != r3);
if (rn == sp) {
rn = APP_SP;
}
thumb_ldri32(&write_p, r0, rn, imm8, pre_index, upwards, writeback);
write_p+=2;
branch_jump(thread_data, &write_p, basic_block, target, SETUP|INSERT_BRANCH);
#endif
stop = true;
}
}
break;
case THUMB_LDRWI32:
case THUMB_LDRHWI32:
case THUMB_LDRSHWI32:
case THUMB_LDRBWI32:
case THUMB_LDRSBWI32:
case THUMB_STRWI32:
case THUMB_STRBWI32:
case THUMB_STRHWI32:
thumb_strwi32_decode_fields(read_address, &rdn, &rn, &imm1);
assert(rdn != pc && rn != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_LDRBL32:
case THUMB_LDRHL32:
case THUMB_LDRL32:
case THUMB_LDRSBL32:
case THUMB_LDRSHL32:
thumb_load_store_single_reg_imm12_32_decode_fields(read_address, &sign_ext, &upwards,
&size, &loadstore, &rn, &rdn, &imm1);
assert(rdn != pc);
modify_in_it_pre(5);
copy_to_reg_32bit(&write_p, rdn, get_original_pc() + (upwards ? imm1 : -imm1));
thumb_load_store_single_reg_imm12_32(&write_p, sign_ext, upwards, size,
loadstore, rdn, rdn, 0);
write_p += 2;
modify_in_it_post();
it_cond_handled = true;
break;
case THUMB_PLDI32:
thumb_load_store_single_reg_imm12_32_decode_fields(read_address, &sign_ext, &upwards, &datasize, &loadstore, &rn, &rdn, &imm1);
assert(rn != pc);
copy_thumb_32();
break;
case THUMB_STRI32:
case THUMB_STRHI32:
case THUMB_STRBI32:
case THUMB_STRT32:
case THUMB_STRBT32:
case THUMB_STRHT32:
// check if src or address is pc
thumb_load_store_single_reg_imm12_32_decode_fields(read_address, &sign_ext, &upwards, &datasize, &loadstore, &rn, &rdn, &imm1);
debug("STR(B/H)32 sign_ext: %d, upwards: %d, rn: %d, rt: %d, imm: %d\n", sign_ext, upwards, rn, rdn, imm1);
if (rn != pc && rdn != pc) {
copy_thumb_32();
it_cond_handled = true;
} else {
fprintf(stderr, "PC involved\n");
while(1);
}
break;
case THUMB_LDR32:
case THUMB_LDRH32:
case THUMB_LDRSH32:
case THUMB_LDRB32:
case THUMB_LDRSB32:
thumb_load_store_single_reg_off_32_decode_fields(read_address, &sign_ext, &datasize, &loadstore, &rn, &rt, &shift, &rm);
assert(rn != pc && rm != pc);
if (rt == pc) {
if (inst != THUMB_LDR32) {
fprintf(stderr, "LDR(S)H/B into PC at %p\n", read_address);
while(1);
}
thread_data->code_cache_meta[basic_block].exit_branch_type = uncond_reg_thumb;
thread_data->code_cache_meta[basic_block].exit_branch_addr = write_p;
assert(rn != sp && rm != sp);
uint32_t r_target = r0;
#ifdef DBM_INLINE_HASH
thumb_push16(&write_p, (1 << r4) | (1 << r5) | (1 << r6));
write_p++;
r_target = r5;
#else
branch_save_context(thread_data, &write_p, true);
#endif
thumb_ldr32 (&write_p, rn, r_target, shift, rm);
write_p += 2;
#ifdef DBM_INLINE_HASH
thumb_check_free_space(thread_data, &write_p, &data_p, &it_state,
&set_addr_prev_block, true, IHL_FSPACE, basic_block);
thumb_inline_hash_lookup(thread_data, &write_p, basic_block, -1);
#else
branch_jump(thread_data, &write_p, basic_block, target, SETUP|INSERT_BRANCH|LATE_APP_SP);
#endif
stop = true;
} else {
copy_thumb_32();
it_cond_handled = true;
}
break;
case THUMB_STR32:
case THUMB_STRH32:
case THUMB_STRB32:
thumb_load_store_single_reg_off_32_decode_fields(read_address, &sign_ext, &datasize, &loadstore, &rn, &rt, &shift, &rm);
assert(rn != pc && rt != pc && rm != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_PLD32:
thumb_load_store_single_reg_off_32_decode_fields(read_address, &sign_ext, &datasize, &loadstore, &rn, &rt, &shift, &rm);
assert(rm != pc && rn != pc);
copy_thumb_32();
break;
case THUMB_PLDIM32:
thumb_pld_t2_32_decode_fields(read_address, &sign_ext, &datasize, &load_store, &rn, &rt, &opcode, &imm8);
assert(rn != pc);
copy_thumb_32();
break;
// data_proc_const_shift instructions that use rn, rd and rm
case THUMB_ADC32:
case THUMB_ADD32:
case THUMB_AND32:
case THUMB_BIC32:
case THUMB_EOR32:
case THUMB_ORN32:
case THUMB_ORR32:
case THUMB_PKH32:
case THUMB_RSB32:
case THUMB_SBC32:
case THUMB_SUB32:
thumb_data_proc_const_shift_decode_fields(read_address, &opcode, &set_flags, &rn, &imm3, &rdn, &imm2, &shift_type, &rm);
assert(rn != pc && rdn != pc && rm != pc);
copy_thumb_32();
it_cond_handled = true;
break;
// data_proc_const_shift instructions that use rm and rd
case THUMB_MOV32:
case THUMB_LSLI32:
case THUMB_LSRI32:
case THUMB_ASRI32:
case THUMB_RORI32:
thumb_data_proc_const_shift_decode_fields(read_address, &opcode, &set_flags, &rn, &imm3, &rdn, &imm2, &shift_type, &rm);
assert(rdn != pc && rm != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_RRX32:
thumb_rrx32_decode_fields(read_address, &set_flags, &rdn, &rm);
assert(rdn != pc && rm != pc);
copy_thumb_32();
break;
case THUMB_MVN32:
thumb_mvn32_decode_fields(read_address, &set_flags, &imm3, &rdn, &imm2, &shift_type, &rm);
assert(rdn != pc && rm != pc);
copy_thumb_32();
it_cond_handled = true;
break;
// data_proc_const_shift instructions that use rm and rn
case THUMB_CMN32:
case THUMB_CMP32:
case THUMB_TEQ32:
case THUMB_TST32:
thumb_data_proc_const_shift_decode_fields(read_address, &opcode, &set_flags, &rn, &imm3, &rdn, &imm2, &shift_type, &rm);
assert(rn != pc && rm != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_LSL32:
case THUMB_LSR32:
case THUMB_ASR32:
case THUMB_ROR32:
thumb_data_proc_reg_shift_decode_fields(read_address, &opcode, &set_flags, &rn, &rdn, &opcode2, &rm);
assert(rn != pc && rdn != pc && rm != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_SXTAB32:
case THUMB_SXTAB1632:
case THUMB_SXTAH32:
case THUMB_UXTAB32:
case THUMB_UXTAB1632:
case THUMB_UXTAH32:
thumb_data_proc_sign_zero_ext_decode_fields(read_address, &opcode, &rn, &rdn, &rotate, &rm);
assert(rdn != pc && rm != pc && rn != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_SXTB32:
case THUMB_SXTB1632:
case THUMB_SXTH32:
case THUMB_UXTB32:
case THUMB_UXTB1632:
case THUMB_UXTH32:
thumb_data_proc_sign_zero_ext_decode_fields(read_address, &opcode, &rn, &rdn, &rotate, &rm);
assert(rdn != pc && rm != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_SIMD_ADD_SUB32:
thumb_simd_add_sub32_decode_fields(read_address, &opcode, &rn, &rdn, &opcode2, &rm);
assert(rn != pc && rdn != pc && rm != pc);
copy_thumb_32();
break;
case THUMB_CLZ32:
case THUMB_QADD32:
case THUMB_QDADD32:
case THUMB_QDSUB32:
case THUMB_QSUB32:
case THUMB_RBIT32:
case THUMB_REV32:
case THUMB_REV1632:
case THUMB_REVSH32:
case THUMB_SEL32:
thumb_data_proc_other_3reg_decode_fields(read_address, &opcode, &rn, &rdn, &opcode2, &rm);
assert(rn != pc && rdn != pc && rm != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_MLA32:
case THUMB_MLS32:
case THUMB_SMMLA32:
case THUMB_SMMLS32:
thumb_data_proc_32_mult_decode_fields(read_address, &opcode, &rn, &racc, &rdn, &opcode2, &rm);
assert(rn != pc && racc != pc && rdn != pc && rm != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_MUL32:
thumb_mul32_decode_fields(read_address, &rn, &rdn, &rm);
assert(rn != pc && rdn != pc && rm != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_SMLAD32:
case THUMB_SMLSD32:
case THUMB_USADA832:
case THUMB_SMLABB32:
thumb_data_proc_rd_rn_rm_ra_decode_fields(read_address, &rdn, &rn, &rm, &racc);
assert(rn != pc && rdn != pc && rm != pc && racc != pc);
copy_thumb_32();
it_cond_handled = true;
break;
// data proc with rd, rn, rm
case THUMB_SMUSD32:
case THUMB_USAD832:
case THUMB_SMMUL32:
case THUMB_SMUAD32:
case THUMB_UADD832:
case THUMB_UQSUB832:
case THUMB_SMULBB32:
thumb_data_proc_rd_rn_rm_decode_fields(read_address, &rdn, &rn, &rm);
assert(rdn != pc && rn != pc && rm != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_SMULL32:
thumb_smull32_decode_fields(read_address, &rn, &rdlo, &rdhi, &rm);
assert(rn != pc && rdlo != pc && rdhi != pc && rm != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_UMULL32:
thumb_umull32_decode_fields(read_address, &rn, &rdlo, &rdhi, &rm);
assert(rn != pc && rdlo != pc && rdhi != pc && rm != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_SDIV32:
case THUMB_UDIV32:
thumb_data_proc_64_mult_decode_fields(read_address, &opcode, &rn, &rdlo, &rdhi, &opcode2, &n_high, &m_swap, &rm);
assert(rn != pc && rdhi != pc && rm != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_SMLAL32:
case THUMB_SMLALD32:
case THUMB_SMLSLD32:
case THUMB_UMLAL32:
case THUMB_UMAAL32:
thumb_data_proc_64_mult_decode_fields(read_address, &opcode, &rn, &rdlo, &rdhi, &opcode2, &n_high, &m_swap, &rm);
assert(rn != pc && rdlo != pc && rdhi != pc && rm != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_B32:
case THUMB_BL32:
case THUMB_BL_ARM32:
thumb_branch32_decode_fields(read_address, &sign_bit, &offset_high, &link, &j1, &thumb_arm, &j2, &offset_low);
debug("B32/BL32/BL_ARM32 sign_bit: %d, j1: %d, j2: %d, offset_high 0x%x, offset_low 0x%x\n",
sign_bit, j1, j2, offset_high, offset_low);
branch_offset = sign_bit ? 0xFF000000 : 0;
branch_offset |= (j1 ^ sign_bit) ? 0 : 1 << 23;
branch_offset |= (j2 ^ sign_bit) ? 0: 1 << 22;
branch_offset |= offset_high << 12;
branch_offset |= offset_low << 1;
debug("branch_offset = 0x%x\n", branch_offset);
if (link_bx_alt(thread_data, &write_p, it_state.cond_inst_after_it, (uint32_t)read_address + 5)) {
it_cond_handled = true;
}
// Seems ok, but keep an eye on this
target = (uint32_t)read_address + branch_offset + 4 + 1;
if(inst == THUMB_BL_ARM32) target &= 0xFFFFFFFC;
debug("branch_target = 0x%x\n", target);
// Set the link register
if (inst != THUMB_B32) {
copy_to_reg_32bit(&write_p, lr, ((uint32_t)read_address) + 4 + 1);
}
#ifdef DBM_INLINE_UNCOND_IMM
if (inst != THUMB_BL_ARM32 && (type == mambo_trace || type == mambo_trace_entry)) {
if ((target - 1) <= (uint32_t)read_address) {
if (inline_back_count >= MAX_BACK_INLINE) {
block_address = lookup_or_stub(thread_data, target);
thumb_cc_branch(thread_data, write_p, block_address);
write_p += 2;
thread_data->code_cache_meta[basic_block].exit_branch_type = trace_inline_max;
stop = true;
break;
} else {
inline_back_count++;
}
}
thumb_scanner_deliver_callbacks(thread_data, POST_BB_C, &it_state, read_address, -1,
&write_p, &data_p, basic_block, type, &set_addr_prev_block, false);
thumb_scanner_deliver_callbacks(thread_data, PRE_BB_C, &it_state, (uint16_t *)(target -1), -1,
&write_p, &data_p, basic_block, type, &set_addr_prev_block, true);
read_address = (uint16_t *)(target - 4 - 1);
} else {
#endif
thumb_check_free_space(thread_data, &write_p, &data_p, &it_state,
&set_addr_prev_block, true, DISP_CALL_SIZE, basic_block);
if (inst == THUMB_BL_ARM32) {
thread_data->code_cache_meta[basic_block].exit_branch_type = uncond_blxi_thumb;
} else {
thread_data->code_cache_meta[basic_block].exit_branch_type = uncond_imm_thumb;
}
thread_data->code_cache_meta[basic_block].branch_taken_addr = target;
thread_data->code_cache_meta[basic_block].exit_branch_addr = write_p;
#ifdef DBM_LINK_UNCOND_IMM
block_address = cc_lookup(thread_data, target);
if (type == mambo_bb && block_address != UINT_MAX && (target & 0x1)) {
debug("Found block for 0x%x at 0x%x\n", target, block_address);
thumb_cc_branch(thread_data, write_p, block_address);
} else {
#endif
branch_save_context(thread_data, &write_p, false);
branch_jump(thread_data, &write_p, basic_block, target, SETUP|REPLACE_TARGET|INSERT_BRANCH);
#ifdef DBM_LINK_UNCOND_IMM
}
#endif
stop = true;
#ifdef DBM_INLINE_UNCOND_IMM
}
#endif
break;
case THUMB_B_COND32:
// Warning: at some point we might want to restore the values of any scratch registers here
thumb_b_cond32_decode_fields(read_address, &sign_bit, &condition, &offset_high, &j1, &j2, &offset_low);
debug("B_COND32: sign_bit %d, j2: %d, j1: %d, offset_high: %x, offset_low %x\n", sign_bit, j2, j1, offset_high, offset_low);
branch_offset = sign_bit ? 0xFFF00000 : 0;
branch_offset |= j2 << 19;
branch_offset |= j1 << 18;
branch_offset |= offset_high << 12;
branch_offset |= offset_low << 1;
debug("branch_offset = %d\n", branch_offset);
// Seems ok, but keep an eye on this
target = (uint32_t)read_address + branch_offset + 4 + 1;
debug("Computed target: 0x%x\n", target);
thumb_check_free_space(thread_data, &write_p, &data_p, &it_state,
&set_addr_prev_block, true, IMM_SIZE, basic_block);
// Mark this as the beggining of code emulating B
thread_data->code_cache_meta[basic_block].exit_branch_type = cond_imm_thumb;
thread_data->code_cache_meta[basic_block].exit_branch_addr = write_p;
thread_data->code_cache_meta[basic_block].branch_taken_addr = target;
thread_data->code_cache_meta[basic_block].branch_skipped_addr = (uint32_t)read_address + 4 + 1;
thread_data->code_cache_meta[basic_block].branch_condition = condition;
#ifdef DBM_LINK_COND_IMM
if (type == mambo_bb) {
if (target & 0x1) {
branch_taken_address = cc_lookup(thread_data, target);
branch_taken_cached = (branch_taken_address != UINT_MAX);
} else {
branch_taken_cached = false;
}
branch_skipped_address = cc_lookup(thread_data, (uint32_t)read_address + 4 + 1);
branch_skipped_cached = (branch_skipped_address != UINT_MAX);
thumb_encode_cond_imm_branch(thread_data, &write_p, basic_block,
branch_taken_cached ? branch_taken_address : target,
branch_skipped_cached ? branch_skipped_address : ((uint32_t)read_address + 4 + 1),
condition, (branch_taken_address != UINT_MAX), (branch_skipped_address != UINT_MAX), false);
} else {
#endif
thumb_encode_cond_imm_branch(thread_data, &write_p, basic_block,
target,
((uint32_t)read_address + 4 + 1),
condition, false, false, false);
#ifdef DBM_LINK_COND_IMM
}
#endif
stop = true;
//while(1);
break;
case THUMB_DSB32:
case THUMB_DMB32:
case THUMB_ISB32:
case THUMB_CLREX32:
copy_thumb_32();
break;
case THUMB_MSR32:
thumb_msr32_decode_fields(read_address, &rn, &mask);
assert(rn != pc);
copy_thumb_32();
break;
case THUMB_MRS32:
thumb_mrs32_decode_fields(read_address, &rdn);
assert(rdn != pc);
copy_thumb_32();
break;
case THUMB_LDRD32:
thumb_ldrd32_decode_fields(read_address, &pre_index, &upwards, &writeback, &rn, &rt, &rdn, &imm8);
assert(rt != pc && rdn != pc);
if (rn == pc) {
assert(pre_index == 1 && writeback == 0);
imm8 <<= 2;
uint32_t addr = get_original_pc() + (upwards ? imm8 : -imm8);
modify_in_it_pre(5);
copy_to_reg_32bit(&write_p, rdn, addr);
thumb_ldrd32(&write_p, 1, 1, 0, rdn, rt, rdn, 0);
write_p += 2;
modify_in_it_post();
} else {
copy_thumb_32();
}
it_cond_handled = true;
break;
case THUMB_STRD32:
thumb_strd32_decode_fields(read_address, &pre_index, &upwards, &writeback, &rn, &rt, &rdn, &imm8);
assert(rn != pc && rt != pc && rdn != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_LDREX32:
case THUMB_STREX32:
switch(inst) {
case THUMB_LDREX32:
thumb_ldrex32_decode_fields(read_address, &rn, &rt, &imm8);
ldrex = true;
rdn = 0;
break;
case THUMB_STREX32:
thumb_strex32_decode_fields(read_address, &rn, &rt, &rdn, &imm8);
ldrex = false;
break;
}
assert(rn != pc && rt != pc && rdn != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_LDREXB32:
case THUMB_LDREXH32:
case THUMB_STREXB32:
case THUMB_STREXH32:
thumb_strexb32_decode_fields(read_address, &rn, &rt, &rdn);
assert(rn != pc && rt != pc);
if (inst == THUMB_STREXB32 || inst == THUMB_STREXH32) {
assert(rdn != pc);
ldrex = false;
} else {
ldrex = true;
}
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_LDREXD32:
case THUMB_STREXD32:
thumb_strexd32_decode_fields(read_address, &rn, &rt, &rt2, &rdn);
assert(rn != pc && rt != pc && rt2 != pc);
if (inst == THUMB_STREX32) assert(rdn != pc);
ldrex = (inst == THUMB_STREXD32);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_TBB32:
case THUMB_TBH32:
// Branch to PC + [value from rn + rm << 1]
thumb_tbh32_decode_fields(read_address, &rn, &rm);
assert(rm != pc);
assert(rn != sp && rm != sp);
scratch_reg = r0;
while (rn == scratch_reg || rm == scratch_reg) {
scratch_reg++;
}
scratch_reg2 = scratch_reg+1;
while (rn == scratch_reg2 || rm == scratch_reg2) {
scratch_reg2++;
}
assert(scratch_reg2 <= 2);
#ifdef DBM_TRACES
if (type == mambo_trace || type == mambo_trace_entry) {
#endif
thread_data->code_cache_meta[basic_block].exit_branch_type = (inst == THUMB_TBB32) ? tbb : tbh;
#ifdef DBM_TRACES
} else {
thread_data->code_cache_meta[basic_block].exit_branch_type = tb_indirect;
}
#endif
thread_data->code_cache_meta[basic_block].exit_branch_addr = write_p;
#ifdef DBM_TB_DIRECT
if (rn == pc) {
debug("TB: w: %p r: %p, BB: %d\n", write_p, read_address, basic_block);
#ifndef DBM_TRACES
// At least two consecutive BBs are needed
assert(thread_data->free_block == basic_block+1);
/*basic_block = */thread_data->free_block++;
data_p += BASIC_BLOCK_SIZE;
thumb_check_free_space(thread_data, &write_p, &data_p, &it_state,
&set_addr_prev_block, true, 472, basic_block);
#else
if (type == mambo_trace || type == mambo_trace_entry) {
#endif
thread_data->code_cache_meta[basic_block].rn = INT_MAX;
thread_data->code_cache_meta[basic_block].free_b = 0;
#ifdef FAST_BT
thumb_cmpi32 (&write_p, 0, rm, 0, TB_CACHE_SIZE-1);
#else
thumb_cmpi32 (&write_p, 0, rm, 0, MAX_TB_INDEX-1);
#endif
write_p += 2;
thumb_it16(&write_p, HI, 8);
write_p++;
#if defined(DBM_D_INLINE_HASH) && !defined(TB_STATS)
#ifdef FAST_BT
thumb_b32_helper(write_p, (uint32_t)write_p + TB_CACHE_SIZE*4 + 16 + (((uint32_t)write_p & 2) ? 0 : 2));
#else
thumb_b32_helper(write_p, (uint32_t)write_p + MAX_TB_INDEX + TB_CACHE_SIZE*4 + 10);
#endif
#else
#ifdef FAST_BT
thumb_b32_helper(write_p, (uint32_t)write_p + TB_CACHE_SIZE*4 + 14 + (((uint32_t)write_p & 2) ? 0 : 2));
#else
thumb_b32_helper(write_p, (uint32_t)write_p + MAX_TB_INDEX + TB_CACHE_SIZE*4 + 8);
#endif
#endif
write_p += 2;
#ifdef FAST_BT
thumb_bx16(&write_p, pc);
write_p++;
if (((uint32_t)write_p) & 2) {
write_p++;
}
arm_ldr((uint32_t **)&write_p, LDR_REG, pc, pc, (LSL << 5) | (2 << 7) | rm, 1, 1, 0);
write_p += 2;
#else
thumb_tbb32(&write_p, pc, rm);
write_p += 2;
#endif
#ifdef FAST_BT
*write_p = 0;
write_p++;
*write_p = 0;
write_p++;
for (int i = 0; i < TB_CACHE_SIZE; i++) {
*(uint32_t *)write_p = (uint32_t)write_p + ((TB_CACHE_SIZE -i) * 4) + 1;
write_p += 2;
}
#else
// Initially all indexes go to the slow dispatcher
for (int i = 0; i < MAX_TB_INDEX/2; i++) {
*write_p = (MAX_TB_INDEX/2 + TB_CACHE_SIZE*2);
*write_p |= *write_p << 8;
write_p++;
}
for (int i = 0; i < TB_CACHE_SIZE; i++) {
thumb_b32_helper(write_p, (uint32_t)write_p + (TB_CACHE_SIZE -i) * 4);
write_p += 2;
}
#endif
#endif // DBM_TB_DIRECT
#if defined(DBM_D_INLINE_HASH) && defined(DBM_TB_DIRECT)
thumb_b16(&write_p, ((uint32_t)write_p) & 2 ? 61 : 60);
write_p++;
#endif
#if defined(DBM_TB_DIRECT) && defined (DBM_TRACES)
}
#endif
#ifdef DBM_D_INLINE_HASH
sr[0] = 3;
while (sr[0] == rn || sr[0] == rm) {
sr[0]++;
}
sr[1] = sr[0] + 1;
while (sr[1] == rn || sr[1] == rm) {
sr[1]++;
}
sr[2] = sr[1] + 1;
while (sr[2] == rn || sr[2] == rm) {
sr[2]++;
}
reglist = (1 << sr[0]) | (1 << sr[1]) | (1 << sr[2]);
thumb_push16(&write_p, reglist);
write_p++;
thumb_check_free_space(thread_data, &write_p, &data_p, &it_state,
&set_addr_prev_block, true, 118, basic_block);
if (rn == pc) {
copy_to_reg_32bit(&write_p, sr[1], (uint32_t)read_address + 4);
rn = sr[1];
}
if (inst == THUMB_TBB32) {
thumb_ldrb32(&write_p, rn, sr[0], 0, rm);
} else {
thumb_ldrh32(&write_p, rn, sr[0], 1, rm);
}
write_p += 2;
thumb_add32(&write_p, 0, sr[1], 0, sr[1], 1, LSL, sr[0]);
write_p+=2;
thumb_addi32 (&write_p, 0, 0, sr[1], 0, sr[0], 1);
write_p+=2;
thumb_inline_hash_lookup(thread_data, &write_p, basic_block, sr[0], sr[1], sr[2], reglist, false, 4);
ihl_result_branch(thread_data, IHL_BRANCH_LDR_PC_PC, &write_p, reglist, sr, false, 4);
rn = pc;
#ifdef DBM_TRACES
if (type == mambo_bb) {
stop = true;
break;
}
#endif
#endif // DBM_D_INLINE_HASH
#ifdef DBM_TB_DIRECT
}
#endif
assert(rn == pc);
branch_save_context(thread_data, &write_p, true);
// Save the index for use by the TB linker
copy_to_reg_32bit(&write_p, scratch_reg, (uint32_t)&thread_data->code_cache_meta[basic_block].rn);
thumb_strwi32(&write_p, rm, scratch_reg, 0);
write_p += 2;
copy_to_reg_32bit(&write_p, scratch_reg, (uint32_t)read_address + 4);
if (rn == pc) {
rn = scratch_reg;
}
// load into R1, from rn + rm << 1
if (inst == THUMB_TBB32) {
thumb_ldrb32(&write_p, rn, scratch_reg2, 0, rm);
} else {
thumb_ldrh32(&write_p, rn, scratch_reg2, 1, rm);
}
write_p += 2;
thumb_add32(&write_p, 0, scratch_reg, 0, scratch_reg, 1, LSL, scratch_reg2);
write_p+=2;
thumb_addi32 (&write_p, 0, 0, scratch_reg, 0, r0, 1);
write_p+=2;
branch_jump(thread_data, &write_p, basic_block, 0, SETUP|INSERT_BRANCH|LATE_APP_SP);
stop = true;
break;
case THUMB_STMEA32:
case THUMB_STMFD32:
thumb_load_store_multiple32_decode_fields(read_address, &opcode, &writeback, &load_store, &rn, ®list);
assert(rn != pc);
assert((reglist & (1 << pc)) == 0);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_LDMFD32:
case THUMB_LDMEA32:
thumb_load_store_multiple32_decode_fields(read_address, &opcode, &writeback, &load_store, &rn, ®list);
assert(rn != pc && (!writeback || (reglist & (1 << rn)) == 0));
if (reglist & (1<<pc)) {
if (link_bx_alt(thread_data, &write_p, it_state.cond_inst_after_it, (uint32_t)read_address + 5)) {
it_cond_handled = true;
}
assert(writeback);
if (reglist & 0x7FFF) {
thumb_load_store_multiple32(&write_p, opcode, writeback, load_store, rn, reglist & 0x7FFF);
write_p += 2;
}
thread_data->code_cache_meta[basic_block].exit_branch_type = uncond_reg_thumb;
thread_data->code_cache_meta[basic_block].exit_branch_addr = write_p;
#ifdef DBM_INLINE_HASH
if (rn == sp) {
assert(inst == THUMB_LDMFD32);
thumb_push16(&write_p, (1 << r4) | (1 << r5));
write_p++;
thumb_ldr_sp16(&write_p, r5, 2);
write_p++;
thumb_str_sp16(&write_p, r6, 2);
write_p++;
} else {
thumb_push16(&write_p, (1 << r4) | (1 << r5) | (1 << r6));
write_p++;
thumb_load_store_multiple32(&write_p, opcode, writeback, load_store, r0, reglist);
write_p += 2;
}
thumb_check_free_space(thread_data, &write_p, &data_p, &it_state,
&set_addr_prev_block, true, IHL_FSPACE, basic_block);
thumb_inline_hash_lookup(thread_data, &write_p, basic_block, -1);
#else
branch_save_context(thread_data, &write_p, false);
assert(rn != r3);
if (rn == sp) {
rn = APP_SP;
}
thumb_load_store_multiple32(&write_p, opcode, writeback, load_store, rn, 1 << 0);
write_p+=2;
branch_jump(thread_data, &write_p, basic_block, 0, SETUP|INSERT_BRANCH);
#endif
stop = true;
} else {
if (inst == THUMB_LDMFD32 && writeback && rn == sp) {
set_inst_pop_regs = write_p;
inst_pop_regs_data = data_p;
poped_regs = reglist;
}
copy_thumb_32();
it_cond_handled = true;
}
break;
case THUMB_MCR32:
thumb_mcr32_decode_fields(read_address, &opc1, &crn, &rt, &coproc, &opc2, &crm);
assert(rt != pc);
copy_thumb_32();
break;
case THUMB_MRC32:
thumb_mrc32_decode_fields(read_address, &opc1, &crn, &rt, &coproc, &opc2, &crm);
if (coproc == 15 && opc1 == 0 && crn == 13 && crm == 0 && opc2 == 3) {
//fprintf(stderr, "Read TPIDRURO into R%d\n", rt);
assert(rt != pc);
modify_in_it_pre(5);
copy_to_reg_32bit(&write_p, rt, (uint32_t)(&thread_data->tls));
thumb_ldrwi32(&write_p, rt, rt, 0);
write_p+=2;
modify_in_it_post();
} else if (opc1 == 0b111 && crn == 0b0001 && coproc == 0b1010) {
// This instruction transfers the FPSCR.{N, Z, C, V} condition flags to the APSR.{N, Z, C, V} condition flags.
copy_thumb_32();
} else {
assert(rt != pc);
copy_thumb_32();
}
it_cond_handled = true;
break;
/* NEON and VFP instructions which might access the PC */
case THUMB_VFP_VLDM_DP:
case THUMB_VFP_VLDM_SP:
case THUMB_VFP_VSTM_DP:
case THUMB_VFP_VSTM_SP:
thumb_vfp_ld_st_m_decode_fields(read_address, &p, &upwards, &writeback, &rn, &d, &vd, &imm8);
assert(rn != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_VFP_VLDR_DP:
case THUMB_VFP_VLDR_SP:
case THUMB_VFP_VSTR_DP:
case THUMB_VFP_VSTR_SP:
thumb_vfp_vldr_vstr_decode_fields(read_address, &upwards, &rn, &d, &vd, &imm8);
if(rn == pc) {
modify_in_it_pre(7);
thumb_push16(&write_p, 1 << r0);
write_p++;
copy_to_reg_32bit(&write_p, r0, get_original_pc());
switch(inst) {
case THUMB_VFP_VLDR_DP:
thumb_vfp_vldr_dp(&write_p, upwards, r0, d, vd, imm8);
break;
case THUMB_VFP_VLDR_SP:
thumb_vfp_vldr_sp(&write_p, upwards, r0, d, vd, imm8);
break;
default:
fprintf(stderr, "inst: %d unimplemented\n", inst);
while(1);
}
write_p += 2;
thumb_pop16(&write_p, 1 << r0);
write_p++;
modify_in_it_post();
} else {
copy_thumb_32();
}
it_cond_handled = true;
break;
case THUMB_VFP_VMOV_CORE_SP:
thumb_vfp_vmov_core_sp_decode_fields(read_address, &opcode, &rt, &n, &vn);
assert(rt != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_VFP_VMOV_2CORE_DP:
thumb_vfp_vmov_2core_dp_decode_fields(read_address, &to_arm, &rt, &rt2, &m, &vm);
assert(rt != pc && rt2 != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_VFP_VMSR:
thumb_vfp_vmsr_decode_fields(read_address, &rt);
assert(rt != pc);
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_NEON_VDUP_CORE: {
uint32_t b, e, q;
thumb_neon_vdup_core_decode_fields(read_address, &b, &e, &q, &d, &vd, &rt);
assert(rt != pc);
copy_thumb_32();
it_cond_handled = true;
break;
}
case THUMB_NEON_VLDX_S_O:
case THUMB_NEON_VSTX_S_O:
case THUMB_NEON_VLDX_S_A:
case THUMB_NEON_VLDX_M:
case THUMB_NEON_VSTX_M: {
thumb_neon_vstx_m_decode_fields(read_address, &opcode, &size, &d, &vd, &rn, &align, &rm);
assert(rn != pc); // rm == pc has a special meaning, doesn't actually use the PC
copy_thumb_32();
it_cond_handled = true;
break;
}
case THUMB_VFP_VMOV_CORE_SCAL:
thumb_vfp_vmov_core_scal_decode_fields(read_address, &d, &vd, &opc1, &opc2, &rt);
assert(rt != pc);
copy_thumb_32();
it_cond_handled = true;
break;
/* NEON and VFP instructions which can't access the PC */
case THUMB_NEON_VABD_I:
case THUMB_NEON_VADD_I:
case THUMB_NEON_VADDL:
case THUMB_NEON_VADDW:
case THUMB_NEON_VAND:
case THUMB_NEON_VBIC:
case THUMB_NEON_VBSL:
case THUMB_NEON_VCGT_I:
case THUMB_NEON_VCLTZ:
case THUMB_NEON_VDUP_SCAL:
case THUMB_NEON_VEOR:
case THUMB_NEON_VEXT:
case THUMB_NEON_VHADD:
case THUMB_NEON_VMAX_I:
case THUMB_NEON_VMIN_I:
case THUMB_NEON_VMLAL_I:
case THUMB_NEON_VMLA_SCAL:
case THUMB_NEON_VMLS_SCAL:
case THUMB_NEON_VMOVI:
case THUMB_NEON_VMOVL:
case THUMB_NEON_VMOVN:
case THUMB_NEON_VMUL_I:
case THUMB_NEON_VMULL_I:
case THUMB_NEON_VMUL_SCAL:
case THUMB_NEON_VMVN:
case THUMB_NEON_VNEG:
case THUMB_NEON_VORN:
case THUMB_NEON_VORR:
case THUMB_NEON_VPADD_I:
case THUMB_NEON_VPADDL:
case THUMB_NEON_VQADD:
case THUMB_NEON_VQMOVN:
case THUMB_NEON_VQMOVUN:
case THUMB_NEON_VQRSHRUN:
case THUMB_NEON_VQSHRUN:
case THUMB_NEON_VQSUB:
case THUMB_NEON_VREV32:
case THUMB_NEON_VREV64:
case THUMB_NEON_VRHADD:
case THUMB_NEON_VRSHR:
case THUMB_NEON_VRSHRN:
case THUMB_NEON_VSHL:
case THUMB_NEON_VSHLI:
case THUMB_NEON_VSHLL:
case THUMB_NEON_VSHR:
case THUMB_NEON_VSHRN:
case THUMB_NEON_VSLI:
case THUMB_NEON_VSUB_I:
case THUMB_NEON_VSUBL:
case THUMB_NEON_VSUBW:
case THUMB_NEON_VSWP:
case THUMB_NEON_VTRN:
case THUMB_NEON_VTST:
case THUMB_VFP_VABS:
case THUMB_VFP_VADD:
case THUMB_VFP_VCMP:
case THUMB_VFP_VCMPE:
case THUMB_VFP_VCMPEZ:
case THUMB_VFP_VCMPZ:
case THUMB_VFP_VCVT_DP_SP:
case THUMB_VFP_VCVT_F_FP:
case THUMB_VFP_VCVT_F_I:
case THUMB_VFP_VDIV:
case THUMB_VFP_VMLA_F:
case THUMB_VFP_VMLS_F:
case THUMB_VFP_VMOV:
case THUMB_VFP_VMOVI:
case THUMB_VFP_VMRS: // rt=0xF is CPSR
case THUMB_VFP_VMUL:
case THUMB_VFP_VNEG:
case THUMB_VFP_VNMLA:
case THUMB_VFP_VNMLS:
case THUMB_VFP_VNMUL:
case THUMB_VFP_VPOP:
case THUMB_VFP_VPUSH:
case THUMB_VFP_VSQRT:
case THUMB_VFP_VSUB:
copy_thumb_32();
it_cond_handled = true;
break;
case THUMB_INVALID:
default:
if (read_address != start_scan) {
thumb_b32_helper(write_p, lookup_or_stub(thread_data, (uint32_t)read_address + 1));
stop = true;
it_cond_handled = true; // If execution actually reached this inst, something is broken anyway
fprintf(stderr, "WARN: deferred scanning because of unknown instruction at: %p\n", read_address);
break;
} else {
fprintf(stderr, "Unknown thumb instruction: %d at %p\n", inst, read_address);
while(1);
exit(EXIT_FAILURE);
}
}
if (it_state.cond_inst_after_it > 0) {
if(!it_cond_handled) {
fprintf(stderr, "Didn't handle instruction-after IT at %p, inst: %d\n", read_address, inst);
while(1);
//exit(EXIT_FAILURE);
}
do_it_iter(&it_state);
}
#ifdef PLUGINS_NEW
} // if(!skip_inst)
#endif
if ((uint16_t *)data_p <= write_p) {
fprintf(stderr, "%d, inst: %p, :write: %p\n", inst, data_p, write_p);
while(1);
}
if (!stop) {
thumb_check_free_space(thread_data, &write_p, &data_p, &it_state,
&set_addr_prev_block, true, MIN_FSPACE, basic_block);
}
debug("\n");
#ifdef PLUGINS_NEW
thumb_scanner_deliver_callbacks(thread_data, POST_INST_C, &it_state, read_address, inst, &write_p,
&data_p, basic_block, type, &set_addr_prev_block, !stop);
#endif
if (inst < THUMB_ADC32) {
read_address++;
} else {
read_address+= 2;
}
}
if (ldrex) {
if (thread_data->code_cache_meta[basic_block].exit_branch_type != uncond_imm_thumb
&& thread_data->code_cache_meta[basic_block].exit_branch_type != cond_imm_thumb
&& thread_data->code_cache_meta[basic_block].exit_branch_type != cbz_thumb) {
fprintf(stderr, "WARN: Basic block containing LDREX and no matching STREX "
"ends with branch type that can not be directly linked\n");
}
}
// We haven't strictly enforced updating write_p after the last instruction
return ((uint32_t)write_p - start_address + 4);
}
void thumb_encode_stub_bb(dbm_thread *thread_data, int basic_block, uint32_t target) {
uint16_t *write_p = (uint16_t *)&thread_data->code_cache->blocks[basic_block];
uint32_t *data_p = (uint32_t *)write_p;
data_p += BASIC_BLOCK_SIZE;
thumb_pop16(&write_p, (1 << r5) | (1 << r6));
write_p++;
branch_save_context(thread_data, &write_p, false);
branch_jump(thread_data, &write_p, basic_block, target, SETUP|REPLACE_TARGET|INSERT_BRANCH);
}
#endif // __arm__
|
the_stack_data/201024.c | /*Design algorithm write C code to delete all duplicate nodes from a doubly circular linked list.*/
#include <stdio.h>
#include <stdlib.h>
// doubly LL
typedef struct node
{
int data;
struct node *prev;
struct node *next;
} DLL;
DLL *allocateMemory(int k)
{
DLL *t = (DLL *)malloc(sizeof(DLL));
t->data = k;
t->prev = NULL;
t->next = NULL;
return t;
}
DLL *insert(DLL *h, int k)
{
DLL *t = allocateMemory(k);
if (!h)
{
t->next = t->prev = t;
h = t;
return h;
}
DLL *iter = h->prev;
t->next = h;
t->prev = iter;
iter->next = t;
h->prev = t;
return h;
}
void displayVerbose(DLL *h)
{
if (!h)
{
printf("Empty!\n");
return;
}
printf("| prev | data | next |\n");
DLL *iter = h;
do
{
printf("Its address: { %p }\n", iter);
printf("| %p | %d | %p |\n\n", iter->prev, iter->data, iter->next);
iter = iter->next;
} while (iter != h);
}
void display(DLL *h)
{
if (!h)
{
printf("Empty!\n");
return;
}
DLL *iter = h;
do
{
printf("%d", iter->data);
iter = iter->next;
} while (iter != h && printf(" <-> "));
printf("\n\n");
}
void deallocateMemory(DLL *head, DLL *iter)
{
if (!head)
{
return;
}
if (iter != head)
{
return;
}
deallocateMemory(head, iter->next);
printf("DELETION of key{%d}\n", iter->data);
free(iter);
}
int isPresent(DLL* head, int key){
if(!head){
return 0;
}
DLL* i = head;
do{
if(i->data == key)
return 1;
i = i->next;
} while (i != head);
return 0;
}
DLL *removeDuplicates(DLL *head)
{
// we move on
// one by one
// if we get that data is already in our history then skip it i.e.
// free it and link the next to its next
if(!head){
return head;
}
DLL *iter = head;
DLL *main = NULL;
do{
int key = iter->data;
if(!isPresent(main,key)){
main = insert(main, key);
}
iter = iter->next;
} while (iter != head);
// so we need to deallocate the memory of head;
iter = 0;
DLL *H = head;
do
{
iter = head;
head = head->next;
free(iter);
} while (head != H);
head = NULL;
H = NULL;
return main;
}
int main(int argc, char **argv)
{
DLL *head = NULL;
int ch;
do
{
printf("Your choices\n");
printf("[ 1 ] insertion\n");
printf("[ 2 ] display\n");
printf("[ 3 ] remove duplicates\n");
printf("[ 0 ] EXIT\n");
printf("> ");
scanf("%d", &ch);
int k;
switch (ch) {
case 1:{
printf("Enter the key to insert: ");
scanf("%d", &k);
head = insert(head, k);
break;
}
case 2:{
printf("DISPLAY\n");
display(head);
break;
}
case 3:{
head = removeDuplicates(head);
break;
}
}
} while (ch);
deallocateMemory(head, head->next);
printf("✅\n");
remove(argv[0]);
return EXIT_SUCCESS;
} |
the_stack_data/9513106.c | #include <unistd.h>
/*
Copyright 2016 Evgeniy Popov
*/
void swab(const void *from, void *to, ssize_t n)
{
ssize_t i = 0;
const char *fromm = from;
char tmp;
char tmpp;
char *too = to;
for (i = 0; i < n; i += 2) {
tmp = *(fromm + i);
tmpp = *(fromm + i + 1);
*(too + i) = tmpp;
*(too + i + 1) = tmp;
}
}
|
the_stack_data/111076775.c | #include <ncurses.h>
int main(void)
{
int x,y;
initscr();
getmaxyx(stdscr,y,x);
printw("Window size is %d rows, %d columns.\n",y,x);
refresh();
getch();
endwin();
return 0;
}
|
the_stack_data/148203.c | #include <stdio.h>
int main()
{
int total = 0;
int x, y, z, i;
for(i=100; i<1000; i++){
x = i % 10;
y = i / 10 % 10;
z = i / 100;
if ((x == y) + (x == z) + (z == y) == 0){
total += 1;
}
}
printf("Количество трехзначных чисел без повторяющихся цифр: %d\n", total);
return 0;
}
|
the_stack_data/165764251.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
void f(const char *f, int n);
void c(const char * f, int n);
//flag{E1F_FUnct10n_Math_S01vE}
//102 108 97 103 123 69 49 70 95 70 85 110 99 116 49 48 110 95 77 97 116 104 95 83 48 49 118 69 125 0
void f(const char *f, int n) {
if (n < 1 || n > 29) {
printf("Wrong\n");
return;
}
c(f, n);
}
void c(const char * f, int n) {
int a[]={34, 29, 76, 98, 43, 52, 97, 24, 40, 23, 4, 69, 44, 52, 43, 80, 1, 63, 79, 48, 55, 8, 26, 95, 4, 34, 82, 11, 51, 81};
int b[]={297, 169, 431, 229, 423, 257, 465, 288, 437, 86, 364, 123, 390, 485, 232, 352, 244, 469, 54, 359, 16, 110, 355, 244, 256, 94, 187, 19, 242, 432};
int c[]={3765, 3301, 7803, 10323, 5712, 3845, 5218, 1968, 4237, 1696, 704, 7713, 4746, 6517, 2339, 4192, 354, 6454, 6137, 5015, 6396, 942, 2825, 8129, 448, 1760, 9863, 778, 6617, 432};
for(int i = 0; i < n; ++i) {
int ax = a[i] * f[i];
int sum = ax + b[i];
if (sum != c[i]) {
printf("Wrong\n");
return;
}
}
printf("Your flag is: %s\n", f);
}
int main(int argc, char *argv[]) {
char flag[255];
printf("Please input your flag:\n");
scanf("%s", flag);
f(flag, strlen(flag));
return 0;
} |
the_stack_data/95449849.c |
#if 0 /* in case someone actually tries to compile this */
/* example.c - an example of using libpng */
/* This is an example of how to use libpng to read and write PNG files.
* The file libpng.txt is much more verbose then this. If you have not
* read it, do so first. This was designed to be a starting point of an
* implementation. This is not officially part of libpng, is hereby placed
* in the public domain, and therefore does not require a copyright notice.
*
* This file does not currently compile, because it is missing certain
* parts, like allocating memory to hold an image. You will have to
* supply these parts to get it to compile. For an example of a minimal
* working PNG reader/writer, see pngtest.c, included in this distribution;
* see also the programs in the contrib directory.
*/
#include "png.h"
/* The png_jmpbuf() macro, used in error handling, became available in
* libpng version 1.0.6. If you want to be able to run your code with older
* versions of libpng, you must define the macro yourself (but only if it
* is not already defined by libpng!).
*/
#ifndef png_jmpbuf
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
#endif
/* Check to see if a file is a PNG file using png_sig_cmp(). png_sig_cmp()
* returns zero if the image is a PNG and nonzero if it isn't a PNG.
*
* The function check_if_png() shown here, but not used, returns nonzero (true)
* if the file can be opened and is a PNG, 0 (false) otherwise.
*
* If this call is successful, and you are going to keep the file open,
* you should call png_set_sig_bytes(png_ptr, PNG_BYTES_TO_CHECK); once
* you have created the png_ptr, so that libpng knows your application
* has read that many bytes from the start of the file. Make sure you
* don't call png_set_sig_bytes() with more than 8 bytes read or give it
* an incorrect number of bytes read, or you will either have read too
* many bytes (your fault), or you are telling libpng to read the wrong
* number of magic bytes (also your fault).
*
* Many applications already read the first 2 or 4 bytes from the start
* of the image to determine the file type, so it would be easiest just
* to pass the bytes to png_sig_cmp() or even skip that if you know
* you have a PNG file, and call png_set_sig_bytes().
*/
#define PNG_BYTES_TO_CHECK 4
int check_if_png(char *file_name, FILE **fp)
{
char buf[PNG_BYTES_TO_CHECK];
/* Open the prospective PNG file. */
if ((*fp = fopen(file_name, "rb")) == NULL)
return 0;
/* Read in some of the signature bytes */
if (fread(buf, 1, PNG_BYTES_TO_CHECK, *fp) != PNG_BYTES_TO_CHECK)
return 0;
/* Compare the first PNG_BYTES_TO_CHECK bytes of the signature.
Return nonzero (true) if they match */
return(!png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK));
}
/* Read a PNG file. You may want to return an error code if the read
* fails (depending upon the failure). There are two "prototypes" given
* here - one where we are given the filename, and we need to open the
* file, and the other where we are given an open file (possibly with
* some or all of the magic bytes read - see comments above).
*/
#ifdef open_file /* prototype 1 */
void read_png(char *file_name) /* We need to open the file */
{
png_structp png_ptr;
png_infop info_ptr;
unsigned int sig_read = 0;
png_uint_32 width, height;
int bit_depth, color_type, interlace_type;
FILE *fp;
if ((fp = fopen(file_name, "rb")) == NULL)
return (ERROR);
#else no_open_file /* prototype 2 */
void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
{
png_structp png_ptr;
png_infop info_ptr;
png_uint_32 width, height;
int bit_depth, color_type, interlace_type;
#endif no_open_file /* only use one prototype! */
/* Create and initialize the png_struct with the desired error handler
* functions. If you want to use the default stderr and longjump method,
* you can supply NULL for the last three parameters. We also supply the
* the compiler header file version, so that we know if the application
* was compiled with a compatible version of the library. REQUIRED
*/
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
png_voidp user_error_ptr, user_error_fn, user_warning_fn);
if (png_ptr == NULL)
{
fclose(fp);
return (ERROR);
}
/* Allocate/initialize the memory for image information. REQUIRED. */
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
fclose(fp);
png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
return (ERROR);
}
/* Set error handling if you are using the setjmp/longjmp method (this is
* the normal method of doing things with libpng). REQUIRED unless you
* set up your own error handlers in the png_create_read_struct() earlier.
*/
if (setjmp(png_jmpbuf(png_ptr)))
{
/* Free all of the memory associated with the png_ptr and info_ptr */
png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
fclose(fp);
/* If we get here, we had a problem reading the file */
return (ERROR);
}
/* One of the following I/O initialization methods is REQUIRED */
#ifdef streams /* PNG file I/O method 1 */
/* Set up the input control if you are using standard C streams */
png_init_io(png_ptr, fp);
#else no_streams /* PNG file I/O method 2 */
/* If you are using replacement read functions, instead of calling
* png_init_io() here you would call:
*/
png_set_read_fn(png_ptr, (void *)user_io_ptr, user_read_fn);
/* where user_io_ptr is a structure you want available to the callbacks */
#endif no_streams /* Use only one I/O method! */
/* If we have already read some of the signature */
png_set_sig_bytes(png_ptr, sig_read);
#ifdef hilevel
/*
* If you have enough memory to read in the entire image at once,
* and you need to specify only transforms that can be controlled
* with one of the PNG_TRANSFORM_* bits (this presently excludes
* dithering, filling, setting background, and doing gamma
* adjustment), then you can read the entire image (including
* pixels) into the info structure with this call:
*/
png_read_png(png_ptr, info_ptr, png_transforms, png_voidp_NULL);
#else
/* OK, you're doing it the hard way, with the lower-level functions */
/* The call to png_read_info() gives us all of the information from the
* PNG file before the first IDAT (image data chunk). REQUIRED
*/
png_read_info(png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
&interlace_type, int_p_NULL, int_p_NULL);
/* Set up the data transformations you want. Note that these are all
* optional. Only call them if you want/need them. Many of the
* transformations only work on specific types of images, and many
* are mutually exclusive.
*/
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
png_set_strip_16(png_ptr);
/* Strip alpha bytes from the input data without combining with the
* background (not recommended).
*/
png_set_strip_alpha(png_ptr);
/* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
* byte into separate bytes (useful for paletted and grayscale images).
*/
png_set_packing(png_ptr);
/* Change the order of packed pixels to least significant bit first
* (not useful if you are using png_set_packing). */
png_set_packswap(png_ptr);
/* Expand paletted colors into true RGB triplets */
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_palette_rgb(png_ptr);
/* Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_gray_1_2_4_to_8(png_ptr);
/* Expand paletted or RGB images with transparency to full alpha channels
* so the data will be available as RGBA quartets.
*/
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(png_ptr);
/* Set the background color to draw transparent and alpha images over.
* It is possible to set the red, green, and blue components directly
* for paletted images instead of supplying a palette index. Note that
* even if the PNG file supplies a background, you are not required to
* use it - you should use the (solid) application background if it has one.
*/
png_color_16 my_background, *image_background;
if (png_get_bKGD(png_ptr, info_ptr, &image_background))
png_set_background(png_ptr, image_background,
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
else
png_set_background(png_ptr, &my_background,
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
/* Some suggestions as to how to get a screen gamma value */
/* Note that screen gamma is the display_exponent, which includes
* the CRT_exponent and any correction for viewing conditions */
if (/* We have a user-defined screen gamma value */)
{
screen_gamma = user-defined screen_gamma;
}
/* This is one way that applications share the same screen gamma value */
else if ((gamma_str = getenv("SCREEN_GAMMA")) != NULL)
{
screen_gamma = atof(gamma_str);
}
/* If we don't have another value */
else
{
screen_gamma = 2.2; /* A good guess for a PC monitors in a dimly
lit room */
screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */
}
/* Tell libpng to handle the gamma conversion for you. The final call
* is a good guess for PC generated images, but it should be configurable
* by the user at run time by the user. It is strongly suggested that
* your application support gamma correction.
*/
int intent;
if (png_get_sRGB(png_ptr, info_ptr, &intent))
png_set_gamma(png_ptr, screen_gamma, 0.45455);
else
{
double image_gamma;
if (png_get_gAMA(png_ptr, info_ptr, &image_gamma))
png_set_gamma(png_ptr, screen_gamma, image_gamma);
else
png_set_gamma(png_ptr, screen_gamma, 0.45455);
}
/* Dither RGB files down to 8 bit palette or reduce palettes
* to the number of colors available on your screen.
*/
if (color_type & PNG_COLOR_MASK_COLOR)
{
int num_palette;
png_colorp palette;
/* This reduces the image to the application supplied palette */
if (/* we have our own palette */)
{
/* An array of colors to which the image should be dithered */
png_color std_color_cube[MAX_SCREEN_COLORS];
png_set_dither(png_ptr, std_color_cube, MAX_SCREEN_COLORS,
MAX_SCREEN_COLORS, png_uint_16p_NULL, 0);
}
/* This reduces the image to the palette supplied in the file */
else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette))
{
png_uint_16p histogram = NULL;
png_get_hIST(png_ptr, info_ptr, &histogram);
png_set_dither(png_ptr, palette, num_palette,
max_screen_colors, histogram, 0);
}
}
/* invert monochrome files to have 0 as white and 1 as black */
png_set_invert_mono(png_ptr);
/* If you want to shift the pixel values from the range [0,255] or
* [0,65535] to the original [0,7] or [0,31], or whatever range the
* colors were originally in:
*/
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
{
png_color_8p sig_bit;
png_get_sBIT(png_ptr, info_ptr, &sig_bit);
png_set_shift(png_ptr, sig_bit);
}
/* flip the RGB pixels to BGR (or RGBA to BGRA) */
if (color_type & PNG_COLOR_MASK_COLOR)
png_set_bgr(png_ptr);
/* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
png_set_swap_alpha(png_ptr);
/* swap bytes of 16 bit files to least significant byte first */
png_set_swap(png_ptr);
/* Add filler (or alpha) byte (before/after each RGB triplet) */
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
/* Turn on interlace handling. REQUIRED if you are not using
* png_read_image(). To see how to handle interlacing passes,
* see the png_read_row() method below:
*/
number_passes = png_set_interlace_handling(png_ptr);
/* Optional call to gamma correct and add the background to the palette
* and update info structure. REQUIRED if you are expecting libpng to
* update the palette for you (ie you selected such a transform above).
*/
png_read_update_info(png_ptr, info_ptr);
/* Allocate the memory to hold the image using the fields of info_ptr. */
/* The easiest way to read the image: */
png_bytep row_pointers[height];
for (row = 0; row < height; row++)
{
row_pointers[row] = png_malloc(png_ptr, png_get_rowbytes(png_ptr,
info_ptr));
}
/* Now it's time to read the image. One of these methods is REQUIRED */
#ifdef entire /* Read the entire image in one go */
png_read_image(png_ptr, row_pointers);
#else no_entire /* Read the image one or more scanlines at a time */
/* The other way to read images - deal with interlacing: */
for (pass = 0; pass < number_passes; pass++)
{
#ifdef single /* Read the image a single row at a time */
for (y = 0; y < height; y++)
{
png_read_rows(png_ptr, &row_pointers[y], png_bytepp_NULL, 1);
}
#else no_single /* Read the image several rows at a time */
for (y = 0; y < height; y += number_of_rows)
{
#ifdef sparkle /* Read the image using the "sparkle" effect. */
png_read_rows(png_ptr, &row_pointers[y], png_bytepp_NULL,
number_of_rows);
#else no_sparkle /* Read the image using the "rectangle" effect */
png_read_rows(png_ptr, png_bytepp_NULL, &row_pointers[y],
number_of_rows);
#endif no_sparkle /* use only one of these two methods */
}
/* if you want to display the image after every pass, do
so here */
#endif no_single /* use only one of these two methods */
}
#endif no_entire /* use only one of these two methods */
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
png_read_end(png_ptr, info_ptr);
#endif hilevel
/* At this point you have read the entire image */
/* clean up after the read, and free any memory allocated - REQUIRED */
png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
/* close the file */
fclose(fp);
/* that's it */
return (OK);
}
/* progressively read a file */
int
initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
{
/* Create and initialize the png_struct with the desired error handler
* functions. If you want to use the default stderr and longjump method,
* you can supply NULL for the last three parameters. We also check that
* the library version is compatible in case we are using dynamically
* linked libraries.
*/
*png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
png_voidp user_error_ptr, user_error_fn, user_warning_fn);
if (*png_ptr == NULL)
{
*info_ptr = NULL;
return (ERROR);
}
*info_ptr = png_create_info_struct(png_ptr);
if (*info_ptr == NULL)
{
png_destroy_read_struct(png_ptr, info_ptr, png_infopp_NULL);
return (ERROR);
}
if (setjmp(png_jmpbuf((*png_ptr))))
{
png_destroy_read_struct(png_ptr, info_ptr, png_infopp_NULL);
return (ERROR);
}
/* This one's new. You will need to provide all three
* function callbacks, even if you aren't using them all.
* If you aren't using all functions, you can specify NULL
* parameters. Even when all three functions are NULL,
* you need to call png_set_progressive_read_fn().
* These functions shouldn't be dependent on global or
* static variables if you are decoding several images
* simultaneously. You should store stream specific data
* in a separate struct, given as the second parameter,
* and retrieve the pointer from inside the callbacks using
* the function png_get_progressive_ptr(png_ptr).
*/
png_set_progressive_read_fn(*png_ptr, (void *)stream_data,
info_callback, row_callback, end_callback);
return (OK);
}
int
process_data(png_structp *png_ptr, png_infop *info_ptr,
png_bytep buffer, png_uint_32 length)
{
if (setjmp(png_jmpbuf((*png_ptr))))
{
/* Free the png_ptr and info_ptr memory on error */
png_destroy_read_struct(png_ptr, info_ptr, png_infopp_NULL);
return (ERROR);
}
/* This one's new also. Simply give it chunks of data as
* they arrive from the data stream (in order, of course).
* On Segmented machines, don't give it any more than 64K.
* The library seems to run fine with sizes of 4K, although
* you can give it much less if necessary (I assume you can
* give it chunks of 1 byte, but I haven't tried with less
* than 256 bytes yet). When this function returns, you may
* want to display any rows that were generated in the row
* callback, if you aren't already displaying them there.
*/
png_process_data(*png_ptr, *info_ptr, buffer, length);
return (OK);
}
info_callback(png_structp png_ptr, png_infop info)
{
/* do any setup here, including setting any of the transformations
* mentioned in the Reading PNG files section. For now, you _must_
* call either png_start_read_image() or png_read_update_info()
* after all the transformations are set (even if you don't set
* any). You may start getting rows before png_process_data()
* returns, so this is your last chance to prepare for that.
*/
}
row_callback(png_structp png_ptr, png_bytep new_row,
png_uint_32 row_num, int pass)
{
/*
* This function is called for every row in the image. If the
* image is interlaced, and you turned on the interlace handler,
* this function will be called for every row in every pass.
*
* In this function you will receive a pointer to new row data from
* libpng called new_row that is to replace a corresponding row (of
* the same data format) in a buffer allocated by your application.
*
* The new row data pointer new_row may be NULL, indicating there is
* no new data to be replaced (in cases of interlace loading).
*
* If new_row is not NULL then you need to call
* png_progressive_combine_row() to replace the corresponding row as
* shown below:
*/
/* Check if row_num is in bounds. */
if((row_num >= 0) && (row_num < height))
{
/* Get pointer to corresponding row in our
* PNG read buffer.
*/
png_bytep old_row = ((png_bytep *)our_data)[row_num];
/* If both rows are allocated then copy the new row
* data to the corresponding row data.
*/
if((old_row != NULL) && (new_row != NULL))
png_progressive_combine_row(png_ptr, old_row, new_row);
}
/*
* The rows and passes are called in order, so you don't really
* need the row_num and pass, but I'm supplying them because it
* may make your life easier.
*
* For the non-NULL rows of interlaced images, you must call
* png_progressive_combine_row() passing in the new row and the
* old row, as demonstrated above. You can call this function for
* NULL rows (it will just return) and for non-interlaced images
* (it just does the png_memcpy for you) if it will make the code
* easier. Thus, you can just do this for all cases:
*/
png_progressive_combine_row(png_ptr, old_row, new_row);
/* where old_row is what was displayed for previous rows. Note
* that the first pass (pass == 0 really) will completely cover
* the old row, so the rows do not have to be initialized. After
* the first pass (and only for interlaced images), you will have
* to pass the current row as new_row, and the function will combine
* the old row and the new row.
*/
}
end_callback(png_structp png_ptr, png_infop info)
{
/* this function is called when the whole image has been read,
* including any chunks after the image (up to and including
* the IEND). You will usually have the same info chunk as you
* had in the header, although some data may have been added
* to the comments and time fields.
*
* Most people won't do much here, perhaps setting a flag that
* marks the image as finished.
*/
}
/* write a png file */
void write_png(char *file_name /* , ... other image information ... */)
{
FILE *fp;
png_structp png_ptr;
png_infop info_ptr;
png_colorp palette;
/* open the file */
fp = fopen(file_name, "wb");
if (fp == NULL)
return (ERROR);
/* Create and initialize the png_struct with the desired error handler
* functions. If you want to use the default stderr and longjump method,
* you can supply NULL for the last three parameters. We also check that
* the library version is compatible with the one used at compile time,
* in case we are using dynamically linked libraries. REQUIRED.
*/
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
png_voidp user_error_ptr, user_error_fn, user_warning_fn);
if (png_ptr == NULL)
{
fclose(fp);
return (ERROR);
}
/* Allocate/initialize the image information data. REQUIRED */
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
fclose(fp);
png_destroy_write_struct(&png_ptr, png_infopp_NULL);
return (ERROR);
}
/* Set error handling. REQUIRED if you aren't supplying your own
* error handling functions in the png_create_write_struct() call.
*/
if (setjmp(png_jmpbuf(png_ptr)))
{
/* If we get here, we had a problem reading the file */
fclose(fp);
png_destroy_write_struct(&png_ptr, &info_ptr);
return (ERROR);
}
/* One of the following I/O initialization functions is REQUIRED */
#ifdef streams /* I/O initialization method 1 */
/* set up the output control if you are using standard C streams */
png_init_io(png_ptr, fp);
#else no_streams /* I/O initialization method 2 */
/* If you are using replacement read functions, instead of calling
* png_init_io() here you would call */
png_set_write_fn(png_ptr, (void *)user_io_ptr, user_write_fn,
user_IO_flush_function);
/* where user_io_ptr is a structure you want available to the callbacks */
#endif no_streams /* only use one initialization method */
#ifdef hilevel
/* This is the easy way. Use it if you already have all the
* image info living info in the structure. You could "|" many
* PNG_TRANSFORM flags into the png_transforms integer here.
*/
png_write_png(png_ptr, info_ptr, png_transforms, png_voidp_NULL);
#else
/* This is the hard way */
/* Set the image information here. Width and height are up to 2^31,
* bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
* the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY,
* PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB,
* or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or
* PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
* currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED
*/
png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, PNG_COLOR_TYPE_???,
PNG_INTERLACE_????, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
/* set the palette if there is one. REQUIRED for indexed-color images */
palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH
* sizeof (png_color));
/* ... set palette colors ... */
png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH);
/* You must not free palette here, because png_set_PLTE only makes a link to
the palette that you malloced. Wait until you are about to destroy
the png structure. */
/* optional significant bit chunk */
/* if we are dealing with a grayscale image then */
sig_bit.gray = true_bit_depth;
/* otherwise, if we are dealing with a color image then */
sig_bit.red = true_red_bit_depth;
sig_bit.green = true_green_bit_depth;
sig_bit.blue = true_blue_bit_depth;
/* if the image has an alpha channel then */
sig_bit.alpha = true_alpha_bit_depth;
png_set_sBIT(png_ptr, info_ptr, sig_bit);
/* Optional gamma chunk is strongly suggested if you have any guess
* as to the correct gamma of the image.
*/
png_set_gAMA(png_ptr, info_ptr, gamma);
/* Optionally write comments into the image */
text_ptr[0].key = "Title";
text_ptr[0].text = "Mona Lisa";
text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr[1].key = "Author";
text_ptr[1].text = "Leonardo DaVinci";
text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr[2].key = "Description";
text_ptr[2].text = "<long text>";
text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt;
#ifdef PNG_iTXt_SUPPORTED
text_ptr[0].lang = NULL;
text_ptr[1].lang = NULL;
text_ptr[2].lang = NULL;
#endif
png_set_text(png_ptr, info_ptr, text_ptr, 3);
/* other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs, */
/* note that if sRGB is present the gAMA and cHRM chunks must be ignored
* on read and must be written in accordance with the sRGB profile */
/* Write the file header information. REQUIRED */
png_write_info(png_ptr, info_ptr);
/* If you want, you can write the info in two steps, in case you need to
* write your private chunk ahead of PLTE:
*
* png_write_info_before_PLTE(write_ptr, write_info_ptr);
* write_my_chunk();
* png_write_info(png_ptr, info_ptr);
*
* However, given the level of known- and unknown-chunk support in 1.1.0
* and up, this should no longer be necessary.
*/
/* Once we write out the header, the compression type on the text
* chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or
* PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again
* at the end.
*/
/* set up the transformations you want. Note that these are
* all optional. Only call them if you want them.
*/
/* invert monochrome pixels */
png_set_invert_mono(png_ptr);
/* Shift the pixels up to a legal bit depth and fill in
* as appropriate to correctly scale the image.
*/
png_set_shift(png_ptr, &sig_bit);
/* pack pixels into bytes */
png_set_packing(png_ptr);
/* swap location of alpha bytes from ARGB to RGBA */
png_set_swap_alpha(png_ptr);
/* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into
* RGB (4 channels -> 3 channels). The second parameter is not used.
*/
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
/* flip BGR pixels to RGB */
png_set_bgr(png_ptr);
/* swap bytes of 16-bit files to most significant byte first */
png_set_swap(png_ptr);
/* swap bits of 1, 2, 4 bit packed pixel formats */
png_set_packswap(png_ptr);
/* turn on interlace handling if you are not using png_write_image() */
if (interlacing)
number_passes = png_set_interlace_handling(png_ptr);
else
number_passes = 1;
/* The easiest way to write the image (you may have a different memory
* layout, however, so choose what fits your needs best). You need to
* use the first method if you aren't handling interlacing yourself.
*/
png_uint_32 k, height, width;
png_byte image[height][width*bytes_per_pixel];
png_bytep row_pointers[height];
for (k = 0; k < height; k++)
row_pointers[k] = image + k*width*bytes_per_pixel;
/* One of the following output methods is REQUIRED */
#ifdef entire /* write out the entire image data in one call */
png_write_image(png_ptr, row_pointers);
/* the other way to write the image - deal with interlacing */
#else no_entire /* write out the image data by one or more scanlines */
/* The number of passes is either 1 for non-interlaced images,
* or 7 for interlaced images.
*/
for (pass = 0; pass < number_passes; pass++)
{
/* Write a few rows at a time. */
png_write_rows(png_ptr, &row_pointers[first_row], number_of_rows);
/* If you are only writing one row at a time, this works */
for (y = 0; y < height; y++)
{
png_write_rows(png_ptr, &row_pointers[y], 1);
}
}
#endif no_entire /* use only one output method */
/* You can write optional chunks like tEXt, zTXt, and tIME at the end
* as well. Shouldn't be necessary in 1.1.0 and up as all the public
* chunks are supported and you can use png_set_unknown_chunks() to
* register unknown chunks into the info structure to be written out.
*/
/* It is REQUIRED to call this to finish writing the rest of the file */
png_write_end(png_ptr, info_ptr);
#endif hilevel
/* If you png_malloced a palette, free it here (don't free info_ptr->palette,
as recommended in versions 1.0.5m and earlier of this example; if
libpng mallocs info_ptr->palette, libpng will free it). If you
allocated it with malloc() instead of png_malloc(), use free() instead
of png_free(). */
png_free(png_ptr, palette);
palette=NULL;
/* Similarly, if you png_malloced any data that you passed in with
png_set_something(), such as a hist or trans array, free it here,
when you can be sure that libpng is through with it. */
png_free(png_ptr, trans);
trans=NULL;
/* clean up after the write, and free any memory allocated */
png_destroy_write_struct(&png_ptr, &info_ptr);
/* close the file */
fclose(fp);
/* that's it */
return (OK);
}
#endif /* if 0 */
|
the_stack_data/120841.c | /**
* file: sums.c
* See https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
*
* Created by hengxin on 11/21/21.
*/
#include <stdio.h>
int main() {
float f = 0.1f;
float sum = 0.0f;
for (int i = 0; i < 10; ++i) {
sum += f;
}
float product = f * 10;
printf("sum = %.15f\nmul = %.15f\n",
sum, product);
return 0;
} |
the_stack_data/15761561.c | extern void __VERIFIER_error() __attribute__ ((__noreturn__));
void __VERIFIER_assert(int expression) { if (!expression) { ERROR: /* assert not proved */
/* assert not proved */
__VERIFIER_error(); }; return; }
int __global_lock;
void __VERIFIER_atomic_begin() { /* reachable */
/* reachable */
/* reachable */
/* reachable */
/* reachable */
__VERIFIER_assume(__global_lock==0); __global_lock=1; return; }
void __VERIFIER_atomic_end() { __VERIFIER_assume(__global_lock==1); __global_lock=0; return; }
#include "assert.h"
#include "pthread.h"
#ifndef TRUE
#define TRUE (_Bool)1
#endif
#ifndef FALSE
#define FALSE (_Bool)0
#endif
#ifndef NULL
#define NULL ((void*)0)
#endif
#ifndef FENCE
#define FENCE(x) ((void)0)
#endif
#ifndef IEEE_FLOAT_EQUAL
#define IEEE_FLOAT_EQUAL(x,y) (x==y)
#endif
#ifndef IEEE_FLOAT_NOTEQUAL
#define IEEE_FLOAT_NOTEQUAL(x,y) (x!=y)
#endif
void * P0(void *arg);
void * P1(void *arg);
void fence();
void isync();
void lwfence();
int __unbuffered_cnt;
int __unbuffered_cnt = 0;
int __unbuffered_p0_EAX;
int __unbuffered_p0_EAX = 0;
int __unbuffered_p1_EAX;
int __unbuffered_p1_EAX = 0;
int __unbuffered_p1_EBX;
int __unbuffered_p1_EBX = 0;
_Bool main$tmp_guard0;
_Bool main$tmp_guard1;
int x;
int x = 0;
int y;
int y = 0;
int z;
int z = 0;
_Bool z$flush_delayed;
int z$mem_tmp;
_Bool z$r_buff0_thd0;
_Bool z$r_buff0_thd1;
_Bool z$r_buff0_thd2;
_Bool z$r_buff1_thd0;
_Bool z$r_buff1_thd1;
_Bool z$r_buff1_thd2;
_Bool z$read_delayed;
int *z$read_delayed_var;
int z$w_buff0;
_Bool z$w_buff0_used;
int z$w_buff1;
_Bool z$w_buff1_used;
_Bool weak$$choice0;
_Bool weak$$choice2;
void * P0(void *arg)
{
__VERIFIER_atomic_begin();
z$w_buff1 = z$w_buff0;
z$w_buff0 = 1;
z$w_buff1_used = z$w_buff0_used;
z$w_buff0_used = TRUE;
__VERIFIER_assert(!(z$w_buff1_used && z$w_buff0_used));
z$r_buff1_thd0 = z$r_buff0_thd0;
z$r_buff1_thd1 = z$r_buff0_thd1;
z$r_buff1_thd2 = z$r_buff0_thd2;
z$r_buff0_thd1 = TRUE;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
__unbuffered_p0_EAX = x;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
z = z$w_buff0_used && z$r_buff0_thd1 ? z$w_buff0 : (z$w_buff1_used && z$r_buff1_thd1 ? z$w_buff1 : z);
z$w_buff0_used = z$w_buff0_used && z$r_buff0_thd1 ? FALSE : z$w_buff0_used;
z$w_buff1_used = z$w_buff0_used && z$r_buff0_thd1 || z$w_buff1_used && z$r_buff1_thd1 ? FALSE : z$w_buff1_used;
z$r_buff0_thd1 = z$w_buff0_used && z$r_buff0_thd1 ? FALSE : z$r_buff0_thd1;
z$r_buff1_thd1 = z$w_buff0_used && z$r_buff0_thd1 || z$w_buff1_used && z$r_buff1_thd1 ? FALSE : z$r_buff1_thd1;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
__unbuffered_cnt = __unbuffered_cnt + 1;
__VERIFIER_atomic_end();
return nondet_0();
}
void * P1(void *arg)
{
__VERIFIER_atomic_begin();
x = 1;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
y = 1;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
__unbuffered_p1_EAX = y;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
weak$$choice0 = nondet_1();
weak$$choice2 = nondet_1();
z$flush_delayed = weak$$choice2;
z$mem_tmp = z;
z = !z$w_buff0_used || !z$r_buff0_thd2 && !z$w_buff1_used || !z$r_buff0_thd2 && !z$r_buff1_thd2 ? z : (z$w_buff0_used && z$r_buff0_thd2 ? z$w_buff0 : z$w_buff1);
z$w_buff0 = weak$$choice2 ? z$w_buff0 : (!z$w_buff0_used || !z$r_buff0_thd2 && !z$w_buff1_used || !z$r_buff0_thd2 && !z$r_buff1_thd2 ? z$w_buff0 : (z$w_buff0_used && z$r_buff0_thd2 ? z$w_buff0 : z$w_buff0));
z$w_buff1 = weak$$choice2 ? z$w_buff1 : (!z$w_buff0_used || !z$r_buff0_thd2 && !z$w_buff1_used || !z$r_buff0_thd2 && !z$r_buff1_thd2 ? z$w_buff1 : (z$w_buff0_used && z$r_buff0_thd2 ? z$w_buff1 : z$w_buff1));
z$w_buff0_used = weak$$choice2 ? z$w_buff0_used : (!z$w_buff0_used || !z$r_buff0_thd2 && !z$w_buff1_used || !z$r_buff0_thd2 && !z$r_buff1_thd2 ? z$w_buff0_used : (z$w_buff0_used && z$r_buff0_thd2 ? FALSE : z$w_buff0_used));
z$w_buff1_used = weak$$choice2 ? z$w_buff1_used : (!z$w_buff0_used || !z$r_buff0_thd2 && !z$w_buff1_used || !z$r_buff0_thd2 && !z$r_buff1_thd2 ? z$w_buff1_used : (z$w_buff0_used && z$r_buff0_thd2 ? FALSE : FALSE));
z$r_buff0_thd2 = weak$$choice2 ? z$r_buff0_thd2 : (!z$w_buff0_used || !z$r_buff0_thd2 && !z$w_buff1_used || !z$r_buff0_thd2 && !z$r_buff1_thd2 ? z$r_buff0_thd2 : (z$w_buff0_used && z$r_buff0_thd2 ? FALSE : z$r_buff0_thd2));
z$r_buff1_thd2 = weak$$choice2 ? z$r_buff1_thd2 : (!z$w_buff0_used || !z$r_buff0_thd2 && !z$w_buff1_used || !z$r_buff0_thd2 && !z$r_buff1_thd2 ? z$r_buff1_thd2 : (z$w_buff0_used && z$r_buff0_thd2 ? FALSE : FALSE));
__unbuffered_p1_EBX = z;
z = z$flush_delayed ? z$mem_tmp : z;
z$flush_delayed = FALSE;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
z = z$w_buff0_used && z$r_buff0_thd2 ? z$w_buff0 : (z$w_buff1_used && z$r_buff1_thd2 ? z$w_buff1 : z);
z$w_buff0_used = z$w_buff0_used && z$r_buff0_thd2 ? FALSE : z$w_buff0_used;
z$w_buff1_used = z$w_buff0_used && z$r_buff0_thd2 || z$w_buff1_used && z$r_buff1_thd2 ? FALSE : z$w_buff1_used;
z$r_buff0_thd2 = z$w_buff0_used && z$r_buff0_thd2 ? FALSE : z$r_buff0_thd2;
z$r_buff1_thd2 = z$w_buff0_used && z$r_buff0_thd2 || z$w_buff1_used && z$r_buff1_thd2 ? FALSE : z$r_buff1_thd2;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
__unbuffered_cnt = __unbuffered_cnt + 1;
__VERIFIER_atomic_end();
return nondet_0();
}
void fence()
{
}
void isync()
{
}
void lwfence()
{
}
int main()
{
pthread_create(NULL, NULL, P0, NULL);
pthread_create(NULL, NULL, P1, NULL);
__VERIFIER_atomic_begin();
main$tmp_guard0 = __unbuffered_cnt == 2;
__VERIFIER_atomic_end();
__VERIFIER_assume(main$tmp_guard0);
__VERIFIER_atomic_begin();
z = z$w_buff0_used && z$r_buff0_thd0 ? z$w_buff0 : (z$w_buff1_used && z$r_buff1_thd0 ? z$w_buff1 : z);
z$w_buff0_used = z$w_buff0_used && z$r_buff0_thd0 ? FALSE : z$w_buff0_used;
z$w_buff1_used = z$w_buff0_used && z$r_buff0_thd0 || z$w_buff1_used && z$r_buff1_thd0 ? FALSE : z$w_buff1_used;
z$r_buff0_thd0 = z$w_buff0_used && z$r_buff0_thd0 ? FALSE : z$r_buff0_thd0;
z$r_buff1_thd0 = z$w_buff0_used && z$r_buff0_thd0 || z$w_buff1_used && z$r_buff1_thd0 ? FALSE : z$r_buff1_thd0;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
/* Program proven to be relaxed for X86, model checker says YES. */
main$tmp_guard1 = !(__unbuffered_p0_EAX == 0 && __unbuffered_p1_EAX == 1 && __unbuffered_p1_EBX == 0);
__VERIFIER_atomic_end();
/* Program proven to be relaxed for X86, model checker says YES. */
__VERIFIER_assert(main$tmp_guard1);
/* reachable */
return 0;
}
|
the_stack_data/22012143.c | #include <stdio.h>
int main(void)
{
char letter = 'A';
double decimal = 5.489;
int number = 100;
printf("%c - Одиночный символ.\n", letter);
printf("decimal = %g, number = %d\n", decimal, number);
printf("%05.2g - decimal\n", decimal);
return (0);
} |
the_stack_data/627973.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bbatumik <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/13 09:57:03 by bbatumik #+# #+# */
/* Updated: 2019/09/14 15:56:02 by bbatumik ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strncpy(char *dest, char *src, unsigned int n)
{
unsigned int i;
i = 0;
while (i < n && src[i] != '\0')
{
dest[i] = src[i];
i++;
}
while (i < n)
{
dest[i] = '\0';
i++;
}
return (dest);
}
|
the_stack_data/151704806.c | /*
Package: dyncall
Library: test
File: test/samples/calls/f16.c
Description:
License:
Copyright (c) 2011-2018 Daniel Adler <[email protected]>,
Tassilo Philipp <[email protected]>
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#define f float
void f16(
f,f,f,f,
f,f,f,f,
f,f,f,f,
f,f,f,f
);
void t(f* x)
{
f16(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9],x[10],x[11],x[12],x[13],x[14],x[15]);
}
|
the_stack_data/125139999.c | /*
* Exercise 1.12
* Write a program that prints its input one word per line
*/
#include <stdio.h>
/* prints input one word
* per line
*/
int main (void)
{
int c;
while ((c = getchar()) != EOF) {
if (c == ' ' || c == '\t' || c == '\n')
putchar('\n');
else
putchar(c);
}
}
|
the_stack_data/49203.c | /*
O Filme
https://www.urionlinejudge.com.br/judge/pt/problems/view/1963
*/
#include <stdio.h>
int main (void) {
double valorAnterior,
valorAtual;
scanf("%lf %lf", &valorAnterior, &valorAtual);
printf("%.2f%%\n", (valorAtual / valorAnterior - 1.0) * 100.0);
return 0;
}
|
the_stack_data/237644347.c | int main() { void* _frame=0;
void *frame = malloc(20);
*(void**)frame=_frame;
( ( int * *) (((char*) frame) + 8) )[0] = malloc(4* ( 10 ) ) ;
;
( ( int *) (((char*) frame) + 16) )[0] = 0 ;
;
( ( int * *) (((char*) frame) + 8) )[0] [ 0 ] = 1 ;
( ( int * *) (((char*) frame) + 8) )[0] [ 1 ] = ( ( int * *) (((char*) frame) + 8) )[0] [ 0 ] + 1 ;
( ( int *) (((char*) frame) + 16) )[0] = ( ( int * *) (((char*) frame) + 8) )[0] [ 1 ] ;
( ( int *) (((char*) frame) + 16) )[0] ;
}
|
the_stack_data/156389209.c | #include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
signed long long int x;
signed long long int y;
scanf("%lld %lld", &x, &y);
char a[1000];
scanf("%s", a);
long long int n = strlen(a);
for (long long int i = 0; i < n; i++)
{
if (a[i] == 78)
{
y = y + 1;
x += 0;
//printf("(%lld, %lld)", x, y);
}
if (a[i] == 83)
{
y = y - 1;
x += 0;
//printf("(%lld, %lld)", x, y);
}
if (a[i] == 87)
{
x = x - 1;
y += 0;
//printf("(%lld, %lld)", x, y);
}
if (a[i] == 69)
{
x = x + 1;
y+= 0;
//printf("(%lld, %lld)", x, y);
}
if (a[i] == '1' || a[i] == '2' || a[i] == '3' || a[i] == '4' || a[i] == '5' || a[i] == '6' || a[i] == '7' || a[i] == '8' || a[i] == '9')
{
//int k = &a[i]; //3
int k_pos = i; //8
//int k_final = a[i-k]; //E
int j = k_pos-1;
int chk = 0;
while(chk < a[i])
{
if (a[j] == 78)
{
y = y - 1;
x += 0;
//printf("(%lld, %lld)", x, y);
}
if (a[j] == 83)
{
y = y + 1;
x += 0;
//printf("(%lld, %lld)", x, y);
}
if (a[j] == 87)
{
x = x + 1;
y += 0;
//printf("(%lld, %lld)", x, y);
}
if (a[j] == 69)
{
x = x - 1;
y += 0;
//printf("(%lld, %lld)", x, y);
}
j--;
chk++;
//printf("(%lld, %lld)", x, y);
}
}
//printf("(%lld, %lld)", x, y);
}
printf("(%lld, %lld)", x, y);
} |
the_stack_data/175144340.c | /*
* Copyright (C) 2008 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <time.h>
#include <errno.h>
unsigned int sleep(unsigned int seconds)
{
struct timespec t;
/* seconds is unsigned, while t.tv_sec is signed
* some people want to do sleep(UINT_MAX), so fake
* support for it by only sleeping 2 billion seconds
*/
if ((int)seconds < 0)
seconds = 0x7fffffff;
t.tv_sec = seconds;
t.tv_nsec = 0;
if ( !nanosleep( &t, &t ) )
return 0;
if ( errno == EINTR )
return t.tv_sec;
return -1;
}
|
the_stack_data/21841.c | /* Copyright (c) 2016, Google Inc.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
#include <openssl/rand.h>
#if defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE)
#include <string.h>
#include <openssl/chacha.h>
#include "../internal.h"
#include "../fipsmodule/rand/internal.h"
// g_num_calls is the number of calls to |CRYPTO_sysrand| that have occurred.
//
// This is intentionally not thread-safe. If the fuzzer mode is ever used in a
// multi-threaded program, replace this with a thread-local. (A mutex would not
// be deterministic.)
static uint64_t g_num_calls = 0;
void RAND_reset_for_fuzzing(void) { g_num_calls = 0; }
void CRYPTO_sysrand(uint8_t *out, size_t requested) {
static const uint8_t kZeroKey[32];
uint8_t nonce[12];
OPENSSL_memset(nonce, 0, sizeof(nonce));
OPENSSL_memcpy(nonce, &g_num_calls, sizeof(g_num_calls));
OPENSSL_memset(out, 0, requested);
CRYPTO_chacha_20(out, out, requested, kZeroKey, nonce, 0);
g_num_calls++;
}
#endif // BORINGSSL_UNSAFE_DETERMINISTIC_MODE
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.