file
stringlengths 18
26
| data
stringlengths 2
1.05M
|
---|---|
the_stack_data/126144.c | #ifdef RL_INTEL_INTR
void dqsb_draw_line_thin_add(float *le, float *block, xy_t start_pos, const int bs, int chan_stride) // SSE2
{
// Generic variables
xyi_t ip;
float y, x;
__m128 yv, xv, *bp;
int ic, ib=0;
// Specific variables
__m128 r1x, r1y, r2x, costh, sinth, col[4];
__m128 rpx, rpy, ycos, ysin, weight;
__m128 d1y, d1x, d2x;
const float gl = DQS_GAUSS_LIMIT;
// Load parameters
r1x = _mm_set_ps1(le[0]);
r1y = _mm_set_ps1(le[1]);
r2x = _mm_set_ps1(le[2]);
costh = _mm_set_ps1(le[3]);
sinth = _mm_set_ps1(le[4]);
col[0] = _mm_set_ps1(le[5]);
col[1] = _mm_set_ps1(le[6]);
col[2] = _mm_set_ps1(le[7]);
col[3] = _mm_set_ps1(le[8]);
for (y=start_pos.y, ip.y=0; ip.y < bs; ip.y++, y+=1.f)
{
yv = _mm_set_ps1(y);
ycos = _mm_mul_ps(yv, costh);
ysin = _mm_mul_ps(yv, sinth);
for (x=start_pos.x, ip.x=0; ip.x < bs; ip.x+=4, x+=4.f, ib+=4)
{
// Initialise coordinates
xv = _mm_add_ps(_mm_set_ps1(x), _mm_set_ps(3.f, 2.f, 1.f, 0.f));
// Rotate coordinates
rpx = _mm_mul_ps(xv, costh); rpy = _mm_mul_ps(xv, sinth);
rpx = _mm_sub_ps(rpx, ysin); rpy = _mm_add_ps(rpy, ycos);
// Distances
d1y = _mm_abs_ps(_mm_sub_ps(rpy, r1y));
d2x = _mm_sub_ps(rpx, r2x);
d1x = _mm_sub_ps(rpx, r1x);
// Distance checks
if (_mm_movemask_ps(_mm_cmplt_ps(d1y, _mm_set_ps1(gl)))
& _mm_movemask_ps(_mm_cmplt_ps(d2x, _mm_set_ps1(gl)))
& _mm_movemask_ps(_mm_cmpgt_ps(d1x, _mm_set_ps1(-gl))))
{
// Ends distance checks
int d1c = _mm_movemask_ps(_mm_cmplt_ps(d1x, _mm_set_ps1(gl))); // 0 if all are far from end
int d2c = _mm_movemask_ps(_mm_cmpgt_ps(d2x, _mm_set_ps1(-gl)));
// Compute pixel weight
weight = _mm_gaussian_d1_ps(d1y);
if (d1c | d2c)
{
if (d1c && d2c) // if both ends are covered
weight = _mm_mul_ps(weight, _mm_sub_ps( _mm_erfr_d1_ps(d1x) , _mm_erfr_d1_ps(d2x) ));
else if (d1c)
weight = _mm_mul_ps(weight, _mm_erfr_d1_ps(d1x));
else
weight = _mm_mul_ps(weight, _mm_erfr_d1_ps(_mm_neg_ps(d2x)));
}
// Add weighted colour
for (ic=0; ic < 4; ic++)
{
bp = (__m128 *) &block[ic*chan_stride + ib];
*bp = _mm_add_ps(_mm_mul_ps(weight, col[ic]), *bp);
}
}
}
}
}
void dqsb_draw_point_add(float *le, float *block, xy_t start_pos, const int bs, int chan_stride) // SSE2
{
// Generic variables
xyi_t ip;
float y, x;
__m128 yv, xv, *bp;
int ic, ib=0;
// Specific variables
__m128 cx, cy, rad, col[4];
__m128 weight, d, dy2, dx2;
const float gl = DQS_GAUSS_LIMIT;
// Load parameters
cx = _mm_set_ps1(le[0]);
cy = _mm_set_ps1(le[1]);
rad = _mm_set_ps1(le[2]);
col[0] = _mm_set_ps1(le[3]);
col[1] = _mm_set_ps1(le[4]);
col[2] = _mm_set_ps1(le[5]);
col[3] = _mm_set_ps1(1.f);
for (y=start_pos.y, ip.y=0; ip.y < bs; ip.y++, y+=1.f)
{
yv = _mm_set_ps1(y);
dy2 = _mm_sub_ps(yv, cy);
dy2 = _mm_mul_ps(dy2, dy2);
for (x=start_pos.x, ip.x=0; ip.x < bs; ip.x+=4, x+=4.f, ib+=4)
{
// Initialise coordinates
xv = _mm_add_ps(_mm_set_ps1(x), _mm_set_ps(3.f, 2.f, 1.f, 0.f));
dx2 = _mm_sub_ps(xv, cx);
dx2 = _mm_mul_ps(dx2, dx2);
// Distance
d = _mm_sqrt_ps(_mm_add_ps(dx2, dy2));
// Distance check
if (_mm_movemask_ps(_mm_cmplt_ps(d, _mm_set_ps1(gl))))
{
// Compute pixel weight
weight = _mm_gaussian_d1_ps(d);
// Add weighted colour
for (ic=0; ic < 4; ic++)
{
bp = (__m128 *) &block[ic*chan_stride + ib];
*bp = _mm_add_ps(_mm_mul_ps(weight, col[ic]), *bp);
}
}
}
}
}
#endif
|
the_stack_data/190768690.c | #include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
typedef int bool;
#define TRUE 1
#define FALSE 0
extern char *optarg;
void create_recursion_process(int process_count) {
int pid, status;
if(process_count == 0) return;
pid = fork();
if (pid == 0) {
create_recursion_process(process_count-1);
exit(process_count-1);
}else if(pid == -1) {
perror("fork error");
exit(1);
}
printf("^start process [id=%d, pid = %d, ppid = %d]\n", process_count, getpid(), getppid());
sleep(1);
pid = wait(&status);
printf("$close process [pid = %d, status = %d]\n", pid, WEXITSTATUS(status));
}
void create_for_process(int process_count) {
int i, pid, status;
for(i = 0; i<process_count; i++) {
switch(pid = fork()) {
case -1:
perror("fork error");
exit(1);
case 0:
printf("^start process [id=%d, pid = %d, ppid = %d]\n", i+1, getpid(), getppid());
sleep(1);
exit(i+1);
}
}
for(i = 0; i<process_count; i++) {
pid = wait(&status);
printf("$close process [pid = %d, status = %d]\n", pid, WEXITSTATUS(status));
}
}
int main(int argc, char* argv[]) {
int cname, process_count;
bool app_type_recursion=FALSE, process_count_received=FALSE;
// get process count and app type
while ((cname = getopt(argc, argv, ":c:r")) != -1) {
switch(cname) {
case 'c':
process_count_received = TRUE;
process_count = atoi(optarg);
break;
case 'r':
app_type_recursion = TRUE;
break;
}
}
if (!process_count_received) {
printf("error no parm");
return 2;
}
// create process
if ( app_type_recursion ) {
create_for_process(process_count);
} else {
create_recursion_process(process_count);
}
return 0;
} |
the_stack_data/138380.c | #include <math.h>
double fmin(double x, double y)
{
if (isnan(x))
return y;
if (isnan(y))
return x;
/* handle signed zeros, see C99 Annex F.9.9.2 */
if (signbit(x) != signbit(y))
return signbit(x) ? x : y;
return x < y ? x : y;
}
|
the_stack_data/17177.c | /*
* Developed by Claudio André <claudioandre.br at gmail.com> in 2012
* Based on source code provided by Samuele Giovanni Tonon
*
* More information at http://openwall.info/wiki/john/OpenCL-SHA-256
*
* Copyright (c) 2011 Samuele Giovanni Tonon <samu at linuxasylum dot net>
* Copyright (c) 2012-2015 Claudio André <claudioandre.br at gmail.com>
* This program comes with ABSOLUTELY NO WARRANTY; express or implied .
* This is free software, and you are welcome to redistribute it
* under certain conditions; as expressed here
* http://www.gnu.org/licenses/gpl-2.0.html
*/
#ifdef HAVE_OPENCL
#if FMT_EXTERNS_H
extern struct fmt_main fmt_opencl_cryptsha256;
#elif FMT_REGISTERS_H
john_register_one(&fmt_opencl_cryptsha256);
#else
#include <string.h>
#include "common-opencl.h"
#include "config.h"
#include "options.h"
#include "opencl_cryptsha256.h"
#define __CRYPTSHA256_CREATE_PROPER_TESTS_ARRAY__
#include "cryptsha256_common.h"
#define FORMAT_LABEL "sha256crypt-opencl"
#define ALGORITHM_NAME "SHA256 OpenCL"
#define OCL_CONFIG "sha256crypt"
//Checks for source code to pick (parameters, sizes, kernels to execute, etc.)
#define _USE_CPU_SOURCE (cpu(source_in_use))
#define _USE_GPU_SOURCE (gpu(source_in_use))
#define _SPLIT_KERNEL_IN_USE (gpu(source_in_use))
static sha256_salt *salt;
static sha256_password *plaintext; // plaintext ciphertexts
static sha256_password *plain_sorted; // sorted list (by plaintext len)
static sha256_hash *calculated_hash; // calculated hashes
static sha256_hash *computed_hash; // calculated hashes (from plain_sorted)
static int
*indices; // relationship between sorted and unsorted plaintext list
static cl_mem salt_buffer; //Salt information.
static cl_mem pass_buffer; //Plaintext buffer.
static cl_mem hash_buffer; //Hash keys (output).
static cl_mem work_buffer, tmp_buffer; //Temporary buffers
static cl_mem pinned_saved_keys, pinned_partial_hashes;
static struct fmt_main *self;
static cl_kernel prepare_kernel, preproc_kernel, final_kernel;
static int new_keys, source_in_use;
static int split_events[3] = { 1, 6, 7 };
//This file contains auto-tuning routine(s). It has to be included after formats definitions.
#include "opencl_autotune.h"
#include "memdbg.h"
/* ------- Helper functions ------- */
static size_t get_task_max_work_group_size()
{
size_t s;
s = autotune_get_task_max_work_group_size(FALSE, 0, crypt_kernel);
if (_SPLIT_KERNEL_IN_USE) {
s = MIN(s, autotune_get_task_max_work_group_size(FALSE, 0,
prepare_kernel));
s = MIN(s, autotune_get_task_max_work_group_size(FALSE, 0,
preproc_kernel));
s = MIN(s, autotune_get_task_max_work_group_size(FALSE, 0,
final_kernel));
}
return s;
}
/* ------- Create and destroy necessary objects ------- */
static void create_clobj(size_t gws, struct fmt_main *self)
{
pinned_saved_keys = clCreateBuffer(context[gpu_id],
CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR,
sizeof(sha256_password) * gws, NULL, &ret_code);
HANDLE_CLERROR(ret_code,
"Error creating page-locked memory pinned_saved_keys");
plaintext = (sha256_password *) mem_alloc(sizeof(sha256_password) * gws);
plain_sorted = (sha256_password *) clEnqueueMapBuffer(queue[gpu_id],
pinned_saved_keys, CL_TRUE, CL_MAP_WRITE, 0,
sizeof(sha256_password) * gws, 0, NULL, NULL, &ret_code);
HANDLE_CLERROR(ret_code, "Error mapping page-locked memory saved_plain");
pinned_partial_hashes = clCreateBuffer(context[gpu_id],
CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR,
sizeof(sha256_hash) * gws, NULL, &ret_code);
HANDLE_CLERROR(ret_code,
"Error creating page-locked memory pinned_partial_hashes");
calculated_hash = (sha256_hash *) mem_alloc(sizeof(sha256_hash) * gws);
computed_hash = (sha256_hash *) clEnqueueMapBuffer(queue[gpu_id],
pinned_partial_hashes, CL_TRUE, CL_MAP_READ, 0,
sizeof(sha256_hash) * gws, 0, NULL, NULL, &ret_code);
HANDLE_CLERROR(ret_code, "Error mapping page-locked memory out_hashes");
// create arguments (buffers)
salt_buffer = clCreateBuffer(context[gpu_id], CL_MEM_READ_ONLY,
sizeof(sha256_salt), NULL, &ret_code);
HANDLE_CLERROR(ret_code, "Error creating salt_buffer out argument");
pass_buffer = clCreateBuffer(context[gpu_id], CL_MEM_READ_ONLY,
sizeof(sha256_password) * gws, NULL, &ret_code);
HANDLE_CLERROR(ret_code, "Error creating buffer argument buffer_keys");
hash_buffer = clCreateBuffer(context[gpu_id], CL_MEM_WRITE_ONLY,
sizeof(sha256_hash) * gws, NULL, &ret_code);
HANDLE_CLERROR(ret_code, "Error creating buffer argument buffer_out");
tmp_buffer = clCreateBuffer(context[gpu_id], CL_MEM_READ_WRITE,
sizeof(sha256_buffers) * gws, NULL, &ret_code);
HANDLE_CLERROR(ret_code, "Error creating buffer argument work_area 1");
work_buffer = clCreateBuffer(context[gpu_id], CL_MEM_READ_WRITE,
sizeof(uint32_t) * (32 * 8) * gws, NULL, &ret_code);
HANDLE_CLERROR(ret_code, "Error creating buffer argument work_area 2");
//Set kernel arguments
HANDLE_CLERROR(clSetKernelArg(crypt_kernel, 0, sizeof(cl_mem),
(void *)&salt_buffer), "Error setting argument 0");
if (!(_SPLIT_KERNEL_IN_USE)) {
HANDLE_CLERROR(clSetKernelArg(crypt_kernel, 1, sizeof(cl_mem),
(void *)&pass_buffer), "Error setting argument 1");
HANDLE_CLERROR(clSetKernelArg(crypt_kernel, 2, sizeof(cl_mem),
(void *)&hash_buffer), "Error setting argument 2");
} else {
//Set prepare kernel arguments
HANDLE_CLERROR(clSetKernelArg(prepare_kernel, 0, sizeof(cl_mem),
(void *)&salt_buffer), "Error setting argument 0");
HANDLE_CLERROR(clSetKernelArg(prepare_kernel, 1, sizeof(cl_mem),
(void *)&pass_buffer), "Error setting argument 1");
HANDLE_CLERROR(clSetKernelArg(prepare_kernel, 2, sizeof(cl_mem),
(void *)&tmp_buffer), "Error setting argument 2");
//Set preprocess kernel arguments
HANDLE_CLERROR(clSetKernelArg(preproc_kernel, 0, sizeof(cl_mem),
(void *)&salt_buffer), "Error setting argument 0");
HANDLE_CLERROR(clSetKernelArg(preproc_kernel, 1, sizeof(cl_mem),
(void *)&pass_buffer), "Error setting argument 1");
HANDLE_CLERROR(clSetKernelArg(preproc_kernel, 2, sizeof(cl_mem),
(void *)&tmp_buffer), "Error setting argument 2");
HANDLE_CLERROR(clSetKernelArg(preproc_kernel, 3, sizeof(cl_mem),
(void *)&work_buffer), "Error setting argument 3");
//Set crypt kernel arguments
HANDLE_CLERROR(clSetKernelArg(crypt_kernel, 1, sizeof(cl_mem),
(void *)&hash_buffer), "Error setting argument 1");
HANDLE_CLERROR(clSetKernelArg(crypt_kernel, 2, sizeof(cl_mem),
(void *)&tmp_buffer), "Error setting argument 2");
HANDLE_CLERROR(clSetKernelArg(crypt_kernel, 3, sizeof(cl_mem),
(void *)&work_buffer), "Error setting argument 3");
//Set final kernel arguments
HANDLE_CLERROR(clSetKernelArg(final_kernel, 0, sizeof(cl_mem),
(void *)&salt_buffer), "Error setting argument 0");
HANDLE_CLERROR(clSetKernelArg(final_kernel, 1, sizeof(cl_mem),
(void *)&hash_buffer), "Error setting argument 2");
HANDLE_CLERROR(clSetKernelArg(final_kernel, 2, sizeof(cl_mem),
(void *)&tmp_buffer), "Error setting argument 3");
HANDLE_CLERROR(clSetKernelArg(final_kernel, 3, sizeof(cl_mem),
(void *)&work_buffer), "Error setting argument 3");
}
memset(plaintext, '\0', sizeof(sha256_password) * gws);
memset(plain_sorted, '\0', sizeof(sha256_password) * gws);
}
static void release_clobj(void)
{
cl_int ret_code;
if (work_buffer) {
ret_code =
clEnqueueUnmapMemObject(queue[gpu_id], pinned_partial_hashes,
computed_hash, 0, NULL, NULL);
HANDLE_CLERROR(ret_code, "Error Unmapping out_hashes");
ret_code = clEnqueueUnmapMemObject(queue[gpu_id], pinned_saved_keys,
plain_sorted, 0, NULL, NULL);
HANDLE_CLERROR(ret_code, "Error Unmapping saved_plain");
HANDLE_CLERROR(clFinish(queue[gpu_id]),
"Error releasing memory mappings");
MEM_FREE(plaintext);
MEM_FREE(calculated_hash);
ret_code = clReleaseMemObject(salt_buffer);
HANDLE_CLERROR(ret_code, "Error Releasing data_info");
ret_code = clReleaseMemObject(pass_buffer);
HANDLE_CLERROR(ret_code, "Error Releasing buffer_keys");
ret_code = clReleaseMemObject(hash_buffer);
HANDLE_CLERROR(ret_code, "Error Releasing buffer_out");
ret_code = clReleaseMemObject(tmp_buffer);
HANDLE_CLERROR(ret_code, "Error Releasing tmp_buffer");
ret_code = clReleaseMemObject(work_buffer);
HANDLE_CLERROR(ret_code, "Error Releasing work_out");
ret_code = clReleaseMemObject(pinned_saved_keys);
HANDLE_CLERROR(ret_code, "Error Releasing pinned_saved_keys");
ret_code = clReleaseMemObject(pinned_partial_hashes);
HANDLE_CLERROR(ret_code, "Error Releasing pinned_partial_hashes");
work_buffer = NULL;
}
}
/* ------- Salt functions ------- */
static void *get_salt(char *ciphertext)
{
static sha256_salt out;
int len;
out.rounds = ROUNDS_DEFAULT;
ciphertext += FORMAT_TAG_LEN;
if (!strncmp(ciphertext, ROUNDS_PREFIX, sizeof(ROUNDS_PREFIX) - 1)) {
const char *num = ciphertext + sizeof(ROUNDS_PREFIX) - 1;
char *endp;
unsigned long int srounds = strtoul(num, &endp, 10);
if (*endp == '$') {
ciphertext = endp + 1;
srounds = srounds < ROUNDS_MIN ? ROUNDS_MIN : srounds;
out.rounds = srounds > ROUNDS_MAX ? ROUNDS_MAX : srounds;
}
}
for (len = 0; ciphertext[len] != '$'; len++);
//Assure buffer has no "trash data".
memset(out.salt, '\0', SALT_LENGTH);
len = (len > SALT_LENGTH ? SALT_LENGTH : len);
//Put the tranfered salt on salt buffer.
memcpy(out.salt, ciphertext, len);
out.length = len;
out.final = out.rounds % HASH_LOOPS;
return &out;
}
static void set_salt(void *salt_info)
{
salt = salt_info;
//Send salt information to GPU.
HANDLE_CLERROR(clEnqueueWriteBuffer(queue[gpu_id], salt_buffer, CL_FALSE,
0, sizeof(sha256_salt), salt, 0, NULL, NULL),
"failed in clEnqueueWriteBuffer salt_buffer");
HANDLE_CLERROR(clFlush(queue[gpu_id]), "failed in clFlush");
}
static int salt_hash(void *salt)
{
return common_salt_hash(salt, SALT_SIZE, SALT_HASH_SIZE);
}
/* ------- Key functions ------- */
static void set_key(char *key, int index)
{
int len;
//Assure buffer has no "trash data".
memset(plaintext[index].pass, '\0', PLAINTEXT_LENGTH);
len = strlen(key);
len = (len > PLAINTEXT_LENGTH ? PLAINTEXT_LENGTH : len);
//Put the tranfered key on password buffer.
memcpy(plaintext[index].pass, key, len);
plaintext[index].length = len;
new_keys = 1;
}
static char *get_key(int index)
{
static char ret[PLAINTEXT_LENGTH + 1];
memcpy(ret, plaintext[index].pass, PLAINTEXT_LENGTH);
ret[plaintext[index].length] = '\0';
return ret;
}
/* ------- Initialization ------- */
static void build_kernel(char *task, char *custom_opts)
{
int major, minor;
if (!strlen(custom_opts)) {
char opt[MAX_OCLINFO_STRING_LEN];
int i;
snprintf(opt, sizeof(opt), "%s_%s", OCL_CONFIG, get_device_name_(gpu_id));
//Remove spaces.
for (i = 0; opt[i]; i++)
if (opt[i] == ' ')
opt[i] = '_';
if (!(custom_opts = getenv(opt)))
custom_opts = cfg_get_param(SECTION_OPTIONS,
SUBSECTION_OPENCL, opt);
if (!(custom_opts) && !(custom_opts = getenv(OCL_CONFIG "_BuildOpts")))
custom_opts = cfg_get_param(SECTION_OPTIONS,
SUBSECTION_OPENCL, OCL_CONFIG "_BuildOpts");
}
opencl_build_kernel(task, gpu_id, custom_opts, 1);
opencl_driver_value(gpu_id, &major, &minor);
if (major == 1311 && minor == 2) {
fprintf(stderr,
"The OpenCL driver in use cannot run this kernel. Please, update your driver!\n");
error();
}
// create kernel(s) to execute
crypt_kernel = clCreateKernel(program[gpu_id], "kernel_crypt", &ret_code);
HANDLE_CLERROR(ret_code,
"Error creating kernel. Double-check kernel name?");
if (_SPLIT_KERNEL_IN_USE) {
prepare_kernel =
clCreateKernel(program[gpu_id], "kernel_prepare", &ret_code);
HANDLE_CLERROR(ret_code,
"Error creating kernel_prepare. Double-check kernel name?");
final_kernel =
clCreateKernel(program[gpu_id], "kernel_final", &ret_code);
HANDLE_CLERROR(ret_code,
"Error creating kernel_final. Double-check kernel name?");
preproc_kernel =
clCreateKernel(program[gpu_id], "kernel_preprocess", &ret_code);
HANDLE_CLERROR(ret_code,
"Error creating kernel_preprocess. Double-check kernel name?");
}
}
static void release_kernel()
{
HANDLE_CLERROR(clReleaseKernel(crypt_kernel), "Release kernel");
HANDLE_CLERROR(clReleaseKernel(prepare_kernel), "Release kernel");
HANDLE_CLERROR(clReleaseKernel(final_kernel), "Release kernel");
HANDLE_CLERROR(clReleaseKernel(preproc_kernel), "Release kernel");
HANDLE_CLERROR(clReleaseProgram(program[gpu_id]), "Release Program");
}
static void init(struct fmt_main *_self)
{
self = _self;
opencl_prepare_dev(gpu_id);
}
static int calibrate()
{
char opt[MAX_OCLINFO_STRING_LEN];
char *task = "$JOHN/kernels/cryptsha256_kernel_GPU.cl";
int i, j, k, l, kernel_opt, best_opt = 0;
unsigned long long best_speed = 0;
size_t best_lws = 0, best_gws = 0;
int loop_set[][5] = {
{1, 2, 3, -1, 0}, //Fist loop inside block()
{9, 10, 11, 0, 0}, //Second loop inside block()
{17, 18, 19, 0, 0}, //Main loop inside kernel crypt()
{1, 1, 0, 0, 0}, //Use vector operations.
{0, 0, 0, 0, 0}
};
fprintf(stderr, "Calibration is trying to figure out the best configuration to "
"use at runtime. Please, wait...\n");
i = j = k = l = 0;
while (loop_set[0][i]) {
if (loop_set[0][i] > 0) {
kernel_opt = (1 << loop_set[0][i]);
kernel_opt += (1 << loop_set[1][j]);
kernel_opt += (1 << loop_set[2][k]);
kernel_opt += ((l & 1) << 25); // vector operations
} else {
i++;
kernel_opt = 0;
}
snprintf(opt, sizeof(opt), "-DUNROLL_LOOP=%i", kernel_opt);
//Build the tuned kernel
build_kernel(task, opt);
autotuned = 0; local_work_size = 0; global_work_size = 0;
autotune_run(self, ROUNDS_DEFAULT, 0, 200ULL);
release_clobj();
release_kernel();
#ifdef OCL_DEBUG
fprintf(stderr, "Configuration is LWS="Zu", GWS="Zu", UNROLL_LOOP=%i, "
"c/s: %llu\n", local_work_size, global_work_size,
kernel_opt, global_speed);
#endif
if (global_speed > (1.01 * best_speed)) {
best_speed = global_speed;
best_lws = local_work_size;
best_gws = global_work_size;
best_opt = kernel_opt;
if (options.verbosity > VERB_LEGACY)
fprintf(stderr, "- Good configuration found: LWS="Zu", GWS="Zu", "
"UNROLL_LOOP=%i, c/s: %llu\n", local_work_size,
global_work_size, kernel_opt, global_speed);
}
l++;
if (!loop_set[3][l]) {
l = 0; k++;
}
if (!loop_set[2][k]) {
k = 0; j++;
}
if (!loop_set[1][j]) {
j = 0; i++;
}
}
//Keep discoverd values.
snprintf(opt, sizeof(opt), ""Zu"", best_gws);
setenv("GWS", opt, 1);
snprintf(opt, sizeof(opt), ""Zu"", best_lws);
setenv("LWS", opt, 1);
fprintf(stderr, "The best configuration is: LWS="Zu", GWS="Zu", UNROLL_LOOP=%i, "
"c/s: %llu\n", best_lws, best_gws, best_opt, best_speed);
return best_opt;
}
static void reset(struct db_main *db)
{
if (!db)
return;
if (!autotuned) {
char *tmp_value;
char *task = "$JOHN/kernels/cryptsha256_kernel_GPU.cl";
char opt[24] = "";
int major, minor;
unsigned long long int max_run_time;
source_in_use = device_info[gpu_id];
//Initialize openCL tuning (library) for this format.
opencl_init_auto_setup(SEED, HASH_LOOPS,
((_SPLIT_KERNEL_IN_USE) ?
split_events : NULL),
warn, 1, self, create_clobj,
release_clobj, sizeof(uint32_t) * (32 * 8), 0, db);
if (cpu(device_info[gpu_id]))
max_run_time = 1000ULL;
else
max_run_time = 200ULL;
//Calibrate or a regular run.
if ((tmp_value = getenv("_CALIBRATE"))) {
int kernel_opt;
kernel_opt = calibrate();
snprintf(opt, sizeof(opt), "-DUNROLL_LOOP=%i", kernel_opt);
} else {
if ((tmp_value = getenv("_TYPE")))
source_in_use = atoi(tmp_value);
opencl_driver_value(gpu_id, &major, &minor);
if (!(_USE_GPU_SOURCE))
task = "$JOHN/kernels/cryptsha256_kernel_DEFAULT.cl";
if (source_in_use != device_info[gpu_id])
fprintf(stderr, "Selected runtime id %d, source (%s)\n",
source_in_use, task);
}
build_kernel(task, opt);
//Auto tune execution from shared/included code.
autotune_run(self, ROUNDS_DEFAULT, 0, max_run_time);
//Clear work buffers.
memset(plaintext, '\0', sizeof(sha256_password) * global_work_size);
}
}
static void done(void)
{
if (autotuned) {
release_clobj();
MEM_FREE(indices);
HANDLE_CLERROR(clReleaseKernel(crypt_kernel), "Release kernel");
if (_SPLIT_KERNEL_IN_USE) {
HANDLE_CLERROR(clReleaseKernel(prepare_kernel), "Release kernel");
HANDLE_CLERROR(clReleaseKernel(final_kernel), "Release kernel");
HANDLE_CLERROR(clReleaseKernel(preproc_kernel), "Release kernel");
}
HANDLE_CLERROR(clReleaseProgram(program[gpu_id]), "Release Program");
autotuned = 0;
}
}
/* ------- Compare functins ------- */
static int cmp_all(void *binary, int count)
{
uint32_t i;
uint32_t b = ((uint32_t *) binary)[0];
for (i = 0; i < count; i++)
if (b == calculated_hash[i].v[0])
return 1;
return 0;
}
static int cmp_one(void *binary, int index)
{
return !memcmp(binary, (void *)&calculated_hash[index], BINARY_SIZE);
}
static int cmp_exact(char *source, int count)
{
return 1;
}
/* ------- Crypt function ------- */
static int crypt_all(int *pcount, struct db_salt *_salt)
{
int count = *pcount;
int i, index;
size_t gws;
size_t *lws = local_work_size ? &local_work_size : NULL;
gws = GET_MULTIPLE_OR_BIGGER(count, local_work_size);
if (new_keys) {
// sort passwords by length
int tot_todo = 0, len;
MEM_FREE(indices);
indices = mem_alloc(gws * sizeof(int));
for (len = 0; len <= PLAINTEXT_LENGTH; len++) {
for (index = 0; index < count; index++) {
if (plaintext[index].length == len)
indices[tot_todo++] = index;
}
}
//Create a sorted candidates list.
for (index = 0; index < count; index++) {
memcpy(plain_sorted[index].pass, plaintext[indices[index]].pass,
PLAINTEXT_LENGTH);
plain_sorted[index].length = plaintext[indices[index]].length;
}
//Transfer plaintext buffer to device.
BENCH_CLERROR(clEnqueueWriteBuffer(queue[gpu_id], pass_buffer,
CL_FALSE, 0, sizeof(sha256_password) * gws, plain_sorted, 0,
NULL, multi_profilingEvent[0]),
"failed in clEnqueueWriteBuffer pass_buffer");
}
//Enqueue the kernel
if (_SPLIT_KERNEL_IN_USE) {
BENCH_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], prepare_kernel, 1,
NULL, &gws, lws, 0, NULL, multi_profilingEvent[3]),
"failed in clEnqueueNDRangeKernel I");
BENCH_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], preproc_kernel, 1,
NULL, &gws, lws, 0, NULL, multi_profilingEvent[4]),
"failed in clEnqueueNDRangeKernel II");
for (i = 0;
i < (ocl_autotune_running ? 3 : (salt->rounds / HASH_LOOPS));
i++) {
BENCH_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], crypt_kernel, 1, NULL,
&gws, lws, 0, NULL, (ocl_autotune_running ?
multi_profilingEvent[split_events[i]] : NULL)), //1, 5, 6
"failed in clEnqueueNDRangeKernel");
HANDLE_CLERROR(clFinish(queue[gpu_id]),
"Error running loop kernel");
opencl_process_event();
}
BENCH_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], final_kernel, 1,
NULL, &gws, lws, 0, NULL, multi_profilingEvent[5]),
"failed in clEnqueueNDRangeKernel III");
} else
BENCH_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], crypt_kernel, 1,
NULL, &gws, lws, 0, NULL, multi_profilingEvent[1]),
"failed in clEnqueueNDRangeKernel");
//Read back hashes
BENCH_CLERROR(clEnqueueReadBuffer(queue[gpu_id], hash_buffer, CL_FALSE, 0,
sizeof(sha256_hash) * gws, computed_hash, 0, NULL,
multi_profilingEvent[2]), "failed in reading data back");
//Do the work
BENCH_CLERROR(clFinish(queue[gpu_id]), "failed in clFinish");
new_keys = 0;
//Build calculated hash list according to original plaintext list order.
for (index = 0; index < count; index++)
memcpy(calculated_hash[indices[index]].v, computed_hash[index].v,
BINARY_SIZE);
return count;
}
/* ------- Binary Hash functions group ------- */
static int get_hash_0(int index)
{
return calculated_hash[index].v[0] & PH_MASK_0;
}
static int get_hash_1(int index)
{
return calculated_hash[index].v[0] & PH_MASK_1;
}
static int get_hash_2(int index)
{
return calculated_hash[index].v[0] & PH_MASK_2;
}
static int get_hash_3(int index)
{
return calculated_hash[index].v[0] & PH_MASK_3;
}
static int get_hash_4(int index)
{
return calculated_hash[index].v[0] & PH_MASK_4;
}
static int get_hash_5(int index)
{
return calculated_hash[index].v[0] & PH_MASK_5;
}
static int get_hash_6(int index)
{
return calculated_hash[index].v[0] & PH_MASK_6;
}
static unsigned int iteration_count(void *salt)
{
sha256_salt *sha256crypt_salt;
sha256crypt_salt = salt;
return (unsigned int)sha256crypt_salt->rounds;
}
/* ------- Format structure ------- */
struct fmt_main fmt_opencl_cryptsha256 = {
{
FORMAT_LABEL,
FORMAT_NAME,
ALGORITHM_NAME,
BENCHMARK_COMMENT,
BENCHMARK_LENGTH,
0,
PLAINTEXT_LENGTH,
BINARY_SIZE,
BINARY_ALIGN,
SALT_SIZE,
SALT_ALIGN,
MIN_KEYS_PER_CRYPT,
MAX_KEYS_PER_CRYPT,
FMT_CASE | FMT_8_BIT,
{
"iteration count",
},
{ FORMAT_TAG },
tests
}, {
init,
done,
reset,
fmt_default_prepare,
valid,
fmt_default_split,
get_binary,
get_salt,
{
iteration_count,
},
fmt_default_source,
{
fmt_default_binary_hash_0,
fmt_default_binary_hash_1,
fmt_default_binary_hash_2,
fmt_default_binary_hash_3,
fmt_default_binary_hash_4,
fmt_default_binary_hash_5,
fmt_default_binary_hash_6
},
salt_hash,
NULL,
set_salt,
set_key,
get_key,
fmt_default_clear_keys,
crypt_all,
{
get_hash_0,
get_hash_1,
get_hash_2,
get_hash_3,
get_hash_4,
get_hash_5,
get_hash_6
},
cmp_all,
cmp_one,
cmp_exact
}
};
#endif /* plugin stanza */
#endif /* HAVE_OPENCL */
|
the_stack_data/30631.c | int main() {
int x;
while (x > 0) {
x--;
}
}
|
the_stack_data/95451388.c | #include <stdio.h>
#include <stdlib.h>
int main()
{
/*
A void pointer is used to refer to ANY ADDRESS TYPE in memory and has a declaration that looks like:
void *ptr;
*/
//The following program uses the same pointer for three different data types:
int x = 33;
float y = 12.4;
char c = 'a';
void *ptr;
ptr = &x;
printf("void ptr points to %d\n", *((int *)ptr));
ptr = &y;
printf("void ptr points to %4.2f\n", *((float *)ptr));
ptr = &c;
printf("void ptr points to %c", *((char *)ptr));
return 0;
}
|
the_stack_data/1228530.c | // This is a simple loop that sums elements of an input array and
// returns the result. It's here mainly because it's one of the
// simple examples guiding the early Subzero design.
int simple_loop(int *a, int n) {
int sum = 0;
for (int i = 0; i < n; ++i)
sum += a[i];
return sum;
}
|
the_stack_data/451217.c | int main() {
int a;
int b;
a = 3;
b = a;
return b;
}
|
the_stack_data/95450000.c | #include <stdio.h>
#include <stdlib.h>
int power(int m, int n)
{
if(n > 0)
{
return m * power(m, n-1);
}
else if (n == 0)
{
return 1;
}
else
{
exit(-1);
}
}
int main()
{
int m, n;
scanf("%d %d", &m, &n);
printf("%d ^ %d = %d", m, n, power(m, n));
return 0;
} |
the_stack_data/139008.c | #ifdef AUTOWAN_ENABLE
#include <stdio.h>
#include <string.h>
#include<unistd.h>
#include <stdlib.h>
#include<errno.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include "autowan.h"
#include "ansc_wrapper_base.h"
#include "cm_hal.h"
#include "gw_prov_ethwan.h"
#include "ccsp_hal_ethsw.h"
#include <sysevent/sysevent.h>
#include <syscfg/syscfg.h>
#ifdef FEATURE_SUPPORT_RDKLOG
#include "rdk_debug.h"
#endif
#define TRUE 1
#define FALSE 0
#define BOOL char
//#define _SIMULATE_PC_
#define AUTO_WAN_LOG GWPROVETHWANLOG
//#define AUTO_WAN_LOG printf
#define WAN_MODE_AUTO 0
#define WAN_MODE_ETH 1
#define WAN_MODE_DOCSIS 2
#define WAN_MODE_UNKNOWN 3
#define AUTOWAN_RETRY_CNT 3
#define AUTOWAN_RETRY_INTERVAL 80 /* TBD */
/*#define MAC_ADDR_LEN 6
typedef struct mac_addr
{
char hw[ MAC_ADDR_LEN ];
} macaddr_t; */
int g_CurrentWanMode = 0;
int g_LastKnowWanMode = 0;
int g_SelectedWanMode = 0;
int g_AutoWanRetryCnt = 0;
int g_AutoWanRetryInterval = 0;
#if defined (_BRIDGE_UTILS_BIN_)
int g_OvsEnable = 0;
#endif
void SetCurrentWanMode(int mode);
void ManageWanModes(int mode);
void IntializeAutoWanConfig();
int GetCurrentWanMode();
int GetSelectedWanMode();
int GetLastKnownWanMode();
void CheckAltWan();
void CheckWanModeLocked();
void* WanMngrThread(void * arg);
void SelectedWanMode(int mode);
void SetLastKnownWanMode(int mode);
void HandleAutoWanMode(void);
void TryAltWan(int *mode);
int CheckWanStatus();
int CheckWanConnection(int mode);
void RevertTriedConfig(int mode);
void AutoWan_BkupAndReboot();
int
CosaDmlEthWanSetEnable
(
BOOL bEnable
);
char* WanModeStr(int WanMode)
{
if(WanMode == WAN_MODE_AUTO)
{
return "WAN_MODE_AUTO";
}
if(WanMode == WAN_MODE_ETH)
{
return "WAN_MODE_ETH";
}
if(WanMode == WAN_MODE_DOCSIS)
{
return "WAN_MODE_DOCSIS";
}
if(WanMode == WAN_MODE_UNKNOWN)
{
return "WAN_MODE_UNKNOWN";
}
return "";
}
void LogWanModeInfo()
{
AUTO_WAN_LOG("CurrentWanMode - %s\n",WanModeStr(g_CurrentWanMode));
AUTO_WAN_LOG("SelectedWanMode - %s\n",WanModeStr(g_SelectedWanMode));
AUTO_WAN_LOG("LastKnowWanMode - %s\n",WanModeStr(g_LastKnowWanMode));
}
void AutoWAN_main()
{
int thread_status = 0;
static pthread_t AutoWAN_tid;
IntializeAutoWanConfig();
#if defined (_BRIDGE_UTILS_BIN_)
char buf[ 8 ] = { 0 };
if( 0 == syscfg_get( NULL, "mesh_ovs_enable", buf, sizeof( buf ) ) )
{
if ( strcmp (buf,"true") == 0 )
g_OvsEnable = 1;
else
g_OvsEnable = 0;
}
else
{
AUTO_WAN_LOG("syscfg_get failed to retrieve ovs_enable\n");
}
#endif
thread_status = pthread_create(&AutoWAN_tid, NULL, WanMngrThread, NULL);
if (thread_status == 0)
{
AUTO_WAN_LOG("WanMngrThread thread created successfully\n");
}
else
{
AUTO_WAN_LOG("%s error occured while creating WanMngrThread thread\n", strerror(errno));
}
}
void IntializeAutoWanConfig()
{
AUTO_WAN_LOG("%s\n",__FUNCTION__);
g_CurrentWanMode = WAN_MODE_UNKNOWN;
g_LastKnowWanMode = WAN_MODE_ETH;//WAN_MODE_UNKNOWN;
g_SelectedWanMode = WAN_MODE_AUTO;
g_AutoWanRetryCnt = AUTOWAN_RETRY_CNT;
g_AutoWanRetryInterval = AUTOWAN_RETRY_INTERVAL;
char out_value[20];
int outbufsz = sizeof(out_value);
memset(out_value,0,sizeof(out_value));
if (!syscfg_get(NULL, "selected_wan_mode", out_value, outbufsz))
{
g_SelectedWanMode = atoi(out_value);
AUTO_WAN_LOG("AUTOWAN %s Selected WAN mode = %s\n",__FUNCTION__,WanModeStr(g_SelectedWanMode));
}
else
{
SelectedWanMode(WAN_MODE_ETH);
AUTO_WAN_LOG("AUTOWAN %s AUTOWAN is not enabled, Selected WAN mode - %s\n",__FUNCTION__,WanModeStr(g_SelectedWanMode));
}
SetCurrentWanMode(WAN_MODE_UNKNOWN);
LogWanModeInfo();
}
int GetCurrentWanMode()
{
return g_CurrentWanMode;
}
void SetCurrentWanMode(int mode)
{
char buf[8];
memset(buf, 0, sizeof(buf));
g_CurrentWanMode = mode;
AUTO_WAN_LOG("%s Set Current WanMode = %s\n",__FUNCTION__, WanModeStr(g_CurrentWanMode));
snprintf(buf, sizeof(buf), "%d", g_CurrentWanMode);
if (syscfg_set(NULL, "curr_wan_mode", buf) != 0)
{
AUTO_WAN_LOG("syscfg_set failed for curr_wan_mode\n");
}
else
{
if (syscfg_commit() != 0)
{
AUTO_WAN_LOG("syscfg_commit failed for curr_wan_mode\n");
}
}
}
int GetSelectedWanMode()
{
return g_SelectedWanMode;
}
void SelectedWanMode(int mode)
{
char buf[8];
g_SelectedWanMode = mode;
AUTO_WAN_LOG("%s Set SelectedWanMode = %s\n",__FUNCTION__, WanModeStr(g_SelectedWanMode));
memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), "%d", mode);
if (syscfg_set(NULL, "selected_wan_mode", buf) != 0)
{
AUTO_WAN_LOG("syscfg_set failed for curr_wan_mode\n");
}
else
{
if (syscfg_commit() != 0)
{
AUTO_WAN_LOG("syscfg_commit failed for curr_wan_mode\n");
}
}
}
int GetLastKnownWanMode()
{
return g_LastKnowWanMode;
}
void SetLastKnownWanMode(int mode)
{
char buf[8];
g_LastKnowWanMode = mode;
AUTO_WAN_LOG("%s Set Last Known WanMode = %s\n",__FUNCTION__, WanModeStr(g_LastKnowWanMode));
memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), "%d", mode);
if (syscfg_set(NULL, "last_wan_mode", buf) != 0)
{
AUTO_WAN_LOG("syscfg_set failed for last_wan_mode\n");
}
else
{
if (syscfg_commit() != 0)
{
AUTO_WAN_LOG("syscfg_commit failed for last_wan_mode\n");
}
}
}
void* WanMngrThread(void* arg)
{
UNREFERENCED_PARAMETER(arg);
AUTO_WAN_LOG("%s\n",__FUNCTION__);
pthread_detach(pthread_self());
AUTO_WAN_LOG("%s Check if AutoWan is Enabled\n",__FUNCTION__);
switch (GetSelectedWanMode())
{
case WAN_MODE_AUTO:
AUTO_WAN_LOG("Auto WAN Mode is enabled, try Last known WAN mode\n");
HandleAutoWanMode();
break;
case WAN_MODE_ETH:
AUTO_WAN_LOG("Booting-Up in SelectedWanMode - %s\n",WanModeStr(GetSelectedWanMode()));
SetLastKnownWanMode(WAN_MODE_ETH);
SetCurrentWanMode(WAN_MODE_ETH);
#if defined(INTEL_PUMA7)
system("cmctl down");
#endif
#ifdef _SIMULATE_PC_
system("killall udhcpc");
system("udhcpc -i eth1 &");
#endif
break;
case WAN_MODE_DOCSIS:
AUTO_WAN_LOG("Booting-Up in SelectedWanMode - %s\n",WanModeStr(GetSelectedWanMode()));
SetLastKnownWanMode(WAN_MODE_DOCSIS);
SetCurrentWanMode(WAN_MODE_DOCSIS);
#ifdef _SIMULATE_PC_
system("killall udhcpc");
system("udhcpc -i eth2 &");
#endif
break;
default: AUTO_WAN_LOG("This is not expected, setting WAN mode to Auto\n");
SelectedWanMode(WAN_MODE_AUTO);
HandleAutoWanMode();
break;
}
return NULL;
}
void HandleAutoWanMode(void)
{
AUTO_WAN_LOG("%s\n",__FUNCTION__);
if(WAN_MODE_UNKNOWN == GetLastKnownWanMode())
{
AUTO_WAN_LOG("Last known WAN mode is Unknown\n");
}
switch (GetLastKnownWanMode())
{
case WAN_MODE_ETH:
AUTO_WAN_LOG("Booting-Up in Last known WanMode - %s\n",WanModeStr(GetLastKnownWanMode()));
#ifdef _SIMULATE_PC_
system("killall udhcpc");
system("udhcpc -i eth1 &");
#endif
ManageWanModes(WAN_MODE_ETH);
break;
case WAN_MODE_DOCSIS:
AUTO_WAN_LOG("Booting-Up in Last known WanMode - %s\n",WanModeStr(GetLastKnownWanMode()));
#ifdef _SIMULATE_PC_
system("killall udhcpc");
system("udhcpc -i eth2 &");
#endif
ManageWanModes(WAN_MODE_DOCSIS);
break;
case WAN_MODE_UNKNOWN:
AUTO_WAN_LOG("Booting-Up in Last known WanMode - %s\n",WanModeStr(GetLastKnownWanMode()));
#ifdef _SIMULATE_PC_
system("killall udhcpc");
system("udhcpc -i eth2 &");
#endif
ManageWanModes(WAN_MODE_DOCSIS);
break;
default: AUTO_WAN_LOG("This is not expected, setting WAN mode to Auto\n");
SelectedWanMode(WAN_MODE_AUTO);
ManageWanModes(WAN_MODE_DOCSIS);
break;
}
}
void ManageWanModes(int mode)
{
int try_mode = mode;
int ret = 0;
while(1)
{
ret = CheckWanConnection(try_mode);
if(ret == 1)
{
SetLastKnownWanMode(try_mode);
SetCurrentWanMode(try_mode);
if(try_mode == mode)
{
AUTO_WAN_LOG("%s - WanMode %s is Locked, Set Current operational mode, reboot is not required, CheckWanConnection=%d\n",__FUNCTION__,WanModeStr(mode),ret);
#if defined(INTEL_PUMA7)
if(try_mode == WAN_MODE_ETH)
{
AUTO_WAN_LOG("%s - Shutting down DOCSIS\n", __FUNCTION__);
system("cmctl down");
}
#endif
} // try_mode == mode
else
{
AUTO_WAN_LOG("%s - WanMode %s is Locked, Set Current operational mode, rebooting... \n",__FUNCTION__,WanModeStr(try_mode));
AutoWan_BkupAndReboot();
}
break;
} // ret == 1
else if(ret == 2)
{
SetLastKnownWanMode(mode);
SetCurrentWanMode(mode);
AUTO_WAN_LOG("%s - WanMode %s is Locked, Set Current operational mode, reboot is not required, CheckWanConnection=%d\n",__FUNCTION__,WanModeStr(mode),ret);
#if defined(INTEL_PUMA7)
if(try_mode == WAN_MODE_ETH)
{
AUTO_WAN_LOG("%s - Shutting down DOCSIS\n", __FUNCTION__);
system("cmctl down");
}
#endif
RevertTriedConfig(mode);
break;
} // ret == 2
else
{
TryAltWan(&try_mode);
}
} // while(1)
}
int CheckWanConnection(int mode)
{
int retry = 0;
int WanLocked = 0;
int ret = 0;
while(retry < AUTOWAN_RETRY_CNT)
{
retry++;
sleep(AUTOWAN_RETRY_INTERVAL);
ret = CheckWanStatus(mode);
if(ret == 1)
{
AUTO_WAN_LOG("%s - Trying %s retry count %d\n",__FUNCTION__,WanModeStr(mode),retry);
}
else if(ret == 2)
{
AUTO_WAN_LOG("%s - WanMode %s is Locked %d\n",__FUNCTION__,WanModeStr(GetLastKnownWanMode()),retry);
WanLocked = 2;
break;
}
else
{
AUTO_WAN_LOG("%s - WanMode %s is Locked\n",__FUNCTION__,WanModeStr(mode));
WanLocked = 1;
break;
}
}
return WanLocked;
}
extern int sysevent_fd_gs;
extern token_t sysevent_token_gs;
// For Gw_prov_ethwan : Ethwan running mode
int CheckWanStatus(int mode)
{
char buff[256] = {0};
char command[256] = {0};
char wan_connection_ifname[ETHWAN_INTERFACE_NAME_MAX_LENGTH] = {0};
FILE *fp;
sysevent_get(sysevent_fd_gs, sysevent_token_gs, "current_wan_state", buff, sizeof(buff));
if (!strcmp(buff, "up")) {
if(mode == WAN_MODE_ETH)
{
memset(buff,0,sizeof(buff));
syscfg_get(NULL, "wan_physical_ifname", buff, sizeof(buff));
AUTO_WAN_LOG("%s - syscfg returned wan_physical_ifname= %s\n",__FUNCTION__,buff);
if(0 != strnlen(buff,sizeof(buff)))
{
snprintf(wan_connection_ifname, sizeof(wan_connection_ifname), "%s", buff);
}
else
{
snprintf(wan_connection_ifname, sizeof(wan_connection_ifname), "%s", WAN_PHY_NAME);
}
AUTO_WAN_LOG("%s - wan_connection_ifname= %s\n",__FUNCTION__,wan_connection_ifname);
/* Validate IPv4 Connection on ETHWAN interface */
memset(command,0,sizeof(command));
snprintf(command, sizeof(command), "ifconfig %s |grep -i 'inet ' |awk '{print $2}' |cut -f2 -d:", wan_connection_ifname);
memset(buff,0,sizeof(buff));
/* Open the command for reading. */
fp = popen(command, "r");
if (fp == NULL)
{
printf("<%s>:<%d> Error popen\n", __FUNCTION__, __LINE__);
}
else
{
/* Read the output a line at a time - output it. */
if (fgets(buff, 50, fp) != NULL)
{
printf("IP :%s", buff);
}
/* close */
pclose(fp);
if(buff[0] != 0)
{
return 2; // Shirish To-Do // Call validate IP function for GLOBAL IP check
}
} // fp == NULL
/* Validate IPv6 Connection on ETHWAN interface */
memset(command,0,sizeof(command));
snprintf(command,sizeof(command), "ifconfig %s |grep -i 'inet6 ' |grep -i 'Global' |awk '{print $3}'", wan_connection_ifname);
memset(buff,0,sizeof(buff));
/* Open the command for reading. */
fp = popen(command, "r");
if (fp == NULL)
{
printf("<%s>:<%d> Error popen\n", __FUNCTION__, __LINE__);
}
else
{
/* Read the output a line at a time - output it. */
if (fgets(buff, 50, fp) != NULL)
{
printf("IP :%s", buff);
}
/* close */
pclose(fp);
if(buff[0] != 0)
{
return 2;
}
} // fp == NULL)
return 1;
} /* (mode == WAN_MODE_ETH)*/
} /* (!strcmp(buff, "up"))*/
if(mode == WAN_MODE_DOCSIS)
{
/* TODO - RDKB Needs to make this a generic design for devices with DOCSIS interface on Host Processor and devices where it's on the PEER Processor */
/* DOCSIS on PEER Processor */
#if defined(INTEL_PUMA7)
char *found = NULL;
int ret = 0;
/* Get DOCSIS Connection CMStatus */
ret = docsis_getCMStatus(buff);
if( ret == RETURN_ERR )
{
AUTO_WAN_LOG("AUTOWAN failed to get CMStatus\n");
return 1;
}
/* Validate DOCSIS Connection CMStatus */
AUTO_WAN_LOG("%s - CM Status = %s\n", __FUNCTION__, buff);
found = strstr(buff, "OPERATIONAL");
if(found)
{
AUTO_WAN_LOG("AUTOWAN DOCSIS wan locked\n");
return 0;
}
else
{
AUTO_WAN_LOG("AUTOWAN DOCSIS wan not locked\n");
return 1;
}
#else
/* DOCSIS on HOST Processor */
/* Validate IPv4 Connection on DOCSIS interface */
snprintf(command,sizeof(command), "ifconfig %s |grep -i 'inet ' |awk '{print $2}' |cut -f2 -d:", DOCSIS_INF_NAME);
memset(buff,0,sizeof(buff));
/* Open the command for reading. */
fp = popen(command, "r");
if (fp == NULL)
{
printf("<%s>:<%d> Error popen\n", __FUNCTION__, __LINE__);
}
else
{
/* Read the output a line at a time - output it. */
if (fgets(buff, 50, fp) != NULL)
{
printf("IP :%s", buff);
}
/* close */
pclose(fp);
if(buff[0] != 0)
{
return 0; // Shirish To-Do // Call validate IP function for GLOBAL IP check
}
} // fp == NULL
/* Validate IPv6 Connection on DOCSIS interface */
memset(command,0,sizeof(command));
snprintf(command,sizeof(command), "ifconfig %s |grep -i 'inet6 ' |grep -i 'Global' |awk '{print $3}'", DOCSIS_INF_NAME);
memset(buff,0,sizeof(buff));
/* Open the command for reading. */
fp = popen(command, "r");
if (fp == NULL)
{
printf("<%s>:<%d> Error popen\n", __FUNCTION__, __LINE__);
}
else
{
/* Read the output a line at a time - output it. */
if (fgets(buff, 256, fp) != NULL)
{
printf("IP :%s", buff);
}
/* close */
pclose(fp);
if(buff[0] != 0)
{
return 0;
}
} // fp == NULL
#endif
} // mode == WAN_MODE_DOCSIS
return 1;
}
void TryAltWan(int *mode)
{
char pRfSignalStatus = 0;
#if !defined(AUTO_WAN_ALWAYS_RECONFIG_EROUTER) || defined(_COSA_BCM_ARM_)
char command[64] = {0};
#endif
#if !defined(AUTO_WAN_ALWAYS_RECONFIG_EROUTER)
char wanPhyName[20] = {0};
char out_value[20] = {0};
syscfg_get(NULL, "wan_physical_ifname", out_value, sizeof(out_value));
AUTO_WAN_LOG("%s - syscfg returned wan_physical_ifname= %s\n",__FUNCTION__,out_value);
if(0 != strnlen(out_value,sizeof(out_value)))
{
snprintf(wanPhyName, sizeof(wanPhyName), "%s", out_value);
}
else
{
snprintf(wanPhyName, sizeof(wanPhyName), "%s", WAN_PHY_NAME);
}
#endif
if(*mode == WAN_MODE_DOCSIS)
{
*mode = WAN_MODE_ETH;
CosaDmlEthWanSetEnable(TRUE);
#if !defined(AUTO_WAN_ALWAYS_RECONFIG_EROUTER)
char ethwan_ifname[ETHWAN_INTERFACE_NAME_MAX_LENGTH] = {0};
if ( (0 != GWP_GetEthWanInterfaceName(ethwan_ifname, sizeof(ethwan_ifname)))
|| (0 == strnlen(ethwan_ifname,sizeof(ethwan_ifname)))
|| (0 == strncmp(ethwan_ifname,"disable",sizeof(ethwan_ifname)))
)
{
/* Fallback case needs to set it default */
snprintf(ethwan_ifname ,sizeof(ethwan_ifname), "%s", ETHWAN_INF_NAME);
}
AUTO_WAN_LOG("%s - mode= %s ethwan_ifname= %s, wanPhyName= %s\n",__FUNCTION__,WanModeStr(WAN_MODE_ETH),ethwan_ifname,wanPhyName);
#if defined (_BRIDGE_UTILS_BIN_)
if ( syscfg_set( NULL, "eth_wan_iface_name", ethwan_ifname ) != 0 )
{
AUTO_WAN_LOG( "syscfg_set failed for eth_wan_iface_name\n" );
}
else
{
if ( syscfg_commit() != 0 )
{
AUTO_WAN_LOG( "syscfg_commit failed for eth_wan_iface_name\n" );
}
}
#endif
#if defined (_BRIDGE_UTILS_BIN_)
if (g_OvsEnable)
{
snprintf(command,sizeof(command),"/usr/bin/bridgeUtils del-port brlan0 %s",ethwan_ifname);
}
else
{
snprintf(command,sizeof(command),"brctl delif brlan0 %s",ethwan_ifname);
}
#else
snprintf(command,sizeof(command),"brctl delif brlan0 %s",ethwan_ifname);
#endif
system(command);
// system("brctl delif brlan0 eth3");
#if defined(_COSA_BCM_ARM_)
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"brctl addif %s %s",wanPhyName, DOCSIS_INF_NAME);
system(command);
// system("brctl addif erouter0 cm0");
#endif
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"udhcpc -i %s &",ethwan_ifname);
system(command);
// system("rm -rf /tmp/wan_locked; udhcpc -i eth3 &");
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"sysctl -w net.ipv6.conf.%s.accept_ra=2",ethwan_ifname);
system(command);
// system("sysctl -w net.ipv6.conf.eth3.accept_ra=2");
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"udhcpc -i %s &",ethwan_ifname);
system(command);
// system("udhcpc -i eth3 &");
system("killall udhcpc");
#endif
} // *mode == WAN_MODE_DOCSIS
else
{
#if defined(INTEL_PUMA7)
AUTO_WAN_LOG("%s - Bringing Up DOCSIS\n", __FUNCTION__);
system("cmctl up");
#endif
if(RETURN_ERR == docsis_IsEnergyDetected(&pRfSignalStatus)) {
AUTO_WAN_LOG("AUTOWAN Failed to get RfSignalStatus \n");
}
if(pRfSignalStatus == 0)
{
AUTO_WAN_LOG("%s - Trying Alternet WanMode - %s\n",__FUNCTION__,WanModeStr(WAN_MODE_DOCSIS));
AUTO_WAN_LOG("%s - Alternet WanMode - %s not present\n",__FUNCTION__,WanModeStr(WAN_MODE_DOCSIS));
return ;
}
AUTO_WAN_LOG("AUTOWAN- %s Dosis present - %d\n",__FUNCTION__,pRfSignalStatus);
*mode = WAN_MODE_DOCSIS;
CosaDmlEthWanSetEnable(FALSE);
#if !defined(AUTO_WAN_ALWAYS_RECONFIG_EROUTER)
system("killall udhcpc");
#if defined(_COSA_BCM_ARM_)
AUTO_WAN_LOG("%s - mode= %s wanPhyName= %s\n",__FUNCTION__,WanModeStr(WAN_MODE_DOCSIS),wanPhyName);
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"brctl delif %s %s",wanPhyName, DOCSIS_INF_NAME);
system(command);
//system("brctl delif erouter0 cm0");
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"udhcpc -i %s &",DOCSIS_INF_NAME);
system(command);
//system("/tmp/wan_locked; udhcpc -i cm0 &");
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"sysctl -w net.ipv6.conf.%s.accept_ra=2",DOCSIS_INF_NAME);
system(command);
//system("sysctl -w net.ipv6.conf.cm0.accept_ra=2");
// system("udhcpc -i cm0 &");
#endif
#endif
}
AUTO_WAN_LOG("%s - Trying Alternet WanMode - %s\n",__FUNCTION__,WanModeStr(*mode));
}
void RevertTriedConfig(int mode)
{
char command[64];
memset(command,0,sizeof(command));
char ethwan_ifname[ETHWAN_INTERFACE_NAME_MAX_LENGTH] = {0};
if(mode == WAN_MODE_DOCSIS)
{
if ( (0 != GWP_GetEthWanInterfaceName(ethwan_ifname, sizeof(ethwan_ifname)))
|| (0 == strnlen(ethwan_ifname,sizeof(ethwan_ifname)))
|| (0 == strncmp(ethwan_ifname,"disable",sizeof(ethwan_ifname)))
)
{
/* Fallback case needs to set it default */
snprintf(ethwan_ifname ,sizeof(ethwan_ifname), "%s", ETHWAN_INF_NAME);
}
AUTO_WAN_LOG("%s - ethwan_ifname= %s\n",__FUNCTION__,ethwan_ifname);
#if defined (_BRIDGE_UTILS_BIN_)
if ( syscfg_set( NULL, "eth_wan_iface_name", ethwan_ifname ) != 0 )
{
AUTO_WAN_LOG( "syscfg_set failed for eth_wan_iface_name\n" );
}
else
{
if ( syscfg_commit() != 0 )
{
AUTO_WAN_LOG( "syscfg_commit failed for eth_wan_iface_name\n" );
}
}
#endif
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"ifconfig %s down",ethwan_ifname);
system(command);
//system("ifconfig eth3 down");
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"ip addr flush dev %s",ethwan_ifname);
system(command);
//system("ip addr flush dev eth3");
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"ip -6 addr flush dev %s",ethwan_ifname);
system(command);
//system("ip -6 addr flush dev eth3");
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"sysctl -w net.ipv6.conf.%s.accept_ra=0",ethwan_ifname);
system(command);
//system("sysctl -w net.ipv6.conf.eth3.accept_ra=0");
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"ifconfig %s up",ethwan_ifname);
system(command);
//system("ifconfig eth3 up");
memset(command,0,sizeof(command));
#if defined (_BRIDGE_UTILS_BIN_)
if (g_OvsEnable)
{
snprintf(command,sizeof(command),"/usr/bin/bridgeUtils add-port brlan0 %s",ethwan_ifname);
}
else
{
snprintf(command,sizeof(command),"brctl addif brlan0 %s",ethwan_ifname);
}
#else
snprintf(command,sizeof(command),"brctl addif brlan0 %s",ethwan_ifname);
#endif
system(command);
//system("brctl addif brlan0 eth3");
#if defined(_COSA_BCM_ARM_)
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"brctl addif erouter0 %s",DOCSIS_INF_NAME);
system(command);
//system("brctl addif erouter0 cm0");
#endif
}
else
{
#if defined(_COSA_BCM_ARM_)
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"ip addr flush dev %s",DOCSIS_INF_NAME);
system(command);
//system("ip addr flush dev cm0");
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"ip -6 addr flush dev %s",DOCSIS_INF_NAME);
system(command);
//system("ip -6 addr flush dev cm0");
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"sysctl -w net.ipv6.conf.%s.accept_ra=0",DOCSIS_INF_NAME);
system(command);
//system("sysctl -w net.ipv6.conf.cm0.accept_ra=0");
memset(command,0,sizeof(command));
snprintf(command,sizeof(command),"brctl addif erouter0 %s",DOCSIS_INF_NAME);
system(command);
//system("brctl addif erouter0 cm0");
#endif
}
}
int
CosaDmlEthWanSetEnable
(
BOOL bEnable
)
{
#if ((defined (_COSA_BCM_ARM_) && !defined(_CBR_PRODUCT_REQ_) && !defined(_PLATFORM_RASPBERRYPI_) && !defined(_PLATFORM_TURRIS_)) || defined(INTEL_PUMA7) || defined(_CBR2_PRODUCT_REQ_))
//BOOL bGetStatus = FALSE;
//CcspHalExtSw_getEthWanEnable(&bGetStatus);
//if (bEnable != bGetStatus)
#if !defined(AUTO_WAN_ALWAYS_RECONFIG_EROUTER)
{
char command[64] = {0};
if(bEnable == FALSE)
{
system("ifconfig erouter0 down");
snprintf(command,sizeof(command),"ip link set erouter0 name %s",ETHWAN_INF_NAME);
system(command);
system("ip link set dummy-rf name erouter0");
system("ifconfig eth0 up;ifconfig erouter0 up");
}
}
#endif
CcspHalExtSw_setEthWanPort ( ETHWAN_DEF_INTF_NUM );
if ( RETURN_OK == CcspHalExtSw_setEthWanEnable( bEnable ) )
{
//pthread_t tid;
char buf[ 8 ];
memset( buf, 0, sizeof( buf ) );
snprintf( buf, sizeof( buf ), "%s", bEnable ? "true" : "false" );
if(bEnable)
{
system("touch /nvram/ETHWAN_ENABLE");
}
else
{
system("rm /nvram/ETHWAN_ENABLE");
}
if ( syscfg_set( NULL, "eth_wan_enabled", buf ) != 0 )
{
AUTO_WAN_LOG( "syscfg_set failed for eth_wan_enabled\n" );
return RETURN_ERR;
}
else
{
if ( syscfg_commit() != 0 )
{
AUTO_WAN_LOG( "syscfg_commit failed for eth_wan_enabled\n" );
return RETURN_ERR;
}
}
}
return RETURN_OK;
#else
return RETURN_ERR;
#endif /* (defined (_COSA_BCM_ARM_) && !defined(_CBR_PRODUCT_REQ_)) */
}
void AutoWan_BkupAndReboot()
{
/* Set the reboot reason */
char buf[8];
snprintf(buf,sizeof(buf),"%d",1);
//OnboardLog("Device reboot due to reason WAN_Mode_Change\n");
if (syscfg_set(NULL, "X_RDKCENTRAL-COM_LastRebootReason", "WAN_Mode_Change") != 0)
{
AUTO_WAN_LOG("RDKB_REBOOT : RebootDevice syscfg_set failed GUI\n");
}
else
{
if (syscfg_commit() != 0)
{
AUTO_WAN_LOG("RDKB_REBOOT : RebootDevice syscfg_commit failed for ETHWAN mode\n");
}
}
if (syscfg_set(NULL, "X_RDKCENTRAL-COM_LastRebootCounter", buf) != 0)
{
AUTO_WAN_LOG("syscfg_set failed\n");
}
else
{
if (syscfg_commit() != 0)
{
AUTO_WAN_LOG("syscfg_commit failed\n");
}
}
/* Need to do reboot the device here */
system("dmcli eRT setv Device.X_CISCO_COM_DeviceControl.RebootDevice string Device");
}
#endif
|
the_stack_data/57950043.c | #include<stdio.h>
int main()
{
int a;
printf("enter year \n");
scanf("%d", &a);
if(a%4 == 0 && a%400 == 0)
printf("leap year");
else if(a%4 == 0 && a%100 == 0 && a%400 != 0)
printf("normal year");
else if(a%4 == 0 && a%100 != 0)
printf("leap year");
else
printf("normal year");
}
|
the_stack_data/847506.c | #include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <netinet/in.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/utsname.h>
#define PORT 6660
#define MAX_CLIENTS 10
#define MAX_SOCKETS MAX_CLIENTS+5
#define PACKET_SIZE 1024
int flags [MAX_SOCKETS];
int blocks [MAX_SOCKETS];
char nicknames [MAX_SOCKETS][PACKET_SIZE];
int used_fds[MAX_SOCKETS];
int partners[MAX_SOCKETS];
int data_use[MAX_SOCKETS];
int running = 0;
int init = 0;
int reset_partners(int id_quitting)
{
partners[partners[id_quitting]] = 0;
partners[id_quitting] = 0;
data_use[partners[id_quitting]] = 0;
data_use[id_quitting] = 0;
return 0;
}
int handle_disconnect(int i)
{
char str2[PACKET_SIZE];
int n;
// Disconnect their partner
sprintf(str2, "/PARTYour partner has disconnected from the server. You will return to the queue.\n");
n = write(partners[i], str2, strlen(str2));
if(n < 0)
{ perror("Error writing to client"); return(1); }
used_fds[partners[i]] = 1;
used_fds[i] = 0;
blocks[i] = 0;
flags[i] = 0;
reset_partners(i);
return 0;
}
/*
sendToClient uses the fd appended to the beginning of
messages to find who the message should be sent to
*/
int sendToClient(char *message, int id)
{
/* char fd_id [5];
char stripped_message [PACKET_SIZE-5];
memcpy(fd_id, &message[0], 4);
memcpy(stripped_message, &message[4], PACKET_SIZE-5);
fd_id[4] = '\0';
int id = strtoul(fd_id, NULL, 10);*/
if(strstr(message, "/CONN") != NULL ||
strstr(message, "/HELP") != NULL ||
strstr(message, "/QUIT") != NULL ||
strstr(message, "/CHAT") != NULL ||
strstr(message, "/FLAG") != NULL)
{
return 0;
}
if(partners[id] > 1)
{
int n = write(partners[id], message, strlen(message));
if(n < 0)
{
perror("Error writing to client");
exit(1);
}
return 1;
}
return 0;
}
// used_fds
// 1 is just connected
// 2 is waiting to find partner
// 3 is connected
int processConnect(char *message, int fd)//, int* used_fds)
{
int x;
int matched = 0;
for(x = 0; x < MAX_SOCKETS; x++)
{
if(blocks[fd] != 0)
break;
if(blocks[x] != 0)
continue;
if(x != fd && used_fds[x] == 2)
{
matched = 1;
int n;
char str[PACKET_SIZE-5];
char str2[PACKET_SIZE-5];
// Write to partner who triggered connection
sprintf(str, "%04d|%s", x, nicknames[x]);
n = write(fd, str, strlen(str));
if(n < 0)
{ perror("Error writing to client"); exit(1); }
used_fds[fd] = 3;
partners[fd] = x;
// Write to waiting partner who was first to connect
sprintf(str2, "%04d|%s", fd, nicknames[fd]);
n = write(x, str2, strlen(str2));
if(n < 0)
{ perror("Error writing to client"); exit(1); }
used_fds[x] = 3;
partners[x] = fd;
printf("Matched! Connecting %d and %d\n", x, fd);
break;
}
}
if(matched == 0)
{
printf("no match\n");
used_fds[fd] = 2; // 2 is fds waiting to find partners
}
return 0;
}
// fd is sending Client's number
int processCommand(char *message, int fd)//, int* used_fds)
{
printf("Processing command message from User %d\n", fd);
if(strstr(message, "/CHAT") != NULL)
{ processConnect(message, fd); }//, used_fds); }
else if(strstr(message, "/FLAG") != NULL)
{
// Flag fd's partner
/*char fd_id [5];
char stripped_message [PACKET_SIZE-5];
memcpy(fd_id, &message[0], 4);
memcpy(stripped_message, &message[4], PACKET_SIZE-5);
fd_id[4] = '\0';
int id = strtoul(fd_id, NULL, 10);*/
int id = partners[fd];
printf("User %d flagged by User %d\n", id, fd);
// check if the client being flagged is actually still conencted
if(used_fds[id] == 3)
{
printf("Flagging done\n");
flags[id] += 1; // Currently has no effect
}
}
else if(strstr(message, "/CONN") != NULL)
{
//char stripped_message [PACKET_SIZE-10];
//memcpy(stripped_message, &message[5], PACKET_SIZE-10);
//char fd_id [5];
//memcpy(fd_id, &message[0], 4);
//fd_id[4] = '\0';
//int id = strtoul(fd_id, NULL, 10);
memcpy(nicknames[fd], &message[5], strlen(message)-4);
char response[PACKET_SIZE];
bzero(response, PACKET_SIZE);
sprintf(response, "You are now connected as %s", nicknames[fd]);
int n = write(fd, response, strlen(response));
if(n < 0)
{ perror("Error ACKing nickname"); return 1; }
}
else if(strstr(message, "/HELP") != NULL)
{
char response[PACKET_SIZE];
bzero(response, PACKET_SIZE);
sprintf(response, "/HELP The server accepts the following commands:\n/CHAT to enter a chatroom\n/FLAG to report misbehavior by your partner\n/FILE path/to/file to begin transferring a file to your partner\n/QUIT to leave your chat.");
int n = write(fd, response, strlen(response));
if(n < 0)
{ perror("Error writing Help message to client"); return 1; }
}
else if(strstr(message, "/QUIT") != NULL)
{
int n;
/*char fd_id [5];
memcpy(fd_id, &message[0], 4);
fd_id[4] = '\0';
int id = strtoul(fd_id, NULL, 10);*/
int id = partners[fd];
char str[PACKET_SIZE];
char str2[PACKET_SIZE];
// Disconnect requester
sprintf(str, "/PARTYou have left from the chatroom. You will return to the queue.\n");
n = write(fd, str, strlen(str));
if(n < 0)
{ perror("Error writing quit to quitter"); return 1; }
used_fds[fd] = 1;
// Disconnect their partner
sprintf(str2, "/PARTYour partner has left from the chatroom. You will return to the queue.\n");
n = write(id, str2, strlen(str2));
if(n < 0)
{ perror("Error writing quit to partner"); return 1; }
used_fds[id] = 1;
reset_partners(fd);
}
else if(strstr(message, "/FILE") != NULL)
{
/*char fd_id [5];
char stripped_message [PACKET_SIZE-5];
bzero(stripped_message, PACKET_SIZE-5);
memcpy(fd_id, &message[0], 4);
memcpy(stripped_message, &message[4], PACKET_SIZE-5);
fd_id[4] = '\0';
int id = strtoul(fd_id, NULL, 10);*/
int id = partners[fd];
int n = write(id,message, strlen(message));
if(n < 0)
{ perror("Error writing to client"); exit(1); }
}
else if(strstr(message, "/ENDF") != NULL){
/*char fd_id [5];
char stripped_message [PACKET_SIZE-5];
bzero(stripped_message, PACKET_SIZE-5);
memcpy(fd_id, &message[0], 4);
memcpy(stripped_message, &message[4], PACKET_SIZE-5);
fd_id[4] = '\0';
int id = strtoul(fd_id, NULL, 10);*/
int id = partners[fd];
int n = write(id, message, strlen(message));
if(n < 0)
{ perror("Error writing to client"); exit(1); }
}
else
{
char response[PACKET_SIZE];
bzero(response, PACKET_SIZE);
sprintf(response, "Command not Found");
int n = write(fd, response, strlen(response));
if(n < 0)
{ perror("Error writing to client"); exit(1); }
}
// compare to keywords for connecting chats blocking people etc.
return 0;
}
int admin_commands(void *socket)
{
int * socket_fd = (int *)socket;
while(1)
{
// read user commands and parse them
char buffer[PACKET_SIZE];
bzero(buffer, PACKET_SIZE);
fgets(buffer, PACKET_SIZE-1, stdin);
if(strstr(buffer, "/STATS") != NULL)
{
FILE *fp;
fp = fopen("stats.txt", "w+b");
int x;
int sQueue = 0, sChat =0;
for(x = 0; x < MAX_SOCKETS; x++)
{
if(used_fds[x] == 2)
sQueue += 1;
else if(used_fds[x] == 3)
sChat += 1;
if(flags[x] != 0)
{
printf("User %d - %s has been flagged %d times.\n", x, nicknames[x], flags[x]);
fprintf(fp, "User %d - %s has been flagged %d times.\n", x, nicknames[x], flags[x]);
}
if(blocks[x] != 0)
{
printf("User %d - %s has been BLOCKED from entering chat.\n", x, nicknames[x]);
fprintf(fp, "User %d - %s has been BLOCKED from entering chat.\n", x, nicknames[x]);
}
if(partners[x]>0 && partners[x] > partners[partners[x]])
{
printf("ChatRoom with %s and %s data usage: %dbytes\n",nicknames[x], nicknames[partners[x]], (data_use[x]+data_use[partners[x]]) );
fprintf(fp, "ChatRoom with %s and %s data usage: %dbytes\n",nicknames[x], nicknames[partners[x]], (data_use[x]+data_use[partners[x]]) );
}
}
printf("%d users are in chat, and %d users are waiting in queue.\n", sChat, sQueue);
fprintf(fp, "%d users are in chat, and %d users are waiting in queue.\n", sChat, sQueue);
fclose(fp);
}
// takes a user's numerical ID
else if(strstr(buffer, "/BLOCK") != NULL)
{
char fd_id [5];
memcpy(fd_id, &buffer[0], 4);
fd_id[4] = '\0';
int id = strtoul(fd_id, NULL, 10);
if(id == 0 || id > MAX_SOCKETS)
perror("Invalid cient ID\n");
else
blocks[id] = 1;
}
// takes a user's numerical ID
else if(strstr(buffer, "/UNBLOCK") != NULL)
{
char fd_id [5];
memcpy(fd_id, &buffer[0], 4);
fd_id[4] = '\0';
int id = strtoul(fd_id, NULL, 10);
if(id == 0 || id > MAX_SOCKETS)
perror("Invalid cient ID\n");
else
blocks[id] = 0;
}
else if(strstr(buffer, "/THROW") != NULL)
{
int n;
char fd_id [5];
memcpy(fd_id, &buffer[7], 4);
fd_id[4] = '\0';
int id = strtoul(fd_id, NULL, 10);
int fd = partners[id];
char str[PACKET_SIZE];
char str2[PACKET_SIZE];
// Disconnect requester
sprintf(str, "/PARTYour Channel has been ended by the admin.\n");
n = write(fd, str, strlen(str));
if(n < 0)
{ perror("Error writing quit to quitter"); return 1; }
used_fds[fd] = 1;
// Disconnect their partner
sprintf(str2, "/PARTYour Channel has been ended by the admin.\n");
n = write(id, str2, strlen(str2));
if(n < 0)
{ perror("Error writing quit to partner"); return 1; }
used_fds[id] = 1;
reset_partners(id);
}
else if(strstr(buffer, "/START") != NULL)
{
if(running == 0)
beginServer();
else
printf("Server has already been started.\n");
}
else if(strstr(buffer, "/END") != NULL)
{
int id = 0;
char str[PACKET_SIZE];
for(id = 0; id < MAX_SOCKETS; id++) {
if(used_fds[id] == 2){
bzero(str, PACKET_SIZE);
sprintf(str, "You've been removed from the queue by the server.\n");
int n = write(id, str, strlen(str));
if(n < 0)
{ perror("Error writing quit to queue"); return 1; }
used_fds[id] = 1;
}
else if(used_fds[id] == 3){
bzero(str, PACKET_SIZE);
sprintf(str, "/PARTYour Channel has been ended by the admin.\n");
int n = write(id, str, strlen(str));
if(n < 0)
{ perror("Error writing quit to partner"); return 1; }
used_fds[id] = 1;
n = write(partners[id], str, strlen(str));
if(n < 0)
{ perror("Error writing quit to partner"); return 1; }
used_fds[partners[id]] = 1;
reset_partners(id);
}
}
printf("Closing server socket.\n");
shutdown((int)socket_fd, SHUT_RDWR);
close((int)socket_fd);
running = 0;
}
else
{
printf("Unknown admin command.\n");
}
}
}
int beginServer(){
int socket_fd, port_num, client_len;
fd_set fd_master_set, read_set;
char buffer[PACKET_SIZE];
struct sockaddr_in server_addr, client_addr;
int n, i, number_sockets = 0;
int client_fd[MAX_SOCKETS];
//init fd to socket type
socket_fd = socket(AF_INET, SOCK_STREAM, 0);
if(socket_fd < 0){
perror("Error trying to open socket");
exit(1);
}
// Only run once.
if(init == 0)
{
init = 1;
//init socket
bzero((char *) &server_addr, sizeof(server_addr)); //zero out addr
port_num = PORT; // set port number
//server_addr will contain address of server
server_addr.sin_family = AF_INET; // Needs to be AF_NET
server_addr.sin_addr.s_addr = htonl(INADDR_ANY); // contains ip address of host
server_addr.sin_port = htons(port_num); //htons converts to network byte order
int yes = 1;
if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
perror("setsockopt");
exit(1);
}
//bind the host address with bind()
if(bind(socket_fd, (struct sockaddr *) &server_addr, sizeof(server_addr)) < 0){
perror("Error Binding");
exit(1);
}
printf("Server listening for sockets on port:%d\n", port_num);
//listen for clients
int n = listen(socket_fd, MAX_SOCKETS);
//printf("Listen result %d\n", n);
client_len = sizeof(client_addr); // set client length
}
FD_ZERO(&fd_master_set);
FD_SET(socket_fd, &fd_master_set);
running = 1;
pthread_t admin_thread;
if(pthread_create(&admin_thread, NULL, (void *)admin_commands, &socket_fd))
{ fprintf(stderr, "Error creating admin thread\n"); exit(1);}
while(1){
read_set = fd_master_set;
n = select(FD_SETSIZE, &read_set, NULL, NULL, NULL);
if(n < 0)
{ perror("Select Failed"); exit(1); }
for(i = 0; i < FD_SETSIZE; i++)
{
if(FD_ISSET(i, &read_set))
{
if(i == socket_fd)
{
if(number_sockets < MAX_CLIENTS)//MAX_SOCKETS)
{
//accept new connection from client
client_fd[number_sockets] =
accept(socket_fd, (struct sockaddr *)&client_addr, &client_len);
if(client_fd[number_sockets] < 0)
{ perror("Error accepting client"); exit(1); }
printf("Client accepted.\n");
used_fds[client_fd[number_sockets]] = 1;
FD_SET(client_fd[number_sockets], &fd_master_set);
number_sockets++;
}
else
{
printf("No more connection space\n");
client_fd[number_sockets] =
accept(socket_fd, (struct sockaddr *)&client_addr, &client_len);
if(client_fd[number_sockets] < 0)
{ perror("Error accepting client"); exit(1); }
printf("Overflow client temporarily accepted.\n");
FD_SET(client_fd[number_sockets], &fd_master_set);
char* str = "/ERRThe queue is full, you cannot connect at this time.\n";
int n = write(client_fd[number_sockets], str, strlen(str));
if(n < 0)
{
perror("Error informing client of full queue");
exit(1);
}
//used_fds[client_fd[number_sockets]] = 1;
//FD_SET(client_fd[number_sockets], &fd_master_set);
FD_CLR(client_fd[number_sockets], &fd_master_set);
//number_sockets --;
}
} else {
//begin communication
bzero(buffer, PACKET_SIZE);
n = read(i, buffer, PACKET_SIZE-1);
if(n < 0){
perror("Error reading from client");
// Do not exit, mark that client as D/C, inform their partner, carry one
FD_CLR(i, &fd_master_set);
FD_CLR(i, &read_set);
handle_disconnect(i);
number_sockets --;
continue;
}
//debug, message coming in
//printf(buffer);
//printf("prebuffed: %s END\n", buffer);
data_use[i] += strlen(buffer);
//handles all messages
if(sendToClient(buffer, i) == 0)
{
processCommand(buffer, i);//, used_fds);
}
}
}
}
}
return 0;
}
int initScreen(){
printf("To being accepting clients type /START\n");
char buffer[PACKET_SIZE];
while(1){
bzero(buffer, PACKET_SIZE);
fgets(buffer, PACKET_SIZE-1, stdin);
if(strstr(buffer, "/START") != NULL){
break;
}
}
beginServer();
return 0;
}
int main (int argc, char *argv[] ){
memset(data_use, 0, sizeof(data_use));
printf("Welcome to the CS513 Chat Server.\n");
struct utsname unameData;
int i = uname(&unameData);
if(i != 0)
perror("Could not find the server's own hostname.");
else
{
printf("Machine Name: %s\n", unameData.sysname);
printf("Host Name: %s\n", unameData.nodename);
char hostname[1024];
hostname[1023] = '\0';
gethostname(hostname, 1023);
printf("Hostname: %s\n", hostname);
struct hostent* h;
h = gethostbyname(hostname);
printf("h_name: %s\n", h->h_name);
}
initScreen();
return 0;
}
|
the_stack_data/29825439.c | //Print "P"
#include <stdio.h>
int main() {
int height = 5;
int i, j;
for (i = 0; i < height; i++) {
for (j = 0; j <= height/2; j++) {
if (j == 0 || i == 0 || i == height/2) {
printf("* ");
}
else if (j == height/2 && i<=height/2) {
printf("* ");
}
else {
printf(" ");
}
}
printf("\n");
}
return 0;
}
|
the_stack_data/70450544.c | #include<stdio.h>
int main(){
int cod[10], op,i,c, sair=0,j;
float saldo[10],soma;
for(i=0;i<10;i++){
printf("Informe o codigo da conta: ");
do{
sair=0;
scanf("%d",&c);
for(j=0;j<i;j++){
if(cod[j]==c){
printf("Ja existe esse codigo!\nInforme outro: ");
sair=1;
break;
}
}
if(sair==0){
cod[i]=c;
}
}while(sair==1);
printf("Informe o saldo da conta: ");
scanf("%f",&saldo[i]);
}
do{
printf("\n1 - Consultar saldo de uma conta\n");
printf("2 - Efetuar deposito em uma conta\n");
printf("3 - Efetuar saque em uma conta\n");
printf("4 - Consultar o ativo bancario\n");
printf("0 - Sair\n");
printf("Escolha uma opcao: ");
scanf("%d",&op);
switch(op){
case 1:
printf("\nInforme o codigo que deseja consultar: ");
scanf("%d",&c);
int existe=0;
for(i=0;i<10;i++){
if(c==cod[i]){
printf("Conta %d \n",cod[i]);
printf("Saldo %f \n",saldo[i]);
existe=1;
}
}
if(existe==0){
printf("Nao existe conta cadastrada com esse codigo!\n");
}
break;
case 2:
printf("\nInforme o codigo da conta: ");
scanf("%d",&c);
float f;
printf("Informe o valor a ser depositado: ");
scanf("%f",&f);
existe=0;
for(i=0;i<10;i++){
if(c==cod[i]){
saldo[i] = saldo[i]+f;
printf("Saldo atualizado!\n\n");
existe=1;
}
}
if(existe==0){
printf("Nao existe conta cadastrada com esse codigo!\n");
}
break;
case 3:
printf("\nInforme o codigo da conta: ");
scanf("%d",&c);
printf("Informe o valor a ser sacado: ");
scanf("%f",&f);
existe=0;
for(i=0;i<10;i++){
if(c==cod[i]){
if(saldo[i]>=f){
saldo[i] = saldo[i]-f;
printf("Saldo atualizado!\n");
}else{
printf("Saldo insuficiente!\n");
}
existe=1;
}
}
if(existe==0){
printf("Nao existe conta cadastrada com esse codigo!\n");
}
break;
case 4:
soma=0;
for(i=0;i<10;i++){
soma=soma+saldo[i];
}
printf("\nAtivo bancario: %f\n",soma);
break;
}
}while(op!=0);
return 0;
}
|
the_stack_data/880706.c | #include <stdio.h>
#include <math.h>
int main() {
int n;
do {
printf("Unesite broj clanova reda: ");
scanf("%d", &n);
} while(n<1);
int i, j;
double brojilac, imenilac, clan;
double sum = 1;
for(i=0; i<n; i++) {
brojilac = pow(-1, i);
double fakt = 1;
for(j=2; j<=i; j++) {
fakt *= j;
}
imenilac = fakt;
clan = brojilac/imenilac;
printf("clan[i=%d] = % lf\n", i, clan);
sum += clan;
}
printf("\nsum = %lf\n", sum);
double e = 1 / sum;
printf("\ne = %lf\n", e);
return 0;
}
|
the_stack_data/54825533.c | void fence()
{
asm("sync");
}
void lwfence()
{
asm("lwsync");
}
void isync()
{
asm("isync");
}
int __unbuffered_cnt = 0;
int __unbuffered_p0_r1 = 0;
int __unbuffered_p1_r1 = 0;
int __unbuffered_p1_r3 = 0;
int __unbuffered_p2_r1 = 0;
int __unbuffered_p3_r1 = 0;
int __unbuffered_p3_r3 = 0;
int __unbuffered_p3_r4 = 0;
int x = 0;
int y = 0;
void *P0(void *arg)
{
__unbuffered_p0_r1 = 1;
y = __unbuffered_p0_r1;
// Instrumentation for CPROVER
fence();
__unbuffered_cnt++;
}
void *P1(void *arg)
{
__unbuffered_p1_r1 = y;
lwfence();
__unbuffered_p1_r3 = x;
// Instrumentation for CPROVER
fence();
__unbuffered_cnt++;
}
void *P2(void *arg)
{
__unbuffered_p2_r1 = 1;
x = __unbuffered_p2_r1;
// Instrumentation for CPROVER
fence();
__unbuffered_cnt++;
}
void *P3(void *arg)
{
__unbuffered_p3_r1 = x;
__unbuffered_p3_r3 = __unbuffered_p3_r1 ^ __unbuffered_p3_r1;
__unbuffered_p3_r4 = *(&y + __unbuffered_p3_r3);
// Instrumentation for CPROVER
fence();
__unbuffered_cnt++;
}
int main()
{
__CPROVER_ASYNC_0:
P0(0);
__CPROVER_ASYNC_1:
P1(0);
__CPROVER_ASYNC_2:
P2(0);
__CPROVER_ASYNC_3:
P3(0);
__CPROVER_assume(__unbuffered_cnt == 4);
fence();
// EXPECT:exists
__CPROVER_assert(
!(__unbuffered_p1_r1 == 1 && __unbuffered_p1_r3 == 0 &&
__unbuffered_p3_r1 == 1 && __unbuffered_p3_r4 == 0),
"Program proven to be relaxed for PPC, model checker says YES.");
return 0;
}
|
the_stack_data/808802.c | // SPDX-License-Identifier: GPL-2.0
/*
* Generate lookup table for the table-driven CRC64 calculation.
*
* gen_crc64table is executed in kernel build time and generates
* lib/crc64table.h. This header is included by lib/crc64.c for
* the table-driven CRC64 calculation.
*
* See lib/crc64.c for more information about which specification
* and polynomial arithmetic that gen_crc64table.c follows to
* generate the lookup table.
*
* Copyright 2018 SUSE Linux.
* Author: Coly Li <[email protected]>
*/
#include <inttypes.h>
#include <stdio.h>
#define CRC64_ECMA182_POLY 0x42F0E1EBA9EA3693ULL
#define CRC64_ROCKSOFT_POLY 0x9A6C9329AC4BC9B5ULL
static uint64_t crc64_table[256] = {0};
static uint64_t crc64_rocksoft_table[256] = {0};
static void generate_reflected_crc64_table(uint64_t table[256], uint64_t poly)
{
uint64_t i, j, c, crc;
for (i = 0; i < 256; i++) {
crc = 0ULL;
c = i;
for (j = 0; j < 8; j++) {
if ((crc ^ (c >> j)) & 1)
crc = (crc >> 1) ^ poly;
else
crc >>= 1;
}
table[i] = crc;
}
}
static void generate_crc64_table(uint64_t table[256], uint64_t poly)
{
uint64_t i, j, c, crc;
for (i = 0; i < 256; i++) {
crc = 0;
c = i << 56;
for (j = 0; j < 8; j++) {
if ((crc ^ c) & 0x8000000000000000ULL)
crc = (crc << 1) ^ poly;
else
crc <<= 1;
c <<= 1;
}
table[i] = crc;
}
}
static void output_table(uint64_t table[256])
{
int i;
for (i = 0; i < 256; i++) {
printf("\t0x%016" PRIx64 "ULL", table[i]);
if (i & 0x1)
printf(",\n");
else
printf(", ");
}
printf("};\n");
}
static void print_crc64_tables(void)
{
printf("/* this file is generated - do not edit */\n\n");
printf("#include <linux/types.h>\n");
printf("#include <linux/cache.h>\n\n");
printf("static const u64 ____cacheline_aligned crc64table[256] = {\n");
output_table(crc64_table);
printf("\nstatic const u64 ____cacheline_aligned crc64rocksofttable[256] = {\n");
output_table(crc64_rocksoft_table);
}
int main(int argc, char *argv[])
{
generate_crc64_table(crc64_table, CRC64_ECMA182_POLY);
generate_reflected_crc64_table(crc64_rocksoft_table, CRC64_ROCKSOFT_POLY);
print_crc64_tables();
return 0;
}
|
the_stack_data/532438.c | /*
Author : Arnob Mahmud
mail : [email protected]
*/
#include <stdio.h>
int main(int argc, char const *argv[])
{
int a, b, sum;
printf("Enter two numbers : \n");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum is %d.\n", sum);
return 0;
}
|
the_stack_data/193892667.c | void strcpy(char *s, char *t) {
while(*s++ = *t++)
;
}
|
the_stack_data/174114.c | #include <stdio.h>
#include <unistd.h>
main()
{
printf("Son is running\n");
int pid, ppid;
pid=getpid();
ppid=getppid();
printf("\n SON PARAM: pid=%i ppid=%i \n",pid,ppid);
printf("Son will close in 5s\n");
sleep(5);
}
|
the_stack_data/153652.c | /***********************************************************************************************//**
* \file xensiv_bgt60trxx_mtb.c
*
* Description: This file contains the MTB platform functions implementation
* for interacting with the XENSIV(TM) BGT60TRxx 60GHz FMCW radar sensors.
*
***************************************************************************************************
* \copyright
* Copyright 2021 Infineon Technologies AG
* 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.
**************************************************************************************************/
#if defined(CY_USING_HAL)
#include "cyhal_system.h"
#include "xensiv_bgt60trxx_mtb.h"
#define XENSIV_BGT60TRXX_ERROR(x) (((x) == XENSIV_BGT60TRXX_STATUS_OK) ? CY_RSLT_SUCCESS :\
CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_HARDWARE_XENSIV_BGT60TRXX, (x)))
static cy_rslt_t xensiv_bgt60trxx_mtb_hard_reset(const xensiv_bgt60trxx_mtb_t* obj);
cy_rslt_t xensiv_bgt60trxx_mtb_init(xensiv_bgt60trxx_mtb_t* obj,
cyhal_spi_t* spi,
cyhal_gpio_t selpin,
cyhal_gpio_t rstpin,
const uint32_t* regs,
size_t len)
{
CY_ASSERT(obj != NULL);
CY_ASSERT(spi != NULL);
CY_ASSERT(selpin != NC);
CY_ASSERT(rstpin != NC);
cy_rslt_t rslt;
obj->selpin = NC;
obj->rstpin = NC;
rslt = cyhal_gpio_init(selpin,
CYHAL_GPIO_DIR_OUTPUT,
CYHAL_GPIO_DRIVE_STRONG,
true);
if (CY_RSLT_SUCCESS == rslt)
{
obj->selpin = selpin;
obj->rstpin = NC;
rslt = cyhal_gpio_init(rstpin,
CYHAL_GPIO_DIR_OUTPUT,
CYHAL_GPIO_DRIVE_STRONG,
true);
}
if (CY_RSLT_SUCCESS == rslt)
{
obj->rstpin = rstpin;
rslt = xensiv_bgt60trxx_mtb_hard_reset(obj);
}
if (CY_RSLT_SUCCESS == rslt)
{
obj->spi = spi;
int32_t res = xensiv_bgt60trxx_init((xensiv_bgt60trxx_t)obj, regs, len);
if (res != XENSIV_BGT60TRXX_STATUS_OK)
{
obj->spi = NULL;
}
rslt = XENSIV_BGT60TRXX_ERROR(res);
}
return rslt;
}
cy_rslt_t xensiv_bgt60trxx_mtb_interrupt_init(xensiv_bgt60trxx_mtb_t* obj,
uint16_t fifo_limit,
cyhal_gpio_t intpin,
uint8_t intr_priority,
xensiv_bgt60trxx_mtb_interrupt_cb_t* interrupt_cb)
{
CY_ASSERT(obj != NULL);
CY_ASSERT(obj->spi != NULL);
CY_ASSERT(interrupt_cb != NULL);
obj->intpin = intpin;
int32_t res = xensiv_bgt60trxx_set_fifo_limit((xensiv_bgt60trxx_t)obj, fifo_limit);
cy_rslt_t rslt = XENSIV_BGT60TRXX_ERROR(res);
if (CY_RSLT_SUCCESS == rslt)
{
rslt = cyhal_gpio_init(intpin,
CYHAL_GPIO_DIR_INPUT,
CYHAL_GPIO_DRIVE_PULLDOWN,
false);
if (rslt == CY_RSLT_SUCCESS)
{
#if defined(CYHAL_API_VERSION) && (CYHAL_API_VERSION >= 2)
cyhal_gpio_register_callback(intpin, (cyhal_gpio_callback_data_t*)interrupt_cb);
#else
cyhal_gpio_register_callback(intpin, interrupt_cb->callback,
interrupt_cb->callback_arg);
#endif
cyhal_gpio_enable_event(intpin,
CYHAL_GPIO_IRQ_RISE,
intr_priority,
true);
}
}
return rslt;
}
void xensiv_bgt60trxx_mtb_free(const xensiv_bgt60trxx_mtb_t* obj)
{
CY_ASSERT(obj != NULL);
if (obj->selpin != NC)
{
cyhal_gpio_free(obj->selpin);
}
if (obj->rstpin != NC)
{
cyhal_gpio_free(obj->rstpin);
}
if (obj->intpin != NC)
{
cyhal_gpio_free(obj->intpin);
}
}
static cy_rslt_t xensiv_bgt60trxx_mtb_hard_reset(const xensiv_bgt60trxx_mtb_t* obj)
{
CY_ASSERT(obj != NULL);
CY_ASSERT(obj->rstpin != NC);
CY_ASSERT(obj->selpin != NC);
cyhal_gpio_t rstpin = obj->rstpin;
cyhal_gpio_t selpin = obj->selpin;
cyhal_gpio_write(selpin, 1);
cyhal_gpio_write(rstpin, 1);
cy_rslt_t rslt = cyhal_system_delay_ms(1);
cyhal_gpio_write(rstpin, 0);
rslt |= cyhal_system_delay_ms(1);
cyhal_gpio_write(rstpin, 1);
rslt |= cyhal_system_delay_ms(1);
return rslt;
}
/********************** driver platform specific implementation ****************************/
#if !defined(XENSIV_BGT60TRXX_MTB_USE_DMA)
int32_t xensiv_bgt60trxx_platform_spi_transfer(void* dev,
const uint8_t* tx_data,
uint32_t tx_len,
uint8_t* rx_data,
uint32_t rx_len)
{
CY_ASSERT(dev != NULL);
CY_ASSERT((tx_data != NULL) || (rx_data != NULL));
xensiv_bgt60trxx_mtb_t* obj = (xensiv_bgt60trxx_mtb_t*)dev;
cyhal_gpio_write(obj->selpin, 0);
cy_rslt_t result = cyhal_spi_transfer(obj->spi,
tx_data,
(tx_data != NULL) ? tx_len : 0U,
rx_data,
(rx_data != NULL) ? rx_len : 0U,
0xFFU);
cyhal_gpio_write(obj->selpin, 1);
return ((CY_RSLT_SUCCESS == result) ?
XENSIV_BGT60TRXX_STATUS_OK :
XENSIV_BGT60TRXX_STATUS_SPI_ERROR);
}
#endif // if !defined(XENSIV_BGT60TRXX_MTB_USE_DMA)
void xensiv_bgt60trxx_platform_delay(uint32_t ms)
{
(void)cyhal_system_delay_ms(ms);
}
uint32_t xensiv_bgt60trxx_platform_word_reverse(uint32_t x)
{
return __REV(x);
}
void xensiv_bgt60trxx_platform_assert(bool expr)
{
CY_ASSERT(expr);
(void)expr; /* make release build */
}
#endif // defined(CY_USING_HAL)
|
the_stack_data/901877.c | /*
* Created 18E04 lynnl
*/
#include <stdio.h>
int main(int argc, char *argv[])
{
return 0;
}
|
the_stack_data/90763842.c | #include<stdio.h>
int main()
{
int health1,health2,harm1,harm2,i,j;
while(scanf("%d%d%d%d",&health1,&harm1,&health2,&harm2)!=EOF)
{
for(i=0;;i++)
{
health2-=harm1;
if(health2<=0)
{
printf("Left\n");
break;
}
health1-=harm2;
if(health1<=0)
{
printf("Right\n");
break;
}
}
}
return 0;
}
|
the_stack_data/62661.c |
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
int timeToclose;
int childPid;
int fd[2];
int toDownload(char * str)
{
if(strlen(str)>2 && str[0]=='D' && str[1]==' ')
return 1;
return 0;
}
void uclient( int c1){
int connected, bytes_recieved,addr_len;
char sendto_data [1024],recvfrom_data[1024];
char regex[100];
char fileName[100];
struct hostent *host;
struct sockaddr_in server_addr;
//host = gethostbyname("127.0.0.1");
host= (struct hostent *) gethostbyname((char *)"127.0.0.1");
//gives me the socket
if ((connected = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
perror("Socket");
fprintf(stderr,"fck\n");
exit(1);
}
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(c1);
server_addr.sin_addr = *((struct in_addr *)host->h_addr);
//bzero(&(server_addr.sin_zero),8);
addr_len = sizeof(struct sockaddr);
/* //establishes connection bw client and server
*/
char *pch;
char copy[1024];
while(1)
{
gets(sendto_data); // DATA which is got in the input buffer
//printf("wtf %s\n",sendto_data);
shortcut :
strcpy(copy,sendto_data);
pch = strtok (copy," ");
//======================= IndexGet =================================
if(pch!=NULL)
{
if(strcmp(pch,"FileHash")==0)
{
pch = strtok (NULL, " ");
if(pch !=NULL)
{
if(strcmp(pch,"Verify")==0)
{
pch = strtok (NULL, " ");
if(pch!=NULL)
{
strcpy(sendto_data,"FV");
strcat(sendto_data,pch);
printf("sendto_data : %s\n",sendto_data);
sendto(connected, sendto_data, strlen(sendto_data), 0,
(struct sockaddr *)&server_addr, sizeof(struct sockaddr));
while(1)
{
bytes_recieved=recvfrom(connected,recvfrom_data,1024,0,
(struct sockaddr *)&server_addr, &addr_len);
recvfrom_data[bytes_recieved] = '\0';
if(strcmp(recvfrom_data,"End Of File") == 0)break;
fwrite(recvfrom_data,1,bytes_recieved,stdout);
/*if(recvfrom_data[0]=='A' && recvfrom_data[1]=='N' && recvfrom_data[2]=='S')
{
printf("\nANS MD5 CAUGHT\n");
char arr[100];
strncpy(arr,recvfrom_data+4,strlen(recvfrom_data)-1);
//file to be received here
printf("\n%s\n",arr);
fflush(stdout);
break;
}*/
}
printf("\nout now\n");
continue;
}
}
else if(strcmp(pch,"CheckAll")==0)
{
strcpy(sendto_data,"FC");
sendto(connected, sendto_data, strlen(sendto_data), 0,
(struct sockaddr *)&server_addr, sizeof(struct sockaddr));
while(1)
{
bytes_recieved=recvfrom(connected,recvfrom_data,1024,0,
(struct sockaddr *)&server_addr, &addr_len);
recvfrom_data[bytes_recieved] = '\0';
if(strcmp(recvfrom_data,"End Of File") == 0)break;
fwrite(recvfrom_data,1,bytes_recieved,stdout);
/*if(recvfrom_data[0]=='A' && recvfrom_data[1]=='N' && recvfrom_data[2]=='S')
{
printf("\nANS MD5 checkall CAUGHT\n");
char arr[100];
strncpy(arr,recvfrom_data+4,strlen(recvfrom_data)-1);
//file to be received here
printf("\n%s\n",arr);
fflush(stdout);
break;
}*/
}
printf("\nout now\n");
continue;
}
}
else printf("wrong usage of FileHash\n");
}
else if(strcmp(pch,"IndexGet")==0)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ");
if(pch!=NULL)
{
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Indexget ShortList >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Add Before Regex
if(strcmp(pch,"ShortList")==0)
{
pch = strtok (NULL, " ");
if(pch!=NULL)
{
strcpy(sendto_data,"IS");
strcat(sendto_data,pch);
pch = strtok (NULL, " ");
if(pch!=NULL)
{
strcat(sendto_data," ");
strcat(sendto_data,pch);
printf("sendto_data : %s\n",sendto_data);
sendto(connected, sendto_data, strlen(sendto_data), 0,
(struct sockaddr *)&server_addr, sizeof(struct sockaddr));
//replace this with fiel catcher
while(1)
{
bytes_recieved=recvfrom(connected,recvfrom_data,1024,0,
(struct sockaddr *)&server_addr, &addr_len);
recvfrom_data[bytes_recieved] = '\0';
if(strcmp(recvfrom_data,"End Of File") == 0)break;
fwrite(recvfrom_data,1,bytes_recieved,stdout);
}
printf("\nout now\n");
continue;
}
}
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<TILL HERE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//======================= IndexGet Regex =================================
if(strcmp(pch,"Regex")==0)
{
pch = strtok (NULL, " ");
if(pch!=NULL)
{
strcpy(sendto_data,"IR");
strcat(sendto_data,pch);
printf("sendto_data : %s\n",sendto_data);
sendto(connected, sendto_data, strlen(sendto_data), 0,
(struct sockaddr *)&server_addr, sizeof(struct sockaddr));
//replace this with fiel catcher
while(1)
{
bytes_recieved=recvfrom(connected,recvfrom_data,1024,0,
(struct sockaddr *)&server_addr, &addr_len);
recvfrom_data[bytes_recieved] = '\0';
if(strcmp(recvfrom_data,"End Of File") == 0)break;
fwrite(recvfrom_data,1,bytes_recieved,stdout);
/*if(recvfrom_data[0]=='A' && recvfrom_data[1]=='N' && recvfrom_data[2]=='S')
{
printf("\nANS REGEX CAUGHT\n");
char arr[100];
strncpy(arr,recvfrom_data+4,strlen(recvfrom_data)-1);
//file to be received here
printf("\n%s\n",arr);
fflush(stdout);
break;
}*/
}
printf("\nout now\n");
continue;
}
else
{
printf("no filename given\n");
}
}
//======================= IndexGet LongList =================================
//if(strcmp(copy,"IndexGet LongList")==0 )
else if(strcmp(pch,"LongList")==0)
{
strcpy(sendto_data,"IL");
printf("------SENDING IL\n");
sendto(connected, sendto_data, strlen(sendto_data), 0,
(struct sockaddr *)&server_addr, sizeof(server_addr));
printf("------ready to receive file\n");
/*bytes_recieved=recvfrom(connected,recvfrom_data,1024,0,
(struct sockaddr *)&server_addr, &addr_len);
recvfrom_data[bytes_recieved] = '\0';
printf("%s\n",recvfrom_data);
fflush(stdout);*/
while(1)
{
//printf("\nstuck 181\n");
bytes_recieved=recvfrom(connected,recvfrom_data,1024,0,
(struct sockaddr *)&server_addr, sizeof(struct sockaddr));
recvfrom_data[bytes_recieved] = '\0';
/*printf("%s\n",recvfrom_data);
fflush(stdout);*/
if(strcmp(recvfrom_data,"End Of File") == 0)break;
fwrite(recvfrom_data,1,bytes_recieved,stdout);
/*if(recvfrom_data[0]=='A' && recvfrom_data[1]=='N' && recvfrom_data[2]=='S')
{
printf("\nANS Longlist CAUGHT\n");
char arr[100];
strncpy(arr,recvfrom_data+4,strlen(recvfrom_data)-1);
//file to be received here
printf("\n%s\n",arr);
fflush(stdout);
break;
}*/
}
printf("\nout now\n");
continue;
}
}
}
else if(strcmp(pch,"Upload") == 0)
{
pch = strtok (NULL, " ");
// strcpy(sendto_data,"IR");
char arr[100];
strcpy(arr,pch);
//strcat(arr,pch);
printf("opening %s\n",arr);
strcpy(sendto_data,"U ");
strcat(sendto_data,pch);
sendto(connected, sendto_data, 1024, 0,
(struct sockaddr *)&server_addr, sizeof(struct sockaddr));
//=================adding protocol=====================
//===================ending protocol==================
//=================told the client that file is to be sent========================
//fgets ( data, sizeof(data), fp ) != NULL
// char data[1024];
/*FILE *fp = fopen(arr,"r");
if(fp == NULL)
{
printf("wrong file\n");
continue;
}
memset(sendto_data,0,1024);
int byteR,sentN;
while(!feof(fp))
{ memset(sendto_data,0,1024);
byteR = fread(sendto_data,1,1024,fp);
sendto_data[byteR] = '\0';
// byteR = strlen(data);
// if(byteR == 0) break
fflush(stdout);
//void *temp = data;
sentN = sendto(connected, sendto_data, 1024, 0,
(struct sockaddr *)&server_addr, sizeof(struct sockaddr));
printf("%s",sendto_data);
printf("read %d sent %d--------\n",sentN,byteR);
//===============================file sent=================================================
}
printf("End file\n");
memset(sendto_data,0,1024);
char end[]= "End Of File";
strcpy(sendto_data,end);
sendto(connected, sendto_data, 1024, 0,
(struct sockaddr *)&server_addr, sizeof(struct sockaddr));
fclose(fp);
*/
}
else if(strcmp(pch,"Download") == 0)
{
pch = strtok (NULL, " ");
if(pch!=NULL)
{
strcpy(sendto_data,"D ");
strcat(sendto_data,pch);
sendto(connected, sendto_data, 1024, 0,
(struct sockaddr *)&server_addr, sizeof(struct sockaddr));
printf("printing %s\n",pch);
// sendto(connected,recvfrom_data,1024,0);
FILE *fp1 = fopen(pch,"wb");
//char dup[1024];
memset(recvfrom_data,0,1024);
while(1){
//bytes_recieved=read(connected,recvfrom_data,1024);
bytes_recieved=recvfrom(connected,recvfrom_data,1024,0,
(struct sockaddr *)&server_addr, &addr_len);
recvfrom_data[bytes_recieved] = '\0';
printf("got %s number %d-----\n",recvfrom_data,bytes_recieved);
if(strcmp(recvfrom_data,"End Of File")==0)
{
break;
}
//else break;
fwrite(recvfrom_data, 1,bytes_recieved, fp1);
//sleep(1);
}
printf("File closed\n");
fclose(fp1);
}
else printf("Wrong use of download");
}
else if(strcmp(pch,"Allow") == 0)
{
close(fd[1]);
int nbytes = read(fd[0],fileName,sizeof(fileName));
strcpy(sendto_data,"Download ");
strcat(sendto_data,fileName);
goto shortcut;
}
else if(strcmp(pch,"Stop") == 0)
{
//close(fd[1]);
printf("Process stopped\n");
}
else{
//normal text===================================================
if ((strcmp(sendto_data , "q") == 0 || strcmp(sendto_data , "Q") == 0) || timeToclose ==1)
{
if(timeToclose)printf("bbye\n");
sendto(connected, sendto_data, strlen(sendto_data), 0,
(struct sockaddr *)&server_addr, sizeof(struct sockaddr)) ;
fflush(stdout);
close(connected);
exit(0);
break;
}
else
sendto(connected, sendto_data, strlen(sendto_data), 0,
(struct sockaddr *)&server_addr, sizeof(struct sockaddr));
}
}
}
return;
}
void userver(int s1){
int sock, connected, true = 1,bytes_recieved,addr_len;
char sendto_data [1024],recvfrom_data[1024],copy[1024];
char regex[100];
struct sockaddr_in server_addr,client_addr;
int sin_size;
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
perror("Socket");
exit(1);
}
//int s1;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(s1);
server_addr.sin_addr.s_addr = INADDR_ANY;
//bzero(&(server_addr.sin_zero),8);
//binded socket to required port
if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr))
== -1) {
perror("Unable to bind");
exit(1);
}
printf("till here\n");
/*if (listen(sock, 5) == -1) {
perror("Listen");
exit(1);
}*/
addr_len = sizeof(struct sockaddr);
printf("\nUDPServer Waiting for client on port 5000");
fflush(stdout);
//sin_size = sizeof(struct sockaddr_in);
//connected represents the client server connection
//connected = accept(sock, (struct sockaddr *)&client_addr,&sin_size);
//printf("\n I got a connection from (%s , %d)",
// inet_ntoa(client_addr.sin_addr),ntohs(client_addr.sin_port));
char * pch;
fflush(stdout);
char command[1024];
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< SOME VARIABLES FOR SHORTLIST >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
char lower[100],upper[100],cpy[1000];
int cntr=0;
char buff[1000];
//char * pch;
FILE *fpr;
FILE *fpr2;
int place=0;
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
while (1)
{
//waits for server to sendto data
bytes_recieved=recvfrom(sock,recvfrom_data,1024,0,
(struct sockaddr *)&client_addr, &addr_len);
recvfrom_data[bytes_recieved] = '\0';
if (strcmp(recvfrom_data , "q") == 0 || strcmp(recvfrom_data , "Q") == 0)
{ printf("have to close\n");
timeToclose = 1;
//sendto(connected, sendto_data,strlen(sendto_data), 0);
close(connected);
//kill(childPid, SIGTERM);
//exit(0);
break;
}
else if(recvfrom_data[0]=='F' && recvfrom_data[1]=='C')
{
system("find . -type f -exec sh -c 'printf \"%s %s \n\" \"$(ls -l --time-style=+%Y%m%d%H%M%S $1 )\" \"$(md5sum $1 | cut -d\" \" -f1)\"' '' '{}' '{}' \\; | awk '{print $7, $6, $8}' > checkall");
//file to be sent here checkall
FILE *fp = fopen("checkall","r");
if(fp == NULL)
{
printf("wrong file\n");
continue;
}
//=================told the client that file is to be sent========================
//fgets ( data, sizeof(data), fp ) != NULL
// char data[1024];
memset(sendto_data,0,1024);
int byteR,sentN;
while(!feof(fp))
{ //memset(sendto_data,0,1024);
byteR = fread(sendto_data,1,1024,fp);
sendto_data[byteR] = '\0';
// byteR = strlen(data);
// if(byteR == 0) break
// fflush(stdout);
//void *temp = data;
sentN = sendto(sock, sendto_data, 1024, 0,
(struct sockaddr *)&client_addr, sizeof(struct sockaddr));
printf("%s",sendto_data);
printf("read %d sent %d--------\n",sentN,byteR);
//===============================file sent=================================================
}
printf("End file\n");
memset(sendto_data,0,1024);
char end[]= "End Of File";
strcpy(sendto_data,end);
sendto(sock, sendto_data, 1024, 0,
(struct sockaddr *)&client_addr, sizeof(struct sockaddr));
fclose(fp);
//when sent file comment next 2 lines
//strcpy(sendto_data,"ANS here is the filehash checkall...... :P");
//sendto(connected, sendto_data,strlen(sendto_data), 0);
printf("recvfrom_data after check all : %s \n",recvfrom_data);
continue;
}
else if(recvfrom_data[0]=='F' && recvfrom_data[1]=='V')
{
printf("Identified FV\n");
strncpy(regex,(char*)recvfrom_data+2,100);
printf("Filename is %s\n",regex);
strcpy(command,"openssl md5 ");
strcat(command,regex);
strcat(command," | cut -d\" \" -f2 > md5");
system(command);
strcpy(command,"date -r ./");
strcat(command,regex);
strcat(command," +%Y%m%d%H%M%S > date");
system(command);
strcpy(command,"paste md5 date > verify");
//strcat(command," > ir");
system(command);
strcpy(command,"rm md5 date");
system(command);
FILE *fp = fopen("verify","r");
if(fp == NULL)
{
printf("wrong file\n");
continue;
}
//=================told the client that file is to be sent========================
//fgets ( data, sizeof(data), fp ) != NULL
// char data[1024];
memset(sendto_data,0,1024);
int byteR,sentN;
while(!feof(fp))
{ //memset(sendto_data,0,1024);
byteR = fread(sendto_data,1,1024,fp);
sendto_data[byteR] = '\0';
// byteR = strlen(data);
// if(byteR == 0) break
// fflush(stdout);
//void *temp = data;
sentN = sendto(sock, sendto_data, 1024, 0,
(struct sockaddr *)&client_addr, sizeof(struct sockaddr));
printf("%s",sendto_data);
printf("read %d sent %d--------\n",sentN,byteR);
//===============================file sent=================================================
}
printf("End file\n");
memset(sendto_data,0,1024);
char end[]= "End Of File";
strcpy(sendto_data,end);
sendto(sock, sendto_data, 1024, 0,
(struct sockaddr *)&client_addr, sizeof(struct sockaddr));
fclose(fp);
//strcpy(sendto_data,"ANS here is the filehash verify...... :P");
//sendto(connected, sendto_data,strlen(sendto_data), 0);
printf("recvfrom_data after verify : %s \n",recvfrom_data);
continue;
}
else if(recvfrom_data[0]=='I' && recvfrom_data[1]=='L')
{
printf("IL RECEIVED\n");
//system("ls -l > longlist");
system("find . -printf '%p %TY%Tm%Td%TH%Tm%Tm %k \n' > il");
//file to be sent here longlist
FILE *fp = fopen("il","r");
if(fp == NULL)
{
printf("wrong file\n");
continue;
}
/*strcpy(sendto_data,"ack");
sendto(sock, sendto_data, 1024, 0,
(struct sockaddr *)&client_addr, sizeof(struct sockaddr));
printf("sent an ack\n");
*/
//=================told the client that file is to be sent========================
//fgets ( data, sizeof(data), fp ) != NULL
// char data[1024];
memset(sendto_data,0,1024);
int byteR,sentN;
while(!feof(fp))
{ //memset(sendto_data,0,1024);
byteR = fread(sendto_data,1,1024,fp);
sendto_data[byteR] = '\0';
// byteR = strlen(data);
// if(byteR == 0) break
// fflush(stdout);
//void *temp = data;
sentN = sendto(sock, sendto_data, 1024, 0,
(struct sockaddr *)&client_addr, sizeof(server_addr));
printf("%s",sendto_data);
printf("read %d sent %d--------\n",sentN,byteR);
//===============================file sent=================================================
}
printf("End file\n");
memset(sendto_data,0,1024);
char end[]= "End Of File";
strcpy(sendto_data,end);
sendto(sock, sendto_data, 1024, 0,
(struct sockaddr *)&client_addr, sizeof(server_addr));
fclose(fp);
//strcpy(sendto_data,"ANS here is the list...... :P");
//int p =sendto(sock, sendto_data, 1024, 0,
// (struct sockaddr *)&client_addr, sizeof(server_addr));
//if(p ==-1) perror("hello");
//printf("recvfrom_data after longlist : %s \n",recvfrom_data);
continue;
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< SHORTLIST >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> TO BE COPIED BEFORE IR
else if(recvfrom_data[0] == 'I' && recvfrom_data[1]=='S')
{
printf("Identified IR\n");
strncpy(regex,(char*)recvfrom_data+2,100);
printf("Timestamps are is %s\n",regex);
pch = strtok (regex," ");
strcpy(lower,pch);
//printf("timestamp 1 : %s\n",pch);
pch = strtok (NULL, " ");
strcpy(upper,pch);
//printf("timestamp 2 : %s\n",pch);
system("ls -l --time-style=+%Y%m%d%H%M%S -t > ls");
fpr = fopen( "ls", "r" );
fpr2 = fopen( "is", "w" );
while ( fgets( buff, 1000, fpr ) != NULL )
{
if(cntr!=0 && cntr!=1)
{
printf("%d hahaha %s",cntr,buff);
strcpy(cpy,buff);
place=0;
pch = strtok (buff," ");
while (pch != NULL)
{
if(place==5)
{
printf("%s\n", pch);
if(strcmp(pch,lower)>0 && strcmp(pch,upper)<0)
{
printf("printing\n");
fprintf(fpr2,"%s",cpy);
}
}
place++;
pch = strtok (NULL," ");
}
}
cntr++;
}
fclose( fpr );
fclose( fpr2 );
FILE *fp = fopen("is","r");
if(fp == NULL)
{
printf("wrong file\n");
continue;
}
//=================told the client that file is to be sent========================
//fgets ( data, sizeof(data), fp ) != NULL
// char data[1024];
memset(sendto_data,0,1024);
int byteR,sentN;
while(!feof(fp))
{ //memset(sendto_data,0,1024);
byteR = fread(sendto_data,1,1024,fp);
sendto_data[byteR] = '\0';
// byteR = strlen(data);
// if(byteR == 0) break
// fflush(stdout);
//void *temp = data;
sentN = sendto(sock, sendto_data, 1024, 0,
(struct sockaddr *)&client_addr, sizeof(struct sockaddr));
printf("%s",sendto_data);
printf("read %d sent %d--------\n",sentN,byteR);
//===============================file sent=================================================
}
printf("End file\n");
memset(sendto_data,0,1024);
char end[]= "End Of File";
strcpy(sendto_data,end);
sendto(sock, sendto_data, 1024, 0,
(struct sockaddr *)&client_addr, sizeof(struct sockaddr));
fclose(fp);
//strcpy(sendto_data,"ANS here is the list...... :P");
//sendto(connected, sendto_data,strlen(sendto_data), 0);
printf("recvfrom_data after regex : %s \n",recvfrom_data);
continue;
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
else if(recvfrom_data[0]=='I' && recvfrom_data[1]=='R')
{
printf("Identified IR\n");
strncpy(regex,(char*)recvfrom_data+2,100);
printf("Regex is %s\n",regex);
strcpy(command,"find . -name \"");
strcat(command,regex);
strcat(command,"\" > ir");
system(command);
//file to be sent here longlist
FILE *fp = fopen("ir","r");
if(fp == NULL)
{
printf("wrong file\n");
continue;
}
//=================told the client that file is to be sent========================
//fgets ( data, sizeof(data), fp ) != NULL
// char data[1024];
memset(sendto_data,0,1024);
int byteR,sentN;
while(!feof(fp))
{ //memset(sendto_data,0,1024);
byteR = fread(sendto_data,1,1024,fp);
sendto_data[byteR] = '\0';
// byteR = strlen(data);
// if(byteR == 0) break
// fflush(stdout);
//void *temp = data;
sentN = sendto(sock, sendto_data, 1024, 0,
(struct sockaddr *)&client_addr, sizeof(struct sockaddr));
printf("%s",sendto_data);
printf("read %d sent %d--------\n",sentN,byteR);
//===============================file sent=================================================
}
printf("End file\n");
memset(sendto_data,0,1024);
char end[]= "End Of File";
strcpy(sendto_data,end);
sendto(sock, sendto_data, 1024, 0,
(struct sockaddr *)&client_addr, sizeof(struct sockaddr));
fclose(fp);
//strcpy(sendto_data,"ANS here is the list...... :P");
//sendto(connected, sendto_data,strlen(sendto_data), 0);
printf("recvfrom_data after regex : %s \n",recvfrom_data);
continue;
}
else if(strlen(recvfrom_data)>2 && recvfrom_data[0]=='U' && recvfrom_data[1]==' ')
{
char arr[100];
strncpy(arr,(char*)recvfrom_data+2,100);
printf("Someone wants to Upload File : %s\n Type \"Allow\" to let them; \"Stop\" to prevent them\n",arr);
// sendto(connected,recvfrom_data,1024,0);
close(fd[0]);
write(fd[1],arr,strlen(arr)+1);
/*FILE *fp1 = fopen(arr,"wb");
//char dup[1024];
memset(recvfrom_data,0,1024);
while(1){
bytes_recieved=read(connected,recvfrom_data,1024);
//recvfrom_data[bytes_recieved] = '\0';
printf("got %s number %d-----\n",recvfrom_data,bytes_recieved);
if(strcmp(recvfrom_data,"End Of File")==0)
{
break;
}
//else break;
fwrite(recvfrom_data, 1,bytes_recieved, fp1);
//bytes_recieved=read(connected,recvfrom_data,1024);
//sleep(1);
}
printf("File closed\n");
fclose(fp1);*/
}
else if(strlen(recvfrom_data)>2 && recvfrom_data[0]=='D' && recvfrom_data[1]==' ')
{
char arr[100];
strcpy(arr,recvfrom_data+2);
//strcat(arr,pch);
printf("opening %s\n",arr);
FILE *fp = fopen(arr,"r");
if(fp == NULL)
{
printf("wrong file\n");
continue;
}
//=================told the client that file is to be sent========================
//fgets ( data, sizeof(data), fp ) != NULL
// char data[1024];
memset(sendto_data,0,1024);
int byteR,sentN;
while(!feof(fp))
{ //memset(sendto_data,0,1024);
byteR = fread(sendto_data,1,1024,fp);
sendto_data[byteR] = '\0';
// byteR = strlen(data);
// if(byteR == 0) break
// fflush(stdout);
//void *temp = data;
sentN = sendto(sock, sendto_data, byteR, 0,
(struct sockaddr *)&client_addr, sizeof(struct sockaddr));
printf("%s",sendto_data);
printf("read %d sent %d--------\n",sentN,byteR);
//===============================file sent=================================================
}
printf("End file\n");
memset(sendto_data,0,1024);
char end[]= "End Of File";
strcpy(sendto_data,end);
sendto(sock, sendto_data, 1024, 0,
(struct sockaddr *)&client_addr, sizeof(struct sockaddr));
fclose(fp);
}
else{//prints out all of it
printf("%s\n" , recvfrom_data);
fflush(stdout);
}
/*
bytes_recieved = recvfrom(connected,recvfrom_data,1024,0);
recvfrom_data[bytes_recieved] = '\0';
if(bytes_recieved == 0) continue;
if (strcmp(recvfrom_data , "q") == 0 || strcmp(recvfrom_data , "Q") == 0)
{
close(connected);
break;
}
else
printf("\n RECIEVED DATA = %s " , recvfrom_data);
fflush(stdout);*/
}
close(sock);
//waitpid(pid,NULL,0);
}
//client handles tcp requests
void client( int c1){
int connected, bytes_recieved;
char send_data [1024],recv_data[1024];
char regex[100];
char fileName[100];
struct hostent *host;
struct sockaddr_in server_addr;
host = gethostbyname("127.0.0.1");
//gives me the socket
if ((connected = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("Socket");
fprintf(stderr,"fck\n");
exit(1);
}
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(c1);
server_addr.sin_addr = *((struct in_addr *)host->h_addr);
bzero(&(server_addr.sin_zero),8);
//establishes connection bw client and server
while (connect(connected, (struct sockaddr *)&server_addr,sizeof(struct sockaddr)) == -1) ;
char *pch;
char copy[1024];
while(1)
{
gets(send_data); // DATA which is got in the input buffer
//printf("wtf %s\n",send_data);
shortcut :
strcpy(copy,send_data);
pch = strtok (copy," ");
//======================= IndexGet =================================
if(pch!=NULL)
{
if(strcmp(pch,"FileHash")==0) // FileHash Verify or FileHash CheckAll
{
pch = strtok (NULL, " ");
if(pch !=NULL)
{
if(strcmp(pch,"Verify")==0)
{
pch = strtok (NULL, " ");
if(pch!=NULL)
{
strcpy(send_data,"FV");
strcat(send_data,pch);
//printf("send_data : %s\n",send_data);
send(connected, send_data,strlen(send_data), 0);
while(1)
{
bytes_recieved=recv(connected,recv_data,1024,0);
recv_data[bytes_recieved] = '\0';
if(strcmp(recv_data,"End Of File") == 0)break;
fwrite(recv_data,1,bytes_recieved,stdout);
}
//printf("\nout now\n");
continue;
}
}
else if(strcmp(pch,"CheckAll")==0)
{
strcpy(send_data,"FC");
send(connected, send_data,strlen(send_data), 0);
while(1)
{
bytes_recieved=recv(connected,recv_data,1024,0);
recv_data[bytes_recieved] = '\0';
if(strcmp(recv_data,"End Of File") == 0)break;
fwrite(recv_data,1,bytes_recieved,stdout);
}
//printf("\nout now\n");
continue;
}
}
else printf("wrong usage of FileHash\n");
}
else if(strcmp(pch,"IndexGet")==0)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ");
if(pch!=NULL)
{
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Indexget ShortList >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Add Before Regex
if(strcmp(pch,"ShortList")==0)
{
pch = strtok (NULL, " ");
if(pch!=NULL)
{
strcpy(send_data,"IS");
strcat(send_data,pch);
pch = strtok (NULL, " ");
if(pch!=NULL)
{
strcat(send_data," ");
strcat(send_data,pch);
//printf("send_data : %s\n",send_data);
send(connected, send_data,strlen(send_data), 0);
//replace this with fiel catcher
while(1)
{
bytes_recieved=recv(connected,recv_data,1024,0);
recv_data[bytes_recieved] = '\0';
if(strcmp(recv_data,"End Of File") == 0)break;
fwrite(recv_data,1,bytes_recieved,stdout);
}
printf("\nout now\n");
continue;
}
}
else printf("Wrong Usage. Please Type \"IndexGet ShortList <filename>\" \n");
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<TILL HERE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//======================= IndexGet Regex =================================
if(strcmp(pch,"Regex")==0)
{
pch = strtok (NULL, " ");
if(pch!=NULL)
{
strcpy(send_data,"IR");
strcat(send_data,pch);
printf("send_data : %s\n",send_data);
send(connected, send_data,strlen(send_data), 0);
while(1)
{
bytes_recieved=recv(connected,recv_data,1024,0);
recv_data[bytes_recieved] = '\0';
if(strcmp(recv_data,"End Of File") == 0)break;
fwrite(recv_data,1,bytes_recieved,stdout);
}
continue;
}
else
{
printf("Regular Expression not Given, please try again\n");
}
}
//======================= IndexGet LongList =================================
//if(strcmp(copy,"IndexGet LongList")==0 )
else if(strcmp(pch,"LongList")==0)
{
strcpy(send_data,"IL");
send(connected, send_data,strlen(send_data), 0);
while(1)
{
//printf("\nstuck 181\n");
bytes_recieved=recv(connected,recv_data,1024,0);
recv_data[bytes_recieved] = '\0';
if(strcmp(recv_data,"End Of File") == 0)break;
fwrite(recv_data,1,bytes_recieved,stdout);
//printf("rec - %s\n",recv_data)
}
// printf("\nout now\n");
continue;
}
}
}
else if(strcmp(pch,"Upload") == 0)
{
// Upload uses the Download functionality of the other user.
pch = strtok (NULL, " ");
// strcpy(send_data,"IR");
char arr[100];
strcpy(arr,pch);
printf("Waiting for permission to Upload %s\n",arr);
strcpy(send_data,"U ");
strcat(send_data,pch);
write(connected,send_data,1024);
}
else if(strcmp(pch,"Download") == 0)
{
pch = strtok (NULL, " ");
if(pch!=NULL)
{
resend: strcpy(send_data,"D ");
strcat(send_data,pch);
write(connected,send_data,1024);
//printf("printing %s\n",pch);
// send(connected,recv_data,1024,0);
//pch is the file to be downloaded and written to
FILE *fp1 = fopen(pch,"w");
memset(recv_data,0,1024);
while(1){
bytes_recieved=read(connected,recv_data,1024);
if(strcmp(recv_data,"End Of File")==0)
{
break;
}
fwrite(recv_data, 1,bytes_recieved, fp1);
}
//printf("File closed\n");
fclose(fp1);
//code to ensure integrity of data..... =====================================
bytes_recieved=read(connected,recv_data,1024);
char dt[1024];
strcpy(dt,recv_data);
char * hsh = strtok(dt," ");
if(hsh == NULL)
hsh = strtok(NULL," ");
//hsh and pch contain name of file under transfer. Both should be same in working case
if(strcmp(hsh,pch) == 0){
hsh = strtok(NULL," ");
char fname[100];
strcpy(fname,pch);
char packet[1024];//will have the final md5 string
char cmd[1000],temp[100];
int stlen,ii;
//system commands==============================================
strcpy(cmd,"md5sum ");
strcat(cmd,fname);
strcat(cmd," | awk '{print $1}'> t1");
system(cmd);
FILE *f1= fopen("t1","r");
fgets( packet, 100, f1 );
stlen=strlen(packet);
packet[stlen-1]='\0';
fclose(f1);
strcpy(cmd,"rm t1");
system(cmd);
// Now packet and hsh have filehashes of the two files =======================
if(strcmp(packet,hsh) == 0 ) printf(" TRANSFER COMPLETE\n");
else {
printf("ERROR md5 shows error, will RE_REQUEST FILE\n") ;
goto resend;
}
}
else printf("ERROR unknown as file names dont match\n");
}
else printf("Wrong use of download");
}
else if(strcmp(pch,"Allow") == 0)
{
close(fd[1]);
int nbytes = read(fd[0],fileName,sizeof(fileName));
strcpy(send_data,"Download ");
strcat(send_data,fileName);
goto shortcut;
}
else if(strcmp(pch,"Stop") == 0)
{
//close(fd[1]);
printf("Process stopped\n");
}
else{
//normal text===================================================
if ((strcmp(send_data , "q") == 0 || strcmp(send_data , "Q") == 0) || timeToclose ==1)
{
if(timeToclose)printf("bbye\n");
send(connected, send_data,strlen(send_data), 0);
fflush(stdout);
close(connected);
kill(childPid, SIGTERM);
exit(0);
break;
}
else
send(connected, send_data,strlen(send_data), 0);
}
}
}
return;
}
void server(int s1){
int sock, connected, true = 1,bytes_recieved;
char send_data [1024],recv_data[1024],copy[1024];
char regex[100];
struct sockaddr_in server_addr,client_addr;
int sin_size;
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("Socket");
exit(1);
}
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(s1);
server_addr.sin_addr.s_addr = INADDR_ANY;
bzero(&(server_addr.sin_zero),8);
//binded socket to required port
if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr))
== -1) {
perror("Unable to bind");
exit(1);
}
if (listen(sock, 5) == -1) {
perror("Listen");
exit(1);
}
printf("\nTCPServer Waiting for client on port %d\n",s1);
fflush(stdout);
sin_size = sizeof(struct sockaddr_in);
//connected represents the client server connection
connected = accept(sock, (struct sockaddr *)&client_addr,&sin_size);
printf("\n I got a connection from (%s , %d)",
inet_ntoa(client_addr.sin_addr),ntohs(client_addr.sin_port));
char * pch;
fflush(stdout);
char command[1024];
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< SOME VARIABLES FOR SHORTLIST >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
char lower[100],upper[100],cpy[1000];
int cntr=0;
char buff[1000];
//char * pch;
FILE *fpr;
FILE *fpr2;
int place=0;
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
while (1)
{
//waits for client to send data
bytes_recieved=recv(connected,recv_data,1024,0);
recv_data[bytes_recieved] = '\0';
if (strcmp(recv_data , "q") == 0 || strcmp(recv_data , "Q") == 0)
{ printf("have to close\n");
timeToclose = 1;
close(connected);
//exit(0);
break;
}
else if(recv_data[0]=='F' && recv_data[1]=='C')
{//its FileHash CheckAll
system("find . -type f -exec sh -c 'printf \"%s %s \n\" \"$(ls -l --time-style=+%Y%m%d%H%M%S $1 )\" \"$(md5sum $1 | cut -d\" \" -f1)\"' '' '{}' '{}' \\; | awk '{print $7, $6, $8}' > checkall");
//file to be sent here checkall
FILE *fp = fopen("checkall","r");
if(fp == NULL)
{
printf("wrong file\n");
continue;
}
//=================told the client that file is to be sent========================
//fgets ( data, sizeof(data), fp ) != NULL
// char data[1024];
memset(send_data,0,1024);
int byteR,sentN;
while(!feof(fp))
{ //memset(send_data,0,1024);
byteR = fread(send_data,1,1024,fp);
send_data[byteR] = '\0';
// byteR = strlen(data);
// if(byteR == 0) break
sentN = write(connected,send_data,1024);
//printf("%s",send_data);
//printf("read %d sent %d--------\n",sentN,byteR);
//===============================file sent=================================================
}
//printf("End file\n");
memset(send_data,0,1024);
char end[]= "End Of File";
strcpy(send_data,end);
write(connected,send_data,1024);
fclose(fp);
//when sent file comment next 2 lines
//strcpy(send_data,"ANS here is the filehash checkall...... :P");
//send(connected, send_data,strlen(send_data), 0);
//printf("recv_data after check all : %s \n",recv_data);
continue;
}
else if(recv_data[0]=='F' && recv_data[1]=='V')
{
// printf("Identified FV\n");
strncpy(regex,(char*)recv_data+2,100);
printf("Verifying %s\n",regex);
strcpy(command,"openssl md5 ");
strcat(command,regex);
strcat(command," | cut -d\" \" -f2 > md5");
system(command);
strcpy(command,"date -r ./");
strcat(command,regex);
strcat(command," +%Y%m%d%H%M%S > date");
system(command);
strcpy(command,"paste md5 date > verify");
//strcat(command," > ir");
system(command);
strcpy(command,"rm md5 date");
system(command);
FILE *fp = fopen("verify","r");
if(fp == NULL)
{
printf("wrong file\n");
continue;
}
//=================told the client that file is to be sent========================
//fgets ( data, sizeof(data), fp ) != NULL
// char data[1024];
memset(send_data,0,1024);
int byteR,sentN;
while(!feof(fp))
{ //memset(send_data,0,1024);
byteR = fread(send_data,1,1024,fp);
send_data[byteR] = '\0';
// byteR = strlen(data);
// if(byteR == 0) break
// fflush(stdout);
//void *temp = data;
sentN = write(connected,send_data,1024);
//printf("%s",send_data);
//printf("read %d sent %d--------\n",sentN,byteR);
//===============================file sent=================================================
}
// printf("End file\n");
memset(send_data,0,1024);
char end[]= "End Of File";
strcpy(send_data,end);
write(connected,send_data,1024);
fclose(fp);
//strcpy(send_data,"ANS here is the filehash verify...... :P");
//send(connected, send_data,strlen(send_data), 0);
//printf("recv_data after verify : %s \n",recv_data);
continue;
}
else if(recv_data[0]=='I' && recv_data[1]=='L')
{
//system("ls -l > longlist");
system("find . -printf '%p %TY%Tm%Td%TH%Tm%Tm %k \n' > il");
//file to be sent here longlist
FILE *fp = fopen("il","r");
if(fp == NULL)
{
printf("wrong file\n");
continue;
}
//=================told the client that file is to be sent========================
//fgets ( data, sizeof(data), fp ) != NULL
// char data[1024];
memset(send_data,0,1024);
int byteR,sentN;
while(!feof(fp))
{ //memset(send_data,0,1024);
byteR = fread(send_data,1,1024,fp);
send_data[byteR] = '\0';
// byteR = strlen(data);
// if(byteR == 0) break
// fflush(stdout);
//void *temp = data;
sentN = write(connected,send_data,1024);
printf("%s",send_data);
printf("read %d sent %d--------\n",sentN,byteR);
//===============================file sent=================================================
}
printf("End file\n");
memset(send_data,0,1024);
char end[]= "End Of File";
strcpy(send_data,end);
write(connected,send_data,1024);
fclose(fp);
//strcpy(send_data,"ANS here is the list...... :P");
//send(connected, send_data,strlen(send_data), 0);
printf("recv_data after longlist : %s \n",recv_data);
continue;
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< SHORTLIST >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> TO BE COPIED BEFORE IR
else if(recv_data[0] == 'I' && recv_data[1]=='S')
{
printf("Identified ID\n");
strncpy(regex,(char*)recv_data+2,100);
printf("Timestamps are is %s\n",regex);
pch = strtok (regex," ");
strcpy(lower,pch);
//printf("timestamp 1 : %s\n",pch);
pch = strtok (NULL, " ");
strcpy(upper,pch);
//printf("timestamp 2 : %s\n",pch);
system("ls -l --time-style=+%Y%m%d%H%M%S -t > ls");
fpr = fopen( "ls", "r" );
fpr2 = fopen( "is", "w" );
while ( fgets( buff, 1000, fpr ) != NULL )
{
if(cntr!=0 && cntr!=1)
{
printf("%d hahaha %s",cntr,buff);
strcpy(cpy,buff);
place=0;
pch = strtok (buff," ");
while (pch != NULL)
{
if(place==5)
{
printf("%s\n", pch);
if(strcmp(pch,lower)>0 && strcmp(pch,upper)<0)
{
printf("printing\n");
fprintf(fpr2,"%s",cpy);
}
}
place++;
pch = strtok (NULL," ");
}
}
cntr++;
}
fclose( fpr );
fclose( fpr2 );
FILE *fp = fopen("is","r");
if(fp == NULL)
{
printf("wrong file\n");
continue;
}
//=================told the client that file is to be sent========================
memset(send_data,0,1024);
int byteR,sentN;
while(!feof(fp))
{ //memset(send_data,0,1024);
byteR = fread(send_data,1,1024,fp);
send_data[byteR] = '\0';
// byteR = strlen(data);
// if(byteR == 0) break
// fflush(stdout);
//void *temp = data;
sentN = write(connected,send_data,1024);
printf("%s",send_data);
printf("read %d sent %d--------\n",sentN,byteR);
//===============================file sent=================================================
}
// printf("End file\n");
memset(send_data,0,1024);
char end[]= "End Of File";
strcpy(send_data,end);
write(connected,send_data,1024);
fclose(fp);
// printf("recv_data after regex : %s \n",recv_data);
continue;
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//Regex uses find to get output of files and then
else if(recv_data[0]=='I' && recv_data[1]=='R')
{
//printf("Identified IR\n");
strncpy(regex,(char*)recv_data+2,100);
//printf("Regex is %s\n",regex);
strcpy(command,"find . -name \"");
strcat(command,regex);
strcat(command,"\" > ir");
system(command);
//file to be sent here longlist
FILE *fp = fopen("ir","r");
if(fp == NULL)
{
printf("wrong file\n");
continue;
}
//=================told the client that file is to be sent========================
memset(send_data,0,1024);
int byteR,sentN;
while(!feof(fp))
{ //memset(send_data,0,1024);
byteR = fread(send_data,1,1024,fp);
send_data[byteR] = '\0';
sentN = write(connected,send_data,1024);
printf("%s",send_data);
printf("read %d sent %d--------\n",sentN,byteR);
//===============================file sent=================================================
}
printf("End file\n");
memset(send_data,0,1024);
char end[]= "End Of File";
strcpy(send_data,end);
write(connected,send_data,1024);
fclose(fp);
continue;
}
else if(strlen(recv_data)>2 && recv_data[0]=='U' && recv_data[1]==' ')
{
char arr[100];
strncpy(arr,(char*)recv_data+2,100);
printf("Someone wants to Upload File : %s\n Type \"Allow\" to let them; \"Stop\" to prevent them\n",arr);
// send(connected,recv_data,1024,0);
close(fd[0]);
write(fd[1],arr,strlen(arr)+1);
}
else if(strlen(recv_data)>2 && recv_data[0]=='D' && recv_data[1]==' ')
{
char arr[100];
strcpy(arr,recv_data+2);
//strcat(arr,pch);
printf("Sending %s\n",arr);
FILE *fp = fopen(arr,"r");
if(fp == NULL)
{
printf("wrong file\n");
continue;
}
//=================told the client that file is to be sent========================
//fgets ( data, sizeof(data), fp ) != NULL
// char data[1024];
memset(send_data,0,1024);
int byteR,sentN;
while(!feof(fp))
{ //memset(send_data,0,1024);
byteR = fread(send_data,1,1024,fp);
sentN = write(connected,send_data,byteR);
//===============================file sent=================================================
}
// printf("End file\n");
memset(send_data,0,1024);
char end[]= "End Of File";
strcpy(send_data,end);
write(connected,send_data,1024);
fclose(fp);
//File sent fully
//sending hash of this file for confirmation at other end
char fname[100];
//gets(fname);
strcpy(fname,arr);
char packet[1024];
char cmd[1000],temp[100];
int stlen,ii;
strcpy(cmd,"md5sum ");
strcat(cmd,fname);
strcat(cmd," | awk '{print $2, $1}'> t1");
system(cmd);
strcpy(cmd,"stat -c%s ");
strcat(cmd,fname);
strcat(cmd," > t2");
system(cmd);
strcpy(cmd,"paste t1 t2 | awk '{print $1, $2, $3}' > md5");
system(cmd);
strcpy(cmd,"rm t1 t2");
system(cmd);
FILE *f1= fopen("md5","r");
fgets( packet, 100, f1 );
stlen=strlen(packet);
packet[stlen-1]='\0';
printf("length of packet now is %d\n",strlen(packet));
printf("packet header : %s\n",packet);
fclose(f1);
strcpy(cmd,"rm md5");
system(cmd);
memset(send_data,0,1024);
//char end[]= "End Of File";
strcpy(send_data,packet);
write(connected,send_data,1024);
}
else{//prints out all of it
printf("%s\n" , recv_data);
fflush(stdout);
}
}
close(sock);
//waitpid(pid,NULL,0);
}
int main()
{
int pid;
int s1,choice=0;
printf("enter s port\n");
scanf("%d",&s1);
printf("enter 0 for tcp mode and 1 for udp mode\n");
scanf("%d",&choice);
timeToclose = 0;
pipe(fd);
childPid = getpid();
pid = fork();
if(!pid)
{
//-------------------client----------------------------------------------
//fprintf(stderr,"kiddo\n");
int c1;
scanf("%d",&c1);
if(choice==0)
client(c1);
else
uclient(c1);
}
else {
//listening socket aka server
if(choice==0)
server(s1);
else
userver(s1);
}
return 0;
}
|
the_stack_data/976379.c | // SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2019 Intel Corporation. All rights reserved.
//
// Author: Artur Kloniecki <[email protected]>
#if CONFIG_COMP_MUX
#include <sof/audio/buffer.h>
#include <sof/audio/component.h>
#include <sof/audio/format.h>
#include <sof/audio/mux.h>
#include <sof/bit.h>
#include <sof/common.h>
#include <ipc/stream.h>
#include <stddef.h>
#include <stdint.h>
static void mux_check_for_wrap(struct audio_stream *sink,
const struct audio_stream **sources,
struct mux_look_up *lookup)
{
const struct audio_stream *source;
uint32_t elem;
/* check sources and destinations for wrap */
for (elem = 0; elem < lookup->num_elems; elem++) {
source = sources[lookup->copy_elem[elem].stream_id];
lookup->copy_elem[elem].dest =
audio_stream_wrap(sink, lookup->copy_elem[elem].dest);
lookup->copy_elem[elem].src =
audio_stream_wrap(source, lookup->copy_elem[elem].src);
}
}
static void demux_check_for_wrap(struct audio_stream *sink,
const struct audio_stream *source,
struct mux_look_up *lookup)
{
uint32_t elem;
/* check sources and destinations for wrap */
for (elem = 0; elem < lookup->num_elems; elem++) {
lookup->copy_elem[elem].dest =
audio_stream_wrap(sink, lookup->copy_elem[elem].dest);
lookup->copy_elem[elem].src =
audio_stream_wrap(source, lookup->copy_elem[elem].src);
}
}
#if CONFIG_FORMAT_S16LE
static uint32_t demux_calc_frames_without_wrap_s16(struct comp_dev *dev,
struct audio_stream *sink,
const struct audio_stream
*source,
struct mux_look_up *lookup)
{
uint32_t frames;
uint32_t min_frames;
void *ptr;
/* for demux we process each source buffer separately - dest/src for
* each copy_elem refers to the same sink/source buffer, so min_frames
* calculation based only on lookup table first element is sufficient.
*/
ptr = (int16_t *)lookup->copy_elem[0].dest -
lookup->copy_elem[0].out_ch;
min_frames = audio_stream_frames_without_wrap(sink, ptr);
ptr = (int16_t *)lookup->copy_elem[0].src -
lookup->copy_elem[0].in_ch;
frames = audio_stream_frames_without_wrap(source, ptr);
min_frames = (frames < min_frames) ? frames : min_frames;
return min_frames;
}
static uint32_t mux_calc_frames_without_wrap_s16(struct comp_dev *dev,
struct audio_stream *sink,
const struct audio_stream
**sources,
struct mux_look_up *lookup)
{
const struct audio_stream *source;
uint32_t frames;
uint32_t min_frames;
uint32_t elem;
void *ptr;
/* dest pointer for all copy_elems in lookup refers to the same
* sink buffer (mux has one sink buffer), so dest min_frames
* calculation based only on lookup table first element is sufficient.
*/
ptr = (int16_t *)lookup->copy_elem[0].dest -
lookup->copy_elem[0].out_ch;
min_frames = audio_stream_frames_without_wrap(sink, ptr);
for (elem = 0; elem < lookup->num_elems; elem++) {
source = sources[lookup->copy_elem[elem].stream_id];
ptr = (int16_t *)lookup->copy_elem[elem].src -
lookup->copy_elem[elem].in_ch;
frames = audio_stream_frames_without_wrap(source, ptr);
min_frames = (frames < min_frames) ? frames : min_frames;
}
return min_frames;
}
static void mux_init_look_up_pointers_s16(struct comp_dev *dev,
struct audio_stream *sink,
const struct audio_stream **sources,
struct mux_look_up *lookup)
{
const struct audio_stream *source;
uint32_t elem;
/* init pointers */
for (elem = 0; elem < lookup->num_elems; elem++) {
source = sources[lookup->copy_elem[elem].stream_id];
lookup->copy_elem[elem].src = (int16_t *)source->r_ptr +
lookup->copy_elem[elem].in_ch;
lookup->copy_elem[elem].src_inc = source->channels;
lookup->copy_elem[elem].dest = (int16_t *)sink->w_ptr +
lookup->copy_elem[elem].out_ch;
lookup->copy_elem[elem].dest_inc = sink->channels;
}
}
static void demux_init_look_up_pointers_s16(struct comp_dev *dev,
struct audio_stream *sink,
const struct audio_stream *source,
struct mux_look_up *lookup)
{
uint32_t elem;
/* init pointers */
for (elem = 0; elem < lookup->num_elems; elem++) {
lookup->copy_elem[elem].src = (int16_t *)source->r_ptr +
lookup->copy_elem[elem].in_ch;
lookup->copy_elem[elem].src_inc = source->channels;
lookup->copy_elem[elem].dest = (int16_t *)sink->w_ptr +
lookup->copy_elem[elem].out_ch;
lookup->copy_elem[elem].dest_inc = sink->channels;
}
}
/**
* Source stream are routed to sinks with regard to look up table based on
* routing bitmasks from mux_stream_data structures array. Each sink channel
* has it's own lookup[].copy_elem describing source and sink fragment of
* memory featured in copying.
*
* @param[in] dev Component device
* @param[in,out] sink Destination buffer.
* @param[in,out] sources Array of source buffers.
* @param[in] frames Number of frames to process.
* @param[in] lookup mux look up table.
*/
static void demux_s16le(struct comp_dev *dev, struct audio_stream *sink,
const struct audio_stream *source, uint32_t frames,
struct mux_look_up *lookup)
{
uint8_t i;
int16_t *src;
int16_t *dst;
uint32_t elem;
uint32_t frames_without_wrap;
comp_dbg(dev, "demux_s16le()");
if (!lookup || !lookup->num_elems)
return;
demux_init_look_up_pointers_s16(dev, sink, source, lookup);
while (frames) {
frames_without_wrap =
demux_calc_frames_without_wrap_s16(dev, sink, source,
lookup);
frames_without_wrap = MIN(frames, frames_without_wrap);
for (i = 0; i < frames_without_wrap; i++) {
for (elem = 0; elem < lookup->num_elems; elem++) {
src = (int16_t *)lookup->copy_elem[elem].src;
dst = (int16_t *)lookup->copy_elem[elem].dest;
*dst = *src;
lookup->copy_elem[elem].src = src +
lookup->copy_elem[elem].src_inc;
lookup->copy_elem[elem].dest = dst +
lookup->copy_elem[elem].dest_inc;
}
}
demux_check_for_wrap(sink, source, lookup);
frames -= frames_without_wrap;
}
}
/**
* Source streams are routed to sink with regard to look up table based on
* routing bitmasks from mux_stream_data structures array. Each sink channel
* has it's own lookup[].copy_elem describing source and sink fragment of
* memory featured in copying.
*
* @param[in] dev Component device
* @param[in,out] sink Destination buffer.
* @param[in,out] sources Array of source buffers.
* @param[in] frames Number of frames to process.
* @param[in] lookup mux look up table.
*/
static void mux_s16le(struct comp_dev *dev, struct audio_stream *sink,
const struct audio_stream **sources, uint32_t frames,
struct mux_look_up *lookup)
{
uint8_t i;
int16_t *src;
int16_t *dst;
uint32_t elem;
uint32_t frames_without_wrap;
comp_dbg(dev, "mux_s16le()");
if (!lookup || !lookup->num_elems)
return;
mux_init_look_up_pointers_s16(dev, sink, sources, lookup);
while (frames) {
frames_without_wrap =
mux_calc_frames_without_wrap_s16(dev, sink, sources,
lookup);
frames_without_wrap = MIN(frames, frames_without_wrap);
for (i = 0; i < frames_without_wrap; i++) {
for (elem = 0; elem < lookup->num_elems; elem++) {
src = (int16_t *)lookup->copy_elem[elem].src;
dst = (int16_t *)lookup->copy_elem[elem].dest;
*dst = *src;
lookup->copy_elem[elem].src = src +
lookup->copy_elem[elem].src_inc;
lookup->copy_elem[elem].dest = dst +
lookup->copy_elem[elem].dest_inc;
}
}
mux_check_for_wrap(sink, sources, lookup);
frames -= frames_without_wrap;
}
}
#endif /* CONFIG_FORMAT_S16LE */
#if CONFIG_FORMAT_S24LE || CONFIG_FORMAT_S32LE
static uint32_t mux_calc_frames_without_wrap_s32(struct comp_dev *dev,
struct audio_stream *sink,
const struct audio_stream
**sources,
struct mux_look_up *lookup)
{
const struct audio_stream *source;
uint32_t frames;
uint32_t min_frames;
uint32_t elem;
void *ptr;
/* dest pointer for all copy_elems in lookup refers to the same
* sink buffer (mux has one sink buffer), so dest min_frames
* calculation based only on lookup table first element is sufficient.
*/
ptr = (int32_t *)lookup->copy_elem[0].dest -
lookup->copy_elem[0].out_ch;
min_frames = audio_stream_frames_without_wrap(sink, ptr);
for (elem = 0; elem < lookup->num_elems; elem++) {
source = sources[lookup->copy_elem[elem].stream_id];
ptr = (int32_t *)lookup->copy_elem[elem].src -
lookup->copy_elem[elem].in_ch;
frames = audio_stream_frames_without_wrap(source, ptr);
min_frames = (frames < min_frames) ? frames : min_frames;
}
return min_frames;
}
static uint32_t demux_calc_frames_without_wrap_s32(struct comp_dev *dev,
struct audio_stream *sink,
const struct audio_stream
*source,
struct mux_look_up *lookup)
{
uint32_t frames;
uint32_t min_frames;
void *ptr;
/* for demux we process each source buffer separately - dest/src for
* each copy_elem refers to the same sink/source buffer, so min_frames
* calculation based only on lookup table first element is sufficient.
*/
ptr = (int32_t *)lookup->copy_elem[0].dest -
lookup->copy_elem[0].out_ch;
min_frames = audio_stream_frames_without_wrap(sink, ptr);
ptr = (int32_t *)lookup->copy_elem[0].src -
lookup->copy_elem[0].in_ch;
frames = audio_stream_frames_without_wrap(source, ptr);
min_frames = (frames < min_frames) ? frames : min_frames;
return min_frames;
}
static void mux_init_look_up_pointers_s32(struct comp_dev *dev,
struct audio_stream *sink,
const struct audio_stream **sources,
struct mux_look_up *lookup)
{
const struct audio_stream *source;
uint32_t elem;
/* init pointers */
for (elem = 0; elem < lookup->num_elems; elem++) {
source = sources[lookup->copy_elem[elem].stream_id];
lookup->copy_elem[elem].src = (int32_t *)source->r_ptr +
lookup->copy_elem[elem].in_ch;
lookup->copy_elem[elem].src_inc = source->channels;
lookup->copy_elem[elem].dest = (int32_t *)sink->w_ptr +
lookup->copy_elem[elem].out_ch;
lookup->copy_elem[elem].dest_inc = sink->channels;
}
}
static void demux_init_look_up_pointers_s32(struct comp_dev *dev,
struct audio_stream *sink,
const struct audio_stream *source,
struct mux_look_up *lookup)
{
uint32_t elem;
/* init pointers */
for (elem = 0; elem < lookup->num_elems; elem++) {
lookup->copy_elem[elem].src = (int32_t *)source->r_ptr +
lookup->copy_elem[elem].in_ch;
lookup->copy_elem[elem].src_inc = source->channels;
lookup->copy_elem[elem].dest = (int32_t *)sink->w_ptr +
lookup->copy_elem[elem].out_ch;
lookup->copy_elem[elem].dest_inc = sink->channels;
}
}
/**
* Source stream are routed to sinks with regard to look up table based on
* routing bitmasks from mux_stream_data structures array. Each sink channel
* has it's own lookup[].copy_elem describing source and sink fragment of
* memory featured in copying.
*
* @param[in] dev Component device
* @param[in,out] sink Destination buffer.
* @param[in,out] sources Array of source buffers.
* @param[in] frames Number of frames to process.
* @param[in] lookup mux look up table.
*/
static void demux_s32le(struct comp_dev *dev, struct audio_stream *sink,
const struct audio_stream *source, uint32_t frames,
struct mux_look_up *lookup)
{
uint8_t i;
int32_t *src;
int32_t *dst;
uint32_t elem;
uint32_t frames_without_wrap;
comp_dbg(dev, "demux_s32le");
if (!lookup || !lookup->num_elems)
return;
demux_init_look_up_pointers_s32(dev, sink, source, lookup);
while (frames) {
frames_without_wrap =
demux_calc_frames_without_wrap_s32(dev, sink, source,
lookup);
frames_without_wrap = MIN(frames, frames_without_wrap);
for (i = 0; i < frames_without_wrap; i++) {
for (elem = 0; elem < lookup->num_elems; elem++) {
src = (int32_t *)lookup->copy_elem[elem].src;
dst = (int32_t *)lookup->copy_elem[elem].dest;
*dst = *src;
lookup->copy_elem[elem].src = src +
lookup->copy_elem[elem].src_inc;
lookup->copy_elem[elem].dest = dst +
lookup->copy_elem[elem].dest_inc;
}
}
demux_check_for_wrap(sink, source, lookup);
frames -= frames_without_wrap;
}
}
/**
* Source streams are routed to sink with regard to look up table based on
* routing bitmasks from mux_stream_data structures array. Each sink channel
* has it's own lookup[].copy_elem describing source and sink fragment of
* memory featured in copying.
*
* @param[in] dev Component device
* @param[in,out] sink Destination buffer.
* @param[in,out] sources Array of source buffers.
* @param[in] frames Number of frames to process.
* @param[in] lookup mux look up table.
*/
static void mux_s32le(struct comp_dev *dev, struct audio_stream *sink,
const struct audio_stream **sources, uint32_t frames,
struct mux_look_up *lookup)
{
uint8_t i;
int32_t *src;
int32_t *dst;
uint32_t elem;
uint32_t frames_without_wrap;
comp_dbg(dev, "mux_s32le()");
if (!lookup || !lookup->num_elems)
return;
mux_init_look_up_pointers_s32(dev, sink, sources, lookup);
while (frames) {
frames_without_wrap =
mux_calc_frames_without_wrap_s32(dev, sink, sources,
lookup);
frames_without_wrap = MIN(frames, frames_without_wrap);
for (i = 0; i < frames_without_wrap; i++) {
for (elem = 0; elem < lookup->num_elems; elem++) {
src = (int32_t *)lookup->copy_elem[elem].src;
dst = (int32_t *)lookup->copy_elem[elem].dest;
*dst = *src;
lookup->copy_elem[elem].src = src +
lookup->copy_elem[elem].src_inc;
lookup->copy_elem[elem].dest = dst +
lookup->copy_elem[elem].dest_inc;
}
}
mux_check_for_wrap(sink, sources, lookup);
frames -= frames_without_wrap;
}
}
#endif /* CONFIG_FORMAT_S24LE CONFIG_FORMAT_S32LE */
const struct comp_func_map mux_func_map[] = {
#if CONFIG_FORMAT_S16LE
{ SOF_IPC_FRAME_S16_LE, &mux_s16le, &demux_s16le },
#endif
#if CONFIG_FORMAT_S24LE
{ SOF_IPC_FRAME_S24_4LE, &mux_s32le, &demux_s32le },
#endif
#if CONFIG_FORMAT_S32LE
{ SOF_IPC_FRAME_S32_LE, &mux_s32le, &demux_s32le },
#endif
};
void mux_prepare_look_up_table(struct comp_dev *dev)
{
struct comp_data *cd = comp_get_drvdata(dev);
uint8_t i;
uint8_t j;
uint8_t k;
uint8_t idx = 0;
/* Prepare look up table */
for (i = 0; i < cd->config.num_streams; i++) {
for (j = 0; j < PLATFORM_MAX_CHANNELS; j++) {
for (k = 0; k < PLATFORM_MAX_CHANNELS; k++) {
if (cd->config.streams[i].mask[j] & BIT(k)) {
/* MUX component has only one sink */
cd->lookup[0].copy_elem[idx].in_ch = j;
cd->lookup[0].copy_elem[idx].out_ch = k;
cd->lookup[0].copy_elem[idx].stream_id =
i;
cd->lookup[0].num_elems = ++idx;
}
}
}
}
}
void demux_prepare_look_up_table(struct comp_dev *dev)
{
struct comp_data *cd = comp_get_drvdata(dev);
uint8_t i;
uint8_t j;
uint8_t k;
uint8_t idx;
/* Prepare look up table */
for (i = 0; i < cd->config.num_streams; i++) {
idx = 0;
for (j = 0; j < PLATFORM_MAX_CHANNELS; j++) {
for (k = 0; k < PLATFORM_MAX_CHANNELS; k++) {
if (cd->config.streams[i].mask[j] & BIT(k)) {
/* DEMUX component has only one source */
cd->lookup[i].copy_elem[idx].in_ch = k;
cd->lookup[i].copy_elem[idx].out_ch = j;
cd->lookup[i].copy_elem[idx].stream_id =
i;
cd->lookup[i].num_elems = ++idx;
}
}
}
}
}
mux_func mux_get_processing_function(struct comp_dev *dev)
{
struct comp_buffer *sinkb;
uint8_t i;
if (list_is_empty(&dev->bsink_list))
return NULL;
sinkb = list_first_item(&dev->bsink_list, struct comp_buffer,
source_list);
for (i = 0; i < ARRAY_SIZE(mux_func_map); i++) {
if (sinkb->stream.frame_fmt == mux_func_map[i].frame_format)
return mux_func_map[i].mux_proc_func;
}
return NULL;
}
demux_func demux_get_processing_function(struct comp_dev *dev)
{
struct comp_buffer *sourceb;
uint8_t i;
if (list_is_empty(&dev->bsource_list))
return NULL;
sourceb = list_first_item(&dev->bsource_list, struct comp_buffer,
sink_list);
for (i = 0; i < ARRAY_SIZE(mux_func_map); i++) {
if (sourceb->stream.frame_fmt == mux_func_map[i].frame_format)
return mux_func_map[i].demux_proc_func;
}
return NULL;
}
#endif /* CONFIG_COMP_MUX */
|
the_stack_data/179826724.c | /*Exercise 2 : Practice to write a simple function
Write a function called circleArea() that take the radius of a circle as an argument and
calculate and return the area. In the main program read the radius value from the user, call
circleArea() and display the result. */
#include <stdio.h>
float circleArea(float radius);
int main(void)
{
float r;
printf("Enter Radius : ");
scanf("%f",&r);//input radius
printf("Area = %.2f",circleArea(r));//print aria
}
float circleArea(float radius)
{
return (22/7.0)*radius*radius;
}//end of main function
|
the_stack_data/45127.c | // Search for an element in a linked list
#include<stdio.h>
#include<stdlib.h>
#include <stdbool.h>
typedef struct node{
int number;
struct node *next;
} node;
// Create Linked List
node *createList(struct node *list, struct node *temp, struct node *tail);
// Element searching in a linked list
bool searchNode(struct node *list, int elm);
// Free Linked List
void freeLinkedList(struct node *list);
int main(void) {
struct node *list = NULL;
// Initialize nodes
struct node *tail; // Current node
struct node *temp; // Temporary node
list = createList(list, temp, tail);
if (list == NULL) {
return 1;
}
// Get element to search in linked list
int search_elm;
printf("\nProvide search element: ");
scanf("%i", &search_elm);
// Search for a node in a linked list
bool elmFound = false;
elmFound = searchNode(list, search_elm);
if (list == NULL) {
return 1;
}
if (elmFound) {
printf("Element found in linked list.\n");
} else {
printf("Element NOT found in linked list.\n");
}
freeLinkedList(list);
}
node *createList(struct node *list, struct node *temp, struct node *tail) {
list = NULL;
// User to determine size / length of linked list
int n;
printf("Create a Linked List\nHow many nodes in list? ");
scanf("%i", &n);
for(int i = 1; i <= n; i++) {
// allocate memory to store current node / tail
tail = malloc(sizeof(node));
if (tail == NULL) {
return (NULL);
}
// Prompt for linked list node value
printf("Input Node %i Value: ", i);
scanf("%i", &tail->number);
if (i == 1) {
temp = list = tail;
} else {
temp->next = tail;
temp = tail;
}
}
return list;
}
// Search for a node in a linked list
bool searchNode(struct node *list, int elm) {
// create a temp node to hold current tail node
struct node *temp = list;
while(temp->next != NULL) {
if (temp->number == elm) {
return true;
}
temp = temp->next;
}
return false;
}
void freeLinkedList(struct node *list) {
// Free linked list
while (list != NULL) {
node *temp = list->next;
free(list);
list = temp;
}
}
|
the_stack_data/122016325.c | #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int find_nth_term(int n, int a, int b, int c) {
if(n==1) return a;
if(n==2) return b;
if(n==3) return c;
return find_nth_term(n-1,a,b,c)+find_nth_term(n-2,a,b,c)+find_nth_term(n-3,a,b,c);
}
int main() {
int n, a, b, c;
scanf("%d %d %d %d", &n, &a, &b, &c);
int ans = find_nth_term(n, a, b, c);
printf("%d", ans);
return 0;
}
|
the_stack_data/115765707.c | #include <stdio.h>
struct point
{
int x;
int y;
};
struct point point_array[100];
int main()
{
int my_point = 10;
point_array[my_point].x = 12;
point_array[my_point].y = 56;
printf("%d, %d\n", point_array[my_point].x, point_array[my_point].y);
return 0;
}
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
|
the_stack_data/82327.c | /*
urlenc.c
Copyright (c) 2010 Duo Security
Copyright (c) 1996 - 2010, Daniel Stenberg, <[email protected]>.
All rights reserved.
Permission to use, copy, modify, and distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright
notice and this permission notice appear in all copies.
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 OF THIRD PARTY RIGHTS. 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.
Except as contained in this notice, the name of a copyright holder shall not
be used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization of the copyright holder.
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
Adapted from libcurl to honor RFC 3986 unreserved characters, add
'+' space encoding, and check memory allocation failures
*/
char *
urlenc_encode(const char *string)
{
size_t alloc, newlen;
char *ns = NULL, *testing_ptr = NULL;
unsigned char in;
size_t strindex=0;
size_t length;
if (!string) return strdup("");
alloc = strlen(string) + 1;
newlen = alloc;
if ((ns = malloc(alloc)) == NULL)
return (NULL);
length = alloc-1;
while (length--) {
in = *string;
switch(in){
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case 'a': case 'b': case 'c': case 'd': case 'e':
case 'f': case 'g': case 'h': case 'i': case 'j':
case 'k': case 'l': case 'm': case 'n': case 'o':
case 'p': case 'q': case 'r': case 's': case 't':
case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
case 'A': case 'B': case 'C': case 'D': case 'E':
case 'F': case 'G': case 'H': case 'I': case 'J':
case 'K': case 'L': case 'M': case 'N': case 'O':
case 'P': case 'Q': case 'R': case 'S': case 'T':
case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
case '_': case '~': case '.': case '-':
ns[strindex++] = in;
break;
default:
newlen += 2; /* this'll become a %XX */
if (newlen > alloc) {
alloc *= 2;
if ((testing_ptr = realloc(ns, alloc)) == NULL) {
free(ns);
return (NULL);
}
ns = testing_ptr;
}
snprintf(&ns[strindex], 4, "%%%02X", in);
strindex += 3;
break;
}
string++;
}
ns[strindex] = 0;
return (ns);
}
char *
urlenc_decode(const char *string, size_t *olen)
{
size_t alloc, strindex=0;
char *ns = NULL;
unsigned char in;
long hex;
if (!string) return NULL;
alloc = strlen(string) + 1;
if ((ns = malloc(alloc)) == NULL)
return (NULL);
while(--alloc > 0) {
in = *string;
if (('%' == in) && isxdigit(string[1]) && isxdigit(string[2])) {
char hexstr[3]; /* '%XX' */
hexstr[0] = string[1];
hexstr[1] = string[2];
hexstr[2] = 0;
hex = strtol(hexstr, NULL, 16);
in = (unsigned char)hex; /* hex is always < 256 */
string += 2;
alloc -= 2;
} else if ('+' == in) {
in = ' ';
}
ns[strindex++] = in;
string++;
}
ns[strindex] = 0;
if (olen) *olen = strindex;
return (ns);
}
|
the_stack_data/102992.c | /* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <errno.h>
#include <signal.h>
#define __need_NULL
#include <stddef.h>
/* Combine sets LEFT and RIGHT by logical AND and place result in DEST. */
int sigandset (sigset_t *dest, const sigset_t *left, const sigset_t *right)
{
if (dest == NULL || left == NULL || right == NULL)
{
__set_errno (EINVAL);
return -1;
}
return __sigandset (dest, left, right);
}
|
the_stack_data/126702891.c | /** ***************************************************************************
* @file processNovAtelGPS.c interface NovAtel OEM4 GPS receiver.
*
* THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
* PARTICULAR PURPOSE.
* @details
* This file provides parsing functions for NovAtel OEM4 GPS receiver.
*****************************************************************************/
/*******************************************************************************
Copyright 2018 ACEINNA, INC
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 GPS
#include <math.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "driverGPS.h"
#include "NovAtelPacketFormats.h"
#include "BITStatus.h"
#define CRC32_POLYNOMIAL 0xEDB88320
static gpsDeltaStruct downVelDelta;
/** ****************************************************************************
* @name processNovAtelBinaryMsg parse a complete NovAtel binary message.
*
* @param [in] msg - input buffer
* @param [in] msgLen - input buffer length
* @param [in] GPSData structure to parse into
* @retval N/A
******************************************************************************/
void processNovAtelBinaryMsg_Fast(char *msg,
unsigned int *msgLength,
GpsData_t *GPSData)
{
unsigned long calcuCRC;
uint32_t* pMsgCRC;
calcuCRC = _CalculateBlockCRC32((unsigned long)(*msgLength - 4),
(unsigned char *)&msg[0]);
pMsgCRC = (uint32_t*)&msg[*msgLength - 4];
if (calcuCRC == *pMsgCRC) {
switch ( *(unsigned short*)&msg[4] ) { // msgID
case 42: /// 0x2a bestPosB
case 47: /// 0x2b PSRPosB - PSeudoRange
_parseBestPosB_Fast((logBestPosB*)msg,
GPSData);
break;
case 99: /// 0x63 bestVelB
case 100: /// 0x64 PSRVelB - PSeudoRange
_parseBestVelB_Fast((logBestVelB*)msg,
GPSData);
break;
default:;
}
}
// bad CRC just return
}
/** ****************************************************************************
* @name parseNovAtelBinaryMsg parse a complete NovAtel binary message.
*
* @param [in] inByte - next byte from serial stream
* @param [in] gpsMsg - GPS message buffer
* @param [in] GPSData structure to parse into
* @retval N/A
******************************************************************************/
int parseNovotelBinaryMessage(uint8_t inByte, uint8_t *gpsMsg, GpsData_t *GPSData)
{
static int state = 0;
static unsigned int len = 0, headerLen = 0;
static uint8_t *ptr;
static uint32_t sync = 0;
unsigned static int totalLen = 0, msgLen = 0;
sync = (sync << 8) | inByte;
if ((sync & 0x00ffffff) == NOVATEL_OME4_BINARY_HEADER){
gpsMsg[0] = (NOVATEL_OME4_BINARY_HEADER >> 16) & 0xff;
gpsMsg[1] = (NOVATEL_OME4_BINARY_HEADER >> 8) & 0xff;
gpsMsg[2] = NOVATEL_OME4_BINARY_HEADER & 0xff;
state = 1;
ptr = &gpsMsg[3];
len = 3;
headerLen = 0;
return 0;
}
if(state == 0){
return 0;
}
*ptr++ = inByte;
len++;
if (len >= MAX_MSG_LENGTH){
// overflow - reset packet engine
state = 0;
return 1;
}
switch (state){
case 1:
// header processing
if (headerLen == 0){
headerLen = inByte;
}else if (len == headerLen){
msgLen = *((uint16_t *)&gpsMsg[8]);
totalLen = msgLen + headerLen + 4; // crc included
// data next
state = 2;
}
break;
case 2:
if (len == totalLen){
processNovAtelBinaryMsg_Fast((char *)gpsMsg, &len, GPSData);
state = 0;
}
break;
default:
break;
}
return 0;
}
void processNovAtelBinaryMsg(char *msg,
unsigned int *msgLength,
GpsData_t *GPSData)
{
unsigned char headerLength = 0;
unsigned short bodyLength = 0;
unsigned short msgID = 0;
unsigned long calcuCRC;
uint32_t* pRecCRC;
calcuCRC = _CalculateBlockCRC32( (unsigned long)(*msgLength - 4),
(unsigned char *)&msg[0]);
pRecCRC = (uint32_t*)&msg[*msgLength - 4];
if (calcuCRC == *pRecCRC) {
headerLength = msg[3];
bodyLength = *(unsigned short*)&msg[8];
msgID = *(unsigned short*)&msg[4];
switch (msgID) {
case 42: /// 0x2a bestPosB
case 47: /// 0x2b PSRPosB - PSeudoRange
_parseBestPosB(msg,
&headerLength,
&bodyLength,
GPSData);
break;
case 99: /// 0x63 bestVelB
case 100: /// 0x64 PSRVelB - PSeudoRange
_parseBestVelB(msg,
&headerLength,
&bodyLength,
GPSData);
break;
default:;
}
}
// bad CRC just return
}
/** ****************************************************************************
* @name _parseBestPosB LOCAL parse a BESTPOSB message.
* @author Doug Hiranaka
* @param [in] bestPosB - input buffer cast to best pos B
* @param [in] GPSData structure to parse into
* @retval N/A
1 BESTPOS header Log header H 0
2 sol stat Solution status, see Table 85 on page 408 Enum 4 H
3 pos type Position type, see Table 84 on page 407 Enum 4 H+4
4 lat Latitude 9 (degrees) Double 8 H+8
5 lon Longitude (degrees) Double 8 H+16
6 hgt Height above mean sea level (metres) Double 8 H+24
7 undulation - relationship between the geoid and ellipsoid (m) of the datum a Float 4 H+32
8 datum id# Datum ID number Enum 4 H+36
9 lat ? Latitude standard deviation (m) Float 4 H+40
10 lon ? Longitude standard deviation (m) Float 4 H+44
11 hgt ? Height standard deviation (m) Float 4 H+48
12 stn id Base station ID Char[4] 4 H+52
13 diff_age Differential age in seconds Float 4 H+56
14 sol_age Solution age in seconds Float 4 H+60
15 #SVs Number of satellites tracked Uchar 1 H+64
16 #solnSVs Number of satellites used in solution Uchar 1 H+65
17 #solnL1SVs Number of satellites with L1/E1/B1 used in solution Uchar 1 H+66
18 #solnMultiSVs # satellites with multi-frequency signals used in solution Uchar 1 H+67
19 Reserved Hex 1 H+68
20 ext sol stat Extended solution status Hex 1 H+69
21 Galileo and BeiDou sig mask Hex 1 H+70
22 GPS and GLONASS sig mask Hex 1 H+71
23 xxxx 32-bit CRC (ASCII and Binary only) Hex 4 H+72
******************************************************************************/
void _parseBestPosB_Fast(logBestPosB *bestPosB,
GpsData_t *GPSData)
{
GPSData->lat = bestPosB->Lat;
GPSData->lon = bestPosB->Lon;
GPSData->alt = bestPosB->hgt + bestPosB->undulation; // altitude above ellipsoid
GPSData->geoidAboveEllipsoid = bestPosB->undulation; // geoid above ellipsoid
if (bestPosB->sol_status != 0) // zero is good fix anything else is
{ // enumeration for bad fix
GPSData->gpsFixType = 0;// PosVelType
gBitStatus.hwStatus.bit.unlockedInternalGPS = 1; // locked
gBitStatus.swStatus.bit.noGPSTrackReference = 1; // no GPS track
gGpsDataPtr->HDOP = 21.0f; // force to above threshold
} else {
GPSData->gpsFixType = bestPosB->pos_type;
gBitStatus.hwStatus.bit.unlockedInternalGPS = 0; // locked
gBitStatus.swStatus.bit.noGPSTrackReference = 0; // GPS track
gGpsDataPtr->HDOP = 1.0f; // force to below threshold
}
//0xFFFFFFFC = b11111111111111111111111111111100
//0xFFFFFFFd = b11111111111111111111111111111101
//0xFFFFFFFe = b11111111111111111111111111111110
// If ITOW is the same as the value stored in GPSData->itow then it seems
// that velocity has already been measured at the current time step. If
// so then set the update flag accordingly, if not then set the GGA value
// only.
if( (bestPosB->header.milliseconds == GPSData->itow ) &&
(GPSData->updateFlagForEachCall & 0x02 ) ) ///GOT_GGA_MSG
{
GPSData->updateFlagForEachCall |= 3; //1 << GOT_GGA_MSG;
} else {
GPSData->updateFlagForEachCall = 1; //GPSData->updateFlagForEachCall & 0xFFFFFFFd;
}
GPSData->itow = (uint32_t) bestPosB->header.milliseconds;
GPSData->LLHCounter++;
float tmp = (float)1.9230769944E-2 * (float)bestPosB->header.week;
float tmpYear = (uint8_t)tmp;
GPSData->GPSyear = (uint8_t)( tmpYear - 20 );
GPSData->GPSmonth = (uint8_t)( ( tmp - tmpYear ) * 12 );
if( GPSData->GPSmonth < 1 ) {
GPSData->GPSmonth = 1;
} else if( GPSData->GPSmonth > 12 ) {
GPSData->GPSmonth = 12;
}
GPSData->GPSday = 1;
// Accuracy measurements
GPSData->GPSHorizAcc = sqrtf( bestPosB->lat_sigma * bestPosB->lat_sigma + bestPosB->lon_sigma * bestPosB->lon_sigma ); // [m]
GPSData->GPSVertAcc = bestPosB->hgt_sigma; // [m]
GPSData->numSatellites = bestPosB->num_obs;
}
/** ****************************************************************************
* @name _parseBestPosB LOCAL parse a BESTPOSB message.
* @author Dong An
* @param [in] completeMessage - input buffer
* @param [in] headerLength - header length
* @param [in] bodyLength - input buffer length
* @param [in] GPSData structure to parse into
* @retval N/A
1 BESTPOS header Log header H 0
2 sol stat Solution status, see Table 85 on page 408 Enum 4 H
3 pos type Position type, see Table 84 on page 407 Enum 4 H+4
4 lat Latitude 9 (degrees) Double 8 H+8
5 lon Longitude (degrees) Double 8 H+16
6 hgt Height above mean sea level (metres) Double 8 H+24
7 undulation - relationship between the geoid and ellipsoid (m) of the datum a Float 4 H+32
8 datum id# Datum ID number Enum 4 H+36
9 lat ? Latitude standard deviation (m) Float 4 H+40
10 lon ? Longitude standard deviation (m) Float 4 H+44
11 hgt ? Height standard deviation (m) Float 4 H+48
12 stn id Base station ID Char[4] 4 H+52
13 diff_age Differential age in seconds Float 4 H+56
14 sol_age Solution age in seconds Float 4 H+60
15 #SVs Number of satellites tracked Uchar 1 H+64
16 #solnSVs Number of satellites used in solution Uchar 1 H+65
17 #solnL1SVs Number of satellites with L1/E1/B1 used in solution Uchar 1 H+66
18 #solnMultiSVs # satellites with multi-frequency signals used in solution Uchar 1 H+67
19 Reserved Hex 1 H+68
20 ext sol stat Extended solution status Hex 1 H+69
21 Galileo and BeiDou sig mask Hex 1 H+70
22 GPS and GLONASS sig mask Hex 1 H+71
23 xxxx 32-bit CRC (ASCII and Binary only) Hex 4 H+72
******************************************************************************/
void _parseBestPosB(char *completeMessage,
unsigned char *headerLength,
unsigned short *bodyLength,
GpsData_t *GPSData)
{
char SolStatus[4];
// these are uint16_t but only looking at first byte
SolStatus[0] = completeMessage[ *headerLength];
GPSData->lat = _assembyToLongDouble((unsigned char*)&completeMessage[*headerLength + 8]); // lat
GPSData->lon = _assembyToLongDouble((unsigned char*)&completeMessage[*headerLength + 16]); // lon
GPSData->alt = _assembyToLongDouble((unsigned char*)&completeMessage[*headerLength + 24]); ///alt
GPSData->updateFlagForEachCall |= 1 << GOT_GGA_MSG;
if (SolStatus[0] != 0) { // zero is good fix anything else is enumeratio for bad fix
gGpsDataPtr->HDOP = 21.0f; // force to above threshold
gBitStatus.hwStatus.bit.unlockedInternalGPS = 1; // not locked
gBitStatus.swStatus.bit.noGPSTrackReference = 1; // no GPS track
} else {
gGpsDataPtr->HDOP = 1.0f; // force to below threshold
gBitStatus.hwStatus.bit.unlockedInternalGPS = 0; // locked
gBitStatus.swStatus.bit.noGPSTrackReference = 0; // GPS track
}
GPSData->gpsFixType = SolStatus[0];
memcpy(&GPSData->itow, &completeMessage[16], 4); ///Itow
GPSData->LLHCounter++;
}
/** ****************************************************************************
* @name _parseBestVelB LOCAL parse a BESTVELB message.
* @author Dong An
* @param [in] bestVelB - input buffer cast to bestVelB
* @param [in] GPSData structure to parse into
* @retval N/A
1 BESTVEL header Log header H 0
2 sol status Solution status (enum) 4 H
3 vel type Velocity type, see Table 84, Position or Velocity Type 4 H+4
4 latency in the velocity time tag in seconds. subrtrac from timeFloat 4 H+8
5 age Differential age in seconds Float 4 H+12
6 hor spd Horizontal speed over ground [m/s] Double 8 H+16
7 trk gnd (track over ground) True North, [deg] Double 8 H+24
8 vert spd Vertical speed, [m/s] + (up) - (down) Double 8 H+32
9 Reserved Float 4 H+40
10 xxxx 32-bit CRC (ASCII and Binary only) Hex 4 H+44
******************************************************************************/
void _parseBestVelB_Fast(logBestVelB *bestVelB,
GpsData_t *GPSData)
{
double radTrueCourse = 0.0;
GPSData->trueCourse = bestVelB->trk_gnd; ///COG wrt true north
radTrueCourse = GPSData->trueCourse * D2R; // [rad]
// Velocity information
GPSData->rawGroundSpeed = bestVelB->hor_spd; // [m/s]
//
GPSData->vNed[0] = bestVelB->hor_spd * cos(radTrueCourse); // [m/s] N
GPSData->vNed[1] = bestVelB->hor_spd * sin(radTrueCourse); // [m/s] E
GPSData->vNed[2] = avgDeltaSmoother( -bestVelB->vert_spd, &downVelDelta);
if (bestVelB->sol_status != 0) // zero is good fix anything else is
{ // enumeration for bad fix
GPSData->gpsFixType = bestVelB->vel_type;
gBitStatus.hwStatus.bit.unlockedInternalGPS = 1; // not locked
gBitStatus.swStatus.bit.noGPSTrackReference = 1; // no GPS track
gGpsDataPtr->HDOP = 21.0f; //
} else {
GPSData->gpsFixType = 0;
gBitStatus.hwStatus.bit.unlockedInternalGPS = 0; // not locked
gBitStatus.swStatus.bit.noGPSTrackReference = 0; // GPS track
gGpsDataPtr->HDOP = 1.0f; //
}
// If ITOW is the same as the value stored in GPSData->itow then it seems
// that velocity has already been measured at the current time step. If
// so then set the update flag accordingly, if not then set the GGA value
// only.
if( ((uint32_t)bestVelB->header.milliseconds == GPSData->itow ) &&
(GPSData->updateFlagForEachCall & 0x01 ) )
{
GPSData->updateFlagForEachCall |= 3; //1 << GOT_VTG_MSG;
} else {
GPSData->updateFlagForEachCall = 2; //GPSData->updateFlagForEachCall & 0xFFFFFFFe;
}
GPSData->itow = (uint32_t) bestVelB->header.milliseconds;
GPSData->VELCounter++;
}
/** ****************************************************************************
* @name _parseBestVelB LOCAL parse a BESTVELB message.
* @author Dong An
* @param [in] completeMessage - input buffer
* @param [in] headerLength - header length
* @param [in] bodyLength - input buffer length
* @param [in] GPSData structure to parse into
* @retval N/A
******************************************************************************/
void _parseBestVelB(char *completeMessage,
unsigned char *headerLength,
unsigned short *bodyLength,
GpsData_t *GPSData)
{
char SolStatus[4];
double radTrueCourse = 0.0;
SolStatus[0] = completeMessage[ *headerLength];
GPSData->rawGroundSpeed = _assembyToLongDouble((unsigned char*)&completeMessage[*headerLength + 16]); // ground speed [m/s]
GPSData->trueCourse = _assembyToLongDouble((unsigned char*)&completeMessage[*headerLength + 24]); ///COG [deg]
radTrueCourse = GPSData->trueCourse * D2R; // [rad]
GPSData->vNed[0] = GPSData->rawGroundSpeed * cos(radTrueCourse); // [m/s] N
GPSData->vNed[1] = GPSData->rawGroundSpeed * sin(radTrueCourse); // [m/s] E
GPSData->vNed[2] = -_assembyToLongDouble((unsigned char*)&completeMessage[*headerLength + 32]); ///vertical Vel [m/s] + up
GPSData->updateFlagForEachCall |= 1 << GOT_VTG_MSG;
if (SolStatus[0] != 0) // zero is good fix anything else is
{ // enumeration for bad fix
gGpsDataPtr->HDOP = 21.0f; //
gBitStatus.hwStatus.bit.unlockedInternalGPS = 1; // not locked
gBitStatus.swStatus.bit.noGPSTrackReference = 1; // GPS track
} else {
gGpsDataPtr->HDOP = 1.0f; //
gBitStatus.hwStatus.bit.unlockedInternalGPS = 0; // not locked
gBitStatus.swStatus.bit.noGPSTrackReference = 0; // GPS track
}
GPSData->gpsFixType = SolStatus[0];
memcpy(&GPSData->itow, &completeMessage[16], 4); ///Itow
GPSData->VELCounter++;
}
/** ****************************************************************************
* @name assembyToLongDouble LOCAL put 8 bytes IEEE double precision into
* "long double" of c2000.
* @author Dong An
* @param [in] doubleBytes - input
* @retval long double version of the number
******************************************************************************/
long double _assembyToLongDouble(unsigned char *inByte)
{
union {
long long dataLong;
long double dataDouble;
} long2Double;
memcpy(&long2Double.dataLong, inByte, 8);
return long2Double.dataDouble;
}
/** ****************************************************************************
* @name _CRC32Value LOCAL subroutine of CRC computation for NovAtel binary
* message of c2000.
* @author Dong An
* @param [in] i - input value
* @retval N/A
******************************************************************************/
unsigned long _CRC32Value(int i)
{
int j;
unsigned long ulCRC;
ulCRC = i;
for(j = 8; j > 0; j--) {
if (ulCRC & 1)
ulCRC = (ulCRC >> 1) ^ CRC32_POLYNOMIAL;
else
ulCRC >>= 1;
}
return ulCRC;
}
/** ****************************************************************************
* @name _CalculateBlockCRC32 LOCAL compute CRC for a complete NovAtel binary
* message of c2000.
* @author Dong An
* @param [in] ulCount - input size 32bit words
* @param [in] ucBuffer - input value
* @retval the calulated CRC
******************************************************************************/
unsigned long _CalculateBlockCRC32(unsigned long ulCount,
unsigned char *ucBuffer)
{
unsigned long ulTemp1;
unsigned long ulTemp2;
unsigned long ulCRC = 0;
while (ulCount-- != 0) {
ulTemp1 = (ulCRC >> 8) & 0x00FFFFFFL;
ulTemp2 = _CRC32Value( ((int)ulCRC ^ *ucBuffer++) & 0xff);
ulCRC = ulTemp1 ^ ulTemp2;
}
return ulCRC;
}
void sendNovAtelBinaryCmdMsg(void)
{
uint8_t baudCmd[] = { "COM COM1,115200,N,8,1,N,OFF,ON\r" };
uint8_t posBCmd[] = { "log com1 BESTPOSB ontime 1\r" };
uint8_t velBCmd[] = { "log com1 BESTVELB ontime 1\r" };
writeGps((char*)posBCmd, strlen((char*)posBCmd));
writeGps((char*)velBCmd, strlen((char*)velBCmd));
writeGps((char*)baudCmd, strlen((char*)baudCmd));
}
#endif // GPS |
the_stack_data/667988.c | #include <stdio.h>
void freq(int* f, int size){
//int size=sizeof(f)/sizeof(f[0]);//size++;
int g,count;
printf("\n%d\n",size);
for(int x=0;x<size;x++){
g=*(f+x);count=0;
if(*(f+x)!=-522715135)
{
for(int y=0;y<size;y++){
if(*(f+y)==-522715135)
{}
else if(*(f+y)==g){
count++;
*(f+y)=-522715135;//-((2^8)-1)
//*(f+x)="/u000";}
}
printf("%d occures %d times\n",g,count);
}
}}
}
int main(){
int o,f;
printf("Enter the number to enter in the array\n");
scanf("%d",&o);
int arr[o];
for(f=0;f<o;f++){
printf("\narr[%d]=",f);
//scanf("%[^\n]*%c",arr[f][0]);
scanf("%d",(arr+f));
}
freq(arr,o);
return 0;
}
|
the_stack_data/187642953.c | f() {
printf(1234);
}
main() {
int a;
a = 6;
printf(a);
a = a + 1;
printf(a);
f();
} |
the_stack_data/100141387.c | // The code for dayofweek was obtained at:
// https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week
#ifdef CS333_P1
#include "types.h"
#include "user.h"
#include "date.h"
static char *months[] = {"NULL", "Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
static char *days[] = {"Sun", "Mon", "Tue", "Wed",
"Thu", "Fri", "Sat"};
static int
dayofweek(int y, int m, int d)
{
return (d+=m<3?y--:y-2,23*m/9+d+4+y/4-y/100+y/400)%7;
}
int
main(int argc, char *argv[])
{
int day;
struct rtcdate r;
if (date(&r)) {
printf(2,"Error: date call failed. %s at line %d\n",
__FILE__, __LINE__);
exit();
}
day = dayofweek(r.year, r.month, r.day);
printf(1, "%s %s %d", days[day], months[r.month], r.day);
printf(1, " ");
if (r.hour < 10) printf(1, "0");
printf(1, "%d:", r.hour);
if (r.minute < 10) printf(1, "0");
printf(1, "%d:", r.minute);
if (r.second < 10) printf(1, "0");
printf(1, "%d UTC %d\n", r.second, r.year);
exit();
}
#endif
|
the_stack_data/629704.c | /*
QUIZ PROGRAM BY ROHAN VERMA
Planning:
We will read from a file called questions.dat in which we will store the data in such a way where:
What is the capital of India?
Delhi
Mumbai
Bangalore
Kolkata
Here the first line is the question
second line contains the correct answer
the next three lines contains the incorrect answers
We will then display the questions till the eof is reached or till an incorrect answer is reached.
*/
#include <stdio.h>
#include <string.h>
FILE* fin;
char buffer[100]; //buffer to store what i scan from questions file
typedef struct {
char question[100];
char a[100];
char b[100];
char c[100];
char d[100];
unsigned int correct;
} Questions;
Questions q;
int main()
{
fin = fopen("questions.dat", "r");
//check if we had an error in opening the file
if (NULL == fin)
{
printf("error in opening the question database");
return (-1);
}
int input = 0, score = 0, lvl = 1; //a loop iterator for saving the input in the structure
while (EOF != fscanf(fin, "%100[^\n]\n", buffer))
{
int user_answer = -1;
if(input == 0)
strcpy(q.question, buffer);
if(input == 1)
strcpy(q.a, buffer);
if(input == 2)
strcpy(q.b, buffer);
if(input == 3)
strcpy(q.c, buffer);
if(input == 4)
strcpy(q.d, buffer);
if(input == 5){
input = -1;
q.correct = atoi(buffer);
//print the question
printf("\n==============================\n");
printf("===========[ QUIZ ]===========\n");
printf("==[LVL:%2d]==========[PTS:%3d]=\n", lvl, score);
printf("==============================\n");
printf("Q. %s\n", q.question);
printf("==============================\n");
printf("1.%s\n2.%s\n3.%s\n4.%s\n\n",q.a,q.b,q.c,q.d);
//input their choice
printf("==============================\n");
printf("Enter your choice (1,2,3,4): ");
scanf("%d", &user_answer);
if(user_answer > 0 && user_answer < 5){
if(user_answer == q.correct+1){
score++;
}
else score--;
}
lvl++;
}
input++;
}
printf("\n\n\n\n===========[ QUIZ ]===========\n");
printf("==[LVL:%2d]==========[PTS:%3d]=\n", lvl, score);
printf("==============================\n");
printf(" Thank you for Participating\n");
printf("==============================\n\n\n\n\n\n");
fclose(fin);
return 0;
} |
the_stack_data/90761511.c | #include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define NTHREADS 5
pid_t pid;
void* hello_world(void *tid){
printf("Hello World. Esta é a Thread %d\n", (int)tid);
sleep(((int)tid+1)*2);
pthread_exit(NULL);
}
int main(int argc, char *argv[]){
pthread_t threads[NTHREADS];
int status, i, retorno;
void *thread_return;
pid = fork();
for(i=0; i<NTHREADS; i++){
printf("Processo [%d] criando thread #%d\n", getpid(), i);
status = pthread_create(&threads[i], NULL, hello_world, (void *)(size_t) i);
if(status!=0){
printf("Erro na criação da thread. Codigo de Erro:%d\n", status);
return 1;
}
}
for(i=0; i<NTHREADS; i++){
printf("Processo[%d]: Esperando Thread %d finalizar....\n", getpid(), i);
retorno = pthread_join(threads[i], &thread_return);
printf("Processo[%d]: Thread %d finalizada. Retorno=%d\n", getpid(), i, retorno);
}
printf("processo [%d] vai finalizar\n", getpid());
return 0;
}
|
the_stack_data/101749.c | #include <stdio.h>
int main(void)
{
printf ("hello world\n");
return 0;
}
|
the_stack_data/1210271.c | // FFI interface to UNIX-style network sockets.
// This socket interface is largely based on the example provided in the
// getaddrinfo man page http://man7.org/linux/man-pages/man3/getaddrinfo.3.html
// This macro is needed for getaddrinfo, as documented in the manpage.
// gcc defines this macro by default, but CompCert does not.
// We must therefore define it explicitly.
#define _POSIX_C_SOURCE 201112L
#include <assert.h> // assert
#include <stdint.h> // uint8_t, uint16_6, etc.
#include <sys/types.h> // socket, bind, listen, getaddrinfo
#include <sys/socket.h> // socket, bind, listen, getaddrinfo
#include <netdb.h> // getaddrinfo
#include <string.h> // memset, strerror
#include <unistd.h> // close
#define FFI_SUCCESS 0
#define FFI_FAILURE 1
// These helper functions are defined in basis_ffi.c
// I figured it would be good to use the same marshalling paradigm as the
// provided FFI functions when possible.
// However, I'm not sure why ints (usually 4 bytes) are converted back and forth
// to 8-byte arrays.
int byte2_to_int(uint8_t *b);
void int_to_byte2(int i, uint8_t *b);
int byte8_to_int(uint8_t *b);
void int_to_byte8(int i, uint8_t *b);
// Arguments: qlen (first 2 bytes of c), and port, a string representation of a
// number, following qlen
// Returns: failure flag in a[0], sockfd as 64-bit int in a[1..8]
void ffilisten(const uint8_t * c, const long clen, uint8_t * a, const long alen) {
assert(clen >= 2);
assert(alen >= 9);
// Parse arguments
int qlen = byte2_to_int(c);
char * port = (char *)c + 2;
struct addrinfo hints;
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
struct addrinfo * result;
if (getaddrinfo(0, port, &hints, &result)) {
freeaddrinfo(result);
a[0] = FFI_FAILURE;
return;
}
int sockfd;
struct addrinfo * r;
// Loop through addrinfo list from getadrrinfo until one works (or failure)
for (r = result; r; r = r->ai_next) {
sockfd = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
if (sockfd == -1)
continue;
int enable = 1;
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
if (!bind(sockfd, r->ai_addr, r->ai_addrlen))
break;
close(sockfd);
}
freeaddrinfo(result);
if (!r || sockfd == -1) {
a[0] = FFI_FAILURE;
return;
}
// Listen for incoming connections, with a maximum queue length of qlen
if (listen(sockfd, qlen)) {
a[0] = FFI_FAILURE;
return;
}
// return sockfd
a[0] = FFI_SUCCESS;
int_to_byte8(sockfd, a+1);
}
// Argument: sockfd as 64-bit int in c
// Returns: failure flag in a[0], conn_sockfd as 64-bit int in a[1..8]
// Blocks until there is an incoming connection
void ffiaccept(const uint8_t * c, const long clen, uint8_t * a, const long alen) {
assert(clen >= 8);
assert(alen >= 9);
// Parse argument
int sockfd = byte8_to_int(c);
struct sockaddr_in conn_addr;
unsigned int conn_addr_len = (unsigned int)(sizeof(struct sockaddr_in));
// accept returns the sockfd corresponding to the first connection in the
// incoming queue. If there is none, blocks until there is.
int conn_sockfd = accept(sockfd, (struct sockaddr *)(&conn_addr), &conn_addr_len);
if(conn_sockfd == -1) {
a[0] = FFI_FAILURE;
return;
}
// return conn_sockfd
a[0] = FFI_SUCCESS;
int_to_byte8(conn_sockfd, a+1);
}
// Arguments: host and port, both stored in that order in c, delimited by a null
// byte. host is a domain name or ip address, as a string. port is a number,
// again as a string. port should be followed by a final null byte.
// Returns: failure flag in a[0], sockfd as 64-bit int in a[1..8]
void fficonnect(uint8_t * c, const long clen, uint8_t * a, const long alen) {
assert(clen >= 2); // Assumes there are at least the null byte delimiter and terminator
assert(alen >= 9);
// Parse arguments
char * host = (char *)c;
char * port = host + strlen(host) + 1;
struct addrinfo hints;
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
struct addrinfo * result;
if (getaddrinfo(host, port, &hints, &result)) {
freeaddrinfo(result);
a[0] = FFI_FAILURE;
return;
}
int sockfd;
struct addrinfo * r;
for (r = result; r; r = r->ai_next) {
sockfd = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
if (sockfd == -1)
continue;
if (!connect(sockfd, r->ai_addr, r->ai_addrlen))
break;
close(sockfd);
}
freeaddrinfo(result);
if (!r || sockfd == -1) {
a[0] = FFI_FAILURE;
return;
}
// return sockfd
a[0] = FFI_SUCCESS;
int_to_byte8(sockfd, a+1);
}
|
the_stack_data/127387.c | /**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* 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 ENABLE_AVX
#include "nnacl/fp32/conv_1x1_x86_fp32.h"
#ifdef _MSC_VER
#include <immintrin.h>
#else
#include <x86intrin.h>
#endif
// sliding window to compate 1x1 conv in x86
void Conv1x1SWFp32(const float *input_data, const float *packed_weight, const float *bias_data, float *output_data,
int task_id, ConvParameter *conv_param, SlidingWindowParam *sw_param) {
int output_w = conv_param->output_w_;
int output_h = conv_param->output_h_;
int ohw = output_h * output_w;
int ohw_step = UP_DIV(ohw, conv_param->thread_num_);
int ohw_start = ohw_step * task_id;
int ohw_end = MSMIN(ohw_start + ohw_step, ohw);
if (ohw_start >= ohw_end) {
return;
}
int oc_tile_ = C8NUM; // oc in algin to C8NUM in x86_64_avx
int act_type = 0;
if (conv_param->act_type_ == ActType_Relu6) {
act_type += 1;
}
if (conv_param->act_type_ == ActType_Relu || conv_param->act_type_ == ActType_Relu6) {
act_type += 2;
}
int pad_d = conv_param->pad_d_;
int pad_l = conv_param->pad_l_;
int pad_r = conv_param->pad_r_;
int pad_u = conv_param->pad_u_;
int oc_align = sw_param->block_channel_;
int oc_align_float = oc_align * sizeof(float);
int ic_align = sw_param->ic_align_;
int in_sw_step = sw_param->in_sw_step_;
int in_sw_step_float = sw_param->in_sw_step_ * sizeof(float);
int kernel_step = sw_param->kernel_step_;
int oc_num = sw_param->c_block_;
int in_step = sw_param->in_step_;
int out_step = sw_param->out_step_;
const int ow_block_num[4] = {12, 6, 4, 3};
const Conv1x1SWKernel kernel[4][2] = {{Conv1x1SW1x8Kernel, Conv1x1SW12x8Kernel},
{Conv1x1SW1x16Kernel, Conv1x1SW6x16Kernel},
{Conv1x1SW1x24Kernel, Conv1x1SW4x24Kernel},
{Conv1x1SW1x32Kernel, Conv1x1SW3x32Kernel}};
for (int b = 0; b < conv_param->output_batch_; b++) {
int ic_block = 128;
int dst_flag = 0;
for (int ic = 0; ic < ic_align; ic += ic_block) {
if (ic_align - ic <= ic_block) {
ic_block = ic_align - ic;
dst_flag = 3 - (ic == 0);
} else {
dst_flag = 1 - (ic == 0);
}
if (pad_d == 0 && pad_l == 0 && pad_r == 0 && pad_u == 0) {
const float *bias = bias_data;
int oc_block = 0;
for (int oc = 0; oc < oc_num; oc += oc_block) {
oc_block = MSMIN(C4NUM, oc_num - oc); // 4 3 2 1
const float *weight = packed_weight + oc * kernel_step + ic * C8NUM * oc_block;
if (bias != NULL) {
bias = bias_data + oc * oc_tile_;
}
const float *src_w = input_data + ic + ohw_start * in_sw_step;
float *dst_oc = output_data + oc * oc_tile_;
int hw_block = ow_block_num[oc_block - 1];
for (int hw = ohw_start; hw < ohw_end; hw += hw_block) {
if (hw_block > ohw_end - hw) { // ow is not enough and process one ow
hw_block = 1;
}
float *dst_w = dst_oc + hw * oc_align;
kernel[oc_block - 1][hw_block / ow_block_num[oc_block - 1]](dst_w, src_w, weight, bias, act_type, hw_block,
oc_block, oc_align_float, ic_block >> 3,
in_sw_step_float, dst_flag);
src_w += hw_block * in_sw_step;
}
}
}
}
input_data += in_step;
output_data += out_step;
} // batch loop
}
void Conv1x1SW3x32Kernel(float *dst, const float *src, const float *weight, const float *bias, size_t act_flag,
size_t ow_block, size_t oc_block, size_t oc_align, size_t ic_align, size_t in_sw_step,
size_t dst_flag) {
asm volatile(
"movq %8, %%rax\n"
"and $0x1, %%eax\n"
"je 0f\n"
"vmovups (%7), %%ymm0\n"
"vmovups 0x20(%7), %%ymm1\n"
"vmovups 0x40(%7), %%ymm2\n"
"vmovups 0x60(%7), %%ymm3\n"
"vmovups (%7, %6, 1), %%ymm4\n"
"vmovups 0x20(%7, %6, 1), %%ymm5\n"
"vmovups 0x40(%7, %6, 1), %%ymm6\n"
"vmovups 0x60(%7, %6, 1), %%ymm7\n"
"vmovups (%7, %6, 2), %%ymm8\n"
"vmovups 0x20(%7, %6, 2), %%ymm9\n"
"vmovups 0x40(%7, %6, 2), %%ymm10\n"
"vmovups 0x60(%7, %6, 2), %%ymm11\n"
"jmp 2f\n"
"0:\n"
"cmpq $0, %2\n"
"je 1f\n"
"vmovups (%2), %%ymm0\n"
"vmovups 0x20(%2), %%ymm1\n"
"vmovups 0x40(%2), %%ymm2\n"
"vmovups 0x60(%2), %%ymm3\n"
"vmovups (%2), %%ymm4\n"
"vmovups 0x20(%2), %%ymm5\n"
"vmovups 0x40(%2), %%ymm6\n"
"vmovups 0x60(%2), %%ymm7\n"
"vmovups (%2), %%ymm8\n"
"vmovups 0x20(%2), %%ymm9\n"
"vmovups 0x40(%2), %%ymm10\n"
"vmovups 0x60(%2), %%ymm11\n"
"jmp 2f\n"
"1:\n"
"vxorps %%ymm0, %%ymm0, %%ymm0\n"
"vxorps %%ymm1, %%ymm1, %%ymm1\n"
"vxorps %%ymm2, %%ymm2, %%ymm2\n"
"vxorps %%ymm3, %%ymm3, %%ymm3\n"
"vxorps %%ymm4, %%ymm4, %%ymm4\n"
"vxorps %%ymm5, %%ymm5, %%ymm5\n"
"vxorps %%ymm6, %%ymm6, %%ymm6\n"
"vxorps %%ymm7, %%ymm7, %%ymm7\n"
"vxorps %%ymm8, %%ymm8, %%ymm8\n"
"vxorps %%ymm9, %%ymm9, %%ymm9\n"
"vxorps %%ymm10, %%ymm10, %%ymm10\n"
"vxorps %%ymm11, %%ymm11, %%ymm11\n"
"2:\n" // LoopIC
"vbroadcastss (%0), %%ymm13\n"
"vbroadcastss (%0, %4), %%ymm14\n"
"vbroadcastss (%0, %4, 2), %%ymm15\n"
"vmovups (%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"vmovups 0x20(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm5\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm9\n"
"vmovups 0x40(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm2\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm10\n"
"vmovups 0x60(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"vbroadcastss 4(%0), %%ymm13\n"
"vbroadcastss 4(%0, %4), %%ymm14\n"
"vbroadcastss 4(%0, %4, 2), %%ymm15\n"
"vmovups 128(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"vmovups 160(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm5\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm9\n"
"vmovups 192(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm2\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm10\n"
"vmovups 224(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"vbroadcastss 8(%0), %%ymm13\n"
"vbroadcastss 8(%0, %4), %%ymm14\n"
"vbroadcastss 8(%0, %4, 2), %%ymm15\n"
"vmovups 256(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"vmovups 288(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm5\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm9\n"
"vmovups 320(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm2\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm10\n"
"vmovups 352(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"vbroadcastss 12(%0), %%ymm13\n"
"vbroadcastss 12(%0, %4), %%ymm14\n"
"vbroadcastss 12(%0, %4, 2), %%ymm15\n"
"vmovups 384(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"vmovups 416(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm5\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm9\n"
"vmovups 448(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm2\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm10\n"
"vmovups 480(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"vbroadcastss 16(%0), %%ymm13\n"
"vbroadcastss 16(%0, %4), %%ymm14\n"
"vbroadcastss 16(%0, %4, 2), %%ymm15\n"
"vmovups 512(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"vmovups 544(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm5\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm9\n"
"vmovups 576(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm2\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm10\n"
"vmovups 608(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"vbroadcastss 20(%0), %%ymm13\n"
"vbroadcastss 20(%0, %4), %%ymm14\n"
"vbroadcastss 20(%0, %4, 2), %%ymm15\n"
"vmovups 640(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"vmovups 672(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm5\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm9\n"
"vmovups 704(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm2\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm10\n"
"vmovups 736(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"vbroadcastss 24(%0), %%ymm13\n"
"vbroadcastss 24(%0, %4), %%ymm14\n"
"vbroadcastss 24(%0, %4, 2), %%ymm15\n"
"vmovups 768(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"vmovups 800(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm5\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm9\n"
"vmovups 832(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm2\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm10\n"
"vmovups 864(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"vbroadcastss 28(%0), %%ymm13\n"
"vbroadcastss 28(%0, %4), %%ymm14\n"
"vbroadcastss 28(%0, %4, 2), %%ymm15\n"
"vmovups 896(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"vmovups 928(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm5\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm9\n"
"vmovups 960(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm2\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm10\n"
"vmovups 992(%1), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"addq $1024, %1\n"
"addq $32, %0\n"
"dec %3\n"
"jg 2b\n"
"movq %8, %%rax\n"
"and $0x2, %%eax\n"
"je 3f\n"
"movq %5, %%rax\n"
"and $0x3, %%eax\n"
"je 3f\n"
// Relu
"vxorps %%ymm12, %%ymm12, %%ymm12\n"
"vmaxps %%ymm12, %%ymm0, %%ymm0\n"
"vmaxps %%ymm12, %%ymm1, %%ymm1\n"
"vmaxps %%ymm12, %%ymm2, %%ymm2\n"
"vmaxps %%ymm12, %%ymm3, %%ymm3\n"
"vmaxps %%ymm12, %%ymm4, %%ymm4\n"
"vmaxps %%ymm12, %%ymm5, %%ymm5\n"
"vmaxps %%ymm12, %%ymm6, %%ymm6\n"
"vmaxps %%ymm12, %%ymm7, %%ymm7\n"
"vmaxps %%ymm12, %%ymm8, %%ymm8\n"
"vmaxps %%ymm12, %%ymm9, %%ymm9\n"
"vmaxps %%ymm12, %%ymm10, %%ymm10\n"
"vmaxps %%ymm12, %%ymm11, %%ymm11\n"
"and $0x1, %%eax\n"
"je 3f\n"
// relu6
"mov $0x40C00000, %%ecx\n"
"vmovd %%ecx, %%xmm14\n"
"vpermps %%ymm14, %%ymm12, %%ymm14\n"
"vminps %%ymm14, %%ymm0, %%ymm0\n"
"vminps %%ymm14, %%ymm1, %%ymm1\n"
"vminps %%ymm14, %%ymm2, %%ymm2\n"
"vminps %%ymm14, %%ymm3, %%ymm3\n"
"vminps %%ymm14, %%ymm4, %%ymm4\n"
"vminps %%ymm14, %%ymm5, %%ymm5\n"
"vminps %%ymm14, %%ymm6, %%ymm6\n"
"vminps %%ymm14, %%ymm7, %%ymm7\n"
"vminps %%ymm14, %%ymm8, %%ymm8\n"
"vminps %%ymm14, %%ymm9, %%ymm9\n"
"vminps %%ymm14, %%ymm10, %%ymm10\n"
"vminps %%ymm14, %%ymm11, %%ymm11\n"
"3:\n"
"vmovups %%ymm0, (%7)\n" // dst_0
"vmovups %%ymm1, 0x20(%7)\n"
"vmovups %%ymm2, 0x40(%7)\n"
"vmovups %%ymm3, 0x60(%7)\n"
"vmovups %%ymm4, (%7, %6, 1)\n"
"vmovups %%ymm5, 0x20(%7, %6, 1)\n"
"vmovups %%ymm6, 0x40(%7, %6, 1)\n"
"vmovups %%ymm7, 0x60(%7, %6, 1)\n"
"vmovups %%ymm8, (%7, %6, 2)\n"
"vmovups %%ymm9, 0x20(%7, %6, 2)\n"
"vmovups %%ymm10, 0x40(%7, %6, 2)\n"
"vmovups %%ymm11, 0x60(%7, %6, 2)\n"
:
: "r"(src), "r"(weight), "r"(bias), "r"(ic_align), "r"(in_sw_step), "r"(act_flag), "r"(oc_align), "r"(dst),
"r"(dst_flag) // 8
: "%rax", "%ecx", "%ymm0", "%ymm1", "%ymm2", "%ymm3", "%ymm4", "%ymm5", "%ymm6", "%ymm7", "%ymm8", "%ymm9",
"%ymm10", "%ymm11", "%ymm12", "%ymm13", "%ymm14", "%ymm15");
}
void Conv1x1SW1x32Kernel(float *dst, const float *src, const float *weight, const float *bias, size_t act_flag,
size_t ow_block, size_t oc_block, size_t oc_align, size_t ic_align, size_t in_sw_step,
size_t dst_flag) {
asm volatile(
"movq %8, %%rax\n"
"and $0x1, %%eax\n"
"je 0f\n"
"vmovups (%7), %%ymm0\n"
"vmovups 0x20(%7), %%ymm1\n"
"vmovups 0x40(%7), %%ymm2\n"
"vmovups 0x60(%7), %%ymm3\n"
"jmp 2f\n"
"0:\n"
"cmpq $0, %2\n"
"je 1f\n"
"vmovups (%2), %%ymm0\n"
"vmovups 0x20(%2), %%ymm1\n"
"vmovups 0x40(%2), %%ymm2\n"
"vmovups 0x60(%2), %%ymm3\n"
"jmp 2f\n"
"1:\n"
"vxorps %%ymm0, %%ymm0, %%ymm0\n"
"vxorps %%ymm1, %%ymm1, %%ymm1\n"
"vxorps %%ymm2, %%ymm2, %%ymm2\n"
"vxorps %%ymm3, %%ymm3, %%ymm3\n"
"2:\n" // LoopIC
"vbroadcastss (%0), %%ymm13\n"
"vmovups (%1), %%ymm4\n"
"vmovups 0x20(%1), %%ymm5\n"
"vmovups 0x40(%1), %%ymm6\n"
"vmovups 0x60(%1), %%ymm7\n"
"vfmadd231ps %%ymm4, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm5, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm6, %%ymm13, %%ymm2\n"
"vfmadd231ps %%ymm7, %%ymm13, %%ymm3\n"
"vbroadcastss 4(%0), %%ymm13\n"
"vmovups 128(%1), %%ymm4\n"
"vmovups 160(%1), %%ymm5\n"
"vmovups 192(%1), %%ymm6\n"
"vmovups 224(%1), %%ymm7\n"
"vfmadd231ps %%ymm4, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm5, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm6, %%ymm13, %%ymm2\n"
"vfmadd231ps %%ymm7, %%ymm13, %%ymm3\n"
"vbroadcastss 8(%0), %%ymm13\n"
"vmovups 256(%1), %%ymm4\n"
"vmovups 288(%1), %%ymm5\n"
"vmovups 320(%1), %%ymm6\n"
"vmovups 352(%1), %%ymm7\n"
"vfmadd231ps %%ymm4, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm5, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm6, %%ymm13, %%ymm2\n"
"vfmadd231ps %%ymm7, %%ymm13, %%ymm3\n"
"vbroadcastss 12(%0), %%ymm13\n"
"vmovups 384(%1), %%ymm4\n"
"vmovups 416(%1), %%ymm5\n"
"vmovups 448(%1), %%ymm6\n"
"vmovups 480(%1), %%ymm7\n"
"vfmadd231ps %%ymm4, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm5, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm6, %%ymm13, %%ymm2\n"
"vfmadd231ps %%ymm7, %%ymm13, %%ymm3\n"
"vbroadcastss 16(%0), %%ymm13\n"
"vmovups 512(%1), %%ymm4\n"
"vmovups 544(%1), %%ymm5\n"
"vmovups 576(%1), %%ymm6\n"
"vmovups 608(%1), %%ymm7\n"
"vfmadd231ps %%ymm4, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm5, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm6, %%ymm13, %%ymm2\n"
"vfmadd231ps %%ymm7, %%ymm13, %%ymm3\n"
"vbroadcastss 20(%0), %%ymm13\n"
"vmovups 640(%1), %%ymm4\n"
"vmovups 672(%1), %%ymm5\n"
"vmovups 704(%1), %%ymm6\n"
"vmovups 736(%1), %%ymm7\n"
"vfmadd231ps %%ymm4, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm5, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm6, %%ymm13, %%ymm2\n"
"vfmadd231ps %%ymm7, %%ymm13, %%ymm3\n"
"vbroadcastss 24(%0), %%ymm13\n"
"vmovups 768(%1), %%ymm4\n"
"vmovups 800(%1), %%ymm5\n"
"vmovups 832(%1), %%ymm6\n"
"vmovups 864(%1), %%ymm7\n"
"vfmadd231ps %%ymm4, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm5, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm6, %%ymm13, %%ymm2\n"
"vfmadd231ps %%ymm7, %%ymm13, %%ymm3\n"
"vbroadcastss 28(%0), %%ymm13\n"
"vmovups 896(%1), %%ymm4\n"
"vmovups 928(%1), %%ymm5\n"
"vmovups 960(%1), %%ymm6\n"
"vmovups 992(%1), %%ymm7\n"
"vfmadd231ps %%ymm4, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm5, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm6, %%ymm13, %%ymm2\n"
"vfmadd231ps %%ymm7, %%ymm13, %%ymm3\n"
"addq $1024, %1\n"
"addq $32, %0\n"
"dec %3\n"
"jg 2b\n"
"movq %8, %%rax\n"
"and $0x2, %%eax\n"
"je 3f\n"
"movq %5, %%rax\n"
"and $0x3, %%eax\n"
"je 3f\n"
// Relu
"vxorps %%ymm12, %%ymm12, %%ymm12\n"
"vmaxps %%ymm12, %%ymm0, %%ymm0\n"
"vmaxps %%ymm12, %%ymm1, %%ymm1\n"
"vmaxps %%ymm12, %%ymm2, %%ymm2\n"
"vmaxps %%ymm12, %%ymm3, %%ymm3\n"
"and $0x1, %%eax\n"
"je 3f\n"
// relu6
"mov $0x40C00000, %%ecx\n"
"vmovd %%ecx, %%xmm14\n"
"vpermps %%ymm14, %%ymm12, %%ymm14\n"
"vminps %%ymm14, %%ymm0, %%ymm0\n"
"vminps %%ymm14, %%ymm1, %%ymm1\n"
"vminps %%ymm14, %%ymm2, %%ymm2\n"
"vminps %%ymm14, %%ymm3, %%ymm3\n"
"3:\n"
"vmovups %%ymm0, (%7)\n" // dst_0
"vmovups %%ymm1, 0x20(%7)\n"
"vmovups %%ymm2, 0x40(%7)\n"
"vmovups %%ymm3, 0x60(%7)\n"
:
: "r"(src), "r"(weight), "r"(bias), "r"(ic_align), "r"(in_sw_step), "r"(act_flag), "r"(oc_align), "r"(dst),
"r"(dst_flag) // 8
: "%rax", "%ecx", "%ymm0", "%ymm1", "%ymm2", "%ymm3", "%ymm4", "%ymm5", "%ymm6", "%ymm7", "%ymm12", "%ymm13",
"%ymm14");
}
void Conv1x1SW4x24Kernel(float *dst, const float *src, const float *weight, const float *bias, size_t act_flag,
size_t ow_block, size_t oc_block, size_t oc_align, size_t ic_align, size_t in_sw_step,
size_t dst_flag) {
size_t src_3_step = 3 * in_sw_step;
float *dst_3 = dst + 3 * oc_align / sizeof(float);
asm volatile(
"movq %10, %%rax\n" // dst_flag
"and $0x1, %%eax\n"
"je 0f\n"
"vmovups (%8), %%ymm0\n" // dst_0
"vmovups 0x20(%8), %%ymm1\n"
"vmovups 0x40(%8), %%ymm2\n"
"vmovups (%8, %7, 1), %%ymm3\n"
"vmovups 0x20(%8, %7, 1), %%ymm4\n"
"vmovups 0x40(%8, %7, 1), %%ymm5\n"
"vmovups (%8, %7, 2), %%ymm6\n"
"vmovups 0x20(%8, %7, 2), %%ymm7\n"
"vmovups 0x40(%8, %7, 2), %%ymm8\n"
"vmovups (%9), %%ymm9\n"
"vmovups 0x20(%9), %%ymm10\n"
"vmovups 0x40(%9), %%ymm11\n"
"jmp 2f\n"
"0:\n"
"cmpq $0, %2\n"
"je 1f\n"
"vmovups (%2), %%ymm0\n"
"vmovups 0x20(%2), %%ymm1\n"
"vmovups 0x40(%2), %%ymm2\n"
"vmovups (%2), %%ymm3\n"
"vmovups 0x20(%2), %%ymm4\n"
"vmovups 0x40(%2), %%ymm5\n"
"vmovups (%2), %%ymm6\n"
"vmovups 0x20(%2), %%ymm7\n"
"vmovups 0x40(%2), %%ymm8\n"
"vmovups (%2), %%ymm9\n"
"vmovups 0x20(%2), %%ymm10\n"
"vmovups 0x40(%2), %%ymm11\n"
"jmp 2f\n"
"1:\n"
"vxorps %%ymm0, %%ymm0, %%ymm0\n"
"vxorps %%ymm1, %%ymm1, %%ymm1\n"
"vxorps %%ymm2, %%ymm2, %%ymm2\n"
"vxorps %%ymm3, %%ymm3, %%ymm3\n"
"vxorps %%ymm4, %%ymm4, %%ymm4\n"
"vxorps %%ymm5, %%ymm5, %%ymm5\n"
"vxorps %%ymm6, %%ymm6, %%ymm6\n"
"vxorps %%ymm7, %%ymm7, %%ymm7\n"
"vxorps %%ymm8, %%ymm8, %%ymm8\n"
"vxorps %%ymm9, %%ymm9, %%ymm9\n"
"vxorps %%ymm10, %%ymm10, %%ymm10\n"
"vxorps %%ymm11, %%ymm11, %%ymm11\n"
"2:\n" // LoopIC
"vmovups (%1), %%ymm13\n"
"vmovups 0x20(%1), %%ymm14\n"
"vmovups 0x40(%1), %%ymm15\n"
"vbroadcastss (%0), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"vbroadcastss (%0, %4), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm5\n"
"vbroadcastss (%0, %4, 2), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"vbroadcastss (%0, %5), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm10\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"vmovups 96(%1), %%ymm13\n"
"vmovups 128(%1), %%ymm14\n"
"vmovups 160(%1), %%ymm15\n"
"vbroadcastss 4(%0), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"vbroadcastss 4(%0, %4), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm5\n"
"vbroadcastss 4(%0, %4, 2), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"vbroadcastss 4(%0, %5), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm10\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"vmovups 192(%1), %%ymm13\n"
"vmovups 224(%1), %%ymm14\n"
"vmovups 256(%1), %%ymm15\n"
"vbroadcastss 8(%0), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"vbroadcastss 8(%0, %4), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm5\n"
"vbroadcastss 8(%0, %4, 2), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"vbroadcastss 8(%0, %5), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm10\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"vmovups 288(%1), %%ymm13\n"
"vmovups 320(%1), %%ymm14\n"
"vmovups 352(%1), %%ymm15\n"
"vbroadcastss 12(%0), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"vbroadcastss 12(%0, %4), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm5\n"
"vbroadcastss 12(%0, %4, 2), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"vbroadcastss 12(%0, %5), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm10\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"vmovups 384(%1), %%ymm13\n"
"vmovups 416(%1), %%ymm14\n"
"vmovups 448(%1), %%ymm15\n"
"vbroadcastss 16(%0), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"vbroadcastss 16(%0, %4), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm5\n"
"vbroadcastss 16(%0, %4, 2), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"vbroadcastss 16(%0, %5), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm10\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"vmovups 480(%1), %%ymm13\n"
"vmovups 512(%1), %%ymm14\n"
"vmovups 544(%1), %%ymm15\n"
"vbroadcastss 20(%0), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"vbroadcastss 20(%0, %4), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm5\n"
"vbroadcastss 20(%0, %4, 2), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"vbroadcastss 20(%0, %5), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm10\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"vmovups 576(%1), %%ymm13\n"
"vmovups 608(%1), %%ymm14\n"
"vmovups 640(%1), %%ymm15\n"
"vbroadcastss 24(%0), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"vbroadcastss 24(%0, %4), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm5\n"
"vbroadcastss 24(%0, %4, 2), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"vbroadcastss 24(%0, %5), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm10\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"vmovups 672(%1), %%ymm13\n"
"vmovups 704(%1), %%ymm14\n"
"vmovups 736(%1), %%ymm15\n"
"vbroadcastss 28(%0), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"vbroadcastss 28(%0, %4), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm5\n"
"vbroadcastss 28(%0, %4, 2), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"vbroadcastss 28(%0, %5), %%ymm12\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm10\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"addq $768, %1\n"
"addq $32, %0\n"
"dec %3\n"
"jg 2b\n"
"movq %10, %%rax\n"
"and $0x2, %%eax\n"
"je 3f\n"
"movq %6, %%rax\n"
"and $0x3, %%eax\n"
"je 3f\n"
// Relu
"vxorps %%ymm12, %%ymm12, %%ymm12\n"
"vmaxps %%ymm12, %%ymm0, %%ymm0\n"
"vmaxps %%ymm12, %%ymm1, %%ymm1\n"
"vmaxps %%ymm12, %%ymm2, %%ymm2\n"
"vmaxps %%ymm12, %%ymm3, %%ymm3\n"
"vmaxps %%ymm12, %%ymm4, %%ymm4\n"
"vmaxps %%ymm12, %%ymm5, %%ymm5\n"
"vmaxps %%ymm12, %%ymm6, %%ymm6\n"
"vmaxps %%ymm12, %%ymm7, %%ymm7\n"
"vmaxps %%ymm12, %%ymm8, %%ymm8\n"
"vmaxps %%ymm12, %%ymm9, %%ymm9\n"
"vmaxps %%ymm12, %%ymm10, %%ymm10\n"
"vmaxps %%ymm12, %%ymm11, %%ymm11\n"
"and $0x1, %%eax\n"
"je 3f\n"
// relu6
"mov $0x40C00000, %%ecx\n"
"vmovd %%ecx, %%xmm14\n"
"vpermps %%ymm14, %%ymm12, %%ymm14\n"
"vminps %%ymm14, %%ymm0, %%ymm0\n"
"vminps %%ymm14, %%ymm1, %%ymm1\n"
"vminps %%ymm14, %%ymm2, %%ymm2\n"
"vminps %%ymm14, %%ymm3, %%ymm3\n"
"vminps %%ymm14, %%ymm4, %%ymm4\n"
"vminps %%ymm14, %%ymm5, %%ymm5\n"
"vminps %%ymm14, %%ymm6, %%ymm6\n"
"vminps %%ymm14, %%ymm7, %%ymm7\n"
"vminps %%ymm14, %%ymm8, %%ymm8\n"
"vminps %%ymm14, %%ymm9, %%ymm9\n"
"vminps %%ymm14, %%ymm10, %%ymm10\n"
"vminps %%ymm14, %%ymm11, %%ymm11\n"
"3:\n"
"vmovups %%ymm0, (%8)\n" // dst_0
"vmovups %%ymm1, 0x20(%8)\n"
"vmovups %%ymm2, 0x40(%8)\n"
"vmovups %%ymm3, (%8, %7, 1)\n"
"vmovups %%ymm4, 0x20(%8, %7, 1)\n"
"vmovups %%ymm5, 0x40(%8, %7, 1)\n"
"vmovups %%ymm6, (%8, %7, 2)\n"
"vmovups %%ymm7, 0x20(%8, %7, 2)\n"
"vmovups %%ymm8, 0x40(%8, %7, 2)\n"
"vmovups %%ymm9, (%9)\n"
"vmovups %%ymm10, 0x20(%9)\n"
"vmovups %%ymm11, 0x40(%9)\n"
:
: "r"(src), "r"(weight), "r"(bias), "r"(ic_align), "r"(in_sw_step), "r"(src_3_step), "r"(act_flag), // 6
"r"(oc_align), "r"(dst), "r"(dst_3), "r"(dst_flag) // 10
: "%rax", "%rcx", "%ymm0", "%ymm1", "%ymm2", "%ymm3", "%ymm4", "%ymm5", "%ymm6", "%ymm7", "%ymm8", "%ymm9",
"%ymm10", "%ymm11", "%ymm12", "%ymm13", "%ymm14", "%ymm15");
}
void Conv1x1SW1x24Kernel(float *dst, const float *src, const float *weight, const float *bias, size_t act_flag,
size_t ow_block, size_t oc_block, size_t oc_align, size_t ic_align, size_t in_sw_step,
size_t dst_flag) {
asm volatile(
"movq %8, %%rax\n"
"and $0x1, %%eax\n"
"je 0f\n"
"vmovups (%7), %%ymm0\n"
"vmovups 0x20(%7), %%ymm1\n"
"vmovups 0x40(%7), %%ymm2\n"
"jmp 2f\n"
"0:\n"
"cmpq $0, %2\n"
"je 1f\n"
"vmovups (%2), %%ymm0\n"
"vmovups 0x20(%2), %%ymm1\n"
"vmovups 0x40(%2), %%ymm2\n"
"jmp 2f\n"
"1:\n"
"vxorps %%ymm0, %%ymm0, %%ymm0\n"
"vxorps %%ymm1, %%ymm1, %%ymm1\n"
"vxorps %%ymm2, %%ymm2, %%ymm2\n"
"2:\n" // LoopIC
"vbroadcastss (%0), %%ymm13\n"
"vmovups (%1), %%ymm4\n"
"vmovups 0x20(%1), %%ymm5\n"
"vmovups 0x40(%1), %%ymm6\n"
"vfmadd231ps %%ymm4, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm5, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm6, %%ymm13, %%ymm2\n"
"vbroadcastss 4(%0), %%ymm13\n"
"vmovups 96(%1), %%ymm4\n"
"vmovups 128(%1), %%ymm5\n"
"vmovups 160(%1), %%ymm6\n"
"vfmadd231ps %%ymm4, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm5, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm6, %%ymm13, %%ymm2\n"
"vbroadcastss 8(%0), %%ymm13\n"
"vmovups 192(%1), %%ymm4\n"
"vmovups 224(%1), %%ymm5\n"
"vmovups 256(%1), %%ymm6\n"
"vfmadd231ps %%ymm4, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm5, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm6, %%ymm13, %%ymm2\n"
"vbroadcastss 12(%0), %%ymm13\n"
"vmovups 288(%1), %%ymm4\n"
"vmovups 320(%1), %%ymm5\n"
"vmovups 352(%1), %%ymm6\n"
"vfmadd231ps %%ymm4, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm5, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm6, %%ymm13, %%ymm2\n"
"vbroadcastss 16(%0), %%ymm13\n"
"vmovups 384(%1), %%ymm4\n"
"vmovups 416(%1), %%ymm5\n"
"vmovups 448(%1), %%ymm6\n"
"vfmadd231ps %%ymm4, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm5, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm6, %%ymm13, %%ymm2\n"
"vbroadcastss 20(%0), %%ymm13\n"
"vmovups 480(%1), %%ymm4\n"
"vmovups 512(%1), %%ymm5\n"
"vmovups 544(%1), %%ymm6\n"
"vfmadd231ps %%ymm4, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm5, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm6, %%ymm13, %%ymm2\n"
"vbroadcastss 24(%0), %%ymm13\n"
"vmovups 576(%1), %%ymm4\n"
"vmovups 608(%1), %%ymm5\n"
"vmovups 640(%1), %%ymm6\n"
"vfmadd231ps %%ymm4, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm5, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm6, %%ymm13, %%ymm2\n"
"vbroadcastss 28(%0), %%ymm13\n"
"vmovups 672(%1), %%ymm4\n"
"vmovups 704(%1), %%ymm5\n"
"vmovups 736(%1), %%ymm6\n"
"vfmadd231ps %%ymm4, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm5, %%ymm13, %%ymm1\n"
"vfmadd231ps %%ymm6, %%ymm13, %%ymm2\n"
"addq $768, %1\n"
"addq $32, %0\n"
"dec %3\n"
"jg 2b\n"
"movq %8, %%rax\n"
"and $0x2, %%eax\n"
"je 3f\n"
"movq %5, %%rax\n"
"and $0x3, %%eax\n"
"je 3f\n"
// Relu
"vxorps %%ymm12, %%ymm12, %%ymm12\n"
"vmaxps %%ymm12, %%ymm0, %%ymm0\n"
"vmaxps %%ymm12, %%ymm1, %%ymm1\n"
"vmaxps %%ymm12, %%ymm2, %%ymm2\n"
"and $0x1, %%eax\n"
"je 3f\n"
// relu6
"mov $0x40C00000, %%ecx\n"
"vmovd %%ecx, %%xmm14\n"
"vpermps %%ymm14, %%ymm12, %%ymm14\n"
"vminps %%ymm14, %%ymm0, %%ymm0\n"
"vminps %%ymm14, %%ymm1, %%ymm1\n"
"vminps %%ymm14, %%ymm2, %%ymm2\n"
"3:\n"
"vmovups %%ymm0, (%7)\n" // dst_0
"vmovups %%ymm1, 0x20(%7)\n"
"vmovups %%ymm2, 0x40(%7)\n"
:
: "r"(src), "r"(weight), "r"(bias), "r"(ic_align), "r"(in_sw_step), "r"(act_flag), "r"(oc_align), "r"(dst),
"r"(dst_flag) // 8
: "%rax", "%ecx", "%ymm0", "%ymm1", "%ymm2", "%ymm4", "%ymm5", "%ymm6", "%ymm12", "%ymm13", "%ymm14");
}
void Conv1x1SW6x16Kernel(float *dst, const float *src, const float *weight, const float *bias, size_t act_flag,
size_t ow_block, size_t oc_block, size_t oc_align, size_t ic_align, size_t in_sw_step,
size_t dst_flag) {
size_t src_3_step = 3 * in_sw_step;
float *dst_3 = dst + 3 * oc_align / sizeof(float);
asm volatile(
"movq %10, %%rax\n" // dst_flag
"and $0x1, %%eax\n"
"je 0f\n"
"vmovups (%8), %%ymm0\n" // dst_0
"vmovups 0x20(%8), %%ymm1\n"
"vmovups (%8, %7, 1), %%ymm2\n"
"vmovups 0x20(%8, %7, 1), %%ymm3\n"
"vmovups (%8, %7, 2), %%ymm4\n"
"vmovups 0x20(%8, %7, 2), %%ymm5\n"
"vmovups (%9), %%ymm6\n"
"vmovups 0x20(%9), %%ymm7\n"
"vmovups (%9, %7, 1), %%ymm8\n"
"vmovups 0x20(%9, %7, 1), %%ymm9\n"
"vmovups (%9, %7, 2), %%ymm10\n"
"vmovups 0x20(%9, %7, 2), %%ymm11\n"
"jmp 2f\n"
"0:\n"
"cmpq $0, %2\n"
"je 1f\n"
"vmovups (%2), %%ymm0\n"
"vmovups 0x20(%2), %%ymm1\n"
// We need to copy ymm0 to ymm3 to reduce IO time, but unfortunately I didn't find the corresponding instruction.
"vmovups (%2), %%ymm2\n"
"vmovups 0x20(%2), %%ymm3\n"
"vmovups (%2), %%ymm4\n"
"vmovups 0x20(%2), %%ymm5\n"
"vmovups (%2), %%ymm6\n"
"vmovups 0x20(%2), %%ymm7\n"
"vmovups (%2), %%ymm8\n"
"vmovups 0x20(%2), %%ymm9\n"
"vmovups (%2), %%ymm10\n"
"vmovups 0x20(%2), %%ymm11\n"
"jmp 2f\n"
"1:\n"
"vxorps %%ymm0, %%ymm0, %%ymm0\n"
"vxorps %%ymm1, %%ymm1, %%ymm1\n"
"vxorps %%ymm2, %%ymm2, %%ymm2\n"
"vxorps %%ymm3, %%ymm3, %%ymm3\n"
"vxorps %%ymm4, %%ymm4, %%ymm4\n"
"vxorps %%ymm5, %%ymm5, %%ymm5\n"
"vxorps %%ymm6, %%ymm6, %%ymm6\n"
"vxorps %%ymm7, %%ymm7, %%ymm7\n"
"vxorps %%ymm8, %%ymm8, %%ymm8\n"
"vxorps %%ymm9, %%ymm9, %%ymm9\n"
"vxorps %%ymm10, %%ymm10, %%ymm10\n"
"vxorps %%ymm11, %%ymm11, %%ymm11\n"
"2:\n" // LoopIC
"movq %0, %%rax\n"
"addq %5, %%rax\n"
"vmovups (%1), %%ymm12\n"
"vmovups 0x20(%1), %%ymm13\n"
"vbroadcastss (%0), %%ymm14\n"
"vbroadcastss (%0, %4), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm0\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm3\n"
"vbroadcastss (%0, %4, 2), %%ymm14\n"
"vbroadcastss (%%rax), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm5\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm6\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm7\n"
"vbroadcastss (%%rax, %4), %%ymm14\n"
"vbroadcastss (%%rax, %4, 2), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm8\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm10\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm11\n"
"vmovups 64(%1), %%ymm12\n"
"vmovups 96(%1), %%ymm13\n"
"vbroadcastss 4(%0), %%ymm14\n"
"vbroadcastss 4(%0, %4), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm0\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm3\n"
"vbroadcastss 4(%0, %4, 2), %%ymm14\n"
"vbroadcastss 4(%%rax), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm5\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm6\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm7\n"
"vbroadcastss 4(%%rax, %4), %%ymm14\n"
"vbroadcastss 4(%%rax, %4, 2), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm8\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm10\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm11\n"
"vmovups 128(%1), %%ymm12\n"
"vmovups 160(%1), %%ymm13\n"
"vbroadcastss 8(%0), %%ymm14\n"
"vbroadcastss 8(%0, %4), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm0\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm3\n"
"vbroadcastss 8(%0, %4, 2), %%ymm14\n"
"vbroadcastss 8(%%rax), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm5\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm6\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm7\n"
"vbroadcastss 8(%%rax, %4), %%ymm14\n"
"vbroadcastss 8(%%rax, %4, 2), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm8\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm10\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm11\n"
"vmovups 192(%1), %%ymm12\n"
"vmovups 224(%1), %%ymm13\n"
"vbroadcastss 12(%0), %%ymm14\n"
"vbroadcastss 12(%0, %4), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm0\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm3\n"
"vbroadcastss 12(%0, %4, 2), %%ymm14\n"
"vbroadcastss 12(%%rax), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm5\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm6\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm7\n"
"vbroadcastss 12(%%rax, %4), %%ymm14\n"
"vbroadcastss 12(%%rax, %4, 2), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm8\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm10\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm11\n"
"vmovups 256(%1), %%ymm12\n"
"vmovups 288(%1), %%ymm13\n"
"vbroadcastss 16(%0), %%ymm14\n"
"vbroadcastss 16(%0, %4), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm0\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm3\n"
"vbroadcastss 16(%0, %4, 2), %%ymm14\n"
"vbroadcastss 16(%%rax), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm5\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm6\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm7\n"
"vbroadcastss 16(%%rax, %4), %%ymm14\n"
"vbroadcastss 16(%%rax, %4, 2), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm8\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm10\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm11\n"
"vmovups 320(%1), %%ymm12\n"
"vmovups 352(%1), %%ymm13\n"
"vbroadcastss 20(%0), %%ymm14\n"
"vbroadcastss 20(%0, %4), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm0\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm3\n"
"vbroadcastss 20(%0, %4, 2), %%ymm14\n"
"vbroadcastss 20(%%rax), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm5\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm6\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm7\n"
"vbroadcastss 20(%%rax, %4), %%ymm14\n"
"vbroadcastss 20(%%rax, %4, 2), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm8\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm10\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm11\n"
"vmovups 384(%1), %%ymm12\n"
"vmovups 416(%1), %%ymm13\n"
"vbroadcastss 24(%0), %%ymm14\n"
"vbroadcastss 24(%0, %4), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm0\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm3\n"
"vbroadcastss 24(%0, %4, 2), %%ymm14\n"
"vbroadcastss 24(%%rax), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm5\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm6\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm7\n"
"vbroadcastss 24(%%rax, %4), %%ymm14\n"
"vbroadcastss 24(%%rax, %4, 2), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm8\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm10\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm11\n"
"vmovups 448(%1), %%ymm12\n"
"vmovups 480(%1), %%ymm13\n"
"vbroadcastss 28(%0), %%ymm14\n"
"vbroadcastss 28(%0, %4), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm0\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm3\n"
"vbroadcastss 28(%0, %4, 2), %%ymm14\n"
"vbroadcastss 28(%%rax), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm5\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm6\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm7\n"
"vbroadcastss 28(%%rax, %4), %%ymm14\n"
"vbroadcastss 28(%%rax, %4, 2), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm8\n"
"vfmadd231ps %%ymm13, %%ymm14, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm10\n"
"vfmadd231ps %%ymm13, %%ymm15, %%ymm11\n"
"addq $512, %1\n"
"addq $32, %0\n"
"dec %3\n"
"jg 2b\n"
"movq %10, %%rax\n"
"and $0x2, %%eax\n"
"je 3f\n"
"movq %6, %%rax\n"
"and $0x3, %%eax\n"
"je 3f\n"
// Relu
"vxorps %%ymm12, %%ymm12, %%ymm12\n"
"vmaxps %%ymm12, %%ymm0, %%ymm0\n"
"vmaxps %%ymm12, %%ymm1, %%ymm1\n"
"vmaxps %%ymm12, %%ymm2, %%ymm2\n"
"vmaxps %%ymm12, %%ymm3, %%ymm3\n"
"vmaxps %%ymm12, %%ymm4, %%ymm4\n"
"vmaxps %%ymm12, %%ymm5, %%ymm5\n"
"vmaxps %%ymm12, %%ymm6, %%ymm6\n"
"vmaxps %%ymm12, %%ymm7, %%ymm7\n"
"vmaxps %%ymm12, %%ymm8, %%ymm8\n"
"vmaxps %%ymm12, %%ymm9, %%ymm9\n"
"vmaxps %%ymm12, %%ymm10, %%ymm10\n"
"vmaxps %%ymm12, %%ymm11, %%ymm11\n"
"and $0x1, %%eax\n"
"je 3f\n"
// relu6
"mov $0x40C00000, %%ecx\n"
"vmovd %%ecx, %%xmm14\n"
"vpermps %%ymm14, %%ymm12, %%ymm14\n"
"vminps %%ymm14, %%ymm0, %%ymm0\n"
"vminps %%ymm14, %%ymm1, %%ymm1\n"
"vminps %%ymm14, %%ymm2, %%ymm2\n"
"vminps %%ymm14, %%ymm3, %%ymm3\n"
"vminps %%ymm14, %%ymm4, %%ymm4\n"
"vminps %%ymm14, %%ymm5, %%ymm5\n"
"vminps %%ymm14, %%ymm6, %%ymm6\n"
"vminps %%ymm14, %%ymm7, %%ymm7\n"
"vminps %%ymm14, %%ymm8, %%ymm8\n"
"vminps %%ymm14, %%ymm9, %%ymm9\n"
"vminps %%ymm14, %%ymm10, %%ymm10\n"
"vminps %%ymm14, %%ymm11, %%ymm11\n"
"3:\n"
"vmovups %%ymm0, (%8)\n" // dst_0
"vmovups %%ymm1, 0x20(%8)\n"
"vmovups %%ymm2, (%8, %7, 1)\n"
"vmovups %%ymm3, 0x20(%8, %7, 1)\n"
"vmovups %%ymm4, (%8, %7, 2)\n"
"vmovups %%ymm5, 0x20(%8, %7, 2)\n"
"vmovups %%ymm6, (%9)\n" // dst+3
"vmovups %%ymm7, 0x20(%9)\n"
"vmovups %%ymm8, (%9, %7, 1)\n"
"vmovups %%ymm9, 0x20(%9, %7, 1)\n"
"vmovups %%ymm10, (%9, %7, 2)\n"
"vmovups %%ymm11, 0x20(%9, %7, 2)\n"
:
: "r"(src), "r"(weight), "r"(bias), "r"(ic_align), "r"(in_sw_step), "r"(src_3_step), "r"(act_flag), // 6
"r"(oc_align), "r"(dst), "r"(dst_3), "r"(dst_flag) // 10
: "%rax", "%rcx", "%ymm0", "%ymm1", "%ymm2", "%ymm3", "%ymm4", "%ymm5", "%ymm6", "%ymm7", "%ymm8", "%ymm9",
"%ymm10", "%ymm11", "%ymm12", "%ymm13", "%ymm14", "%ymm15");
}
void Conv1x1SW1x16Kernel(float *dst, const float *src, const float *weight, const float *bias, size_t act_flag,
size_t ow_block, size_t oc_block, size_t oc_align, size_t ic_align, size_t in_sw_step,
size_t dst_flag) {
asm volatile(
"movq %8, %%rax\n"
"and $0x1, %%eax\n"
"je 0f\n"
"vmovups (%7), %%ymm0\n"
"vmovups 0x20(%7), %%ymm1\n"
"jmp 2f\n"
"0:\n"
"cmpq $0, %2\n"
"je 1f\n"
"vmovups (%2), %%ymm0\n"
"vmovups 0x20(%2), %%ymm1\n"
"jmp 2f\n"
"1:\n"
"vxorps %%ymm0, %%ymm0, %%ymm0\n"
"vxorps %%ymm1, %%ymm1, %%ymm1\n"
"2:\n" // LoopIC
"vbroadcastss (%0), %%ymm12\n"
"vmovups (%1), %%ymm13\n"
"vmovups 0x20(%1), %%ymm14\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"vbroadcastss 4(%0), %%ymm12\n"
"vmovups 64(%1), %%ymm13\n"
"vmovups 96(%1), %%ymm14\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"vbroadcastss 8(%0), %%ymm12\n"
"vmovups 128(%1), %%ymm13\n"
"vmovups 160(%1), %%ymm14\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"vbroadcastss 12(%0), %%ymm12\n"
"vmovups 192(%1), %%ymm13\n"
"vmovups 224(%1), %%ymm14\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"vbroadcastss 16(%0), %%ymm12\n"
"vmovups 256(%1), %%ymm13\n"
"vmovups 288(%1), %%ymm14\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"vbroadcastss 20(%0), %%ymm12\n"
"vmovups 320(%1), %%ymm13\n"
"vmovups 352(%1), %%ymm14\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"vbroadcastss 24(%0), %%ymm12\n"
"vmovups 384(%1), %%ymm13\n"
"vmovups 416(%1), %%ymm14\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"vbroadcastss 28(%0), %%ymm12\n"
"vmovups 448(%1), %%ymm13\n"
"vmovups 480(%1), %%ymm14\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"addq $512, %1\n"
"addq $32, %0\n"
"dec %3\n"
"jg 2b\n"
"movq %8, %%rax\n"
"and $0x2, %%eax\n"
"je 3f\n"
"movq %5, %%rax\n"
"and $0x3, %%eax\n"
"je 3f\n"
// Relu
"vxorps %%ymm12, %%ymm12, %%ymm12\n"
"vmaxps %%ymm12, %%ymm0, %%ymm0\n"
"vmaxps %%ymm12, %%ymm1, %%ymm1\n"
"and $0x1, %%eax\n"
"je 3f\n"
// relu6
"mov $0x40C00000, %%ecx\n"
"vmovd %%ecx, %%xmm14\n"
"vpermps %%ymm14, %%ymm12, %%ymm14\n"
"vminps %%ymm14, %%ymm0, %%ymm0\n"
"vminps %%ymm14, %%ymm1, %%ymm1\n"
"3:\n"
"vmovups %%ymm0, (%7)\n" // dst_0
"vmovups %%ymm1, 0x20(%7)\n"
:
: "r"(src), "r"(weight), "r"(bias), "r"(ic_align), "r"(in_sw_step), "r"(act_flag), "r"(oc_align), "r"(dst),
"r"(dst_flag) // 8
: "%rax", "%ecx", "%ymm0", "%ymm1", "%ymm12", "%ymm13", "%ymm14");
}
void Conv1x1SW12x8Kernel(float *dst, const float *src, const float *weight, const float *bias, size_t act_flag,
size_t ow_block, size_t oc_block, size_t oc_align, size_t ic_align, size_t in_sw_step,
size_t dst_flag) {
ic_align <<= 3;
size_t src_3_step = 3 * in_sw_step;
float *dst_3 = dst + 3 * oc_align / sizeof(float);
float *dst_5 = dst + 5 * oc_align / sizeof(float);
float *dst_9 = dst + 9 * oc_align / sizeof(float);
asm volatile(
"movq %12, %%rax\n"
"and $0x1, %%eax\n"
"je 0f\n"
"vmovups (%8), %%ymm0\n" // dst_0
"vmovups (%8, %7), %%ymm1\n"
"vmovups (%8, %7, 2), %%ymm2\n"
"vmovups (%9), %%ymm3\n" // dst_3
"vmovups (%8, %7, 4), %%ymm4\n"
"vmovups (%10), %%ymm5\n" // dst_5
"vmovups (%10, %7, 1), %%ymm6\n"
"vmovups (%10, %7, 2), %%ymm7\n"
"vmovups (%8, %7, 8), %%ymm8\n"
"vmovups (%11), %%ymm9\n" // dst_9
"vmovups (%11, %7, 1), %%ymm10\n"
"vmovups (%11, %7, 2), %%ymm11\n"
"jmp 2f\n"
"0:\n"
"cmpq $0, %2\n"
"je 1f\n"
"vmovups (%2), %%ymm0\n"
"vmovups (%2), %%ymm1\n"
"vmovups (%2), %%ymm2\n"
"vmovups (%2), %%ymm3\n"
"vmovups (%2), %%ymm4\n"
"vmovups (%2), %%ymm5\n"
"vmovups (%2), %%ymm6\n"
"vmovups (%2), %%ymm7\n"
"vmovups (%2), %%ymm8\n"
"vmovups (%2), %%ymm9\n"
"vmovups (%2), %%ymm10\n"
"vmovups (%2), %%ymm11\n"
"jmp 2f\n"
"1:\n"
"vxorps %%ymm0, %%ymm0, %%ymm0\n"
"vxorps %%ymm1, %%ymm1, %%ymm1\n"
"vxorps %%ymm2, %%ymm2, %%ymm2\n"
"vxorps %%ymm3, %%ymm3, %%ymm3\n"
"vxorps %%ymm4, %%ymm4, %%ymm4\n"
"vxorps %%ymm5, %%ymm5, %%ymm5\n"
"vxorps %%ymm6, %%ymm6, %%ymm6\n"
"vxorps %%ymm7, %%ymm7, %%ymm7\n"
"vxorps %%ymm8, %%ymm8, %%ymm8\n"
"vxorps %%ymm9, %%ymm9, %%ymm9\n"
"vxorps %%ymm10, %%ymm10, %%ymm10\n"
"vxorps %%ymm11, %%ymm11, %%ymm11\n"
"2:\n" // LoopIC
"vmovups (%1), %%ymm12\n"
"movq %0, %%rax\n"
"vbroadcastss (%%rax), %%ymm13\n"
"vbroadcastss (%%rax, %4), %%ymm14\n"
"vbroadcastss (%%rax, %4, 2), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm1\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm2\n"
"addq %5, %%rax\n"
"vbroadcastss (%%rax), %%ymm13\n"
"vbroadcastss (%%rax, %4), %%ymm14\n"
"vbroadcastss (%%rax, %4, 2), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm3\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm4\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm5\n"
"addq %5, %%rax\n"
"vbroadcastss (%%rax), %%ymm13\n"
"vbroadcastss (%%rax, %4), %%ymm14\n"
"vbroadcastss (%%rax, %4, 2), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm6\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm7\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm8\n"
"addq %5, %%rax\n"
"vbroadcastss (%%rax), %%ymm13\n"
"vbroadcastss (%%rax, %4), %%ymm14\n"
"vbroadcastss (%%rax, %4, 2), %%ymm15\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm9\n"
"vfmadd231ps %%ymm12, %%ymm14, %%ymm10\n"
"vfmadd231ps %%ymm12, %%ymm15, %%ymm11\n"
"addq $32, %1\n"
"addq $4, %0\n"
"dec %3\n"
"jg 2b\n"
:
: "r"(src), "r"(weight), "r"(bias), "r"(ic_align), "r"(in_sw_step), "r"(src_3_step), "r"(act_flag), // 6
"r"(oc_align), "r"(dst), "r"(dst_3), "r"(dst_5), "r"(dst_9), "r"(dst_flag) // 12
: "%rax", "%ymm0", "%ymm1", "%ymm2", "%ymm3", "%ymm4", "%ymm5", "%ymm6", "%ymm7", "%ymm8", "%ymm9", "%ymm10",
"%ymm11", "%ymm12", "%ymm13", "%ymm14", "%ymm15");
asm volatile(
"and $0x2, %%eax\n"
"je 0f\n"
"movq %0, %%rax\n"
"and $0x3, %%eax\n"
"je 0f\n"
// Relu
"vxorps %%ymm12, %%ymm12, %%ymm12\n"
"vmaxps %%ymm12, %%ymm0, %%ymm0\n"
"vmaxps %%ymm12, %%ymm1, %%ymm1\n"
"vmaxps %%ymm12, %%ymm2, %%ymm2\n"
"vmaxps %%ymm12, %%ymm3, %%ymm3\n"
"vmaxps %%ymm12, %%ymm4, %%ymm4\n"
"vmaxps %%ymm12, %%ymm5, %%ymm5\n"
"vmaxps %%ymm12, %%ymm6, %%ymm6\n"
"vmaxps %%ymm12, %%ymm7, %%ymm7\n"
"vmaxps %%ymm12, %%ymm8, %%ymm8\n"
"vmaxps %%ymm12, %%ymm9, %%ymm9\n"
"vmaxps %%ymm12, %%ymm10, %%ymm10\n"
"vmaxps %%ymm12, %%ymm11, %%ymm11\n"
"and $0x1, %%eax\n"
"je 0f\n"
// relu6
"mov $0x40C00000, %%ecx\n"
"vmovd %%ecx, %%xmm14\n"
"vpermps %%ymm14, %%ymm12, %%ymm14\n"
"vminps %%ymm14, %%ymm0, %%ymm0\n"
"vminps %%ymm14, %%ymm1, %%ymm1\n"
"vminps %%ymm14, %%ymm2, %%ymm2\n"
"vminps %%ymm14, %%ymm3, %%ymm3\n"
"vminps %%ymm14, %%ymm4, %%ymm4\n"
"vminps %%ymm14, %%ymm5, %%ymm5\n"
"vminps %%ymm14, %%ymm6, %%ymm6\n"
"vminps %%ymm14, %%ymm7, %%ymm7\n"
"vminps %%ymm14, %%ymm8, %%ymm8\n"
"vminps %%ymm14, %%ymm9, %%ymm9\n"
"vminps %%ymm14, %%ymm10, %%ymm10\n"
"vminps %%ymm14, %%ymm11, %%ymm11\n"
"0:\n"
"vmovups %%ymm0, (%2)\n" // dst_0
"vmovups %%ymm1, (%2, %1)\n"
"vmovups %%ymm2, (%2, %1, 2)\n"
"vmovups %%ymm3, (%3)\n" // dst_3
"vmovups %%ymm4, (%2, %1, 4)\n"
"vmovups %%ymm5, (%4)\n" // dst_5
"vmovups %%ymm6, (%4, %1, 1)\n"
"vmovups %%ymm7, (%4, %1, 2)\n"
"vmovups %%ymm8, (%2, %1, 8)\n"
"vmovups %%ymm9, (%5)\n" // dst_9
"vmovups %%ymm10, (%5, %1, 1)\n"
"vmovups %%ymm11, (%5, %1, 2)\n"
:
: "r"(act_flag), "r"(oc_align), "r"(dst), "r"(dst_3), "r"(dst_5), "r"(dst_9), "a"(dst_flag) // 6
: "%ecx", "%ymm0", "%ymm1", "%ymm2", "%ymm3", "%ymm4", "%ymm5", "%ymm6", "%ymm7", "%ymm8", "%ymm9", "%ymm10",
"%ymm11", "%ymm12", "%ymm14");
}
void Conv1x1SW1x8Kernel(float *dst, const float *src, const float *weight, const float *bias, size_t act_flag,
size_t ow_block, size_t oc_block, size_t oc_align, size_t ic_align, size_t in_sw_step,
size_t dst_flag) {
asm volatile(
"movq %8, %%rax\n"
"and $0x1, %%eax\n"
"je 0f\n"
"vmovups (%7), %%ymm0\n"
"jmp 2f\n"
"0:\n"
"cmpq $0, %2\n"
"je 1f\n"
"vmovups (%2), %%ymm0\n"
"jmp 2f\n"
"1:\n"
"vxorps %%ymm0, %%ymm0, %%ymm0\n"
"2:\n" // LoopIC
"vbroadcastss (%0), %%ymm12\n"
"vmovups (%1), %%ymm13\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vbroadcastss 4(%0), %%ymm12\n"
"vmovups 32(%1), %%ymm13\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vbroadcastss 8(%0), %%ymm12\n"
"vmovups 64(%1), %%ymm13\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vbroadcastss 12(%0), %%ymm12\n"
"vmovups 96(%1), %%ymm13\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vbroadcastss 16(%0), %%ymm12\n"
"vmovups 128(%1), %%ymm13\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vbroadcastss 20(%0), %%ymm12\n"
"vmovups 160(%1), %%ymm13\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vbroadcastss 24(%0), %%ymm12\n"
"vmovups 192(%1), %%ymm13\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"vbroadcastss 28(%0), %%ymm12\n"
"vmovups 224(%1), %%ymm13\n"
"vfmadd231ps %%ymm12, %%ymm13, %%ymm0\n"
"addq $256, %1\n"
"addq $32, %0\n"
"dec %3\n"
"jg 2b\n"
"movq %8, %%rax\n"
"and $0x2, %%eax\n"
"je 3f\n"
"movq %5, %%rax\n"
"and $0x3, %%eax\n"
"je 3f\n"
// Relu
"vxorps %%ymm12, %%ymm12, %%ymm12\n"
"vmaxps %%ymm12, %%ymm0, %%ymm0\n"
"and $0x1, %%eax\n"
"je 3f\n"
// relu6
"mov $0x40C00000, %%ecx\n"
"vmovd %%ecx, %%xmm14\n"
"vpermps %%ymm14, %%ymm12, %%ymm14\n"
"vminps %%ymm14, %%ymm0, %%ymm0\n"
"3:\n"
"vmovups %%ymm0, (%7)\n" // dst_0
:
: "r"(src), "r"(weight), "r"(bias), "r"(ic_align), "r"(in_sw_step), "r"(act_flag), "r"(oc_align), "r"(dst),
"r"(dst_flag) // 8
: "%rax", "%ecx", "%ymm0", "%ymm12", "%ymm13");
}
#ifdef ENABLE_DEBUG
void Conv1x1SWOWxOCKernel(float *dst, const float *src, const float *weight, const float *bias, size_t act_flag,
size_t ow_block, size_t oc_block, size_t oc_align, size_t ic_align, size_t in_sw_step,
size_t dst_flag) {
oc_align /= sizeof(float);
in_sw_step /= sizeof(float);
ic_align <<= 3;
__m256 dst_data[12];
const float *src_sw[12];
__m256 weight_data[4];
for (int i = 0; i < 4; ++i) {
weight_data[i] = _mm256_set1_ps(0.0f);
}
for (int i = 0; i < ow_block; ++i) {
if (dst_flag & 0x01) {
for (int j = 0; j < oc_block; ++j) {
dst_data[i * oc_block + j] = _mm256_loadu_ps(dst + i * oc_align + j * C8NUM);
}
} else {
if (bias != NULL) {
for (int j = 0; j < oc_block; ++j) {
dst_data[i * oc_block + j] = _mm256_loadu_ps(bias + j * 8);
}
} else {
for (int j = 0; j < oc_block; ++j) {
dst_data[i * oc_block + j] = _mm256_set1_ps(0.0f);
}
}
}
src_sw[i] = src + i * in_sw_step;
}
const float *weight_kernel = weight;
for (int ic = 0; ic < ic_align; ++ic) {
for (int j = 0; j < oc_block; ++j) {
weight_data[j] = _mm256_loadu_ps(weight_kernel + j * C8NUM);
}
for (int i = 0; i < ow_block; ++i) {
for (int j = 0; j < oc_block; ++j) {
dst_data[i * oc_block + j] += src_sw[i][ic] * weight_data[j];
}
}
weight_kernel += C8NUM * oc_block;
} // ic loop
// add bias and relu
for (int i = 0; i < ow_block; ++i) {
for (int j = 0; j < oc_block; ++j) {
if (dst_flag & 0x02) {
if (0x1 & act_flag) { // relu6
dst_data[i * oc_block + j] = _mm256_min_ps(dst_data[i * oc_block + j], _mm256_set1_ps(6.0f));
}
if (0x2 & act_flag) { // relu
dst_data[i * oc_block + j] = _mm256_max_ps(dst_data[i * oc_block + j], _mm256_set1_ps(0.0f));
}
}
_mm256_storeu_ps(dst + i * oc_align + j * C8NUM, dst_data[i * oc_block + j]);
}
}
}
#endif
#endif
|
the_stack_data/190769453.c | #ifndef lint
static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
#endif
#define YYBYACC 1
#define YYMAJOR 1
#define YYMINOR 9
#define YYEMPTY (-1)
#define yyclearin (yychar = YYEMPTY)
#define yyerrok (yyerrflag = 0)
#define YYRECOVERING() (yyerrflag != 0)
#ifndef yyparse
#define yyparse calc2_parse
#endif /* yyparse */
#ifndef yylex
#define yylex calc2_lex
#endif /* yylex */
#ifndef yyerror
#define yyerror calc2_error
#endif /* yyerror */
#ifndef yychar
#define yychar calc2_char
#endif /* yychar */
#ifndef yyval
#define yyval calc2_val
#endif /* yyval */
#ifndef yylval
#define yylval calc2_lval
#endif /* yylval */
#ifndef yydebug
#define yydebug calc2_debug
#endif /* yydebug */
#ifndef yynerrs
#define yynerrs calc2_nerrs
#endif /* yynerrs */
#ifndef yyerrflag
#define yyerrflag calc2_errflag
#endif /* yyerrflag */
#ifndef yylhs
#define yylhs calc2_lhs
#endif /* yylhs */
#ifndef yylen
#define yylen calc2_len
#endif /* yylen */
#ifndef yydefred
#define yydefred calc2_defred
#endif /* yydefred */
#ifndef yydgoto
#define yydgoto calc2_dgoto
#endif /* yydgoto */
#ifndef yysindex
#define yysindex calc2_sindex
#endif /* yysindex */
#ifndef yyrindex
#define yyrindex calc2_rindex
#endif /* yyrindex */
#ifndef yygindex
#define yygindex calc2_gindex
#endif /* yygindex */
#ifndef yytable
#define yytable calc2_table
#endif /* yytable */
#ifndef yycheck
#define yycheck calc2_check
#endif /* yycheck */
#ifndef yyname
#define yyname calc2_name
#endif /* yyname */
#ifndef yyrule
#define yyrule calc2_rule
#endif /* yyrule */
#define YYPREFIX "calc2_"
#define YYPURE 0
#line 7 "calc2.y"
# include <stdio.h>
# include <ctype.h>
#ifdef YYBISON
#define YYLEX_PARAM base
#define YYLEX_DECL() yylex(int *YYLEX_PARAM)
#define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
int YYLEX_DECL();
static void YYERROR_DECL();
#endif
#line 111 "calc2.tab.c"
#ifndef YYSTYPE
typedef int YYSTYPE;
#endif
/* compatibility with bison */
#ifdef YYPARSE_PARAM
/* compatibility with FreeBSD */
# ifdef YYPARSE_PARAM_TYPE
# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
# else
# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
# endif
#else
# define YYPARSE_DECL() yyparse(int regs[26], int * base)
#endif
/* Parameters sent to lex. */
#ifdef YYLEX_PARAM
# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
# define YYLEX yylex(YYLEX_PARAM)
#else
# define YYLEX_DECL() yylex(int * base)
# define YYLEX yylex(base)
#endif
/* Parameters sent to yyerror. */
#ifndef YYERROR_DECL
#define YYERROR_DECL() yyerror(int regs[26], int * base, const char *s)
#endif
#ifndef YYERROR_CALL
#define YYERROR_CALL(msg) yyerror(regs, base, msg)
#endif
extern int YYPARSE_DECL();
#define DIGIT 257
#define LETTER 258
#define UMINUS 259
#define YYERRCODE 256
static const short calc2_lhs[] = { -1,
0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 3, 3,
};
static const short calc2_len[] = { 2,
0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
3, 3, 3, 2, 1, 1, 1, 2,
};
static const short calc2_defred[] = { 1,
0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
10, 11,
};
static const short calc2_dgoto[] = { 1,
7, 8, 9,
};
static const short calc2_sindex[] = { 0,
-40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
-38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
-38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
0, 0,
};
static const short calc2_rindex[] = { 0,
0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
0, 0,
};
static const short calc2_gindex[] = { 0,
0, 65, 0,
};
#define YYTABLESIZE 220
static const short calc2_table[] = { 6,
16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
};
static const short calc2_check[] = { 40,
10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
-1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
-1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
-1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
-1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
-1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
-1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
-1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
-1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
-1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
-1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
};
#define YYFINAL 1
#ifndef YYDEBUG
#define YYDEBUG 0
#endif
#define YYMAXTOKEN 259
#if YYDEBUG
static const char *yyname[] = {
"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
};
static const char *yyrule[] = {
"$accept : list",
"list :",
"list : list stat '\\n'",
"list : list error '\\n'",
"stat : expr",
"stat : LETTER '=' expr",
"expr : '(' expr ')'",
"expr : expr '+' expr",
"expr : expr '-' expr",
"expr : expr '*' expr",
"expr : expr '/' expr",
"expr : expr '%' expr",
"expr : expr '&' expr",
"expr : expr '|' expr",
"expr : '-' expr",
"expr : LETTER",
"expr : number",
"number : DIGIT",
"number : number DIGIT",
};
#endif
int yydebug;
int yynerrs;
int yyerrflag;
int yychar;
YYSTYPE yyval;
YYSTYPE yylval;
/* define the initial stack-sizes */
#ifdef YYSTACKSIZE
#undef YYMAXDEPTH
#define YYMAXDEPTH YYSTACKSIZE
#else
#ifdef YYMAXDEPTH
#define YYSTACKSIZE YYMAXDEPTH
#else
#define YYSTACKSIZE 500
#define YYMAXDEPTH 500
#endif
#endif
#define YYINITSTACKSIZE 500
typedef struct {
unsigned stacksize;
short *s_base;
short *s_mark;
short *s_last;
YYSTYPE *l_base;
YYSTYPE *l_mark;
} YYSTACKDATA;
/* variables for the parser stack */
static YYSTACKDATA yystack;
#line 73 "calc2.y"
/* start of programs */
#ifdef YYBYACC
extern int YYLEX_DECL();
#endif
int
main (void)
{
int regs[26];
int base = 10;
while(!feof(stdin)) {
yyparse(regs, &base);
}
return 0;
}
static void
YYERROR_DECL()
{
fprintf(stderr, "%s\n", s);
}
int
YYLEX_DECL()
{
/* lexical analysis routine */
/* returns LETTER for a lower case letter, yylval = 0 through 25 */
/* return DIGIT for a digit, yylval = 0 through 9 */
/* all other characters are returned immediately */
int c;
while( (c=getchar()) == ' ' ) { /* skip blanks */ }
/* c is now nonblank */
if( islower( c )) {
yylval = c - 'a';
return ( LETTER );
}
if( isdigit( c )) {
yylval = (c - '0') % (*base);
return ( DIGIT );
}
return( c );
}
#line 356 "calc2.tab.c"
#if YYDEBUG
#include <stdio.h> /* needed for printf */
#endif
#include <stdlib.h> /* needed for malloc, etc */
#include <string.h> /* needed for memset */
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
static int yygrowstack(YYSTACKDATA *data)
{
int i;
unsigned newsize;
short *newss;
YYSTYPE *newvs;
if ((newsize = data->stacksize) == 0)
newsize = YYINITSTACKSIZE;
else if (newsize >= YYMAXDEPTH)
return -1;
else if ((newsize *= 2) > YYMAXDEPTH)
newsize = YYMAXDEPTH;
i = data->s_mark - data->s_base;
newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
if (newss == 0)
return -1;
data->s_base = newss;
data->s_mark = newss + i;
newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
if (newvs == 0)
return -1;
data->l_base = newvs;
data->l_mark = newvs + i;
data->stacksize = newsize;
data->s_last = data->s_base + newsize - 1;
return 0;
}
#if YYPURE || defined(YY_NO_LEAKS)
static void yyfreestack(YYSTACKDATA *data)
{
free(data->s_base);
free(data->l_base);
memset(data, 0, sizeof(*data));
}
#else
#define yyfreestack(data) /* nothing */
#endif
#define YYABORT goto yyabort
#define YYREJECT goto yyabort
#define YYACCEPT goto yyaccept
#define YYERROR goto yyerrlab
int
YYPARSE_DECL()
{
int yym, yyn, yystate;
#if YYDEBUG
const char *yys;
if ((yys = getenv("YYDEBUG")) != 0)
{
yyn = *yys;
if (yyn >= '0' && yyn <= '9')
yydebug = yyn - '0';
}
#endif
yynerrs = 0;
yyerrflag = 0;
yychar = YYEMPTY;
yystate = 0;
#if YYPURE
memset(&yystack, 0, sizeof(yystack));
#endif
if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
yystack.s_mark = yystack.s_base;
yystack.l_mark = yystack.l_base;
yystate = 0;
*yystack.s_mark = 0;
yyloop:
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
if (yychar < 0)
{
if ((yychar = YYLEX) < 0) yychar = 0;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("%sdebug: state %d, reading %d (%s)\n",
YYPREFIX, yystate, yychar, yys);
}
#endif
}
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, shifting to state %d\n",
YYPREFIX, yystate, yytable[yyn]);
#endif
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
{
goto yyoverflow;
}
yystate = yytable[yyn];
*++yystack.s_mark = yytable[yyn];
*++yystack.l_mark = yylval;
yychar = YYEMPTY;
if (yyerrflag > 0) --yyerrflag;
goto yyloop;
}
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
yyn = yytable[yyn];
goto yyreduce;
}
if (yyerrflag) goto yyinrecovery;
yyerror(regs, base, "syntax error");
goto yyerrlab;
yyerrlab:
++yynerrs;
yyinrecovery:
if (yyerrflag < 3)
{
yyerrflag = 3;
for (;;)
{
if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, error recovery shifting\
to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
#endif
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
{
goto yyoverflow;
}
yystate = yytable[yyn];
*++yystack.s_mark = yytable[yyn];
*++yystack.l_mark = yylval;
goto yyloop;
}
else
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: error recovery discarding state %d\n",
YYPREFIX, *yystack.s_mark);
#endif
if (yystack.s_mark <= yystack.s_base) goto yyabort;
--yystack.s_mark;
--yystack.l_mark;
}
}
}
else
{
if (yychar == 0) goto yyabort;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
YYPREFIX, yystate, yychar, yys);
}
#endif
yychar = YYEMPTY;
goto yyloop;
}
yyreduce:
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
YYPREFIX, yystate, yyn, yyrule[yyn]);
#endif
yym = yylen[yyn];
if (yym)
yyval = yystack.l_mark[1-yym];
else
memset(&yyval, 0, sizeof yyval);
switch (yyn)
{
case 3:
#line 35 "calc2.y"
{ yyerrok ; }
break;
case 4:
#line 39 "calc2.y"
{ printf("%d\n",yystack.l_mark[0]);}
break;
case 5:
#line 41 "calc2.y"
{ regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
break;
case 6:
#line 45 "calc2.y"
{ yyval = yystack.l_mark[-1]; }
break;
case 7:
#line 47 "calc2.y"
{ yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
break;
case 8:
#line 49 "calc2.y"
{ yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
break;
case 9:
#line 51 "calc2.y"
{ yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
break;
case 10:
#line 53 "calc2.y"
{ yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
break;
case 11:
#line 55 "calc2.y"
{ yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
break;
case 12:
#line 57 "calc2.y"
{ yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
break;
case 13:
#line 59 "calc2.y"
{ yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
break;
case 14:
#line 61 "calc2.y"
{ yyval = - yystack.l_mark[0]; }
break;
case 15:
#line 63 "calc2.y"
{ yyval = regs[yystack.l_mark[0]]; }
break;
case 17:
#line 68 "calc2.y"
{ yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
break;
case 18:
#line 70 "calc2.y"
{ yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
break;
#line 622 "calc2.tab.c"
}
yystack.s_mark -= yym;
yystate = *yystack.s_mark;
yystack.l_mark -= yym;
yym = yylhs[yyn];
if (yystate == 0 && yym == 0)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: after reduction, shifting from state 0 to\
state %d\n", YYPREFIX, YYFINAL);
#endif
yystate = YYFINAL;
*++yystack.s_mark = YYFINAL;
*++yystack.l_mark = yyval;
if (yychar < 0)
{
if ((yychar = YYLEX) < 0) yychar = 0;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("%sdebug: state %d, reading %d (%s)\n",
YYPREFIX, YYFINAL, yychar, yys);
}
#endif
}
if (yychar == 0) goto yyaccept;
goto yyloop;
}
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
yystate = yytable[yyn];
else
yystate = yydgoto[yym];
#if YYDEBUG
if (yydebug)
printf("%sdebug: after reduction, shifting from state %d \
to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
#endif
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
{
goto yyoverflow;
}
*++yystack.s_mark = (short) yystate;
*++yystack.l_mark = yyval;
goto yyloop;
yyoverflow:
yyerror(regs, base, "yacc stack overflow");
yyabort:
yyfreestack(&yystack);
return (1);
yyaccept:
yyfreestack(&yystack);
return (0);
}
|
the_stack_data/234517050.c | #include <ncurses.h>
int main() {
int ch;
initscr(); /* Start curses mode */
raw(); /* Line buffering disabled */
noecho(); /* Stop printing junk, bro! */
keypad(stdscr, TRUE); /* We get to press ALL the keys!! */
printw("Type any character to see it nice 'n' thick...\n");
ch = getch();
if (ch == KEY_F(2))
printw("F2 Key was pressed, dawg.");
else {
printw("You pressed: ");
attron(A_BOLD);
printw("%c", ch);
attroff(A_BOLD);
}
// Display, wait, and end:
refresh(); /* Print it on to the real screen */
getch(); /* Wait for user input */
endwin(); /* End curses mode */
return 0;
}
|
the_stack_data/145452122.c | //Remove “b” and “ac” from a given string in single pass
#include<stdio.h>
int main()
{
int i=0,j=0,flag=0;
char str[100];
gets(str);
while(str[i]!='\0')
{
flag=0;
if(str[i]=='b')
{
j++;
flag=1;
i++;
}
if(str[i]=='a')
{
if(str[i+1]=='c')
{
flag=1;
j=j+2;
i=i+2;
}
}
if(flag==0){
printf("%c",str[j]);
j++;
i++;
}
}
return 0;
}
|
the_stack_data/211081922.c | /* { dg-do compile } */
/* { dg-options "-O -fstrict-aliasing -fno-tree-sra -fdump-tree-fre1-details" } */
/* Should be optimized, propagating &a into (*p)[i]. */
/* For this testcase we need TBAA to work. */
struct Foo
{
void *data;
int size;
};
void foo(double (*q)[4], struct Foo *tmp1)
{
double a[4];
int i;
tmp1->data = &a;
tmp1->size = 4;
for (i=0; i<4; ++i)
{
double (*p)[4] = tmp1->data;
(*p)[i] = (*q)[i];
}
}
/* { dg-final { scan-tree-dump "Replaced tmp1_.\\\(D\\\)->data with &a" "fre1" } } */
|
the_stack_data/150889.c | #include <stdio.h>
int main()
{
char input[1001];
fgets (input, 1001, stdin);
int frequencies[26] = {0};
for(int i = 0; input[i]; i++)
{
if(input[i] >= 'A' && input[i] <= 'Z')
{
frequencies[input[i] - 'A']++;
}
if(input[i] >= 'a' && input[i] <= 'z')
{
frequencies[input[i] - 'a']++;
}
}
for(int i = 0; i < 26; i++)
{
if(frequencies[i] > 0)
{
printf("%c - %d\n", 'a' + i, frequencies[i]);
}
}
return 0;
}
|
the_stack_data/139143.c | #include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
static int globval = 7;
static char buf[] = "hello world\n";
int main(void) {
int val = 88;
pid_t pid;
if ((write(STDOUT_FILENO, buf, strlen(buf))) != strlen(buf)) {
puts("error in write");
exit(1);
}
printf("before fork\n");
if ((pid = fork()) < 0) {
puts("error in fork");
exit(1);
} else if (pid == 0) {
// child process will copy the address space, so it will not change the value in parent process.
globval++;
val++;
} else if (pid > 0) {
// do nothing.
sleep(2);
}
printf("pid: %d, globval: %d, val: %d\n", getpid(), globval, val);
exit(0);
} |
the_stack_data/257422.c | // RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11
void foo() __attribute__((xray_always_instrument));
struct __attribute__((xray_always_instrument)) a { int x; }; // expected-warning {{'xray_always_instrument' attribute only applies to functions and methods}}
void bar() __attribute__((xray_always_instrument("not-supported"))); // expected-error {{'xray_always_instrument' attribute takes no arguments}}
|
the_stack_data/76700804.c |
#include <yaml.h>
#include <stdlib.h>
#include <stdio.h>
int
main(int argc, char *argv[])
{
int help = 0;
int canonical = 0;
int unicode = 0;
int k;
int done = 0;
yaml_parser_t parser;
yaml_emitter_t emitter;
yaml_event_t input_event;
yaml_document_t output_document;
int root;
/* Clear the objects. */
memset(&parser, 0, sizeof(parser));
memset(&emitter, 0, sizeof(emitter));
memset(&input_event, 0, sizeof(input_event));
memset(&output_document, 0, sizeof(output_document));
/* Analyze command line options. */
for (k = 1; k < argc; k ++)
{
if (strcmp(argv[k], "-h") == 0
|| strcmp(argv[k], "--help") == 0) {
help = 1;
}
else if (strcmp(argv[k], "-c") == 0
|| strcmp(argv[k], "--canonical") == 0) {
canonical = 1;
}
else if (strcmp(argv[k], "-u") == 0
|| strcmp(argv[k], "--unicode") == 0) {
unicode = 1;
}
else {
fprintf(stderr, "Unrecognized option: %s\n"
"Try `%s --help` for more information.\n",
argv[k], argv[0]);
return 1;
}
}
/* Display the help string. */
if (help)
{
printf("%s <input\n"
"or\n%s -h | --help\nDeconstruct a YAML stream\n\nOptions:\n"
"-h, --help\t\tdisplay this help and exit\n"
"-c, --canonical\t\toutput in the canonical YAML format\n"
"-u, --unicode\t\toutput unescaped non-ASCII characters\n",
argv[0], argv[0]);
return 0;
}
/* Initialize the parser and emitter objects. */
if (!yaml_parser_initialize(&parser)) {
fprintf(stderr, "Could not initialize the parser object\n");
return 1;
}
if (!yaml_emitter_initialize(&emitter)) {
yaml_parser_delete(&parser);
fprintf(stderr, "Could not inialize the emitter object\n");
return 1;
}
/* Set the parser parameters. */
yaml_parser_set_input_file(&parser, stdin);
/* Set the emitter parameters. */
yaml_emitter_set_output_file(&emitter, stdout);
yaml_emitter_set_canonical(&emitter, canonical);
yaml_emitter_set_unicode(&emitter, unicode);
/* Create and emit the STREAM-START event. */
if (!yaml_emitter_open(&emitter))
goto emitter_error;
/* Create a output_document object. */
if (!yaml_document_initialize(&output_document, NULL, NULL, NULL, 0, 0))
goto document_error;
/* Create the root sequence. */
root = yaml_document_add_sequence(&output_document, NULL,
YAML_BLOCK_SEQUENCE_STYLE);
if (!root) goto document_error;
/* Loop through the input events. */
while (!done)
{
int properties, key, value, map, seq;
/* Get the next event. */
if (!yaml_parser_parse(&parser, &input_event))
goto parser_error;
/* Check if this is the stream end. */
if (input_event.type == YAML_STREAM_END_EVENT) {
done = 1;
}
/* Create a mapping node and attach it to the root sequence. */
properties = yaml_document_add_mapping(&output_document, NULL,
YAML_BLOCK_MAPPING_STYLE);
if (!properties) goto document_error;
if (!yaml_document_append_sequence_item(&output_document,
root, properties)) goto document_error;
/* Analyze the event. */
switch (input_event.type)
{
case YAML_STREAM_START_EVENT:
/* Add 'type': 'STREAM-START'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"STREAM-START", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Add 'encoding': <encoding>. */
if (input_event.data.stream_start.encoding)
{
yaml_encoding_t encoding
= input_event.data.stream_start.encoding;
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"encoding", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)(encoding == YAML_UTF8_ENCODING ? "utf-8" :
encoding == YAML_UTF16LE_ENCODING ? "utf-16-le" :
encoding == YAML_UTF16BE_ENCODING ? "utf-16-be" :
"unknown"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
break;
case YAML_STREAM_END_EVENT:
/* Add 'type': 'STREAM-END'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"STREAM-END", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
break;
case YAML_DOCUMENT_START_EVENT:
/* Add 'type': 'DOCUMENT-START'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"DOCUMENT-START", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Display the output_document version numbers. */
if (input_event.data.document_start.version_directive)
{
yaml_version_directive_t *version
= input_event.data.document_start.version_directive;
char number[64];
/* Add 'version': {}. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"version", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
map = yaml_document_add_mapping(&output_document, NULL,
YAML_FLOW_MAPPING_STYLE);
if (!map) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, map)) goto document_error;
/* Add 'major': <number>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"major", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
sprintf(number, "%d", version->major);
value = yaml_document_add_scalar(&output_document, (yaml_char_t *)YAML_INT_TAG,
(yaml_char_t *)number, -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
map, key, value)) goto document_error;
/* Add 'minor': <number>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"minor", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
sprintf(number, "%d", version->minor);
value = yaml_document_add_scalar(&output_document, (yaml_char_t *)YAML_INT_TAG,
(yaml_char_t *)number, -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
map, key, value)) goto document_error;
}
/* Display the output_document tag directives. */
if (input_event.data.document_start.tag_directives.start
!= input_event.data.document_start.tag_directives.end)
{
yaml_tag_directive_t *tag;
/* Add 'tags': []. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"tags", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
seq = yaml_document_add_sequence(&output_document, NULL,
YAML_BLOCK_SEQUENCE_STYLE);
if (!seq) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, seq)) goto document_error;
for (tag = input_event.data.document_start.tag_directives.start;
tag != input_event.data.document_start.tag_directives.end;
tag ++)
{
/* Add {}. */
map = yaml_document_add_mapping(&output_document, NULL,
YAML_FLOW_MAPPING_STYLE);
if (!map) goto document_error;
if (!yaml_document_append_sequence_item(&output_document,
seq, map)) goto document_error;
/* Add 'handle': <handle>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"handle", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
tag->handle, -1, YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
map, key, value)) goto document_error;
/* Add 'prefix': <prefix>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"prefix", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
tag->prefix, -1, YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
map, key, value)) goto document_error;
}
}
/* Add 'implicit': <flag>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"implicit", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, (yaml_char_t *)YAML_BOOL_TAG,
(yaml_char_t *)(input_event.data.document_start.implicit ?
"true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
break;
case YAML_DOCUMENT_END_EVENT:
/* Add 'type': 'DOCUMENT-END'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"DOCUMENT-END", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Add 'implicit': <flag>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"implicit", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, (yaml_char_t *)YAML_BOOL_TAG,
(yaml_char_t *)(input_event.data.document_end.implicit ?
"true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
break;
case YAML_ALIAS_EVENT:
/* Add 'type': 'ALIAS'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"ALIAS", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Add 'anchor': <anchor>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"anchor", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
input_event.data.alias.anchor, -1,
YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
break;
case YAML_SCALAR_EVENT:
/* Add 'type': 'SCALAR'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"SCALAR", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Add 'anchor': <anchor>. */
if (input_event.data.scalar.anchor)
{
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"anchor", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
input_event.data.scalar.anchor, -1,
YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
/* Add 'tag': <tag>. */
if (input_event.data.scalar.tag)
{
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"tag", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
input_event.data.scalar.tag, -1,
YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
/* Add 'value': <value>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"value", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
input_event.data.scalar.value,
input_event.data.scalar.length,
YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Display if the scalar tag is implicit. */
/* Add 'implicit': {} */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"version", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
map = yaml_document_add_mapping(&output_document, NULL,
YAML_FLOW_MAPPING_STYLE);
if (!map) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, map)) goto document_error;
/* Add 'plain': <flag>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"plain", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, (yaml_char_t *)YAML_BOOL_TAG,
(yaml_char_t *)(input_event.data.scalar.plain_implicit ?
"true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
map, key, value)) goto document_error;
/* Add 'quoted': <flag>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"quoted", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, (yaml_char_t *)YAML_BOOL_TAG,
(yaml_char_t *)(input_event.data.scalar.quoted_implicit ?
"true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
map, key, value)) goto document_error;
/* Display the style information. */
if (input_event.data.scalar.style)
{
yaml_scalar_style_t style = input_event.data.scalar.style;
/* Add 'style': <style>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"style", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)(style == YAML_PLAIN_SCALAR_STYLE ? "plain" :
style == YAML_SINGLE_QUOTED_SCALAR_STYLE ?
"single-quoted" :
style == YAML_DOUBLE_QUOTED_SCALAR_STYLE ?
"double-quoted" :
style == YAML_LITERAL_SCALAR_STYLE ? "literal" :
style == YAML_FOLDED_SCALAR_STYLE ? "folded" :
"unknown"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
break;
case YAML_SEQUENCE_START_EVENT:
/* Add 'type': 'SEQUENCE-START'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"SEQUENCE-START", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Add 'anchor': <anchor>. */
if (input_event.data.sequence_start.anchor)
{
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"anchor", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
input_event.data.sequence_start.anchor, -1,
YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
/* Add 'tag': <tag>. */
if (input_event.data.sequence_start.tag)
{
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"tag", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
input_event.data.sequence_start.tag, -1,
YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
/* Add 'implicit': <flag>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"implicit", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, (yaml_char_t *)YAML_BOOL_TAG,
(yaml_char_t *)(input_event.data.sequence_start.implicit ?
"true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Display the style information. */
if (input_event.data.sequence_start.style)
{
yaml_sequence_style_t style
= input_event.data.sequence_start.style;
/* Add 'style': <style>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"style", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)(style == YAML_BLOCK_SEQUENCE_STYLE ? "block" :
style == YAML_FLOW_SEQUENCE_STYLE ? "flow" :
"unknown"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
break;
case YAML_SEQUENCE_END_EVENT:
/* Add 'type': 'SEQUENCE-END'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"SEQUENCE-END", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
break;
case YAML_MAPPING_START_EVENT:
/* Add 'type': 'MAPPING-START'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"MAPPING-START", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Add 'anchor': <anchor>. */
if (input_event.data.mapping_start.anchor)
{
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"anchor", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
input_event.data.mapping_start.anchor, -1,
YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
/* Add 'tag': <tag>. */
if (input_event.data.mapping_start.tag)
{
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"tag", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
input_event.data.mapping_start.tag, -1,
YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
/* Add 'implicit': <flag>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"implicit", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, (yaml_char_t *)YAML_BOOL_TAG,
(yaml_char_t *)(input_event.data.mapping_start.implicit ?
"true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Display the style information. */
if (input_event.data.sequence_start.style)
{
yaml_sequence_style_t style
= (yaml_sequence_style_t) input_event.data.mapping_start.style;
/* Add 'style': <style>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"style", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)(style == YAML_BLOCK_MAPPING_STYLE ? "block" :
style == YAML_FLOW_MAPPING_STYLE ? "flow" :
"unknown"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
break;
case YAML_MAPPING_END_EVENT:
/* Add 'type': 'MAPPING-END'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"MAPPING-END", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
break;
default:
/* It couldn't really happen. */
break;
}
/* Delete the event object. */
yaml_event_delete(&input_event);
}
if (!yaml_emitter_dump(&emitter, &output_document))
goto emitter_error;
if (!yaml_emitter_close(&emitter))
goto emitter_error;
yaml_parser_delete(&parser);
yaml_emitter_delete(&emitter);
return 0;
parser_error:
/* Display a parser error message. */
switch (parser.error)
{
case YAML_MEMORY_ERROR:
fprintf(stderr, "Memory error: Not enough memory for parsing\n");
break;
case YAML_READER_ERROR:
if (parser.problem_value != -1) {
fprintf(stderr, "Reader error: %s: #%X at %zd\n", parser.problem,
parser.problem_value, parser.problem_offset);
}
else {
fprintf(stderr, "Reader error: %s at %zd\n", parser.problem,
parser.problem_offset);
}
break;
case YAML_SCANNER_ERROR:
if (parser.context) {
fprintf(stderr, "Scanner error: %s at line %lu, column %lu\n"
"%s at line %lu, column %lu\n", parser.context,
parser.context_mark.line+1, parser.context_mark.column+1,
parser.problem, parser.problem_mark.line+1,
parser.problem_mark.column+1);
}
else {
fprintf(stderr, "Scanner error: %s at line %lu, column %lu\n",
parser.problem, parser.problem_mark.line+1,
parser.problem_mark.column+1);
}
break;
case YAML_PARSER_ERROR:
if (parser.context) {
fprintf(stderr, "Parser error: %s at line %lu, column %lu\n"
"%s at line %lu, column %lu\n", parser.context,
parser.context_mark.line+1, parser.context_mark.column+1,
parser.problem, parser.problem_mark.line+1,
parser.problem_mark.column+1);
}
else {
fprintf(stderr, "Parser error: %s at line %lu, column %lu\n",
parser.problem, parser.problem_mark.line+1,
parser.problem_mark.column+1);
}
break;
default:
/* Couldn't happen. */
fprintf(stderr, "Internal error\n");
break;
}
yaml_event_delete(&input_event);
yaml_document_delete(&output_document);
yaml_parser_delete(&parser);
yaml_emitter_delete(&emitter);
return 1;
emitter_error:
/* Display an emitter error message. */
switch (emitter.error)
{
case YAML_MEMORY_ERROR:
fprintf(stderr, "Memory error: Not enough memory for emitting\n");
break;
case YAML_WRITER_ERROR:
fprintf(stderr, "Writer error: %s\n", emitter.problem);
break;
case YAML_EMITTER_ERROR:
fprintf(stderr, "Emitter error: %s\n", emitter.problem);
break;
default:
/* Couldn't happen. */
fprintf(stderr, "Internal error\n");
break;
}
yaml_event_delete(&input_event);
yaml_document_delete(&output_document);
yaml_parser_delete(&parser);
yaml_emitter_delete(&emitter);
return 1;
document_error:
fprintf(stderr, "Memory error: Not enough memory for creating a document\n");
yaml_event_delete(&input_event);
yaml_document_delete(&output_document);
yaml_parser_delete(&parser);
yaml_emitter_delete(&emitter);
return 1;
}
|
the_stack_data/290622.c | #include <stdio.h>
#include <stdlib.h>
//Thiago da Silva Ferreira
//Calcular fatorial
int main(void) {
int num,cont=1, fat=1;
printf("Digite um numero para calcular o fatorial:");
scanf("%d", &num);
for(cont=1; cont<=num; cont++){
fat=fat*cont;
}
printf("Fatorial de %d e %d", num , fat);
return 0;
}
|
the_stack_data/28263490.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 int input[1] , unsigned int 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 int input[1] ;
unsigned int output[1] ;
int randomFuns_i5 ;
unsigned int 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 int )strtoul(argv[randomFuns_i5 + 1], 0, 10);
input[randomFuns_i5] = randomFuns_value6;
randomFuns_i5 ++;
}
RandomFunc(input, output);
if (output[0] == 1796140976U) {
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 int input[1] , unsigned int output[1] )
{
unsigned int state[1] ;
unsigned int local2 ;
unsigned int local1 ;
char copy11 ;
{
state[0UL] = input[0UL] + 1373777115U;
local1 = 0UL;
while (local1 < 0U) {
local2 = 0UL;
while (local2 < 0U) {
if (state[0UL] <= (local2 | local1)) {
copy11 = *((char *)(& state[local1]) + 1);
*((char *)(& state[local1]) + 1) = *((char *)(& state[local1]) + 2);
*((char *)(& state[local1]) + 2) = copy11;
state[local2] |= (((state[local1] << (((state[local2] >> 3U) & 15U) | 1UL)) | (state[local1] >> (32 - (((state[local2] >> 3U) & 15U) | 1UL)))) & 15U) << 2UL;
} else {
state[local1] |= (state[0UL] & 63U) << 4UL;
}
local2 ++;
}
local1 ++;
}
output[0UL] = (state[0UL] << 1U) * 1578328702U;
}
}
|
the_stack_data/14200744.c |
#include <stdio.h>
union TOGETHER {
char cmd[16];
unsigned int words[4];
} a;
int main(void)
{
a.cmd[0] = 0x1;
a.cmd[1] = 0x2;
a.cmd[2] = 0x3;
a.cmd[3] = 0x4;
a.cmd[4] = 0x5;
a.cmd[5] = 0x6;
a.cmd[6] = 0x7;
a.cmd[7] = 0x8;
a.cmd[8] = 0x9;
a.cmd[9] = 0xa;
a.cmd[10] = 0xb;
a.cmd[11] = 0xc;
a.cmd[12] = 0xd;
a.cmd[13] = 0xe;
a.cmd[14] = 0xf;
a.cmd[15] = 0xff;
fprintf(stderr, "words[0]=%#x, words[1]=%#x, words[2]=%#x, words[3]=%#x\n", a.words[0], a.words[1], a.words[2], a.words[3]);
exit(0);
}
|
the_stack_data/111613.c | #include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char** argv){
int rfd, wfd, n;
char buf[10];
mode_t mode;
if(argc!=3){
printf("usage : ./mycp src dest");
exit(1);
}
rfd = open(argv[1], O_RDONLY);
if(rfd == -1){
perror("Open src file");
exit(1);
}
wfd = open(argv[2], O_CREAT | O_WRONLY | O_TRUNC, 0644);
if(wfd==-1){
perror("Open dest file");
exit(1);
}
while((n = read(rfd, buf, 6)) > 0){
if(write(wfd, buf, n)!=n)
perror("Write");
if(n==-1) perror("read");
}
close(rfd);
close(wfd);
return 0;
}
|
the_stack_data/199917.c | #include<stdio.h>
#include<stdlib.h>
int comp(const void*a,const void*b)
{
return *(int*)b-*(int*)a;
}
int main()
{
int n, l;
scanf("%d", &n);
int a[n + 1];
int c;
int b[100000 + 1];
int j;
for (int w = 0;w <= 100000;w++)
{
b[w] = 0;
}
int tmp = 0;
j=0;
for(int i = 1; i <= n;i++)
{
scanf("%d", &c);
b[c]++;
if (b[c] == 1)
{
a[j] = c;
j++;
}
}
qsort(a, j, sizeof(int), comp);
scanf("%d", &l);
printf("%d %d\n", a[l-1], b[a[l - 1]]);
return 0;
} |
the_stack_data/215766851.c | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI_E pow(M_PI, M_E)
#define E_PI pow(M_E, M_PI)
/**
* An approximated value for both is 27, because both numbers are
* near 3: e ~ 3, pi ~ 3 => p^e ~ 3^3 = 27, e^pi ~ 3^3 = 27.
*
* Calculating...
* pi^e = 22.459157718361041
* e^pi = 23.140692632779263
*/
int main()
{
printf("\n\te = %1.15lf\n", M_E);
printf("\tpi = %1.15lf\n", M_PI);
printf("\n\tpi^e = %1.15lf\n", PI_E);
printf("\te^pi = %1.15lf\n\n", E_PI);
return EXIT_SUCCESS;
}
|
the_stack_data/136155.c | int main(void) {
int count = 0;
label: ;
int x;
int y = 1;
static int z;
if (count < 1){
count++;
goto label;
}
return 0;
}
|
the_stack_data/103265677.c | #include <math.h>
float remainderf(float x, float y)
{
int q;
return remquof(x, y, &q);
}
|
the_stack_data/212644241.c | #include <stdio.h>
int add_numbers(int a, int b); //Fowrward declaration
int main(int argc, char *argv[])
{
//Varialbles declarations
int result;
//Pointer declarations
int (*myFunction_ptr)(int, int);
myFunction_ptr = &add_numbers;
result = myFunction_ptr(3,7);
printf("result = %d\n", result);
return 0;
}
int add_numbers(int a, int b)
{
int sum;
sum = a + b;
return sum;
}
|
the_stack_data/36075158.c |
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/timeb.h>
#include <dirent.h>
#include <time.h>
#include <libgen.h>
int main(int argc, char const *argv[])
{
/* code */
/*
char path[30] = "./site1/page1_100.html";
char *dname = dirname(path);
char *bname = basename(dname);
printf("dname == '%s'\n", bname);*/
char searchBuffer[20];
printf("sizeof of searchBuffer before memset == %ld\n", sizeof(searchBuffer));
memset(searchBuffer, '\0', sizeof(searchBuffer));
printf("sizeof of searchBuffer after memset == %ld\n", sizeof(searchBuffer));
return 0;
} |
the_stack_data/28262718.c | #include <stdio.h>
void logop(int i) {
printf("computed: %i\n", i);
} |
the_stack_data/150144246.c | /*
*利用枚举和localtime实现
* 获取当前的日期(0-6),通过和枚举类型进行比较,得出当天休息或工作
* struct tm*localtime(const time_t *timer)
* 函数返回指向tm结构的指针,struct tm结构包含t_wday,用0-6表示一周。
*/
#include<stdio.h>
#include <time.h>
int main(void)
{
enum Week{sun, mon, tue, wed, thu, fri, sat};
enum Week day;
time_t t;
struct tm* w = localtime(&t) ;
day = w->tm_wday;
switch(day){
case mon:
case tue:
case wed:
case thu:
case fri: printf("work day T_T\n");break;
case sat:
case sun: printf("holiday ^_^\n"); break;
default:break;
}
return 0;
}
|
the_stack_data/125139470.c | extern float __VERIFIER_nondet_float(void);
extern int __VERIFIER_nondet_int(void);
typedef enum {false, true} bool;
bool __VERIFIER_nondet_bool(void) {
return __VERIFIER_nondet_int() != 0;
}
int main()
{
bool _J2420, _x__J2420;
bool _J2413, _x__J2413;
float x_1, _x_x_1;
bool _EL_U_2391, _x__EL_U_2391;
float x_24, _x_x_24;
float x_27, _x_x_27;
float x_12, _x_x_12;
float x_19, _x_x_19;
float x_5, _x_x_5;
float x_8, _x_x_8;
bool _EL_U_2393, _x__EL_U_2393;
float x_20, _x_x_20;
float x_13, _x_x_13;
float x_3, _x_x_3;
float x_0, _x_x_0;
float x_21, _x_x_21;
float x_6, _x_x_6;
float x_22, _x_x_22;
float x_7, _x_x_7;
float x_9, _x_x_9;
float x_10, _x_x_10;
float x_14, _x_x_14;
float x_25, _x_x_25;
float x_15, _x_x_15;
float x_17, _x_x_17;
float x_18, _x_x_18;
float x_2, _x_x_2;
float x_23, _x_x_23;
float x_26, _x_x_26;
float x_4, _x_x_4;
float x_11, _x_x_11;
float x_16, _x_x_16;
int __steps_to_fair = __VERIFIER_nondet_int();
_J2420 = __VERIFIER_nondet_bool();
_J2413 = __VERIFIER_nondet_bool();
x_1 = __VERIFIER_nondet_float();
_EL_U_2391 = __VERIFIER_nondet_bool();
x_24 = __VERIFIER_nondet_float();
x_27 = __VERIFIER_nondet_float();
x_12 = __VERIFIER_nondet_float();
x_19 = __VERIFIER_nondet_float();
x_5 = __VERIFIER_nondet_float();
x_8 = __VERIFIER_nondet_float();
_EL_U_2393 = __VERIFIER_nondet_bool();
x_20 = __VERIFIER_nondet_float();
x_13 = __VERIFIER_nondet_float();
x_3 = __VERIFIER_nondet_float();
x_0 = __VERIFIER_nondet_float();
x_21 = __VERIFIER_nondet_float();
x_6 = __VERIFIER_nondet_float();
x_22 = __VERIFIER_nondet_float();
x_7 = __VERIFIER_nondet_float();
x_9 = __VERIFIER_nondet_float();
x_10 = __VERIFIER_nondet_float();
x_14 = __VERIFIER_nondet_float();
x_25 = __VERIFIER_nondet_float();
x_15 = __VERIFIER_nondet_float();
x_17 = __VERIFIER_nondet_float();
x_18 = __VERIFIER_nondet_float();
x_2 = __VERIFIER_nondet_float();
x_23 = __VERIFIER_nondet_float();
x_26 = __VERIFIER_nondet_float();
x_4 = __VERIFIER_nondet_float();
x_11 = __VERIFIER_nondet_float();
x_16 = __VERIFIER_nondet_float();
bool __ok = (1 && (((( !(-3.0 <= (x_12 + (-1.0 * x_24)))) || (_EL_U_2393 && (( !(3.0 <= (x_5 + (-1.0 * x_19)))) || (( !(-3.0 <= (x_12 + (-1.0 * x_24)))) && _EL_U_2391)))) && ( !_J2413)) && ( !_J2420)));
while (__steps_to_fair >= 0 && __ok) {
if ((_J2413 && _J2420)) {
__steps_to_fair = __VERIFIER_nondet_int();
} else {
__steps_to_fair--;
}
_x__J2420 = __VERIFIER_nondet_bool();
_x__J2413 = __VERIFIER_nondet_bool();
_x_x_1 = __VERIFIER_nondet_float();
_x__EL_U_2391 = __VERIFIER_nondet_bool();
_x_x_24 = __VERIFIER_nondet_float();
_x_x_27 = __VERIFIER_nondet_float();
_x_x_12 = __VERIFIER_nondet_float();
_x_x_19 = __VERIFIER_nondet_float();
_x_x_5 = __VERIFIER_nondet_float();
_x_x_8 = __VERIFIER_nondet_float();
_x__EL_U_2393 = __VERIFIER_nondet_bool();
_x_x_20 = __VERIFIER_nondet_float();
_x_x_13 = __VERIFIER_nondet_float();
_x_x_3 = __VERIFIER_nondet_float();
_x_x_0 = __VERIFIER_nondet_float();
_x_x_21 = __VERIFIER_nondet_float();
_x_x_6 = __VERIFIER_nondet_float();
_x_x_22 = __VERIFIER_nondet_float();
_x_x_7 = __VERIFIER_nondet_float();
_x_x_9 = __VERIFIER_nondet_float();
_x_x_10 = __VERIFIER_nondet_float();
_x_x_14 = __VERIFIER_nondet_float();
_x_x_25 = __VERIFIER_nondet_float();
_x_x_15 = __VERIFIER_nondet_float();
_x_x_17 = __VERIFIER_nondet_float();
_x_x_18 = __VERIFIER_nondet_float();
_x_x_2 = __VERIFIER_nondet_float();
_x_x_23 = __VERIFIER_nondet_float();
_x_x_26 = __VERIFIER_nondet_float();
_x_x_4 = __VERIFIER_nondet_float();
_x_x_11 = __VERIFIER_nondet_float();
_x_x_16 = __VERIFIER_nondet_float();
__ok = ((((((((((((((((((((((((((((((((x_27 + (-1.0 * _x_x_0)) <= -5.0) && (((x_26 + (-1.0 * _x_x_0)) <= -11.0) && (((x_22 + (-1.0 * _x_x_0)) <= -17.0) && (((x_19 + (-1.0 * _x_x_0)) <= -17.0) && (((x_16 + (-1.0 * _x_x_0)) <= -13.0) && (((x_13 + (-1.0 * _x_x_0)) <= -19.0) && (((x_9 + (-1.0 * _x_x_0)) <= -10.0) && (((x_8 + (-1.0 * _x_x_0)) <= -9.0) && (((x_6 + (-1.0 * _x_x_0)) <= -13.0) && (((x_5 + (-1.0 * _x_x_0)) <= -12.0) && (((x_4 + (-1.0 * _x_x_0)) <= -1.0) && (((x_2 + (-1.0 * _x_x_0)) <= -5.0) && (((x_0 + (-1.0 * _x_x_0)) <= -14.0) && ((x_1 + (-1.0 * _x_x_0)) <= -20.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_0)) == -5.0) || (((x_26 + (-1.0 * _x_x_0)) == -11.0) || (((x_22 + (-1.0 * _x_x_0)) == -17.0) || (((x_19 + (-1.0 * _x_x_0)) == -17.0) || (((x_16 + (-1.0 * _x_x_0)) == -13.0) || (((x_13 + (-1.0 * _x_x_0)) == -19.0) || (((x_9 + (-1.0 * _x_x_0)) == -10.0) || (((x_8 + (-1.0 * _x_x_0)) == -9.0) || (((x_6 + (-1.0 * _x_x_0)) == -13.0) || (((x_5 + (-1.0 * _x_x_0)) == -12.0) || (((x_4 + (-1.0 * _x_x_0)) == -1.0) || (((x_2 + (-1.0 * _x_x_0)) == -5.0) || (((x_0 + (-1.0 * _x_x_0)) == -14.0) || ((x_1 + (-1.0 * _x_x_0)) == -20.0))))))))))))))) && ((((x_25 + (-1.0 * _x_x_1)) <= -11.0) && (((x_24 + (-1.0 * _x_x_1)) <= -13.0) && (((x_23 + (-1.0 * _x_x_1)) <= -2.0) && (((x_19 + (-1.0 * _x_x_1)) <= -18.0) && (((x_15 + (-1.0 * _x_x_1)) <= -16.0) && (((x_14 + (-1.0 * _x_x_1)) <= -15.0) && (((x_13 + (-1.0 * _x_x_1)) <= -16.0) && (((x_12 + (-1.0 * _x_x_1)) <= -6.0) && (((x_11 + (-1.0 * _x_x_1)) <= -15.0) && (((x_7 + (-1.0 * _x_x_1)) <= -4.0) && (((x_5 + (-1.0 * _x_x_1)) <= -10.0) && (((x_4 + (-1.0 * _x_x_1)) <= -11.0) && (((x_1 + (-1.0 * _x_x_1)) <= -8.0) && ((x_2 + (-1.0 * _x_x_1)) <= -4.0)))))))))))))) && (((x_25 + (-1.0 * _x_x_1)) == -11.0) || (((x_24 + (-1.0 * _x_x_1)) == -13.0) || (((x_23 + (-1.0 * _x_x_1)) == -2.0) || (((x_19 + (-1.0 * _x_x_1)) == -18.0) || (((x_15 + (-1.0 * _x_x_1)) == -16.0) || (((x_14 + (-1.0 * _x_x_1)) == -15.0) || (((x_13 + (-1.0 * _x_x_1)) == -16.0) || (((x_12 + (-1.0 * _x_x_1)) == -6.0) || (((x_11 + (-1.0 * _x_x_1)) == -15.0) || (((x_7 + (-1.0 * _x_x_1)) == -4.0) || (((x_5 + (-1.0 * _x_x_1)) == -10.0) || (((x_4 + (-1.0 * _x_x_1)) == -11.0) || (((x_1 + (-1.0 * _x_x_1)) == -8.0) || ((x_2 + (-1.0 * _x_x_1)) == -4.0)))))))))))))))) && ((((x_25 + (-1.0 * _x_x_2)) <= -13.0) && (((x_23 + (-1.0 * _x_x_2)) <= -6.0) && (((x_21 + (-1.0 * _x_x_2)) <= -11.0) && (((x_20 + (-1.0 * _x_x_2)) <= -9.0) && (((x_19 + (-1.0 * _x_x_2)) <= -14.0) && (((x_16 + (-1.0 * _x_x_2)) <= -7.0) && (((x_14 + (-1.0 * _x_x_2)) <= -1.0) && (((x_12 + (-1.0 * _x_x_2)) <= -1.0) && (((x_11 + (-1.0 * _x_x_2)) <= -14.0) && (((x_10 + (-1.0 * _x_x_2)) <= -6.0) && (((x_5 + (-1.0 * _x_x_2)) <= -12.0) && (((x_4 + (-1.0 * _x_x_2)) <= -16.0) && (((x_1 + (-1.0 * _x_x_2)) <= -13.0) && ((x_3 + (-1.0 * _x_x_2)) <= -4.0)))))))))))))) && (((x_25 + (-1.0 * _x_x_2)) == -13.0) || (((x_23 + (-1.0 * _x_x_2)) == -6.0) || (((x_21 + (-1.0 * _x_x_2)) == -11.0) || (((x_20 + (-1.0 * _x_x_2)) == -9.0) || (((x_19 + (-1.0 * _x_x_2)) == -14.0) || (((x_16 + (-1.0 * _x_x_2)) == -7.0) || (((x_14 + (-1.0 * _x_x_2)) == -1.0) || (((x_12 + (-1.0 * _x_x_2)) == -1.0) || (((x_11 + (-1.0 * _x_x_2)) == -14.0) || (((x_10 + (-1.0 * _x_x_2)) == -6.0) || (((x_5 + (-1.0 * _x_x_2)) == -12.0) || (((x_4 + (-1.0 * _x_x_2)) == -16.0) || (((x_1 + (-1.0 * _x_x_2)) == -13.0) || ((x_3 + (-1.0 * _x_x_2)) == -4.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_3)) <= -3.0) && (((x_26 + (-1.0 * _x_x_3)) <= -7.0) && (((x_23 + (-1.0 * _x_x_3)) <= -8.0) && (((x_21 + (-1.0 * _x_x_3)) <= -3.0) && (((x_20 + (-1.0 * _x_x_3)) <= -13.0) && (((x_18 + (-1.0 * _x_x_3)) <= -2.0) && (((x_16 + (-1.0 * _x_x_3)) <= -6.0) && (((x_15 + (-1.0 * _x_x_3)) <= -11.0) && (((x_13 + (-1.0 * _x_x_3)) <= -17.0) && (((x_11 + (-1.0 * _x_x_3)) <= -18.0) && (((x_10 + (-1.0 * _x_x_3)) <= -18.0) && (((x_8 + (-1.0 * _x_x_3)) <= -18.0) && (((x_3 + (-1.0 * _x_x_3)) <= -5.0) && ((x_5 + (-1.0 * _x_x_3)) <= -12.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_3)) == -3.0) || (((x_26 + (-1.0 * _x_x_3)) == -7.0) || (((x_23 + (-1.0 * _x_x_3)) == -8.0) || (((x_21 + (-1.0 * _x_x_3)) == -3.0) || (((x_20 + (-1.0 * _x_x_3)) == -13.0) || (((x_18 + (-1.0 * _x_x_3)) == -2.0) || (((x_16 + (-1.0 * _x_x_3)) == -6.0) || (((x_15 + (-1.0 * _x_x_3)) == -11.0) || (((x_13 + (-1.0 * _x_x_3)) == -17.0) || (((x_11 + (-1.0 * _x_x_3)) == -18.0) || (((x_10 + (-1.0 * _x_x_3)) == -18.0) || (((x_8 + (-1.0 * _x_x_3)) == -18.0) || (((x_3 + (-1.0 * _x_x_3)) == -5.0) || ((x_5 + (-1.0 * _x_x_3)) == -12.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_4)) <= -9.0) && (((x_26 + (-1.0 * _x_x_4)) <= -14.0) && (((x_25 + (-1.0 * _x_x_4)) <= -9.0) && (((x_22 + (-1.0 * _x_x_4)) <= -8.0) && (((x_19 + (-1.0 * _x_x_4)) <= -3.0) && (((x_18 + (-1.0 * _x_x_4)) <= -14.0) && (((x_14 + (-1.0 * _x_x_4)) <= -4.0) && (((x_13 + (-1.0 * _x_x_4)) <= -15.0) && (((x_10 + (-1.0 * _x_x_4)) <= -14.0) && (((x_9 + (-1.0 * _x_x_4)) <= -8.0) && (((x_8 + (-1.0 * _x_x_4)) <= -10.0) && (((x_7 + (-1.0 * _x_x_4)) <= -5.0) && (((x_0 + (-1.0 * _x_x_4)) <= -16.0) && ((x_5 + (-1.0 * _x_x_4)) <= -8.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_4)) == -9.0) || (((x_26 + (-1.0 * _x_x_4)) == -14.0) || (((x_25 + (-1.0 * _x_x_4)) == -9.0) || (((x_22 + (-1.0 * _x_x_4)) == -8.0) || (((x_19 + (-1.0 * _x_x_4)) == -3.0) || (((x_18 + (-1.0 * _x_x_4)) == -14.0) || (((x_14 + (-1.0 * _x_x_4)) == -4.0) || (((x_13 + (-1.0 * _x_x_4)) == -15.0) || (((x_10 + (-1.0 * _x_x_4)) == -14.0) || (((x_9 + (-1.0 * _x_x_4)) == -8.0) || (((x_8 + (-1.0 * _x_x_4)) == -10.0) || (((x_7 + (-1.0 * _x_x_4)) == -5.0) || (((x_0 + (-1.0 * _x_x_4)) == -16.0) || ((x_5 + (-1.0 * _x_x_4)) == -8.0)))))))))))))))) && ((((x_26 + (-1.0 * _x_x_5)) <= -16.0) && (((x_24 + (-1.0 * _x_x_5)) <= -18.0) && (((x_23 + (-1.0 * _x_x_5)) <= -1.0) && (((x_22 + (-1.0 * _x_x_5)) <= -12.0) && (((x_21 + (-1.0 * _x_x_5)) <= -18.0) && (((x_20 + (-1.0 * _x_x_5)) <= -11.0) && (((x_19 + (-1.0 * _x_x_5)) <= -3.0) && (((x_15 + (-1.0 * _x_x_5)) <= -2.0) && (((x_13 + (-1.0 * _x_x_5)) <= -20.0) && (((x_10 + (-1.0 * _x_x_5)) <= -4.0) && (((x_8 + (-1.0 * _x_x_5)) <= -18.0) && (((x_6 + (-1.0 * _x_x_5)) <= -9.0) && (((x_3 + (-1.0 * _x_x_5)) <= -4.0) && ((x_5 + (-1.0 * _x_x_5)) <= -13.0)))))))))))))) && (((x_26 + (-1.0 * _x_x_5)) == -16.0) || (((x_24 + (-1.0 * _x_x_5)) == -18.0) || (((x_23 + (-1.0 * _x_x_5)) == -1.0) || (((x_22 + (-1.0 * _x_x_5)) == -12.0) || (((x_21 + (-1.0 * _x_x_5)) == -18.0) || (((x_20 + (-1.0 * _x_x_5)) == -11.0) || (((x_19 + (-1.0 * _x_x_5)) == -3.0) || (((x_15 + (-1.0 * _x_x_5)) == -2.0) || (((x_13 + (-1.0 * _x_x_5)) == -20.0) || (((x_10 + (-1.0 * _x_x_5)) == -4.0) || (((x_8 + (-1.0 * _x_x_5)) == -18.0) || (((x_6 + (-1.0 * _x_x_5)) == -9.0) || (((x_3 + (-1.0 * _x_x_5)) == -4.0) || ((x_5 + (-1.0 * _x_x_5)) == -13.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_6)) <= -5.0) && (((x_22 + (-1.0 * _x_x_6)) <= -9.0) && (((x_18 + (-1.0 * _x_x_6)) <= -17.0) && (((x_16 + (-1.0 * _x_x_6)) <= -20.0) && (((x_15 + (-1.0 * _x_x_6)) <= -7.0) && (((x_14 + (-1.0 * _x_x_6)) <= -15.0) && (((x_13 + (-1.0 * _x_x_6)) <= -2.0) && (((x_11 + (-1.0 * _x_x_6)) <= -17.0) && (((x_10 + (-1.0 * _x_x_6)) <= -14.0) && (((x_9 + (-1.0 * _x_x_6)) <= -16.0) && (((x_8 + (-1.0 * _x_x_6)) <= -8.0) && (((x_6 + (-1.0 * _x_x_6)) <= -6.0) && (((x_0 + (-1.0 * _x_x_6)) <= -8.0) && ((x_4 + (-1.0 * _x_x_6)) <= -20.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_6)) == -5.0) || (((x_22 + (-1.0 * _x_x_6)) == -9.0) || (((x_18 + (-1.0 * _x_x_6)) == -17.0) || (((x_16 + (-1.0 * _x_x_6)) == -20.0) || (((x_15 + (-1.0 * _x_x_6)) == -7.0) || (((x_14 + (-1.0 * _x_x_6)) == -15.0) || (((x_13 + (-1.0 * _x_x_6)) == -2.0) || (((x_11 + (-1.0 * _x_x_6)) == -17.0) || (((x_10 + (-1.0 * _x_x_6)) == -14.0) || (((x_9 + (-1.0 * _x_x_6)) == -16.0) || (((x_8 + (-1.0 * _x_x_6)) == -8.0) || (((x_6 + (-1.0 * _x_x_6)) == -6.0) || (((x_0 + (-1.0 * _x_x_6)) == -8.0) || ((x_4 + (-1.0 * _x_x_6)) == -20.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_7)) <= -11.0) && (((x_26 + (-1.0 * _x_x_7)) <= -1.0) && (((x_25 + (-1.0 * _x_x_7)) <= -6.0) && (((x_22 + (-1.0 * _x_x_7)) <= -5.0) && (((x_21 + (-1.0 * _x_x_7)) <= -18.0) && (((x_19 + (-1.0 * _x_x_7)) <= -13.0) && (((x_17 + (-1.0 * _x_x_7)) <= -1.0) && (((x_14 + (-1.0 * _x_x_7)) <= -18.0) && (((x_13 + (-1.0 * _x_x_7)) <= -6.0) && (((x_12 + (-1.0 * _x_x_7)) <= -1.0) && (((x_10 + (-1.0 * _x_x_7)) <= -9.0) && (((x_9 + (-1.0 * _x_x_7)) <= -20.0) && (((x_1 + (-1.0 * _x_x_7)) <= -8.0) && ((x_7 + (-1.0 * _x_x_7)) <= -14.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_7)) == -11.0) || (((x_26 + (-1.0 * _x_x_7)) == -1.0) || (((x_25 + (-1.0 * _x_x_7)) == -6.0) || (((x_22 + (-1.0 * _x_x_7)) == -5.0) || (((x_21 + (-1.0 * _x_x_7)) == -18.0) || (((x_19 + (-1.0 * _x_x_7)) == -13.0) || (((x_17 + (-1.0 * _x_x_7)) == -1.0) || (((x_14 + (-1.0 * _x_x_7)) == -18.0) || (((x_13 + (-1.0 * _x_x_7)) == -6.0) || (((x_12 + (-1.0 * _x_x_7)) == -1.0) || (((x_10 + (-1.0 * _x_x_7)) == -9.0) || (((x_9 + (-1.0 * _x_x_7)) == -20.0) || (((x_1 + (-1.0 * _x_x_7)) == -8.0) || ((x_7 + (-1.0 * _x_x_7)) == -14.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_8)) <= -14.0) && (((x_25 + (-1.0 * _x_x_8)) <= -5.0) && (((x_20 + (-1.0 * _x_x_8)) <= -5.0) && (((x_19 + (-1.0 * _x_x_8)) <= -1.0) && (((x_18 + (-1.0 * _x_x_8)) <= -5.0) && (((x_16 + (-1.0 * _x_x_8)) <= -5.0) && (((x_15 + (-1.0 * _x_x_8)) <= -2.0) && (((x_13 + (-1.0 * _x_x_8)) <= -10.0) && (((x_10 + (-1.0 * _x_x_8)) <= -19.0) && (((x_9 + (-1.0 * _x_x_8)) <= -9.0) && (((x_6 + (-1.0 * _x_x_8)) <= -4.0) && (((x_4 + (-1.0 * _x_x_8)) <= -8.0) && (((x_0 + (-1.0 * _x_x_8)) <= -11.0) && ((x_3 + (-1.0 * _x_x_8)) <= -6.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_8)) == -14.0) || (((x_25 + (-1.0 * _x_x_8)) == -5.0) || (((x_20 + (-1.0 * _x_x_8)) == -5.0) || (((x_19 + (-1.0 * _x_x_8)) == -1.0) || (((x_18 + (-1.0 * _x_x_8)) == -5.0) || (((x_16 + (-1.0 * _x_x_8)) == -5.0) || (((x_15 + (-1.0 * _x_x_8)) == -2.0) || (((x_13 + (-1.0 * _x_x_8)) == -10.0) || (((x_10 + (-1.0 * _x_x_8)) == -19.0) || (((x_9 + (-1.0 * _x_x_8)) == -9.0) || (((x_6 + (-1.0 * _x_x_8)) == -4.0) || (((x_4 + (-1.0 * _x_x_8)) == -8.0) || (((x_0 + (-1.0 * _x_x_8)) == -11.0) || ((x_3 + (-1.0 * _x_x_8)) == -6.0)))))))))))))))) && ((((x_25 + (-1.0 * _x_x_9)) <= -6.0) && (((x_21 + (-1.0 * _x_x_9)) <= -4.0) && (((x_20 + (-1.0 * _x_x_9)) <= -10.0) && (((x_19 + (-1.0 * _x_x_9)) <= -19.0) && (((x_18 + (-1.0 * _x_x_9)) <= -15.0) && (((x_15 + (-1.0 * _x_x_9)) <= -14.0) && (((x_14 + (-1.0 * _x_x_9)) <= -17.0) && (((x_13 + (-1.0 * _x_x_9)) <= -13.0) && (((x_12 + (-1.0 * _x_x_9)) <= -5.0) && (((x_10 + (-1.0 * _x_x_9)) <= -4.0) && (((x_7 + (-1.0 * _x_x_9)) <= -20.0) && (((x_6 + (-1.0 * _x_x_9)) <= -14.0) && (((x_0 + (-1.0 * _x_x_9)) <= -12.0) && ((x_3 + (-1.0 * _x_x_9)) <= -9.0)))))))))))))) && (((x_25 + (-1.0 * _x_x_9)) == -6.0) || (((x_21 + (-1.0 * _x_x_9)) == -4.0) || (((x_20 + (-1.0 * _x_x_9)) == -10.0) || (((x_19 + (-1.0 * _x_x_9)) == -19.0) || (((x_18 + (-1.0 * _x_x_9)) == -15.0) || (((x_15 + (-1.0 * _x_x_9)) == -14.0) || (((x_14 + (-1.0 * _x_x_9)) == -17.0) || (((x_13 + (-1.0 * _x_x_9)) == -13.0) || (((x_12 + (-1.0 * _x_x_9)) == -5.0) || (((x_10 + (-1.0 * _x_x_9)) == -4.0) || (((x_7 + (-1.0 * _x_x_9)) == -20.0) || (((x_6 + (-1.0 * _x_x_9)) == -14.0) || (((x_0 + (-1.0 * _x_x_9)) == -12.0) || ((x_3 + (-1.0 * _x_x_9)) == -9.0)))))))))))))))) && ((((x_26 + (-1.0 * _x_x_10)) <= -13.0) && (((x_24 + (-1.0 * _x_x_10)) <= -3.0) && (((x_22 + (-1.0 * _x_x_10)) <= -15.0) && (((x_19 + (-1.0 * _x_x_10)) <= -6.0) && (((x_13 + (-1.0 * _x_x_10)) <= -20.0) && (((x_12 + (-1.0 * _x_x_10)) <= -9.0) && (((x_10 + (-1.0 * _x_x_10)) <= -12.0) && (((x_7 + (-1.0 * _x_x_10)) <= -13.0) && (((x_6 + (-1.0 * _x_x_10)) <= -15.0) && (((x_5 + (-1.0 * _x_x_10)) <= -4.0) && (((x_4 + (-1.0 * _x_x_10)) <= -12.0) && (((x_3 + (-1.0 * _x_x_10)) <= -15.0) && (((x_0 + (-1.0 * _x_x_10)) <= -16.0) && ((x_1 + (-1.0 * _x_x_10)) <= -18.0)))))))))))))) && (((x_26 + (-1.0 * _x_x_10)) == -13.0) || (((x_24 + (-1.0 * _x_x_10)) == -3.0) || (((x_22 + (-1.0 * _x_x_10)) == -15.0) || (((x_19 + (-1.0 * _x_x_10)) == -6.0) || (((x_13 + (-1.0 * _x_x_10)) == -20.0) || (((x_12 + (-1.0 * _x_x_10)) == -9.0) || (((x_10 + (-1.0 * _x_x_10)) == -12.0) || (((x_7 + (-1.0 * _x_x_10)) == -13.0) || (((x_6 + (-1.0 * _x_x_10)) == -15.0) || (((x_5 + (-1.0 * _x_x_10)) == -4.0) || (((x_4 + (-1.0 * _x_x_10)) == -12.0) || (((x_3 + (-1.0 * _x_x_10)) == -15.0) || (((x_0 + (-1.0 * _x_x_10)) == -16.0) || ((x_1 + (-1.0 * _x_x_10)) == -18.0)))))))))))))))) && ((((x_24 + (-1.0 * _x_x_11)) <= -14.0) && (((x_21 + (-1.0 * _x_x_11)) <= -6.0) && (((x_20 + (-1.0 * _x_x_11)) <= -18.0) && (((x_19 + (-1.0 * _x_x_11)) <= -1.0) && (((x_17 + (-1.0 * _x_x_11)) <= -4.0) && (((x_16 + (-1.0 * _x_x_11)) <= -2.0) && (((x_13 + (-1.0 * _x_x_11)) <= -18.0) && (((x_12 + (-1.0 * _x_x_11)) <= -1.0) && (((x_11 + (-1.0 * _x_x_11)) <= -12.0) && (((x_9 + (-1.0 * _x_x_11)) <= -10.0) && (((x_7 + (-1.0 * _x_x_11)) <= -8.0) && (((x_5 + (-1.0 * _x_x_11)) <= -2.0) && (((x_2 + (-1.0 * _x_x_11)) <= -3.0) && ((x_4 + (-1.0 * _x_x_11)) <= -5.0)))))))))))))) && (((x_24 + (-1.0 * _x_x_11)) == -14.0) || (((x_21 + (-1.0 * _x_x_11)) == -6.0) || (((x_20 + (-1.0 * _x_x_11)) == -18.0) || (((x_19 + (-1.0 * _x_x_11)) == -1.0) || (((x_17 + (-1.0 * _x_x_11)) == -4.0) || (((x_16 + (-1.0 * _x_x_11)) == -2.0) || (((x_13 + (-1.0 * _x_x_11)) == -18.0) || (((x_12 + (-1.0 * _x_x_11)) == -1.0) || (((x_11 + (-1.0 * _x_x_11)) == -12.0) || (((x_9 + (-1.0 * _x_x_11)) == -10.0) || (((x_7 + (-1.0 * _x_x_11)) == -8.0) || (((x_5 + (-1.0 * _x_x_11)) == -2.0) || (((x_2 + (-1.0 * _x_x_11)) == -3.0) || ((x_4 + (-1.0 * _x_x_11)) == -5.0)))))))))))))))) && ((((x_25 + (-1.0 * _x_x_12)) <= -4.0) && (((x_22 + (-1.0 * _x_x_12)) <= -3.0) && (((x_21 + (-1.0 * _x_x_12)) <= -8.0) && (((x_19 + (-1.0 * _x_x_12)) <= -11.0) && (((x_18 + (-1.0 * _x_x_12)) <= -3.0) && (((x_17 + (-1.0 * _x_x_12)) <= -15.0) && (((x_14 + (-1.0 * _x_x_12)) <= -10.0) && (((x_11 + (-1.0 * _x_x_12)) <= -5.0) && (((x_10 + (-1.0 * _x_x_12)) <= -18.0) && (((x_9 + (-1.0 * _x_x_12)) <= -2.0) && (((x_8 + (-1.0 * _x_x_12)) <= -20.0) && (((x_5 + (-1.0 * _x_x_12)) <= -6.0) && (((x_0 + (-1.0 * _x_x_12)) <= -10.0) && ((x_4 + (-1.0 * _x_x_12)) <= -18.0)))))))))))))) && (((x_25 + (-1.0 * _x_x_12)) == -4.0) || (((x_22 + (-1.0 * _x_x_12)) == -3.0) || (((x_21 + (-1.0 * _x_x_12)) == -8.0) || (((x_19 + (-1.0 * _x_x_12)) == -11.0) || (((x_18 + (-1.0 * _x_x_12)) == -3.0) || (((x_17 + (-1.0 * _x_x_12)) == -15.0) || (((x_14 + (-1.0 * _x_x_12)) == -10.0) || (((x_11 + (-1.0 * _x_x_12)) == -5.0) || (((x_10 + (-1.0 * _x_x_12)) == -18.0) || (((x_9 + (-1.0 * _x_x_12)) == -2.0) || (((x_8 + (-1.0 * _x_x_12)) == -20.0) || (((x_5 + (-1.0 * _x_x_12)) == -6.0) || (((x_0 + (-1.0 * _x_x_12)) == -10.0) || ((x_4 + (-1.0 * _x_x_12)) == -18.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_13)) <= -18.0) && (((x_25 + (-1.0 * _x_x_13)) <= -4.0) && (((x_24 + (-1.0 * _x_x_13)) <= -19.0) && (((x_22 + (-1.0 * _x_x_13)) <= -14.0) && (((x_21 + (-1.0 * _x_x_13)) <= -6.0) && (((x_19 + (-1.0 * _x_x_13)) <= -11.0) && (((x_16 + (-1.0 * _x_x_13)) <= -16.0) && (((x_13 + (-1.0 * _x_x_13)) <= -9.0) && (((x_11 + (-1.0 * _x_x_13)) <= -16.0) && (((x_9 + (-1.0 * _x_x_13)) <= -1.0) && (((x_8 + (-1.0 * _x_x_13)) <= -17.0) && (((x_5 + (-1.0 * _x_x_13)) <= -5.0) && (((x_1 + (-1.0 * _x_x_13)) <= -11.0) && ((x_4 + (-1.0 * _x_x_13)) <= -6.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_13)) == -18.0) || (((x_25 + (-1.0 * _x_x_13)) == -4.0) || (((x_24 + (-1.0 * _x_x_13)) == -19.0) || (((x_22 + (-1.0 * _x_x_13)) == -14.0) || (((x_21 + (-1.0 * _x_x_13)) == -6.0) || (((x_19 + (-1.0 * _x_x_13)) == -11.0) || (((x_16 + (-1.0 * _x_x_13)) == -16.0) || (((x_13 + (-1.0 * _x_x_13)) == -9.0) || (((x_11 + (-1.0 * _x_x_13)) == -16.0) || (((x_9 + (-1.0 * _x_x_13)) == -1.0) || (((x_8 + (-1.0 * _x_x_13)) == -17.0) || (((x_5 + (-1.0 * _x_x_13)) == -5.0) || (((x_1 + (-1.0 * _x_x_13)) == -11.0) || ((x_4 + (-1.0 * _x_x_13)) == -6.0)))))))))))))))) && ((((x_23 + (-1.0 * _x_x_14)) <= -17.0) && (((x_22 + (-1.0 * _x_x_14)) <= -12.0) && (((x_19 + (-1.0 * _x_x_14)) <= -16.0) && (((x_17 + (-1.0 * _x_x_14)) <= -12.0) && (((x_16 + (-1.0 * _x_x_14)) <= -7.0) && (((x_15 + (-1.0 * _x_x_14)) <= -17.0) && (((x_13 + (-1.0 * _x_x_14)) <= -12.0) && (((x_12 + (-1.0 * _x_x_14)) <= -2.0) && (((x_10 + (-1.0 * _x_x_14)) <= -6.0) && (((x_8 + (-1.0 * _x_x_14)) <= -15.0) && (((x_6 + (-1.0 * _x_x_14)) <= -8.0) && (((x_5 + (-1.0 * _x_x_14)) <= -1.0) && (((x_0 + (-1.0 * _x_x_14)) <= -14.0) && ((x_1 + (-1.0 * _x_x_14)) <= -14.0)))))))))))))) && (((x_23 + (-1.0 * _x_x_14)) == -17.0) || (((x_22 + (-1.0 * _x_x_14)) == -12.0) || (((x_19 + (-1.0 * _x_x_14)) == -16.0) || (((x_17 + (-1.0 * _x_x_14)) == -12.0) || (((x_16 + (-1.0 * _x_x_14)) == -7.0) || (((x_15 + (-1.0 * _x_x_14)) == -17.0) || (((x_13 + (-1.0 * _x_x_14)) == -12.0) || (((x_12 + (-1.0 * _x_x_14)) == -2.0) || (((x_10 + (-1.0 * _x_x_14)) == -6.0) || (((x_8 + (-1.0 * _x_x_14)) == -15.0) || (((x_6 + (-1.0 * _x_x_14)) == -8.0) || (((x_5 + (-1.0 * _x_x_14)) == -1.0) || (((x_0 + (-1.0 * _x_x_14)) == -14.0) || ((x_1 + (-1.0 * _x_x_14)) == -14.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_15)) <= -9.0) && (((x_25 + (-1.0 * _x_x_15)) <= -2.0) && (((x_24 + (-1.0 * _x_x_15)) <= -2.0) && (((x_19 + (-1.0 * _x_x_15)) <= -20.0) && (((x_17 + (-1.0 * _x_x_15)) <= -17.0) && (((x_16 + (-1.0 * _x_x_15)) <= -16.0) && (((x_15 + (-1.0 * _x_x_15)) <= -17.0) && (((x_12 + (-1.0 * _x_x_15)) <= -15.0) && (((x_10 + (-1.0 * _x_x_15)) <= -1.0) && (((x_7 + (-1.0 * _x_x_15)) <= -13.0) && (((x_5 + (-1.0 * _x_x_15)) <= -4.0) && (((x_3 + (-1.0 * _x_x_15)) <= -11.0) && (((x_0 + (-1.0 * _x_x_15)) <= -4.0) && ((x_2 + (-1.0 * _x_x_15)) <= -11.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_15)) == -9.0) || (((x_25 + (-1.0 * _x_x_15)) == -2.0) || (((x_24 + (-1.0 * _x_x_15)) == -2.0) || (((x_19 + (-1.0 * _x_x_15)) == -20.0) || (((x_17 + (-1.0 * _x_x_15)) == -17.0) || (((x_16 + (-1.0 * _x_x_15)) == -16.0) || (((x_15 + (-1.0 * _x_x_15)) == -17.0) || (((x_12 + (-1.0 * _x_x_15)) == -15.0) || (((x_10 + (-1.0 * _x_x_15)) == -1.0) || (((x_7 + (-1.0 * _x_x_15)) == -13.0) || (((x_5 + (-1.0 * _x_x_15)) == -4.0) || (((x_3 + (-1.0 * _x_x_15)) == -11.0) || (((x_0 + (-1.0 * _x_x_15)) == -4.0) || ((x_2 + (-1.0 * _x_x_15)) == -11.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_16)) <= -5.0) && (((x_26 + (-1.0 * _x_x_16)) <= -7.0) && (((x_25 + (-1.0 * _x_x_16)) <= -6.0) && (((x_24 + (-1.0 * _x_x_16)) <= -12.0) && (((x_21 + (-1.0 * _x_x_16)) <= -1.0) && (((x_14 + (-1.0 * _x_x_16)) <= -8.0) && (((x_13 + (-1.0 * _x_x_16)) <= -20.0) && (((x_12 + (-1.0 * _x_x_16)) <= -2.0) && (((x_11 + (-1.0 * _x_x_16)) <= -16.0) && (((x_9 + (-1.0 * _x_x_16)) <= -7.0) && (((x_8 + (-1.0 * _x_x_16)) <= -20.0) && (((x_7 + (-1.0 * _x_x_16)) <= -12.0) && (((x_0 + (-1.0 * _x_x_16)) <= -11.0) && ((x_6 + (-1.0 * _x_x_16)) <= -13.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_16)) == -5.0) || (((x_26 + (-1.0 * _x_x_16)) == -7.0) || (((x_25 + (-1.0 * _x_x_16)) == -6.0) || (((x_24 + (-1.0 * _x_x_16)) == -12.0) || (((x_21 + (-1.0 * _x_x_16)) == -1.0) || (((x_14 + (-1.0 * _x_x_16)) == -8.0) || (((x_13 + (-1.0 * _x_x_16)) == -20.0) || (((x_12 + (-1.0 * _x_x_16)) == -2.0) || (((x_11 + (-1.0 * _x_x_16)) == -16.0) || (((x_9 + (-1.0 * _x_x_16)) == -7.0) || (((x_8 + (-1.0 * _x_x_16)) == -20.0) || (((x_7 + (-1.0 * _x_x_16)) == -12.0) || (((x_0 + (-1.0 * _x_x_16)) == -11.0) || ((x_6 + (-1.0 * _x_x_16)) == -13.0)))))))))))))))) && ((((x_26 + (-1.0 * _x_x_17)) <= -19.0) && (((x_25 + (-1.0 * _x_x_17)) <= -9.0) && (((x_23 + (-1.0 * _x_x_17)) <= -16.0) && (((x_22 + (-1.0 * _x_x_17)) <= -9.0) && (((x_21 + (-1.0 * _x_x_17)) <= -13.0) && (((x_20 + (-1.0 * _x_x_17)) <= -16.0) && (((x_19 + (-1.0 * _x_x_17)) <= -10.0) && (((x_18 + (-1.0 * _x_x_17)) <= -20.0) && (((x_15 + (-1.0 * _x_x_17)) <= -12.0) && (((x_12 + (-1.0 * _x_x_17)) <= -9.0) && (((x_11 + (-1.0 * _x_x_17)) <= -19.0) && (((x_5 + (-1.0 * _x_x_17)) <= -14.0) && (((x_3 + (-1.0 * _x_x_17)) <= -10.0) && ((x_4 + (-1.0 * _x_x_17)) <= -13.0)))))))))))))) && (((x_26 + (-1.0 * _x_x_17)) == -19.0) || (((x_25 + (-1.0 * _x_x_17)) == -9.0) || (((x_23 + (-1.0 * _x_x_17)) == -16.0) || (((x_22 + (-1.0 * _x_x_17)) == -9.0) || (((x_21 + (-1.0 * _x_x_17)) == -13.0) || (((x_20 + (-1.0 * _x_x_17)) == -16.0) || (((x_19 + (-1.0 * _x_x_17)) == -10.0) || (((x_18 + (-1.0 * _x_x_17)) == -20.0) || (((x_15 + (-1.0 * _x_x_17)) == -12.0) || (((x_12 + (-1.0 * _x_x_17)) == -9.0) || (((x_11 + (-1.0 * _x_x_17)) == -19.0) || (((x_5 + (-1.0 * _x_x_17)) == -14.0) || (((x_3 + (-1.0 * _x_x_17)) == -10.0) || ((x_4 + (-1.0 * _x_x_17)) == -13.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_18)) <= -4.0) && (((x_26 + (-1.0 * _x_x_18)) <= -14.0) && (((x_25 + (-1.0 * _x_x_18)) <= -7.0) && (((x_24 + (-1.0 * _x_x_18)) <= -20.0) && (((x_23 + (-1.0 * _x_x_18)) <= -18.0) && (((x_22 + (-1.0 * _x_x_18)) <= -7.0) && (((x_15 + (-1.0 * _x_x_18)) <= -19.0) && (((x_14 + (-1.0 * _x_x_18)) <= -18.0) && (((x_13 + (-1.0 * _x_x_18)) <= -13.0) && (((x_12 + (-1.0 * _x_x_18)) <= -11.0) && (((x_10 + (-1.0 * _x_x_18)) <= -18.0) && (((x_9 + (-1.0 * _x_x_18)) <= -2.0) && (((x_4 + (-1.0 * _x_x_18)) <= -7.0) && ((x_8 + (-1.0 * _x_x_18)) <= -5.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_18)) == -4.0) || (((x_26 + (-1.0 * _x_x_18)) == -14.0) || (((x_25 + (-1.0 * _x_x_18)) == -7.0) || (((x_24 + (-1.0 * _x_x_18)) == -20.0) || (((x_23 + (-1.0 * _x_x_18)) == -18.0) || (((x_22 + (-1.0 * _x_x_18)) == -7.0) || (((x_15 + (-1.0 * _x_x_18)) == -19.0) || (((x_14 + (-1.0 * _x_x_18)) == -18.0) || (((x_13 + (-1.0 * _x_x_18)) == -13.0) || (((x_12 + (-1.0 * _x_x_18)) == -11.0) || (((x_10 + (-1.0 * _x_x_18)) == -18.0) || (((x_9 + (-1.0 * _x_x_18)) == -2.0) || (((x_4 + (-1.0 * _x_x_18)) == -7.0) || ((x_8 + (-1.0 * _x_x_18)) == -5.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_19)) <= -14.0) && (((x_26 + (-1.0 * _x_x_19)) <= -9.0) && (((x_23 + (-1.0 * _x_x_19)) <= -11.0) && (((x_22 + (-1.0 * _x_x_19)) <= -17.0) && (((x_14 + (-1.0 * _x_x_19)) <= -3.0) && (((x_13 + (-1.0 * _x_x_19)) <= -10.0) && (((x_9 + (-1.0 * _x_x_19)) <= -4.0) && (((x_8 + (-1.0 * _x_x_19)) <= -19.0) && (((x_7 + (-1.0 * _x_x_19)) <= -12.0) && (((x_5 + (-1.0 * _x_x_19)) <= -11.0) && (((x_4 + (-1.0 * _x_x_19)) <= -19.0) && (((x_2 + (-1.0 * _x_x_19)) <= -9.0) && (((x_0 + (-1.0 * _x_x_19)) <= -16.0) && ((x_1 + (-1.0 * _x_x_19)) <= -16.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_19)) == -14.0) || (((x_26 + (-1.0 * _x_x_19)) == -9.0) || (((x_23 + (-1.0 * _x_x_19)) == -11.0) || (((x_22 + (-1.0 * _x_x_19)) == -17.0) || (((x_14 + (-1.0 * _x_x_19)) == -3.0) || (((x_13 + (-1.0 * _x_x_19)) == -10.0) || (((x_9 + (-1.0 * _x_x_19)) == -4.0) || (((x_8 + (-1.0 * _x_x_19)) == -19.0) || (((x_7 + (-1.0 * _x_x_19)) == -12.0) || (((x_5 + (-1.0 * _x_x_19)) == -11.0) || (((x_4 + (-1.0 * _x_x_19)) == -19.0) || (((x_2 + (-1.0 * _x_x_19)) == -9.0) || (((x_0 + (-1.0 * _x_x_19)) == -16.0) || ((x_1 + (-1.0 * _x_x_19)) == -16.0)))))))))))))))) && ((((x_24 + (-1.0 * _x_x_20)) <= -17.0) && (((x_22 + (-1.0 * _x_x_20)) <= -10.0) && (((x_21 + (-1.0 * _x_x_20)) <= -7.0) && (((x_20 + (-1.0 * _x_x_20)) <= -8.0) && (((x_18 + (-1.0 * _x_x_20)) <= -14.0) && (((x_17 + (-1.0 * _x_x_20)) <= -17.0) && (((x_12 + (-1.0 * _x_x_20)) <= -13.0) && (((x_9 + (-1.0 * _x_x_20)) <= -8.0) && (((x_7 + (-1.0 * _x_x_20)) <= -7.0) && (((x_6 + (-1.0 * _x_x_20)) <= -19.0) && (((x_5 + (-1.0 * _x_x_20)) <= -15.0) && (((x_3 + (-1.0 * _x_x_20)) <= -4.0) && (((x_0 + (-1.0 * _x_x_20)) <= -9.0) && ((x_2 + (-1.0 * _x_x_20)) <= -15.0)))))))))))))) && (((x_24 + (-1.0 * _x_x_20)) == -17.0) || (((x_22 + (-1.0 * _x_x_20)) == -10.0) || (((x_21 + (-1.0 * _x_x_20)) == -7.0) || (((x_20 + (-1.0 * _x_x_20)) == -8.0) || (((x_18 + (-1.0 * _x_x_20)) == -14.0) || (((x_17 + (-1.0 * _x_x_20)) == -17.0) || (((x_12 + (-1.0 * _x_x_20)) == -13.0) || (((x_9 + (-1.0 * _x_x_20)) == -8.0) || (((x_7 + (-1.0 * _x_x_20)) == -7.0) || (((x_6 + (-1.0 * _x_x_20)) == -19.0) || (((x_5 + (-1.0 * _x_x_20)) == -15.0) || (((x_3 + (-1.0 * _x_x_20)) == -4.0) || (((x_0 + (-1.0 * _x_x_20)) == -9.0) || ((x_2 + (-1.0 * _x_x_20)) == -15.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_21)) <= -2.0) && (((x_26 + (-1.0 * _x_x_21)) <= -16.0) && (((x_24 + (-1.0 * _x_x_21)) <= -2.0) && (((x_22 + (-1.0 * _x_x_21)) <= -5.0) && (((x_20 + (-1.0 * _x_x_21)) <= -17.0) && (((x_17 + (-1.0 * _x_x_21)) <= -5.0) && (((x_16 + (-1.0 * _x_x_21)) <= -11.0) && (((x_15 + (-1.0 * _x_x_21)) <= -11.0) && (((x_13 + (-1.0 * _x_x_21)) <= -14.0) && (((x_10 + (-1.0 * _x_x_21)) <= -11.0) && (((x_6 + (-1.0 * _x_x_21)) <= -3.0) && (((x_5 + (-1.0 * _x_x_21)) <= -18.0) && (((x_3 + (-1.0 * _x_x_21)) <= -4.0) && ((x_4 + (-1.0 * _x_x_21)) <= -15.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_21)) == -2.0) || (((x_26 + (-1.0 * _x_x_21)) == -16.0) || (((x_24 + (-1.0 * _x_x_21)) == -2.0) || (((x_22 + (-1.0 * _x_x_21)) == -5.0) || (((x_20 + (-1.0 * _x_x_21)) == -17.0) || (((x_17 + (-1.0 * _x_x_21)) == -5.0) || (((x_16 + (-1.0 * _x_x_21)) == -11.0) || (((x_15 + (-1.0 * _x_x_21)) == -11.0) || (((x_13 + (-1.0 * _x_x_21)) == -14.0) || (((x_10 + (-1.0 * _x_x_21)) == -11.0) || (((x_6 + (-1.0 * _x_x_21)) == -3.0) || (((x_5 + (-1.0 * _x_x_21)) == -18.0) || (((x_3 + (-1.0 * _x_x_21)) == -4.0) || ((x_4 + (-1.0 * _x_x_21)) == -15.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_22)) <= -17.0) && (((x_26 + (-1.0 * _x_x_22)) <= -15.0) && (((x_24 + (-1.0 * _x_x_22)) <= -20.0) && (((x_19 + (-1.0 * _x_x_22)) <= -7.0) && (((x_18 + (-1.0 * _x_x_22)) <= -17.0) && (((x_15 + (-1.0 * _x_x_22)) <= -4.0) && (((x_14 + (-1.0 * _x_x_22)) <= -17.0) && (((x_12 + (-1.0 * _x_x_22)) <= -3.0) && (((x_6 + (-1.0 * _x_x_22)) <= -9.0) && (((x_5 + (-1.0 * _x_x_22)) <= -9.0) && (((x_4 + (-1.0 * _x_x_22)) <= -16.0) && (((x_2 + (-1.0 * _x_x_22)) <= -12.0) && (((x_0 + (-1.0 * _x_x_22)) <= -16.0) && ((x_1 + (-1.0 * _x_x_22)) <= -17.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_22)) == -17.0) || (((x_26 + (-1.0 * _x_x_22)) == -15.0) || (((x_24 + (-1.0 * _x_x_22)) == -20.0) || (((x_19 + (-1.0 * _x_x_22)) == -7.0) || (((x_18 + (-1.0 * _x_x_22)) == -17.0) || (((x_15 + (-1.0 * _x_x_22)) == -4.0) || (((x_14 + (-1.0 * _x_x_22)) == -17.0) || (((x_12 + (-1.0 * _x_x_22)) == -3.0) || (((x_6 + (-1.0 * _x_x_22)) == -9.0) || (((x_5 + (-1.0 * _x_x_22)) == -9.0) || (((x_4 + (-1.0 * _x_x_22)) == -16.0) || (((x_2 + (-1.0 * _x_x_22)) == -12.0) || (((x_0 + (-1.0 * _x_x_22)) == -16.0) || ((x_1 + (-1.0 * _x_x_22)) == -17.0)))))))))))))))) && ((((x_23 + (-1.0 * _x_x_23)) <= -1.0) && (((x_22 + (-1.0 * _x_x_23)) <= -1.0) && (((x_19 + (-1.0 * _x_x_23)) <= -5.0) && (((x_17 + (-1.0 * _x_x_23)) <= -7.0) && (((x_16 + (-1.0 * _x_x_23)) <= -13.0) && (((x_15 + (-1.0 * _x_x_23)) <= -10.0) && (((x_13 + (-1.0 * _x_x_23)) <= -7.0) && (((x_11 + (-1.0 * _x_x_23)) <= -10.0) && (((x_9 + (-1.0 * _x_x_23)) <= -3.0) && (((x_8 + (-1.0 * _x_x_23)) <= -19.0) && (((x_6 + (-1.0 * _x_x_23)) <= -19.0) && (((x_2 + (-1.0 * _x_x_23)) <= -5.0) && (((x_0 + (-1.0 * _x_x_23)) <= -11.0) && ((x_1 + (-1.0 * _x_x_23)) <= -6.0)))))))))))))) && (((x_23 + (-1.0 * _x_x_23)) == -1.0) || (((x_22 + (-1.0 * _x_x_23)) == -1.0) || (((x_19 + (-1.0 * _x_x_23)) == -5.0) || (((x_17 + (-1.0 * _x_x_23)) == -7.0) || (((x_16 + (-1.0 * _x_x_23)) == -13.0) || (((x_15 + (-1.0 * _x_x_23)) == -10.0) || (((x_13 + (-1.0 * _x_x_23)) == -7.0) || (((x_11 + (-1.0 * _x_x_23)) == -10.0) || (((x_9 + (-1.0 * _x_x_23)) == -3.0) || (((x_8 + (-1.0 * _x_x_23)) == -19.0) || (((x_6 + (-1.0 * _x_x_23)) == -19.0) || (((x_2 + (-1.0 * _x_x_23)) == -5.0) || (((x_0 + (-1.0 * _x_x_23)) == -11.0) || ((x_1 + (-1.0 * _x_x_23)) == -6.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_24)) <= -18.0) && (((x_26 + (-1.0 * _x_x_24)) <= -12.0) && (((x_25 + (-1.0 * _x_x_24)) <= -14.0) && (((x_24 + (-1.0 * _x_x_24)) <= -15.0) && (((x_23 + (-1.0 * _x_x_24)) <= -20.0) && (((x_22 + (-1.0 * _x_x_24)) <= -9.0) && (((x_21 + (-1.0 * _x_x_24)) <= -4.0) && (((x_16 + (-1.0 * _x_x_24)) <= -18.0) && (((x_15 + (-1.0 * _x_x_24)) <= -20.0) && (((x_14 + (-1.0 * _x_x_24)) <= -18.0) && (((x_5 + (-1.0 * _x_x_24)) <= -3.0) && (((x_4 + (-1.0 * _x_x_24)) <= -11.0) && (((x_1 + (-1.0 * _x_x_24)) <= -18.0) && ((x_3 + (-1.0 * _x_x_24)) <= -11.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_24)) == -18.0) || (((x_26 + (-1.0 * _x_x_24)) == -12.0) || (((x_25 + (-1.0 * _x_x_24)) == -14.0) || (((x_24 + (-1.0 * _x_x_24)) == -15.0) || (((x_23 + (-1.0 * _x_x_24)) == -20.0) || (((x_22 + (-1.0 * _x_x_24)) == -9.0) || (((x_21 + (-1.0 * _x_x_24)) == -4.0) || (((x_16 + (-1.0 * _x_x_24)) == -18.0) || (((x_15 + (-1.0 * _x_x_24)) == -20.0) || (((x_14 + (-1.0 * _x_x_24)) == -18.0) || (((x_5 + (-1.0 * _x_x_24)) == -3.0) || (((x_4 + (-1.0 * _x_x_24)) == -11.0) || (((x_1 + (-1.0 * _x_x_24)) == -18.0) || ((x_3 + (-1.0 * _x_x_24)) == -11.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_25)) <= -10.0) && (((x_23 + (-1.0 * _x_x_25)) <= -10.0) && (((x_19 + (-1.0 * _x_x_25)) <= -15.0) && (((x_18 + (-1.0 * _x_x_25)) <= -3.0) && (((x_17 + (-1.0 * _x_x_25)) <= -9.0) && (((x_16 + (-1.0 * _x_x_25)) <= -9.0) && (((x_15 + (-1.0 * _x_x_25)) <= -16.0) && (((x_14 + (-1.0 * _x_x_25)) <= -11.0) && (((x_11 + (-1.0 * _x_x_25)) <= -7.0) && (((x_9 + (-1.0 * _x_x_25)) <= -3.0) && (((x_4 + (-1.0 * _x_x_25)) <= -13.0) && (((x_3 + (-1.0 * _x_x_25)) <= -9.0) && (((x_1 + (-1.0 * _x_x_25)) <= -1.0) && ((x_2 + (-1.0 * _x_x_25)) <= -15.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_25)) == -10.0) || (((x_23 + (-1.0 * _x_x_25)) == -10.0) || (((x_19 + (-1.0 * _x_x_25)) == -15.0) || (((x_18 + (-1.0 * _x_x_25)) == -3.0) || (((x_17 + (-1.0 * _x_x_25)) == -9.0) || (((x_16 + (-1.0 * _x_x_25)) == -9.0) || (((x_15 + (-1.0 * _x_x_25)) == -16.0) || (((x_14 + (-1.0 * _x_x_25)) == -11.0) || (((x_11 + (-1.0 * _x_x_25)) == -7.0) || (((x_9 + (-1.0 * _x_x_25)) == -3.0) || (((x_4 + (-1.0 * _x_x_25)) == -13.0) || (((x_3 + (-1.0 * _x_x_25)) == -9.0) || (((x_1 + (-1.0 * _x_x_25)) == -1.0) || ((x_2 + (-1.0 * _x_x_25)) == -15.0)))))))))))))))) && ((((x_26 + (-1.0 * _x_x_26)) <= -14.0) && (((x_24 + (-1.0 * _x_x_26)) <= -9.0) && (((x_22 + (-1.0 * _x_x_26)) <= -11.0) && (((x_21 + (-1.0 * _x_x_26)) <= -6.0) && (((x_18 + (-1.0 * _x_x_26)) <= -13.0) && (((x_15 + (-1.0 * _x_x_26)) <= -19.0) && (((x_13 + (-1.0 * _x_x_26)) <= -9.0) && (((x_10 + (-1.0 * _x_x_26)) <= -6.0) && (((x_9 + (-1.0 * _x_x_26)) <= -11.0) && (((x_8 + (-1.0 * _x_x_26)) <= -11.0) && (((x_6 + (-1.0 * _x_x_26)) <= -5.0) && (((x_5 + (-1.0 * _x_x_26)) <= -6.0) && (((x_0 + (-1.0 * _x_x_26)) <= -20.0) && ((x_1 + (-1.0 * _x_x_26)) <= -14.0)))))))))))))) && (((x_26 + (-1.0 * _x_x_26)) == -14.0) || (((x_24 + (-1.0 * _x_x_26)) == -9.0) || (((x_22 + (-1.0 * _x_x_26)) == -11.0) || (((x_21 + (-1.0 * _x_x_26)) == -6.0) || (((x_18 + (-1.0 * _x_x_26)) == -13.0) || (((x_15 + (-1.0 * _x_x_26)) == -19.0) || (((x_13 + (-1.0 * _x_x_26)) == -9.0) || (((x_10 + (-1.0 * _x_x_26)) == -6.0) || (((x_9 + (-1.0 * _x_x_26)) == -11.0) || (((x_8 + (-1.0 * _x_x_26)) == -11.0) || (((x_6 + (-1.0 * _x_x_26)) == -5.0) || (((x_5 + (-1.0 * _x_x_26)) == -6.0) || (((x_0 + (-1.0 * _x_x_26)) == -20.0) || ((x_1 + (-1.0 * _x_x_26)) == -14.0)))))))))))))))) && ((((x_26 + (-1.0 * _x_x_27)) <= -7.0) && (((x_24 + (-1.0 * _x_x_27)) <= -1.0) && (((x_23 + (-1.0 * _x_x_27)) <= -3.0) && (((x_18 + (-1.0 * _x_x_27)) <= -19.0) && (((x_17 + (-1.0 * _x_x_27)) <= -5.0) && (((x_15 + (-1.0 * _x_x_27)) <= -12.0) && (((x_14 + (-1.0 * _x_x_27)) <= -5.0) && (((x_12 + (-1.0 * _x_x_27)) <= -11.0) && (((x_10 + (-1.0 * _x_x_27)) <= -10.0) && (((x_9 + (-1.0 * _x_x_27)) <= -7.0) && (((x_7 + (-1.0 * _x_x_27)) <= -3.0) && (((x_6 + (-1.0 * _x_x_27)) <= -11.0) && (((x_0 + (-1.0 * _x_x_27)) <= -19.0) && ((x_3 + (-1.0 * _x_x_27)) <= -20.0)))))))))))))) && (((x_26 + (-1.0 * _x_x_27)) == -7.0) || (((x_24 + (-1.0 * _x_x_27)) == -1.0) || (((x_23 + (-1.0 * _x_x_27)) == -3.0) || (((x_18 + (-1.0 * _x_x_27)) == -19.0) || (((x_17 + (-1.0 * _x_x_27)) == -5.0) || (((x_15 + (-1.0 * _x_x_27)) == -12.0) || (((x_14 + (-1.0 * _x_x_27)) == -5.0) || (((x_12 + (-1.0 * _x_x_27)) == -11.0) || (((x_10 + (-1.0 * _x_x_27)) == -10.0) || (((x_9 + (-1.0 * _x_x_27)) == -7.0) || (((x_7 + (-1.0 * _x_x_27)) == -3.0) || (((x_6 + (-1.0 * _x_x_27)) == -11.0) || (((x_0 + (-1.0 * _x_x_27)) == -19.0) || ((x_3 + (-1.0 * _x_x_27)) == -20.0)))))))))))))))) && ((((_EL_U_2391 == ((_x__EL_U_2391 && ( !(-3.0 <= (_x_x_12 + (-1.0 * _x_x_24))))) || ( !(3.0 <= (_x_x_5 + (-1.0 * _x_x_19)))))) && (_EL_U_2393 == (( !(-3.0 <= (_x_x_12 + (-1.0 * _x_x_24)))) || (_x__EL_U_2393 && ((_x__EL_U_2391 && ( !(-3.0 <= (_x_x_12 + (-1.0 * _x_x_24))))) || ( !(3.0 <= (_x_x_5 + (-1.0 * _x_x_19))))))))) && (_x__J2413 == (( !(_J2413 && _J2420)) && ((_J2413 && _J2420) || ((( !(3.0 <= (x_5 + (-1.0 * x_19)))) || ( !(( !(3.0 <= (x_5 + (-1.0 * x_19)))) || (( !(-3.0 <= (x_12 + (-1.0 * x_24)))) && _EL_U_2391)))) || _J2413))))) && (_x__J2420 == (( !(_J2413 && _J2420)) && ((_J2413 && _J2420) || ((( !(-3.0 <= (x_12 + (-1.0 * x_24)))) || ( !(( !(-3.0 <= (x_12 + (-1.0 * x_24)))) || (_EL_U_2393 && (( !(3.0 <= (x_5 + (-1.0 * x_19)))) || (( !(-3.0 <= (x_12 + (-1.0 * x_24)))) && _EL_U_2391)))))) || _J2420))))));
_J2420 = _x__J2420;
_J2413 = _x__J2413;
x_1 = _x_x_1;
_EL_U_2391 = _x__EL_U_2391;
x_24 = _x_x_24;
x_27 = _x_x_27;
x_12 = _x_x_12;
x_19 = _x_x_19;
x_5 = _x_x_5;
x_8 = _x_x_8;
_EL_U_2393 = _x__EL_U_2393;
x_20 = _x_x_20;
x_13 = _x_x_13;
x_3 = _x_x_3;
x_0 = _x_x_0;
x_21 = _x_x_21;
x_6 = _x_x_6;
x_22 = _x_x_22;
x_7 = _x_x_7;
x_9 = _x_x_9;
x_10 = _x_x_10;
x_14 = _x_x_14;
x_25 = _x_x_25;
x_15 = _x_x_15;
x_17 = _x_x_17;
x_18 = _x_x_18;
x_2 = _x_x_2;
x_23 = _x_x_23;
x_26 = _x_x_26;
x_4 = _x_x_4;
x_11 = _x_x_11;
x_16 = _x_x_16;
}
}
|
the_stack_data/128391.c | #include <stdio.h>
#include <math.h>
// Float: 2.7182819843292236328125
// Real : 2.7182818284590452353602874713527...
// Posit: 2.7182818353176116943359375
int main(int argc, char** argv) {
float e = 2.0f;
float prevE = 0.0f;
float step = 2.0f;
float prevStep = 0.0f;
float denom = 2.0f;
while (e != prevE && step != prevStep) {
float term = 1.0f / denom;
prevE = e;
e += term;
prevStep = step;
step += 1.0f;
denom *= step;
}
printf("%.50e\n", e);
}
|
the_stack_data/429844.c | // [ACM] #10035 - Primary Arithmetic
// Problem Status CPU Date&Time(UTC) ID Best CPU
// 10035 Accepted 0.043 2006-10-18 12:24:26 5053538 0.010
#include<stdio.h>
#include<string.h>
int main(void)
{
char a[11], b[11], temp;
int la, lb, i, k, l, t = 0;
while(1)
{
k = 0;
t = 0;
for(i = 0; i < 10; i++)
{
a[i] = 0;
b[i] = 0;
}
scanf("%s %s" , a, b);
if(a[0] == '0' && b[0] == '0')
break;
la = strlen(a);
lb = strlen(b);
l = la > lb ? la : la == lb ? la : lb;
for(i = 0; i < la / 2; i++)
{
temp = a[la - i - 1];
a[la - i - 1] = a[i];
a[i] = temp;
}
for(i = 0; i < lb / 2; i++)
{
temp = b[ lb - 1 -i];
b[lb - 1 - i] = b[i];
b[i] = temp;
}
for(i = 0; i < l; i ++)
{
if(a[i])
a[i] = a[i] -48;
if(b[i])
b[i] = b[i] -48;
if(a[i] + b[i] + t > 9)
{
k ++;
t = 1;
}
else
t = 0;
}
if(k == 1)
printf("1 carry operation.\n");
else if(k != 0)
printf("%d carry operations.\n" , k);
else
printf("No carry operation.\n");
}
return 0;
}
|
the_stack_data/934338.c | /* mbed Microcontroller Library
*******************************************************************************
* Copyright (c) 2017, STMicroelectronics
* 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. 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 DEVICE_SERIAL
#include "serial_api_hal.h"
#define UART_NUM (3)
uint32_t serial_irq_ids[UART_NUM] = {0};
UART_HandleTypeDef uart_handlers[UART_NUM];
static uart_irq_handler irq_handler;
/******************************************************************************
* INTERRUPTS HANDLING
******************************************************************************/
static void uart_irq(int id)
{
UART_HandleTypeDef * huart = &uart_handlers[id];
if (serial_irq_ids[id] != 0) {
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE) != RESET) {
irq_handler(serial_irq_ids[id], TxIrq);
}
}
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) {
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_RXNE) != RESET) {
irq_handler(serial_irq_ids[id], RxIrq);
/* Flag has been cleared when reading the content */
}
}
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR) != RESET) {
volatile uint32_t tmpval __attribute__((unused)) = huart->Instance->DR; // Clear ORE flag
}
}
}
}
static void uart1_irq(void)
{
uart_irq(0);
}
static void uart2_irq(void)
{
uart_irq(1);
}
static void uart3_irq(void)
{
uart_irq(2);
}
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
{
struct serial_s *obj_s = SERIAL_S(obj);
irq_handler = handler;
serial_irq_ids[obj_s->index] = id;
}
void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
IRQn_Type irq_n = (IRQn_Type)0;
uint32_t vector = 0;
if (obj_s->uart == UART_1) {
irq_n = USART1_IRQn;
vector = (uint32_t)&uart1_irq;
}
if (obj_s->uart == UART_2) {
irq_n = USART2_IRQn;
vector = (uint32_t)&uart2_irq;
}
if (obj_s->uart == UART_3) {
irq_n = USART3_IRQn;
vector = (uint32_t)&uart3_irq;
}
if (enable) {
if (irq == RxIrq) {
__HAL_UART_ENABLE_IT(huart, UART_IT_RXNE);
} else { // TxIrq
__HAL_UART_ENABLE_IT(huart, UART_IT_TXE);
}
NVIC_SetVector(irq_n, vector);
NVIC_EnableIRQ(irq_n);
} else { // disable
int all_disabled = 0;
if (irq == RxIrq) {
__HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);
// Check if TxIrq is disabled too
if ((huart->Instance->CR1 & USART_CR1_TXEIE) == 0) {
all_disabled = 1;
}
} else { // TxIrq
__HAL_UART_DISABLE_IT(huart, UART_IT_TXE);
// Check if RxIrq is disabled too
if ((huart->Instance->CR1 & USART_CR1_RXNEIE) == 0) {
all_disabled = 1;
}
}
if (all_disabled) {
NVIC_DisableIRQ(irq_n);
}
}
}
/******************************************************************************
* READ/WRITE
******************************************************************************/
int serial_getc(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
while (!serial_readable(obj));
if (obj_s->databits == UART_WORDLENGTH_8B) {
return (int)(huart->Instance->DR & (uint8_t)0xFF);
} else {
return (int)(huart->Instance->DR & (uint16_t)0x1FF);
}
}
void serial_putc(serial_t *obj, int c)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
while (!serial_writable(obj));
if (obj_s->databits == UART_WORDLENGTH_8B) {
huart->Instance->DR = (uint8_t)(c & (uint8_t)0xFF);
} else {
huart->Instance->DR = (uint16_t)(c & (uint16_t)0x1FF);
}
}
void serial_clear(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
huart->TxXferCount = 0;
huart->RxXferCount = 0;
}
void serial_break_set(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
HAL_LIN_SendBreak(huart);
}
#if DEVICE_SERIAL_ASYNCH
/******************************************************************************
* LOCAL HELPER FUNCTIONS
******************************************************************************/
/**
* Configure the TX buffer for an asynchronous write serial transaction
*
* @param obj The serial object.
* @param tx The buffer for sending.
* @param tx_length The number of words to transmit.
*/
static void serial_tx_buffer_set(serial_t *obj, void *tx, int tx_length, uint8_t width)
{
(void)width;
// Exit if a transmit is already on-going
if (serial_tx_active(obj)) {
return;
}
obj->tx_buff.buffer = tx;
obj->tx_buff.length = tx_length;
obj->tx_buff.pos = 0;
}
/**
* Configure the RX buffer for an asynchronous write serial transaction
*
* @param obj The serial object.
* @param tx The buffer for sending.
* @param tx_length The number of words to transmit.
*/
static void serial_rx_buffer_set(serial_t *obj, void *rx, int rx_length, uint8_t width)
{
(void)width;
// Exit if a reception is already on-going
if (serial_rx_active(obj)) {
return;
}
obj->rx_buff.buffer = rx;
obj->rx_buff.length = rx_length;
obj->rx_buff.pos = 0;
}
/**
* Configure events
*
* @param obj The serial object
* @param event The logical OR of the events to configure
* @param enable Set to non-zero to enable events, or zero to disable them
*/
static void serial_enable_event(serial_t *obj, int event, uint8_t enable)
{
struct serial_s *obj_s = SERIAL_S(obj);
// Shouldn't have to enable interrupt here, just need to keep track of the requested events.
if (enable) {
obj_s->events |= event;
} else {
obj_s->events &= ~event;
}
}
/**
* Get index of serial object TX IRQ, relating it to the physical peripheral.
*
* @param obj pointer to serial object
* @return internal NVIC TX IRQ index of U(S)ART peripheral
*/
static IRQn_Type serial_get_irq_n(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
IRQn_Type irq_n;
switch (obj_s->index) {
case 0:
irq_n = USART1_IRQn;
break;
case 1:
irq_n = USART2_IRQn;
break;
case 2:
irq_n = USART3_IRQn;
break;
default:
irq_n = (IRQn_Type)0;
}
return irq_n;
}
/******************************************************************************
* MBED API FUNCTIONS
******************************************************************************/
/**
* Begin asynchronous TX transfer. The used buffer is specified in the serial
* object, tx_buff
*
* @param obj The serial object
* @param tx The buffer for sending
* @param tx_length The number of words to transmit
* @param tx_width The bit width of buffer word
* @param handler The serial handler
* @param event The logical OR of events to be registered
* @param hint A suggestion for how to use DMA with this transfer
* @return Returns number of data transfered, or 0 otherwise
*/
int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx_width, uint32_t handler, uint32_t event, DMAUsage hint)
{
// TODO: DMA usage is currently ignored
(void) hint;
// Check buffer is ok
MBED_ASSERT(tx != (void*)0);
MBED_ASSERT(tx_width == 8); // support only 8b width
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef * huart = &uart_handlers[obj_s->index];
if (tx_length == 0) {
return 0;
}
// Set up buffer
serial_tx_buffer_set(obj, (void *)tx, tx_length, tx_width);
// Set up events
serial_enable_event(obj, SERIAL_EVENT_TX_ALL, 0); // Clear all events
serial_enable_event(obj, event, 1); // Set only the wanted events
// Enable interrupt
IRQn_Type irq_n = serial_get_irq_n(obj);
NVIC_ClearPendingIRQ(irq_n);
NVIC_DisableIRQ(irq_n);
NVIC_SetPriority(irq_n, 1);
NVIC_SetVector(irq_n, (uint32_t)handler);
NVIC_EnableIRQ(irq_n);
// the following function will enable UART_IT_TXE and error interrupts
if (HAL_UART_Transmit_IT(huart, (uint8_t*)tx, tx_length) != HAL_OK) {
return 0;
}
return tx_length;
}
/**
* Begin asynchronous RX transfer (enable interrupt for data collecting)
* The used buffer is specified in the serial object, rx_buff
*
* @param obj The serial object
* @param rx The buffer for sending
* @param rx_length The number of words to transmit
* @param rx_width The bit width of buffer word
* @param handler The serial handler
* @param event The logical OR of events to be registered
* @param handler The serial handler
* @param char_match A character in range 0-254 to be matched
* @param hint A suggestion for how to use DMA with this transfer
*/
void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_width, uint32_t handler, uint32_t event, uint8_t char_match, DMAUsage hint)
{
// TODO: DMA usage is currently ignored
(void) hint;
/* Sanity check arguments */
MBED_ASSERT(obj);
MBED_ASSERT(rx != (void*)0);
MBED_ASSERT(rx_width == 8); // support only 8b width
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
serial_enable_event(obj, SERIAL_EVENT_RX_ALL, 0);
serial_enable_event(obj, event, 1);
// set CharMatch
obj->char_match = char_match;
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
IRQn_Type irq_n = serial_get_irq_n(obj);
NVIC_ClearPendingIRQ(irq_n);
NVIC_DisableIRQ(irq_n);
NVIC_SetPriority(irq_n, 0);
NVIC_SetVector(irq_n, (uint32_t)handler);
NVIC_EnableIRQ(irq_n);
// following HAL function will enable the RXNE interrupt + error interrupts
HAL_UART_Receive_IT(huart, (uint8_t*)rx, rx_length);
}
/**
* Attempts to determine if the serial peripheral is already in use for TX
*
* @param obj The serial object
* @return Non-zero if the TX transaction is ongoing, 0 otherwise
*/
uint8_t serial_tx_active(serial_t *obj)
{
MBED_ASSERT(obj);
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
return ((HAL_UART_GetState(huart) == HAL_UART_STATE_BUSY_TX) ? 1 : 0);
}
/**
* Attempts to determine if the serial peripheral is already in use for RX
*
* @param obj The serial object
* @return Non-zero if the RX transaction is ongoing, 0 otherwise
*/
uint8_t serial_rx_active(serial_t *obj)
{
MBED_ASSERT(obj);
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
return ((HAL_UART_GetState(huart) == HAL_UART_STATE_BUSY_RX) ? 1 : 0);
}
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TC) != RESET) {
__HAL_UART_CLEAR_FLAG(huart, UART_FLAG_TC);
}
}
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) {
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_PE) != RESET) {
volatile uint32_t tmpval __attribute__((unused)) = huart->Instance->DR; // Clear PE flag
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET) {
volatile uint32_t tmpval __attribute__((unused)) = huart->Instance->DR; // Clear FE flag
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_NE) != RESET) {
volatile uint32_t tmpval __attribute__((unused)) = huart->Instance->DR; // Clear NE flag
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {
volatile uint32_t tmpval __attribute__((unused)) = huart->Instance->DR; // Clear ORE flag
}
}
/**
* The asynchronous TX and RX handler.
*
* @param obj The serial object
* @return Returns event flags if a TX/RX transfer termination condition was met or 0 otherwise
*/
int serial_irq_handler_asynch(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
volatile int return_event = 0;
uint8_t *buf = (uint8_t*)(obj->rx_buff.buffer);
uint8_t i = 0;
// TX PART:
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TC) != RESET) {
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_TC) != RESET) {
// Return event SERIAL_EVENT_TX_COMPLETE if requested
if ((obj_s->events & SERIAL_EVENT_TX_COMPLETE ) != 0) {
return_event |= (SERIAL_EVENT_TX_COMPLETE & obj_s->events);
}
}
}
// Handle error events
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_PE) != RESET) {
if (__HAL_UART_GET_IT_SOURCE(huart, USART_IT_ERR) != RESET) {
return_event |= (SERIAL_EVENT_RX_PARITY_ERROR & obj_s->events);
}
}
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET) {
if (__HAL_UART_GET_IT_SOURCE(huart, USART_IT_ERR) != RESET) {
return_event |= (SERIAL_EVENT_RX_FRAMING_ERROR & obj_s->events);
}
}
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {
if (__HAL_UART_GET_IT_SOURCE(huart, USART_IT_ERR) != RESET) {
return_event |= (SERIAL_EVENT_RX_OVERRUN_ERROR & obj_s->events);
}
}
HAL_UART_IRQHandler(huart);
// Abort if an error occurs
if ((return_event & SERIAL_EVENT_RX_PARITY_ERROR) ||
(return_event & SERIAL_EVENT_RX_FRAMING_ERROR) ||
(return_event & SERIAL_EVENT_RX_OVERRUN_ERROR)) {
return return_event;
}
//RX PART
if (huart->RxXferSize != 0) {
obj->rx_buff.pos = huart->RxXferSize - huart->RxXferCount;
}
if ((huart->RxXferCount == 0) && (obj->rx_buff.pos >= (obj->rx_buff.length - 1))) {
return_event |= (SERIAL_EVENT_RX_COMPLETE & obj_s->events);
}
// Check if char_match is present
if (obj_s->events & SERIAL_EVENT_RX_CHARACTER_MATCH) {
if (buf != NULL) {
for (i = 0; i < obj->rx_buff.pos; i++) {
if (buf[i] == obj->char_match) {
obj->rx_buff.pos = i;
return_event |= (SERIAL_EVENT_RX_CHARACTER_MATCH & obj_s->events);
serial_rx_abort_asynch(obj);
break;
}
}
}
}
return return_event;
}
/**
* Abort the ongoing TX transaction. It disables the enabled interupt for TX and
* flush TX hardware buffer if TX FIFO is used
*
* @param obj The serial object
*/
void serial_tx_abort_asynch(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
__HAL_UART_DISABLE_IT(huart, UART_IT_TC);
__HAL_UART_DISABLE_IT(huart, UART_IT_TXE);
// clear flags
__HAL_UART_CLEAR_FLAG(huart, UART_FLAG_TC);
// reset states
huart->TxXferCount = 0;
// update handle state
if(huart->gState == HAL_UART_STATE_BUSY_TX_RX) {
huart->gState = HAL_UART_STATE_BUSY_RX;
} else {
huart->gState = HAL_UART_STATE_READY;
}
}
/**
* Abort the ongoing RX transaction It disables the enabled interrupt for RX and
* flush RX hardware buffer if RX FIFO is used
*
* @param obj The serial object
*/
void serial_rx_abort_asynch(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
// disable interrupts
__HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);
__HAL_UART_DISABLE_IT(huart, UART_IT_PE);
__HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
// clear flags
__HAL_UART_CLEAR_FLAG(huart, UART_FLAG_RXNE);
volatile uint32_t tmpval __attribute__((unused)) = huart->Instance->DR; // Clear errors flag
// reset states
huart->RxXferCount = 0;
// update handle state
if(huart->RxState == HAL_UART_STATE_BUSY_TX_RX) {
huart->RxState = HAL_UART_STATE_BUSY_TX;
} else {
huart->RxState = HAL_UART_STATE_READY;
}
}
#endif /* DEVICE_SERIAL_ASYNCH */
#if DEVICE_SERIAL_FC
/**
* Set HW Control Flow
* @param obj The serial object
* @param type The Control Flow type (FlowControlNone, FlowControlRTS, FlowControlCTS, FlowControlRTSCTS)
* @param rxflow Pin for the rxflow
* @param txflow Pin for the txflow
*/
void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow)
{
struct serial_s *obj_s = SERIAL_S(obj);
// Determine the UART to use (UART_1, UART_2, ...)
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
obj_s->uart = (UARTName)pinmap_merge(uart_cts, uart_rts);
MBED_ASSERT(obj_s->uart != (UARTName)NC);
if(type == FlowControlNone) {
// Disable hardware flow control
obj_s->hw_flow_ctl = UART_HWCONTROL_NONE;
}
if (type == FlowControlRTS) {
// Enable RTS
MBED_ASSERT(uart_rts != (UARTName)NC);
obj_s->hw_flow_ctl = UART_HWCONTROL_RTS;
obj_s->pin_rts = rxflow;
// Enable the pin for RTS function
pinmap_pinout(rxflow, PinMap_UART_RTS);
}
if (type == FlowControlCTS) {
// Enable CTS
MBED_ASSERT(uart_cts != (UARTName)NC);
obj_s->hw_flow_ctl = UART_HWCONTROL_CTS;
obj_s->pin_cts = txflow;
// Enable the pin for CTS function
pinmap_pinout(txflow, PinMap_UART_CTS);
}
if (type == FlowControlRTSCTS) {
// Enable CTS & RTS
MBED_ASSERT(uart_rts != (UARTName)NC);
MBED_ASSERT(uart_cts != (UARTName)NC);
obj_s->hw_flow_ctl = UART_HWCONTROL_RTS_CTS;
obj_s->pin_rts = rxflow;
obj_s->pin_cts = txflow;
// Enable the pin for CTS function
pinmap_pinout(txflow, PinMap_UART_CTS);
// Enable the pin for RTS function
pinmap_pinout(rxflow, PinMap_UART_RTS);
}
init_uart(obj);
}
#endif /* DEVICE_SERIAL_FC */
#endif /* DEVICE_SERIAL */
|
the_stack_data/148576746.c | #include <string.h>
#define N 10000
static void*
pmemccpy(void *a1, void *a2, int c, size_t n)
{
char *s1, *s2;
s1 = a1;
s2 = a2;
while(n > 0) {
if((*s1++ = *s2++) == c)
return s1;
n--;
}
return 0;
}
char*
strcpy(char *s1, const char *s2)
{
char *os1;
os1 = s1;
while(!pmemccpy(s1, s2, 0, N)) {
s1 += N;
s2 += N;
}
return os1;
}
|
the_stack_data/301809.c | #include <stdio.h>
void main()
{
printf("\nHello World!\n");
//printf is a command to print output on the terminal the statement inside "" is printed.
// "\n" is used to move to the next line
return 0;
}
|
the_stack_data/20620.c | struct S {
char *Operator;
};
const struct S b1006_props = {
.Operator = "OR"
};
void foo(struct S x) {
char * s = x.Operator;
assert(s[0]=='O');
}
void bar(struct S *x) {
char * s = x->Operator;
assert(s[0]=='O');
}
int main()
{
assert(b1006_props.Operator[0]=='O');
foo(b1006_props);
bar(&b1006_props);
}
|
the_stack_data/234518046.c | #include <stdint.h>
struct Bar {
uint8_t foo[4096];
};
int da_func() {
struct Bar b = { 0 };
return 0;
}
|
the_stack_data/15761888.c | // clang-format off
// RUN: clang -S -emit-llvm %s -o - | opt -load %pluginpath/analysis/meminstfinderpass.so -load %pluginpath/%pluginname %pluginargs -S 2>&1 | FileCheck %s
// clang-format on
#include <stdlib.h>
typedef struct ms {
int a;
double b;
} mystruct;
void test() {
mystruct* m = (mystruct*)malloc(sizeof(mystruct));
free(m);
}
// CHECK: Malloc{{[ ]*}}:{{[ ]*}}1
// CHECK: Free{{[ ]*}}:{{[ ]*}}1
// CHECK: Alloca{{[ ]*}}:{{[ ]*}}0
|
the_stack_data/151705667.c | #include <stdio.h>
#include <string.h>
void main(){
int i;
char chrs[3];
char data;
char d1,d2;
for (i = 0; i < 256; i++){
sprintf(chrs,"%02x",i);
if(('0' <= chrs[0]) && (chrs[0] <= '9')){
d1 = chrs[0] - '0';
} else {
if (('a' <= chrs[0]) && (chrs[0] <= 'f')){
d1 = (chrs[0] - 'a') + 10;
} else {
d1 = (chrs[0] - 'A') + 10;
}
}
if(('0' <= chrs[1]) && (chrs[1] <= '9')){
d2 = chrs[1] - '0';
} else {
if (('a' <= chrs[1]) && (chrs[1] <= 'f')){
d2 = (chrs[1] - 'a') + 10;
} else {
d2 = (chrs[1] - 'A') + 10;
}
}
data = (d1 << 4) + (d2);
printf("%02x: %x - %x -> %02x\n", i, d1, d2,(data & 0x00FF));
}
}
|
the_stack_data/388485.c | /**ARGS: -DFOO1 -UFOO2 */
/**SYSCODE: = 1 | 16 */
#if defined(FOO1)
KEEP ME
#endif
|
the_stack_data/129019.c | // This is a modification of distance.c, which was released by Google as part
// of the word2vec code. Their original notice appears below.
// Copyright 2013 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 <stdio.h>
#include <string.h>
#include <math.h>
#include <malloc.h>
const long long max_size = 2000; // max length of strings
const long long N = 40; // number of closest words that will be shown
const long long max_w = 50; // max length of vocabulary entries
int main(int argc, char **argv) {
FILE *f, *fo;
char in_file[max_size], out_file[max_size];
float len;
long long words, size, a, b;
char ch;
float *M;
char *vocab;
if (argc < 3) {
printf("Usage: ./bin2text <IN-FILE> <OUT-FILE>\nwhere IN-FILE contains word projections in the BINARY FORMAT, and OUT-FILE is the output text file name\n");
return 0;
}
strcpy(in_file, argv[1]);
strcpy(out_file, argv[2]);
f = fopen(in_file, "rb");
if (f == NULL) {
printf("Input file not found\n");
return -1;
}
fscanf(f, "%lld", &words);
fscanf(f, "%lld", &size);
vocab = (char *)malloc((long long)words * max_w * sizeof(char));
M = (float *)malloc((long long)words * (long long)size * sizeof(float));
if (M == NULL) {
printf("Cannot allocate memory: %lld MB %lld %lld\n", (long long)words * size * sizeof(float) / 1048576, words, size);
return -1;
}
for (b = 0; b < words; b++) {
a = 0;
while (1) {
vocab[b * max_w + a] = fgetc(f);
if (feof(f) || (vocab[b * max_w + a] == ' ')) break;
if ((a < max_w) && (vocab[b * max_w + a] != '\n')) a++;
}
vocab[b * max_w + a] = 0;
for (a = 0; a < size; a++) fread(&M[a + b * size], sizeof(float), 1, f);
/* Don't normalize the vectors
len = 0;
for (a = 0; a < size; a++) len += M[a + b * size] * M[a + b * size];
len = sqrt(len);
for (a = 0; a < size; a++) M[a + b * size] /= len;
*/
}
fclose(f);
// Write the vectors to a text file
fo = fopen(out_file, "w");
fprintf(fo, "%lld %lld\n", words, size);
for (a = 0; a < words; a++) {
fprintf(fo, "%s ", &vocab[a * max_w]);
for (b = 0; b < size; b++) fprintf(fo, "%f ", M[a * size + b]);
fprintf(fo, "\n");
}
fclose(fo);
return 0;
} |
the_stack_data/7950155.c | /* $OpenBSD: ffs.c,v 1.8 2014/06/10 04:17:37 deraadt Exp $ */
/*
* Public domain.
* Written by Dale Rahn.
*/
#include <string.h>
/*
* ffs -- vax ffs instruction
*/
int
ffs(int mask)
{
int bit;
unsigned int r = mask;
static const signed char t[16] = {
-28, 1, 2, 1,
3, 1, 2, 1,
4, 1, 2, 1,
3, 1, 2, 1
};
bit = 0;
if (!(r & 0xffff)) {
bit += 16;
r >>= 16;
}
if (!(r & 0xff)) {
bit += 8;
r >>= 8;
}
if (!(r & 0xf)) {
bit += 4;
r >>= 4;
}
return (bit + t[ r & 0xf ]);
}
DEF_WEAK(ffs);
|
the_stack_data/548273.c | //Author: Amar Gwari Date: 06/10/19 Time: 20:08
#include<stdio.h>
int main()
{
long long int N,i=0,a=0,b,z;
printf("Please Enter The Number Of Your Choice\n");
scanf("%lld",&N);
for(i=1;i<=N/2;i++)
{
if(N%i == 0)
{
a+=i;
}
}
if(a == N)
printf("\nThe Number Is Perfect!\n");
else
printf("\nThe Number Is Not Perfect\n");
return 0;
}
|
the_stack_data/247578.c | #include<stdio.h>
int main()
{
float a,b,c;
scanf("%f",&a);
scanf("%f",&b);
scanf("%f",&c);
if(a>b){
if(a>c) printf("%.1f",a);
else printf("%.1f",a);
}
else{
if(c>b) printf("%.1f",c);
else printf("%.1f",b);
}
}
|
the_stack_data/745076.c | #include<stdio.h>
int main()
{
int N;
printf("enter case number:\n1=binary search\n2=linear search\n3=bubble sort\n4=merging");
scanf("%d",&N);
switch(N)
{
case 1:
binary_search();
case 2:
linear_search();
case 3:
bubble_sort();
case 4:
merging();
}
}
int binary_search()
{
int arr[1000],temp,len,i,j;
printf("Enter the length of the array: ");
scanf("%d",&len);
printf("\nEnter the elements in the array:\n");
for(i=0;i<len;i++)
{
scanf("%d",&arr[i]);
}
//BUBBLE SORT
for(i=0;i<len;i++)
{
for(j=0;j<len-1;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
//BINARY SEARCH
int high,low,mid,target;
printf("\nEnter the search key: ");
scanf("%d",&target);
low=0;
high=len-1;
while(high>=low)
{
mid=(low+(high-low))/2;
if(arr[mid]==target)
{
printf("Your Search key %d is found in the given array!",target);
break;
}
else if(arr[mid]<target)
{
low=mid+1;
}
else
{
high=mid-1;
}
}
return 0;
}
int linear_search()
{
int arr[1000],len,i,j,temp=0,index,search_key;
printf("Enter the length of the array: ");
scanf("%d",&len);
printf("\nEnter the numbers in array: ");
for(i=0;i<len;i++)
{
scanf("%d",&arr[i]);
}
printf("\n\n\t Enter the search key: ");
scanf("%d",&search_key);
for(i=0;i<len;i++)
{
if(arr[i]==search_key)
{
index=i;
temp=1;
printf("HURRAY! your search key %d is found in given array at index = %d",search_key,index);
break;
}
}
if(temp==0)
printf("-1");
return 0;
}
int bubble_sort()
{
int i,j,n,temp=0;
int a[10];
printf("enter the size of the array: ");
scanf("%d",&n);
printf("enter the array elements: \n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("your entered elements: \n");
for(i=0;i<n;i++)
printf("%d ",a[i]);
//bubble sorting
for(i=0;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("sorted elements: \n");
for(i=0;i<n;i++)
printf("%d ",a[i]);
return 0;
}
int merging()
{
int i,j,n1,n2,n;
int a1[10],a2[10],a3[10];
printf("\n enter the size of array1:");
scanf("%d",&n1);
printf("\nenter the size of array2: ");
scanf("%d",&n2);
printf("\nenter the elements of array1: ");
n=n1+n2;
for(i=0;i<n1;i++)
{
scanf("%d",&a1[i]);
}
printf("\narray1: ");
for(i=0;i<n1;i++)
printf("%d ",a1[i]);
printf("\nenter array2 elements: ");
for(i=0;i<n2;i++)
scanf("%d",&a2[i]);
printf("\narray2: ");
for(i=0;i<n2;i++)
printf("%d ",a2[i]);
for(i=0;i<n1;i++)
{
a3[i]=a1[i];
}
for(i=n1;i<n;i++)
{
a3[i]=a2[i-n1];
}
printf("\nMerged Array: ");
for(i=0;i<n;i++)
{
printf("%d ",a3[i]);
}
} |
the_stack_data/143708.c | /* Arithmetic instruction */
#include <stdint.h>
void main(void)
{
volatile uint8_t a = 0x7e, b = 0x19, c;
c = a - b;
c = 0; //$ch.c
return; //$bre
}
|
the_stack_data/15762653.c | #include <stdio.h>
void printMessage (void)
{
printf ("Programming is fun.\n");
}
int main (void)
{
int i = 1;
do
{ ++i;
printMessage ();
}
while (i < 10);
i = 10;
return 0;
} |
the_stack_data/179829732.c | #include <unistd.h>
void putstr(char *str)
{
int i;
i = 0;
while(*str)
write(1, str++, 1);
}
int strlen(char *str)
{
int i;
i = 0;
while (*str)
i++;
return (i);
}
char *search_and_replace(char *str, char a, char b)
{
int i;
i = -1;
while (str[++i])
if (str[i] == a)
str[i] = b;
return (str);
}
int main(int ac, char **av)
{
int i;
i = 0;
if (ac == 4)
if (strlen(av[2]) == 1 && strlen(av[3]) == 1)
putstr(search_and_replace(av[1][i], av[2][0], av[3][0]));
write(1, "\n", 1);
return (0);
}
|
the_stack_data/142480.c | /* original parser id follows */
/* yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" */
/* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */
#define YYBYACC 1
#define YYMAJOR 2
#define YYMINOR 0
#define YYCHECK "yyyymmdd"
#define YYEMPTY (-1)
#define yyclearin (yychar = YYEMPTY)
#define yyerrok (yyerrflag = 0)
#define YYRECOVERING() (yyerrflag != 0)
#define YYENOMEM (-2)
#define YYEOF 0
#ifndef yyparse
#define yyparse calc_parse
#endif /* yyparse */
#ifndef yylex
#define yylex calc_lex
#endif /* yylex */
#ifndef yyerror
#define yyerror calc_error
#endif /* yyerror */
#ifndef yychar
#define yychar calc_char
#endif /* yychar */
#ifndef yyval
#define yyval calc_val
#endif /* yyval */
#ifndef yylval
#define yylval calc_lval
#endif /* yylval */
#ifndef yydebug
#define yydebug calc_debug
#endif /* yydebug */
#ifndef yynerrs
#define yynerrs calc_nerrs
#endif /* yynerrs */
#ifndef yyerrflag
#define yyerrflag calc_errflag
#endif /* yyerrflag */
#ifndef yylhs
#define yylhs calc_lhs
#endif /* yylhs */
#ifndef yylen
#define yylen calc_len
#endif /* yylen */
#ifndef yydefred
#define yydefred calc_defred
#endif /* yydefred */
#ifndef yydgoto
#define yydgoto calc_dgoto
#endif /* yydgoto */
#ifndef yysindex
#define yysindex calc_sindex
#endif /* yysindex */
#ifndef yyrindex
#define yyrindex calc_rindex
#endif /* yyrindex */
#ifndef yygindex
#define yygindex calc_gindex
#endif /* yygindex */
#ifndef yytable
#define yytable calc_table
#endif /* yytable */
#ifndef yycheck
#define yycheck calc_check
#endif /* yycheck */
#ifndef yyname
#define yyname calc_name
#endif /* yyname */
#ifndef yyrule
#define yyrule calc_rule
#endif /* yyrule */
#define YYPREFIX "calc_"
#define YYPURE 0
#line 4 "code_calc.y"
# include <stdio.h>
# include <ctype.h>
int regs[26];
int base;
#ifdef YYBISON
int yylex(void);
static void yyerror(const char *s);
#endif
#line 113 "code_calc.code.c"
#if ! defined(YYSTYPE) && ! defined(YYSTYPE_IS_DECLARED)
/* Default: YYSTYPE is the semantic value type. */
typedef int YYSTYPE;
# define YYSTYPE_IS_DECLARED 1
#endif
/* compatibility with bison */
#ifdef YYPARSE_PARAM
/* compatibility with FreeBSD */
# ifdef YYPARSE_PARAM_TYPE
# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
# else
# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
# endif
#else
# define YYPARSE_DECL() yyparse(void)
#endif
/* Parameters sent to lex. */
#ifdef YYLEX_PARAM
# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
# define YYLEX yylex(YYLEX_PARAM)
#else
# define YYLEX_DECL() yylex(void)
# define YYLEX yylex()
#endif
/* Parameters sent to yyerror. */
#ifndef YYERROR_DECL
#define YYERROR_DECL() yyerror(const char *s)
#endif
#ifndef YYERROR_CALL
#define YYERROR_CALL(msg) yyerror(msg)
#endif
#define DIGIT 257
#define LETTER 258
#define UMINUS 259
#define YYERRCODE 256
#undef yytname
#define yytname yyname
#define YYTABLESIZE 220
#define YYFINAL 1
#ifndef YYDEBUG
#define YYDEBUG 0
#endif
#define YYMAXTOKEN 259
#define YYUNDFTOKEN 265
#define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
extern int YYPARSE_DECL();
typedef int YYINT;
extern YYINT yylhs[];
extern YYINT yylen[];
extern YYINT yydefred[];
extern YYINT yydgoto[];
extern YYINT yysindex[];
extern YYINT yyrindex[];
extern YYINT yygindex[];
extern YYINT yytable[];
extern YYINT yycheck[];
#if YYDEBUG || defined(yytname)
extern char *yyname[];
#endif
#if YYDEBUG
extern char *yyrule[];
#endif
#if YYDEBUG
int yydebug;
#endif
int yyerrflag;
int yychar;
YYSTYPE yyval;
YYSTYPE yylval;
int yynerrs;
/* define the initial stack-sizes */
#ifdef YYSTACKSIZE
#undef YYMAXDEPTH
#define YYMAXDEPTH YYSTACKSIZE
#else
#ifdef YYMAXDEPTH
#define YYSTACKSIZE YYMAXDEPTH
#else
#define YYSTACKSIZE 10000
#define YYMAXDEPTH 10000
#endif
#endif
#define YYINITSTACKSIZE 200
typedef struct {
unsigned stacksize;
YYINT *s_base;
YYINT *s_mark;
YYINT *s_last;
YYSTYPE *l_base;
YYSTYPE *l_mark;
} YYSTACKDATA;
/* variables for the parser stack */
static YYSTACKDATA yystack;
#line 70 "code_calc.y"
/* start of programs */
#ifdef YYBYACC
extern int YYLEX_DECL();
#endif
int
main (void)
{
while(!feof(stdin)) {
yyparse();
}
return 0;
}
static void
yyerror(const char *s)
{
fprintf(stderr, "%s\n", s);
}
int
yylex(void)
{
/* lexical analysis routine */
/* returns LETTER for a lower case letter, yylval = 0 through 25 */
/* return DIGIT for a digit, yylval = 0 through 9 */
/* all other characters are returned immediately */
int c;
while( (c=getchar()) == ' ' ) { /* skip blanks */ }
/* c is now nonblank */
if( islower( c )) {
yylval = c - 'a';
return ( LETTER );
}
if( isdigit( c )) {
yylval = c - '0';
return ( DIGIT );
}
return( c );
}
#line 265 "code_calc.code.c"
#if YYDEBUG
#include <stdio.h> /* needed for printf */
#endif
#include <stdlib.h> /* needed for malloc, etc */
#include <string.h> /* needed for memset */
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
static int yygrowstack(YYSTACKDATA *data)
{
int i;
unsigned newsize;
YYINT *newss;
YYSTYPE *newvs;
if ((newsize = data->stacksize) == 0)
newsize = YYINITSTACKSIZE;
else if (newsize >= YYMAXDEPTH)
return YYENOMEM;
else if ((newsize *= 2) > YYMAXDEPTH)
newsize = YYMAXDEPTH;
i = (int) (data->s_mark - data->s_base);
newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss));
if (newss == 0)
return YYENOMEM;
data->s_base = newss;
data->s_mark = newss + i;
newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
if (newvs == 0)
return YYENOMEM;
data->l_base = newvs;
data->l_mark = newvs + i;
data->stacksize = newsize;
data->s_last = data->s_base + newsize - 1;
return 0;
}
#if YYPURE || defined(YY_NO_LEAKS)
static void yyfreestack(YYSTACKDATA *data)
{
free(data->s_base);
free(data->l_base);
memset(data, 0, sizeof(*data));
}
#else
#define yyfreestack(data) /* nothing */
#endif
#define YYABORT goto yyabort
#define YYREJECT goto yyabort
#define YYACCEPT goto yyaccept
#define YYERROR goto yyerrlab
int
YYPARSE_DECL()
{
int yym, yyn, yystate;
#if YYDEBUG
const char *yys;
if ((yys = getenv("YYDEBUG")) != 0)
{
yyn = *yys;
if (yyn >= '0' && yyn <= '9')
yydebug = yyn - '0';
}
#endif
/* yym is set below */
/* yyn is set below */
yynerrs = 0;
yyerrflag = 0;
yychar = YYEMPTY;
yystate = 0;
#if YYPURE
memset(&yystack, 0, sizeof(yystack));
#endif
if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
yystack.s_mark = yystack.s_base;
yystack.l_mark = yystack.l_base;
yystate = 0;
*yystack.s_mark = 0;
yyloop:
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
if (yychar < 0)
{
yychar = YYLEX;
if (yychar < 0) yychar = YYEOF;
#if YYDEBUG
if (yydebug)
{
if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
printf("%sdebug: state %d, reading %d (%s)\n",
YYPREFIX, yystate, yychar, yys);
}
#endif
}
if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, shifting to state %d\n",
YYPREFIX, yystate, yytable[yyn]);
#endif
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
yystate = yytable[yyn];
*++yystack.s_mark = yytable[yyn];
*++yystack.l_mark = yylval;
yychar = YYEMPTY;
if (yyerrflag > 0) --yyerrflag;
goto yyloop;
}
if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
{
yyn = yytable[yyn];
goto yyreduce;
}
if (yyerrflag != 0) goto yyinrecovery;
YYERROR_CALL("syntax error");
goto yyerrlab; /* redundant goto avoids 'unused label' warning */
yyerrlab:
++yynerrs;
yyinrecovery:
if (yyerrflag < 3)
{
yyerrflag = 3;
for (;;)
{
if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, error recovery shifting\
to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
#endif
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
yystate = yytable[yyn];
*++yystack.s_mark = yytable[yyn];
*++yystack.l_mark = yylval;
goto yyloop;
}
else
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: error recovery discarding state %d\n",
YYPREFIX, *yystack.s_mark);
#endif
if (yystack.s_mark <= yystack.s_base) goto yyabort;
--yystack.s_mark;
--yystack.l_mark;
}
}
}
else
{
if (yychar == YYEOF) goto yyabort;
#if YYDEBUG
if (yydebug)
{
if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
YYPREFIX, yystate, yychar, yys);
}
#endif
yychar = YYEMPTY;
goto yyloop;
}
yyreduce:
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
YYPREFIX, yystate, yyn, yyrule[yyn]);
#endif
yym = yylen[yyn];
if (yym > 0)
yyval = yystack.l_mark[1-yym];
else
memset(&yyval, 0, sizeof yyval);
switch (yyn)
{
case 3:
#line 32 "code_calc.y"
{ yyerrok ; }
#line 467 "code_calc.code.c"
break;
case 4:
#line 36 "code_calc.y"
{ printf("%d\n",yystack.l_mark[0]);}
#line 472 "code_calc.code.c"
break;
case 5:
#line 38 "code_calc.y"
{ regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
#line 477 "code_calc.code.c"
break;
case 6:
#line 42 "code_calc.y"
{ yyval = yystack.l_mark[-1]; }
#line 482 "code_calc.code.c"
break;
case 7:
#line 44 "code_calc.y"
{ yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
#line 487 "code_calc.code.c"
break;
case 8:
#line 46 "code_calc.y"
{ yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
#line 492 "code_calc.code.c"
break;
case 9:
#line 48 "code_calc.y"
{ yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
#line 497 "code_calc.code.c"
break;
case 10:
#line 50 "code_calc.y"
{ yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
#line 502 "code_calc.code.c"
break;
case 11:
#line 52 "code_calc.y"
{ yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
#line 507 "code_calc.code.c"
break;
case 12:
#line 54 "code_calc.y"
{ yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
#line 512 "code_calc.code.c"
break;
case 13:
#line 56 "code_calc.y"
{ yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
#line 517 "code_calc.code.c"
break;
case 14:
#line 58 "code_calc.y"
{ yyval = - yystack.l_mark[0]; }
#line 522 "code_calc.code.c"
break;
case 15:
#line 60 "code_calc.y"
{ yyval = regs[yystack.l_mark[0]]; }
#line 527 "code_calc.code.c"
break;
case 17:
#line 65 "code_calc.y"
{ yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
#line 532 "code_calc.code.c"
break;
case 18:
#line 67 "code_calc.y"
{ yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
#line 537 "code_calc.code.c"
break;
#line 539 "code_calc.code.c"
}
yystack.s_mark -= yym;
yystate = *yystack.s_mark;
yystack.l_mark -= yym;
yym = yylhs[yyn];
if (yystate == 0 && yym == 0)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: after reduction, shifting from state 0 to\
state %d\n", YYPREFIX, YYFINAL);
#endif
yystate = YYFINAL;
*++yystack.s_mark = YYFINAL;
*++yystack.l_mark = yyval;
if (yychar < 0)
{
yychar = YYLEX;
if (yychar < 0) yychar = YYEOF;
#if YYDEBUG
if (yydebug)
{
if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
printf("%sdebug: state %d, reading %d (%s)\n",
YYPREFIX, YYFINAL, yychar, yys);
}
#endif
}
if (yychar == YYEOF) goto yyaccept;
goto yyloop;
}
if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
yystate = yytable[yyn];
else
yystate = yydgoto[yym];
#if YYDEBUG
if (yydebug)
printf("%sdebug: after reduction, shifting from state %d \
to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
#endif
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
*++yystack.s_mark = (YYINT) yystate;
*++yystack.l_mark = yyval;
goto yyloop;
yyoverflow:
YYERROR_CALL("yacc stack overflow");
yyabort:
yyfreestack(&yystack);
return (1);
yyaccept:
yyfreestack(&yystack);
return (0);
}
|
the_stack_data/215463.c | /*
ID: lxdlam1
LANG: C
TASK: palsquare
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
char *tobase(int base, int num);
int isPal(char src[]);
char *reverseString(char src[]);
int main()
{
FILE *fin = fopen("palsquare.in", "r");
FILE *fout = fopen("palsquare.out", "w");
int base, i;
fscanf(fin, "%d", &base);
for (i = 0; i <= 300; i++)
{
if (isPal(tobase(base, i * i)))
fprintf(fout, "%s %s\n", reverseString(tobase(base, i)), tobase(base, i * i));
}
fclose(fin);
fclose(fout);
return 0;
}
char *tobase(int base, int num)
{
int i;
char *str = (char *)calloc(32, sizeof(char));
for (i = 0; num > 0; i++)
{
if (num % base <= 9)
*(str + i) = num % base + '0';
else
{
switch (num % base)
{
case 10:
*(str + i) = 'A';
break;
case 11:
*(str + i) = 'B';
break;
case 12:
*(str + i) = 'C';
break;
case 13:
*(str + i) = 'D';
break;
case 14:
*(str + i) = 'E';
break;
case 15:
*(str + i) = 'F';
break;
case 16:
*(str + i) = 'G';
break;
case 17:
*(str + i) = 'H';
break;
case 18:
*(str + i) = 'I';
break;
case 19:
*(str + i) = 'J';
break;
default:
break;
}
}
num /= base;
}
return str;
}
int isPal(char src[])
{
int i;
for (i = 0; i <= strlen(src) / 2; i++)
{
if (src[i] != src[strlen(src) - 1 - i] || src[0] == '\0')
return 0;
}
return 1;
}
char *reverseString(char src[])
{
int i;
char temp;
for (i = 0; i < strlen(src) / 2; i++)
{
temp = src[i];
src[i] = src[strlen(src) - 1 - i];
src[strlen(src) - 1 - i] = temp;
}
return src;
} |
the_stack_data/176705403.c | int main(int argc, char **argv)
{
__CPROVER_assume(argc == 1);
assert(argc == 1);
}
|
the_stack_data/941565.c | #include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#define PORT 8080
#define HOSTLEN 256
#define oops(msg) {perror(msg); exit(1);}
int main(int argc, char** argv) {
struct sockaddr_in saddr;
struct hostent* hp;
char hostname[HOSTLEN];
int sock_id, sock_fd;
FILE* sock_fp;
time_t thetime;
// step1: ask kerenl for a socket.
sock_id = socket(AF_INET, SOCK_STREAM, 0);
if (sock_id == -1) {
oops("socket");
}
// step2: bind address to socket: address = host + port.
bzero((void*)&saddr, sizeof(saddr));
gethostname(hostname, HOSTLEN);
hp = gethostbyname(hostname);
bcopy((void*)hp->h_addr, (void*)&saddr.sin_addr, hp->h_length);
saddr.sin_port = htons(PORT);
saddr.sin_family = AF_INET;
printf("%s %d\n", hostname, saddr.sin_port);
if (bind(sock_id, (struct sockaddr*)&saddr, sizeof(saddr)) != 0)
oops("bind");
// Step3: allow incoming calls with Qsize = 1 on socket.
if (listen(sock_id, 1) != 0) {
oops("listen");
}
// main loop: accept, wirte, close
while (1) {
sock_fd = accept(sock_id, NULL, NULL);
printf("Wow, get a call\n");
if (sock_id == -1) {
oops("accept");
}
sock_fp = fdopen(sock_fd, "w");
if (sock_fp == NULL) {
oops("fdopen");
}
thetime = time(NULL);
fprintf(sock_fp, "The time here is...");
fprintf(sock_fp, "%s", ctime(&thetime));
fclose(sock_fp);
}
} |
the_stack_data/675581.c | #include <stdio.h>
int main()
{
printf("Hello\n");
return 0;
} |
the_stack_data/87638863.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: slammari <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/06 17:38:20 by slammari #+# #+# */
/* Updated: 2021/10/09 18:04:11 by slammari ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
i++;
}
return (i);
}
|
the_stack_data/5743.c |
#include "stdio.h"
#include <stdarg.h>
#include <string.h>
int __android_log_print(int prio, const char *tag, const char *fmt, ...)
{
va_list ap;
char buf[256];
va_start(ap, fmt);
if(strncmp(fmt, "This application", 15)==0){
return 0;
}
vsnprintf(buf, 256, fmt, ap);
va_end(ap);
return puts(buf);
}
|
the_stack_data/51699272.c | #include <limits.h>
int main(void)
{
int x = INT_MIN;
x--;
}
|
the_stack_data/68887140.c | /*
* System call names.
*
* DO NOT EDIT-- this file is automatically generated.
* created from Id: syscalls.master,v 1.55.2.1 1999/05/05 22:53:05 dt Exp
*/
char *syscallnames[] = {
"syscall", /* 0 = syscall */
"exit", /* 1 = exit */
"fork", /* 2 = fork */
"read", /* 3 = read */
"write", /* 4 = write */
"open", /* 5 = open */
"close", /* 6 = close */
"wait4", /* 7 = wait4 */
"old.creat", /* 8 = old creat */
"link", /* 9 = link */
"unlink", /* 10 = unlink */
"obs_execv", /* 11 = obsolete execv */
"chdir", /* 12 = chdir */
"fchdir", /* 13 = fchdir */
"mknod", /* 14 = mknod */
"chmod", /* 15 = chmod */
"chown", /* 16 = chown */
"break", /* 17 = break */
"getfsstat", /* 18 = getfsstat */
"old.lseek", /* 19 = old lseek */
"getpid", /* 20 = getpid */
"mount", /* 21 = mount */
"unmount", /* 22 = unmount */
"setuid", /* 23 = setuid */
"getuid", /* 24 = getuid */
"geteuid", /* 25 = geteuid */
"ptrace", /* 26 = ptrace */
"recvmsg", /* 27 = recvmsg */
"sendmsg", /* 28 = sendmsg */
"recvfrom", /* 29 = recvfrom */
"accept", /* 30 = accept */
"getpeername", /* 31 = getpeername */
"getsockname", /* 32 = getsockname */
"access", /* 33 = access */
"chflags", /* 34 = chflags */
"fchflags", /* 35 = fchflags */
"sync", /* 36 = sync */
"kill", /* 37 = kill */
"old.stat", /* 38 = old stat */
"getppid", /* 39 = getppid */
"old.lstat", /* 40 = old lstat */
"dup", /* 41 = dup */
"pipe", /* 42 = pipe */
"getegid", /* 43 = getegid */
"profil", /* 44 = profil */
"ktrace", /* 45 = ktrace */
"sigaction", /* 46 = sigaction */
"getgid", /* 47 = getgid */
"sigprocmask", /* 48 = sigprocmask */
"getlogin", /* 49 = getlogin */
"setlogin", /* 50 = setlogin */
"acct", /* 51 = acct */
"sigpending", /* 52 = sigpending */
"sigaltstack", /* 53 = sigaltstack */
"ioctl", /* 54 = ioctl */
"reboot", /* 55 = reboot */
"revoke", /* 56 = revoke */
"symlink", /* 57 = symlink */
"readlink", /* 58 = readlink */
"execve", /* 59 = execve */
"umask", /* 60 = umask */
"chroot", /* 61 = chroot */
"old.fstat", /* 62 = old fstat */
"old.getkerninfo", /* 63 = old getkerninfo */
"old.getpagesize", /* 64 = old getpagesize */
"msync", /* 65 = msync */
"vfork", /* 66 = vfork */
"obs_vread", /* 67 = obsolete vread */
"obs_vwrite", /* 68 = obsolete vwrite */
"sbrk", /* 69 = sbrk */
"sstk", /* 70 = sstk */
"old.mmap", /* 71 = old mmap */
"vadvise", /* 72 = vadvise */
"munmap", /* 73 = munmap */
"mprotect", /* 74 = mprotect */
"madvise", /* 75 = madvise */
"obs_vhangup", /* 76 = obsolete vhangup */
"obs_vlimit", /* 77 = obsolete vlimit */
"mincore", /* 78 = mincore */
"getgroups", /* 79 = getgroups */
"setgroups", /* 80 = setgroups */
"getpgrp", /* 81 = getpgrp */
"setpgid", /* 82 = setpgid */
"setitimer", /* 83 = setitimer */
"old.wait", /* 84 = old wait */
"swapon", /* 85 = swapon */
"getitimer", /* 86 = getitimer */
"old.gethostname", /* 87 = old gethostname */
"old.sethostname", /* 88 = old sethostname */
"getdtablesize", /* 89 = getdtablesize */
"dup2", /* 90 = dup2 */
"#91", /* 91 = getdopt */
"fcntl", /* 92 = fcntl */
"select", /* 93 = select */
"#94", /* 94 = setdopt */
"fsync", /* 95 = fsync */
"setpriority", /* 96 = setpriority */
"socket", /* 97 = socket */
"connect", /* 98 = connect */
"old.accept", /* 99 = old accept */
"getpriority", /* 100 = getpriority */
"old.send", /* 101 = old send */
"old.recv", /* 102 = old recv */
"sigreturn", /* 103 = sigreturn */
"bind", /* 104 = bind */
"setsockopt", /* 105 = setsockopt */
"listen", /* 106 = listen */
"obs_vtimes", /* 107 = obsolete vtimes */
"old.sigvec", /* 108 = old sigvec */
"old.sigblock", /* 109 = old sigblock */
"old.sigsetmask", /* 110 = old sigsetmask */
"sigsuspend", /* 111 = sigsuspend */
"old.sigstack", /* 112 = old sigstack */
"old.recvmsg", /* 113 = old recvmsg */
"old.sendmsg", /* 114 = old sendmsg */
"obs_vtrace", /* 115 = obsolete vtrace */
"gettimeofday", /* 116 = gettimeofday */
"getrusage", /* 117 = getrusage */
"getsockopt", /* 118 = getsockopt */
"#119", /* 119 = resuba */
"readv", /* 120 = readv */
"writev", /* 121 = writev */
"settimeofday", /* 122 = settimeofday */
"fchown", /* 123 = fchown */
"fchmod", /* 124 = fchmod */
"old.recvfrom", /* 125 = old recvfrom */
"setreuid", /* 126 = setreuid */
"setregid", /* 127 = setregid */
"rename", /* 128 = rename */
"old.truncate", /* 129 = old truncate */
"old.ftruncate", /* 130 = old ftruncate */
"flock", /* 131 = flock */
"mkfifo", /* 132 = mkfifo */
"sendto", /* 133 = sendto */
"shutdown", /* 134 = shutdown */
"socketpair", /* 135 = socketpair */
"mkdir", /* 136 = mkdir */
"rmdir", /* 137 = rmdir */
"utimes", /* 138 = utimes */
"obs_4.2", /* 139 = obsolete 4.2 sigreturn */
"adjtime", /* 140 = adjtime */
"old.getpeername", /* 141 = old getpeername */
"old.gethostid", /* 142 = old gethostid */
"old.sethostid", /* 143 = old sethostid */
"old.getrlimit", /* 144 = old getrlimit */
"old.setrlimit", /* 145 = old setrlimit */
"old.killpg", /* 146 = old killpg */
"setsid", /* 147 = setsid */
"quotactl", /* 148 = quotactl */
"old.quota", /* 149 = old quota */
"old.getsockname", /* 150 = old getsockname */
"#151", /* 151 = sem_lock */
"#152", /* 152 = sem_wakeup */
"#153", /* 153 = asyncdaemon */
"#154", /* 154 = nosys */
"nfssvc", /* 155 = nfssvc */
"old.getdirentries", /* 156 = old getdirentries */
"statfs", /* 157 = statfs */
"fstatfs", /* 158 = fstatfs */
"#159", /* 159 = nosys */
"#160", /* 160 = nosys */
"getfh", /* 161 = getfh */
"getdomainname", /* 162 = getdomainname */
"setdomainname", /* 163 = setdomainname */
"uname", /* 164 = uname */
"sysarch", /* 165 = sysarch */
"rtprio", /* 166 = rtprio */
"#167", /* 167 = nosys */
"#168", /* 168 = nosys */
"semsys", /* 169 = semsys */
"msgsys", /* 170 = msgsys */
"shmsys", /* 171 = shmsys */
"#172", /* 172 = nosys */
"pread", /* 173 = pread */
"pwrite", /* 174 = pwrite */
"#175", /* 175 = nosys */
"ntp_adjtime", /* 176 = ntp_adjtime */
"#177", /* 177 = sfork */
"#178", /* 178 = getdescriptor */
"#179", /* 179 = setdescriptor */
"#180", /* 180 = nosys */
"setgid", /* 181 = setgid */
"setegid", /* 182 = setegid */
"seteuid", /* 183 = seteuid */
"#184", /* 184 = lfs_bmapv */
"#185", /* 185 = lfs_markv */
"#186", /* 186 = lfs_segclean */
"#187", /* 187 = lfs_segwait */
"stat", /* 188 = stat */
"fstat", /* 189 = fstat */
"lstat", /* 190 = lstat */
"pathconf", /* 191 = pathconf */
"fpathconf", /* 192 = fpathconf */
"#193", /* 193 = nosys */
"getrlimit", /* 194 = getrlimit */
"setrlimit", /* 195 = setrlimit */
"getdirentries", /* 196 = getdirentries */
"mmap", /* 197 = mmap */
"__syscall", /* 198 = __syscall */
"lseek", /* 199 = lseek */
"truncate", /* 200 = truncate */
"ftruncate", /* 201 = ftruncate */
"__sysctl", /* 202 = __sysctl */
"mlock", /* 203 = mlock */
"munlock", /* 204 = munlock */
"undelete", /* 205 = undelete */
"futimes", /* 206 = futimes */
"getpgid", /* 207 = getpgid */
"#208", /* 208 = newreboot */
"poll", /* 209 = poll */
"lkmnosys", /* 210 = lkmnosys */
"lkmnosys", /* 211 = lkmnosys */
"lkmnosys", /* 212 = lkmnosys */
"lkmnosys", /* 213 = lkmnosys */
"lkmnosys", /* 214 = lkmnosys */
"lkmnosys", /* 215 = lkmnosys */
"lkmnosys", /* 216 = lkmnosys */
"lkmnosys", /* 217 = lkmnosys */
"lkmnosys", /* 218 = lkmnosys */
"lkmnosys", /* 219 = lkmnosys */
"__semctl", /* 220 = __semctl */
"semget", /* 221 = semget */
"semop", /* 222 = semop */
"semconfig", /* 223 = semconfig */
"msgctl", /* 224 = msgctl */
"msgget", /* 225 = msgget */
"msgsnd", /* 226 = msgsnd */
"msgrcv", /* 227 = msgrcv */
"shmat", /* 228 = shmat */
"shmctl", /* 229 = shmctl */
"shmdt", /* 230 = shmdt */
"shmget", /* 231 = shmget */
"clock_gettime", /* 232 = clock_gettime */
"clock_settime", /* 233 = clock_settime */
"clock_getres", /* 234 = clock_getres */
"#235", /* 235 = timer_create */
"#236", /* 236 = timer_delete */
"#237", /* 237 = timer_settime */
"#238", /* 238 = timer_gettime */
"#239", /* 239 = timer_getoverrun */
"nanosleep", /* 240 = nanosleep */
"#241", /* 241 = nosys */
"#242", /* 242 = nosys */
"#243", /* 243 = nosys */
"#244", /* 244 = nosys */
"#245", /* 245 = nosys */
"#246", /* 246 = nosys */
"#247", /* 247 = nosys */
"#248", /* 248 = nosys */
"#249", /* 249 = nosys */
"minherit", /* 250 = minherit */
"rfork", /* 251 = rfork */
"openbsd_poll", /* 252 = openbsd_poll */
"issetugid", /* 253 = issetugid */
"lchown", /* 254 = lchown */
"#255", /* 255 = nosys */
"#256", /* 256 = nosys */
"#257", /* 257 = nosys */
"#258", /* 258 = nosys */
"#259", /* 259 = nosys */
"#260", /* 260 = nosys */
"#261", /* 261 = nosys */
"#262", /* 262 = nosys */
"#263", /* 263 = nosys */
"#264", /* 264 = nosys */
"#265", /* 265 = nosys */
"#266", /* 266 = nosys */
"#267", /* 267 = nosys */
"#268", /* 268 = nosys */
"#269", /* 269 = nosys */
"#270", /* 270 = nosys */
"#271", /* 271 = nosys */
"getdents", /* 272 = getdents */
"#273", /* 273 = nosys */
"lchmod", /* 274 = lchmod */
"netbsd_lchown", /* 275 = netbsd_lchown */
"lutimes", /* 276 = lutimes */
"netbsd_msync", /* 277 = netbsd_msync */
"nstat", /* 278 = nstat */
"nfstat", /* 279 = nfstat */
"nlstat", /* 280 = nlstat */
"#281", /* 281 = nosys */
"#282", /* 282 = nosys */
"#283", /* 283 = nosys */
"#284", /* 284 = nosys */
"#285", /* 285 = nosys */
"#286", /* 286 = nosys */
"#287", /* 287 = nosys */
"#288", /* 288 = nosys */
"#289", /* 289 = nosys */
"#290", /* 290 = nosys */
"#291", /* 291 = nosys */
"#292", /* 292 = nosys */
"#293", /* 293 = nosys */
"#294", /* 294 = nosys */
"#295", /* 295 = nosys */
"#296", /* 296 = nosys */
"#297", /* 297 = nosys */
"#298", /* 298 = nosys */
"#299", /* 299 = nosys */
"modnext", /* 300 = modnext */
"modstat", /* 301 = modstat */
"modfnext", /* 302 = modfnext */
"modfind", /* 303 = modfind */
"kldload", /* 304 = kldload */
"kldunload", /* 305 = kldunload */
"kldfind", /* 306 = kldfind */
"kldnext", /* 307 = kldnext */
"kldstat", /* 308 = kldstat */
"kldfirstmod", /* 309 = kldfirstmod */
"getsid", /* 310 = getsid */
"#311", /* 311 = setresuid */
"#312", /* 312 = setresgid */
"obs_signanosleep", /* 313 = obsolete signanosleep */
"aio_return", /* 314 = aio_return */
"aio_suspend", /* 315 = aio_suspend */
"aio_cancel", /* 316 = aio_cancel */
"aio_error", /* 317 = aio_error */
"aio_read", /* 318 = aio_read */
"aio_write", /* 319 = aio_write */
"lio_listio", /* 320 = lio_listio */
"yield", /* 321 = yield */
"thr_sleep", /* 322 = thr_sleep */
"thr_wakeup", /* 323 = thr_wakeup */
"mlockall", /* 324 = mlockall */
"munlockall", /* 325 = munlockall */
"__getcwd", /* 326 = __getcwd */
"sched_setparam", /* 327 = sched_setparam */
"sched_getparam", /* 328 = sched_getparam */
"sched_setscheduler", /* 329 = sched_setscheduler */
"sched_getscheduler", /* 330 = sched_getscheduler */
"sched_yield", /* 331 = sched_yield */
"sched_get_priority_max", /* 332 = sched_get_priority_max */
"sched_get_priority_min", /* 333 = sched_get_priority_min */
"sched_rr_get_interval", /* 334 = sched_rr_get_interval */
"utrace", /* 335 = utrace */
"sendfile", /* 336 = sendfile */
"kldsym", /* 337 = kldsym */
};
|
the_stack_data/775045.c | /*
decrypt smime AES encrypted DER binary files that are larger than 1.5GB
by Imre Fitos 2018
based on Dr Stephen N. Henson's suggestion from 2011
to work around the malloc failure
https://groups.google.com/forum/#!topic/mailing.openssl.users/xCxyJyEgjGU
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <openssl/crypto.h>
#include <openssl/pem.h>
#include <openssl/pkcs7.h>
#include <openssl/err.h>
int main (int argc, char *argv[])
{
struct stat sb;
off_t len;
void *p;
int fd;
BIO *in = NULL, *privbio = NULL;
BIO *out = BIO_new_fp(stdout, BIO_NOCLOSE);
EVP_PKEY *rkey = NULL;
PKCS7 *p7 = NULL;
int ret = 1;
OpenSSL_add_all_algorithms();
ERR_load_crypto_strings();
if (argc != 3) {
fprintf (stderr, "usage: %s <privkey> <infile> > outfile\n", argv[0]);
return 1;
}
/* read private key */
privbio = BIO_new_file(argv[1], "r");
if (!privbio)
goto err;
fprintf(stderr, "About to read priv key\n");
rkey = PEM_read_bio_PrivateKey(privbio, NULL, 0, NULL);
/* read file to decrypt */
fd = open (argv[2], O_RDONLY);
if (fd == -1) {
perror ("open");
return 1;
}
if (fstat (fd, &sb) == -1) {
perror ("fstat");
return 1;
}
if (!S_ISREG (sb.st_mode)) {
fprintf (stderr, "%s is not a file\n", argv[3]);
return 1;
}
p = mmap (NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (p == MAP_FAILED) {
perror ("mmap");
return 1;
}
if (close (fd) == -1) {
perror ("close");
return 1;
}
fprintf(stderr, "About to read encrypted file\n");
p7 = d2i_PKCS7(NULL, (const unsigned char **)&p, sb.st_size);
if (!p7)
goto err;
fprintf(stderr, "About to decrypt encrypted file\n");
if (!PKCS7_decrypt(p7, rkey, NULL, out, 0))
goto err;
/* letting the OS take care of it until I find out why it EINVALs
if (munmap ((void *) p, sb.st_size) == -1) {
perror ("munmap");
return 1;
}
*/
return 0;
err:
if (ret) {
fprintf(stderr, "EROR:\n");
ERR_print_errors_fp(stderr);
}
PKCS7_free(p7);
EVP_PKEY_free(rkey);
BIO_free(out);
BIO_free(privbio);
return ret;
}
|
the_stack_data/1262203.c | /*
* linux/fs/ext3/bitmap.c
*
* Copyright (C) 1992, 1993, 1994, 1995
* Remy Card ([email protected])
* Laboratoire MASI - Institut Blaise Pascal
* Universite Pierre et Marie Curie (Paris VI)
*/
#ifdef EXT3FS_DEBUG
#include <linux/buffer_head.h>
#include "ext3_fs.h"
static int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0};
unsigned long ext3_count_free (struct buffer_head * map, unsigned int numchars)
{
unsigned int i;
unsigned long sum = 0;
if (!map)
return (0);
for (i = 0; i < numchars; i++)
sum += nibblemap[map->b_data[i] & 0xf] +
nibblemap[(map->b_data[i] >> 4) & 0xf];
return (sum);
}
#endif /* EXT3FS_DEBUG */
|
the_stack_data/72012617.c | /***
* This code is a part of EvoApproxLib library (ehw.fit.vutbr.cz/approxlib) distributed under The MIT License.
* When used, please cite the following article(s): V. Mrazek, L. Sekanina, Z. Vasicek "Libraries of Approximate Circuits: Automated Design and Application in CNN Accelerators" IEEE Journal on Emerging and Selected Topics in Circuits and Systems, Vol 10, No 4, 2020
* This file contains a circuit from a sub-set of pareto optimal circuits with respect to the pwr and ep parameters
***/
// MAE% = 0.073 %
// MAE = 3.0
// WCE% = 0.29 %
// WCE = 12
// WCRE% = 100.00 %
// EP% = 70.90 %
// MRE% = 1.67 %
// MSE = 16
// PDK45_PWR = 0.114 mW
// PDK45_AREA = 284.4 um2
// PDK45_DELAY = 1.00 ns
#include <stdint.h>
#include <stdlib.h>
uint64_t mul8x4u_577(const uint64_t A,const uint64_t B)
{
uint64_t dout_12, dout_15, dout_16, dout_17, dout_18, dout_19, dout_22, dout_23, dout_24, dout_25, dout_26, dout_27, dout_35, dout_36, dout_40, dout_41, dout_43, dout_44, dout_45, dout_46, dout_47, dout_48, dout_49, dout_50, dout_51, dout_52, dout_53, dout_54, dout_55, dout_56, dout_57, dout_58, dout_59, dout_60, dout_61, dout_63, dout_64, dout_65, dout_66, dout_67, dout_68, dout_69, dout_72, dout_73, dout_77, dout_78, dout_79, dout_80, dout_81, dout_82, dout_83, dout_84, dout_85, dout_86, dout_87, dout_88, dout_89, dout_90, dout_91, dout_92, dout_93, dout_94, dout_95, dout_96, dout_97, dout_98, dout_99, dout_100, dout_101, dout_102, dout_103, dout_104, dout_105, dout_106, dout_107, dout_108, dout_109, dout_110, dout_111, dout_112, dout_113, dout_114, dout_115, dout_116, dout_117, dout_118, dout_119, dout_120, dout_121, dout_122, dout_123, dout_124, dout_125, dout_126, dout_127, dout_128, dout_129, dout_130, dout_131, dout_132, dout_133, dout_134, dout_135, dout_136, dout_137, dout_138, dout_139, dout_140, dout_141, dout_142, dout_143, dout_144, dout_145, dout_146, dout_147, dout_148, dout_149, dout_150, dout_151;
uint64_t O;
dout_12=((A >> 1)&1)&((B >> 0)&1);
dout_15=((A >> 3)&1)&((B >> 0)&1);
dout_16=((A >> 4)&1)&((B >> 0)&1);
dout_17=((A >> 5)&1)&((B >> 0)&1);
dout_18=((A >> 6)&1)&((B >> 0)&1);
dout_19=((A >> 7)&1)&((B >> 0)&1);
dout_22=((A >> 2)&1)&((B >> 1)&1);
dout_23=((A >> 3)&1)&((B >> 1)&1);
dout_24=((A >> 4)&1)&((B >> 1)&1);
dout_25=((A >> 5)&1)&((B >> 1)&1);
dout_26=((A >> 6)&1)&((B >> 1)&1);
dout_27=((A >> 7)&1)&((B >> 1)&1);
dout_35=dout_15|dout_22;
dout_36=dout_15&dout_22;
dout_40=dout_16^dout_23;
dout_41=dout_16&dout_23;
dout_43=dout_40^dout_36;
dout_44=dout_41|dout_36;
dout_45=dout_17^dout_24;
dout_46=dout_17&dout_24;
dout_47=dout_45&dout_44;
dout_48=dout_45^dout_44;
dout_49=dout_46|dout_47;
dout_50=dout_18^dout_25;
dout_51=dout_18&dout_25;
dout_52=dout_50&dout_49;
dout_53=dout_50^dout_49;
dout_54=dout_51|dout_52;
dout_55=dout_19^dout_26;
dout_56=dout_19&dout_26;
dout_57=dout_55&dout_54;
dout_58=dout_55^dout_54;
dout_59=dout_56|dout_57;
dout_60=dout_59&dout_27;
dout_61=dout_59^dout_27;
dout_63=((A >> 1)&1)&((B >> 2)&1);
dout_64=((A >> 2)&1)&((B >> 2)&1);
dout_65=((A >> 3)&1)&((B >> 2)&1);
dout_66=((A >> 4)&1)&((B >> 2)&1);
dout_67=((A >> 5)&1)&((B >> 2)&1);
dout_68=((A >> 6)&1)&((B >> 2)&1);
dout_69=((A >> 7)&1)&((B >> 2)&1);
dout_72=dout_35|dout_63;
dout_73=dout_35&dout_63;
dout_77=dout_43^dout_64;
dout_78=dout_43&dout_64;
dout_79=dout_77&dout_73;
dout_80=dout_77^dout_73;
dout_81=dout_78|dout_79;
dout_82=dout_48^dout_65;
dout_83=dout_48&dout_65;
dout_84=dout_82&dout_81;
dout_85=dout_82^dout_81;
dout_86=dout_83|dout_84;
dout_87=dout_53^dout_66;
dout_88=dout_53&dout_66;
dout_89=dout_87&dout_86;
dout_90=dout_87^dout_86;
dout_91=dout_88|dout_89;
dout_92=dout_58^dout_67;
dout_93=dout_58&dout_67;
dout_94=dout_92&dout_91;
dout_95=dout_92^dout_91;
dout_96=dout_93|dout_94;
dout_97=dout_61^dout_68;
dout_98=dout_61&dout_68;
dout_99=dout_97&dout_96;
dout_100=dout_97^dout_96;
dout_101=dout_98|dout_99;
dout_102=dout_60^dout_69;
dout_103=dout_59&dout_69;
dout_104=dout_102&dout_101;
dout_105=dout_102^dout_101;
dout_106=dout_103|dout_104;
dout_107=((A >> 0)&1)&((B >> 3)&1);
dout_108=((A >> 1)&1)&((B >> 3)&1);
dout_109=((A >> 2)&1)&((B >> 3)&1);
dout_110=((A >> 3)&1)&((B >> 3)&1);
dout_111=((A >> 4)&1)&((B >> 3)&1);
dout_112=((A >> 5)&1)&((B >> 3)&1);
dout_113=((A >> 6)&1)&((B >> 3)&1);
dout_114=((A >> 7)&1)&((B >> 3)&1);
dout_115=dout_72&dout_107;
dout_116=dout_72|dout_107;
dout_117=dout_80^dout_108;
dout_118=dout_80&dout_108;
dout_119=dout_117&dout_115;
dout_120=dout_117^dout_115;
dout_121=dout_118|dout_119;
dout_122=dout_85^dout_109;
dout_123=dout_85&dout_109;
dout_124=dout_122&dout_121;
dout_125=dout_122^dout_121;
dout_126=dout_123|dout_124;
dout_127=dout_90^dout_110;
dout_128=dout_90&dout_110;
dout_129=dout_127&dout_126;
dout_130=dout_127^dout_126;
dout_131=dout_128|dout_129;
dout_132=dout_95^dout_111;
dout_133=dout_95&dout_111;
dout_134=dout_132&dout_131;
dout_135=dout_132^dout_131;
dout_136=dout_133|dout_134;
dout_137=dout_100^dout_112;
dout_138=dout_100&dout_112;
dout_139=dout_137&dout_136;
dout_140=dout_137^dout_136;
dout_141=dout_138|dout_139;
dout_142=dout_105^dout_113;
dout_143=dout_105&dout_113;
dout_144=dout_142&dout_141;
dout_145=dout_142^dout_141;
dout_146=dout_143|dout_144;
dout_147=dout_106^dout_114;
dout_148=dout_106&((B >> 3)&1);
dout_149=dout_114&dout_146;
dout_150=dout_147^dout_146;
dout_151=dout_148|dout_149;
O = 0;
O |= (dout_12&1) << 0;
O |= (dout_25&1) << 1;
O |= (0&1) << 2;
O |= (dout_116&1) << 3;
O |= (dout_120&1) << 4;
O |= (dout_125&1) << 5;
O |= (dout_130&1) << 6;
O |= (dout_135&1) << 7;
O |= (dout_140&1) << 8;
O |= (dout_145&1) << 9;
O |= (dout_150&1) << 10;
O |= (dout_151&1) << 11;
return O;
}
|
the_stack_data/117327454.c | #include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define MAX_STRING 256
main(int argc, char *argv[])
{
char buffer[MAX_STRING];
int format;
int number;
int i,value;
char c;
if (argc != 3){
sprintf(buffer, "usage: es1_2 {0|1]} number_of_integers\n");
write(2, buffer, strlen(buffer));
sprintf(buffer, " 0--> escribe los numeros en ascii\n");
write(2, buffer, strlen(buffer));
sprintf(buffer, " 1--> escribe los numeros en formato int\n");
write(2, buffer, strlen(buffer));
exit(1);
}
format=atoi(argv[1]);
if ((format != 0) && (format != 1)){
sprintf(buffer, "usage: es1_2 {0|1]}\n");
write(2, buffer, strlen(buffer));
exit(1);
}
number=atoi(argv[2]);
sprintf(buffer,"............................\n");
write(2,buffer,strlen(buffer));
sprintf(buffer,"Si argv[1]==0 escribiremos los numero en ascii, sino en formato interno (int)\n");
write(2,buffer,strlen(buffer));
sprintf(buffer,"............................\n");
write(2,buffer,strlen(buffer));
srand(time(NULL));
c='\n';
for(i=0;i<number;i++){
// Generamos numeros aleatorios
value=rand();
if (format == 1){
// Escribimos el numero=4 bytes, y un '\n'
write(1,&value,sizeof(value));
write(1,&c,sizeof(c));
} else{
// En este caso escribimos el numero en ascii
// con un \n al final tambien
sprintf(buffer,"%d\n",value);
write(1,buffer, strlen(buffer));
}
}
}
|
the_stack_data/165767163.c | void
foo (void)
{
int i;
#pragma omp for schedule(static, 1)
for (i = 0; i < 10; i++)
;
#pragma omp for schedule(static, 0) /* { dg-warning "chunk size value must be positive" } */
for (i = 0; i < 10; i++)
;
#pragma omp for schedule(static, -7) /* { dg-warning "chunk size value must be positive" } */
for (i = 0; i < 10; i++)
;
}
|
the_stack_data/84680.c | /*
* Originally by Linus Torvalds.
* Smart CONFIG_* processing by Werner Almesberger, Michael Chastain.
*
* Usage: mkdep cflags -- file ...
*
* Read source files and output makefile dependency lines for them.
* I make simple dependency lines for #include <*.h> and #include "*.h".
* I also find instances of CONFIG_FOO and generate dependencies
* like include/config/foo.h.
*
* 1 August 1999, Michael Elizabeth Chastain, <[email protected]>
* - Keith Owens reported a bug in smart config processing. There used
* to be an optimization for "#define CONFIG_FOO ... #ifdef CONFIG_FOO",
* so that the file would not depend on CONFIG_FOO because the file defines
* this symbol itself. But this optimization is bogus! Consider this code:
* "#if 0 \n #define CONFIG_FOO \n #endif ... #ifdef CONFIG_FOO". Here
* the definition is inactivated, but I still used it. It turns out this
* actually happens a few times in the kernel source. The simple way to
* fix this problem is to remove this particular optimization.
*
* 2.3.99-pre1, Andrew Morton <[email protected]>
* - Changed so that 'filename.o' depends upon 'filename.[cS]'. This is so that
* missing source files are noticed, rather than silently ignored.
*
* 2.4.2-pre3, Keith Owens <[email protected]>
* - Accept cflags followed by '--' followed by filenames. mkdep extracts -I
* options from cflags and looks in the specified directories as well as the
* defaults. Only -I is supported, no attempt is made to handle -idirafter,
* -isystem, -I- etc.
*
* Aug 2003: stephan beal <[email protected]>
* - removed HPATH requirement for use in the toc project (toc.sourceforge.net)
*
* Aug 2003: rusty <[email protected]>
* Other changes for use in toc/libfunUtil:
* - Add support for C++ file extensions .cc, .C, .c++, .cxx, .cpp.
* (Previously, this was doing "a" right thing, by making foo.c++ depend on
* the headers #included by foo.c++, with a "touch foo.c++" rule which
* would then cause the .o file to be out of date, but "the" right thing is
* for foo.o to depend on the headers #included by foo.c++. I guess there
* aren't many C++ files in the Linux kernel tree, ha ha.)
*
* Dec 2003: [email protected]
* Changes for toc.sourceforge.net:
* - removed the default 'touch' behaviour to avoid collissions with targets
* generated via toc.
*
* 20 Aug 2004: [email protected]
* - Removed unused hpath from main(). WTF does gcc NOW start to
* complain about that!?!?!?
* - Added some parens to keep gcc from bitching (again... why now?
* Been compiling w/o complaint for over a year).
*
* 7 April 2005: [email protected]
* - Made an -Isomedir dir lookup failure non-fatal, because it often
* happens when using a custom --prefix when configuring a tree to
* build under, e.g. ~/tmp.
*
* 8 June 2007: [email protected]
* - Added creation of empty target for files which have no explicit deps.
* This avoids the "no rule to create ..." when a file is moved/deleted.*
*
* 16 June 2007: [email protected]
* - Removed all CONFIG-related code (~150 lines), as it is not useful
* outside of the linux kernel (original home of this code) and it
* greatly decreases the readability of this code.
*
*/
#include <ctype.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
/**
TOC_MODE enables:
- no 'touch'ing of targets, to avoid overriding
rules defined elsewhere in toc.
*/
#define TOC_MODE 1
char __depname[512] = "\n\t@touch ";
#define depname (__depname+9)
int hasdep;
struct path_struct {
int len;
char *buffer;
};
struct path_struct *path_array;
int paths;
/* Current input file */
static const char *g_filename;
/*
* This records all the configuration options seen.
* In perl this would be a hash, but here it's a long string
* of values separated by newlines. This is simple and
* extremely fast.
*/
char * str_config = NULL;
int size_config = 0;
int len_config = 0;
static void
do_depname(void)
{
if (!hasdep) {
hasdep = 1;
//printf( "depname=%s, g_filename=%s", depname, g_filename );
printf("%s:", depname);
if (g_filename)
printf(" %s", g_filename);
}
}
/*
* This records all the precious .h filenames. No need for a hash,
* it's a long string of values enclosed in tab and newline.
*/
char * str_precious = NULL;
int size_precious = 0;
int len_precious = 0;
/*
* Grow the precious string to a desired length.
* Usually the first growth is plenty.
*/
void grow_precious(int len)
{
while (len_precious + len > size_precious) {
if (size_precious == 0)
size_precious = 2048;
str_precious = realloc(str_precious, size_precious *= 2);
if (str_precious == NULL)
{ perror("malloc"); exit(1); }
}
}
/*
* Add a new value to the precious string.
*/
void define_precious(const char * filename)
{
int len = strlen(filename);
grow_precious(len + 4);
*(str_precious+len_precious++) = '\t';
memcpy(str_precious+len_precious, filename, len);
len_precious += len;
memcpy(str_precious+len_precious, " \\\n", 3);
len_precious += 3;
}
/*
* Handle an #include line.
*/
void handle_include(int start, const char * name, int len)
{
struct path_struct *path;
int i;
for (i = start, path = path_array+start; i < paths; ++i, ++path) {
memcpy(path->buffer+path->len, name, len);
path->buffer[path->len+len] = '\0';
if (access(path->buffer, F_OK) == 0) {
do_depname();
printf(" \\\n %s", path->buffer);
return;
}
}
}
/*
* Add a path to the list of include paths.
*/
void add_path(const char * name)
{
struct path_struct *path;
char resolved_path[PATH_MAX+1];
const char *name2;
if (strcmp(name, ".")) {
name2 = realpath(name, resolved_path);
if (!name2) {
return; /* added by [email protected], because i don't care about this failure. */
/* fprintf(stderr, "realpath(%s) failed, %m\n", name); */
/* exit(1); */
}
}
else {
name2 = "";
}
path_array = realloc(path_array, (++paths)*sizeof(*path_array));
if (!path_array) {
fprintf(stderr, "cannot expand path_arry\n");
exit(1);
}
path = path_array+paths-1;
path->len = strlen(name2);
path->buffer = malloc(path->len+1+256+1);
if (!path->buffer) {
fprintf(stderr, "cannot allocate path buffer\n");
exit(1);
}
strcpy(path->buffer, name2);
if (path->len && *(path->buffer+path->len-1) != '/') {
*(path->buffer+path->len) = '/';
*(path->buffer+(++(path->len))) = '\0';
}
}
/*
* Macros for stunningly fast map-based character access.
* __buf is a register which holds the current word of the input.
* Thus, there is one memory access per sizeof(unsigned long) characters.
*/
#if defined(__alpha__) || defined(__i386__) || defined(__ia64__) || defined(__x86_64__) || defined(__MIPSEL__) \
|| defined(__arm__)
#define LE_MACHINE
#endif
#ifdef LE_MACHINE
#define next_byte(x) (x >>= 8)
#define current ((unsigned char) __buf)
#else
#define next_byte(x) (x <<= 8)
#define current (__buf >> 8*(sizeof(unsigned long)-1))
#endif
#define GETNEXT { \
next_byte(__buf); \
if ((unsigned long) next % sizeof(unsigned long) == 0) { \
if (next >= end) \
break; \
__buf = * (unsigned long *) next; \
} \
next++; \
}
/*
* State machine macros.
*/
#define CASE(c,label) if (current == c) goto label
#define NOTCASE(c,label) if (current != c) goto label
/*
* Yet another state machine speedup.
*/
#define MAX2(a,b) ((a)>(b)?(a):(b))
#define MIN2(a,b) ((a)<(b)?(a):(b))
#define MAX4(a,b,c,d) (MAX2(a,MAX2(b,MAX2(c,d))))
#define MIN4(a,b,c,d) (MIN2(a,MIN2(b,MIN2(c,d))))
/*
* The state machine looks for (approximately) these Perl regular expressions:
*
* m|\/\*.*?\*\/|
* m|\/\/.*|
* m|'.*?'|
* m|".*?"|
* m|#\s*include\s*"(.*?)"|
* m|#\s*include\s*<(.*?>"|
*
* About 98% of the CPU time is spent here, and most of that is in
* the 'start' paragraph. Because the current characters are
* in a register, the start loop usually eats 4 or 8 characters
* per memory read. The MAX4 and MIN4 tests dispose of most
* input characters with 1 or 2 comparisons.
*/
void state_machine(const char * map, const char * end)
{
const char * next = map;
const char * map_dot;
unsigned long __buf = 0;
for (;;) {
start:
GETNEXT
__start:
if (current > MAX4('/','\'','"','#')) goto start;
if (current < MIN4('/','\'','"','#')) goto start;
CASE('/', slash);
CASE('\'', squote);
CASE('"', dquote);
CASE('#', pound);
goto start;
/* // */
slash_slash:
GETNEXT
CASE('\n', start);
NOTCASE('\\', slash_slash);
GETNEXT
goto slash_slash;
/* / */
slash:
GETNEXT
CASE('/', slash_slash);
NOTCASE('*', __start);
slash_star_dot_star:
GETNEXT
__slash_star_dot_star:
NOTCASE('*', slash_star_dot_star);
GETNEXT
NOTCASE('/', __slash_star_dot_star);
goto start;
/* '.*?' */
squote:
GETNEXT
CASE('\'', start);
NOTCASE('\\', squote);
GETNEXT
goto squote;
/* ".*?" */
dquote:
GETNEXT
CASE('"', start);
NOTCASE('\\', dquote);
GETNEXT
goto dquote;
/* #\s* */
pound:
GETNEXT
CASE(' ', pound);
CASE('\t', pound);
CASE('i', pound_i);
goto __start;
/* #\s*i */
pound_i:
GETNEXT NOTCASE('n', __start);
GETNEXT NOTCASE('c', __start);
GETNEXT NOTCASE('l', __start);
GETNEXT NOTCASE('u', __start);
GETNEXT NOTCASE('d', __start);
GETNEXT NOTCASE('e', __start);
goto pound_include;
/* #\s*include\s* */
pound_include:
GETNEXT
CASE(' ', pound_include);
CASE('\t', pound_include);
map_dot = next;
CASE('"', pound_include_dquote);
CASE('<', pound_include_langle);
goto __start;
/* #\s*include\s*"(.*)" */
pound_include_dquote:
GETNEXT
CASE('\n', start);
NOTCASE('"', pound_include_dquote);
handle_include(0, map_dot, next - map_dot - 1);
goto start;
/* #\s*include\s*<(.*)> */
pound_include_langle:
GETNEXT
CASE('\n', start);
NOTCASE('>', pound_include_langle);
handle_include(1, map_dot, next - map_dot - 1);
goto start;
}
}
/*
* Generate dependencies for one file.
*/
void do_depend(const char * filename, const char * command)
{
int mapsize;
int pagesizem1 = getpagesize()-1;
int fd;
struct stat st;
char * map;
fd = open(filename, O_RDONLY);
if (fd < 0) {
fprintf(stderr,"cannot open file: %s\n",filename);
return;
}
fstat(fd, &st);
if (st.st_size == 0) {
fprintf(stderr,"%s is empty\n",filename);
close(fd);
return;
}
mapsize = st.st_size;
mapsize = (mapsize+pagesizem1) & ~pagesizem1;
map = mmap(NULL, mapsize, PROT_READ, MAP_PRIVATE, fd, 0);
if ((long) map == -1) {
fprintf(stderr,"mmap failed\n");
close(fd);
return;
}
if ((unsigned long) map % sizeof(unsigned long) != 0)
{
fprintf(stderr, "do_depend: map not aligned\n");
exit(1);
}
hasdep = 0;
state_machine(map, map+st.st_size);
if (hasdep) {
puts(command);
if (*command)
define_precious(filename);
}
else
{
// Create empty target to avoid "no rule to create ..." when we delete/rename a file:
printf("%s:\n", filename);
}
munmap(map, mapsize);
close(fd);
}
/*
* Generate dependencies for all files.
*/
int main(int argc, char **argv)
{
int len;
add_path("."); /* for #include "..." */
while (++argv, --argc > 0) {
if (strncmp(*argv, "-I", 2) == 0) {
if (*((*argv)+2) ) {
add_path((*argv)+2);
}
else {
++argv;
--argc;
}
}
else if (strcmp(*argv, "--") == 0) {
break;
}
}
while (--argc > 0) {
const char * filename = *++argv;
#if TOC_MODE
const char * command = "";
#else
const char * command = __depname;
#endif
g_filename = 0;
len = strlen(filename);
memcpy(depname, filename, len+1);
if (len > 2 && filename[len-2] == '.') {
if (filename[len-1] == 'c' ||
filename[len-1] == 'S' ||
filename[len-1] == 'C') {
depname[len-1] = 'o';
g_filename = filename;
command = "";
}
}
else if (len > 3 && filename[len-3] == '.') {
if (filename[len-2] == 'c' && filename[len-1] == 'c') {
depname[len-2] = 'o';
depname[len-1] = '\0';
g_filename = filename;
command = "";
}
}
else if (len > 4 && filename[len-4] == '.') {
if ( filename[len-3] == 'c' && // check for c++/cxx/cpp
(
(filename[len-2] == '+' && filename[len-1] == '+') ||
(filename[len-2] == 'x' && filename[len-1] == 'x') ||
(filename[len-2] == 'p' && filename[len-1] == 'p')
)
) {
depname[len-3] = 'o';
depname[len-2] = '\0';
g_filename = filename;
command = "";
}
}
do_depend(filename, command);
}
if (len_precious) {
*(str_precious+len_precious) = '\0';
printf(".PRECIOUS:%s\n", str_precious);
}
return 0;
}
|
the_stack_data/42708.c | void p();
void q();
void printf();
enum nevin {X=3, Y=10};
int i;
main () {
p();
printf("%d\n", i);
q();
printf("%d\n", i);
}
void p() {
enum dino { L=1, S=2};
i = L;
}
void q() {
enum dino { L=3, S=4};
i = L;
}
|
the_stack_data/202316.c | #include <stdio.h>
#include<malloc.h>
void flip(int *a, int end_index){
int bgng=0, temp;
while(bgng<end_index){
temp=*(a+end_index);
*(a+end_index)=*(a+bgng);
*(a+bgng)=temp;
bgng++;
end_index--;
}
}
int MAX(const int *a, int end_index){
int max=0, i;
for(i=0; i<end_index; i++){
if(*(a+i)>*(a+max))
max=i;
}
return max;
}
void pancake(int *a, int n){
int current_size=n;
for(current_size=n; current_size>1; current_size--){
int max=MAX(a, current_size);
if(max!=current_size-1){
flip(a, max);
flip(a, current_size-1);
}
}
}
int main() {
int *a, i, n;
printf("\nenter the no.of elements in the array: ");
scanf("%d", &n);
a=(int*)malloc(n*sizeof(int));
printf("\nenter the array: ");
for(i=0; i<n; i++)
scanf("%d", a+i);
pancake(a, n);
printf("\n");
for(i=0; i<n; i++)
printf("%d ", *(a+i));
return 0;
} |
the_stack_data/150139222.c | #include <stdlib.h>
typedef struct gs_imager_state_s {
struct {
int half_width;
int cap;
float miter_limit;
} line_params;
} gs_imager_state;
static const gs_imager_state gstate_initial = { { 1 } };
void gstate_path_memory(gs_imager_state *pgs) {
*pgs = gstate_initial;
}
int gs_state_update_overprint(void)
{
return gstate_initial.line_params.half_width;
}
extern void abort (void);
int main()
{
if (gs_state_update_overprint() != 1)
abort ();
return 0;
}
|
the_stack_data/43480.c | /*****************************************************************************
*
* $Id: fixwav.c 18 2011-03-09 21:47:56Z mjeffe $
*
* DESCRITION
* This fixes wav files created by audiofile, which I use to digitize
* my records. audiofile doesn't know how big the file will be when
* it starts to sample, so it just slams some big number in the "file
* size" positions of the wav file header. This program slams the
* appropriate modified file size into the required positions of the
* wav file header.
*
*
* NOTES
* It will only work for 16 bit sample rate, 44kHz wav files.
*
****************************************************************************/
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
/*
* globals
*/
char *me;
struct stat buf;
/*
* function prototypes
*/
int process_file(char *file_name);
/*************************************************************************
* MAIN
************************************************************************/
int main(int argc, char *argv[]) {
int i;
char *filename;
me = argv[0]; /* set the global variable with this programs name */
/* process each input file on the command line */
if ( argc < 2 ) {
fprintf(stderr, "%s: missing file to process\n", me);
fprintf(stderr, "usage: %s file1 [file2 ...]\n", me);
exit(1);
} else {
for ( i=1; i<argc; i++ ) {
process_file(argv[i]);
}
}
return(0);
}
/*************************************************************************
* fix wav file
************************************************************************/
int process_file(char *file_name) {
FILE *infile;
int i;
unsigned int size1 = 0;
unsigned int size2 = 0;
/* open intput file */
infile = fopen(file_name, "r+b");
if (infile == NULL) {
fprintf(stderr, "%s: unable to open %s\n", me, file_name);
exit(1);
}
/* find out how big the file is */
fstat(fileno(infile), &buf);
size1 = buf.st_size - 8;
size2 = buf.st_size - 44;
/*
* first file size is at offset 0x04 (bytes 5 - 8)
* This is the (file size) - 8
*/
fseek(infile, 4, SEEK_SET);
fwrite(&size1, 4, 1, infile);
/*
* second file size is at bytes 41 - 44
* This is the (file size) - 44
*/
fseek(infile, 40, SEEK_SET);
fwrite(&size2, 4, 1, infile);
/* close the input file */
fclose(infile);
return(0);
}
|
the_stack_data/85508.c | #include<stdio.h>
double f(int x){
double n=1;
int i;
for(i=1;i<=x;i++) n=n*i;
return n;
}
int main(){
int m,n,x;
scanf("%d%d",&m,&n);
if(n==0) printf("0");
else{
x=f(m)/(f(n)*f(m-n));
printf("%d",x);
return 0;}
} |
the_stack_data/14199016.c | // This file tests that -fprofile-sample-use enables location tracking
// generation in the same way that -Rpass does. The sample profiler needs
// to associate line locations in the profile to the code, so it needs the
// frontend to emit source location annotations.
// RUN: %clang_cc1 %s -fprofile-sample-use=%S/Inputs/profile-sample-use-loc-tracking.prof -emit-llvm -o - 2>/dev/null | FileCheck %s
// -fprofile-sample-use should produce source location annotations, exclusively
// (just like -gmlt).
// CHECK: , !dbg !
// CHECK-NOT: DW_TAG_base_type
// The CU should be marked NoDebug (to prevent writing debug info to
// the final output).
// CHECK: !llvm.dbg.cu = !{![[CU:.*]]}
// CHECK: ![[CU]] = distinct !DICompileUnit({{.*}}emissionKind: NoDebug
int bar(int j) {
return (j + j - 2) * (j - 2) * j;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.