file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/9513005.c | /* <MIT License>
Copyright (c) 2013 Marek Majkowski <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
</MIT License>
Original location:
https://github.com/majek/csiphash/
Solution inspired by code from:
Samuel Neves (supercop/crypto_auth/siphash24/little)
djb (supercop/crypto_auth/siphash24/little2)
Jean-Philippe Aumasson (https://131002.net/siphash/siphash24.c)
*/
#include <stdint.h>
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define _le64toh(x) ((uint64_t)(x))
#elif defined(_WIN32)
/* Windows is always little endian, unless you're on xbox360
http://msdn.microsoft.com/en-us/library/b0084kay(v=vs.80).aspx */
#define _le64toh(x) ((uint64_t)(x))
#elif defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#define _le64toh(x) OSSwapLittleToHostInt64(x)
#else
/* See: http://sourceforge.net/p/predef/wiki/Endianness/ */
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/endian.h>
#else
#include <endian.h>
#endif
#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \
__BYTE_ORDER == __LITTLE_ENDIAN
#define _le64toh(x) ((uint64_t)(x))
#else
#define _le64toh(x) le64toh(x)
#endif
#endif
#define ROTATE(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b))))
#define HALF_ROUND(a, b, c, d, s, t) \
a += b; \
c += d; \
b = ROTATE(b, s) ^ a; \
d = ROTATE(d, t) ^ c; \
a = ROTATE(a, 32);
#define DOUBLE_ROUND(v0, v1, v2, v3) \
HALF_ROUND(v0, v1, v2, v3, 13, 16); \
HALF_ROUND(v2, v1, v0, v3, 17, 21); \
HALF_ROUND(v0, v1, v2, v3, 13, 16); \
HALF_ROUND(v2, v1, v0, v3, 17, 21);
#define ROUND(v0, v1, v2, v3) \
HALF_ROUND(v0, v1, v2, v3, 13, 16); \
HALF_ROUND(v2, v1, v0, v3, 17, 21);
uint64_t siphash24(const void *src, unsigned long src_sz, const char key[16])
{
const uint64_t *_key = (uint64_t *)key;
uint64_t k0 = _le64toh(_key[0]);
uint64_t k1 = _le64toh(_key[1]);
uint64_t b = (uint64_t)src_sz << 56;
const uint64_t *in = (uint64_t *)src;
uint64_t v0 = k0 ^ 0x736f6d6570736575ULL;
uint64_t v1 = k1 ^ 0x646f72616e646f6dULL;
uint64_t v2 = k0 ^ 0x6c7967656e657261ULL;
uint64_t v3 = k1 ^ 0x7465646279746573ULL;
while (src_sz >= 8) {
uint64_t mi = _le64toh(*in);
in += 1;
src_sz -= 8;
v3 ^= mi;
DOUBLE_ROUND(v0, v1, v2, v3);
v0 ^= mi;
}
uint64_t t = 0;
uint8_t *pt = (uint8_t *)&t;
uint8_t *m = (uint8_t *)in;
switch (src_sz) {
case 7:
pt[6] = m[6];
/* fallthrough */
case 6:
pt[5] = m[5];
/* fallthrough */
case 5:
pt[4] = m[4];
/* fallthrough */
case 4:
*((uint32_t *)&pt[0]) = *((uint32_t *)&m[0]);
break;
case 3:
pt[2] = m[2];
/* fallthrough */
case 2:
pt[1] = m[1];
/* fallthrough */
case 1:
pt[0] = m[0];
}
b |= _le64toh(t);
v3 ^= b;
DOUBLE_ROUND(v0, v1, v2, v3);
v0 ^= b;
v2 ^= 0xff;
DOUBLE_ROUND(v0, v1, v2, v3);
DOUBLE_ROUND(v0, v1, v2, v3);
return (v0 ^ v1) ^ (v2 ^ v3);
}
uint32_t hsiphash(const void *src, unsigned long src_sz, const char key[16])
{
const uint64_t *_key = (uint64_t *)key;
uint64_t k0 = _le64toh(_key[0]);
uint64_t k1 = _le64toh(_key[1]);
uint64_t b = (uint64_t)src_sz << 56;
const uint64_t *in = (uint64_t *)src;
uint64_t v0 = k0 ^ 0x736f6d6570736575ULL;
uint64_t v1 = k1 ^ 0x646f72616e646f6dULL;
uint64_t v2 = k0 ^ 0x6c7967656e657261ULL;
uint64_t v3 = k1 ^ 0x7465646279746573ULL;
while (src_sz >= 8) {
uint64_t mi = _le64toh(*in);
in += 1;
src_sz -= 8;
v3 ^= mi;
ROUND(v0, v1, v2, v3);
v0 ^= mi;
}
uint64_t t = 0;
uint8_t *pt = (uint8_t *)&t;
uint8_t *m = (uint8_t *)in;
switch (src_sz) {
case 7:
pt[6] = m[6];
/* fallthrough */
case 6:
pt[5] = m[5];
/* fallthrough */
case 5:
pt[4] = m[4];
/* fallthrough */
case 4:
*((uint32_t *)&pt[0]) = *((uint32_t *)&m[0]);
break;
case 3:
pt[2] = m[2];
/* fallthrough */
case 2:
pt[1] = m[1];
/* fallthrough */
case 1:
pt[0] = m[0];
}
b |= _le64toh(t);
v3 ^= b;
ROUND(v0, v1, v2, v3);
v0 ^= b;
v2 ^= 0xff;
ROUND(v0, v1, v2, v3);
ROUND(v0, v1, v2, v3);
return (v0 ^ v1) ^ (v2 ^ v3);
}
/* Hardcode key to allow compiler to inline it. */
static const char siphash_key[16] = {0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
uint32_t hsiphash_static(const void *src, unsigned long src_sz)
{
return hsiphash(src, src_sz, siphash_key);
}
|
the_stack_data/148300.c | #include <stdio.h>
int max_2(int x, int y) {
return ((x > y) ? x : y);
}
int max_3(int x, int y, int z) {
return ((x > max_2(y, z)) ? x : max_2(y, z));
}
int gdc(int x, int y, int z) {
int res = 1;
for (int i = 2; i <= max_3(x, y, z); i++) {
if (x % i == 0 && y % i == 0 && z % i == 0)
res++;
}
return res;
}
int main(void) {
int x, y, z;
while(scanf("%d %d %d", &x, &y, &z) != EOF) {
if (x * x == y * y + z * z || y * y == x * x + z * z || z * z == x * x + y * y) {
if (gdc(x, y, z) == 1) {
printf("tripla pitagorica primitiva\n");
} else {
printf("tripla pitagorica\n");
}
} else {
printf("tripla\n");
}
}
return 0;
} |
the_stack_data/149088.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
typedef char* string;
typedef struct _Pair {
string key;
void *value;
} Pair;
string h2b[] = {
"0000", "0001", "0010", "0011",
"0100", "0101", "0110", "0111",
"1000", "1001", "1010", "1011",
"1100", "1101", "1110", "1111"};
char hexDigits[] = "0123456789ABCDEF";
void hex2binary(string hex, string binary) {
for (int i=0; hex[i] != '\0'; i++) {
char *ptr = strchr(hexDigits, hex[i]);
assert(ptr != NULL);
char h = ptr - hexDigits;
sprintf(&binary[4*i], "%s", h2b[h]);
}
}
void decimal2binary(int d, string binary) {
char hex[100];
sprintf(hex, "%04X", d);
hex2binary(hex, binary);
}
Pair dMap[] = {
{"", "000"}, {"M", "001"}, {"D", "010"}, {"MD", "011"},
{"A","100"}, {"AM","101"}, {"AD","110"}, {"AMD","111"}
};
Pair cMap[] = {
{"0", "0101010"}, {"1", "0111111"}, {"-1", "0111010"},
{"D", "0001100"}, {"A", "0110000"}, {"!D", "0001101"},
{"!A", "0110001"}, {"-D", "0001111"}, {"-A", "0110011"},
{"D+1", "0011111"}, {"A+1", "0110111"}, {"D-1", "0001110"},
{"A-1", "0110010"}, {"D+A", "0000010"}, {"D-A", "0010011"},
{"A-D", "0000111"}, {"D&A", "0000000"}, {"D|A", "0010101"},
{"M", "1110000"}, {"!M", "1110001"}, {"-M", "1110011"},
{"M+1", "1110111"}, {"M-1", "1110010"}, {"D+M", "1000010"},
{"D-M", "1010011"}, {"M-D", "1000111"}, {"D&M", "1000000"},
{"D|M", "1010101"}
};
Pair jMap[] = {
{"", "000"}, {"JGT","001"}, {"JEQ","010"}, {"JGE","011"},
{"JLT","100"}, {"JNE","101"}, {"JLE","110"}, {"JMP","111"}
};
#define SYM_SIZE 1000*100
int addr[SYM_SIZE] = {
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15,
16384, 24576,
0, 1, 2, 3, 4
};
Pair symTable[SYM_SIZE] = {
{"R0",&addr[0]},{"R1",&addr[1]},{"R2",&addr[2]},{"R3",&addr[3]},
{"R4",&addr[4]},{"R5",&addr[5]},{"R6",&addr[6]},{"R7",&addr[7]},
{"R8",&addr[8]}, {"R9",&addr[9]}, {"R10",&addr[10]}, {"R11",&addr[11]},
{"R12",&addr[12]}, {"R13",&addr[13]}, {"R14",&addr[14]}, {"R15",&addr[15]},
{"SCREEN",&addr[16]}, {"KBD",&addr[17]}, {"SP",&addr[18]}, {"LCL",&addr[19]},
{"ARG",&addr[20]}, {"THIS",&addr[21]}, {"THAT",&addr[22]}
};
int symTop = 23;
int varTop = 16;
char strTable[SYM_SIZE * 10];
char *strTableEnd = strTable;
char *newStr(char *str) {
char *strBegin = strTableEnd;
strcpy(strTableEnd, str);
strTableEnd += strlen(str) + 1;
return strBegin;
}
#define arraySize(array) (sizeof(array)/sizeof(array[0]))
int find(string key, Pair map[], int len) {
for (int i=0; i<len; i++) {
if (strcmp(map[i].key, key)==0)
return i;
}
return -1;
}
void* lookup(string key, Pair map[], int len) {
int i = find(key, map, len);
if (i==-1) return NULL;
return map[i].value;
}
void symAdd(char *label, int address, Pair map[], int *top) {
addr[*top] = address;
Pair p = { newStr(label), &addr[*top] };
map[(*top)++] = p;
printf(" p.key=%s *p.value=%d top=%d\n", p.key, *(int*)p.value, *top);
}
void symDump(Pair *map, int top) {
printf("======= SYMBOL TABLE ===========\n");
for (int i=0; i<top; i++) {
char *key = map[i].key;
int *vptr = map[i].value;
printf("%d: %s, %d\n", i, key, *vptr);
}
}
char *parse(string line) {
char *codePtr = line, *codeEnd = line;
while (strchr("\t ", *codePtr) != NULL) codePtr++;
while (*codeEnd != '\0' && strchr("/\n\r", *codeEnd) == NULL) codeEnd++;
*codeEnd = '\0';
return codePtr;
}
void code2binary(string code, string binary) {
char d[10], comp[100], j[10];
string dcode, ccode, jcode;
if (code[0]=='@') { // A 指令: @number || @symbol
int address;
int match = sscanf(code, "@%d", &address);
if (match == 1)
decimal2binary(address, binary);
else {
char symbol[100];
match = sscanf(code, "@%s", symbol);
int* addrPtr = lookup(symbol, symTable, symTop);
if (addrPtr == NULL) { // 宣告變數
symAdd(symbol, varTop, symTable, &symTop); // 新增一個變數
address = varTop++;
} else { // 已知變數 (標記) 位址
address = *addrPtr;
}
decimal2binary(address, binary);
}
} else { // C 指令
if (strchr(code, '=') != NULL) { // d=comp
sscanf(code, "%[^=]=%s", d, comp);
dcode = lookup(d, dMap, arraySize(dMap));
ccode = lookup(comp, cMap, arraySize(cMap));
sprintf(binary, "111%s%s000", ccode, dcode);
} else {
sscanf(code, "%[^;];%s", comp, j); // comp;j
ccode = lookup(comp, cMap, arraySize(cMap));
jcode = lookup(j, jMap, arraySize(jMap));
sprintf(binary, "111%s000%s", ccode, jcode);
}
}
}
void pass1(string inFile) {
printf("============= PASS1 ================\n");
char line[100]="";
FILE *fp = fopen(inFile, "r");
int address = 0;
while (fgets(line, sizeof(line), fp)) {
char *code = parse(line);
if (strlen(code)==0) continue;
printf("%02d:%s\n", address, code);
if (code[0] == '(') {
char label[100];
sscanf(code, "(%[^)])", label);
symAdd(label, address, symTable, &symTop);
} else {
address ++;
}
}
fclose(fp);
}
void pass2(string inFile, string outFile) {
printf("============= PASS2 ================\n");
char line[100], binary[17];
FILE *fp = fopen(inFile, "r");
FILE *ofp = fopen(outFile, "w");
while (fgets(line, sizeof(line), fp)) {
char *code = parse(line);
if (strlen(code)==0) continue;
if (code[0] == '(') {
printf("%s\n", code);
} else {
code2binary(code, binary);
printf(" %-20s %s\n", code, binary);
fprintf(ofp, "%s\n", binary);
}
}
fclose(fp);
fclose(ofp);
}
void assemble(string file) {
char inFile[100], outFile[100];
sprintf(inFile, "%s.asm", file);
sprintf(outFile, "%s.my.hack", file);
symDump(symTable, symTop);
pass1(inFile);
symDump(symTable, symTop);
pass2(inFile, outFile);
}
// run: ./asm <file>
// notice : <file> with no extension.
int main(int argc, char *argv[]) {
assemble(argv[1]);
}
|
the_stack_data/41539.c | /*
* Disk Array driver for HP Smart Array controllers, SCSI Tape module.
* (C) Copyright 2001, 2007 Hewlett-Packard Development Company, L.P.
*
* 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; version 2 of the License.
*
* 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 300, Boston, MA
* 02111-1307, USA.
*
* Questions/Comments/Bugfixes to [email protected]
*
* Author: Stephen M. Cameron
*/
#ifdef CONFIG_CISS_SCSI_TAPE
/* Here we have code to present the driver as a scsi driver
as it is simultaneously presented as a block driver. The
reason for doing this is to allow access to SCSI tape drives
through the array controller. Note in particular, neither
physical nor logical disks are presented through the scsi layer. */
#include <linux/timer.h>
#include <linux/completion.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <asm/atomic.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_device.h>
#include <scsi/scsi_host.h>
#include "cciss_scsi.h"
#define CCISS_ABORT_MSG 0x00
#define CCISS_RESET_MSG 0x01
static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff,
size_t size,
__u8 page_code, unsigned char *scsi3addr,
int cmd_type);
static CommandList_struct *cmd_alloc(ctlr_info_t *h, int get_from_pool);
static void cmd_free(ctlr_info_t *h, CommandList_struct *c, int got_from_pool);
static int cciss_scsi_proc_info(
struct Scsi_Host *sh,
char *buffer, /* data buffer */
char **start, /* where data in buffer starts */
off_t offset, /* offset from start of imaginary file */
int length, /* length of data in buffer */
int func); /* 0 == read, 1 == write */
static int cciss_scsi_queue_command (struct scsi_cmnd *cmd,
void (* done)(struct scsi_cmnd *));
static int cciss_eh_device_reset_handler(struct scsi_cmnd *);
static int cciss_eh_abort_handler(struct scsi_cmnd *);
static struct cciss_scsi_hba_t ccissscsi[MAX_CTLR] = {
{ .name = "cciss0", .ndevices = 0 },
{ .name = "cciss1", .ndevices = 0 },
{ .name = "cciss2", .ndevices = 0 },
{ .name = "cciss3", .ndevices = 0 },
{ .name = "cciss4", .ndevices = 0 },
{ .name = "cciss5", .ndevices = 0 },
{ .name = "cciss6", .ndevices = 0 },
{ .name = "cciss7", .ndevices = 0 },
};
static struct scsi_host_template cciss_driver_template = {
.module = THIS_MODULE,
.name = "cciss",
.proc_name = "cciss",
.proc_info = cciss_scsi_proc_info,
.queuecommand = cciss_scsi_queue_command,
.can_queue = SCSI_CCISS_CAN_QUEUE,
.this_id = 7,
.sg_tablesize = MAXSGENTRIES,
.cmd_per_lun = 1,
.use_clustering = DISABLE_CLUSTERING,
/* Can't have eh_bus_reset_handler or eh_host_reset_handler for cciss */
.eh_device_reset_handler= cciss_eh_device_reset_handler,
.eh_abort_handler = cciss_eh_abort_handler,
};
#pragma pack(1)
struct cciss_scsi_cmd_stack_elem_t {
CommandList_struct cmd;
ErrorInfo_struct Err;
__u32 busaddr;
__u32 pad;
};
#pragma pack()
#define CMD_STACK_SIZE (SCSI_CCISS_CAN_QUEUE * \
CCISS_MAX_SCSI_DEVS_PER_HBA + 2)
// plus two for init time usage
#pragma pack(1)
struct cciss_scsi_cmd_stack_t {
struct cciss_scsi_cmd_stack_elem_t *pool;
struct cciss_scsi_cmd_stack_elem_t *elem[CMD_STACK_SIZE];
dma_addr_t cmd_pool_handle;
int top;
};
#pragma pack()
struct cciss_scsi_adapter_data_t {
struct Scsi_Host *scsi_host;
struct cciss_scsi_cmd_stack_t cmd_stack;
int registered;
spinlock_t lock; // to protect ccissscsi[ctlr];
};
#define CPQ_TAPE_LOCK(ctlr, flags) spin_lock_irqsave( \
&(((struct cciss_scsi_adapter_data_t *) \
hba[ctlr]->scsi_ctlr)->lock), flags);
#define CPQ_TAPE_UNLOCK(ctlr, flags) spin_unlock_irqrestore( \
&(((struct cciss_scsi_adapter_data_t *) \
hba[ctlr]->scsi_ctlr)->lock), flags);
static CommandList_struct *
scsi_cmd_alloc(ctlr_info_t *h)
{
/* assume only one process in here at a time, locking done by caller. */
/* use CCISS_LOCK(ctlr) */
/* might be better to rewrite how we allocate scsi commands in a way that */
/* needs no locking at all. */
/* take the top memory chunk off the stack and return it, if any. */
struct cciss_scsi_cmd_stack_elem_t *c;
struct cciss_scsi_adapter_data_t *sa;
struct cciss_scsi_cmd_stack_t *stk;
u64bit temp64;
sa = (struct cciss_scsi_adapter_data_t *) h->scsi_ctlr;
stk = &sa->cmd_stack;
if (stk->top < 0)
return NULL;
c = stk->elem[stk->top];
/* memset(c, 0, sizeof(*c)); */
memset(&c->cmd, 0, sizeof(c->cmd));
memset(&c->Err, 0, sizeof(c->Err));
/* set physical addr of cmd and addr of scsi parameters */
c->cmd.busaddr = c->busaddr;
/* (__u32) (stk->cmd_pool_handle +
(sizeof(struct cciss_scsi_cmd_stack_elem_t)*stk->top)); */
temp64.val = (__u64) (c->busaddr + sizeof(CommandList_struct));
/* (__u64) (stk->cmd_pool_handle +
(sizeof(struct cciss_scsi_cmd_stack_elem_t)*stk->top) +
sizeof(CommandList_struct)); */
stk->top--;
c->cmd.ErrDesc.Addr.lower = temp64.val32.lower;
c->cmd.ErrDesc.Addr.upper = temp64.val32.upper;
c->cmd.ErrDesc.Len = sizeof(ErrorInfo_struct);
c->cmd.ctlr = h->ctlr;
c->cmd.err_info = &c->Err;
return (CommandList_struct *) c;
}
static void
scsi_cmd_free(ctlr_info_t *h, CommandList_struct *cmd)
{
/* assume only one process in here at a time, locking done by caller. */
/* use CCISS_LOCK(ctlr) */
/* drop the free memory chunk on top of the stack. */
struct cciss_scsi_adapter_data_t *sa;
struct cciss_scsi_cmd_stack_t *stk;
sa = (struct cciss_scsi_adapter_data_t *) h->scsi_ctlr;
stk = &sa->cmd_stack;
if (stk->top >= CMD_STACK_SIZE) {
printk("cciss: scsi_cmd_free called too many times.\n");
BUG();
}
stk->top++;
stk->elem[stk->top] = (struct cciss_scsi_cmd_stack_elem_t *) cmd;
}
static int
scsi_cmd_stack_setup(int ctlr, struct cciss_scsi_adapter_data_t *sa)
{
int i;
struct cciss_scsi_cmd_stack_t *stk;
size_t size;
stk = &sa->cmd_stack;
size = sizeof(struct cciss_scsi_cmd_stack_elem_t) * CMD_STACK_SIZE;
// pci_alloc_consistent guarantees 32-bit DMA address will
// be used
stk->pool = (struct cciss_scsi_cmd_stack_elem_t *)
pci_alloc_consistent(hba[ctlr]->pdev, size, &stk->cmd_pool_handle);
if (stk->pool == NULL) {
printk("stk->pool is null\n");
return -1;
}
for (i=0; i<CMD_STACK_SIZE; i++) {
stk->elem[i] = &stk->pool[i];
stk->elem[i]->busaddr = (__u32) (stk->cmd_pool_handle +
(sizeof(struct cciss_scsi_cmd_stack_elem_t) * i));
}
stk->top = CMD_STACK_SIZE-1;
return 0;
}
static void
scsi_cmd_stack_free(int ctlr)
{
struct cciss_scsi_adapter_data_t *sa;
struct cciss_scsi_cmd_stack_t *stk;
size_t size;
sa = (struct cciss_scsi_adapter_data_t *) hba[ctlr]->scsi_ctlr;
stk = &sa->cmd_stack;
if (stk->top != CMD_STACK_SIZE-1) {
printk( "cciss: %d scsi commands are still outstanding.\n",
CMD_STACK_SIZE - stk->top);
// BUG();
printk("WE HAVE A BUG HERE!!! stk=0x%p\n", stk);
}
size = sizeof(struct cciss_scsi_cmd_stack_elem_t) * CMD_STACK_SIZE;
pci_free_consistent(hba[ctlr]->pdev, size, stk->pool, stk->cmd_pool_handle);
stk->pool = NULL;
}
#if 0
static int xmargin=8;
static int amargin=60;
static void
print_bytes (unsigned char *c, int len, int hex, int ascii)
{
int i;
unsigned char *x;
if (hex)
{
x = c;
for (i=0;i<len;i++)
{
if ((i % xmargin) == 0 && i>0) printk("\n");
if ((i % xmargin) == 0) printk("0x%04x:", i);
printk(" %02x", *x);
x++;
}
printk("\n");
}
if (ascii)
{
x = c;
for (i=0;i<len;i++)
{
if ((i % amargin) == 0 && i>0) printk("\n");
if ((i % amargin) == 0) printk("0x%04x:", i);
if (*x > 26 && *x < 128) printk("%c", *x);
else printk(".");
x++;
}
printk("\n");
}
}
static void
print_cmd(CommandList_struct *cp)
{
printk("queue:%d\n", cp->Header.ReplyQueue);
printk("sglist:%d\n", cp->Header.SGList);
printk("sgtot:%d\n", cp->Header.SGTotal);
printk("Tag:0x%08x/0x%08x\n", cp->Header.Tag.upper,
cp->Header.Tag.lower);
printk("LUN:0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
cp->Header.LUN.LunAddrBytes[0],
cp->Header.LUN.LunAddrBytes[1],
cp->Header.LUN.LunAddrBytes[2],
cp->Header.LUN.LunAddrBytes[3],
cp->Header.LUN.LunAddrBytes[4],
cp->Header.LUN.LunAddrBytes[5],
cp->Header.LUN.LunAddrBytes[6],
cp->Header.LUN.LunAddrBytes[7]);
printk("CDBLen:%d\n", cp->Request.CDBLen);
printk("Type:%d\n",cp->Request.Type.Type);
printk("Attr:%d\n",cp->Request.Type.Attribute);
printk(" Dir:%d\n",cp->Request.Type.Direction);
printk("Timeout:%d\n",cp->Request.Timeout);
printk( "CDB: %02x %02x %02x %02x %02x %02x %02x %02x"
" %02x %02x %02x %02x %02x %02x %02x %02x\n",
cp->Request.CDB[0], cp->Request.CDB[1],
cp->Request.CDB[2], cp->Request.CDB[3],
cp->Request.CDB[4], cp->Request.CDB[5],
cp->Request.CDB[6], cp->Request.CDB[7],
cp->Request.CDB[8], cp->Request.CDB[9],
cp->Request.CDB[10], cp->Request.CDB[11],
cp->Request.CDB[12], cp->Request.CDB[13],
cp->Request.CDB[14], cp->Request.CDB[15]),
printk("edesc.Addr: 0x%08x/0%08x, Len = %d\n",
cp->ErrDesc.Addr.upper, cp->ErrDesc.Addr.lower,
cp->ErrDesc.Len);
printk("sgs..........Errorinfo:\n");
printk("scsistatus:%d\n", cp->err_info->ScsiStatus);
printk("senselen:%d\n", cp->err_info->SenseLen);
printk("cmd status:%d\n", cp->err_info->CommandStatus);
printk("resid cnt:%d\n", cp->err_info->ResidualCnt);
printk("offense size:%d\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_size);
printk("offense byte:%d\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_num);
printk("offense value:%d\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_value);
}
#endif
static int
find_bus_target_lun(int ctlr, int *bus, int *target, int *lun)
{
/* finds an unused bus, target, lun for a new device */
/* assumes hba[ctlr]->scsi_ctlr->lock is held */
int i, found=0;
unsigned char target_taken[CCISS_MAX_SCSI_DEVS_PER_HBA];
memset(&target_taken[0], 0, CCISS_MAX_SCSI_DEVS_PER_HBA);
target_taken[SELF_SCSI_ID] = 1;
for (i=0;i<ccissscsi[ctlr].ndevices;i++)
target_taken[ccissscsi[ctlr].dev[i].target] = 1;
for (i=0;i<CCISS_MAX_SCSI_DEVS_PER_HBA;i++) {
if (!target_taken[i]) {
*bus = 0; *target=i; *lun = 0; found=1;
break;
}
}
return (!found);
}
struct scsi2map {
char scsi3addr[8];
int bus, target, lun;
};
static int
cciss_scsi_add_entry(int ctlr, int hostno,
struct cciss_scsi_dev_t *device,
struct scsi2map *added, int *nadded)
{
/* assumes hba[ctlr]->scsi_ctlr->lock is held */
int n = ccissscsi[ctlr].ndevices;
struct cciss_scsi_dev_t *sd;
int i, bus, target, lun;
unsigned char addr1[8], addr2[8];
if (n >= CCISS_MAX_SCSI_DEVS_PER_HBA) {
printk("cciss%d: Too many devices, "
"some will be inaccessible.\n", ctlr);
return -1;
}
bus = target = -1;
lun = 0;
/* Is this device a non-zero lun of a multi-lun device */
/* byte 4 of the 8-byte LUN addr will contain the logical unit no. */
if (device->scsi3addr[4] != 0) {
/* Search through our list and find the device which */
/* has the same 8 byte LUN address, excepting byte 4. */
/* Assign the same bus and target for this new LUN. */
/* Use the logical unit number from the firmware. */
memcpy(addr1, device->scsi3addr, 8);
addr1[4] = 0;
for (i = 0; i < n; i++) {
sd = &ccissscsi[ctlr].dev[i];
memcpy(addr2, sd->scsi3addr, 8);
addr2[4] = 0;
/* differ only in byte 4? */
if (memcmp(addr1, addr2, 8) == 0) {
bus = sd->bus;
target = sd->target;
lun = device->scsi3addr[4];
break;
}
}
}
sd = &ccissscsi[ctlr].dev[n];
if (lun == 0) {
if (find_bus_target_lun(ctlr,
&sd->bus, &sd->target, &sd->lun) != 0)
return -1;
} else {
sd->bus = bus;
sd->target = target;
sd->lun = lun;
}
added[*nadded].bus = sd->bus;
added[*nadded].target = sd->target;
added[*nadded].lun = sd->lun;
(*nadded)++;
memcpy(sd->scsi3addr, device->scsi3addr, 8);
memcpy(sd->vendor, device->vendor, sizeof(sd->vendor));
memcpy(sd->revision, device->revision, sizeof(sd->revision));
memcpy(sd->device_id, device->device_id, sizeof(sd->device_id));
sd->devtype = device->devtype;
ccissscsi[ctlr].ndevices++;
/* initially, (before registering with scsi layer) we don't
know our hostno and we don't want to print anything first
time anyway (the scsi layer's inquiries will show that info) */
if (hostno != -1)
printk("cciss%d: %s device c%db%dt%dl%d added.\n",
ctlr, scsi_device_type(sd->devtype), hostno,
sd->bus, sd->target, sd->lun);
return 0;
}
static void
cciss_scsi_remove_entry(int ctlr, int hostno, int entry,
struct scsi2map *removed, int *nremoved)
{
/* assumes hba[ctlr]->scsi_ctlr->lock is held */
int i;
struct cciss_scsi_dev_t sd;
if (entry < 0 || entry >= CCISS_MAX_SCSI_DEVS_PER_HBA) return;
sd = ccissscsi[ctlr].dev[entry];
removed[*nremoved].bus = sd.bus;
removed[*nremoved].target = sd.target;
removed[*nremoved].lun = sd.lun;
(*nremoved)++;
for (i=entry;i<ccissscsi[ctlr].ndevices-1;i++)
ccissscsi[ctlr].dev[i] = ccissscsi[ctlr].dev[i+1];
ccissscsi[ctlr].ndevices--;
printk("cciss%d: %s device c%db%dt%dl%d removed.\n",
ctlr, scsi_device_type(sd.devtype), hostno,
sd.bus, sd.target, sd.lun);
}
#define SCSI3ADDR_EQ(a,b) ( \
(a)[7] == (b)[7] && \
(a)[6] == (b)[6] && \
(a)[5] == (b)[5] && \
(a)[4] == (b)[4] && \
(a)[3] == (b)[3] && \
(a)[2] == (b)[2] && \
(a)[1] == (b)[1] && \
(a)[0] == (b)[0])
static void fixup_botched_add(int ctlr, char *scsi3addr)
{
/* called when scsi_add_device fails in order to re-adjust */
/* ccissscsi[] to match the mid layer's view. */
unsigned long flags;
int i, j;
CPQ_TAPE_LOCK(ctlr, flags);
for (i = 0; i < ccissscsi[ctlr].ndevices; i++) {
if (memcmp(scsi3addr,
ccissscsi[ctlr].dev[i].scsi3addr, 8) == 0) {
for (j = i; j < ccissscsi[ctlr].ndevices-1; j++)
ccissscsi[ctlr].dev[j] =
ccissscsi[ctlr].dev[j+1];
ccissscsi[ctlr].ndevices--;
break;
}
}
CPQ_TAPE_UNLOCK(ctlr, flags);
}
static int device_is_the_same(struct cciss_scsi_dev_t *dev1,
struct cciss_scsi_dev_t *dev2)
{
return dev1->devtype == dev2->devtype &&
memcmp(dev1->scsi3addr, dev2->scsi3addr,
sizeof(dev1->scsi3addr)) == 0 &&
memcmp(dev1->device_id, dev2->device_id,
sizeof(dev1->device_id)) == 0 &&
memcmp(dev1->vendor, dev2->vendor,
sizeof(dev1->vendor)) == 0 &&
memcmp(dev1->model, dev2->model,
sizeof(dev1->model)) == 0 &&
memcmp(dev1->revision, dev2->revision,
sizeof(dev1->revision)) == 0;
}
static int
adjust_cciss_scsi_table(int ctlr, int hostno,
struct cciss_scsi_dev_t sd[], int nsds)
{
/* sd contains scsi3 addresses and devtypes, but
bus target and lun are not filled in. This funciton
takes what's in sd to be the current and adjusts
ccissscsi[] to be in line with what's in sd. */
int i,j, found, changes=0;
struct cciss_scsi_dev_t *csd;
unsigned long flags;
struct scsi2map *added, *removed;
int nadded, nremoved;
struct Scsi_Host *sh = NULL;
added = kzalloc(sizeof(*added) * CCISS_MAX_SCSI_DEVS_PER_HBA,
GFP_KERNEL);
removed = kzalloc(sizeof(*removed) * CCISS_MAX_SCSI_DEVS_PER_HBA,
GFP_KERNEL);
if (!added || !removed) {
printk(KERN_WARNING "cciss%d: Out of memory in "
"adjust_cciss_scsi_table\n", ctlr);
goto free_and_out;
}
CPQ_TAPE_LOCK(ctlr, flags);
if (hostno != -1) /* if it's not the first time... */
sh = ((struct cciss_scsi_adapter_data_t *)
hba[ctlr]->scsi_ctlr)->scsi_host;
/* find any devices in ccissscsi[] that are not in
sd[] and remove them from ccissscsi[] */
i = 0;
nremoved = 0;
nadded = 0;
while(i<ccissscsi[ctlr].ndevices) {
csd = &ccissscsi[ctlr].dev[i];
found=0;
for (j=0;j<nsds;j++) {
if (SCSI3ADDR_EQ(sd[j].scsi3addr,
csd->scsi3addr)) {
if (device_is_the_same(&sd[j], csd))
found=2;
else
found=1;
break;
}
}
if (found == 0) { /* device no longer present. */
changes++;
/* printk("cciss%d: %s device c%db%dt%dl%d removed.\n",
ctlr, scsi_device_type(csd->devtype), hostno,
csd->bus, csd->target, csd->lun); */
cciss_scsi_remove_entry(ctlr, hostno, i,
removed, &nremoved);
/* remove ^^^, hence i not incremented */
} else if (found == 1) { /* device is different in some way */
changes++;
printk("cciss%d: device c%db%dt%dl%d has changed.\n",
ctlr, hostno, csd->bus, csd->target, csd->lun);
cciss_scsi_remove_entry(ctlr, hostno, i,
removed, &nremoved);
/* remove ^^^, hence i not incremented */
if (cciss_scsi_add_entry(ctlr, hostno, &sd[j],
added, &nadded) != 0)
/* we just removed one, so add can't fail. */
BUG();
csd->devtype = sd[j].devtype;
memcpy(csd->device_id, sd[j].device_id,
sizeof(csd->device_id));
memcpy(csd->vendor, sd[j].vendor,
sizeof(csd->vendor));
memcpy(csd->model, sd[j].model,
sizeof(csd->model));
memcpy(csd->revision, sd[j].revision,
sizeof(csd->revision));
} else /* device is same as it ever was, */
i++; /* so just move along. */
}
/* Now, make sure every device listed in sd[] is also
listed in ccissscsi[], adding them if they aren't found */
for (i=0;i<nsds;i++) {
found=0;
for (j=0;j<ccissscsi[ctlr].ndevices;j++) {
csd = &ccissscsi[ctlr].dev[j];
if (SCSI3ADDR_EQ(sd[i].scsi3addr,
csd->scsi3addr)) {
if (device_is_the_same(&sd[i], csd))
found=2; /* found device */
else
found=1; /* found a bug. */
break;
}
}
if (!found) {
changes++;
if (cciss_scsi_add_entry(ctlr, hostno, &sd[i],
added, &nadded) != 0)
break;
} else if (found == 1) {
/* should never happen... */
changes++;
printk(KERN_WARNING "cciss%d: device "
"unexpectedly changed\n", ctlr);
/* but if it does happen, we just ignore that device */
}
}
CPQ_TAPE_UNLOCK(ctlr, flags);
/* Don't notify scsi mid layer of any changes the first time through */
/* (or if there are no changes) scsi_scan_host will do it later the */
/* first time through. */
if (hostno == -1 || !changes)
goto free_and_out;
/* Notify scsi mid layer of any removed devices */
for (i = 0; i < nremoved; i++) {
struct scsi_device *sdev =
scsi_device_lookup(sh, removed[i].bus,
removed[i].target, removed[i].lun);
if (sdev != NULL) {
scsi_remove_device(sdev);
scsi_device_put(sdev);
} else {
/* We don't expect to get here. */
/* future cmds to this device will get selection */
/* timeout as if the device was gone. */
printk(KERN_WARNING "cciss%d: didn't find "
"c%db%dt%dl%d\n for removal.",
ctlr, hostno, removed[i].bus,
removed[i].target, removed[i].lun);
}
}
/* Notify scsi mid layer of any added devices */
for (i = 0; i < nadded; i++) {
int rc;
rc = scsi_add_device(sh, added[i].bus,
added[i].target, added[i].lun);
if (rc == 0)
continue;
printk(KERN_WARNING "cciss%d: scsi_add_device "
"c%db%dt%dl%d failed, device not added.\n",
ctlr, hostno,
added[i].bus, added[i].target, added[i].lun);
/* now we have to remove it from ccissscsi, */
/* since it didn't get added to scsi mid layer */
fixup_botched_add(ctlr, added[i].scsi3addr);
}
free_and_out:
kfree(added);
kfree(removed);
return 0;
}
static int
lookup_scsi3addr(int ctlr, int bus, int target, int lun, char *scsi3addr)
{
int i;
struct cciss_scsi_dev_t *sd;
unsigned long flags;
CPQ_TAPE_LOCK(ctlr, flags);
for (i=0;i<ccissscsi[ctlr].ndevices;i++) {
sd = &ccissscsi[ctlr].dev[i];
if (sd->bus == bus &&
sd->target == target &&
sd->lun == lun) {
memcpy(scsi3addr, &sd->scsi3addr[0], 8);
CPQ_TAPE_UNLOCK(ctlr, flags);
return 0;
}
}
CPQ_TAPE_UNLOCK(ctlr, flags);
return -1;
}
static void
cciss_scsi_setup(int cntl_num)
{
struct cciss_scsi_adapter_data_t * shba;
ccissscsi[cntl_num].ndevices = 0;
shba = (struct cciss_scsi_adapter_data_t *)
kmalloc(sizeof(*shba), GFP_KERNEL);
if (shba == NULL)
return;
shba->scsi_host = NULL;
spin_lock_init(&shba->lock);
shba->registered = 0;
if (scsi_cmd_stack_setup(cntl_num, shba) != 0) {
kfree(shba);
shba = NULL;
}
hba[cntl_num]->scsi_ctlr = (void *) shba;
return;
}
static void
complete_scsi_command( CommandList_struct *cp, int timeout, __u32 tag)
{
struct scsi_cmnd *cmd;
ctlr_info_t *ctlr;
ErrorInfo_struct *ei;
ei = cp->err_info;
/* First, see if it was a message rather than a command */
if (cp->Request.Type.Type == TYPE_MSG) {
cp->cmd_type = CMD_MSG_DONE;
return;
}
cmd = (struct scsi_cmnd *) cp->scsi_cmd;
ctlr = hba[cp->ctlr];
scsi_dma_unmap(cmd);
cmd->result = (DID_OK << 16); /* host byte */
cmd->result |= (COMMAND_COMPLETE << 8); /* msg byte */
/* cmd->result |= (GOOD < 1); */ /* status byte */
cmd->result |= (ei->ScsiStatus);
/* printk("Scsistatus is 0x%02x\n", ei->ScsiStatus); */
/* copy the sense data whether we need to or not. */
memcpy(cmd->sense_buffer, ei->SenseInfo,
ei->SenseLen > SCSI_SENSE_BUFFERSIZE ?
SCSI_SENSE_BUFFERSIZE :
ei->SenseLen);
scsi_set_resid(cmd, ei->ResidualCnt);
if(ei->CommandStatus != 0)
{ /* an error has occurred */
switch(ei->CommandStatus)
{
case CMD_TARGET_STATUS:
/* Pass it up to the upper layers... */
if( ei->ScsiStatus)
{
#if 0
printk(KERN_WARNING "cciss: cmd %p "
"has SCSI Status = %x\n",
cp,
ei->ScsiStatus);
#endif
cmd->result |= (ei->ScsiStatus < 1);
}
else { /* scsi status is zero??? How??? */
/* Ordinarily, this case should never happen, but there is a bug
in some released firmware revisions that allows it to happen
if, for example, a 4100 backplane loses power and the tape
drive is in it. We assume that it's a fatal error of some
kind because we can't show that it wasn't. We will make it
look like selection timeout since that is the most common
reason for this to occur, and it's severe enough. */
cmd->result = DID_NO_CONNECT << 16;
}
break;
case CMD_DATA_UNDERRUN: /* let mid layer handle it. */
break;
case CMD_DATA_OVERRUN:
printk(KERN_WARNING "cciss: cp %p has"
" completed with data overrun "
"reported\n", cp);
break;
case CMD_INVALID: {
/* print_bytes(cp, sizeof(*cp), 1, 0);
print_cmd(cp); */
/* We get CMD_INVALID if you address a non-existent tape drive instead
of a selection timeout (no response). You will see this if you yank
out a tape drive, then try to access it. This is kind of a shame
because it means that any other CMD_INVALID (e.g. driver bug) will
get interpreted as a missing target. */
cmd->result = DID_NO_CONNECT << 16;
}
break;
case CMD_PROTOCOL_ERR:
printk(KERN_WARNING "cciss: cp %p has "
"protocol error \n", cp);
break;
case CMD_HARDWARE_ERR:
cmd->result = DID_ERROR << 16;
printk(KERN_WARNING "cciss: cp %p had "
" hardware error\n", cp);
break;
case CMD_CONNECTION_LOST:
cmd->result = DID_ERROR << 16;
printk(KERN_WARNING "cciss: cp %p had "
"connection lost\n", cp);
break;
case CMD_ABORTED:
cmd->result = DID_ABORT << 16;
printk(KERN_WARNING "cciss: cp %p was "
"aborted\n", cp);
break;
case CMD_ABORT_FAILED:
cmd->result = DID_ERROR << 16;
printk(KERN_WARNING "cciss: cp %p reports "
"abort failed\n", cp);
break;
case CMD_UNSOLICITED_ABORT:
cmd->result = DID_ABORT << 16;
printk(KERN_WARNING "cciss: cp %p aborted "
"do to an unsolicited abort\n", cp);
break;
case CMD_TIMEOUT:
cmd->result = DID_TIME_OUT << 16;
printk(KERN_WARNING "cciss: cp %p timedout\n",
cp);
break;
default:
cmd->result = DID_ERROR << 16;
printk(KERN_WARNING "cciss: cp %p returned "
"unknown status %x\n", cp,
ei->CommandStatus);
}
}
// printk("c:%p:c%db%dt%dl%d ", cmd, ctlr->ctlr, cmd->channel,
// cmd->target, cmd->lun);
cmd->scsi_done(cmd);
scsi_cmd_free(ctlr, cp);
}
static int
cciss_scsi_detect(int ctlr)
{
struct Scsi_Host *sh;
int error;
sh = scsi_host_alloc(&cciss_driver_template, sizeof(struct ctlr_info *));
if (sh == NULL)
goto fail;
sh->io_port = 0; // good enough? FIXME,
sh->n_io_port = 0; // I don't think we use these two...
sh->this_id = SELF_SCSI_ID;
((struct cciss_scsi_adapter_data_t *)
hba[ctlr]->scsi_ctlr)->scsi_host = (void *) sh;
sh->hostdata[0] = (unsigned long) hba[ctlr];
sh->irq = hba[ctlr]->intr[SIMPLE_MODE_INT];
sh->unique_id = sh->irq;
error = scsi_add_host(sh, &hba[ctlr]->pdev->dev);
if (error)
goto fail_host_put;
scsi_scan_host(sh);
return 1;
fail_host_put:
scsi_host_put(sh);
fail:
return 0;
}
static void
cciss_unmap_one(struct pci_dev *pdev,
CommandList_struct *cp,
size_t buflen,
int data_direction)
{
u64bit addr64;
addr64.val32.lower = cp->SG[0].Addr.lower;
addr64.val32.upper = cp->SG[0].Addr.upper;
pci_unmap_single(pdev, (dma_addr_t) addr64.val, buflen, data_direction);
}
static void
cciss_map_one(struct pci_dev *pdev,
CommandList_struct *cp,
unsigned char *buf,
size_t buflen,
int data_direction)
{
__u64 addr64;
addr64 = (__u64) pci_map_single(pdev, buf, buflen, data_direction);
cp->SG[0].Addr.lower =
(__u32) (addr64 & (__u64) 0x00000000FFFFFFFF);
cp->SG[0].Addr.upper =
(__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF);
cp->SG[0].Len = buflen;
cp->Header.SGList = (__u8) 1; /* no. SGs contig in this cmd */
cp->Header.SGTotal = (__u16) 1; /* total sgs in this cmd list */
}
static int
cciss_scsi_do_simple_cmd(ctlr_info_t *c,
CommandList_struct *cp,
unsigned char *scsi3addr,
unsigned char *cdb,
unsigned char cdblen,
unsigned char *buf, int bufsize,
int direction)
{
unsigned long flags;
DECLARE_COMPLETION_ONSTACK(wait);
cp->cmd_type = CMD_IOCTL_PEND; // treat this like an ioctl
cp->scsi_cmd = NULL;
cp->Header.ReplyQueue = 0; // unused in simple mode
memcpy(&cp->Header.LUN, scsi3addr, sizeof(cp->Header.LUN));
cp->Header.Tag.lower = cp->busaddr; // Use k. address of cmd as tag
// Fill in the request block...
/* printk("Using scsi3addr 0x%02x%0x2%0x2%0x2%0x2%0x2%0x2%0x2\n",
scsi3addr[0], scsi3addr[1], scsi3addr[2], scsi3addr[3],
scsi3addr[4], scsi3addr[5], scsi3addr[6], scsi3addr[7]); */
memset(cp->Request.CDB, 0, sizeof(cp->Request.CDB));
memcpy(cp->Request.CDB, cdb, cdblen);
cp->Request.Timeout = 0;
cp->Request.CDBLen = cdblen;
cp->Request.Type.Type = TYPE_CMD;
cp->Request.Type.Attribute = ATTR_SIMPLE;
cp->Request.Type.Direction = direction;
/* Fill in the SG list and do dma mapping */
cciss_map_one(c->pdev, cp, (unsigned char *) buf,
bufsize, DMA_FROM_DEVICE);
cp->waiting = &wait;
/* Put the request on the tail of the request queue */
spin_lock_irqsave(CCISS_LOCK(c->ctlr), flags);
addQ(&c->reqQ, cp);
c->Qdepth++;
start_io(c);
spin_unlock_irqrestore(CCISS_LOCK(c->ctlr), flags);
wait_for_completion(&wait);
/* undo the dma mapping */
cciss_unmap_one(c->pdev, cp, bufsize, DMA_FROM_DEVICE);
return(0);
}
static void
cciss_scsi_interpret_error(CommandList_struct *cp)
{
ErrorInfo_struct *ei;
ei = cp->err_info;
switch(ei->CommandStatus)
{
case CMD_TARGET_STATUS:
printk(KERN_WARNING "cciss: cmd %p has "
"completed with errors\n", cp);
printk(KERN_WARNING "cciss: cmd %p "
"has SCSI Status = %x\n",
cp,
ei->ScsiStatus);
if (ei->ScsiStatus == 0)
printk(KERN_WARNING
"cciss:SCSI status is abnormally zero. "
"(probably indicates selection timeout "
"reported incorrectly due to a known "
"firmware bug, circa July, 2001.)\n");
break;
case CMD_DATA_UNDERRUN: /* let mid layer handle it. */
printk("UNDERRUN\n");
break;
case CMD_DATA_OVERRUN:
printk(KERN_WARNING "cciss: cp %p has"
" completed with data overrun "
"reported\n", cp);
break;
case CMD_INVALID: {
/* controller unfortunately reports SCSI passthru's */
/* to non-existent targets as invalid commands. */
printk(KERN_WARNING "cciss: cp %p is "
"reported invalid (probably means "
"target device no longer present)\n",
cp);
/* print_bytes((unsigned char *) cp, sizeof(*cp), 1, 0);
print_cmd(cp); */
}
break;
case CMD_PROTOCOL_ERR:
printk(KERN_WARNING "cciss: cp %p has "
"protocol error \n", cp);
break;
case CMD_HARDWARE_ERR:
/* cmd->result = DID_ERROR << 16; */
printk(KERN_WARNING "cciss: cp %p had "
" hardware error\n", cp);
break;
case CMD_CONNECTION_LOST:
printk(KERN_WARNING "cciss: cp %p had "
"connection lost\n", cp);
break;
case CMD_ABORTED:
printk(KERN_WARNING "cciss: cp %p was "
"aborted\n", cp);
break;
case CMD_ABORT_FAILED:
printk(KERN_WARNING "cciss: cp %p reports "
"abort failed\n", cp);
break;
case CMD_UNSOLICITED_ABORT:
printk(KERN_WARNING "cciss: cp %p aborted "
"do to an unsolicited abort\n", cp);
break;
case CMD_TIMEOUT:
printk(KERN_WARNING "cciss: cp %p timedout\n",
cp);
break;
default:
printk(KERN_WARNING "cciss: cp %p returned "
"unknown status %x\n", cp,
ei->CommandStatus);
}
}
static int
cciss_scsi_do_inquiry(ctlr_info_t *c, unsigned char *scsi3addr,
unsigned char page, unsigned char *buf,
unsigned char bufsize)
{
int rc;
CommandList_struct *cp;
char cdb[6];
ErrorInfo_struct *ei;
unsigned long flags;
spin_lock_irqsave(CCISS_LOCK(c->ctlr), flags);
cp = scsi_cmd_alloc(c);
spin_unlock_irqrestore(CCISS_LOCK(c->ctlr), flags);
if (cp == NULL) { /* trouble... */
printk("cmd_alloc returned NULL!\n");
return -1;
}
ei = cp->err_info;
cdb[0] = CISS_INQUIRY;
cdb[1] = (page != 0);
cdb[2] = page;
cdb[3] = 0;
cdb[4] = bufsize;
cdb[5] = 0;
rc = cciss_scsi_do_simple_cmd(c, cp, scsi3addr, cdb,
6, buf, bufsize, XFER_READ);
if (rc != 0) return rc; /* something went wrong */
if (ei->CommandStatus != 0 &&
ei->CommandStatus != CMD_DATA_UNDERRUN) {
cciss_scsi_interpret_error(cp);
rc = -1;
}
spin_lock_irqsave(CCISS_LOCK(c->ctlr), flags);
scsi_cmd_free(c, cp);
spin_unlock_irqrestore(CCISS_LOCK(c->ctlr), flags);
return rc;
}
/* Get the device id from inquiry page 0x83 */
static int cciss_scsi_get_device_id(ctlr_info_t *c, unsigned char *scsi3addr,
unsigned char *device_id, int buflen)
{
int rc;
unsigned char *buf;
if (buflen > 16)
buflen = 16;
buf = kzalloc(64, GFP_KERNEL);
if (!buf)
return -1;
rc = cciss_scsi_do_inquiry(c, scsi3addr, 0x83, buf, 64);
if (rc == 0)
memcpy(device_id, &buf[8], buflen);
kfree(buf);
return rc != 0;
}
static int
cciss_scsi_do_report_phys_luns(ctlr_info_t *c,
ReportLunData_struct *buf, int bufsize)
{
int rc;
CommandList_struct *cp;
unsigned char cdb[12];
unsigned char scsi3addr[8];
ErrorInfo_struct *ei;
unsigned long flags;
spin_lock_irqsave(CCISS_LOCK(c->ctlr), flags);
cp = scsi_cmd_alloc(c);
spin_unlock_irqrestore(CCISS_LOCK(c->ctlr), flags);
if (cp == NULL) { /* trouble... */
printk("cmd_alloc returned NULL!\n");
return -1;
}
memset(&scsi3addr[0], 0, 8); /* address the controller */
cdb[0] = CISS_REPORT_PHYS;
cdb[1] = 0;
cdb[2] = 0;
cdb[3] = 0;
cdb[4] = 0;
cdb[5] = 0;
cdb[6] = (bufsize >> 24) & 0xFF; //MSB
cdb[7] = (bufsize >> 16) & 0xFF;
cdb[8] = (bufsize >> 8) & 0xFF;
cdb[9] = bufsize & 0xFF;
cdb[10] = 0;
cdb[11] = 0;
rc = cciss_scsi_do_simple_cmd(c, cp, scsi3addr,
cdb, 12,
(unsigned char *) buf,
bufsize, XFER_READ);
if (rc != 0) return rc; /* something went wrong */
ei = cp->err_info;
if (ei->CommandStatus != 0 &&
ei->CommandStatus != CMD_DATA_UNDERRUN) {
cciss_scsi_interpret_error(cp);
rc = -1;
}
spin_lock_irqsave(CCISS_LOCK(c->ctlr), flags);
scsi_cmd_free(c, cp);
spin_unlock_irqrestore(CCISS_LOCK(c->ctlr), flags);
return rc;
}
static void
cciss_update_non_disk_devices(int cntl_num, int hostno)
{
/* the idea here is we could get notified from /proc
that some devices have changed, so we do a report
physical luns cmd, and adjust our list of devices
accordingly. (We can't rely on the scsi-mid layer just
doing inquiries, because the "busses" that the scsi
mid-layer probes are totally fabricated by this driver,
so new devices wouldn't show up.
the scsi3addr's of devices won't change so long as the
adapter is not reset. That means we can rescan and
tell which devices we already know about, vs. new
devices, vs. disappearing devices.
Also, if you yank out a tape drive, then put in a disk
in it's place, (say, a configured volume from another
array controller for instance) _don't_ poke this driver
(so it thinks it's still a tape, but _do_ poke the scsi
mid layer, so it does an inquiry... the scsi mid layer
will see the physical disk. This would be bad. Need to
think about how to prevent that. One idea would be to
snoop all scsi responses and if an inquiry repsonse comes
back that reports a disk, chuck it an return selection
timeout instead and adjust our table... Not sure i like
that though.
*/
#define OBDR_TAPE_INQ_SIZE 49
#define OBDR_TAPE_SIG "$DR-10"
ReportLunData_struct *ld_buff;
unsigned char *inq_buff;
unsigned char scsi3addr[8];
ctlr_info_t *c;
__u32 num_luns=0;
unsigned char *ch;
struct cciss_scsi_dev_t *currentsd, *this_device;
int ncurrent=0;
int reportlunsize = sizeof(*ld_buff) + CISS_MAX_PHYS_LUN * 8;
int i;
c = (ctlr_info_t *) hba[cntl_num];
ld_buff = kzalloc(reportlunsize, GFP_KERNEL);
inq_buff = kmalloc(OBDR_TAPE_INQ_SIZE, GFP_KERNEL);
currentsd = kzalloc(sizeof(*currentsd) *
(CCISS_MAX_SCSI_DEVS_PER_HBA+1), GFP_KERNEL);
if (ld_buff == NULL || inq_buff == NULL || currentsd == NULL) {
printk(KERN_ERR "cciss: out of memory\n");
goto out;
}
this_device = ¤tsd[CCISS_MAX_SCSI_DEVS_PER_HBA];
if (cciss_scsi_do_report_phys_luns(c, ld_buff, reportlunsize) == 0) {
ch = &ld_buff->LUNListLength[0];
num_luns = ((ch[0]<<24) | (ch[1]<<16) | (ch[2]<<8) | ch[3]) / 8;
if (num_luns > CISS_MAX_PHYS_LUN) {
printk(KERN_WARNING
"cciss: Maximum physical LUNs (%d) exceeded. "
"%d LUNs ignored.\n", CISS_MAX_PHYS_LUN,
num_luns - CISS_MAX_PHYS_LUN);
num_luns = CISS_MAX_PHYS_LUN;
}
}
else {
printk(KERN_ERR "cciss: Report physical LUNs failed.\n");
goto out;
}
/* adjust our table of devices */
for (i = 0; i < num_luns; i++) {
/* for each physical lun, do an inquiry */
if (ld_buff->LUN[i][3] & 0xC0) continue;
memset(inq_buff, 0, OBDR_TAPE_INQ_SIZE);
memcpy(&scsi3addr[0], &ld_buff->LUN[i][0], 8);
if (cciss_scsi_do_inquiry(hba[cntl_num], scsi3addr, 0, inq_buff,
(unsigned char) OBDR_TAPE_INQ_SIZE) != 0)
/* Inquiry failed (msg printed already) */
continue; /* so we will skip this device. */
this_device->devtype = (inq_buff[0] & 0x1f);
this_device->bus = -1;
this_device->target = -1;
this_device->lun = -1;
memcpy(this_device->scsi3addr, scsi3addr, 8);
memcpy(this_device->vendor, &inq_buff[8],
sizeof(this_device->vendor));
memcpy(this_device->model, &inq_buff[16],
sizeof(this_device->model));
memcpy(this_device->revision, &inq_buff[32],
sizeof(this_device->revision));
memset(this_device->device_id, 0,
sizeof(this_device->device_id));
cciss_scsi_get_device_id(hba[cntl_num], scsi3addr,
this_device->device_id, sizeof(this_device->device_id));
switch (this_device->devtype)
{
case 0x05: /* CD-ROM */ {
/* We don't *really* support actual CD-ROM devices,
* just this "One Button Disaster Recovery" tape drive
* which temporarily pretends to be a CD-ROM drive.
* So we check that the device is really an OBDR tape
* device by checking for "$DR-10" in bytes 43-48 of
* the inquiry data.
*/
char obdr_sig[7];
strncpy(obdr_sig, &inq_buff[43], 6);
obdr_sig[6] = '\0';
if (strncmp(obdr_sig, OBDR_TAPE_SIG, 6) != 0)
/* Not OBDR device, ignore it. */
break;
}
/* fall through . . . */
case 0x01: /* sequential access, (tape) */
case 0x08: /* medium changer */
if (ncurrent >= CCISS_MAX_SCSI_DEVS_PER_HBA) {
printk(KERN_INFO "cciss%d: %s ignored, "
"too many devices.\n", cntl_num,
scsi_device_type(this_device->devtype));
break;
}
currentsd[ncurrent] = *this_device;
ncurrent++;
break;
default:
break;
}
}
adjust_cciss_scsi_table(cntl_num, hostno, currentsd, ncurrent);
out:
kfree(inq_buff);
kfree(ld_buff);
kfree(currentsd);
return;
}
static int
is_keyword(char *ptr, int len, char *verb) // Thanks to ncr53c8xx.c
{
int verb_len = strlen(verb);
if (len >= verb_len && !memcmp(verb,ptr,verb_len))
return verb_len;
else
return 0;
}
static int
cciss_scsi_user_command(int ctlr, int hostno, char *buffer, int length)
{
int arg_len;
if ((arg_len = is_keyword(buffer, length, "rescan")) != 0)
cciss_update_non_disk_devices(ctlr, hostno);
else
return -EINVAL;
return length;
}
static int
cciss_scsi_proc_info(struct Scsi_Host *sh,
char *buffer, /* data buffer */
char **start, /* where data in buffer starts */
off_t offset, /* offset from start of imaginary file */
int length, /* length of data in buffer */
int func) /* 0 == read, 1 == write */
{
int buflen, datalen;
ctlr_info_t *ci;
int i;
int cntl_num;
ci = (ctlr_info_t *) sh->hostdata[0];
if (ci == NULL) /* This really shouldn't ever happen. */
return -EINVAL;
cntl_num = ci->ctlr; /* Get our index into the hba[] array */
if (func == 0) { /* User is reading from /proc/scsi/ciss*?/?* */
buflen = sprintf(buffer, "cciss%d: SCSI host: %d\n",
cntl_num, sh->host_no);
/* this information is needed by apps to know which cciss
device corresponds to which scsi host number without
having to open a scsi target device node. The device
information is not a duplicate of /proc/scsi/scsi because
the two may be out of sync due to scsi hotplug, rather
this info is for an app to be able to use to know how to
get them back in sync. */
for (i=0;i<ccissscsi[cntl_num].ndevices;i++) {
struct cciss_scsi_dev_t *sd = &ccissscsi[cntl_num].dev[i];
buflen += sprintf(&buffer[buflen], "c%db%dt%dl%d %02d "
"0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
sh->host_no, sd->bus, sd->target, sd->lun,
sd->devtype,
sd->scsi3addr[0], sd->scsi3addr[1],
sd->scsi3addr[2], sd->scsi3addr[3],
sd->scsi3addr[4], sd->scsi3addr[5],
sd->scsi3addr[6], sd->scsi3addr[7]);
}
datalen = buflen - offset;
if (datalen < 0) { /* they're reading past EOF. */
datalen = 0;
*start = buffer+buflen;
} else
*start = buffer + offset;
return(datalen);
} else /* User is writing to /proc/scsi/cciss*?/?* ... */
return cciss_scsi_user_command(cntl_num, sh->host_no,
buffer, length);
}
/* cciss_scatter_gather takes a struct scsi_cmnd, (cmd), and does the pci
dma mapping and fills in the scatter gather entries of the
cciss command, cp. */
static void
cciss_scatter_gather(struct pci_dev *pdev,
CommandList_struct *cp,
struct scsi_cmnd *cmd)
{
unsigned int len;
struct scatterlist *sg;
__u64 addr64;
int use_sg, i;
BUG_ON(scsi_sg_count(cmd) > MAXSGENTRIES);
use_sg = scsi_dma_map(cmd);
if (use_sg) { /* not too many addrs? */
scsi_for_each_sg(cmd, sg, use_sg, i) {
addr64 = (__u64) sg_dma_address(sg);
len = sg_dma_len(sg);
cp->SG[i].Addr.lower =
(__u32) (addr64 & (__u64) 0x00000000FFFFFFFF);
cp->SG[i].Addr.upper =
(__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF);
cp->SG[i].Len = len;
cp->SG[i].Ext = 0; // we are not chaining
}
}
cp->Header.SGList = (__u8) use_sg; /* no. SGs contig in this cmd */
cp->Header.SGTotal = (__u16) use_sg; /* total sgs in this cmd list */
return;
}
static int
cciss_scsi_queue_command (struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *))
{
ctlr_info_t **c;
int ctlr, rc;
unsigned char scsi3addr[8];
CommandList_struct *cp;
unsigned long flags;
// Get the ptr to our adapter structure (hba[i]) out of cmd->host.
// We violate cmd->host privacy here. (Is there another way?)
c = (ctlr_info_t **) &cmd->device->host->hostdata[0];
ctlr = (*c)->ctlr;
rc = lookup_scsi3addr(ctlr, cmd->device->channel, cmd->device->id,
cmd->device->lun, scsi3addr);
if (rc != 0) {
/* the scsi nexus does not match any that we presented... */
/* pretend to mid layer that we got selection timeout */
cmd->result = DID_NO_CONNECT << 16;
done(cmd);
/* we might want to think about registering controller itself
as a processor device on the bus so sg binds to it. */
return 0;
}
/* printk("cciss_queue_command, p=%p, cmd=0x%02x, c%db%dt%dl%d\n",
cmd, cmd->cmnd[0], ctlr, cmd->channel, cmd->target, cmd->lun);*/
// printk("q:%p:c%db%dt%dl%d ", cmd, ctlr, cmd->channel,
// cmd->target, cmd->lun);
/* Ok, we have a reasonable scsi nexus, so send the cmd down, and
see what the device thinks of it. */
spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
cp = scsi_cmd_alloc(*c);
spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
if (cp == NULL) { /* trouble... */
printk("scsi_cmd_alloc returned NULL!\n");
/* FIXME: next 3 lines are -> BAD! <- */
cmd->result = DID_NO_CONNECT << 16;
done(cmd);
return 0;
}
// Fill in the command list header
cmd->scsi_done = done; // save this for use by completion code
// save cp in case we have to abort it
cmd->host_scribble = (unsigned char *) cp;
cp->cmd_type = CMD_SCSI;
cp->scsi_cmd = cmd;
cp->Header.ReplyQueue = 0; // unused in simple mode
memcpy(&cp->Header.LUN.LunAddrBytes[0], &scsi3addr[0], 8);
cp->Header.Tag.lower = cp->busaddr; // Use k. address of cmd as tag
// Fill in the request block...
cp->Request.Timeout = 0;
memset(cp->Request.CDB, 0, sizeof(cp->Request.CDB));
BUG_ON(cmd->cmd_len > sizeof(cp->Request.CDB));
cp->Request.CDBLen = cmd->cmd_len;
memcpy(cp->Request.CDB, cmd->cmnd, cmd->cmd_len);
cp->Request.Type.Type = TYPE_CMD;
cp->Request.Type.Attribute = ATTR_SIMPLE;
switch(cmd->sc_data_direction)
{
case DMA_TO_DEVICE: cp->Request.Type.Direction = XFER_WRITE; break;
case DMA_FROM_DEVICE: cp->Request.Type.Direction = XFER_READ; break;
case DMA_NONE: cp->Request.Type.Direction = XFER_NONE; break;
case DMA_BIDIRECTIONAL:
// This can happen if a buggy application does a scsi passthru
// and sets both inlen and outlen to non-zero. ( see
// ../scsi/scsi_ioctl.c:scsi_ioctl_send_command() )
cp->Request.Type.Direction = XFER_RSVD;
// This is technically wrong, and cciss controllers should
// reject it with CMD_INVALID, which is the most correct
// response, but non-fibre backends appear to let it
// slide by, and give the same results as if this field
// were set correctly. Either way is acceptable for
// our purposes here.
break;
default:
printk("cciss: unknown data direction: %d\n",
cmd->sc_data_direction);
BUG();
break;
}
cciss_scatter_gather((*c)->pdev, cp, cmd); // Fill the SG list
/* Put the request on the tail of the request queue */
spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
addQ(&(*c)->reqQ, cp);
(*c)->Qdepth++;
start_io(*c);
spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
/* the cmd'll come back via intr handler in complete_scsi_command() */
return 0;
}
static void
cciss_unregister_scsi(int ctlr)
{
struct cciss_scsi_adapter_data_t *sa;
struct cciss_scsi_cmd_stack_t *stk;
unsigned long flags;
/* we are being forcibly unloaded, and may not refuse. */
spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
sa = (struct cciss_scsi_adapter_data_t *) hba[ctlr]->scsi_ctlr;
stk = &sa->cmd_stack;
/* if we weren't ever actually registered, don't unregister */
if (sa->registered) {
spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
scsi_remove_host(sa->scsi_host);
scsi_host_put(sa->scsi_host);
spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
}
/* set scsi_host to NULL so our detect routine will
find us on register */
sa->scsi_host = NULL;
spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
scsi_cmd_stack_free(ctlr);
kfree(sa);
}
static int
cciss_engage_scsi(int ctlr)
{
struct cciss_scsi_adapter_data_t *sa;
struct cciss_scsi_cmd_stack_t *stk;
unsigned long flags;
spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
sa = (struct cciss_scsi_adapter_data_t *) hba[ctlr]->scsi_ctlr;
stk = &sa->cmd_stack;
if (sa->registered) {
printk("cciss%d: SCSI subsystem already engaged.\n", ctlr);
spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
return ENXIO;
}
sa->registered = 1;
spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
cciss_update_non_disk_devices(ctlr, -1);
cciss_scsi_detect(ctlr);
return 0;
}
static void
cciss_seq_tape_report(struct seq_file *seq, int ctlr)
{
unsigned long flags;
CPQ_TAPE_LOCK(ctlr, flags);
seq_printf(seq,
"Sequential access devices: %d\n\n",
ccissscsi[ctlr].ndevices);
CPQ_TAPE_UNLOCK(ctlr, flags);
}
static int wait_for_device_to_become_ready(ctlr_info_t *h,
unsigned char lunaddr[])
{
int rc;
int count = 0;
int waittime = HZ;
CommandList_struct *c;
c = cmd_alloc(h, 1);
if (!c) {
printk(KERN_WARNING "cciss%d: out of memory in "
"wait_for_device_to_become_ready.\n", h->ctlr);
return IO_ERROR;
}
/* Send test unit ready until device ready, or give up. */
while (count < 20) {
/* Wait for a bit. do this first, because if we send
* the TUR right away, the reset will just abort it.
*/
schedule_timeout_uninterruptible(waittime);
count++;
/* Increase wait time with each try, up to a point. */
if (waittime < (HZ * 30))
waittime = waittime * 2;
/* Send the Test Unit Ready */
rc = fill_cmd(c, TEST_UNIT_READY, h->ctlr, NULL, 0, 0,
lunaddr, TYPE_CMD);
if (rc == 0)
rc = sendcmd_withirq_core(h, c, 0);
(void) process_sendcmd_error(h, c);
if (rc != 0)
goto retry_tur;
if (c->err_info->CommandStatus == CMD_SUCCESS)
break;
if (c->err_info->CommandStatus == CMD_TARGET_STATUS &&
c->err_info->ScsiStatus == SAM_STAT_CHECK_CONDITION) {
if (c->err_info->SenseInfo[2] == NO_SENSE)
break;
if (c->err_info->SenseInfo[2] == UNIT_ATTENTION) {
unsigned char asc;
asc = c->err_info->SenseInfo[12];
check_for_unit_attention(h, c);
if (asc == POWER_OR_RESET)
break;
}
}
retry_tur:
printk(KERN_WARNING "cciss%d: Waiting %d secs "
"for device to become ready.\n",
h->ctlr, waittime / HZ);
rc = 1; /* device not ready. */
}
if (rc)
printk("cciss%d: giving up on device.\n", h->ctlr);
else
printk(KERN_WARNING "cciss%d: device is ready.\n", h->ctlr);
cmd_free(h, c, 1);
return rc;
}
/* Need at least one of these error handlers to keep ../scsi/hosts.c from
* complaining. Doing a host- or bus-reset can't do anything good here.
* Despite what it might say in scsi_error.c, there may well be commands
* on the controller, as the cciss driver registers twice, once as a block
* device for the logical drives, and once as a scsi device, for any tape
* drives. So we know there are no commands out on the tape drives, but we
* don't know there are no commands on the controller, and it is likely
* that there probably are, as the cciss block device is most commonly used
* as a boot device (embedded controller on HP/Compaq systems.)
*/
static int cciss_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
{
int rc;
CommandList_struct *cmd_in_trouble;
unsigned char lunaddr[8];
ctlr_info_t **c;
int ctlr;
/* find the controller to which the command to be aborted was sent */
c = (ctlr_info_t **) &scsicmd->device->host->hostdata[0];
if (c == NULL) /* paranoia */
return FAILED;
ctlr = (*c)->ctlr;
printk(KERN_WARNING "cciss%d: resetting tape drive or medium changer.\n", ctlr);
/* find the command that's giving us trouble */
cmd_in_trouble = (CommandList_struct *) scsicmd->host_scribble;
if (cmd_in_trouble == NULL) /* paranoia */
return FAILED;
memcpy(lunaddr, &cmd_in_trouble->Header.LUN.LunAddrBytes[0], 8);
/* send a reset to the SCSI LUN which the command was sent to */
rc = sendcmd_withirq(CCISS_RESET_MSG, ctlr, NULL, 0, 0, lunaddr,
TYPE_MSG);
if (rc == 0 && wait_for_device_to_become_ready(*c, lunaddr) == 0)
return SUCCESS;
printk(KERN_WARNING "cciss%d: resetting device failed.\n", ctlr);
return FAILED;
}
static int cciss_eh_abort_handler(struct scsi_cmnd *scsicmd)
{
int rc;
CommandList_struct *cmd_to_abort;
unsigned char lunaddr[8];
ctlr_info_t **c;
int ctlr;
/* find the controller to which the command to be aborted was sent */
c = (ctlr_info_t **) &scsicmd->device->host->hostdata[0];
if (c == NULL) /* paranoia */
return FAILED;
ctlr = (*c)->ctlr;
printk(KERN_WARNING "cciss%d: aborting tardy SCSI cmd\n", ctlr);
/* find the command to be aborted */
cmd_to_abort = (CommandList_struct *) scsicmd->host_scribble;
if (cmd_to_abort == NULL) /* paranoia */
return FAILED;
memcpy(lunaddr, &cmd_to_abort->Header.LUN.LunAddrBytes[0], 8);
rc = sendcmd_withirq(CCISS_ABORT_MSG, ctlr, &cmd_to_abort->Header.Tag,
0, 0, lunaddr, TYPE_MSG);
if (rc == 0)
return SUCCESS;
return FAILED;
}
#else /* no CONFIG_CISS_SCSI_TAPE */
/* If no tape support, then these become defined out of existence */
#define cciss_scsi_setup(cntl_num)
#endif /* CONFIG_CISS_SCSI_TAPE */
|
the_stack_data/120942.c | /*Exercise 4 - Functions
Implement the three functions minimum(), maximum() and multiply() below the main() function.
Do not change the code given in the main() function when you are implementing your solution.*/
#include <stdio.h>
int main() {
int no1, no2;
printf("Enter a value for no 1 : ");
scanf("%d", &no1);
printf("Enter a value for no 2 : ");
scanf("%d", &no2);
printf("%d ", minimum(no1, no2));
printf("%d ", maximum(no1, no2));
printf("%d ", multiply(no1, no2));
return 0;
}
int minimum(int no1 , int no2)
{
if (no1 > no2)
{
return no2;
}
else return no1;
}
int maximum(int no1, int no2)
{
if(no1 > no2)
{
return no1;
}
else return no2;
}
int multiply(int no1, int no2)
{
return no1 * no2;
} |
the_stack_data/165764352.c | #include <stdio.h>
void printArray(int [], int);
void insertionsort(int [], int );
int main(){
int arr[] = {88,44,66,22,100};
// Getting the length of array
int size = sizeof(arr)/sizeof(arr[0]);
printf("Original array is: ");
printArray(arr, size);
insertionsort(arr, size);
printf("Sorted array is: ");
printArray(arr, size);
return 0;
}
// insertionsort
void insertionsort(int arr[], int n){
for (int i = 1; i < n; i++)
{
// first Element of unsorted part
int currentElem = arr[i];
// index of Element in sorted part
int indexInSorted = i-1;
// shifts the array 1 element right unitl perfect position for currentElem
while (indexInSorted >= 0 && arr[indexInSorted] > currentElem)
{
arr[indexInSorted + 1] = arr[indexInSorted];
indexInSorted--;
}
// placing the currentElem at it correct position
arr[indexInSorted + 1] = currentElem;
}
}
// printArray displays the Array elements spaced in one line
// arr[] -> array to be printed
// n -> size of the array
void printArray(int arr[], int n){
for (int i = 0; i < n; i++)
{
printf("%d ", arr[i]);
}
printf("\n");
} |
the_stack_data/99675.c | #include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <fcntl.h>
void main()
{
while(1)
{
// Creating I2C-2 bus_
int file;
char *bus_ = "/dev/i2c-2";
if ((file = open(bus_, O_RDWR)) < 0)
{
printf("Cannot open bus_. \n");
exit(1);
}
// I2C device, Address of ADXL345 is 0x53(83)
ioctl(file, I2C_SLAVE, 0x53);
// Selecting Bandwidth_rate_register(0x2C)
//in_Normal_mode, Output_data_rate = 100 Hz(0x0A)
char config[2]={0};
config[0] = 0x2C;
config[1] = 0x0A;
write(file, config, 2);
// Select PCR(Power_control_register)(0x2D)
// Auto-sleep_disable(0x08)
config[0] = 0x2D;
config[1] = 0x08;
write(file, config, 2);
// Select DFR(Data_format_register)(0x31)
// Self_test_disabled, 4-wire_interface, Full_resolution, range = +/-2g(0x08)
config[0] = 0x31;
config[1] = 0x08;
write(file, config, 2);
sleep(1);
// Reading data(6bytes) from_register(0x32)
// x_Acc_lsb, x_Acc_msb, y_Acc_lsb, y_Acc_msb, z_Acc_lsb, z_Acc_msb
char reg[1] = {0x32};
write(file, reg, 1);
char data[6] ={0};
if(read(file, data, 6) != 6)
{
printf("Incorrect : I/O Incorrect \n");
exit(1);
}
else
{
// Convert the data to 10-bits
int x_Acc = ((data[1] & 0x03) * 256 + (data[0] & 0xFF));
if(x_Acc > 511)
{
x_Acc -= 1024;
}
int y_Acc = ((data[3] & 0x03) * 256 + (data[2] & 0xFF));
if(y_Acc > 511)
{
y_Acc -= 1024;
}
int z_Acc = ((data[5] & 0x03) * 256 + (data[4] & 0xFF));
if(z_Acc > 511)
{
z_Acc -= 1024;
}
// Output data to screen
printf("Accelerometer reading \n ");
printf(" X-Axis = %d \n", x_Acc);
printf(" Y-Axis = %d \n", y_Acc);
printf(" Z-Axis = %d \n", z_Acc);
}
}
}
|
the_stack_data/418715.c | #include<stdio.h>
int main(){
int gasto, cupom, cupons_ganho;
printf("Quantos gastou nesse supermercado: ");
scanf("%d",&gasto);
cupom = 20;
cupons_ganho=gasto/cupom;
printf("Voce ganhou %.0d cupons",cupons_ganho);
return 0;
} |
the_stack_data/330758.c | const unsigned char local_audio_net_succ[2880] = {
0xFF, 0xF3, 0x28, 0xC4, 0x00, 0x0C, 0x70, 0x9E, 0x3C, 0x01, 0x58, 0x10, 0x01, 0xE4, 0xAD, 0xDB,
0x87, 0xE4, 0x8B, 0x91, 0x62, 0x38, 0x20, 0x12, 0x9E, 0x34, 0x78, 0xA1, 0xB0, 0x4B, 0x31, 0x1B,
0xCC, 0x67, 0x34, 0xA4, 0x20, 0xEA, 0x18, 0x6D, 0x79, 0xAC, 0x2C, 0x7D, 0x5B, 0x11, 0x51, 0xA6,
0x49, 0x59, 0xDB, 0xF6, 0x20, 0x20, 0x03, 0x75, 0x38, 0x00, 0x03, 0x07, 0x8F, 0xC0, 0x3D, 0xDE,
0x7B, 0x8E, 0xFC, 0x96, 0x9F, 0xA9, 0x1E, 0x9C, 0xFF, 0xF3, 0x28, 0xC4, 0x09, 0x0E, 0x68, 0xD6,
0xC8, 0x01, 0x98, 0x78, 0x00, 0x29, 0x7A, 0x90, 0x31, 0x89, 0x64, 0x04, 0xD7, 0x2A, 0x95, 0x46,
0xB8, 0x58, 0xB8, 0xDF, 0x4F, 0x17, 0x02, 0xF2, 0x9C, 0x03, 0x47, 0x59, 0xBF, 0x8C, 0x88, 0x42,
0x15, 0x69, 0x12, 0x30, 0x07, 0x9F, 0xFF, 0xFF, 0x1F, 0x14, 0xED, 0x6E, 0x14, 0x7F, 0xFD, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xEC, 0x42, 0x02, 0x6B, 0x6B, 0x92, 0xEC, 0x30, 0xD8, 0x01, 0xFF, 0xF9,
0xFF, 0xF3, 0x28, 0xC4, 0x0A, 0x0F, 0x90, 0xE7, 0x2A, 0x5F, 0xCB, 0x60, 0x02, 0x60, 0x6C, 0x03,
0xD2, 0x9F, 0xD4, 0x12, 0x02, 0x71, 0xB3, 0x5B, 0x31, 0x06, 0x84, 0xE3, 0xD7, 0x33, 0x2D, 0x8F,
0x0A, 0xD6, 0xD6, 0x66, 0xE9, 0xD1, 0xAD, 0x31, 0x3D, 0xAC, 0xD0, 0xF0, 0x4B, 0x18, 0x3D, 0x97,
0x3B, 0x8D, 0x09, 0xDF, 0xA8, 0x10, 0x77, 0xFE, 0xFF, 0xFF, 0xFF, 0xD4, 0xA5, 0xDF, 0xDD, 0xB1,
0xDA, 0xEA, 0x03, 0x7F, 0x80, 0xF0, 0xF0, 0x3F, 0xFF, 0xF3, 0x28, 0xC4, 0x06, 0x0E, 0xB0, 0xF6,
0xDD, 0x94, 0x6B, 0xD0, 0x70, 0x2B, 0x04, 0x98, 0xA4, 0x74, 0xB9, 0xFC, 0xA0, 0x55, 0x46, 0xFF,
0x3D, 0xBC, 0x55, 0x36, 0x33, 0x67, 0x18, 0xC9, 0x07, 0x16, 0x15, 0x4E, 0x3F, 0x2C, 0x20, 0x05,
0xD7, 0xFE, 0x78, 0x7C, 0x2D, 0x75, 0xCB, 0x8A, 0x07, 0xCB, 0x5F, 0x90, 0xEE, 0xA8, 0x96, 0x97,
0x68, 0xFF, 0xFF, 0xFF, 0xDB, 0xA9, 0xBB, 0xE8, 0x48, 0x4A, 0x15, 0x49, 0x65, 0xB6, 0xDB, 0x40,
0xFF, 0xF3, 0x28, 0xC4, 0x06, 0x0E, 0x48, 0xEF, 0x02, 0x5E, 0x6B, 0xD6, 0x72, 0xB4, 0x01, 0xDD,
0x8D, 0x90, 0x06, 0xA4, 0x0B, 0x95, 0xFC, 0x8B, 0x7C, 0x2D, 0xFF, 0xE4, 0x2F, 0x86, 0x33, 0xDA,
0xEB, 0x10, 0x8D, 0xF8, 0xCC, 0xBF, 0xEE, 0xC0, 0x94, 0xE1, 0xEF, 0xA8, 0x29, 0x35, 0xB6, 0xFC,
0x18, 0x8E, 0x95, 0x9D, 0x5F, 0xA2, 0xEF, 0xFA, 0xBF, 0xFF, 0xFF, 0xFE, 0x58, 0xF2, 0x4F, 0x75,
0x55, 0xF5, 0x22, 0x09, 0xA2, 0x03, 0x33, 0x54, 0xFF, 0xF3, 0x28, 0xC4, 0x07, 0x0E, 0xE0, 0xD2,
0xA0, 0x00, 0xA6, 0x12, 0x70, 0x28, 0x6C, 0x3D, 0x30, 0xDF, 0x89, 0x7B, 0xD1, 0xB0, 0x02, 0x1B,
0xF7, 0x72, 0xF6, 0xB7, 0x13, 0x2C, 0xB1, 0x7E, 0x21, 0xCB, 0xD8, 0xF7, 0x26, 0xE3, 0x24, 0x87,
0x30, 0xDF, 0xE2, 0x30, 0xB9, 0xBB, 0xFB, 0x36, 0x09, 0xBC, 0x93, 0x72, 0x2B, 0x67, 0x68, 0x2D,
0x7D, 0xBD, 0xFF, 0xFF, 0xFF, 0xFF, 0xC8, 0xEA, 0x32, 0x85, 0x0C, 0x41, 0x2B, 0x8E, 0xDB, 0x40,
0xFF, 0xF3, 0x28, 0xC4, 0x06, 0x0E, 0x78, 0xAA, 0xEA, 0x5E, 0x6E, 0x0C, 0x4E, 0xA0, 0x01, 0xEE,
0x82, 0x44, 0xE0, 0xDF, 0x05, 0x91, 0x5E, 0xDA, 0xFF, 0xD1, 0x6E, 0x8B, 0x87, 0x6A, 0x51, 0x49,
0x1D, 0x6B, 0xA5, 0x05, 0x1A, 0xD1, 0xAE, 0x47, 0x3C, 0xFF, 0x3A, 0xF3, 0x28, 0x26, 0x71, 0x61,
0x40, 0x64, 0x08, 0xE3, 0x6E, 0x1C, 0xB6, 0x9D, 0xFE, 0xAF, 0xFF, 0xFF, 0xEA, 0xA4, 0x50, 0x7C,
0x4A, 0x0A, 0xFE, 0xFD, 0x66, 0xE1, 0x74, 0x45, 0xFF, 0xF3, 0x28, 0xC4, 0x07, 0x0E, 0x00, 0xE6,
0xC8, 0xC8, 0x83, 0xCC, 0x70, 0x26, 0x00, 0x80, 0x37, 0x30, 0xD4, 0xB5, 0x63, 0x4C, 0xA5, 0xBB,
0x1A, 0x40, 0x2F, 0x03, 0x50, 0x58, 0x25, 0xDF, 0xD6, 0xF1, 0x9B, 0x30, 0x04, 0x10, 0xC8, 0x7F,
0x96, 0xD9, 0xEF, 0x2D, 0xB1, 0x33, 0x24, 0x99, 0x49, 0xD9, 0x30, 0xE0, 0xE2, 0x63, 0x89, 0x8D,
0x60, 0xF2, 0x0F, 0x6A, 0x7B, 0xEA, 0xFD, 0x45, 0xE9, 0x74, 0x38, 0xA0, 0x03, 0x40, 0x7A, 0x52,
0xFF, 0xF3, 0x28, 0xC4, 0x0A, 0x0C, 0xE8, 0xDA, 0xC4, 0x00, 0x8E, 0x18, 0x70, 0xEB, 0x7A, 0xCB,
0xB5, 0xE7, 0x60, 0x25, 0x02, 0x25, 0x5B, 0x16, 0xC7, 0x2D, 0x6F, 0xFF, 0x9A, 0x5D, 0x73, 0xD0,
0x39, 0x16, 0x77, 0xF5, 0x26, 0xC9, 0x54, 0x09, 0x6D, 0x56, 0x67, 0x5D, 0x06, 0x81, 0xA4, 0x07,
0xFF, 0xFF, 0xFF, 0xFF, 0xF7, 0xF8, 0xBD, 0x12, 0x13, 0x33, 0xF7, 0x00, 0x12, 0x00, 0x3D, 0x50,
0xCF, 0x0A, 0x02, 0x8B, 0x5D, 0x68, 0xBB, 0x20, 0xFF, 0xF3, 0x28, 0xC4, 0x11, 0x0D, 0x20, 0xC6,
0xF2, 0x3E, 0x3C, 0x1E, 0x72, 0xF1, 0xD6, 0x48, 0xF4, 0xEC, 0x82, 0xF7, 0x0C, 0x6F, 0x92, 0xD7,
0x1B, 0xE7, 0x1F, 0xDA, 0xFB, 0xDA, 0x9D, 0x09, 0x77, 0x8B, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0x1B,
0x0E, 0xB2, 0x0F, 0xB0, 0xED, 0x0B, 0x14, 0x71, 0x25, 0x34, 0x34, 0x5F, 0x00, 0xF0, 0x3E, 0xA4,
0xDD, 0x93, 0x58, 0x09, 0xB2, 0xF3, 0x8F, 0xBF, 0x5C, 0xE1, 0xB1, 0x3A, 0x96, 0x0D, 0x15, 0x9C,
0xFF, 0xF3, 0x28, 0xC4, 0x17, 0x0D, 0x28, 0xDE, 0xDD, 0x94, 0x6B, 0xD2, 0x70, 0x7B, 0xFC, 0x7C,
0x3C, 0x00, 0x81, 0x95, 0x99, 0xFF, 0xF8, 0xE4, 0xD3, 0x16, 0x36, 0x15, 0x3D, 0x53, 0xFE, 0x0D,
0x87, 0x3F, 0xFF, 0xFF, 0xFF, 0xFE, 0x87, 0xDF, 0xCE, 0xED, 0x42, 0xFC, 0x20, 0x03, 0x33, 0x14,
0x42, 0x15, 0x57, 0xFD, 0xEB, 0x99, 0xC0, 0x68, 0xF6, 0x90, 0xC0, 0x80, 0x81, 0xA2, 0x8D, 0xDE,
0xFE, 0xE0, 0x21, 0x87, 0xB9, 0x2A, 0x7E, 0xCB, 0xFF, 0xF3, 0x28, 0xC4, 0x1D, 0x0D, 0x30, 0xB2,
0xC8, 0x00, 0x0E, 0x1E, 0x4C, 0x0B, 0x79, 0xC6, 0x29, 0x5D, 0xC5, 0xA0, 0xE8, 0x40, 0xB8, 0x08,
0x44, 0x7A, 0x64, 0xE2, 0x7F, 0xFF, 0xFF, 0xFF, 0x4B, 0xFE, 0x39, 0xCA, 0xA2, 0x00, 0x91, 0x3F,
0xFF, 0xF0, 0x3F, 0x88, 0xC0, 0xA0, 0x24, 0x28, 0x4F, 0xC5, 0x6E, 0xF1, 0x76, 0x3D, 0x06, 0x4A,
0xB5, 0x43, 0x47, 0xE6, 0x18, 0x01, 0x00, 0x42, 0xCB, 0xEC, 0x24, 0xE2, 0x2C, 0x59, 0xEA, 0xFB,
0xFF, 0xF3, 0x28, 0xC4, 0x23, 0x0D, 0x38, 0x9E, 0xD5, 0x94, 0x53, 0xCA, 0x4C, 0x50, 0x15, 0x12,
0x86, 0xBF, 0x5B, 0xBF, 0xFF, 0x53, 0x5C, 0x49, 0x29, 0x65, 0x29, 0x48, 0x19, 0x35, 0xD1, 0xF0,
0x01, 0xF4, 0x00, 0x54, 0x62, 0x91, 0xB9, 0x75, 0xE9, 0x62, 0xF3, 0x47, 0xF0, 0xD5, 0x83, 0x15,
0x96, 0x97, 0x7F, 0x77, 0xE1, 0xC4, 0x8D, 0x3E, 0x55, 0xC5, 0x28, 0xFF, 0xFF, 0xFA, 0x5E, 0x82,
0x80, 0x85, 0x40, 0x83, 0xFE, 0x90, 0xF4, 0xEA, 0xFF, 0xF3, 0x28, 0xC4, 0x29, 0x0C, 0xD0, 0x5E,
0xB0, 0x00, 0x0E, 0x5E, 0x28, 0x49, 0x39, 0x2B, 0xBB, 0xDD, 0xFF, 0xFF, 0xF9, 0x6B, 0xC5, 0x95,
0xF9, 0x48, 0x07, 0x18, 0x2F, 0xE8, 0xB0, 0xA4, 0xE7, 0x07, 0xD8, 0x18, 0xD2, 0x13, 0xD0, 0x13,
0x23, 0x64, 0x92, 0x15, 0xC0, 0xC5, 0x03, 0x86, 0xDA, 0x8F, 0xB3, 0xF5, 0x20, 0xBE, 0xB4, 0xDF,
0xFF, 0xFF, 0xFF, 0xFF, 0xF7, 0xFF, 0xF7, 0x57, 0xAB, 0x98, 0x00, 0x23, 0x25, 0x47, 0x1E, 0xEE,
0xFF, 0xF3, 0x28, 0xC4, 0x30, 0x0C, 0x89, 0x9E, 0xBC, 0x00, 0x9C, 0x84, 0x94, 0xAD, 0x15, 0x2A,
0xFA, 0x80, 0x78, 0x0E, 0x90, 0xBE, 0x99, 0x70, 0xC8, 0x67, 0x40, 0xF1, 0x28, 0x98, 0x2D, 0x22,
0x91, 0x1C, 0x02, 0x72, 0x24, 0x6E, 0xD9, 0x60, 0xB8, 0x69, 0xEB, 0x41, 0xBD, 0x4B, 0xFB, 0xFD,
0x1B, 0xFF, 0xFF, 0xFF, 0xFE, 0x4F, 0x90, 0xFC, 0x31, 0x82, 0x8E, 0xF2, 0xC4, 0xCE, 0x7D, 0x5D,
0xB4, 0x26, 0xF9, 0x89, 0x0C, 0x03, 0xC2, 0xC3, 0xFF, 0xF3, 0x28, 0xC4, 0x38, 0x0C, 0x71, 0x9E,
0xC4, 0x00, 0x8C, 0x04, 0x94, 0x9C, 0xA9, 0xDE, 0xFC, 0xE4, 0x88, 0xDC, 0x06, 0xB2, 0x34, 0x4B,
0x2F, 0xC0, 0x13, 0x1F, 0x98, 0x1B, 0x76, 0xCB, 0x5D, 0xAE, 0xBD, 0x60, 0xA9, 0xE9, 0x6F, 0xFF,
0xFF, 0xE5, 0xA2, 0xEC, 0x09, 0x80, 0x83, 0x41, 0x57, 0x02, 0xB6, 0x7F, 0xC4, 0xB0, 0x92, 0x2A,
0x13, 0xF3, 0xAB, 0xC2, 0x84, 0x49, 0x43, 0x0C, 0x4E, 0x08, 0xF2, 0xD1, 0x54, 0xCD, 0xEE, 0x83,
0xFF, 0xF3, 0x28, 0xC4, 0x41, 0x0C, 0x10, 0x7A, 0xB4, 0x00, 0x9E, 0x18, 0x48, 0xEC, 0x40, 0x69,
0x7A, 0x64, 0x80, 0x63, 0x23, 0x3E, 0x23, 0x63, 0xBD, 0x88, 0x07, 0x38, 0x23, 0x26, 0x7C, 0xB8,
0x5E, 0x08, 0x39, 0x8E, 0x7B, 0xE9, 0xFF, 0xFF, 0xF6, 0xB8, 0xDD, 0x1F, 0xFF, 0xF3, 0xFF, 0x8F,
0xFE, 0x69, 0x74, 0x80, 0x0E, 0xC1, 0xD5, 0x67, 0xD7, 0x8B, 0x5C, 0xF8, 0xD7, 0x70, 0xC2, 0x9C,
0xEA, 0x5B, 0x1D, 0x56, 0xA8, 0xE6, 0x76, 0x67, 0xFF, 0xF3, 0x28, 0xC4, 0x4B, 0x0B, 0x68, 0x66,
0x98, 0xC8, 0x2E, 0xDE, 0x28, 0x31, 0x9E, 0x55, 0xBA, 0xB1, 0x64, 0x44, 0x66, 0xA2, 0x75, 0xBF,
0xFF, 0xFF, 0xBF, 0xF9, 0xFE, 0x78, 0xAA, 0x49, 0x7A, 0x18, 0x64, 0xDB, 0xDD, 0xDC, 0x7D, 0x45,
0x73, 0xF3, 0xC4, 0xDC, 0x72, 0xED, 0x2C, 0x1C, 0x00, 0xA0, 0x89, 0x0B, 0x62, 0x95, 0x52, 0xEE,
0x4D, 0xA7, 0x11, 0xDF, 0x7D, 0xEF, 0xFF, 0xF3, 0xFF, 0x08, 0xF2, 0x42, 0x24, 0x3C, 0x7B, 0xF0,
0xFF, 0xF3, 0x28, 0xC4, 0x58, 0x18, 0x53, 0x1E, 0xAC, 0xF4, 0x78, 0x90, 0xBC, 0x68, 0xF3, 0x22,
0x8B, 0xBA, 0xD1, 0xC5, 0x2C, 0x51, 0x15, 0xC3, 0x58, 0x72, 0xA6, 0xE3, 0x90, 0x24, 0xD3, 0xF6,
0x21, 0x2C, 0xE3, 0xAC, 0x15, 0xBA, 0x3C, 0x3C, 0x90, 0xC6, 0x35, 0x11, 0x89, 0x08, 0x20, 0x3B,
0x92, 0xF6, 0xA1, 0x14, 0xED, 0xBD, 0x09, 0x9A, 0xD6, 0xFB, 0xDF, 0xFF, 0xFF, 0xFF, 0xFE, 0x7E,
0xE2, 0xB9, 0xA8, 0xA7, 0xE6, 0x60, 0x4E, 0x34, 0xFF, 0xF3, 0x28, 0xC4, 0x31, 0x17, 0xE3, 0x1E,
0xA0, 0x00, 0xC8, 0x90, 0xBC, 0x85, 0xBA, 0x8A, 0x5A, 0xBE, 0xEF, 0x5B, 0xFA, 0x1B, 0x5D, 0xCC,
0x3D, 0x09, 0x41, 0xE0, 0xF4, 0x54, 0x48, 0x20, 0x9C, 0x7F, 0x75, 0xBD, 0xDF, 0x4D, 0x3F, 0xFC,
0xFF, 0xFD, 0x7F, 0xF3, 0x4C, 0xB2, 0x55, 0x4A, 0xA8, 0xB5, 0x4A, 0xDC, 0x5D, 0x6D, 0x6F, 0x1D,
0x9B, 0xAC, 0x0D, 0xB5, 0x5D, 0xF3, 0xA7, 0xFF, 0xFF, 0xEB, 0x9A, 0xAC, 0xFA, 0xA7, 0x29, 0x88,
0xFF, 0xF3, 0x28, 0xC4, 0x0C, 0x0F, 0x31, 0x92, 0xC4, 0xCA, 0xCB, 0x44, 0x94, 0x88, 0x4F, 0x4F,
0x74, 0xA8, 0xD9, 0x4F, 0xEA, 0x36, 0x03, 0xD0, 0x39, 0x8C, 0x83, 0x27, 0xEB, 0x63, 0x45, 0x37,
0xFA, 0xD0, 0x8D, 0xFF, 0xFF, 0xFF, 0xFF, 0x4B, 0xFF, 0xC8, 0xA0, 0x60, 0x18, 0x88, 0x14, 0x04,
0xCA, 0x7A, 0x9C, 0x89, 0x51, 0x50, 0x89, 0xB3, 0x7F, 0xFF, 0xFD, 0x57, 0x17, 0xAD, 0x11, 0xC1,
0x04, 0x70, 0x49, 0x23, 0x82, 0x01, 0xF5, 0xAD, 0xFF, 0xF3, 0x28, 0xC4, 0x0A, 0x0E, 0x01, 0xFA,
0xE6, 0x5F, 0x4D, 0x28, 0x00, 0xEC, 0x31, 0x05, 0xA0, 0x2E, 0x92, 0xEF, 0x57, 0xD0, 0x2E, 0x00,
0xB4, 0x18, 0x4A, 0x6C, 0xEF, 0xFA, 0x01, 0x81, 0x3F, 0xF3, 0x2F, 0xFF, 0x2B, 0x7F, 0xF7, 0x23,
0x7F, 0xC5, 0xDD, 0x3F, 0xEA, 0x53, 0xFF, 0xAA, 0xB1, 0xFF, 0xE6, 0x30, 0x9B, 0x7E, 0xBF, 0xFF,
0xFF, 0xD0, 0x1A, 0xDD, 0x3E, 0xF5, 0xFF, 0x2C, 0x20, 0xBA, 0x54, 0xB4, 0xBF, 0x41, 0xB3, 0x45,
0xFF, 0xF3, 0x28, 0xC4, 0x0D, 0x10, 0x09, 0xFE, 0xB4, 0x01, 0x99, 0x68, 0x00, 0x1E, 0xE8, 0xCF,
0xF9, 0x7C, 0x34, 0x00, 0x0D, 0x96, 0xA4, 0x79, 0x2C, 0x6C, 0xCB, 0x5B, 0x7E, 0x6A, 0xEC, 0x97,
0xFF, 0xD6, 0x95, 0xFF, 0xFC, 0xE9, 0xE3, 0xCA, 0x27, 0x8E, 0x54, 0x56, 0xDF, 0xFE, 0xCE, 0x69,
0xCC, 0x51, 0xFE, 0x97, 0xFF, 0x4C, 0xCD, 0x35, 0xA6, 0x67, 0x15, 0x44, 0xEA, 0xD7, 0xFF, 0xF4,
0xAA, 0xFF, 0x9C, 0x61, 0xB5, 0x71, 0xA1, 0x5C, 0xFF, 0xF3, 0x28, 0xC4, 0x07, 0x0E, 0x52, 0x6A,
0xD0, 0x01, 0x85, 0x10, 0x00, 0xF8, 0x26, 0x37, 0xFB, 0xA9, 0x3F, 0xF9, 0x7F, 0xFF, 0xD3, 0x9C,
0x9F, 0xFD, 0x7B, 0xCE, 0xDF, 0xFD, 0xB2, 0x48, 0x8C, 0xA5, 0x44, 0x42, 0x2B, 0x8C, 0x4F, 0xFF,
0x41, 0x1C, 0xA7, 0xBC, 0xF4, 0x38, 0x60, 0x85, 0x60, 0xA4, 0x19, 0xC5, 0x7F, 0xC6, 0x38, 0x72,
0x22, 0x09, 0x73, 0xC8, 0x42, 0x0C, 0x01, 0x6A, 0xC9, 0xF8, 0xBC, 0xB9, 0x4E, 0x20, 0x8B, 0x50,
0xFF, 0xF3, 0x28, 0xC4, 0x08, 0x0B, 0xA1, 0x56, 0xBC, 0x01, 0xC1, 0x18, 0x00, 0xA7, 0x64, 0xCA,
0x8F, 0x6E, 0x6F, 0x7F, 0xBF, 0x08, 0x9C, 0xB3, 0x11, 0xA7, 0x5C, 0x89, 0x3D, 0x1E, 0x74, 0x2F,
0x4D, 0x94, 0x5A, 0x6E, 0x23, 0x02, 0xBF, 0xAA, 0x29, 0xF6, 0xC3, 0xB2, 0x52, 0xAE, 0xE2, 0x26,
0xB2, 0x90, 0x8E, 0xBA, 0xF6, 0x4C, 0xA8, 0x42, 0x81, 0x43, 0x1E, 0xA4, 0xBE, 0x80, 0x40, 0x00,
0x78, 0x57, 0x24, 0x67, 0x05, 0x01, 0x40, 0x41, 0xFF, 0xF3, 0x28, 0xC4, 0x14, 0x0C, 0xA8, 0xEE,
0xC4, 0x00, 0x6A, 0x46, 0x70, 0xCB, 0x8A, 0xE4, 0x09, 0x8A, 0xD1, 0xA4, 0xC6, 0x7E, 0x41, 0xC5,
0xA1, 0xBB, 0x8B, 0xC8, 0x3E, 0x66, 0xEF, 0x2C, 0x80, 0x00, 0x08, 0x0F, 0x02, 0xAF, 0x23, 0xFF,
0xFF, 0xFF, 0xFF, 0x45, 0xF5, 0x85, 0x78, 0x13, 0x60, 0x9D, 0x14, 0xA7, 0x44, 0xFC, 0x68, 0x1F,
0xAD, 0x6F, 0x84, 0xD0, 0xB5, 0xAE, 0xAC, 0xE0, 0x36, 0x30, 0x12, 0x8F, 0x5D, 0x64, 0xEC, 0xF0,
0xFF, 0xF3, 0x28, 0xC4, 0x1C, 0x0B, 0xB0, 0xE6, 0xD0, 0x00, 0x6B, 0x06, 0x71, 0xFA, 0x80, 0x89,
0x14, 0x83, 0xA8, 0xC9, 0x4C, 0x4D, 0x24, 0x70, 0x25, 0x61, 0x60, 0xDD, 0xC4, 0xB7, 0xCD, 0xF5,
0x0E, 0x5B, 0x6D, 0xB6, 0xDA, 0x00, 0xB4, 0x01, 0xF0, 0xAD, 0x0B, 0x9A, 0x4D, 0xDA, 0xC3, 0x04,
0xEB, 0x85, 0x37, 0xC8, 0x85, 0x39, 0xDA, 0x24, 0x20, 0xDA, 0x04, 0x88, 0xDC, 0xF2, 0x52, 0x70,
0xC1, 0x5B, 0x59, 0x45, 0x95, 0xA4, 0xCE, 0xBA, 0xFF, 0xF3, 0x28, 0xC4, 0x28, 0x0D, 0x38, 0xBF,
0x0A, 0x5E, 0x6B, 0xDA, 0x4E, 0x8B, 0xC4, 0x65, 0x89, 0x86, 0xAD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
0x1A, 0x24, 0xD7, 0xE5, 0xB8, 0x09, 0x17, 0xCC, 0xED, 0xA8, 0xD8, 0x85, 0xB8, 0x7D, 0x9D, 0x24,
0x70, 0xB6, 0xD0, 0x00, 0xF6, 0x41, 0x2A, 0xDA, 0x2D, 0xC5, 0xA9, 0x49, 0x0E, 0x78, 0x2F, 0x60,
0xD2, 0x26, 0x65, 0x7B, 0x50, 0x90, 0x99, 0xD5, 0x3C, 0xA8, 0x88, 0x28, 0x1D, 0xFF, 0xFF, 0xFF,
0xFF, 0xF3, 0x28, 0xC4, 0x2E, 0x0C, 0x78, 0x82, 0xA0, 0x00, 0xCE, 0x1E, 0x48, 0xFF, 0xFE, 0xAC,
0x4B, 0x00, 0x40, 0x02, 0x72, 0x40, 0x04, 0x90, 0x01, 0xEE, 0xC1, 0x7E, 0x80, 0xF5, 0x07, 0xC8,
0x5D, 0x01, 0x8A, 0x1A, 0xBA, 0x3A, 0x43, 0x56, 0x8E, 0xD6, 0xEA, 0x48, 0x9E, 0xE9, 0x20, 0x10,
0x10, 0xAE, 0x65, 0x7F, 0x49, 0xC1, 0xA0, 0x03, 0x7F, 0xFF, 0xFF, 0xFF, 0xA7, 0xFE, 0xE1, 0x10,
0xF3, 0xCA, 0xBD, 0x6A, 0x1D, 0xB7, 0xDB, 0x4D, 0xFF, 0xF3, 0x28, 0xC4, 0x37, 0x0C, 0x98, 0xB6,
0xBA, 0x5F, 0x52, 0x10, 0x02, 0x8F, 0xF3, 0x76, 0xB4, 0x63, 0x74, 0xEA, 0xF1, 0x30, 0x34, 0xC3,
0x03, 0xF4, 0x64, 0x40, 0xA1, 0x0B, 0x37, 0xFF, 0x80, 0x86, 0x95, 0xF4, 0x68, 0xA4, 0xCC, 0x1C,
0x7F, 0xFF, 0xF9, 0xA6, 0x18, 0xEA, 0x26, 0x1C, 0x70, 0xBD, 0xC5, 0xB2, 0x7B, 0x35, 0xCE, 0x7F,
0x97, 0x5C, 0x20, 0x66, 0xC0, 0x25, 0x64, 0x81, 0xB6, 0x62, 0xE1, 0x86, 0x8D, 0x2C, 0x2F, 0xFF,
0xFF, 0xF3, 0x28, 0xC4, 0x3F, 0x17, 0xD9, 0x12, 0xAC, 0xCB, 0x8F, 0xC0, 0x00, 0xFF, 0xFB, 0xB6,
0xFD, 0xE5, 0x95, 0x25, 0x88, 0x0A, 0x44, 0x26, 0x2D, 0xE2, 0x72, 0x7B, 0x55, 0xF7, 0x7F, 0xFF,
0x13, 0xC3, 0x07, 0xF5, 0xCB, 0x7F, 0xF7, 0x17, 0x34, 0x8D, 0x4B, 0x4B, 0x32, 0xB5, 0x71, 0x50,
0x87, 0xFF, 0xFF, 0x35, 0x4D, 0x1A, 0x95, 0x36, 0x23, 0xE9, 0x66, 0x6C, 0xD5, 0xA5, 0xAB, 0x66,
0x81, 0xF5, 0x6B, 0xA4, 0x34, 0x22, 0x85, 0xDB, 0xFF, 0xF3, 0x28, 0xC4, 0x1A, 0x0D, 0x40, 0xBA,
0xC8, 0xCB, 0xD8, 0x78, 0x00, 0x16, 0x7B, 0xFF, 0xBD, 0x88, 0x1A, 0xB3, 0xCF, 0xDB, 0xD2, 0xDB,
0x8F, 0x04, 0x47, 0x07, 0xE6, 0x20, 0xE1, 0x0B, 0x09, 0x27, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x18,
0xFD, 0x42, 0x13, 0x24, 0xA6, 0x23, 0x59, 0xC3, 0xBF, 0xDC, 0x75, 0x56, 0x70, 0x2E, 0xC3, 0xEC,
0x52, 0x6A, 0x96, 0xCF, 0x70, 0xC7, 0x5D, 0x94, 0xB7, 0x00, 0x14, 0xDC, 0xFB, 0xFC, 0xD6, 0x17,
0xFF, 0xF3, 0x28, 0xC4, 0x20, 0x0D, 0x08, 0xB6, 0xC0, 0x00, 0x3E, 0x30, 0x4C, 0x6E, 0xC1, 0x4D,
0xB2, 0x1A, 0xAF, 0x79, 0x69, 0x29, 0xE1, 0x10, 0x3B, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xB9, 0x99,
0x85, 0xAA, 0x0C, 0x32, 0xC7, 0xE8, 0x13, 0xCE, 0x80, 0x09, 0xC0, 0x12, 0xC1, 0x3A, 0x92, 0x2A,
0x5D, 0xD0, 0x27, 0x83, 0xEA, 0x0B, 0xBA, 0x9D, 0x91, 0xB2, 0x68, 0x16, 0xC3, 0x56, 0x83, 0xF4,
0xEA, 0xBA, 0x96, 0x68, 0x40, 0x8C, 0xD6, 0xE6, 0xFF, 0xF3, 0x28, 0xC4, 0x26, 0x0D, 0x00, 0xDE,
0xB8, 0xCA, 0x9C, 0xA0, 0x70, 0x28, 0x3F, 0xAC, 0xBC, 0x7F, 0xFF, 0xF9, 0x9F, 0xFF, 0xFF, 0xF6,
0xEC, 0x46, 0x25, 0x01, 0x0B, 0x52, 0x4A, 0xD1, 0x68, 0xB6, 0x81, 0xF9, 0xC5, 0xDA, 0x20, 0x00,
0xD0, 0x27, 0x8A, 0x26, 0x49, 0xF9, 0xC1, 0xC4, 0x0A, 0xF1, 0xEF, 0xEA, 0x3E, 0x10, 0x06, 0x49,
0xB2, 0xF1, 0x15, 0xCD, 0x75, 0xBA, 0x09, 0x01, 0x9D, 0xFF, 0x11, 0x3B, 0xAE, 0xEF, 0xFF, 0xFF,
0xFF, 0xF3, 0x28, 0xC4, 0x2D, 0x0D, 0x10, 0xE6, 0xE2, 0x5E, 0x3B, 0x4A, 0x72, 0x3C, 0x9F, 0x4B,
0xF2, 0xDF, 0xFF, 0xE4, 0xAA, 0x00, 0x81, 0x51, 0xAF, 0x6D, 0xFF, 0xFF, 0x81, 0xFD, 0xF0, 0x90,
0x04, 0x2B, 0x98, 0xDD, 0x42, 0x97, 0x98, 0xCE, 0x8E, 0x02, 0x8E, 0x53, 0x7E, 0xEA, 0x67, 0xE8,
0x6C, 0xCA, 0x02, 0x24, 0xAE, 0xEC, 0xF1, 0x2B, 0xBC, 0x42, 0xEF, 0x23, 0xFF, 0xFD, 0x7E, 0xC2,
0x27, 0x59, 0xFF, 0xEB, 0x3B, 0x3C, 0xD2, 0x54, 0xFF, 0xF3, 0x28, 0xC4, 0x33, 0x0C, 0xC8, 0xEE,
0xDA, 0x5E, 0x28, 0x84, 0x72, 0xD5, 0x92, 0xA9, 0x26, 0x1E, 0x01, 0xDA, 0x81, 0x71, 0x81, 0x05,
0x10, 0x24, 0x70, 0x85, 0xD7, 0x44, 0x44, 0x9A, 0x57, 0x20, 0x92, 0x77, 0x1D, 0xB5, 0x5A, 0x86,
0x8B, 0x76, 0x52, 0x53, 0x04, 0xCC, 0x55, 0x15, 0xDF, 0xE9, 0x69, 0x45, 0xB2, 0x4B, 0x15, 0x4C,
0x41, 0x4D, 0x45, 0x33, 0x2E, 0x39, 0x39, 0x2E, 0x35, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0xFF, 0xF3, 0x28, 0xC4, 0x3A, 0x0A, 0x40, 0x62, 0x0C, 0x00, 0x4E, 0x18, 0x29, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xFF, 0xF3, 0x28, 0xC4, 0x4C, 0x00, 0x00, 0x03,
0x48, 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0xFF, 0xF3, 0x28, 0xC4, 0x87, 0x00, 0x00, 0x03, 0x48, 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xFF, 0xF3, 0x28, 0xC4, 0xC2, 0x00, 0x00, 0x03,
0x48, 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
};
|
the_stack_data/11971.c | /******************************************************************************
1. Informe as duas notas de um aluno (P1 e P2) e a quantidade de faltas no
semestre, calcule a media das notas e o percentual de faltas sobre 20 aulas.
Caso o percentual de faltas for maior que 30% o aluno esta automaticamente
reprovado, caso ao contrario verifique se a media e maior igual a 6, se
afirmativo o aluno esta aprovado, senão informe uma nota P3 para recalcular a
media, se a nova media for maior igual a 6, escreva aprovado no exame, caso
negativo exiba reprovado por nota.
Aluno: Jonathan Baliellas
*******************************************************************************/
#include <stdio.h>
int main()
{
//DECLARAÇÃO DE VARIÁVEIS
float p1, p2, p3, media;
int faltas;
//INÍCIO
//Entrada
refazP1:
printf("Informe a nota da P1: ");
scanf("%f", &p1);
if(p1 > 10 || p1 < 0){
printf("Você informou uma nota inválida!\n");
goto refazP1;
}
refazP2:
printf("Informe a nota da P2: ");
scanf("%f", &p2);
if(p2 > 10 || p2 < 0){
printf("Você informou uma nota inválida!\n");
goto refazP2;
}
refazFaltas:
printf("Informe o número de faltas: ");
scanf("%i", &faltas);
if(faltas > 20 || faltas < 0){
printf("Você informou um número inválido!\n");
goto refazFaltas;
}
//Processamento/Saída
if(faltas > 20 * 0.3){
printf("O aluno está reprovado por falta.");
} else {
media = (p1 + p2) / 2;
if (media >= 6){
goto aprovado;
} else {
printf("A média do aluno é %.1f. O aluno deverá realizar a P3.\n", media);
refazP3:
printf("Informe a nota da P3: ");
scanf("%f", &p3);
if(p3 > 10 || p3 < 0){
printf("Você informou uma nota inválida!\n");
goto refazP3;
}
media = (p1 + p2 + p3) / 3;
if (media >= 6){
aprovado:
printf("APROVADO!\nA média do aluno é %.1f.", media);
} else {
printf("REPROVADO!\nA média do aluno é %.1f.\n", media);
printf("O aluno não atingiu a nota mínima para aprovação.");
}
}
}
} |
the_stack_data/62638086.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 26:Reciprocal_cycles.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adelille <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/25 16:13:24 by adelille #+# #+# */
/* Updated: 2021/10/25 17:37:05 by adelille ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
static int ft_rc_len(int d)
{
int seen[1000] = { -1 };
int n;
int index;
n = 1;
index = 0;
while (seen[n] == 0 && n != 0)
{
seen[n] = index;
n *= 10;
n %= d;
index++;
}
return (index - seen[n] + 1);
}
int main(void)
{
int d;
int tmp;
int big;
int index;
d = 2;
big = -1;
while (d < 1000)
{
tmp = ft_rc_len(d);
if (tmp > big)
{
big = tmp;
index = d;
}
d++;
}
printf("Longest reciprocal cycles is 1/%d, for length of %d\n", d, big);
return (0);
}
|
the_stack_data/79333.c | /* Only the inner loop can be parallelized
*/
#include <omp.h>
void foo()
{
int n = 100;
int m = 100;
double b[n][m];
int i;
int j;
for (i = 0; i <= n - 1; i += 1) {
#pragma omp parallel for private (j)
for (j = 0; j <= m - 1; j += 1) {
b[i][j] = b[i - 1][j - 1];
}
}
}
|
the_stack_data/6572.c | // Mocking function computeS() in
// "libCEED/examples/solids/qfunctions/finite-strain-neo-hookean-initial-1.h"
// with Enzyme
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define VECSIZE 6
int __enzyme_augmentsize(void *, ...);
void __enzyme_augmentfwd(void *, ...);
void __enzyme_reverse(void *, ...);
int enzyme_dup;
int enzyme_tape;
int enzyme_const;
int enzyme_allocated;
void computeS(double *Swork, double *E2work, double lambda, double mu);
void grad_S(double *S, double *dS, double *E, double *dE, double lambda, double mu) {
int size = __enzyme_augmentsize((void *)computeS, enzyme_dup, enzyme_dup, enzyme_const, enzyme_const); // We need to add Const as well
void *data = malloc(size);
__enzyme_augmentfwd((void *)computeS, enzyme_allocated, size, enzyme_tape, data, S, dS, E, dE, lambda, mu);
__enzyme_reverse((void *)computeS, enzyme_allocated, size, enzyme_tape, data, S, dS, E, dE, lambda, mu);
free(data);
}
double log1p_series_shifted(double x) {
double left = sqrt(2.)/2 - 1;
double right = sqrt(2.) - 1;
double sum = 0;
if (x < left) {
sum -= log(2.) / 2;
x = 1 + 2 * x;
} else if (right < x) {
sum += log(2.) / 2;
x = (x - 1) / 2;
}
double y = x / (2. + x);
double y2 = y*y;
sum += y;
y *= y2;
sum += y / 3;
y *= y2;
sum += y / 5;
y *= y2;
sum += y / 7;
return 2 * sum;
};
double computeDetCM1(double *E2work) {
return E2work[0]*(E2work[1]*E2work[2]-E2work[3]*E2work[3]) +
E2work[5]*(E2work[4]*E2work[3]-E2work[5]*E2work[2]) +
E2work[4]*(E2work[5]*E2work[3]-E2work[4]*E2work[1]) +
E2work[0] + E2work[1] + E2work[2] +
E2work[0]*E2work[1] + E2work[0]*E2work[2] +
E2work[1]*E2work[2] - E2work[5]*E2work[5] -
E2work[4]*E2work[4] - E2work[3]*E2work[3];
};
int computeMatinvSym(double A[3][3], double detA, double *Ainv) {
// Compute A^(-1) : A-Inverse
double B[VECSIZE] = {A[1][1]*A[2][2] - A[1][2]*A[2][1],
A[0][0]*A[2][2] - A[0][2]*A[2][0],
A[0][0]*A[1][1] - A[0][1]*A[1][0],
A[0][2]*A[1][0] - A[0][0]*A[1][2],
A[0][1]*A[1][2] - A[0][2]*A[1][1],
A[0][2]*A[2][1] - A[0][1]*A[2][2]
};
for ( int m = 0; m < VECSIZE; m++) Ainv[m] = B[m] / (detA);
return 0;
};
void computeS(double *Swork, double *E2work, double lambda, double mu) {
double E2[3][3] = {{E2work[0], E2work[5], E2work[4]},
{E2work[5], E2work[1], E2work[3]},
{E2work[4], E2work[3], E2work[2]}
};
// C : right Cauchy-Green tensor
double C[3][3] = {{1 + E2[0][0], E2[0][1], E2[0][2]},
{E2[0][1], 1 + E2[1][1], E2[1][2]},
{E2[0][2], E2[1][2], 1 + E2[2][2]}
};
// Compute C^(-1) : C-Inverse
double Cinvwork[VECSIZE];
double detCm1 = computeDetCM1(E2work);
computeMatinvSym(C, detCm1+1, Cinvwork);
double C_inv[3][3] = {{Cinvwork[0], Cinvwork[5], Cinvwork[4]},
{Cinvwork[5], Cinvwork[1], Cinvwork[3]},
{Cinvwork[4], Cinvwork[3], Cinvwork[2]}
};
// Compute the Second Piola-Kirchhoff (S)
int indj[VECSIZE] = {0, 1, 2, 1, 0, 0}, indk[VECSIZE] = {0, 1, 2, 2, 2, 1};
double logJ = log1p_series_shifted(detCm1) / 2.;
for ( int m = 0; m < VECSIZE; m++) {
Swork[m] = lambda*logJ*Cinvwork[m];
for ( int n = 0; n < 3; n++)
Swork[m] += mu*C_inv[indj[m]][n]*E2[n][indk[m]];
}
};
int main() {
double E = .3;
double nu = .3;
double TwoMu = E / (1 + nu);
double mu = TwoMu / 2;
double Kbulk = E / (3*(1 - 2*nu));
double lambda = (3*Kbulk - TwoMu) / 3;
double E2work[VECSIZE] = {0., 0., 0., 0., 0., 0.};
E2work[0] = 0.5895232828911128;
E2work[1] = 0.2362491738162759;
E2work[2] = 0.9793730522395296;
E2work[3] = 0.2190993957421843;
E2work[4] = 0.0126503210747925;
E2work[5] = 0.6570956167695403;
double J[VECSIZE][VECSIZE];
for (int i=0; i<VECSIZE; i++) for (int j=0; j<6; j++) J[i][j] = 0.;
double Swork[VECSIZE];
for (int i=0; i<VECSIZE; i++) {
double dSwork[VECSIZE] = {0., 0., 0., 0., 0., 0.}; dSwork[i] = 1.;
grad_S(Swork, dSwork, E2work, J[i], lambda, mu);
}
double deltaEwork[VECSIZE] = {0., 0., 0., 0., 0., 0.};
deltaEwork[0] = 0.9681576729097205;
deltaEwork[1] = 0.7994338113484318;
deltaEwork[2] = 0.2755183472001872;
deltaEwork[3] = 0.6500440500146469;
deltaEwork[4] = 0.0593948875992271;
deltaEwork[5] = 0.6002528007029311;
double deltaSwork[VECSIZE];
for (int i=0; i<VECSIZE; i++) {
deltaSwork[i] = 0;
for (int j=0; j<VECSIZE; j++)
deltaSwork[i] += J[i][j] * 2. * deltaEwork[j]; // we need deltaE2work = 2 .* deltaEwork
}
double deltaS[3][3] = {{deltaSwork[0], deltaSwork[5], deltaSwork[4]},
{deltaSwork[5], deltaSwork[1], deltaSwork[3]},
{deltaSwork[4], deltaSwork[3], deltaSwork[2]}
};
printf("\n\nSwork = ");
for (int i=0; i<VECSIZE; i++) printf("\t %.6lf", Swork[i]);
printf("\n\ndeltaSwork = ");
for (int i=0; i<VECSIZE; i++) printf("\t %.6lf", deltaSwork[i]);
printf("\n\ndeltaS =\n\n");
for (int i=0; i<3; i++) printf("\t\t%.12lf", deltaS[0][i]);
printf("\n\n");
for (int i=0; i<3; i++) printf("\t\t%.12lf", deltaS[1][i]);
printf("\n\n");
for (int i=0; i<3; i++) printf("\t\t%.12lf", deltaS[2][i]);
printf("\n\n");
return 0;
}
/*
Output:
Swork = 0.098041 0.092640 0.104300 0.002458 -0.000928 0.009383
deltaSwork = 0.169671 0.219554 0.099307 -0.010067 0.003474 -0.085117
deltaS =
0.169670848078 -0.085117173016 0.003473687038
-0.085117173016 0.219553855108 -0.010067073475
0.003473687038 -0.010067073475 0.099307342055
*/
|
the_stack_data/3262062.c | // Test without serialization:
// RUN: %clang_cc1 -ast-dump %s | FileCheck %s
//
// Test with serialization:
// RUN: %clang_cc1 -emit-pch -o %t %s
// RUN: %clang_cc1 -x c -include-pch %t -ast-dump-all /dev/null \
// RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
// RUN: | FileCheck %s
void foo1(void*);
void foo2(void* const);
void bar() {
// CHECK: FunctionDecl {{.*}} <line:{{.*}}, line:{{.*}}> line:{{.*}} bar 'void ()'
foo1(0);
// CHECK: ImplicitCastExpr {{.*}} <col:{{.*}}> 'void *' <NullToPointer>
foo2(0);
// CHECK: ImplicitCastExpr {{.*}} <col:{{.*}}> 'void *' <NullToPointer>
}
|
the_stack_data/617843.c | /**
******************************************************************************
* @file stm32f1xx_ll_usart.c
* @author MCD Application Team
* @version V1.1.1
* @date 12-May-2017
* @brief USART LL module driver.
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
#if defined(USE_FULL_LL_DRIVER)
/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_ll_usart.h"
#include "stm32f1xx_ll_rcc.h"
#include "stm32f1xx_ll_bus.h"
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif
/** @addtogroup STM32F1xx_LL_Driver
* @{
*/
#if defined (USART1) || defined (USART2) || defined (USART3) || defined (UART4) || defined (UART5)
/** @addtogroup USART_LL
* @{
*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/** @addtogroup USART_LL_Private_Constants
* @{
*/
/**
* @}
*/
/* Private macros ------------------------------------------------------------*/
/** @addtogroup USART_LL_Private_Macros
* @{
*/
/* __BAUDRATE__ The maximum Baud Rate is derived from the maximum clock available
* divided by the smallest oversampling used on the USART (i.e. 8) */
#define IS_LL_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 10000000U)
#define IS_LL_USART_DIRECTION(__VALUE__) (((__VALUE__) == LL_USART_DIRECTION_NONE) \
|| ((__VALUE__) == LL_USART_DIRECTION_RX) \
|| ((__VALUE__) == LL_USART_DIRECTION_TX) \
|| ((__VALUE__) == LL_USART_DIRECTION_TX_RX))
#define IS_LL_USART_PARITY(__VALUE__) (((__VALUE__) == LL_USART_PARITY_NONE) \
|| ((__VALUE__) == LL_USART_PARITY_EVEN) \
|| ((__VALUE__) == LL_USART_PARITY_ODD))
#define IS_LL_USART_DATAWIDTH(__VALUE__) (((__VALUE__) == LL_USART_DATAWIDTH_8B) \
|| ((__VALUE__) == LL_USART_DATAWIDTH_9B))
#define IS_LL_USART_OVERSAMPLING(__VALUE__) (((__VALUE__) == LL_USART_OVERSAMPLING_16) \
|| ((__VALUE__) == LL_USART_OVERSAMPLING_8))
#define IS_LL_USART_LASTBITCLKOUTPUT(__VALUE__) (((__VALUE__) == LL_USART_LASTCLKPULSE_NO_OUTPUT) \
|| ((__VALUE__) == LL_USART_LASTCLKPULSE_OUTPUT))
#define IS_LL_USART_CLOCKPHASE(__VALUE__) (((__VALUE__) == LL_USART_PHASE_1EDGE) \
|| ((__VALUE__) == LL_USART_PHASE_2EDGE))
#define IS_LL_USART_CLOCKPOLARITY(__VALUE__) (((__VALUE__) == LL_USART_POLARITY_LOW) \
|| ((__VALUE__) == LL_USART_POLARITY_HIGH))
#define IS_LL_USART_CLOCKOUTPUT(__VALUE__) (((__VALUE__) == LL_USART_CLOCK_DISABLE) \
|| ((__VALUE__) == LL_USART_CLOCK_ENABLE))
#define IS_LL_USART_STOPBITS(__VALUE__) (((__VALUE__) == LL_USART_STOPBITS_0_5) \
|| ((__VALUE__) == LL_USART_STOPBITS_1) \
|| ((__VALUE__) == LL_USART_STOPBITS_1_5) \
|| ((__VALUE__) == LL_USART_STOPBITS_2))
#define IS_LL_USART_HWCONTROL(__VALUE__) (((__VALUE__) == LL_USART_HWCONTROL_NONE) \
|| ((__VALUE__) == LL_USART_HWCONTROL_RTS) \
|| ((__VALUE__) == LL_USART_HWCONTROL_CTS) \
|| ((__VALUE__) == LL_USART_HWCONTROL_RTS_CTS))
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup USART_LL_Exported_Functions
* @{
*/
/** @addtogroup USART_LL_EF_Init
* @{
*/
/**
* @brief De-initialize USART registers (Registers restored to their default values).
* @param USARTx USART Instance
* @retval An ErrorStatus enumeration value:
* - SUCCESS: USART registers are de-initialized
* - ERROR: USART registers are not de-initialized
*/
ErrorStatus LL_USART_DeInit(USART_TypeDef *USARTx)
{
ErrorStatus status = SUCCESS;
/* Check the parameters */
assert_param(IS_UART_INSTANCE(USARTx));
if (USARTx == USART1)
{
/* Force reset of USART clock */
LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_USART1);
/* Release reset of USART clock */
LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_USART1);
}
else if (USARTx == USART2)
{
/* Force reset of USART clock */
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_USART2);
/* Release reset of USART clock */
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_USART2);
}
#if defined(USART3)
else if (USARTx == USART3)
{
/* Force reset of USART clock */
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_USART3);
/* Release reset of USART clock */
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_USART3);
}
#endif /* USART3 */
#if defined(UART4)
else if (USARTx == UART4)
{
/* Force reset of UART clock */
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UART4);
/* Release reset of UART clock */
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UART4);
}
#endif /* UART4 */
#if defined(UART5)
else if (USARTx == UART5)
{
/* Force reset of UART clock */
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UART5);
/* Release reset of UART clock */
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UART5);
}
#endif /* UART5 */
else
{
status = ERROR;
}
return (status);
}
/**
* @brief Initialize USART registers according to the specified
* parameters in USART_InitStruct.
* @note As some bits in USART configuration registers can only be written when the USART is disabled (USART_CR1_UE bit =0),
* USART IP should be in disabled state prior calling this function. Otherwise, ERROR result will be returned.
* @note Baud rate value stored in USART_InitStruct BaudRate field, should be valid (different from 0).
* @param USARTx USART Instance
* @param USART_InitStruct: pointer to a LL_USART_InitTypeDef structure
* that contains the configuration information for the specified USART peripheral.
* @retval An ErrorStatus enumeration value:
* - SUCCESS: USART registers are initialized according to USART_InitStruct content
* - ERROR: Problem occurred during USART Registers initialization
*/
ErrorStatus LL_USART_Init(USART_TypeDef *USARTx, LL_USART_InitTypeDef *USART_InitStruct)
{
ErrorStatus status = ERROR;
uint32_t periphclk = LL_RCC_PERIPH_FREQUENCY_NO;
LL_RCC_ClocksTypeDef rcc_clocks;
/* Check the parameters */
assert_param(IS_UART_INSTANCE(USARTx));
assert_param(IS_LL_USART_BAUDRATE(USART_InitStruct->BaudRate));
assert_param(IS_LL_USART_DATAWIDTH(USART_InitStruct->DataWidth));
assert_param(IS_LL_USART_STOPBITS(USART_InitStruct->StopBits));
assert_param(IS_LL_USART_PARITY(USART_InitStruct->Parity));
assert_param(IS_LL_USART_DIRECTION(USART_InitStruct->TransferDirection));
assert_param(IS_LL_USART_HWCONTROL(USART_InitStruct->HardwareFlowControl));
#if defined(USART_CR1_OVER8)
assert_param(IS_LL_USART_OVERSAMPLING(USART_InitStruct->OverSampling));
#endif /* USART_OverSampling_Feature */
/* USART needs to be in disabled state, in order to be able to configure some bits in
CRx registers */
if (LL_USART_IsEnabled(USARTx) == 0U)
{
/*---------------------------- USART CR1 Configuration -----------------------
* Configure USARTx CR1 (USART Word Length, Parity, Mode and Oversampling bits) with parameters:
* - DataWidth: USART_CR1_M bits according to USART_InitStruct->DataWidth value
* - Parity: USART_CR1_PCE, USART_CR1_PS bits according to USART_InitStruct->Parity value
* - TransferDirection: USART_CR1_TE, USART_CR1_RE bits according to USART_InitStruct->TransferDirection value
* - Oversampling: USART_CR1_OVER8 bit according to USART_InitStruct->OverSampling value.
*/
#if defined(USART_CR1_OVER8)
MODIFY_REG(USARTx->CR1,
(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS |
USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8),
(USART_InitStruct->DataWidth | USART_InitStruct->Parity |
USART_InitStruct->TransferDirection | USART_InitStruct->OverSampling));
#else
MODIFY_REG(USARTx->CR1,
(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS |
USART_CR1_TE | USART_CR1_RE),
(USART_InitStruct->DataWidth | USART_InitStruct->Parity |
USART_InitStruct->TransferDirection));
#endif /* USART_OverSampling_Feature */
/*---------------------------- USART CR2 Configuration -----------------------
* Configure USARTx CR2 (Stop bits) with parameters:
* - Stop Bits: USART_CR2_STOP bits according to USART_InitStruct->StopBits value.
* - CLKEN, CPOL, CPHA and LBCL bits are to be configured using LL_USART_ClockInit().
*/
LL_USART_SetStopBitsLength(USARTx, USART_InitStruct->StopBits);
/*---------------------------- USART CR3 Configuration -----------------------
* Configure USARTx CR3 (Hardware Flow Control) with parameters:
* - HardwareFlowControl: USART_CR3_RTSE, USART_CR3_CTSE bits according to USART_InitStruct->HardwareFlowControl value.
*/
LL_USART_SetHWFlowCtrl(USARTx, USART_InitStruct->HardwareFlowControl);
/*---------------------------- USART BRR Configuration -----------------------
* Retrieve Clock frequency used for USART Peripheral
*/
LL_RCC_GetSystemClocksFreq(&rcc_clocks);
if (USARTx == USART1)
{
periphclk = rcc_clocks.PCLK2_Frequency;
}
else if (USARTx == USART2)
{
periphclk = rcc_clocks.PCLK1_Frequency;
}
#if defined(USART3)
else if (USARTx == USART3)
{
periphclk = rcc_clocks.PCLK1_Frequency;
}
#endif /* USART3 */
#if defined(UART4)
else if (USARTx == UART4)
{
periphclk = rcc_clocks.PCLK1_Frequency;
}
#endif /* UART4 */
#if defined(UART5)
else if (USARTx == UART5)
{
periphclk = rcc_clocks.PCLK1_Frequency;
}
#endif /* UART5 */
else
{
/* Nothing to do, as error code is already assigned to ERROR value */
}
/* Configure the USART Baud Rate :
- valid baud rate value (different from 0) is required
- Peripheral clock as returned by RCC service, should be valid (different from 0).
*/
if ((periphclk != LL_RCC_PERIPH_FREQUENCY_NO)
&& (USART_InitStruct->BaudRate != 0U))
{
status = SUCCESS;
#if defined(USART_CR1_OVER8)
LL_USART_SetBaudRate(USARTx,
periphclk,
USART_InitStruct->OverSampling,
USART_InitStruct->BaudRate);
#else
LL_USART_SetBaudRate(USARTx,
periphclk,
USART_InitStruct->BaudRate);
#endif /* USART_OverSampling_Feature */
}
}
/* Endif (=> USART not in Disabled state => return ERROR) */
return (status);
}
/**
* @brief Set each @ref LL_USART_InitTypeDef field to default value.
* @param USART_InitStruct: pointer to a @ref LL_USART_InitTypeDef structure
* whose fields will be set to default values.
* @retval None
*/
void LL_USART_StructInit(LL_USART_InitTypeDef *USART_InitStruct)
{
/* Set USART_InitStruct fields to default values */
USART_InitStruct->BaudRate = 9600U;
USART_InitStruct->DataWidth = LL_USART_DATAWIDTH_8B;
USART_InitStruct->StopBits = LL_USART_STOPBITS_1;
USART_InitStruct->Parity = LL_USART_PARITY_NONE ;
USART_InitStruct->TransferDirection = LL_USART_DIRECTION_TX_RX;
USART_InitStruct->HardwareFlowControl = LL_USART_HWCONTROL_NONE;
#if defined(USART_CR1_OVER8)
USART_InitStruct->OverSampling = LL_USART_OVERSAMPLING_16;
#endif /* USART_OverSampling_Feature */
}
/**
* @brief Initialize USART Clock related settings according to the
* specified parameters in the USART_ClockInitStruct.
* @note As some bits in USART configuration registers can only be written when the USART is disabled (USART_CR1_UE bit =0),
* USART IP should be in disabled state prior calling this function. Otherwise, ERROR result will be returned.
* @param USARTx USART Instance
* @param USART_ClockInitStruct: pointer to a @ref LL_USART_ClockInitTypeDef structure
* that contains the Clock configuration information for the specified USART peripheral.
* @retval An ErrorStatus enumeration value:
* - SUCCESS: USART registers related to Clock settings are initialized according to USART_ClockInitStruct content
* - ERROR: Problem occurred during USART Registers initialization
*/
ErrorStatus LL_USART_ClockInit(USART_TypeDef *USARTx, LL_USART_ClockInitTypeDef *USART_ClockInitStruct)
{
ErrorStatus status = SUCCESS;
/* Check USART Instance and Clock signal output parameters */
assert_param(IS_UART_INSTANCE(USARTx));
assert_param(IS_LL_USART_CLOCKOUTPUT(USART_ClockInitStruct->ClockOutput));
/* USART needs to be in disabled state, in order to be able to configure some bits in
CRx registers */
if (LL_USART_IsEnabled(USARTx) == 0U)
{
/*---------------------------- USART CR2 Configuration -----------------------*/
/* If Clock signal has to be output */
if (USART_ClockInitStruct->ClockOutput == LL_USART_CLOCK_DISABLE)
{
/* Deactivate Clock signal delivery :
* - Disable Clock Output: USART_CR2_CLKEN cleared
*/
LL_USART_DisableSCLKOutput(USARTx);
}
else
{
/* Ensure USART instance is USART capable */
assert_param(IS_USART_INSTANCE(USARTx));
/* Check clock related parameters */
assert_param(IS_LL_USART_CLOCKPOLARITY(USART_ClockInitStruct->ClockPolarity));
assert_param(IS_LL_USART_CLOCKPHASE(USART_ClockInitStruct->ClockPhase));
assert_param(IS_LL_USART_LASTBITCLKOUTPUT(USART_ClockInitStruct->LastBitClockPulse));
/*---------------------------- USART CR2 Configuration -----------------------
* Configure USARTx CR2 (Clock signal related bits) with parameters:
* - Enable Clock Output: USART_CR2_CLKEN set
* - Clock Polarity: USART_CR2_CPOL bit according to USART_ClockInitStruct->ClockPolarity value
* - Clock Phase: USART_CR2_CPHA bit according to USART_ClockInitStruct->ClockPhase value
* - Last Bit Clock Pulse Output: USART_CR2_LBCL bit according to USART_ClockInitStruct->LastBitClockPulse value.
*/
MODIFY_REG(USARTx->CR2,
USART_CR2_CLKEN | USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_LBCL,
USART_CR2_CLKEN | USART_ClockInitStruct->ClockPolarity |
USART_ClockInitStruct->ClockPhase | USART_ClockInitStruct->LastBitClockPulse);
}
}
/* Else (USART not in Disabled state => return ERROR */
else
{
status = ERROR;
}
return (status);
}
/**
* @brief Set each field of a @ref LL_USART_ClockInitTypeDef type structure to default value.
* @param USART_ClockInitStruct: pointer to a @ref LL_USART_ClockInitTypeDef structure
* whose fields will be set to default values.
* @retval None
*/
void LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct)
{
/* Set LL_USART_ClockInitStruct fields with default values */
USART_ClockInitStruct->ClockOutput = LL_USART_CLOCK_DISABLE;
USART_ClockInitStruct->ClockPolarity = LL_USART_POLARITY_LOW; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */
USART_ClockInitStruct->ClockPhase = LL_USART_PHASE_1EDGE; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */
USART_ClockInitStruct->LastBitClockPulse = LL_USART_LASTCLKPULSE_NO_OUTPUT; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* USART1 || USART2 || USART3 || UART4 || UART5 */
/**
* @}
*/
#endif /* USE_FULL_LL_DRIVER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
the_stack_data/243892141.c | /*
* Exercise 1-15
* Rewrite the temperature conversion program of Section 1.2 to use a function
* for conversion.
*/
#include <stdio.h>
void displayTemperatureTable(float fahr, float max, float step) {
float celsius;
printf("%10s %10s\n", "Fahrenheit", "Celsius");
printf("%10s %10s\n", "----------", "-------");
while (fahr <= max) {
celsius = (5.0 / 9.0) * (fahr - 32.0);
printf("%10.0f %10.1f\n", fahr, celsius);
fahr = fahr + step;
}
}
main() {
displayTemperatureTable(0, 300, 20);
} |
the_stack_data/843118.c | # include <stdio.h>
# include <math.h>
# include <stdlib.h>
int A[10][10] = { {0} };
char S[10][100] = { {0} };
int min(int a,int b) {
if (a>b)
return b;
else
return a;
}
int get (char* a, char* b) {
int i;
int k=min(strlen(a),strlen(b));
for (i=k;i>0;i--) {
int j;
for (j=0;j<i && b[j]==a[strlen(a)-i+j];j++) {
}
if (j==i)
break;
}
return strlen(b)-i;
}
void super(int n)
{
int i = 0, j = 0;
for(; i < n; ++i){
for(j = 0; j < n; ++j) if(i != j){
A[i][j] = get(S[i], S[j]);
// printf("%d %d\n",i,j);
printf("%d %d %d\n",i, j, A[i][j]);
}
}
}
int answer2(int n, int sum, int *B, int prev, int s)
{
int i = 0, ans = 10000;
int C[10] = {0};
for(i = 0 ; i < n; ++i){
if(B[i] != 0){
B[i] = 0;
C[i] = answer2(n, sum + A[prev][i], B, i, s - 1);
B[i] = i + 1;
}
}
if(s == 0) return sum;
for(i = 0; i < n; ++i){
if(C[i] != 0 && C[i] < ans) ans = C[i];
}
return ans;
}
int answer(int n)
{
int i = 0, ans = 10000;
int B[10] = {0};
int C[10] = {0};
for(; i < n; ++i) B[i] = i + 1;
for(i = 0; i < n; ++i){
B[i] = 0;
C[i] = answer2(n, strlen(S[i]), B, i, n - 1);
B[i] = i + 1;
}
for(i = 0; i < n; ++i){
if(C[i] < ans) ans = C[i];
}
return ans;
}
int main (int argc , char **argv )
{
int i = 0, n = 0;
scanf("%d ", &n);
for(i = 0; i < n; ++i) gets(S[i]);
super(n);
printf("%d", answer(n));
return 0;
} |
the_stack_data/225142837.c | // DATA RACE in fsutil.(*InodeSimpleExtendedAttributes).RemoveXattr
// https://syzkaller.appspot.com/bug?id=7f0dbff5f042ea4dd463a056dc6f47f846f2e5f8
// status:open
// 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 <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <linux/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/neighbour.h>
#include <linux/net.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/tcp.h>
#include <linux/veth.h>
unsigned long long procid;
static __thread int skip_segv;
static __thread jmp_buf segv_env;
static void segv_handler(int sig, siginfo_t* info, void* ctx)
{
uintptr_t addr = (uintptr_t)info->si_addr;
const uintptr_t prog_start = 1 << 20;
const uintptr_t prog_end = 100 << 20;
if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) &&
(addr < prog_start || addr > prog_end)) {
_longjmp(segv_env, 1);
}
exit(sig);
}
static void install_segv_handler(void)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8);
syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8);
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = segv_handler;
sa.sa_flags = SA_NODEFER | SA_SIGINFO;
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGBUS, &sa, NULL);
}
#define NONFAILING(...) \
{ \
__atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \
if (_setjmp(segv_env) == 0) { \
__VA_ARGS__; \
} \
__atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \
}
static void sleep_ms(uint64_t ms)
{
usleep(ms * 1000);
}
static uint64_t current_time_ms(void)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts))
exit(1);
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}
static void 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;
for (i = 0; i < 100; i++) {
if (pthread_create(&th, &attr, fn, arg) == 0) {
pthread_attr_destroy(&attr);
return;
}
if (errno == EAGAIN) {
usleep(50);
continue;
}
break;
}
exit(1);
}
typedef struct {
int state;
} event_t;
static void event_init(event_t* ev)
{
ev->state = 0;
}
static void event_reset(event_t* ev)
{
ev->state = 0;
}
static void event_set(event_t* ev)
{
if (ev->state)
exit(1);
__atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE);
syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 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_RELAXED))
return 1;
now = current_time_ms();
if (now - start > timeout)
return 0;
}
}
static bool write_file(const char* file, const char* what, ...)
{
char buf[1024];
va_list args;
va_start(args, what);
vsnprintf(buf, sizeof(buf), what, args);
va_end(args);
buf[sizeof(buf) - 1] = 0;
int len = strlen(buf);
int fd = open(file, O_WRONLY | O_CLOEXEC);
if (fd == -1)
return false;
if (write(fd, buf, len) != len) {
int err = errno;
close(fd);
errno = err;
return false;
}
close(fd);
return true;
}
struct nlmsg {
char* pos;
int nesting;
struct nlattr* nested[8];
char buf[1024];
};
static struct nlmsg nlmsg;
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;
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 (hdr->nlmsg_type == NLMSG_DONE) {
*reply_len = 0;
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_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 int tunfd = -1;
static int tun_frags_enabled;
#define TUN_IFACE "syz_tun"
#define LOCAL_MAC 0xaaaaaaaaaaaa
#define REMOTE_MAC 0xaaaaaaaaaabb
#define LOCAL_IPV4 "172.20.20.170"
#define REMOTE_IPV4 "172.20.20.187"
#define LOCAL_IPV6 "fe80::aa"
#define REMOTE_IPV6 "fe80::bb"
#define IFF_NAPI 0x0010
#define IFF_NAPI_FRAGS 0x0020
static void initialize_tun(void)
{
tunfd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
if (tunfd == -1) {
printf("tun: can't open /dev/net/tun: please enable CONFIG_TUN=y\n");
printf("otherwise fuzzing or reproducing might not work as intended\n");
return;
}
const int kTunFd = 240;
if (dup2(tunfd, kTunFd) < 0)
exit(1);
close(tunfd);
tunfd = kTunFd;
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, TUN_IFACE, IFNAMSIZ);
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
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);
}
const int kInitNetNsFd = 239;
#define DEVLINK_FAMILY_NAME "devlink"
#define DEVLINK_CMD_PORT_GET 5
#define DEVLINK_CMD_RELOAD 37
#define DEVLINK_ATTR_BUS_NAME 1
#define DEVLINK_ATTR_DEV_NAME 2
#define DEVLINK_ATTR_NETDEV_NAME 7
#define DEVLINK_ATTR_NETNS_FD 138
static int netlink_devlink_id_get(struct nlmsg* nlmsg, int sock)
{
struct genlmsghdr genlhdr;
struct nlattr* attr;
int err, n;
uint16_t id = 0;
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, DEVLINK_FAMILY_NAME,
strlen(DEVLINK_FAMILY_NAME) + 1);
err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n);
if (err) {
return -1;
}
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); /* recv ack */
return id;
}
static void netlink_devlink_netns_move(const char* bus_name,
const char* dev_name, int netns_fd)
{
struct genlmsghdr genlhdr;
int sock;
int id, err;
sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (sock == -1)
exit(1);
id = netlink_devlink_id_get(&nlmsg, sock);
if (id == -1)
goto error;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = DEVLINK_CMD_RELOAD;
netlink_init(&nlmsg, id, 0, &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);
netlink_attr(&nlmsg, DEVLINK_ATTR_NETNS_FD, &netns_fd, sizeof(netns_fd));
err = netlink_send(&nlmsg, sock);
if (err) {
}
error:
close(sock);
}
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_devlink_id_get(&nlmsg, sock);
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) {
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);
}
static void initialize_devlink_pci(void)
{
int netns = open("/proc/self/ns/net", O_RDONLY);
if (netns == -1)
exit(1);
int ret = setns(kInitNetNsFd, 0);
if (ret == -1)
exit(1);
netlink_devlink_netns_move("pci", "0000:00:10.0", netns);
ret = setns(netns, 0);
if (ret == -1)
exit(1);
close(netns);
initialize_devlink_ports("pci", "0000:00:10.0", "netpci");
}
#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 int netlink_wireguard_id_get(struct nlmsg* nlmsg, int sock)
{
struct genlmsghdr genlhdr;
struct nlattr* attr;
int err, n;
uint16_t id = 0;
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, WG_GENL_NAME,
strlen(WG_GENL_NAME) + 1);
err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n);
if (err) {
return -1;
}
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); /* recv ack */
return id;
}
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;
/* Unused, but useful in case we change this:
const struct sockaddr_in endpoint_a_v4 = {
.sin_family = AF_INET,
.sin_port = htons(listen_a),
.sin_addr = {htonl(INADDR_LOOPBACK)}};*/
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;
/* Unused, but useful in case we change this:
const struct sockaddr_in6 endpoint_b_v6 = {
.sin6_family = AF_INET6,
.sin6_port = htons(listen_b)};
endpoint_b_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 = {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_wireguard_id_get(&nlmsg, sock);
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) {
}
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) {
}
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) {
}
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)
return -1;
if (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 XT_TABLE_SIZE 1536
#define XT_MAX_ENTRIES 10
struct xt_counters {
uint64_t pcnt, bcnt;
};
struct ipt_getinfo {
char name[32];
unsigned int valid_hooks;
unsigned int hook_entry[5];
unsigned int underflow[5];
unsigned int num_entries;
unsigned int size;
};
struct ipt_get_entries {
char name[32];
unsigned int size;
void* entrytable[XT_TABLE_SIZE / sizeof(void*)];
};
struct ipt_replace {
char name[32];
unsigned int valid_hooks;
unsigned int num_entries;
unsigned int size;
unsigned int hook_entry[5];
unsigned int underflow[5];
unsigned int num_counters;
struct xt_counters* counters;
char entrytable[XT_TABLE_SIZE];
};
struct ipt_table_desc {
const char* name;
struct ipt_getinfo info;
struct ipt_replace replace;
};
static struct ipt_table_desc ipv4_tables[] = {
{.name = "filter"}, {.name = "nat"}, {.name = "mangle"},
{.name = "raw"}, {.name = "security"},
};
static struct ipt_table_desc ipv6_tables[] = {
{.name = "filter"}, {.name = "nat"}, {.name = "mangle"},
{.name = "raw"}, {.name = "security"},
};
#define IPT_BASE_CTL 64
#define IPT_SO_SET_REPLACE (IPT_BASE_CTL)
#define IPT_SO_GET_INFO (IPT_BASE_CTL)
#define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1)
struct arpt_getinfo {
char name[32];
unsigned int valid_hooks;
unsigned int hook_entry[3];
unsigned int underflow[3];
unsigned int num_entries;
unsigned int size;
};
struct arpt_get_entries {
char name[32];
unsigned int size;
void* entrytable[XT_TABLE_SIZE / sizeof(void*)];
};
struct arpt_replace {
char name[32];
unsigned int valid_hooks;
unsigned int num_entries;
unsigned int size;
unsigned int hook_entry[3];
unsigned int underflow[3];
unsigned int num_counters;
struct xt_counters* counters;
char entrytable[XT_TABLE_SIZE];
};
struct arpt_table_desc {
const char* name;
struct arpt_getinfo info;
struct arpt_replace replace;
};
static struct arpt_table_desc arpt_tables[] = {
{.name = "filter"},
};
#define ARPT_BASE_CTL 96
#define ARPT_SO_SET_REPLACE (ARPT_BASE_CTL)
#define ARPT_SO_GET_INFO (ARPT_BASE_CTL)
#define ARPT_SO_GET_ENTRIES (ARPT_BASE_CTL + 1)
static void checkpoint_iptables(struct ipt_table_desc* tables, int num_tables,
int family, int level)
{
struct ipt_get_entries entries;
socklen_t optlen;
int fd, i;
fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < num_tables; i++) {
struct ipt_table_desc* table = &tables[i];
strcpy(table->info.name, table->name);
strcpy(table->replace.name, table->name);
optlen = sizeof(table->info);
if (getsockopt(fd, level, IPT_SO_GET_INFO, &table->info, &optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->info.size > sizeof(table->replace.entrytable))
exit(1);
if (table->info.num_entries > XT_MAX_ENTRIES)
exit(1);
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size;
if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
table->replace.valid_hooks = table->info.valid_hooks;
table->replace.num_entries = table->info.num_entries;
table->replace.size = table->info.size;
memcpy(table->replace.hook_entry, table->info.hook_entry,
sizeof(table->replace.hook_entry));
memcpy(table->replace.underflow, table->info.underflow,
sizeof(table->replace.underflow));
memcpy(table->replace.entrytable, entries.entrytable, table->info.size);
}
close(fd);
}
static void reset_iptables(struct ipt_table_desc* tables, int num_tables,
int family, int level)
{
struct xt_counters counters[XT_MAX_ENTRIES];
struct ipt_get_entries entries;
struct ipt_getinfo info;
socklen_t optlen;
int fd, i;
fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < num_tables; i++) {
struct ipt_table_desc* table = &tables[i];
if (table->info.valid_hooks == 0)
continue;
memset(&info, 0, sizeof(info));
strcpy(info.name, table->name);
optlen = sizeof(info);
if (getsockopt(fd, level, IPT_SO_GET_INFO, &info, &optlen))
exit(1);
if (memcmp(&table->info, &info, sizeof(table->info)) == 0) {
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size;
if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
if (memcmp(table->replace.entrytable, entries.entrytable,
table->info.size) == 0)
continue;
}
table->replace.num_counters = info.num_entries;
table->replace.counters = counters;
optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) +
table->replace.size;
if (setsockopt(fd, level, IPT_SO_SET_REPLACE, &table->replace, optlen))
exit(1);
}
close(fd);
}
static void checkpoint_arptables(void)
{
struct arpt_get_entries entries;
socklen_t optlen;
unsigned i;
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) {
struct arpt_table_desc* table = &arpt_tables[i];
strcpy(table->info.name, table->name);
strcpy(table->replace.name, table->name);
optlen = sizeof(table->info);
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &table->info, &optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->info.size > sizeof(table->replace.entrytable))
exit(1);
if (table->info.num_entries > XT_MAX_ENTRIES)
exit(1);
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size;
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
table->replace.valid_hooks = table->info.valid_hooks;
table->replace.num_entries = table->info.num_entries;
table->replace.size = table->info.size;
memcpy(table->replace.hook_entry, table->info.hook_entry,
sizeof(table->replace.hook_entry));
memcpy(table->replace.underflow, table->info.underflow,
sizeof(table->replace.underflow));
memcpy(table->replace.entrytable, entries.entrytable, table->info.size);
}
close(fd);
}
static void reset_arptables()
{
struct xt_counters counters[XT_MAX_ENTRIES];
struct arpt_get_entries entries;
struct arpt_getinfo info;
socklen_t optlen;
unsigned i;
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) {
struct arpt_table_desc* table = &arpt_tables[i];
if (table->info.valid_hooks == 0)
continue;
memset(&info, 0, sizeof(info));
strcpy(info.name, table->name);
optlen = sizeof(info);
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &info, &optlen))
exit(1);
if (memcmp(&table->info, &info, sizeof(table->info)) == 0) {
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size;
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
if (memcmp(table->replace.entrytable, entries.entrytable,
table->info.size) == 0)
continue;
} else {
}
table->replace.num_counters = info.num_entries;
table->replace.counters = counters;
optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) +
table->replace.size;
if (setsockopt(fd, SOL_IP, ARPT_SO_SET_REPLACE, &table->replace, optlen))
exit(1);
}
close(fd);
}
#define NF_BR_NUMHOOKS 6
#define EBT_TABLE_MAXNAMELEN 32
#define EBT_CHAIN_MAXNAMELEN 32
#define EBT_BASE_CTL 128
#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
#define EBT_SO_GET_INFO (EBT_BASE_CTL)
#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO + 1)
#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES + 1)
#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO + 1)
struct ebt_replace {
char name[EBT_TABLE_MAXNAMELEN];
unsigned int valid_hooks;
unsigned int nentries;
unsigned int entries_size;
struct ebt_entries* hook_entry[NF_BR_NUMHOOKS];
unsigned int num_counters;
struct ebt_counter* counters;
char* entries;
};
struct ebt_entries {
unsigned int distinguisher;
char name[EBT_CHAIN_MAXNAMELEN];
unsigned int counter_offset;
int policy;
unsigned int nentries;
char data[0] __attribute__((aligned(__alignof__(struct ebt_replace))));
};
struct ebt_table_desc {
const char* name;
struct ebt_replace replace;
char entrytable[XT_TABLE_SIZE];
};
static struct ebt_table_desc ebt_tables[] = {
{.name = "filter"},
{.name = "nat"},
{.name = "broute"},
};
static void checkpoint_ebtables(void)
{
socklen_t optlen;
unsigned i;
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) {
struct ebt_table_desc* table = &ebt_tables[i];
strcpy(table->replace.name, table->name);
optlen = sizeof(table->replace);
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_INFO, &table->replace,
&optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->replace.entries_size > sizeof(table->entrytable))
exit(1);
table->replace.num_counters = 0;
table->replace.entries = table->entrytable;
optlen = sizeof(table->replace) + table->replace.entries_size;
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_ENTRIES, &table->replace,
&optlen))
exit(1);
}
close(fd);
}
static void reset_ebtables()
{
struct ebt_replace replace;
char entrytable[XT_TABLE_SIZE];
socklen_t optlen;
unsigned i, j, h;
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) {
struct ebt_table_desc* table = &ebt_tables[i];
if (table->replace.valid_hooks == 0)
continue;
memset(&replace, 0, sizeof(replace));
strcpy(replace.name, table->name);
optlen = sizeof(replace);
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INFO, &replace, &optlen))
exit(1);
replace.num_counters = 0;
table->replace.entries = 0;
for (h = 0; h < NF_BR_NUMHOOKS; h++)
table->replace.hook_entry[h] = 0;
if (memcmp(&table->replace, &replace, sizeof(table->replace)) == 0) {
memset(&entrytable, 0, sizeof(entrytable));
replace.entries = entrytable;
optlen = sizeof(replace) + replace.entries_size;
if (getsockopt(fd, SOL_IP, EBT_SO_GET_ENTRIES, &replace, &optlen))
exit(1);
if (memcmp(table->entrytable, entrytable, replace.entries_size) == 0)
continue;
}
for (j = 0, h = 0; h < NF_BR_NUMHOOKS; h++) {
if (table->replace.valid_hooks & (1 << h)) {
table->replace.hook_entry[h] =
(struct ebt_entries*)table->entrytable + j;
j++;
}
}
table->replace.entries = table->entrytable;
optlen = sizeof(table->replace) + table->replace.entries_size;
if (setsockopt(fd, SOL_IP, EBT_SO_SET_ENTRIES, &table->replace, optlen))
exit(1);
}
close(fd);
}
static void checkpoint_net_namespace(void)
{
checkpoint_ebtables();
checkpoint_arptables();
checkpoint_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]),
AF_INET, SOL_IP);
checkpoint_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]),
AF_INET6, SOL_IPV6);
}
static void reset_net_namespace(void)
{
reset_ebtables();
reset_arptables();
reset_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]),
AF_INET, SOL_IP);
reset_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]),
AF_INET6, SOL_IPV6);
}
static void setup_cgroups()
{
if (mkdir("/syzcgroup", 0777)) {
}
if (mkdir("/syzcgroup/unified", 0777)) {
}
if (mount("none", "/syzcgroup/unified", "cgroup2", 0, NULL)) {
}
if (chmod("/syzcgroup/unified", 0777)) {
}
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");
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();
int netns = open("/proc/self/ns/net", O_RDONLY);
if (netns == -1)
exit(1);
if (dup2(netns, kInitNetNsFd) < 0)
exit(1);
close(netns);
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = (200 << 20);
setrlimit(RLIMIT_AS, &rlim);
rlim.rlim_cur = rlim.rlim_max = 32 << 20;
setrlimit(RLIMIT_MEMLOCK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 136 << 20;
setrlimit(RLIMIT_FSIZE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 1 << 20;
setrlimit(RLIMIT_STACK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 0;
setrlimit(RLIMIT_CORE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 256;
setrlimit(RLIMIT_NOFILE, &rlim);
if (unshare(CLONE_NEWNS)) {
}
if (unshare(CLONE_NEWIPC)) {
}
if (unshare(0x02000000)) {
}
if (unshare(CLONE_NEWUTS)) {
}
if (unshare(CLONE_SYSVSEM)) {
}
typedef struct {
const char* name;
const char* value;
} sysctl_t;
static const sysctl_t sysctls[] = {
{"/proc/sys/kernel/shmmax", "16777216"},
{"/proc/sys/kernel/shmall", "536870912"},
{"/proc/sys/kernel/shmmni", "1024"},
{"/proc/sys/kernel/msgmax", "8192"},
{"/proc/sys/kernel/msgmni", "1024"},
{"/proc/sys/kernel/msgmnb", "1024"},
{"/proc/sys/kernel/sem", "1024 1048576 500 1024"},
};
unsigned i;
for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++)
write_file(sysctls[i].name, sysctls[i].value);
}
int wait_for_loop(int pid)
{
if (pid < 0)
exit(1);
int status = 0;
while (waitpid(-1, &status, __WALL) != pid) {
}
return WEXITSTATUS(status);
}
static 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();
sandbox_common();
drop_caps();
initialize_netdevices_init();
if (unshare(CLONE_NEWNET)) {
}
initialize_devlink_pci();
initialize_tun();
initialize_netdevices();
loop();
exit(1);
}
#define FS_IOC_SETFLAGS _IOW('f', 2, long)
static void remove_dir(const char* dir)
{
DIR* dp;
struct dirent* ep;
int iter = 0;
retry:
while (umount2(dir, MNT_DETACH) == 0) {
}
dp = opendir(dir);
if (dp == NULL) {
if (errno == EMFILE) {
exit(1);
}
exit(1);
}
while ((ep = readdir(dp))) {
if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
continue;
char filename[FILENAME_MAX];
snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name);
while (umount2(filename, MNT_DETACH) == 0) {
}
struct stat st;
if (lstat(filename, &st))
exit(1);
if (S_ISDIR(st.st_mode)) {
remove_dir(filename);
continue;
}
int i;
for (i = 0;; i++) {
if (unlink(filename) == 0)
break;
if (errno == EPERM) {
int fd = open(filename, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
}
close(fd);
continue;
}
}
if (errno == EROFS) {
break;
}
if (errno != EBUSY || i > 100)
exit(1);
if (umount2(filename, MNT_DETACH))
exit(1);
}
}
closedir(dp);
int i;
for (i = 0;; i++) {
if (rmdir(dir) == 0)
break;
if (i < 100) {
if (errno == EPERM) {
int fd = open(dir, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
}
close(fd);
continue;
}
}
if (errno == EROFS) {
break;
}
if (errno == EBUSY) {
if (umount2(dir, MNT_DETACH))
exit(1);
continue;
}
if (errno == ENOTEMPTY) {
if (iter < 100) {
iter++;
goto retry;
}
}
}
exit(1);
}
}
static void kill_and_wait(int pid, int* status)
{
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
int i;
for (i = 0; i < 100; i++) {
if (waitpid(-1, status, WNOHANG | __WALL) == pid)
return;
usleep(1000);
}
DIR* dir = opendir("/sys/fs/fuse/connections");
if (dir) {
for (;;) {
struct dirent* ent = readdir(dir);
if (!ent)
break;
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
continue;
char abort[300];
snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
ent->d_name);
int fd = open(abort, O_WRONLY);
if (fd == -1) {
continue;
}
if (write(fd, abort, 1) < 0) {
}
close(fd);
}
closedir(dir);
} else {
}
while (waitpid(-1, status, __WALL) != pid) {
}
}
static void setup_loop()
{
setup_cgroups_loop();
checkpoint_net_namespace();
}
static void reset_loop()
{
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()
{
int fd;
for (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;
int collide = 0;
again:
for (call = 0; call < 11; call++) {
for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0]));
thread++) {
struct thread_t* th = &threads[thread];
if (!th->created) {
th->created = 1;
event_init(&th->ready);
event_init(&th->done);
event_set(&th->done);
thread_start(thr, th);
}
if (!event_isset(&th->done))
continue;
event_reset(&th->done);
th->call = call;
__atomic_fetch_add(&running, 1, __ATOMIC_RELAXED);
event_set(&th->ready);
if (collide && (call % 2) == 0)
break;
event_timedwait(&th->done, 45);
break;
}
}
for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++)
sleep_ms(1);
close_fds();
if (!collide) {
collide = 1;
goto again;
}
}
static void execute_one(void);
#define WAIT_FLAGS __WALL
static void loop(void)
{
setup_loop();
int iter;
for (iter = 0;; iter++) {
char cwdbuf[32];
sprintf(cwdbuf, "./%d", iter);
if (mkdir(cwdbuf, 0777))
exit(1);
reset_loop();
int pid = fork();
if (pid < 0)
exit(1);
if (pid == 0) {
if (chdir(cwdbuf))
exit(1);
setup_test();
execute_one();
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);
}
}
#ifndef __NR_memfd_create
#define __NR_memfd_create 319
#endif
uint64_t r[5] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff,
0xffffffffffffffff, 0xffffffffffffffff};
void execute_call(int call)
{
intptr_t res;
switch (call) {
case 0:
NONFAILING(memcpy((void*)0x20001c80, "/dev/null\000", 10));
res = syscall(__NR_openat, 0xffffffffffffff9cul, 0x20001c80ul, 0ul, 0ul);
if (res != -1)
r[0] = res;
break;
case 1:
NONFAILING(memcpy((void*)0x20001d40, "\000", 1));
res = syscall(__NR_memfd_create, 0x20001d40ul, 0ul);
if (res != -1)
r[1] = res;
break;
case 2:
res = syscall(__NR_openat, 0xffffffffffffff9cul, 0ul, 0ul, 0ul);
if (res != -1)
r[2] = res;
break;
case 3:
res = syscall(__NR_memfd_create, 0ul, 0ul);
if (res != -1)
r[3] = res;
break;
case 4:
syscall(__NR_dup3, r[3], r[2], 0ul);
break;
case 5:
syscall(__NR_fsetxattr, r[2], 0ul, 0ul, 0ul, 0ul);
break;
case 6:
syscall(__NR_write, r[2], 0ul, 0ul);
break;
case 7:
res = syscall(__NR_dup3, r[1], r[0], 0ul);
if (res != -1)
r[4] = res;
break;
case 8:
NONFAILING(memcpy((void*)0x20000080, "user.syz\000", 9));
syscall(__NR_fsetxattr, r[0], 0x20000080ul, 0ul, 0ul, 0ul);
break;
case 9:
NONFAILING(memcpy((void*)0x20000040, "user.syz\000", 9));
syscall(__NR_fremovexattr, r[0], 0x20000040ul);
break;
case 10:
syscall(__NR_flistxattr, r[4], 0ul, 0ul);
break;
}
}
int main(void)
{
syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x32ul, -1, 0);
setup_binfmt_misc();
install_segv_handler();
use_temporary_dir();
do_sandbox_none();
return 0;
}
|
the_stack_data/181393476.c | #include <stdint.h>
#include <string.h>
//----------------------------------------------------------------------------------------------------------------------
// 88BC907AAEBC9E311E776A2A49D04EF917F0DC65D46A020B3458E8EA8B9416A94002C28AED2C71EE38EB8360CBA8AC52AACC6F034AF8A8BD3125014FB2633925
//----------------------------------------------------------------------------------------------------------------------
static uint64_t op(uint64_t const * const src, const unsigned int shift)
{
const uint64_t sbox[8][256] =
{
{
UINT64_C(0x18186018c07830d8), UINT64_C(0x23238c2305af4626), UINT64_C(0xc6c63fc67ef991b8), UINT64_C(0xe8e887e8136fcdfb),
UINT64_C(0x878726874ca113cb), UINT64_C(0xb8b8dab8a9626d11), UINT64_C(0x0101040108050209), UINT64_C(0x4f4f214f426e9e0d),
UINT64_C(0x3636d836adee6c9b), UINT64_C(0xa6a6a2a6590451ff), UINT64_C(0xd2d26fd2debdb90c), UINT64_C(0xf5f5f3f5fb06f70e),
UINT64_C(0x7979f979ef80f296), UINT64_C(0x6f6fa16f5fcede30), UINT64_C(0x91917e91fcef3f6d), UINT64_C(0x52525552aa07a4f8),
UINT64_C(0x60609d6027fdc047), UINT64_C(0xbcbccabc89766535), UINT64_C(0x9b9b569baccd2b37), UINT64_C(0x8e8e028e048c018a),
UINT64_C(0xa3a3b6a371155bd2), UINT64_C(0x0c0c300c603c186c), UINT64_C(0x7b7bf17bff8af684), UINT64_C(0x3535d435b5e16a80),
UINT64_C(0x1d1d741de8693af5), UINT64_C(0xe0e0a7e05347ddb3), UINT64_C(0xd7d77bd7f6acb321), UINT64_C(0xc2c22fc25eed999c),
UINT64_C(0x2e2eb82e6d965c43), UINT64_C(0x4b4b314b627a9629), UINT64_C(0xfefedffea321e15d), UINT64_C(0x575741578216aed5),
UINT64_C(0x15155415a8412abd), UINT64_C(0x7777c1779fb6eee8), UINT64_C(0x3737dc37a5eb6e92), UINT64_C(0xe5e5b3e57b56d79e),
UINT64_C(0x9f9f469f8cd92313), UINT64_C(0xf0f0e7f0d317fd23), UINT64_C(0x4a4a354a6a7f9420), UINT64_C(0xdada4fda9e95a944),
UINT64_C(0x58587d58fa25b0a2), UINT64_C(0xc9c903c906ca8fcf), UINT64_C(0x2929a429558d527c), UINT64_C(0x0a0a280a5022145a),
UINT64_C(0xb1b1feb1e14f7f50), UINT64_C(0xa0a0baa0691a5dc9), UINT64_C(0x6b6bb16b7fdad614), UINT64_C(0x85852e855cab17d9),
UINT64_C(0xbdbdcebd8173673c), UINT64_C(0x5d5d695dd234ba8f), UINT64_C(0x1010401080502090), UINT64_C(0xf4f4f7f4f303f507),
UINT64_C(0xcbcb0bcb16c08bdd), UINT64_C(0x3e3ef83eedc67cd3), UINT64_C(0x0505140528110a2d), UINT64_C(0x676781671fe6ce78),
UINT64_C(0xe4e4b7e47353d597), UINT64_C(0x27279c2725bb4e02), UINT64_C(0x4141194132588273), UINT64_C(0x8b8b168b2c9d0ba7),
UINT64_C(0xa7a7a6a7510153f6), UINT64_C(0x7d7de97dcf94fab2), UINT64_C(0x95956e95dcfb3749), UINT64_C(0xd8d847d88e9fad56),
UINT64_C(0xfbfbcbfb8b30eb70), UINT64_C(0xeeee9fee2371c1cd), UINT64_C(0x7c7ced7cc791f8bb), UINT64_C(0x6666856617e3cc71),
UINT64_C(0xdddd53dda68ea77b), UINT64_C(0x17175c17b84b2eaf), UINT64_C(0x4747014702468e45), UINT64_C(0x9e9e429e84dc211a),
UINT64_C(0xcaca0fca1ec589d4), UINT64_C(0x2d2db42d75995a58), UINT64_C(0xbfbfc6bf9179632e), UINT64_C(0x07071c07381b0e3f),
UINT64_C(0xadad8ead012347ac), UINT64_C(0x5a5a755aea2fb4b0), UINT64_C(0x838336836cb51bef), UINT64_C(0x3333cc3385ff66b6),
UINT64_C(0x636391633ff2c65c), UINT64_C(0x02020802100a0412), UINT64_C(0xaaaa92aa39384993), UINT64_C(0x7171d971afa8e2de),
UINT64_C(0xc8c807c80ecf8dc6), UINT64_C(0x19196419c87d32d1), UINT64_C(0x494939497270923b), UINT64_C(0xd9d943d9869aaf5f),
UINT64_C(0xf2f2eff2c31df931), UINT64_C(0xe3e3abe34b48dba8), UINT64_C(0x5b5b715be22ab6b9), UINT64_C(0x88881a8834920dbc),
UINT64_C(0x9a9a529aa4c8293e), UINT64_C(0x262698262dbe4c0b), UINT64_C(0x3232c8328dfa64bf), UINT64_C(0xb0b0fab0e94a7d59),
UINT64_C(0xe9e983e91b6acff2), UINT64_C(0x0f0f3c0f78331e77), UINT64_C(0xd5d573d5e6a6b733), UINT64_C(0x80803a8074ba1df4),
UINT64_C(0xbebec2be997c6127), UINT64_C(0xcdcd13cd26de87eb), UINT64_C(0x3434d034bde46889), UINT64_C(0x48483d487a759032),
UINT64_C(0xffffdbffab24e354), UINT64_C(0x7a7af57af78ff48d), UINT64_C(0x90907a90f4ea3d64), UINT64_C(0x5f5f615fc23ebe9d),
UINT64_C(0x202080201da0403d), UINT64_C(0x6868bd6867d5d00f), UINT64_C(0x1a1a681ad07234ca), UINT64_C(0xaeae82ae192c41b7),
UINT64_C(0xb4b4eab4c95e757d), UINT64_C(0x54544d549a19a8ce), UINT64_C(0x93937693ece53b7f), UINT64_C(0x222288220daa442f),
UINT64_C(0x64648d6407e9c863), UINT64_C(0xf1f1e3f1db12ff2a), UINT64_C(0x7373d173bfa2e6cc), UINT64_C(0x12124812905a2482),
UINT64_C(0x40401d403a5d807a), UINT64_C(0x0808200840281048), UINT64_C(0xc3c32bc356e89b95), UINT64_C(0xecec97ec337bc5df),
UINT64_C(0xdbdb4bdb9690ab4d), UINT64_C(0xa1a1bea1611f5fc0), UINT64_C(0x8d8d0e8d1c830791), UINT64_C(0x3d3df43df5c97ac8),
UINT64_C(0x97976697ccf1335b), UINT64_C(0x0000000000000000), UINT64_C(0xcfcf1bcf36d483f9), UINT64_C(0x2b2bac2b4587566e),
UINT64_C(0x7676c57697b3ece1), UINT64_C(0x8282328264b019e6), UINT64_C(0xd6d67fd6fea9b128), UINT64_C(0x1b1b6c1bd87736c3),
UINT64_C(0xb5b5eeb5c15b7774), UINT64_C(0xafaf86af112943be), UINT64_C(0x6a6ab56a77dfd41d), UINT64_C(0x50505d50ba0da0ea),
UINT64_C(0x45450945124c8a57), UINT64_C(0xf3f3ebf3cb18fb38), UINT64_C(0x3030c0309df060ad), UINT64_C(0xefef9bef2b74c3c4),
UINT64_C(0x3f3ffc3fe5c37eda), UINT64_C(0x55554955921caac7), UINT64_C(0xa2a2b2a2791059db), UINT64_C(0xeaea8fea0365c9e9),
UINT64_C(0x656589650fecca6a), UINT64_C(0xbabad2bab9686903), UINT64_C(0x2f2fbc2f65935e4a), UINT64_C(0xc0c027c04ee79d8e),
UINT64_C(0xdede5fdebe81a160), UINT64_C(0x1c1c701ce06c38fc), UINT64_C(0xfdfdd3fdbb2ee746), UINT64_C(0x4d4d294d52649a1f),
UINT64_C(0x92927292e4e03976), UINT64_C(0x7575c9758fbceafa), UINT64_C(0x06061806301e0c36), UINT64_C(0x8a8a128a249809ae),
UINT64_C(0xb2b2f2b2f940794b), UINT64_C(0xe6e6bfe66359d185), UINT64_C(0x0e0e380e70361c7e), UINT64_C(0x1f1f7c1ff8633ee7),
UINT64_C(0x6262956237f7c455), UINT64_C(0xd4d477d4eea3b53a), UINT64_C(0xa8a89aa829324d81), UINT64_C(0x96966296c4f43152),
UINT64_C(0xf9f9c3f99b3aef62), UINT64_C(0xc5c533c566f697a3), UINT64_C(0x2525942535b14a10), UINT64_C(0x59597959f220b2ab),
UINT64_C(0x84842a8454ae15d0), UINT64_C(0x7272d572b7a7e4c5), UINT64_C(0x3939e439d5dd72ec), UINT64_C(0x4c4c2d4c5a619816),
UINT64_C(0x5e5e655eca3bbc94), UINT64_C(0x7878fd78e785f09f), UINT64_C(0x3838e038ddd870e5), UINT64_C(0x8c8c0a8c14860598),
UINT64_C(0xd1d163d1c6b2bf17), UINT64_C(0xa5a5aea5410b57e4), UINT64_C(0xe2e2afe2434dd9a1), UINT64_C(0x616199612ff8c24e),
UINT64_C(0xb3b3f6b3f1457b42), UINT64_C(0x2121842115a54234), UINT64_C(0x9c9c4a9c94d62508), UINT64_C(0x1e1e781ef0663cee),
UINT64_C(0x4343114322528661), UINT64_C(0xc7c73bc776fc93b1), UINT64_C(0xfcfcd7fcb32be54f), UINT64_C(0x0404100420140824),
UINT64_C(0x51515951b208a2e3), UINT64_C(0x99995e99bcc72f25), UINT64_C(0x6d6da96d4fc4da22), UINT64_C(0x0d0d340d68391a65),
UINT64_C(0xfafacffa8335e979), UINT64_C(0xdfdf5bdfb684a369), UINT64_C(0x7e7ee57ed79bfca9), UINT64_C(0x242490243db44819),
UINT64_C(0x3b3bec3bc5d776fe), UINT64_C(0xabab96ab313d4b9a), UINT64_C(0xcece1fce3ed181f0), UINT64_C(0x1111441188552299),
UINT64_C(0x8f8f068f0c890383), UINT64_C(0x4e4e254e4a6b9c04), UINT64_C(0xb7b7e6b7d1517366), UINT64_C(0xebeb8beb0b60cbe0),
UINT64_C(0x3c3cf03cfdcc78c1), UINT64_C(0x81813e817cbf1ffd), UINT64_C(0x94946a94d4fe3540), UINT64_C(0xf7f7fbf7eb0cf31c),
UINT64_C(0xb9b9deb9a1676f18), UINT64_C(0x13134c13985f268b), UINT64_C(0x2c2cb02c7d9c5851), UINT64_C(0xd3d36bd3d6b8bb05),
UINT64_C(0xe7e7bbe76b5cd38c), UINT64_C(0x6e6ea56e57cbdc39), UINT64_C(0xc4c437c46ef395aa), UINT64_C(0x03030c03180f061b),
UINT64_C(0x565645568a13acdc), UINT64_C(0x44440d441a49885e), UINT64_C(0x7f7fe17fdf9efea0), UINT64_C(0xa9a99ea921374f88),
UINT64_C(0x2a2aa82a4d825467), UINT64_C(0xbbbbd6bbb16d6b0a), UINT64_C(0xc1c123c146e29f87), UINT64_C(0x53535153a202a6f1),
UINT64_C(0xdcdc57dcae8ba572), UINT64_C(0x0b0b2c0b58271653), UINT64_C(0x9d9d4e9d9cd32701), UINT64_C(0x6c6cad6c47c1d82b),
UINT64_C(0x3131c43195f562a4), UINT64_C(0x7474cd7487b9e8f3), UINT64_C(0xf6f6fff6e309f115), UINT64_C(0x464605460a438c4c),
UINT64_C(0xacac8aac092645a5), UINT64_C(0x89891e893c970fb5), UINT64_C(0x14145014a04428b4), UINT64_C(0xe1e1a3e15b42dfba),
UINT64_C(0x16165816b04e2ca6), UINT64_C(0x3a3ae83acdd274f7), UINT64_C(0x6969b9696fd0d206), UINT64_C(0x09092409482d1241),
UINT64_C(0x7070dd70a7ade0d7), UINT64_C(0xb6b6e2b6d954716f), UINT64_C(0xd0d067d0ceb7bd1e), UINT64_C(0xeded93ed3b7ec7d6),
UINT64_C(0xcccc17cc2edb85e2), UINT64_C(0x424215422a578468), UINT64_C(0x98985a98b4c22d2c), UINT64_C(0xa4a4aaa4490e55ed),
UINT64_C(0x2828a0285d885075), UINT64_C(0x5c5c6d5cda31b886), UINT64_C(0xf8f8c7f8933fed6b), UINT64_C(0x8686228644a411c2),
},
{
UINT64_C(0xd818186018c07830), UINT64_C(0x2623238c2305af46), UINT64_C(0xb8c6c63fc67ef991), UINT64_C(0xfbe8e887e8136fcd),
UINT64_C(0xcb878726874ca113), UINT64_C(0x11b8b8dab8a9626d), UINT64_C(0x0901010401080502), UINT64_C(0x0d4f4f214f426e9e),
UINT64_C(0x9b3636d836adee6c), UINT64_C(0xffa6a6a2a6590451), UINT64_C(0x0cd2d26fd2debdb9), UINT64_C(0x0ef5f5f3f5fb06f7),
UINT64_C(0x967979f979ef80f2), UINT64_C(0x306f6fa16f5fcede), UINT64_C(0x6d91917e91fcef3f), UINT64_C(0xf852525552aa07a4),
UINT64_C(0x4760609d6027fdc0), UINT64_C(0x35bcbccabc897665), UINT64_C(0x379b9b569baccd2b), UINT64_C(0x8a8e8e028e048c01),
UINT64_C(0xd2a3a3b6a371155b), UINT64_C(0x6c0c0c300c603c18), UINT64_C(0x847b7bf17bff8af6), UINT64_C(0x803535d435b5e16a),
UINT64_C(0xf51d1d741de8693a), UINT64_C(0xb3e0e0a7e05347dd), UINT64_C(0x21d7d77bd7f6acb3), UINT64_C(0x9cc2c22fc25eed99),
UINT64_C(0x432e2eb82e6d965c), UINT64_C(0x294b4b314b627a96), UINT64_C(0x5dfefedffea321e1), UINT64_C(0xd5575741578216ae),
UINT64_C(0xbd15155415a8412a), UINT64_C(0xe87777c1779fb6ee), UINT64_C(0x923737dc37a5eb6e), UINT64_C(0x9ee5e5b3e57b56d7),
UINT64_C(0x139f9f469f8cd923), UINT64_C(0x23f0f0e7f0d317fd), UINT64_C(0x204a4a354a6a7f94), UINT64_C(0x44dada4fda9e95a9),
UINT64_C(0xa258587d58fa25b0), UINT64_C(0xcfc9c903c906ca8f), UINT64_C(0x7c2929a429558d52), UINT64_C(0x5a0a0a280a502214),
UINT64_C(0x50b1b1feb1e14f7f), UINT64_C(0xc9a0a0baa0691a5d), UINT64_C(0x146b6bb16b7fdad6), UINT64_C(0xd985852e855cab17),
UINT64_C(0x3cbdbdcebd817367), UINT64_C(0x8f5d5d695dd234ba), UINT64_C(0x9010104010805020), UINT64_C(0x07f4f4f7f4f303f5),
UINT64_C(0xddcbcb0bcb16c08b), UINT64_C(0xd33e3ef83eedc67c), UINT64_C(0x2d0505140528110a), UINT64_C(0x78676781671fe6ce),
UINT64_C(0x97e4e4b7e47353d5), UINT64_C(0x0227279c2725bb4e), UINT64_C(0x7341411941325882), UINT64_C(0xa78b8b168b2c9d0b),
UINT64_C(0xf6a7a7a6a7510153), UINT64_C(0xb27d7de97dcf94fa), UINT64_C(0x4995956e95dcfb37), UINT64_C(0x56d8d847d88e9fad),
UINT64_C(0x70fbfbcbfb8b30eb), UINT64_C(0xcdeeee9fee2371c1), UINT64_C(0xbb7c7ced7cc791f8), UINT64_C(0x716666856617e3cc),
UINT64_C(0x7bdddd53dda68ea7), UINT64_C(0xaf17175c17b84b2e), UINT64_C(0x454747014702468e), UINT64_C(0x1a9e9e429e84dc21),
UINT64_C(0xd4caca0fca1ec589), UINT64_C(0x582d2db42d75995a), UINT64_C(0x2ebfbfc6bf917963), UINT64_C(0x3f07071c07381b0e),
UINT64_C(0xacadad8ead012347), UINT64_C(0xb05a5a755aea2fb4), UINT64_C(0xef838336836cb51b), UINT64_C(0xb63333cc3385ff66),
UINT64_C(0x5c636391633ff2c6), UINT64_C(0x1202020802100a04), UINT64_C(0x93aaaa92aa393849), UINT64_C(0xde7171d971afa8e2),
UINT64_C(0xc6c8c807c80ecf8d), UINT64_C(0xd119196419c87d32), UINT64_C(0x3b49493949727092), UINT64_C(0x5fd9d943d9869aaf),
UINT64_C(0x31f2f2eff2c31df9), UINT64_C(0xa8e3e3abe34b48db), UINT64_C(0xb95b5b715be22ab6), UINT64_C(0xbc88881a8834920d),
UINT64_C(0x3e9a9a529aa4c829), UINT64_C(0x0b262698262dbe4c), UINT64_C(0xbf3232c8328dfa64), UINT64_C(0x59b0b0fab0e94a7d),
UINT64_C(0xf2e9e983e91b6acf), UINT64_C(0x770f0f3c0f78331e), UINT64_C(0x33d5d573d5e6a6b7), UINT64_C(0xf480803a8074ba1d),
UINT64_C(0x27bebec2be997c61), UINT64_C(0xebcdcd13cd26de87), UINT64_C(0x893434d034bde468), UINT64_C(0x3248483d487a7590),
UINT64_C(0x54ffffdbffab24e3), UINT64_C(0x8d7a7af57af78ff4), UINT64_C(0x6490907a90f4ea3d), UINT64_C(0x9d5f5f615fc23ebe),
UINT64_C(0x3d202080201da040), UINT64_C(0x0f6868bd6867d5d0), UINT64_C(0xca1a1a681ad07234), UINT64_C(0xb7aeae82ae192c41),
UINT64_C(0x7db4b4eab4c95e75), UINT64_C(0xce54544d549a19a8), UINT64_C(0x7f93937693ece53b), UINT64_C(0x2f222288220daa44),
UINT64_C(0x6364648d6407e9c8), UINT64_C(0x2af1f1e3f1db12ff), UINT64_C(0xcc7373d173bfa2e6), UINT64_C(0x8212124812905a24),
UINT64_C(0x7a40401d403a5d80), UINT64_C(0x4808082008402810), UINT64_C(0x95c3c32bc356e89b), UINT64_C(0xdfecec97ec337bc5),
UINT64_C(0x4ddbdb4bdb9690ab), UINT64_C(0xc0a1a1bea1611f5f), UINT64_C(0x918d8d0e8d1c8307), UINT64_C(0xc83d3df43df5c97a),
UINT64_C(0x5b97976697ccf133), UINT64_C(0x0000000000000000), UINT64_C(0xf9cfcf1bcf36d483), UINT64_C(0x6e2b2bac2b458756),
UINT64_C(0xe17676c57697b3ec), UINT64_C(0xe68282328264b019), UINT64_C(0x28d6d67fd6fea9b1), UINT64_C(0xc31b1b6c1bd87736),
UINT64_C(0x74b5b5eeb5c15b77), UINT64_C(0xbeafaf86af112943), UINT64_C(0x1d6a6ab56a77dfd4), UINT64_C(0xea50505d50ba0da0),
UINT64_C(0x5745450945124c8a), UINT64_C(0x38f3f3ebf3cb18fb), UINT64_C(0xad3030c0309df060), UINT64_C(0xc4efef9bef2b74c3),
UINT64_C(0xda3f3ffc3fe5c37e), UINT64_C(0xc755554955921caa), UINT64_C(0xdba2a2b2a2791059), UINT64_C(0xe9eaea8fea0365c9),
UINT64_C(0x6a656589650fecca), UINT64_C(0x03babad2bab96869), UINT64_C(0x4a2f2fbc2f65935e), UINT64_C(0x8ec0c027c04ee79d),
UINT64_C(0x60dede5fdebe81a1), UINT64_C(0xfc1c1c701ce06c38), UINT64_C(0x46fdfdd3fdbb2ee7), UINT64_C(0x1f4d4d294d52649a),
UINT64_C(0x7692927292e4e039), UINT64_C(0xfa7575c9758fbcea), UINT64_C(0x3606061806301e0c), UINT64_C(0xae8a8a128a249809),
UINT64_C(0x4bb2b2f2b2f94079), UINT64_C(0x85e6e6bfe66359d1), UINT64_C(0x7e0e0e380e70361c), UINT64_C(0xe71f1f7c1ff8633e),
UINT64_C(0x556262956237f7c4), UINT64_C(0x3ad4d477d4eea3b5), UINT64_C(0x81a8a89aa829324d), UINT64_C(0x5296966296c4f431),
UINT64_C(0x62f9f9c3f99b3aef), UINT64_C(0xa3c5c533c566f697), UINT64_C(0x102525942535b14a), UINT64_C(0xab59597959f220b2),
UINT64_C(0xd084842a8454ae15), UINT64_C(0xc57272d572b7a7e4), UINT64_C(0xec3939e439d5dd72), UINT64_C(0x164c4c2d4c5a6198),
UINT64_C(0x945e5e655eca3bbc), UINT64_C(0x9f7878fd78e785f0), UINT64_C(0xe53838e038ddd870), UINT64_C(0x988c8c0a8c148605),
UINT64_C(0x17d1d163d1c6b2bf), UINT64_C(0xe4a5a5aea5410b57), UINT64_C(0xa1e2e2afe2434dd9), UINT64_C(0x4e616199612ff8c2),
UINT64_C(0x42b3b3f6b3f1457b), UINT64_C(0x342121842115a542), UINT64_C(0x089c9c4a9c94d625), UINT64_C(0xee1e1e781ef0663c),
UINT64_C(0x6143431143225286), UINT64_C(0xb1c7c73bc776fc93), UINT64_C(0x4ffcfcd7fcb32be5), UINT64_C(0x2404041004201408),
UINT64_C(0xe351515951b208a2), UINT64_C(0x2599995e99bcc72f), UINT64_C(0x226d6da96d4fc4da), UINT64_C(0x650d0d340d68391a),
UINT64_C(0x79fafacffa8335e9), UINT64_C(0x69dfdf5bdfb684a3), UINT64_C(0xa97e7ee57ed79bfc), UINT64_C(0x19242490243db448),
UINT64_C(0xfe3b3bec3bc5d776), UINT64_C(0x9aabab96ab313d4b), UINT64_C(0xf0cece1fce3ed181), UINT64_C(0x9911114411885522),
UINT64_C(0x838f8f068f0c8903), UINT64_C(0x044e4e254e4a6b9c), UINT64_C(0x66b7b7e6b7d15173), UINT64_C(0xe0ebeb8beb0b60cb),
UINT64_C(0xc13c3cf03cfdcc78), UINT64_C(0xfd81813e817cbf1f), UINT64_C(0x4094946a94d4fe35), UINT64_C(0x1cf7f7fbf7eb0cf3),
UINT64_C(0x18b9b9deb9a1676f), UINT64_C(0x8b13134c13985f26), UINT64_C(0x512c2cb02c7d9c58), UINT64_C(0x05d3d36bd3d6b8bb),
UINT64_C(0x8ce7e7bbe76b5cd3), UINT64_C(0x396e6ea56e57cbdc), UINT64_C(0xaac4c437c46ef395), UINT64_C(0x1b03030c03180f06),
UINT64_C(0xdc565645568a13ac), UINT64_C(0x5e44440d441a4988), UINT64_C(0xa07f7fe17fdf9efe), UINT64_C(0x88a9a99ea921374f),
UINT64_C(0x672a2aa82a4d8254), UINT64_C(0x0abbbbd6bbb16d6b), UINT64_C(0x87c1c123c146e29f), UINT64_C(0xf153535153a202a6),
UINT64_C(0x72dcdc57dcae8ba5), UINT64_C(0x530b0b2c0b582716), UINT64_C(0x019d9d4e9d9cd327), UINT64_C(0x2b6c6cad6c47c1d8),
UINT64_C(0xa43131c43195f562), UINT64_C(0xf37474cd7487b9e8), UINT64_C(0x15f6f6fff6e309f1), UINT64_C(0x4c464605460a438c),
UINT64_C(0xa5acac8aac092645), UINT64_C(0xb589891e893c970f), UINT64_C(0xb414145014a04428), UINT64_C(0xbae1e1a3e15b42df),
UINT64_C(0xa616165816b04e2c), UINT64_C(0xf73a3ae83acdd274), UINT64_C(0x066969b9696fd0d2), UINT64_C(0x4109092409482d12),
UINT64_C(0xd77070dd70a7ade0), UINT64_C(0x6fb6b6e2b6d95471), UINT64_C(0x1ed0d067d0ceb7bd), UINT64_C(0xd6eded93ed3b7ec7),
UINT64_C(0xe2cccc17cc2edb85), UINT64_C(0x68424215422a5784), UINT64_C(0x2c98985a98b4c22d), UINT64_C(0xeda4a4aaa4490e55),
UINT64_C(0x752828a0285d8850), UINT64_C(0x865c5c6d5cda31b8), UINT64_C(0x6bf8f8c7f8933fed), UINT64_C(0xc28686228644a411),
},
{
UINT64_C(0x30d818186018c078), UINT64_C(0x462623238c2305af), UINT64_C(0x91b8c6c63fc67ef9), UINT64_C(0xcdfbe8e887e8136f),
UINT64_C(0x13cb878726874ca1), UINT64_C(0x6d11b8b8dab8a962), UINT64_C(0x0209010104010805), UINT64_C(0x9e0d4f4f214f426e),
UINT64_C(0x6c9b3636d836adee), UINT64_C(0x51ffa6a6a2a65904), UINT64_C(0xb90cd2d26fd2debd), UINT64_C(0xf70ef5f5f3f5fb06),
UINT64_C(0xf2967979f979ef80), UINT64_C(0xde306f6fa16f5fce), UINT64_C(0x3f6d91917e91fcef), UINT64_C(0xa4f852525552aa07),
UINT64_C(0xc04760609d6027fd), UINT64_C(0x6535bcbccabc8976), UINT64_C(0x2b379b9b569baccd), UINT64_C(0x018a8e8e028e048c),
UINT64_C(0x5bd2a3a3b6a37115), UINT64_C(0x186c0c0c300c603c), UINT64_C(0xf6847b7bf17bff8a), UINT64_C(0x6a803535d435b5e1),
UINT64_C(0x3af51d1d741de869), UINT64_C(0xddb3e0e0a7e05347), UINT64_C(0xb321d7d77bd7f6ac), UINT64_C(0x999cc2c22fc25eed),
UINT64_C(0x5c432e2eb82e6d96), UINT64_C(0x96294b4b314b627a), UINT64_C(0xe15dfefedffea321), UINT64_C(0xaed5575741578216),
UINT64_C(0x2abd15155415a841), UINT64_C(0xeee87777c1779fb6), UINT64_C(0x6e923737dc37a5eb), UINT64_C(0xd79ee5e5b3e57b56),
UINT64_C(0x23139f9f469f8cd9), UINT64_C(0xfd23f0f0e7f0d317), UINT64_C(0x94204a4a354a6a7f), UINT64_C(0xa944dada4fda9e95),
UINT64_C(0xb0a258587d58fa25), UINT64_C(0x8fcfc9c903c906ca), UINT64_C(0x527c2929a429558d), UINT64_C(0x145a0a0a280a5022),
UINT64_C(0x7f50b1b1feb1e14f), UINT64_C(0x5dc9a0a0baa0691a), UINT64_C(0xd6146b6bb16b7fda), UINT64_C(0x17d985852e855cab),
UINT64_C(0x673cbdbdcebd8173), UINT64_C(0xba8f5d5d695dd234), UINT64_C(0x2090101040108050), UINT64_C(0xf507f4f4f7f4f303),
UINT64_C(0x8bddcbcb0bcb16c0), UINT64_C(0x7cd33e3ef83eedc6), UINT64_C(0x0a2d050514052811), UINT64_C(0xce78676781671fe6),
UINT64_C(0xd597e4e4b7e47353), UINT64_C(0x4e0227279c2725bb), UINT64_C(0x8273414119413258), UINT64_C(0x0ba78b8b168b2c9d),
UINT64_C(0x53f6a7a7a6a75101), UINT64_C(0xfab27d7de97dcf94), UINT64_C(0x374995956e95dcfb), UINT64_C(0xad56d8d847d88e9f),
UINT64_C(0xeb70fbfbcbfb8b30), UINT64_C(0xc1cdeeee9fee2371), UINT64_C(0xf8bb7c7ced7cc791), UINT64_C(0xcc716666856617e3),
UINT64_C(0xa77bdddd53dda68e), UINT64_C(0x2eaf17175c17b84b), UINT64_C(0x8e45474701470246), UINT64_C(0x211a9e9e429e84dc),
UINT64_C(0x89d4caca0fca1ec5), UINT64_C(0x5a582d2db42d7599), UINT64_C(0x632ebfbfc6bf9179), UINT64_C(0x0e3f07071c07381b),
UINT64_C(0x47acadad8ead0123), UINT64_C(0xb4b05a5a755aea2f), UINT64_C(0x1bef838336836cb5), UINT64_C(0x66b63333cc3385ff),
UINT64_C(0xc65c636391633ff2), UINT64_C(0x041202020802100a), UINT64_C(0x4993aaaa92aa3938), UINT64_C(0xe2de7171d971afa8),
UINT64_C(0x8dc6c8c807c80ecf), UINT64_C(0x32d119196419c87d), UINT64_C(0x923b494939497270), UINT64_C(0xaf5fd9d943d9869a),
UINT64_C(0xf931f2f2eff2c31d), UINT64_C(0xdba8e3e3abe34b48), UINT64_C(0xb6b95b5b715be22a), UINT64_C(0x0dbc88881a883492),
UINT64_C(0x293e9a9a529aa4c8), UINT64_C(0x4c0b262698262dbe), UINT64_C(0x64bf3232c8328dfa), UINT64_C(0x7d59b0b0fab0e94a),
UINT64_C(0xcff2e9e983e91b6a), UINT64_C(0x1e770f0f3c0f7833), UINT64_C(0xb733d5d573d5e6a6), UINT64_C(0x1df480803a8074ba),
UINT64_C(0x6127bebec2be997c), UINT64_C(0x87ebcdcd13cd26de), UINT64_C(0x68893434d034bde4), UINT64_C(0x903248483d487a75),
UINT64_C(0xe354ffffdbffab24), UINT64_C(0xf48d7a7af57af78f), UINT64_C(0x3d6490907a90f4ea), UINT64_C(0xbe9d5f5f615fc23e),
UINT64_C(0x403d202080201da0), UINT64_C(0xd00f6868bd6867d5), UINT64_C(0x34ca1a1a681ad072), UINT64_C(0x41b7aeae82ae192c),
UINT64_C(0x757db4b4eab4c95e), UINT64_C(0xa8ce54544d549a19), UINT64_C(0x3b7f93937693ece5), UINT64_C(0x442f222288220daa),
UINT64_C(0xc86364648d6407e9), UINT64_C(0xff2af1f1e3f1db12), UINT64_C(0xe6cc7373d173bfa2), UINT64_C(0x248212124812905a),
UINT64_C(0x807a40401d403a5d), UINT64_C(0x1048080820084028), UINT64_C(0x9b95c3c32bc356e8), UINT64_C(0xc5dfecec97ec337b),
UINT64_C(0xab4ddbdb4bdb9690), UINT64_C(0x5fc0a1a1bea1611f), UINT64_C(0x07918d8d0e8d1c83), UINT64_C(0x7ac83d3df43df5c9),
UINT64_C(0x335b97976697ccf1), UINT64_C(0x0000000000000000), UINT64_C(0x83f9cfcf1bcf36d4), UINT64_C(0x566e2b2bac2b4587),
UINT64_C(0xece17676c57697b3), UINT64_C(0x19e68282328264b0), UINT64_C(0xb128d6d67fd6fea9), UINT64_C(0x36c31b1b6c1bd877),
UINT64_C(0x7774b5b5eeb5c15b), UINT64_C(0x43beafaf86af1129), UINT64_C(0xd41d6a6ab56a77df), UINT64_C(0xa0ea50505d50ba0d),
UINT64_C(0x8a5745450945124c), UINT64_C(0xfb38f3f3ebf3cb18), UINT64_C(0x60ad3030c0309df0), UINT64_C(0xc3c4efef9bef2b74),
UINT64_C(0x7eda3f3ffc3fe5c3), UINT64_C(0xaac755554955921c), UINT64_C(0x59dba2a2b2a27910), UINT64_C(0xc9e9eaea8fea0365),
UINT64_C(0xca6a656589650fec), UINT64_C(0x6903babad2bab968), UINT64_C(0x5e4a2f2fbc2f6593), UINT64_C(0x9d8ec0c027c04ee7),
UINT64_C(0xa160dede5fdebe81), UINT64_C(0x38fc1c1c701ce06c), UINT64_C(0xe746fdfdd3fdbb2e), UINT64_C(0x9a1f4d4d294d5264),
UINT64_C(0x397692927292e4e0), UINT64_C(0xeafa7575c9758fbc), UINT64_C(0x0c3606061806301e), UINT64_C(0x09ae8a8a128a2498),
UINT64_C(0x794bb2b2f2b2f940), UINT64_C(0xd185e6e6bfe66359), UINT64_C(0x1c7e0e0e380e7036), UINT64_C(0x3ee71f1f7c1ff863),
UINT64_C(0xc4556262956237f7), UINT64_C(0xb53ad4d477d4eea3), UINT64_C(0x4d81a8a89aa82932), UINT64_C(0x315296966296c4f4),
UINT64_C(0xef62f9f9c3f99b3a), UINT64_C(0x97a3c5c533c566f6), UINT64_C(0x4a102525942535b1), UINT64_C(0xb2ab59597959f220),
UINT64_C(0x15d084842a8454ae), UINT64_C(0xe4c57272d572b7a7), UINT64_C(0x72ec3939e439d5dd), UINT64_C(0x98164c4c2d4c5a61),
UINT64_C(0xbc945e5e655eca3b), UINT64_C(0xf09f7878fd78e785), UINT64_C(0x70e53838e038ddd8), UINT64_C(0x05988c8c0a8c1486),
UINT64_C(0xbf17d1d163d1c6b2), UINT64_C(0x57e4a5a5aea5410b), UINT64_C(0xd9a1e2e2afe2434d), UINT64_C(0xc24e616199612ff8),
UINT64_C(0x7b42b3b3f6b3f145), UINT64_C(0x42342121842115a5), UINT64_C(0x25089c9c4a9c94d6), UINT64_C(0x3cee1e1e781ef066),
UINT64_C(0x8661434311432252), UINT64_C(0x93b1c7c73bc776fc), UINT64_C(0xe54ffcfcd7fcb32b), UINT64_C(0x0824040410042014),
UINT64_C(0xa2e351515951b208), UINT64_C(0x2f2599995e99bcc7), UINT64_C(0xda226d6da96d4fc4), UINT64_C(0x1a650d0d340d6839),
UINT64_C(0xe979fafacffa8335), UINT64_C(0xa369dfdf5bdfb684), UINT64_C(0xfca97e7ee57ed79b), UINT64_C(0x4819242490243db4),
UINT64_C(0x76fe3b3bec3bc5d7), UINT64_C(0x4b9aabab96ab313d), UINT64_C(0x81f0cece1fce3ed1), UINT64_C(0x2299111144118855),
UINT64_C(0x03838f8f068f0c89), UINT64_C(0x9c044e4e254e4a6b), UINT64_C(0x7366b7b7e6b7d151), UINT64_C(0xcbe0ebeb8beb0b60),
UINT64_C(0x78c13c3cf03cfdcc), UINT64_C(0x1ffd81813e817cbf), UINT64_C(0x354094946a94d4fe), UINT64_C(0xf31cf7f7fbf7eb0c),
UINT64_C(0x6f18b9b9deb9a167), UINT64_C(0x268b13134c13985f), UINT64_C(0x58512c2cb02c7d9c), UINT64_C(0xbb05d3d36bd3d6b8),
UINT64_C(0xd38ce7e7bbe76b5c), UINT64_C(0xdc396e6ea56e57cb), UINT64_C(0x95aac4c437c46ef3), UINT64_C(0x061b03030c03180f),
UINT64_C(0xacdc565645568a13), UINT64_C(0x885e44440d441a49), UINT64_C(0xfea07f7fe17fdf9e), UINT64_C(0x4f88a9a99ea92137),
UINT64_C(0x54672a2aa82a4d82), UINT64_C(0x6b0abbbbd6bbb16d), UINT64_C(0x9f87c1c123c146e2), UINT64_C(0xa6f153535153a202),
UINT64_C(0xa572dcdc57dcae8b), UINT64_C(0x16530b0b2c0b5827), UINT64_C(0x27019d9d4e9d9cd3), UINT64_C(0xd82b6c6cad6c47c1),
UINT64_C(0x62a43131c43195f5), UINT64_C(0xe8f37474cd7487b9), UINT64_C(0xf115f6f6fff6e309), UINT64_C(0x8c4c464605460a43),
UINT64_C(0x45a5acac8aac0926), UINT64_C(0x0fb589891e893c97), UINT64_C(0x28b414145014a044), UINT64_C(0xdfbae1e1a3e15b42),
UINT64_C(0x2ca616165816b04e), UINT64_C(0x74f73a3ae83acdd2), UINT64_C(0xd2066969b9696fd0), UINT64_C(0x124109092409482d),
UINT64_C(0xe0d77070dd70a7ad), UINT64_C(0x716fb6b6e2b6d954), UINT64_C(0xbd1ed0d067d0ceb7), UINT64_C(0xc7d6eded93ed3b7e),
UINT64_C(0x85e2cccc17cc2edb), UINT64_C(0x8468424215422a57), UINT64_C(0x2d2c98985a98b4c2), UINT64_C(0x55eda4a4aaa4490e),
UINT64_C(0x50752828a0285d88), UINT64_C(0xb8865c5c6d5cda31), UINT64_C(0xed6bf8f8c7f8933f), UINT64_C(0x11c28686228644a4),
},
{
UINT64_C(0x7830d818186018c0), UINT64_C(0xaf462623238c2305), UINT64_C(0xf991b8c6c63fc67e), UINT64_C(0x6fcdfbe8e887e813),
UINT64_C(0xa113cb878726874c), UINT64_C(0x626d11b8b8dab8a9), UINT64_C(0x0502090101040108), UINT64_C(0x6e9e0d4f4f214f42),
UINT64_C(0xee6c9b3636d836ad), UINT64_C(0x0451ffa6a6a2a659), UINT64_C(0xbdb90cd2d26fd2de), UINT64_C(0x06f70ef5f5f3f5fb),
UINT64_C(0x80f2967979f979ef), UINT64_C(0xcede306f6fa16f5f), UINT64_C(0xef3f6d91917e91fc), UINT64_C(0x07a4f852525552aa),
UINT64_C(0xfdc04760609d6027), UINT64_C(0x766535bcbccabc89), UINT64_C(0xcd2b379b9b569bac), UINT64_C(0x8c018a8e8e028e04),
UINT64_C(0x155bd2a3a3b6a371), UINT64_C(0x3c186c0c0c300c60), UINT64_C(0x8af6847b7bf17bff), UINT64_C(0xe16a803535d435b5),
UINT64_C(0x693af51d1d741de8), UINT64_C(0x47ddb3e0e0a7e053), UINT64_C(0xacb321d7d77bd7f6), UINT64_C(0xed999cc2c22fc25e),
UINT64_C(0x965c432e2eb82e6d), UINT64_C(0x7a96294b4b314b62), UINT64_C(0x21e15dfefedffea3), UINT64_C(0x16aed55757415782),
UINT64_C(0x412abd15155415a8), UINT64_C(0xb6eee87777c1779f), UINT64_C(0xeb6e923737dc37a5), UINT64_C(0x56d79ee5e5b3e57b),
UINT64_C(0xd923139f9f469f8c), UINT64_C(0x17fd23f0f0e7f0d3), UINT64_C(0x7f94204a4a354a6a), UINT64_C(0x95a944dada4fda9e),
UINT64_C(0x25b0a258587d58fa), UINT64_C(0xca8fcfc9c903c906), UINT64_C(0x8d527c2929a42955), UINT64_C(0x22145a0a0a280a50),
UINT64_C(0x4f7f50b1b1feb1e1), UINT64_C(0x1a5dc9a0a0baa069), UINT64_C(0xdad6146b6bb16b7f), UINT64_C(0xab17d985852e855c),
UINT64_C(0x73673cbdbdcebd81), UINT64_C(0x34ba8f5d5d695dd2), UINT64_C(0x5020901010401080), UINT64_C(0x03f507f4f4f7f4f3),
UINT64_C(0xc08bddcbcb0bcb16), UINT64_C(0xc67cd33e3ef83eed), UINT64_C(0x110a2d0505140528), UINT64_C(0xe6ce78676781671f),
UINT64_C(0x53d597e4e4b7e473), UINT64_C(0xbb4e0227279c2725), UINT64_C(0x5882734141194132), UINT64_C(0x9d0ba78b8b168b2c),
UINT64_C(0x0153f6a7a7a6a751), UINT64_C(0x94fab27d7de97dcf), UINT64_C(0xfb374995956e95dc), UINT64_C(0x9fad56d8d847d88e),
UINT64_C(0x30eb70fbfbcbfb8b), UINT64_C(0x71c1cdeeee9fee23), UINT64_C(0x91f8bb7c7ced7cc7), UINT64_C(0xe3cc716666856617),
UINT64_C(0x8ea77bdddd53dda6), UINT64_C(0x4b2eaf17175c17b8), UINT64_C(0x468e454747014702), UINT64_C(0xdc211a9e9e429e84),
UINT64_C(0xc589d4caca0fca1e), UINT64_C(0x995a582d2db42d75), UINT64_C(0x79632ebfbfc6bf91), UINT64_C(0x1b0e3f07071c0738),
UINT64_C(0x2347acadad8ead01), UINT64_C(0x2fb4b05a5a755aea), UINT64_C(0xb51bef838336836c), UINT64_C(0xff66b63333cc3385),
UINT64_C(0xf2c65c636391633f), UINT64_C(0x0a04120202080210), UINT64_C(0x384993aaaa92aa39), UINT64_C(0xa8e2de7171d971af),
UINT64_C(0xcf8dc6c8c807c80e), UINT64_C(0x7d32d119196419c8), UINT64_C(0x70923b4949394972), UINT64_C(0x9aaf5fd9d943d986),
UINT64_C(0x1df931f2f2eff2c3), UINT64_C(0x48dba8e3e3abe34b), UINT64_C(0x2ab6b95b5b715be2), UINT64_C(0x920dbc88881a8834),
UINT64_C(0xc8293e9a9a529aa4), UINT64_C(0xbe4c0b262698262d), UINT64_C(0xfa64bf3232c8328d), UINT64_C(0x4a7d59b0b0fab0e9),
UINT64_C(0x6acff2e9e983e91b), UINT64_C(0x331e770f0f3c0f78), UINT64_C(0xa6b733d5d573d5e6), UINT64_C(0xba1df480803a8074),
UINT64_C(0x7c6127bebec2be99), UINT64_C(0xde87ebcdcd13cd26), UINT64_C(0xe468893434d034bd), UINT64_C(0x75903248483d487a),
UINT64_C(0x24e354ffffdbffab), UINT64_C(0x8ff48d7a7af57af7), UINT64_C(0xea3d6490907a90f4), UINT64_C(0x3ebe9d5f5f615fc2),
UINT64_C(0xa0403d202080201d), UINT64_C(0xd5d00f6868bd6867), UINT64_C(0x7234ca1a1a681ad0), UINT64_C(0x2c41b7aeae82ae19),
UINT64_C(0x5e757db4b4eab4c9), UINT64_C(0x19a8ce54544d549a), UINT64_C(0xe53b7f93937693ec), UINT64_C(0xaa442f222288220d),
UINT64_C(0xe9c86364648d6407), UINT64_C(0x12ff2af1f1e3f1db), UINT64_C(0xa2e6cc7373d173bf), UINT64_C(0x5a24821212481290),
UINT64_C(0x5d807a40401d403a), UINT64_C(0x2810480808200840), UINT64_C(0xe89b95c3c32bc356), UINT64_C(0x7bc5dfecec97ec33),
UINT64_C(0x90ab4ddbdb4bdb96), UINT64_C(0x1f5fc0a1a1bea161), UINT64_C(0x8307918d8d0e8d1c), UINT64_C(0xc97ac83d3df43df5),
UINT64_C(0xf1335b97976697cc), UINT64_C(0x0000000000000000), UINT64_C(0xd483f9cfcf1bcf36), UINT64_C(0x87566e2b2bac2b45),
UINT64_C(0xb3ece17676c57697), UINT64_C(0xb019e68282328264), UINT64_C(0xa9b128d6d67fd6fe), UINT64_C(0x7736c31b1b6c1bd8),
UINT64_C(0x5b7774b5b5eeb5c1), UINT64_C(0x2943beafaf86af11), UINT64_C(0xdfd41d6a6ab56a77), UINT64_C(0x0da0ea50505d50ba),
UINT64_C(0x4c8a574545094512), UINT64_C(0x18fb38f3f3ebf3cb), UINT64_C(0xf060ad3030c0309d), UINT64_C(0x74c3c4efef9bef2b),
UINT64_C(0xc37eda3f3ffc3fe5), UINT64_C(0x1caac75555495592), UINT64_C(0x1059dba2a2b2a279), UINT64_C(0x65c9e9eaea8fea03),
UINT64_C(0xecca6a656589650f), UINT64_C(0x686903babad2bab9), UINT64_C(0x935e4a2f2fbc2f65), UINT64_C(0xe79d8ec0c027c04e),
UINT64_C(0x81a160dede5fdebe), UINT64_C(0x6c38fc1c1c701ce0), UINT64_C(0x2ee746fdfdd3fdbb), UINT64_C(0x649a1f4d4d294d52),
UINT64_C(0xe0397692927292e4), UINT64_C(0xbceafa7575c9758f), UINT64_C(0x1e0c360606180630), UINT64_C(0x9809ae8a8a128a24),
UINT64_C(0x40794bb2b2f2b2f9), UINT64_C(0x59d185e6e6bfe663), UINT64_C(0x361c7e0e0e380e70), UINT64_C(0x633ee71f1f7c1ff8),
UINT64_C(0xf7c4556262956237), UINT64_C(0xa3b53ad4d477d4ee), UINT64_C(0x324d81a8a89aa829), UINT64_C(0xf4315296966296c4),
UINT64_C(0x3aef62f9f9c3f99b), UINT64_C(0xf697a3c5c533c566), UINT64_C(0xb14a102525942535), UINT64_C(0x20b2ab59597959f2),
UINT64_C(0xae15d084842a8454), UINT64_C(0xa7e4c57272d572b7), UINT64_C(0xdd72ec3939e439d5), UINT64_C(0x6198164c4c2d4c5a),
UINT64_C(0x3bbc945e5e655eca), UINT64_C(0x85f09f7878fd78e7), UINT64_C(0xd870e53838e038dd), UINT64_C(0x8605988c8c0a8c14),
UINT64_C(0xb2bf17d1d163d1c6), UINT64_C(0x0b57e4a5a5aea541), UINT64_C(0x4dd9a1e2e2afe243), UINT64_C(0xf8c24e616199612f),
UINT64_C(0x457b42b3b3f6b3f1), UINT64_C(0xa542342121842115), UINT64_C(0xd625089c9c4a9c94), UINT64_C(0x663cee1e1e781ef0),
UINT64_C(0x5286614343114322), UINT64_C(0xfc93b1c7c73bc776), UINT64_C(0x2be54ffcfcd7fcb3), UINT64_C(0x1408240404100420),
UINT64_C(0x08a2e351515951b2), UINT64_C(0xc72f2599995e99bc), UINT64_C(0xc4da226d6da96d4f), UINT64_C(0x391a650d0d340d68),
UINT64_C(0x35e979fafacffa83), UINT64_C(0x84a369dfdf5bdfb6), UINT64_C(0x9bfca97e7ee57ed7), UINT64_C(0xb44819242490243d),
UINT64_C(0xd776fe3b3bec3bc5), UINT64_C(0x3d4b9aabab96ab31), UINT64_C(0xd181f0cece1fce3e), UINT64_C(0x5522991111441188),
UINT64_C(0x8903838f8f068f0c), UINT64_C(0x6b9c044e4e254e4a), UINT64_C(0x517366b7b7e6b7d1), UINT64_C(0x60cbe0ebeb8beb0b),
UINT64_C(0xcc78c13c3cf03cfd), UINT64_C(0xbf1ffd81813e817c), UINT64_C(0xfe354094946a94d4), UINT64_C(0x0cf31cf7f7fbf7eb),
UINT64_C(0x676f18b9b9deb9a1), UINT64_C(0x5f268b13134c1398), UINT64_C(0x9c58512c2cb02c7d), UINT64_C(0xb8bb05d3d36bd3d6),
UINT64_C(0x5cd38ce7e7bbe76b), UINT64_C(0xcbdc396e6ea56e57), UINT64_C(0xf395aac4c437c46e), UINT64_C(0x0f061b03030c0318),
UINT64_C(0x13acdc565645568a), UINT64_C(0x49885e44440d441a), UINT64_C(0x9efea07f7fe17fdf), UINT64_C(0x374f88a9a99ea921),
UINT64_C(0x8254672a2aa82a4d), UINT64_C(0x6d6b0abbbbd6bbb1), UINT64_C(0xe29f87c1c123c146), UINT64_C(0x02a6f153535153a2),
UINT64_C(0x8ba572dcdc57dcae), UINT64_C(0x2716530b0b2c0b58), UINT64_C(0xd327019d9d4e9d9c), UINT64_C(0xc1d82b6c6cad6c47),
UINT64_C(0xf562a43131c43195), UINT64_C(0xb9e8f37474cd7487), UINT64_C(0x09f115f6f6fff6e3), UINT64_C(0x438c4c464605460a),
UINT64_C(0x2645a5acac8aac09), UINT64_C(0x970fb589891e893c), UINT64_C(0x4428b414145014a0), UINT64_C(0x42dfbae1e1a3e15b),
UINT64_C(0x4e2ca616165816b0), UINT64_C(0xd274f73a3ae83acd), UINT64_C(0xd0d2066969b9696f), UINT64_C(0x2d12410909240948),
UINT64_C(0xade0d77070dd70a7), UINT64_C(0x54716fb6b6e2b6d9), UINT64_C(0xb7bd1ed0d067d0ce), UINT64_C(0x7ec7d6eded93ed3b),
UINT64_C(0xdb85e2cccc17cc2e), UINT64_C(0x578468424215422a), UINT64_C(0xc22d2c98985a98b4), UINT64_C(0x0e55eda4a4aaa449),
UINT64_C(0x8850752828a0285d), UINT64_C(0x31b8865c5c6d5cda), UINT64_C(0x3fed6bf8f8c7f893), UINT64_C(0xa411c28686228644),
},
{
UINT64_C(0xc07830d818186018), UINT64_C(0x05af462623238c23), UINT64_C(0x7ef991b8c6c63fc6), UINT64_C(0x136fcdfbe8e887e8),
UINT64_C(0x4ca113cb87872687), UINT64_C(0xa9626d11b8b8dab8), UINT64_C(0x0805020901010401), UINT64_C(0x426e9e0d4f4f214f),
UINT64_C(0xadee6c9b3636d836), UINT64_C(0x590451ffa6a6a2a6), UINT64_C(0xdebdb90cd2d26fd2), UINT64_C(0xfb06f70ef5f5f3f5),
UINT64_C(0xef80f2967979f979), UINT64_C(0x5fcede306f6fa16f), UINT64_C(0xfcef3f6d91917e91), UINT64_C(0xaa07a4f852525552),
UINT64_C(0x27fdc04760609d60), UINT64_C(0x89766535bcbccabc), UINT64_C(0xaccd2b379b9b569b), UINT64_C(0x048c018a8e8e028e),
UINT64_C(0x71155bd2a3a3b6a3), UINT64_C(0x603c186c0c0c300c), UINT64_C(0xff8af6847b7bf17b), UINT64_C(0xb5e16a803535d435),
UINT64_C(0xe8693af51d1d741d), UINT64_C(0x5347ddb3e0e0a7e0), UINT64_C(0xf6acb321d7d77bd7), UINT64_C(0x5eed999cc2c22fc2),
UINT64_C(0x6d965c432e2eb82e), UINT64_C(0x627a96294b4b314b), UINT64_C(0xa321e15dfefedffe), UINT64_C(0x8216aed557574157),
UINT64_C(0xa8412abd15155415), UINT64_C(0x9fb6eee87777c177), UINT64_C(0xa5eb6e923737dc37), UINT64_C(0x7b56d79ee5e5b3e5),
UINT64_C(0x8cd923139f9f469f), UINT64_C(0xd317fd23f0f0e7f0), UINT64_C(0x6a7f94204a4a354a), UINT64_C(0x9e95a944dada4fda),
UINT64_C(0xfa25b0a258587d58), UINT64_C(0x06ca8fcfc9c903c9), UINT64_C(0x558d527c2929a429), UINT64_C(0x5022145a0a0a280a),
UINT64_C(0xe14f7f50b1b1feb1), UINT64_C(0x691a5dc9a0a0baa0), UINT64_C(0x7fdad6146b6bb16b), UINT64_C(0x5cab17d985852e85),
UINT64_C(0x8173673cbdbdcebd), UINT64_C(0xd234ba8f5d5d695d), UINT64_C(0x8050209010104010), UINT64_C(0xf303f507f4f4f7f4),
UINT64_C(0x16c08bddcbcb0bcb), UINT64_C(0xedc67cd33e3ef83e), UINT64_C(0x28110a2d05051405), UINT64_C(0x1fe6ce7867678167),
UINT64_C(0x7353d597e4e4b7e4), UINT64_C(0x25bb4e0227279c27), UINT64_C(0x3258827341411941), UINT64_C(0x2c9d0ba78b8b168b),
UINT64_C(0x510153f6a7a7a6a7), UINT64_C(0xcf94fab27d7de97d), UINT64_C(0xdcfb374995956e95), UINT64_C(0x8e9fad56d8d847d8),
UINT64_C(0x8b30eb70fbfbcbfb), UINT64_C(0x2371c1cdeeee9fee), UINT64_C(0xc791f8bb7c7ced7c), UINT64_C(0x17e3cc7166668566),
UINT64_C(0xa68ea77bdddd53dd), UINT64_C(0xb84b2eaf17175c17), UINT64_C(0x02468e4547470147), UINT64_C(0x84dc211a9e9e429e),
UINT64_C(0x1ec589d4caca0fca), UINT64_C(0x75995a582d2db42d), UINT64_C(0x9179632ebfbfc6bf), UINT64_C(0x381b0e3f07071c07),
UINT64_C(0x012347acadad8ead), UINT64_C(0xea2fb4b05a5a755a), UINT64_C(0x6cb51bef83833683), UINT64_C(0x85ff66b63333cc33),
UINT64_C(0x3ff2c65c63639163), UINT64_C(0x100a041202020802), UINT64_C(0x39384993aaaa92aa), UINT64_C(0xafa8e2de7171d971),
UINT64_C(0x0ecf8dc6c8c807c8), UINT64_C(0xc87d32d119196419), UINT64_C(0x7270923b49493949), UINT64_C(0x869aaf5fd9d943d9),
UINT64_C(0xc31df931f2f2eff2), UINT64_C(0x4b48dba8e3e3abe3), UINT64_C(0xe22ab6b95b5b715b), UINT64_C(0x34920dbc88881a88),
UINT64_C(0xa4c8293e9a9a529a), UINT64_C(0x2dbe4c0b26269826), UINT64_C(0x8dfa64bf3232c832), UINT64_C(0xe94a7d59b0b0fab0),
UINT64_C(0x1b6acff2e9e983e9), UINT64_C(0x78331e770f0f3c0f), UINT64_C(0xe6a6b733d5d573d5), UINT64_C(0x74ba1df480803a80),
UINT64_C(0x997c6127bebec2be), UINT64_C(0x26de87ebcdcd13cd), UINT64_C(0xbde468893434d034), UINT64_C(0x7a75903248483d48),
UINT64_C(0xab24e354ffffdbff), UINT64_C(0xf78ff48d7a7af57a), UINT64_C(0xf4ea3d6490907a90), UINT64_C(0xc23ebe9d5f5f615f),
UINT64_C(0x1da0403d20208020), UINT64_C(0x67d5d00f6868bd68), UINT64_C(0xd07234ca1a1a681a), UINT64_C(0x192c41b7aeae82ae),
UINT64_C(0xc95e757db4b4eab4), UINT64_C(0x9a19a8ce54544d54), UINT64_C(0xece53b7f93937693), UINT64_C(0x0daa442f22228822),
UINT64_C(0x07e9c86364648d64), UINT64_C(0xdb12ff2af1f1e3f1), UINT64_C(0xbfa2e6cc7373d173), UINT64_C(0x905a248212124812),
UINT64_C(0x3a5d807a40401d40), UINT64_C(0x4028104808082008), UINT64_C(0x56e89b95c3c32bc3), UINT64_C(0x337bc5dfecec97ec),
UINT64_C(0x9690ab4ddbdb4bdb), UINT64_C(0x611f5fc0a1a1bea1), UINT64_C(0x1c8307918d8d0e8d), UINT64_C(0xf5c97ac83d3df43d),
UINT64_C(0xccf1335b97976697), UINT64_C(0x0000000000000000), UINT64_C(0x36d483f9cfcf1bcf), UINT64_C(0x4587566e2b2bac2b),
UINT64_C(0x97b3ece17676c576), UINT64_C(0x64b019e682823282), UINT64_C(0xfea9b128d6d67fd6), UINT64_C(0xd87736c31b1b6c1b),
UINT64_C(0xc15b7774b5b5eeb5), UINT64_C(0x112943beafaf86af), UINT64_C(0x77dfd41d6a6ab56a), UINT64_C(0xba0da0ea50505d50),
UINT64_C(0x124c8a5745450945), UINT64_C(0xcb18fb38f3f3ebf3), UINT64_C(0x9df060ad3030c030), UINT64_C(0x2b74c3c4efef9bef),
UINT64_C(0xe5c37eda3f3ffc3f), UINT64_C(0x921caac755554955), UINT64_C(0x791059dba2a2b2a2), UINT64_C(0x0365c9e9eaea8fea),
UINT64_C(0x0fecca6a65658965), UINT64_C(0xb9686903babad2ba), UINT64_C(0x65935e4a2f2fbc2f), UINT64_C(0x4ee79d8ec0c027c0),
UINT64_C(0xbe81a160dede5fde), UINT64_C(0xe06c38fc1c1c701c), UINT64_C(0xbb2ee746fdfdd3fd), UINT64_C(0x52649a1f4d4d294d),
UINT64_C(0xe4e0397692927292), UINT64_C(0x8fbceafa7575c975), UINT64_C(0x301e0c3606061806), UINT64_C(0x249809ae8a8a128a),
UINT64_C(0xf940794bb2b2f2b2), UINT64_C(0x6359d185e6e6bfe6), UINT64_C(0x70361c7e0e0e380e), UINT64_C(0xf8633ee71f1f7c1f),
UINT64_C(0x37f7c45562629562), UINT64_C(0xeea3b53ad4d477d4), UINT64_C(0x29324d81a8a89aa8), UINT64_C(0xc4f4315296966296),
UINT64_C(0x9b3aef62f9f9c3f9), UINT64_C(0x66f697a3c5c533c5), UINT64_C(0x35b14a1025259425), UINT64_C(0xf220b2ab59597959),
UINT64_C(0x54ae15d084842a84), UINT64_C(0xb7a7e4c57272d572), UINT64_C(0xd5dd72ec3939e439), UINT64_C(0x5a6198164c4c2d4c),
UINT64_C(0xca3bbc945e5e655e), UINT64_C(0xe785f09f7878fd78), UINT64_C(0xddd870e53838e038), UINT64_C(0x148605988c8c0a8c),
UINT64_C(0xc6b2bf17d1d163d1), UINT64_C(0x410b57e4a5a5aea5), UINT64_C(0x434dd9a1e2e2afe2), UINT64_C(0x2ff8c24e61619961),
UINT64_C(0xf1457b42b3b3f6b3), UINT64_C(0x15a5423421218421), UINT64_C(0x94d625089c9c4a9c), UINT64_C(0xf0663cee1e1e781e),
UINT64_C(0x2252866143431143), UINT64_C(0x76fc93b1c7c73bc7), UINT64_C(0xb32be54ffcfcd7fc), UINT64_C(0x2014082404041004),
UINT64_C(0xb208a2e351515951), UINT64_C(0xbcc72f2599995e99), UINT64_C(0x4fc4da226d6da96d), UINT64_C(0x68391a650d0d340d),
UINT64_C(0x8335e979fafacffa), UINT64_C(0xb684a369dfdf5bdf), UINT64_C(0xd79bfca97e7ee57e), UINT64_C(0x3db4481924249024),
UINT64_C(0xc5d776fe3b3bec3b), UINT64_C(0x313d4b9aabab96ab), UINT64_C(0x3ed181f0cece1fce), UINT64_C(0x8855229911114411),
UINT64_C(0x0c8903838f8f068f), UINT64_C(0x4a6b9c044e4e254e), UINT64_C(0xd1517366b7b7e6b7), UINT64_C(0x0b60cbe0ebeb8beb),
UINT64_C(0xfdcc78c13c3cf03c), UINT64_C(0x7cbf1ffd81813e81), UINT64_C(0xd4fe354094946a94), UINT64_C(0xeb0cf31cf7f7fbf7),
UINT64_C(0xa1676f18b9b9deb9), UINT64_C(0x985f268b13134c13), UINT64_C(0x7d9c58512c2cb02c), UINT64_C(0xd6b8bb05d3d36bd3),
UINT64_C(0x6b5cd38ce7e7bbe7), UINT64_C(0x57cbdc396e6ea56e), UINT64_C(0x6ef395aac4c437c4), UINT64_C(0x180f061b03030c03),
UINT64_C(0x8a13acdc56564556), UINT64_C(0x1a49885e44440d44), UINT64_C(0xdf9efea07f7fe17f), UINT64_C(0x21374f88a9a99ea9),
UINT64_C(0x4d8254672a2aa82a), UINT64_C(0xb16d6b0abbbbd6bb), UINT64_C(0x46e29f87c1c123c1), UINT64_C(0xa202a6f153535153),
UINT64_C(0xae8ba572dcdc57dc), UINT64_C(0x582716530b0b2c0b), UINT64_C(0x9cd327019d9d4e9d), UINT64_C(0x47c1d82b6c6cad6c),
UINT64_C(0x95f562a43131c431), UINT64_C(0x87b9e8f37474cd74), UINT64_C(0xe309f115f6f6fff6), UINT64_C(0x0a438c4c46460546),
UINT64_C(0x092645a5acac8aac), UINT64_C(0x3c970fb589891e89), UINT64_C(0xa04428b414145014), UINT64_C(0x5b42dfbae1e1a3e1),
UINT64_C(0xb04e2ca616165816), UINT64_C(0xcdd274f73a3ae83a), UINT64_C(0x6fd0d2066969b969), UINT64_C(0x482d124109092409),
UINT64_C(0xa7ade0d77070dd70), UINT64_C(0xd954716fb6b6e2b6), UINT64_C(0xceb7bd1ed0d067d0), UINT64_C(0x3b7ec7d6eded93ed),
UINT64_C(0x2edb85e2cccc17cc), UINT64_C(0x2a57846842421542), UINT64_C(0xb4c22d2c98985a98), UINT64_C(0x490e55eda4a4aaa4),
UINT64_C(0x5d8850752828a028), UINT64_C(0xda31b8865c5c6d5c), UINT64_C(0x933fed6bf8f8c7f8), UINT64_C(0x44a411c286862286),
},
{
UINT64_C(0x18c07830d8181860), UINT64_C(0x2305af462623238c), UINT64_C(0xc67ef991b8c6c63f), UINT64_C(0xe8136fcdfbe8e887),
UINT64_C(0x874ca113cb878726), UINT64_C(0xb8a9626d11b8b8da), UINT64_C(0x0108050209010104), UINT64_C(0x4f426e9e0d4f4f21),
UINT64_C(0x36adee6c9b3636d8), UINT64_C(0xa6590451ffa6a6a2), UINT64_C(0xd2debdb90cd2d26f), UINT64_C(0xf5fb06f70ef5f5f3),
UINT64_C(0x79ef80f2967979f9), UINT64_C(0x6f5fcede306f6fa1), UINT64_C(0x91fcef3f6d91917e), UINT64_C(0x52aa07a4f8525255),
UINT64_C(0x6027fdc04760609d), UINT64_C(0xbc89766535bcbcca), UINT64_C(0x9baccd2b379b9b56), UINT64_C(0x8e048c018a8e8e02),
UINT64_C(0xa371155bd2a3a3b6), UINT64_C(0x0c603c186c0c0c30), UINT64_C(0x7bff8af6847b7bf1), UINT64_C(0x35b5e16a803535d4),
UINT64_C(0x1de8693af51d1d74), UINT64_C(0xe05347ddb3e0e0a7), UINT64_C(0xd7f6acb321d7d77b), UINT64_C(0xc25eed999cc2c22f),
UINT64_C(0x2e6d965c432e2eb8), UINT64_C(0x4b627a96294b4b31), UINT64_C(0xfea321e15dfefedf), UINT64_C(0x578216aed5575741),
UINT64_C(0x15a8412abd151554), UINT64_C(0x779fb6eee87777c1), UINT64_C(0x37a5eb6e923737dc), UINT64_C(0xe57b56d79ee5e5b3),
UINT64_C(0x9f8cd923139f9f46), UINT64_C(0xf0d317fd23f0f0e7), UINT64_C(0x4a6a7f94204a4a35), UINT64_C(0xda9e95a944dada4f),
UINT64_C(0x58fa25b0a258587d), UINT64_C(0xc906ca8fcfc9c903), UINT64_C(0x29558d527c2929a4), UINT64_C(0x0a5022145a0a0a28),
UINT64_C(0xb1e14f7f50b1b1fe), UINT64_C(0xa0691a5dc9a0a0ba), UINT64_C(0x6b7fdad6146b6bb1), UINT64_C(0x855cab17d985852e),
UINT64_C(0xbd8173673cbdbdce), UINT64_C(0x5dd234ba8f5d5d69), UINT64_C(0x1080502090101040), UINT64_C(0xf4f303f507f4f4f7),
UINT64_C(0xcb16c08bddcbcb0b), UINT64_C(0x3eedc67cd33e3ef8), UINT64_C(0x0528110a2d050514), UINT64_C(0x671fe6ce78676781),
UINT64_C(0xe47353d597e4e4b7), UINT64_C(0x2725bb4e0227279c), UINT64_C(0x4132588273414119), UINT64_C(0x8b2c9d0ba78b8b16),
UINT64_C(0xa7510153f6a7a7a6), UINT64_C(0x7dcf94fab27d7de9), UINT64_C(0x95dcfb374995956e), UINT64_C(0xd88e9fad56d8d847),
UINT64_C(0xfb8b30eb70fbfbcb), UINT64_C(0xee2371c1cdeeee9f), UINT64_C(0x7cc791f8bb7c7ced), UINT64_C(0x6617e3cc71666685),
UINT64_C(0xdda68ea77bdddd53), UINT64_C(0x17b84b2eaf17175c), UINT64_C(0x4702468e45474701), UINT64_C(0x9e84dc211a9e9e42),
UINT64_C(0xca1ec589d4caca0f), UINT64_C(0x2d75995a582d2db4), UINT64_C(0xbf9179632ebfbfc6), UINT64_C(0x07381b0e3f07071c),
UINT64_C(0xad012347acadad8e), UINT64_C(0x5aea2fb4b05a5a75), UINT64_C(0x836cb51bef838336), UINT64_C(0x3385ff66b63333cc),
UINT64_C(0x633ff2c65c636391), UINT64_C(0x02100a0412020208), UINT64_C(0xaa39384993aaaa92), UINT64_C(0x71afa8e2de7171d9),
UINT64_C(0xc80ecf8dc6c8c807), UINT64_C(0x19c87d32d1191964), UINT64_C(0x497270923b494939), UINT64_C(0xd9869aaf5fd9d943),
UINT64_C(0xf2c31df931f2f2ef), UINT64_C(0xe34b48dba8e3e3ab), UINT64_C(0x5be22ab6b95b5b71), UINT64_C(0x8834920dbc88881a),
UINT64_C(0x9aa4c8293e9a9a52), UINT64_C(0x262dbe4c0b262698), UINT64_C(0x328dfa64bf3232c8), UINT64_C(0xb0e94a7d59b0b0fa),
UINT64_C(0xe91b6acff2e9e983), UINT64_C(0x0f78331e770f0f3c), UINT64_C(0xd5e6a6b733d5d573), UINT64_C(0x8074ba1df480803a),
UINT64_C(0xbe997c6127bebec2), UINT64_C(0xcd26de87ebcdcd13), UINT64_C(0x34bde468893434d0), UINT64_C(0x487a75903248483d),
UINT64_C(0xffab24e354ffffdb), UINT64_C(0x7af78ff48d7a7af5), UINT64_C(0x90f4ea3d6490907a), UINT64_C(0x5fc23ebe9d5f5f61),
UINT64_C(0x201da0403d202080), UINT64_C(0x6867d5d00f6868bd), UINT64_C(0x1ad07234ca1a1a68), UINT64_C(0xae192c41b7aeae82),
UINT64_C(0xb4c95e757db4b4ea), UINT64_C(0x549a19a8ce54544d), UINT64_C(0x93ece53b7f939376), UINT64_C(0x220daa442f222288),
UINT64_C(0x6407e9c86364648d), UINT64_C(0xf1db12ff2af1f1e3), UINT64_C(0x73bfa2e6cc7373d1), UINT64_C(0x12905a2482121248),
UINT64_C(0x403a5d807a40401d), UINT64_C(0x0840281048080820), UINT64_C(0xc356e89b95c3c32b), UINT64_C(0xec337bc5dfecec97),
UINT64_C(0xdb9690ab4ddbdb4b), UINT64_C(0xa1611f5fc0a1a1be), UINT64_C(0x8d1c8307918d8d0e), UINT64_C(0x3df5c97ac83d3df4),
UINT64_C(0x97ccf1335b979766), UINT64_C(0x0000000000000000), UINT64_C(0xcf36d483f9cfcf1b), UINT64_C(0x2b4587566e2b2bac),
UINT64_C(0x7697b3ece17676c5), UINT64_C(0x8264b019e6828232), UINT64_C(0xd6fea9b128d6d67f), UINT64_C(0x1bd87736c31b1b6c),
UINT64_C(0xb5c15b7774b5b5ee), UINT64_C(0xaf112943beafaf86), UINT64_C(0x6a77dfd41d6a6ab5), UINT64_C(0x50ba0da0ea50505d),
UINT64_C(0x45124c8a57454509), UINT64_C(0xf3cb18fb38f3f3eb), UINT64_C(0x309df060ad3030c0), UINT64_C(0xef2b74c3c4efef9b),
UINT64_C(0x3fe5c37eda3f3ffc), UINT64_C(0x55921caac7555549), UINT64_C(0xa2791059dba2a2b2), UINT64_C(0xea0365c9e9eaea8f),
UINT64_C(0x650fecca6a656589), UINT64_C(0xbab9686903babad2), UINT64_C(0x2f65935e4a2f2fbc), UINT64_C(0xc04ee79d8ec0c027),
UINT64_C(0xdebe81a160dede5f), UINT64_C(0x1ce06c38fc1c1c70), UINT64_C(0xfdbb2ee746fdfdd3), UINT64_C(0x4d52649a1f4d4d29),
UINT64_C(0x92e4e03976929272), UINT64_C(0x758fbceafa7575c9), UINT64_C(0x06301e0c36060618), UINT64_C(0x8a249809ae8a8a12),
UINT64_C(0xb2f940794bb2b2f2), UINT64_C(0xe66359d185e6e6bf), UINT64_C(0x0e70361c7e0e0e38), UINT64_C(0x1ff8633ee71f1f7c),
UINT64_C(0x6237f7c455626295), UINT64_C(0xd4eea3b53ad4d477), UINT64_C(0xa829324d81a8a89a), UINT64_C(0x96c4f43152969662),
UINT64_C(0xf99b3aef62f9f9c3), UINT64_C(0xc566f697a3c5c533), UINT64_C(0x2535b14a10252594), UINT64_C(0x59f220b2ab595979),
UINT64_C(0x8454ae15d084842a), UINT64_C(0x72b7a7e4c57272d5), UINT64_C(0x39d5dd72ec3939e4), UINT64_C(0x4c5a6198164c4c2d),
UINT64_C(0x5eca3bbc945e5e65), UINT64_C(0x78e785f09f7878fd), UINT64_C(0x38ddd870e53838e0), UINT64_C(0x8c148605988c8c0a),
UINT64_C(0xd1c6b2bf17d1d163), UINT64_C(0xa5410b57e4a5a5ae), UINT64_C(0xe2434dd9a1e2e2af), UINT64_C(0x612ff8c24e616199),
UINT64_C(0xb3f1457b42b3b3f6), UINT64_C(0x2115a54234212184), UINT64_C(0x9c94d625089c9c4a), UINT64_C(0x1ef0663cee1e1e78),
UINT64_C(0x4322528661434311), UINT64_C(0xc776fc93b1c7c73b), UINT64_C(0xfcb32be54ffcfcd7), UINT64_C(0x0420140824040410),
UINT64_C(0x51b208a2e3515159), UINT64_C(0x99bcc72f2599995e), UINT64_C(0x6d4fc4da226d6da9), UINT64_C(0x0d68391a650d0d34),
UINT64_C(0xfa8335e979fafacf), UINT64_C(0xdfb684a369dfdf5b), UINT64_C(0x7ed79bfca97e7ee5), UINT64_C(0x243db44819242490),
UINT64_C(0x3bc5d776fe3b3bec), UINT64_C(0xab313d4b9aabab96), UINT64_C(0xce3ed181f0cece1f), UINT64_C(0x1188552299111144),
UINT64_C(0x8f0c8903838f8f06), UINT64_C(0x4e4a6b9c044e4e25), UINT64_C(0xb7d1517366b7b7e6), UINT64_C(0xeb0b60cbe0ebeb8b),
UINT64_C(0x3cfdcc78c13c3cf0), UINT64_C(0x817cbf1ffd81813e), UINT64_C(0x94d4fe354094946a), UINT64_C(0xf7eb0cf31cf7f7fb),
UINT64_C(0xb9a1676f18b9b9de), UINT64_C(0x13985f268b13134c), UINT64_C(0x2c7d9c58512c2cb0), UINT64_C(0xd3d6b8bb05d3d36b),
UINT64_C(0xe76b5cd38ce7e7bb), UINT64_C(0x6e57cbdc396e6ea5), UINT64_C(0xc46ef395aac4c437), UINT64_C(0x03180f061b03030c),
UINT64_C(0x568a13acdc565645), UINT64_C(0x441a49885e44440d), UINT64_C(0x7fdf9efea07f7fe1), UINT64_C(0xa921374f88a9a99e),
UINT64_C(0x2a4d8254672a2aa8), UINT64_C(0xbbb16d6b0abbbbd6), UINT64_C(0xc146e29f87c1c123), UINT64_C(0x53a202a6f1535351),
UINT64_C(0xdcae8ba572dcdc57), UINT64_C(0x0b582716530b0b2c), UINT64_C(0x9d9cd327019d9d4e), UINT64_C(0x6c47c1d82b6c6cad),
UINT64_C(0x3195f562a43131c4), UINT64_C(0x7487b9e8f37474cd), UINT64_C(0xf6e309f115f6f6ff), UINT64_C(0x460a438c4c464605),
UINT64_C(0xac092645a5acac8a), UINT64_C(0x893c970fb589891e), UINT64_C(0x14a04428b4141450), UINT64_C(0xe15b42dfbae1e1a3),
UINT64_C(0x16b04e2ca6161658), UINT64_C(0x3acdd274f73a3ae8), UINT64_C(0x696fd0d2066969b9), UINT64_C(0x09482d1241090924),
UINT64_C(0x70a7ade0d77070dd), UINT64_C(0xb6d954716fb6b6e2), UINT64_C(0xd0ceb7bd1ed0d067), UINT64_C(0xed3b7ec7d6eded93),
UINT64_C(0xcc2edb85e2cccc17), UINT64_C(0x422a578468424215), UINT64_C(0x98b4c22d2c98985a), UINT64_C(0xa4490e55eda4a4aa),
UINT64_C(0x285d8850752828a0), UINT64_C(0x5cda31b8865c5c6d), UINT64_C(0xf8933fed6bf8f8c7), UINT64_C(0x8644a411c2868622),
},
{
UINT64_C(0x6018c07830d81818), UINT64_C(0x8c2305af46262323), UINT64_C(0x3fc67ef991b8c6c6), UINT64_C(0x87e8136fcdfbe8e8),
UINT64_C(0x26874ca113cb8787), UINT64_C(0xdab8a9626d11b8b8), UINT64_C(0x0401080502090101), UINT64_C(0x214f426e9e0d4f4f),
UINT64_C(0xd836adee6c9b3636), UINT64_C(0xa2a6590451ffa6a6), UINT64_C(0x6fd2debdb90cd2d2), UINT64_C(0xf3f5fb06f70ef5f5),
UINT64_C(0xf979ef80f2967979), UINT64_C(0xa16f5fcede306f6f), UINT64_C(0x7e91fcef3f6d9191), UINT64_C(0x5552aa07a4f85252),
UINT64_C(0x9d6027fdc0476060), UINT64_C(0xcabc89766535bcbc), UINT64_C(0x569baccd2b379b9b), UINT64_C(0x028e048c018a8e8e),
UINT64_C(0xb6a371155bd2a3a3), UINT64_C(0x300c603c186c0c0c), UINT64_C(0xf17bff8af6847b7b), UINT64_C(0xd435b5e16a803535),
UINT64_C(0x741de8693af51d1d), UINT64_C(0xa7e05347ddb3e0e0), UINT64_C(0x7bd7f6acb321d7d7), UINT64_C(0x2fc25eed999cc2c2),
UINT64_C(0xb82e6d965c432e2e), UINT64_C(0x314b627a96294b4b), UINT64_C(0xdffea321e15dfefe), UINT64_C(0x41578216aed55757),
UINT64_C(0x5415a8412abd1515), UINT64_C(0xc1779fb6eee87777), UINT64_C(0xdc37a5eb6e923737), UINT64_C(0xb3e57b56d79ee5e5),
UINT64_C(0x469f8cd923139f9f), UINT64_C(0xe7f0d317fd23f0f0), UINT64_C(0x354a6a7f94204a4a), UINT64_C(0x4fda9e95a944dada),
UINT64_C(0x7d58fa25b0a25858), UINT64_C(0x03c906ca8fcfc9c9), UINT64_C(0xa429558d527c2929), UINT64_C(0x280a5022145a0a0a),
UINT64_C(0xfeb1e14f7f50b1b1), UINT64_C(0xbaa0691a5dc9a0a0), UINT64_C(0xb16b7fdad6146b6b), UINT64_C(0x2e855cab17d98585),
UINT64_C(0xcebd8173673cbdbd), UINT64_C(0x695dd234ba8f5d5d), UINT64_C(0x4010805020901010), UINT64_C(0xf7f4f303f507f4f4),
UINT64_C(0x0bcb16c08bddcbcb), UINT64_C(0xf83eedc67cd33e3e), UINT64_C(0x140528110a2d0505), UINT64_C(0x81671fe6ce786767),
UINT64_C(0xb7e47353d597e4e4), UINT64_C(0x9c2725bb4e022727), UINT64_C(0x1941325882734141), UINT64_C(0x168b2c9d0ba78b8b),
UINT64_C(0xa6a7510153f6a7a7), UINT64_C(0xe97dcf94fab27d7d), UINT64_C(0x6e95dcfb37499595), UINT64_C(0x47d88e9fad56d8d8),
UINT64_C(0xcbfb8b30eb70fbfb), UINT64_C(0x9fee2371c1cdeeee), UINT64_C(0xed7cc791f8bb7c7c), UINT64_C(0x856617e3cc716666),
UINT64_C(0x53dda68ea77bdddd), UINT64_C(0x5c17b84b2eaf1717), UINT64_C(0x014702468e454747), UINT64_C(0x429e84dc211a9e9e),
UINT64_C(0x0fca1ec589d4caca), UINT64_C(0xb42d75995a582d2d), UINT64_C(0xc6bf9179632ebfbf), UINT64_C(0x1c07381b0e3f0707),
UINT64_C(0x8ead012347acadad), UINT64_C(0x755aea2fb4b05a5a), UINT64_C(0x36836cb51bef8383), UINT64_C(0xcc3385ff66b63333),
UINT64_C(0x91633ff2c65c6363), UINT64_C(0x0802100a04120202), UINT64_C(0x92aa39384993aaaa), UINT64_C(0xd971afa8e2de7171),
UINT64_C(0x07c80ecf8dc6c8c8), UINT64_C(0x6419c87d32d11919), UINT64_C(0x39497270923b4949), UINT64_C(0x43d9869aaf5fd9d9),
UINT64_C(0xeff2c31df931f2f2), UINT64_C(0xabe34b48dba8e3e3), UINT64_C(0x715be22ab6b95b5b), UINT64_C(0x1a8834920dbc8888),
UINT64_C(0x529aa4c8293e9a9a), UINT64_C(0x98262dbe4c0b2626), UINT64_C(0xc8328dfa64bf3232), UINT64_C(0xfab0e94a7d59b0b0),
UINT64_C(0x83e91b6acff2e9e9), UINT64_C(0x3c0f78331e770f0f), UINT64_C(0x73d5e6a6b733d5d5), UINT64_C(0x3a8074ba1df48080),
UINT64_C(0xc2be997c6127bebe), UINT64_C(0x13cd26de87ebcdcd), UINT64_C(0xd034bde468893434), UINT64_C(0x3d487a7590324848),
UINT64_C(0xdbffab24e354ffff), UINT64_C(0xf57af78ff48d7a7a), UINT64_C(0x7a90f4ea3d649090), UINT64_C(0x615fc23ebe9d5f5f),
UINT64_C(0x80201da0403d2020), UINT64_C(0xbd6867d5d00f6868), UINT64_C(0x681ad07234ca1a1a), UINT64_C(0x82ae192c41b7aeae),
UINT64_C(0xeab4c95e757db4b4), UINT64_C(0x4d549a19a8ce5454), UINT64_C(0x7693ece53b7f9393), UINT64_C(0x88220daa442f2222),
UINT64_C(0x8d6407e9c8636464), UINT64_C(0xe3f1db12ff2af1f1), UINT64_C(0xd173bfa2e6cc7373), UINT64_C(0x4812905a24821212),
UINT64_C(0x1d403a5d807a4040), UINT64_C(0x2008402810480808), UINT64_C(0x2bc356e89b95c3c3), UINT64_C(0x97ec337bc5dfecec),
UINT64_C(0x4bdb9690ab4ddbdb), UINT64_C(0xbea1611f5fc0a1a1), UINT64_C(0x0e8d1c8307918d8d), UINT64_C(0xf43df5c97ac83d3d),
UINT64_C(0x6697ccf1335b9797), UINT64_C(0x0000000000000000), UINT64_C(0x1bcf36d483f9cfcf), UINT64_C(0xac2b4587566e2b2b),
UINT64_C(0xc57697b3ece17676), UINT64_C(0x328264b019e68282), UINT64_C(0x7fd6fea9b128d6d6), UINT64_C(0x6c1bd87736c31b1b),
UINT64_C(0xeeb5c15b7774b5b5), UINT64_C(0x86af112943beafaf), UINT64_C(0xb56a77dfd41d6a6a), UINT64_C(0x5d50ba0da0ea5050),
UINT64_C(0x0945124c8a574545), UINT64_C(0xebf3cb18fb38f3f3), UINT64_C(0xc0309df060ad3030), UINT64_C(0x9bef2b74c3c4efef),
UINT64_C(0xfc3fe5c37eda3f3f), UINT64_C(0x4955921caac75555), UINT64_C(0xb2a2791059dba2a2), UINT64_C(0x8fea0365c9e9eaea),
UINT64_C(0x89650fecca6a6565), UINT64_C(0xd2bab9686903baba), UINT64_C(0xbc2f65935e4a2f2f), UINT64_C(0x27c04ee79d8ec0c0),
UINT64_C(0x5fdebe81a160dede), UINT64_C(0x701ce06c38fc1c1c), UINT64_C(0xd3fdbb2ee746fdfd), UINT64_C(0x294d52649a1f4d4d),
UINT64_C(0x7292e4e039769292), UINT64_C(0xc9758fbceafa7575), UINT64_C(0x1806301e0c360606), UINT64_C(0x128a249809ae8a8a),
UINT64_C(0xf2b2f940794bb2b2), UINT64_C(0xbfe66359d185e6e6), UINT64_C(0x380e70361c7e0e0e), UINT64_C(0x7c1ff8633ee71f1f),
UINT64_C(0x956237f7c4556262), UINT64_C(0x77d4eea3b53ad4d4), UINT64_C(0x9aa829324d81a8a8), UINT64_C(0x6296c4f431529696),
UINT64_C(0xc3f99b3aef62f9f9), UINT64_C(0x33c566f697a3c5c5), UINT64_C(0x942535b14a102525), UINT64_C(0x7959f220b2ab5959),
UINT64_C(0x2a8454ae15d08484), UINT64_C(0xd572b7a7e4c57272), UINT64_C(0xe439d5dd72ec3939), UINT64_C(0x2d4c5a6198164c4c),
UINT64_C(0x655eca3bbc945e5e), UINT64_C(0xfd78e785f09f7878), UINT64_C(0xe038ddd870e53838), UINT64_C(0x0a8c148605988c8c),
UINT64_C(0x63d1c6b2bf17d1d1), UINT64_C(0xaea5410b57e4a5a5), UINT64_C(0xafe2434dd9a1e2e2), UINT64_C(0x99612ff8c24e6161),
UINT64_C(0xf6b3f1457b42b3b3), UINT64_C(0x842115a542342121), UINT64_C(0x4a9c94d625089c9c), UINT64_C(0x781ef0663cee1e1e),
UINT64_C(0x1143225286614343), UINT64_C(0x3bc776fc93b1c7c7), UINT64_C(0xd7fcb32be54ffcfc), UINT64_C(0x1004201408240404),
UINT64_C(0x5951b208a2e35151), UINT64_C(0x5e99bcc72f259999), UINT64_C(0xa96d4fc4da226d6d), UINT64_C(0x340d68391a650d0d),
UINT64_C(0xcffa8335e979fafa), UINT64_C(0x5bdfb684a369dfdf), UINT64_C(0xe57ed79bfca97e7e), UINT64_C(0x90243db448192424),
UINT64_C(0xec3bc5d776fe3b3b), UINT64_C(0x96ab313d4b9aabab), UINT64_C(0x1fce3ed181f0cece), UINT64_C(0x4411885522991111),
UINT64_C(0x068f0c8903838f8f), UINT64_C(0x254e4a6b9c044e4e), UINT64_C(0xe6b7d1517366b7b7), UINT64_C(0x8beb0b60cbe0ebeb),
UINT64_C(0xf03cfdcc78c13c3c), UINT64_C(0x3e817cbf1ffd8181), UINT64_C(0x6a94d4fe35409494), UINT64_C(0xfbf7eb0cf31cf7f7),
UINT64_C(0xdeb9a1676f18b9b9), UINT64_C(0x4c13985f268b1313), UINT64_C(0xb02c7d9c58512c2c), UINT64_C(0x6bd3d6b8bb05d3d3),
UINT64_C(0xbbe76b5cd38ce7e7), UINT64_C(0xa56e57cbdc396e6e), UINT64_C(0x37c46ef395aac4c4), UINT64_C(0x0c03180f061b0303),
UINT64_C(0x45568a13acdc5656), UINT64_C(0x0d441a49885e4444), UINT64_C(0xe17fdf9efea07f7f), UINT64_C(0x9ea921374f88a9a9),
UINT64_C(0xa82a4d8254672a2a), UINT64_C(0xd6bbb16d6b0abbbb), UINT64_C(0x23c146e29f87c1c1), UINT64_C(0x5153a202a6f15353),
UINT64_C(0x57dcae8ba572dcdc), UINT64_C(0x2c0b582716530b0b), UINT64_C(0x4e9d9cd327019d9d), UINT64_C(0xad6c47c1d82b6c6c),
UINT64_C(0xc43195f562a43131), UINT64_C(0xcd7487b9e8f37474), UINT64_C(0xfff6e309f115f6f6), UINT64_C(0x05460a438c4c4646),
UINT64_C(0x8aac092645a5acac), UINT64_C(0x1e893c970fb58989), UINT64_C(0x5014a04428b41414), UINT64_C(0xa3e15b42dfbae1e1),
UINT64_C(0x5816b04e2ca61616), UINT64_C(0xe83acdd274f73a3a), UINT64_C(0xb9696fd0d2066969), UINT64_C(0x2409482d12410909),
UINT64_C(0xdd70a7ade0d77070), UINT64_C(0xe2b6d954716fb6b6), UINT64_C(0x67d0ceb7bd1ed0d0), UINT64_C(0x93ed3b7ec7d6eded),
UINT64_C(0x17cc2edb85e2cccc), UINT64_C(0x15422a5784684242), UINT64_C(0x5a98b4c22d2c9898), UINT64_C(0xaaa4490e55eda4a4),
UINT64_C(0xa0285d8850752828), UINT64_C(0x6d5cda31b8865c5c), UINT64_C(0xc7f8933fed6bf8f8), UINT64_C(0x228644a411c28686),
},
{
UINT64_C(0x186018c07830d818), UINT64_C(0x238c2305af462623), UINT64_C(0xc63fc67ef991b8c6), UINT64_C(0xe887e8136fcdfbe8),
UINT64_C(0x8726874ca113cb87), UINT64_C(0xb8dab8a9626d11b8), UINT64_C(0x0104010805020901), UINT64_C(0x4f214f426e9e0d4f),
UINT64_C(0x36d836adee6c9b36), UINT64_C(0xa6a2a6590451ffa6), UINT64_C(0xd26fd2debdb90cd2), UINT64_C(0xf5f3f5fb06f70ef5),
UINT64_C(0x79f979ef80f29679), UINT64_C(0x6fa16f5fcede306f), UINT64_C(0x917e91fcef3f6d91), UINT64_C(0x525552aa07a4f852),
UINT64_C(0x609d6027fdc04760), UINT64_C(0xbccabc89766535bc), UINT64_C(0x9b569baccd2b379b), UINT64_C(0x8e028e048c018a8e),
UINT64_C(0xa3b6a371155bd2a3), UINT64_C(0x0c300c603c186c0c), UINT64_C(0x7bf17bff8af6847b), UINT64_C(0x35d435b5e16a8035),
UINT64_C(0x1d741de8693af51d), UINT64_C(0xe0a7e05347ddb3e0), UINT64_C(0xd77bd7f6acb321d7), UINT64_C(0xc22fc25eed999cc2),
UINT64_C(0x2eb82e6d965c432e), UINT64_C(0x4b314b627a96294b), UINT64_C(0xfedffea321e15dfe), UINT64_C(0x5741578216aed557),
UINT64_C(0x155415a8412abd15), UINT64_C(0x77c1779fb6eee877), UINT64_C(0x37dc37a5eb6e9237), UINT64_C(0xe5b3e57b56d79ee5),
UINT64_C(0x9f469f8cd923139f), UINT64_C(0xf0e7f0d317fd23f0), UINT64_C(0x4a354a6a7f94204a), UINT64_C(0xda4fda9e95a944da),
UINT64_C(0x587d58fa25b0a258), UINT64_C(0xc903c906ca8fcfc9), UINT64_C(0x29a429558d527c29), UINT64_C(0x0a280a5022145a0a),
UINT64_C(0xb1feb1e14f7f50b1), UINT64_C(0xa0baa0691a5dc9a0), UINT64_C(0x6bb16b7fdad6146b), UINT64_C(0x852e855cab17d985),
UINT64_C(0xbdcebd8173673cbd), UINT64_C(0x5d695dd234ba8f5d), UINT64_C(0x1040108050209010), UINT64_C(0xf4f7f4f303f507f4),
UINT64_C(0xcb0bcb16c08bddcb), UINT64_C(0x3ef83eedc67cd33e), UINT64_C(0x05140528110a2d05), UINT64_C(0x6781671fe6ce7867),
UINT64_C(0xe4b7e47353d597e4), UINT64_C(0x279c2725bb4e0227), UINT64_C(0x4119413258827341), UINT64_C(0x8b168b2c9d0ba78b),
UINT64_C(0xa7a6a7510153f6a7), UINT64_C(0x7de97dcf94fab27d), UINT64_C(0x956e95dcfb374995), UINT64_C(0xd847d88e9fad56d8),
UINT64_C(0xfbcbfb8b30eb70fb), UINT64_C(0xee9fee2371c1cdee), UINT64_C(0x7ced7cc791f8bb7c), UINT64_C(0x66856617e3cc7166),
UINT64_C(0xdd53dda68ea77bdd), UINT64_C(0x175c17b84b2eaf17), UINT64_C(0x47014702468e4547), UINT64_C(0x9e429e84dc211a9e),
UINT64_C(0xca0fca1ec589d4ca), UINT64_C(0x2db42d75995a582d), UINT64_C(0xbfc6bf9179632ebf), UINT64_C(0x071c07381b0e3f07),
UINT64_C(0xad8ead012347acad), UINT64_C(0x5a755aea2fb4b05a), UINT64_C(0x8336836cb51bef83), UINT64_C(0x33cc3385ff66b633),
UINT64_C(0x6391633ff2c65c63), UINT64_C(0x020802100a041202), UINT64_C(0xaa92aa39384993aa), UINT64_C(0x71d971afa8e2de71),
UINT64_C(0xc807c80ecf8dc6c8), UINT64_C(0x196419c87d32d119), UINT64_C(0x4939497270923b49), UINT64_C(0xd943d9869aaf5fd9),
UINT64_C(0xf2eff2c31df931f2), UINT64_C(0xe3abe34b48dba8e3), UINT64_C(0x5b715be22ab6b95b), UINT64_C(0x881a8834920dbc88),
UINT64_C(0x9a529aa4c8293e9a), UINT64_C(0x2698262dbe4c0b26), UINT64_C(0x32c8328dfa64bf32), UINT64_C(0xb0fab0e94a7d59b0),
UINT64_C(0xe983e91b6acff2e9), UINT64_C(0x0f3c0f78331e770f), UINT64_C(0xd573d5e6a6b733d5), UINT64_C(0x803a8074ba1df480),
UINT64_C(0xbec2be997c6127be), UINT64_C(0xcd13cd26de87ebcd), UINT64_C(0x34d034bde4688934), UINT64_C(0x483d487a75903248),
UINT64_C(0xffdbffab24e354ff), UINT64_C(0x7af57af78ff48d7a), UINT64_C(0x907a90f4ea3d6490), UINT64_C(0x5f615fc23ebe9d5f),
UINT64_C(0x2080201da0403d20), UINT64_C(0x68bd6867d5d00f68), UINT64_C(0x1a681ad07234ca1a), UINT64_C(0xae82ae192c41b7ae),
UINT64_C(0xb4eab4c95e757db4), UINT64_C(0x544d549a19a8ce54), UINT64_C(0x937693ece53b7f93), UINT64_C(0x2288220daa442f22),
UINT64_C(0x648d6407e9c86364), UINT64_C(0xf1e3f1db12ff2af1), UINT64_C(0x73d173bfa2e6cc73), UINT64_C(0x124812905a248212),
UINT64_C(0x401d403a5d807a40), UINT64_C(0x0820084028104808), UINT64_C(0xc32bc356e89b95c3), UINT64_C(0xec97ec337bc5dfec),
UINT64_C(0xdb4bdb9690ab4ddb), UINT64_C(0xa1bea1611f5fc0a1), UINT64_C(0x8d0e8d1c8307918d), UINT64_C(0x3df43df5c97ac83d),
UINT64_C(0x976697ccf1335b97), UINT64_C(0x0000000000000000), UINT64_C(0xcf1bcf36d483f9cf), UINT64_C(0x2bac2b4587566e2b),
UINT64_C(0x76c57697b3ece176), UINT64_C(0x82328264b019e682), UINT64_C(0xd67fd6fea9b128d6), UINT64_C(0x1b6c1bd87736c31b),
UINT64_C(0xb5eeb5c15b7774b5), UINT64_C(0xaf86af112943beaf), UINT64_C(0x6ab56a77dfd41d6a), UINT64_C(0x505d50ba0da0ea50),
UINT64_C(0x450945124c8a5745), UINT64_C(0xf3ebf3cb18fb38f3), UINT64_C(0x30c0309df060ad30), UINT64_C(0xef9bef2b74c3c4ef),
UINT64_C(0x3ffc3fe5c37eda3f), UINT64_C(0x554955921caac755), UINT64_C(0xa2b2a2791059dba2), UINT64_C(0xea8fea0365c9e9ea),
UINT64_C(0x6589650fecca6a65), UINT64_C(0xbad2bab9686903ba), UINT64_C(0x2fbc2f65935e4a2f), UINT64_C(0xc027c04ee79d8ec0),
UINT64_C(0xde5fdebe81a160de), UINT64_C(0x1c701ce06c38fc1c), UINT64_C(0xfdd3fdbb2ee746fd), UINT64_C(0x4d294d52649a1f4d),
UINT64_C(0x927292e4e0397692), UINT64_C(0x75c9758fbceafa75), UINT64_C(0x061806301e0c3606), UINT64_C(0x8a128a249809ae8a),
UINT64_C(0xb2f2b2f940794bb2), UINT64_C(0xe6bfe66359d185e6), UINT64_C(0x0e380e70361c7e0e), UINT64_C(0x1f7c1ff8633ee71f),
UINT64_C(0x62956237f7c45562), UINT64_C(0xd477d4eea3b53ad4), UINT64_C(0xa89aa829324d81a8), UINT64_C(0x966296c4f4315296),
UINT64_C(0xf9c3f99b3aef62f9), UINT64_C(0xc533c566f697a3c5), UINT64_C(0x25942535b14a1025), UINT64_C(0x597959f220b2ab59),
UINT64_C(0x842a8454ae15d084), UINT64_C(0x72d572b7a7e4c572), UINT64_C(0x39e439d5dd72ec39), UINT64_C(0x4c2d4c5a6198164c),
UINT64_C(0x5e655eca3bbc945e), UINT64_C(0x78fd78e785f09f78), UINT64_C(0x38e038ddd870e538), UINT64_C(0x8c0a8c148605988c),
UINT64_C(0xd163d1c6b2bf17d1), UINT64_C(0xa5aea5410b57e4a5), UINT64_C(0xe2afe2434dd9a1e2), UINT64_C(0x6199612ff8c24e61),
UINT64_C(0xb3f6b3f1457b42b3), UINT64_C(0x21842115a5423421), UINT64_C(0x9c4a9c94d625089c), UINT64_C(0x1e781ef0663cee1e),
UINT64_C(0x4311432252866143), UINT64_C(0xc73bc776fc93b1c7), UINT64_C(0xfcd7fcb32be54ffc), UINT64_C(0x0410042014082404),
UINT64_C(0x515951b208a2e351), UINT64_C(0x995e99bcc72f2599), UINT64_C(0x6da96d4fc4da226d), UINT64_C(0x0d340d68391a650d),
UINT64_C(0xfacffa8335e979fa), UINT64_C(0xdf5bdfb684a369df), UINT64_C(0x7ee57ed79bfca97e), UINT64_C(0x2490243db4481924),
UINT64_C(0x3bec3bc5d776fe3b), UINT64_C(0xab96ab313d4b9aab), UINT64_C(0xce1fce3ed181f0ce), UINT64_C(0x1144118855229911),
UINT64_C(0x8f068f0c8903838f), UINT64_C(0x4e254e4a6b9c044e), UINT64_C(0xb7e6b7d1517366b7), UINT64_C(0xeb8beb0b60cbe0eb),
UINT64_C(0x3cf03cfdcc78c13c), UINT64_C(0x813e817cbf1ffd81), UINT64_C(0x946a94d4fe354094), UINT64_C(0xf7fbf7eb0cf31cf7),
UINT64_C(0xb9deb9a1676f18b9), UINT64_C(0x134c13985f268b13), UINT64_C(0x2cb02c7d9c58512c), UINT64_C(0xd36bd3d6b8bb05d3),
UINT64_C(0xe7bbe76b5cd38ce7), UINT64_C(0x6ea56e57cbdc396e), UINT64_C(0xc437c46ef395aac4), UINT64_C(0x030c03180f061b03),
UINT64_C(0x5645568a13acdc56), UINT64_C(0x440d441a49885e44), UINT64_C(0x7fe17fdf9efea07f), UINT64_C(0xa99ea921374f88a9),
UINT64_C(0x2aa82a4d8254672a), UINT64_C(0xbbd6bbb16d6b0abb), UINT64_C(0xc123c146e29f87c1), UINT64_C(0x535153a202a6f153),
UINT64_C(0xdc57dcae8ba572dc), UINT64_C(0x0b2c0b582716530b), UINT64_C(0x9d4e9d9cd327019d), UINT64_C(0x6cad6c47c1d82b6c),
UINT64_C(0x31c43195f562a431), UINT64_C(0x74cd7487b9e8f374), UINT64_C(0xf6fff6e309f115f6), UINT64_C(0x4605460a438c4c46),
UINT64_C(0xac8aac092645a5ac), UINT64_C(0x891e893c970fb589), UINT64_C(0x145014a04428b414), UINT64_C(0xe1a3e15b42dfbae1),
UINT64_C(0x165816b04e2ca616), UINT64_C(0x3ae83acdd274f73a), UINT64_C(0x69b9696fd0d20669), UINT64_C(0x092409482d124109),
UINT64_C(0x70dd70a7ade0d770), UINT64_C(0xb6e2b6d954716fb6), UINT64_C(0xd067d0ceb7bd1ed0), UINT64_C(0xed93ed3b7ec7d6ed),
UINT64_C(0xcc17cc2edb85e2cc), UINT64_C(0x4215422a57846842), UINT64_C(0x985a98b4c22d2c98), UINT64_C(0xa4aaa4490e55eda4),
UINT64_C(0x28a0285d88507528), UINT64_C(0x5c6d5cda31b8865c), UINT64_C(0xf8c7f8933fed6bf8), UINT64_C(0x86228644a411c286),
}
};
uint64_t r = 0;
unsigned int s = (shift + 8) & 7;
uint64_t * b = (uint64_t*)sbox;
unsigned int x = 56;
for (int i=0;i<8;i++)
{
const unsigned char t = src[s] >> x;
s = (s - 1) & 7;
r ^= b[t];
x -= 8;
b += 256;
}
return r;
}
//----------------------------------------------------------------------------------------------------------------------
static void inner_wp_hash(uint64_t K[2][8], uint64_t state[2][8])
{
for (int i=0;i<10;i++)
{
const uint64_t rc[10] =
{
0x1823C6E887B8014F, 0x36A6D2F5796F9152, 0x60BC9B8EA30C7B35, 0x1DE0D7C22E4BFE57, 0x157737E59FF04ADA,
0x58C9290AB1A06B85, 0xBD5D10F4CB3E0567, 0xE427418BA77D95D8, 0xFBEE7C66DD17479E, 0xCA2DBF07AD5A8333,
};
const unsigned int m = i & 1;
const unsigned int x = m ^ 1;
uint64_t const * const restrict km = K[m];
uint64_t * const restrict kx = K[x];
uint64_t const * const restrict sm = state[m];
uint64_t * const restrict sx = state[x];
kx[0] = op(km, 0) ^ rc[i];
kx[1] = op(km, 1);
kx[2] = op(km, 2);
kx[3] = op(km, 3);
kx[4] = op(km, 4);
kx[5] = op(km, 5);
kx[6] = op(km, 6);
kx[7] = op(km, 7);
sx[0] = op(sm, 0) ^ kx[0];
sx[1] = op(sm, 1) ^ kx[1];
sx[2] = op(sm, 2) ^ kx[2];
sx[3] = op(sm, 3) ^ kx[3];
sx[4] = op(sm, 4) ^ kx[4];
sx[5] = op(sm, 5) ^ kx[5];
sx[6] = op(sm, 6) ^ kx[6];
sx[7] = op(sm, 7) ^ kx[7];
}
}
//----------------------------------------------------------------------------------------------------------------------
void whirlpool_mod(void * const out, void const * const in)
{
uint64_t hash[8], state[2][8], K[2][8];
memset( K, 0, 64);
memcpy(state, in, 64);
inner_wp_hash(K, state);
for (int i=0;i<8;i++)
{
uint64_t in_q;
memcpy(&in_q, &in[i * 8], 8);
hash[i] = state[0][i] ^ in_q;
}
memcpy( K, hash, 64);
memcpy(state, hash, 64);
inner_wp_hash(K, state);
for (int i=0;i<8;i++)
{
unsigned char * const restrict p = out;
const uint64_t out_q = hash[i] ^ state[0][i];
memcpy(&p[i * 8], &out_q, 8);
}
}
//---------------------------------------------------------------------------------------------------------------------- |
the_stack_data/182952546.c | #include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <signal.h>
#include <string.h>
void signal_handler(int sig)
{
static count = 0;
printf("signal occured %d\n", ++count);
}
void main(void)
{
struct sigaction act, oact;
struct itimerval it;
//memset (&act, 0, sizeof (act));
act.sa_handler = signal_handler;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigaction(SIGPROF, &act, NULL); //attachh single for signal handler.
it.it_interval.tv_sec = 0;
it.it_interval.tv_usec = 250000;
it.it_value.tv_sec = 0;
it.it_value.tv_usec = 250000;
setitimer(ITIMER_PROF, &it, NULL); //generate singal at each intervals.
while(1);
}
|
the_stack_data/75138237.c | /* This testcase is part of GDB, the GNU debugger.
Copyright 2007-2014 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdio.h>
#include <stdlib.h>
#define DELTA (0.0001df)
#define DELTA_B (0.001)
double double_val1 = 45.125;
double double_val2 = -67.75;
double double_val3 = 0.25;
double double_val4 = 1.25;
double double_val5 = 2.25;
double double_val6 = 3.25;
double double_val7 = 4.25;
double double_val8 = 5.25;
double double_val9 = 6.25;
double double_val10 = 7.25;
double double_val11 = 8.25;
double double_val12 = 9.25;
double double_val13 = 10.25;
double double_val14 = 11.25;
_Decimal32 dec32_val1 = 3.14159df;
_Decimal32 dec32_val2 = -2.3765df;
_Decimal32 dec32_val3 = 0.2df;
_Decimal32 dec32_val4 = 1.2df;
_Decimal32 dec32_val5 = 2.2df;
_Decimal32 dec32_val6 = 3.2df;
_Decimal32 dec32_val7 = 4.2df;
_Decimal32 dec32_val8 = 5.2df;
_Decimal32 dec32_val9 = 6.2df;
_Decimal32 dec32_val10 = 7.2df;
_Decimal32 dec32_val11 = 8.2df;
_Decimal32 dec32_val12 = 9.2df;
_Decimal32 dec32_val13 = 10.2df;
_Decimal32 dec32_val14 = 11.2df;
_Decimal32 dec32_val15 = 12.2df;
_Decimal32 dec32_val16 = 13.2df;
_Decimal64 dec64_val1 = 3.14159dd;
_Decimal64 dec64_val2 = -2.3765dd;
_Decimal64 dec64_val3 = 0.2dd;
_Decimal64 dec64_val4 = 1.2dd;
_Decimal64 dec64_val5 = 2.2dd;
_Decimal64 dec64_val6 = 3.2dd;
_Decimal64 dec64_val7 = 4.2dd;
_Decimal64 dec64_val8 = 5.2dd;
_Decimal64 dec64_val9 = 6.2dd;
_Decimal64 dec64_val10 = 7.2dd;
_Decimal64 dec64_val11 = 8.2dd;
_Decimal64 dec64_val12 = 9.2dd;
_Decimal64 dec64_val13 = 10.2dd;
_Decimal64 dec64_val14 = 11.2dd;
_Decimal64 dec64_val15 = 12.2dd;
_Decimal64 dec64_val16 = 13.2dd;
_Decimal128 dec128_val1 = 3.14159dl;
_Decimal128 dec128_val2 = -2.3765dl;
_Decimal128 dec128_val3 = 0.2dl;
_Decimal128 dec128_val4 = 1.2dl;
_Decimal128 dec128_val5 = 2.2dl;
_Decimal128 dec128_val6 = 3.2dl;
_Decimal128 dec128_val7 = 4.2dl;
_Decimal128 dec128_val8 = 5.2dl;
_Decimal128 dec128_val9 = 6.2dl;
_Decimal128 dec128_val10 = 7.2dl;
_Decimal128 dec128_val11 = 8.2dl;
_Decimal128 dec128_val12 = 9.2dl;
_Decimal128 dec128_val13 = 10.2dl;
_Decimal128 dec128_val14 = 11.2dl;
_Decimal128 dec128_val15 = 12.2dl;
_Decimal128 dec128_val16 = 13.2dl;
volatile _Decimal32 d32;
volatile _Decimal64 d64;
volatile _Decimal128 d128;
struct decstruct
{
int int4;
long long8;
float float4;
double double8;
_Decimal32 dec32;
_Decimal64 dec64;
_Decimal128 dec128;
} ds;
static _Decimal32
arg0_32 (_Decimal32 arg0, _Decimal32 arg1, _Decimal32 arg2,
_Decimal32 arg3, _Decimal32 arg4, _Decimal32 arg5)
{
return arg0;
}
static _Decimal64
arg0_64 (_Decimal64 arg0, _Decimal64 arg1, _Decimal64 arg2,
_Decimal64 arg3, _Decimal64 arg4, _Decimal64 arg5)
{
return arg0;
}
static _Decimal128
arg0_128 (_Decimal128 arg0, _Decimal128 arg1, _Decimal128 arg2,
_Decimal128 arg3, _Decimal128 arg4, _Decimal128 arg5)
{
return arg0;
}
/* Function to test if _Decimal128 argument interferes with stack slots
because of alignment. */
int
decimal_dec128_align (double arg0, _Decimal128 arg1, double arg2, double arg3,
double arg4, double arg5, double arg6, double arg7,
double arg8, double arg9, double arg10, double arg11,
double arg12, double arg13)
{
return ((arg0 - double_val1) < DELTA_B
&& (arg0 - double_val1) > -DELTA_B
&& (arg1 - dec128_val2) < DELTA
&& (arg1 - dec128_val2) > -DELTA
&& (arg2 - double_val3) < DELTA_B
&& (arg2 - double_val3) > -DELTA_B
&& (arg3 - double_val4) < DELTA_B
&& (arg3 - double_val4) > -DELTA_B
&& (arg4 - double_val5) < DELTA_B
&& (arg4 - double_val5) > -DELTA_B
&& (arg5 - double_val6) < DELTA_B
&& (arg5 - double_val6) > -DELTA_B
&& (arg6 - double_val7) < DELTA_B
&& (arg6 - double_val7) > -DELTA_B
&& (arg7 - double_val8) < DELTA_B
&& (arg7 - double_val8) > -DELTA_B
&& (arg8 - double_val9) < DELTA_B
&& (arg8 - double_val9) > -DELTA_B
&& (arg9 - double_val10) < DELTA_B
&& (arg9 - double_val10) > -DELTA_B
&& (arg10 - double_val11) < DELTA_B
&& (arg10 - double_val11) > -DELTA_B
&& (arg11 - double_val12) < DELTA_B
&& (arg11 - double_val12) > -DELTA_B
&& (arg12 - double_val13) < DELTA_B
&& (arg12 - double_val13) > -DELTA_B
&& (arg13 - double_val14) < DELTA_B
&& (arg13 - double_val14) > -DELTA_B);
}
int
decimal_mixed (_Decimal32 arg0, _Decimal64 arg1, _Decimal128 arg2)
{
return ((arg0 - dec32_val1) < DELTA
&& (arg0 - dec32_val1) > -DELTA
&& (arg1 - dec64_val1) < DELTA
&& (arg1 - dec64_val1) > -DELTA
&& (arg2 - dec128_val1) < DELTA
&& (arg2 - dec128_val1) > -DELTA);
}
/* These functions have many arguments to force some of them to be passed via
the stack instead of registers, to test that GDB can construct correctly
the parameter save area. Note that Linux/ppc32 has 8 float registers to use
for float parameter passing and Linux/ppc64 has 13, so the number of
arguments has to be at least 14 to contemplate these platforms. */
int
decimal_many_args_dec32 (_Decimal32 f1, _Decimal32 f2, _Decimal32 f3,
_Decimal32 f4, _Decimal32 f5, _Decimal32 f6,
_Decimal32 f7, _Decimal32 f8, _Decimal32 f9,
_Decimal32 f10, _Decimal32 f11, _Decimal32 f12,
_Decimal32 f13, _Decimal32 f14, _Decimal32 f15,
_Decimal32 f16)
{
_Decimal32 sum_args;
_Decimal32 sum_values;
sum_args = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12
+ f13 + f14 + f15 + f16;
sum_values = dec32_val1 + dec32_val2 + dec32_val3 + dec32_val4 + dec32_val5
+ dec32_val6 + dec32_val7 + dec32_val8 + dec32_val9
+ dec32_val10 + dec32_val11 + dec32_val12 + dec32_val13
+ dec32_val14 + dec32_val15 + dec32_val16;
return ((sum_args - sum_values) < DELTA
&& (sum_args - sum_values) > -DELTA);
}
int
decimal_many_args_dec64 (_Decimal64 f1, _Decimal64 f2, _Decimal64 f3,
_Decimal64 f4, _Decimal64 f5, _Decimal64 f6,
_Decimal64 f7, _Decimal64 f8, _Decimal64 f9,
_Decimal64 f10, _Decimal64 f11, _Decimal64 f12,
_Decimal64 f13, _Decimal64 f14, _Decimal64 f15,
_Decimal64 f16)
{
_Decimal64 sum_args;
_Decimal64 sum_values;
sum_args = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12
+ f13 + f14 + f15 + f16;
sum_values = dec64_val1 + dec64_val2 + dec64_val3 + dec64_val4 + dec64_val5
+ dec64_val6 + dec64_val7 + dec64_val8 + dec64_val9
+ dec64_val10 + dec64_val11 + dec64_val12 + dec64_val13
+ dec64_val14 + dec64_val15 + dec64_val16;
return ((sum_args - sum_values) < DELTA
&& (sum_args - sum_values) > -DELTA);
}
int
decimal_many_args_dec128 (_Decimal128 f1, _Decimal128 f2, _Decimal128 f3,
_Decimal128 f4, _Decimal128 f5, _Decimal128 f6,
_Decimal128 f7, _Decimal128 f8, _Decimal128 f9,
_Decimal128 f10, _Decimal128 f11, _Decimal128 f12,
_Decimal128 f13, _Decimal128 f14, _Decimal128 f15,
_Decimal128 f16)
{
_Decimal128 sum_args;
_Decimal128 sum_values;
sum_args = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12
+ f13 + f14 + f15 + f16;
sum_values = dec128_val1 + dec128_val2 + dec128_val3 + dec128_val4 + dec128_val5
+ dec128_val6 + dec128_val7 + dec128_val8 + dec128_val9
+ dec128_val10 + dec128_val11 + dec128_val12 + dec128_val13
+ dec128_val14 + dec128_val15 + dec128_val16;
return ((sum_args - sum_values) < DELTA
&& (sum_args - sum_values) > -DELTA);
}
int
decimal_many_args_mixed (_Decimal32 f1, _Decimal32 f2, _Decimal32 f3,
_Decimal64 f4, _Decimal64 f5, _Decimal64 f6,
_Decimal64 f7, _Decimal128 f8, _Decimal128 f9,
_Decimal128 f10, _Decimal32 f11, _Decimal64 f12,
_Decimal32 f13, _Decimal64 f14, _Decimal128 f15)
{
_Decimal128 sum_args;
_Decimal128 sum_values;
sum_args = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12
+ f13 + f14 + f15;
sum_values = dec32_val1 + dec32_val2 + dec32_val3 + dec64_val4 + dec64_val5
+ dec64_val6 + dec64_val7 + dec128_val8 + dec128_val9
+ dec128_val10 + dec32_val11 + dec64_val12 + dec32_val13
+ dec64_val14 + dec128_val15;
return ((sum_args - sum_values) < DELTA
&& (sum_args - sum_values) > -DELTA);
}
int main()
{
/* An finite 32-bits decimal floating point. */
d32 = 1.2345df; /* Initialize d32. */
/* Non-finite 32-bits decimal floating point: infinity and NaN. */
d32 = __builtin_infd32(); /* Positive infd32. */
d32 = -__builtin_infd32(); /* Negative infd32. */
d32 = __builtin_nand32("");
/* An finite 64-bits decimal floating point. */
d64 = 1.2345dd; /* Initialize d64. */
/* Non-finite 64-bits decimal floating point: infinity and NaN. */
d64 = __builtin_infd64(); /* Positive infd64. */
d64 = -__builtin_infd64(); /* Negative infd64. */
d64 = __builtin_nand64("");
/* An finite 128-bits decimal floating point. */
d128 = 1.2345dl; /* Initialize d128. */
/* Non-finite 128-bits decimal floating point: infinity and NaN. */
d128 = __builtin_infd128(); /* Positive infd128. */
d128 = -__builtin_infd128(); /* Negative infd128. */
d128 = __builtin_nand128("");
/* Functions with decimal floating point as parameter and return value. */
d32 = arg0_32 (0.1df, 1.0df, 2.0df, 3.0df, 4.0df, 5.0df);
d64 = arg0_64 (0.1dd, 1.0dd, 2.0dd, 3.0dd, 4.0dd, 5.0dd);
d128 = arg0_128 (0.1dl, 1.0dl, 2.0dl, 3.0dl, 4.0dl, 5.0dl);
ds.int4 = 1;
ds.long8 = 2;
ds.float4 = 3.1;
ds.double8 = 4.2;
ds.dec32 = 1.2345df;
ds.dec64 = 1.2345dd;
ds.dec128 = 1.2345dl;
return 0; /* Exit point. */
}
|
the_stack_data/135787.c | /* Copyright (C) 2003-2015 Free Software Foundation, Inc.
This file is part of GDB.
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/>. */
#ifdef SYMBOL_PREFIX
#define SYMBOL(str) SYMBOL_PREFIX #str
#else
#define SYMBOL(str) #str
#endif
void standard (void);
int
main (void)
{
standard ();
return 0;
}
/* A normal prologue. */
#ifdef __x86_64__
asm(".text\n"
" .align 8\n"
SYMBOL (standard) ":\n"
" push %rbp\n"
" mov %rsp, %rbp\n"
" push %rdi\n"
" int3\n"
" leaveq\n"
" retq\n");
#else
asm(".text\n"
" .align 8\n"
" .global " SYMBOL(standard) "\n"
SYMBOL (standard) ":\n"
" pushl %ebp\n"
" movl %esp, %ebp\n"
" pushl %edi\n"
" int3\n"
" leave\n"
" ret\n");
#endif
|
the_stack_data/200143750.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char str1[1004],str2[1004];
while(scanf("%s %s",str1,str2) != EOF){
int exist = 0;
int ascii_usd[260][1004];
memset(ascii_usd,0,sizeof(ascii_usd));
int len1 = strlen(str1);
int len2 = strlen(str2);
for(int i=0; i<len1; i++){
int value = str1[i];
int ip = ascii_usd[value][0] + 1;
ascii_usd[value][0]++;
ascii_usd[value][ip] = i;
}
int ansbegin = 0;
int anslenth = 0;
for(int i=0;i<len2; i++){
int lenth2 = len2-i;
char head = str2[i];
int value = head;
if(ascii_usd[value][0] != 0){
int number = ascii_usd[value][0];
for(int j=1; j<=number ; j++){
int locate = ascii_usd[value][j];
int lenth1 = len1-locate;
int min = lenth1 > lenth2 ? lenth2 : lenth1;
int tempbegin = locate;
int templenth = 0;
for(int ip=0; ip<min; ip++){
if(str1[locate+ip] == str2[i+ip]){
templenth++;
}
else{
break;
}
}
if(templenth > anslenth){
anslenth = templenth;
ansbegin = tempbegin;
}
}
}
}
if(anslenth != 0){
for(int i=0; i<anslenth; i++){
printf("%c",str1[ansbegin+i]);
}
}
else{
printf("#");
}
printf("\n");
}
return 0;
} |
the_stack_data/1225137.c | /***********************************************************************
* Code listing from "Advanced Linux Programming," by CodeSourcery LLC *
* Copyright (C) 2001 by New Riders Publishing *
* See COPYRIGHT for license information. *
***********************************************************************/
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
/* Returns the process id of the calling processes, as determined from
the /proc/self symlink. */
pid_t get_pid_from_proc_self ()
{
char target[32];
int pid;
/* Read the target of the symbolic link. */
readlink ("/proc/self", target, sizeof (target));
/* The target is a directory named for the process id. */
sscanf (target, "%d", &pid);
return (pid_t) pid;
}
int main ()
{
printf ("/proc/self reports process id %d\n",
(int) get_pid_from_proc_self ());
printf ("getpid() reports process id %d\n", (int) getpid ());
return 0;
}
|
the_stack_data/98576275.c | #include <stdio.h>
int main(void) {
printf("%zu\n%zu\n%zu\n", sizeof(int), sizeof(short), sizeof(long));
printf("%lu\n%lu\n%lu\n", sizeof(float), sizeof(double), sizeof(long double));
return 0;
} |
the_stack_data/132954336.c | /* Generated by CIL v. 1.7.0 */
/* print_CIL_Input is false */
struct _IO_FILE;
struct timeval;
extern void signal(int sig , void *func ) ;
extern float strtof(char const *str , char const *endptr ) ;
typedef struct _IO_FILE FILE;
extern int atoi(char const *s ) ;
extern double strtod(char const *str , char const *endptr ) ;
extern int fclose(void *stream ) ;
extern void *fopen(char const *filename , char const *mode ) ;
extern void abort() ;
extern void exit(int status ) ;
extern int raise(int sig ) ;
extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ;
extern int strcmp(char const *a , char const *b ) ;
extern int rand() ;
extern unsigned long strtoul(char const *str , char const *endptr , int base ) ;
void RandomFunc(unsigned char input[1] , unsigned char output[1] ) ;
extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ;
extern int gettimeofday(struct timeval *tv , void *tz , ...) ;
extern int printf(char const *format , ...) ;
int main(int argc , char *argv[] ) ;
void megaInit(void) ;
extern unsigned long strlen(char const *s ) ;
extern long strtol(char const *str , char const *endptr , int base ) ;
extern unsigned long strnlen(char const *s , unsigned long maxlen ) ;
extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ;
struct timeval {
long tv_sec ;
long tv_usec ;
};
extern void *malloc(unsigned long size ) ;
extern int scanf(char const *format , ...) ;
void megaInit(void)
{
{
}
}
int main(int argc , char *argv[] )
{
unsigned char input[1] ;
unsigned char output[1] ;
int randomFuns_i5 ;
unsigned char randomFuns_value6 ;
int randomFuns_main_i7 ;
{
megaInit();
if (argc != 2) {
printf("Call this program with %i arguments\n", 1);
exit(-1);
} else {
}
randomFuns_i5 = 0;
while (randomFuns_i5 < 1) {
randomFuns_value6 = (unsigned char )strtoul(argv[randomFuns_i5 + 1], 0, 10);
input[randomFuns_i5] = randomFuns_value6;
randomFuns_i5 ++;
}
RandomFunc(input, output);
if (output[0] == 114) {
printf("You win!\n");
} else {
}
randomFuns_main_i7 = 0;
while (randomFuns_main_i7 < 1) {
printf("%u\n", output[randomFuns_main_i7]);
randomFuns_main_i7 ++;
}
}
}
void RandomFunc(unsigned char input[1] , unsigned char output[1] )
{
unsigned char state[1] ;
{
state[0UL] = (input[0UL] - 51238316UL) - (unsigned char)191;
if ((state[0UL] >> (unsigned char)3) & (unsigned char)1) {
if (state[0UL] & (unsigned char)1) {
if (state[0UL] & (unsigned char)1) {
state[0UL] |= (state[0UL] & (unsigned char)15) << 3UL;
} else {
state[0UL] |= (state[0UL] & (unsigned char)7) << 2UL;
}
} else
if ((state[0UL] >> (unsigned char)3) & (unsigned char)1) {
state[0UL] |= (((state[0UL] << ((state[0UL] & (unsigned char)15) | 1UL)) | (state[0UL] >> (8 - ((state[0UL] & (unsigned char)15) | 1UL)))) & (unsigned char)63) << 4UL;
} else {
state[0UL] |= (state[0UL] & (unsigned char)63) << 4UL;
}
} else {
state[0UL] = (state[0UL] >> (((state[0UL] >> (unsigned char)4) & (unsigned char)15) | 1UL)) | (state[0UL] << (8 - (((state[0UL] >> (unsigned char)4) & (unsigned char)15) | 1UL)));
}
output[0UL] = state[0UL] * 246575798UL + (unsigned char)254;
}
}
|
the_stack_data/555665.c | #include <stdio.h>
#include <assert.h>
void mainQ(int guess, int t, int n, int m, int d, int secret) {
int p = 0;
int i = 0;
assert(guess <= secret);
if(guess <= secret){
if(t == 1){
p += 1;
}
else if(t == 2){
for(i = 0; i<n;i++){
p += 1;
}
}
else{
for(i = 0; i<n*n*n;i++){
p += 1;
}
}
}
else{
if(t == 1){
p += 1;
}
else if(t == 2){
for(i = 0; i<n*n;i++){
p += 1;
}
}
else{
for(i = 0; i<n*n*n;i++){
p += 1;
}
}
}
int n2 = n*n;
int n3 = n*n*n;
//%%%traces: int secret, int p, int n, int n2, int n3
}
int main(int argc, char **argv) {
mainQ(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), atoi(argv[4]), atoi(argv[5]), atoi(argv[6]));
return 0;
}
|
the_stack_data/55874.c | #include <errno.h>
#include <limits.h>
#include <sys/sem.h>
int semget(key_t key, int n, int fl) {
errno = ENOSYS;
return -1;
}
|
the_stack_data/113349.c | #include<stdio.h>
#include<math.h>
int main()
{
int binr, temp,thisdigit=0;
int dec=0;
printf("Enter a binary number = ");
scanf("%d",&binr);
temp=binr;
for(int i = 0; temp>0; i++)
{
thisdigit = temp%10;
dec += thisdigit?(pow(2,i)):0;
temp/=10;
}
printf("Your decimal number is %d",dec);
return 0;
} |
the_stack_data/18823.c | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#define MAX_NUM_VARS 20 // maximum number of variables in a grid-tiling
/*********************************************************************************************************/
/********************************************** PROTOTYPES ***********************************************/
/*********************************************************************************************************/
/* This function gets the tile indicies for each tiling */
void GetTileIndices(unsigned int num_tilings, unsigned int memory_size, double* doubles, unsigned int num_doubles, int* ints, unsigned int num_ints, unsigned int* tile_indices);
/* This function takes the modulo of n by k even when n is negative */
int ModuloNegativeSafe(int n, int k);
/* This function takes an array of integers and returns the corresponding tile after hashing */
int HashTiles(int* ints, unsigned int num_ints, long m, int increment);
/* This function initializes episodes */
void InitializeEpisode(unsigned int number_of_non_terminal_states, unsigned int max_number_of_actions, unsigned int* state_tile_indices, unsigned int number_of_state_tilings, unsigned int number_of_state_tiles, double** state_double_variables, unsigned int number_of_state_double_variables, int** state_int_variables, unsigned int number_of_state_int_variables, double* weights, double* approximate_state_action_value_function, double* policy, double* policy_cumulative_sum, double epsilon, unsigned int* initial_state_index, unsigned int* initial_action_index);
/* This function selects a policy with using epsilon-greedy from the state-action-value function */
void EpsilonGreedyPolicyFromApproximateStateActionFunction(unsigned int max_number_of_actions, unsigned int number_of_state_tilings, unsigned int number_of_state_tiles, unsigned int* state_tile_indices, double* weights, double* approximate_state_action_value_function, double* policy, double* policy_cumulative_sum, double epsilon);
/* This function loops through episodes and updates the policy */
void LoopThroughEpisode(unsigned int number_of_non_terminal_states, unsigned int** number_of_state_action_successor_states, unsigned int*** state_action_successor_state_indices, double*** state_action_successor_state_transition_probabilities_cumulative_sum, double*** state_action_successor_state_rewards, unsigned int max_number_of_actions, unsigned int number_of_state_tilings, unsigned int number_of_state_tiles, double** state_double_variables, unsigned int number_of_state_double_variables, int** state_int_variables, unsigned int number_of_state_int_variables, unsigned int* state_tile_indices, unsigned int* next_state_tile_indices, double* weights, double* approximate_state_action_value_function, double* policy, double* policy_cumulative_sum, double alpha, double epsilon, double discounting_factor_gamma, unsigned int maximum_episode_length, unsigned int state_index, unsigned int action_index);
/* This function calculates the approximate state action value function w^T * x */
double ApproximateStateActionValueFunction(unsigned int number_of_state_tilings, unsigned int number_of_state_tiles, unsigned int* state_tile_indices, unsigned int action_index, double* weights);
/* This function returns a random uniform number within range [0,1] */
double UnifRand(void);
/*********************************************************************************************************/
/************************************************* MAIN **************************************************/
/*********************************************************************************************************/
int main(int argc, char* argv[])
{
unsigned int i, j, k;
int system_return;
/*********************************************************************************************************/
/**************************************** READ IN THE ENVIRONMENT ****************************************/
/*********************************************************************************************************/
/* Get the number of states */
unsigned int number_of_states = 0;
FILE* infile_number_of_states = fopen("inputs/number_of_states.txt", "r");
system_return = fscanf(infile_number_of_states, "%u", &number_of_states);
if (system_return == -1)
{
printf("Failed reading file inputs/number_of_states.txt\n");
}
fclose(infile_number_of_states);
/* Get number of terminal states */
unsigned int number_of_terminal_states = 0;
FILE* infile_number_of_terminal_states = fopen("inputs/number_of_terminal_states.txt", "r");
system_return = fscanf(infile_number_of_terminal_states, "%u", &number_of_terminal_states);
if (system_return == -1)
{
printf("Failed reading file inputs/number_of_terminal_states.txt\n");
}
fclose(infile_number_of_terminal_states);
/* Get number of non-terminal states */
unsigned int number_of_non_terminal_states = number_of_states - number_of_terminal_states;
/* Get the number of actions per non-terminal state */
unsigned int* number_of_actions_per_non_terminal_state;
FILE* infile_number_of_actions_per_non_terminal_state = fopen("inputs/number_of_actions_per_non_terminal_state.txt", "r");
number_of_actions_per_non_terminal_state = malloc(sizeof(int) * number_of_non_terminal_states);
for (i = 0; i < number_of_non_terminal_states; i++)
{
system_return = fscanf(infile_number_of_actions_per_non_terminal_state, "%u", &number_of_actions_per_non_terminal_state[i]);
if (system_return == -1)
{
printf("Failed reading file inputs/number_of_actions_per_non_terminal_state.txt\n");
}
} // end of i loop
fclose(infile_number_of_actions_per_non_terminal_state);
/* Get the number of actions per all states */
unsigned int* number_of_actions_per_state;
number_of_actions_per_state = malloc(sizeof(int) * number_of_states);
for (i = 0; i < number_of_non_terminal_states; i++)
{
number_of_actions_per_state[i] = number_of_actions_per_non_terminal_state[i];
} // end of i loop
for (i = 0; i < number_of_terminal_states; i++)
{
number_of_actions_per_state[i + number_of_non_terminal_states] = 0;
} // end of i loop
/* Get the number of state-action successor states */
unsigned int** number_of_state_action_successor_states;
FILE* infile_number_of_state_action_successor_states = fopen("inputs/number_of_state_action_successor_states.txt", "r");
number_of_state_action_successor_states = malloc(sizeof(int*) * number_of_non_terminal_states);
for (i = 0; i < number_of_non_terminal_states; i++)
{
number_of_state_action_successor_states[i] = malloc(sizeof(int) * number_of_actions_per_non_terminal_state[i]);
for (j = 0; j < number_of_actions_per_non_terminal_state[i]; j++)
{
system_return = fscanf(infile_number_of_state_action_successor_states, "%u\t", &number_of_state_action_successor_states[i][j]);
if (system_return == -1)
{
printf("Failed reading file inputs/number_of_state_action_successor_states.txt\n");
}
} // end of j loop
} // end of i loop
fclose(infile_number_of_state_action_successor_states);
/* Get the state-action-successor state indices */
unsigned int*** state_action_successor_state_indices;
FILE* infile_state_action_successor_state_indices = fopen("inputs/state_action_successor_state_indices.txt", "r");
state_action_successor_state_indices = malloc(sizeof(unsigned int**) * number_of_non_terminal_states);
for (i = 0; i < number_of_non_terminal_states; i++)
{
state_action_successor_state_indices[i] = malloc(sizeof(unsigned int*) * number_of_actions_per_non_terminal_state[i]);
for (j = 0; j < number_of_actions_per_non_terminal_state[i]; j++)
{
state_action_successor_state_indices[i][j] = malloc(sizeof(unsigned int*) * number_of_state_action_successor_states[i][j]);
for (k = 0; k < number_of_state_action_successor_states[i][j]; k++)
{
system_return = fscanf(infile_state_action_successor_state_indices, "%u\t", &state_action_successor_state_indices[i][j][k]);
if (system_return == -1)
{
printf("Failed reading file inputs/state_action_successor_state_indices.txt\n");
}
} // end of k loop
system_return = fscanf(infile_state_action_successor_state_indices, "\n");
if (system_return == -1)
{
printf("Failed reading file inputs/state_action_successor_state_indices.txt\n");
}
} // end of j loop
} // end of i loop
fclose(infile_state_action_successor_state_indices);
/* Get the state-action-successor state transition probabilities */
double*** state_action_successor_state_transition_probabilities;
FILE* infile_state_action_successor_state_transition_probabilities = fopen("inputs/state_action_successor_state_transition_probabilities.txt", "r");
state_action_successor_state_transition_probabilities = malloc(sizeof(double**) * number_of_non_terminal_states);
for (i = 0; i < number_of_non_terminal_states; i++)
{
state_action_successor_state_transition_probabilities[i] = malloc(sizeof(double*) * number_of_actions_per_non_terminal_state[i]);
for (j = 0; j < number_of_actions_per_non_terminal_state[i]; j++)
{
state_action_successor_state_transition_probabilities[i][j] = malloc(sizeof(double*) * number_of_state_action_successor_states[i][j]);
for (k = 0; k < number_of_state_action_successor_states[i][j]; k++)
{
system_return = fscanf(infile_state_action_successor_state_transition_probabilities, "%lf\t", &state_action_successor_state_transition_probabilities[i][j][k]);
if (system_return == -1)
{
printf("Failed reading file inputs/state_action_successor_state_transition_probabilities.txt\n");
}
} // end of k loop
system_return = fscanf(infile_state_action_successor_state_transition_probabilities, "\n");
if (system_return == -1)
{
printf("Failed reading file inputs/state_action_successor_state_transition_probabilities.txt\n");
}
} // end of j loop
} // end of i loop
fclose(infile_state_action_successor_state_transition_probabilities);
/* Create the state-action-successor state transition probability cumulative sum array */
double*** state_action_successor_state_transition_probabilities_cumulative_sum;
state_action_successor_state_transition_probabilities_cumulative_sum = malloc(sizeof(double**) * number_of_non_terminal_states);
for (i = 0; i < number_of_non_terminal_states; i++)
{
state_action_successor_state_transition_probabilities_cumulative_sum[i] = malloc(sizeof(double*) * number_of_actions_per_non_terminal_state[i]);
for (j = 0; j < number_of_actions_per_non_terminal_state[i]; j++)
{
state_action_successor_state_transition_probabilities_cumulative_sum[i][j] = malloc(sizeof(double*) * number_of_state_action_successor_states[i][j]);
if (number_of_state_action_successor_states[i][j] > 0)
{
state_action_successor_state_transition_probabilities_cumulative_sum[i][j][0] = state_action_successor_state_transition_probabilities[i][j][0];
for (k = 1; k < number_of_state_action_successor_states[i][j]; k++)
{
state_action_successor_state_transition_probabilities_cumulative_sum[i][j][k] = state_action_successor_state_transition_probabilities_cumulative_sum[i][j][k - 1] + state_action_successor_state_transition_probabilities[i][j][k];
} // end of k loop
}
} // end of j loop
} // end of i loop
/* Get the state-action-successor state rewards */
double*** state_action_successor_state_rewards;
FILE* infile_state_action_successor_state_rewards = fopen("inputs/state_action_successor_state_rewards.txt", "r");
state_action_successor_state_rewards = malloc(sizeof(double**) * number_of_non_terminal_states);
for (i = 0; i < number_of_non_terminal_states; i++)
{
state_action_successor_state_rewards[i] = malloc(sizeof(double*) * number_of_actions_per_non_terminal_state[i]);
for (j = 0; j < number_of_actions_per_non_terminal_state[i]; j++)
{
state_action_successor_state_rewards[i][j] = malloc(sizeof(double) * number_of_state_action_successor_states[i][j]);
for (k = 0; k < number_of_state_action_successor_states[i][j]; k++)
{
system_return = fscanf(infile_state_action_successor_state_rewards, "%lf\t", &state_action_successor_state_rewards[i][j][k]);
if (system_return == -1)
{
printf("Failed reading file inputs/state_action_successor_state_rewards.txt\n");
}
} // end of k loop
system_return = fscanf(infile_state_action_successor_state_rewards, "\n");
if (system_return == -1)
{
printf("Failed reading file inputs/state_action_successor_state_rewards.txt\n");
}
} // end of j loop
} // end of i loop
fclose(infile_state_action_successor_state_rewards);
/*********************************************************************************************************/
/********************************************* CREATE TILING *********************************************/
/*********************************************************************************************************/
/* Get the number of state double variables */
unsigned int number_of_state_double_variables = 0;
FILE* infile_number_of_state_double_variables = fopen("inputs/number_of_state_double_variables.txt", "r");
system_return = fscanf(infile_number_of_state_double_variables, "%u", &number_of_state_double_variables);
if (system_return == -1)
{
printf("Failed reading file inputs/number_of_state_double_variables.txt\n");
}
fclose(infile_number_of_state_double_variables);
/* Get the number of state int variables */
unsigned int number_of_state_int_variables = 0;
FILE* infile_number_of_state_int_variables = fopen("inputs/number_of_state_int_variables.txt", "r");
system_return = fscanf(infile_number_of_state_int_variables, "%u", &number_of_state_int_variables);
if (system_return == -1)
{
printf("Failed reading file inputs/number_of_state_int_variables.txt\n");
}
fclose(infile_number_of_state_int_variables);
/* Get state double variables */
double** state_double_variables;
FILE* infile_state_double_variables = fopen("inputs/state_double_variables.txt", "r");
state_double_variables = malloc(sizeof(double*) * number_of_states);
for (i = 0; i < number_of_states; i++)
{
state_double_variables[i] = malloc(sizeof(double) * number_of_state_double_variables);
for (j = 0; j < number_of_state_double_variables; j++)
{
system_return = fscanf(infile_state_double_variables, "%lf\t", &state_double_variables[i][j]);
if (system_return == -1)
{
printf("Failed reading file inputs/state_double_variables.txt\n");
}
} // end of j loop
} // end of i loop
fclose(infile_state_double_variables);
/* Get state int variables */
int** state_int_variables;
FILE* infile_state_int_variables = fopen("inputs/state_int_variables.txt", "r");
state_int_variables = malloc(sizeof(int*) * number_of_states);
for (i = 0; i < number_of_states; i++)
{
state_int_variables[i] = malloc(sizeof(int) * number_of_state_int_variables);
for (j = 0; j < number_of_state_int_variables; j++)
{
system_return = fscanf(infile_state_int_variables, "%d\t", &state_int_variables[i][j]);
if (system_return == -1)
{
printf("Failed reading file inputs/state_int_variables.txt\n");
}
} // end of j loop
} // end of i loop
fclose(infile_state_int_variables);
/* Set the number of tilings */
unsigned int number_of_state_tilings = 4;
/* Set the number of tiles per tiling */
unsigned int number_of_state_tiles_per_state_tiling = 4 * 4;
/* Calculate the number of tiles */
unsigned int number_of_state_tiles = number_of_state_tilings * number_of_state_tiles_per_state_tiling;
/* Create array to store state tile indicies */
unsigned int* state_tile_indices;
state_tile_indices = malloc(sizeof(unsigned int) * number_of_state_tilings);
for (i = 0; i < number_of_state_tilings; i++)
{
state_tile_indices[i] = 0;
} // end of i loop
/* Create array to store next state tile indicies */
unsigned int* next_state_tile_indices;
next_state_tile_indices = malloc(sizeof(unsigned int) * number_of_state_tilings);
for (i = 0; i < number_of_state_tilings; i++)
{
next_state_tile_indices[i] = 0;
} // end of i loop
/*********************************************************************************************************/
/********************************************* SETUP WEIGHTS *********************************************/
/*********************************************************************************************************/
/* Get max number of actions */
unsigned int max_number_of_actions = 0;
for (i = 0; i < number_of_non_terminal_states; i++)
{
if (number_of_actions_per_non_terminal_state[i] > max_number_of_actions)
{
max_number_of_actions = number_of_actions_per_non_terminal_state[i];
}
} // end of i loop
/* Set the number of features */
unsigned int number_of_weights = number_of_state_tiles * max_number_of_actions;
/* Create our weights */
double* weights;
weights = malloc(sizeof(double) * number_of_weights);
/* Initialize weights to zero */
for (i = 0; i < number_of_weights; i++)
{
weights[i] = 0.0;
} // end of i loop
/*********************************************************************************************************/
/**************************************** SETUP POLICY ITERATION *****************************************/
/*********************************************************************************************************/
/* Set the number of episodes */
unsigned int number_of_episodes = 100000;
/* Set the maximum episode length */
unsigned int maximum_episode_length = 200;
/* Create state-action-value function array */
double* approximate_state_action_value_function;
approximate_state_action_value_function = malloc(sizeof(double) * max_number_of_actions);
for (i = 0; i < max_number_of_actions; i++)
{
approximate_state_action_value_function[i] = 0.0;
} // end of i loop
/* Create policy array */
double* policy;
policy = malloc(sizeof(double) * max_number_of_actions);
for (i = 0; i < max_number_of_actions; i++)
{
policy[i] = 1.0 / max_number_of_actions;
} // end of i loop
/* Create policy cumulative sum array */
double* policy_cumulative_sum;
policy_cumulative_sum = malloc(sizeof(double) * max_number_of_actions);
policy_cumulative_sum[0] = policy[0];
for (i = 1; i < max_number_of_actions; i++)
{
policy_cumulative_sum[i] = policy_cumulative_sum[i - 1] + policy[i];
} // end of i loop
/* Set learning rate alpha */
double alpha = 0.1;
/* Set epsilon for our epsilon level of exploration */
double epsilon = 0.1;
/* Set discounting factor gamma */
double discounting_factor_gamma = 1.0;
/* Set random seed */
srand(0);
/*********************************************************************************************************/
/****************************************** RUN POLICY CONTROL *****************************************/
/*********************************************************************************************************/
printf("\nInitial weights:\n");
for (i = 0; i < number_of_weights; i++)
{
printf("%lf\t", weights[i]);
} // end of i loop
printf("\n");
printf("\nInitial state-action-value function:\n");
for (i = 0; i < number_of_states; i++)
{
printf("%u", i);
GetTileIndices(number_of_state_tilings, number_of_state_tiles, state_double_variables[i], number_of_state_double_variables, state_int_variables[i], number_of_state_int_variables, state_tile_indices);
for (j = 0; j < max_number_of_actions; j++)
{
printf("\t%lf", ApproximateStateActionValueFunction(number_of_state_tilings, number_of_state_tiles, state_tile_indices, j, weights));
} // end of j loop
printf("\n");
} // end of i loop
unsigned int initial_state_index = 0, initial_action_index = 0;
/* Loop over episodes */
for (i = 0; i < number_of_episodes; i++)
{
/* Initialize episode to get initial state and action */
InitializeEpisode(number_of_non_terminal_states, max_number_of_actions, state_tile_indices, number_of_state_tilings, number_of_state_tiles, state_double_variables, number_of_state_double_variables, state_int_variables, number_of_state_int_variables, weights, approximate_state_action_value_function, policy, policy_cumulative_sum, epsilon, &initial_state_index, &initial_action_index);
/* Loop through episode and update the policy */
LoopThroughEpisode(number_of_non_terminal_states, number_of_state_action_successor_states, state_action_successor_state_indices, state_action_successor_state_transition_probabilities_cumulative_sum, state_action_successor_state_rewards, max_number_of_actions, number_of_state_tilings, number_of_state_tiles, state_double_variables, number_of_state_double_variables, state_int_variables, number_of_state_int_variables, state_tile_indices, next_state_tile_indices, weights, approximate_state_action_value_function, policy, policy_cumulative_sum, alpha, epsilon, discounting_factor_gamma, maximum_episode_length, initial_state_index, initial_action_index);
} // end of i loop
/*********************************************************************************************************/
/**************************************** PRINT VALUES AND POLICIES ****************************************/
/*********************************************************************************************************/
printf("\nFinal weights:\n");
for (i = 0; i < number_of_weights; i++)
{
printf("%lf\t", weights[i]);
} // end of i loop
printf("\n");
printf("\nFinal state-action-value function:\n");
for (i = 0; i < number_of_states; i++)
{
printf("%u", i);
GetTileIndices(number_of_state_tilings, number_of_state_tiles, state_double_variables[i], number_of_state_double_variables, state_int_variables[i], number_of_state_int_variables, state_tile_indices);
for (j = 0; j < max_number_of_actions; j++)
{
printf("\t%lf", ApproximateStateActionValueFunction(number_of_state_tilings, number_of_state_tiles, state_tile_indices, j, weights));
} // end of j loop
printf("\n");
} // end of i loop
/*********************************************************************************************************/
/****************************************** FREE DYNAMIC MEMORY ******************************************/
/*********************************************************************************************************/
/* Free policy iteration arrays */
free(policy_cumulative_sum);
free(policy);
free(approximate_state_action_value_function);
/* Free weight arrays */
free(weights);
/* Free tiling arrays */
free(next_state_tile_indices);
free(state_tile_indices);
for (i = 0; i < number_of_states; i++)
{
free(state_int_variables[i]);
free(state_double_variables[i]);
} // end of i loop
free(state_int_variables);
free(state_double_variables);
/* Free environment arrays */
for (i = 0; i < number_of_non_terminal_states; i++)
{
for (j = 0; j < number_of_actions_per_non_terminal_state[i]; j++)
{
free(state_action_successor_state_rewards[i][j]);
free(state_action_successor_state_transition_probabilities_cumulative_sum[i][j]);
free(state_action_successor_state_transition_probabilities[i][j]);
free(state_action_successor_state_indices[i][j]);
} // end of j loop
free(state_action_successor_state_rewards[i]);
free(state_action_successor_state_transition_probabilities_cumulative_sum[i]);
free(state_action_successor_state_transition_probabilities[i]);
free(state_action_successor_state_indices[i]);
free(number_of_state_action_successor_states[i]);
} // end of i loop
free(state_action_successor_state_rewards);
free(state_action_successor_state_transition_probabilities_cumulative_sum);
free(state_action_successor_state_transition_probabilities);
free(state_action_successor_state_indices);
free(number_of_state_action_successor_states);
free(number_of_actions_per_state);
free(number_of_actions_per_non_terminal_state);
return 0;
} // end of main
/*********************************************************************************************************/
/*********************************************** FUNCTIONS ***********************************************/
/*********************************************************************************************************/
/* This function gets the tile indicies for each tiling */
void GetTileIndices(unsigned int num_tilings, unsigned int memory_size, double* doubles, unsigned int num_doubles, int* ints, unsigned int num_ints, unsigned int* tile_indices)
{
unsigned int i, j;
int qstate[MAX_NUM_VARS];
int base[MAX_NUM_VARS];
int coordinates[MAX_NUM_VARS * 2 + 1]; /* one interval number per relevant dimension */
unsigned int num_coordinates = num_doubles + num_ints + 1;
for (i = 0; i < num_ints; i++)
{
coordinates[num_doubles + 1 + i] = ints[i];
} // end of i loop
/* Quantize state to integers (henceforth, tile widths == num_tilings) */
for (i = 0; i < num_doubles; i++)
{
qstate[i] = (int)floor(doubles[i] * num_tilings);
base[i] = 0;
}
/* Compute the tile numbers */
for (j = 0; j < num_tilings; j++)
{
/* Loop over each relevant dimension */
for (i = 0; i < num_doubles; i++)
{
/* Find coordinates of activated tile in tiling space */
coordinates[i] = qstate[i] - ModuloNegativeSafe(qstate[i] - base[i], num_tilings);
/* Compute displacement of next tiling in quantized space */
base[i] += 1 + (2 * i);
} // end of i loop
/* Add additional indices for tiling and hashing_set so they hash differently */
coordinates[i] = j;
tile_indices[j] = HashTiles(coordinates, num_coordinates, memory_size, 449);
} // end of j loop
return;
} // end of GetTileIndices function
/* This function takes the modulo of n by k even when n is negative */
int ModuloNegativeSafe(int n, int k)
{
return (n >= 0) ? n % k : k - 1 - ((-n - 1) % k);
} // end of ModuloNegativeSafe function
/* This function takes an array of integers and returns the corresponding tile after hashing */
int HashTiles(int* ints, unsigned int num_ints, long m, int increment)
{
static unsigned int rndseq[2048];
static int first_call = 1;
unsigned int i, k;
long index;
long sum = 0;
/* If first call to hashing, initialize table of random numbers */
if (first_call)
{
for (k = 0; k < 2048; k++)
{
rndseq[k] = 0;
for (i = 0; i < (int)sizeof(int); ++i)
{
rndseq[k] = (rndseq[k] << 8) | (rand() & 0xff);
} /// end of i loop
} // end of k loop
first_call = 0;
}
for (i = 0; i < num_ints; i++)
{
/* Add random table offset for this dimension and wrap around */
index = ints[i];
index += (increment * i);
index %= 2048;
while (index < 0)
{
index += 2048;
}
/* Add selected random number to sum */
sum += (long)rndseq[(int)index];
} // end of i loop
index = (int)(sum % m);
while (index < 0)
{
index += m;
}
return(index);
} // end of HashTiles function
/* This function initializes episodes */
void InitializeEpisode(unsigned int number_of_non_terminal_states, unsigned int max_number_of_actions, unsigned int* state_tile_indices, unsigned int number_of_state_tilings, unsigned int number_of_state_tiles, double** state_double_variables, unsigned int number_of_state_double_variables, int** state_int_variables, unsigned int number_of_state_int_variables, double* weights, double* approximate_state_action_value_function, double* policy, double* policy_cumulative_sum, double epsilon, unsigned int* initial_state_index, unsigned int* initial_action_index)
{
unsigned int i;
double probability = 0.0;
/* Initial state */
(*initial_state_index) = rand() % number_of_non_terminal_states; // randomly choose an initial state from all non-terminal states
/* Get tiled feature indices of state */
GetTileIndices(number_of_state_tilings, number_of_state_tiles, state_double_variables[(*initial_state_index)], number_of_state_double_variables, state_int_variables[(*initial_state_index)], number_of_state_int_variables, state_tile_indices);
/* Get initial action */
probability = UnifRand();
/* Choose policy for chosen state by epsilon-greedy choosing from the state-action-value function */
EpsilonGreedyPolicyFromApproximateStateActionFunction(max_number_of_actions, number_of_state_tilings, number_of_state_tiles, state_tile_indices, weights, approximate_state_action_value_function, policy, policy_cumulative_sum, epsilon);
/* Find which action using probability */
for (i = 0; i < max_number_of_actions; i++)
{
if (probability <= policy_cumulative_sum[i])
{
(*initial_action_index) = i;
break; // break i loop since we found our index
}
} // end of i loop
return;
} // end of InitializeEpisode function
/* This function selects a policy with using epsilon-greedy from the approximate state-action-value function */
void EpsilonGreedyPolicyFromApproximateStateActionFunction(unsigned int max_number_of_actions, unsigned int number_of_state_tilings, unsigned int number_of_state_tiles, unsigned int* state_tile_indices, double* weights, double* approximate_state_action_value_function, double* policy, double* policy_cumulative_sum, double epsilon)
{
unsigned int i, max_action_count = 1;
double max_state_action_value = -DBL_MAX, max_policy_apportioned_probability_per_action = 1.0, remaining_apportioned_probability_per_action = 0.0;
/* Update policy greedily from state-value function */
for (i = 0; i < max_number_of_actions; i++)
{
/* Save max state action value and find the number of actions that have the same max state action value */
approximate_state_action_value_function[i] = ApproximateStateActionValueFunction(number_of_state_tilings, number_of_state_tiles, state_tile_indices, i, weights);
if (approximate_state_action_value_function[i] > max_state_action_value)
{
max_state_action_value = approximate_state_action_value_function[i];
max_action_count = 1;
}
else if (approximate_state_action_value_function[i] == max_state_action_value)
{
max_action_count++;
}
} // end of i loop
/* Apportion policy probability across ties equally for state-action pairs that have the same value and spread out epsilon otherwise */
if (max_action_count == max_number_of_actions)
{
max_policy_apportioned_probability_per_action = 1.0 / max_action_count;
remaining_apportioned_probability_per_action = 0.0;
}
else
{
max_policy_apportioned_probability_per_action = (1.0 - epsilon) / max_action_count;
remaining_apportioned_probability_per_action = epsilon / (max_number_of_actions - max_action_count);
}
/* Update policy with our apportioned probabilities */
for (i = 0; i < max_number_of_actions; i++)
{
if (approximate_state_action_value_function[i] == max_state_action_value)
{
policy[i] = max_policy_apportioned_probability_per_action;
}
else
{
policy[i] = remaining_apportioned_probability_per_action;
}
} // end of i loop
/* Update policy cumulative sum */
policy_cumulative_sum[0] = policy[0];
for (i = 1; i < max_number_of_actions; i++)
{
policy_cumulative_sum[i] = policy_cumulative_sum[i - 1] + policy[i];
} // end of i loop
return;
} // end of EpsilonGreedyPolicyFromStateActionFunction function
/* This function loops through episodes and updates the policy */
void LoopThroughEpisode(unsigned int number_of_non_terminal_states, unsigned int** number_of_state_action_successor_states, unsigned int*** state_action_successor_state_indices, double*** state_action_successor_state_transition_probabilities_cumulative_sum, double*** state_action_successor_state_rewards, unsigned int max_number_of_actions, unsigned int number_of_state_tilings, unsigned int number_of_state_tiles, double** state_double_variables, unsigned int number_of_state_double_variables, int** state_int_variables, unsigned int number_of_state_int_variables, unsigned int* state_tile_indices, unsigned int* next_state_tile_indices, double* weights, double* approximate_state_action_value_function, double* policy, double* policy_cumulative_sum, double alpha, double epsilon, double discounting_factor_gamma, unsigned int maximum_episode_length, unsigned int state_index, unsigned int action_index)
{
unsigned int i, j;
unsigned int successor_state_transition_index, next_state_index, next_action_index;
double probability, reward;
/* Loop through episode steps until termination */
for (i = 0; i < maximum_episode_length; i++)
{
/* Get reward */
probability = UnifRand();
for (j = 0; j < number_of_state_action_successor_states[state_index][action_index]; j++)
{
if (probability <= state_action_successor_state_transition_probabilities_cumulative_sum[state_index][action_index][j])
{
successor_state_transition_index = j;
break; // break j loop since we found our index
}
} // end of j loop
/* Get reward from state and action */
reward = state_action_successor_state_rewards[state_index][action_index][successor_state_transition_index];
/* Get next state */
next_state_index = state_action_successor_state_indices[state_index][action_index][successor_state_transition_index];
/* Check to see if we actioned into a terminal state */
if (next_state_index >= number_of_non_terminal_states)
{
/* Get tiled feature indices of state */
GetTileIndices(number_of_state_tilings, number_of_state_tiles, state_double_variables[state_index], number_of_state_double_variables, state_int_variables[state_index], number_of_state_int_variables, state_tile_indices);
/* Update weights */
for (j = 0; j < number_of_state_tilings; j++)
{
weights[action_index * number_of_state_tiles + state_tile_indices[j]] += alpha * (reward - ApproximateStateActionValueFunction(number_of_state_tilings, number_of_state_tiles, state_tile_indices, action_index, weights)); // since this is linear grad(q(S, A, w)) = x(S, A, w) which is 1 for tiled index otherwise 0
} // end of j loop
break; // episode terminated since we ended up in a terminal state
}
else
{
/* Get tiled feature indices of next state */
GetTileIndices(number_of_state_tilings, number_of_state_tiles, state_double_variables[next_state_index], number_of_state_double_variables, state_int_variables[next_state_index], number_of_state_int_variables, next_state_tile_indices);
/* Get next action */
probability = UnifRand();
/* Choose policy for chosen state by epsilon-greedy choosing from the state-action-value function */
EpsilonGreedyPolicyFromApproximateStateActionFunction(max_number_of_actions, number_of_state_tilings, number_of_state_tiles, next_state_tile_indices, weights, approximate_state_action_value_function, policy, policy_cumulative_sum, epsilon);
/* Find which action using probability */
for (j = 0; j < max_number_of_actions; j++)
{
if (probability <= policy_cumulative_sum[j])
{
next_action_index = j;
break; // break j loop since we found our index
}
} // end of j loop
/* Update weights */
for (j = 0; j < number_of_state_tilings; j++)
{
weights[action_index * number_of_state_tiles + state_tile_indices[j]] += alpha * (reward + discounting_factor_gamma * ApproximateStateActionValueFunction(number_of_state_tilings, number_of_state_tiles, next_state_tile_indices, next_action_index, weights) - ApproximateStateActionValueFunction(number_of_state_tilings, number_of_state_tiles, state_tile_indices, action_index, weights)); // since this is linear grad(q(S, A, w)) = x(S, A, w) which is 1 for tiled index otherwise 0
} // end of j loop
/* Update state and action to next state and action */
state_index = next_state_index;
action_index = next_action_index;
}
} // end of i loop
return;
} // end of LoopThroughEpisode function
/* This function calculates the approximate state action value function w^T * x */
double ApproximateStateActionValueFunction(unsigned int number_of_state_tilings, unsigned int number_of_state_tiles, unsigned int* state_tile_indices, unsigned int action_index, double* weights)
{
unsigned int i;
double approximate_state_action_value_function = 0.0;
for (i = 0; i < number_of_state_tilings; i++)
{
approximate_state_action_value_function += weights[action_index * number_of_state_tiles + state_tile_indices[i]];
} // end of i loop
return approximate_state_action_value_function;
} // end of ApproximateStateActionValueFunction function
/* This function returns a random uniform number within range [0,1] */
double UnifRand(void)
{
return (double)rand() / (double)RAND_MAX;
} // end of UnifRand function |
the_stack_data/90727.c | void main()
{
int x = 0;
int y = 0;
while(x<10)
{
++x;
++y;
}
while(y<20)
{
++y;
++x;
}
assert(x==20 && y==20);
}
|
the_stack_data/1106401.c | /* Exercise 3-1. Our binary search makes two tests inside the loop, when one would suffice (at the price of more tests outside.)
Write a version with only one test inside the loop and measure the difference in run-time. */
#include <stdio.h>
#include <time.h>
#define VERSION 2 /* change the version number to either 1 or 2 */
#define CHECK_RUNTIME 1 /* change to 0 to turn off runtime check else for runtime check set value to > 0 */
int binsearch_V01(int x, int v[], int n);
int binsearch_V02(int x, int v[], int n);
double runtime_diff(int x, int v[], int n);
int main()
{
int x = 11;
int n = 11;
int v[11] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
int found_V01, found_V02;
if (VERSION == 1)
{
found_V01 = binsearch_V01(x, v, n);
if (found_V01 > 0)
printf("Position of element %d in array v[] is %d (V01)\n", x, found_V01);
else
printf("Element %d not found\n", x);
}
else if (VERSION == 2)
{
found_V02 = binsearch_V02(x, v, n);
if (found_V02 > 0)
printf("Position of element %d in array v[] is %d (V02)\n", x, found_V02);
else
printf("Element %d not found\n", x);
}
else
printf("Entered version number is not correct\n");
if (CHECK_RUNTIME > 0)
{
/* runtime difference b/w 2 versions */
printf("runtime difference b/w V01 and V02 (V01 - V02) ran over 10,000 times is = %f\n", runtime_diff(x, v, n));
}
return 0;
}
/* binsearch_V01: find x in v[0] <= v[1] <= ... <= v[n-1] */
int binsearch_V01(int x, int v[], int n)
{
int low, high, mid;
low = 0;
high = n - 1;
while (low <= high)
{
mid = (low+high)/2;
if (x < v[mid])
high = mid - 1;
else if (x > v[mid])
low = mid + 1;
else /* found match */
return mid;
}
return -1; /* no match */
}
/* binsearch_V02: find x in v[0] <= v[1] <= ... <= v[n-1] :- version with only one test inside the loop */
int binsearch_V02(int x, int v[], int n)
{
int low, high, mid;
low = 0;
high = n - 1;
while (low <= high)
{
mid = (low+high)/2;
if (x < v[mid])
high = mid - 1;
else
low = mid + 1;
}
if (low >= high)
return low-1;
else
return -1;
}
double runtime_diff(int x, int v[], int n)
{
int average = 10000;
int i;
double time_spent1 = 0;
double time_spent2 = 0;
for (i = 0; i < average; i++)
{
clock_t begin1 = clock();
binsearch_V01(x, v, n);
clock_t end1 = clock();
time_spent1 += (double)(end1 - begin1) / CLOCKS_PER_SEC;
clock_t begin2 = clock();
binsearch_V02(x, v, n);
clock_t end2 = clock();
time_spent2 += (double)(end2 - begin2) / CLOCKS_PER_SEC;
}
return (time_spent1 - time_spent2);
}
|
the_stack_data/590936.c | // autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <endian.h>
#include <fcntl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <linux/genetlink.h>
#include <linux/if_addr.h>
#include <linux/if_link.h>
#include <linux/in6.h>
#include <linux/neighbour.h>
#include <linux/net.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/veth.h>
struct nlmsg {
char* pos;
int nesting;
struct nlattr* nested[8];
char buf[1024];
};
static struct nlmsg nlmsg;
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;
memcpy(attr + 1, data, size);
nlmsg->pos += NLMSG_ALIGN(attr->nla_len);
}
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 (hdr->nlmsg_type == NLMSG_DONE) {
*reply_len = 0;
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_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_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;
}
const int kInitNetNsFd = 239;
#define DEVLINK_FAMILY_NAME "devlink"
#define DEVLINK_CMD_PORT_GET 5
#define DEVLINK_CMD_RELOAD 37
#define DEVLINK_ATTR_BUS_NAME 1
#define DEVLINK_ATTR_DEV_NAME 2
#define DEVLINK_ATTR_NETDEV_NAME 7
#define DEVLINK_ATTR_NETNS_FD 138
static int netlink_devlink_id_get(struct nlmsg* nlmsg, int sock)
{
struct genlmsghdr genlhdr;
struct nlattr* attr;
int err, n;
uint16_t id = 0;
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, DEVLINK_FAMILY_NAME,
strlen(DEVLINK_FAMILY_NAME) + 1);
err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n);
if (err) {
return -1;
}
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); /* recv ack */
return id;
}
static void netlink_devlink_netns_move(const char* bus_name,
const char* dev_name, int netns_fd)
{
struct genlmsghdr genlhdr;
int sock;
int id, err;
sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (sock == -1)
exit(1);
id = netlink_devlink_id_get(&nlmsg, sock);
if (id == -1)
goto error;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = DEVLINK_CMD_RELOAD;
netlink_init(&nlmsg, id, 0, &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);
netlink_attr(&nlmsg, DEVLINK_ATTR_NETNS_FD, &netns_fd, sizeof(netns_fd));
err = netlink_send(&nlmsg, sock);
if (err) {
}
error:
close(sock);
}
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_devlink_id_get(&nlmsg, sock);
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) {
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);
}
static void initialize_devlink_pci(void)
{
int netns = open("/proc/self/ns/net", O_RDONLY);
if (netns == -1)
exit(1);
int ret = setns(kInitNetNsFd, 0);
if (ret == -1)
exit(1);
netlink_devlink_netns_move("pci", "0000:00:10.0", netns);
ret = setns(netns, 0);
if (ret == -1)
exit(1);
close(netns);
initialize_devlink_ports("pci", "0000:00:10.0", "netpci");
}
static long syz_open_dev(volatile long a0, volatile long a1, volatile long a2)
{
if (a0 == 0xc || a0 == 0xb) {
char buf[128];
sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1,
(uint8_t)a2);
return open(buf, O_RDWR, 0);
} else {
char buf[1024];
char* hash;
strncpy(buf, (char*)a0, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = 0;
while ((hash = strchr(buf, '#'))) {
*hash = '0' + (char)(a1 % 10);
a1 /= 10;
}
return open(buf, a2, 0);
}
}
uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff,
0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x32ul, -1, 0);
intptr_t res = 0;
res = syz_open_dev(0xc, 4, 1);
if (res != -1)
r[0] = res;
*(uint32_t*)0x20000000 = 0;
*(uint32_t*)0x20000004 = 0;
*(uint32_t*)0x20000008 = 1;
*(uint32_t*)0x2000000c = 3;
*(uint32_t*)0x20000010 = 0x100;
*(uint64_t*)0x20000018 = 0x200003c0;
memcpy(
(void*)0x200003c0,
"\xcb\xb6\x2c\x7c\x7e\x12\x72\x7d\x60\xc5\xdb\x26\x5c\x1d\x8b\x3f\x75\x25"
"\x50\xd4\xea\xc7\xaf\xf1\x02\x13\x26\xe1\x5d\xfd\xad\x91\x1d\x57\xa8\x53"
"\x41\x4b\x19\x47\x02\xa4\x1a\x75\x60\x56\x8b\xe1\x11\x1d\xac\x9f\xf2\x58"
"\x6d\x67\xdc\x8e\xf3\xe9\xd3\x66\x94\xc5\xea\x96\xd8\x98\x5a\x99\x53\xe8"
"\x77\x5c\xbf\x7a\xe1\x51\xea\x1f\xd6\x1f\xbc\x2d\x44\xe7\x60\x31\x83\x3d"
"\xff\xb4\x47\xc4\x25\xc9\x74\x9c\x7d\xe7\xfb\xe2\xe5\x65\xb4\xa2\x5f\x7b"
"\x2a\xc0\x13\x92\xce\x04\xec\x8d\x6d\x21\x0e\x0a\x23\xae\x3a\x5f\xd8\x1c"
"\x3c\x89\xc9\x28\x74\x70\x9f\xcd\xd4\xd4\xc3\xff\xe7\xfa\x05\x2a\xc6\x8f"
"\xb6\xdf\x7e\x48\x2e\x24\xbe\x6a\xc8\x19\x10\x39\xb4\x34\xaa\x0e\x9f\x97"
"\x39\xae\xdf\x30\xc0\xfa\x9c\x42\xcd\xa4\x11\x02\x5c\xa2\x0c\x42\xbf\x88"
"\x68\x56\x03\x99\x87\x3f\x4d\x1b\x28\xed\x71\x3e\x41\x1b\x34\xec\x02\x63"
"\x21\xc8\xcd\x9a\xd1\x7c\xbc\x95\x70\x4c\x14\x2d\x7c\x71\x06\x3b\x4a\x0b"
"\x52\xe2\x20\x73\xf8\x59\xd6\x32\x89\x92\x12\x6e\x5f\x50\x57\xad\x1d\x02"
"\x29\xba\xde\xc1\xe0\x88\x0f\x47\x6f\x18\xce\x68\x55\x60\x78\xa0\x06\x7d"
"\x8e\x90\x05\x7f\x56\x0b\x51\x51\xc4\x50\xe6\x55\x89\x81\x2f\x77\x9b\x50"
"\xe4\xde\xd6\x60\xee\x4a\xa6\x1e\x7f\x84\xa9\xb4\xb7\x91\x83\x71\x14\x09"
"\x55\x39\xfb\x55\x73\xe4\x7c\xce\x26\xdc\x38\x31\x19\x13\x99\x51\x81\xe7"
"\x28\xfd\x4d\x6d\x33\x4e\x62\xfd\x0a\x82\x2f\x93\x71\xbc\xdc\x43\xc8\xa6"
"\x96\x88\xa1\x1f\xc9\xf4\x3a\xfe\x64\x2c\x30\xdd\xf3\x94\x65\xb1\x3c\xf1"
"\xdd\xad\xd7\x89\x70\x77\x18\x27\xf4\x45\xf0\xd4\x56\x1e\x8e\x2b\xb6\xcf"
"\x22\x44\x63\x4b\xcd\x72\xd1\x24\xf3\xca\xa1\x52\xc6\xfd\x6d\x47\xbb\x00"
"\x4b\x97\x97\x5d\x4a\x46\xb2\xee\x12\x9b\x88\x9d\xc5\x9c\x1c\x71\x62\xff"
"\xf2\x2c\x42\x95\x54\x52\x95\xea\x72\xfe\x14\xc6\xb2\xba\xb3\x5a\xb5\x45"
"\x51\x73\x98\xb0\x03\xb6\xd3\xb8\x9c\x5c\x64\xb4\x49\xf7\xd5\x60\xdd\xe2"
"\x0f\xc1\x3b\x3e\xc8\x8d\xc0\x52\x42\xa1\x60\x07\x6c\xcb\xff\x3e\x32\xb8"
"\x78\x0b\xd1\x91\xa0\xb1\x2a\x6f\x99\x00\xa9\x3f\xa1\x2d\x9f\xb5\xed\x34"
"\x88\xd5\xcd\x0a\xa3\x29\x58\x3f\x2c\x47\xc4\xfd\x47\x26\x46\x9c\x98\xe0"
"\xb6\x6d\x74\xc3\x1d\x0a\x1f\x7f\xc1\x0c\xc1\x94\x4d\x25\x26\x7e\xff\x7a"
"\x74\x0c\xc4\x30\x06\x9b\x58\x47\x9c\xa6\x96\x00\x63\x6a\x0f\x22\xa4\x70"
"\xa6\x9b\x46\xc1\xcc\x1b\x95\xcf\x32\xdd\x7b\x73\xad\x67\x41\x61\xca\x39"
"\x25\x83\xaa\x83\x4a\xaa\xde\x88\xa4\x39\x33\x89\xb7\x6d\x58\x8a\x60\x81"
"\x91\xdb\x7c\xa7\x5d\xd0\x09\x38\x2a\x45\x83\xe8\x78\x1e\xb0\x9f\x48\xa4"
"\x4d\x06\xb4\x17\x56\xeb\x3f\x1b\x7e\xea\x18\xad\xf2\x97\x83\x22\xd0\xb3"
"\x84\xdf\x03\x07\x98\x91\xe1\x0f\x09\x2c\x57\x33\x20\xfb\x94\x1f\x10\xe3"
"\xc3\xaf\x6f\x3e\x72\xb2\xaf\xcd\x95\xa3\x66\x6a\x6a\x40\xa8\x40\xe6\x3d"
"\x1c\xb9\xe2\x49\x25\xc0\x49\x7a\x04\xef\x7b\x9b\x1e\xe3\x9d\xe0\x45\x6f"
"\xec\xd6\x76\xac\xee\x23\x3f\x5b\x64\x5e\x8d\x05\xf3\xf5\x05\xa1\x2a\x0f"
"\x5b\x35\x65\x86\xf2\x2c\x2c\x2c\xeb\xef\x83\xc5\xe6\x8c\x22\x72\x34\x95"
"\xab\xa0\x64\x27\x92\x55\xde\x48\x9e\x33\xe9\x20\x9a\x63\x68\x90\xbc\xfb"
"\x2a\x52\x7e\x8d\xa8\x36\x21\xae\xf3\x74\xf5\xa1\x1d\x8a\xc7\x7f\x5d\xcd"
"\x42\x1f\x45\xe5\x2d\xdf\x9b\xc3\x5f\x64\xcf\x72\x1c\xe6\xc9\x6b\x56\x13"
"\x26\x8c\x02\x5c\xa9\x91\x0a\x8a\x23\x5e\x6a\xf3\xd6\x7a\xdd\xc6\x6e\x75"
"\xc1\x56\x4a\x7f\x86\x84\xfc\xd2\x3e\xc9\x8d\x61\xa4\xfa\x42\x2c\x55\xe6"
"\x78\x9c\xbc\x42\xb1\xd5\x32\x63\x3e\x65\x8a\x5c\x2f\xfe\x57\x67\x03\x97"
"\x62\xf1\x8c\xce\x89\xb8\x00\x0e\x37\xca\xbc\x35\x40\x9d\x3c\x7a\x02\x13"
"\xde\x87\xce\x95\xcf\xbf\xb0\xc7\x1b\xe4\xc4\xef\x44\x86\x6b\xd8\xe0\x50"
"\xe3\x36\xb3\x1a\x6e\x8f\x15\xbd\x21\x60\xe5\x48\x48\xad\xa2\x56\xdf\x90"
"\x27\x58\xeb\xbc\x1e\x83\x7f\xab\x4c\xb8\xbb\x84\x67\xa7\x3d\xf7\x17\xd9"
"\x2e\x22\x04\x48\x2f\xe9\x5c\x21\x12\x11\x86\xa5\x7c\x3b\x12\xf7\x5c\x83"
"\x6a\xb7\x02\x43\x34\x18\xf3\x29\x44\x32\x3e\xaa\xad\xbc\xa3\x66\x96\x1c"
"\x25\x62\x0c\x43\x95\x1a\x7a\x3f\xd3\xe3\xcc\x85\xd6\xa3\x99\x6b\x50\xd1"
"\x2e\xa7\x6d\xf6\x58\xa6\x40\x5f\xdf\x1c\x9f\x2c\x05\x24\x8d\x95\x15\xce"
"\x96\x65\x0e\xbf\x62\x96\x64\xe6\xc1\x92\xdd\x28\xe1\x61\x72\xbe\x15\x93"
"\xe9\x4d\xbc\xa0\xe5\x54\xfc\xe9\x73\x6c\x73\x54\x03\x0c\x64\xfd\xaf\x35"
"\x03\x8e\x1f\x1e\x1d\x20\xe0\x6f\x34\x8e\xf5\xae\x75\x41\x39\xb4\xe8\x12"
"\xc6\x0f\xbc\x55\xba\xce\x83\xf2\x7b\xb8\x35\xc1\x64\xc2\x9f\x5f\x7c\x1d"
"\xbe\xeb\xfd\x98\x8a\x16\x23\x5c\x4b\xbe\xe4\xd9\xa3\xbc\x66\x6f",
1024);
syscall(__NR_ioctl, r[0], 0x4b72ul, 0x20000000ul);
res = syz_open_dev(0xc, 4, 1);
if (res != -1)
r[1] = res;
*(uint16_t*)0x20000000 = 0;
*(uint16_t*)0x20000002 = 0;
*(uint16_t*)0x20000004 = 0x77ff;
*(uint16_t*)0x20000006 = 0xb;
*(uint16_t*)0x20000008 = 0;
*(uint16_t*)0x2000000a = 0;
syscall(__NR_ioctl, r[1], 0x560aul, 0x20000000ul);
res = syz_open_dev(0xc, 4, 1);
if (res != -1)
r[2] = res;
*(uint16_t*)0x20000140 = 0x41;
*(uint16_t*)0x20000142 = 2;
*(uint16_t*)0x20000144 = 7;
syscall(__NR_ioctl, r[2], 0x5609ul, 0x20000140ul);
res = syz_open_dev(0xc, 4, 1);
if (res != -1)
r[3] = res;
syscall(__NR_ioctl, r[3], 0x4b3aul, 0ul);
return 0;
}
|
the_stack_data/206392561.c | /*
Professor_A is going to handle course-Y for the students of
BCB, BCE, BCI, BCT, BDS, BKT. The minimum strength of the class is 10.
Write a C program to read the registration numbers of students attending the course-Y.
Help the professor to analyze the count value of
students with respect to their department_category and display the same.
*/
#include "stdio.h"
#include "string.h"
int main(){
//init roll number type counters
int bcb,bce,bci,bct,bds,bkt;
bcb=0;
bce=0;
bci=0;
bct=0;
bds=0;
bkt=0;
int n;
scanf("%d",&n);
for (int i = 0; i < n; i++)
{
char roll_no[10];
scanf("%s",roll_no);
if (strstr(roll_no,"BCB")!=NULL)
{
bcb++;
}
else if (strstr(roll_no,"BCE")!=NULL)
{
bce++;
}
if (strstr(roll_no,"BCI")!=NULL)
{
bci++;
}
if (strstr(roll_no,"BCT")!=NULL)
{
bct++;
}
if (strstr(roll_no,"BDS")!=NULL)
{
bds++;
}
if (strstr(roll_no,"BKT")!=NULL)
{
bkt++;
}
}
printf("BCB : %d\n",bcb);
printf("BCE : %d\n",bce);
printf("BCI : %d\n",bci);
printf("BCT : %d\n",bct);
printf("BDS : %d\n",bds);
printf("BKT : %d\n",bkt);
} |
the_stack_data/317.c | #include <stdio.h>
#include <time.h>
int main()
{
time_t now;
char buf[40];
time(&now);
strftime(buf, 40, "%c", localtime(&now));
printf("%s\n", buf);
return 0;
}
|
the_stack_data/437289.c | //code implementation of malloc for color to grayscale transformation
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#define NUM_THREADS 50
int main()
{
FILE *image, *outputImage, *lecturas;
image = fopen("sample.bmp","rb"); //Original image
outputImage = fopen("imgMalloc2.bmp","wb"); //Transformed image
double t1, t2, time;
unsigned char r, g, b; //Pixel
unsigned char *rgb, *gs;
rgb = (unsigned char*)malloc(262145*3*sizeof(unsigned char));
gs = (unsigned char*)malloc(262145*3*sizeof(unsigned char));
int j = 0;
for(int i=0; i<54; i++) fputc(fgetc(image), outputImage); //Copy the header of the original to the output image
omp_set_num_threads(NUM_THREADS);
while(!feof(image)){
*(rgb + j) = fgetc(image);
j++;
}
t1 = omp_get_wtime();
#pragma omp parallel
{
#pragma omp for ordered
for(int i =0; i < 262145*3; i+=3){ //Read the channels of each pixel
r = *(rgb + i);
g = *(rgb + i + 1);
b = *(rgb + i + 2);
unsigned char pixel = 0.21*r+0.72*g+0.07*b; //Obtain grays
//write the gray pixels to the new image
#pragma omp ordered
{
*(gs + i) = pixel;
*(gs + i + 1) = pixel;
*(gs + i + 2) = pixel;
}
}
}
t2 = omp_get_wtime();
time = t2 - t1;//execution time
printf("Time = %f\n",time);
for(int i = 0; i < 262145*3; i++){
fputc(*(gs + i), outputImage);
}
free(rgb);
free(gs);
fclose(image);
fclose(outputImage);
return 0;
}
|
the_stack_data/57527.c | # 1 "papi_fwrappers.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "papi_fwrappers.c"
# 22 "papi_fwrappers.c"
#pragma GCC visibility push(default)
# 1 "/usr/include/stdio.h" 1 3 4
# 27 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/features.h" 1 3 4
# 374 "/usr/include/features.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 1 3 4
# 385 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4
# 386 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 2 3 4
# 375 "/usr/include/features.h" 2 3 4
# 398 "/usr/include/features.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 1 3 4
# 10 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/gnu/stubs-64.h" 1 3 4
# 11 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 2 3 4
# 399 "/usr/include/features.h" 2 3 4
# 28 "/usr/include/stdio.h" 2 3 4
# 1 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h" 1 3 4
# 212 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h" 3 4
typedef long unsigned int size_t;
# 34 "/usr/include/stdio.h" 2 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/types.h" 1 3 4
# 27 "/usr/include/x86_64-linux-gnu/bits/types.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4
# 28 "/usr/include/x86_64-linux-gnu/bits/types.h" 2 3 4
typedef unsigned char __u_char;
typedef unsigned short int __u_short;
typedef unsigned int __u_int;
typedef unsigned long int __u_long;
typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef signed short int __int16_t;
typedef unsigned short int __uint16_t;
typedef signed int __int32_t;
typedef unsigned int __uint32_t;
typedef signed long int __int64_t;
typedef unsigned long int __uint64_t;
typedef long int __quad_t;
typedef unsigned long int __u_quad_t;
# 121 "/usr/include/x86_64-linux-gnu/bits/types.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/typesizes.h" 1 3 4
# 122 "/usr/include/x86_64-linux-gnu/bits/types.h" 2 3 4
typedef unsigned long int __dev_t;
typedef unsigned int __uid_t;
typedef unsigned int __gid_t;
typedef unsigned long int __ino_t;
typedef unsigned long int __ino64_t;
typedef unsigned int __mode_t;
typedef unsigned long int __nlink_t;
typedef long int __off_t;
typedef long int __off64_t;
typedef int __pid_t;
typedef struct { int __val[2]; } __fsid_t;
typedef long int __clock_t;
typedef unsigned long int __rlim_t;
typedef unsigned long int __rlim64_t;
typedef unsigned int __id_t;
typedef long int __time_t;
typedef unsigned int __useconds_t;
typedef long int __suseconds_t;
typedef int __daddr_t;
typedef int __key_t;
typedef int __clockid_t;
typedef void * __timer_t;
typedef long int __blksize_t;
typedef long int __blkcnt_t;
typedef long int __blkcnt64_t;
typedef unsigned long int __fsblkcnt_t;
typedef unsigned long int __fsblkcnt64_t;
typedef unsigned long int __fsfilcnt_t;
typedef unsigned long int __fsfilcnt64_t;
typedef long int __fsword_t;
typedef long int __ssize_t;
typedef long int __syscall_slong_t;
typedef unsigned long int __syscall_ulong_t;
typedef __off64_t __loff_t;
typedef __quad_t *__qaddr_t;
typedef char *__caddr_t;
typedef long int __intptr_t;
typedef unsigned int __socklen_t;
# 36 "/usr/include/stdio.h" 2 3 4
# 44 "/usr/include/stdio.h" 3 4
struct _IO_FILE;
typedef struct _IO_FILE FILE;
# 64 "/usr/include/stdio.h" 3 4
typedef struct _IO_FILE __FILE;
# 74 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/libio.h" 1 3 4
# 31 "/usr/include/libio.h" 3 4
# 1 "/usr/include/_G_config.h" 1 3 4
# 15 "/usr/include/_G_config.h" 3 4
# 1 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h" 1 3 4
# 16 "/usr/include/_G_config.h" 2 3 4
# 1 "/usr/include/wchar.h" 1 3 4
# 82 "/usr/include/wchar.h" 3 4
typedef struct
{
int __count;
union
{
unsigned int __wch;
char __wchb[4];
} __value;
} __mbstate_t;
# 21 "/usr/include/_G_config.h" 2 3 4
typedef struct
{
__off_t __pos;
__mbstate_t __state;
} _G_fpos_t;
typedef struct
{
__off64_t __pos;
__mbstate_t __state;
} _G_fpos64_t;
# 32 "/usr/include/libio.h" 2 3 4
# 49 "/usr/include/libio.h" 3 4
# 1 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h" 1 3 4
# 40 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h" 3 4
typedef __builtin_va_list __gnuc_va_list;
# 50 "/usr/include/libio.h" 2 3 4
# 144 "/usr/include/libio.h" 3 4
struct _IO_jump_t; struct _IO_FILE;
# 154 "/usr/include/libio.h" 3 4
typedef void _IO_lock_t;
struct _IO_marker {
struct _IO_marker *_next;
struct _IO_FILE *_sbuf;
int _pos;
# 177 "/usr/include/libio.h" 3 4
};
enum __codecvt_result
{
__codecvt_ok,
__codecvt_partial,
__codecvt_error,
__codecvt_noconv
};
# 245 "/usr/include/libio.h" 3 4
struct _IO_FILE {
int _flags;
char* _IO_read_ptr;
char* _IO_read_end;
char* _IO_read_base;
char* _IO_write_base;
char* _IO_write_ptr;
char* _IO_write_end;
char* _IO_buf_base;
char* _IO_buf_end;
char *_IO_save_base;
char *_IO_backup_base;
char *_IO_save_end;
struct _IO_marker *_markers;
struct _IO_FILE *_chain;
int _fileno;
int _flags2;
__off_t _old_offset;
unsigned short _cur_column;
signed char _vtable_offset;
char _shortbuf[1];
_IO_lock_t *_lock;
# 293 "/usr/include/libio.h" 3 4
__off64_t _offset;
# 302 "/usr/include/libio.h" 3 4
void *__pad1;
void *__pad2;
void *__pad3;
void *__pad4;
size_t __pad5;
int _mode;
char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)];
};
typedef struct _IO_FILE _IO_FILE;
struct _IO_FILE_plus;
extern struct _IO_FILE_plus _IO_2_1_stdin_;
extern struct _IO_FILE_plus _IO_2_1_stdout_;
extern struct _IO_FILE_plus _IO_2_1_stderr_;
# 338 "/usr/include/libio.h" 3 4
typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
typedef __ssize_t __io_write_fn (void *__cookie, const char *__buf,
size_t __n);
typedef int __io_seek_fn (void *__cookie, __off64_t *__pos, int __w);
typedef int __io_close_fn (void *__cookie);
# 390 "/usr/include/libio.h" 3 4
extern int __underflow (_IO_FILE *);
extern int __uflow (_IO_FILE *);
extern int __overflow (_IO_FILE *, int);
# 434 "/usr/include/libio.h" 3 4
extern int _IO_getc (_IO_FILE *__fp);
extern int _IO_putc (int __c, _IO_FILE *__fp);
extern int _IO_feof (_IO_FILE *__fp) __attribute__ ((__nothrow__ , __leaf__));
extern int _IO_ferror (_IO_FILE *__fp) __attribute__ ((__nothrow__ , __leaf__));
extern int _IO_peekc_locked (_IO_FILE *__fp);
extern void _IO_flockfile (_IO_FILE *) __attribute__ ((__nothrow__ , __leaf__));
extern void _IO_funlockfile (_IO_FILE *) __attribute__ ((__nothrow__ , __leaf__));
extern int _IO_ftrylockfile (_IO_FILE *) __attribute__ ((__nothrow__ , __leaf__));
# 464 "/usr/include/libio.h" 3 4
extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict,
__gnuc_va_list, int *__restrict);
extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict,
__gnuc_va_list);
extern __ssize_t _IO_padn (_IO_FILE *, int, __ssize_t);
extern size_t _IO_sgetn (_IO_FILE *, void *, size_t);
extern __off64_t _IO_seekoff (_IO_FILE *, __off64_t, int, int);
extern __off64_t _IO_seekpos (_IO_FILE *, __off64_t, int);
extern void _IO_free_backup_area (_IO_FILE *) __attribute__ ((__nothrow__ , __leaf__));
# 75 "/usr/include/stdio.h" 2 3 4
typedef __gnuc_va_list va_list;
# 90 "/usr/include/stdio.h" 3 4
typedef __off_t off_t;
# 102 "/usr/include/stdio.h" 3 4
typedef __ssize_t ssize_t;
typedef _G_fpos_t fpos_t;
# 164 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/stdio_lim.h" 1 3 4
# 165 "/usr/include/stdio.h" 2 3 4
extern struct _IO_FILE *stdin;
extern struct _IO_FILE *stdout;
extern struct _IO_FILE *stderr;
extern int remove (const char *__filename) __attribute__ ((__nothrow__ , __leaf__));
extern int rename (const char *__old, const char *__new) __attribute__ ((__nothrow__ , __leaf__));
extern int renameat (int __oldfd, const char *__old, int __newfd,
const char *__new) __attribute__ ((__nothrow__ , __leaf__));
extern FILE *tmpfile (void) ;
# 209 "/usr/include/stdio.h" 3 4
extern char *tmpnam (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ;
extern char *tmpnam_r (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ;
# 227 "/usr/include/stdio.h" 3 4
extern char *tempnam (const char *__dir, const char *__pfx)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) ;
extern int fclose (FILE *__stream);
extern int fflush (FILE *__stream);
# 252 "/usr/include/stdio.h" 3 4
extern int fflush_unlocked (FILE *__stream);
# 266 "/usr/include/stdio.h" 3 4
extern FILE *fopen (const char *__restrict __filename,
const char *__restrict __modes) ;
extern FILE *freopen (const char *__restrict __filename,
const char *__restrict __modes,
FILE *__restrict __stream) ;
# 295 "/usr/include/stdio.h" 3 4
# 306 "/usr/include/stdio.h" 3 4
extern FILE *fdopen (int __fd, const char *__modes) __attribute__ ((__nothrow__ , __leaf__)) ;
# 319 "/usr/include/stdio.h" 3 4
extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
__attribute__ ((__nothrow__ , __leaf__)) ;
extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __attribute__ ((__nothrow__ , __leaf__)) ;
extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__));
extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
int __modes, size_t __n) __attribute__ ((__nothrow__ , __leaf__));
extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,
size_t __size) __attribute__ ((__nothrow__ , __leaf__));
extern void setlinebuf (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
extern int fprintf (FILE *__restrict __stream,
const char *__restrict __format, ...);
extern int printf (const char *__restrict __format, ...);
extern int sprintf (char *__restrict __s,
const char *__restrict __format, ...) __attribute__ ((__nothrow__));
extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
__gnuc_va_list __arg);
extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg);
extern int vsprintf (char *__restrict __s, const char *__restrict __format,
__gnuc_va_list __arg) __attribute__ ((__nothrow__));
extern int snprintf (char *__restrict __s, size_t __maxlen,
const char *__restrict __format, ...)
__attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4)));
extern int vsnprintf (char *__restrict __s, size_t __maxlen,
const char *__restrict __format, __gnuc_va_list __arg)
__attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 0)));
# 412 "/usr/include/stdio.h" 3 4
extern int vdprintf (int __fd, const char *__restrict __fmt,
__gnuc_va_list __arg)
__attribute__ ((__format__ (__printf__, 2, 0)));
extern int dprintf (int __fd, const char *__restrict __fmt, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
extern int fscanf (FILE *__restrict __stream,
const char *__restrict __format, ...) ;
extern int scanf (const char *__restrict __format, ...) ;
extern int sscanf (const char *__restrict __s,
const char *__restrict __format, ...) __attribute__ ((__nothrow__ , __leaf__));
# 443 "/usr/include/stdio.h" 3 4
extern int fscanf (FILE *__restrict __stream, const char *__restrict __format, ...) __asm__ ("" "__isoc99_fscanf")
;
extern int scanf (const char *__restrict __format, ...) __asm__ ("" "__isoc99_scanf")
;
extern int sscanf (const char *__restrict __s, const char *__restrict __format, ...) __asm__ ("" "__isoc99_sscanf") __attribute__ ((__nothrow__ , __leaf__))
;
# 463 "/usr/include/stdio.h" 3 4
extern int vfscanf (FILE *__restrict __s, const char *__restrict __format,
__gnuc_va_list __arg)
__attribute__ ((__format__ (__scanf__, 2, 0))) ;
extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg)
__attribute__ ((__format__ (__scanf__, 1, 0))) ;
extern int vsscanf (const char *__restrict __s,
const char *__restrict __format, __gnuc_va_list __arg)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__format__ (__scanf__, 2, 0)));
# 494 "/usr/include/stdio.h" 3 4
extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vfscanf")
__attribute__ ((__format__ (__scanf__, 2, 0))) ;
extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vscanf")
__attribute__ ((__format__ (__scanf__, 1, 0))) ;
extern int vsscanf (const char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vsscanf") __attribute__ ((__nothrow__ , __leaf__))
__attribute__ ((__format__ (__scanf__, 2, 0)));
# 522 "/usr/include/stdio.h" 3 4
extern int fgetc (FILE *__stream);
extern int getc (FILE *__stream);
extern int getchar (void);
# 550 "/usr/include/stdio.h" 3 4
extern int getc_unlocked (FILE *__stream);
extern int getchar_unlocked (void);
# 561 "/usr/include/stdio.h" 3 4
extern int fgetc_unlocked (FILE *__stream);
extern int fputc (int __c, FILE *__stream);
extern int putc (int __c, FILE *__stream);
extern int putchar (int __c);
# 594 "/usr/include/stdio.h" 3 4
extern int fputc_unlocked (int __c, FILE *__stream);
extern int putc_unlocked (int __c, FILE *__stream);
extern int putchar_unlocked (int __c);
extern int getw (FILE *__stream);
extern int putw (int __w, FILE *__stream);
extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
;
# 638 "/usr/include/stdio.h" 3 4
extern char *gets (char *__s) __attribute__ ((__deprecated__));
# 665 "/usr/include/stdio.h" 3 4
extern __ssize_t __getdelim (char **__restrict __lineptr,
size_t *__restrict __n, int __delimiter,
FILE *__restrict __stream) ;
extern __ssize_t getdelim (char **__restrict __lineptr,
size_t *__restrict __n, int __delimiter,
FILE *__restrict __stream) ;
extern __ssize_t getline (char **__restrict __lineptr,
size_t *__restrict __n,
FILE *__restrict __stream) ;
extern int fputs (const char *__restrict __s, FILE *__restrict __stream);
extern int puts (const char *__s);
extern int ungetc (int __c, FILE *__stream);
extern size_t fread (void *__restrict __ptr, size_t __size,
size_t __n, FILE *__restrict __stream) ;
extern size_t fwrite (const void *__restrict __ptr, size_t __size,
size_t __n, FILE *__restrict __s);
# 737 "/usr/include/stdio.h" 3 4
extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
size_t __n, FILE *__restrict __stream) ;
extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size,
size_t __n, FILE *__restrict __stream);
extern int fseek (FILE *__stream, long int __off, int __whence);
extern long int ftell (FILE *__stream) ;
extern void rewind (FILE *__stream);
# 773 "/usr/include/stdio.h" 3 4
extern int fseeko (FILE *__stream, __off_t __off, int __whence);
extern __off_t ftello (FILE *__stream) ;
# 792 "/usr/include/stdio.h" 3 4
extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos);
extern int fsetpos (FILE *__stream, const fpos_t *__pos);
# 815 "/usr/include/stdio.h" 3 4
# 824 "/usr/include/stdio.h" 3 4
extern void clearerr (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
extern int feof (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
extern int ferror (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
extern void clearerr_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
extern int feof_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
extern int ferror_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
extern void perror (const char *__s);
# 1 "/usr/include/x86_64-linux-gnu/bits/sys_errlist.h" 1 3 4
# 26 "/usr/include/x86_64-linux-gnu/bits/sys_errlist.h" 3 4
extern int sys_nerr;
extern const char *const sys_errlist[];
# 854 "/usr/include/stdio.h" 2 3 4
extern int fileno (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
extern int fileno_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
# 873 "/usr/include/stdio.h" 3 4
extern FILE *popen (const char *__command, const char *__modes) ;
extern int pclose (FILE *__stream);
extern char *ctermid (char *__s) __attribute__ ((__nothrow__ , __leaf__));
# 913 "/usr/include/stdio.h" 3 4
extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
# 943 "/usr/include/stdio.h" 3 4
# 25 "papi_fwrappers.c" 2
# 1 "/usr/include/assert.h" 1 3 4
# 66 "/usr/include/assert.h" 3 4
extern void __assert_fail (const char *__assertion, const char *__file,
unsigned int __line, const char *__function)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__noreturn__));
extern void __assert_perror_fail (int __errnum, const char *__file,
unsigned int __line, const char *__function)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__noreturn__));
extern void __assert (const char *__assertion, const char *__file, int __line)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__noreturn__));
# 26 "papi_fwrappers.c" 2
# 1 "/usr/include/string.h" 1 3 4
# 27 "/usr/include/string.h" 3 4
# 1 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h" 1 3 4
# 33 "/usr/include/string.h" 2 3 4
# 44 "/usr/include/string.h" 3 4
extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern void *memmove (void *__dest, const void *__src, size_t __n)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern void *memccpy (void *__restrict __dest, const void *__restrict __src,
int __c, size_t __n)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern void *memset (void *__s, int __c, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern int memcmp (const void *__s1, const void *__s2, size_t __n)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
# 96 "/usr/include/string.h" 3 4
extern void *memchr (const void *__s, int __c, size_t __n)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
# 127 "/usr/include/string.h" 3 4
extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *strncpy (char *__restrict __dest,
const char *__restrict __src, size_t __n)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *strcat (char *__restrict __dest, const char *__restrict __src)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *strncat (char *__restrict __dest, const char *__restrict __src,
size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern int strcmp (const char *__s1, const char *__s2)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern int strncmp (const char *__s1, const char *__s2, size_t __n)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern int strcoll (const char *__s1, const char *__s2)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern size_t strxfrm (char *__restrict __dest,
const char *__restrict __src, size_t __n)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2)));
# 1 "/usr/include/xlocale.h" 1 3 4
# 27 "/usr/include/xlocale.h" 3 4
typedef struct __locale_struct
{
struct __locale_data *__locales[13];
const unsigned short int *__ctype_b;
const int *__ctype_tolower;
const int *__ctype_toupper;
const char *__names[13];
} *__locale_t;
typedef __locale_t locale_t;
# 164 "/usr/include/string.h" 2 3 4
extern int strcoll_l (const char *__s1, const char *__s2, __locale_t __l)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 3)));
extern size_t strxfrm_l (char *__dest, const char *__src, size_t __n,
__locale_t __l) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 4)));
extern char *strdup (const char *__s)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1)));
extern char *strndup (const char *__string, size_t __n)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1)));
# 211 "/usr/include/string.h" 3 4
# 236 "/usr/include/string.h" 3 4
extern char *strchr (const char *__s, int __c)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
# 263 "/usr/include/string.h" 3 4
extern char *strrchr (const char *__s, int __c)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
# 282 "/usr/include/string.h" 3 4
extern size_t strcspn (const char *__s, const char *__reject)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern size_t strspn (const char *__s, const char *__accept)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
# 315 "/usr/include/string.h" 3 4
extern char *strpbrk (const char *__s, const char *__accept)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
# 342 "/usr/include/string.h" 3 4
extern char *strstr (const char *__haystack, const char *__needle)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *strtok (char *__restrict __s, const char *__restrict __delim)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2)));
extern char *__strtok_r (char *__restrict __s,
const char *__restrict __delim,
char **__restrict __save_ptr)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 3)));
extern char *strtok_r (char *__restrict __s, const char *__restrict __delim,
char **__restrict __save_ptr)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 3)));
# 397 "/usr/include/string.h" 3 4
extern size_t strlen (const char *__s)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
extern size_t strnlen (const char *__string, size_t __maxlen)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
extern char *strerror (int __errnum) __attribute__ ((__nothrow__ , __leaf__));
# 427 "/usr/include/string.h" 3 4
extern int strerror_r (int __errnum, char *__buf, size_t __buflen) __asm__ ("" "__xpg_strerror_r") __attribute__ ((__nothrow__ , __leaf__))
__attribute__ ((__nonnull__ (2)));
# 445 "/usr/include/string.h" 3 4
extern char *strerror_l (int __errnum, __locale_t __l) __attribute__ ((__nothrow__ , __leaf__));
extern void __bzero (void *__s, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern void bcopy (const void *__src, void *__dest, size_t __n)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern void bzero (void *__s, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern int bcmp (const void *__s1, const void *__s2, size_t __n)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
# 489 "/usr/include/string.h" 3 4
extern char *index (const char *__s, int __c)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
# 517 "/usr/include/string.h" 3 4
extern char *rindex (const char *__s, int __c)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
extern int ffs (int __i) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__));
# 534 "/usr/include/string.h" 3 4
extern int strcasecmp (const char *__s1, const char *__s2)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern int strncasecmp (const char *__s1, const char *__s2, size_t __n)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
# 557 "/usr/include/string.h" 3 4
extern char *strsep (char **__restrict __stringp,
const char *__restrict __delim)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *strsignal (int __sig) __attribute__ ((__nothrow__ , __leaf__));
extern char *__stpcpy (char *__restrict __dest, const char *__restrict __src)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *stpcpy (char *__restrict __dest, const char *__restrict __src)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *__stpncpy (char *__restrict __dest,
const char *__restrict __src, size_t __n)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *stpncpy (char *__restrict __dest,
const char *__restrict __src, size_t __n)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
# 644 "/usr/include/string.h" 3 4
# 27 "papi_fwrappers.c" 2
# 1 "papi.h" 1
# 25 "papi.h"
#pragma GCC visibility push(default)
# 239 "papi.h"
# 1 "/usr/include/x86_64-linux-gnu/sys/types.h" 1 3 4
# 27 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4
typedef __u_char u_char;
typedef __u_short u_short;
typedef __u_int u_int;
typedef __u_long u_long;
typedef __quad_t quad_t;
typedef __u_quad_t u_quad_t;
typedef __fsid_t fsid_t;
typedef __loff_t loff_t;
typedef __ino_t ino_t;
# 60 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4
typedef __dev_t dev_t;
typedef __gid_t gid_t;
typedef __mode_t mode_t;
typedef __nlink_t nlink_t;
typedef __uid_t uid_t;
# 98 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4
typedef __pid_t pid_t;
typedef __id_t id_t;
# 115 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4
typedef __daddr_t daddr_t;
typedef __caddr_t caddr_t;
typedef __key_t key_t;
# 132 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4
# 1 "/usr/include/time.h" 1 3 4
# 57 "/usr/include/time.h" 3 4
typedef __clock_t clock_t;
# 73 "/usr/include/time.h" 3 4
typedef __time_t time_t;
# 91 "/usr/include/time.h" 3 4
typedef __clockid_t clockid_t;
# 103 "/usr/include/time.h" 3 4
typedef __timer_t timer_t;
# 133 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4
# 146 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4
# 1 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h" 1 3 4
# 147 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4
typedef unsigned long int ulong;
typedef unsigned short int ushort;
typedef unsigned int uint;
# 194 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4
typedef int int8_t __attribute__ ((__mode__ (__QI__)));
typedef int int16_t __attribute__ ((__mode__ (__HI__)));
typedef int int32_t __attribute__ ((__mode__ (__SI__)));
typedef int int64_t __attribute__ ((__mode__ (__DI__)));
typedef unsigned int u_int8_t __attribute__ ((__mode__ (__QI__)));
typedef unsigned int u_int16_t __attribute__ ((__mode__ (__HI__)));
typedef unsigned int u_int32_t __attribute__ ((__mode__ (__SI__)));
typedef unsigned int u_int64_t __attribute__ ((__mode__ (__DI__)));
typedef int register_t __attribute__ ((__mode__ (__word__)));
# 216 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4
# 1 "/usr/include/endian.h" 1 3 4
# 36 "/usr/include/endian.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/endian.h" 1 3 4
# 37 "/usr/include/endian.h" 2 3 4
# 60 "/usr/include/endian.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/byteswap.h" 1 3 4
# 28 "/usr/include/x86_64-linux-gnu/bits/byteswap.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4
# 29 "/usr/include/x86_64-linux-gnu/bits/byteswap.h" 2 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/byteswap-16.h" 1 3 4
# 36 "/usr/include/x86_64-linux-gnu/bits/byteswap.h" 2 3 4
# 44 "/usr/include/x86_64-linux-gnu/bits/byteswap.h" 3 4
static __inline unsigned int
__bswap_32 (unsigned int __bsx)
{
return __builtin_bswap32 (__bsx);
}
# 108 "/usr/include/x86_64-linux-gnu/bits/byteswap.h" 3 4
static __inline __uint64_t
__bswap_64 (__uint64_t __bsx)
{
return __builtin_bswap64 (__bsx);
}
# 61 "/usr/include/endian.h" 2 3 4
# 217 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4
# 1 "/usr/include/x86_64-linux-gnu/sys/select.h" 1 3 4
# 30 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/select.h" 1 3 4
# 22 "/usr/include/x86_64-linux-gnu/bits/select.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4
# 23 "/usr/include/x86_64-linux-gnu/bits/select.h" 2 3 4
# 31 "/usr/include/x86_64-linux-gnu/sys/select.h" 2 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/sigset.h" 1 3 4
# 22 "/usr/include/x86_64-linux-gnu/bits/sigset.h" 3 4
typedef int __sig_atomic_t;
typedef struct
{
unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))];
} __sigset_t;
# 34 "/usr/include/x86_64-linux-gnu/sys/select.h" 2 3 4
typedef __sigset_t sigset_t;
# 1 "/usr/include/time.h" 1 3 4
# 120 "/usr/include/time.h" 3 4
struct timespec
{
__time_t tv_sec;
__syscall_slong_t tv_nsec;
};
# 44 "/usr/include/x86_64-linux-gnu/sys/select.h" 2 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/time.h" 1 3 4
# 30 "/usr/include/x86_64-linux-gnu/bits/time.h" 3 4
struct timeval
{
__time_t tv_sec;
__suseconds_t tv_usec;
};
# 46 "/usr/include/x86_64-linux-gnu/sys/select.h" 2 3 4
typedef __suseconds_t suseconds_t;
typedef long int __fd_mask;
# 64 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4
typedef struct
{
__fd_mask __fds_bits[1024 / (8 * (int) sizeof (__fd_mask))];
} fd_set;
typedef __fd_mask fd_mask;
# 96 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4
# 106 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4
extern int select (int __nfds, fd_set *__restrict __readfds,
fd_set *__restrict __writefds,
fd_set *__restrict __exceptfds,
struct timeval *__restrict __timeout);
# 118 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4
extern int pselect (int __nfds, fd_set *__restrict __readfds,
fd_set *__restrict __writefds,
fd_set *__restrict __exceptfds,
const struct timespec *__restrict __timeout,
const __sigset_t *__restrict __sigmask);
# 131 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4
# 220 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4
# 1 "/usr/include/x86_64-linux-gnu/sys/sysmacros.h" 1 3 4
# 24 "/usr/include/x86_64-linux-gnu/sys/sysmacros.h" 3 4
__extension__
extern unsigned int gnu_dev_major (unsigned long long int __dev)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__));
__extension__
extern unsigned int gnu_dev_minor (unsigned long long int __dev)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__));
__extension__
extern unsigned long long int gnu_dev_makedev (unsigned int __major,
unsigned int __minor)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__));
# 58 "/usr/include/x86_64-linux-gnu/sys/sysmacros.h" 3 4
# 223 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4
typedef __blksize_t blksize_t;
typedef __blkcnt_t blkcnt_t;
typedef __fsblkcnt_t fsblkcnt_t;
typedef __fsfilcnt_t fsfilcnt_t;
# 270 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 1 3 4
# 21 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4
# 22 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 2 3 4
# 60 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 3 4
typedef unsigned long int pthread_t;
union pthread_attr_t
{
char __size[56];
long int __align;
};
typedef union pthread_attr_t pthread_attr_t;
typedef struct __pthread_internal_list
{
struct __pthread_internal_list *__prev;
struct __pthread_internal_list *__next;
} __pthread_list_t;
# 90 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 3 4
typedef union
{
struct __pthread_mutex_s
{
int __lock;
unsigned int __count;
int __owner;
unsigned int __nusers;
int __kind;
short __spins;
short __elision;
__pthread_list_t __list;
# 124 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 3 4
} __data;
char __size[40];
long int __align;
} pthread_mutex_t;
typedef union
{
char __size[4];
int __align;
} pthread_mutexattr_t;
typedef union
{
struct
{
int __lock;
unsigned int __futex;
__extension__ unsigned long long int __total_seq;
__extension__ unsigned long long int __wakeup_seq;
__extension__ unsigned long long int __woken_seq;
void *__mutex;
unsigned int __nwaiters;
unsigned int __broadcast_seq;
} __data;
char __size[48];
__extension__ long long int __align;
} pthread_cond_t;
typedef union
{
char __size[4];
int __align;
} pthread_condattr_t;
typedef unsigned int pthread_key_t;
typedef int pthread_once_t;
typedef union
{
struct
{
int __lock;
unsigned int __nr_readers;
unsigned int __readers_wakeup;
unsigned int __writer_wakeup;
unsigned int __nr_readers_queued;
unsigned int __nr_writers_queued;
int __writer;
int __shared;
unsigned long int __pad1;
unsigned long int __pad2;
unsigned int __flags;
} __data;
# 211 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 3 4
char __size[56];
long int __align;
} pthread_rwlock_t;
typedef union
{
char __size[8];
long int __align;
} pthread_rwlockattr_t;
typedef volatile int pthread_spinlock_t;
typedef union
{
char __size[32];
long int __align;
} pthread_barrier_t;
typedef union
{
char __size[4];
int __align;
} pthread_barrierattr_t;
# 271 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4
# 240 "papi.h" 2
# 1 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/limits.h" 1 3 4
# 34 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/limits.h" 3 4
# 1 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/syslimits.h" 1 3 4
# 1 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/limits.h" 1 3 4
# 168 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/limits.h" 3 4
# 1 "/usr/include/limits.h" 1 3 4
# 143 "/usr/include/limits.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/posix1_lim.h" 1 3 4
# 160 "/usr/include/x86_64-linux-gnu/bits/posix1_lim.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/local_lim.h" 1 3 4
# 38 "/usr/include/x86_64-linux-gnu/bits/local_lim.h" 3 4
# 1 "/usr/include/linux/limits.h" 1 3 4
# 39 "/usr/include/x86_64-linux-gnu/bits/local_lim.h" 2 3 4
# 161 "/usr/include/x86_64-linux-gnu/bits/posix1_lim.h" 2 3 4
# 144 "/usr/include/limits.h" 2 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/posix2_lim.h" 1 3 4
# 148 "/usr/include/limits.h" 2 3 4
# 169 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/limits.h" 2 3 4
# 8 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/syslimits.h" 2 3 4
# 35 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/limits.h" 2 3 4
# 241 "papi.h" 2
# 1 "papiStdEventDefs.h" 1
# 51 "papiStdEventDefs.h"
enum
{
PAPI_L1_DCM_idx = 0,
PAPI_L1_ICM_idx,
PAPI_L2_DCM_idx,
PAPI_L2_ICM_idx,
PAPI_L3_DCM_idx,
PAPI_L3_ICM_idx,
PAPI_L1_TCM_idx,
PAPI_L2_TCM_idx,
PAPI_L3_TCM_idx,
PAPI_CA_SNP_idx,
PAPI_CA_SHR_idx,
PAPI_CA_CLN_idx,
PAPI_CA_INV_idx,
PAPI_CA_ITV_idx,
PAPI_L3_LDM_idx,
PAPI_L3_STM_idx,
PAPI_BRU_IDL_idx,
PAPI_FXU_IDL_idx,
PAPI_FPU_IDL_idx,
PAPI_LSU_IDL_idx,
PAPI_TLB_DM_idx,
PAPI_TLB_IM_idx,
PAPI_TLB_TL_idx,
PAPI_L1_LDM_idx,
PAPI_L1_STM_idx,
PAPI_L2_LDM_idx,
PAPI_L2_STM_idx,
PAPI_BTAC_M_idx,
PAPI_PRF_DM_idx,
PAPI_L3_DCH_idx,
PAPI_TLB_SD_idx,
PAPI_CSR_FAL_idx,
PAPI_CSR_SUC_idx,
PAPI_CSR_TOT_idx,
PAPI_MEM_SCY_idx,
PAPI_MEM_RCY_idx,
PAPI_MEM_WCY_idx,
PAPI_STL_ICY_idx,
PAPI_FUL_ICY_idx,
PAPI_STL_CCY_idx,
PAPI_FUL_CCY_idx,
PAPI_HW_INT_idx,
PAPI_BR_UCN_idx,
PAPI_BR_CN_idx,
PAPI_BR_TKN_idx,
PAPI_BR_NTK_idx,
PAPI_BR_MSP_idx,
PAPI_BR_PRC_idx,
PAPI_FMA_INS_idx,
PAPI_TOT_IIS_idx,
PAPI_TOT_INS_idx,
PAPI_INT_INS_idx,
PAPI_FP_INS_idx,
PAPI_LD_INS_idx,
PAPI_SR_INS_idx,
PAPI_BR_INS_idx,
PAPI_VEC_INS_idx,
PAPI_RES_STL_idx,
PAPI_FP_STAL_idx,
PAPI_TOT_CYC_idx,
PAPI_LST_INS_idx,
PAPI_SYC_INS_idx,
PAPI_L1_DCH_idx,
PAPI_L2_DCH_idx,
PAPI_L1_DCA_idx,
PAPI_L2_DCA_idx,
PAPI_L3_DCA_idx,
PAPI_L1_DCR_idx,
PAPI_L2_DCR_idx,
PAPI_L3_DCR_idx,
PAPI_L1_DCW_idx,
PAPI_L2_DCW_idx,
PAPI_L3_DCW_idx,
PAPI_L1_ICH_idx,
PAPI_L2_ICH_idx,
PAPI_L3_ICH_idx,
PAPI_L1_ICA_idx,
PAPI_L2_ICA_idx,
PAPI_L3_ICA_idx,
PAPI_L1_ICR_idx,
PAPI_L2_ICR_idx,
PAPI_L3_ICR_idx,
PAPI_L1_ICW_idx,
PAPI_L2_ICW_idx,
PAPI_L3_ICW_idx,
PAPI_L1_TCH_idx,
PAPI_L2_TCH_idx,
PAPI_L3_TCH_idx,
PAPI_L1_TCA_idx,
PAPI_L2_TCA_idx,
PAPI_L3_TCA_idx,
PAPI_L1_TCR_idx,
PAPI_L2_TCR_idx,
PAPI_L3_TCR_idx,
PAPI_L1_TCW_idx,
PAPI_L2_TCW_idx,
PAPI_L3_TCW_idx,
PAPI_FML_INS_idx,
PAPI_FAD_INS_idx,
PAPI_FDV_INS_idx,
PAPI_FSQ_INS_idx,
PAPI_FNV_INS_idx,
PAPI_FP_OPS_idx,
PAPI_SP_OPS_idx,
PAPI_DP_OPS_idx,
PAPI_VEC_SP_idx,
PAPI_VEC_DP_idx,
PAPI_REF_CYC_idx,
PAPI_END_idx
};
# 242 "papi.h" 2
# 478 "papi.h"
enum {
PAPI_ENUM_EVENTS = 0,
PAPI_ENUM_FIRST,
PAPI_PRESET_ENUM_AVAIL,
PAPI_PRESET_ENUM_MSC,
PAPI_PRESET_ENUM_INS,
PAPI_PRESET_ENUM_IDL,
PAPI_PRESET_ENUM_BR,
PAPI_PRESET_ENUM_CND,
PAPI_PRESET_ENUM_MEM,
PAPI_PRESET_ENUM_CACH,
PAPI_PRESET_ENUM_L1,
PAPI_PRESET_ENUM_L2,
PAPI_PRESET_ENUM_L3,
PAPI_PRESET_ENUM_TLB,
PAPI_PRESET_ENUM_FP,
PAPI_NTV_ENUM_UMASKS,
PAPI_NTV_ENUM_UMASK_COMBOS,
PAPI_NTV_ENUM_IARR,
PAPI_NTV_ENUM_DARR,
PAPI_NTV_ENUM_OPCM,
PAPI_NTV_ENUM_IEAR,
PAPI_NTV_ENUM_DEAR,
PAPI_NTV_ENUM_GROUPS
};
# 542 "papi.h"
# 1 "/usr/include/signal.h" 1 3 4
# 30 "/usr/include/signal.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/sigset.h" 1 3 4
# 102 "/usr/include/x86_64-linux-gnu/bits/sigset.h" 3 4
extern int __sigismember (const __sigset_t *, int);
extern int __sigaddset (__sigset_t *, int);
extern int __sigdelset (__sigset_t *, int);
# 33 "/usr/include/signal.h" 2 3 4
typedef __sig_atomic_t sig_atomic_t;
# 57 "/usr/include/signal.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/signum.h" 1 3 4
# 58 "/usr/include/signal.h" 2 3 4
# 75 "/usr/include/signal.h" 3 4
# 1 "/usr/include/time.h" 1 3 4
# 76 "/usr/include/signal.h" 2 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/siginfo.h" 1 3 4
# 24 "/usr/include/x86_64-linux-gnu/bits/siginfo.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4
# 25 "/usr/include/x86_64-linux-gnu/bits/siginfo.h" 2 3 4
typedef union sigval
{
int sival_int;
void *sival_ptr;
} sigval_t;
# 58 "/usr/include/x86_64-linux-gnu/bits/siginfo.h" 3 4
typedef __clock_t __sigchld_clock_t;
typedef struct
{
int si_signo;
int si_errno;
int si_code;
union
{
int _pad[((128 / sizeof (int)) - 4)];
struct
{
__pid_t si_pid;
__uid_t si_uid;
} _kill;
struct
{
int si_tid;
int si_overrun;
sigval_t si_sigval;
} _timer;
struct
{
__pid_t si_pid;
__uid_t si_uid;
sigval_t si_sigval;
} _rt;
struct
{
__pid_t si_pid;
__uid_t si_uid;
int si_status;
__sigchld_clock_t si_utime;
__sigchld_clock_t si_stime;
} _sigchld;
struct
{
void *si_addr;
short int si_addr_lsb;
} _sigfault;
struct
{
long int si_band;
int si_fd;
} _sigpoll;
struct
{
void *_call_addr;
int _syscall;
unsigned int _arch;
} _sigsys;
} _sifields;
} siginfo_t ;
# 153 "/usr/include/x86_64-linux-gnu/bits/siginfo.h" 3 4
enum
{
SI_ASYNCNL = -60,
SI_TKILL = -6,
SI_SIGIO,
SI_ASYNCIO,
SI_MESGQ,
SI_TIMER,
SI_QUEUE,
SI_USER,
SI_KERNEL = 0x80
};
enum
{
ILL_ILLOPC = 1,
ILL_ILLOPN,
ILL_ILLADR,
ILL_ILLTRP,
ILL_PRVOPC,
ILL_PRVREG,
ILL_COPROC,
ILL_BADSTK
};
enum
{
FPE_INTDIV = 1,
FPE_INTOVF,
FPE_FLTDIV,
FPE_FLTOVF,
FPE_FLTUND,
FPE_FLTRES,
FPE_FLTINV,
FPE_FLTSUB
};
enum
{
SEGV_MAPERR = 1,
SEGV_ACCERR
};
enum
{
BUS_ADRALN = 1,
BUS_ADRERR,
BUS_OBJERR,
BUS_MCEERR_AR,
BUS_MCEERR_AO
};
enum
{
TRAP_BRKPT = 1,
TRAP_TRACE
};
enum
{
CLD_EXITED = 1,
CLD_KILLED,
CLD_DUMPED,
CLD_TRAPPED,
CLD_STOPPED,
CLD_CONTINUED
};
enum
{
POLL_IN = 1,
POLL_OUT,
POLL_MSG,
POLL_ERR,
POLL_PRI,
POLL_HUP
};
# 307 "/usr/include/x86_64-linux-gnu/bits/siginfo.h" 3 4
typedef struct sigevent
{
sigval_t sigev_value;
int sigev_signo;
int sigev_notify;
union
{
int _pad[((64 / sizeof (int)) - 4)];
__pid_t _tid;
struct
{
void (*_function) (sigval_t);
pthread_attr_t *_attribute;
} _sigev_thread;
} _sigev_un;
} sigevent_t;
enum
{
SIGEV_SIGNAL = 0,
SIGEV_NONE,
SIGEV_THREAD,
SIGEV_THREAD_ID = 4
};
# 81 "/usr/include/signal.h" 2 3 4
typedef void (*__sighandler_t) (int);
extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
__attribute__ ((__nothrow__ , __leaf__));
# 100 "/usr/include/signal.h" 3 4
extern __sighandler_t signal (int __sig, __sighandler_t __handler)
__attribute__ ((__nothrow__ , __leaf__));
# 114 "/usr/include/signal.h" 3 4
# 127 "/usr/include/signal.h" 3 4
extern int kill (__pid_t __pid, int __sig) __attribute__ ((__nothrow__ , __leaf__));
extern int killpg (__pid_t __pgrp, int __sig) __attribute__ ((__nothrow__ , __leaf__));
extern int raise (int __sig) __attribute__ ((__nothrow__ , __leaf__));
extern __sighandler_t ssignal (int __sig, __sighandler_t __handler)
__attribute__ ((__nothrow__ , __leaf__));
extern int gsignal (int __sig) __attribute__ ((__nothrow__ , __leaf__));
extern void psignal (int __sig, const char *__s);
extern void psiginfo (const siginfo_t *__pinfo, const char *__s);
# 167 "/usr/include/signal.h" 3 4
extern int __sigpause (int __sig_or_mask, int __is_sig);
# 189 "/usr/include/signal.h" 3 4
extern int sigblock (int __mask) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__deprecated__));
extern int sigsetmask (int __mask) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__deprecated__));
extern int siggetmask (void) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__deprecated__));
# 209 "/usr/include/signal.h" 3 4
typedef __sighandler_t sig_t;
extern int sigemptyset (sigset_t *__set) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern int sigfillset (sigset_t *__set) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern int sigaddset (sigset_t *__set, int __signo) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern int sigdelset (sigset_t *__set, int __signo) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern int sigismember (const sigset_t *__set, int __signo)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
# 245 "/usr/include/signal.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/sigaction.h" 1 3 4
# 24 "/usr/include/x86_64-linux-gnu/bits/sigaction.h" 3 4
struct sigaction
{
union
{
__sighandler_t sa_handler;
void (*sa_sigaction) (int, siginfo_t *, void *);
}
__sigaction_handler;
__sigset_t sa_mask;
int sa_flags;
void (*sa_restorer) (void);
};
# 246 "/usr/include/signal.h" 2 3 4
extern int sigprocmask (int __how, const sigset_t *__restrict __set,
sigset_t *__restrict __oset) __attribute__ ((__nothrow__ , __leaf__));
extern int sigsuspend (const sigset_t *__set) __attribute__ ((__nonnull__ (1)));
extern int sigaction (int __sig, const struct sigaction *__restrict __act,
struct sigaction *__restrict __oact) __attribute__ ((__nothrow__ , __leaf__));
extern int sigpending (sigset_t *__set) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern int sigwait (const sigset_t *__restrict __set, int *__restrict __sig)
__attribute__ ((__nonnull__ (1, 2)));
extern int sigwaitinfo (const sigset_t *__restrict __set,
siginfo_t *__restrict __info) __attribute__ ((__nonnull__ (1)));
extern int sigtimedwait (const sigset_t *__restrict __set,
siginfo_t *__restrict __info,
const struct timespec *__restrict __timeout)
__attribute__ ((__nonnull__ (1)));
extern int sigqueue (__pid_t __pid, int __sig, const union sigval __val)
__attribute__ ((__nothrow__ , __leaf__));
# 303 "/usr/include/signal.h" 3 4
extern const char *const _sys_siglist[65];
extern const char *const sys_siglist[65];
struct sigvec
{
__sighandler_t sv_handler;
int sv_mask;
int sv_flags;
};
# 327 "/usr/include/signal.h" 3 4
extern int sigvec (int __sig, const struct sigvec *__vec,
struct sigvec *__ovec) __attribute__ ((__nothrow__ , __leaf__));
# 1 "/usr/include/x86_64-linux-gnu/bits/sigcontext.h" 1 3 4
# 29 "/usr/include/x86_64-linux-gnu/bits/sigcontext.h" 3 4
struct _fpx_sw_bytes
{
__uint32_t magic1;
__uint32_t extended_size;
__uint64_t xstate_bv;
__uint32_t xstate_size;
__uint32_t padding[7];
};
struct _fpreg
{
unsigned short significand[4];
unsigned short exponent;
};
struct _fpxreg
{
unsigned short significand[4];
unsigned short exponent;
unsigned short padding[3];
};
struct _xmmreg
{
__uint32_t element[4];
};
# 121 "/usr/include/x86_64-linux-gnu/bits/sigcontext.h" 3 4
struct _fpstate
{
__uint16_t cwd;
__uint16_t swd;
__uint16_t ftw;
__uint16_t fop;
__uint64_t rip;
__uint64_t rdp;
__uint32_t mxcsr;
__uint32_t mxcr_mask;
struct _fpxreg _st[8];
struct _xmmreg _xmm[16];
__uint32_t padding[24];
};
struct sigcontext
{
__uint64_t r8;
__uint64_t r9;
__uint64_t r10;
__uint64_t r11;
__uint64_t r12;
__uint64_t r13;
__uint64_t r14;
__uint64_t r15;
__uint64_t rdi;
__uint64_t rsi;
__uint64_t rbp;
__uint64_t rbx;
__uint64_t rdx;
__uint64_t rax;
__uint64_t rcx;
__uint64_t rsp;
__uint64_t rip;
__uint64_t eflags;
unsigned short cs;
unsigned short gs;
unsigned short fs;
unsigned short __pad0;
__uint64_t err;
__uint64_t trapno;
__uint64_t oldmask;
__uint64_t cr2;
__extension__ union
{
struct _fpstate * fpstate;
__uint64_t __fpstate_word;
};
__uint64_t __reserved1 [8];
};
struct _xsave_hdr
{
__uint64_t xstate_bv;
__uint64_t reserved1[2];
__uint64_t reserved2[5];
};
struct _ymmh_state
{
__uint32_t ymmh_space[64];
};
struct _xstate
{
struct _fpstate fpstate;
struct _xsave_hdr xstate_hdr;
struct _ymmh_state ymmh;
};
# 333 "/usr/include/signal.h" 2 3 4
extern int sigreturn (struct sigcontext *__scp) __attribute__ ((__nothrow__ , __leaf__));
# 1 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h" 1 3 4
# 343 "/usr/include/signal.h" 2 3 4
extern int siginterrupt (int __sig, int __interrupt) __attribute__ ((__nothrow__ , __leaf__));
# 1 "/usr/include/x86_64-linux-gnu/bits/sigstack.h" 1 3 4
# 25 "/usr/include/x86_64-linux-gnu/bits/sigstack.h" 3 4
struct sigstack
{
void *ss_sp;
int ss_onstack;
};
enum
{
SS_ONSTACK = 1,
SS_DISABLE
};
# 49 "/usr/include/x86_64-linux-gnu/bits/sigstack.h" 3 4
typedef struct sigaltstack
{
void *ss_sp;
int ss_flags;
size_t ss_size;
} stack_t;
# 350 "/usr/include/signal.h" 2 3 4
# 1 "/usr/include/x86_64-linux-gnu/sys/ucontext.h" 1 3 4
# 22 "/usr/include/x86_64-linux-gnu/sys/ucontext.h" 3 4
# 1 "/usr/include/signal.h" 1 3 4
# 23 "/usr/include/x86_64-linux-gnu/sys/ucontext.h" 2 3 4
# 31 "/usr/include/x86_64-linux-gnu/sys/ucontext.h" 3 4
__extension__ typedef long long int greg_t;
typedef greg_t gregset_t[23];
# 92 "/usr/include/x86_64-linux-gnu/sys/ucontext.h" 3 4
struct _libc_fpxreg
{
unsigned short int significand[4];
unsigned short int exponent;
unsigned short int padding[3];
};
struct _libc_xmmreg
{
__uint32_t element[4];
};
struct _libc_fpstate
{
__uint16_t cwd;
__uint16_t swd;
__uint16_t ftw;
__uint16_t fop;
__uint64_t rip;
__uint64_t rdp;
__uint32_t mxcsr;
__uint32_t mxcr_mask;
struct _libc_fpxreg _st[8];
struct _libc_xmmreg _xmm[16];
__uint32_t padding[24];
};
typedef struct _libc_fpstate *fpregset_t;
typedef struct
{
gregset_t gregs;
fpregset_t fpregs;
__extension__ unsigned long long __reserved1 [8];
} mcontext_t;
typedef struct ucontext
{
unsigned long int uc_flags;
struct ucontext *uc_link;
stack_t uc_stack;
mcontext_t uc_mcontext;
__sigset_t uc_sigmask;
struct _libc_fpstate __fpregs_mem;
} ucontext_t;
# 353 "/usr/include/signal.h" 2 3 4
extern int sigstack (struct sigstack *__ss, struct sigstack *__oss)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__deprecated__));
extern int sigaltstack (const struct sigaltstack *__restrict __ss,
struct sigaltstack *__restrict __oss) __attribute__ ((__nothrow__ , __leaf__));
# 388 "/usr/include/signal.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/sigthread.h" 1 3 4
# 30 "/usr/include/x86_64-linux-gnu/bits/sigthread.h" 3 4
extern int pthread_sigmask (int __how,
const __sigset_t *__restrict __newmask,
__sigset_t *__restrict __oldmask)__attribute__ ((__nothrow__ , __leaf__));
extern int pthread_kill (pthread_t __threadid, int __signo) __attribute__ ((__nothrow__ , __leaf__));
# 389 "/usr/include/signal.h" 2 3 4
extern int __libc_current_sigrtmin (void) __attribute__ ((__nothrow__ , __leaf__));
extern int __libc_current_sigrtmax (void) __attribute__ ((__nothrow__ , __leaf__));
# 543 "papi.h" 2
# 555 "papi.h"
typedef unsigned long PAPI_thread_id_t;
typedef struct _papi_all_thr_spec {
int num;
PAPI_thread_id_t *id;
void **data;
} PAPI_all_thr_spec_t;
typedef void (*PAPI_overflow_handler_t) (int EventSet, void *address,
long long overflow_vector, void *context);
# 579 "papi.h"
typedef struct _papi_sprofil {
void *pr_base;
unsigned pr_size;
caddr_t pr_off;
unsigned pr_scale;
} PAPI_sprofil_t;
typedef struct _papi_itimer_option {
int itimer_num;
int itimer_sig;
int ns;
int flags;
} PAPI_itimer_option_t;
typedef struct _papi_inherit_option {
int eventset;
int inherit;
} PAPI_inherit_option_t;
typedef struct _papi_domain_option {
int def_cidx;
int eventset;
int domain;
} PAPI_domain_option_t;
typedef struct _papi_granularity_option {
int def_cidx;
int eventset;
int granularity;
} PAPI_granularity_option_t;
typedef struct _papi_preload_option {
char lib_preload_env[128];
char lib_preload_sep;
char lib_dir_env[128];
char lib_dir_sep;
} PAPI_preload_info_t;
typedef struct _papi_component_option {
char name[128];
char short_name[64];
char description[128];
char version[64];
char support_version[64];
char kernel_version[64];
char disabled_reason[128];
int disabled;
int CmpIdx;
int num_cntrs;
int num_mpx_cntrs;
int num_preset_events;
int num_native_events;
int default_domain;
int available_domains;
int default_granularity;
int available_granularities;
int hardware_intr_sig;
int component_type;
char *pmu_names[40];
int reserved[8];
unsigned int hardware_intr:1;
unsigned int precise_intr:1;
unsigned int posix1b_timers:1;
unsigned int kernel_profile:1;
unsigned int kernel_multiplex:1;
unsigned int fast_counter_read:1;
unsigned int fast_real_timer:1;
unsigned int fast_virtual_timer:1;
unsigned int attach:1;
unsigned int attach_must_ptrace:1;
unsigned int cntr_umasks:1;
unsigned int cpu:1;
unsigned int inherit:1;
unsigned int reserved_bits:12;
} PAPI_component_info_t;
typedef struct _papi_mpx_info {
int timer_sig;
int timer_num;
int timer_us;
} PAPI_mpx_info_t;
typedef int (*PAPI_debug_handler_t) (int code);
typedef struct _papi_debug_option {
int level;
PAPI_debug_handler_t handler;
} PAPI_debug_option_t;
typedef struct _papi_address_map {
char name[1024];
caddr_t text_start;
caddr_t text_end;
caddr_t data_start;
caddr_t data_end;
caddr_t bss_start;
caddr_t bss_end;
} PAPI_address_map_t;
typedef struct _papi_program_info {
char fullname[1024];
PAPI_address_map_t address_info;
} PAPI_exe_info_t;
typedef struct _papi_shared_lib_info {
PAPI_address_map_t *map;
int count;
} PAPI_shlib_info_t;
typedef char* PAPI_user_defined_events_file_t;
# 747 "papi.h"
typedef struct _papi_mh_tlb_info {
int type;
int num_entries;
int page_size;
int associativity;
} PAPI_mh_tlb_info_t;
typedef struct _papi_mh_cache_info {
int type;
int size;
int line_size;
int num_lines;
int associativity;
} PAPI_mh_cache_info_t;
typedef struct _papi_mh_level_info {
PAPI_mh_tlb_info_t tlb[6];
PAPI_mh_cache_info_t cache[6];
} PAPI_mh_level_t;
typedef struct _papi_mh_info {
int levels;
PAPI_mh_level_t level[4];
} PAPI_mh_info_t;
typedef struct _papi_hw_info {
int ncpu;
int threads;
int cores;
int sockets;
int nnodes;
int totalcpus;
int vendor;
char vendor_string[128];
int model;
char model_string[128];
float revision;
int cpuid_family;
int cpuid_model;
int cpuid_stepping;
int cpu_max_mhz;
int cpu_min_mhz;
PAPI_mh_info_t mem_hierarchy;
int virtualized;
char virtual_vendor_string[128];
char virtual_vendor_version[128];
float mhz;
int clock_mhz;
int reserved[8];
} PAPI_hw_info_t;
typedef struct _papi_attach_option {
int eventset;
unsigned long tid;
} PAPI_attach_option_t;
typedef struct _papi_cpu_option {
int eventset;
unsigned int cpu_num;
} PAPI_cpu_option_t;
typedef struct _papi_multiplex_option {
int eventset;
int ns;
int flags;
} PAPI_multiplex_option_t;
typedef struct _papi_addr_range_option {
int eventset;
caddr_t start;
caddr_t end;
int start_off;
int end_off;
} PAPI_addr_range_option_t;
typedef union
{
PAPI_preload_info_t preload;
PAPI_debug_option_t debug;
PAPI_inherit_option_t inherit;
PAPI_granularity_option_t granularity;
PAPI_granularity_option_t defgranularity;
PAPI_domain_option_t domain;
PAPI_domain_option_t defdomain;
PAPI_attach_option_t attach;
PAPI_cpu_option_t cpu;
PAPI_multiplex_option_t multiplex;
PAPI_itimer_option_t itimer;
PAPI_hw_info_t *hw_info;
PAPI_shlib_info_t *shlib_info;
PAPI_exe_info_t *exe_info;
PAPI_component_info_t *cmp_info;
PAPI_addr_range_option_t addr;
PAPI_user_defined_events_file_t events_file;
} PAPI_option_t;
typedef struct _dmem_t {
long long peak;
long long size;
long long resident;
long long high_water_mark;
long long shared;
long long text;
long long library;
long long heap;
long long locked;
long long stack;
long long pagesize;
long long pte;
} PAPI_dmem_info_t;
# 923 "papi.h"
enum {
PAPI_LOCATION_CORE = 0,
PAPI_LOCATION_CPU,
PAPI_LOCATION_PACKAGE,
PAPI_LOCATION_UNCORE,
};
enum {
PAPI_DATATYPE_INT64 = 0,
PAPI_DATATYPE_UINT64,
PAPI_DATATYPE_FP64,
PAPI_DATATYPE_BIT64,
};
enum {
PAPI_VALUETYPE_RUNNING_SUM = 0,
PAPI_VALUETYPE_ABSOLUTE,
};
enum {
PAPI_TIMESCOPE_SINCE_START = 0,
PAPI_TIMESCOPE_SINCE_LAST,
PAPI_TIMESCOPE_UNTIL_NEXT,
PAPI_TIMESCOPE_POINT,
};
enum {
PAPI_UPDATETYPE_ARBITRARY = 0,
PAPI_UPDATETYPE_PUSH,
PAPI_UPDATETYPE_PULL,
PAPI_UPDATETYPE_FIXEDFREQ,
};
typedef struct event_info {
unsigned int event_code;
char symbol[1024];
char short_descr[64];
char long_descr[1024];
int component_index;
char units[64];
int location;
int data_type;
int value_type;
int timescope;
int update_type;
int update_freq;
unsigned int count;
unsigned int event_type;
char derived[64];
char postfix[256];
unsigned int code[12];
char name[12]
[256];
char note[1024];
} PAPI_event_info_t;
int ffsll(long long lli);
int PAPI_accum(int EventSet, long long * values);
int PAPI_add_event(int EventSet, int Event);
int PAPI_add_named_event(int EventSet, char *EventName);
int PAPI_add_events(int EventSet, int *Events, int number);
int PAPI_assign_eventset_component(int EventSet, int cidx);
int PAPI_attach(int EventSet, unsigned long tid);
int PAPI_cleanup_eventset(int EventSet);
int PAPI_create_eventset(int *EventSet);
int PAPI_detach(int EventSet);
int PAPI_destroy_eventset(int *EventSet);
int PAPI_enum_event(int *EventCode, int modifier);
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx);
int PAPI_event_code_to_name(int EventCode, char *out);
int PAPI_event_name_to_code(char *in, int *out);
int PAPI_get_dmem_info(PAPI_dmem_info_t *dest);
int PAPI_get_event_info(int EventCode, PAPI_event_info_t * info);
const PAPI_exe_info_t *PAPI_get_executable_info(void);
const PAPI_hw_info_t *PAPI_get_hardware_info(void);
const PAPI_component_info_t *PAPI_get_component_info(int cidx);
int PAPI_get_multiplex(int EventSet);
int PAPI_get_opt(int option, PAPI_option_t * ptr);
int PAPI_get_cmp_opt(int option, PAPI_option_t * ptr,int cidx);
long long PAPI_get_real_cyc(void);
long long PAPI_get_real_nsec(void);
long long PAPI_get_real_usec(void);
const PAPI_shlib_info_t *PAPI_get_shared_lib_info(void);
int PAPI_get_thr_specific(int tag, void **ptr);
int PAPI_get_overflow_event_index(int Eventset, long long overflow_vector, int *array, int *number);
long long PAPI_get_virt_cyc(void);
long long PAPI_get_virt_nsec(void);
long long PAPI_get_virt_usec(void);
int PAPI_is_initialized(void);
int PAPI_library_init(int version);
int PAPI_list_events(int EventSet, int *Events, int *number);
int PAPI_list_threads(unsigned long *tids, int *number);
int PAPI_lock(int);
int PAPI_multiplex_init(void);
int PAPI_num_cmp_hwctrs(int cidx);
int PAPI_num_events(int EventSet);
int PAPI_overflow(int EventSet, int EventCode, int threshold,
int flags, PAPI_overflow_handler_t handler);
void PAPI_perror(char *msg );
int PAPI_profil(void *buf, unsigned bufsiz, caddr_t offset,
unsigned scale, int EventSet, int EventCode,
int threshold, int flags);
int PAPI_query_event(int EventCode);
int PAPI_query_named_event(char *EventName);
int PAPI_read(int EventSet, long long * values);
int PAPI_read_ts(int EventSet, long long * values, long long *cyc);
int PAPI_register_thread(void);
int PAPI_remove_event(int EventSet, int EventCode);
int PAPI_remove_named_event(int EventSet, char *EventName);
int PAPI_remove_events(int EventSet, int *Events, int number);
int PAPI_reset(int EventSet);
int PAPI_set_debug(int level);
int PAPI_set_cmp_domain(int domain, int cidx);
int PAPI_set_domain(int domain);
int PAPI_set_cmp_granularity(int granularity, int cidx);
int PAPI_set_granularity(int granularity);
int PAPI_set_multiplex(int EventSet);
int PAPI_set_opt(int option, PAPI_option_t * ptr);
int PAPI_set_thr_specific(int tag, void *ptr);
void PAPI_shutdown(void);
int PAPI_sprofil(PAPI_sprofil_t * prof, int profcnt, int EventSet, int EventCode, int threshold, int flags);
int PAPI_start(int EventSet);
int PAPI_state(int EventSet, int *status);
int PAPI_stop(int EventSet, long long * values);
char *PAPI_strerror(int);
unsigned long PAPI_thread_id(void);
int PAPI_thread_init(unsigned long (*id_fn) (void));
int PAPI_unlock(int);
int PAPI_unregister_thread(void);
int PAPI_write(int EventSet, long long * values);
int PAPI_get_event_component(int EventCode);
int PAPI_get_eventset_component(int EventSet);
int PAPI_get_component_index(char *name);
int PAPI_disable_component(int cidx);
int PAPI_disable_component_by_name( char *name );
# 1116 "papi.h"
int PAPI_accum_counters(long long * values, int array_len);
int PAPI_num_counters(void);
int PAPI_num_components(void);
int PAPI_read_counters(long long * values, int array_len);
int PAPI_start_counters(int *events, int array_len);
int PAPI_stop_counters(long long * values, int array_len);
int PAPI_flips(float *rtime, float *ptime, long long * flpins, float *mflips);
int PAPI_flops(float *rtime, float *ptime, long long * flpops, float *mflops);
int PAPI_ipc(float *rtime, float *ptime, long long * ins, float *ipc);
int PAPI_epc(int event, float *rtime, float *ptime, long long *ref, long long *core, long long *evt, float *epc);
int PAPI_num_hwctrs(void);
#pragma GCC visibility pop
# 28 "papi_fwrappers.c" 2
# 51 "papi_fwrappers.c"
static void Fortran2cstring( char *cstring, char *Fstring, int clen , int Flen )
{
int slen, i;
slen = Flen < clen ? Flen : clen;
strncpy( cstring, Fstring, ( size_t ) slen );
for ( i = slen - 1; i > -1 && cstring[i] == ' '; cstring[i--] = '\0' );
cstring[clen - 1] = '\0';
if ( slen < clen )
cstring[slen] = '\0';
}
# 79 "papi_fwrappers.c"
void papif_accum_ ( int *EventSet, long long *values, int *check )
{
*check = PAPI_accum( *EventSet, values );
}
# 95 "papi_fwrappers.c"
void papif_add_event_ ( int *EventSet, int *Event, int *check )
{
*check = PAPI_add_event( *EventSet, *Event );
}
# 112 "papi_fwrappers.c"
void papif_add_named_event_ ( int *EventSet, char *EventName, int *check, int Event_len )
{
char tmp[128];
Fortran2cstring( tmp, EventName, 128, Event_len );
*check = PAPI_add_named_event( *EventSet, tmp );
}
# 137 "papi_fwrappers.c"
void papif_add_events_ ( int *EventSet, int *Events, int *number, int *check )
{
*check = PAPI_add_events( *EventSet, Events, *number );
}
# 153 "papi_fwrappers.c"
void papif_cleanup_eventset_ ( int *EventSet, int *check )
{
*check = PAPI_cleanup_eventset( *EventSet );
}
# 169 "papi_fwrappers.c"
void papif_create_eventset_ ( int *EventSet, int *check )
{
*check = PAPI_create_eventset( EventSet );
}
# 185 "papi_fwrappers.c"
void papif_assign_eventset_component_ ( int *EventSet, int *cidx, int *check )
{
*check = PAPI_assign_eventset_component( *EventSet, *cidx );
}
# 201 "papi_fwrappers.c"
void papif_destroy_eventset_ ( int *EventSet, int *check )
{
*check = PAPI_destroy_eventset( EventSet );
}
# 218 "papi_fwrappers.c"
void papif_get_dmem_info_ ( long long *dest, int *check )
{
*check = PAPI_get_dmem_info( ( PAPI_dmem_info_t * ) dest );
}
# 238 "papi_fwrappers.c"
void papif_get_exe_info_ ( char *fullname, char *name, long long *text_start, long long *text_end, long long *data_start, long long *data_end, long long *bss_start, long long *bss_end, int *check, int fullname_len, int name_len )
# 249 "papi_fwrappers.c"
{
PAPI_option_t e;
if ( ( *check = PAPI_get_opt( 17, &e ) ) == 0 ) {
int i;
strncpy( fullname, e.exe_info->fullname, ( size_t ) fullname_len );
for ( i = ( int ) strlen( e.exe_info->fullname ); i < fullname_len;
fullname[i++] = ' ' );
strncpy( name, e.exe_info->address_info.name, ( size_t ) name_len );
for ( i = ( int ) strlen( e.exe_info->address_info.name ); i < name_len;
name[i++] = ' ' );
*text_start = ( long ) e.exe_info->address_info.text_start;
*text_end = ( long ) e.exe_info->address_info.text_end;
*data_start = ( long ) e.exe_info->address_info.data_start;
*data_end = ( long ) e.exe_info->address_info.data_end;
*bss_start = ( long ) e.exe_info->address_info.bss_start;
*bss_end = ( long ) e.exe_info->address_info.bss_end;
}
}
# 291 "papi_fwrappers.c"
void papif_get_hardware_info_ ( int *ncpu, int *nnodes, int *totalcpus, int *vendor, char *vendor_str, int *model, char *model_str, float *revision, float *mhz, int vendor_len, int model_len )
# 317 "papi_fwrappers.c"
{
const PAPI_hw_info_t *hwinfo;
int i;
hwinfo = PAPI_get_hardware_info( );
if ( hwinfo == ((void *)0) ) {
*ncpu = 0;
*nnodes = 0;
*totalcpus = 0;
*vendor = 0;
*model = 0;
*revision = 0;
*mhz = 0;
} else {
*ncpu = hwinfo->ncpu;
*nnodes = hwinfo->nnodes;
*totalcpus = hwinfo->totalcpus;
*vendor = hwinfo->vendor;
*model = hwinfo->model;
*revision = hwinfo->revision;
*mhz = hwinfo->cpu_max_mhz;
strncpy( vendor_str, hwinfo->vendor_string, ( size_t ) vendor_len );
for ( i = ( int ) strlen( hwinfo->vendor_string ); i < vendor_len;
vendor_str[i++] = ' ' );
strncpy( model_str, hwinfo->model_string, ( size_t ) model_len );
for ( i = ( int ) strlen( hwinfo->model_string ); i < model_len;
model_str[i++] = ' ' );
}
return;
}
# 366 "papi_fwrappers.c"
void papif_num_hwctrs_ ( int *num )
{
*num = PAPI_num_hwctrs( );
}
# 382 "papi_fwrappers.c"
void papif_num_cmp_hwctrs_ ( int *cidx, int *num )
{
*num = PAPI_num_cmp_hwctrs( *cidx );
}
# 398 "papi_fwrappers.c"
void papif_get_real_cyc_ ( long long *real_cyc )
{
*real_cyc = PAPI_get_real_cyc( );
}
# 413 "papi_fwrappers.c"
void papif_get_real_usec_ ( long long *time )
{
*time = PAPI_get_real_usec( );
}
# 428 "papi_fwrappers.c"
void papif_get_real_nsec_ ( long long *time )
{
*time = PAPI_get_real_nsec( );
}
# 443 "papi_fwrappers.c"
void papif_get_virt_cyc_ ( long long *virt_cyc )
{
*virt_cyc = PAPI_get_virt_cyc( );
}
# 458 "papi_fwrappers.c"
void papif_get_virt_usec_ ( long long *time )
{
*time = PAPI_get_virt_usec( );
}
# 473 "papi_fwrappers.c"
void papif_is_initialized_ ( int *level )
{
*level = PAPI_is_initialized( );
}
# 488 "papi_fwrappers.c"
void papif_library_init_ ( int *check )
{
*check = PAPI_library_init( *check );
}
# 503 "papi_fwrappers.c"
void papif_thread_id_ ( unsigned long *id )
{
*id = PAPI_thread_id( );
}
# 518 "papi_fwrappers.c"
void papif_register_thread_ ( int *check )
{
*check = PAPI_register_thread( );
}
# 533 "papi_fwrappers.c"
void papif_unregster_thread_ ( int *check )
{
*check = PAPI_unregister_thread( );
}
# 549 "papi_fwrappers.c"
void papif_thread_init_ ( unsigned long int ( *handle ) ( void ), int *check )
{
*check = PAPI_thread_init( handle );
}
# 565 "papi_fwrappers.c"
void papif_list_events_ ( int *EventSet, int *Events, int *number, int *check )
{
*check = PAPI_list_events( *EventSet, Events, number );
}
# 581 "papi_fwrappers.c"
void papif_multiplex_init_ ( int *check )
{
*check = PAPI_multiplex_init( );
}
# 596 "papi_fwrappers.c"
void papif_get_multiplex_ ( int *EventSet, int *check )
{
*check = PAPI_get_multiplex( *EventSet );
}
# 612 "papi_fwrappers.c"
void papif_set_multiplex_ ( int *EventSet, int *check )
{
*check = PAPI_set_multiplex( *EventSet );
}
# 629 "papi_fwrappers.c"
void papif_perror_ ( char *message, int message_len )
{
char tmp[128];
Fortran2cstring( tmp, message, 128, message_len );
PAPI_perror( tmp );
}
# 665 "papi_fwrappers.c"
void papif_query_event_ ( int *EventCode, int *check )
{
*check = PAPI_query_event( *EventCode );
}
# 682 "papi_fwrappers.c"
void papif_query_named_event_ ( char *EventName, int *check, int Event_len )
{
char tmp[128];
Fortran2cstring( tmp, EventName, 128, Event_len );
*check = PAPI_query_named_event( tmp );
}
# 710 "papi_fwrappers.c"
void papif_get_event_info_ ( int *EventCode, char *symbol, char *long_descr, char *short_descr, int *count, char *event_note, int *flags, int *check, int symbol_len, int long_descr_len, int short_descr_len, int event_note_len )
# 720 "papi_fwrappers.c"
{
PAPI_event_info_t info;
( void ) flags;
int i;
if ( ( *check = PAPI_get_event_info( *EventCode, &info ) ) == 0 ) {
strncpy( symbol, info.symbol, ( size_t ) symbol_len );
for ( i = ( int ) strlen( info.symbol ); i < symbol_len;
symbol[i++] = ' ' );
strncpy( long_descr, info.long_descr, ( size_t ) long_descr_len );
for ( i = ( int ) strlen( info.long_descr ); i < long_descr_len;
long_descr[i++] = ' ' );
strncpy( short_descr, info.short_descr, ( size_t ) short_descr_len );
for ( i = ( int ) strlen( info.short_descr ); i < short_descr_len;
short_descr[i++] = ' ' );
*count = ( int ) info.count;
int note_len=0;
strncpy( event_note, info.note, ( size_t ) event_note_len );
note_len=strlen(info.note);
for ( i = note_len; i < event_note_len;
event_note[i++] = ' ' );
}
# 759 "papi_fwrappers.c"
}
# 772 "papi_fwrappers.c"
void papif_event_code_to_name_ ( int *EventCode, char *out_str, int *check, int out_len )
{
char tmp[128];
int i;
*check = PAPI_event_code_to_name( *EventCode, tmp );
strncpy( out_str, tmp, ( size_t ) out_len );
for ( i = ( int ) strlen( tmp ); i < out_len; out_str[i++] = ' ' );
}
# 804 "papi_fwrappers.c"
void papif_event_name_to_code_ ( char *in_str, int *out, int *check, int in_len )
{
int slen, i;
char tmpin[128];
slen = in_len < 128 ? in_len : 128;
strncpy( tmpin, in_str, ( size_t ) slen );
for ( i = slen - 1; i > -1 && tmpin[i] == ' '; tmpin[i--] = '\0' );
tmpin[128 - 1] = '\0';
if ( slen < 128 )
tmpin[slen] = '\0';
*check = PAPI_event_name_to_code( tmpin, out );
}
# 844 "papi_fwrappers.c"
void papif_num_events_ ( int *EventCode, int *count )
{
*count = PAPI_num_events( *EventCode );
}
# 859 "papi_fwrappers.c"
void papif_enum_event_ ( int *EventCode, int *modifier, int *check )
{
*check = PAPI_enum_event( EventCode, *modifier );
}
# 875 "papi_fwrappers.c"
void papif_read_ ( int *EventSet, long long *values, int *check )
{
*check = PAPI_read( *EventSet, values );
}
# 891 "papi_fwrappers.c"
void papif_read_ts_ ( int *EventSet, long long *values, long long *cycles, int *check )
{
*check = PAPI_read_ts( *EventSet, values, cycles );
}
# 907 "papi_fwrappers.c"
void papif_remove_event_ ( int *EventSet, int *Event, int *check )
{
*check = PAPI_remove_event( *EventSet, *Event );
}
# 924 "papi_fwrappers.c"
void papif_remove_named_event_ ( int *EventSet, char *EventName, int *check, int Event_len )
{
char tmp[128];
Fortran2cstring( tmp, EventName, 128, Event_len );
*check = PAPI_remove_named_event( *EventSet, tmp );
}
# 949 "papi_fwrappers.c"
void papif_remove_events_ ( int *EventSet, int *Events, int *number, int *check )
{
*check = PAPI_remove_events( *EventSet, Events, *number );
}
# 965 "papi_fwrappers.c"
void papif_reset_ ( int *EventSet, int *check )
{
*check = PAPI_reset( *EventSet );
}
# 980 "papi_fwrappers.c"
void papif_set_debug_ ( int *debug, int *check )
{
*check = PAPI_set_debug( *debug );
}
# 995 "papi_fwrappers.c"
void papif_set_domain_ ( int *domain, int *check )
{
*check = PAPI_set_domain( *domain );
}
# 1010 "papi_fwrappers.c"
void papif_set_cmp_domain_ ( int *domain, int *cidx, int *check )
{
*check = PAPI_set_cmp_domain( *domain, *cidx );
}
# 1026 "papi_fwrappers.c"
void papif_set_granularity_ ( int *granularity, int *check )
{
*check = PAPI_set_granularity( *granularity );
}
# 1042 "papi_fwrappers.c"
void papif_set_cmp_granularity_ ( int *granularity, int *cidx, int *check )
{
*check = PAPI_set_cmp_granularity( *granularity, *cidx );
}
# 1058 "papi_fwrappers.c"
void papif_shutdown_ ( void )
{
PAPI_shutdown( );
}
# 1073 "papi_fwrappers.c"
void papif_start_ ( int *EventSet, int *check )
{
*check = PAPI_start( *EventSet );
}
# 1088 "papi_fwrappers.c"
void papif_state_ ( int *EventSet, int *status, int *check )
{
*check = PAPI_state( *EventSet, status );
}
# 1104 "papi_fwrappers.c"
void papif_stop_ ( int *EventSet, long long *values, int *check )
{
*check = PAPI_stop( *EventSet, values );
}
# 1120 "papi_fwrappers.c"
void papif_write_ ( int *EventSet, long long *values, int *check )
{
*check = PAPI_write( *EventSet, values );
}
# 1136 "papi_fwrappers.c"
void papif_lock_ ( int *lock, int *check )
{
*check = PAPI_lock( *lock );
}
# 1152 "papi_fwrappers.c"
void papif_unlock_ ( int *lock, int *check )
{
*check = PAPI_unlock( *lock );
}
# 1170 "papi_fwrappers.c"
void papif_start_counters_ ( int *events, int *array_len, int *check )
{
*check = PAPI_start_counters( events, *array_len );
}
# 1186 "papi_fwrappers.c"
void papif_read_counters_ ( long long *values, int *array_len, int *check )
{
*check = PAPI_read_counters( values, *array_len );
}
# 1202 "papi_fwrappers.c"
void papif_stop_counters_ ( long long *values, int *array_len, int *check )
{
*check = PAPI_stop_counters( values, *array_len );
}
# 1218 "papi_fwrappers.c"
void papif_accum_counters_ ( long long *values, int *array_len, int *check )
{
*check = PAPI_accum_counters( values, *array_len );
}
# 1234 "papi_fwrappers.c"
void papif_num_counters_ ( int *numevents )
{
*numevents = PAPI_num_counters( );
}
# 1249 "papi_fwrappers.c"
void papif_ipc_ ( float *rtime, float *ptime, long long *ins, float *ipc, int *check )
{
*check = PAPI_ipc( rtime, ptime, ins, ipc );
}
# 1266 "papi_fwrappers.c"
void papif_epc_ ( int event, float *rtime, float *ptime, long long *ref, long long *core, long long *evt, float *epc, int *check)
{
*check = PAPI_epc( event, rtime, ptime, ref, core, evt, epc );
}
# 1284 "papi_fwrappers.c"
void papif_flips_ ( float *real_time, float *proc_time, long long *flpins, float *mflips, int *check )
{
*check = PAPI_flips( real_time, proc_time, flpins, mflips );
}
# 1301 "papi_fwrappers.c"
void papif_flops_ ( float *real_time, float *proc_time, long long *flpops, float *mflops, int *check )
{
*check = PAPI_flops( real_time, proc_time, flpops, mflops );
}
# 1323 "papi_fwrappers.c"
void papif_get_clockrate_ ( int *cr )
{
*cr = PAPI_get_opt( 14, ((void *)0) );
}
# 1341 "papi_fwrappers.c"
void papif_get_preload_ ( char *lib_preload_env, int *check, int lib_preload_env_len )
{
PAPI_option_t p;
int i;
if ( ( *check = PAPI_get_opt( 13, &p ) ) == 0 ) {
strncpy( lib_preload_env, p.preload.lib_preload_env,
( size_t ) lib_preload_env_len );
for ( i = ( int ) strlen( p.preload.lib_preload_env );
i < lib_preload_env_len; lib_preload_env[i++] = ' ' );
}
}
# 1375 "papi_fwrappers.c"
void papif_get_granularity_ ( int *eventset, int *granularity, int *mode, int *check )
{
PAPI_option_t g;
if ( *mode == 6 ) {
*granularity = PAPI_get_opt( *mode, &g );
*check = 0;
} else if ( *mode == 7 ) {
g.granularity.eventset = *eventset;
if ( ( *check = PAPI_get_opt( *mode, &g ) ) == 0 ) {
*granularity = g.granularity.granularity;
}
} else {
*check = -1;
}
}
# 1403 "papi_fwrappers.c"
void papif_get_domain_ ( int *eventset, int *domain, int *mode, int *check )
{
PAPI_option_t d;
if ( *mode == 4 ) {
*domain = PAPI_get_opt( *mode, ((void *)0) );
*check = 0;
} else if ( *mode == 5 ) {
d.domain.eventset = *eventset;
if ( ( *check = PAPI_get_opt( *mode, &d ) ) == 0 ) {
*domain = d.domain.domain;
}
} else {
*check = -1;
}
}
# 1443 "papi_fwrappers.c"
void papif_set_event_domain_ ( int *es, int *domain, int *check )
{
PAPI_option_t d;
d.domain.domain = *domain;
d.domain.eventset = *es;
*check = PAPI_set_opt( 5, &d );
}
# 1463 "papi_fwrappers.c"
void papif_set_inherit_ ( int *inherit, int *check )
{
PAPI_option_t i;
i.inherit.inherit = *inherit;
*check = PAPI_set_opt( 28, &i );
}
#pragma GCC visibility pop
|
the_stack_data/70261.c | /************************************************************
* File: KaitlinLab1.c
* Project: Lab 01
* Author:
* Version: 1.0
* Date: 7 February, 2020
* Course: CMPE170
* Instructor: Oveeyn Moonian
* Description: The average number of runs of adjacent one bits in an 8-bit, 12-bit, and 16 bit integer.
* *********************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
//FUNCTION DECLARATION
double CalcRunningAvg(double, unsigned int, unsigned int);
/*********************************************************************
* Function Print Error; checks number of runs; calculates avgBitsRuns using function CalcRunningAvg
* Arguments: char * message - string error message
*
* Returns: avgBitRuns
* Description: if the arguments does not equal 2, an error message will be produced. If the argument
* equals 2, follows through with calculating avgBitRuns
* ******************************************************************/
int main(int argc, char* argv[]) {
//checks to see if arguments is equal to 2; if arguments are more or less than two, error statement will be produced
if (argc != 2) {
printf("\nError: Expected integer argument.\n");
return(EXIT_FAILURE);
}
int numBits = atoi(argv[1]); //the number of bits in the numbers to count bit runs
int maxNum = pow(2, numBits); //the maximum number based on the given number of bits (numBits)
double avgBitRuns = 0; //the running average of the number of bit runs
for (unsigned int i = 0; i < maxNum; i++)
{
unsigned int j = i; //used to cycle through all of the bits for each number (i)
int runCount = 0; //the number of bit runs for the current number (i)
bool runStarted = 0; //boolean to identify when a new run of bits has been detected
while (j > 0) {
//look at the least significant bit (LSB) in 'j'
//a run is started (and counted) if the LSB is 1 AND a run hasn't already started
if (j & 1) {
if (!runStarted) {
runStarted = 1;
runCount++;
}
}
//a run of bits is ended (runStarted = 0) when the LSB goes back to 0
else {
if (runStarted) {
runStarted = 0;
}
}
//bit shift 'j' to the right by 1, because we need to look at the next bit
//so a number with a bit pattern of 00011010 shifts to the right to become 00001101
j >>= 1;
}
//calculates the average bit runs using the function CalcRunningAvg below
avgBitRuns = CalcRunningAvg(avgBitRuns, i, runCount);
}
//prints the average to the user
printf("\n%.2f\n", avgBitRuns);
return (EXIT_SUCCESS);
}
/*********************************************************************
* Function calculate the newRunningAvg
* Arguments: no arguments
*
* Returns: newRunningAvg
* Description: calculates newRunningAvg from the number input from the user.
* ******************************************************************/
double CalcRunningAvg(double currentAvg, unsigned int n, unsigned int newCount) {
double runNum = (double)n;
double newRunningAvg = (currentAvg * (runNum / (runNum + 1.0))) + ((double)newCount / (runNum + 1.0));
return newRunningAvg;
}
|
the_stack_data/18888268.c | /*
* Copyright(c) 2021 Fraunhofer AISEC
* Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef MBEDTLS_CONFIG_FILE
#include MBEDTLS_CONFIG_FILE
#if defined(MBEDTLS_PK_WRITE_C)
#include "mbedtls/pk.h"
#include "mbedtls/ecdh.h"
#include "mbedtls/hmac_drbg.h"
#include "lz_ecc.h"
int lz_derive_ecc_keypair(lz_ecc_keypair *keypair, const void *seed, size_t seed_size)
{
mbedtls_pk_init(keypair);
mbedtls_hmac_drbg_context hmac_drbg_ctx;
mbedtls_hmac_drbg_init(&hmac_drbg_ctx);
int re;
// Get hash algorithm
const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256);
if (md_info == NULL) {
dbgprint(DBG_INFO, "ERROR: Could not find hash algorithm\n");
re = -1;
goto clean;
}
// Initialize drgb context
CHECK(mbedtls_hmac_drbg_seed_buf(&hmac_drbg_ctx, md_info, seed, seed_size),
"Error while initializing DRGB context");
CHECK(mbedtls_pk_setup(keypair, mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY)),
"Error setting up public key context");
CHECK(mbedtls_ecp_gen_key(MBEDTLS_ECP_DP_SECP256R1, mbedtls_pk_ec(*keypair),
mbedtls_hmac_drbg_random, &hmac_drbg_ctx),
"Could not derive ECC keypair");
clean:
if (re < 0) {
mbedtls_pk_free(keypair);
}
mbedtls_hmac_drbg_free(&hmac_drbg_ctx);
return re;
}
#if defined(MBEDTLS_PEM_WRITE_C)
int lz_pub_key_to_pem(lz_ecc_keypair *keypair, lz_ecc_pub_key_pem *pem)
{
int re = 0;
// Writing the pubkey to the buffer
CHECK(mbedtls_pk_write_pubkey_pem(keypair, (unsigned char*)pem->key, sizeof(pem->key)),
"Error writing pubkey (PEM)");
clean:
return re;
}
int lz_priv_key_to_pem(lz_ecc_keypair *keypair, lz_ecc_priv_key_pem *pem)
{
int re = 0;
CHECK(mbedtls_pk_write_key_pem(keypair, (unsigned char*)pem->key, sizeof(pem->key)),
"Error writing pubkey (PEM)");
clean:
return re;
}
#endif
#if defined(MBEDTLS_PK_PARSE_C)
int lz_pem_to_pub_key(lz_ecc_keypair *keypair, const lz_ecc_pub_key_pem *pem)
{
mbedtls_pk_init(keypair);
int re = 0;
CHECK(mbedtls_pk_parse_public_key(keypair, (unsigned char*)pem->key,
strnlen(pem->key, MAX_PUB_ECP_PEM_BYTES - 1) + 1),
"Error parsing the public PEM key");
clean:
if (re < 0) {
mbedtls_pk_free(keypair);
}
return re;
}
int lz_pem_to_priv_key(lz_ecc_keypair *keypair, const lz_ecc_priv_key_pem *pem)
{
mbedtls_pk_init(keypair);
int re = 0;
CHECK(mbedtls_pk_parse_key(keypair, (unsigned char*)pem->key, strlen(pem->key) + 1, NULL, 0),
"Error parsing the private PEM key");
clean:
if (re < 0) {
mbedtls_pk_free(keypair);
}
return re;
}
#endif
lz_ecc_private_key *lz_keypair_to_private(lz_ecc_keypair *keypair)
{
return &mbedtls_pk_ec(*keypair)->d;
}
lz_ecc_public_key *lz_keypair_to_public(lz_ecc_keypair *keypair)
{
return &mbedtls_pk_ec(*keypair)->Q;
}
int lz_compare_public_key(lz_ecc_public_key *k1, lz_ecc_public_key *k2)
{
return mbedtls_ecp_point_cmp(k1, k2);
}
void lz_free_keypair(lz_ecc_keypair *keypair)
{
mbedtls_pk_free(keypair);
}
#endif /* MBEDTLS_PK_WRITE_C_ */
#endif /* MBEDTLS_CONFIG_FILE */
|
the_stack_data/36075951.c | /*
* Copyright (c) 2020-2021, SkillerRaptor <[email protected]>
*
* SPDX-License-Identifier: MIT
*/
#include <stdio.h>
static FILE std_streams[3];
FILE* stdin = &std_streams[0];
FILE* stdout = &std_streams[1];
FILE* stderr = &std_streams[2];
FILE* fopen(const char* file, const char* mode)
{
// TODO: Implement fopen
return NULL;
}
int fclose(FILE* stream)
{
// TODO: Implement fclose
return 0;
}
int fprintf(FILE* stream, const char* format, ...)
{
va_list args;
va_start(args, format);
int ret = vfprintf(stream, format, args);
va_end(args);
return ret;
}
int printf(const char* format, ...)
{
va_list args;
va_start(args, format);
int ret = vprintf(format, args);
va_end(args);
return ret;
}
int sprintf(char* buffer, const char* format, ...)
{
va_list args;
va_start(args, format);
int ret = vsprintf(buffer, format, args);
va_end(args);
return ret;
}
int snprintf(char* buffer, size_t buffer_size, const char* format, ...)
{
va_list args;
va_start(args, format);
int ret = vsnprintf(buffer, buffer_size, format, args);
va_end(args);
return ret;
}
int vfprintf(FILE* stream, const char* format, va_list args)
{
// TODO: Implement vfprintf
return 0;
}
int vprintf(const char* format, va_list args)
{
// TODO: Implement vprintf
return 0;
}
int vsprintf(char* buffer, const char* format, va_list args)
{
// TODO: Implement vsprintf
return 0;
}
int vsnprintf(char* buffer, size_t buffer_size, const char* format, va_list args)
{
// TODO: Implement vsnprintf
return 0;
} |
the_stack_data/141252.c | #include<stdio.h>
#include<unistd.h>
int main(int argc, char *argv[]) {
printf("\tuid\tgid\teuid\tegid\n");
printf("parent\t%d\t%d\t%d\t%d\n", getuid(), getgid(), geteuid(), getegid());
if (fork() == 0) {
printf("child\t%d\t%d\t%d\t%d\n", getuid(), getgid(), geteuid(), getegid());
}
return 0;
}
|
the_stack_data/166514.c | #include<stdio.h>
main()
{
int arr[20];
int i=0, sum=0, size;
printf("Enter the size of the array");
scanf("%d",&size);
printf("\nEnter %d elements into Array",size);
for(i=0;i<size;i++)
scanf("%d",&arr[i]);
printf("\nArray Elements are :\n");
for(i=0;i<size;i++)
printf("%d\t",arr[i]);
for(i=0;i<size;i++)
sum = sum + arr[i];
printf("\n\nSum of Array Elements : %d",sum);
}
|
the_stack_data/181391925.c | #include <stdio.h>
#include <stdlib.h>
void foo (char *aop[]) {
printf("foo\n");
}
void bar (char *aop[4]) {
printf("bar\n");
}
void hoo (char (*pta)[]) {
printf("hoo\n");
}
void wow (char (*pta)[4]) {
printf("wow\n");
}
int main (int argc, char *argv[]) {
char a='a', b='b', c='c', d='d';
char array[4] = {'e', 'f', 'g', 'h'};
char *pointer = array;
char **double_pointer;
char *array_of_pointer[4]; // Array of pointers (char *)
char (*pointer_to_array)[4]; // Pointer of array (char [])
// char *nosize_array_of_pointer[]; // <GCC ERROR> error: array size missing in ‘ptr_arr’
char (*pointer_to_nosize_array)[];
array_of_pointer[0] = &a;
array_of_pointer[1] = &b;
array_of_pointer[2] = &c;
array_of_pointer[3] = &d;
pointer_to_array = &array;
/** <CONCLUSION 1>
*
* Double Pointer = Array of Pointer != Pointer to Array
**/
foo(double_pointer);
foo(array_of_pointer);
// foo(pointer_to_array); // <GCC ERROR> note: expected ‘char **’ but argument is of type ‘char (*)[4]’
// foo(pointer_to_nosize_array); // <GCC ERROR> expected ‘char **’ but argument is of type ‘char (*)[]’
bar(double_pointer);
bar(array_of_pointer);
// bar(pointer_to_array); // <GCC ERROR> note: expected ‘char **’ but argument is of type ‘char (*)[4]’
// hoo(double_pointer); // <GCC ERROR> note: expected ‘char (*)[]’ but argument is of type ‘char **’
// hoo(array_of_pointer); // <GCC ERROR> note: expected ‘char (*)[]’ but argument is of type ‘char **’
hoo(pointer_to_array);
hoo(pointer_to_nosize_array);
// wow(double_pointer); // <GCC ERROR> note: expected ‘char (*)[4]’ but argument is of type ‘char **’
// wow(array_of_pointer); // <GCC ERROR> note: expected ‘char (*)[4]’ but argument is of type ‘char **’
wow(pointer_to_array);
wow(pointer_to_nosize_array);
/** <CONCLUSION 2>
*
* Pointer != Array
* Array: Read Only
* Array expressions may not be the target of an assignment; the = operator isn't defined to copy the contents of one array to the other.
**/
pointer += 2;
pointer_to_array += 2;
// pointer_to_nosize_array += 2; // <GCC ERROR> error: invalid use of array with unspecified bounds
// *pointer_to_array += 2; // <GCC ERROR> error: invalid operands to binary + (have ‘char[4]’ and ‘int’)
// array = array + 2; // <GCC ERROR> error: incompatible types when assigning to type ‘char[4]’ from type ‘char *’
// array += 2; // <GCC ERROR> error: invalid operands to binary + (have ‘char[4]’ and ‘int’)
// array_of_pointer += 2; // <GCC ERROR> error: invalid operands to binary + (have ‘char[4]’ and ‘int’)
return 0;
}
|
the_stack_data/129810.c | // This file is part of CPAchecker,
// a tool for configurable software verification:
// https://cpachecker.sosy-lab.org
//
// SPDX-FileCopyrightText: 2007-2020 Dirk Beyer <https://www.sosy-lab.org>
//
// SPDX-License-Identifier: Apache-2.0
#include <limits.h>
// macro simplifies test code
#define shouldBeTrue(a) \
if (!(a)) \
{ \
goto ERROR; \
}
// Test whether the side effect (=third parameter) is calculated correctly
int main()
{
// __builtin_add_overflow
{
int a; long long c;
// no overflow in type of c
__builtin_add_overflow(INT_MAX, INT_MAX, &c);
shouldBeTrue(c == 2LL * INT_MAX)
int x = INT_MAX, y = INT_MAX;
__builtin_add_overflow(x, y, &c);
shouldBeTrue(c == 1LL*x + y)
// overflow
__builtin_add_overflow(INT_MAX, 1, &a);
shouldBeTrue(a == INT_MIN)
}
// // __builtin_sadd_overflow
{
int a;
// no overflow
__builtin_sadd_overflow(INT_MAX-1ll, 1, &a);
shouldBeTrue(a == INT_MAX)
// overflow
__builtin_sadd_overflow(INT_MAX, 4, &a);
shouldBeTrue(a == INT_MIN+3)
// overflow during parameter conversion and calculation
__builtin_sadd_overflow(INT_MAX + 1ll, -100, &a);
shouldBeTrue(a == INT_MAX - 99)
}
// __builtin_saddl_overflow
{
long a;
__builtin_saddl_overflow(LONG_MAX - 1ll, 1l, &a);
shouldBeTrue(a == LONG_MAX)
__builtin_saddl_overflow(LONG_MAX, 4l, &a);
shouldBeTrue(a == LONG_MIN + 3l)
__builtin_saddl_overflow(LONG_MAX + 1LL, -100l, &a);
shouldBeTrue(a == LONG_MAX - 99l)
}
// __builtin_saddll_overflow
{
long long a;
__builtin_saddll_overflow(LLONG_MAX - 1LL, 1LL, &a);
shouldBeTrue(a == LLONG_MAX)
long c;
__builtin_saddll_overflow(LLONG_MAX - 1ll, 1l, &c);
shouldBeTrue(c == -1) // type conversion when writing to c
__builtin_saddll_overflow(LLONG_MAX, 4LL, &a);
shouldBeTrue(a == LLONG_MIN + 3LL)
}
// __builtin_uadd_overflow
{
unsigned int a;
__builtin_uadd_overflow(UINT_MAX - 1ull, 1u, &a);
shouldBeTrue(a == UINT_MAX)
__builtin_uadd_overflow(UINT_MAX, 4u, &a);
shouldBeTrue(a == 3u)
__builtin_uadd_overflow(UINT_MAX + 1ull, -100u, &a);
shouldBeTrue(a == UINT_MAX - 99u)
}
// __builtin_uaddl_overflow
{
unsigned long a;
__builtin_uaddl_overflow(ULONG_MAX - 1ull, 1ul, &a);
shouldBeTrue(a == ULONG_MAX)
__builtin_uaddl_overflow(ULONG_MAX, 4ul, &a);
shouldBeTrue(a == 3ul)
__builtin_uaddl_overflow(ULONG_MAX + 1ull, -100ul, &a);
shouldBeTrue(a == ULONG_MAX - 99ul)
}
// __builtin_uaddll_overflow
{
unsigned long long a;
__builtin_uaddll_overflow(ULLONG_MAX - 1uLL, 1uLL, &a);
shouldBeTrue(a == ULLONG_MAX)
__builtin_uaddll_overflow(ULLONG_MAX, 4uLL, &a);
shouldBeTrue(a == 0uLL + 3uLL)
}
// __builtin_sub_overflow
{
int a; long long c;
// no overflow in type of c
__builtin_sub_overflow(INT_MIN, 100, &c);
shouldBeTrue(c == INT_MIN - 100ll)
// overflow
__builtin_sub_overflow(INT_MIN, 1, &a);
shouldBeTrue(a == INT_MAX)
}
// __builtin_ssub_overflow
{
int a;
__builtin_ssub_overflow(INT_MIN + 1ll, 1, &a);
shouldBeTrue(a == INT_MIN)
__builtin_ssub_overflow(INT_MIN, 4, &a);
shouldBeTrue(a == INT_MAX - 3)
__builtin_ssub_overflow(INT_MAX + 1ll, 100, &a);
shouldBeTrue(a == INT_MAX - 99)
}
// __builtin_ssubl_overflow
{
long a;
__builtin_ssubl_overflow(LONG_MIN + 1ll, 1l, &a);
shouldBeTrue(a == LONG_MIN)
__builtin_ssubl_overflow(LONG_MIN, 4l, &a);
shouldBeTrue(a == LONG_MAX - 3l)
__builtin_ssubl_overflow(LONG_MAX + 1ll, 100l, &a);
shouldBeTrue(a == LONG_MAX - 99l)
}
// __builtin_ssubll_overflow
{
long long a;
__builtin_ssubll_overflow(LLONG_MIN + 1ll, 1ll, &a);
shouldBeTrue(a == LLONG_MIN)
__builtin_ssubll_overflow(LLONG_MIN, 4ll, &a);
shouldBeTrue(a == LLONG_MAX - 3ll)
}
// __builtin_usub_overflow
{
unsigned int a;
__builtin_usub_overflow(1u, 1u, &a);
shouldBeTrue(a == 0u)
__builtin_usub_overflow(0u, 4u, &a);
shouldBeTrue(a == UINT_MAX - 3u)
__builtin_usub_overflow(UINT_MAX + 1ull, 100u, &a);
shouldBeTrue(a == UINT_MAX - 99u)
}
// __builtin_usubl_overflow
{
unsigned long int a;
__builtin_usubl_overflow(1ul, 1ul, &a);
shouldBeTrue(a == 0ul)
__builtin_usubl_overflow(0ul, 4ul, &a);
shouldBeTrue(a == ULONG_MAX - 3ul)
__builtin_usubl_overflow(ULONG_MAX + 1ull, 100ul, &a);
shouldBeTrue(a == ULONG_MAX - 99ul)
}
// __builtin_usubll_overflow
{
unsigned long long int a;
__builtin_usubll_overflow(1ull, 1ull, &a);
shouldBeTrue(a == 0ull)
__builtin_usubll_overflow(0ull, 4ull, &a);
shouldBeTrue(a == ULLONG_MAX - 3ull)
}
// __builtin_mul_overflow
{
int a; long long c;
// no overflow in type of c
__builtin_mul_overflow(INT_MAX, 2, &c);
shouldBeTrue(c == INT_MAX * 2ll)
// overflow
__builtin_mul_overflow(INT_MAX, 2, &a);
shouldBeTrue(a == -2)
}
// __builtin_smul_overflow
{
int a;
__builtin_smul_overflow(5, 2, &a);
shouldBeTrue(a == 10)
__builtin_smul_overflow(INT_MAX, 2, &a);
shouldBeTrue(a == -2)
}
// __builtin_smull_overflow
{
long a;
__builtin_smull_overflow(5, 2, &a);
shouldBeTrue(a == 10)
__builtin_smull_overflow(LONG_MAX, 2, &a);
shouldBeTrue(a == -2)
}
// __builtin_smulll_overflow
{
long long a;
__builtin_smulll_overflow(5, 2, &a);
shouldBeTrue(a == 10)
__builtin_smulll_overflow(LLONG_MAX, 2, &a);
shouldBeTrue(a == -2)
}
// __builtin_umul_overflow
{
unsigned int a;
__builtin_umul_overflow(5, 2, &a);
shouldBeTrue(a == 10)
__builtin_umul_overflow(UINT_MAX, 2, &a);
shouldBeTrue(a == UINT_MAX - 1)
}
// __builtin_umull_overflow
{
unsigned long a;
__builtin_umull_overflow(5, 2, &a);
shouldBeTrue(a == 10)
__builtin_umull_overflow(ULONG_MAX, 2, &a);
shouldBeTrue(a == ULONG_MAX - 1)
}
// __builtin_umulll_overflow
{
unsigned long long a;
__builtin_umulll_overflow(5, 2, &a);
shouldBeTrue(a == 10)
__builtin_umulll_overflow(ULLONG_MAX, 2, &a);
shouldBeTrue(a == ULLONG_MAX - 1)
}
return 0;
ERROR:
return 1;
}
|
the_stack_data/93888325.c | /* PR rtl-optimization/54921 */
/* { dg-do run } */
/* { dg-options "-Os -fno-omit-frame-pointer -fsched2-use-superblocks -ftree-slp-vectorize" } */
/* { dg-additional-options "-fstack-protector" { target fstack_protector } } */
struct A
{
int a;
char b[32];
} a, b;
__attribute__((noinline, noclone))
struct A
bar (int x)
{
struct A r;
static int n;
r.a = ++n;
__builtin_memset (r.b, 0, sizeof (r.b));
r.b[0] = x;
return r;
}
int
main ()
{
a = bar (3);
b = bar (4);
if (a.a != 1 || a.b[0] != 3 || b.a != 2 || b.b[0] != 4)
__builtin_abort ();
return 0;
}
|
the_stack_data/974623.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node_t{
char v;
struct node_t *r;
struct node_t *l;
struct node_t *f;
}node;
node *newnode(char v){
node *tem=malloc(sizeof(node));
tem->r=NULL;
tem->l=NULL;
tem->f=NULL;
tem->v=v;
return tem;
}
char *find(char *str,char targe,char *l,char *r){
int i,j;
int ai=0,bi=0;
int flat=0;
for(i=0;str[i]!='\0';i++){
if(str[i]==targe){
flat =1;
continue;
}
if(flat==0){
l[ai]=str[i];
ai++;
}
else{
r[bi]=str[i];
bi++;
}
}
l[ai]='\0';
r[bi]='\0';
}
char *match(char *a,char *b ){
int i,j;
int max=-1;
int min=-1;
for(i=0;a[i]!='\0';i++){
for(j=0;b[j]!='\0';j++){
if(a[i]==b[j]){
if(max==-1)min=j;
else min=min<j?min:j;
max=max>j?max:j;
}
}
}
char *ans=malloc(sizeof(char)*100);
for (int i = 0; i <= max-min; i++){
ans[i]=b[i+min];
}
ans[max+1]='\0';
if(max==-1)return "\0";
return ans;
}
node *findpre(char *mid,char *pre,int type){
if(mid[0]=='\0'||pre[0]=='\0'){
return NULL;
}
node *tem;
if(type==0)tem=newnode(*pre);
else tem=newnode(pre[strlen(pre)-1]);
char l[100]="",r[100]="";
find(mid,tem->v,l,r);
char *lpre=match(l,pre);
char *rpre=match(r,pre);
tem->l=findpre(l,lpre,type);
tem->r=findpre(r,rpre,type);
return tem;
}
void bfs(node *a[100],int len){
//printf("!%c\n",(a[0])->v);
int i;
int listlen=0;
node *tem[100];
for(i=0;i<len;i++){
printf("%c",(a[i])->v);
if((a[i])->l!=NULL){
tem[listlen]=a[i]->l;
listlen+=1;
}
if((a[i])->r!=NULL){
tem[listlen]=a[i]->r;
listlen+=1;
}
}
if(listlen!=0)bfs(tem,listlen);
}
int main(){
char order[100]="";
char mid[100]="";
char path[100]="";
int type=0;
scanf("%s",order);
if(*order=='I'){
scanf("%s",mid);
}else {
if(*order=='O')type=1;
scanf("%s",path);
}
scanf("%s",order);
if(*order=='I'){
scanf("%s",mid);
}else {
if(*order=='O')type=1;
scanf("%s",path);
}
node *root=findpre(mid,path,type);
bfs(&root,1);
return 0;
}
|
the_stack_data/242329996.c | // Copyright (c) 2015 Nuxi, https://nuxi.nl/
//
// SPDX-License-Identifier: BSD-2-Clause
#include <string.h>
void *memccpy(void *restrict s1, const void *restrict s2, int c, size_t n) {
unsigned char *sb1 = s1;
const unsigned char *sb2 = s2;
while (n-- > 0) {
*sb1 = *sb2++;
if (*sb1++ == (unsigned char)c)
return sb1;
}
return NULL;
}
|
the_stack_data/126702098.c | /*
* appl/telnet/libtelnet/forward.c
*/
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* General-purpose forwarding routines. These routines may be put into */
/* libkrb5.a to allow widespread use */
#if defined(KERBEROS) || defined(KRB5)
#include <stdio.h>
#include <netdb.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "krb5.h"
#include <errno.h>
#include "krb5forw.h"
#if defined(NEED_SETENV) || defined(NEED_SETENV_PROTO)
extern int setenv(char *, char *, int);
#endif
extern char *line; /* see sys_term.c */
/* Decode, decrypt and store the forwarded creds in the local ccache. */
krb5_error_code
rd_and_store_for_creds(context, auth_context, inbuf, ticket)
krb5_context context;
krb5_auth_context auth_context;
krb5_data *inbuf;
krb5_ticket *ticket;
{
krb5_creds **creds;
krb5_error_code retval;
char ccname[35];
krb5_ccache ccache = NULL;
if ((retval = krb5_rd_cred(context, auth_context, inbuf, &creds, NULL)))
return(retval);
sprintf(ccname, "FILE:/tmp/krb5cc_p%ld", (long) getpid());
setenv("KRB5CCNAME", ccname, 1);
if ((retval = krb5_cc_resolve(context, ccname, &ccache)))
goto cleanup;
if ((retval = krb5_cc_initialize(context, ccache,
ticket->enc_part2->client)))
goto cleanup;
if ((retval = krb5_cc_store_cred(context, ccache, *creds)))
goto cleanup;
cleanup:
krb5_free_creds(context, *creds);
return retval;
}
#endif /* defined(KRB5) && defined(FORWARD) */
|
the_stack_data/189044.c | #include <stdio.h>
#include <math.h>
#define ROZMIAR 10
#define ILOSC 4
void przeksztalc(const double zrodlo[], double cel[], int n, double (*funkcja)(double liczba));
double przeciwna(double liczba);
double odwrocona(double liczba);
int main(void)
{
double (*funkcje[ILOSC])(double) = { sin, cos, przeciwna, odwrocona };
double zrodlo[ROZMIAR] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10 };
double cel[ROZMIAR];
for (int i = 0; i < ILOSC; i++)
przeksztalc(zrodlo, cel, ROZMIAR, funkcje[i]);
return 0;
}
void przeksztalc(const double zrodlo[], double cel[], int n, double (*funkcja)(double liczba))
{
for (int i = 0; i < n; i++)
{
cel[i] = (*funkcja)(zrodlo[i]);
printf("%.2f ", cel[i]);
}
putchar('\n');
}
double przeciwna(double liczba)
{
return -liczba;
}
double odwrocona(double liczba)
{
return 1 / liczba;
} |
the_stack_data/126806.c |
#include <pthread.h>
const int num = 2;
int fun2()
{
while(1) {}
}
int fun1()
{
fun2();
}
void *func(void* arg) {
fun1();
return ((void *)0);
}
int main(int argc, char* argv[]) {
int i,j;
pthread_t threads[num];
for ( i = 0; i < num; i++) {
pthread_create(&threads[i], NULL, func, NULL);
}
for (i = 0; i < num; i++) {
pthread_join(threads[i], NULL);
}
return 0;
}
|
the_stack_data/154830067.c | /*
Copyright 2012 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <sys/mman.h>
#include <asm/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <time.h>
#include <malloc.h>
#include <string.h>
#include <unistd.h>
#include <syscall.h>
#include <stdlib.h>
#include <err.h>
#include <sched.h>
#include <getopt.h>
typedef unsigned long long u64;
#define DECLARE_ARGS(val, low, high) unsigned low, high
#define EAX_EDX_VAL(val, low, high) ((low) | ((u64)(high) << 32))
#define EAX_EDX_ARGS(val, low, high) "a" (low), "d" (high)
#define EAX_EDX_RET(val, low, high) "=a" (low), "=d" (high)
static inline unsigned long long
_rdtsc(void)
{
DECLARE_ARGS(val, low, high);
asm volatile("rdtsc" : EAX_EDX_RET(val, low, high));
return EAX_EDX_VAL(val, low, high);
}
#define MAX_CPUS 2048
#define NR_CPU_BITS (MAX_CPUS>>3)
static int
pin_cpu(pid_t pid, unsigned int cpu)
{
unsigned long long my_mask[NR_CPU_BITS];
memset(my_mask, 0, sizeof(my_mask));
if (cpu >= MAX_CPUS)
errx(1, "this program supports only up to %d CPUs", MAX_CPUS);
my_mask[cpu>>6] = 1ULL << (cpu&63);
return syscall(__NR_sched_setaffinity, pid, sizeof(my_mask), &my_mask);
}
void
usage()
{
fprintf(stderr," malloc_test need at least 3 arguments setting values for -r, -m and -l\n");
fprintf(stderr," -r indicates what core to use when running the triad\n");
fprintf(stderr," -l number of 64 byte lines in the buffer to malloc, initialize and free\n");
fprintf(stderr," [-m] value increases the number of calls to triad by a multiplier = value\n");
}
void
main(int argc, char ** argv)
{
double *a, *b, *c, xx=0.01, bw, avg_bw, best_bw=-1.0;
char * buf1, *buf2, *buf3;
int i,j,k,offset_a=0,offset_b=0,offset_c=0, mult=1,iter=1000, c_val;
int len,num_pages, num_lines, cpu_run,scale;
u64 start, stop, run_time, call_start, call_stop, call_run_time,total_bytes=0;
__pid_t pid=0;
int cpu_setsize;
cpu_set_t mask;
int *buff;
size_t buf_size;
off_t offset = 0;
int fd = -1;
// process input arguments
if(argc < 3 ){
printf("triad driver needs at least 3 arguments, cpu_init, cpu_run, cache_level, [call count multiplier def = 1], [offset a, offset_b, offset_c defaults = 0] \n");
printf(" argc = %d\n",argc);
usage();
err(1, "bad arguments");
}
while ((c_val = getopt(argc, argv, "i:r:l:m:a:b:c")) != -1) {
switch(c_val) {
case 'r':
cpu_run = atoi(optarg);
break;
case 'l':
num_pages = atoi(optarg);
break;
case 'm':
mult = atoi(optarg);
break;
default:
err(1, "unknown option %c", c_val);
}
}
// pin core affinity for initialization
if(pin_cpu(pid, cpu_run) == -1) {
err(1,"failed to set affinity");
}
else{
fprintf(stderr," process pinned to core %d for triad run\n",cpu_run);
}
// set buffer sizes and loop tripcount
buf_size = (u64)4096*(u64)num_pages;
num_lines=64*num_pages;
iter = iter*mult;
// malloc and initialize buffers
printf(" starting malloc loop of %d iterations with buf_size = %ld, num_lines = %d\n",iter,buf_size, num_lines);
call_start = _rdtsc();
for(i=0;i<iter;i++){
start = _rdtsc();
buff = (int*) malloc(buf_size);
if(buff == NULL)
{
fprintf(stderr,"malloc failed\n");
err(1,"malloc failed");
}
for(j=0;j<num_lines-1;j+=32)
{
buff[j*16] = 0;
}
free(buff);
stop = _rdtsc();
run_time = stop - start;
}
call_stop = _rdtsc();
call_run_time = call_stop - call_start;
// printout
printf(" allocating %lld bytes and initializing and freeing took %lld cycles\n",(u64)len*(u64)iter,run_time);
}
|
the_stack_data/93887333.c |
void node_process(float in, float *out)
{
*out = in;
}
|
the_stack_data/994365.c | // File name: ExtremeC_exampels_chapter2_5.c
// Description: Example 2.5
#include <unistd.h> // Needed for sleep function
#include <stdlib.h> // Needed for malloc function
#include <stdio.h> // Needed for printf
int main(int argc, char** argv) {
void* ptr = malloc(1024); // Allocate 1KB from heap
printf("Address: %p\n", ptr);
fflush(stdout); // To force the print
// Infinite loop
while (1) {
sleep(1); // Sleep 1 second
};
return 0;
}
|
the_stack_data/92324864.c | #include <stdio.h>
int main()
{
int n,i,x, sum=0;
scanf("%d", &n);
for( i=0; i<n; i++)
{
scanf("%d", &x);
sum=sum+x;
};
printf("%d\n", sum);
return 0;
}
|
the_stack_data/126703310.c | #ifdef USE_XMP
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <xmp.h>
#include "audio/sources/xmp_source.h"
#include "utils/allocator.h"
#include "utils/log.h"
typedef struct {
xmp_context ctx;
} xmp_source;
audio_source_freq xmp_freqs[] = {
{11025, 0, "11025Hz"},
{22050, 0, "22050Hz"},
{44100, 1, "44100Hz"},
{48000, 1, "48000Hz"},
{0,0,0} // Guard
};
audio_source_resampler xmp_resamplers[] = {
{XMP_INTERP_NEAREST, 0, "Nearest"},
{XMP_INTERP_LINEAR, 1, "Linear"},
{XMP_INTERP_SPLINE, 0, "Cubic"},
{0,0,0}
};
audio_source_freq* xmp_get_freqs() {
return xmp_freqs;
}
audio_source_resampler* xmp_get_resamplers() {
return xmp_resamplers;
}
int xmp_source_update(audio_source *src, char *buffer, int len) {
xmp_source *local = source_get_userdata(src);
int ret = xmp_play_buffer(local->ctx, buffer, len, (src->loop == 1) ? 999999 : 1);
return (ret != 0) ? 0 : len;
}
void xmp_source_close(audio_source *src) {
xmp_source *local = source_get_userdata(src);
xmp_end_player(local->ctx);
xmp_release_module(local->ctx);
xmp_free_context(local->ctx);
omf_free(local);
source_set_userdata(src, local);
DEBUG("XMP Source: Closed.");
}
int xmp_source_init(audio_source *src, const char* file, int channels, int freq, int resampler) {
xmp_source *local = omf_calloc(1, sizeof(xmp_source));
// Create a libxmp context
local->ctx = xmp_create_context();
if(local->ctx == NULL) {
PERROR("XMP Source: Unable to initialize xmp context.");
goto error_0;
}
// Load the module file
if(xmp_load_module(local->ctx, (char*)file) < 0) {
PERROR("XMP Source: Unable to open module file.");
goto error_1;
}
// Show some information
struct xmp_module_info mi;
xmp_get_module_info(local->ctx, &mi);
DEBUG("XMP Source: Track is %s (%s)", mi.mod->name, mi.mod->type);
// Start the player
int flags = 0;
if(channels == 1) {
flags |= XMP_FORMAT_MONO;
DEBUG("XMP Source: Setting to MONO.");
}
if(xmp_start_player(local->ctx, freq, flags) != 0) {
PERROR("XMP Source: Unable to open module file.");
goto error_1;
}
if(xmp_set_player(local->ctx, XMP_PLAYER_INTERP, resampler) != 0) {
PERROR("XMP Source: Unable to set resampler.");
goto error_1;
}
// Audio information
source_set_frequency(src, freq);
source_set_bytes(src, 2);
source_set_channels(src, channels);
source_set_resampler(src, resampler);
// Set callbacks
source_set_userdata(src, local);
source_set_update_cb(src, xmp_source_update);
source_set_close_cb(src, xmp_source_close);
// Some debug info
DEBUG("XMP Source: Loaded file '%s' succesfully.", file);
// All done
return 0;
error_1:
xmp_free_context(local->ctx);
error_0:
omf_free(local);
return 1;
}
#endif // USE_XMP
|
the_stack_data/100140806.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/02 22:03:32 by cacharle #+# #+# */
/* Updated: 2019/07/15 13:18:04 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
|
the_stack_data/234517859.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_program_name.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: angmarti <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/25 17:24:17 by angmarti #+# #+# */
/* Updated: 2021/08/25 17:30:15 by angmarti ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int main(int argc, char **argv)
{
int i;
argc++;
i = 0;
while (argv[0][i] != '\0')
write(1, &argv[0][i++], 1);
write(1, "\n", 1);
}
|
the_stack_data/207063.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char str[32]="Do you like Linux?";
char *ptr,*p;
int i;
ptr = (char *) malloc(32);
printf("strlen(str)=%d\n", strlen(str));
memcpy(ptr, str, strlen(str));
for (i=0; i<32; i++) {
printf("%d", i);
putchar(ptr[i]);
}
// printf("%s\n", ptr);
printf("\n");
memset(ptr+12,'l',1);
// printf("%s\n", ptr);
for (i=0; i<32; i++) {
printf("%d", i);
putchar(ptr[i]);
}
printf("\n");
p = (char *) memchr(ptr,'l',18);
printf("%s\n", p);
memmove(str+12,str+7,11);
printf("%s\n", str);
}
|
the_stack_data/150080.c | #include<stdio.h>
void squeeezze(char s1[], char s2[])
{
int i, j, k;
for (i = k = 0; s1[i] != '\0'; i++) {
for (j = 0; s2[j] != '\0' && s2[j] != s1[i]; j++)
;
if (s2[j] == '\0')
s1[k++] = s1[i];
}
s1[k] = '\0';
}
int main()
{
char s1 [] = "abcdddefghijklmn";
char s2 [] = "cdin888";
squeeezze(s1, s2);
printf("%s\n", s1);
}
|
the_stack_data/1146913.c | /**
* testbpd.c - test bidirectional pipes
*/
main()
{
int p[2];
if ( pipe(p) == -1 ) exit(1);
if ( write(p[0], "hello", 5) == -1 )
perror("write into pipe[0] failed");
else
printf("write into pipe[0] worked\n");
} |
the_stack_data/58531.c | /*-
* Copyright (c) 2002 Tim J. Robbins
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
* $FreeBSD: head/lib/libc/string/wcsrchr.c 105786 2002-10-23 10:52:04Z tjr $
*/
#include <wchar.h>
wchar_t *
wcsrchr(const wchar_t *s, wchar_t c)
{
const wchar_t *last;
last = NULL;
for (;;) {
if (*s == c)
last = s;
if (*s == L'\0')
break;
s++;
}
return ((wchar_t *)last);
}
|
the_stack_data/125141761.c | #include <stdio.h>
#include <stdlib.h>
int main(){
int hora_inicial, minuto_inicial, hora_final, minuto_final;
scanf("%d", &hora_inicial);
scanf("%d", &minuto_inicial);
scanf("%d", &hora_final);
scanf("%d", &minuto_final);
int minutos_totais_i, minutos_totais_f;
minutos_totais_i = (hora_inicial * 60) + minuto_inicial;
minutos_totais_f = (hora_final * 60) + minuto_final;
int minutos_duracao, duracao, minuto;
if (minutos_totais_f > minutos_totais_i){
minutos_duracao = minutos_totais_f - minutos_totais_i;
duracao = minutos_duracao / 60;
minuto = minutos_duracao % 60;
}
if (minutos_totais_i == minutos_totais_f){
duracao = 24;
minuto = 0;
}
if (minutos_totais_i > minutos_totais_f){
minutos_duracao = minutos_totais_i - minutos_totais_f;
minutos_duracao = (24*60) - minutos_duracao;
duracao = minutos_duracao / 60;
minuto = minutos_duracao % 60;
}
printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n", duracao, minuto);
return 0;
}
|
the_stack_data/95450942.c | /**/
#include <stdio.h>
#include <string.h>
int main (void)
{
char str[21];
int i;
int count;
count = 0;
printf("Please enter a string > ");
fgets(str, 21-2, stdin);
for (i=0; i<21; i++){
if (str[i] == 'a')
count++;
if (str[i] == 'e')
count++;
if (str[i] == 'i')
count++;
if (str[i] == 'o')
count++;
if (str[i] == 'u')
count++;
if (str[i] == 'y')
count++;
}
printf("The number of syllables is %d.\n", count);
return 0;
}
|
the_stack_data/790676.c | #include <stdio.h>
int res = 0;
int main()
{
while (1 > 0)
{
printf("Masukan input:\n");
int _x;
scanf("%d", &_x);
if (_x != 0)
{
res = res + _x;
}
else
{
break;
}
}
printf("Total input: %d\n", res);
return 0;
} |
the_stack_data/243894005.c | // This file is part of CPAchecker,
// a tool for configurable software verification:
// https://cpachecker.sosy-lab.org
//
// SPDX-FileCopyrightText: 2007-2020 Dirk Beyer <https://www.sosy-lab.org>
//
// SPDX-License-Identifier: Apache-2.0
int L = 0;
void lock() {
if (L != 0) {
ERROR:
goto ERROR;
}
L++;
}
void unlock() {
if (L != 1) {
ERROR:
goto ERROR;
}
L--;
}
int main() {
int old, new;
int undet;
do {
lock();
old = new;
if (undet) {
unlock();
new++;
}
} while (new != old);
}
|
the_stack_data/76701385.c | /*Exercise 3 - Repetition
Write a C program to calculate the sum of the numbers from 1 to n.
Where n is a keyboard input.
e.g.
n -> 100
sum = 1+2+3+....+ 99+100 = 5050
n -> 1-
sum = 1+2+3+...+10 = 55 */
#include <stdio.h>
int main() {
int n, i, sum = 0;
printf("Input the number: ");
scanf("%d", &n);
if(n > 0){
for( i=1; i <= n; i++)
{
sum = sum + i;
}
printf("sum of the numbers 1 to n: %d",sum);
}
else{
printf("invalid input");
}
return 0;
}
|
the_stack_data/496955.c | // memory leak in nf_tables_addchain
// https://syzkaller.appspot.com/bug?id=c99868fde67014f7e9f5
// status:6
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
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 bool write_file(const char* file, const char* what, ...)
{
char buf[1024];
va_list args;
va_start(args, what);
vsnprintf(buf, sizeof(buf), what, args);
va_end(args);
buf[sizeof(buf) - 1] = 0;
int len = strlen(buf);
int fd = open(file, O_WRONLY | O_CLOEXEC);
if (fd == -1)
return false;
if (write(fd, buf, len) != len) {
int err = errno;
close(fd);
errno = err;
return false;
}
close(fd);
return true;
}
static void kill_and_wait(int pid, int* status)
{
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
int i;
for (i = 0; i < 100; i++) {
if (waitpid(-1, status, WNOHANG | __WALL) == pid)
return;
usleep(1000);
}
DIR* dir = opendir("/sys/fs/fuse/connections");
if (dir) {
for (;;) {
struct dirent* ent = readdir(dir);
if (!ent)
break;
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
continue;
char abort[300];
snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
ent->d_name);
int fd = open(abort, O_WRONLY);
if (fd == -1) {
continue;
}
if (write(fd, abort, 1) < 0) {
}
close(fd);
}
closedir(dir);
} else {
}
while (waitpid(-1, status, __WALL) != pid) {
}
}
static void setup_test()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
write_file("/proc/self/oom_score_adj", "1000");
}
#define KMEMLEAK_FILE "/sys/kernel/debug/kmemleak"
static void setup_leak()
{
if (!write_file(KMEMLEAK_FILE, "scan"))
exit(1);
sleep(5);
if (!write_file(KMEMLEAK_FILE, "scan"))
exit(1);
if (!write_file(KMEMLEAK_FILE, "clear"))
exit(1);
}
static void check_leaks(void)
{
int fd = open(KMEMLEAK_FILE, O_RDWR);
if (fd == -1)
exit(1);
uint64_t start = current_time_ms();
if (write(fd, "scan", 4) != 4)
exit(1);
sleep(1);
while (current_time_ms() - start < 4 * 1000)
sleep(1);
if (write(fd, "scan", 4) != 4)
exit(1);
static char buf[128 << 10];
ssize_t n = read(fd, buf, sizeof(buf) - 1);
if (n < 0)
exit(1);
int nleaks = 0;
if (n != 0) {
sleep(1);
if (write(fd, "scan", 4) != 4)
exit(1);
if (lseek(fd, 0, SEEK_SET) < 0)
exit(1);
n = read(fd, buf, sizeof(buf) - 1);
if (n < 0)
exit(1);
buf[n] = 0;
char* pos = buf;
char* end = buf + n;
while (pos < end) {
char* next = strstr(pos + 1, "unreferenced object");
if (!next)
next = end;
char prev = *next;
*next = 0;
fprintf(stderr, "BUG: memory leak\n%s\n", pos);
*next = prev;
pos = next;
nleaks++;
}
}
if (write(fd, "clear", 5) != 5)
exit(1);
close(fd);
if (nleaks)
exit(1);
}
static void execute_one(void);
#define WAIT_FLAGS __WALL
static void loop(void)
{
int iter;
for (iter = 0;; iter++) {
int pid = fork();
if (pid < 0)
exit(1);
if (pid == 0) {
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;
}
check_leaks();
}
}
uint64_t r[1] = {0xffffffffffffffff};
void execute_one(void)
{
intptr_t res = 0;
res = syscall(__NR_socket, 0x10ul, 3ul, 0xc);
if (res != -1)
r[0] = res;
*(uint64_t*)0x200000c0 = 0;
*(uint32_t*)0x200000c8 = 0;
*(uint64_t*)0x200000d0 = 0x20000080;
*(uint64_t*)0x20000080 = 0x20000100;
memcpy((void*)0x20000100,
"\x14\x00\x00\x00\x10\x00\x01\x00\x00\xf4\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x0a\x20\x00\x00\x00\x00\x0a\x03\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x0a\x00\x00\x00\x09\x00\x01\x00\x73\x79\x7a\x31\x00\x00\x00"
"\x00\x34\x00\x00\x00\x03\x0a\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00"
"\x0a\x00\x00\x00\x08\x00\x0b\x40\x00\x00\x00\x05\x09\x00\x01\x00\x73"
"\x79\x7a\x31\x00\x00",
90);
*(uint64_t*)0x20000088 = 0x7c;
*(uint64_t*)0x200000d8 = 1;
*(uint64_t*)0x200000e0 = 0;
*(uint64_t*)0x200000e8 = 0;
*(uint32_t*)0x200000f0 = 0;
syscall(__NR_sendmsg, r[0], 0x200000c0ul, 0ul);
}
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_leak();
loop();
return 0;
}
|
the_stack_data/17835.c | /*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD: src/crypto/telnet/libtelnet/kerberos5.c,v 1.1.1.1.8.2 2003/04/24 19:13:59 nectar Exp $
* $DragonFly: src/crypto/telnet/libtelnet/kerberos5.c,v 1.2 2003/06/17 04:24:37 dillon Exp $
*/
/*
* Copyright (C) 1990 by the Massachusetts Institute of Technology
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*/
#ifdef KRB5
#include <arpa/telnet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <ctype.h>
#include <pwd.h>
#define Authenticator k5_Authenticator
#include <krb5.h>
#undef Authenticator
#include "encrypt.h"
#include "auth.h"
#include "misc.h"
int forward_flags = 0; /* Flags get set in telnet/main.c on -f and -F */
/* These values need to be the same as those defined in telnet/main.c. */
/* Either define them in both places, or put in some common header file. */
#define OPTS_FORWARD_CREDS 0x00000002
#define OPTS_FORWARDABLE_CREDS 0x00000001
void kerberos5_forward (Authenticator *);
static unsigned char str_data[1024] = { IAC, SB, TELOPT_AUTHENTICATION, 0,
AUTHTYPE_KERBEROS_V5, };
#define KRB_AUTH 0 /* Authentication data follows */
#define KRB_REJECT 1 /* Rejected (reason might follow) */
#define KRB_ACCEPT 2 /* Accepted */
#define KRB_RESPONSE 3 /* Response for mutual auth. */
#define KRB_FORWARD 4 /* Forwarded credentials follow */
#define KRB_FORWARD_ACCEPT 5 /* Forwarded credentials accepted */
#define KRB_FORWARD_REJECT 6 /* Forwarded credentials rejected */
static krb5_data auth;
static krb5_ticket *ticket;
static krb5_context context;
static krb5_auth_context auth_context;
static int
Data(Authenticator *ap, int type, const char *d, int c)
{
unsigned char *p = str_data + 4;
const unsigned char *cd = d;
if (c == -1)
c = strlen(cd);
if (auth_debug_mode) {
printf("%s:%d: [%d] (%d)",
str_data[3] == TELQUAL_IS ? ">>>IS" : ">>>REPLY",
str_data[3],
type, c);
printd(d, c);
printf("\r\n");
}
*p++ = ap->type;
*p++ = ap->way;
*p++ = type;
while (c-- > 0) {
if ((*p++ = *cd++) == IAC)
*p++ = IAC;
}
*p++ = IAC;
*p++ = SE;
if (str_data[3] == TELQUAL_IS)
printsub('>', &str_data[2], p - &str_data[2]);
return(net_write(str_data, p - str_data));
}
int
kerberos5_init(Authenticator *ap __unused, int server)
{
krb5_error_code ret;
ret = krb5_init_context(&context);
if (ret)
return 0;
if (server) {
krb5_keytab kt;
krb5_kt_cursor cursor;
ret = krb5_kt_default(context, &kt);
if (ret)
return 0;
ret = krb5_kt_start_seq_get (context, kt, &cursor);
if (ret) {
krb5_kt_close (context, kt);
return 0;
}
krb5_kt_end_seq_get (context, kt, &cursor);
krb5_kt_close (context, kt);
str_data[3] = TELQUAL_REPLY;
} else
str_data[3] = TELQUAL_IS;
return(1);
}
extern int net;
static int
kerberos5_send(const char *name, Authenticator *ap)
{
krb5_error_code ret;
krb5_ccache ccache;
int ap_opts;
krb5_data cksum_data;
char foo[2];
if (!UserNameRequested) {
if (auth_debug_mode) {
printf("Kerberos V5: no user name supplied\r\n");
}
return(0);
}
ret = krb5_cc_default(context, &ccache);
if (ret) {
if (auth_debug_mode) {
printf("Kerberos V5: could not get default ccache: %s\r\n",
krb5_get_err_text (context, ret));
}
return 0;
}
if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL)
ap_opts = AP_OPTS_MUTUAL_REQUIRED;
else
ap_opts = 0;
ap_opts |= AP_OPTS_USE_SUBKEY;
ret = krb5_auth_con_init (context, &auth_context);
if (ret) {
if (auth_debug_mode) {
printf("Kerberos V5: krb5_auth_con_init failed (%s)\r\n",
krb5_get_err_text(context, ret));
}
return(0);
}
ret = krb5_auth_con_setaddrs_from_fd (context,
auth_context,
&net);
if (ret) {
if (auth_debug_mode) {
printf ("Kerberos V5:"
" krb5_auth_con_setaddrs_from_fd failed (%s)\r\n",
krb5_get_err_text(context, ret));
}
return(0);
}
krb5_auth_con_setkeytype (context, auth_context, KEYTYPE_DES);
foo[0] = ap->type;
foo[1] = ap->way;
cksum_data.length = sizeof(foo);
cksum_data.data = foo;
{
krb5_principal service;
char sname[128];
ret = krb5_sname_to_principal (context,
RemoteHostName,
NULL,
KRB5_NT_SRV_HST,
&service);
if(ret) {
if (auth_debug_mode) {
printf ("Kerberos V5:"
" krb5_sname_to_principal(%s) failed (%s)\r\n",
RemoteHostName, krb5_get_err_text(context, ret));
}
return 0;
}
ret = krb5_unparse_name_fixed(context, service, sname, sizeof(sname));
if(ret) {
if (auth_debug_mode) {
printf ("Kerberos V5:"
" krb5_unparse_name_fixed failed (%s)\r\n",
krb5_get_err_text(context, ret));
}
return 0;
}
printf("[ Trying %s (%s)... ]\r\n", name, sname);
ret = krb5_mk_req_exact(context, &auth_context, ap_opts,
service,
&cksum_data, ccache, &auth);
krb5_free_principal (context, service);
}
if (ret) {
if (1 || auth_debug_mode) {
printf("Kerberos V5: mk_req failed (%s)\r\n",
krb5_get_err_text(context, ret));
}
return(0);
}
if (!auth_sendname((unsigned char *)UserNameRequested,
strlen(UserNameRequested))) {
if (auth_debug_mode)
printf("Not enough room for user name\r\n");
return(0);
}
if (!Data(ap, KRB_AUTH, auth.data, auth.length)) {
if (auth_debug_mode)
printf("Not enough room for authentication data\r\n");
return(0);
}
if (auth_debug_mode) {
printf("Sent Kerberos V5 credentials to server\r\n");
}
return(1);
}
int
kerberos5_send_mutual(Authenticator *ap)
{
return kerberos5_send("mutual KERBEROS5", ap);
}
int
kerberos5_send_oneway(Authenticator *ap)
{
return kerberos5_send("KERBEROS5", ap);
}
void
kerberos5_is(Authenticator *ap, unsigned char *data, int cnt)
{
krb5_error_code ret;
krb5_data outbuf;
krb5_keyblock *key_block;
char *name;
krb5_principal server;
int zero = 0;
if (cnt-- < 1)
return;
switch (*data++) {
case KRB_AUTH:
auth.data = (char *)data;
auth.length = cnt;
auth_context = NULL;
ret = krb5_auth_con_init (context, &auth_context);
if (ret) {
Data(ap, KRB_REJECT, "krb5_auth_con_init failed", -1);
auth_finished(ap, AUTH_REJECT);
if (auth_debug_mode)
printf("Kerberos V5: krb5_auth_con_init failed (%s)\r\n",
krb5_get_err_text(context, ret));
return;
}
ret = krb5_auth_con_setaddrs_from_fd (context,
auth_context,
&zero);
if (ret) {
Data(ap, KRB_REJECT, "krb5_auth_con_setaddrs_from_fd failed", -1);
auth_finished(ap, AUTH_REJECT);
if (auth_debug_mode)
printf("Kerberos V5: "
"krb5_auth_con_setaddrs_from_fd failed (%s)\r\n",
krb5_get_err_text(context, ret));
return;
}
ret = krb5_sock_to_principal (context,
0,
"host",
KRB5_NT_SRV_HST,
&server);
if (ret) {
Data(ap, KRB_REJECT, "krb5_sock_to_principal failed", -1);
auth_finished(ap, AUTH_REJECT);
if (auth_debug_mode)
printf("Kerberos V5: "
"krb5_sock_to_principal failed (%s)\r\n",
krb5_get_err_text(context, ret));
return;
}
ret = krb5_rd_req(context,
&auth_context,
&auth,
server,
NULL,
NULL,
&ticket);
krb5_free_principal (context, server);
if (ret) {
char *errbuf;
asprintf(&errbuf,
"Read req failed: %s",
krb5_get_err_text(context, ret));
Data(ap, KRB_REJECT, errbuf, -1);
if (auth_debug_mode)
printf("%s\r\n", errbuf);
free (errbuf);
return;
}
{
char foo[2];
foo[0] = ap->type;
foo[1] = ap->way;
ret = krb5_verify_authenticator_checksum(context,
auth_context,
foo,
sizeof(foo));
if (ret) {
char *errbuf;
asprintf(&errbuf, "Bad checksum: %s",
krb5_get_err_text(context, ret));
Data(ap, KRB_REJECT, errbuf, -1);
if (auth_debug_mode)
printf ("%s\r\n", errbuf);
free(errbuf);
return;
}
}
ret = krb5_auth_con_getremotesubkey (context,
auth_context,
&key_block);
if (ret) {
Data(ap, KRB_REJECT, "krb5_auth_con_getremotesubkey failed", -1);
auth_finished(ap, AUTH_REJECT);
if (auth_debug_mode)
printf("Kerberos V5: "
"krb5_auth_con_getremotesubkey failed (%s)\r\n",
krb5_get_err_text(context, ret));
return;
}
if (key_block == NULL) {
ret = krb5_auth_con_getkey(context,
auth_context,
&key_block);
}
if (ret) {
Data(ap, KRB_REJECT, "krb5_auth_con_getkey failed", -1);
auth_finished(ap, AUTH_REJECT);
if (auth_debug_mode)
printf("Kerberos V5: "
"krb5_auth_con_getkey failed (%s)\r\n",
krb5_get_err_text(context, ret));
return;
}
if (key_block == NULL) {
Data(ap, KRB_REJECT, "no subkey received", -1);
auth_finished(ap, AUTH_REJECT);
if (auth_debug_mode)
printf("Kerberos V5: "
"krb5_auth_con_getremotesubkey returned NULL key\r\n");
return;
}
if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) {
ret = krb5_mk_rep(context, auth_context, &outbuf);
if (ret) {
Data(ap, KRB_REJECT,
"krb5_mk_rep failed", -1);
auth_finished(ap, AUTH_REJECT);
if (auth_debug_mode)
printf("Kerberos V5: "
"krb5_mk_rep failed (%s)\r\n",
krb5_get_err_text(context, ret));
return;
}
Data(ap, KRB_RESPONSE, outbuf.data, outbuf.length);
}
if (krb5_unparse_name(context, ticket->client, &name))
name = 0;
if(UserNameRequested && krb5_kuserok(context,
ticket->client,
UserNameRequested)) {
Data(ap, KRB_ACCEPT, name, name ? -1 : 0);
if (auth_debug_mode) {
printf("Kerberos5 identifies him as ``%s''\r\n",
name ? name : "");
}
if(key_block->keytype == ETYPE_DES_CBC_MD5 ||
key_block->keytype == ETYPE_DES_CBC_MD4 ||
key_block->keytype == ETYPE_DES_CBC_CRC) {
Session_Key skey;
skey.type = SK_DES;
skey.length = 8;
skey.data = key_block->keyvalue.data;
encrypt_session_key(&skey, 0);
}
} else {
char *msg;
asprintf (&msg, "user `%s' is not authorized to "
"login as `%s'",
name ? name : "<unknown>",
UserNameRequested ? UserNameRequested : "<nobody>");
if (msg == NULL)
Data(ap, KRB_REJECT, NULL, 0);
else {
Data(ap, KRB_REJECT, (void *)msg, -1);
free(msg);
}
auth_finished (ap, AUTH_REJECT);
krb5_free_keyblock_contents(context, key_block);
break;
}
auth_finished(ap, AUTH_USER);
krb5_free_keyblock_contents(context, key_block);
break;
case KRB_FORWARD: {
struct passwd *pwd;
char ccname[1024]; /* XXX */
krb5_data inbuf;
krb5_ccache ccache;
inbuf.data = (char *)data;
inbuf.length = cnt;
pwd = getpwnam (UserNameRequested);
if (pwd == NULL)
break;
snprintf (ccname, sizeof(ccname),
"FILE:/tmp/krb5cc_%u", pwd->pw_uid);
ret = krb5_cc_resolve (context, ccname, &ccache);
if (ret) {
if (auth_debug_mode)
printf ("Kerberos V5: could not get ccache: %s\r\n",
krb5_get_err_text(context, ret));
break;
}
ret = krb5_cc_initialize (context,
ccache,
ticket->client);
if (ret) {
if (auth_debug_mode)
printf ("Kerberos V5: could not init ccache: %s\r\n",
krb5_get_err_text(context, ret));
break;
}
#if defined(DCE)
esetenv("KRB5CCNAME", ccname, 1);
#endif
ret = krb5_rd_cred2 (context,
auth_context,
ccache,
&inbuf);
if(ret) {
char *errbuf;
asprintf (&errbuf,
"Read forwarded creds failed: %s",
krb5_get_err_text (context, ret));
if(errbuf == NULL)
Data(ap, KRB_FORWARD_REJECT, NULL, 0);
else
Data(ap, KRB_FORWARD_REJECT, errbuf, -1);
if (auth_debug_mode)
printf("Could not read forwarded credentials: %s\r\n",
errbuf);
free (errbuf);
} else {
Data(ap, KRB_FORWARD_ACCEPT, 0, 0);
#if defined(DCE)
dfsfwd = 1;
#endif
}
chown (ccname + 5, pwd->pw_uid, -1);
if (auth_debug_mode)
printf("Forwarded credentials obtained\r\n");
break;
}
default:
if (auth_debug_mode)
printf("Unknown Kerberos option %d\r\n", data[-1]);
Data(ap, KRB_REJECT, 0, 0);
break;
}
}
void
kerberos5_reply(Authenticator *ap, unsigned char *data, int cnt)
{
static int mutual_complete = 0;
if (cnt-- < 1)
return;
switch (*data++) {
case KRB_REJECT:
if (cnt > 0) {
printf("[ Kerberos V5 refuses authentication because %.*s ]\r\n",
cnt, data);
} else
printf("[ Kerberos V5 refuses authentication ]\r\n");
auth_send_retry();
return;
case KRB_ACCEPT: {
krb5_error_code ret;
Session_Key skey;
krb5_keyblock *keyblock;
if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL &&
!mutual_complete) {
printf("[ Kerberos V5 accepted you, but didn't provide mutual authentication! ]\r\n");
auth_send_retry();
return;
}
if (cnt)
printf("[ Kerberos V5 accepts you as ``%.*s'' ]\r\n", cnt, data);
else
printf("[ Kerberos V5 accepts you ]\r\n");
ret = krb5_auth_con_getlocalsubkey (context,
auth_context,
&keyblock);
if (ret)
ret = krb5_auth_con_getkey (context,
auth_context,
&keyblock);
if(ret) {
printf("[ krb5_auth_con_getkey: %s ]\r\n",
krb5_get_err_text(context, ret));
auth_send_retry();
return;
}
skey.type = SK_DES;
skey.length = 8;
skey.data = keyblock->keyvalue.data;
encrypt_session_key(&skey, 0);
krb5_free_keyblock_contents (context, keyblock);
auth_finished(ap, AUTH_USER);
if (forward_flags & OPTS_FORWARD_CREDS)
kerberos5_forward(ap);
break;
}
case KRB_RESPONSE:
if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) {
/* the rest of the reply should contain a krb_ap_rep */
krb5_ap_rep_enc_part *reply;
krb5_data inbuf;
krb5_error_code ret;
inbuf.length = cnt;
inbuf.data = (char *)data;
ret = krb5_rd_rep(context, auth_context, &inbuf, &reply);
if (ret) {
printf("[ Mutual authentication failed: %s ]\r\n",
krb5_get_err_text (context, ret));
auth_send_retry();
return;
}
krb5_free_ap_rep_enc_part(context, reply);
mutual_complete = 1;
}
return;
case KRB_FORWARD_ACCEPT:
printf("[ Kerberos V5 accepted forwarded credentials ]\r\n");
return;
case KRB_FORWARD_REJECT:
printf("[ Kerberos V5 refuses forwarded credentials because %.*s ]\r\n",
cnt, data);
return;
default:
if (auth_debug_mode)
printf("Unknown Kerberos option %d\r\n", data[-1]);
return;
}
}
int
kerberos5_status(Authenticator *ap __unused, char *name, int level)
{
if (level < AUTH_USER)
return(level);
if (UserNameRequested &&
krb5_kuserok(context,
ticket->client,
UserNameRequested))
{
strcpy(name, UserNameRequested);
return(AUTH_VALID);
} else
return(AUTH_USER);
}
#define BUMP(buf, len) while (*(buf)) {++(buf), --(len);}
#define ADDC(buf, len, c) if ((len) > 0) {*(buf)++ = (c); --(len);}
void
kerberos5_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
{
int i;
buf[buflen-1] = '\0'; /* make sure its NULL terminated */
buflen -= 1;
switch(data[3]) {
case KRB_REJECT: /* Rejected (reason might follow) */
strlcpy((char *)buf, " REJECT ", buflen);
goto common;
case KRB_ACCEPT: /* Accepted (name might follow) */
strlcpy((char *)buf, " ACCEPT ", buflen);
common:
BUMP(buf, buflen);
if (cnt <= 4)
break;
ADDC(buf, buflen, '"');
for (i = 4; i < cnt; i++)
ADDC(buf, buflen, data[i]);
ADDC(buf, buflen, '"');
ADDC(buf, buflen, '\0');
break;
case KRB_AUTH: /* Authentication data follows */
strlcpy((char *)buf, " AUTH", buflen);
goto common2;
case KRB_RESPONSE:
strlcpy((char *)buf, " RESPONSE", buflen);
goto common2;
case KRB_FORWARD: /* Forwarded credentials follow */
strlcpy((char *)buf, " FORWARD", buflen);
goto common2;
case KRB_FORWARD_ACCEPT: /* Forwarded credentials accepted */
strlcpy((char *)buf, " FORWARD_ACCEPT", buflen);
goto common2;
case KRB_FORWARD_REJECT: /* Forwarded credentials rejected */
/* (reason might follow) */
strlcpy((char *)buf, " FORWARD_REJECT", buflen);
goto common2;
default:
snprintf(buf, buflen, " %d (unknown)", data[3]);
common2:
BUMP(buf, buflen);
for (i = 4; i < cnt; i++) {
snprintf(buf, buflen, " %d", data[i]);
BUMP(buf, buflen);
}
break;
}
}
void
kerberos5_forward(Authenticator *ap)
{
krb5_error_code ret;
krb5_ccache ccache;
krb5_creds creds;
krb5_kdc_flags flags;
krb5_data out_data;
krb5_principal principal;
ret = krb5_cc_default (context, &ccache);
if (ret) {
if (auth_debug_mode)
printf ("KerberosV5: could not get default ccache: %s\r\n",
krb5_get_err_text (context, ret));
return;
}
ret = krb5_cc_get_principal (context, ccache, &principal);
if (ret) {
if (auth_debug_mode)
printf ("KerberosV5: could not get principal: %s\r\n",
krb5_get_err_text (context, ret));
return;
}
memset (&creds, 0, sizeof(creds));
creds.client = principal;
ret = krb5_build_principal (context,
&creds.server,
strlen(principal->realm),
principal->realm,
"krbtgt",
principal->realm,
NULL);
if (ret) {
if (auth_debug_mode)
printf ("KerberosV5: could not get principal: %s\r\n",
krb5_get_err_text (context, ret));
return;
}
creds.times.endtime = 0;
flags.i = 0;
flags.b.forwarded = 1;
if (forward_flags & OPTS_FORWARDABLE_CREDS)
flags.b.forwardable = 1;
ret = krb5_get_forwarded_creds (context,
auth_context,
ccache,
flags.i,
RemoteHostName,
&creds,
&out_data);
if (ret) {
if (auth_debug_mode)
printf ("Kerberos V5: error getting forwarded creds: %s\r\n",
krb5_get_err_text (context, ret));
return;
}
if(!Data(ap, KRB_FORWARD, out_data.data, out_data.length)) {
if (auth_debug_mode)
printf("Not enough room for authentication data\r\n");
} else {
if (auth_debug_mode)
printf("Forwarded local Kerberos V5 credentials to server\r\n");
}
}
#if defined(DCE)
/* if this was a K5 authentication try and join a PAG for the user. */
void
kerberos5_dfspag(void)
{
if (dfsk5ok) {
dfspag = krb5_dfs_pag(context, dfsfwd, ticket->client,
UserNameRequested);
}
}
#endif
#endif /* KRB5 */
|
the_stack_data/151308.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pgurn <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/08/22 17:45:16 by pgurn #+# #+# */
/* Updated: 2020/08/22 18:31:43 by pgurn ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
char *ft_strncpy(char *dest, char *src, unsigned int n)
{
unsigned int i;
i = 0;
while (src != '\0' && (i < n))
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (dest);
}
int main(void)
{
return (0);
}
|
the_stack_data/1027324.c |
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main()
{
setlocale(LC_ALL, "portuguese");
int vetor[25], i, n = 10;
vetor[0] = 1;
vetor[1] = 6;
for (i = 2; i < 25; i++){
vetor[i] = vetor[i - 1] + n;
n = n * 2;
}
for (i = 0; i < 25; i++){
printf("%d ", vetor[i]);
}
getchar();
return 0;
}
|
the_stack_data/2965.c | // Tests for 3C.
//
// RUN: rm -rf %t*
// RUN: 3c -base-dir=%S -addcr %s -- | FileCheck -match-full-lines %s
// RUN: 3c -base-dir=%S -addcr %s -- | %clang -c -Xclang -verify -fcheckedc-extension -x c -o /dev/null -
// RUN: 3c -base-dir=%S -addcr -output-dir=%t.checked %s --
// RUN: 3c -base-dir=%t.checked -addcr %t.checked/boundary_tests.c -- | diff %t.checked/boundary_tests.c -
// expected-no-diagnostics
void do_something(int *a, int b) { *a = b; }
//CHECK: void do_something(_Ptr<int> a, int b) _Checked { *a = b; }
void mut(int *a, int b);
//CHECK: void mut(_Ptr<int> a, int b);
void mut(int *a, int b) { *a += b; }
//CHECK: void mut(_Ptr<int> a, int b) _Checked { *a += b; }
void bad_ctx(void) {
int *x = (int *)0x8001000;
mut(x, 1);
}
void good_ctx(void) {
int u = 0;
mut(&u, 1);
}
|
the_stack_data/192331539.c | #include <stdio.h> /* sprintf() */
#include <sys/types.h> /* open() */
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h> /* exit() */
#include <sys/ioctl.h> /* ioctl() */
#include <linux/i2c-dev.h>
#include <unistd.h> /* read() / write() */
#include <errno.h>
#include <math.h> /* pow() */
#define I2C_DEV "/dev/i2c-3"
#define DEV_ADDR 0x68
static const unsigned char BIT_RDY = 7; //data ready
static const unsigned char BIT_C1 = 6; //channel select
static const unsigned char BIT_C0 = 5; //channel select
static const unsigned char BIT_OC = 4; //conversion mode (one shot/continuous)
static const unsigned char BIT_S1 = 3; //sample rate
static const unsigned char BIT_S0 = 2; //sample rate
static const unsigned char BIT_G1 = 1; //gain
static const unsigned char BIT_G0 = 0; //gain
int fd;
/* issue a general call reset to the device */
void dev_reset() {
int result;
unsigned char buf[10];
buf[0] = 0x00;
buf[1] = 0x06;
result = write( fd, buf, 2);
if ( result != 2 ) {
/* ERROR HANDLING: i2c transaction failed */
perror("(reset) Failed to write to the i2c bus");
}
}
int main() {
int result;
int channel;
int gain;
double filter;
int filter_init;
unsigned char reg;
double v;
unsigned char buf[10];
double psi, pa, alt_m;
fd = open( I2C_DEV, O_RDWR );
if ( fd < 0 ) {
perror(I2C_DEV);
exit(1);
}
result = ioctl( fd, I2C_SLAVE, DEV_ADDR );
if ( result < 0 ) {
perror("Failed to acquire bus access and/or talk to slave");
exit(1);
}
dev_reset();
filter = 0.0;
filter_init = 0;
while ( 1 ) {
for ( gain = 0; gain < 1; gain++ ) {
for ( channel = 0; channel < 1; channel++ ) {
/* compute register command */
reg = 1 << BIT_RDY |
channel << BIT_C0 |
1 << BIT_OC |
1 << BIT_S1 |
gain;
/* write command register */
buf[0] = reg;
result = write( fd, buf, 1);
if ( result != 1 ) {
/* ERROR HANDLING: i2c transaction failed */
perror("Failed to write to the i2c bus");
dev_reset();
sleep(1);
}
usleep(4000);
/* read response */
result = read( fd, buf, 3);
if ( result != 3 ) {
perror("Failed to read from the i2c bus");
}
/* display result */
result = buf[0] << 8 | buf[1];
if ( result >= 32768) {
result = 65536 - result;
}
v = (double)result * 2.048 / 32768.0;
if ( filter_init ) {
filter = 0.999 * filter + 0.001 * v;
} else {
filter = v;
filter_init = 1;
}
pa = 97482 * v / 0.5031;
psi = pa / 6894.75729;
alt_m = 44330.8 - 4946.54 * pow(pa, 0.1902632);
printf("reg: %0x ch: %d gain: %d %0X %0X %0X %.4fv (%d) %.0f %.4f\n", reg, channel, gain, buf[0], buf[1], buf[2], v, result, pa, alt_m );
//printf("ch: %d gain: %d volt = %.4f\n", channel, gain, v);
usleep(90000);
}
}
}
}
|
the_stack_data/75137221.c | #include <stdio.h>
#include <string.h>
int main(void)
{
char input[1000] = ""; // 입력을 받을 문자열
char src[100]; // 비교할 문자열
char words[10][100]; // 저장할 문자열
char* pos = input; // 루프에서 사용할 문자열
int count = 0, j = 0, i, srccnt = 0; // 각각 단어 개수, 루프에서 사용할 두 변수, 마지막으로 비교하는 문자열의 검출된 개수를 저장하는 변수이다.
scanf("%[^\n]", input); // 입력을 받는다.
getchar();
scanf("%[^\n]", src); // 비교할 문자열을 입력받는다.
getchar();
while (1) // 루프
{
while (*pos >= 'a' && *pos <= 'z' || *pos >= 'A' && *pos <= 'Z') // 알파벳이 나온 경우
words[count][j++] = *(pos++); // 단어를 만든다.
if (j != 0) // 공백등의 다른 문자가 섞이는 것을 방지
{
words[count++][j] = '\0'; // 널을 집어넣어 문자열로 만든다.
j = 0; // 철자 개수 초기화
}
if (*pos == '\0') // 끝 부분에 온 경우 루프 탈출
break;
else // 그렇지 않은 경우 포인터 연산으로 다음 문자로..
pos++;
}
for (i = 0; i < count; i++) // 비교하는 루프
if (strcmp(words[i], src) == 0) // 완전히 일치하는 문자열이 나온 경우. strcmp는 철자 개수까지 완전히 일치해야 0을 반환하므로 (일치) 다른 단어 내에 있는 경우도 제외할 수 있다.
srccnt++; // 개수 증가
printf("%d\n", srccnt); // 찾은 개수 출력
return 0;
} |
the_stack_data/32220.c | /*
* exercise_02_02.c
*
* Author: Henrik Samuelsson, henrik.samuelsson(at)gmail.com
*/
#include <stdio.h>
int main (void)
{
printf ("In C, lowercase letters are significant.\n");
printf ("main() is where program execution begins.\n");
printf ("Opening and closing braces enclose program statements in a routine.\n");
printf ("All program statements must be terminated by a semicolon.\n");
return 0;
}
|
the_stack_data/15566.c | //
// main.c
// Multiple of 13
//
// Created by MacBook on 31/03/17.
// Copyright © 2017 Bruno Botelho. All rights reserved.
//
#include <stdio.h>
int main(int argc, const char * argv[]) {
// insert code here...
int sum=0,x,y,maior,menor;
scanf("%d%d",&x,&y);
maior=x>y?x:y;
menor=x>y?y:x;
for(int i=menor;i<=maior;i++){
sum+=(i%13!=0)?i:0;
}
printf("%d\n",sum);
return 0;
}
|
the_stack_data/231394003.c | // waz.cpp : Defines the entry point for the console application.
///*
/*
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <Windows.h>
#include <stdlib.h>
using namespace std;
bool gameover;
const int width = 20;
const int height = 20;
int x, y, fruitX, fruitY, score, dir1, ntail;
int tailX[100], tailY[100];
enum eDirection { STOP = 0, RIGHT, LEFT, UP, DOWN };
eDirection dir;
void setup()
{
gameover = false;
dir = STOP;
x = width / 2;
y = height / 2;
fruitX = rand() % width;
fruitY = rand() % height;
score = 0;
}
void draw()
{
system("cls");
for (int i = 0; i < width + 2; i++)
{
cout << "#";
}
cout << endl;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
if (j == 0)
cout << "#";
if (i == y&&j == x)
{
cout << "O";
}
else if (i == fruitY&&j == fruitX)
cout << "F";
else
{
bool print = false;
for (int k = 0; k < ntail; k++)
{
if (tailX[k] == j &&tailY[k] == i)
{
cout << "o";
print = true;
}
}
if (!print)
cout << " ";
}
if (j == width - 1)
cout << "#";
}
cout << endl;
}
for (int i = 0; i < width + 2; i++)
{
cout << "#";
}
cout << endl;
cout << "SCORE:" << score << endl;
}
void input()
{
if (_kbhit())
{
switch (_getch())
{
case 'a':
dir = LEFT;
break;
case 'd':
dir = RIGHT;
break;
case 'w':
dir = UP;
break;
case 's':
dir = DOWN;
break;
case 'x':
gameover = true;
break;
}
}
}
void logic()
{
int prevX = tailX[0];
int prevY = tailY[0];
int prev2X, prev2Y;
tailX[0] = x;
tailY[0] = y;
for (int i = 1; i < ntail; i++)
{
prev2X = tailX[i];
prev2Y = tailY[i];
tailX[i] = prevX;
tailY[i] = prevY;
prevX = prev2X;
prevY = prev2Y;
}
switch (dir)
{
case LEFT:
x--;
break;
case RIGHT:
x++;
break;
case UP:
y--;
break;
case DOWN:
y++;
default:
break;
}
if (x > width || x<0 || y>height || y < 0)
gameover = true;
for (int i = 0; i < ntail; i++)
{
if (tailX[i] == x&&tailY[i] == y)
gameover = true;
}
if (x == fruitX && y == fruitY)
{
score = +10;
fruitX = rand() % width;
fruitY = rand() % height;
ntail++;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
setup();
while (gameover != true)
{
draw();
input();
logic();
Sleep(30);
}
return 0;
}
*/
|
the_stack_data/37639035.c |
/**
* C program to create and traverse a Linked List
*/
#include <stdio.h>
#include <stdlib.h>
/* Structure of a node */
struct node {
int data; // Data
struct node *next; // Address
}*head;
/*
* Functions to create and display list
*/
void createList(int n);
void traverseList();
int main()
{
int n;
printf("Enter the total number of nodes: ");
scanf("%d", &n);
createList(n);
printf("\nData in the list \n");
traverseList();
return 0;
}
/*
* Create a list of n nodes
*/
void createList(int n)
{
struct node *newNode, *temp;
int data, i;
head = (struct node *)malloc(sizeof(struct node));
// Terminate if memory not allocated
if(head == NULL)
{
printf("Unable to allocate memory.");
exit(0);
}
// Input data of node from the user
printf("Enter the data of node 1: ");
scanf("%d", &data);
head->data = data; // Link data field with data
head->next = NULL; // Link address field to NULL
// Create n - 1 nodes and add to list
temp = head;
for(i=2; i<=n; i++)
{
newNode = (struct node *)malloc(sizeof(struct node));
/* If memory is not allocated for newNode */
if(newNode == NULL)
{
printf("Unable to allocate memory.");
break;
}
printf("Enter the data of node %d: ", i);
scanf("%d", &data);
newNode->data = data; // Link data field of newNode
newNode->next = NULL; // Make sure new node points to NULL
temp->next = newNode; // Link previous node with newNode
temp = temp->next; // Make current node as previous node
}
}
/*
* Display entire list
*/
void traverseList()
{
struct node *temp;
// Return if list is empty
if(head == NULL)
{
printf("List is empty.");
return;
}
temp = head;
while(temp != NULL)
{
printf("Data = %d\n", temp->data); // Print data of current node
temp = temp->next; // Move to next node
}
} |
the_stack_data/124555.c | #include <string.h>
#include <stdio.h>
#include <unistd.h>
void p(char *param_1, char *dash)
{
char *str;
char bigBuffer[4104];
puts(dash);
read(stdin, bigBuffer, 4096);
str = strchr(bigBuffer, 10); //10 is ASCII for '\n'
*str = '\0';
strncpy(param_1, bigBuffer, 20);
return;
}
void pp(char *buffer)
{
char smallBufferOne[20];
char smallBufferTwo[20];
int len;
p(smallBufferOne," - ");
p(smallBufferTwo," - ");
strcpy(buffer, smallBufferOne);
len = strlen(buffer);
buffer[len] = ' ';
strcat(buffer,smallBufferTwo);
return;
}
int main(void)
{
char buffer[54];
pp(buffer);
puts(buffer);
return 0;
} |
the_stack_data/103213.c | /**
******************************************************************************
* @file stm32f3xx_ll_hrtim.c
* @author MCD Application Team
* @brief HRTIM LL module driver.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2016 STMicroelectronics.
* All rights reserved.</center></h2>
*
* 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(USE_FULL_LL_DRIVER)
/* Includes ------------------------------------------------------------------*/
#include "stm32f3xx_ll_hrtim.h"
#include "stm32f3xx_ll_bus.h"
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif
/** @addtogroup STM32F3xx_LL_Driver
* @{
*/
#if defined (HRTIM1)
/** @addtogroup HRTIM_LL
* @{
*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup HRTIM_LL_Exported_Functions
* @{
*/
/**
* @brief Set HRTIM instance registers to their reset values.
* @param HRTIMx High Resolution Timer instance
* @retval ErrorStatus enumeration value:
* - SUCCESS: HRTIMx registers are de-initialized
* - ERROR: invalid HRTIMx instance
*/
ErrorStatus LL_HRTIM_DeInit(HRTIM_TypeDef *HRTIMx)
{
ErrorStatus result = SUCCESS;
/* Check the parameters */
assert_param(IS_HRTIM_ALL_INSTANCE(HRTIMx));
LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_HRTIM1);
LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_HRTIM1);
return result;
}
/**
* @}
*/
/**
* @}
*/
#endif /* HRTIM1 */
/**
* @}
*/
#endif /* USE_FULL_LL_DRIVER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
the_stack_data/162642555.c | #include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <sys/wait.h>
int main(int argc, char **argv)
{
pid_t pid;
pid = fork();
if (pid > 0)
{
printf("\nPROCESO PADRE %d\n", getpid());
wait(NULL);
}
else
{
printf("\nPROCESO HIJO %d\n", getpid());
printf("\nLlamada a PS usando SYSTEM\n");
system("ps -l");
printf("\nLlamada a PS usando EXECLP\n");
execlp("ps","ps", "-l", NULL);
}
printf("\n");
exit(0);
} |
the_stack_data/73575475.c | struct test {
int a;
int b[3];
char c;
};
int func(struct test t) {
int sum = 0;
sum += t.a;
sum += t.b[0];
sum += t.b[1];
sum += t.b[2];
// sum += t.c;
t.a = 0;
t.b[0] = 0;
t.b[1] = 0;
t.b[2] = 0;
t.c = 0;
return sum;
}
int main() {
struct test t = { 1, { 4, 8, 16 }, 2 };
int ret = func(t);
return ret; // + t.a + t.b[0] + t.b[1] + t.b[2] + t.c;
}
/* struct test {
int a;
int b[3];
char c;
};
int func(struct test t) {
int sum = 0;
sum += t.a;
sum += t.b[0];
sum += t.b[1];
sum += t.b[2];
sum += t.c;
t.a = 0;
t.b[0] = 0;
t.b[1] = 0;
t.b[2] = 0;
t.c = 0;
return sum;
}
int main() {
struct test t = {1, {4, 8, 16}, 2};
int ret = func(t) + func(t);
return ret + t.a + t.b[0] + t.b[1] + t.b[2] + t.c;
}
* */
|
the_stack_data/64199328.c | #include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <linux/can.h>
#include <linux/can/raw.h>
int main()
{
struct ifreq ifr; /* CAN interface info struct */
struct sockaddr_can addr; /* CAN adddress info struct */
struct can_frame frame; /* CAN frame struct */
struct can_filter rfilter[2]; /* CAN reception filter */
int s; /* SocketCAN handle */
memset(&ifr, 0, sizeof(ifr));
memset(&addr, 0, sizeof(addr));
memset(&frame, 0, sizeof(frame));
// TODO: Open a socket here
/* Convert interface string "can0" to index */
strcpy(ifr.ifr_name, "can0");
ioctl(s, SIOCGIFINDEX, &ifr);
/* Setup address for binding */
addr.can_ifindex = ifr.ifr_ifindex;
addr.can_family = AF_CAN;
// TODO: Set the reception filter on this RAW socket
// TODO: Bind socket to can0 interface
while(1)
{
// TODO: Read received frame and print on console
}
close(s);
return 0;
}
|
the_stack_data/232955133.c | #include <stdio.h>
#include <stdlib.h>
#define A 2
#define B 4
typedef int object_t;
typedef int key_t;
typedef struct tr_n_t {
int degree;
int height;
key_t key[B];
struct tr_n_t* next[B];
/* possibly other information */
} tree_node_t;
// _____________________________________________________________________________
#define BLOCKSIZE 256
tree_node_t* currentblock = NULL;
int size_left;
tree_node_t* free_list = NULL;
tree_node_t*
get_node()
{
tree_node_t* tmp;
if ( free_list != NULL ) {
tmp = free_list;
free_list = free_list->next[0];
} else {
if ( currentblock == NULL || size_left == 0) {
currentblock = (tree_node_t*) malloc( BLOCKSIZE * sizeof(tree_node_t) );
size_left = BLOCKSIZE;
}
tmp = currentblock++;
size_left -= 1;
}
return ( tmp );
}
void
return_node(tree_node_t* node)
{
node->next[0] = free_list;
free_list = node;
}
tree_node_t*
create_tree()
{
tree_node_t* tmp;
tmp = get_node();
tmp->height = 0;
tmp->degree = 0;
return ( tmp );
}
void
list_node(tree_node_t* tree)
{
int i;
if (tree->height == 0 ) {
printf("leaf, degree %d, keys", tree->degree);
for (i = 0; i < tree->degree; i++)
{ printf(" %d", tree->key[i]); }
printf(" end ");
} else {
printf("node height %d, degree %d, keys", tree->height, tree->degree);
for (i = 1; i < tree->degree; i++)
{ printf(" %d", tree->key[i]); }
printf(" end ");
}
}
object_t*
find(tree_node_t* tree, key_t query_key)
{
tree_node_t* current_node;
object_t* object;
current_node = tree;
while ( current_node->height >= 0 ) {
int lower, upper; /* binary search among keys */
lower = 0;
upper = current_node->degree;
while ( upper > lower + 1 ) {
if ( query_key < current_node->key[ (upper + lower) / 2 ] )
{ upper = (upper + lower) / 2; }
else
{ lower = (upper + lower) / 2; }
}
if ( current_node->height > 0)
{ current_node = current_node->next[lower]; }
else {
/* block of height 0, contains the object pointers */
if ( current_node->key[lower] == query_key )
{ object = (object_t*) current_node->next[lower]; }
else
{ object = NULL; }
return ( object );
}
}
}
int
insert(tree_node_t* tree, key_t new_key, object_t* new_object)
{
tree_node_t* current_node, *insert_pt;
tree_node_t* node_stack[20];
int stack_p = 0;
key_t insert_key;
int finished;
current_node = tree;
if ( tree->height == 0 && tree->degree == 0) {
tree->key[0] = new_key;
tree->next[0] = (tree_node_t*) new_object;
tree->degree = 1;
return (0); /*insert in empty tree */
}
while ( current_node->height > 0 ) { /* not at leaf level */
int lower, upper; /* binary search among keys */
node_stack[stack_p++] = current_node ;
lower = 0;
upper = current_node->degree;
while ( upper > lower + 1 ) {
if ( new_key < current_node->key[ (upper + lower) / 2 ] )
{ upper = (upper + lower) / 2; }
else
{ lower = (upper + lower) / 2; }
}
current_node = current_node->next[lower];
} /* now current_node is leaf node in which we insert */
insert_pt = (tree_node_t*) new_object;
insert_key = new_key;
finished = 0;
while ( !finished ) {
int i, start;
if ( current_node->height > 0)
{ start = 1; } /* insertion in non-leaf starts at 1*/
else
{ start = 0; } /* insertion in non-leaf starts at 0*/
if ( current_node->degree < B ) { /* node still has room */
/* move everything up to create the insertion gap */
i = current_node->degree;
while ( (i > start) && ( current_node->key[i - 1] > insert_key)) {
current_node->key[i] = current_node->key[i - 1];
current_node->next[i] = current_node->next[i - 1];
i -= 1;
}
current_node->key[i] = insert_key;
current_node->next[i] = insert_pt;
current_node->degree += 1;
finished = 1;
} /* end insert in non-full node */
else { /* node is full, have to split the node*/
tree_node_t* new_node;
int j, insert_done = 0;
new_node = get_node();
i = B - 1;
j = (B - 1) / 2;
while (j >= 0) { /* copy upper half to new node */
if ( insert_done || insert_key < current_node->key[i] ) {
new_node->next[j] = current_node->next[i];
new_node->key[j--] = current_node->key[i--];
} else {
new_node->next[j] = insert_pt;
new_node->key[j--] = insert_key;
insert_done = 1;
}
} /* upper half done, insert in lower half, if necessary*/
while ( !insert_done) {
if ( insert_key < current_node->key[i] && i >= start ) {
current_node->next[i + 1] = current_node->next[i];
current_node->key[i + 1] = current_node->key[i];
i -= 1;
} else {
current_node->next[i + 1] = insert_pt;
current_node->key[i + 1] = insert_key;
insert_done = 1;
}
} /*finished insertion */
current_node->degree = B + 1 - ((B + 1) / 2);
new_node->degree = (B + 1) / 2;
new_node->height = current_node->height;
/* split nodes complete, now insert the new node above */
insert_pt = new_node;
insert_key = new_node->key[0];
if ( stack_p > 0 ) { /* not at root; move one level up */
current_node = node_stack[ --stack_p ];
} else { /* splitting root: needs copy to keep root address*/
new_node = get_node();
for ( i = 0; i < current_node->degree; i++ ) {
new_node->next[i] = current_node->next[i];
new_node->key[i] = current_node->key[i];
}
new_node->height = current_node->height;
new_node->degree = current_node->degree;
current_node->height += 1;
current_node->degree = 2;
current_node->next[0] = new_node;
current_node->next[1] = insert_pt;
current_node->key[1] = insert_key;
finished = 1;
} /* end splitting root */
} /* end node splitting */
} /* end of rebalancing */
return ( 0 );
}
object_t*
delete (tree_node_t* tree, key_t delete_key)
{
tree_node_t* current, *tmp_node;
tree_node_t* node_stack[20];
int index_stack[20];
int finished, i, j, stack_p = 0;
current = tree;
while ( current->height > 0 ) { /* not at leaf level */
int lower, upper; /* binary search among keys */
lower = 0;
upper = current->degree;
while ( upper > lower + 1 ) {
if ( delete_key < current->key[ (upper + lower) / 2 ] )
{ upper = (upper + lower) / 2; }
else
{ lower = (upper + lower) / 2; }
}
index_stack[stack_p] = lower ;
node_stack[stack_p++] = current ;
current = current->next[lower];
} /* now current is leaf node from which we delete */
for ( i = 0; i < current->degree ; i++ )
if ( current->key[i] == delete_key )
{ break; }
if ( i == current->degree ) {
return ( NULL ); /* delete failed; key does not exist */
} else { /* key exists, now delete from leaf node */
object_t* del_object;
del_object = (object_t*) current->next[i];
current->degree -= 1;
while ( i < current->degree ) {
current->next[i] = current->next[i + 1];
current->key[i] = current->key[i + 1];
i += 1;
} /* deleted from node, now rebalance */
finished = 0;
while ( ! finished ) {
if (current->degree >= A ) {
finished = 1; /* node still full enough, can stop */
} else { /* node became underful */
if ( stack_p == 0 ) { /* current is root */
if (current->degree >= 2 )
{ finished = 1; } /* root still necessary */
else if ( current->height == 0 )
{ finished = 1; } /* deleting last keys from root */
else { /* delete root, copy to keep address */
tmp_node = current->next[0];
for ( i = 0; i < tmp_node->degree; i++ ) {
current->next[i] = tmp_node->next[i];
current->key[i] = tmp_node->key[i];
}
current->degree = tmp_node->degree;
current->height = tmp_node->height;
return_node( tmp_node );
finished = 1;
}
} /* done with root */
else { /* delete from non-root node */
tree_node_t* upper, *neighbor;
int curr;
upper = node_stack[ --stack_p ];
curr = index_stack[stack_p];
if ( curr < upper->degree - 1 ) { /* not last*/
neighbor = upper->next[curr + 1];
if ( neighbor->degree > A ) {
/* sharing possible */
i = current->degree;
if ( current->height > 0 )
{ current->key[i] = upper->key[curr + 1]; }
else { /* on leaf level, take leaf key */
current->key[i] = neighbor->key[0];
neighbor->key[0] = neighbor->key[1];
}
current->next[i] = neighbor->next[0];
upper->key[curr + 1] = neighbor->key[1];
neighbor->next[0] = neighbor->next[1];
for ( j = 2; j < neighbor->degree; j++) {
neighbor->next[j - 1] = neighbor->next[j];
neighbor->key[j - 1] = neighbor->key[j];
}
neighbor->degree -= 1;
current->degree += 1;
finished = 1;
} /* sharing complete */
else { /* must join */
i = current->degree;
if ( current->height > 0 )
{ current->key[i] = upper->key[curr + 1]; }
else /* on leaf level, take leaf key */
{ current->key[i] = neighbor->key[0]; }
current->next[i] = neighbor->next[0];
for ( j = 1; j < neighbor->degree; j++) {
current->next[++i] = neighbor->next[j];
current->key[i] = neighbor->key[j];
}
current->degree = i + 1;
return_node( neighbor );
upper->degree -= 1;
i = curr + 1;
while ( i < upper->degree ) {
upper->next[i] = upper->next[i + 1];
upper->key[i] = upper->key[i + 1];
i += 1;
} /* deleted from upper, now propagate up */
current = upper;
} /* end of share/joining if-else*/
} else { /* current is last entry in upper */
neighbor = upper->next[curr - 1];
if ( neighbor->degree > A ) {
/* sharing possible */
for ( j = current->degree; j > 1; j--) {
current->next[j] = current->next[j - 1];
current->key[j] = current->key[j - 1];
}
current->next[1] = current->next[0];
i = neighbor->degree;
current->next[0] = neighbor->next[i - 1];
if ( current->height > 0 ) {
current->key[1] = upper->key[curr];
} else { /* on leaf level, take leaf key */
current->key[1] = current->key[0];
current->key[0] = neighbor->key[i - 1];
}
upper->key[curr] = neighbor->key[i - 1];
neighbor->degree -= 1;
current->degree += 1;
finished = 1;
} /* sharing complete */
else { /* must join */
i = neighbor->degree;
if ( current->height > 0 )
{ neighbor->key[i] = upper->key[curr]; }
else /* on leaf level, take leaf key */
{ neighbor->key[i] = current->key[0]; }
neighbor->next[i] = current->next[0];
for ( j = 1; j < current->degree; j++) {
neighbor->next[++i] = current->next[j];
neighbor->key[i] = current->key[j];
}
neighbor->degree = i + 1;
return_node( current );
upper->degree -= 1;
/* deleted from upper, now propagate up */
current = upper;
} /* end of share/joining if-else */
} /* end of current is (not) last in upper if-else*/
} /* end of delete root/non-root if-else */
} /* end of full/underfull if-else */
} /* end of while not finished */
return ( del_object );
} /* end of delete object exists if-else */
}
void
check_tree(tree_node_t* tree, int lower, int upper)
{
int i;
int seq_error = 0;
if ( tree->height > 0 ) {
printf("(%d:", tree->height);
for (i = 1; i < tree->degree; i++ )
{ printf(" %d", tree->key[i]); }
for (i = 1; i < tree->degree; i++ ) {
if ( !( lower <= tree->key[i] && tree->key[i] < upper) ) {
seq_error = 1;
}
}
if ( seq_error == 1)
{ printf(":?"); }
printf(")");
check_tree(tree->next[0], lower, tree->key[1]);
for (i = 1; i < tree->degree - 1; i++ )
{ check_tree(tree->next[i], tree->key[i], tree->key[i + 1]); }
check_tree(tree->next[tree->degree - 1],
tree->key[tree->degree - 1], upper);
} else {
printf("[");
for (i = 0; i < tree->degree; i++ )
{ printf(" %d", tree->key[i]); }
for (i = 0; i < tree->degree; i++ ) {
if ( !( lower <= tree->key[i] && tree->key[i] < upper) ) {
seq_error = 1;
}
}
if ( seq_error == 1)
{ printf(":?"); }
printf("]");
}
}
// _____________________________________________________________________________
// Simple test
int
main()
{
tree_node_t* searchtree;
char nextop;
searchtree = create_tree();
printf("Made Tree: (%d,%d)-Tree\n", A, B);
while ( (nextop = getchar()) != 'q' ) {
if ( nextop == 'i' ) {
int inskey, *insobj, success;
insobj = (int*) malloc(sizeof(int));
scanf(" %d", &inskey);
*insobj = 10 * inskey + 2;
success = insert( searchtree, inskey, insobj );
if ( success == 0 )
printf(" insert successful, key = %d, object value = %d\n",
inskey, *insobj);
else
{ printf(" insert failed, success = %d\n", success); }
}
if ( nextop == 'f' ) {
int findkey, *findobj;
scanf(" %d", &findkey);
findobj = find( searchtree, findkey);
if ( findobj == NULL )
{ printf(" find failed, for key %d\n", findkey); }
else
{ printf(" find successful, found object %d\n", *findobj); }
}
if ( nextop == 'd' ) {
int delkey, *delobj;
scanf(" %d", &delkey);
delobj = delete ( searchtree, delkey);
if ( delobj == NULL )
{ printf(" delete failed for key %d\n", delkey); }
else
printf(" delete successful, deleted object %d\n",
*delobj);
}
if ( nextop == '?' ) {
printf(" Checking tree\n");
check_tree(searchtree, -1000, 1000);
printf("\n");
/*if( searchtree->left != NULL )
printf("key in root is %d, height of tree is %d\n",
searchtree->key, searchtree->height );*/
printf(" Finished Checking tree\n");
}
}
return (0);
}
|
the_stack_data/51700269.c | #include <stdio.h>
int main()
{
int i;
for(i = 1; i <= 100; i++)
{
if(i % 2 == 0)
{
printf("%d\n", i);
}
}
return 0;
}
|
the_stack_data/92326537.c | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef char* string;
typedef struct
{
char nome[50];
int idade;
} Cliente;
typedef struct cel
{
Cliente this;
struct cel *next;
struct cel *prev;
} Celula;
Cliente newCliente(string nome, int idade);
void addToList(Celula *head, Cliente c, int index);
void rmvFromList(Celula *head, int index);
Celula* acsInList(Celula *head, int index);
int distFromBegin(Celula *head, Cliente c);
int distFromEnd(Celula *head, Cliente c);
void listList(Celula *head, int sentido);
int main()
{
Celula *head;
head = malloc(sizeof(Celula));
addToList(head, newCliente("Marcos", 25), 0);
addToList(head, newCliente("Marcio", 18), 0);
addToList(head, newCliente("Carlos", 18), 0);
addToList(head, newCliente("Cassio", 30), 0);
addToList(head, newCliente("Samuel", 30), 0);
printf("%d ", distFromBegin(head, newCliente("Samuel", 30)));
printf("%d\n", distFromEnd(head, newCliente("Samuel", 30)));
printf("%s %s\n", acsInList(head, 0)->this.nome, acsInList(head, 2)->this.nome);
rmvFromList(head, 2);
printf("%s %s\n", acsInList(head, 0)->this.nome, acsInList(head, 1)->this.nome);
return 0;
}
Cliente newCliente(string nome, int idade)
{
Cliente c;
strcpy(c.nome, nome);
c.idade = idade;
return c;
}
void addToList(Celula *head, Cliente c, int index)
{
int i;
Celula *p;
Celula *cel;
cel = malloc(sizeof(Celula));
cel->this = c;
cel->prev = NULL;
cel->next = NULL;
p = head;
if(p->next!=NULL)
{
for(i=0;i<index && p->next!=NULL; i++)
p = p->next;
cel->prev = p;
if(p->next!=NULL)
p->next->prev = cel;
else
head->prev = cel;
cel->next = p->next;
p->next = cel;
}
else
{
head->next = cel;
head->prev = cel;
cel->prev = head;
}
}
void rmvFromList(Celula *head, int index)
{
int i;
Celula *p;
Celula *q;
p = head;
if(head->next!=NULL)
{
for(i=0;i<index && p->next!=NULL; i++)
p = p->next;
if(p->next!=NULL)
{
q = p->next;
p->next = q->next;
if(q->next!=NULL)
{
q->next->prev = q;
free(q);
}
else
head->prev = p;
}
else
printf("O elemento a ser excluído nao existe!");
}
else
printf("A lista esta vazia!");
}
Celula* acsInList(Celula *head, int index)
{
int i=-1;
Celula *p;
p = head;
if(p->next!=NULL)
for(i=0, p = head->next; i<index && p->next!=NULL; i++)
p = p->next;
if(i<index)
p = NULL;
return p;
}
int distFromBegin(Celula *head, Cliente c)
{
int i;
Celula *p;
for(i=0, p=head->next; p!=NULL; i++, p = p->next)
if(p->this.idade == c.idade)
if(strcmp(p->this.nome, c.nome))
return i;
return -1;
}
int distFromEnd(Celula *head, Cliente c)
{
int i;
Celula *p;
for(i=0,p=head->prev; p!=NULL; i++, p = p->prev)
if(p->this.idade == c.idade)
if(strcmp(p->this.nome, c.nome))
return i;
return -1;
}
|
the_stack_data/748471.c | #include<stdio.h>
#include<stdlib.h>
typedef struct list
{
int value;
struct list *right;
struct list *left;
} list;
list *head=NULL;
list *tail=NULL;
list init (int date)
{
list *ptr=(list*)malloc(sizeof(list));
ptr->value=date;
ptr->right=NULL;
ptr->left=NULL;
head=ptr;
tail=ptr;
}
int isEmpty()
{
if (head==NULL && tail==NULL)
return 1;
else return 0;
}
void insertEnd (int date)
{
if (isEmpty()==1)
init (date);
else
{
list *ptr=(list*)malloc(sizeof(list));
ptr->value=date;
ptr->right=NULL;
ptr->left=tail;
tail=ptr;
ptr->left->right=ptr;
}
}
void insertList()
{
list *ptr=head;
while (ptr!=NULL)
{
printf ("%d ", ptr->value);
ptr=ptr->right;
}
}
int delit()
{
if (isEmpty())
{return 0;}
list *ptr=head;
if (ptr==tail)
{
head=NULL;
tail=NULL;
free(ptr);
return 1;
}
list *ptr1=NULL;
ptr1=ptr->right;
free(ptr);
head=ptr1;
return 1;
}
int main()
{
int k, date;
scanf("%d", &k);
scanf("%d", &date);
init(date);
for(int i=0; i<k-1; i++)
{
scanf ("%d", &date);
insertEnd(date);
}
insertList();
printf ("\n");
for (int i=0; i<k; i++)
{delit();
insertList();
printf("\n");
}
return 0;
}
|
the_stack_data/234517912.c | #define _GNU_SOURCE
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/time.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <malloc.h>
// amount of data to read on the
// disk after seeking, by default
// we read 512 bytes (one sector)
#define BUFFERSIZE 512
// number of loop reading the
// disk, we make an average after all
// the loops
#define DISKLOOP 128
#define TYPE_HDD "HDD"
#define TYPE_SSD "SSD"
void diep(const char *str) {
perror(str);
exit(EXIT_FAILURE);
}
void dies(const char *str) {
fprintf(stderr, "[-] %s\n", str);
exit(EXIT_FAILURE);
}
// returns time in microseconds
uint64_t systime() {
struct timeval tv;
if(gettimeofday(&tv, NULL) < 0)
diep("gettimeofday");
return (tv.tv_sec * 1000000) + tv.tv_usec;
}
uint64_t seektest(int fd, off_t offa, off_t offb) {
uint64_t tinit, tend;
void *buffer;
// purge full disk from cache
// this don't do anything else than
// requesting the kernel to flush all the
// pages which contains cache about this disk
// to ensure we hit the disk (at least on a kernel
// perspective)
if(posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED))
diep("posix_fadvise");
// allocate aligned memory
// it's not anymore really needed to make
// aligned memory but it's still better for performance
//
// this was required when doing the test using
// O_DIRECT flag, and implementation still use it
// in case of change later
if(posix_memalign(&buffer, 512, BUFFERSIZE))
dies("posix_memalign");
// first seek
lseek(fd, offa, SEEK_SET);
if(read(fd, buffer, BUFFERSIZE) < 0)
diep("read init");
// starting timing
// we compute the time to do the
// second seek only
tinit = systime();
// second seek
lseek(fd, offb, SEEK_SET);
if(read(fd, buffer, BUFFERSIZE) < 0)
diep("read end");
// computing time elapsed
tend = systime();
free(buffer);
return tend - tinit;
}
// this is the real implementation of the check
// it returns an averae seektime in microseconds (us)
// this is an approximative value but enough to determine
// if the disk is an SSD or HDD
uint64_t seektime(int fd, size_t disklen) {
// counters
size_t checked = 0;
uint64_t fulltime = 0;
// loop on the seek test
for(checked = 0; checked < DISKLOOP; checked += 1) {
// generate random offset within the disk
off_t offa = rand() % disklen;
off_t offb = rand() % disklen;
// probing seektime between theses two offset
uint64_t thistime = seektest(fd, offa, offb);
// printf("[+] seektime: %lu us\n", thistime);
fulltime += thistime;
checked += 1;
}
// returns the average
return (fulltime / checked);
}
void output(int json, char *type, char *device, uint64_t elapsed) {
if(json == 1) {
printf("{\"device\": \"%s\", \"type\": \"%s\", \"elapsed\": %lu}\n", device, type, elapsed);
} else {
printf("%s: %s (%lu us)\n", device, type, elapsed);
}
}
void usage(char *program) {
printf("Usage: %s [-j] device\n\n", program);
printf(" -j provide a json output\n");
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[]) {
int opt, json = 0;
char *device;
int fd;
while((opt = getopt(argc, argv, "j")) != -1) {
switch(opt) {
case 'j':
json = 1;
break;
default:
usage(argv[0]);
}
}
if(optind >= argc)
usage(argv[0]);
device = argv[optind];
// open disk in read-only
//
// we could open it in O_DIRECT flag
// but this is not as efficient then
// opening it with default settings
// and clearing the cache
if((fd = open(device, O_SYNC | O_RDONLY)) < 0)
diep(argv[1]);
// randomize
srand(time(NULL));
// seeking disk length
off_t disklen = lseek(fd, 0, SEEK_END);
// starting seektime test
uint64_t elapsed = seektime(fd, disklen);
// analyzing seektime
char *type = (elapsed >= 500) ? TYPE_HDD : TYPE_SSD;
output(json, type, device, elapsed);
close(fd);
return 0;
}
|
the_stack_data/211081060.c | #include <stdio.h>
int main(int argc, char const *argv[])
{
// return 0;
}
|
the_stack_data/145452860.c |
#include <stdio.h>
void scilab_rt_sleep_i0_(int x)
{
printf("%d",x);
}
|
the_stack_data/122014734.c | #include <omp.h>
#include <stdlib.h>
#include <stdio.h>
#define BONES_MIN(a,b) ((a<b) ? a : b)
#define BONES_MAX(a,b) ((a>b) ? a : b)
#define DIV_CEIL(a,b) ((a+b-1)/b)
#define DIV_FLOOR(a,b) (a/b)
// Multiple iterations for kernel measurements
#define ITERS 1
// Function to initialize the CPU platform (for fair measurements)
void bones_initialize_target(void) {
int bones_thread_count = omp_get_num_procs();
omp_set_num_threads(bones_thread_count);
#pragma omp parallel
{
int bones_thread_id = omp_get_thread_num();
}
}
// Declaration of the original function
int bones_main(void);
// New main function for initialisation and clean-up
int main(void) {
// Initialisation
bones_initialize_target();
// Original main function
int bones_return = bones_main();
// Clean-up
return bones_return;
}
|
the_stack_data/508623.c | /* Ecrit une valeur 32bit non-signée à l'adresse indiquée */
/* Public domain */
#include <ctype.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
static bool parse_dec(const char * arg, uint32_t *out);
static bool parse_hex(const char * arg, uint32_t *out);
static bool parse_bin(const char * arg, uint32_t *out);
static bool parse_number(const char * arg, uint32_t *out);
int main(int argc, const char *argv[]) {
if (argc == 3) {
uint32_t address, value;
if (parse_number(argv[1], &address)) {
if (parse_number(argv[2], &value)) {
*((uint32_t*)address) = value;
return 0; /* Success, E_OK */
}
else {
fputs("Valeur non reconnue.\n", stderr);
}
}
else {
fputs("Adresse non reconnue.\n", stderr);
}
} else {
puts("UTILISATION: POKE32 <addresse> <valeur>\n");
return -1;
}
}
static bool parse_dec(const char * arg, uint32_t *out) {
uint32_t n = 0;
while (*arg) {
if (*arg == ':' || *arg == '_') {
arg++;
continue;
} else if (isdigit(*arg)) {
n *= 10;
n += *arg - '0';
} else {
return false;
}
arg++;
}
*out = n;
return true;
}
static bool parse_hex(const char * arg, uint32_t *out) {
uint32_t n = 0;
while (*arg) {
if (*arg == ':' || *arg == '_') {
arg++;
continue;
} else if (isdigit(*arg)) {
n *= 16;
n += *arg - '0';
} else if ((*arg >= 'a') && (*arg <= 'f')) {
n *= 16;
n += *arg - 'a' + 10;
} else if ((*arg >= 'A') && (*arg <= 'F')) {
n *= 16;
n += *arg - 'A' + 10;
} else {
return false;
}
arg++;
}
*out = n;
return true;
}
static bool parse_bin(const char * arg, uint32_t *out) {
uint32_t n = 0;
while (*arg) {
if (*arg == ':' || *arg == '_') {
arg++;
continue;
} else if ((*arg == '0') || (*arg == '1')) {
n *= 2;
n += *arg - '0';
} else {
return false;
}
arg++;
}
*out = n;
return true;
}
/*
* Evaluate an argument to a number
*/
static bool parse_number(const char * arg, uint32_t *out) {
size_t len = strlen(arg);
if (len > 2) {
if (arg[0] == '0') {
if (arg[1] == 'x') {
return parse_hex(&arg[2], out);
} else if (arg[1] == 'b') {
return parse_bin(&arg[2], out);
}
}
}
if (len > 1) {
if (arg[0] == '$') {
return parse_hex(&arg[1], out);
} else if (arg[0] == '%') {
return parse_bin(&arg[1], out);
}
}
return parse_dec(arg, out);
} |
the_stack_data/1131356.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
void T();
void EPRIME();
void F();
void TPRIME();
void ERROR();
void E();
int i=0;
char str[100];
int main(){
printf("Enter the expression:- ");
gets(str);
E();
if(strlen(str)==i)
printf("Valid Expression\n");
else
printf("Invalid Expression\n");
return 0;
}
void E(){
T();
EPRIME();
}
void EPRIME(){
if(str[i]=='+'){
i++;
T();
EPRIME();
}
}
void T(){
F();
TPRIME();
}
void TPRIME(){
if(str[i]=='*'){
i++;
F();
TPRIME();
}
}
void F(){
if(str[i]>='0'&&str[i]<='9'){
i++;
while(str[i]>='0'&&str[i]<='9')
i++;
}
else{
if(str[i]=='('){
i++;
E();
if(str[i]==')')
i++;
else
ERROR();
}
else
ERROR();
}
}
void ERROR(){
printf("Invalid Expression\n");
exit(1);
}
|
the_stack_data/80736.c | #pragma acc data create (u[0:gnr], v[0:gnr], r[0:gnr])
#pragma acc data deviceptr (r1, r2) present (ou[0:n3*n2*n1], or[0:n3*n2*n1])
#pragma acc parallel loop gang num_gangs (n3-2) num_workers (16) vector_length (64)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc parallel loop gang num_gangs (n3-2) num_workers (16) vector_length (64)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc data deviceptr (u1, u2) present (ou[0:n3*n2*n1], ov[0:n3*n2*n1], or[0:n3*n2*n1])
#pragma acc parallel num_gangs (n3-2) num_workers (8) vector_length (128)
#pragma acc kernels
#pragma acc loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc parallel num_gangs (n3-2) num_workers (8) vector_length (128)
#pragma acc kernels
#pragma acc loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc data deviceptr (x1, y1) present (or[0:m3k*m2k*m1k], os[0:m3j*m2j*m1j])
#pragma acc parallel loop gang num_gangs (m3j-2) num_workers (8) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc parallel loop gang num_gangs (m3j-2) num_workers (8) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc data deviceptr (z1, z2, z3) present (oz[0:mm3*mm2*mm1], ou[0:n3*n2*n1])
#pragma acc parallel loop gang num_gangs (mm3-1) num_workers (8) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc parallel loop gang num_gangs (mm3-1) num_workers (8) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc parallel loop gang num_gangs (mm3-1) num_workers (8) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc parallel loop gang num_gangs (mm3-1) num_workers (8) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc parallel loop gang num_gangs (mm3-1) num_workers (8) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc parallel loop gang num_gangs (mm3-d3) num_workers (8) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc parallel loop gang num_gangs (mm3-d3) num_workers (8) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc parallel loop gang num_gangs (mm3-d3) num_workers (8) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc parallel loop gang num_gangs (mm3-d3) num_workers (8) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc parallel loop gang num_gangs (mm3-1) num_workers (8) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc parallel loop gang num_gangs (mm3-1) num_workers (8) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc parallel loop gang num_gangs (mm3-1) num_workers (8) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc parallel loop gang num_gangs (mm3-1) num_workers (8) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc data copyin (or[0:n3*n2*n1])
#pragma acc parallel loop gang reduction (+: s) reduction (max: temp) num_gangs (n3-2) num_workers (8) vector_length (128)
#pragma acc kernels loop gang reduction (+: s) reduction (max: temp) independent
#pragma acc loop worker independent
#pragma acc loop vector independent
#pragma acc data present (ou[0:n3*n2*n1])
#pragma acc parallel loop gang num_gangs (n3-2) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop vector independent
#pragma acc parallel loop gang num_gangs (n3-2) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop vector independent
#pragma acc parallel loop gang num_gangs (n2) vector_length (128)
#pragma acc kernels loop gang independent
#pragma acc loop vector independent
#pragma acc update device (oz[0:n3*n2*n1])
#pragma acc parallel present (oz[0:n3*n2*n1]) num_gangs (n3) num_workers (8) vector_length (128)
#pragma acc kernels present (oz[0:n3*n2*n1])
#pragma acc loop gang independent
#pragma acc loop worker independent
#pragma acc loop vector independent
|
the_stack_data/187643399.c | /*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
*
* 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.
*
*/
#ifdef TINYUSB_MIDI_DEVICE
#include "tusb.h"
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
* Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
*
* Auto ProductID layout's Bitmap:
* [MSB] MIDI | HID | MSC | CDC [LSB]
*/
#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) )
#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
_PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = 0x00,
.bDeviceSubClass = 0x00,
.bDeviceProtocol = 0x00,
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
.idVendor = USB_VENDOR_ID,
.idProduct = USB_PID,
.bcdDevice = 0x0100,
.iManufacturer = 0x01,
.iProduct = 0x02,
.iSerialNumber = 0x03,
.bNumConfigurations = 0x01
};
// Invoked when received GET DEVICE DESCRIPTOR
// Application return pointer to descriptor
uint8_t const * tud_descriptor_device_cb(void)
{
return (uint8_t const *) &desc_device;
}
//--------------------------------------------------------------------+
// Configuration Descriptor
//--------------------------------------------------------------------+
enum
{
ITF_NUM_MIDI = 0,
ITF_NUM_MIDI_STREAMING,
ITF_NUM_TOTAL
};
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_MIDI_DESC_LEN)
#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX
// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
// 0 control, 1 In, 2 Bulk, 3 Iso, 4 In etc ...
#define EPNUM_MIDI 0x02
#else
#define EPNUM_MIDI 0x01
#endif
uint8_t const desc_fs_configuration[] =
{
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
// Interface number, string index, EP Out & EP In address, EP size
TUD_MIDI_DESCRIPTOR(ITF_NUM_MIDI, 0, EPNUM_MIDI, 0x80 | EPNUM_MIDI, 64)
};
#if TUD_OPT_HIGH_SPEED
uint8_t const desc_hs_configuration[] =
{
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
// Interface number, string index, EP Out & EP In address, EP size
TUD_MIDI_DESCRIPTOR(ITF_NUM_MIDI, 0, EPNUM_MIDI, 0x80 | EPNUM_MIDI, 512)
};
#endif
// Invoked when received GET CONFIGURATION DESCRIPTOR
// Application return pointer to descriptor
// Descriptor contents must exist long enough for transfer to complete
uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
{
(void) index; // for multiple configurations
#if TUD_OPT_HIGH_SPEED
// Although we are highspeed, host may be fullspeed.
return (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_hs_configuration : desc_fs_configuration;
#else
return desc_fs_configuration;
#endif
}
//--------------------------------------------------------------------+
// String Descriptors
//--------------------------------------------------------------------+
// array of pointer to string descriptors
extern char KLST_U_ID_SERIAL[];
char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"Klangstrom", // 1: Manufacturer
"KLST MIDI Device", // 2: Product
KLST_U_ID_SERIAL, // 3: Serials, should use chip ID
};
static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
{
(void) langid;
uint8_t chr_count;
if ( index == 0)
{
memcpy(&_desc_str[1], string_desc_arr[0], 2);
chr_count = 1;
}else
{
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
const char* str = string_desc_arr[index];
// Cap at max char
chr_count = strlen(str);
if ( chr_count > 31 ) chr_count = 31;
// Convert ASCII string into UTF-16
for(uint8_t i=0; i<chr_count; i++)
{
_desc_str[1+i] = str[i];
}
}
// first byte is length (including header), second byte is string type
_desc_str[0] = (TUSB_DESC_STRING << 8 ) | (2*chr_count + 2);
return _desc_str;
}
#endif // TINYUSB_MIDI_DEVICE |
the_stack_data/707975.c | #include <stdint.h>
/* 俄罗斯农民乘法,具体规则如下:
* --------------------------------------------------------------
* 把每一个数字分别写在列头。
* 将头一列的数字加倍,将第二列的数字减半。
* 如果在第二列的数字是奇数,将它除以二并把余数去掉。
* 如果第二列的数字是偶数,将其所在行删除。
* 继续加倍、减半和删除直到第二列的数字为1。
* 将第一列中剩余的数字相加。于是就得出了根据原始数字计算出的结果。
* --------------------------------------------------------------
*/
uint64_t russian_farmer_multiplication(uint64_t multiplicand,uint64_t multiplier)
{
uint64_t result = 0;
while( multiplicand ) {
if( multiplicand & 1 ) {
result += multiplier;
}
multiplicand >>= 1;
multiplier <<= 1;
}
return result;
}
|
the_stack_data/93887278.c | #include <stdio.h>
int main(int argc, char const *argv[])
{
int number;
char* array[100];
int i = 0, j;
printf("Enter a number: ");
scanf("%d", &number);
while(number != 0){
switch (number % 10){
case 0:
array[i++] = "zero"; break;
case 1:
array[i++] = "one"; break;
case 2:
array[i++] = "two"; break;
case 3:
array[i++] = "three"; break;
case 4:
array[i++] = "four"; break;
case 5:
array[i++] = "five"; break;
case 6:
array[i++] = "six"; break;
case 7:
array[i++] = "seven"; break;
case 8:
array[i++] = "eight"; break;
case 9:
array[i++] = "nine"; break;
}
number /= 10;
}
for(j = i-1; j >= 0; j--){
printf("%s ", array[j]);
}
printf("\n");
return 0;
} |
the_stack_data/187642011.c | #include <stdio.h>
#include <stdlib.h>
#define N 10
int main()
{
int a[N], *p;
printf("Enter %d numbers: ", N);
for(p = a; p < a + N; p++)
{
scanf("%d", p);
}
printf("In reverse order: ");
for(p = a + N - 1; p >= a; p--)
{
printf("%d ", *p);
}
printf("\n");
return 0;
}
|
the_stack_data/47536.c | /*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)labs.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <stdlib.h>
long
labs(j)
long j;
{
return (j < 0 ? -j : j);
}
|
the_stack_data/60270.c | #include <stdio.h>
#include <stdlib.h>
#define N 20
void printSeq(int a[], int n) {
printf("[");
for (int i=0; i<n; i++) printf("%d ", a[i]);
if (n==0) printf("]\n"); else printf("\b]\n");
}
void quicksort(int arr[], int n) {
/* Sorts arr in ascending order.
* n is the dimension of arr.
* Uses a divide and conquer approach.
* 1. Split arr into two parts left and right with respect
* to a pivot where left contains elements < pivot and
* right has elements >= pivot. This is the divide step.
* 2. quicksort left, quicksort right. The recursive step.
* 3. stick left, pivot, right for final sorted array - conquer step.
*/
if(n<2) return;//base step. Array sorted if empty or has 1 element.
int larr[n], rarr[n], pivot=arr[0];//pivot chosen as first element in arr.
int i, li=0, ri=0;
//Divide step
for(i=1;i<n;i++)
if(arr[i]<pivot) larr[li++]=arr[i]; else rarr[ri++]=arr[i];
printf("larr="); printSeq(larr,li); printf("pivot=%d\n", pivot);
printf("rarr=");printSeq(rarr,ri);
//Recursive step
quicksort(larr,li); quicksort(rarr,ri);
//Conquer step. Copy in order arrays larr, pivot and rarr into arr.
for(i=0;i<li;i++) arr[i]=larr[i];//copy larr
arr[i]=pivot;//copy pivot
for(i++;i<n;i++) arr[i]=rarr[i-li-1];//copy rarr
return;
}
int main() {
int a[N], n, i;
printf("Sequence length (>0, <20) = ");
scanf("%d", &n);
if (n<1) {printf("Illegal length\n"); exit(0);}
printf("Give seq. elements sep. by white space = ");
for (i=0; i<n; i++) scanf("%d", &a[i]);
printf("Original sequence = ");
printSeq(a, n);
quicksort(a, n);
printf("Sorted sequence = ");
printSeq(a, n);
return 0;
}
|
the_stack_data/82948946.c | #include <stdio.h>
#include <stdint.h>
#include <ctype.h>
#include <arpa/inet.h>
#include <string.h>
void hexdump(void *ptr, int buflen) {
unsigned char *buf = (unsigned char *) ptr;
int i, j;
for (i = 0; i < buflen; i += 16) {
printf("%06x: ", i);
for (j = 0; j < 16; j++)
if (i + j < buflen)
printf("%02x ", buf[i + j]);
else
printf(" ");
printf(" ");
for (j = 0; j < 16; j++)
if (i + j < buflen)
printf("%c", isprint(buf[i + j]) ? buf[i + j] : '.');
printf("\n");
}
}
void hexdumpraw(void *ptr, char *result, int buflen) {
unsigned char *buf = (unsigned char *) ptr;
int a = 0;
for (a = 0; a < buflen; a++) {
sprintf(result + (a * 2), "%02X", buf[a]);
}
}
/* Convert IP string to 32 bit unsigned int */
uint32_t ip2int(char *ip) {
struct in_addr a;
if (!inet_aton(ip, &a)) {
// IP was invalid - return 0
return ((uint32_t) 0);
}
return a.s_addr;
}
/* Convert 32bit unsigned int to a string representation */
void int2ip(uint32_t ip, char *result) {
struct in_addr a;
a.s_addr = ip;
strcpy(result, inet_ntoa(a));
}
|