file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/419083.c
|
/*BEGIN_LEGAL
Intel Open Source License
Copyright (c) 2002-2015 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution. Neither the name of
the Intel Corporation nor the names of its contributors may be used to
endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
ITS 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.
END_LEGAL */
/*
* This test prints the application's blocked signal mask at various points.
* By comparing a native run with a run under Pin, we can verify that Pin emulates
* the signal mask correctly.
*/
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#ifdef TARGET_ANDROID
#include "android_ucontext.h"
#else
#include <sys/ucontext.h>
#endif
#if defined(TARGET_MAC) || (TARGET_ANDROID)
#define MAXMASK 32
#else
#define MAXMASK 64
#endif
static void Handle(int);
static void PrintCurrentMask(const char *);
static void PrintMask(const char *, sigset_t *);
int main()
{
struct sigaction act;
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, SIGSTOP);
sigaddset(&mask, SIGFPE);
if (sigprocmask(SIG_SETMASK, &mask, 0) != 0)
{
fprintf(stderr, "unable to set blocked signal mask\n");
return 1;
}
PrintCurrentMask("Initial: ");
act.sa_handler = Handle;
act.sa_flags = SA_NODEFER;
sigemptyset(&act.sa_mask);
sigaddset(&act.sa_mask, SIGSEGV);
sigaddset(&act.sa_mask, SIGHUP);
sigaddset(&act.sa_mask, SIGKILL);
if (sigaction(SIGUSR1, &act, 0) != 0)
{
fprintf(stderr, "Unable to set USR1 handler\n");
return 1;
}
act.sa_flags = 0;
if (sigaction(SIGUSR2, &act, 0) != 0)
{
fprintf(stderr, "Unable to set USR2 handler\n");
return 1;
}
raise(SIGUSR1);
PrintCurrentMask("After USR1: ");
raise(SIGUSR2);
PrintCurrentMask("After USR2: ");
sigemptyset(&act.sa_mask);
if (sigaction(SIGUSR1, 0, &act) != 0)
{
fprintf(stderr, "Unable to get USR1 hander\n");
return 1;
}
PrintMask("USR1 Blocks: ", &act.sa_mask);
sigemptyset(&act.sa_mask);
if (sigaction(SIGUSR2, 0, &act) != 0)
{
fprintf(stderr, "Unable to get USR2 hander\n");
return 1;
}
PrintMask("USR2 Blocks: ", &act.sa_mask);
return 0;
}
static void Handle(int sig)
{
if (sig == SIGUSR1)
PrintCurrentMask("USR1 handler: ");
else if (sig == SIGUSR2)
PrintCurrentMask("USR2 handler: ");
else
{
fprintf(stderr, "Unexpected signal %d\n", sig);
exit(1);
}
}
static void PrintCurrentMask(const char *prefix)
{
sigset_t mask;
if (sigprocmask(SIG_SETMASK, 0, &mask) == 0)
PrintMask(prefix, &mask);
else
printf("%s[ERROR]\n", prefix);
}
static void PrintMask(const char *prefix, sigset_t *mask)
{
int sig;
int first;
first = 1;
printf("%s[", prefix);
for (sig = 1; sig < MAXMASK; sig++)
{
if (sigismember(mask, sig))
{
if (!first)
printf(" ");
first = 0;
printf("%d", sig);
}
}
printf("]\n");
}
|
the_stack_data/154829471.c
|
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(void)
{
int i, j, k, random;
printf("딥러닝 연산중임\n");
printf("Tensor 기반 연산이다보니 시간이 for 루프가 많음\n");
printf("하드웨어 장치에서 데이터를 가져와서 처리하고 있음\n");
printf("그런데 데이터가 갑자기 누락되어서 연산 자체를 폐기해야 하는 상황임\n");
printf("우리가 실제 에러를 만들 순 없으니 특정한 순간을 가정하고 진행함\n");
// 난수 생성을 위한 시드값 초기화
srand(time(NULL));
random = rand() % 3;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
for (k = 0; k < 3; k++)
{
if (j == random)
{
printf("data: %3d, Error!\n", random);
break;
}
printf("i = %3d, j = %3d, k = %d\n", i, j, k);
}
}
}
return 0;
}
|
the_stack_data/62636706.c
|
// Making "COFFEE" using "Grid system" [version 3]
// ----------------------------------------------------
#include<stdio.h>
void main()
{
for (int r = 1; r <= 10; r++)
{
for (int c = 1; c <= 41; c++)
{
// For "C"------------------------------// For "O"-----------------------------------------------------// For "F"-----------------------------------------------// For "2nd F"-----------------------------------------// For "E"------------------------------------------------------// For "2nd E"-------------------------------------------------|
//if ( (r==1&&c<=6)||(c==1)||(r==10&&c<=6) || (r==1&&c>=8&&c<=13)||(r==10&&c>=8&&c<=13)||(c==8)||(c==13) || (c==15)||(r==1&&c>=15&&c<=20)||(r==5&&c>=15&&c<=18) || (c==22)||(r==1&&c>=22&&c<=27)||(r==5&&c>=22&&c<=25) || (c==29)||((r==1||r==10)&&c>=29&&c<=34)||(r==5&&c>=29&&c<=32) || (c==36)||((r==1||r==10)&&c>=36&&c<=41)||(r==5&&c>=36&&c<=39))
if ((c==1||c==8||c==13||c==22||c==36||c==15||c==29) || ((r==1||r==10)&&c<=6) || ((r==1||r==10)&&c>=8&&c<=13)||(r==1&&c>=15&&c<=20)||(r==5&&((c>=15&&c<=18)||(c>=22&&c<=25))) || (r==1&&c>=22&&c<=27) || ((r==1||r==10)&&((c>=29&&c<=34)||(c>=36&&c<=41))) || (r==5&&((c>=29&&c<=32)||(c>=36&&39))))
printf("##",r);
else
printf(" ");
// }
// For "O"
// if ((r==1 && c>=8 && c<=13 )||(r==10 && c >= 8 && c <= 13 ))
// printf("*",r);
// else
// printf("");
}
printf("\n");
}
}
// Code by Abel Roy //
|
the_stack_data/170452798.c
|
typedef struct
{
char *op;
char *description;
} OperatorMapping;
OperatorMapping op_mapping[] = {
{ "b", "Close, fill, and stroke path using nonzero winding number rule" },
{ "B", "Fill and stroke path using nonzero winding number rule" },
{ "b*", "Close, fill, and stroke path using even-odd rule" },
{ "B*", "Fill and stroke path using even-odd rule" },
{ "BDC", "(PDF 1.2) Begin marked-content sequence with property list" },
{ "BI", "Begin inline image object" },
{ "BMC", "(PDF 1.2) Begin marked-content sequence" },
{ "BT", "Begin text object" },
{ "BX", "(PDF 1.1) Begin compatibility section" },
{ "c", "Append curved segment to path (three control points)" },
{ "cm", "Concatenate matrix to current transformation matrix" },
{ "CS", "(PDF 1.1) Set color space for stroking operations" },
{ "cs", "(PDF 1.1) Set color space for nonstroking operations" },
{ "d", "Set line dash pattern" },
{ "d0", "Set glyph width in Type 3 font" },
{ "d1", "Set glyph width and bounding box in Type 3 font" },
{ "Do", "Invoke named XObject" },
{ "DP", "(PDF 1.2) Define marked-content point with property list" },
{ "EI", "End inline image object" },
{ "EMC", "(PDF 1.2) End marked-content sequence" },
{ "ET", "End text object" },
{ "EX", "(PDF 1.1) End compatibility section" },
{ "f", "Fill path using nonzero winding number rule" },
{ "F", "Fill path using nonzero winding number rule (obsolete)" },
{ "f*", "Fill path using even-odd rule" },
{ "G", "Set gray level for stroking operations" },
{ "g", "Set gray level for nonstroking operations" },
{ "gs", "(PDF 1.2) Set parameters from graphics state parameter dictionary" },
{ "h", "Close subpath" },
{ "i", "Set flatness tolerance" },
{ "ID", "Begin inline image data" },
{ "j", "Set line join style" },
{ "J", "Set line cap style" },
{ "K", "Set CMYK color for stroking operations" },
{ "k", "Set CMYK color for nonstroking operations" },
{ "l", "Append straight line segment to path" },
{ "m", "Begin new subpath" },
{ "M", "Set miter limit" },
{ "MP", "(PDF 1.2) Define marked-content point" },
{ "n", "End path without filling or stroking" },
{ "q", "Save graphics state" },
{ "Q", "Restore graphics state" },
{ "re", "Append rectangle to path" },
{ "RG", "Set RGB color for stroking operations" },
{ "rg", "Set RGB color for nonstroking operations" },
{ "ri", "Set color rendering intent" },
{ "s", "Close and stroke path" },
{ "S", "Stroke path" },
{ "SC", "(PDF 1.1) Set color for stroking operations" },
{ "sc", "(PDF 1.1) Set color for nonstroking operations" },
{ "SCN", "(PDF 1.2) Set color for stroking operations (ICCBased and special color spaces)" },
{ "scn", "(PDF 1.2) Set color for nonstroking operations (ICCBased and special color spaces)" },
{ "sh", "(PDF 1.3) Paint area defined by shading pattern" },
{ "T*", "Move to start of next text line" },
{ "Tc", "Set character spacing" },
{ "Td", "Move text position" },
{ "TD", "Move text position and set leading" },
{ "Tf", "Set text font and size" },
{ "Tj", "Show text" },
{ "TJ", "Show text, allowing individual glyph positioning" },
{ "TL", "Set text leading" },
{ "Tm", "Set text matrix and text line matrix" },
{ "Tr", "Set text rendering mode" },
{ "Ts", "Set text rise" },
{ "Tw", "Set word spacing" },
{ "Tz", "Set horizontal text scaling" },
{ "v", "Append curved segment to path (initial point replicated)" },
{ "w", "Set line width" },
{ "W", "Set clipping path using nonzero winding number rule" },
{ "W*", "Set clipping path using even-odd rule" },
{ "y", "Append curved segment to path (final point replicated)" },
{ "'", "Move to next line and show text" },
{ "\"", "Set word and character spacing, move to next line, and show text" },
};
|
the_stack_data/170453410.c
|
int main(){
int a,b,c;
a = 10;
b = 14;
c = a < b;
return c;
}
|
the_stack_data/236325.c
|
// RUN: not %clang %s -cake-is-lie -%0 -%d -HHHH -munknown-to-clang-option -print-stats -funknown-to-clang-option -### 2>&1 | \
// RUN: FileCheck %s
// RUN: %clang_cl -cake-is-lie -%0 -%d -HHHH -munknown-to-clang-option -print-stats -funknown-to-clang-option -### -c -- %s 2>&1 | \
// RUN: FileCheck %s --check-prefix=CL
// RUN: not %clang_cl -cake-is-lie -%0 -%d -HHHH -munknown-to-clang-option -print-stats -funknown-to-clang-option -c -Werror=unknown-argument -### -- %s 2>&1 | \
// RUN: FileCheck %s --check-prefix=CL-ERROR
// RUN: %clang_cl -cake-is-lie -%0 -%d -HHHH -munknown-to-clang-option -print-stats -funknown-to-clang-option -c -Wno-unknown-argument -### -- %s 2>&1 | \
// RUN: FileCheck %s --check-prefix=SILENT
// CHECK: error: unknown argument: '-cake-is-lie'
// CHECK: error: unknown argument: '-%0'
// CHECK: error: unknown argument: '-%d'
// CHECK: error: unknown argument: '-HHHH'
// CHECK: error: unknown argument: '-munknown-to-clang-option'
// CHECK: error: unknown argument: '-print-stats'
// CHECK: error: unknown argument: '-funknown-to-clang-option'
// CL: warning: unknown argument ignored in clang-cl: '-cake-is-lie'
// CL: warning: unknown argument ignored in clang-cl: '-%0'
// CL: warning: unknown argument ignored in clang-cl: '-%d'
// CL: warning: unknown argument ignored in clang-cl: '-HHHH'
// CL: warning: unknown argument ignored in clang-cl: '-munknown-to-clang-option'
// CL: warning: unknown argument ignored in clang-cl: '-print-stats'
// CL: warning: unknown argument ignored in clang-cl: '-funknown-to-clang-option'
// CL-ERROR: error: unknown argument ignored in clang-cl: '-cake-is-lie'
// CL-ERROR: error: unknown argument ignored in clang-cl: '-%0'
// CL-ERROR: error: unknown argument ignored in clang-cl: '-%d'
// CL-ERROR: error: unknown argument ignored in clang-cl: '-HHHH'
// CL-ERROR: error: unknown argument ignored in clang-cl: '-munknown-to-clang-option'
// CL-ERROR: error: unknown argument ignored in clang-cl: '-print-stats'
// CL-ERROR: error: unknown argument ignored in clang-cl: '-funknown-to-clang-option'
// SILENT-NOT: error:
// SILENT-NOT: warning:
// RUN: %clang -S %s -o %t.s -Wunknown-to-clang-option 2>&1 | FileCheck --check-prefix=IGNORED %s
// IGNORED: warning: unknown warning option '-Wunknown-to-clang-option'
|
the_stack_data/184516976.c
|
#include <stdio.h>
#define TAM 5
typedef struct fila{
int elem[TAM];
int cabecalho, ultimo;
}FILA;
void inicializar(FILA *fila) {
fila->ultimo = 0;
fila->cabecalho = fila->ultimo;
}
int filaVazia(FILA *fila) {
return(fila->ultimo == fila->cabecalho);
}
int filaCheia(FILA *fila) {
int proxi =(fila->ultimo+1) %TAM;
return(proxi == fila->cabecalho);
}
int enfileirar(FILA* fila, int elemento) {
int proxi;
if(filaCheia(fila)) {
printf("\nFila Cheia!");
return 0;
}
proxi =(fila->ultimo+1) %TAM;
fila->elem[proxi] = elemento;
fila->ultimo = proxi;
return 1;
}
int desenfileirar(FILA *fila) {
int removido = -1;
if(filaVazia(fila)) {
printf("\nFila Vazia!");
return removido;
}
fila->cabecalho =(fila->cabecalho+1) %TAM;
removido = fila->elem[fila->cabecalho];
return removido;
}
void imprimir(FILA* fila) {
if(filaVazia(fila)) {
printf("Fila Vazia!\n");
return;
}
while (!filaVazia(fila))
printf("%d ", desenfileirar(fila));
printf("\n");
}
int main() {
FILA fila;
inicializar(&fila);
imprimir(&fila);
enfileirar(&fila, 2);
enfileirar(&fila, 5);
enfileirar(&fila, 7);
imprimir(&fila);
imprimir(&fila);
return 0;
}
|
the_stack_data/69677.c
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atamraka <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/06/10 18:02:07 by atamraka #+# #+# */
/* Updated: 2021/06/10 18:03:26 by atamraka ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_display(char *arguments);
int main(int argc, char **argv)
{
if (argc <= 1)
write(2, "File name missing.\n", 19);
else if (argc > 2)
write(2, "Too many arguments.\n", 20);
else
ft_display(argv[1]);
return (0);
}
|
the_stack_data/146480.c
|
// soma simples
#include <stdio.h>
int main() {
int A, B;
scanf("%d %d", &A, &B);
printf("SOMA = %d\n", A+B);
return 0;
}
|
the_stack_data/25137861.c
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int f1( int j, int *dj, int n)
{
int i;
for (i = 0; i < n; i += 2)
if (j == dj[i])
return 0;
return 1;
}
int f2( int i, int *dj, int n)
{
int j;
for (j = 1; j < n - 1; j += 2)
if (i == dj[j])
return dj[j];
}
int f3( int i, int *dj, int n)
{
int j;
for (j = 0; j < n; j += 2)
if (i == dj[j])
return dj[j + 1];
}
int maxsum (int **b, int n)
{
int i, j, max = 0, y = 0, m[n], dj[2*n], min;
for (i = 0; i < 2*n; i++)
dj[i] = -1;
for (i = 0; i < n; i++)
m[i] = 0;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
if (b[i][j] > m[i])
if (f1(j, dj, 2*n) == 1){
m[i] = b[i][j];
dj[y] = j;
y++;
dj[y] = i;
y++;
}
else
if (b[i][j] > b[f3(j, dj, 2*n)][j]){
m[i] = b[i][j];
dj[f2(i, dj, n)] = i;
i = f2(i, dj, n);
}
min = m[1];
for (i = 0; i < n; i++)
if (m[i] < min)
min = m[i];
for (i = 0; i < n; i++)
max += m[i];
max -= min;
return max;
}
int main(int argc,char **argv)
{
int i, j, n, x = 0, t, v, r;
scanf("%d", &n);
char **a = (char**) malloc(n * sizeof(char*));
int **b = (int**) malloc(n * sizeof(int*));
for (i = 0; i < n; i++){
b[i] = (int*) malloc(n * sizeof(int));
for (j = 0; j < n; j++)
b[i][j] = 0;
}
for (i = 0; i < n; i++){
a[i] = (char*) malloc(16 * sizeof(char));
for (j = 0; j < 16; j++)
a[i][j] = 0;
scanf("\n");
scanf("%s", a[i]);
}
for (i = 0; i < n; i++)
for (j = 0; j < n; j++){
r = t = strlen(a[i]) - 1;
v = 0;
if (i != j){
LOL:
if (a[i][strlen(a[i]) - t] == a[j][v])
while (a[i][strlen(a[i]) - t] != 0)
if (a[i][strlen(a[i]) - t] == a[j][v]){
b[i][j] ++;
t--;
v++;
}
else
{
b[i][j] = 0;
v = 0;
goto LOL;
}
else while (a[i][strlen(a[i]) - t] != 0)
{
t = r--;
v = 0;
goto LOL;
}
}
}
for (i = 0; i < n; i++)
x += strlen(a[i]);
x -= maxsum( b, n);
printf("%d\n", x);
for (i = 0; i < n; i++){
free (a[i]);
free (b[i]);
}
free (a);
free (b);
scanf("%d", &v);
return 0;
}
|
the_stack_data/67326364.c
|
/**
******************************************************************************
* @file stm32f4xx_ll_lptim.c
* @author MCD Application Team
* @brief LPTIM LL module driver.
******************************************************************************
* @attention
*
* Copyright (c) 2016 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#if defined(USE_FULL_LL_DRIVER)
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_ll_lptim.h"
#include "stm32f4xx_ll_bus.h"
#include "stm32f4xx_ll_rcc.h"
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
/** @addtogroup STM32F4xx_LL_Driver
* @{
*/
#if defined (LPTIM1)
/** @addtogroup LPTIM_LL
* @{
*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/** @addtogroup LPTIM_LL_Private_Macros
* @{
*/
#define IS_LL_LPTIM_CLOCK_SOURCE(__VALUE__) (((__VALUE__) == LL_LPTIM_CLK_SOURCE_INTERNAL) \
|| ((__VALUE__) == LL_LPTIM_CLK_SOURCE_EXTERNAL))
#define IS_LL_LPTIM_CLOCK_PRESCALER(__VALUE__) (((__VALUE__) == LL_LPTIM_PRESCALER_DIV1) \
|| ((__VALUE__) == LL_LPTIM_PRESCALER_DIV2) \
|| ((__VALUE__) == LL_LPTIM_PRESCALER_DIV4) \
|| ((__VALUE__) == LL_LPTIM_PRESCALER_DIV8) \
|| ((__VALUE__) == LL_LPTIM_PRESCALER_DIV16) \
|| ((__VALUE__) == LL_LPTIM_PRESCALER_DIV32) \
|| ((__VALUE__) == LL_LPTIM_PRESCALER_DIV64) \
|| ((__VALUE__) == LL_LPTIM_PRESCALER_DIV128))
#define IS_LL_LPTIM_WAVEFORM(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_PWM) \
|| ((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_SETONCE))
#define IS_LL_LPTIM_OUTPUT_POLARITY(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_REGULAR) \
|| ((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_INVERSE))
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/** @defgroup LPTIM_Private_Functions LPTIM Private Functions
* @{
*/
/**
* @}
*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup LPTIM_LL_Exported_Functions
* @{
*/
/** @addtogroup LPTIM_LL_EF_Init
* @{
*/
/**
* @brief Set LPTIMx registers to their reset values.
* @param LPTIMx LP Timer instance
* @retval An ErrorStatus enumeration value:
* - SUCCESS: LPTIMx registers are de-initialized
* - ERROR: invalid LPTIMx instance
*/
ErrorStatus LL_LPTIM_DeInit(LPTIM_TypeDef *LPTIMx)
{
ErrorStatus result = SUCCESS;
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(LPTIMx));
if (LPTIMx == LPTIM1)
{
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_LPTIM1);
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_LPTIM1);
}
else
{
result = ERROR;
}
return result;
}
/**
* @brief Set each fields of the LPTIM_InitStruct structure to its default
* value.
* @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
* @retval None
*/
void LL_LPTIM_StructInit(LL_LPTIM_InitTypeDef *LPTIM_InitStruct)
{
/* Set the default configuration */
LPTIM_InitStruct->ClockSource = LL_LPTIM_CLK_SOURCE_INTERNAL;
LPTIM_InitStruct->Prescaler = LL_LPTIM_PRESCALER_DIV1;
LPTIM_InitStruct->Waveform = LL_LPTIM_OUTPUT_WAVEFORM_PWM;
LPTIM_InitStruct->Polarity = LL_LPTIM_OUTPUT_POLARITY_REGULAR;
}
/**
* @brief Configure the LPTIMx peripheral according to the specified parameters.
* @note LL_LPTIM_Init can only be called when the LPTIM instance is disabled.
* @note LPTIMx can be disabled using unitary function @ref LL_LPTIM_Disable().
* @param LPTIMx LP Timer Instance
* @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: LPTIMx instance has been initialized
* - ERROR: LPTIMx instance hasn't been initialized
*/
ErrorStatus LL_LPTIM_Init(LPTIM_TypeDef *LPTIMx, LL_LPTIM_InitTypeDef *LPTIM_InitStruct)
{
ErrorStatus result = SUCCESS;
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(LPTIMx));
assert_param(IS_LL_LPTIM_CLOCK_SOURCE(LPTIM_InitStruct->ClockSource));
assert_param(IS_LL_LPTIM_CLOCK_PRESCALER(LPTIM_InitStruct->Prescaler));
assert_param(IS_LL_LPTIM_WAVEFORM(LPTIM_InitStruct->Waveform));
assert_param(IS_LL_LPTIM_OUTPUT_POLARITY(LPTIM_InitStruct->Polarity));
/* The LPTIMx_CFGR register must only be modified when the LPTIM is disabled
(ENABLE bit is reset to 0).
*/
if (LL_LPTIM_IsEnabled(LPTIMx) == 1UL)
{
result = ERROR;
}
else
{
/* Set CKSEL bitfield according to ClockSource value */
/* Set PRESC bitfield according to Prescaler value */
/* Set WAVE bitfield according to Waveform value */
/* Set WAVEPOL bitfield according to Polarity value */
MODIFY_REG(LPTIMx->CFGR,
(LPTIM_CFGR_CKSEL | LPTIM_CFGR_PRESC | LPTIM_CFGR_WAVE | LPTIM_CFGR_WAVPOL),
LPTIM_InitStruct->ClockSource | \
LPTIM_InitStruct->Prescaler | \
LPTIM_InitStruct->Waveform | \
LPTIM_InitStruct->Polarity);
}
return result;
}
/**
* @brief Disable the LPTIM instance
* @rmtoll CR ENABLE LL_LPTIM_Disable
* @param LPTIMx Low-Power Timer instance
* @note The following sequence is required to solve LPTIM disable HW limitation.
* Please check Errata Sheet ES0335 for more details under "MCU may remain
* stuck in LPTIM interrupt when entering Stop mode" section.
* @retval None
*/
void LL_LPTIM_Disable(LPTIM_TypeDef *LPTIMx)
{
LL_RCC_ClocksTypeDef rcc_clock;
uint32_t tmpclksource = 0;
uint32_t tmpIER;
uint32_t tmpCFGR;
uint32_t tmpCMP;
uint32_t tmpARR;
uint32_t primask_bit;
uint32_t tmpOR;
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(LPTIMx));
/* Enter critical section */
primask_bit = __get_PRIMASK();
__set_PRIMASK(1) ;
/********** Save LPTIM Config *********/
/* Save LPTIM source clock */
switch ((uint32_t)LPTIMx)
{
case LPTIM1_BASE:
tmpclksource = LL_RCC_GetLPTIMClockSource(LL_RCC_LPTIM1_CLKSOURCE);
break;
default:
break;
}
/* Save LPTIM configuration registers */
tmpIER = LPTIMx->IER;
tmpCFGR = LPTIMx->CFGR;
tmpCMP = LPTIMx->CMP;
tmpARR = LPTIMx->ARR;
tmpOR = LPTIMx->OR;
/************* Reset LPTIM ************/
(void)LL_LPTIM_DeInit(LPTIMx);
/********* Restore LPTIM Config *******/
LL_RCC_GetSystemClocksFreq(&rcc_clock);
if ((tmpCMP != 0UL) || (tmpARR != 0UL))
{
/* Force LPTIM source kernel clock from APB */
switch ((uint32_t)LPTIMx)
{
case LPTIM1_BASE:
LL_RCC_SetLPTIMClockSource(LL_RCC_LPTIM1_CLKSOURCE_PCLK1);
break;
default:
break;
}
if (tmpCMP != 0UL)
{
/* Restore CMP and ARR registers (LPTIM should be enabled first) */
LPTIMx->CR |= LPTIM_CR_ENABLE;
LPTIMx->CMP = tmpCMP;
/* Polling on CMP write ok status after above restore operation */
do
{
rcc_clock.SYSCLK_Frequency--; /* Used for timeout */
} while (((LL_LPTIM_IsActiveFlag_CMPOK(LPTIMx) != 1UL)) && ((rcc_clock.SYSCLK_Frequency) > 0UL));
LL_LPTIM_ClearFlag_CMPOK(LPTIMx);
}
if (tmpARR != 0UL)
{
LPTIMx->CR |= LPTIM_CR_ENABLE;
LPTIMx->ARR = tmpARR;
LL_RCC_GetSystemClocksFreq(&rcc_clock);
/* Polling on ARR write ok status after above restore operation */
do
{
rcc_clock.SYSCLK_Frequency--; /* Used for timeout */
}
while (((LL_LPTIM_IsActiveFlag_ARROK(LPTIMx) != 1UL)) && ((rcc_clock.SYSCLK_Frequency) > 0UL));
LL_LPTIM_ClearFlag_ARROK(LPTIMx);
}
/* Restore LPTIM source kernel clock */
LL_RCC_SetLPTIMClockSource(tmpclksource);
}
/* Restore configuration registers (LPTIM should be disabled first) */
LPTIMx->CR &= ~(LPTIM_CR_ENABLE);
LPTIMx->IER = tmpIER;
LPTIMx->CFGR = tmpCFGR;
LPTIMx->OR = tmpOR;
/* Exit critical section: restore previous priority mask */
__set_PRIMASK(primask_bit);
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* LPTIM1 */
/**
* @}
*/
#endif /* USE_FULL_LL_DRIVER */
|
the_stack_data/20451485.c
|
#ifdef __SSSE3__
#include <string.h>
#include <tmmintrin.h>
#include "poly.h" /* for ntru_to_arr_32() */
#include "poly_ssse3.h"
#include "types.h"
#define NTRU_SPARSE_THRESH_SSSE3 14
uint8_t ntru_mult_int_sse(NtruIntPoly *a, NtruIntPoly *b, NtruIntPoly *c, uint16_t mod_mask) {
uint16_t N = a->N;
if (N != b->N)
return 0;
c->N = N;
int16_t c_coeffs[2*NTRU_INT_POLY_SIZE]; /* double capacity for intermediate result */
memset(&c_coeffs, 0, sizeof(c_coeffs));
uint16_t k;
for (k=N; k<NTRU_INT_POLY_SIZE; k++) {
a->coeffs[k] = 0;
b->coeffs[k] = 0;
}
for (k=0; k<N; k+=8) {
uint8_t j;
/* process coeffs in 8x8 blocks */
__m128i b128[8];
for (j=0; j<8; j++)
b128[j] = _mm_set1_epi16(b->coeffs[k+j]);
/* indices 0..7 */
__m128i a128 = _mm_lddqu_si128((__m128i*)&a->coeffs[0]);
__m128i c128 = _mm_lddqu_si128((__m128i*)&c_coeffs[k]);
for (j=0; j<8; j++) {
__m128i product = _mm_mullo_epi16(a128, b128[j]);
c128 = _mm_add_epi16(c128, product);
a128 = _mm_slli_si128(a128, 2);
}
_mm_storeu_si128((__m128i*)&c_coeffs[k], c128);
/* indices 8... */
uint16_t i;
for (i=8; i<N+8; i+=8) {
__m128i c128 = _mm_lddqu_si128((__m128i*)&c_coeffs[k+i]);
__m128i a128_0 = _mm_lddqu_si128((__m128i*)&a->coeffs[i-7]);
__m128i a128_1 = _mm_lddqu_si128((__m128i*)&a->coeffs[i]);
for (j=0; j<8; j++) {
__m128i product = _mm_mullo_epi16(a128_1, b128[j]);
c128 = _mm_add_epi16(c128, product);
a128_0 = _mm_slli_si128(a128_0, 2);
a128_1 = _mm_alignr_epi8(a128_1, a128_0, 14);
}
_mm_storeu_si128((__m128i*)&c_coeffs[k+i], c128);
}
}
/* no need to SSE-ify the following loop b/c the compiler auto-vectorizes it */
for (k=0; k<N; k++)
c->coeffs[k] = c_coeffs[k] + c_coeffs[N+k];
ntru_mod_sse(c, mod_mask);
return 1;
}
/* Optimized for small df */
uint8_t ntru_mult_tern_sse_sparse(NtruIntPoly *a, NtruTernPoly *b, NtruIntPoly *c, uint16_t mod_mask) {
uint16_t N = a->N;
if (N != b->N)
return 0;
memset(&c->coeffs, 0, N * sizeof c->coeffs[0]);
c->N = N;
/* add coefficients that are multiplied by 1 */
uint16_t i;
for (i=0; i<b->num_ones; i++) {
int16_t j;
int16_t k = b->ones[i];
uint16_t j_end = N<b->ones[i] ? 0 : N-b->ones[i];
/* it is safe not to truncate the last block of 8 coefficients */
/* because there is extra room at the end of the coeffs array */
for (j=0; j<j_end; j+=8,k+=8) {
__m128i ck = _mm_lddqu_si128((__m128i*)&c->coeffs[k]);
__m128i aj = _mm_lddqu_si128((__m128i*)&a->coeffs[j]);
__m128i ca = _mm_add_epi16(ck, aj);
_mm_storeu_si128((__m128i*)&c->coeffs[k], ca);
}
j = j_end;
for (k=0; j<N-7; j+=8,k+=8) {
__m128i ck = _mm_lddqu_si128((__m128i*)&c->coeffs[k]);
__m128i aj = _mm_lddqu_si128((__m128i*)&a->coeffs[j]);
__m128i ca = _mm_add_epi16(ck, aj);
_mm_storeu_si128((__m128i*)&c->coeffs[k], ca);
}
for (; j<N; j++,k++)
c->coeffs[k] += a->coeffs[j];
}
/* subtract coefficients that are multiplied by -1 */
for (i=0; i<b->num_neg_ones; i++) {
int16_t j;
int16_t k = b->neg_ones[i];
uint16_t j_end = N<b->neg_ones[i] ? 0 : N-b->neg_ones[i];
/* it is safe not to truncate the last block of 8 coefficients */
/* because there is extra room at the end of the coeffs array */
for (j=0; j<j_end; j+=8,k+=8) {
__m128i ck = _mm_lddqu_si128((__m128i*)&c->coeffs[k]);
__m128i aj = _mm_lddqu_si128((__m128i*)&a->coeffs[j]);
__m128i ca = _mm_sub_epi16(ck, aj);
_mm_storeu_si128((__m128i*)&c->coeffs[k], ca);
}
j = j_end;
for (k=0; j<N-7; j+=8,k+=8) {
__m128i ck = _mm_lddqu_si128((__m128i*)&c->coeffs[k]);
__m128i aj = _mm_lddqu_si128((__m128i*)&a->coeffs[j]);
__m128i ca = _mm_sub_epi16(ck, aj);
_mm_storeu_si128((__m128i*)&c->coeffs[k], ca);
}
for (; j<N; j++,k++)
c->coeffs[k] -= a->coeffs[j];
}
ntru_mod_sse(c, mod_mask);
return 1;
}
/* Optimized for large df */
uint8_t ntru_mult_tern_sse_dense(NtruIntPoly *a, NtruTernPoly *b, NtruIntPoly *c, uint16_t mod_mask) {
uint16_t N = a->N;
if (N != b->N)
return 0;
c->N = N;
uint16_t i;
for (i=N; i<NTRU_INT_POLY_SIZE; i++)
a->coeffs[i] = 0;
int16_t c_coeffs_arr[8+2*NTRU_INT_POLY_SIZE]; /* double capacity for intermediate result + another 8 */
int16_t *c_coeffs = c_coeffs_arr + 8;
memset(&c_coeffs_arr, 0, sizeof(c_coeffs_arr));
__m128i a_coeffs0[8];
a_coeffs0[0] = _mm_lddqu_si128((__m128i*)&a->coeffs[0]);
for (i=1; i<8; i++)
a_coeffs0[i] = _mm_slli_si128(a_coeffs0[i-1], 2);
/* add coefficients that are multiplied by 1 */
for (i=0; i<b->num_ones; i++) {
int16_t k = b->ones[i];
/* process the first num_coeffs0 coefficients, 1<=num_coeffs0<=8 */
uint8_t num_bytes0 = 16 - (((size_t)&c_coeffs[k])%16);
uint8_t num_coeffs0 = num_bytes0 / 2; /* c_coeffs[k+num_coeffs0] is 16-byte aligned */
k -= 8 - num_coeffs0;
__m128i *ck = (__m128i*)&c_coeffs[k];
__m128i aj = a_coeffs0[8-num_coeffs0];
__m128i ca = _mm_add_epi16(*ck, aj);
_mm_store_si128(ck, ca);
k += 8;
/* process the remaining coefficients in blocks of 8. */
/* it is safe not to truncate the last block of 8 coefficients */
/* because there is extra room at the end of the coeffs array */
ck = (__m128i*)&c_coeffs[k];
int16_t j;
for (j=num_coeffs0; j<N; j+=8,k+=8) {
__m128i aj = _mm_lddqu_si128((__m128i*)&a->coeffs[j]);
__m128i ca = _mm_add_epi16(*ck, aj);
_mm_store_si128(ck, ca);
ck++;
}
}
/* subtract coefficients that are multiplied by -1 */
for (i=0; i<b->num_neg_ones; i++) {
int16_t k = b->neg_ones[i];
/* process the first num_coeffs0 coefficients, 1<=num_coeffs0<=8 */
uint8_t num_bytes0 = 16 - (((size_t)&c_coeffs[k])%16);
uint8_t num_coeffs0 = num_bytes0 / 2; /* c_coeffs[k+num_coeffs0] is 16-byte aligned */
k -= 8 - num_coeffs0;
__m128i *ck = (__m128i*)&c_coeffs[k];
__m128i aj = a_coeffs0[8-num_coeffs0];
__m128i ca = _mm_sub_epi16(*ck, aj);
_mm_store_si128(ck, ca);
k += 8;
/* process the remaining coefficients in blocks of 8. */
/* it is safe not to truncate the last block of 8 coefficients */
/* because there is extra room at the end of the coeffs array */
ck = (__m128i*)&c_coeffs[k];
int16_t j;
for (j=num_coeffs0; j<N; j+=8,k+=8) {
__m128i aj = _mm_lddqu_si128((__m128i*)&a->coeffs[j]);
__m128i ca = _mm_sub_epi16(*ck, aj);
_mm_store_si128(ck, ca);
ck++;
}
}
/* reduce c_coeffs[0..2N-1] to [0..N-1] and apply mod_mask to reduce values mod q */
/* handle the first coefficients individually if c_coeffs is not 16-byte aligned */
for (i=0; ((size_t)&c_coeffs[i])%16; i++)
c->coeffs[i] = (c_coeffs[i] + c_coeffs[N+i]) & mod_mask;
/* handle the remaining ones in blocks of 8 */
__m128i mod_mask_128 = _mm_set1_epi16(mod_mask);
__m128i *ci = (__m128i*)(&c_coeffs[i]);
for (; i<N; i+=8) {
__m128i c128_1 = _mm_lddqu_si128((__m128i*)&c_coeffs[i+N]);
__m128i c128_0 = _mm_add_epi16(*ci, c128_1);
c128_0 = _mm_and_si128(c128_0, mod_mask_128);
_mm_storeu_si128((__m128i*)&c->coeffs[i], c128_0);
ci++;
}
return 1;
}
uint8_t ntru_mult_tern_sse(NtruIntPoly *a, NtruTernPoly *b, NtruIntPoly *c, uint16_t mod_mask) {
if (b->num_ones<NTRU_SPARSE_THRESH_SSSE3 && b->num_neg_ones<NTRU_SPARSE_THRESH_SSSE3)
return ntru_mult_tern_sse_sparse(a, b, c, mod_mask);
else
return ntru_mult_tern_sse_dense(a, b, c, mod_mask);
}
void ntru_to_arr_sse_2048(NtruIntPoly *p, uint8_t *a) {
/* mask{n} masks bits n..n+10 except for mask64 which masks bits 64..66 */
__m128i mask0 = {(1<<11)-1, 0};
__m128i mask11 = _mm_slli_epi64(mask0, 11);
__m128i mask22 = _mm_slli_epi64(mask11, 11);
__m128i mask33 = _mm_slli_epi64(mask22, 11);
__m128i mask44 = _mm_slli_epi64(mask33, 11);
__m128i mask55 = {(uint64_t)((1<<9)-1) << 55, 3};
__m128i mask64 = {0, 3};
__m128i mask66 = {0, ((1<<11)-1) << 2};
__m128i mask77 = _mm_slli_epi64(mask66, 11);
__m128i mask88 = _mm_slli_epi64(mask77, 11);
__m128i mask99 = _mm_slli_epi64(mask88, 11);
uint16_t a_idx = 0;
uint16_t p_idx;
uint16_t N = p->N;
for (p_idx=0; p_idx<N-10; p_idx+=8) {
__m128i p128 = _mm_lddqu_si128((__m128i*)&p->coeffs[p_idx]); /* 8 coeffs of p starting at p_idx */
__m128i a128 = _mm_and_si128(p128, mask0); /* bits [0..10] -> [0..10] */
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_srli_epi64(p128, 5), mask11)); /* [16..26] -> [11..21] */
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_srli_epi64(p128, 10), mask22)); /* [32..42] -> [22..32] */
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_srli_epi64(p128, 15), mask33)); /* [48..58] -> [33..43] */
__m128i p128_64 = _mm_srli_si128(p128, 8);
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_slli_epi64(p128_64, 44), mask44)); /* [64..74] -> [44..54] */
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_slli_epi64(p128_64, 39), mask55)); /* [80..88] -> [55..63] */
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_srli_epi64(p128, 25), mask64)); /* [89..90] -> [64..65] */
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_srli_epi64(p128, 30), mask66)); /* [96..111] -> [66..76] */
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_srli_epi64(p128, 35), mask77)); /* [112..127] -> [77..87] */
_mm_storeu_si128((__m128i*)&a[a_idx], a128);
a_idx += 11;
}
/* remaining coeffs (up to 10) */
__m128i p128 = _mm_lddqu_si128((__m128i*)&p->coeffs[p_idx]); /* 8 coeffs of p starting at p_idx */
__m128i a128 = _mm_setzero_si128();
if (N-p_idx > 0)
a128 = _mm_and_si128(p128, mask0); /* bits [0..10] -> [0..10] */
if (N-p_idx > 1)
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_srli_epi64(p128, 5), mask11)); /* [16..26] -> [11..21] */
if (N-p_idx > 2)
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_srli_epi64(p128, 10), mask22)); /* [32..42] -> [22..32] */
if (N-p_idx > 3)
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_srli_epi64(p128, 15), mask33)); /* [48..58] -> [33..43] */
__m128i p128_64 = _mm_srli_si128(p128, 8);
if (N-p_idx > 4)
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_slli_epi64(p128_64, 44), mask44)); /* [64..74] -> [44..54] */
if (N-p_idx > 5) {
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_slli_epi64(p128_64, 39), mask55)); /* [80..88] -> [55..63] */
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_srli_epi64(p128, 25), mask64)); /* [89..90] -> [64..65] */
}
if (N-p_idx > 6)
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_srli_epi64(p128, 30), mask66)); /* [96..111] -> [66..76] */
if (N-p_idx > 7)
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_srli_epi64(p128, 35), mask77)); /* [112..127] -> [77..87] */
if (N-p_idx > 8) {
p128 = _mm_lddqu_si128((__m128i*)&p->coeffs[p_idx+8]); /* coeffs p_idx+8 through p_idx+15 */
p128_64 = _mm_slli_si128(p128, 8);
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_slli_epi64(p128_64, 24), mask88)); /* [0..15] -> [88..98] */
}
if (N-p_idx > 9)
a128 = _mm_or_si128(a128, _mm_and_si128(_mm_slli_epi64(p128_64, 19), mask99)); /* [16..31] -> [99..109] */
uint8_t a_last[16];
_mm_storeu_si128((__m128i*)a_last, a128);
memcpy(&a[a_idx], a_last, ((N-p_idx)*11+7)/8);
}
void ntru_to_arr_sse(NtruIntPoly *p, uint16_t q, uint8_t *a) {
if (q == 2048)
ntru_to_arr_sse_2048(p, a);
else
ntru_to_arr_32(p, q, a);
}
void ntru_mod_sse(NtruIntPoly *p, uint16_t mod_mask) {
uint16_t i;
__m128i mod_mask_128 = _mm_set1_epi16(mod_mask);
for (i=0; i<p->N; i+=8) {
__m128i a = _mm_lddqu_si128((__m128i*)&p->coeffs[i]);
a = _mm_and_si128(a, mod_mask_128);
_mm_storeu_si128((__m128i*)&p->coeffs[i], a);
}
}
/* (i%3)+3 for i=0..7 */
__m128i NTRU_MOD3_LUT = {0x0403050403050403, 0};
/**
* SSE version of ntru_mod3.
* Based on Douglas W Jones' mod3 function at
* http://homepage.cs.uiowa.edu/~jones/bcd/mod.shtml.
*/
void ntru_mod3_sse(NtruIntPoly *p) {
uint16_t i;
for (i=0; i<(p->N+7)/8*8; i+=8) {
__m128i a = _mm_lddqu_si128((__m128i*)&p->coeffs[i]);
/* make positive */
__m128i _3000 = _mm_set1_epi16(3000);
a = _mm_add_epi16(a, _3000);
/* a = (a>>8) + (a&0xFF); (sum base 2**8 digits) */
__m128i a1 = _mm_srli_epi16(a, 8);
__m128i mask = _mm_set1_epi16(0x00FF);
__m128i a2 = _mm_and_si128(a, mask);
a = _mm_add_epi16(a1, a2);
/* a = (a>>4) + (a&0xF); (sum base 2**4 digits; worst case 0x3B) */
a1 = _mm_srli_epi16(a, 4);
mask = _mm_set1_epi16(0x000F);
a2 = _mm_and_si128(a, mask);
a = _mm_add_epi16(a1, a2);
/* a = (a>>2) + (a&0x3); (sum base 2**2 digits; worst case 0x1B) */
a1 = _mm_srli_epi16(a, 2);
mask = _mm_set1_epi16(0x0003);
a2 = _mm_and_si128(a, mask);
a = _mm_add_epi16(a1, a2);
/* a = (a>>2) + (a&0x3); (sum base 2**2 digits; worst case 0x7) */
a1 = _mm_srli_epi16(a, 2);
mask = _mm_set1_epi16(0x0003);
a2 = _mm_and_si128(a, mask);
a = _mm_add_epi16(a1, a2);
__m128i a_mod3 = _mm_shuffle_epi8(NTRU_MOD3_LUT, a);
/* _mm_shuffle_epi8 changed bytes 1, 3, 5, ... to non-zero; change them back to zero */
mask = _mm_set1_epi16(0x00FF);
a_mod3 = _mm_and_si128(a_mod3, mask);
/* subtract 3 so coefficients are in the 0..2 range */
__m128i three = _mm_set1_epi16(0x0003);
a_mod3 = _mm_sub_epi16(a_mod3, three);
_mm_storeu_si128((__m128i*)&p->coeffs[i], a_mod3);
}
}
#endif /* __SSSE3__ */
|
the_stack_data/147708.c
|
#include <stdio.h>
void main ( )
{
int i;
for (i=1; i<=20; i=i+1)
printf ("%4d" , i );
}
|
the_stack_data/109984.c
|
#include <stdio.h>
#include <stdlib.h>
inline static int
max(int a, int b) {
return a > b ? a : b;
}
inline static int
max_slice(int A[], int start, int stop) {
int current_max = 0;
int total_max = 0;
int i;
for (i = start; i < stop; i++) {
current_max = max(0, current_max + A[i]);
total_max = max(total_max, current_max);
}
return total_max;
}
int solution(int A[], int N) {
int i;
int *l_arr = NULL;
int *r_arr = NULL;
int max_val = 0;
l_arr = calloc(sizeof(int), N);
r_arr = calloc(sizeof(int), N);
for (i = 1; i < N - 1; i++) {
l_arr[i] = max(l_arr[i - 1] + A[i], 0);
}
for (i = N - 2; i > 0; i--) {
r_arr[i] = max(r_arr[i + 1] + A[i], 0);
}
for (i = 1; i < N - 1; i++) {
max_val = max(max_val, l_arr[i - 1] + r_arr[i + 1]);
}
free(r_arr);
free(l_arr);
return max_val;
}
int main() {
int A[] = { 3, 2, 6, -1, 4, 5, -1, 2};
printf("Result: %d\n", solution(A, 8));
return 0;
}
|
the_stack_data/89331.c
|
#include <stdlib.h>
#include <stdio.h>
int *val;
void sort (int n) {
int t;
for (int i=n-1; i>0; i--)
for (int j=i-1; j>=0; j--)
if (*(val + i) < *(val + j)) {
t = *(val + i);
*(val + i) = *(val + j);
*(val + j) = t;
}
}
int main (int argc, char** argv) {
char* ep;
int n;
n = argc - 1;
val = malloc(n * sizeof(int));
for (int i=0; i<n; i++) {
val[i] = strtol (argv[i+1], &ep, 10);
if (*ep) {
fprintf (stderr, "Argument %d is not a number\n", i);
return -1;
}
}
sort (n);
for (int i=0; i<n; i++)
printf ("%d\n", val[i]);
}
|
the_stack_data/61074377.c
|
/*Exercise 3 - Repetition
Write a C program to calculate the sum of the numbers from 1 to n.
Where n is a keyboard input.
e.g.
n -> 100
sum = 1+2+3+....+ 99+100 = 5050
n -> 1-
sum = 1+2+3+...+10 = 55 */
#include <stdio.h>
int main() {
int n,total=0,count=1;
printf("Enter number-");
scanf("%d",&n);
while(count<=n){
total=total+count;
count=count+1;
}
printf("%d",total);
return 0;
}
|
the_stack_data/31387989.c
|
#if !defined(MQTT_DIRECT)
#if defined(MQTT_COMM_ENABLED)
#include "sdk-testsuites_internal.h"
#include "cut.h"
#include "utest_mqtt.h"
/**************************************************************************************/
/* IOT_MQTT_Publish */
/**************************************************************************************/
#if 1
/* IOT_MQTT_Publish:正常 */
CASE(MQTT_PREAUTH, case_01)
{
int ret = -1;
void *pclient = NULL;
iotx_mqtt_topic_info_t topic;
TEST_REPLACE_DEVCERT(&UTEST_MQTT_PRODUCT_KEY, &UTEST_MQTT_PRODUCT_SECRET, &UTEST_MQTT_DEVICE_NAME,
&UTEST_MQTT_DEVICE_SECRET);
utest_mqtt_update_topic();
pclient = mqtt_init_by_dev(0);
ASSERT_NOT_NULL(pclient);
HAL_Snprintf(msg_pub, MSG_LEN_MAX, "{\"attr_name\":\"temperature\", \"attr_value\":\"199\"}");
memset(&topic, 0x0, sizeof(iotx_mqtt_topic_info_t));
topic.qos = IOTX_MQTT_QOS1;
topic.retain = 0;
topic.dup = 0;
topic.payload = msg_buf;
topic.payload_len = strlen(msg_buf);
ret = IOT_MQTT_Publish(pclient, UTEST_TOPIC_DATA, &topic);
if (NULL != pclient) {
IOT_MQTT_Destroy(&pclient);
}
ASSERT_TRUE(ret >= 0);
}
#endif
/* IOT_MQTT_Publish:handle=NULL */
CASE(MQTT_PREAUTH, case_02)
{
int ret = -1;
void *pclient = NULL;
iotx_mqtt_topic_info_t topic;
TEST_REPLACE_DEVCERT(&UTEST_MQTT_PRODUCT_KEY, &UTEST_MQTT_PRODUCT_SECRET, &UTEST_MQTT_DEVICE_NAME,
&UTEST_MQTT_DEVICE_SECRET);
utest_mqtt_update_topic();
HAL_Snprintf(msg_pub, MSG_LEN_MAX, "{\"attr_name\":\"temperature\", \"attr_value\":\"199\"}");
memset(&topic, 0x0, sizeof(iotx_mqtt_topic_info_t));
topic.qos = IOTX_MQTT_QOS1;
topic.retain = 0;
topic.dup = 0;
topic.payload = msg_buf;
topic.payload_len = strlen(msg_buf);
ret = IOT_MQTT_Publish(pclient, UTEST_TOPIC_DATA, &topic);
ASSERT_TRUE(ret < 0);
}
/* IOT_MQTT_Publish:payload_len has some margine */
/* the payload_len is larger than the actual size, small than critial value */
CASE(MQTT_PREAUTH, case_03)
{
int ret = -1;
void *pclient = NULL;
iotx_mqtt_topic_info_t topic;
TEST_REPLACE_DEVCERT(&UTEST_MQTT_PRODUCT_KEY, &UTEST_MQTT_PRODUCT_SECRET, &UTEST_MQTT_DEVICE_NAME,
&UTEST_MQTT_DEVICE_SECRET);
utest_mqtt_update_topic();
pclient = mqtt_init_by_dev(0);
ASSERT_NOT_NULL(pclient);
HAL_Snprintf(msg_pub, MSG_LEN_MAX, "{\"attr_name\":\"temperature\", \"attr_value\":\"199\"}");
memset(&topic, 0x0, sizeof(iotx_mqtt_topic_info_t));
topic.qos = IOTX_MQTT_QOS1;
topic.retain = 0;
topic.dup = 0;
topic.payload = msg_buf;
topic.payload_len = MSG_LEN_MAX - strlen(UTEST_TOPIC_DATA) - 4 - 1 - 2 - 30;
ret = IOT_MQTT_Publish(pclient, UTEST_TOPIC_DATA, &topic);
if (NULL != pclient) {
IOT_MQTT_Destroy(&pclient);
}
ASSERT_TRUE(ret >= 0);
}
#if 1
/* IOT_MQTT_Publish:payload_len is too large*/
CASE(MQTT_PREAUTH, case_04)
{
int ret = -1;
void *pclient = NULL;
iotx_mqtt_topic_info_t topic;
TEST_REPLACE_DEVCERT(&UTEST_MQTT_PRODUCT_KEY, &UTEST_MQTT_PRODUCT_SECRET, &UTEST_MQTT_DEVICE_NAME,
&UTEST_MQTT_DEVICE_SECRET);
utest_mqtt_update_topic();
pclient = mqtt_init_by_dev(0);
ASSERT_NOT_NULL(pclient);
HAL_Snprintf(msg_pub, MSG_LEN_MAX, "{\"attr_name\":\"temperature\", \"attr_value\":\"199\"}");
memset(&topic, 0x0, sizeof(iotx_mqtt_topic_info_t));
topic.qos = IOTX_MQTT_QOS1;
topic.retain = 0;
topic.dup = 0;
topic.payload = msg_buf;
topic.payload_len = MSG_LEN_MAX;
ret = IOT_MQTT_Publish(pclient, UTEST_TOPIC_DATA, &topic);
if (NULL != pclient) {
IOT_MQTT_Destroy(&pclient);
}
ASSERT_TRUE(ret == MQTT_PUBLISH_PACKET_ERROR);
}
#endif
#if 1
/* IOT_MQTT_Publish:payload=NULL */
CASE(MQTT_PREAUTH, case_05)
{
int ret = -1;
void *pclient = NULL;
iotx_mqtt_topic_info_t topic;
TEST_REPLACE_DEVCERT(&UTEST_MQTT_PRODUCT_KEY, &UTEST_MQTT_PRODUCT_SECRET, &UTEST_MQTT_DEVICE_NAME,
&UTEST_MQTT_DEVICE_SECRET);
utest_mqtt_update_topic();
pclient = mqtt_init_by_dev(0);
ASSERT_NOT_NULL(pclient);
HAL_Snprintf(msg_pub, MSG_LEN_MAX, "{\"attr_name\":\"temperature\", \"attr_value\":\"199\"}");
memset(&topic, 0x0, sizeof(iotx_mqtt_topic_info_t));
topic.qos = IOTX_MQTT_QOS1;
topic.retain = 0;
topic.dup = 0;
topic.payload = NULL;
topic.payload_len = MSG_LEN_MAX - strlen(UTEST_TOPIC_DATA) - 4 - 3;
ret = IOT_MQTT_Publish(pclient, UTEST_TOPIC_DATA, &topic);
if (NULL != pclient) {
IOT_MQTT_Destroy(&pclient);
}
ASSERT_TRUE(ret < 0);
}
#endif
//the payload len is critical
CASE(MQTT_PREAUTH, case_06)
{
int ret = -1;
void *pclient = NULL;
iotx_mqtt_topic_info_t topic;
TEST_REPLACE_DEVCERT(&UTEST_MQTT_PRODUCT_KEY, &UTEST_MQTT_PRODUCT_SECRET, &UTEST_MQTT_DEVICE_NAME,
&UTEST_MQTT_DEVICE_SECRET);
utest_mqtt_update_topic();
pclient = mqtt_init_by_dev(0);
ASSERT_NOT_NULL(pclient);
HAL_Snprintf(msg_pub, MSG_LEN_MAX, "{\"attr_name\":\"temperature\", \"attr_value\":\"199\"}");
memset(&topic, 0x0, sizeof(iotx_mqtt_topic_info_t));
topic.qos = IOTX_MQTT_QOS1;
topic.retain = 0;
topic.dup = 0;
topic.payload = msg_buf;
//here 4 means lens of idenfiter, topic len, header flags; 3 mins msg len(1 byte) + 2 byte margin
topic.payload_len = MSG_LEN_MAX - strlen(UTEST_TOPIC_DATA) - 4 - 3;
ret = IOT_MQTT_Publish(pclient, UTEST_TOPIC_DATA, &topic);
if (NULL != pclient) {
IOT_MQTT_Destroy(&pclient);
}
ASSERT_TRUE(ret >= 0);
}
/* if the len is smaller than critical value */
CASE(MQTT_PREAUTH, case_07)
{
int ret = -1;
void *pclient = NULL;
iotx_mqtt_topic_info_t topic;
TEST_REPLACE_DEVCERT(&UTEST_MQTT_PRODUCT_KEY, &UTEST_MQTT_PRODUCT_SECRET, &UTEST_MQTT_DEVICE_NAME,
&UTEST_MQTT_DEVICE_SECRET);
utest_mqtt_update_topic();
pclient = mqtt_init_by_dev(0);
ASSERT_NOT_NULL(pclient);
HAL_Snprintf(msg_pub, MSG_LEN_MAX, "{\"attr_name\":\"temperature\", \"attr_value\":\"199\"}");
memset(&topic, 0x0, sizeof(iotx_mqtt_topic_info_t));
topic.qos = IOTX_MQTT_QOS1;
topic.retain = 0;
topic.dup = 0;
topic.payload = msg_buf;
//here 4 means lens of idenfiter, topic len, header flags; 3 mins msg len(1 byte) + 2 byte margin
//here remove the 2 byte margin, which will relult in error
topic.payload_len = MSG_LEN_MAX - strlen(UTEST_TOPIC_DATA) - 4 - 3 + 1;
ret = IOT_MQTT_Publish(pclient, UTEST_TOPIC_DATA, &topic);
if (NULL != pclient) {
IOT_MQTT_Destroy(&pclient);
}
ASSERT_TRUE(ret < 0);
}
SUITE(MQTT_PREAUTH) = {
ADD_CASE(MQTT_PREAUTH, case_01),
ADD_CASE(MQTT_PREAUTH, case_02),
ADD_CASE(MQTT_PREAUTH, case_03),
ADD_CASE(MQTT_PREAUTH, case_04),
ADD_CASE(MQTT_PREAUTH, case_05),
ADD_CASE(MQTT_PREAUTH, case_06),
ADD_CASE(MQTT_PREAUTH, case_07),
ADD_CASE_NULL
};
#endif
#endif
|
the_stack_data/237643075.c
|
/*
M3 -- Meka Robotics Real-Time Control System
Copyright (c) 2010 Meka Robotics
Author: [email protected] (Aaron Edsinger)
M3 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 3 of the License, or
(at your option) any later version.
M3 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 M3. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef USE_CURRENT
#include "setup.h"
#include "current.h"
#include "control.h"
#include "pwm.h"
extern int test; //Test
extern int fsa_state[1];
extern unsigned int actual_pwm; //pwm.c
//Assuming step is called at 2kHz
#define I_RMS_MOM_BUF_SZ 16
#define I_RMS_MOM_BUF_SHIFT 4
#define I_RMS_MOM_DS 248 //2000Hz to 8.06Hz, Buff of 16 gives ~2s window size.
//Assuming step is called at 2kHz
#define I_RMS_CONT_BUF_SZ 32
#define I_RMS_CONT_BUF_SHIFT 5
#define I_RMS_CONT_DS 624 //2000Hz to 3.2Hz. Buff of 32 gives ~10S window size.
volatile int i_mA;
volatile unsigned int i_zero_a, i_zero_b;
volatile int i_zero_cnt;
volatile long i_rms_mom_buf[I_RMS_MOM_BUF_SZ];
volatile long i_rms_cont_buf[I_RMS_CONT_BUF_SZ];
volatile unsigned int i_zero_sum_a, i_zero_sum_b;
volatile long i_rms_cont_sq, i_rms_mom_sq, i_fault_val; //squared value
volatile int i_rms_mom_ds,i_rms_cont_ds;
volatile long i_rms_mom_sum, i_rms_cont_sum;
volatile int i_rms_mom_idx,i_rms_cont_idx;
volatile int i_state,i_fault_cont,i_fault_mom;
int current_fault_mom_flag()
{
if(i_fault_mom)
return M3ACT_FLAG_I_FAULT_MOM;
else
return 0;
}
int current_fault_cont_flag()
{
if (i_fault_cont)
return M3ACT_FLAG_I_FAULT_CONT;
else
return 0;
}
int get_current_ma()
{
return i_mA;
}
long get_current_rms_mom_sq_ma()
{
return i_rms_mom_sq;
}
long get_current_rms_cont_sq_ma()
{
return i_rms_cont_sq;
}
int get_current_state()
{
return i_state;
}
//Calculates an average cycle current based on a single peak current measurement
unsigned int correct_mA(unsigned int pwm, unsigned int max_pwm, unsigned int current)
{
unsigned long result = 0;
unsigned int ratio = 0;
if(pwm <= 0)
return 0;
ratio = (max_pwm << 3) / pwm;
result = ((unsigned long)current * (unsigned long)ratio);
result = result >> 3;
return (unsigned int) result;
}
void reset_current_buf()
{
//i_mA=0;
i_rms_cont_idx=0;
i_rms_cont_sum=0;
i_rms_cont_sq=0;
i_rms_cont_ds=0;
i_rms_mom_idx=0;
i_rms_mom_sum=0;
i_rms_mom_sq=0;
i_rms_mom_ds=0;
memset((long *)i_rms_mom_buf,0,sizeof(long)*I_RMS_MOM_BUF_SZ);
memset((long *)i_rms_cont_buf,0,sizeof(long)*I_RMS_CONT_BUF_SZ);
}
void step_current()
{
unsigned int z = 0;
static unsigned int zero_done = 0;
//Measure zero sensor reading at startup
if (i_zero_cnt < 17 && i_zero_cnt > 0 && i_state == CURRENT_STARTUP)
{
i_zero_sum_a = i_zero_sum_a + get_avg_adc(ADC_CURRENT_A);
i_zero_sum_b = i_zero_sum_b + get_avg_adc(ADC_CURRENT_B);
if (i_zero_cnt == 1)
{
i_zero_a = (i_zero_sum_a >> 4);
i_zero_b = (i_zero_sum_b >> 4);
//Make sure that the zero is valid
#ifdef USE_MAX2_0_2
if((i_zero_a > MAX2_0_2_AMP_MIN) && (i_zero_a < MAX2_0_2_AMP_MAX))
#endif
#ifdef USE_MAX2_0_3
if(i_zero_b < MAX2_0_3_AMP_MIN)
#endif
{
//Value in the range (+-10% for ACS, close to 0 for shunt), we use it
i_state = CURRENT_READY;
zero_done = 1;
}
else
{
//Try again...
i_state = CURRENT_STARTUP;
i_zero_sum_a = 0;
i_zero_sum_b = 0;
i_zero_cnt = 100;
}
}
}
i_zero_cnt=MAX(0,i_zero_cnt-1);
//Avoid false readings at power-up (ex.: after e-stop is released)
if((fsa_state[0] == CTRL_OFF || fsa_state[0] == CTRL_ABORT) && zero_done)
i_state = CURRENT_HOLD;
if (i_state == CURRENT_HOLD)
{
i_zero_a = get_avg_adc(ADC_CURRENT_A);
i_zero_b = get_avg_adc(ADC_CURRENT_B);
//Make sure that the value is in the range (the 5VM bus is on)
#ifdef USE_MAX2_0_2
if((i_zero_a > MAX2_0_2_AMP_MIN) && (i_zero_a < MAX2_0_2_AMP_MAX))
#endif
#ifdef USE_MAX2_0_3
if(i_zero_b < MAX2_0_3_AMP_MIN)
#endif
{
//Value in the range (+-10% for ACS, close to 0 for shunt), we use it
i_state = CURRENT_READY;
}
else
{
//Try again...
i_state = CURRENT_HOLD;
}
}
if (i_state == CURRENT_READY)
{
//Compute 'instantaneous' current
//Hall effect sensor
#ifdef USE_MAX2_0_2
int x =(int)get_avg_adc(ADC_CURRENT_A) - (int)i_zero_a;
i_mA = (x * ADC_CURRENT_MA_PER_TICK);
//Return 0 if CTRL_OFF or CTRL_ABORT
if(fsa_state[0] == CTRL_OFF || fsa_state[0] == CTRL_ABORT)
i_mA = 0;
#endif
//Shunt sensor, we use the absolute value
#ifdef USE_MAX2_0_3
int x =(int)get_avg_adc(ADC_CURRENT_B);
if(x > (int)i_zero_b)
x = x - (int)i_zero_b;
else
x = 0;
x = x * MAX2_0_3_CURRRENT_GAIN;
i_mA = correct_mA(actual_pwm, 2000, x);//correct_mA(actual_pwm, PWM_MAX_DUTY, x);
//Return 0 if CTRL_OFF or CTRL_ABORT
if(fsa_state[0] == CTRL_OFF || fsa_state[0] == CTRL_ABORT)
i_mA = 0;
#endif
//Now compute the momentary RMS value
i_rms_mom_ds=INC_MOD(i_rms_mom_ds,I_RMS_MOM_DS);
if (i_rms_mom_ds==0)
{
i_rms_mom_idx=INC_MOD(i_rms_mom_idx,I_RMS_MOM_BUF_SZ);
i_rms_mom_buf[i_rms_mom_idx]=(long)i_mA*(long)i_mA; //RMS
i_rms_mom_sum = 0;
for(z = 0; z < I_RMS_MOM_BUF_SZ; z++)
{
//Sum all values
i_rms_mom_sum += i_rms_mom_buf[z];
}
i_rms_mom_sq=i_rms_mom_sum>>I_RMS_MOM_BUF_SHIFT;
if ((!i_fault_mom) && (i_rms_mom_sq > CURRENT_MAX_MOM_RMS_SQ))
{
if((i_mA > MAX_MOM_CURRENT) || (i_mA < -MAX_MOM_CURRENT))
{
//if (i_state==CURRENT_READY)
// i_fault_val=i_rms_mom_sq;
i_state = CURRENT_FAULT_MOM;
i_fault_mom = 1;
reset_current_buf();//power turns off
}
}
}
//Now compute the continuous RMS value
i_rms_cont_ds=INC_MOD(i_rms_cont_ds,I_RMS_CONT_DS);
if (i_rms_cont_ds==0)
{
i_rms_cont_idx=INC_MOD(i_rms_cont_idx,I_RMS_CONT_BUF_SZ);
i_rms_cont_buf[i_rms_cont_idx]=(long)i_mA*(long)i_mA;
i_rms_cont_sum = 0;
for(z = 0; z < I_RMS_CONT_BUF_SZ; z++)
{
i_rms_cont_sum += i_rms_cont_buf[z];
}
i_rms_cont_sq=i_rms_cont_sum >> I_RMS_CONT_BUF_SHIFT;
}
if (!i_fault_cont && i_rms_cont_sq>CURRENT_MAX_CONT_RMS_SQ)
{
// if (i_state==CURRENT_READY)
// i_fault_val=i_rms_cont_sq;
i_state=CURRENT_FAULT_CONT;
i_fault_cont=1;
reset_current_buf();//power turns off
}
}
}
void setup_current()
{
i_mA=0;
i_zero_a=0;
i_zero_b=0;
i_zero_cnt=250;
i_zero_sum_a=0;
i_zero_sum_b=0;
i_rms_cont_idx=0;
i_rms_cont_sum=0;
i_rms_cont_sq=0;
i_rms_cont_ds=0;
i_fault_cont=0;
i_fault_mom=0;
i_rms_mom_idx=0;
i_rms_mom_sum=0;
i_rms_mom_sq=0;
i_rms_mom_ds=0;
i_state=CURRENT_STARTUP;
memset((long *)i_rms_mom_buf,0,sizeof(long)*I_RMS_MOM_BUF_SZ);
memset((long *)i_rms_cont_buf,0,sizeof(long)*I_RMS_CONT_BUF_SZ);
}
#endif //USE_CURRENT
|
the_stack_data/175143072.c
|
/* Capstone Disassembly Engine */
/* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */
#ifdef CAPSTONE_HAS_X86
#if defined(CAPSTONE_HAS_OSXKERNEL)
#include <Availability.h>
#endif
#include <string.h>
#ifndef CAPSTONE_HAS_OSXKERNEL
#include <stdlib.h>
#endif
#include "X86Mapping.h"
#include "X86DisassemblerDecoder.h"
#include "../../utils.h"
const uint64_t arch_masks[9] = {
0, 0xff,
0xffff, // 16bit
0,
0xffffffff, // 32bit
0, 0, 0,
0xffffffffffffffffLL // 64bit
};
static const x86_reg sib_base_map[] = {
X86_REG_INVALID,
#define ENTRY(x) X86_REG_##x,
ALL_SIB_BASES
#undef ENTRY
};
// Fill-ins to make the compiler happy. These constants are never actually
// assigned; they are just filler to make an automatically-generated switch
// statement work.
enum {
X86_REG_BX_SI = 500,
X86_REG_BX_DI = 501,
X86_REG_BP_SI = 502,
X86_REG_BP_DI = 503,
X86_REG_sib = 504,
X86_REG_sib64 = 505
};
static const x86_reg sib_index_map[] = {
X86_REG_INVALID,
#define ENTRY(x) X86_REG_##x,
ALL_EA_BASES
REGS_XMM
REGS_YMM
REGS_ZMM
#undef ENTRY
};
static const x86_reg segment_map[] = {
X86_REG_INVALID,
X86_REG_CS,
X86_REG_SS,
X86_REG_DS,
X86_REG_ES,
X86_REG_FS,
X86_REG_GS,
};
x86_reg x86_map_sib_base(int r)
{
return sib_base_map[r];
}
x86_reg x86_map_sib_index(int r)
{
return sib_index_map[r];
}
x86_reg x86_map_segment(int r)
{
return segment_map[r];
}
#ifndef CAPSTONE_DIET
static const name_map reg_name_maps[] = {
{ X86_REG_INVALID, NULL },
{ X86_REG_AH, "ah" },
{ X86_REG_AL, "al" },
{ X86_REG_AX, "ax" },
{ X86_REG_BH, "bh" },
{ X86_REG_BL, "bl" },
{ X86_REG_BP, "bp" },
{ X86_REG_BPL, "bpl" },
{ X86_REG_BX, "bx" },
{ X86_REG_CH, "ch" },
{ X86_REG_CL, "cl" },
{ X86_REG_CS, "cs" },
{ X86_REG_CX, "cx" },
{ X86_REG_DH, "dh" },
{ X86_REG_DI, "di" },
{ X86_REG_DIL, "dil" },
{ X86_REG_DL, "dl" },
{ X86_REG_DS, "ds" },
{ X86_REG_DX, "dx" },
{ X86_REG_EAX, "eax" },
{ X86_REG_EBP, "ebp" },
{ X86_REG_EBX, "ebx" },
{ X86_REG_ECX, "ecx" },
{ X86_REG_EDI, "edi" },
{ X86_REG_EDX, "edx" },
{ X86_REG_EFLAGS, "flags" },
{ X86_REG_EIP, "eip" },
{ X86_REG_EIZ, "eiz" },
{ X86_REG_ES, "es" },
{ X86_REG_ESI, "esi" },
{ X86_REG_ESP, "esp" },
{ X86_REG_FPSW, "fpsw" },
{ X86_REG_FS, "fs" },
{ X86_REG_GS, "gs" },
{ X86_REG_IP, "ip" },
{ X86_REG_RAX, "rax" },
{ X86_REG_RBP, "rbp" },
{ X86_REG_RBX, "rbx" },
{ X86_REG_RCX, "rcx" },
{ X86_REG_RDI, "rdi" },
{ X86_REG_RDX, "rdx" },
{ X86_REG_RIP, "rip" },
{ X86_REG_RIZ, "riz" },
{ X86_REG_RSI, "rsi" },
{ X86_REG_RSP, "rsp" },
{ X86_REG_SI, "si" },
{ X86_REG_SIL, "sil" },
{ X86_REG_SP, "sp" },
{ X86_REG_SPL, "spl" },
{ X86_REG_SS, "ss" },
{ X86_REG_CR0, "cr0" },
{ X86_REG_CR1, "cr1" },
{ X86_REG_CR2, "cr2" },
{ X86_REG_CR3, "cr3" },
{ X86_REG_CR4, "cr4" },
{ X86_REG_CR5, "cr5" },
{ X86_REG_CR6, "cr6" },
{ X86_REG_CR7, "cr7" },
{ X86_REG_CR8, "cr8" },
{ X86_REG_CR9, "cr9" },
{ X86_REG_CR10, "cr10" },
{ X86_REG_CR11, "cr11" },
{ X86_REG_CR12, "cr12" },
{ X86_REG_CR13, "cr13" },
{ X86_REG_CR14, "cr14" },
{ X86_REG_CR15, "cr15" },
{ X86_REG_DR0, "dr0" },
{ X86_REG_DR1, "dr1" },
{ X86_REG_DR2, "dr2" },
{ X86_REG_DR3, "dr3" },
{ X86_REG_DR4, "dr4" },
{ X86_REG_DR5, "dr5" },
{ X86_REG_DR6, "dr6" },
{ X86_REG_DR7, "dr7" },
{ X86_REG_DR8, "dr8" },
{ X86_REG_DR9, "dr9" },
{ X86_REG_DR10, "dr10" },
{ X86_REG_DR11, "dr11" },
{ X86_REG_DR12, "dr12" },
{ X86_REG_DR13, "dr13" },
{ X86_REG_DR14, "dr14" },
{ X86_REG_DR15, "dr15" },
{ X86_REG_FP0, "fp0" },
{ X86_REG_FP1, "fp1" },
{ X86_REG_FP2, "fp2" },
{ X86_REG_FP3, "fp3" },
{ X86_REG_FP4, "fp4" },
{ X86_REG_FP5, "fp5" },
{ X86_REG_FP6, "fp6" },
{ X86_REG_FP7, "fp7" },
{ X86_REG_K0, "k0" },
{ X86_REG_K1, "k1" },
{ X86_REG_K2, "k2" },
{ X86_REG_K3, "k3" },
{ X86_REG_K4, "k4" },
{ X86_REG_K5, "k5" },
{ X86_REG_K6, "k6" },
{ X86_REG_K7, "k7" },
{ X86_REG_MM0, "mm0" },
{ X86_REG_MM1, "mm1" },
{ X86_REG_MM2, "mm2" },
{ X86_REG_MM3, "mm3" },
{ X86_REG_MM4, "mm4" },
{ X86_REG_MM5, "mm5" },
{ X86_REG_MM6, "mm6" },
{ X86_REG_MM7, "mm7" },
{ X86_REG_R8, "r8" },
{ X86_REG_R9, "r9" },
{ X86_REG_R10, "r10" },
{ X86_REG_R11, "r11" },
{ X86_REG_R12, "r12" },
{ X86_REG_R13, "r13" },
{ X86_REG_R14, "r14" },
{ X86_REG_R15, "r15" },
{ X86_REG_ST0, "st(0)" },
{ X86_REG_ST1, "st(1)" },
{ X86_REG_ST2, "st(2)" },
{ X86_REG_ST3, "st(3)" },
{ X86_REG_ST4, "st(4)" },
{ X86_REG_ST5, "st(5)" },
{ X86_REG_ST6, "st(6)" },
{ X86_REG_ST7, "st(7)" },
{ X86_REG_XMM0, "xmm0" },
{ X86_REG_XMM1, "xmm1" },
{ X86_REG_XMM2, "xmm2" },
{ X86_REG_XMM3, "xmm3" },
{ X86_REG_XMM4, "xmm4" },
{ X86_REG_XMM5, "xmm5" },
{ X86_REG_XMM6, "xmm6" },
{ X86_REG_XMM7, "xmm7" },
{ X86_REG_XMM8, "xmm8" },
{ X86_REG_XMM9, "xmm9" },
{ X86_REG_XMM10, "xmm10" },
{ X86_REG_XMM11, "xmm11" },
{ X86_REG_XMM12, "xmm12" },
{ X86_REG_XMM13, "xmm13" },
{ X86_REG_XMM14, "xmm14" },
{ X86_REG_XMM15, "xmm15" },
{ X86_REG_XMM16, "xmm16" },
{ X86_REG_XMM17, "xmm17" },
{ X86_REG_XMM18, "xmm18" },
{ X86_REG_XMM19, "xmm19" },
{ X86_REG_XMM20, "xmm20" },
{ X86_REG_XMM21, "xmm21" },
{ X86_REG_XMM22, "xmm22" },
{ X86_REG_XMM23, "xmm23" },
{ X86_REG_XMM24, "xmm24" },
{ X86_REG_XMM25, "xmm25" },
{ X86_REG_XMM26, "xmm26" },
{ X86_REG_XMM27, "xmm27" },
{ X86_REG_XMM28, "xmm28" },
{ X86_REG_XMM29, "xmm29" },
{ X86_REG_XMM30, "xmm30" },
{ X86_REG_XMM31, "xmm31" },
{ X86_REG_YMM0, "ymm0" },
{ X86_REG_YMM1, "ymm1" },
{ X86_REG_YMM2, "ymm2" },
{ X86_REG_YMM3, "ymm3" },
{ X86_REG_YMM4, "ymm4" },
{ X86_REG_YMM5, "ymm5" },
{ X86_REG_YMM6, "ymm6" },
{ X86_REG_YMM7, "ymm7" },
{ X86_REG_YMM8, "ymm8" },
{ X86_REG_YMM9, "ymm9" },
{ X86_REG_YMM10, "ymm10" },
{ X86_REG_YMM11, "ymm11" },
{ X86_REG_YMM12, "ymm12" },
{ X86_REG_YMM13, "ymm13" },
{ X86_REG_YMM14, "ymm14" },
{ X86_REG_YMM15, "ymm15" },
{ X86_REG_YMM16, "ymm16" },
{ X86_REG_YMM17, "ymm17" },
{ X86_REG_YMM18, "ymm18" },
{ X86_REG_YMM19, "ymm19" },
{ X86_REG_YMM20, "ymm20" },
{ X86_REG_YMM21, "ymm21" },
{ X86_REG_YMM22, "ymm22" },
{ X86_REG_YMM23, "ymm23" },
{ X86_REG_YMM24, "ymm24" },
{ X86_REG_YMM25, "ymm25" },
{ X86_REG_YMM26, "ymm26" },
{ X86_REG_YMM27, "ymm27" },
{ X86_REG_YMM28, "ymm28" },
{ X86_REG_YMM29, "ymm29" },
{ X86_REG_YMM30, "ymm30" },
{ X86_REG_YMM31, "ymm31" },
{ X86_REG_ZMM0, "zmm0" },
{ X86_REG_ZMM1, "zmm1" },
{ X86_REG_ZMM2, "zmm2" },
{ X86_REG_ZMM3, "zmm3" },
{ X86_REG_ZMM4, "zmm4" },
{ X86_REG_ZMM5, "zmm5" },
{ X86_REG_ZMM6, "zmm6" },
{ X86_REG_ZMM7, "zmm7" },
{ X86_REG_ZMM8, "zmm8" },
{ X86_REG_ZMM9, "zmm9" },
{ X86_REG_ZMM10, "zmm10" },
{ X86_REG_ZMM11, "zmm11" },
{ X86_REG_ZMM12, "zmm12" },
{ X86_REG_ZMM13, "zmm13" },
{ X86_REG_ZMM14, "zmm14" },
{ X86_REG_ZMM15, "zmm15" },
{ X86_REG_ZMM16, "zmm16" },
{ X86_REG_ZMM17, "zmm17" },
{ X86_REG_ZMM18, "zmm18" },
{ X86_REG_ZMM19, "zmm19" },
{ X86_REG_ZMM20, "zmm20" },
{ X86_REG_ZMM21, "zmm21" },
{ X86_REG_ZMM22, "zmm22" },
{ X86_REG_ZMM23, "zmm23" },
{ X86_REG_ZMM24, "zmm24" },
{ X86_REG_ZMM25, "zmm25" },
{ X86_REG_ZMM26, "zmm26" },
{ X86_REG_ZMM27, "zmm27" },
{ X86_REG_ZMM28, "zmm28" },
{ X86_REG_ZMM29, "zmm29" },
{ X86_REG_ZMM30, "zmm30" },
{ X86_REG_ZMM31, "zmm31" },
{ X86_REG_R8B, "r8b" },
{ X86_REG_R9B, "r9b" },
{ X86_REG_R10B, "r10b" },
{ X86_REG_R11B, "r11b" },
{ X86_REG_R12B, "r12b" },
{ X86_REG_R13B, "r13b" },
{ X86_REG_R14B, "r14b" },
{ X86_REG_R15B, "r15b" },
{ X86_REG_R8D, "r8d" },
{ X86_REG_R9D, "r9d" },
{ X86_REG_R10D, "r10d" },
{ X86_REG_R11D, "r11d" },
{ X86_REG_R12D, "r12d" },
{ X86_REG_R13D, "r13d" },
{ X86_REG_R14D, "r14d" },
{ X86_REG_R15D, "r15d" },
{ X86_REG_R8W, "r8w" },
{ X86_REG_R9W, "r9w" },
{ X86_REG_R10W, "r10w" },
{ X86_REG_R11W, "r11w" },
{ X86_REG_R12W, "r12w" },
{ X86_REG_R13W, "r13w" },
{ X86_REG_R14W, "r14w" },
{ X86_REG_R15W, "r15w" },
{ X86_REG_BND0, "bnd0" },
{ X86_REG_BND1, "bnd1" },
{ X86_REG_BND2, "bnd2" },
{ X86_REG_BND3, "bnd3" },
};
#endif
// register size in non-64bit mode
const uint8_t regsize_map_32 [] = {
0, // { X86_REG_INVALID, NULL },
1, // { X86_REG_AH, "ah" },
1, // { X86_REG_AL, "al" },
2, // { X86_REG_AX, "ax" },
1, // { X86_REG_BH, "bh" },
1, // { X86_REG_BL, "bl" },
2, // { X86_REG_BP, "bp" },
1, // { X86_REG_BPL, "bpl" },
2, // { X86_REG_BX, "bx" },
1, // { X86_REG_CH, "ch" },
1, // { X86_REG_CL, "cl" },
2, // { X86_REG_CS, "cs" },
2, // { X86_REG_CX, "cx" },
1, // { X86_REG_DH, "dh" },
2, // { X86_REG_DI, "di" },
1, // { X86_REG_DIL, "dil" },
1, // { X86_REG_DL, "dl" },
2, // { X86_REG_DS, "ds" },
2, // { X86_REG_DX, "dx" },
4, // { X86_REG_EAX, "eax" },
4, // { X86_REG_EBP, "ebp" },
4, // { X86_REG_EBX, "ebx" },
4, // { X86_REG_ECX, "ecx" },
4, // { X86_REG_EDI, "edi" },
4, // { X86_REG_EDX, "edx" },
4, // { X86_REG_EFLAGS, "flags" },
4, // { X86_REG_EIP, "eip" },
4, // { X86_REG_EIZ, "eiz" },
2, // { X86_REG_ES, "es" },
4, // { X86_REG_ESI, "esi" },
4, // { X86_REG_ESP, "esp" },
10, // { X86_REG_FPSW, "fpsw" },
2, // { X86_REG_FS, "fs" },
2, // { X86_REG_GS, "gs" },
2, // { X86_REG_IP, "ip" },
8, // { X86_REG_RAX, "rax" },
8, // { X86_REG_RBP, "rbp" },
8, // { X86_REG_RBX, "rbx" },
8, // { X86_REG_RCX, "rcx" },
8, // { X86_REG_RDI, "rdi" },
8, // { X86_REG_RDX, "rdx" },
8, // { X86_REG_RIP, "rip" },
8, // { X86_REG_RIZ, "riz" },
8, // { X86_REG_RSI, "rsi" },
8, // { X86_REG_RSP, "rsp" },
2, // { X86_REG_SI, "si" },
1, // { X86_REG_SIL, "sil" },
2, // { X86_REG_SP, "sp" },
1, // { X86_REG_SPL, "spl" },
2, // { X86_REG_SS, "ss" },
4, // { X86_REG_CR0, "cr0" },
4, // { X86_REG_CR1, "cr1" },
4, // { X86_REG_CR2, "cr2" },
4, // { X86_REG_CR3, "cr3" },
4, // { X86_REG_CR4, "cr4" },
8, // { X86_REG_CR5, "cr5" },
8, // { X86_REG_CR6, "cr6" },
8, // { X86_REG_CR7, "cr7" },
8, // { X86_REG_CR8, "cr8" },
8, // { X86_REG_CR9, "cr9" },
8, // { X86_REG_CR10, "cr10" },
8, // { X86_REG_CR11, "cr11" },
8, // { X86_REG_CR12, "cr12" },
8, // { X86_REG_CR13, "cr13" },
8, // { X86_REG_CR14, "cr14" },
8, // { X86_REG_CR15, "cr15" },
4, // { X86_REG_DR0, "dr0" },
4, // { X86_REG_DR1, "dr1" },
4, // { X86_REG_DR2, "dr2" },
4, // { X86_REG_DR3, "dr3" },
4, // { X86_REG_DR4, "dr4" },
4, // { X86_REG_DR5, "dr5" },
4, // { X86_REG_DR6, "dr6" },
4, // { X86_REG_DR7, "dr7" },
4, // { X86_REG_DR8, "dr8" },
4, // { X86_REG_DR9, "dr9" },
4, // { X86_REG_DR10, "dr10" },
4, // { X86_REG_DR11, "dr11" },
4, // { X86_REG_DR12, "dr12" },
4, // { X86_REG_DR13, "dr13" },
4, // { X86_REG_DR14, "dr14" },
4, // { X86_REG_DR15, "dr15" },
10, // { X86_REG_FP0, "fp0" },
10, // { X86_REG_FP1, "fp1" },
10, // { X86_REG_FP2, "fp2" },
10, // { X86_REG_FP3, "fp3" },
10, // { X86_REG_FP4, "fp4" },
10, // { X86_REG_FP5, "fp5" },
10, // { X86_REG_FP6, "fp6" },
10, // { X86_REG_FP7, "fp7" },
2, // { X86_REG_K0, "k0" },
2, // { X86_REG_K1, "k1" },
2, // { X86_REG_K2, "k2" },
2, // { X86_REG_K3, "k3" },
2, // { X86_REG_K4, "k4" },
2, // { X86_REG_K5, "k5" },
2, // { X86_REG_K6, "k6" },
2, // { X86_REG_K7, "k7" },
8, // { X86_REG_MM0, "mm0" },
8, // { X86_REG_MM1, "mm1" },
8, // { X86_REG_MM2, "mm2" },
8, // { X86_REG_MM3, "mm3" },
8, // { X86_REG_MM4, "mm4" },
8, // { X86_REG_MM5, "mm5" },
8, // { X86_REG_MM6, "mm6" },
8, // { X86_REG_MM7, "mm7" },
8, // { X86_REG_R8, "r8" },
8, // { X86_REG_R9, "r9" },
8, // { X86_REG_R10, "r10" },
8, // { X86_REG_R11, "r11" },
8, // { X86_REG_R12, "r12" },
8, // { X86_REG_R13, "r13" },
8, // { X86_REG_R14, "r14" },
8, // { X86_REG_R15, "r15" },
10, // { X86_REG_ST0, "st0" },
10, // { X86_REG_ST1, "st1" },
10, // { X86_REG_ST2, "st2" },
10, // { X86_REG_ST3, "st3" },
10, // { X86_REG_ST4, "st4" },
10, // { X86_REG_ST5, "st5" },
10, // { X86_REG_ST6, "st6" },
10, // { X86_REG_ST7, "st7" },
16, // { X86_REG_XMM0, "xmm0" },
16, // { X86_REG_XMM1, "xmm1" },
16, // { X86_REG_XMM2, "xmm2" },
16, // { X86_REG_XMM3, "xmm3" },
16, // { X86_REG_XMM4, "xmm4" },
16, // { X86_REG_XMM5, "xmm5" },
16, // { X86_REG_XMM6, "xmm6" },
16, // { X86_REG_XMM7, "xmm7" },
16, // { X86_REG_XMM8, "xmm8" },
16, // { X86_REG_XMM9, "xmm9" },
16, // { X86_REG_XMM10, "xmm10" },
16, // { X86_REG_XMM11, "xmm11" },
16, // { X86_REG_XMM12, "xmm12" },
16, // { X86_REG_XMM13, "xmm13" },
16, // { X86_REG_XMM14, "xmm14" },
16, // { X86_REG_XMM15, "xmm15" },
16, // { X86_REG_XMM16, "xmm16" },
16, // { X86_REG_XMM17, "xmm17" },
16, // { X86_REG_XMM18, "xmm18" },
16, // { X86_REG_XMM19, "xmm19" },
16, // { X86_REG_XMM20, "xmm20" },
16, // { X86_REG_XMM21, "xmm21" },
16, // { X86_REG_XMM22, "xmm22" },
16, // { X86_REG_XMM23, "xmm23" },
16, // { X86_REG_XMM24, "xmm24" },
16, // { X86_REG_XMM25, "xmm25" },
16, // { X86_REG_XMM26, "xmm26" },
16, // { X86_REG_XMM27, "xmm27" },
16, // { X86_REG_XMM28, "xmm28" },
16, // { X86_REG_XMM29, "xmm29" },
16, // { X86_REG_XMM30, "xmm30" },
16, // { X86_REG_XMM31, "xmm31" },
32, // { X86_REG_YMM0, "ymm0" },
32, // { X86_REG_YMM1, "ymm1" },
32, // { X86_REG_YMM2, "ymm2" },
32, // { X86_REG_YMM3, "ymm3" },
32, // { X86_REG_YMM4, "ymm4" },
32, // { X86_REG_YMM5, "ymm5" },
32, // { X86_REG_YMM6, "ymm6" },
32, // { X86_REG_YMM7, "ymm7" },
32, // { X86_REG_YMM8, "ymm8" },
32, // { X86_REG_YMM9, "ymm9" },
32, // { X86_REG_YMM10, "ymm10" },
32, // { X86_REG_YMM11, "ymm11" },
32, // { X86_REG_YMM12, "ymm12" },
32, // { X86_REG_YMM13, "ymm13" },
32, // { X86_REG_YMM14, "ymm14" },
32, // { X86_REG_YMM15, "ymm15" },
32, // { X86_REG_YMM16, "ymm16" },
32, // { X86_REG_YMM17, "ymm17" },
32, // { X86_REG_YMM18, "ymm18" },
32, // { X86_REG_YMM19, "ymm19" },
32, // { X86_REG_YMM20, "ymm20" },
32, // { X86_REG_YMM21, "ymm21" },
32, // { X86_REG_YMM22, "ymm22" },
32, // { X86_REG_YMM23, "ymm23" },
32, // { X86_REG_YMM24, "ymm24" },
32, // { X86_REG_YMM25, "ymm25" },
32, // { X86_REG_YMM26, "ymm26" },
32, // { X86_REG_YMM27, "ymm27" },
32, // { X86_REG_YMM28, "ymm28" },
32, // { X86_REG_YMM29, "ymm29" },
32, // { X86_REG_YMM30, "ymm30" },
32, // { X86_REG_YMM31, "ymm31" },
64, // { X86_REG_ZMM0, "zmm0" },
64, // { X86_REG_ZMM1, "zmm1" },
64, // { X86_REG_ZMM2, "zmm2" },
64, // { X86_REG_ZMM3, "zmm3" },
64, // { X86_REG_ZMM4, "zmm4" },
64, // { X86_REG_ZMM5, "zmm5" },
64, // { X86_REG_ZMM6, "zmm6" },
64, // { X86_REG_ZMM7, "zmm7" },
64, // { X86_REG_ZMM8, "zmm8" },
64, // { X86_REG_ZMM9, "zmm9" },
64, // { X86_REG_ZMM10, "zmm10" },
64, // { X86_REG_ZMM11, "zmm11" },
64, // { X86_REG_ZMM12, "zmm12" },
64, // { X86_REG_ZMM13, "zmm13" },
64, // { X86_REG_ZMM14, "zmm14" },
64, // { X86_REG_ZMM15, "zmm15" },
64, // { X86_REG_ZMM16, "zmm16" },
64, // { X86_REG_ZMM17, "zmm17" },
64, // { X86_REG_ZMM18, "zmm18" },
64, // { X86_REG_ZMM19, "zmm19" },
64, // { X86_REG_ZMM20, "zmm20" },
64, // { X86_REG_ZMM21, "zmm21" },
64, // { X86_REG_ZMM22, "zmm22" },
64, // { X86_REG_ZMM23, "zmm23" },
64, // { X86_REG_ZMM24, "zmm24" },
64, // { X86_REG_ZMM25, "zmm25" },
64, // { X86_REG_ZMM26, "zmm26" },
64, // { X86_REG_ZMM27, "zmm27" },
64, // { X86_REG_ZMM28, "zmm28" },
64, // { X86_REG_ZMM29, "zmm29" },
64, // { X86_REG_ZMM30, "zmm30" },
64, // { X86_REG_ZMM31, "zmm31" },
1, // { X86_REG_R8B, "r8b" },
1, // { X86_REG_R9B, "r9b" },
1, // { X86_REG_R10B, "r10b" },
1, // { X86_REG_R11B, "r11b" },
1, // { X86_REG_R12B, "r12b" },
1, // { X86_REG_R13B, "r13b" },
1, // { X86_REG_R14B, "r14b" },
1, // { X86_REG_R15B, "r15b" },
4, // { X86_REG_R8D, "r8d" },
4, // { X86_REG_R9D, "r9d" },
4, // { X86_REG_R10D, "r10d" },
4, // { X86_REG_R11D, "r11d" },
4, // { X86_REG_R12D, "r12d" },
4, // { X86_REG_R13D, "r13d" },
4, // { X86_REG_R14D, "r14d" },
4, // { X86_REG_R15D, "r15d" },
2, // { X86_REG_R8W, "r8w" },
2, // { X86_REG_R9W, "r9w" },
2, // { X86_REG_R10W, "r10w" },
2, // { X86_REG_R11W, "r11w" },
2, // { X86_REG_R12W, "r12w" },
2, // { X86_REG_R13W, "r13w" },
2, // { X86_REG_R14W, "r14w" },
2, // { X86_REG_R15W, "r15w" },
16, // { X86_REG_BND0, "bnd0" },
16, // { X86_REG_BND1, "bnd0" },
16, // { X86_REG_BND2, "bnd0" },
16, // { X86_REG_BND3, "bnd0" },
};
// register size in 64bit mode
const uint8_t regsize_map_64 [] = {
0, // { X86_REG_INVALID, NULL },
1, // { X86_REG_AH, "ah" },
1, // { X86_REG_AL, "al" },
2, // { X86_REG_AX, "ax" },
1, // { X86_REG_BH, "bh" },
1, // { X86_REG_BL, "bl" },
2, // { X86_REG_BP, "bp" },
1, // { X86_REG_BPL, "bpl" },
2, // { X86_REG_BX, "bx" },
1, // { X86_REG_CH, "ch" },
1, // { X86_REG_CL, "cl" },
2, // { X86_REG_CS, "cs" },
2, // { X86_REG_CX, "cx" },
1, // { X86_REG_DH, "dh" },
2, // { X86_REG_DI, "di" },
1, // { X86_REG_DIL, "dil" },
1, // { X86_REG_DL, "dl" },
2, // { X86_REG_DS, "ds" },
2, // { X86_REG_DX, "dx" },
4, // { X86_REG_EAX, "eax" },
4, // { X86_REG_EBP, "ebp" },
4, // { X86_REG_EBX, "ebx" },
4, // { X86_REG_ECX, "ecx" },
4, // { X86_REG_EDI, "edi" },
4, // { X86_REG_EDX, "edx" },
8, // { X86_REG_EFLAGS, "flags" },
4, // { X86_REG_EIP, "eip" },
4, // { X86_REG_EIZ, "eiz" },
2, // { X86_REG_ES, "es" },
4, // { X86_REG_ESI, "esi" },
4, // { X86_REG_ESP, "esp" },
10, // { X86_REG_FPSW, "fpsw" },
2, // { X86_REG_FS, "fs" },
2, // { X86_REG_GS, "gs" },
2, // { X86_REG_IP, "ip" },
8, // { X86_REG_RAX, "rax" },
8, // { X86_REG_RBP, "rbp" },
8, // { X86_REG_RBX, "rbx" },
8, // { X86_REG_RCX, "rcx" },
8, // { X86_REG_RDI, "rdi" },
8, // { X86_REG_RDX, "rdx" },
8, // { X86_REG_RIP, "rip" },
8, // { X86_REG_RIZ, "riz" },
8, // { X86_REG_RSI, "rsi" },
8, // { X86_REG_RSP, "rsp" },
2, // { X86_REG_SI, "si" },
1, // { X86_REG_SIL, "sil" },
2, // { X86_REG_SP, "sp" },
1, // { X86_REG_SPL, "spl" },
2, // { X86_REG_SS, "ss" },
8, // { X86_REG_CR0, "cr0" },
8, // { X86_REG_CR1, "cr1" },
8, // { X86_REG_CR2, "cr2" },
8, // { X86_REG_CR3, "cr3" },
8, // { X86_REG_CR4, "cr4" },
8, // { X86_REG_CR5, "cr5" },
8, // { X86_REG_CR6, "cr6" },
8, // { X86_REG_CR7, "cr7" },
8, // { X86_REG_CR8, "cr8" },
8, // { X86_REG_CR9, "cr9" },
8, // { X86_REG_CR10, "cr10" },
8, // { X86_REG_CR11, "cr11" },
8, // { X86_REG_CR12, "cr12" },
8, // { X86_REG_CR13, "cr13" },
8, // { X86_REG_CR14, "cr14" },
8, // { X86_REG_CR15, "cr15" },
8, // { X86_REG_DR0, "dr0" },
8, // { X86_REG_DR1, "dr1" },
8, // { X86_REG_DR2, "dr2" },
8, // { X86_REG_DR3, "dr3" },
8, // { X86_REG_DR4, "dr4" },
8, // { X86_REG_DR5, "dr5" },
8, // { X86_REG_DR6, "dr6" },
8, // { X86_REG_DR7, "dr7" },
8, // { X86_REG_DR8, "dr8" },
8, // { X86_REG_DR9, "dr9" },
8, // { X86_REG_DR10, "dr10" },
8, // { X86_REG_DR11, "dr11" },
8, // { X86_REG_DR12, "dr12" },
8, // { X86_REG_DR13, "dr13" },
8, // { X86_REG_DR14, "dr14" },
8, // { X86_REG_DR15, "dr15" },
10, // { X86_REG_FP0, "fp0" },
10, // { X86_REG_FP1, "fp1" },
10, // { X86_REG_FP2, "fp2" },
10, // { X86_REG_FP3, "fp3" },
10, // { X86_REG_FP4, "fp4" },
10, // { X86_REG_FP5, "fp5" },
10, // { X86_REG_FP6, "fp6" },
10, // { X86_REG_FP7, "fp7" },
2, // { X86_REG_K0, "k0" },
2, // { X86_REG_K1, "k1" },
2, // { X86_REG_K2, "k2" },
2, // { X86_REG_K3, "k3" },
2, // { X86_REG_K4, "k4" },
2, // { X86_REG_K5, "k5" },
2, // { X86_REG_K6, "k6" },
2, // { X86_REG_K7, "k7" },
8, // { X86_REG_MM0, "mm0" },
8, // { X86_REG_MM1, "mm1" },
8, // { X86_REG_MM2, "mm2" },
8, // { X86_REG_MM3, "mm3" },
8, // { X86_REG_MM4, "mm4" },
8, // { X86_REG_MM5, "mm5" },
8, // { X86_REG_MM6, "mm6" },
8, // { X86_REG_MM7, "mm7" },
8, // { X86_REG_R8, "r8" },
8, // { X86_REG_R9, "r9" },
8, // { X86_REG_R10, "r10" },
8, // { X86_REG_R11, "r11" },
8, // { X86_REG_R12, "r12" },
8, // { X86_REG_R13, "r13" },
8, // { X86_REG_R14, "r14" },
8, // { X86_REG_R15, "r15" },
10, // { X86_REG_ST0, "st0" },
10, // { X86_REG_ST1, "st1" },
10, // { X86_REG_ST2, "st2" },
10, // { X86_REG_ST3, "st3" },
10, // { X86_REG_ST4, "st4" },
10, // { X86_REG_ST5, "st5" },
10, // { X86_REG_ST6, "st6" },
10, // { X86_REG_ST7, "st7" },
16, // { X86_REG_XMM0, "xmm0" },
16, // { X86_REG_XMM1, "xmm1" },
16, // { X86_REG_XMM2, "xmm2" },
16, // { X86_REG_XMM3, "xmm3" },
16, // { X86_REG_XMM4, "xmm4" },
16, // { X86_REG_XMM5, "xmm5" },
16, // { X86_REG_XMM6, "xmm6" },
16, // { X86_REG_XMM7, "xmm7" },
16, // { X86_REG_XMM8, "xmm8" },
16, // { X86_REG_XMM9, "xmm9" },
16, // { X86_REG_XMM10, "xmm10" },
16, // { X86_REG_XMM11, "xmm11" },
16, // { X86_REG_XMM12, "xmm12" },
16, // { X86_REG_XMM13, "xmm13" },
16, // { X86_REG_XMM14, "xmm14" },
16, // { X86_REG_XMM15, "xmm15" },
16, // { X86_REG_XMM16, "xmm16" },
16, // { X86_REG_XMM17, "xmm17" },
16, // { X86_REG_XMM18, "xmm18" },
16, // { X86_REG_XMM19, "xmm19" },
16, // { X86_REG_XMM20, "xmm20" },
16, // { X86_REG_XMM21, "xmm21" },
16, // { X86_REG_XMM22, "xmm22" },
16, // { X86_REG_XMM23, "xmm23" },
16, // { X86_REG_XMM24, "xmm24" },
16, // { X86_REG_XMM25, "xmm25" },
16, // { X86_REG_XMM26, "xmm26" },
16, // { X86_REG_XMM27, "xmm27" },
16, // { X86_REG_XMM28, "xmm28" },
16, // { X86_REG_XMM29, "xmm29" },
16, // { X86_REG_XMM30, "xmm30" },
16, // { X86_REG_XMM31, "xmm31" },
32, // { X86_REG_YMM0, "ymm0" },
32, // { X86_REG_YMM1, "ymm1" },
32, // { X86_REG_YMM2, "ymm2" },
32, // { X86_REG_YMM3, "ymm3" },
32, // { X86_REG_YMM4, "ymm4" },
32, // { X86_REG_YMM5, "ymm5" },
32, // { X86_REG_YMM6, "ymm6" },
32, // { X86_REG_YMM7, "ymm7" },
32, // { X86_REG_YMM8, "ymm8" },
32, // { X86_REG_YMM9, "ymm9" },
32, // { X86_REG_YMM10, "ymm10" },
32, // { X86_REG_YMM11, "ymm11" },
32, // { X86_REG_YMM12, "ymm12" },
32, // { X86_REG_YMM13, "ymm13" },
32, // { X86_REG_YMM14, "ymm14" },
32, // { X86_REG_YMM15, "ymm15" },
32, // { X86_REG_YMM16, "ymm16" },
32, // { X86_REG_YMM17, "ymm17" },
32, // { X86_REG_YMM18, "ymm18" },
32, // { X86_REG_YMM19, "ymm19" },
32, // { X86_REG_YMM20, "ymm20" },
32, // { X86_REG_YMM21, "ymm21" },
32, // { X86_REG_YMM22, "ymm22" },
32, // { X86_REG_YMM23, "ymm23" },
32, // { X86_REG_YMM24, "ymm24" },
32, // { X86_REG_YMM25, "ymm25" },
32, // { X86_REG_YMM26, "ymm26" },
32, // { X86_REG_YMM27, "ymm27" },
32, // { X86_REG_YMM28, "ymm28" },
32, // { X86_REG_YMM29, "ymm29" },
32, // { X86_REG_YMM30, "ymm30" },
32, // { X86_REG_YMM31, "ymm31" },
64, // { X86_REG_ZMM0, "zmm0" },
64, // { X86_REG_ZMM1, "zmm1" },
64, // { X86_REG_ZMM2, "zmm2" },
64, // { X86_REG_ZMM3, "zmm3" },
64, // { X86_REG_ZMM4, "zmm4" },
64, // { X86_REG_ZMM5, "zmm5" },
64, // { X86_REG_ZMM6, "zmm6" },
64, // { X86_REG_ZMM7, "zmm7" },
64, // { X86_REG_ZMM8, "zmm8" },
64, // { X86_REG_ZMM9, "zmm9" },
64, // { X86_REG_ZMM10, "zmm10" },
64, // { X86_REG_ZMM11, "zmm11" },
64, // { X86_REG_ZMM12, "zmm12" },
64, // { X86_REG_ZMM13, "zmm13" },
64, // { X86_REG_ZMM14, "zmm14" },
64, // { X86_REG_ZMM15, "zmm15" },
64, // { X86_REG_ZMM16, "zmm16" },
64, // { X86_REG_ZMM17, "zmm17" },
64, // { X86_REG_ZMM18, "zmm18" },
64, // { X86_REG_ZMM19, "zmm19" },
64, // { X86_REG_ZMM20, "zmm20" },
64, // { X86_REG_ZMM21, "zmm21" },
64, // { X86_REG_ZMM22, "zmm22" },
64, // { X86_REG_ZMM23, "zmm23" },
64, // { X86_REG_ZMM24, "zmm24" },
64, // { X86_REG_ZMM25, "zmm25" },
64, // { X86_REG_ZMM26, "zmm26" },
64, // { X86_REG_ZMM27, "zmm27" },
64, // { X86_REG_ZMM28, "zmm28" },
64, // { X86_REG_ZMM29, "zmm29" },
64, // { X86_REG_ZMM30, "zmm30" },
64, // { X86_REG_ZMM31, "zmm31" },
1, // { X86_REG_R8B, "r8b" },
1, // { X86_REG_R9B, "r9b" },
1, // { X86_REG_R10B, "r10b" },
1, // { X86_REG_R11B, "r11b" },
1, // { X86_REG_R12B, "r12b" },
1, // { X86_REG_R13B, "r13b" },
1, // { X86_REG_R14B, "r14b" },
1, // { X86_REG_R15B, "r15b" },
4, // { X86_REG_R8D, "r8d" },
4, // { X86_REG_R9D, "r9d" },
4, // { X86_REG_R10D, "r10d" },
4, // { X86_REG_R11D, "r11d" },
4, // { X86_REG_R12D, "r12d" },
4, // { X86_REG_R13D, "r13d" },
4, // { X86_REG_R14D, "r14d" },
4, // { X86_REG_R15D, "r15d" },
2, // { X86_REG_R8W, "r8w" },
2, // { X86_REG_R9W, "r9w" },
2, // { X86_REG_R10W, "r10w" },
2, // { X86_REG_R11W, "r11w" },
2, // { X86_REG_R12W, "r12w" },
2, // { X86_REG_R13W, "r13w" },
2, // { X86_REG_R14W, "r14w" },
2, // { X86_REG_R15W, "r15w" },
16, // { X86_REG_BND0, "bnd0" },
16, // { X86_REG_BND1, "bnd0" },
16, // { X86_REG_BND2, "bnd0" },
16, // { X86_REG_BND3, "bnd0" },
};
const char *X86_reg_name(csh handle, unsigned int reg)
{
#ifndef CAPSTONE_DIET
cs_struct *ud = (cs_struct *)handle;
if (reg >= ARR_SIZE(reg_name_maps))
return NULL;
if (reg == X86_REG_EFLAGS) {
if (ud->mode & CS_MODE_32)
return "eflags";
if (ud->mode & CS_MODE_64)
return "rflags";
}
return reg_name_maps[reg].name;
#else
return NULL;
#endif
}
#ifndef CAPSTONE_DIET
static const char * const insn_name_maps[] = {
NULL, // X86_INS_INVALID
#ifndef CAPSTONE_X86_REDUCE
#include "X86MappingInsnName.inc"
#else
#include "X86MappingInsnName_reduce.inc"
#endif
};
#endif
// NOTE: insn_name_maps[] is sorted in order
const char *X86_insn_name(csh handle, unsigned int id)
{
#ifndef CAPSTONE_DIET
if (id >= ARR_SIZE(insn_name_maps))
return NULL;
return insn_name_maps[id];
#else
return NULL;
#endif
}
#ifndef CAPSTONE_DIET
static const name_map group_name_maps[] = {
// generic groups
{ X86_GRP_INVALID, NULL },
{ X86_GRP_JUMP, "jump" },
{ X86_GRP_CALL, "call" },
{ X86_GRP_RET, "ret" },
{ X86_GRP_INT, "int" },
{ X86_GRP_IRET, "iret" },
{ X86_GRP_PRIVILEGE, "privilege" },
{ X86_GRP_BRANCH_RELATIVE, "branch_relative" },
// architecture-specific groups
{ X86_GRP_VM, "vm" },
{ X86_GRP_3DNOW, "3dnow" },
{ X86_GRP_AES, "aes" },
{ X86_GRP_ADX, "adx" },
{ X86_GRP_AVX, "avx" },
{ X86_GRP_AVX2, "avx2" },
{ X86_GRP_AVX512, "avx512" },
{ X86_GRP_BMI, "bmi" },
{ X86_GRP_BMI2, "bmi2" },
{ X86_GRP_CMOV, "cmov" },
{ X86_GRP_F16C, "fc16" },
{ X86_GRP_FMA, "fma" },
{ X86_GRP_FMA4, "fma4" },
{ X86_GRP_FSGSBASE, "fsgsbase" },
{ X86_GRP_HLE, "hle" },
{ X86_GRP_MMX, "mmx" },
{ X86_GRP_MODE32, "mode32" },
{ X86_GRP_MODE64, "mode64" },
{ X86_GRP_RTM, "rtm" },
{ X86_GRP_SHA, "sha" },
{ X86_GRP_SSE1, "sse1" },
{ X86_GRP_SSE2, "sse2" },
{ X86_GRP_SSE3, "sse3" },
{ X86_GRP_SSE41, "sse41" },
{ X86_GRP_SSE42, "sse42" },
{ X86_GRP_SSE4A, "sse4a" },
{ X86_GRP_SSSE3, "ssse3" },
{ X86_GRP_PCLMUL, "pclmul" },
{ X86_GRP_XOP, "xop" },
{ X86_GRP_CDI, "cdi" },
{ X86_GRP_ERI, "eri" },
{ X86_GRP_TBM, "tbm" },
{ X86_GRP_16BITMODE, "16bitmode" },
{ X86_GRP_NOT64BITMODE, "not64bitmode" },
{ X86_GRP_SGX, "sgx" },
{ X86_GRP_DQI, "dqi" },
{ X86_GRP_BWI, "bwi" },
{ X86_GRP_PFI, "pfi" },
{ X86_GRP_VLX, "vlx" },
{ X86_GRP_SMAP, "smap" },
{ X86_GRP_NOVLX, "novlx" },
{ X86_GRP_FPU, "fpu" },
};
#endif
const char *X86_group_name(csh handle, unsigned int id)
{
#ifndef CAPSTONE_DIET
return id2name(group_name_maps, ARR_SIZE(group_name_maps), id);
#else
return NULL;
#endif
}
#define GET_INSTRINFO_ENUM
#ifdef CAPSTONE_X86_REDUCE
#include "X86GenInstrInfo_reduce.inc"
const insn_map_x86 insns[] = { // reduce x86 instructions
#include "X86MappingInsn_reduce.inc"
};
#else
#include "X86GenInstrInfo.inc"
const insn_map_x86 insns[] = { // full x86 instructions
#include "X86MappingInsn.inc"
};
#endif
#ifndef CAPSTONE_DIET
// in arr, replace r1 = r2
static void arr_replace(uint16_t *arr, uint8_t max, x86_reg r1, x86_reg r2)
{
uint8_t i;
for(i = 0; i < max; i++) {
if (arr[i] == r1) {
arr[i] = r2;
break;
}
}
}
#endif
// look for @id in @insns
// return -1 if not found
unsigned int find_insn(unsigned int id)
{
// binary searching since the IDs are sorted in order
unsigned int left, right, m;
unsigned int max = ARR_SIZE(insns);
right = max - 1;
if (id < insns[0].id || id > insns[right].id)
// not found
return -1;
left = 0;
while(left <= right) {
m = (left + right) / 2;
if (id == insns[m].id) {
return m;
}
if (id < insns[m].id)
right = m - 1;
else
left = m + 1;
}
// not found
// printf("NOT FOUNDDDDDDDDDDDDDDD id = %u\n", id);
return -1;
}
// given internal insn id, return public instruction info
void X86_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id)
{
unsigned int i = find_insn(id);
if (i != -1) {
insn->id = insns[i].mapid;
if (h->detail) {
#ifndef CAPSTONE_DIET
memcpy(insn->detail->regs_read, insns[i].regs_use, sizeof(insns[i].regs_use));
insn->detail->regs_read_count = (uint8_t)count_positive(insns[i].regs_use);
// special cases when regs_write[] depends on arch
switch(id) {
default:
memcpy(insn->detail->regs_write, insns[i].regs_mod, sizeof(insns[i].regs_mod));
insn->detail->regs_write_count = (uint8_t)count_positive(insns[i].regs_mod);
break;
case X86_RDTSC:
if (h->mode == CS_MODE_64) {
memcpy(insn->detail->regs_write, insns[i].regs_mod, sizeof(insns[i].regs_mod));
insn->detail->regs_write_count = (uint8_t)count_positive(insns[i].regs_mod);
} else {
insn->detail->regs_write[0] = X86_REG_EAX;
insn->detail->regs_write[1] = X86_REG_EDX;
insn->detail->regs_write_count = 2;
}
break;
case X86_RDTSCP:
if (h->mode == CS_MODE_64) {
memcpy(insn->detail->regs_write, insns[i].regs_mod, sizeof(insns[i].regs_mod));
insn->detail->regs_write_count = (uint8_t)count_positive(insns[i].regs_mod);
} else {
insn->detail->regs_write[0] = X86_REG_EAX;
insn->detail->regs_write[1] = X86_REG_ECX;
insn->detail->regs_write[2] = X86_REG_EDX;
insn->detail->regs_write_count = 3;
}
break;
}
switch(insn->id) {
default:
break;
case X86_INS_LOOP:
case X86_INS_LOOPE:
case X86_INS_LOOPNE:
switch(h->mode) {
default: break;
case CS_MODE_16:
insn->detail->regs_read[0] = X86_REG_CX;
insn->detail->regs_read_count = 1;
insn->detail->regs_write[0] = X86_REG_CX;
insn->detail->regs_write_count = 1;
break;
case CS_MODE_32:
insn->detail->regs_read[0] = X86_REG_ECX;
insn->detail->regs_read_count = 1;
insn->detail->regs_write[0] = X86_REG_ECX;
insn->detail->regs_write_count = 1;
break;
case CS_MODE_64:
insn->detail->regs_read[0] = X86_REG_RCX;
insn->detail->regs_read_count = 1;
insn->detail->regs_write[0] = X86_REG_RCX;
insn->detail->regs_write_count = 1;
break;
}
// LOOPE & LOOPNE also read EFLAGS
if (insn->id != X86_INS_LOOP) {
insn->detail->regs_read[1] = X86_REG_EFLAGS;
insn->detail->regs_read_count = 2;
}
break;
case X86_INS_LODSB:
case X86_INS_LODSD:
case X86_INS_LODSQ:
case X86_INS_LODSW:
switch(h->mode) {
default:
break;
case CS_MODE_16:
arr_replace(insn->detail->regs_read, insn->detail->regs_read_count, X86_REG_ESI, X86_REG_SI);
arr_replace(insn->detail->regs_write, insn->detail->regs_write_count, X86_REG_ESI, X86_REG_SI);
break;
case CS_MODE_64:
arr_replace(insn->detail->regs_read, insn->detail->regs_read_count, X86_REG_ESI, X86_REG_RSI);
arr_replace(insn->detail->regs_write, insn->detail->regs_write_count, X86_REG_ESI, X86_REG_RSI);
break;
}
break;
case X86_INS_SCASB:
case X86_INS_SCASW:
case X86_INS_SCASQ:
case X86_INS_STOSB:
case X86_INS_STOSD:
case X86_INS_STOSQ:
case X86_INS_STOSW:
switch(h->mode) {
default:
break;
case CS_MODE_16:
arr_replace(insn->detail->regs_read, insn->detail->regs_read_count, X86_REG_EDI, X86_REG_DI);
arr_replace(insn->detail->regs_write, insn->detail->regs_write_count, X86_REG_EDI, X86_REG_DI);
break;
case CS_MODE_64:
arr_replace(insn->detail->regs_read, insn->detail->regs_read_count, X86_REG_EDI, X86_REG_RDI);
arr_replace(insn->detail->regs_write, insn->detail->regs_write_count, X86_REG_EDI, X86_REG_RDI);
break;
}
break;
case X86_INS_CMPSB:
case X86_INS_CMPSD:
case X86_INS_CMPSQ:
case X86_INS_CMPSW:
case X86_INS_MOVSB:
case X86_INS_MOVSW:
case X86_INS_MOVSD:
case X86_INS_MOVSQ:
switch(h->mode) {
default:
break;
case CS_MODE_16:
arr_replace(insn->detail->regs_read, insn->detail->regs_read_count, X86_REG_EDI, X86_REG_DI);
arr_replace(insn->detail->regs_write, insn->detail->regs_write_count, X86_REG_EDI, X86_REG_DI);
arr_replace(insn->detail->regs_read, insn->detail->regs_read_count, X86_REG_ESI, X86_REG_SI);
arr_replace(insn->detail->regs_write, insn->detail->regs_write_count, X86_REG_ESI, X86_REG_SI);
break;
case CS_MODE_64:
arr_replace(insn->detail->regs_read, insn->detail->regs_read_count, X86_REG_EDI, X86_REG_RDI);
arr_replace(insn->detail->regs_write, insn->detail->regs_write_count, X86_REG_EDI, X86_REG_RDI);
arr_replace(insn->detail->regs_read, insn->detail->regs_read_count, X86_REG_ESI, X86_REG_RSI);
arr_replace(insn->detail->regs_write, insn->detail->regs_write_count, X86_REG_ESI, X86_REG_RSI);
break;
}
break;
case X86_INS_RET:
switch(h->mode) {
case CS_MODE_16:
insn->detail->regs_write[0] = X86_REG_SP;
insn->detail->regs_read[0] = X86_REG_SP;
break;
case CS_MODE_32:
insn->detail->regs_write[0] = X86_REG_ESP;
insn->detail->regs_read[0] = X86_REG_ESP;
break;
default: // 64-bit
insn->detail->regs_write[0] = X86_REG_RSP;
insn->detail->regs_read[0] = X86_REG_RSP;
break;
}
insn->detail->regs_write_count = 1;
insn->detail->regs_read_count = 1;
break;
}
memcpy(insn->detail->groups, insns[i].groups, sizeof(insns[i].groups));
insn->detail->groups_count = (uint8_t)count_positive8(insns[i].groups);
if (insns[i].branch || insns[i].indirect_branch) {
// this insn also belongs to JUMP group. add JUMP group
insn->detail->groups[insn->detail->groups_count] = X86_GRP_JUMP;
insn->detail->groups_count++;
}
switch (insns[i].id) {
case X86_OUT8ir:
case X86_OUT16ir:
case X86_OUT32ir:
if (insn->detail->x86.operands[0].imm == -78) {
// Writing to port 0xb2 causes an SMI on most platforms
// See: http://cs.gmu.edu/~tr-admin/papers/GMU-CS-TR-2011-8.pdf
insn->detail->groups[insn->detail->groups_count] = X86_GRP_INT;
insn->detail->groups_count++;
}
break;
default:
break;
}
#endif
}
}
}
// map special instructions with accumulate registers.
// this is needed because LLVM embeds these register names into AsmStrs[],
// but not separately in operands
struct insn_reg {
uint16_t insn;
x86_reg reg;
enum cs_ac_type access;
};
struct insn_reg2 {
uint16_t insn;
x86_reg reg1, reg2;
enum cs_ac_type access1, access2;
};
static const struct insn_reg insn_regs_att[] = {
{ X86_INSB, X86_REG_DX, CS_AC_READ },
{ X86_INSL, X86_REG_DX, CS_AC_READ },
{ X86_INSW, X86_REG_DX, CS_AC_READ },
{ X86_MOV16o16a, X86_REG_AX, CS_AC_READ },
{ X86_MOV16o32a, X86_REG_AX, CS_AC_READ },
{ X86_MOV16o64a, X86_REG_AX, CS_AC_READ },
{ X86_MOV32o16a, X86_REG_EAX, CS_AC_READ },
{ X86_MOV32o32a, X86_REG_EAX, CS_AC_READ },
{ X86_MOV32o64a, X86_REG_EAX, CS_AC_READ },
{ X86_MOV64o32a, X86_REG_RAX, CS_AC_READ },
{ X86_MOV64o64a, X86_REG_RAX, CS_AC_READ },
{ X86_MOV8o16a, X86_REG_AL, CS_AC_READ },
{ X86_MOV8o32a, X86_REG_AL, CS_AC_READ },
{ X86_MOV8o64a, X86_REG_AL, CS_AC_READ },
{ X86_OUT16ir, X86_REG_AX, CS_AC_READ },
{ X86_OUT32ir, X86_REG_EAX, CS_AC_READ },
{ X86_OUT8ir, X86_REG_AL, CS_AC_READ },
{ X86_POPDS16, X86_REG_DS, CS_AC_WRITE },
{ X86_POPDS32, X86_REG_DS, CS_AC_WRITE },
{ X86_POPES16, X86_REG_ES, CS_AC_WRITE },
{ X86_POPES32, X86_REG_ES, CS_AC_WRITE },
{ X86_POPFS16, X86_REG_FS, CS_AC_WRITE },
{ X86_POPFS32, X86_REG_FS, CS_AC_WRITE },
{ X86_POPFS64, X86_REG_FS, CS_AC_WRITE },
{ X86_POPGS16, X86_REG_GS, CS_AC_WRITE },
{ X86_POPGS32, X86_REG_GS, CS_AC_WRITE },
{ X86_POPGS64, X86_REG_GS, CS_AC_WRITE },
{ X86_POPSS16, X86_REG_SS, CS_AC_WRITE },
{ X86_POPSS32, X86_REG_SS, CS_AC_WRITE },
{ X86_PUSHCS16, X86_REG_CS, CS_AC_READ },
{ X86_PUSHCS32, X86_REG_CS, CS_AC_READ },
{ X86_PUSHDS16, X86_REG_DS, CS_AC_READ },
{ X86_PUSHDS32, X86_REG_DS, CS_AC_READ },
{ X86_PUSHES16, X86_REG_ES, CS_AC_READ },
{ X86_PUSHES32, X86_REG_ES, CS_AC_READ },
{ X86_PUSHFS16, X86_REG_FS, CS_AC_READ },
{ X86_PUSHFS32, X86_REG_FS, CS_AC_READ },
{ X86_PUSHFS64, X86_REG_FS, CS_AC_READ },
{ X86_PUSHGS16, X86_REG_GS, CS_AC_READ },
{ X86_PUSHGS32, X86_REG_GS, CS_AC_READ },
{ X86_PUSHGS64, X86_REG_GS, CS_AC_READ },
{ X86_PUSHSS16, X86_REG_SS, CS_AC_READ },
{ X86_PUSHSS32, X86_REG_SS, CS_AC_READ },
{ X86_RCL16rCL, X86_REG_CL, CS_AC_READ },
{ X86_RCL32rCL, X86_REG_CL, CS_AC_READ },
{ X86_RCL64rCL, X86_REG_CL, CS_AC_READ },
{ X86_RCL8rCL, X86_REG_CL, CS_AC_READ },
{ X86_RCR16rCL, X86_REG_CL, CS_AC_READ },
{ X86_RCR32rCL, X86_REG_CL, CS_AC_READ },
{ X86_RCR64rCL, X86_REG_CL, CS_AC_READ },
{ X86_RCR8rCL, X86_REG_CL, CS_AC_READ },
{ X86_ROL16rCL, X86_REG_CL, CS_AC_READ },
{ X86_ROL32rCL, X86_REG_CL, CS_AC_READ },
{ X86_ROL64rCL, X86_REG_CL, CS_AC_READ },
{ X86_ROL8rCL, X86_REG_CL, CS_AC_READ },
{ X86_ROR16rCL, X86_REG_CL, CS_AC_READ },
{ X86_ROR32rCL, X86_REG_CL, CS_AC_READ },
{ X86_ROR64rCL, X86_REG_CL, CS_AC_READ },
{ X86_ROR8rCL, X86_REG_CL, CS_AC_READ },
{ X86_SAL16rCL, X86_REG_CL, CS_AC_READ },
{ X86_SAL32rCL, X86_REG_CL, CS_AC_READ },
{ X86_SAL64rCL, X86_REG_CL, CS_AC_READ },
{ X86_SAL8rCL, X86_REG_CL, CS_AC_READ },
{ X86_SAR16rCL, X86_REG_CL, CS_AC_READ },
{ X86_SAR32rCL, X86_REG_CL, CS_AC_READ },
{ X86_SAR64rCL, X86_REG_CL, CS_AC_READ },
{ X86_SAR8rCL, X86_REG_CL, CS_AC_READ },
{ X86_SHL16rCL, X86_REG_CL, CS_AC_READ },
{ X86_SHL32rCL, X86_REG_CL, CS_AC_READ },
{ X86_SHL64rCL, X86_REG_CL, CS_AC_READ },
{ X86_SHL8rCL, X86_REG_CL, CS_AC_READ },
{ X86_SHLD16mrCL, X86_REG_CL, CS_AC_READ },
{ X86_SHLD16rrCL, X86_REG_CL, CS_AC_READ },
{ X86_SHLD32mrCL, X86_REG_CL, CS_AC_READ },
{ X86_SHLD32rrCL, X86_REG_CL, CS_AC_READ },
{ X86_SHLD64mrCL, X86_REG_CL, CS_AC_READ },
{ X86_SHLD64rrCL, X86_REG_CL, CS_AC_READ },
{ X86_SHR16rCL, X86_REG_CL, CS_AC_READ },
{ X86_SHR32rCL, X86_REG_CL, CS_AC_READ },
{ X86_SHR64rCL, X86_REG_CL, CS_AC_READ },
{ X86_SHR8rCL, X86_REG_CL, CS_AC_READ },
{ X86_SHRD16mrCL, X86_REG_CL, CS_AC_READ },
{ X86_SHRD16rrCL, X86_REG_CL, CS_AC_READ },
{ X86_SHRD32mrCL, X86_REG_CL, CS_AC_READ },
{ X86_SHRD32rrCL, X86_REG_CL, CS_AC_READ },
{ X86_SHRD64mrCL, X86_REG_CL, CS_AC_READ },
{ X86_SHRD64rrCL, X86_REG_CL, CS_AC_READ },
{ X86_XCHG16ar, X86_REG_AX, CS_AC_WRITE | CS_AC_READ },
{ X86_XCHG32ar, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ },
{ X86_XCHG64ar, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ },
};
static const struct insn_reg insn_regs_att_extra[] = {
// dummy entry, to avoid empty array
{ 0, 0 },
#ifndef CAPSTONE_X86_REDUCE
{ X86_ADD_FrST0, X86_REG_ST0, CS_AC_READ },
{ X86_DIVR_FrST0, X86_REG_ST0, CS_AC_READ },
{ X86_DIV_FrST0, X86_REG_ST0, CS_AC_READ },
{ X86_FNSTSW16r, X86_REG_AX, CS_AC_READ },
{ X86_MUL_FrST0, X86_REG_ST0, CS_AC_READ },
{ X86_SKINIT, X86_REG_EAX, CS_AC_READ },
{ X86_SUBR_FrST0, X86_REG_ST0, CS_AC_READ },
{ X86_SUB_FrST0, X86_REG_ST0, CS_AC_READ },
{ X86_VMLOAD32, X86_REG_EAX, CS_AC_READ },
{ X86_VMLOAD64, X86_REG_RAX, CS_AC_READ },
{ X86_VMRUN32, X86_REG_EAX, CS_AC_READ },
{ X86_VMRUN64, X86_REG_RAX, CS_AC_READ },
{ X86_VMSAVE32, X86_REG_EAX, CS_AC_READ },
{ X86_VMSAVE64, X86_REG_RAX, CS_AC_READ },
#endif
};
static const struct insn_reg insn_regs_intel[] = {
{ X86_ADC16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ },
{ X86_ADC32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ },
{ X86_ADC64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ },
{ X86_ADC8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ },
{ X86_ADD16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ },
{ X86_ADD32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ },
{ X86_ADD64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ },
{ X86_ADD8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ },
{ X86_AND16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ },
{ X86_AND32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ },
{ X86_AND64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ },
{ X86_AND8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ },
{ X86_CMP16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ },
{ X86_CMP32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ },
{ X86_CMP64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ },
{ X86_CMP8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ },
{ X86_IN16ri, X86_REG_AX, CS_AC_WRITE },
{ X86_IN32ri, X86_REG_EAX, CS_AC_WRITE },
{ X86_IN8ri, X86_REG_AL, CS_AC_WRITE },
{ X86_LODSB, X86_REG_AL, CS_AC_WRITE },
{ X86_LODSL, X86_REG_EAX, CS_AC_WRITE },
{ X86_LODSQ, X86_REG_RAX, CS_AC_WRITE },
{ X86_LODSW, X86_REG_AX, CS_AC_WRITE },
{ X86_MOV16ao16, X86_REG_AX, CS_AC_WRITE }, // 16-bit A1 1020 // mov ax, word ptr [0x2010]
{ X86_MOV16ao32, X86_REG_AX, CS_AC_WRITE }, // 32-bit A1 10203040 // mov ax, word ptr [0x40302010]
{ X86_MOV16ao64, X86_REG_AX, CS_AC_WRITE }, // 64-bit 66 A1 1020304050607080 // movabs ax, word ptr [0x8070605040302010]
{ X86_MOV32ao16, X86_REG_EAX, CS_AC_WRITE }, // 32-bit 67 A1 1020 // mov eax, dword ptr [0x2010]
{ X86_MOV32ao32, X86_REG_EAX, CS_AC_WRITE }, // 32-bit A1 10203040 // mov eax, dword ptr [0x40302010]
{ X86_MOV32ao64, X86_REG_EAX, CS_AC_WRITE }, // 64-bit A1 1020304050607080 // movabs eax, dword ptr [0x8070605040302010]
{ X86_MOV64ao32, X86_REG_RAX, CS_AC_WRITE }, // 64-bit 48 8B04 10203040 // mov rax, qword ptr [0x40302010]
{ X86_MOV64ao64, X86_REG_RAX, CS_AC_WRITE }, // 64-bit 48 A1 1020304050607080 // movabs rax, qword ptr [0x8070605040302010]
{ X86_MOV8ao16, X86_REG_AL, CS_AC_WRITE }, // 16-bit A0 1020 // mov al, byte ptr [0x2010]
{ X86_MOV8ao32, X86_REG_AL, CS_AC_WRITE }, // 32-bit A0 10203040 // mov al, byte ptr [0x40302010]
{ X86_MOV8ao64, X86_REG_AL, CS_AC_WRITE }, // 64-bit 66 A0 1020304050607080 // movabs al, byte ptr [0x8070605040302010]
{ X86_OR16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ },
{ X86_OR32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ },
{ X86_OR64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ },
{ X86_OR8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ },
{ X86_OUTSB, X86_REG_DX, CS_AC_WRITE },
{ X86_OUTSL, X86_REG_DX, CS_AC_WRITE },
{ X86_OUTSW, X86_REG_DX, CS_AC_WRITE },
{ X86_POPDS16, X86_REG_DS, CS_AC_WRITE },
{ X86_POPDS32, X86_REG_DS, CS_AC_WRITE },
{ X86_POPES16, X86_REG_ES, CS_AC_WRITE },
{ X86_POPES32, X86_REG_ES, CS_AC_WRITE },
{ X86_POPFS16, X86_REG_FS, CS_AC_WRITE },
{ X86_POPFS32, X86_REG_FS, CS_AC_WRITE },
{ X86_POPFS64, X86_REG_FS, CS_AC_WRITE },
{ X86_POPGS16, X86_REG_GS, CS_AC_WRITE },
{ X86_POPGS32, X86_REG_GS, CS_AC_WRITE },
{ X86_POPGS64, X86_REG_GS, CS_AC_WRITE },
{ X86_POPSS16, X86_REG_SS, CS_AC_WRITE },
{ X86_POPSS32, X86_REG_SS, CS_AC_WRITE },
{ X86_PUSHCS16, X86_REG_CS, CS_AC_READ },
{ X86_PUSHCS32, X86_REG_CS, CS_AC_READ },
{ X86_PUSHDS16, X86_REG_DS, CS_AC_READ },
{ X86_PUSHDS32, X86_REG_DS, CS_AC_READ },
{ X86_PUSHES16, X86_REG_ES, CS_AC_READ },
{ X86_PUSHES32, X86_REG_ES, CS_AC_READ },
{ X86_PUSHFS16, X86_REG_FS, CS_AC_READ },
{ X86_PUSHFS32, X86_REG_FS, CS_AC_READ },
{ X86_PUSHFS64, X86_REG_FS, CS_AC_READ },
{ X86_PUSHGS16, X86_REG_GS, CS_AC_READ },
{ X86_PUSHGS32, X86_REG_GS, CS_AC_READ },
{ X86_PUSHGS64, X86_REG_GS, CS_AC_READ },
{ X86_PUSHSS16, X86_REG_SS, CS_AC_READ },
{ X86_PUSHSS32, X86_REG_SS, CS_AC_READ },
{ X86_SBB16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ },
{ X86_SBB32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ },
{ X86_SBB64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ },
{ X86_SBB8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ },
{ X86_SCASB, X86_REG_AL, CS_AC_WRITE | CS_AC_READ },
{ X86_SCASL, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ },
{ X86_SCASQ, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ },
{ X86_SCASW, X86_REG_AX, CS_AC_WRITE | CS_AC_READ },
{ X86_SUB16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ },
{ X86_SUB32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ },
{ X86_SUB64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ },
{ X86_SUB8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ },
{ X86_TEST16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ },
{ X86_TEST32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ },
{ X86_TEST64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ },
{ X86_TEST8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ },
{ X86_XOR16i16, X86_REG_AX, CS_AC_WRITE | CS_AC_READ },
{ X86_XOR32i32, X86_REG_EAX, CS_AC_WRITE | CS_AC_READ },
{ X86_XOR64i32, X86_REG_RAX, CS_AC_WRITE | CS_AC_READ },
{ X86_XOR8i8, X86_REG_AL, CS_AC_WRITE | CS_AC_READ },
};
static const struct insn_reg insn_regs_intel_extra[] = {
// dummy entry, to avoid empty array
{ 0, 0, 0 },
#ifndef CAPSTONE_X86_REDUCE
{ X86_CMOVBE_F, X86_REG_ST0, CS_AC_WRITE },
{ X86_CMOVB_F, X86_REG_ST0, CS_AC_WRITE },
{ X86_CMOVE_F, X86_REG_ST0, CS_AC_WRITE },
{ X86_CMOVNBE_F, X86_REG_ST0, CS_AC_WRITE },
{ X86_CMOVNB_F, X86_REG_ST0, CS_AC_WRITE },
{ X86_CMOVNE_F, X86_REG_ST0, CS_AC_WRITE },
{ X86_CMOVNP_F, X86_REG_ST0, CS_AC_WRITE },
{ X86_CMOVP_F, X86_REG_ST0, CS_AC_WRITE },
// { X86_COMP_FST0r, X86_REG_ST0, CS_AC_WRITE },
// { X86_COM_FST0r, X86_REG_ST0, CS_AC_WRITE },
{ X86_FNSTSW16r, X86_REG_AX, CS_AC_WRITE },
{ X86_SKINIT, X86_REG_EAX, CS_AC_WRITE },
{ X86_VMLOAD32, X86_REG_EAX, CS_AC_WRITE },
{ X86_VMLOAD64, X86_REG_RAX, CS_AC_WRITE },
{ X86_VMRUN32, X86_REG_EAX, CS_AC_WRITE },
{ X86_VMRUN64, X86_REG_RAX, CS_AC_WRITE },
{ X86_VMSAVE32, X86_REG_EAX, CS_AC_READ },
{ X86_VMSAVE64, X86_REG_RAX, CS_AC_READ },
{ X86_XCH_F, X86_REG_ST0, CS_AC_WRITE },
#endif
};
static const struct insn_reg2 insn_regs_intel2[] = {
{ X86_IN16rr, X86_REG_AX, X86_REG_DX, CS_AC_WRITE, CS_AC_READ },
{ X86_IN32rr, X86_REG_EAX, X86_REG_DX, CS_AC_WRITE, CS_AC_READ },
{ X86_IN8rr, X86_REG_AL, X86_REG_DX, CS_AC_WRITE, CS_AC_READ },
{ X86_INVLPGA32, X86_REG_EAX, X86_REG_ECX, CS_AC_READ, CS_AC_READ },
{ X86_INVLPGA64, X86_REG_RAX, X86_REG_ECX, CS_AC_READ, CS_AC_READ },
{ X86_OUT16rr, X86_REG_DX, X86_REG_AX, CS_AC_READ, CS_AC_READ },
{ X86_OUT32rr, X86_REG_DX, X86_REG_EAX, CS_AC_READ, CS_AC_READ },
{ X86_OUT8rr, X86_REG_DX, X86_REG_AL, CS_AC_READ, CS_AC_READ },
};
static int binary_search1(const struct insn_reg *insns, unsigned int max, unsigned int id)
{
unsigned int first, last, mid;
first = 0;
last = max -1;
if (insns[0].insn > id || insns[last].insn < id) {
// not found
return -1;
}
while (first <= last) {
mid = (first + last) / 2;
if (insns[mid].insn < id) {
first = mid + 1;
} else if (insns[mid].insn == id) {
return mid;
} else {
if (mid == 0)
break;
last = mid - 1;
}
}
// not found
return -1;
}
static int binary_search2(const struct insn_reg2 *insns, unsigned int max, unsigned int id)
{
unsigned int first, last, mid;
first = 0;
last = max -1;
if (insns[0].insn > id || insns[last].insn < id) {
// not found
return -1;
}
while (first <= last) {
mid = (first + last) / 2;
if (insns[mid].insn < id) {
first = mid + 1;
} else if (insns[mid].insn == id) {
return mid;
} else {
if (mid == 0)
break;
last = mid - 1;
}
}
// not found
return -1;
}
// return register of given instruction id
// return 0 if not found
// this is to handle instructions embedding accumulate registers into AsmStrs[]
x86_reg X86_insn_reg_intel(unsigned int id, enum cs_ac_type *access)
{
int i;
i = binary_search1(insn_regs_intel, ARR_SIZE(insn_regs_intel), id);
if (i != -1) {
if (access) {
*access = insn_regs_intel[i].access;
}
return insn_regs_intel[i].reg;
}
i = binary_search1(insn_regs_intel_extra, ARR_SIZE(insn_regs_intel_extra), id);
if (i != -1) {
if (access) {
*access = insn_regs_intel_extra[i].access;
}
return insn_regs_intel_extra[i].reg;
}
// not found
return 0;
}
bool X86_insn_reg_intel2(unsigned int id, x86_reg *reg1, enum cs_ac_type *access1, x86_reg *reg2, enum cs_ac_type *access2)
{
int i = binary_search2(insn_regs_intel2, ARR_SIZE(insn_regs_intel2), id);
if (i != -1) {
*reg1 = insn_regs_intel2[i].reg1;
*reg2 = insn_regs_intel2[i].reg2;
if (access1)
*access1 = insn_regs_intel2[i].access1;
if (access2)
*access2 = insn_regs_intel2[i].access2;
return true;
}
// not found
return false;
}
x86_reg X86_insn_reg_att(unsigned int id, enum cs_ac_type *access)
{
int i;
i = binary_search1(insn_regs_att, ARR_SIZE(insn_regs_att), id);
if (i != -1) {
if (access)
*access = insn_regs_att[i].access;
return insn_regs_att[i].reg;
}
i = binary_search1(insn_regs_att_extra, ARR_SIZE(insn_regs_att_extra), id);
if (i != -1) {
if (access)
*access = insn_regs_att_extra[i].access;
return insn_regs_att_extra[i].reg;
}
// not found
return 0;
}
// ATT just reuses Intel data, but with the order of registers reversed
bool X86_insn_reg_att2(unsigned int id, x86_reg *reg1, enum cs_ac_type *access1, x86_reg *reg2, enum cs_ac_type *access2)
{
int i = binary_search2(insn_regs_intel2, ARR_SIZE(insn_regs_intel2), id);
if (i != -1) {
*reg1 = insn_regs_intel2[i].reg2;
*reg2 = insn_regs_intel2[i].reg1;
if (access1)
*access1 = insn_regs_intel2[i].access2;
if (access2)
*access2 = insn_regs_intel2[i].access1;
return true;
}
// not found
return false;
}
// given MCInst's id, find out if this insn is valid for REPNE prefix
static bool valid_repne(cs_struct *h, unsigned int opcode)
{
unsigned int id;
unsigned int i = find_insn(opcode);
if (i != -1) {
id = insns[i].mapid;
switch(id) {
default:
return false;
case X86_INS_CMPSB:
case X86_INS_CMPSS:
case X86_INS_CMPSW:
case X86_INS_CMPSQ:
case X86_INS_SCASB:
case X86_INS_SCASW:
case X86_INS_SCASQ:
case X86_INS_MOVSB:
case X86_INS_MOVSS:
case X86_INS_MOVSW:
case X86_INS_MOVSQ:
case X86_INS_LODSB:
case X86_INS_LODSW:
case X86_INS_LODSD:
case X86_INS_LODSQ:
case X86_INS_STOSB:
case X86_INS_STOSW:
case X86_INS_STOSD:
case X86_INS_STOSQ:
case X86_INS_INSB:
case X86_INS_INSW:
case X86_INS_INSD:
case X86_INS_OUTSB:
case X86_INS_OUTSW:
case X86_INS_OUTSD:
return true;
case X86_INS_MOVSD:
if (opcode == X86_MOVSW) // REP MOVSB
return true;
return false;
case X86_INS_CMPSD:
if (opcode == X86_CMPSL) // REP CMPSD
return true;
return false;
case X86_INS_SCASD:
if (opcode == X86_SCASL) // REP SCASD
return true;
return false;
}
}
// not found
return false;
}
// given MCInst's id, find out if this insn is valid for BND prefix
// BND prefix is valid for CALL/JMP/RET
#ifndef CAPSTONE_DIET
static bool valid_bnd(cs_struct *h, unsigned int opcode)
{
unsigned int id;
unsigned int i = find_insn(opcode);
if (i != -1) {
id = insns[i].mapid;
switch(id) {
default:
return false;
case X86_INS_JAE:
case X86_INS_JA:
case X86_INS_JBE:
case X86_INS_JB:
case X86_INS_JCXZ:
case X86_INS_JECXZ:
case X86_INS_JE:
case X86_INS_JGE:
case X86_INS_JG:
case X86_INS_JLE:
case X86_INS_JL:
case X86_INS_JMP:
case X86_INS_JNE:
case X86_INS_JNO:
case X86_INS_JNP:
case X86_INS_JNS:
case X86_INS_JO:
case X86_INS_JP:
case X86_INS_JRCXZ:
case X86_INS_JS:
case X86_INS_CALL:
case X86_INS_RET:
case X86_INS_RETF:
case X86_INS_RETFQ:
return true;
}
}
// not found
return false;
}
#endif
// return true if the opcode is XCHG [mem]
static bool xchg_mem(unsigned int opcode)
{
switch(opcode) {
default:
return false;
case X86_XCHG8rm:
case X86_XCHG16rm:
case X86_XCHG32rm:
case X86_XCHG64rm:
return true;
}
}
// given MCInst's id, find out if this insn is valid for REP prefix
static bool valid_rep(cs_struct *h, unsigned int opcode)
{
unsigned int id;
unsigned int i = find_insn(opcode);
if (i != -1) {
id = insns[i].mapid;
switch(id) {
default:
return false;
case X86_INS_MOVSB:
case X86_INS_MOVSW:
case X86_INS_MOVSQ:
case X86_INS_LODSB:
case X86_INS_LODSW:
case X86_INS_LODSQ:
case X86_INS_STOSB:
case X86_INS_STOSW:
case X86_INS_STOSQ:
case X86_INS_INSB:
case X86_INS_INSW:
case X86_INS_INSD:
case X86_INS_OUTSB:
case X86_INS_OUTSW:
case X86_INS_OUTSD:
return true;
// following are some confused instructions, which have the same
// mnemonics in 128bit media instructions. Intel is horribly crazy!
case X86_INS_MOVSD:
if (opcode == X86_MOVSL) // REP MOVSD
return true;
return false;
case X86_INS_LODSD:
if (opcode == X86_LODSL) // REP LODSD
return true;
return false;
case X86_INS_STOSD:
if (opcode == X86_STOSL) // REP STOSD
return true;
return false;
}
}
// not found
return false;
}
// given MCInst's id, find out if this insn is valid for REPE prefix
static bool valid_repe(cs_struct *h, unsigned int opcode)
{
unsigned int id;
unsigned int i = find_insn(opcode);
if (i != -1) {
id = insns[i].mapid;
switch(id) {
default:
return false;
case X86_INS_CMPSB:
case X86_INS_CMPSW:
case X86_INS_CMPSQ:
case X86_INS_SCASB:
case X86_INS_SCASW:
case X86_INS_SCASQ:
return true;
// following are some confused instructions, which have the same
// mnemonics in 128bit media instructions. Intel is horribly crazy!
case X86_INS_CMPSD:
if (opcode == X86_CMPSL) // REP CMPSD
return true;
return false;
case X86_INS_SCASD:
if (opcode == X86_SCASL) // REP SCASD
return true;
return false;
}
}
// not found
return false;
}
#ifndef CAPSTONE_DIET
// add *CX register to regs_read[] & regs_write[]
static void add_cx(MCInst *MI)
{
if (MI->csh->detail) {
x86_reg cx;
if (MI->csh->mode & CS_MODE_16)
cx = X86_REG_CX;
else if (MI->csh->mode & CS_MODE_32)
cx = X86_REG_ECX;
else // 64-bit
cx = X86_REG_RCX;
MI->flat_insn->detail->regs_read[MI->flat_insn->detail->regs_read_count] = cx;
MI->flat_insn->detail->regs_read_count++;
MI->flat_insn->detail->regs_write[MI->flat_insn->detail->regs_write_count] = cx;
MI->flat_insn->detail->regs_write_count++;
}
}
#endif
// return true if we patch the mnemonic
bool X86_lockrep(MCInst *MI, SStream *O)
{
unsigned int opcode;
bool res = false;
switch(MI->x86_prefix[0]) {
default:
break;
case 0xf0:
#ifndef CAPSTONE_DIET
if (MI->xAcquireRelease == 0xf2)
SStream_concat(O, "xacquire|lock|");
else if (MI->xAcquireRelease == 0xf3)
SStream_concat(O, "xrelease|lock|");
else
SStream_concat(O, "lock|");
#endif
break;
case 0xf2: // repne
opcode = MCInst_getOpcode(MI);
#ifndef CAPSTONE_DIET // only care about memonic in standard (non-diet) mode
if (xchg_mem(opcode) && MI->xAcquireRelease) {
SStream_concat(O, "xacquire|");
} else if (valid_repne(MI->csh, opcode)) {
SStream_concat(O, "repne|");
add_cx(MI);
} else if (valid_bnd(MI->csh, opcode)) {
SStream_concat(O, "bnd|");
} else {
// invalid prefix
MI->x86_prefix[0] = 0;
// handle special cases
#ifndef CAPSTONE_X86_REDUCE
#if 0
if (opcode == X86_MULPDrr) {
MCInst_setOpcode(MI, X86_MULSDrr);
SStream_concat0(O, "mulsd\t");
res = true;
}
#endif
#endif
}
#else // diet mode -> only patch opcode in special cases
if (!valid_repne(MI->csh, opcode)) {
MI->x86_prefix[0] = 0;
}
#ifndef CAPSTONE_X86_REDUCE
#if 0
// handle special cases
if (opcode == X86_MULPDrr) {
MCInst_setOpcode(MI, X86_MULSDrr);
}
#endif
#endif
#endif
break;
case 0xf3:
opcode = MCInst_getOpcode(MI);
#ifndef CAPSTONE_DIET // only care about memonic in standard (non-diet) mode
if (xchg_mem(opcode) && MI->xAcquireRelease) {
SStream_concat(O, "xrelease|");
} else if (valid_rep(MI->csh, opcode)) {
SStream_concat(O, "rep|");
add_cx(MI);
} else if (valid_repe(MI->csh, opcode)) {
SStream_concat(O, "repe|");
add_cx(MI);
} else {
// invalid prefix
MI->x86_prefix[0] = 0;
// handle special cases
#ifndef CAPSTONE_X86_REDUCE
#if 0
// FIXME: remove this special case?
if (opcode == X86_MULPDrr) {
MCInst_setOpcode(MI, X86_MULSSrr);
SStream_concat0(O, "mulss\t");
res = true;
}
#endif
#endif
}
#else // diet mode -> only patch opcode in special cases
if (!valid_rep(MI->csh, opcode) && !valid_repe(MI->csh, opcode)) {
MI->x86_prefix[0] = 0;
}
#ifndef CAPSTONE_X86_REDUCE
#if 0
// handle special cases
// FIXME: remove this special case?
if (opcode == X86_MULPDrr) {
MCInst_setOpcode(MI, X86_MULSSrr);
}
#endif
#endif
#endif
break;
}
// copy normalized prefix[] back to x86.prefix[]
if (MI->csh->detail)
memcpy(MI->flat_insn->detail->x86.prefix, MI->x86_prefix, ARR_SIZE(MI->x86_prefix));
return res;
}
void op_addReg(MCInst *MI, int reg)
{
if (MI->csh->detail) {
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_REG;
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].reg = reg;
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->csh->regsize_map[reg];
MI->flat_insn->detail->x86.op_count++;
}
if (MI->op1_size == 0)
MI->op1_size = MI->csh->regsize_map[reg];
}
void op_addImm(MCInst *MI, int v)
{
if (MI->csh->detail) {
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_IMM;
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].imm = v;
// if op_count > 0, then this operand's size is taken from the destination op
if (MI->csh->syntax != CS_OPT_SYNTAX_ATT) {
if (MI->flat_insn->detail->x86.op_count > 0)
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->flat_insn->detail->x86.operands[0].size;
else
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->imm_size;
} else
MI->has_imm = true;
MI->flat_insn->detail->x86.op_count++;
}
if (MI->op1_size == 0)
MI->op1_size = MI->imm_size;
}
void op_addXopCC(MCInst *MI, int v)
{
if (MI->csh->detail) {
MI->flat_insn->detail->x86.xop_cc = v;
}
}
void op_addSseCC(MCInst *MI, int v)
{
if (MI->csh->detail) {
MI->flat_insn->detail->x86.sse_cc = v;
}
}
void op_addAvxCC(MCInst *MI, int v)
{
if (MI->csh->detail) {
MI->flat_insn->detail->x86.avx_cc = v;
}
}
void op_addAvxRoundingMode(MCInst *MI, int v)
{
if (MI->csh->detail) {
MI->flat_insn->detail->x86.avx_rm = v;
}
}
// below functions supply details to X86GenAsmWriter*.inc
void op_addAvxZeroOpmask(MCInst *MI)
{
if (MI->csh->detail) {
// link with the previous operand
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count - 1].avx_zero_opmask = true;
}
}
void op_addAvxSae(MCInst *MI)
{
if (MI->csh->detail) {
MI->flat_insn->detail->x86.avx_sae = true;
}
}
void op_addAvxBroadcast(MCInst *MI, x86_avx_bcast v)
{
if (MI->csh->detail) {
// link with the previous operand
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count - 1].avx_bcast = v;
}
}
#ifndef CAPSTONE_DIET
// map instruction to its characteristics
typedef struct insn_op {
uint64_t flags; // how this instruction update EFLAGS(arithmetic instrcutions) of FPU FLAGS(for FPU instructions)
uint8_t access[6];
} insn_op;
static const insn_op insn_ops[] = {
#ifdef CAPSTONE_X86_REDUCE
#include "X86MappingInsnOp_reduce.inc"
#else
#include "X86MappingInsnOp.inc"
#endif
};
// given internal insn id, return operand access info
const uint8_t *X86_get_op_access(cs_struct *h, unsigned int id, uint64_t *eflags)
{
unsigned int i = find_insn(id);
if (i != -1) {
*eflags = insn_ops[i].flags;
return insn_ops[i].access;
}
return NULL;
}
void X86_reg_access(const cs_insn *insn,
cs_regs regs_read, uint8_t *regs_read_count,
cs_regs regs_write, uint8_t *regs_write_count)
{
uint8_t i;
uint8_t read_count, write_count;
cs_x86 *x86 = &(insn->detail->x86);
read_count = insn->detail->regs_read_count;
write_count = insn->detail->regs_write_count;
// implicit registers
memcpy(regs_read, insn->detail->regs_read, read_count * sizeof(insn->detail->regs_read[0]));
memcpy(regs_write, insn->detail->regs_write, write_count * sizeof(insn->detail->regs_write[0]));
// explicit registers
for (i = 0; i < x86->op_count; i++) {
cs_x86_op *op = &(x86->operands[i]);
switch((int)op->type) {
case X86_OP_REG:
if ((op->access & CS_AC_READ) && !arr_exist(regs_read, read_count, op->reg)) {
regs_read[read_count] = op->reg;
read_count++;
}
if ((op->access & CS_AC_WRITE) && !arr_exist(regs_write, write_count, op->reg)) {
regs_write[write_count] = op->reg;
write_count++;
}
break;
case X86_OP_MEM:
// registers appeared in memory references always being read
if ((op->mem.segment != X86_REG_INVALID)) {
regs_read[read_count] = op->mem.segment;
read_count++;
}
if ((op->mem.base != X86_REG_INVALID) && !arr_exist(regs_read, read_count, op->mem.base)) {
regs_read[read_count] = op->mem.base;
read_count++;
}
if ((op->mem.index != X86_REG_INVALID) && !arr_exist(regs_read, read_count, op->mem.index)) {
regs_read[read_count] = op->mem.index;
read_count++;
}
default:
break;
}
}
*regs_read_count = read_count;
*regs_write_count = write_count;
}
#endif
// map immediate size to instruction id
// this array is sorted for binary searching
static const struct size_id {
uint8_t enc_size;
uint8_t size;
uint16_t id;
} x86_imm_size[] = {
#include "X86ImmSize.inc"
};
// given the instruction name, return the size of its immediate operand (or 0)
uint8_t X86_immediate_size(unsigned int id, uint8_t *enc_size)
{
// binary searching since the IDs are sorted in order
unsigned int left, right, m;
right = ARR_SIZE(x86_imm_size) - 1;
if (id < x86_imm_size[0].id || id > x86_imm_size[right].id)
// not found
return 0;
left = 0;
while (left <= right) {
m = (left + right) / 2;
if (id == x86_imm_size[m].id) {
if (enc_size != NULL)
*enc_size = x86_imm_size[m].enc_size;
return x86_imm_size[m].size;
}
if (id > x86_imm_size[m].id)
left = m + 1;
else {
if (m == 0)
break;
right = m - 1;
}
}
// not found
return 0;
}
#define GET_REGINFO_ENUM
#include "X86GenRegisterInfo.inc"
// map internal register id to public register id
static const struct register_map {
unsigned short id;
unsigned short pub_id;
} reg_map [] = {
// first dummy map
{ 0, 0 },
#include "X86MappingReg.inc"
};
// return 0 on invalid input, or public register ID otherwise
// NOTE: reg_map is sorted in order of internal register
unsigned short X86_register_map(unsigned short id)
{
if (id < ARR_SIZE(reg_map))
return reg_map[id].pub_id;
return 0;
}
#endif
|
the_stack_data/45451076.c
|
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define MAX_BUFFLEN 1024
#define MAX_NUM 100
char *home;
char *dir;
int mysys(const char *cmdstring)
{
pid_t pid;
int status = -1;
if (cmdstring == NULL)
return 1;
if ((pid = fork()) < 0)
status = -1;
else if (pid == 0)
{
execl("/bin/sh", "sh", "-c", cmdstring, (char *)0);
exit(127);
}
else
{
while (waitpid(pid, &status, 0) < 0)
{
if (errno != EINTR)
{
status = -1;
break;
}
}
}
return status;
}
int judge_buff(char *buff)
{
if(buff[0] == '\0')
return 0;
char code[MAX_BUFFLEN];
strcpy(code, buff);
char *next = strchr(code, ' ');
if(next != NULL)
next[0] = '\0';
//printf("[code] %s", code);
if(strcmp(code, "cd") == 0)
return 1;
else if(strcmp(code, "exit") == 0)
return 2;
else
return 0;
}
int cd(char *buff)
{
char code[MAX_BUFFLEN];
char *argv[MAX_NUM]; // no more than 100 arguments
int count = 0; // N.O. of arguments
char *next = NULL;
char *rest = code;
strcpy(code, buff);
argv[count++] = code;
while(next = strchr(rest, ' '))
{
next[0] = '\0';
rest = next + 1;
// printf("rest = \"%s\"\n", rest);
if(rest[0] != '\0' && rest[0] != ' ')
argv[count++] = rest;
if(count + 2 > MAX_NUM)
return 127;
}
argv[count++] = NULL;
if(count == 2)
{
chdir(home);
dir = getcwd(NULL, 0);
}
else
{
int res = chdir(argv[count - 2]);
dir = getcwd(NULL, 0);
if(res == -1)
{
printf("cd: No such path %s\n", argv[count - 2]);
return -1;
}
}
return 0;
}
int main()
{
home = getenv("HOME");
dir = getcwd(NULL, 0);
char buff[MAX_BUFFLEN];
printf("[%s]$ ", dir);
while(gets(buff))
{
int res = judge_buff(buff);
if(res == 0)
mysys(buff);
else if(res == 1)
cd(buff);
else if(res == 2)
return 0;
printf("[%s]$ ", dir);
}
mysys("pwd");
mysys("echo ,HELLO WORLD , sdfa sdfadf ss ");
mysys("echo /G");
mysys("echo ,,");
mysys("echo");
return 0;
}
|
the_stack_data/178265405.c
|
// Program 4.3
// More arithmetic expressions
#include<stdio.h>
int main( void )
{
int a = 25;
int b = 2;
float c = 25.0;
float d = 2.0;
printf( "6 + a / 5 * b = %i\n", 6 + a / 5 * b );
printf( "a / b * b = %i\n", a / b * b );
printf( "c / d * d = %f\n", c / d * d );
printf( "-a = %i\n", -a );
return 0;
}
|
the_stack_data/165768981.c
|
//@ ltl invariant negative: ((X AP(x_10 - x_0 > 12)) || ([] AP(x_4 - x_0 >= 9)));
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;
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_;
while(1) {
x_0_ = (((8.0 + x_1) > ((11.0 + x_2) > (18.0 + x_3)? (11.0 + x_2) : (18.0 + x_3))? (8.0 + x_1) : ((11.0 + x_2) > (18.0 + x_3)? (11.0 + x_2) : (18.0 + x_3))) > ((4.0 + x_6) > ((2.0 + x_7) > (7.0 + x_11)? (2.0 + x_7) : (7.0 + x_11))? (4.0 + x_6) : ((2.0 + x_7) > (7.0 + x_11)? (2.0 + x_7) : (7.0 + x_11)))? ((8.0 + x_1) > ((11.0 + x_2) > (18.0 + x_3)? (11.0 + x_2) : (18.0 + x_3))? (8.0 + x_1) : ((11.0 + x_2) > (18.0 + x_3)? (11.0 + x_2) : (18.0 + x_3))) : ((4.0 + x_6) > ((2.0 + x_7) > (7.0 + x_11)? (2.0 + x_7) : (7.0 + x_11))? (4.0 + x_6) : ((2.0 + x_7) > (7.0 + x_11)? (2.0 + x_7) : (7.0 + x_11))));
x_1_ = (((3.0 + x_3) > ((6.0 + x_4) > (5.0 + x_6)? (6.0 + x_4) : (5.0 + x_6))? (3.0 + x_3) : ((6.0 + x_4) > (5.0 + x_6)? (6.0 + x_4) : (5.0 + x_6))) > ((17.0 + x_9) > ((11.0 + x_10) > (2.0 + x_11)? (11.0 + x_10) : (2.0 + x_11))? (17.0 + x_9) : ((11.0 + x_10) > (2.0 + x_11)? (11.0 + x_10) : (2.0 + x_11)))? ((3.0 + x_3) > ((6.0 + x_4) > (5.0 + x_6)? (6.0 + x_4) : (5.0 + x_6))? (3.0 + x_3) : ((6.0 + x_4) > (5.0 + x_6)? (6.0 + x_4) : (5.0 + x_6))) : ((17.0 + x_9) > ((11.0 + x_10) > (2.0 + x_11)? (11.0 + x_10) : (2.0 + x_11))? (17.0 + x_9) : ((11.0 + x_10) > (2.0 + x_11)? (11.0 + x_10) : (2.0 + x_11))));
x_2_ = (((12.0 + x_1) > ((6.0 + x_3) > (5.0 + x_4)? (6.0 + x_3) : (5.0 + x_4))? (12.0 + x_1) : ((6.0 + x_3) > (5.0 + x_4)? (6.0 + x_3) : (5.0 + x_4))) > ((7.0 + x_8) > ((5.0 + x_9) > (4.0 + x_10)? (5.0 + x_9) : (4.0 + x_10))? (7.0 + x_8) : ((5.0 + x_9) > (4.0 + x_10)? (5.0 + x_9) : (4.0 + x_10)))? ((12.0 + x_1) > ((6.0 + x_3) > (5.0 + x_4)? (6.0 + x_3) : (5.0 + x_4))? (12.0 + x_1) : ((6.0 + x_3) > (5.0 + x_4)? (6.0 + x_3) : (5.0 + x_4))) : ((7.0 + x_8) > ((5.0 + x_9) > (4.0 + x_10)? (5.0 + x_9) : (4.0 + x_10))? (7.0 + x_8) : ((5.0 + x_9) > (4.0 + x_10)? (5.0 + x_9) : (4.0 + x_10))));
x_3_ = (((17.0 + x_4) > ((3.0 + x_5) > (4.0 + x_6)? (3.0 + x_5) : (4.0 + x_6))? (17.0 + x_4) : ((3.0 + x_5) > (4.0 + x_6)? (3.0 + x_5) : (4.0 + x_6))) > ((15.0 + x_7) > ((18.0 + x_8) > (13.0 + x_9)? (18.0 + x_8) : (13.0 + x_9))? (15.0 + x_7) : ((18.0 + x_8) > (13.0 + x_9)? (18.0 + x_8) : (13.0 + x_9)))? ((17.0 + x_4) > ((3.0 + x_5) > (4.0 + x_6)? (3.0 + x_5) : (4.0 + x_6))? (17.0 + x_4) : ((3.0 + x_5) > (4.0 + x_6)? (3.0 + x_5) : (4.0 + x_6))) : ((15.0 + x_7) > ((18.0 + x_8) > (13.0 + x_9)? (18.0 + x_8) : (13.0 + x_9))? (15.0 + x_7) : ((18.0 + x_8) > (13.0 + x_9)? (18.0 + x_8) : (13.0 + x_9))));
x_4_ = (((3.0 + x_0) > ((6.0 + x_1) > (11.0 + x_4)? (6.0 + x_1) : (11.0 + x_4))? (3.0 + x_0) : ((6.0 + x_1) > (11.0 + x_4)? (6.0 + x_1) : (11.0 + x_4))) > ((8.0 + x_8) > ((12.0 + x_9) > (10.0 + x_10)? (12.0 + x_9) : (10.0 + x_10))? (8.0 + x_8) : ((12.0 + x_9) > (10.0 + x_10)? (12.0 + x_9) : (10.0 + x_10)))? ((3.0 + x_0) > ((6.0 + x_1) > (11.0 + x_4)? (6.0 + x_1) : (11.0 + x_4))? (3.0 + x_0) : ((6.0 + x_1) > (11.0 + x_4)? (6.0 + x_1) : (11.0 + x_4))) : ((8.0 + x_8) > ((12.0 + x_9) > (10.0 + x_10)? (12.0 + x_9) : (10.0 + x_10))? (8.0 + x_8) : ((12.0 + x_9) > (10.0 + x_10)? (12.0 + x_9) : (10.0 + x_10))));
x_5_ = (((6.0 + x_4) > ((2.0 + x_5) > (14.0 + x_7)? (2.0 + x_5) : (14.0 + x_7))? (6.0 + x_4) : ((2.0 + x_5) > (14.0 + x_7)? (2.0 + x_5) : (14.0 + x_7))) > ((20.0 + x_8) > ((7.0 + x_9) > (7.0 + x_10)? (7.0 + x_9) : (7.0 + x_10))? (20.0 + x_8) : ((7.0 + x_9) > (7.0 + x_10)? (7.0 + x_9) : (7.0 + x_10)))? ((6.0 + x_4) > ((2.0 + x_5) > (14.0 + x_7)? (2.0 + x_5) : (14.0 + x_7))? (6.0 + x_4) : ((2.0 + x_5) > (14.0 + x_7)? (2.0 + x_5) : (14.0 + x_7))) : ((20.0 + x_8) > ((7.0 + x_9) > (7.0 + x_10)? (7.0 + x_9) : (7.0 + x_10))? (20.0 + x_8) : ((7.0 + x_9) > (7.0 + x_10)? (7.0 + x_9) : (7.0 + x_10))));
x_6_ = (((9.0 + x_0) > ((12.0 + x_2) > (2.0 + x_3)? (12.0 + x_2) : (2.0 + x_3))? (9.0 + x_0) : ((12.0 + x_2) > (2.0 + x_3)? (12.0 + x_2) : (2.0 + x_3))) > ((13.0 + x_7) > ((2.0 + x_9) > (11.0 + x_11)? (2.0 + x_9) : (11.0 + x_11))? (13.0 + x_7) : ((2.0 + x_9) > (11.0 + x_11)? (2.0 + x_9) : (11.0 + x_11)))? ((9.0 + x_0) > ((12.0 + x_2) > (2.0 + x_3)? (12.0 + x_2) : (2.0 + x_3))? (9.0 + x_0) : ((12.0 + x_2) > (2.0 + x_3)? (12.0 + x_2) : (2.0 + x_3))) : ((13.0 + x_7) > ((2.0 + x_9) > (11.0 + x_11)? (2.0 + x_9) : (11.0 + x_11))? (13.0 + x_7) : ((2.0 + x_9) > (11.0 + x_11)? (2.0 + x_9) : (11.0 + x_11))));
x_7_ = (((16.0 + x_0) > ((1.0 + x_1) > (20.0 + x_3)? (1.0 + x_1) : (20.0 + x_3))? (16.0 + x_0) : ((1.0 + x_1) > (20.0 + x_3)? (1.0 + x_1) : (20.0 + x_3))) > ((18.0 + x_6) > ((1.0 + x_8) > (18.0 + x_10)? (1.0 + x_8) : (18.0 + x_10))? (18.0 + x_6) : ((1.0 + x_8) > (18.0 + x_10)? (1.0 + x_8) : (18.0 + x_10)))? ((16.0 + x_0) > ((1.0 + x_1) > (20.0 + x_3)? (1.0 + x_1) : (20.0 + x_3))? (16.0 + x_0) : ((1.0 + x_1) > (20.0 + x_3)? (1.0 + x_1) : (20.0 + x_3))) : ((18.0 + x_6) > ((1.0 + x_8) > (18.0 + x_10)? (1.0 + x_8) : (18.0 + x_10))? (18.0 + x_6) : ((1.0 + x_8) > (18.0 + x_10)? (1.0 + x_8) : (18.0 + x_10))));
x_8_ = (((15.0 + x_0) > ((20.0 + x_1) > (11.0 + x_6)? (20.0 + x_1) : (11.0 + x_6))? (15.0 + x_0) : ((20.0 + x_1) > (11.0 + x_6)? (20.0 + x_1) : (11.0 + x_6))) > ((5.0 + x_8) > ((6.0 + x_9) > (12.0 + x_11)? (6.0 + x_9) : (12.0 + x_11))? (5.0 + x_8) : ((6.0 + x_9) > (12.0 + x_11)? (6.0 + x_9) : (12.0 + x_11)))? ((15.0 + x_0) > ((20.0 + x_1) > (11.0 + x_6)? (20.0 + x_1) : (11.0 + x_6))? (15.0 + x_0) : ((20.0 + x_1) > (11.0 + x_6)? (20.0 + x_1) : (11.0 + x_6))) : ((5.0 + x_8) > ((6.0 + x_9) > (12.0 + x_11)? (6.0 + x_9) : (12.0 + x_11))? (5.0 + x_8) : ((6.0 + x_9) > (12.0 + x_11)? (6.0 + x_9) : (12.0 + x_11))));
x_9_ = (((16.0 + x_3) > ((4.0 + x_4) > (13.0 + x_5)? (4.0 + x_4) : (13.0 + x_5))? (16.0 + x_3) : ((4.0 + x_4) > (13.0 + x_5)? (4.0 + x_4) : (13.0 + x_5))) > ((11.0 + x_6) > ((3.0 + x_7) > (7.0 + x_9)? (3.0 + x_7) : (7.0 + x_9))? (11.0 + x_6) : ((3.0 + x_7) > (7.0 + x_9)? (3.0 + x_7) : (7.0 + x_9)))? ((16.0 + x_3) > ((4.0 + x_4) > (13.0 + x_5)? (4.0 + x_4) : (13.0 + x_5))? (16.0 + x_3) : ((4.0 + x_4) > (13.0 + x_5)? (4.0 + x_4) : (13.0 + x_5))) : ((11.0 + x_6) > ((3.0 + x_7) > (7.0 + x_9)? (3.0 + x_7) : (7.0 + x_9))? (11.0 + x_6) : ((3.0 + x_7) > (7.0 + x_9)? (3.0 + x_7) : (7.0 + x_9))));
x_10_ = (((15.0 + x_0) > ((11.0 + x_1) > (15.0 + x_2)? (11.0 + x_1) : (15.0 + x_2))? (15.0 + x_0) : ((11.0 + x_1) > (15.0 + x_2)? (11.0 + x_1) : (15.0 + x_2))) > ((15.0 + x_7) > ((9.0 + x_9) > (9.0 + x_10)? (9.0 + x_9) : (9.0 + x_10))? (15.0 + x_7) : ((9.0 + x_9) > (9.0 + x_10)? (9.0 + x_9) : (9.0 + x_10)))? ((15.0 + x_0) > ((11.0 + x_1) > (15.0 + x_2)? (11.0 + x_1) : (15.0 + x_2))? (15.0 + x_0) : ((11.0 + x_1) > (15.0 + x_2)? (11.0 + x_1) : (15.0 + x_2))) : ((15.0 + x_7) > ((9.0 + x_9) > (9.0 + x_10)? (9.0 + x_9) : (9.0 + x_10))? (15.0 + x_7) : ((9.0 + x_9) > (9.0 + x_10)? (9.0 + x_9) : (9.0 + x_10))));
x_11_ = (((13.0 + x_0) > ((6.0 + x_2) > (14.0 + x_3)? (6.0 + x_2) : (14.0 + x_3))? (13.0 + x_0) : ((6.0 + x_2) > (14.0 + x_3)? (6.0 + x_2) : (14.0 + x_3))) > ((1.0 + x_9) > ((3.0 + x_10) > (11.0 + x_11)? (3.0 + x_10) : (11.0 + x_11))? (1.0 + x_9) : ((3.0 + x_10) > (11.0 + x_11)? (3.0 + x_10) : (11.0 + x_11)))? ((13.0 + x_0) > ((6.0 + x_2) > (14.0 + x_3)? (6.0 + x_2) : (14.0 + x_3))? (13.0 + x_0) : ((6.0 + x_2) > (14.0 + x_3)? (6.0 + x_2) : (14.0 + x_3))) : ((1.0 + x_9) > ((3.0 + x_10) > (11.0 + x_11)? (3.0 + x_10) : (11.0 + x_11))? (1.0 + x_9) : ((3.0 + x_10) > (11.0 + x_11)? (3.0 + x_10) : (11.0 + x_11))));
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_;
}
return 0;
}
|
the_stack_data/89199082.c
|
/*
* Copyright © 2014-2017 Broadcom
*
* 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 (including the next
* paragraph) 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.
*/
/**
* @file v3d_simulator.c
*
* Implements V3D simulation on top of a non-V3D GEM fd.
*
* This file's goal is to emulate the V3D ioctls' behavior in the kernel on
* top of the simpenrose software simulator. Generally, V3D driver BOs have a
* GEM-side copy of their contents and a simulator-side memory area that the
* GEM contents get copied into during simulation. Once simulation is done,
* the simulator's data is copied back out to the GEM BOs, so that rendering
* appears on the screen as if actual hardware rendering had been done.
*
* One of the limitations of this code is that we shouldn't really need a
* GEM-side BO for non-window-system BOs. However, do we need unique BO
* handles for each of our GEM bos so that this file can look up its state
* from the handle passed in at submit ioctl time (also, a couple of places
* outside of this file still call ioctls directly on the fd).
*
* Another limitation is that BO import doesn't work unless the underlying
* window system's BO size matches what V3D is going to use, which of course
* doesn't work out in practice. This means that for now, only DRI3 (V3D
* makes the winsys BOs) is supported, not DRI2 (window system makes the winys
* BOs).
*/
#ifdef USE_V3D_SIMULATOR
#include <stdio.h>
#include <sys/mman.h>
#include "c11/threads.h"
#include "util/hash_table.h"
#include "util/ralloc.h"
#include "util/set.h"
#include "util/u_dynarray.h"
#include "util/u_memory.h"
#include "util/u_mm.h"
#include "util/u_math.h"
#include <xf86drm.h>
#include "drm-uapi/i915_drm.h"
#include "drm-uapi/v3d_drm.h"
#include "v3d_simulator.h"
#include "v3d_simulator_wrapper.h"
/** Global (across GEM fds) state for the simulator */
static struct v3d_simulator_state {
mtx_t mutex;
mtx_t submit_lock;
struct v3d_hw *v3d;
int ver;
/* Base virtual address of the heap. */
void *mem;
/* Base hardware address of the heap. */
uint32_t mem_base;
/* Size of the heap. */
uint32_t mem_size;
struct mem_block *heap;
struct mem_block *overflow;
/** Mapping from GEM fd to struct v3d_simulator_file * */
struct hash_table *fd_map;
/** Last performance monitor ID. */
uint32_t last_perfid;
struct util_dynarray bin_oom;
int refcount;
} sim_state = {
.mutex = _MTX_INITIALIZER_NP,
};
/** Per-GEM-fd state for the simulator. */
struct v3d_simulator_file {
int fd;
/** Mapping from GEM handle to struct v3d_simulator_bo * */
struct hash_table *bo_map;
/** Dynamic array with performance monitors */
struct v3d_simulator_perfmon **perfmons;
uint32_t perfmons_size;
uint32_t active_perfid;
struct mem_block *gmp;
void *gmp_vaddr;
/** Actual GEM fd is i915, so we should use their create ioctl. */
bool is_i915;
};
/** Wrapper for drm_v3d_bo tracking the simulator-specific state. */
struct v3d_simulator_bo {
struct v3d_simulator_file *file;
/** Area for this BO within sim_state->mem */
struct mem_block *block;
uint32_t size;
uint64_t mmap_offset;
void *sim_vaddr;
void *gem_vaddr;
int handle;
};
struct v3d_simulator_perfmon {
uint32_t ncounters;
uint8_t counters[DRM_V3D_MAX_PERF_COUNTERS];
uint64_t values[DRM_V3D_MAX_PERF_COUNTERS];
};
static void *
int_to_key(int key)
{
return (void *)(uintptr_t)key;
}
#define PERFMONS_ALLOC_SIZE 100
static uint32_t
perfmons_next_id(struct v3d_simulator_file *sim_file) {
sim_state.last_perfid++;
if (sim_state.last_perfid > sim_file->perfmons_size) {
sim_file->perfmons_size += PERFMONS_ALLOC_SIZE;
sim_file->perfmons = reralloc(sim_file,
sim_file->perfmons,
struct v3d_simulator_perfmon *,
sim_file->perfmons_size);
}
return sim_state.last_perfid;
}
static struct v3d_simulator_file *
v3d_get_simulator_file_for_fd(int fd)
{
struct hash_entry *entry = _mesa_hash_table_search(sim_state.fd_map,
int_to_key(fd + 1));
return entry ? entry->data : NULL;
}
/* A marker placed just after each BO, then checked after rendering to make
* sure it's still there.
*/
#define BO_SENTINEL 0xfedcba98
/* 128kb */
#define GMP_ALIGN2 17
/**
* Sets the range of GPU virtual address space to have the given GMP
* permissions (bit 0 = read, bit 1 = write, write-only forbidden).
*/
static void
set_gmp_flags(struct v3d_simulator_file *file,
uint32_t offset, uint32_t size, uint32_t flag)
{
assert((offset & ((1 << GMP_ALIGN2) - 1)) == 0);
int gmp_offset = offset >> GMP_ALIGN2;
int gmp_count = align(size, 1 << GMP_ALIGN2) >> GMP_ALIGN2;
uint32_t *gmp = file->gmp_vaddr;
assert(flag <= 0x3);
for (int i = gmp_offset; i < gmp_offset + gmp_count; i++) {
int32_t bitshift = (i % 16) * 2;
gmp[i / 16] &= ~(0x3 << bitshift);
gmp[i / 16] |= flag << bitshift;
}
}
/**
* Allocates space in simulator memory and returns a tracking struct for it
* that also contains the drm_gem_cma_object struct.
*/
static struct v3d_simulator_bo *
v3d_create_simulator_bo(int fd, unsigned size)
{
struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
struct v3d_simulator_bo *sim_bo = rzalloc(file,
struct v3d_simulator_bo);
size = align(size, 4096);
sim_bo->file = file;
mtx_lock(&sim_state.mutex);
sim_bo->block = u_mmAllocMem(sim_state.heap, size + 4, GMP_ALIGN2, 0);
mtx_unlock(&sim_state.mutex);
assert(sim_bo->block);
set_gmp_flags(file, sim_bo->block->ofs, size, 0x3);
sim_bo->size = size;
/* Allocate space for the buffer in simulator memory. */
sim_bo->sim_vaddr = sim_state.mem + sim_bo->block->ofs - sim_state.mem_base;
memset(sim_bo->sim_vaddr, 0xd0, size);
*(uint32_t *)(sim_bo->sim_vaddr + sim_bo->size) = BO_SENTINEL;
return sim_bo;
}
static struct v3d_simulator_bo *
v3d_create_simulator_bo_for_gem(int fd, int handle, unsigned size)
{
struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
struct v3d_simulator_bo *sim_bo =
v3d_create_simulator_bo(fd, size);
sim_bo->handle = handle;
/* Map the GEM buffer for copy in/out to the simulator. i915 blocks
* dumb mmap on render nodes, so use their ioctl directly if we're on
* one.
*/
int ret;
if (file->is_i915) {
struct drm_i915_gem_mmap_gtt map = {
.handle = handle,
};
/* We could potentially use non-gtt (cached) for LLC systems,
* but the copy-in/out won't be the limiting factor on
* simulation anyway.
*/
ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &map);
sim_bo->mmap_offset = map.offset;
} else {
struct drm_mode_map_dumb map = {
.handle = handle,
};
ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &map);
sim_bo->mmap_offset = map.offset;
}
if (ret) {
fprintf(stderr, "Failed to get MMAP offset: %d\n", ret);
abort();
}
sim_bo->gem_vaddr = mmap(NULL, sim_bo->size,
PROT_READ | PROT_WRITE, MAP_SHARED,
fd, sim_bo->mmap_offset);
if (sim_bo->gem_vaddr == MAP_FAILED) {
fprintf(stderr, "mmap of bo %d (offset 0x%016llx, size %d) failed\n",
handle, (long long)sim_bo->mmap_offset, sim_bo->size);
abort();
}
/* A handle of 0 is used for v3d_gem.c internal allocations that
* don't need to go in the lookup table.
*/
if (handle != 0) {
mtx_lock(&sim_state.mutex);
_mesa_hash_table_insert(file->bo_map, int_to_key(handle),
sim_bo);
mtx_unlock(&sim_state.mutex);
}
return sim_bo;
}
static int bin_fd;
uint32_t
v3d_simulator_get_spill(uint32_t spill_size)
{
struct v3d_simulator_bo *sim_bo =
v3d_create_simulator_bo(bin_fd, spill_size);
util_dynarray_append(&sim_state.bin_oom, struct v3d_simulator_bo *,
sim_bo);
return sim_bo->block->ofs;
}
static void
v3d_free_simulator_bo(struct v3d_simulator_bo *sim_bo)
{
struct v3d_simulator_file *sim_file = sim_bo->file;
set_gmp_flags(sim_file, sim_bo->block->ofs, sim_bo->size, 0x0);
if (sim_bo->gem_vaddr)
munmap(sim_bo->gem_vaddr, sim_bo->size);
mtx_lock(&sim_state.mutex);
u_mmFreeMem(sim_bo->block);
if (sim_bo->handle) {
_mesa_hash_table_remove_key(sim_file->bo_map,
int_to_key(sim_bo->handle));
}
mtx_unlock(&sim_state.mutex);
ralloc_free(sim_bo);
}
static struct v3d_simulator_bo *
v3d_get_simulator_bo(struct v3d_simulator_file *file, int gem_handle)
{
if (gem_handle == 0)
return NULL;
mtx_lock(&sim_state.mutex);
struct hash_entry *entry =
_mesa_hash_table_search(file->bo_map, int_to_key(gem_handle));
mtx_unlock(&sim_state.mutex);
return entry ? entry->data : NULL;
}
static void
v3d_simulator_copy_in_handle(struct v3d_simulator_file *file, int handle)
{
struct v3d_simulator_bo *sim_bo = v3d_get_simulator_bo(file, handle);
if (!sim_bo)
return;
memcpy(sim_bo->sim_vaddr, sim_bo->gem_vaddr, sim_bo->size);
}
static void
v3d_simulator_copy_out_handle(struct v3d_simulator_file *file, int handle)
{
struct v3d_simulator_bo *sim_bo = v3d_get_simulator_bo(file, handle);
if (!sim_bo)
return;
memcpy(sim_bo->gem_vaddr, sim_bo->sim_vaddr, sim_bo->size);
if (*(uint32_t *)(sim_bo->sim_vaddr +
sim_bo->size) != BO_SENTINEL) {
fprintf(stderr, "Buffer overflow in handle %d\n",
handle);
}
}
static int
v3d_simulator_pin_bos(struct v3d_simulator_file *file,
struct drm_v3d_submit_cl *submit)
{
uint32_t *bo_handles = (uint32_t *)(uintptr_t)submit->bo_handles;
for (int i = 0; i < submit->bo_handle_count; i++)
v3d_simulator_copy_in_handle(file, bo_handles[i]);
return 0;
}
static int
v3d_simulator_unpin_bos(struct v3d_simulator_file *file,
struct drm_v3d_submit_cl *submit)
{
uint32_t *bo_handles = (uint32_t *)(uintptr_t)submit->bo_handles;
for (int i = 0; i < submit->bo_handle_count; i++)
v3d_simulator_copy_out_handle(file, bo_handles[i]);
return 0;
}
static struct v3d_simulator_perfmon *
v3d_get_simulator_perfmon(int fd, uint32_t perfid)
{
if (!perfid || perfid > sim_state.last_perfid)
return NULL;
struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
mtx_lock(&sim_state.mutex);
assert(perfid <= file->perfmons_size);
struct v3d_simulator_perfmon *perfmon = file->perfmons[perfid - 1];
mtx_unlock(&sim_state.mutex);
return perfmon;
}
static void
v3d_simulator_perfmon_switch(int fd, uint32_t perfid)
{
struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
struct v3d_simulator_perfmon *perfmon;
if (perfid == file->active_perfid)
return;
perfmon = v3d_get_simulator_perfmon(fd, file->active_perfid);
if (perfmon)
v3d41_simulator_perfmon_stop(sim_state.v3d,
perfmon->ncounters,
perfmon->values);
perfmon = v3d_get_simulator_perfmon(fd, perfid);
if (perfmon)
v3d41_simulator_perfmon_start(sim_state.v3d,
perfmon->ncounters,
perfmon->counters);
file->active_perfid = perfid;
}
static int
v3d_simulator_submit_cl_ioctl(int fd, struct drm_v3d_submit_cl *submit)
{
struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
int ret;
ret = v3d_simulator_pin_bos(file, submit);
if (ret)
return ret;
mtx_lock(&sim_state.submit_lock);
bin_fd = fd;
v3d_simulator_perfmon_switch(fd, submit->perfmon_id);
if (sim_state.ver >= 41)
v3d41_simulator_submit_cl_ioctl(sim_state.v3d, submit, file->gmp->ofs);
else
v3d33_simulator_submit_cl_ioctl(sim_state.v3d, submit, file->gmp->ofs);
util_dynarray_foreach(&sim_state.bin_oom, struct v3d_simulator_bo *,
sim_bo) {
v3d_free_simulator_bo(*sim_bo);
}
util_dynarray_clear(&sim_state.bin_oom);
mtx_unlock(&sim_state.submit_lock);
ret = v3d_simulator_unpin_bos(file, submit);
if (ret)
return ret;
return 0;
}
/**
* Do fixups after a BO has been opened from a handle.
*
* This could be done at DRM_IOCTL_GEM_OPEN/DRM_IOCTL_GEM_PRIME_FD_TO_HANDLE
* time, but we're still using drmPrimeFDToHandle() so we have this helper to
* be called afterward instead.
*/
void v3d_simulator_open_from_handle(int fd, int handle, uint32_t size)
{
v3d_create_simulator_bo_for_gem(fd, handle, size);
}
/**
* Simulated ioctl(fd, DRM_V3D_CREATE_BO) implementation.
*
* Making a V3D BO is just a matter of making a corresponding BO on the host.
*/
static int
v3d_simulator_create_bo_ioctl(int fd, struct drm_v3d_create_bo *args)
{
struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
/* i915 bans dumb create on render nodes, so we have to use their
* native ioctl in case we're on a render node.
*/
int ret;
if (file->is_i915) {
struct drm_i915_gem_create create = {
.size = args->size,
};
ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
args->handle = create.handle;
} else {
struct drm_mode_create_dumb create = {
.width = 128,
.bpp = 8,
.height = (args->size + 127) / 128,
};
ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &create);
assert(ret != 0 || create.size >= args->size);
args->handle = create.handle;
}
if (ret == 0) {
struct v3d_simulator_bo *sim_bo =
v3d_create_simulator_bo_for_gem(fd, args->handle,
args->size);
args->offset = sim_bo->block->ofs;
}
return ret;
}
/**
* Simulated ioctl(fd, DRM_V3D_MMAP_BO) implementation.
*
* We've already grabbed the mmap offset when we created the sim bo, so just
* return it.
*/
static int
v3d_simulator_mmap_bo_ioctl(int fd, struct drm_v3d_mmap_bo *args)
{
struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
struct v3d_simulator_bo *sim_bo = v3d_get_simulator_bo(file,
args->handle);
args->offset = sim_bo->mmap_offset;
return 0;
}
static int
v3d_simulator_get_bo_offset_ioctl(int fd, struct drm_v3d_get_bo_offset *args)
{
struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
struct v3d_simulator_bo *sim_bo = v3d_get_simulator_bo(file,
args->handle);
args->offset = sim_bo->block->ofs;
return 0;
}
static int
v3d_simulator_gem_close_ioctl(int fd, struct drm_gem_close *args)
{
/* Free the simulator's internal tracking. */
struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
struct v3d_simulator_bo *sim_bo = v3d_get_simulator_bo(file,
args->handle);
v3d_free_simulator_bo(sim_bo);
/* Pass the call on down. */
return drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, args);
}
static int
v3d_simulator_get_param_ioctl(int fd, struct drm_v3d_get_param *args)
{
if (sim_state.ver >= 41)
return v3d41_simulator_get_param_ioctl(sim_state.v3d, args);
else
return v3d33_simulator_get_param_ioctl(sim_state.v3d, args);
}
static int
v3d_simulator_submit_tfu_ioctl(int fd, struct drm_v3d_submit_tfu *args)
{
struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
int ret;
v3d_simulator_copy_in_handle(file, args->bo_handles[0]);
v3d_simulator_copy_in_handle(file, args->bo_handles[1]);
v3d_simulator_copy_in_handle(file, args->bo_handles[2]);
v3d_simulator_copy_in_handle(file, args->bo_handles[3]);
if (sim_state.ver >= 41)
ret = v3d41_simulator_submit_tfu_ioctl(sim_state.v3d, args);
else
ret = v3d33_simulator_submit_tfu_ioctl(sim_state.v3d, args);
v3d_simulator_copy_out_handle(file, args->bo_handles[0]);
return ret;
}
static int
v3d_simulator_submit_csd_ioctl(int fd, struct drm_v3d_submit_csd *args)
{
struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
uint32_t *bo_handles = (uint32_t *)(uintptr_t)args->bo_handles;
int ret;
for (int i = 0; i < args->bo_handle_count; i++)
v3d_simulator_copy_in_handle(file, bo_handles[i]);
v3d_simulator_perfmon_switch(fd, args->perfmon_id);
if (sim_state.ver >= 41)
ret = v3d41_simulator_submit_csd_ioctl(sim_state.v3d, args,
file->gmp->ofs);
else
ret = -1;
for (int i = 0; i < args->bo_handle_count; i++)
v3d_simulator_copy_out_handle(file, bo_handles[i]);
return ret;
}
static int
v3d_simulator_perfmon_create_ioctl(int fd, struct drm_v3d_perfmon_create *args)
{
struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
if (args->ncounters == 0 ||
args->ncounters > DRM_V3D_MAX_PERF_COUNTERS)
return -EINVAL;
struct v3d_simulator_perfmon *perfmon = rzalloc(file,
struct v3d_simulator_perfmon);
perfmon->ncounters = args->ncounters;
for (int i = 0; i < args->ncounters; i++) {
if (args->counters[i] >= V3D_PERFCNT_NUM) {
ralloc_free(perfmon);
return -EINVAL;
} else {
perfmon->counters[i] = args->counters[i];
}
}
mtx_lock(&sim_state.mutex);
args->id = perfmons_next_id(file);
file->perfmons[args->id - 1] = perfmon;
mtx_unlock(&sim_state.mutex);
return 0;
}
static int
v3d_simulator_perfmon_destroy_ioctl(int fd, struct drm_v3d_perfmon_destroy *args)
{
struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
struct v3d_simulator_perfmon *perfmon =
v3d_get_simulator_perfmon(fd, args->id);
if (!perfmon)
return -EINVAL;
mtx_lock(&sim_state.mutex);
file->perfmons[args->id - 1] = NULL;
mtx_unlock(&sim_state.mutex);
ralloc_free(perfmon);
return 0;
}
static int
v3d_simulator_perfmon_get_values_ioctl(int fd, struct drm_v3d_perfmon_get_values *args)
{
struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
mtx_lock(&sim_state.submit_lock);
/* Stop the perfmon if it is still active */
if (args->id == file->active_perfid)
v3d_simulator_perfmon_switch(fd, 0);
mtx_unlock(&sim_state.submit_lock);
struct v3d_simulator_perfmon *perfmon =
v3d_get_simulator_perfmon(fd, args->id);
if (!perfmon)
return -EINVAL;
memcpy((void *)args->values_ptr, perfmon->values, perfmon->ncounters * sizeof(uint64_t));
return 0;
}
int
v3d_simulator_ioctl(int fd, unsigned long request, void *args)
{
switch (request) {
case DRM_IOCTL_V3D_SUBMIT_CL:
return v3d_simulator_submit_cl_ioctl(fd, args);
case DRM_IOCTL_V3D_CREATE_BO:
return v3d_simulator_create_bo_ioctl(fd, args);
case DRM_IOCTL_V3D_MMAP_BO:
return v3d_simulator_mmap_bo_ioctl(fd, args);
case DRM_IOCTL_V3D_GET_BO_OFFSET:
return v3d_simulator_get_bo_offset_ioctl(fd, args);
case DRM_IOCTL_V3D_WAIT_BO:
/* We do all of the v3d rendering synchronously, so we just
* return immediately on the wait ioctls. This ignores any
* native rendering to the host BO, so it does mean we race on
* front buffer rendering.
*/
return 0;
case DRM_IOCTL_V3D_GET_PARAM:
return v3d_simulator_get_param_ioctl(fd, args);
case DRM_IOCTL_GEM_CLOSE:
return v3d_simulator_gem_close_ioctl(fd, args);
case DRM_IOCTL_V3D_SUBMIT_TFU:
return v3d_simulator_submit_tfu_ioctl(fd, args);
case DRM_IOCTL_V3D_SUBMIT_CSD:
return v3d_simulator_submit_csd_ioctl(fd, args);
case DRM_IOCTL_V3D_PERFMON_CREATE:
return v3d_simulator_perfmon_create_ioctl(fd, args);
case DRM_IOCTL_V3D_PERFMON_DESTROY:
return v3d_simulator_perfmon_destroy_ioctl(fd, args);
case DRM_IOCTL_V3D_PERFMON_GET_VALUES:
return v3d_simulator_perfmon_get_values_ioctl(fd, args);
case DRM_IOCTL_GEM_OPEN:
case DRM_IOCTL_GEM_FLINK:
return drmIoctl(fd, request, args);
default:
fprintf(stderr, "Unknown ioctl 0x%08x\n", (int)request);
abort();
}
}
uint32_t
v3d_simulator_get_mem_size(void)
{
return sim_state.mem_size;
}
static void
v3d_simulator_init_global()
{
mtx_lock(&sim_state.mutex);
if (sim_state.refcount++) {
mtx_unlock(&sim_state.mutex);
return;
}
sim_state.v3d = v3d_hw_auto_new(NULL);
v3d_hw_alloc_mem(sim_state.v3d, 1024 * 1024 * 1024);
sim_state.mem_base =
v3d_hw_get_mem(sim_state.v3d, &sim_state.mem_size,
&sim_state.mem);
/* Allocate from anywhere from 4096 up. We don't allocate at 0,
* because for OQs and some other addresses in the HW, 0 means
* disabled.
*/
sim_state.heap = u_mmInit(4096, sim_state.mem_size - 4096);
/* Make a block of 0xd0 at address 0 to make sure we don't screw up
* and land there.
*/
struct mem_block *b = u_mmAllocMem(sim_state.heap, 4096, GMP_ALIGN2, 0);
memset(sim_state.mem + b->ofs - sim_state.mem_base, 0xd0, 4096);
sim_state.ver = v3d_hw_get_version(sim_state.v3d);
mtx_unlock(&sim_state.mutex);
sim_state.fd_map =
_mesa_hash_table_create(NULL,
_mesa_hash_pointer,
_mesa_key_pointer_equal);
util_dynarray_init(&sim_state.bin_oom, NULL);
if (sim_state.ver >= 41)
v3d41_simulator_init_regs(sim_state.v3d);
else
v3d33_simulator_init_regs(sim_state.v3d);
}
struct v3d_simulator_file *
v3d_simulator_init(int fd)
{
v3d_simulator_init_global();
struct v3d_simulator_file *sim_file = rzalloc(NULL, struct v3d_simulator_file);
drmVersionPtr version = drmGetVersion(fd);
if (version && strncmp(version->name, "i915", version->name_len) == 0)
sim_file->is_i915 = true;
drmFreeVersion(version);
sim_file->bo_map =
_mesa_hash_table_create(sim_file,
_mesa_hash_pointer,
_mesa_key_pointer_equal);
mtx_lock(&sim_state.mutex);
_mesa_hash_table_insert(sim_state.fd_map, int_to_key(fd + 1),
sim_file);
mtx_unlock(&sim_state.mutex);
sim_file->gmp = u_mmAllocMem(sim_state.heap, 8096, GMP_ALIGN2, 0);
sim_file->gmp_vaddr = (sim_state.mem + sim_file->gmp->ofs -
sim_state.mem_base);
memset(sim_file->gmp_vaddr, 0, 8096);
return sim_file;
}
void
v3d_simulator_destroy(struct v3d_simulator_file *sim_file)
{
mtx_lock(&sim_state.mutex);
if (!--sim_state.refcount) {
_mesa_hash_table_destroy(sim_state.fd_map, NULL);
util_dynarray_fini(&sim_state.bin_oom);
u_mmDestroy(sim_state.heap);
/* No memsetting the struct, because it contains the mutex. */
sim_state.mem = NULL;
}
mtx_unlock(&sim_state.mutex);
ralloc_free(sim_file);
}
#endif /* USE_V3D_SIMULATOR */
|
the_stack_data/24620.c
|
/**
******************************************************************************
* @file stm32wlxx_ll_lptim.c
* @author MCD Application Team
* @brief LPTIM LL module driver.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
#if defined(USE_FULL_LL_DRIVER)
/* Includes ------------------------------------------------------------------*/
#include "stm32wlxx_ll_lptim.h"
#include "stm32wlxx_ll_bus.h"
#include "stm32wlxx_ll_rcc.h"
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif
/** @addtogroup STM32WLxx_LL_Driver
* @{
*/
#if defined (LPTIM1) || defined (LPTIM2) || defined (LPTIM3)
/** @addtogroup LPTIM_LL
* @{
*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/** @addtogroup LPTIM_LL_Private_Macros
* @{
*/
#define IS_LL_LPTIM_CLOCK_SOURCE(__VALUE__) (((__VALUE__) == LL_LPTIM_CLK_SOURCE_INTERNAL) \
|| ((__VALUE__) == LL_LPTIM_CLK_SOURCE_EXTERNAL))
#define IS_LL_LPTIM_CLOCK_PRESCALER(__VALUE__) (((__VALUE__) == LL_LPTIM_PRESCALER_DIV1) \
|| ((__VALUE__) == LL_LPTIM_PRESCALER_DIV2) \
|| ((__VALUE__) == LL_LPTIM_PRESCALER_DIV4) \
|| ((__VALUE__) == LL_LPTIM_PRESCALER_DIV8) \
|| ((__VALUE__) == LL_LPTIM_PRESCALER_DIV16) \
|| ((__VALUE__) == LL_LPTIM_PRESCALER_DIV32) \
|| ((__VALUE__) == LL_LPTIM_PRESCALER_DIV64) \
|| ((__VALUE__) == LL_LPTIM_PRESCALER_DIV128))
#define IS_LL_LPTIM_WAVEFORM(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_PWM) || \
((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_SETONCE))
#define IS_LL_LPTIM_OUTPUT_POLARITY(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_REGULAR) || \
((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_INVERSE))
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/** @defgroup LPTIM_Private_Functions LPTIM Private Functions
* @{
*/
/**
* @}
*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup LPTIM_LL_Exported_Functions
* @{
*/
/** @addtogroup LPTIM_LL_EF_Init
* @{
*/
/**
* @brief Set LPTIMx registers to their reset values.
* @param LPTIMx LP Timer instance
* @retval An ErrorStatus enumeration value:
* - SUCCESS: LPTIMx registers are de-initialized
* - ERROR: invalid LPTIMx instance
*/
ErrorStatus LL_LPTIM_DeInit(LPTIM_TypeDef *LPTIMx)
{
ErrorStatus result = SUCCESS;
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(LPTIMx));
if (LPTIMx == LPTIM1)
{
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_LPTIM1);
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_LPTIM1);
}
else if (LPTIMx == LPTIM2)
{
LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_LPTIM2);
LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_LPTIM2);
}
else if (LPTIMx == LPTIM3)
{
LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_LPTIM3);
LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_LPTIM3);
}
else
{
result = ERROR;
}
return result;
}
/**
* @brief Set each fields of the LPTIM_InitStruct structure to its default
* value.
* @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
* @retval None
*/
void LL_LPTIM_StructInit(LL_LPTIM_InitTypeDef *LPTIM_InitStruct)
{
/* Set the default configuration */
LPTIM_InitStruct->ClockSource = LL_LPTIM_CLK_SOURCE_INTERNAL;
LPTIM_InitStruct->Prescaler = LL_LPTIM_PRESCALER_DIV1;
LPTIM_InitStruct->Waveform = LL_LPTIM_OUTPUT_WAVEFORM_PWM;
LPTIM_InitStruct->Polarity = LL_LPTIM_OUTPUT_POLARITY_REGULAR;
}
/**
* @brief Configure the LPTIMx peripheral according to the specified parameters.
* @note LL_LPTIM_Init can only be called when the LPTIM instance is disabled.
* @note LPTIMx can be disabled using unitary function @ref LL_LPTIM_Disable().
* @param LPTIMx LP Timer Instance
* @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: LPTIMx instance has been initialized
* - ERROR: LPTIMx instance hasn't been initialized
*/
ErrorStatus LL_LPTIM_Init(LPTIM_TypeDef *LPTIMx, LL_LPTIM_InitTypeDef *LPTIM_InitStruct)
{
ErrorStatus result = SUCCESS;
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(LPTIMx));
assert_param(IS_LL_LPTIM_CLOCK_SOURCE(LPTIM_InitStruct->ClockSource));
assert_param(IS_LL_LPTIM_CLOCK_PRESCALER(LPTIM_InitStruct->Prescaler));
assert_param(IS_LL_LPTIM_WAVEFORM(LPTIM_InitStruct->Waveform));
assert_param(IS_LL_LPTIM_OUTPUT_POLARITY(LPTIM_InitStruct->Polarity));
/* The LPTIMx_CFGR register must only be modified when the LPTIM is disabled
(ENABLE bit is reset to 0).
*/
if (LL_LPTIM_IsEnabled(LPTIMx) == 1UL)
{
result = ERROR;
}
else
{
/* Set CKSEL bitfield according to ClockSource value */
/* Set PRESC bitfield according to Prescaler value */
/* Set WAVE bitfield according to Waveform value */
/* Set WAVEPOL bitfield according to Polarity value */
MODIFY_REG(LPTIMx->CFGR,
(LPTIM_CFGR_CKSEL | LPTIM_CFGR_PRESC | LPTIM_CFGR_WAVE | LPTIM_CFGR_WAVPOL),
LPTIM_InitStruct->ClockSource | \
LPTIM_InitStruct->Prescaler | \
LPTIM_InitStruct->Waveform | \
LPTIM_InitStruct->Polarity);
}
return result;
}
/**
* @brief Disable the LPTIM instance
* @rmtoll CR ENABLE LL_LPTIM_Disable
* @param LPTIMx Low-Power Timer instance
* @note The following sequence is required to solve LPTIM disable HW limitation.
* Please check Errata Sheet ES0335 for more details under "MCU may remain
* stuck in LPTIM interrupt when entering Stop mode" section.
* @retval None
*/
void LL_LPTIM_Disable(LPTIM_TypeDef *LPTIMx)
{
LL_RCC_ClocksTypeDef rcc_clock;
uint32_t tmpclksource = 0;
uint32_t tmpIER;
uint32_t tmpCFGR;
uint32_t tmpCMP;
uint32_t tmpARR;
uint32_t tmpOR;
uint32_t tmpRCR;
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(LPTIMx));
__disable_irq();
/********** Save LPTIM Config *********/
/* Save LPTIM source clock */
switch ((uint32_t)LPTIMx)
{
case LPTIM1_BASE:
tmpclksource = LL_RCC_GetLPTIMClockSource(LL_RCC_LPTIM1_CLKSOURCE);
break;
case LPTIM2_BASE:
tmpclksource = LL_RCC_GetLPTIMClockSource(LL_RCC_LPTIM2_CLKSOURCE);
break;
case LPTIM3_BASE:
tmpclksource = LL_RCC_GetLPTIMClockSource(LL_RCC_LPTIM3_CLKSOURCE);
break;
default:
break;
}
/* Save LPTIM configuration registers */
tmpIER = LPTIMx->IER;
tmpCFGR = LPTIMx->CFGR;
tmpCMP = LPTIMx->CMP;
tmpARR = LPTIMx->ARR;
tmpOR = LPTIMx->OR;
tmpRCR = LPTIMx->RCR;
/************* Reset LPTIM ************/
(void)LL_LPTIM_DeInit(LPTIMx);
/********* Restore LPTIM Config *******/
LL_RCC_GetSystemClocksFreq(&rcc_clock);
if ((tmpCMP != 0UL) || (tmpARR != 0UL) || (tmpRCR != 0UL))
{
/* Force LPTIM source kernel clock from APB */
switch ((uint32_t)LPTIMx)
{
case LPTIM1_BASE:
LL_RCC_SetLPTIMClockSource(LL_RCC_LPTIM1_CLKSOURCE_PCLK1);
break;
case LPTIM2_BASE:
LL_RCC_SetLPTIMClockSource(LL_RCC_LPTIM2_CLKSOURCE_PCLK1);
break;
case LPTIM3_BASE:
LL_RCC_SetLPTIMClockSource(LL_RCC_LPTIM3_CLKSOURCE_PCLK1);
break;
default:
break;
}
if (tmpCMP != 0UL)
{
/* Restore CMP and ARR registers (LPTIM should be enabled first) */
LPTIMx->CR |= LPTIM_CR_ENABLE;
LPTIMx->CMP = tmpCMP;
/* Polling on CMP write ok status after above restore operation */
do
{
rcc_clock.SYSCLK_Frequency--; /* Used for timeout */
} while (((LL_LPTIM_IsActiveFlag_CMPOK(LPTIMx) != 1UL)) && ((rcc_clock.SYSCLK_Frequency) > 0UL));
LL_LPTIM_ClearFlag_CMPOK(LPTIMx);
}
if (tmpARR != 0UL)
{
LPTIMx->CR |= LPTIM_CR_ENABLE;
LPTIMx->ARR = tmpARR;
LL_RCC_GetSystemClocksFreq(&rcc_clock);
/* Polling on ARR write ok status after above restore operation */
do
{
rcc_clock.SYSCLK_Frequency--; /* Used for timeout */
}
while (((LL_LPTIM_IsActiveFlag_ARROK(LPTIMx) != 1UL)) && ((rcc_clock.SYSCLK_Frequency) > 0UL));
LL_LPTIM_ClearFlag_ARROK(LPTIMx);
}
if (tmpRCR != 0UL)
{
LPTIMx->CR |= LPTIM_CR_ENABLE;
LPTIMx->RCR = tmpRCR;
LL_RCC_GetSystemClocksFreq(&rcc_clock);
/* Polling on RCR write ok status after above restore operation */
do
{
rcc_clock.SYSCLK_Frequency--; /* Used for timeout */
} while (((LL_LPTIM_IsActiveFlag_REPOK(LPTIMx) != 1UL)) && ((rcc_clock.SYSCLK_Frequency) > 0UL));
LL_LPTIM_ClearFlag_REPOK(LPTIMx);
}
/* Restore LPTIM source kernel clock */
LL_RCC_SetLPTIMClockSource(tmpclksource);
}
/* Restore configuration registers (LPTIM should be disabled first) */
LPTIMx->CR &= ~(LPTIM_CR_ENABLE);
LPTIMx->IER = tmpIER;
LPTIMx->CFGR = tmpCFGR;
LPTIMx->OR = tmpOR;
__enable_irq();
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* LPTIM1 || LPTIM2 || LPTIM3 */
/**
* @}
*/
#endif /* USE_FULL_LL_DRIVER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
the_stack_data/150140246.c
|
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int data;
struct Node *next;
};
void display(struct Node *);
void build(int *, int, struct Node **);
void append(struct Node **, int);
void insert(struct Node**, int, int);
int del(struct Node **, int);
int main()
{
struct Node *head = NULL;
int arr[] = {10, 20, 30, 40};
build(arr, 4, &head);
display(head);
insert(&head , 50, 2);
display(head);
del(&head,4);
display(head);
return 0;
}
int del(struct Node **head, int position)
{
if(position < 0)
{
printf("Invalid Index\n");
return -1;
}
if(*head == NULL)
{
printf("Head is null\n");
return -1;
}
struct Node *curr = *head, *tail = NULL;
int i=0, data;
if(position == 0)
{
do
{
curr = curr->next;
} while (curr->next != *head);
tail = *head;
data = tail->data;
curr->next = tail->next;
tail->next = NULL;
*head = curr->next;
free(tail);
return data;
}
do
{
if(position == i)
break;
tail = curr;
curr = curr->next;
i++;
} while (curr != *head);
if(curr== *head || i<position)
{
printf("Invalid Index\n");
return -1;
}
tail->next = curr->next;
data = curr->data;
curr->next = NULL;
free(curr);
return data;
}
void insert(struct Node** head, int value, int position)
{
if(position < 0)
{
printf("Invalid Index\n");
return;
}
struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = value;
newNode->next = NULL;
if(!(*head))
{
newNode->next = *head;
*head = newNode;
return;
}
struct Node *curr = *head;
int i = 0;
if(position == 0)
{
do
{
curr = curr->next;
} while (curr->next != *head);
curr->next = newNode;
newNode->next = *head;
*head = newNode;
return ;
}
do
{
if(i == position-1)
break;
curr = curr->next;
i++;
} while ((curr != *head));
if((curr == *head) && i < position)
{
printf("Invalid Index\n");
return;
}
newNode->next = curr->next;
curr->next = newNode;
return;
}
void append(struct Node **head, int data)
{
struct Node *newNode = (struct Node *)malloc(sizeof(struct Node));
newNode->data = data;
newNode->next = NULL;
if (!(*head))
{
*head = newNode;
newNode->next = *head;
}
else
{
struct Node *t = *head;
do
{
t = t->next;
} while (t->next != (*head));
t->next = newNode;
newNode->next = *head;
}
}
void build(int *arr, int n, struct Node **head)
{
int i = 0;
for (; i < n; i++)
{
append(head, arr[i]);
}
}
void display(struct Node *head)
{
struct Node *curr = head;
printf("------------------------------------\n");
do
{
printf("%d ->", curr->data);
curr = curr->next;
} while (curr != head);
printf("\n------------------------------------\n");
}
|
the_stack_data/827189.c
|
//===-- main.c --------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <stdio.h>
int g_common_1; // Not initialized on purpose to cause it to be undefined external in .o file
int g_file_global_int = 42;
static const int g_file_static_int = 2;
const char *g_file_global_cstr = "g_file_global_cstr";
static const char *g_file_static_cstr = "g_file_static_cstr";
int *g_ptr = &g_file_global_int;
extern int g_a;
int main (int argc, char const *argv[])
{
g_common_1 = g_file_global_int / g_file_static_int;
static const char *g_func_static_cstr = "g_func_static_cstr";
printf ("%s %s\n", g_file_global_cstr, g_file_static_cstr);
return g_file_global_int + g_a + g_common_1 + *g_ptr; // Set break point at this line. //// break $source:$line; continue; var -global g_a -global g_global_int
}
|
the_stack_data/59512685.c
|
//
#include <stdio.h>
#include <math.h>
int main() {
int int_1, int_2, int_3, int_4;
printf("Please enter 4 numbers separated by spaces > ");
scanf("%d %d %d %d", &int_1, &int_2, &int_3, &int_4);
if (int_1 < int_2 && int_1 < int_3 && int_1 < int_4)
printf("%d is the smallest \n", int_1);
else if(int_2 < int_1 && int_2 < int_3 && int_2 < int_4)
printf("%d is the smallest \n", int_2);
else if (int_3 < int_1 && int_3 < int_2 && int_3 < int_4)
printf("%d is the smallest \n", int_3);
else (printf("%d is the smallest \n", int_4));
return(0);
}
|
the_stack_data/574479.c
|
#include <stdio.h>
int main(void)
{
printf("Hello, World\n");
return 0;
}
|
the_stack_data/355441.c
|
int gpu_index = 0;
#ifdef GPU
#include "cuda.h"
//#include "utils.h"
#include "blas.h"
#include "assert.h"
#include <stdlib.h>
#include <time.h>
void cuda_set_device(int n)
{
gpu_index = n;
cudaError_t status = cudaSetDevice(n);
check_error(status);
}
int cuda_get_device()
{
int n = 0;
cudaError_t status = cudaGetDevice(&n);
check_error(status);
return n;
}
void check_error(cudaError_t status)
{
//cudaDeviceSynchronize();
cudaError_t status2 = cudaGetLastError();
if (status != cudaSuccess)
{
const char *s = cudaGetErrorString(status);
char buffer[256];
printf("CUDA Error: %s\n", s);
assert(0);
snprintf(buffer, 256, "CUDA Error: %s", s);
error(buffer);
}
if (status2 != cudaSuccess)
{
const char *s = cudaGetErrorString(status);
char buffer[256];
printf("CUDA Error Prev: %s\n", s);
assert(0);
snprintf(buffer, 256, "CUDA Error Prev: %s", s);
error(buffer);
}
}
dim3 cuda_gridsize(size_t n){
size_t k = (n-1) / BLOCK + 1;
size_t x = k;
size_t y = 1;
if(x > 65535){
x = ceil(sqrt(k));
y = (n-1)/(x*BLOCK) + 1;
}
dim3 d = {x, y, 1};
//printf("%ld %ld %ld %ld\n", n, x, y, x*y*BLOCK);
return d;
}
#ifdef CUDNN
cudnnHandle_t cudnn_handle()
{
static int init[16] = {0};
static cudnnHandle_t handle[16];
int i = cuda_get_device();
if(!init[i]) {
cudnnCreate(&handle[i]);
init[i] = 1;
}
return handle[i];
}
#endif
cublasHandle_t blas_handle()
{
static int init[16] = {0};
static cublasHandle_t handle[16];
int i = cuda_get_device();
if(!init[i]) {
cublasCreate(&handle[i]);
init[i] = 1;
}
return handle[i];
}
float *cuda_make_array(float *x, size_t n)
{
float *x_gpu;
size_t size = sizeof(float)*n;
cudaError_t status = cudaMalloc((void **)&x_gpu, size);
check_error(status);
if(x){
status = cudaMemcpy(x_gpu, x, size, cudaMemcpyHostToDevice);
check_error(status);
}
if(!x_gpu) error("Cuda malloc failed\n");
return x_gpu;
}
void cuda_random(float *x_gpu, size_t n)
{
static curandGenerator_t gen[16];
static int init[16] = {0};
int i = cuda_get_device();
if(!init[i]){
curandCreateGenerator(&gen[i], CURAND_RNG_PSEUDO_DEFAULT);
curandSetPseudoRandomGeneratorSeed(gen[i], time(0));
init[i] = 1;
}
curandGenerateUniform(gen[i], x_gpu, n);
check_error(cudaPeekAtLastError());
}
float cuda_compare(float *x_gpu, float *x, size_t n, char *s)
{
float *tmp = calloc(n, sizeof(float));
cuda_pull_array(x_gpu, tmp, n);
//int i;
//for(i = 0; i < n; ++i) printf("%f %f\n", tmp[i], x[i]);
axpy_cpu(n, -1, x, 1, tmp, 1);
float err = dot_cpu(n, tmp, 1, tmp, 1);
printf("Error %s: %f\n", s, sqrt(err/n));
free(tmp);
return err;
}
int *cuda_make_int_array(size_t n)
{
int *x_gpu;
size_t size = sizeof(int)*n;
cudaError_t status = cudaMalloc((void **)&x_gpu, size);
check_error(status);
return x_gpu;
}
void cuda_free(float *x_gpu)
{
cudaError_t status = cudaFree(x_gpu);
check_error(status);
}
void cuda_push_array(float *x_gpu, float *x, size_t n)
{
size_t size = sizeof(float)*n;
cudaError_t status = cudaMemcpy(x_gpu, x, size, cudaMemcpyHostToDevice);
check_error(status);
}
void cuda_pull_array(float *x_gpu, float *x, size_t n)
{
size_t size = sizeof(float)*n;
cudaError_t status = cudaMemcpy(x, x_gpu, size, cudaMemcpyDeviceToHost);
check_error(status);
}
#endif
|
the_stack_data/132155.c
|
#include <stdio.h>
/******************************************************************************
A "union" allows you to access the same area of memory as two different
types of objects. In the example below, a 64-bit area of memory (8 bytes)
is treated as a 64-bit unsigned integer (type "unsigned long long") in
some places, and as a 64-bit double precision floating point in others.
Note the use of the "%llx" and "%lf" formatting specs in the calls to
"printf", as well as the "ULL" suffix on the 64-bit literal constant.
******************************************************************************/
union dp_item
{
double drep;
unsigned long long int irep;
};
int main()
{
double A = 1.25;
union dp_item B;
B.drep = A;
printf( "B as a 64-bit dp float: %16.8lf\n", B.drep );
printf( "B as a 64-bit integer: %016llx\n", B.irep );
B.irep = B.irep ^ 0xffffffffffffffffULL;
printf( "B as a 64-bit integer: %016llx\n", B.irep );
return 0;
}
|
the_stack_data/115613.c
|
#include <stdio.h>
int main()
{
int a=5,b=6,c=5;
int T = 1, F = 0;
printf("\n =====Bitwise Operators ====\n\n");
printf("\n T=%d and F=%d\n", T,F);
printf("\n T & T -> %d", T & T);
printf("\n T & F -> %d", T & F);
printf("\n F & T -> %d", F & T);
printf("\n F & F -> %d", F & F);
printf("\n\n\n T | T -> %d", T | T);
printf("\n T | F -> %d", T | F);
printf("\n F | T -> %d", F | T);
printf("\n F | F -> %d", F | F);
printf("\n\n\n a = %d b = %d c=%d", a , b, c);
printf("\n a & b -> %d", a & b);
printf("\n a & c -> %d", a & c);
printf("\n a | b -> %d", a | b);
printf("\n a | c -> %d", a | c);
printf("\n\n\n T ^ T -> %d", T ^ T);
printf("\n T ^ F -> %d", T ^ F);
printf("\n F ^ T -> %d", F ^ T);
printf("\n F ^ F -> %d", F ^ F);
printf("\n a ^ b -> %d", a ^ b);
//Compliment
printf("\n ~a --> %d", ~a);
printf("\n ~T --> %d", ~T);
printf("\n ~F --> %d", ~F);
}
|
the_stack_data/64200487.c
|
/* A Bison parser, made by GNU Bison 3.5.1. */
/* Bison implementation for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 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/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* C LALR(1) parser skeleton written by Richard Stallman, by
simplifying the original so-called "semantic" parser. */
/* All symbols defined below should begin with yy or YY, to avoid
infringing on user name space. This should be done even for local
variables, as they might otherwise be expanded by user macros.
There are some unavoidable exceptions within include files to
define necessary library symbols; they are noted "INFRINGES ON
USER NAME SPACE" below. */
/* Undocumented macros, especially those whose name start with YY_,
are private implementation details. Do not rely on them. */
/* Identify Bison output. */
#define YYBISON 1
/* Bison version. */
#define YYBISON_VERSION "3.5.1"
/* Skeleton name. */
#define YYSKELETON_NAME "yacc.c"
/* Pure parsers. */
#define YYPURE 0
/* Push parsers. */
#define YYPUSH 0
/* Pull parsers. */
#define YYPULL 1
/* First part of user prologue. */
#line 1 "b4yacc.y"
#include<stdio.h>
void yyerror(char*);
int yylex();
FILE *yyin;
#line 77 "y.tab.c"
# ifndef YY_CAST
# ifdef __cplusplus
# define YY_CAST(Type, Val) static_cast<Type> (Val)
# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
# else
# define YY_CAST(Type, Val) ((Type) (Val))
# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
# endif
# endif
# ifndef YY_NULLPTR
# if defined __cplusplus
# if 201103L <= __cplusplus
# define YY_NULLPTR nullptr
# else
# define YY_NULLPTR 0
# endif
# else
# define YY_NULLPTR ((void*)0)
# endif
# endif
/* Enabling verbose error messages. */
#ifdef YYERROR_VERBOSE
# undef YYERROR_VERBOSE
# define YYERROR_VERBOSE 1
#else
# define YYERROR_VERBOSE 0
#endif
/* Use api.header.include to #include this header
instead of duplicating it here. */
#ifndef YY_YY_Y_TAB_H_INCLUDED
# define YY_YY_Y_TAB_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* Token type. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
aint = 258,
afloat = 259,
achar = 260,
abool = 261,
boolval = 262,
aString = 263,
var = 264,
equ = 265,
digit = 266,
number = 267,
decimal = 268,
charval = 269,
Stringval = 270,
comma = 271,
newl = 272,
sc = 273
};
#endif
/* Tokens. */
#define aint 258
#define afloat 259
#define achar 260
#define abool 261
#define boolval 262
#define aString 263
#define var 264
#define equ 265
#define digit 266
#define number 267
#define decimal 268
#define charval 269
#define Stringval 270
#define comma 271
#define newl 272
#define sc 273
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef int YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE yylval;
int yyparse (void);
#endif /* !YY_YY_Y_TAB_H_INCLUDED */
#ifdef short
# undef short
#endif
/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
<limits.h> and (if available) <stdint.h> are included
so that the code can choose integer types of a good width. */
#ifndef __PTRDIFF_MAX__
# include <limits.h> /* INFRINGES ON USER NAME SPACE */
# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
# include <stdint.h> /* INFRINGES ON USER NAME SPACE */
# define YY_STDINT_H
# endif
#endif
/* Narrow types that promote to a signed type and that can represent a
signed or unsigned integer of at least N bits. In tables they can
save space and decrease cache pressure. Promoting to a signed type
helps avoid bugs in integer arithmetic. */
#ifdef __INT_LEAST8_MAX__
typedef __INT_LEAST8_TYPE__ yytype_int8;
#elif defined YY_STDINT_H
typedef int_least8_t yytype_int8;
#else
typedef signed char yytype_int8;
#endif
#ifdef __INT_LEAST16_MAX__
typedef __INT_LEAST16_TYPE__ yytype_int16;
#elif defined YY_STDINT_H
typedef int_least16_t yytype_int16;
#else
typedef short yytype_int16;
#endif
#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
typedef __UINT_LEAST8_TYPE__ yytype_uint8;
#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
&& UINT_LEAST8_MAX <= INT_MAX)
typedef uint_least8_t yytype_uint8;
#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
typedef unsigned char yytype_uint8;
#else
typedef short yytype_uint8;
#endif
#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
typedef __UINT_LEAST16_TYPE__ yytype_uint16;
#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
&& UINT_LEAST16_MAX <= INT_MAX)
typedef uint_least16_t yytype_uint16;
#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
typedef unsigned short yytype_uint16;
#else
typedef int yytype_uint16;
#endif
#ifndef YYPTRDIFF_T
# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
# define YYPTRDIFF_T __PTRDIFF_TYPE__
# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
# elif defined PTRDIFF_MAX
# ifndef ptrdiff_t
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# endif
# define YYPTRDIFF_T ptrdiff_t
# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
# else
# define YYPTRDIFF_T long
# define YYPTRDIFF_MAXIMUM LONG_MAX
# endif
#endif
#ifndef YYSIZE_T
# ifdef __SIZE_TYPE__
# define YYSIZE_T __SIZE_TYPE__
# elif defined size_t
# define YYSIZE_T size_t
# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# define YYSIZE_T size_t
# else
# define YYSIZE_T unsigned
# endif
#endif
#define YYSIZE_MAXIMUM \
YY_CAST (YYPTRDIFF_T, \
(YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
? YYPTRDIFF_MAXIMUM \
: YY_CAST (YYSIZE_T, -1)))
#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
/* Stored state numbers (used for stacks). */
typedef yytype_int8 yy_state_t;
/* State numbers in computations. */
typedef int yy_state_fast_t;
#ifndef YY_
# if defined YYENABLE_NLS && YYENABLE_NLS
# if ENABLE_NLS
# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
# endif
# endif
# ifndef YY_
# define YY_(Msgid) Msgid
# endif
#endif
#ifndef YY_ATTRIBUTE_PURE
# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
# else
# define YY_ATTRIBUTE_PURE
# endif
#endif
#ifndef YY_ATTRIBUTE_UNUSED
# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
# else
# define YY_ATTRIBUTE_UNUSED
# endif
#endif
/* Suppress unused-variable warnings by "using" E. */
#if ! defined lint || defined __GNUC__
# define YYUSE(E) ((void) (E))
#else
# define YYUSE(E) /* empty */
#endif
#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
/* Suppress an incorrect diagnostic about yylval being uninitialized. */
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
_Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
_Pragma ("GCC diagnostic pop")
#else
# define YY_INITIAL_VALUE(Value) Value
#endif
#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
# define YY_IGNORE_MAYBE_UNINITIALIZED_END
#endif
#ifndef YY_INITIAL_VALUE
# define YY_INITIAL_VALUE(Value) /* Nothing. */
#endif
#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
# define YY_IGNORE_USELESS_CAST_BEGIN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
# define YY_IGNORE_USELESS_CAST_END \
_Pragma ("GCC diagnostic pop")
#endif
#ifndef YY_IGNORE_USELESS_CAST_BEGIN
# define YY_IGNORE_USELESS_CAST_BEGIN
# define YY_IGNORE_USELESS_CAST_END
#endif
#define YY_ASSERT(E) ((void) (0 && (E)))
#if ! defined yyoverflow || YYERROR_VERBOSE
/* The parser invokes alloca or malloc; define the necessary symbols. */
# ifdef YYSTACK_USE_ALLOCA
# if YYSTACK_USE_ALLOCA
# ifdef __GNUC__
# define YYSTACK_ALLOC __builtin_alloca
# elif defined __BUILTIN_VA_ARG_INCR
# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
# elif defined _AIX
# define YYSTACK_ALLOC __alloca
# elif defined _MSC_VER
# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
# define alloca _alloca
# else
# define YYSTACK_ALLOC alloca
# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
/* Use EXIT_SUCCESS as a witness for stdlib.h. */
# ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
# endif
# endif
# endif
# endif
# endif
# ifdef YYSTACK_ALLOC
/* Pacify GCC's 'empty if-body' warning. */
# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
# ifndef YYSTACK_ALLOC_MAXIMUM
/* The OS might guarantee only one guard page at the bottom of the stack,
and a page size can be as small as 4096 bytes. So we cannot safely
invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
to allow for a few compiler-allocated temporary stack slots. */
# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
# endif
# else
# define YYSTACK_ALLOC YYMALLOC
# define YYSTACK_FREE YYFREE
# ifndef YYSTACK_ALLOC_MAXIMUM
# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
# endif
# if (defined __cplusplus && ! defined EXIT_SUCCESS \
&& ! ((defined YYMALLOC || defined malloc) \
&& (defined YYFREE || defined free)))
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
# ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
# endif
# endif
# ifndef YYMALLOC
# define YYMALLOC malloc
# if ! defined malloc && ! defined EXIT_SUCCESS
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
# endif
# endif
# ifndef YYFREE
# define YYFREE free
# if ! defined free && ! defined EXIT_SUCCESS
void free (void *); /* INFRINGES ON USER NAME SPACE */
# endif
# endif
# endif
#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
#if (! defined yyoverflow \
&& (! defined __cplusplus \
|| (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
/* A type that is properly aligned for any stack member. */
union yyalloc
{
yy_state_t yyss_alloc;
YYSTYPE yyvs_alloc;
};
/* The size of the maximum gap between one aligned stack and the next. */
# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
/* The size of an array large to enough to hold all stacks, each with
N elements. */
# define YYSTACK_BYTES(N) \
((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
+ YYSTACK_GAP_MAXIMUM)
# define YYCOPY_NEEDED 1
/* Relocate STACK from its old location to the new one. The
local variables YYSIZE and YYSTACKSIZE give the old and new number of
elements in the stack, and YYPTR gives the new location of the
stack. Advance YYPTR to a properly aligned location for the next
stack. */
# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
do \
{ \
YYPTRDIFF_T yynewbytes; \
YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
Stack = &yyptr->Stack_alloc; \
yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
yyptr += yynewbytes / YYSIZEOF (*yyptr); \
} \
while (0)
#endif
#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
/* Copy COUNT objects from SRC to DST. The source and destination do
not overlap. */
# ifndef YYCOPY
# if defined __GNUC__ && 1 < __GNUC__
# define YYCOPY(Dst, Src, Count) \
__builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
# else
# define YYCOPY(Dst, Src, Count) \
do \
{ \
YYPTRDIFF_T yyi; \
for (yyi = 0; yyi < (Count); yyi++) \
(Dst)[yyi] = (Src)[yyi]; \
} \
while (0)
# endif
# endif
#endif /* !YYCOPY_NEEDED */
/* YYFINAL -- State number of the termination state. */
#define YYFINAL 22
/* YYLAST -- Last index in YYTABLE. */
#define YYLAST 61
/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 19
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS 12
/* YYNRULES -- Number of rules. */
#define YYNRULES 42
/* YYNSTATES -- Number of states. */
#define YYNSTATES 72
#define YYUNDEFTOK 2
#define YYMAXUTOK 273
/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
as returned by yylex, with out-of-bounds checking. */
#define YYTRANSLATE(YYX) \
(0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
as returned by yylex. */
static const yytype_int8 yytranslate[] =
{
0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18
};
#if YYDEBUG
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_int8 yyrline[] =
{
0, 9, 9, 10, 11, 12, 13, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 26, 26, 26,
26, 26, 26, 28, 28, 28, 28, 28, 28, 28,
28, 30, 30, 30, 30, 32, 32, 32, 32, 34,
34, 34, 34
};
#endif
#if YYDEBUG || YYERROR_VERBOSE || 0
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
"$end", "error", "$undefined", "aint", "afloat", "achar", "abool",
"boolval", "aString", "var", "equ", "digit", "number", "decimal",
"charval", "Stringval", "comma", "newl", "sc", "$accept", "s", "I", "F",
"C", "B", "S", "I1", "F1", "C1", "B1", "S1", YY_NULLPTR
};
#endif
# ifdef YYPRINT
/* YYTOKNUM[NUM] -- (External) token number corresponding to the
(internal) symbol number NUM (which must be that of a token). */
static const yytype_int16 yytoknum[] =
{
0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273
};
# endif
#define YYPACT_NINF (-33)
#define yypact_value_is_default(Yyn) \
((Yyn) == YYPACT_NINF)
#define YYTABLE_NINF (-1)
#define yytable_value_is_error(Yyn) \
0
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
static const yytype_int8 yypact[] =
{
15, -5, 18, 19, 20, 29, 22, -33, -33, -33,
-33, -33, -7, 21, -4, 23, -3, 24, -2, 25,
1, 26, -33, 4, -5, 28, 13, 18, 30, 32,
19, 31, 33, 20, 34, 35, 29, 36, 38, 39,
-33, -33, 40, 41, 42, -33, -33, 43, -33, -33,
44, -33, -33, 45, -33, -33, -5, -5, 18, 18,
18, 19, 20, 29, -33, -33, -33, -33, -33, -33,
-33, -33
};
/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
Performed when YYTABLE does not specify something else to do. Zero
means the default is an error. */
static const yytype_int8 yydefact[] =
{
0, 0, 0, 0, 0, 0, 0, 2, 3, 4,
5, 6, 17, 0, 23, 0, 31, 0, 35, 0,
39, 0, 1, 0, 0, 7, 0, 0, 9, 0,
0, 11, 0, 0, 13, 0, 0, 15, 19, 21,
18, 8, 25, 27, 29, 24, 10, 33, 32, 12,
37, 36, 14, 41, 40, 16, 0, 0, 0, 0,
0, 0, 0, 0, 20, 22, 26, 28, 30, 34,
38, 42
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int8 yypgoto[] =
{
-33, -33, -33, -33, -33, -33, -33, -22, -27, -25,
-32, -26
};
/* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int8 yydefgoto[] =
{
-1, 6, 7, 8, 9, 10, 11, 13, 15, 17,
19, 21
};
/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
positive, shift that token. If negative, reduce the rule whose
number is the opposite. If YYTABLE_NINF, syntax error. */
static const yytype_int8 yytable[] =
{
45, 51, 40, 23, 12, 48, 26, 29, 32, 24,
54, 35, 27, 30, 33, 38, 39, 36, 1, 2,
3, 4, 22, 5, 42, 43, 44, 14, 16, 18,
70, 66, 67, 68, 64, 65, 69, 71, 20, 25,
50, 28, 31, 34, 37, 41, 47, 46, 49, 0,
53, 52, 0, 55, 56, 57, 58, 59, 60, 61,
62, 63
};
static const yytype_int8 yycheck[] =
{
27, 33, 24, 10, 9, 30, 10, 10, 10, 16,
36, 10, 16, 16, 16, 11, 12, 16, 3, 4,
5, 6, 0, 8, 11, 12, 13, 9, 9, 9,
62, 58, 59, 60, 56, 57, 61, 63, 9, 18,
7, 18, 18, 18, 18, 17, 14, 17, 17, -1,
15, 17, -1, 17, 16, 16, 16, 16, 16, 16,
16, 16
};
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
static const yytype_int8 yystos[] =
{
0, 3, 4, 5, 6, 8, 20, 21, 22, 23,
24, 25, 9, 26, 9, 27, 9, 28, 9, 29,
9, 30, 0, 10, 16, 18, 10, 16, 18, 10,
16, 18, 10, 16, 18, 10, 16, 18, 11, 12,
26, 17, 11, 12, 13, 27, 17, 14, 28, 17,
7, 29, 17, 15, 30, 17, 16, 16, 16, 16,
16, 16, 16, 16, 26, 26, 27, 27, 27, 28,
29, 30
};
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const yytype_int8 yyr1[] =
{
0, 19, 20, 20, 20, 20, 20, 21, 21, 22,
22, 23, 23, 24, 24, 25, 25, 26, 26, 26,
26, 26, 26, 27, 27, 27, 27, 27, 27, 27,
27, 28, 28, 28, 28, 29, 29, 29, 29, 30,
30, 30, 30
};
/* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
static const yytype_int8 yyr2[] =
{
0, 2, 1, 1, 1, 1, 1, 3, 4, 3,
4, 3, 4, 3, 4, 3, 4, 1, 3, 3,
5, 3, 5, 1, 3, 3, 5, 3, 5, 3,
5, 1, 3, 3, 5, 1, 3, 3, 5, 1,
3, 3, 5
};
#define yyerrok (yyerrstatus = 0)
#define yyclearin (yychar = YYEMPTY)
#define YYEMPTY (-2)
#define YYEOF 0
#define YYACCEPT goto yyacceptlab
#define YYABORT goto yyabortlab
#define YYERROR goto yyerrorlab
#define YYRECOVERING() (!!yyerrstatus)
#define YYBACKUP(Token, Value) \
do \
if (yychar == YYEMPTY) \
{ \
yychar = (Token); \
yylval = (Value); \
YYPOPSTACK (yylen); \
yystate = *yyssp; \
goto yybackup; \
} \
else \
{ \
yyerror (YY_("syntax error: cannot back up")); \
YYERROR; \
} \
while (0)
/* Error token number */
#define YYTERROR 1
#define YYERRCODE 256
/* Enable debugging if requested. */
#if YYDEBUG
# ifndef YYFPRINTF
# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
# define YYFPRINTF fprintf
# endif
# define YYDPRINTF(Args) \
do { \
if (yydebug) \
YYFPRINTF Args; \
} while (0)
/* This macro is provided for backward compatibility. */
#ifndef YY_LOCATION_PRINT
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
#endif
# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
do { \
if (yydebug) \
{ \
YYFPRINTF (stderr, "%s ", Title); \
yy_symbol_print (stderr, \
Type, Value); \
YYFPRINTF (stderr, "\n"); \
} \
} while (0)
/*-----------------------------------.
| Print this symbol's value on YYO. |
`-----------------------------------*/
static void
yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep)
{
FILE *yyoutput = yyo;
YYUSE (yyoutput);
if (!yyvaluep)
return;
# ifdef YYPRINT
if (yytype < YYNTOKENS)
YYPRINT (yyo, yytoknum[yytype], *yyvaluep);
# endif
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
YYUSE (yytype);
YY_IGNORE_MAYBE_UNINITIALIZED_END
}
/*---------------------------.
| Print this symbol on YYO. |
`---------------------------*/
static void
yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep)
{
YYFPRINTF (yyo, "%s %s (",
yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
yy_symbol_value_print (yyo, yytype, yyvaluep);
YYFPRINTF (yyo, ")");
}
/*------------------------------------------------------------------.
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
| TOP (included). |
`------------------------------------------------------------------*/
static void
yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
{
YYFPRINTF (stderr, "Stack now");
for (; yybottom <= yytop; yybottom++)
{
int yybot = *yybottom;
YYFPRINTF (stderr, " %d", yybot);
}
YYFPRINTF (stderr, "\n");
}
# define YY_STACK_PRINT(Bottom, Top) \
do { \
if (yydebug) \
yy_stack_print ((Bottom), (Top)); \
} while (0)
/*------------------------------------------------.
| Report that the YYRULE is going to be reduced. |
`------------------------------------------------*/
static void
yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, int yyrule)
{
int yylno = yyrline[yyrule];
int yynrhs = yyr2[yyrule];
int yyi;
YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
yyrule - 1, yylno);
/* The symbols being reduced. */
for (yyi = 0; yyi < yynrhs; yyi++)
{
YYFPRINTF (stderr, " $%d = ", yyi + 1);
yy_symbol_print (stderr,
yystos[+yyssp[yyi + 1 - yynrhs]],
&yyvsp[(yyi + 1) - (yynrhs)]
);
YYFPRINTF (stderr, "\n");
}
}
# define YY_REDUCE_PRINT(Rule) \
do { \
if (yydebug) \
yy_reduce_print (yyssp, yyvsp, Rule); \
} while (0)
/* Nonzero means print parse trace. It is left uninitialized so that
multiple parsers can coexist. */
int yydebug;
#else /* !YYDEBUG */
# define YYDPRINTF(Args)
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
# define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule)
#endif /* !YYDEBUG */
/* YYINITDEPTH -- initial size of the parser's stacks. */
#ifndef YYINITDEPTH
# define YYINITDEPTH 200
#endif
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
if the built-in stack extension method is used).
Do not make this value too large; the results are undefined if
YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
evaluated with infinite-precision integer arithmetic. */
#ifndef YYMAXDEPTH
# define YYMAXDEPTH 10000
#endif
#if YYERROR_VERBOSE
# ifndef yystrlen
# if defined __GLIBC__ && defined _STRING_H
# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S)))
# else
/* Return the length of YYSTR. */
static YYPTRDIFF_T
yystrlen (const char *yystr)
{
YYPTRDIFF_T yylen;
for (yylen = 0; yystr[yylen]; yylen++)
continue;
return yylen;
}
# endif
# endif
# ifndef yystpcpy
# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
# define yystpcpy stpcpy
# else
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
YYDEST. */
static char *
yystpcpy (char *yydest, const char *yysrc)
{
char *yyd = yydest;
const char *yys = yysrc;
while ((*yyd++ = *yys++) != '\0')
continue;
return yyd - 1;
}
# endif
# endif
# ifndef yytnamerr
/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
quotes and backslashes, so that it's suitable for yyerror. The
heuristic is that double-quoting is unnecessary unless the string
contains an apostrophe, a comma, or backslash (other than
backslash-backslash). YYSTR is taken from yytname. If YYRES is
null, do not copy; instead, return the length of what the result
would have been. */
static YYPTRDIFF_T
yytnamerr (char *yyres, const char *yystr)
{
if (*yystr == '"')
{
YYPTRDIFF_T yyn = 0;
char const *yyp = yystr;
for (;;)
switch (*++yyp)
{
case '\'':
case ',':
goto do_not_strip_quotes;
case '\\':
if (*++yyp != '\\')
goto do_not_strip_quotes;
else
goto append;
append:
default:
if (yyres)
yyres[yyn] = *yyp;
yyn++;
break;
case '"':
if (yyres)
yyres[yyn] = '\0';
return yyn;
}
do_not_strip_quotes: ;
}
if (yyres)
return yystpcpy (yyres, yystr) - yyres;
else
return yystrlen (yystr);
}
# endif
/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
about the unexpected token YYTOKEN for the state stack whose top is
YYSSP.
Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
not large enough to hold the message. In that case, also set
*YYMSG_ALLOC to the required number of bytes. Return 2 if the
required number of bytes is too large to store. */
static int
yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
yy_state_t *yyssp, int yytoken)
{
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
/* Internationalized format string. */
const char *yyformat = YY_NULLPTR;
/* Arguments of yyformat: reported tokens (one for the "unexpected",
one per "expected"). */
char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
/* Actual size of YYARG. */
int yycount = 0;
/* Cumulated lengths of YYARG. */
YYPTRDIFF_T yysize = 0;
/* There are many possibilities here to consider:
- If this state is a consistent state with a default action, then
the only way this function was invoked is if the default action
is an error action. In that case, don't check for expected
tokens because there are none.
- The only way there can be no lookahead present (in yychar) is if
this state is a consistent state with a default action. Thus,
detecting the absence of a lookahead is sufficient to determine
that there is no unexpected or expected token to report. In that
case, just report a simple "syntax error".
- Don't assume there isn't a lookahead just because this state is a
consistent state with a default action. There might have been a
previous inconsistent state, consistent state with a non-default
action, or user semantic action that manipulated yychar.
- Of course, the expected token list depends on states to have
correct lookahead information, and it depends on the parser not
to perform extra reductions after fetching a lookahead from the
scanner and before detecting a syntax error. Thus, state merging
(from LALR or IELR) and default reductions corrupt the expected
token list. However, the list is correct for canonical LR with
one exception: it will still contain any token that will not be
accepted due to an error action in a later state.
*/
if (yytoken != YYEMPTY)
{
int yyn = yypact[+*yyssp];
YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
yysize = yysize0;
yyarg[yycount++] = yytname[yytoken];
if (!yypact_value_is_default (yyn))
{
/* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. In other words, skip the first -YYN actions for
this state because they are default actions. */
int yyxbegin = yyn < 0 ? -yyn : 0;
/* Stay within bounds of both yycheck and yytname. */
int yychecklim = YYLAST - yyn + 1;
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
int yyx;
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
&& !yytable_value_is_error (yytable[yyx + yyn]))
{
if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
{
yycount = 1;
yysize = yysize0;
break;
}
yyarg[yycount++] = yytname[yyx];
{
YYPTRDIFF_T yysize1
= yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
yysize = yysize1;
else
return 2;
}
}
}
}
switch (yycount)
{
# define YYCASE_(N, S) \
case N: \
yyformat = S; \
break
default: /* Avoid compiler warnings. */
YYCASE_(0, YY_("syntax error"));
YYCASE_(1, YY_("syntax error, unexpected %s"));
YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
# undef YYCASE_
}
{
/* Don't count the "%s"s in the final size, but reserve room for
the terminator. */
YYPTRDIFF_T yysize1 = yysize + (yystrlen (yyformat) - 2 * yycount) + 1;
if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
yysize = yysize1;
else
return 2;
}
if (*yymsg_alloc < yysize)
{
*yymsg_alloc = 2 * yysize;
if (! (yysize <= *yymsg_alloc
&& *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
*yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
return 1;
}
/* Avoid sprintf, as that infringes on the user's name space.
Don't have undefined behavior even if the translation
produced a string with the wrong number of "%s"s. */
{
char *yyp = *yymsg;
int yyi = 0;
while ((*yyp = *yyformat) != '\0')
if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
{
yyp += yytnamerr (yyp, yyarg[yyi++]);
yyformat += 2;
}
else
{
++yyp;
++yyformat;
}
}
return 0;
}
#endif /* YYERROR_VERBOSE */
/*-----------------------------------------------.
| Release the memory associated to this symbol. |
`-----------------------------------------------*/
static void
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
{
YYUSE (yyvaluep);
if (!yymsg)
yymsg = "Deleting";
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
YYUSE (yytype);
YY_IGNORE_MAYBE_UNINITIALIZED_END
}
/* The lookahead symbol. */
int yychar;
/* The semantic value of the lookahead symbol. */
YYSTYPE yylval;
/* Number of syntax errors so far. */
int yynerrs;
/*----------.
| yyparse. |
`----------*/
int
yyparse (void)
{
yy_state_fast_t yystate;
/* Number of tokens to shift before error messages enabled. */
int yyerrstatus;
/* The stacks and their tools:
'yyss': related to states.
'yyvs': related to semantic values.
Refer to the stacks through separate pointers, to allow yyoverflow
to reallocate them elsewhere. */
/* The state stack. */
yy_state_t yyssa[YYINITDEPTH];
yy_state_t *yyss;
yy_state_t *yyssp;
/* The semantic value stack. */
YYSTYPE yyvsa[YYINITDEPTH];
YYSTYPE *yyvs;
YYSTYPE *yyvsp;
YYPTRDIFF_T yystacksize;
int yyn;
int yyresult;
/* Lookahead token as an internal (translated) token number. */
int yytoken = 0;
/* The variables used to return semantic value and location from the
action routines. */
YYSTYPE yyval;
#if YYERROR_VERBOSE
/* Buffer for error messages, and its allocated size. */
char yymsgbuf[128];
char *yymsg = yymsgbuf;
YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf;
#endif
#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
/* The number of symbols on the RHS of the reduced rule.
Keep to zero when no symbol should be popped. */
int yylen = 0;
yyssp = yyss = yyssa;
yyvsp = yyvs = yyvsa;
yystacksize = YYINITDEPTH;
YYDPRINTF ((stderr, "Starting parse\n"));
yystate = 0;
yyerrstatus = 0;
yynerrs = 0;
yychar = YYEMPTY; /* Cause a token to be read. */
goto yysetstate;
/*------------------------------------------------------------.
| yynewstate -- push a new state, which is found in yystate. |
`------------------------------------------------------------*/
yynewstate:
/* In all cases, when you get here, the value and location stacks
have just been pushed. So pushing a state here evens the stacks. */
yyssp++;
/*--------------------------------------------------------------------.
| yysetstate -- set current state (the top of the stack) to yystate. |
`--------------------------------------------------------------------*/
yysetstate:
YYDPRINTF ((stderr, "Entering state %d\n", yystate));
YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
YY_IGNORE_USELESS_CAST_BEGIN
*yyssp = YY_CAST (yy_state_t, yystate);
YY_IGNORE_USELESS_CAST_END
if (yyss + yystacksize - 1 <= yyssp)
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
goto yyexhaustedlab;
#else
{
/* Get the current used size of the three stacks, in elements. */
YYPTRDIFF_T yysize = yyssp - yyss + 1;
# if defined yyoverflow
{
/* Give user a chance to reallocate the stack. Use copies of
these so that the &'s don't force the real ones into
memory. */
yy_state_t *yyss1 = yyss;
YYSTYPE *yyvs1 = yyvs;
/* Each stack pointer address is followed by the size of the
data in use in that stack, in bytes. This used to be a
conditional around just the two extra args, but that might
be undefined if yyoverflow is a macro. */
yyoverflow (YY_("memory exhausted"),
&yyss1, yysize * YYSIZEOF (*yyssp),
&yyvs1, yysize * YYSIZEOF (*yyvsp),
&yystacksize);
yyss = yyss1;
yyvs = yyvs1;
}
# else /* defined YYSTACK_RELOCATE */
/* Extend the stack our own way. */
if (YYMAXDEPTH <= yystacksize)
goto yyexhaustedlab;
yystacksize *= 2;
if (YYMAXDEPTH < yystacksize)
yystacksize = YYMAXDEPTH;
{
yy_state_t *yyss1 = yyss;
union yyalloc *yyptr =
YY_CAST (union yyalloc *,
YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
if (! yyptr)
goto yyexhaustedlab;
YYSTACK_RELOCATE (yyss_alloc, yyss);
YYSTACK_RELOCATE (yyvs_alloc, yyvs);
# undef YYSTACK_RELOCATE
if (yyss1 != yyssa)
YYSTACK_FREE (yyss1);
}
# endif
yyssp = yyss + yysize - 1;
yyvsp = yyvs + yysize - 1;
YY_IGNORE_USELESS_CAST_BEGIN
YYDPRINTF ((stderr, "Stack size increased to %ld\n",
YY_CAST (long, yystacksize)));
YY_IGNORE_USELESS_CAST_END
if (yyss + yystacksize - 1 <= yyssp)
YYABORT;
}
#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
if (yystate == YYFINAL)
YYACCEPT;
goto yybackup;
/*-----------.
| yybackup. |
`-----------*/
yybackup:
/* Do appropriate processing given the current state. Read a
lookahead token if we need one and don't already have one. */
/* First try to decide what to do without reference to lookahead token. */
yyn = yypact[yystate];
if (yypact_value_is_default (yyn))
goto yydefault;
/* Not known => get a lookahead token if don't already have one. */
/* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
if (yychar == YYEMPTY)
{
YYDPRINTF ((stderr, "Reading a token: "));
yychar = yylex ();
}
if (yychar <= YYEOF)
{
yychar = yytoken = YYEOF;
YYDPRINTF ((stderr, "Now at end of input.\n"));
}
else
{
yytoken = YYTRANSLATE (yychar);
YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
}
/* If the proper action on seeing token YYTOKEN is to reduce or to
detect an error, take that action. */
yyn += yytoken;
if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
goto yydefault;
yyn = yytable[yyn];
if (yyn <= 0)
{
if (yytable_value_is_error (yyn))
goto yyerrlab;
yyn = -yyn;
goto yyreduce;
}
/* Count tokens shifted since error; after three, turn off error
status. */
if (yyerrstatus)
yyerrstatus--;
/* Shift the lookahead token. */
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
yystate = yyn;
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
*++yyvsp = yylval;
YY_IGNORE_MAYBE_UNINITIALIZED_END
/* Discard the shifted token. */
yychar = YYEMPTY;
goto yynewstate;
/*-----------------------------------------------------------.
| yydefault -- do the default action for the current state. |
`-----------------------------------------------------------*/
yydefault:
yyn = yydefact[yystate];
if (yyn == 0)
goto yyerrlab;
goto yyreduce;
/*-----------------------------.
| yyreduce -- do a reduction. |
`-----------------------------*/
yyreduce:
/* yyn is the number of a rule to reduce with. */
yylen = yyr2[yyn];
/* If YYLEN is nonzero, implement the default value of the action:
'$$ = $1'.
Otherwise, the following line sets YYVAL to garbage.
This behavior is undocumented and Bison
users should not rely upon it. Assigning to YYVAL
unconditionally makes the parser a bit smaller, and it avoids a
GCC warning that YYVAL may be used uninitialized. */
yyval = yyvsp[1-yylen];
YY_REDUCE_PRINT (yyn);
switch (yyn)
{
case 2:
#line 9 "b4yacc.y"
{printf("Valid Integer Declaration\n");return 0;}
#line 1374 "y.tab.c"
break;
case 3:
#line 10 "b4yacc.y"
{printf("Valid Float Declaration\n");return 0;}
#line 1380 "y.tab.c"
break;
case 4:
#line 11 "b4yacc.y"
{printf("Valid Character Declaration\n");return 0;}
#line 1386 "y.tab.c"
break;
case 5:
#line 12 "b4yacc.y"
{printf("Valid Boolean Declaration\n");return 0;}
#line 1392 "y.tab.c"
break;
case 6:
#line 13 "b4yacc.y"
{printf("Valid String Declaration\n");return 0;}
#line 1398 "y.tab.c"
break;
#line 1402 "y.tab.c"
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
that yytoken be updated with the new translation. We take the
approach of translating immediately before every use of yytoken.
One alternative is translating here after every semantic action,
but that translation would be missed if the semantic action invokes
YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
incorrect destructor might then be invoked immediately. In the
case of YYERROR or YYBACKUP, subsequent parser actions might lead
to an incorrect destructor call or verbose syntax error message
before the lookahead is translated. */
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
YYPOPSTACK (yylen);
yylen = 0;
YY_STACK_PRINT (yyss, yyssp);
*++yyvsp = yyval;
/* Now 'shift' the result of the reduction. Determine what state
that goes to, based on the state we popped back to and the rule
number reduced by. */
{
const int yylhs = yyr1[yyn] - YYNTOKENS;
const int yyi = yypgoto[yylhs] + *yyssp;
yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
? yytable[yyi]
: yydefgoto[yylhs]);
}
goto yynewstate;
/*--------------------------------------.
| yyerrlab -- here on detecting error. |
`--------------------------------------*/
yyerrlab:
/* Make sure we have latest lookahead translation. See comments at
user semantic actions for why this is necessary. */
yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
/* If not already recovering from an error, report this error. */
if (!yyerrstatus)
{
++yynerrs;
#if ! YYERROR_VERBOSE
yyerror (YY_("syntax error"));
#else
# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
yyssp, yytoken)
{
char const *yymsgp = YY_("syntax error");
int yysyntax_error_status;
yysyntax_error_status = YYSYNTAX_ERROR;
if (yysyntax_error_status == 0)
yymsgp = yymsg;
else if (yysyntax_error_status == 1)
{
if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);
yymsg = YY_CAST (char *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc)));
if (!yymsg)
{
yymsg = yymsgbuf;
yymsg_alloc = sizeof yymsgbuf;
yysyntax_error_status = 2;
}
else
{
yysyntax_error_status = YYSYNTAX_ERROR;
yymsgp = yymsg;
}
}
yyerror (yymsgp);
if (yysyntax_error_status == 2)
goto yyexhaustedlab;
}
# undef YYSYNTAX_ERROR
#endif
}
if (yyerrstatus == 3)
{
/* If just tried and failed to reuse lookahead token after an
error, discard it. */
if (yychar <= YYEOF)
{
/* Return failure if at end of input. */
if (yychar == YYEOF)
YYABORT;
}
else
{
yydestruct ("Error: discarding",
yytoken, &yylval);
yychar = YYEMPTY;
}
}
/* Else will try to reuse lookahead token after shifting the error
token. */
goto yyerrlab1;
/*---------------------------------------------------.
| yyerrorlab -- error raised explicitly by YYERROR. |
`---------------------------------------------------*/
yyerrorlab:
/* Pacify compilers when the user code never invokes YYERROR and the
label yyerrorlab therefore never appears in user code. */
if (0)
YYERROR;
/* Do not reclaim the symbols of the rule whose action triggered
this YYERROR. */
YYPOPSTACK (yylen);
yylen = 0;
YY_STACK_PRINT (yyss, yyssp);
yystate = *yyssp;
goto yyerrlab1;
/*-------------------------------------------------------------.
| yyerrlab1 -- common code for both syntax error and YYERROR. |
`-------------------------------------------------------------*/
yyerrlab1:
yyerrstatus = 3; /* Each real token shifted decrements this. */
for (;;)
{
yyn = yypact[yystate];
if (!yypact_value_is_default (yyn))
{
yyn += YYTERROR;
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
{
yyn = yytable[yyn];
if (0 < yyn)
break;
}
}
/* Pop the current state because it cannot handle the error token. */
if (yyssp == yyss)
YYABORT;
yydestruct ("Error: popping",
yystos[yystate], yyvsp);
YYPOPSTACK (1);
yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp);
}
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
*++yyvsp = yylval;
YY_IGNORE_MAYBE_UNINITIALIZED_END
/* Shift the error token. */
YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
yystate = yyn;
goto yynewstate;
/*-------------------------------------.
| yyacceptlab -- YYACCEPT comes here. |
`-------------------------------------*/
yyacceptlab:
yyresult = 0;
goto yyreturn;
/*-----------------------------------.
| yyabortlab -- YYABORT comes here. |
`-----------------------------------*/
yyabortlab:
yyresult = 1;
goto yyreturn;
#if !defined yyoverflow || YYERROR_VERBOSE
/*-------------------------------------------------.
| yyexhaustedlab -- memory exhaustion comes here. |
`-------------------------------------------------*/
yyexhaustedlab:
yyerror (YY_("memory exhausted"));
yyresult = 2;
/* Fall through. */
#endif
/*-----------------------------------------------------.
| yyreturn -- parsing is finished, return the result. |
`-----------------------------------------------------*/
yyreturn:
if (yychar != YYEMPTY)
{
/* Make sure we have latest lookahead translation. See comments at
user semantic actions for why this is necessary. */
yytoken = YYTRANSLATE (yychar);
yydestruct ("Cleanup: discarding lookahead",
yytoken, &yylval);
}
/* Do not reclaim the symbols of the rule whose action triggered
this YYABORT or YYACCEPT. */
YYPOPSTACK (yylen);
YY_STACK_PRINT (yyss, yyssp);
while (yyssp != yyss)
{
yydestruct ("Cleanup: popping",
yystos[+*yyssp], yyvsp);
YYPOPSTACK (1);
}
#ifndef yyoverflow
if (yyss != yyssa)
YYSTACK_FREE (yyss);
#endif
#if YYERROR_VERBOSE
if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);
#endif
return yyresult;
}
#line 36 "b4yacc.y"
int main()
{
yyin=fopen("test.txt","r");
yyparse();
return 0;
}
void yyerror(char *s){
fprintf(stderr, "Error!!: %s\n",s);
}
|
the_stack_data/200144182.c
|
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
static struct {
const char *argv0;
bool all : 1;
} opt;
static int list(const char *path, int label)
{
static int notfirst;
struct stat statbuf;
struct dirent *ent;
DIR *dh;
if (stat(path, &statbuf)) {
fprintf(stderr, "%s: unable to stat %s: %s\n",
opt.argv0, path, strerror(errno));
return 1;
}
if (!S_ISDIR(statbuf.st_mode)) {
printf("%s\n", path);
return 0;
}
if (label) {
if (notfirst)
putchar('\n');
notfirst = 1;
printf("%s:\n", path);
}
dh = opendir(path);
if (!dh) {
fprintf(stderr, "%s: %s: %s\n",
opt.argv0, path, strerror(errno));
return 1;
}
while ((ent = readdir(dh))) {
if (ent->d_name[0] == '.' && !opt.all)
continue;
printf("%s\n", ent->d_name);
}
if (closedir(dh)) {
fprintf(stderr, "%s: %s: %s\n",
opt.argv0, path, strerror(errno));
return 1;
}
return 0;
}
/* Usage: ls [-a] [PATH...] */
int main(int argc, const char *argv[])
{
int i;
opt.argv0 = argv[0];
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-') {
break;
} else if (!strcmp(argv[i], "-a")) {
opt.all = 1;
} else {
fprintf(stderr, "%s: invalid argument: %s\n",
argv[0], argv[i]);
return 1;
}
}
if (i == argc) {
if (list(".", 0))
return 1;
} else if (i == argc - 1) {
if (list(argv[i], 0))
return 1;
} else for (; i < argc; i++) {
if (list(argv[i], 1))
return 1;
}
return 0;
}
|
the_stack_data/432908.c
|
#include <stdio.h>
#define NMAX 10
int binsearch(int x, int v[], int n);
int main()
{
int x, n;
int v[NMAX];
for (x = 0; x < NMAX; x++)
v[x] = x*x;
x = 9;
n = binsearch(x, v, NMAX);
printf("%d\n", n);
}
int binsearch(int x, int v[], int n)
{
int low = 0;
int high = n-1;
int mid;
while (v[mid = (low + high)/2] != x && low <= high) {
printf("%6d,%6d,%6d\n", low, mid, high);
if (x < v[mid])
high = mid - 1;
else
low = mid + 1;
}
return v[mid] == x ? mid : -1;
return -1;
}
|
the_stack_data/87637081.c
|
#include <stdio.h>
int main ( int argc, char* argv[] ) {
int i;
for ( i =0; i < argc; i++ ) {
printf( " %s \n ", *(argv+i) ); //argv is a pointer
}
return 0;
}
|
the_stack_data/170451943.c
|
#include <stdio.h>
main(){
int m,c;
for (c = 0; c<=100; c+=1 ){
m = c*7;
if (7%c == 0){
printf("%d ",m);
}
}
}
|
the_stack_data/59511915.c
|
#include <stdio.h>
main(){
char nome[20],tipo[3];
int mes;
float peso;
for(int i = 1; i <=5; i++){
printf("Escreva o nome do %do doador: ",i);
scanf("%s",&nome);
printf("Qual o tipo sanguineo do doador? ");
scanf("%s",&tipo);
printf("O peso do doador: ");
scanf("%f",&peso);
printf("Quantos meses desde a ultima doacao? ");
scanf("%d",&mes);
printf("-----------------------------\n");
if(peso >= 50 && mes>=6){
printf("o doador %s pode doar e tem eh do tipo %s\n",nome,tipo);
printf("-----------------------------\n");
}else{
printf("o doador %s nao pode doar\n",nome);
printf("-----------------------------\n");
}
}
}
|
the_stack_data/206394170.c
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#define THURSDAY 4 /* for reformation */
#define SATURDAY 6 /* 1 Jan 1 was a Saturday */
#define FIRST_MISSING_DAY 639787 /* 3 Sep 1752 */
#define NUMBER_MISSING_DAYS 11 /* 11 day correction */
#define MAXDAYS 42 /* max slots in a month array */
#define SPACE -1 /* used in day array */
static int days_in_month[2][13] = {
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
};
int sep1752[MAXDAYS] = {
SPACE,
SPACE,
1,
2,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
},
j_sep1752[MAXDAYS] = {
SPACE,
SPACE,
245,
246,
258,
259,
260,
261,
262,
263,
264,
265,
266,
267,
268,
269,
270,
271,
272,
273,
274,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
},
empty[MAXDAYS] = {
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
SPACE,
};
char *month_names[12] = {
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
};
char *day_headings = " S M Tu W Th F S";
char *j_day_headings = " S M Tu W Th F S";
/* leap year -- account for gregorian reformation in 1752 */
#define leap_year(yr) \
((yr) <= 1752 ? !((yr) % 4) : !((yr) % 4) && ((yr) % 100) || !((yr) % 400))
/* number of centuries since 1700, not inclusive */
#define centuries_since_1700(yr) \
((yr) > 1700 ? (yr) / 100 - 17 : 0)
/* number of centuries since 1700 whose modulo of 400 is 0 */
#define quad_centuries_since_1700(yr) \
((yr) > 1600 ? ((yr)-1600) / 400 : 0)
/* number of leap years between year 1 and this year, not inclusive */
#define leap_years_since_year_1(yr) \
((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))
int julian;
#define DAY_LEN 3 /* 3 spaces per day */
#define J_DAY_LEN 4 /* 4 spaces per day */
#define WEEK_LEN 20 /* 7 * 3 - one space at the end */
#define J_WEEK_LEN 27 /* 7 * 4 - one space at the end */
#define HEAD_SEP 2 /* spaces between day headings */
#define J_HEAD_SEP 2
void ascii_day(register char *p, register int day)
{
register int display, val;
static char *aday[] = {
"",
" 1",
" 2",
" 3",
" 4",
" 5",
" 6",
" 7",
" 8",
" 9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
};
if (day == SPACE)
{
memset(p, ' ', julian ? J_DAY_LEN : DAY_LEN);
return;
}
if (julian)
{
if (val = (day / 100))
{
day %= 100;
*p++ = val + '0';
display = 1;
}
else
{
*p++ = ' ';
display = 0;
}
val = day / 10;
if (val || display)
*p++ = val + '0';
else
*p++ = ' ';
*p++ = day % 10 + '0';
}
else
{
*p++ = aday[day][0];
*p++ = aday[day][1];
}
*p = ' ';
}
void trim_trailing_spaces(register char *s)
{
register char *p;
for (p = s; *p; ++p)
;
while (p > s && isspace(*--p))
;
if (p > s)
p++;
*p = '\0';
}
void center(char *str, register int len, int separate)
{
len -= strlen(str);
(void)printf("%*s%s%*s", len / 2, "", str, len / 2 + len % 2, "");
if (separate)
(void)printf("%*s", separate, "");
}
/*
* day_in_year --
* return the 1 based day number within the year
*/
int day_in_year(register int day, register int month, int year)
{
register int i, leap;
leap = leap_year(year);
for (i = 1; i < month; i++)
{
day += days_in_month[leap][i];
}
return (day);
}
/*
* day_in_week
* return the 0 based day number for any date from 1 Jan. 1 to
* 31 Dec. 9999. Assumes the Gregorian reformation eliminates
* 3 Sep. 1752 through 13 Sep. 1752. Returns Thursday for all
* missing days.
*/
int day_in_week(int day, int month, int year)
{
long temp;
temp = (long)(year - 1) * 365 + leap_years_since_year_1(year - 1) + day_in_year(day, month, year);
if (temp < FIRST_MISSING_DAY)
{
return ((temp - 1 + SATURDAY) % 7);
}
if (temp >= (FIRST_MISSING_DAY + NUMBER_MISSING_DAYS))
{
return (((temp - 1 + SATURDAY) - NUMBER_MISSING_DAYS) % 7);
}
return (THURSDAY);
}
/*
* day_array --
* Fill in an array of 42 integers with a calendar. Assume for a moment
* that you took the (maximum) 6 rows in a calendar and stretched them
* out end to end. You would have 42 numbers or spaces. This routine
* builds that array for any month from Jan. 1 through Dec. 9999.
*/
void day_array(int month, int year, register int *days)
{
register int i, day, dw, dm;
if (month == 9 && year == 1752)
{
bcopy(julian ? j_sep1752 : sep1752, days, MAXDAYS * sizeof(int));
return;
}
bcopy(empty, days, MAXDAYS * sizeof(int));
dm = days_in_month[leap_year(year)][month];
dw = day_in_week(1, month, year);
day = julian ? day_in_year(1, month, year) : 1;
while (dm--)
days[dw++] = day++;
}
void monthly(int month, int year)
{
register int col, row;
register char *p;
int len, days[MAXDAYS];
char lineout[30];
day_array(month, year, days);
len = sprintf(lineout, "%s %d", month_names[month - 1], year);
(void)printf("%*s%s\n%s\n",
((julian ? J_WEEK_LEN : WEEK_LEN) - len) / 2, "",
lineout, julian ? j_day_headings : day_headings);
for (row = 0; row < 6; row++)
{
for (col = 0, p = lineout; col < 7; col++,
p += julian ? J_DAY_LEN : DAY_LEN)
ascii_day(p, days[row * 7 + col]);
*p = 0;
trim_trailing_spaces(lineout);
(void)printf("%s\n", lineout);
}
}
void j_yearly(int year)
{
register int col, *dp, i, month, row, which_cal;
register char *p;
int days[12][MAXDAYS];
char lineout[80];
(void)sprintf(lineout, "%d", year);
center(lineout, J_WEEK_LEN * 2 + J_HEAD_SEP, 0);
(void)printf("\n\n");
for (i = 0; i < 12; i++)
day_array(i + 1, year, days[i]);
(void)memset(lineout, ' ', sizeof(lineout) - 1);
lineout[sizeof(lineout) - 1] = '\0';
for (month = 0; month < 12; month += 2)
{
center(month_names[month], J_WEEK_LEN, J_HEAD_SEP);
center(month_names[month + 1], J_WEEK_LEN, 0);
(void)printf("\n%s%*s%s\n", j_day_headings, J_HEAD_SEP, "",
j_day_headings);
for (row = 0; row < 6; row++)
{
for (which_cal = 0; which_cal < 2; which_cal++)
{
p = lineout + which_cal * (J_WEEK_LEN + 2);
dp = &days[month + which_cal][row * 7];
for (col = 0; col < 7; col++, p += J_DAY_LEN)
ascii_day(p, *dp++);
}
trim_trailing_spaces(lineout);
(void)printf("%s\n", lineout);
}
}
(void)printf("\n");
}
void yearly(int year)
{
register int col, *dp, i, month, row, which_cal;
register char *p;
int days[12][MAXDAYS];
char lineout[80];
(void)sprintf(lineout, "%d", year);
center(lineout, WEEK_LEN * 3 + HEAD_SEP * 2, 0);
(void)printf("\n\n");
for (i = 0; i < 12; i++)
day_array(i + 1, year, days[i]);
(void)memset(lineout, ' ', sizeof(lineout) - 1);
lineout[sizeof(lineout) - 1] = '\0';
for (month = 0; month < 12; month += 3)
{
center(month_names[month], WEEK_LEN, HEAD_SEP);
center(month_names[month + 1], WEEK_LEN, HEAD_SEP);
center(month_names[month + 2], WEEK_LEN, 0);
(void)printf("\n%s%*s%s%*s%s\n", day_headings, HEAD_SEP,
"", day_headings, HEAD_SEP, "", day_headings);
for (row = 0; row < 6; row++)
{
for (which_cal = 0; which_cal < 3; which_cal++)
{
p = lineout + which_cal * (WEEK_LEN + 2);
dp = &days[month + which_cal][row * 7];
for (col = 0; col < 7; col++, p += DAY_LEN)
ascii_day(p, *dp++);
}
trim_trailing_spaces(lineout);
(void)printf("%s\n", lineout);
}
}
(void)printf("\n");
}
void usage()
{
(void)fprintf(stderr, "usage: cal [-jy] [[month] year]\n");
exit(1);
}
int main(int argc, char **argv)
{
printf("argc = %d\n", argc);
struct tm *local_time;
time_t now, time();
int ch, month, year, yflag;
yflag = 0;
int execLen = strlen(argv[0]);
printf("exec = %s\texeclen = %d\n", argv[0], execLen);
int argStart = execLen+2; //remove space and -
int arCounter = argc-1;
int nonOptCnt = 0;
char **startArgv = argv+argc;
for (int i = 1; i < argc; i++)
{
if (argv[i][0] != '-')
{
printf("\n\nargv[%d][0] = %c\n", i, argv[i][0]);
puts("not a option");
nonOptCnt++;
startArgv--;
continue;
}
int len = strlen(argv[i]);
printf("\n\nargv[%d] = %s\tlen = %d\n", i, argv[i], len);
char temp[len];
strcpy(temp, *argv+(argStart));
printf("temp = %s\n", temp);
int lentemp = strlen(temp);
printf("lentemp = %d\n", lentemp);
for (int i = 0; i < lentemp; i++)
{
char tempchar;
tempchar = temp[i];
printf("ch = %c\n", tempchar);
switch (tempchar)
{
case 'j':
julian = 1;
break;
case 'y':
yflag = 1;
break;
case '?':
default:
usage();
}
}
argStart += lentemp+2;
arCounter--;
}
printf("*argv = %s\targc = %d\t*startArgv = %s\tnonOptCnt = %d\n\n", *argv, argc, *startArgv, nonOptCnt);
month = 0;
switch (nonOptCnt) //nonOptCnt
{
case 2:
printf("*startArgv = %s\n", *startArgv);
if ((month = atoi(*startArgv++)) <= 0 || month > 12)
{
(void)fprintf(stderr,
"cal: illegal month value: use 0-12\n");
exit(1);
}
/* FALLTHROUGH */
case 1:
if ((year = atoi(*startArgv)) <= 0 || year > 9999)
{
(void)fprintf(stderr,
"cal: illegal year value: use 0-9999\n");
exit(1);
}
break;
case 0:
(void)time(&now);
local_time = localtime(&now);
year = local_time->tm_year + 1900;
if (!yflag)
month = local_time->tm_mon + 1;
break;
default:
usage();
}
if (month) monthly(month, year);
else if (julian) j_yearly(year);
else yearly(year);
exit(0);
}
|
the_stack_data/167331221.c
|
// RUN: %clang_cc1 -triple x86_64-pc-linux -emit-llvm < %s | FileCheck %s
// Check that the type of this global isn't i1
// CHECK: @test ={{.*}} global i8 1
_Bool test = &test;
|
the_stack_data/220456517.c
|
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)strtol.c 5.4 (Berkeley) 2/23/91";*/
static char *rcsid = "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <pthread.h>
#include <limits.h>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
/*
* Convert a string to a long integer.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
long
strtol(nptr, endptr, base)
const char *nptr;
char **endptr;
register int base;
{
register const char *s = nptr;
register unsigned long acc;
register int c;
register unsigned long cutoff;
register int neg = 0, any, cutlim;
/*
* Skip white space and pick up leading +/- sign if any.
* If base is 0, allow 0x for hex and 0 for octal, else
* assume decimal; if base is already 16, allow 0x.
*/
do {
c = *s++;
} while (isspace(c));
if (c == '-') {
neg = 1;
c = *s++;
} else if (c == '+')
c = *s++;
if ((base == 0 || base == 16) &&
c == '0' && (*s == 'x' || *s == 'X')) {
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == '0' ? 8 : 10;
/*
* Compute the cutoff value between legal numbers and illegal
* numbers. That is the largest legal value, divided by the
* base. An input number that is greater than this value, if
* followed by a legal input character, is too big. One that
* is equal to this value may be valid or not; the limit
* between valid and invalid numbers is then based on the last
* digit. For instance, if the range for longs is
* [-2147483648..2147483647] and the input base is 10,
* cutoff will be set to 214748364 and cutlim to either
* 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
* a value > 214748364, or equal but the next digit is > 7 (or 8),
* the number is too big, and we will return a range error.
*
* Set any if any `digits' consumed; make it negative to indicate
* overflow.
*/
cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
cutlim = cutoff % (unsigned long)base;
cutoff /= (unsigned long)base;
for (acc = 0, any = 0;; c = *s++) {
if (isdigit(c))
c -= '0';
else if (isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
any = -1;
else {
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0) {
acc = neg ? LONG_MIN : LONG_MAX;
errno = ERANGE;
} else if (neg)
acc = -acc;
if (endptr != 0)
*endptr = (char *) (any ? s - 1 : nptr);
return (acc);
}
|
the_stack_data/417256.c
|
/* $NetBSD: h_hash.c,v 1.1 2011/01/02 22:03:25 pgoyette Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
/*
* Combined MD5/SHA1 time and regression test.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <md5.h>
#include <sha1.h>
int mflag, rflag, sflag, tflag;
static void
usage(void)
{
(void)fprintf(stderr,
"Usage:\t%s -r[ms] < test-file\n"
"\t%s -t[ms]\n",
getprogname(), getprogname());
exit(1);
/* NOTREACHED */
}
static void
hexdump (unsigned char *buf, int len)
{
int i;
for (i=0; i<len; i++) {
printf("%02x", buf[i]);
}
printf("\n");
}
static void
timetest(void)
{
printf("sorry, not yet\n");
}
#define CHOMP(buf, len, last) \
if ((len > 0) && \
(buf[len-1] == '\n')) { \
buf[len-1] = '\0'; \
len--; \
last = 1; \
}
static void
regress(void)
{
unsigned char buf[1024];
unsigned char out[20];
int len, outlen, last;
while (fgets((char *)buf, sizeof(buf), stdin) != NULL) {
last = 0;
len = strlen((char *)buf);
CHOMP(buf, len, last);
if (mflag) {
MD5_CTX ctx;
MD5Init(&ctx);
MD5Update(&ctx, buf, len);
while (!last &&
fgets((char *)buf, sizeof(buf), stdin) != NULL) {
len = strlen((char *)buf);
CHOMP(buf, len, last);
MD5Update(&ctx, buf, len);
}
MD5Final(out, &ctx);
outlen = 16;
} else {
SHA1_CTX ctx;
SHA1Init(&ctx);
SHA1Update(&ctx, buf, len);
while (!last &&
fgets((char *)buf, sizeof(buf), stdin) != NULL) {
len = strlen((char *)buf);
CHOMP(buf, len, last);
SHA1Update(&ctx, buf, len);
}
SHA1Final(out, &ctx);
outlen = 20;
}
hexdump(out, outlen);
}
}
int
main(int argc, char **argv)
{
int ch;
while ((ch = getopt(argc, argv, "mrst")) != -1)
switch (ch) {
case 'm':
mflag = 1;
break;
case 'r':
rflag = 1;
break;
case 's':
sflag = 1;
break;
case 't':
tflag = 1;
break;
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
if (argc > 0)
usage();
if (!(mflag || sflag))
mflag = 1;
if ((mflag ^ sflag) != 1)
usage();
if ((tflag ^ rflag) != 1)
usage();
if (tflag)
timetest();
if (rflag)
regress();
exit(0);
}
|
the_stack_data/116983.c
|
/* Autogenerated: 'src/ExtractionOCaml/bedrock2_word_by_word_montgomery' --lang bedrock2 --static --no-wide-int --widen-carry --widen-bytes --split-multiret --no-select --no-field-element-typedefs p224 64 '2^224 - 2^96 + 1' mul square add sub opp from_montgomery to_montgomery nonzero selectznz to_bytes from_bytes one msat divstep divstep_precomp */
/* curve description: p224 */
/* machine_wordsize = 64 (from "64") */
/* requested operations: mul, square, add, sub, opp, from_montgomery, to_montgomery, nonzero, selectznz, to_bytes, from_bytes, one, msat, divstep, divstep_precomp */
/* m = 0xffffffffffffffffffffffffffffffff000000000000000000000001 (from "2^224 - 2^96 + 1") */
/* */
/* NOTE: In addition to the bounds specified above each function, all */
/* functions synthesized for this Montgomery arithmetic require the */
/* input to be strictly less than the prime modulus (m), and also */
/* require the input to be in the unique saturated representation. */
/* All functions also ensure that these two properties are true of */
/* return values. */
/* */
/* Computed values: */
/* eval z = z[0] + (z[1] << 64) + (z[2] << 128) + (z[3] << 192) */
/* bytes_eval z = z[0] + (z[1] << 8) + (z[2] << 16) + (z[3] << 24) + (z[4] << 32) + (z[5] << 40) + (z[6] << 48) + (z[7] << 56) + (z[8] << 64) + (z[9] << 72) + (z[10] << 80) + (z[11] << 88) + (z[12] << 96) + (z[13] << 104) + (z[14] << 112) + (z[15] << 120) + (z[16] << 128) + (z[17] << 136) + (z[18] << 144) + (z[19] << 152) + (z[20] << 160) + (z[21] << 168) + (z[22] << 176) + (z[23] << 184) + (z[24] << 192) + (z[25] << 200) + (z[26] << 208) + (z[27] << 216) */
/* twos_complement_eval z = let x1 := z[0] + (z[1] << 64) + (z[2] << 128) + (z[3] << 192) in */
/* if x1 & (2^256-1) < 2^255 then x1 & (2^256-1) else (x1 & (2^256-1)) - 2^256 */
#include <stdint.h>
#include <memory.h>
// LITTLE-ENDIAN memory access is REQUIRED
// the following two functions are required to work around -fstrict-aliasing
static inline uintptr_t _br2_load(uintptr_t a, size_t sz) {
uintptr_t r = 0;
memcpy(&r, (void*)a, sz);
return r;
}
static inline void _br2_store(uintptr_t a, uintptr_t v, size_t sz) {
memcpy((void*)a, &v, sz);
}
/*
* Input Bounds:
* in0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* in1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static
void internal_fiat_p224_mul(uintptr_t out0, uintptr_t in0, uintptr_t in1) {
uintptr_t x1, x2, x3, x0, x11, x16, x19, x21, x17, x22, x14, x23, x25, x26, x15, x27, x12, x28, x30, x31, x13, x36, x39, x41, x37, x42, x34, x43, x45, x46, x35, x33, x48, x18, x49, x20, x50, x38, x51, x53, x54, x24, x55, x40, x56, x58, x59, x29, x60, x44, x61, x63, x64, x32, x65, x47, x66, x68, x8, x74, x77, x79, x75, x80, x72, x81, x83, x84, x73, x85, x70, x86, x88, x89, x71, x76, x52, x92, x57, x93, x78, x94, x96, x97, x62, x98, x82, x99, x101, x102, x67, x103, x87, x104, x106, x107, x69, x108, x90, x109, x111, x116, x119, x121, x117, x122, x114, x123, x125, x126, x115, x113, x128, x91, x129, x95, x130, x118, x131, x133, x134, x100, x135, x120, x136, x138, x139, x105, x140, x124, x141, x143, x144, x110, x145, x127, x146, x148, x149, x112, x9, x155, x158, x160, x156, x161, x153, x162, x164, x165, x154, x166, x151, x167, x169, x170, x152, x157, x132, x173, x137, x174, x159, x175, x177, x178, x142, x179, x163, x180, x182, x183, x147, x184, x168, x185, x187, x188, x150, x189, x171, x190, x192, x197, x200, x202, x198, x203, x195, x204, x206, x207, x196, x194, x209, x172, x210, x176, x211, x199, x212, x214, x215, x181, x216, x201, x217, x219, x220, x186, x221, x205, x222, x224, x225, x191, x226, x208, x227, x229, x230, x193, x7, x6, x5, x10, x4, x236, x239, x241, x237, x242, x234, x243, x245, x246, x235, x247, x232, x248, x250, x251, x233, x238, x213, x254, x218, x255, x240, x256, x258, x259, x223, x260, x244, x261, x263, x264, x228, x265, x249, x266, x268, x269, x231, x270, x252, x271, x273, x278, x281, x283, x279, x284, x276, x285, x287, x288, x277, x275, x290, x253, x291, x257, x292, x280, x293, x295, x296, x262, x297, x282, x298, x300, x301, x267, x302, x286, x303, x305, x306, x272, x307, x289, x308, x310, x311, x274, x314, x315, x316, x318, x319, x320, x321, x323, x324, x325, x326, x328, x329, x312, x330, x294, x332, x313, x333, x299, x335, x317, x336, x304, x338, x322, x339, x331, x309, x341, x327, x342, x334, x337, x340, x343, x344, x345, x346, x347;
x0 = _br2_load((in0)+((uintptr_t)0ULL), sizeof(uintptr_t));
x1 = _br2_load((in0)+((uintptr_t)8ULL), sizeof(uintptr_t));
x2 = _br2_load((in0)+((uintptr_t)16ULL), sizeof(uintptr_t));
x3 = _br2_load((in0)+((uintptr_t)24ULL), sizeof(uintptr_t));
/*skip*/
x4 = _br2_load((in1)+((uintptr_t)0ULL), sizeof(uintptr_t));
x5 = _br2_load((in1)+((uintptr_t)8ULL), sizeof(uintptr_t));
x6 = _br2_load((in1)+((uintptr_t)16ULL), sizeof(uintptr_t));
x7 = _br2_load((in1)+((uintptr_t)24ULL), sizeof(uintptr_t));
/*skip*/
/*skip*/
x8 = x1;
x9 = x2;
x10 = x3;
x11 = x0;
x12 = (x11)*(x7);
x13 = sizeof(intptr_t) == 4 ? ((uint64_t)(x11)*(x7))>>32 : ((__uint128_t)(x11)*(x7))>>64;
x14 = (x11)*(x6);
x15 = sizeof(intptr_t) == 4 ? ((uint64_t)(x11)*(x6))>>32 : ((__uint128_t)(x11)*(x6))>>64;
x16 = (x11)*(x5);
x17 = sizeof(intptr_t) == 4 ? ((uint64_t)(x11)*(x5))>>32 : ((__uint128_t)(x11)*(x5))>>64;
x18 = (x11)*(x4);
x19 = sizeof(intptr_t) == 4 ? ((uint64_t)(x11)*(x4))>>32 : ((__uint128_t)(x11)*(x4))>>64;
x20 = (x19)+(x16);
x21 = (x20)<(x19);
x22 = (x21)+(x17);
x23 = (x22)<(x17);
x24 = (x22)+(x14);
x25 = (x24)<(x14);
x26 = (x23)+(x25);
x27 = (x26)+(x15);
x28 = (x27)<(x15);
x29 = (x27)+(x12);
x30 = (x29)<(x12);
x31 = (x28)+(x30);
x32 = (x31)+(x13);
x33 = (x18)*((uintptr_t)18446744073709551615ULL);
x34 = (x33)*((uintptr_t)4294967295ULL);
x35 = sizeof(intptr_t) == 4 ? ((uint64_t)(x33)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x33)*((uintptr_t)4294967295ULL))>>64;
x36 = (x33)*((uintptr_t)18446744073709551615ULL);
x37 = sizeof(intptr_t) == 4 ? ((uint64_t)(x33)*((uintptr_t)18446744073709551615ULL))>>32 : ((__uint128_t)(x33)*((uintptr_t)18446744073709551615ULL))>>64;
x38 = (x33)*((uintptr_t)18446744069414584320ULL);
x39 = sizeof(intptr_t) == 4 ? ((uint64_t)(x33)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x33)*((uintptr_t)18446744069414584320ULL))>>64;
x40 = (x39)+(x36);
x41 = (x40)<(x39);
x42 = (x41)+(x37);
x43 = (x42)<(x37);
x44 = (x42)+(x34);
x45 = (x44)<(x34);
x46 = (x43)+(x45);
x47 = (x46)+(x35);
x48 = (x18)+(x33);
x49 = (x48)<(x18);
x50 = (x49)+(x20);
x51 = (x50)<(x20);
x52 = (x50)+(x38);
x53 = (x52)<(x38);
x54 = (x51)+(x53);
x55 = (x54)+(x24);
x56 = (x55)<(x24);
x57 = (x55)+(x40);
x58 = (x57)<(x40);
x59 = (x56)+(x58);
x60 = (x59)+(x29);
x61 = (x60)<(x29);
x62 = (x60)+(x44);
x63 = (x62)<(x44);
x64 = (x61)+(x63);
x65 = (x64)+(x32);
x66 = (x65)<(x32);
x67 = (x65)+(x47);
x68 = (x67)<(x47);
x69 = (x66)+(x68);
x70 = (x8)*(x7);
x71 = sizeof(intptr_t) == 4 ? ((uint64_t)(x8)*(x7))>>32 : ((__uint128_t)(x8)*(x7))>>64;
x72 = (x8)*(x6);
x73 = sizeof(intptr_t) == 4 ? ((uint64_t)(x8)*(x6))>>32 : ((__uint128_t)(x8)*(x6))>>64;
x74 = (x8)*(x5);
x75 = sizeof(intptr_t) == 4 ? ((uint64_t)(x8)*(x5))>>32 : ((__uint128_t)(x8)*(x5))>>64;
x76 = (x8)*(x4);
x77 = sizeof(intptr_t) == 4 ? ((uint64_t)(x8)*(x4))>>32 : ((__uint128_t)(x8)*(x4))>>64;
x78 = (x77)+(x74);
x79 = (x78)<(x77);
x80 = (x79)+(x75);
x81 = (x80)<(x75);
x82 = (x80)+(x72);
x83 = (x82)<(x72);
x84 = (x81)+(x83);
x85 = (x84)+(x73);
x86 = (x85)<(x73);
x87 = (x85)+(x70);
x88 = (x87)<(x70);
x89 = (x86)+(x88);
x90 = (x89)+(x71);
x91 = (x52)+(x76);
x92 = (x91)<(x52);
x93 = (x92)+(x57);
x94 = (x93)<(x57);
x95 = (x93)+(x78);
x96 = (x95)<(x78);
x97 = (x94)+(x96);
x98 = (x97)+(x62);
x99 = (x98)<(x62);
x100 = (x98)+(x82);
x101 = (x100)<(x82);
x102 = (x99)+(x101);
x103 = (x102)+(x67);
x104 = (x103)<(x67);
x105 = (x103)+(x87);
x106 = (x105)<(x87);
x107 = (x104)+(x106);
x108 = (x107)+(x69);
x109 = (x108)<(x69);
x110 = (x108)+(x90);
x111 = (x110)<(x90);
x112 = (x109)+(x111);
x113 = (x91)*((uintptr_t)18446744073709551615ULL);
x114 = (x113)*((uintptr_t)4294967295ULL);
x115 = sizeof(intptr_t) == 4 ? ((uint64_t)(x113)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x113)*((uintptr_t)4294967295ULL))>>64;
x116 = (x113)*((uintptr_t)18446744073709551615ULL);
x117 = sizeof(intptr_t) == 4 ? ((uint64_t)(x113)*((uintptr_t)18446744073709551615ULL))>>32 : ((__uint128_t)(x113)*((uintptr_t)18446744073709551615ULL))>>64;
x118 = (x113)*((uintptr_t)18446744069414584320ULL);
x119 = sizeof(intptr_t) == 4 ? ((uint64_t)(x113)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x113)*((uintptr_t)18446744069414584320ULL))>>64;
x120 = (x119)+(x116);
x121 = (x120)<(x119);
x122 = (x121)+(x117);
x123 = (x122)<(x117);
x124 = (x122)+(x114);
x125 = (x124)<(x114);
x126 = (x123)+(x125);
x127 = (x126)+(x115);
x128 = (x91)+(x113);
x129 = (x128)<(x91);
x130 = (x129)+(x95);
x131 = (x130)<(x95);
x132 = (x130)+(x118);
x133 = (x132)<(x118);
x134 = (x131)+(x133);
x135 = (x134)+(x100);
x136 = (x135)<(x100);
x137 = (x135)+(x120);
x138 = (x137)<(x120);
x139 = (x136)+(x138);
x140 = (x139)+(x105);
x141 = (x140)<(x105);
x142 = (x140)+(x124);
x143 = (x142)<(x124);
x144 = (x141)+(x143);
x145 = (x144)+(x110);
x146 = (x145)<(x110);
x147 = (x145)+(x127);
x148 = (x147)<(x127);
x149 = (x146)+(x148);
x150 = (x149)+(x112);
x151 = (x9)*(x7);
x152 = sizeof(intptr_t) == 4 ? ((uint64_t)(x9)*(x7))>>32 : ((__uint128_t)(x9)*(x7))>>64;
x153 = (x9)*(x6);
x154 = sizeof(intptr_t) == 4 ? ((uint64_t)(x9)*(x6))>>32 : ((__uint128_t)(x9)*(x6))>>64;
x155 = (x9)*(x5);
x156 = sizeof(intptr_t) == 4 ? ((uint64_t)(x9)*(x5))>>32 : ((__uint128_t)(x9)*(x5))>>64;
x157 = (x9)*(x4);
x158 = sizeof(intptr_t) == 4 ? ((uint64_t)(x9)*(x4))>>32 : ((__uint128_t)(x9)*(x4))>>64;
x159 = (x158)+(x155);
x160 = (x159)<(x158);
x161 = (x160)+(x156);
x162 = (x161)<(x156);
x163 = (x161)+(x153);
x164 = (x163)<(x153);
x165 = (x162)+(x164);
x166 = (x165)+(x154);
x167 = (x166)<(x154);
x168 = (x166)+(x151);
x169 = (x168)<(x151);
x170 = (x167)+(x169);
x171 = (x170)+(x152);
x172 = (x132)+(x157);
x173 = (x172)<(x132);
x174 = (x173)+(x137);
x175 = (x174)<(x137);
x176 = (x174)+(x159);
x177 = (x176)<(x159);
x178 = (x175)+(x177);
x179 = (x178)+(x142);
x180 = (x179)<(x142);
x181 = (x179)+(x163);
x182 = (x181)<(x163);
x183 = (x180)+(x182);
x184 = (x183)+(x147);
x185 = (x184)<(x147);
x186 = (x184)+(x168);
x187 = (x186)<(x168);
x188 = (x185)+(x187);
x189 = (x188)+(x150);
x190 = (x189)<(x150);
x191 = (x189)+(x171);
x192 = (x191)<(x171);
x193 = (x190)+(x192);
x194 = (x172)*((uintptr_t)18446744073709551615ULL);
x195 = (x194)*((uintptr_t)4294967295ULL);
x196 = sizeof(intptr_t) == 4 ? ((uint64_t)(x194)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x194)*((uintptr_t)4294967295ULL))>>64;
x197 = (x194)*((uintptr_t)18446744073709551615ULL);
x198 = sizeof(intptr_t) == 4 ? ((uint64_t)(x194)*((uintptr_t)18446744073709551615ULL))>>32 : ((__uint128_t)(x194)*((uintptr_t)18446744073709551615ULL))>>64;
x199 = (x194)*((uintptr_t)18446744069414584320ULL);
x200 = sizeof(intptr_t) == 4 ? ((uint64_t)(x194)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x194)*((uintptr_t)18446744069414584320ULL))>>64;
x201 = (x200)+(x197);
x202 = (x201)<(x200);
x203 = (x202)+(x198);
x204 = (x203)<(x198);
x205 = (x203)+(x195);
x206 = (x205)<(x195);
x207 = (x204)+(x206);
x208 = (x207)+(x196);
x209 = (x172)+(x194);
x210 = (x209)<(x172);
x211 = (x210)+(x176);
x212 = (x211)<(x176);
x213 = (x211)+(x199);
x214 = (x213)<(x199);
x215 = (x212)+(x214);
x216 = (x215)+(x181);
x217 = (x216)<(x181);
x218 = (x216)+(x201);
x219 = (x218)<(x201);
x220 = (x217)+(x219);
x221 = (x220)+(x186);
x222 = (x221)<(x186);
x223 = (x221)+(x205);
x224 = (x223)<(x205);
x225 = (x222)+(x224);
x226 = (x225)+(x191);
x227 = (x226)<(x191);
x228 = (x226)+(x208);
x229 = (x228)<(x208);
x230 = (x227)+(x229);
x231 = (x230)+(x193);
x232 = (x10)*(x7);
x233 = sizeof(intptr_t) == 4 ? ((uint64_t)(x10)*(x7))>>32 : ((__uint128_t)(x10)*(x7))>>64;
x234 = (x10)*(x6);
x235 = sizeof(intptr_t) == 4 ? ((uint64_t)(x10)*(x6))>>32 : ((__uint128_t)(x10)*(x6))>>64;
x236 = (x10)*(x5);
x237 = sizeof(intptr_t) == 4 ? ((uint64_t)(x10)*(x5))>>32 : ((__uint128_t)(x10)*(x5))>>64;
x238 = (x10)*(x4);
x239 = sizeof(intptr_t) == 4 ? ((uint64_t)(x10)*(x4))>>32 : ((__uint128_t)(x10)*(x4))>>64;
x240 = (x239)+(x236);
x241 = (x240)<(x239);
x242 = (x241)+(x237);
x243 = (x242)<(x237);
x244 = (x242)+(x234);
x245 = (x244)<(x234);
x246 = (x243)+(x245);
x247 = (x246)+(x235);
x248 = (x247)<(x235);
x249 = (x247)+(x232);
x250 = (x249)<(x232);
x251 = (x248)+(x250);
x252 = (x251)+(x233);
x253 = (x213)+(x238);
x254 = (x253)<(x213);
x255 = (x254)+(x218);
x256 = (x255)<(x218);
x257 = (x255)+(x240);
x258 = (x257)<(x240);
x259 = (x256)+(x258);
x260 = (x259)+(x223);
x261 = (x260)<(x223);
x262 = (x260)+(x244);
x263 = (x262)<(x244);
x264 = (x261)+(x263);
x265 = (x264)+(x228);
x266 = (x265)<(x228);
x267 = (x265)+(x249);
x268 = (x267)<(x249);
x269 = (x266)+(x268);
x270 = (x269)+(x231);
x271 = (x270)<(x231);
x272 = (x270)+(x252);
x273 = (x272)<(x252);
x274 = (x271)+(x273);
x275 = (x253)*((uintptr_t)18446744073709551615ULL);
x276 = (x275)*((uintptr_t)4294967295ULL);
x277 = sizeof(intptr_t) == 4 ? ((uint64_t)(x275)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x275)*((uintptr_t)4294967295ULL))>>64;
x278 = (x275)*((uintptr_t)18446744073709551615ULL);
x279 = sizeof(intptr_t) == 4 ? ((uint64_t)(x275)*((uintptr_t)18446744073709551615ULL))>>32 : ((__uint128_t)(x275)*((uintptr_t)18446744073709551615ULL))>>64;
x280 = (x275)*((uintptr_t)18446744069414584320ULL);
x281 = sizeof(intptr_t) == 4 ? ((uint64_t)(x275)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x275)*((uintptr_t)18446744069414584320ULL))>>64;
x282 = (x281)+(x278);
x283 = (x282)<(x281);
x284 = (x283)+(x279);
x285 = (x284)<(x279);
x286 = (x284)+(x276);
x287 = (x286)<(x276);
x288 = (x285)+(x287);
x289 = (x288)+(x277);
x290 = (x253)+(x275);
x291 = (x290)<(x253);
x292 = (x291)+(x257);
x293 = (x292)<(x257);
x294 = (x292)+(x280);
x295 = (x294)<(x280);
x296 = (x293)+(x295);
x297 = (x296)+(x262);
x298 = (x297)<(x262);
x299 = (x297)+(x282);
x300 = (x299)<(x282);
x301 = (x298)+(x300);
x302 = (x301)+(x267);
x303 = (x302)<(x267);
x304 = (x302)+(x286);
x305 = (x304)<(x286);
x306 = (x303)+(x305);
x307 = (x306)+(x272);
x308 = (x307)<(x272);
x309 = (x307)+(x289);
x310 = (x309)<(x289);
x311 = (x308)+(x310);
x312 = (x311)+(x274);
x313 = (x294)-((uintptr_t)1ULL);
x314 = (x294)<(x313);
x315 = (x299)-((uintptr_t)18446744069414584320ULL);
x316 = (x299)<(x315);
x317 = (x315)-(x314);
x318 = (x315)<(x317);
x319 = (x316)+(x318);
x320 = (x304)-((uintptr_t)18446744073709551615ULL);
x321 = (x304)<(x320);
x322 = (x320)-(x319);
x323 = (x320)<(x322);
x324 = (x321)+(x323);
x325 = (x309)-((uintptr_t)4294967295ULL);
x326 = (x309)<(x325);
x327 = (x325)-(x324);
x328 = (x325)<(x327);
x329 = (x326)+(x328);
x330 = (x312)-(x329);
x331 = (x312)<(x330);
x332 = ((uintptr_t)-1ULL)+((x331)==((uintptr_t)0ULL));
x333 = (x332)^((uintptr_t)18446744073709551615ULL);
x334 = ((x294)&(x332))|((x313)&(x333));
x335 = ((uintptr_t)-1ULL)+((x331)==((uintptr_t)0ULL));
x336 = (x335)^((uintptr_t)18446744073709551615ULL);
x337 = ((x299)&(x335))|((x317)&(x336));
x338 = ((uintptr_t)-1ULL)+((x331)==((uintptr_t)0ULL));
x339 = (x338)^((uintptr_t)18446744073709551615ULL);
x340 = ((x304)&(x338))|((x322)&(x339));
x341 = ((uintptr_t)-1ULL)+((x331)==((uintptr_t)0ULL));
x342 = (x341)^((uintptr_t)18446744073709551615ULL);
x343 = ((x309)&(x341))|((x327)&(x342));
x344 = x334;
x345 = x337;
x346 = x340;
x347 = x343;
/*skip*/
_br2_store((out0)+((uintptr_t)0ULL), x344, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)8ULL), x345, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)16ULL), x346, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)24ULL), x347, sizeof(uintptr_t));
/*skip*/
return;
}
/* NOTE: The following wrapper function is not covered by Coq proofs */
static void fiat_p224_mul(uint64_t out1[4], const uint64_t arg1[4], const uint64_t arg2[4]) {
internal_fiat_p224_mul((uintptr_t)out1, (uintptr_t)arg1, (uintptr_t)arg2);
}
/*
* Input Bounds:
* in0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static
void internal_fiat_p224_square(uintptr_t out0, uintptr_t in0) {
uintptr_t x7, x12, x15, x17, x13, x18, x10, x19, x21, x22, x11, x23, x8, x24, x26, x27, x9, x32, x35, x37, x33, x38, x30, x39, x41, x42, x31, x29, x44, x14, x45, x16, x46, x34, x47, x49, x50, x20, x51, x36, x52, x54, x55, x25, x56, x40, x57, x59, x60, x28, x61, x43, x62, x64, x4, x70, x73, x75, x71, x76, x68, x77, x79, x80, x69, x81, x66, x82, x84, x85, x67, x72, x48, x88, x53, x89, x74, x90, x92, x93, x58, x94, x78, x95, x97, x98, x63, x99, x83, x100, x102, x103, x65, x104, x86, x105, x107, x112, x115, x117, x113, x118, x110, x119, x121, x122, x111, x109, x124, x87, x125, x91, x126, x114, x127, x129, x130, x96, x131, x116, x132, x134, x135, x101, x136, x120, x137, x139, x140, x106, x141, x123, x142, x144, x145, x108, x5, x151, x154, x156, x152, x157, x149, x158, x160, x161, x150, x162, x147, x163, x165, x166, x148, x153, x128, x169, x133, x170, x155, x171, x173, x174, x138, x175, x159, x176, x178, x179, x143, x180, x164, x181, x183, x184, x146, x185, x167, x186, x188, x193, x196, x198, x194, x199, x191, x200, x202, x203, x192, x190, x205, x168, x206, x172, x207, x195, x208, x210, x211, x177, x212, x197, x213, x215, x216, x182, x217, x201, x218, x220, x221, x187, x222, x204, x223, x225, x226, x189, x3, x2, x1, x6, x0, x232, x235, x237, x233, x238, x230, x239, x241, x242, x231, x243, x228, x244, x246, x247, x229, x234, x209, x250, x214, x251, x236, x252, x254, x255, x219, x256, x240, x257, x259, x260, x224, x261, x245, x262, x264, x265, x227, x266, x248, x267, x269, x274, x277, x279, x275, x280, x272, x281, x283, x284, x273, x271, x286, x249, x287, x253, x288, x276, x289, x291, x292, x258, x293, x278, x294, x296, x297, x263, x298, x282, x299, x301, x302, x268, x303, x285, x304, x306, x307, x270, x310, x311, x312, x314, x315, x316, x317, x319, x320, x321, x322, x324, x325, x308, x326, x290, x328, x309, x329, x295, x331, x313, x332, x300, x334, x318, x335, x327, x305, x337, x323, x338, x330, x333, x336, x339, x340, x341, x342, x343;
x0 = _br2_load((in0)+((uintptr_t)0ULL), sizeof(uintptr_t));
x1 = _br2_load((in0)+((uintptr_t)8ULL), sizeof(uintptr_t));
x2 = _br2_load((in0)+((uintptr_t)16ULL), sizeof(uintptr_t));
x3 = _br2_load((in0)+((uintptr_t)24ULL), sizeof(uintptr_t));
/*skip*/
/*skip*/
x4 = x1;
x5 = x2;
x6 = x3;
x7 = x0;
x8 = (x7)*(x3);
x9 = sizeof(intptr_t) == 4 ? ((uint64_t)(x7)*(x3))>>32 : ((__uint128_t)(x7)*(x3))>>64;
x10 = (x7)*(x2);
x11 = sizeof(intptr_t) == 4 ? ((uint64_t)(x7)*(x2))>>32 : ((__uint128_t)(x7)*(x2))>>64;
x12 = (x7)*(x1);
x13 = sizeof(intptr_t) == 4 ? ((uint64_t)(x7)*(x1))>>32 : ((__uint128_t)(x7)*(x1))>>64;
x14 = (x7)*(x0);
x15 = sizeof(intptr_t) == 4 ? ((uint64_t)(x7)*(x0))>>32 : ((__uint128_t)(x7)*(x0))>>64;
x16 = (x15)+(x12);
x17 = (x16)<(x15);
x18 = (x17)+(x13);
x19 = (x18)<(x13);
x20 = (x18)+(x10);
x21 = (x20)<(x10);
x22 = (x19)+(x21);
x23 = (x22)+(x11);
x24 = (x23)<(x11);
x25 = (x23)+(x8);
x26 = (x25)<(x8);
x27 = (x24)+(x26);
x28 = (x27)+(x9);
x29 = (x14)*((uintptr_t)18446744073709551615ULL);
x30 = (x29)*((uintptr_t)4294967295ULL);
x31 = sizeof(intptr_t) == 4 ? ((uint64_t)(x29)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x29)*((uintptr_t)4294967295ULL))>>64;
x32 = (x29)*((uintptr_t)18446744073709551615ULL);
x33 = sizeof(intptr_t) == 4 ? ((uint64_t)(x29)*((uintptr_t)18446744073709551615ULL))>>32 : ((__uint128_t)(x29)*((uintptr_t)18446744073709551615ULL))>>64;
x34 = (x29)*((uintptr_t)18446744069414584320ULL);
x35 = sizeof(intptr_t) == 4 ? ((uint64_t)(x29)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x29)*((uintptr_t)18446744069414584320ULL))>>64;
x36 = (x35)+(x32);
x37 = (x36)<(x35);
x38 = (x37)+(x33);
x39 = (x38)<(x33);
x40 = (x38)+(x30);
x41 = (x40)<(x30);
x42 = (x39)+(x41);
x43 = (x42)+(x31);
x44 = (x14)+(x29);
x45 = (x44)<(x14);
x46 = (x45)+(x16);
x47 = (x46)<(x16);
x48 = (x46)+(x34);
x49 = (x48)<(x34);
x50 = (x47)+(x49);
x51 = (x50)+(x20);
x52 = (x51)<(x20);
x53 = (x51)+(x36);
x54 = (x53)<(x36);
x55 = (x52)+(x54);
x56 = (x55)+(x25);
x57 = (x56)<(x25);
x58 = (x56)+(x40);
x59 = (x58)<(x40);
x60 = (x57)+(x59);
x61 = (x60)+(x28);
x62 = (x61)<(x28);
x63 = (x61)+(x43);
x64 = (x63)<(x43);
x65 = (x62)+(x64);
x66 = (x4)*(x3);
x67 = sizeof(intptr_t) == 4 ? ((uint64_t)(x4)*(x3))>>32 : ((__uint128_t)(x4)*(x3))>>64;
x68 = (x4)*(x2);
x69 = sizeof(intptr_t) == 4 ? ((uint64_t)(x4)*(x2))>>32 : ((__uint128_t)(x4)*(x2))>>64;
x70 = (x4)*(x1);
x71 = sizeof(intptr_t) == 4 ? ((uint64_t)(x4)*(x1))>>32 : ((__uint128_t)(x4)*(x1))>>64;
x72 = (x4)*(x0);
x73 = sizeof(intptr_t) == 4 ? ((uint64_t)(x4)*(x0))>>32 : ((__uint128_t)(x4)*(x0))>>64;
x74 = (x73)+(x70);
x75 = (x74)<(x73);
x76 = (x75)+(x71);
x77 = (x76)<(x71);
x78 = (x76)+(x68);
x79 = (x78)<(x68);
x80 = (x77)+(x79);
x81 = (x80)+(x69);
x82 = (x81)<(x69);
x83 = (x81)+(x66);
x84 = (x83)<(x66);
x85 = (x82)+(x84);
x86 = (x85)+(x67);
x87 = (x48)+(x72);
x88 = (x87)<(x48);
x89 = (x88)+(x53);
x90 = (x89)<(x53);
x91 = (x89)+(x74);
x92 = (x91)<(x74);
x93 = (x90)+(x92);
x94 = (x93)+(x58);
x95 = (x94)<(x58);
x96 = (x94)+(x78);
x97 = (x96)<(x78);
x98 = (x95)+(x97);
x99 = (x98)+(x63);
x100 = (x99)<(x63);
x101 = (x99)+(x83);
x102 = (x101)<(x83);
x103 = (x100)+(x102);
x104 = (x103)+(x65);
x105 = (x104)<(x65);
x106 = (x104)+(x86);
x107 = (x106)<(x86);
x108 = (x105)+(x107);
x109 = (x87)*((uintptr_t)18446744073709551615ULL);
x110 = (x109)*((uintptr_t)4294967295ULL);
x111 = sizeof(intptr_t) == 4 ? ((uint64_t)(x109)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x109)*((uintptr_t)4294967295ULL))>>64;
x112 = (x109)*((uintptr_t)18446744073709551615ULL);
x113 = sizeof(intptr_t) == 4 ? ((uint64_t)(x109)*((uintptr_t)18446744073709551615ULL))>>32 : ((__uint128_t)(x109)*((uintptr_t)18446744073709551615ULL))>>64;
x114 = (x109)*((uintptr_t)18446744069414584320ULL);
x115 = sizeof(intptr_t) == 4 ? ((uint64_t)(x109)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x109)*((uintptr_t)18446744069414584320ULL))>>64;
x116 = (x115)+(x112);
x117 = (x116)<(x115);
x118 = (x117)+(x113);
x119 = (x118)<(x113);
x120 = (x118)+(x110);
x121 = (x120)<(x110);
x122 = (x119)+(x121);
x123 = (x122)+(x111);
x124 = (x87)+(x109);
x125 = (x124)<(x87);
x126 = (x125)+(x91);
x127 = (x126)<(x91);
x128 = (x126)+(x114);
x129 = (x128)<(x114);
x130 = (x127)+(x129);
x131 = (x130)+(x96);
x132 = (x131)<(x96);
x133 = (x131)+(x116);
x134 = (x133)<(x116);
x135 = (x132)+(x134);
x136 = (x135)+(x101);
x137 = (x136)<(x101);
x138 = (x136)+(x120);
x139 = (x138)<(x120);
x140 = (x137)+(x139);
x141 = (x140)+(x106);
x142 = (x141)<(x106);
x143 = (x141)+(x123);
x144 = (x143)<(x123);
x145 = (x142)+(x144);
x146 = (x145)+(x108);
x147 = (x5)*(x3);
x148 = sizeof(intptr_t) == 4 ? ((uint64_t)(x5)*(x3))>>32 : ((__uint128_t)(x5)*(x3))>>64;
x149 = (x5)*(x2);
x150 = sizeof(intptr_t) == 4 ? ((uint64_t)(x5)*(x2))>>32 : ((__uint128_t)(x5)*(x2))>>64;
x151 = (x5)*(x1);
x152 = sizeof(intptr_t) == 4 ? ((uint64_t)(x5)*(x1))>>32 : ((__uint128_t)(x5)*(x1))>>64;
x153 = (x5)*(x0);
x154 = sizeof(intptr_t) == 4 ? ((uint64_t)(x5)*(x0))>>32 : ((__uint128_t)(x5)*(x0))>>64;
x155 = (x154)+(x151);
x156 = (x155)<(x154);
x157 = (x156)+(x152);
x158 = (x157)<(x152);
x159 = (x157)+(x149);
x160 = (x159)<(x149);
x161 = (x158)+(x160);
x162 = (x161)+(x150);
x163 = (x162)<(x150);
x164 = (x162)+(x147);
x165 = (x164)<(x147);
x166 = (x163)+(x165);
x167 = (x166)+(x148);
x168 = (x128)+(x153);
x169 = (x168)<(x128);
x170 = (x169)+(x133);
x171 = (x170)<(x133);
x172 = (x170)+(x155);
x173 = (x172)<(x155);
x174 = (x171)+(x173);
x175 = (x174)+(x138);
x176 = (x175)<(x138);
x177 = (x175)+(x159);
x178 = (x177)<(x159);
x179 = (x176)+(x178);
x180 = (x179)+(x143);
x181 = (x180)<(x143);
x182 = (x180)+(x164);
x183 = (x182)<(x164);
x184 = (x181)+(x183);
x185 = (x184)+(x146);
x186 = (x185)<(x146);
x187 = (x185)+(x167);
x188 = (x187)<(x167);
x189 = (x186)+(x188);
x190 = (x168)*((uintptr_t)18446744073709551615ULL);
x191 = (x190)*((uintptr_t)4294967295ULL);
x192 = sizeof(intptr_t) == 4 ? ((uint64_t)(x190)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x190)*((uintptr_t)4294967295ULL))>>64;
x193 = (x190)*((uintptr_t)18446744073709551615ULL);
x194 = sizeof(intptr_t) == 4 ? ((uint64_t)(x190)*((uintptr_t)18446744073709551615ULL))>>32 : ((__uint128_t)(x190)*((uintptr_t)18446744073709551615ULL))>>64;
x195 = (x190)*((uintptr_t)18446744069414584320ULL);
x196 = sizeof(intptr_t) == 4 ? ((uint64_t)(x190)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x190)*((uintptr_t)18446744069414584320ULL))>>64;
x197 = (x196)+(x193);
x198 = (x197)<(x196);
x199 = (x198)+(x194);
x200 = (x199)<(x194);
x201 = (x199)+(x191);
x202 = (x201)<(x191);
x203 = (x200)+(x202);
x204 = (x203)+(x192);
x205 = (x168)+(x190);
x206 = (x205)<(x168);
x207 = (x206)+(x172);
x208 = (x207)<(x172);
x209 = (x207)+(x195);
x210 = (x209)<(x195);
x211 = (x208)+(x210);
x212 = (x211)+(x177);
x213 = (x212)<(x177);
x214 = (x212)+(x197);
x215 = (x214)<(x197);
x216 = (x213)+(x215);
x217 = (x216)+(x182);
x218 = (x217)<(x182);
x219 = (x217)+(x201);
x220 = (x219)<(x201);
x221 = (x218)+(x220);
x222 = (x221)+(x187);
x223 = (x222)<(x187);
x224 = (x222)+(x204);
x225 = (x224)<(x204);
x226 = (x223)+(x225);
x227 = (x226)+(x189);
x228 = (x6)*(x3);
x229 = sizeof(intptr_t) == 4 ? ((uint64_t)(x6)*(x3))>>32 : ((__uint128_t)(x6)*(x3))>>64;
x230 = (x6)*(x2);
x231 = sizeof(intptr_t) == 4 ? ((uint64_t)(x6)*(x2))>>32 : ((__uint128_t)(x6)*(x2))>>64;
x232 = (x6)*(x1);
x233 = sizeof(intptr_t) == 4 ? ((uint64_t)(x6)*(x1))>>32 : ((__uint128_t)(x6)*(x1))>>64;
x234 = (x6)*(x0);
x235 = sizeof(intptr_t) == 4 ? ((uint64_t)(x6)*(x0))>>32 : ((__uint128_t)(x6)*(x0))>>64;
x236 = (x235)+(x232);
x237 = (x236)<(x235);
x238 = (x237)+(x233);
x239 = (x238)<(x233);
x240 = (x238)+(x230);
x241 = (x240)<(x230);
x242 = (x239)+(x241);
x243 = (x242)+(x231);
x244 = (x243)<(x231);
x245 = (x243)+(x228);
x246 = (x245)<(x228);
x247 = (x244)+(x246);
x248 = (x247)+(x229);
x249 = (x209)+(x234);
x250 = (x249)<(x209);
x251 = (x250)+(x214);
x252 = (x251)<(x214);
x253 = (x251)+(x236);
x254 = (x253)<(x236);
x255 = (x252)+(x254);
x256 = (x255)+(x219);
x257 = (x256)<(x219);
x258 = (x256)+(x240);
x259 = (x258)<(x240);
x260 = (x257)+(x259);
x261 = (x260)+(x224);
x262 = (x261)<(x224);
x263 = (x261)+(x245);
x264 = (x263)<(x245);
x265 = (x262)+(x264);
x266 = (x265)+(x227);
x267 = (x266)<(x227);
x268 = (x266)+(x248);
x269 = (x268)<(x248);
x270 = (x267)+(x269);
x271 = (x249)*((uintptr_t)18446744073709551615ULL);
x272 = (x271)*((uintptr_t)4294967295ULL);
x273 = sizeof(intptr_t) == 4 ? ((uint64_t)(x271)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x271)*((uintptr_t)4294967295ULL))>>64;
x274 = (x271)*((uintptr_t)18446744073709551615ULL);
x275 = sizeof(intptr_t) == 4 ? ((uint64_t)(x271)*((uintptr_t)18446744073709551615ULL))>>32 : ((__uint128_t)(x271)*((uintptr_t)18446744073709551615ULL))>>64;
x276 = (x271)*((uintptr_t)18446744069414584320ULL);
x277 = sizeof(intptr_t) == 4 ? ((uint64_t)(x271)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x271)*((uintptr_t)18446744069414584320ULL))>>64;
x278 = (x277)+(x274);
x279 = (x278)<(x277);
x280 = (x279)+(x275);
x281 = (x280)<(x275);
x282 = (x280)+(x272);
x283 = (x282)<(x272);
x284 = (x281)+(x283);
x285 = (x284)+(x273);
x286 = (x249)+(x271);
x287 = (x286)<(x249);
x288 = (x287)+(x253);
x289 = (x288)<(x253);
x290 = (x288)+(x276);
x291 = (x290)<(x276);
x292 = (x289)+(x291);
x293 = (x292)+(x258);
x294 = (x293)<(x258);
x295 = (x293)+(x278);
x296 = (x295)<(x278);
x297 = (x294)+(x296);
x298 = (x297)+(x263);
x299 = (x298)<(x263);
x300 = (x298)+(x282);
x301 = (x300)<(x282);
x302 = (x299)+(x301);
x303 = (x302)+(x268);
x304 = (x303)<(x268);
x305 = (x303)+(x285);
x306 = (x305)<(x285);
x307 = (x304)+(x306);
x308 = (x307)+(x270);
x309 = (x290)-((uintptr_t)1ULL);
x310 = (x290)<(x309);
x311 = (x295)-((uintptr_t)18446744069414584320ULL);
x312 = (x295)<(x311);
x313 = (x311)-(x310);
x314 = (x311)<(x313);
x315 = (x312)+(x314);
x316 = (x300)-((uintptr_t)18446744073709551615ULL);
x317 = (x300)<(x316);
x318 = (x316)-(x315);
x319 = (x316)<(x318);
x320 = (x317)+(x319);
x321 = (x305)-((uintptr_t)4294967295ULL);
x322 = (x305)<(x321);
x323 = (x321)-(x320);
x324 = (x321)<(x323);
x325 = (x322)+(x324);
x326 = (x308)-(x325);
x327 = (x308)<(x326);
x328 = ((uintptr_t)-1ULL)+((x327)==((uintptr_t)0ULL));
x329 = (x328)^((uintptr_t)18446744073709551615ULL);
x330 = ((x290)&(x328))|((x309)&(x329));
x331 = ((uintptr_t)-1ULL)+((x327)==((uintptr_t)0ULL));
x332 = (x331)^((uintptr_t)18446744073709551615ULL);
x333 = ((x295)&(x331))|((x313)&(x332));
x334 = ((uintptr_t)-1ULL)+((x327)==((uintptr_t)0ULL));
x335 = (x334)^((uintptr_t)18446744073709551615ULL);
x336 = ((x300)&(x334))|((x318)&(x335));
x337 = ((uintptr_t)-1ULL)+((x327)==((uintptr_t)0ULL));
x338 = (x337)^((uintptr_t)18446744073709551615ULL);
x339 = ((x305)&(x337))|((x323)&(x338));
x340 = x330;
x341 = x333;
x342 = x336;
x343 = x339;
/*skip*/
_br2_store((out0)+((uintptr_t)0ULL), x340, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)8ULL), x341, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)16ULL), x342, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)24ULL), x343, sizeof(uintptr_t));
/*skip*/
return;
}
/* NOTE: The following wrapper function is not covered by Coq proofs */
static void fiat_p224_square(uint64_t out1[4], const uint64_t arg1[4]) {
internal_fiat_p224_square((uintptr_t)out1, (uintptr_t)arg1);
}
/*
* Input Bounds:
* in0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* in1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static
void internal_fiat_p224_add(uintptr_t out0, uintptr_t in0, uintptr_t in1) {
uintptr_t x4, x0, x9, x1, x5, x11, x2, x6, x13, x3, x7, x17, x19, x15, x21, x8, x24, x16, x25, x10, x27, x18, x28, x12, x30, x20, x31, x23, x14, x33, x22, x34, x26, x29, x32, x35, x36, x37, x38, x39;
x0 = _br2_load((in0)+((uintptr_t)0ULL), sizeof(uintptr_t));
x1 = _br2_load((in0)+((uintptr_t)8ULL), sizeof(uintptr_t));
x2 = _br2_load((in0)+((uintptr_t)16ULL), sizeof(uintptr_t));
x3 = _br2_load((in0)+((uintptr_t)24ULL), sizeof(uintptr_t));
/*skip*/
x4 = _br2_load((in1)+((uintptr_t)0ULL), sizeof(uintptr_t));
x5 = _br2_load((in1)+((uintptr_t)8ULL), sizeof(uintptr_t));
x6 = _br2_load((in1)+((uintptr_t)16ULL), sizeof(uintptr_t));
x7 = _br2_load((in1)+((uintptr_t)24ULL), sizeof(uintptr_t));
/*skip*/
/*skip*/
x8 = (x0)+(x4);
x9 = ((x8)<(x0))+(x1);
x10 = (x9)+(x5);
x11 = (((x9)<(x1))+((x10)<(x5)))+(x2);
x12 = (x11)+(x6);
x13 = (((x11)<(x2))+((x12)<(x6)))+(x3);
x14 = (x13)+(x7);
x15 = ((x13)<(x3))+((x14)<(x7));
x16 = (x8)-((uintptr_t)1ULL);
x17 = (x10)-((uintptr_t)18446744069414584320ULL);
x18 = (x17)-((x8)<(x16));
x19 = (x12)-((uintptr_t)18446744073709551615ULL);
x20 = (x19)-(((x10)<(x17))+((x17)<(x18)));
x21 = (x14)-((uintptr_t)4294967295ULL);
x22 = (x21)-(((x12)<(x19))+((x19)<(x20)));
x23 = (x15)<((x15)-(((x14)<(x21))+((x21)<(x22))));
x24 = ((uintptr_t)-1ULL)+((x23)==((uintptr_t)0ULL));
x25 = (x24)^((uintptr_t)18446744073709551615ULL);
x26 = ((x8)&(x24))|((x16)&(x25));
x27 = ((uintptr_t)-1ULL)+((x23)==((uintptr_t)0ULL));
x28 = (x27)^((uintptr_t)18446744073709551615ULL);
x29 = ((x10)&(x27))|((x18)&(x28));
x30 = ((uintptr_t)-1ULL)+((x23)==((uintptr_t)0ULL));
x31 = (x30)^((uintptr_t)18446744073709551615ULL);
x32 = ((x12)&(x30))|((x20)&(x31));
x33 = ((uintptr_t)-1ULL)+((x23)==((uintptr_t)0ULL));
x34 = (x33)^((uintptr_t)18446744073709551615ULL);
x35 = ((x14)&(x33))|((x22)&(x34));
x36 = x26;
x37 = x29;
x38 = x32;
x39 = x35;
/*skip*/
_br2_store((out0)+((uintptr_t)0ULL), x36, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)8ULL), x37, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)16ULL), x38, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)24ULL), x39, sizeof(uintptr_t));
/*skip*/
return;
}
/* NOTE: The following wrapper function is not covered by Coq proofs */
static void fiat_p224_add(uint64_t out1[4], const uint64_t arg1[4], const uint64_t arg2[4]) {
internal_fiat_p224_add((uintptr_t)out1, (uintptr_t)arg1, (uintptr_t)arg2);
}
/*
* Input Bounds:
* in0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* in1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static
void internal_fiat_p224_sub(uintptr_t out0, uintptr_t in0, uintptr_t in1) {
uintptr_t x4, x5, x0, x6, x1, x9, x7, x2, x11, x3, x13, x8, x17, x10, x19, x12, x14, x15, x16, x18, x20, x21, x22, x23, x24, x25;
x0 = _br2_load((in0)+((uintptr_t)0ULL), sizeof(uintptr_t));
x1 = _br2_load((in0)+((uintptr_t)8ULL), sizeof(uintptr_t));
x2 = _br2_load((in0)+((uintptr_t)16ULL), sizeof(uintptr_t));
x3 = _br2_load((in0)+((uintptr_t)24ULL), sizeof(uintptr_t));
/*skip*/
x4 = _br2_load((in1)+((uintptr_t)0ULL), sizeof(uintptr_t));
x5 = _br2_load((in1)+((uintptr_t)8ULL), sizeof(uintptr_t));
x6 = _br2_load((in1)+((uintptr_t)16ULL), sizeof(uintptr_t));
x7 = _br2_load((in1)+((uintptr_t)24ULL), sizeof(uintptr_t));
/*skip*/
/*skip*/
x8 = (x0)-(x4);
x9 = (x1)-(x5);
x10 = (x9)-((x0)<(x8));
x11 = (x2)-(x6);
x12 = (x11)-(((x1)<(x9))+((x9)<(x10)));
x13 = (x3)-(x7);
x14 = (x13)-(((x2)<(x11))+((x11)<(x12)));
x15 = ((uintptr_t)-1ULL)+((((x3)<(x13))+((x13)<(x14)))==((uintptr_t)0ULL));
x16 = (x8)+((x15)&((uintptr_t)1ULL));
x17 = ((x16)<(x8))+(x10);
x18 = (x17)+((x15)&((uintptr_t)18446744069414584320ULL));
x19 = (((x17)<(x10))+((x18)<((x15)&((uintptr_t)18446744069414584320ULL))))+(x12);
x20 = (x19)+(x15);
x21 = ((((x19)<(x12))+((x20)<(x15)))+(x14))+((x15)&((uintptr_t)4294967295ULL));
x22 = x16;
x23 = x18;
x24 = x20;
x25 = x21;
/*skip*/
_br2_store((out0)+((uintptr_t)0ULL), x22, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)8ULL), x23, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)16ULL), x24, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)24ULL), x25, sizeof(uintptr_t));
/*skip*/
return;
}
/* NOTE: The following wrapper function is not covered by Coq proofs */
static void fiat_p224_sub(uint64_t out1[4], const uint64_t arg1[4], const uint64_t arg2[4]) {
internal_fiat_p224_sub((uintptr_t)out1, (uintptr_t)arg1, (uintptr_t)arg2);
}
/*
* Input Bounds:
* in0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static
void internal_fiat_p224_opp(uintptr_t out0, uintptr_t in0) {
uintptr_t x0, x1, x2, x5, x3, x7, x9, x4, x13, x6, x15, x8, x10, x11, x12, x14, x16, x17, x18, x19, x20, x21;
x0 = _br2_load((in0)+((uintptr_t)0ULL), sizeof(uintptr_t));
x1 = _br2_load((in0)+((uintptr_t)8ULL), sizeof(uintptr_t));
x2 = _br2_load((in0)+((uintptr_t)16ULL), sizeof(uintptr_t));
x3 = _br2_load((in0)+((uintptr_t)24ULL), sizeof(uintptr_t));
/*skip*/
/*skip*/
x4 = ((uintptr_t)0ULL)-(x0);
x5 = ((uintptr_t)0ULL)-(x1);
x6 = (x5)-(((uintptr_t)0ULL)<(x4));
x7 = ((uintptr_t)0ULL)-(x2);
x8 = (x7)-((((uintptr_t)0ULL)<(x5))+((x5)<(x6)));
x9 = ((uintptr_t)0ULL)-(x3);
x10 = (x9)-((((uintptr_t)0ULL)<(x7))+((x7)<(x8)));
x11 = ((uintptr_t)-1ULL)+(((((uintptr_t)0ULL)<(x9))+((x9)<(x10)))==((uintptr_t)0ULL));
x12 = (x4)+((x11)&((uintptr_t)1ULL));
x13 = ((x12)<(x4))+(x6);
x14 = (x13)+((x11)&((uintptr_t)18446744069414584320ULL));
x15 = (((x13)<(x6))+((x14)<((x11)&((uintptr_t)18446744069414584320ULL))))+(x8);
x16 = (x15)+(x11);
x17 = ((((x15)<(x8))+((x16)<(x11)))+(x10))+((x11)&((uintptr_t)4294967295ULL));
x18 = x12;
x19 = x14;
x20 = x16;
x21 = x17;
/*skip*/
_br2_store((out0)+((uintptr_t)0ULL), x18, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)8ULL), x19, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)16ULL), x20, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)24ULL), x21, sizeof(uintptr_t));
/*skip*/
return;
}
/* NOTE: The following wrapper function is not covered by Coq proofs */
static void fiat_p224_opp(uint64_t out1[4], const uint64_t arg1[4]) {
internal_fiat_p224_opp((uintptr_t)out1, (uintptr_t)arg1);
}
/*
* Input Bounds:
* in0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static
void internal_fiat_p224_from_montgomery(uintptr_t out0, uintptr_t in0) {
uintptr_t x0, x10, x12, x8, x6, x5, x4, x9, x11, x13, x1, x15, x16, x17, x28, x30, x26, x24, x23, x19, x33, x20, x27, x35, x21, x29, x37, x22, x18, x14, x7, x31, x2, x34, x36, x38, x49, x51, x47, x45, x44, x40, x54, x41, x48, x56, x42, x50, x58, x43, x39, x32, x25, x52, x3, x55, x57, x59, x69, x61, x73, x62, x68, x75, x63, x70, x77, x64, x60, x53, x46, x71, x67, x72, x66, x65, x81, x83, x85, x74, x88, x80, x89, x76, x91, x82, x92, x78, x94, x84, x95, x87, x79, x97, x86, x98, x90, x93, x96, x99, x100, x101, x102, x103;
x0 = _br2_load((in0)+((uintptr_t)0ULL), sizeof(uintptr_t));
x1 = _br2_load((in0)+((uintptr_t)8ULL), sizeof(uintptr_t));
x2 = _br2_load((in0)+((uintptr_t)16ULL), sizeof(uintptr_t));
x3 = _br2_load((in0)+((uintptr_t)24ULL), sizeof(uintptr_t));
/*skip*/
/*skip*/
x4 = x0;
x5 = (x4)*((uintptr_t)18446744073709551615ULL);
x6 = (x5)*((uintptr_t)4294967295ULL);
x7 = sizeof(intptr_t) == 4 ? ((uint64_t)(x5)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x5)*((uintptr_t)4294967295ULL))>>64;
x8 = sizeof(intptr_t) == 4 ? ((uint64_t)(x5)*((uintptr_t)18446744073709551615ULL))>>32 : ((__uint128_t)(x5)*((uintptr_t)18446744073709551615ULL))>>64;
x9 = (x5)*((uintptr_t)18446744069414584320ULL);
x10 = sizeof(intptr_t) == 4 ? ((uint64_t)(x5)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x5)*((uintptr_t)18446744069414584320ULL))>>64;
x11 = (x10)+((x5)*((uintptr_t)18446744073709551615ULL));
x12 = ((x11)<(x10))+(x8);
x13 = (x12)+(x6);
x14 = ((x12)<(x8))+((x13)<(x6));
x15 = (((x4)+(x5))<(x4))+(x9);
x16 = ((x15)<(x9))+(x11);
x17 = ((x16)<(x11))+(x13);
x18 = (x17)<(x13);
x19 = (x15)+(x1);
x20 = ((x19)<(x15))+(x16);
x21 = ((x20)<(x16))+(x17);
x22 = (x21)<(x17);
x23 = (x19)*((uintptr_t)18446744073709551615ULL);
x24 = (x23)*((uintptr_t)4294967295ULL);
x25 = sizeof(intptr_t) == 4 ? ((uint64_t)(x23)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x23)*((uintptr_t)4294967295ULL))>>64;
x26 = sizeof(intptr_t) == 4 ? ((uint64_t)(x23)*((uintptr_t)18446744073709551615ULL))>>32 : ((__uint128_t)(x23)*((uintptr_t)18446744073709551615ULL))>>64;
x27 = (x23)*((uintptr_t)18446744069414584320ULL);
x28 = sizeof(intptr_t) == 4 ? ((uint64_t)(x23)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x23)*((uintptr_t)18446744069414584320ULL))>>64;
x29 = (x28)+((x23)*((uintptr_t)18446744073709551615ULL));
x30 = ((x29)<(x28))+(x26);
x31 = (x30)+(x24);
x32 = ((x30)<(x26))+((x31)<(x24));
x33 = (((x19)+(x23))<(x19))+(x20);
x34 = (x33)+(x27);
x35 = (((x33)<(x20))+((x34)<(x27)))+(x21);
x36 = (x35)+(x29);
x37 = (((x35)<(x21))+((x36)<(x29)))+((x22)+((x18)+((x14)+(x7))));
x38 = (x37)+(x31);
x39 = ((x37)<((x22)+((x18)+((x14)+(x7)))))+((x38)<(x31));
x40 = (x34)+(x2);
x41 = ((x40)<(x34))+(x36);
x42 = ((x41)<(x36))+(x38);
x43 = (x42)<(x38);
x44 = (x40)*((uintptr_t)18446744073709551615ULL);
x45 = (x44)*((uintptr_t)4294967295ULL);
x46 = sizeof(intptr_t) == 4 ? ((uint64_t)(x44)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x44)*((uintptr_t)4294967295ULL))>>64;
x47 = sizeof(intptr_t) == 4 ? ((uint64_t)(x44)*((uintptr_t)18446744073709551615ULL))>>32 : ((__uint128_t)(x44)*((uintptr_t)18446744073709551615ULL))>>64;
x48 = (x44)*((uintptr_t)18446744069414584320ULL);
x49 = sizeof(intptr_t) == 4 ? ((uint64_t)(x44)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x44)*((uintptr_t)18446744069414584320ULL))>>64;
x50 = (x49)+((x44)*((uintptr_t)18446744073709551615ULL));
x51 = ((x50)<(x49))+(x47);
x52 = (x51)+(x45);
x53 = ((x51)<(x47))+((x52)<(x45));
x54 = (((x40)+(x44))<(x40))+(x41);
x55 = (x54)+(x48);
x56 = (((x54)<(x41))+((x55)<(x48)))+(x42);
x57 = (x56)+(x50);
x58 = (((x56)<(x42))+((x57)<(x50)))+((x43)+((x39)+((x32)+(x25))));
x59 = (x58)+(x52);
x60 = ((x58)<((x43)+((x39)+((x32)+(x25)))))+((x59)<(x52));
x61 = (x55)+(x3);
x62 = ((x61)<(x55))+(x57);
x63 = ((x62)<(x57))+(x59);
x64 = (x63)<(x59);
x65 = (x61)*((uintptr_t)18446744073709551615ULL);
x66 = (x65)*((uintptr_t)4294967295ULL);
x67 = sizeof(intptr_t) == 4 ? ((uint64_t)(x65)*((uintptr_t)18446744073709551615ULL))>>32 : ((__uint128_t)(x65)*((uintptr_t)18446744073709551615ULL))>>64;
x68 = (x65)*((uintptr_t)18446744069414584320ULL);
x69 = sizeof(intptr_t) == 4 ? ((uint64_t)(x65)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x65)*((uintptr_t)18446744069414584320ULL))>>64;
x70 = (x69)+((x65)*((uintptr_t)18446744073709551615ULL));
x71 = ((x70)<(x69))+(x67);
x72 = (x71)+(x66);
x73 = (((x61)+(x65))<(x61))+(x62);
x74 = (x73)+(x68);
x75 = (((x73)<(x62))+((x74)<(x68)))+(x63);
x76 = (x75)+(x70);
x77 = (((x75)<(x63))+((x76)<(x70)))+((x64)+((x60)+((x53)+(x46))));
x78 = (x77)+(x72);
x79 = (((x77)<((x64)+((x60)+((x53)+(x46)))))+((x78)<(x72)))+((((x71)<(x67))+((x72)<(x66)))+(sizeof(intptr_t) == 4 ? ((uint64_t)(x65)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x65)*((uintptr_t)4294967295ULL))>>64));
x80 = (x74)-((uintptr_t)1ULL);
x81 = (x76)-((uintptr_t)18446744069414584320ULL);
x82 = (x81)-((x74)<(x80));
x83 = (x78)-((uintptr_t)18446744073709551615ULL);
x84 = (x83)-(((x76)<(x81))+((x81)<(x82)));
x85 = (x79)-((uintptr_t)4294967295ULL);
x86 = (x85)-(((x78)<(x83))+((x83)<(x84)));
x87 = ((uintptr_t)0ULL)<(((uintptr_t)0ULL)-(((x79)<(x85))+((x85)<(x86))));
x88 = ((uintptr_t)-1ULL)+((x87)==((uintptr_t)0ULL));
x89 = (x88)^((uintptr_t)18446744073709551615ULL);
x90 = ((x74)&(x88))|((x80)&(x89));
x91 = ((uintptr_t)-1ULL)+((x87)==((uintptr_t)0ULL));
x92 = (x91)^((uintptr_t)18446744073709551615ULL);
x93 = ((x76)&(x91))|((x82)&(x92));
x94 = ((uintptr_t)-1ULL)+((x87)==((uintptr_t)0ULL));
x95 = (x94)^((uintptr_t)18446744073709551615ULL);
x96 = ((x78)&(x94))|((x84)&(x95));
x97 = ((uintptr_t)-1ULL)+((x87)==((uintptr_t)0ULL));
x98 = (x97)^((uintptr_t)18446744073709551615ULL);
x99 = ((x79)&(x97))|((x86)&(x98));
x100 = x90;
x101 = x93;
x102 = x96;
x103 = x99;
/*skip*/
_br2_store((out0)+((uintptr_t)0ULL), x100, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)8ULL), x101, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)16ULL), x102, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)24ULL), x103, sizeof(uintptr_t));
/*skip*/
return;
}
/* NOTE: The following wrapper function is not covered by Coq proofs */
static void fiat_p224_from_montgomery(uint64_t out1[4], const uint64_t arg1[4]) {
internal_fiat_p224_from_montgomery((uintptr_t)out1, (uintptr_t)arg1);
}
/*
* Input Bounds:
* in0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static
void internal_fiat_p224_to_montgomery(uintptr_t out0, uintptr_t in0) {
uintptr_t x1, x2, x3, x0, x7, x14, x16, x12, x10, x18, x11, x8, x26, x28, x24, x22, x21, x13, x31, x15, x25, x33, x17, x27, x35, x19, x29, x43, x45, x42, x40, x47, x41, x38, x4, x32, x51, x34, x44, x53, x36, x46, x55, x37, x20, x9, x30, x23, x48, x63, x65, x61, x59, x58, x50, x68, x52, x62, x70, x54, x64, x72, x56, x66, x80, x82, x79, x77, x84, x78, x75, x5, x69, x88, x71, x81, x90, x73, x83, x92, x74, x57, x49, x39, x67, x60, x85, x100, x102, x98, x96, x95, x87, x105, x89, x99, x107, x91, x101, x109, x93, x103, x116, x118, x115, x113, x106, x123, x108, x117, x125, x110, x119, x133, x122, x137, x124, x132, x139, x126, x134, x141, x127, x111, x94, x86, x76, x104, x97, x128, x120, x114, x121, x112, x6, x135, x131, x136, x130, x129, x145, x147, x149, x138, x152, x144, x153, x140, x155, x146, x156, x142, x158, x148, x159, x151, x143, x161, x150, x162, x154, x157, x160, x163, x164, x165, x166, x167;
x0 = _br2_load((in0)+((uintptr_t)0ULL), sizeof(uintptr_t));
x1 = _br2_load((in0)+((uintptr_t)8ULL), sizeof(uintptr_t));
x2 = _br2_load((in0)+((uintptr_t)16ULL), sizeof(uintptr_t));
x3 = _br2_load((in0)+((uintptr_t)24ULL), sizeof(uintptr_t));
/*skip*/
/*skip*/
x4 = x1;
x5 = x2;
x6 = x3;
x7 = x0;
x8 = (x7)*((uintptr_t)4294967295ULL);
x9 = sizeof(intptr_t) == 4 ? ((uint64_t)(x7)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x7)*((uintptr_t)4294967295ULL))>>64;
x10 = (x7)*((uintptr_t)18446744065119617024ULL);
x11 = sizeof(intptr_t) == 4 ? ((uint64_t)(x7)*((uintptr_t)18446744065119617024ULL))>>32 : ((__uint128_t)(x7)*((uintptr_t)18446744065119617024ULL))>>64;
x12 = sizeof(intptr_t) == 4 ? ((uint64_t)(x7)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x7)*((uintptr_t)18446744069414584320ULL))>>64;
x13 = (x7)*((uintptr_t)18446744069414584321ULL);
x14 = sizeof(intptr_t) == 4 ? ((uint64_t)(x7)*((uintptr_t)18446744069414584321ULL))>>32 : ((__uint128_t)(x7)*((uintptr_t)18446744069414584321ULL))>>64;
x15 = (x14)+((x7)*((uintptr_t)18446744069414584320ULL));
x16 = ((x15)<(x14))+(x12);
x17 = (x16)+(x10);
x18 = (((x16)<(x12))+((x17)<(x10)))+(x11);
x19 = (x18)+(x8);
x20 = ((x18)<(x11))+((x19)<(x8));
x21 = (x13)*((uintptr_t)18446744073709551615ULL);
x22 = (x21)*((uintptr_t)4294967295ULL);
x23 = sizeof(intptr_t) == 4 ? ((uint64_t)(x21)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x21)*((uintptr_t)4294967295ULL))>>64;
x24 = sizeof(intptr_t) == 4 ? ((uint64_t)(x21)*((uintptr_t)18446744073709551615ULL))>>32 : ((__uint128_t)(x21)*((uintptr_t)18446744073709551615ULL))>>64;
x25 = (x21)*((uintptr_t)18446744069414584320ULL);
x26 = sizeof(intptr_t) == 4 ? ((uint64_t)(x21)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x21)*((uintptr_t)18446744069414584320ULL))>>64;
x27 = (x26)+((x21)*((uintptr_t)18446744073709551615ULL));
x28 = ((x27)<(x26))+(x24);
x29 = (x28)+(x22);
x30 = ((x28)<(x24))+((x29)<(x22));
x31 = (((x13)+(x21))<(x13))+(x15);
x32 = (x31)+(x25);
x33 = (((x31)<(x15))+((x32)<(x25)))+(x17);
x34 = (x33)+(x27);
x35 = (((x33)<(x17))+((x34)<(x27)))+(x19);
x36 = (x35)+(x29);
x37 = ((x35)<(x19))+((x36)<(x29));
x38 = (x4)*((uintptr_t)4294967295ULL);
x39 = sizeof(intptr_t) == 4 ? ((uint64_t)(x4)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x4)*((uintptr_t)4294967295ULL))>>64;
x40 = (x4)*((uintptr_t)18446744065119617024ULL);
x41 = sizeof(intptr_t) == 4 ? ((uint64_t)(x4)*((uintptr_t)18446744065119617024ULL))>>32 : ((__uint128_t)(x4)*((uintptr_t)18446744065119617024ULL))>>64;
x42 = sizeof(intptr_t) == 4 ? ((uint64_t)(x4)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x4)*((uintptr_t)18446744069414584320ULL))>>64;
x43 = sizeof(intptr_t) == 4 ? ((uint64_t)(x4)*((uintptr_t)18446744069414584321ULL))>>32 : ((__uint128_t)(x4)*((uintptr_t)18446744069414584321ULL))>>64;
x44 = (x43)+((x4)*((uintptr_t)18446744069414584320ULL));
x45 = ((x44)<(x43))+(x42);
x46 = (x45)+(x40);
x47 = (((x45)<(x42))+((x46)<(x40)))+(x41);
x48 = (x47)+(x38);
x49 = ((x47)<(x41))+((x48)<(x38));
x50 = (x32)+((x4)*((uintptr_t)18446744069414584321ULL));
x51 = ((x50)<(x32))+(x34);
x52 = (x51)+(x44);
x53 = (((x51)<(x34))+((x52)<(x44)))+(x36);
x54 = (x53)+(x46);
x55 = (((x53)<(x36))+((x54)<(x46)))+(((x37)+((x20)+(x9)))+((x30)+(x23)));
x56 = (x55)+(x48);
x57 = ((x55)<(((x37)+((x20)+(x9)))+((x30)+(x23))))+((x56)<(x48));
x58 = (x50)*((uintptr_t)18446744073709551615ULL);
x59 = (x58)*((uintptr_t)4294967295ULL);
x60 = sizeof(intptr_t) == 4 ? ((uint64_t)(x58)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x58)*((uintptr_t)4294967295ULL))>>64;
x61 = sizeof(intptr_t) == 4 ? ((uint64_t)(x58)*((uintptr_t)18446744073709551615ULL))>>32 : ((__uint128_t)(x58)*((uintptr_t)18446744073709551615ULL))>>64;
x62 = (x58)*((uintptr_t)18446744069414584320ULL);
x63 = sizeof(intptr_t) == 4 ? ((uint64_t)(x58)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x58)*((uintptr_t)18446744069414584320ULL))>>64;
x64 = (x63)+((x58)*((uintptr_t)18446744073709551615ULL));
x65 = ((x64)<(x63))+(x61);
x66 = (x65)+(x59);
x67 = ((x65)<(x61))+((x66)<(x59));
x68 = (((x50)+(x58))<(x50))+(x52);
x69 = (x68)+(x62);
x70 = (((x68)<(x52))+((x69)<(x62)))+(x54);
x71 = (x70)+(x64);
x72 = (((x70)<(x54))+((x71)<(x64)))+(x56);
x73 = (x72)+(x66);
x74 = ((x72)<(x56))+((x73)<(x66));
x75 = (x5)*((uintptr_t)4294967295ULL);
x76 = sizeof(intptr_t) == 4 ? ((uint64_t)(x5)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x5)*((uintptr_t)4294967295ULL))>>64;
x77 = (x5)*((uintptr_t)18446744065119617024ULL);
x78 = sizeof(intptr_t) == 4 ? ((uint64_t)(x5)*((uintptr_t)18446744065119617024ULL))>>32 : ((__uint128_t)(x5)*((uintptr_t)18446744065119617024ULL))>>64;
x79 = sizeof(intptr_t) == 4 ? ((uint64_t)(x5)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x5)*((uintptr_t)18446744069414584320ULL))>>64;
x80 = sizeof(intptr_t) == 4 ? ((uint64_t)(x5)*((uintptr_t)18446744069414584321ULL))>>32 : ((__uint128_t)(x5)*((uintptr_t)18446744069414584321ULL))>>64;
x81 = (x80)+((x5)*((uintptr_t)18446744069414584320ULL));
x82 = ((x81)<(x80))+(x79);
x83 = (x82)+(x77);
x84 = (((x82)<(x79))+((x83)<(x77)))+(x78);
x85 = (x84)+(x75);
x86 = ((x84)<(x78))+((x85)<(x75));
x87 = (x69)+((x5)*((uintptr_t)18446744069414584321ULL));
x88 = ((x87)<(x69))+(x71);
x89 = (x88)+(x81);
x90 = (((x88)<(x71))+((x89)<(x81)))+(x73);
x91 = (x90)+(x83);
x92 = (((x90)<(x73))+((x91)<(x83)))+(((x74)+((x57)+((x49)+(x39))))+((x67)+(x60)));
x93 = (x92)+(x85);
x94 = ((x92)<(((x74)+((x57)+((x49)+(x39))))+((x67)+(x60))))+((x93)<(x85));
x95 = (x87)*((uintptr_t)18446744073709551615ULL);
x96 = (x95)*((uintptr_t)4294967295ULL);
x97 = sizeof(intptr_t) == 4 ? ((uint64_t)(x95)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x95)*((uintptr_t)4294967295ULL))>>64;
x98 = sizeof(intptr_t) == 4 ? ((uint64_t)(x95)*((uintptr_t)18446744073709551615ULL))>>32 : ((__uint128_t)(x95)*((uintptr_t)18446744073709551615ULL))>>64;
x99 = (x95)*((uintptr_t)18446744069414584320ULL);
x100 = sizeof(intptr_t) == 4 ? ((uint64_t)(x95)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x95)*((uintptr_t)18446744069414584320ULL))>>64;
x101 = (x100)+((x95)*((uintptr_t)18446744073709551615ULL));
x102 = ((x101)<(x100))+(x98);
x103 = (x102)+(x96);
x104 = ((x102)<(x98))+((x103)<(x96));
x105 = (((x87)+(x95))<(x87))+(x89);
x106 = (x105)+(x99);
x107 = (((x105)<(x89))+((x106)<(x99)))+(x91);
x108 = (x107)+(x101);
x109 = (((x107)<(x91))+((x108)<(x101)))+(x93);
x110 = (x109)+(x103);
x111 = ((x109)<(x93))+((x110)<(x103));
x112 = (x6)*((uintptr_t)4294967295ULL);
x113 = (x6)*((uintptr_t)18446744065119617024ULL);
x114 = sizeof(intptr_t) == 4 ? ((uint64_t)(x6)*((uintptr_t)18446744065119617024ULL))>>32 : ((__uint128_t)(x6)*((uintptr_t)18446744065119617024ULL))>>64;
x115 = sizeof(intptr_t) == 4 ? ((uint64_t)(x6)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x6)*((uintptr_t)18446744069414584320ULL))>>64;
x116 = sizeof(intptr_t) == 4 ? ((uint64_t)(x6)*((uintptr_t)18446744069414584321ULL))>>32 : ((__uint128_t)(x6)*((uintptr_t)18446744069414584321ULL))>>64;
x117 = (x116)+((x6)*((uintptr_t)18446744069414584320ULL));
x118 = ((x117)<(x116))+(x115);
x119 = (x118)+(x113);
x120 = (((x118)<(x115))+((x119)<(x113)))+(x114);
x121 = (x120)+(x112);
x122 = (x106)+((x6)*((uintptr_t)18446744069414584321ULL));
x123 = ((x122)<(x106))+(x108);
x124 = (x123)+(x117);
x125 = (((x123)<(x108))+((x124)<(x117)))+(x110);
x126 = (x125)+(x119);
x127 = (((x125)<(x110))+((x126)<(x119)))+(((x111)+((x94)+((x86)+(x76))))+((x104)+(x97)));
x128 = (x127)+(x121);
x129 = (x122)*((uintptr_t)18446744073709551615ULL);
x130 = (x129)*((uintptr_t)4294967295ULL);
x131 = sizeof(intptr_t) == 4 ? ((uint64_t)(x129)*((uintptr_t)18446744073709551615ULL))>>32 : ((__uint128_t)(x129)*((uintptr_t)18446744073709551615ULL))>>64;
x132 = (x129)*((uintptr_t)18446744069414584320ULL);
x133 = sizeof(intptr_t) == 4 ? ((uint64_t)(x129)*((uintptr_t)18446744069414584320ULL))>>32 : ((__uint128_t)(x129)*((uintptr_t)18446744069414584320ULL))>>64;
x134 = (x133)+((x129)*((uintptr_t)18446744073709551615ULL));
x135 = ((x134)<(x133))+(x131);
x136 = (x135)+(x130);
x137 = (((x122)+(x129))<(x122))+(x124);
x138 = (x137)+(x132);
x139 = (((x137)<(x124))+((x138)<(x132)))+(x126);
x140 = (x139)+(x134);
x141 = (((x139)<(x126))+((x140)<(x134)))+(x128);
x142 = (x141)+(x136);
x143 = ((((x141)<(x128))+((x142)<(x136)))+((((x127)<(((x111)+((x94)+((x86)+(x76))))+((x104)+(x97))))+((x128)<(x121)))+((((x120)<(x114))+((x121)<(x112)))+(sizeof(intptr_t) == 4 ? ((uint64_t)(x6)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x6)*((uintptr_t)4294967295ULL))>>64))))+((((x135)<(x131))+((x136)<(x130)))+(sizeof(intptr_t) == 4 ? ((uint64_t)(x129)*((uintptr_t)4294967295ULL))>>32 : ((__uint128_t)(x129)*((uintptr_t)4294967295ULL))>>64));
x144 = (x138)-((uintptr_t)1ULL);
x145 = (x140)-((uintptr_t)18446744069414584320ULL);
x146 = (x145)-((x138)<(x144));
x147 = (x142)-((uintptr_t)18446744073709551615ULL);
x148 = (x147)-(((x140)<(x145))+((x145)<(x146)));
x149 = (x143)-((uintptr_t)4294967295ULL);
x150 = (x149)-(((x142)<(x147))+((x147)<(x148)));
x151 = ((uintptr_t)0ULL)<(((uintptr_t)0ULL)-(((x143)<(x149))+((x149)<(x150))));
x152 = ((uintptr_t)-1ULL)+((x151)==((uintptr_t)0ULL));
x153 = (x152)^((uintptr_t)18446744073709551615ULL);
x154 = ((x138)&(x152))|((x144)&(x153));
x155 = ((uintptr_t)-1ULL)+((x151)==((uintptr_t)0ULL));
x156 = (x155)^((uintptr_t)18446744073709551615ULL);
x157 = ((x140)&(x155))|((x146)&(x156));
x158 = ((uintptr_t)-1ULL)+((x151)==((uintptr_t)0ULL));
x159 = (x158)^((uintptr_t)18446744073709551615ULL);
x160 = ((x142)&(x158))|((x148)&(x159));
x161 = ((uintptr_t)-1ULL)+((x151)==((uintptr_t)0ULL));
x162 = (x161)^((uintptr_t)18446744073709551615ULL);
x163 = ((x143)&(x161))|((x150)&(x162));
x164 = x154;
x165 = x157;
x166 = x160;
x167 = x163;
/*skip*/
_br2_store((out0)+((uintptr_t)0ULL), x164, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)8ULL), x165, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)16ULL), x166, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)24ULL), x167, sizeof(uintptr_t));
/*skip*/
return;
}
/* NOTE: The following wrapper function is not covered by Coq proofs */
static void fiat_p224_to_montgomery(uint64_t out1[4], const uint64_t arg1[4]) {
internal_fiat_p224_to_montgomery((uintptr_t)out1, (uintptr_t)arg1);
}
/*
* Input Bounds:
* in0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out0: [0x0 ~> 0xffffffffffffffff]
*/
static
uintptr_t internal_fiat_p224_nonzero(uintptr_t in0) {
uintptr_t x0, x1, x2, x3, x4, out0, x5;
x0 = _br2_load((in0)+((uintptr_t)0ULL), sizeof(uintptr_t));
x1 = _br2_load((in0)+((uintptr_t)8ULL), sizeof(uintptr_t));
x2 = _br2_load((in0)+((uintptr_t)16ULL), sizeof(uintptr_t));
x3 = _br2_load((in0)+((uintptr_t)24ULL), sizeof(uintptr_t));
/*skip*/
/*skip*/
x4 = (x0)|((x1)|((x2)|(x3)));
x5 = x4;
out0 = x5;
return out0;
}
/* NOTE: The following wrapper function is not covered by Coq proofs */
static void fiat_p224_nonzero(uint64_t* out1, const uint64_t arg1[4]) {
*out1 = (uint64_t)internal_fiat_p224_nonzero((uintptr_t)arg1);
}
/*
* Input Bounds:
* in0: [0x0 ~> 0x1]
* in1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* in2: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static
void internal_fiat_p224_selectznz(uintptr_t out0, uintptr_t in0, uintptr_t in1, uintptr_t in2) {
uintptr_t x4, x8, x0, x9, x5, x11, x1, x12, x6, x14, x2, x15, x7, x17, x3, x18, x10, x13, x16, x19, x20, x21, x22, x23;
/*skip*/
x0 = _br2_load((in1)+((uintptr_t)0ULL), sizeof(uintptr_t));
x1 = _br2_load((in1)+((uintptr_t)8ULL), sizeof(uintptr_t));
x2 = _br2_load((in1)+((uintptr_t)16ULL), sizeof(uintptr_t));
x3 = _br2_load((in1)+((uintptr_t)24ULL), sizeof(uintptr_t));
/*skip*/
x4 = _br2_load((in2)+((uintptr_t)0ULL), sizeof(uintptr_t));
x5 = _br2_load((in2)+((uintptr_t)8ULL), sizeof(uintptr_t));
x6 = _br2_load((in2)+((uintptr_t)16ULL), sizeof(uintptr_t));
x7 = _br2_load((in2)+((uintptr_t)24ULL), sizeof(uintptr_t));
/*skip*/
/*skip*/
x8 = ((uintptr_t)-1ULL)+((in0)==((uintptr_t)0ULL));
x9 = (x8)^((uintptr_t)18446744073709551615ULL);
x10 = ((x4)&(x8))|((x0)&(x9));
x11 = ((uintptr_t)-1ULL)+((in0)==((uintptr_t)0ULL));
x12 = (x11)^((uintptr_t)18446744073709551615ULL);
x13 = ((x5)&(x11))|((x1)&(x12));
x14 = ((uintptr_t)-1ULL)+((in0)==((uintptr_t)0ULL));
x15 = (x14)^((uintptr_t)18446744073709551615ULL);
x16 = ((x6)&(x14))|((x2)&(x15));
x17 = ((uintptr_t)-1ULL)+((in0)==((uintptr_t)0ULL));
x18 = (x17)^((uintptr_t)18446744073709551615ULL);
x19 = ((x7)&(x17))|((x3)&(x18));
x20 = x10;
x21 = x13;
x22 = x16;
x23 = x19;
/*skip*/
_br2_store((out0)+((uintptr_t)0ULL), x20, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)8ULL), x21, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)16ULL), x22, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)24ULL), x23, sizeof(uintptr_t));
/*skip*/
return;
}
/* NOTE: The following wrapper function is not covered by Coq proofs */
static void fiat_p224_selectznz(uint64_t out1[4], uint8_t arg1, const uint64_t arg2[4], const uint64_t arg3[4]) {
internal_fiat_p224_selectznz((uintptr_t)out1, (uintptr_t)arg1, (uintptr_t)arg2, (uintptr_t)arg3);
}
/*
* Input Bounds:
* in0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffff]]
* Output Bounds:
* out0: [[0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff]]
*/
static
void internal_fiat_p224_to_bytes(uintptr_t out0, uintptr_t in0) {
uintptr_t x3, x2, x1, x0, x7, x9, x11, x13, x15, x17, x19, x6, x23, x25, x27, x29, x31, x33, x5, x37, x39, x41, x43, x45, x47, x4, x51, x53, x8, x10, x12, x14, x16, x18, x20, x21, x22, x24, x26, x28, x30, x32, x34, x35, x36, x38, x40, x42, x44, x46, x48, x49, x50, x52, x54, x55, x56, x57, x58, x59, x60, x61, x62, x63, x64, x65, x66, x67, x68, x69, x70, x71, x72, x73, x74, x75, x76, x77, x78, x79, x80, x81, x82, x83;
x0 = _br2_load((in0)+((uintptr_t)0ULL), sizeof(uintptr_t));
x1 = _br2_load((in0)+((uintptr_t)8ULL), sizeof(uintptr_t));
x2 = _br2_load((in0)+((uintptr_t)16ULL), sizeof(uintptr_t));
x3 = _br2_load((in0)+((uintptr_t)24ULL), sizeof(uintptr_t));
/*skip*/
/*skip*/
x4 = x3;
x5 = x2;
x6 = x1;
x7 = x0;
x8 = (x7)&((uintptr_t)255ULL);
x9 = (x7)>>((uintptr_t)8ULL);
x10 = (x9)&((uintptr_t)255ULL);
x11 = (x9)>>((uintptr_t)8ULL);
x12 = (x11)&((uintptr_t)255ULL);
x13 = (x11)>>((uintptr_t)8ULL);
x14 = (x13)&((uintptr_t)255ULL);
x15 = (x13)>>((uintptr_t)8ULL);
x16 = (x15)&((uintptr_t)255ULL);
x17 = (x15)>>((uintptr_t)8ULL);
x18 = (x17)&((uintptr_t)255ULL);
x19 = (x17)>>((uintptr_t)8ULL);
x20 = (x19)&((uintptr_t)255ULL);
x21 = (x19)>>((uintptr_t)8ULL);
x22 = (x6)&((uintptr_t)255ULL);
x23 = (x6)>>((uintptr_t)8ULL);
x24 = (x23)&((uintptr_t)255ULL);
x25 = (x23)>>((uintptr_t)8ULL);
x26 = (x25)&((uintptr_t)255ULL);
x27 = (x25)>>((uintptr_t)8ULL);
x28 = (x27)&((uintptr_t)255ULL);
x29 = (x27)>>((uintptr_t)8ULL);
x30 = (x29)&((uintptr_t)255ULL);
x31 = (x29)>>((uintptr_t)8ULL);
x32 = (x31)&((uintptr_t)255ULL);
x33 = (x31)>>((uintptr_t)8ULL);
x34 = (x33)&((uintptr_t)255ULL);
x35 = (x33)>>((uintptr_t)8ULL);
x36 = (x5)&((uintptr_t)255ULL);
x37 = (x5)>>((uintptr_t)8ULL);
x38 = (x37)&((uintptr_t)255ULL);
x39 = (x37)>>((uintptr_t)8ULL);
x40 = (x39)&((uintptr_t)255ULL);
x41 = (x39)>>((uintptr_t)8ULL);
x42 = (x41)&((uintptr_t)255ULL);
x43 = (x41)>>((uintptr_t)8ULL);
x44 = (x43)&((uintptr_t)255ULL);
x45 = (x43)>>((uintptr_t)8ULL);
x46 = (x45)&((uintptr_t)255ULL);
x47 = (x45)>>((uintptr_t)8ULL);
x48 = (x47)&((uintptr_t)255ULL);
x49 = (x47)>>((uintptr_t)8ULL);
x50 = (x4)&((uintptr_t)255ULL);
x51 = (x4)>>((uintptr_t)8ULL);
x52 = (x51)&((uintptr_t)255ULL);
x53 = (x51)>>((uintptr_t)8ULL);
x54 = (x53)&((uintptr_t)255ULL);
x55 = (x53)>>((uintptr_t)8ULL);
x56 = x8;
x57 = x10;
x58 = x12;
x59 = x14;
x60 = x16;
x61 = x18;
x62 = x20;
x63 = x21;
x64 = x22;
x65 = x24;
x66 = x26;
x67 = x28;
x68 = x30;
x69 = x32;
x70 = x34;
x71 = x35;
x72 = x36;
x73 = x38;
x74 = x40;
x75 = x42;
x76 = x44;
x77 = x46;
x78 = x48;
x79 = x49;
x80 = x50;
x81 = x52;
x82 = x54;
x83 = x55;
/*skip*/
_br2_store((out0)+((uintptr_t)0ULL), x56, 1);
_br2_store((out0)+((uintptr_t)1ULL), x57, 1);
_br2_store((out0)+((uintptr_t)2ULL), x58, 1);
_br2_store((out0)+((uintptr_t)3ULL), x59, 1);
_br2_store((out0)+((uintptr_t)4ULL), x60, 1);
_br2_store((out0)+((uintptr_t)5ULL), x61, 1);
_br2_store((out0)+((uintptr_t)6ULL), x62, 1);
_br2_store((out0)+((uintptr_t)7ULL), x63, 1);
_br2_store((out0)+((uintptr_t)8ULL), x64, 1);
_br2_store((out0)+((uintptr_t)9ULL), x65, 1);
_br2_store((out0)+((uintptr_t)10ULL), x66, 1);
_br2_store((out0)+((uintptr_t)11ULL), x67, 1);
_br2_store((out0)+((uintptr_t)12ULL), x68, 1);
_br2_store((out0)+((uintptr_t)13ULL), x69, 1);
_br2_store((out0)+((uintptr_t)14ULL), x70, 1);
_br2_store((out0)+((uintptr_t)15ULL), x71, 1);
_br2_store((out0)+((uintptr_t)16ULL), x72, 1);
_br2_store((out0)+((uintptr_t)17ULL), x73, 1);
_br2_store((out0)+((uintptr_t)18ULL), x74, 1);
_br2_store((out0)+((uintptr_t)19ULL), x75, 1);
_br2_store((out0)+((uintptr_t)20ULL), x76, 1);
_br2_store((out0)+((uintptr_t)21ULL), x77, 1);
_br2_store((out0)+((uintptr_t)22ULL), x78, 1);
_br2_store((out0)+((uintptr_t)23ULL), x79, 1);
_br2_store((out0)+((uintptr_t)24ULL), x80, 1);
_br2_store((out0)+((uintptr_t)25ULL), x81, 1);
_br2_store((out0)+((uintptr_t)26ULL), x82, 1);
_br2_store((out0)+((uintptr_t)27ULL), x83, 1);
/*skip*/
return;
}
/* NOTE: The following wrapper function is not covered by Coq proofs */
static void fiat_p224_to_bytes(uint8_t out1[28], const uint64_t arg1[4]) {
internal_fiat_p224_to_bytes((uintptr_t)out1, (uintptr_t)arg1);
}
/*
* Input Bounds:
* in0: [[0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff]]
* Output Bounds:
* out0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffff]]
*/
static
void internal_fiat_p224_from_bytes(uintptr_t out0, uintptr_t in0) {
uintptr_t x27, x26, x25, x24, x23, x22, x21, x20, x19, x18, x17, x16, x15, x14, x13, x12, x11, x10, x9, x8, x7, x6, x5, x4, x3, x2, x1, x0, x54, x55, x53, x56, x52, x57, x51, x58, x50, x59, x49, x60, x48, x61, x46, x47, x45, x63, x44, x64, x43, x65, x42, x66, x41, x67, x40, x68, x38, x39, x37, x70, x36, x71, x35, x72, x34, x73, x33, x74, x32, x75, x30, x31, x29, x77, x28, x78, x62, x69, x76, x79, x80, x81, x82, x83;
x0 = _br2_load((in0)+((uintptr_t)0ULL), 1);
x1 = _br2_load((in0)+((uintptr_t)1ULL), 1);
x2 = _br2_load((in0)+((uintptr_t)2ULL), 1);
x3 = _br2_load((in0)+((uintptr_t)3ULL), 1);
x4 = _br2_load((in0)+((uintptr_t)4ULL), 1);
x5 = _br2_load((in0)+((uintptr_t)5ULL), 1);
x6 = _br2_load((in0)+((uintptr_t)6ULL), 1);
x7 = _br2_load((in0)+((uintptr_t)7ULL), 1);
x8 = _br2_load((in0)+((uintptr_t)8ULL), 1);
x9 = _br2_load((in0)+((uintptr_t)9ULL), 1);
x10 = _br2_load((in0)+((uintptr_t)10ULL), 1);
x11 = _br2_load((in0)+((uintptr_t)11ULL), 1);
x12 = _br2_load((in0)+((uintptr_t)12ULL), 1);
x13 = _br2_load((in0)+((uintptr_t)13ULL), 1);
x14 = _br2_load((in0)+((uintptr_t)14ULL), 1);
x15 = _br2_load((in0)+((uintptr_t)15ULL), 1);
x16 = _br2_load((in0)+((uintptr_t)16ULL), 1);
x17 = _br2_load((in0)+((uintptr_t)17ULL), 1);
x18 = _br2_load((in0)+((uintptr_t)18ULL), 1);
x19 = _br2_load((in0)+((uintptr_t)19ULL), 1);
x20 = _br2_load((in0)+((uintptr_t)20ULL), 1);
x21 = _br2_load((in0)+((uintptr_t)21ULL), 1);
x22 = _br2_load((in0)+((uintptr_t)22ULL), 1);
x23 = _br2_load((in0)+((uintptr_t)23ULL), 1);
x24 = _br2_load((in0)+((uintptr_t)24ULL), 1);
x25 = _br2_load((in0)+((uintptr_t)25ULL), 1);
x26 = _br2_load((in0)+((uintptr_t)26ULL), 1);
x27 = _br2_load((in0)+((uintptr_t)27ULL), 1);
/*skip*/
/*skip*/
x28 = (x27)<<((uintptr_t)24ULL);
x29 = (x26)<<((uintptr_t)16ULL);
x30 = (x25)<<((uintptr_t)8ULL);
x31 = x24;
x32 = (x23)<<((uintptr_t)56ULL);
x33 = (x22)<<((uintptr_t)48ULL);
x34 = (x21)<<((uintptr_t)40ULL);
x35 = (x20)<<((uintptr_t)32ULL);
x36 = (x19)<<((uintptr_t)24ULL);
x37 = (x18)<<((uintptr_t)16ULL);
x38 = (x17)<<((uintptr_t)8ULL);
x39 = x16;
x40 = (x15)<<((uintptr_t)56ULL);
x41 = (x14)<<((uintptr_t)48ULL);
x42 = (x13)<<((uintptr_t)40ULL);
x43 = (x12)<<((uintptr_t)32ULL);
x44 = (x11)<<((uintptr_t)24ULL);
x45 = (x10)<<((uintptr_t)16ULL);
x46 = (x9)<<((uintptr_t)8ULL);
x47 = x8;
x48 = (x7)<<((uintptr_t)56ULL);
x49 = (x6)<<((uintptr_t)48ULL);
x50 = (x5)<<((uintptr_t)40ULL);
x51 = (x4)<<((uintptr_t)32ULL);
x52 = (x3)<<((uintptr_t)24ULL);
x53 = (x2)<<((uintptr_t)16ULL);
x54 = (x1)<<((uintptr_t)8ULL);
x55 = x0;
x56 = (x54)+(x55);
x57 = (x53)+(x56);
x58 = (x52)+(x57);
x59 = (x51)+(x58);
x60 = (x50)+(x59);
x61 = (x49)+(x60);
x62 = (x48)+(x61);
x63 = (x46)+(x47);
x64 = (x45)+(x63);
x65 = (x44)+(x64);
x66 = (x43)+(x65);
x67 = (x42)+(x66);
x68 = (x41)+(x67);
x69 = (x40)+(x68);
x70 = (x38)+(x39);
x71 = (x37)+(x70);
x72 = (x36)+(x71);
x73 = (x35)+(x72);
x74 = (x34)+(x73);
x75 = (x33)+(x74);
x76 = (x32)+(x75);
x77 = (x30)+(x31);
x78 = (x29)+(x77);
x79 = (x28)+(x78);
x80 = x62;
x81 = x69;
x82 = x76;
x83 = x79;
/*skip*/
_br2_store((out0)+((uintptr_t)0ULL), x80, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)8ULL), x81, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)16ULL), x82, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)24ULL), x83, sizeof(uintptr_t));
/*skip*/
return;
}
/* NOTE: The following wrapper function is not covered by Coq proofs */
static void fiat_p224_from_bytes(uint64_t out1[4], const uint8_t arg1[28]) {
internal_fiat_p224_from_bytes((uintptr_t)out1, (uintptr_t)arg1);
}
/*
* Input Bounds:
* Output Bounds:
* out0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static
void internal_fiat_p224_set_one(uintptr_t out0) {
uintptr_t x0, x1, x2, x3;
/*skip*/
x0 = (uintptr_t)18446744069414584320ULL;
x1 = (uintptr_t)18446744073709551615ULL;
x2 = (uintptr_t)0ULL;
x3 = (uintptr_t)0ULL;
/*skip*/
_br2_store((out0)+((uintptr_t)0ULL), x0, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)8ULL), x1, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)16ULL), x2, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)24ULL), x3, sizeof(uintptr_t));
/*skip*/
return;
}
/* NOTE: The following wrapper function is not covered by Coq proofs */
static void fiat_p224_set_one(uint64_t out1[4]) {
internal_fiat_p224_set_one((uintptr_t)out1);
}
/*
* Input Bounds:
* Output Bounds:
* out0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static
void internal_fiat_p224_msat(uintptr_t out0) {
uintptr_t x0, x1, x2, x3, x4;
/*skip*/
x0 = (uintptr_t)1ULL;
x1 = (uintptr_t)18446744069414584320ULL;
x2 = (uintptr_t)18446744073709551615ULL;
x3 = (uintptr_t)4294967295ULL;
x4 = (uintptr_t)0ULL;
/*skip*/
_br2_store((out0)+((uintptr_t)0ULL), x0, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)8ULL), x1, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)16ULL), x2, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)24ULL), x3, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)32ULL), x4, sizeof(uintptr_t));
/*skip*/
return;
}
/* NOTE: The following wrapper function is not covered by Coq proofs */
static void fiat_p224_msat(uint64_t out1[5]) {
internal_fiat_p224_msat((uintptr_t)out1);
}
/*
* Input Bounds:
* in0: [0x0 ~> 0xffffffffffffffff]
* in1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* in2: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* in3: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* in4: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out0: [0x0 ~> 0xffffffffffffffff]
* out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* out2: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* out3: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* out4: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static
uintptr_t internal_fiat_p224_divstep(uintptr_t out1, uintptr_t out2, uintptr_t out3, uintptr_t out4, uintptr_t in0, uintptr_t in1, uintptr_t in2, uintptr_t in3, uintptr_t in4) {
uintptr_t x18, x20, x21, x22, x24, x25, x27, x28, x30, x31, x33, x34, x36, x37, x0, x40, x1, x42, x2, x44, x3, x46, x4, x39, x48, x5, x49, x41, x51, x6, x52, x43, x54, x7, x55, x45, x57, x8, x58, x47, x60, x9, x61, x63, x64, x66, x67, x69, x70, x72, x73, x76, x77, x78, x80, x81, x82, x83, x85, x86, x87, x88, x90, x93, x94, x95, x97, x98, x99, x100, x102, x103, x104, x105, x107, x108, x91, x109, x13, x12, x11, x10, x115, x113, x116, x118, x119, x112, x120, x122, x123, x111, x124, x126, x127, x114, x130, x117, x131, x132, x134, x135, x121, x136, x137, x139, x140, x125, x141, x128, x129, x143, x14, x144, x133, x146, x15, x147, x138, x149, x16, x150, x19, x142, x152, x17, x153, x156, x157, x159, x160, x162, x163, x165, x166, x168, x169, x158, x50, x172, x53, x173, x161, x174, x176, x177, x56, x178, x164, x179, x181, x182, x59, x183, x167, x184, x186, x187, x62, x188, x170, x65, x190, x191, x68, x193, x194, x71, x196, x197, x155, x74, x199, x200, x192, x145, x203, x148, x204, x195, x205, x207, x208, x151, x209, x198, x210, x212, x213, x154, x214, x201, x215, x217, x220, x221, x222, x224, x225, x226, x227, x229, x230, x231, x232, x234, x235, x218, x236, x23, x171, x175, x180, x185, x189, x75, x244, x92, x245, x79, x247, x96, x248, x84, x250, x101, x251, x110, x89, x253, x106, x254, x202, x256, x219, x257, x206, x259, x223, x260, x211, x262, x228, x263, x237, x216, x265, x233, x266, x238, x26, x29, x32, x35, x38, x239, x240, x241, x242, x243, x246, x249, x252, x255, x258, x261, x264, x267, out0, x268, x269, x270, x271, x272, x273, x274, x275, x276, x277, x278, x279, x280, x281, x282, x283, x284, x285, x286;
/*skip*/
x0 = _br2_load((in1)+((uintptr_t)0ULL), sizeof(uintptr_t));
x1 = _br2_load((in1)+((uintptr_t)8ULL), sizeof(uintptr_t));
x2 = _br2_load((in1)+((uintptr_t)16ULL), sizeof(uintptr_t));
x3 = _br2_load((in1)+((uintptr_t)24ULL), sizeof(uintptr_t));
x4 = _br2_load((in1)+((uintptr_t)32ULL), sizeof(uintptr_t));
/*skip*/
x5 = _br2_load((in2)+((uintptr_t)0ULL), sizeof(uintptr_t));
x6 = _br2_load((in2)+((uintptr_t)8ULL), sizeof(uintptr_t));
x7 = _br2_load((in2)+((uintptr_t)16ULL), sizeof(uintptr_t));
x8 = _br2_load((in2)+((uintptr_t)24ULL), sizeof(uintptr_t));
x9 = _br2_load((in2)+((uintptr_t)32ULL), sizeof(uintptr_t));
/*skip*/
x10 = _br2_load((in3)+((uintptr_t)0ULL), sizeof(uintptr_t));
x11 = _br2_load((in3)+((uintptr_t)8ULL), sizeof(uintptr_t));
x12 = _br2_load((in3)+((uintptr_t)16ULL), sizeof(uintptr_t));
x13 = _br2_load((in3)+((uintptr_t)24ULL), sizeof(uintptr_t));
/*skip*/
x14 = _br2_load((in4)+((uintptr_t)0ULL), sizeof(uintptr_t));
x15 = _br2_load((in4)+((uintptr_t)8ULL), sizeof(uintptr_t));
x16 = _br2_load((in4)+((uintptr_t)16ULL), sizeof(uintptr_t));
x17 = _br2_load((in4)+((uintptr_t)24ULL), sizeof(uintptr_t));
/*skip*/
/*skip*/
x18 = ((in0)^((uintptr_t)18446744073709551615ULL))+((uintptr_t)1ULL);
x19 = ((x18)>>((uintptr_t)63ULL))&((x5)&((uintptr_t)1ULL));
x20 = ((in0)^((uintptr_t)18446744073709551615ULL))+((uintptr_t)1ULL);
x21 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x22 = (x21)^((uintptr_t)18446744073709551615ULL);
x23 = ((x20)&(x21))|((in0)&(x22));
x24 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x25 = (x24)^((uintptr_t)18446744073709551615ULL);
x26 = ((x5)&(x24))|((x0)&(x25));
x27 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x28 = (x27)^((uintptr_t)18446744073709551615ULL);
x29 = ((x6)&(x27))|((x1)&(x28));
x30 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x31 = (x30)^((uintptr_t)18446744073709551615ULL);
x32 = ((x7)&(x30))|((x2)&(x31));
x33 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x34 = (x33)^((uintptr_t)18446744073709551615ULL);
x35 = ((x8)&(x33))|((x3)&(x34));
x36 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x37 = (x36)^((uintptr_t)18446744073709551615ULL);
x38 = ((x9)&(x36))|((x4)&(x37));
x39 = ((uintptr_t)1ULL)+((x0)^((uintptr_t)18446744073709551615ULL));
x40 = (x39)<((uintptr_t)1ULL);
x41 = (x40)+((x1)^((uintptr_t)18446744073709551615ULL));
x42 = (x41)<((x1)^((uintptr_t)18446744073709551615ULL));
x43 = (x42)+((x2)^((uintptr_t)18446744073709551615ULL));
x44 = (x43)<((x2)^((uintptr_t)18446744073709551615ULL));
x45 = (x44)+((x3)^((uintptr_t)18446744073709551615ULL));
x46 = (x45)<((x3)^((uintptr_t)18446744073709551615ULL));
x47 = (x46)+((x4)^((uintptr_t)18446744073709551615ULL));
x48 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x49 = (x48)^((uintptr_t)18446744073709551615ULL);
x50 = ((x39)&(x48))|((x5)&(x49));
x51 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x52 = (x51)^((uintptr_t)18446744073709551615ULL);
x53 = ((x41)&(x51))|((x6)&(x52));
x54 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x55 = (x54)^((uintptr_t)18446744073709551615ULL);
x56 = ((x43)&(x54))|((x7)&(x55));
x57 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x58 = (x57)^((uintptr_t)18446744073709551615ULL);
x59 = ((x45)&(x57))|((x8)&(x58));
x60 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x61 = (x60)^((uintptr_t)18446744073709551615ULL);
x62 = ((x47)&(x60))|((x9)&(x61));
x63 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x64 = (x63)^((uintptr_t)18446744073709551615ULL);
x65 = ((x14)&(x63))|((x10)&(x64));
x66 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x67 = (x66)^((uintptr_t)18446744073709551615ULL);
x68 = ((x15)&(x66))|((x11)&(x67));
x69 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x70 = (x69)^((uintptr_t)18446744073709551615ULL);
x71 = ((x16)&(x69))|((x12)&(x70));
x72 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x73 = (x72)^((uintptr_t)18446744073709551615ULL);
x74 = ((x17)&(x72))|((x13)&(x73));
x75 = (x65)+(x65);
x76 = (x75)<(x65);
x77 = (x76)+(x68);
x78 = (x77)<(x68);
x79 = (x77)+(x68);
x80 = (x79)<(x68);
x81 = (x78)+(x80);
x82 = (x81)+(x71);
x83 = (x82)<(x71);
x84 = (x82)+(x71);
x85 = (x84)<(x71);
x86 = (x83)+(x85);
x87 = (x86)+(x74);
x88 = (x87)<(x74);
x89 = (x87)+(x74);
x90 = (x89)<(x74);
x91 = (x88)+(x90);
x92 = (x75)-((uintptr_t)1ULL);
x93 = (x75)<(x92);
x94 = (x79)-((uintptr_t)18446744069414584320ULL);
x95 = (x79)<(x94);
x96 = (x94)-(x93);
x97 = (x94)<(x96);
x98 = (x95)+(x97);
x99 = (x84)-((uintptr_t)18446744073709551615ULL);
x100 = (x84)<(x99);
x101 = (x99)-(x98);
x102 = (x99)<(x101);
x103 = (x100)+(x102);
x104 = (x89)-((uintptr_t)4294967295ULL);
x105 = (x89)<(x104);
x106 = (x104)-(x103);
x107 = (x104)<(x106);
x108 = (x105)+(x107);
x109 = (x91)-(x108);
x110 = (x91)<(x109);
x111 = x13;
x112 = x12;
x113 = x11;
x114 = x10;
x115 = ((uintptr_t)0ULL)<(((uintptr_t)0ULL)-(x114));
x116 = ((uintptr_t)0ULL)<(((uintptr_t)0ULL)-(x113));
x117 = (((uintptr_t)0ULL)-(x113))-(x115);
x118 = (((uintptr_t)0ULL)-(x113))<(x117);
x119 = (x116)+(x118);
x120 = ((uintptr_t)0ULL)<(((uintptr_t)0ULL)-(x112));
x121 = (((uintptr_t)0ULL)-(x112))-(x119);
x122 = (((uintptr_t)0ULL)-(x112))<(x121);
x123 = (x120)+(x122);
x124 = ((uintptr_t)0ULL)<(((uintptr_t)0ULL)-(x111));
x125 = (((uintptr_t)0ULL)-(x111))-(x123);
x126 = (((uintptr_t)0ULL)-(x111))<(x125);
x127 = (x124)+(x126);
x128 = ((uintptr_t)-1ULL)+((x127)==((uintptr_t)0ULL));
x129 = (((uintptr_t)0ULL)-(x114))+((x128)&((uintptr_t)1ULL));
x130 = (x129)<(((uintptr_t)0ULL)-(x114));
x131 = (x130)+(x117);
x132 = (x131)<(x117);
x133 = (x131)+((x128)&((uintptr_t)18446744069414584320ULL));
x134 = (x133)<((x128)&((uintptr_t)18446744069414584320ULL));
x135 = (x132)+(x134);
x136 = (x135)+(x121);
x137 = (x136)<(x121);
x138 = (x136)+(x128);
x139 = (x138)<(x128);
x140 = (x137)+(x139);
x141 = (x140)+(x125);
x142 = (x141)+((x128)&((uintptr_t)4294967295ULL));
x143 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x144 = (x143)^((uintptr_t)18446744073709551615ULL);
x145 = ((x129)&(x143))|((x14)&(x144));
x146 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x147 = (x146)^((uintptr_t)18446744073709551615ULL);
x148 = ((x133)&(x146))|((x15)&(x147));
x149 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x150 = (x149)^((uintptr_t)18446744073709551615ULL);
x151 = ((x138)&(x149))|((x16)&(x150));
x152 = ((uintptr_t)-1ULL)+((x19)==((uintptr_t)0ULL));
x153 = (x152)^((uintptr_t)18446744073709551615ULL);
x154 = ((x142)&(x152))|((x17)&(x153));
x155 = (x50)&((uintptr_t)1ULL);
x156 = ((uintptr_t)-1ULL)+((x155)==((uintptr_t)0ULL));
x157 = (x156)^((uintptr_t)18446744073709551615ULL);
x158 = ((x26)&(x156))|(((uintptr_t)0ULL)&(x157));
x159 = ((uintptr_t)-1ULL)+((x155)==((uintptr_t)0ULL));
x160 = (x159)^((uintptr_t)18446744073709551615ULL);
x161 = ((x29)&(x159))|(((uintptr_t)0ULL)&(x160));
x162 = ((uintptr_t)-1ULL)+((x155)==((uintptr_t)0ULL));
x163 = (x162)^((uintptr_t)18446744073709551615ULL);
x164 = ((x32)&(x162))|(((uintptr_t)0ULL)&(x163));
x165 = ((uintptr_t)-1ULL)+((x155)==((uintptr_t)0ULL));
x166 = (x165)^((uintptr_t)18446744073709551615ULL);
x167 = ((x35)&(x165))|(((uintptr_t)0ULL)&(x166));
x168 = ((uintptr_t)-1ULL)+((x155)==((uintptr_t)0ULL));
x169 = (x168)^((uintptr_t)18446744073709551615ULL);
x170 = ((x38)&(x168))|(((uintptr_t)0ULL)&(x169));
x171 = (x50)+(x158);
x172 = (x171)<(x50);
x173 = (x172)+(x53);
x174 = (x173)<(x53);
x175 = (x173)+(x161);
x176 = (x175)<(x161);
x177 = (x174)+(x176);
x178 = (x177)+(x56);
x179 = (x178)<(x56);
x180 = (x178)+(x164);
x181 = (x180)<(x164);
x182 = (x179)+(x181);
x183 = (x182)+(x59);
x184 = (x183)<(x59);
x185 = (x183)+(x167);
x186 = (x185)<(x167);
x187 = (x184)+(x186);
x188 = (x187)+(x62);
x189 = (x188)+(x170);
x190 = ((uintptr_t)-1ULL)+((x155)==((uintptr_t)0ULL));
x191 = (x190)^((uintptr_t)18446744073709551615ULL);
x192 = ((x65)&(x190))|(((uintptr_t)0ULL)&(x191));
x193 = ((uintptr_t)-1ULL)+((x155)==((uintptr_t)0ULL));
x194 = (x193)^((uintptr_t)18446744073709551615ULL);
x195 = ((x68)&(x193))|(((uintptr_t)0ULL)&(x194));
x196 = ((uintptr_t)-1ULL)+((x155)==((uintptr_t)0ULL));
x197 = (x196)^((uintptr_t)18446744073709551615ULL);
x198 = ((x71)&(x196))|(((uintptr_t)0ULL)&(x197));
x199 = ((uintptr_t)-1ULL)+((x155)==((uintptr_t)0ULL));
x200 = (x199)^((uintptr_t)18446744073709551615ULL);
x201 = ((x74)&(x199))|(((uintptr_t)0ULL)&(x200));
x202 = (x145)+(x192);
x203 = (x202)<(x145);
x204 = (x203)+(x148);
x205 = (x204)<(x148);
x206 = (x204)+(x195);
x207 = (x206)<(x195);
x208 = (x205)+(x207);
x209 = (x208)+(x151);
x210 = (x209)<(x151);
x211 = (x209)+(x198);
x212 = (x211)<(x198);
x213 = (x210)+(x212);
x214 = (x213)+(x154);
x215 = (x214)<(x154);
x216 = (x214)+(x201);
x217 = (x216)<(x201);
x218 = (x215)+(x217);
x219 = (x202)-((uintptr_t)1ULL);
x220 = (x202)<(x219);
x221 = (x206)-((uintptr_t)18446744069414584320ULL);
x222 = (x206)<(x221);
x223 = (x221)-(x220);
x224 = (x221)<(x223);
x225 = (x222)+(x224);
x226 = (x211)-((uintptr_t)18446744073709551615ULL);
x227 = (x211)<(x226);
x228 = (x226)-(x225);
x229 = (x226)<(x228);
x230 = (x227)+(x229);
x231 = (x216)-((uintptr_t)4294967295ULL);
x232 = (x216)<(x231);
x233 = (x231)-(x230);
x234 = (x231)<(x233);
x235 = (x232)+(x234);
x236 = (x218)-(x235);
x237 = (x218)<(x236);
x238 = (x23)+((uintptr_t)1ULL);
x239 = ((x171)>>((uintptr_t)1ULL))|((x175)<<((uintptr_t)63ULL));
x240 = ((x175)>>((uintptr_t)1ULL))|((x180)<<((uintptr_t)63ULL));
x241 = ((x180)>>((uintptr_t)1ULL))|((x185)<<((uintptr_t)63ULL));
x242 = ((x185)>>((uintptr_t)1ULL))|((x189)<<((uintptr_t)63ULL));
x243 = ((x189)&((uintptr_t)9223372036854775808ULL))|((x189)>>((uintptr_t)1ULL));
x244 = ((uintptr_t)-1ULL)+((x110)==((uintptr_t)0ULL));
x245 = (x244)^((uintptr_t)18446744073709551615ULL);
x246 = ((x75)&(x244))|((x92)&(x245));
x247 = ((uintptr_t)-1ULL)+((x110)==((uintptr_t)0ULL));
x248 = (x247)^((uintptr_t)18446744073709551615ULL);
x249 = ((x79)&(x247))|((x96)&(x248));
x250 = ((uintptr_t)-1ULL)+((x110)==((uintptr_t)0ULL));
x251 = (x250)^((uintptr_t)18446744073709551615ULL);
x252 = ((x84)&(x250))|((x101)&(x251));
x253 = ((uintptr_t)-1ULL)+((x110)==((uintptr_t)0ULL));
x254 = (x253)^((uintptr_t)18446744073709551615ULL);
x255 = ((x89)&(x253))|((x106)&(x254));
x256 = ((uintptr_t)-1ULL)+((x237)==((uintptr_t)0ULL));
x257 = (x256)^((uintptr_t)18446744073709551615ULL);
x258 = ((x202)&(x256))|((x219)&(x257));
x259 = ((uintptr_t)-1ULL)+((x237)==((uintptr_t)0ULL));
x260 = (x259)^((uintptr_t)18446744073709551615ULL);
x261 = ((x206)&(x259))|((x223)&(x260));
x262 = ((uintptr_t)-1ULL)+((x237)==((uintptr_t)0ULL));
x263 = (x262)^((uintptr_t)18446744073709551615ULL);
x264 = ((x211)&(x262))|((x228)&(x263));
x265 = ((uintptr_t)-1ULL)+((x237)==((uintptr_t)0ULL));
x266 = (x265)^((uintptr_t)18446744073709551615ULL);
x267 = ((x216)&(x265))|((x233)&(x266));
x268 = x238;
x269 = x26;
x270 = x29;
x271 = x32;
x272 = x35;
x273 = x38;
/*skip*/
x274 = x239;
x275 = x240;
x276 = x241;
x277 = x242;
x278 = x243;
/*skip*/
x279 = x246;
x280 = x249;
x281 = x252;
x282 = x255;
/*skip*/
x283 = x258;
x284 = x261;
x285 = x264;
x286 = x267;
/*skip*/
out0 = x268;
_br2_store((out1)+((uintptr_t)0ULL), x269, sizeof(uintptr_t));
_br2_store((out1)+((uintptr_t)8ULL), x270, sizeof(uintptr_t));
_br2_store((out1)+((uintptr_t)16ULL), x271, sizeof(uintptr_t));
_br2_store((out1)+((uintptr_t)24ULL), x272, sizeof(uintptr_t));
_br2_store((out1)+((uintptr_t)32ULL), x273, sizeof(uintptr_t));
/*skip*/
_br2_store((out2)+((uintptr_t)0ULL), x274, sizeof(uintptr_t));
_br2_store((out2)+((uintptr_t)8ULL), x275, sizeof(uintptr_t));
_br2_store((out2)+((uintptr_t)16ULL), x276, sizeof(uintptr_t));
_br2_store((out2)+((uintptr_t)24ULL), x277, sizeof(uintptr_t));
_br2_store((out2)+((uintptr_t)32ULL), x278, sizeof(uintptr_t));
/*skip*/
_br2_store((out3)+((uintptr_t)0ULL), x279, sizeof(uintptr_t));
_br2_store((out3)+((uintptr_t)8ULL), x280, sizeof(uintptr_t));
_br2_store((out3)+((uintptr_t)16ULL), x281, sizeof(uintptr_t));
_br2_store((out3)+((uintptr_t)24ULL), x282, sizeof(uintptr_t));
/*skip*/
_br2_store((out4)+((uintptr_t)0ULL), x283, sizeof(uintptr_t));
_br2_store((out4)+((uintptr_t)8ULL), x284, sizeof(uintptr_t));
_br2_store((out4)+((uintptr_t)16ULL), x285, sizeof(uintptr_t));
_br2_store((out4)+((uintptr_t)24ULL), x286, sizeof(uintptr_t));
/*skip*/
return out0;
}
/* NOTE: The following wrapper function is not covered by Coq proofs */
static void fiat_p224_divstep(uint64_t* out1, uint64_t out2[5], uint64_t out3[5], uint64_t out4[4], uint64_t out5[4], uint64_t arg1, const uint64_t arg2[5], const uint64_t arg3[5], const uint64_t arg4[4], const uint64_t arg5[4]) {
*out1 = (uint64_t)internal_fiat_p224_divstep((uintptr_t)out2, (uintptr_t)out3, (uintptr_t)out4, (uintptr_t)out5, (uintptr_t)arg1, (uintptr_t)arg2, (uintptr_t)arg3, (uintptr_t)arg4, (uintptr_t)arg5);
}
/*
* Input Bounds:
* Output Bounds:
* out0: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static
void internal_fiat_p224_divstep_precomp(uintptr_t out0) {
uintptr_t x0, x1, x2, x3;
/*skip*/
x0 = (uintptr_t)36028796993798145ULL;
x1 = (uintptr_t)18410715272404008960ULL;
x2 = (uintptr_t)16777215ULL;
x3 = (uintptr_t)4286578688ULL;
/*skip*/
_br2_store((out0)+((uintptr_t)0ULL), x0, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)8ULL), x1, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)16ULL), x2, sizeof(uintptr_t));
_br2_store((out0)+((uintptr_t)24ULL), x3, sizeof(uintptr_t));
/*skip*/
return;
}
/* NOTE: The following wrapper function is not covered by Coq proofs */
static void fiat_p224_divstep_precomp(uint64_t out1[4]) {
internal_fiat_p224_divstep_precomp((uintptr_t)out1);
}
|
the_stack_data/96336.c
|
// kernel panic: stack is corrupted in rcu_dynticks_curr_cpu_in_eqs
// https://syzkaller.appspot.com/bug?id=ed2483e4eb5b72ba18e3e4651ca492ee7e298d65
// status:dup
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <pthread.h>
#include <sched.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <linux/futex.h>
#include <linux/if_addr.h>
#include <linux/if_ether.h>
#include <linux/if_link.h>
#include <linux/if_tun.h>
#include <linux/in6.h>
#include <linux/ip.h>
#include <linux/neighbour.h>
#include <linux/net.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/tcp.h>
#include <linux/veth.h>
unsigned long long procid;
static __thread int skip_segv;
static __thread jmp_buf segv_env;
static void segv_handler(int sig, siginfo_t* info, void* ctx)
{
uintptr_t addr = (uintptr_t)info->si_addr;
const uintptr_t prog_start = 1 << 20;
const uintptr_t prog_end = 100 << 20;
if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) &&
(addr < prog_start || addr > prog_end)) {
_longjmp(segv_env, 1);
}
exit(sig);
}
static void install_segv_handler(void)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8);
syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8);
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = segv_handler;
sa.sa_flags = SA_NODEFER | SA_SIGINFO;
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGBUS, &sa, NULL);
}
#define NONFAILING(...) \
{ \
__atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \
if (_setjmp(segv_env) == 0) { \
__VA_ARGS__; \
} \
__atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \
}
static void sleep_ms(uint64_t ms)
{
usleep(ms * 1000);
}
static uint64_t current_time_ms(void)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts))
exit(1);
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}
static void use_temporary_dir(void)
{
char tmpdir_template[] = "./syzkaller.XXXXXX";
char* tmpdir = mkdtemp(tmpdir_template);
if (!tmpdir)
exit(1);
if (chmod(tmpdir, 0777))
exit(1);
if (chdir(tmpdir))
exit(1);
}
static void thread_start(void* (*fn)(void*), void* arg)
{
pthread_t th;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 128 << 10);
if (pthread_create(&th, &attr, fn, arg))
exit(1);
pthread_attr_destroy(&attr);
}
#define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off))
#define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \
*(type*)(addr) = \
htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \
(((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len))))
typedef struct {
int state;
} event_t;
static void event_init(event_t* ev)
{
ev->state = 0;
}
static void event_reset(event_t* ev)
{
ev->state = 0;
}
static void event_set(event_t* ev)
{
if (ev->state)
exit(1);
__atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE);
syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG);
}
static void event_wait(event_t* ev)
{
while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0);
}
static int event_isset(event_t* ev)
{
return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE);
}
static int event_timedwait(event_t* ev, uint64_t timeout)
{
uint64_t start = current_time_ms();
uint64_t now = start;
for (;;) {
uint64_t remain = timeout - (now - start);
struct timespec ts;
ts.tv_sec = remain / 1000;
ts.tv_nsec = (remain % 1000) * 1000 * 1000;
syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts);
if (__atomic_load_n(&ev->state, __ATOMIC_RELAXED))
return 1;
now = current_time_ms();
if (now - start > timeout)
return 0;
}
}
static bool write_file(const char* file, const char* what, ...)
{
char buf[1024];
va_list args;
va_start(args, what);
vsnprintf(buf, sizeof(buf), what, args);
va_end(args);
buf[sizeof(buf) - 1] = 0;
int len = strlen(buf);
int fd = open(file, O_WRONLY | O_CLOEXEC);
if (fd == -1)
return false;
if (write(fd, buf, len) != len) {
int err = errno;
close(fd);
errno = err;
return false;
}
close(fd);
return true;
}
static struct {
char* pos;
int nesting;
struct nlattr* nested[8];
char buf[1024];
} nlmsg;
static void netlink_init(int typ, int flags, const void* data, int size)
{
memset(&nlmsg, 0, sizeof(nlmsg));
struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg.buf;
hdr->nlmsg_type = typ;
hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags;
memcpy(hdr + 1, data, size);
nlmsg.pos = (char*)(hdr + 1) + NLMSG_ALIGN(size);
}
static void netlink_attr(int typ, const void* data, int size)
{
struct nlattr* attr = (struct nlattr*)nlmsg.pos;
attr->nla_len = sizeof(*attr) + size;
attr->nla_type = typ;
memcpy(attr + 1, data, size);
nlmsg.pos += NLMSG_ALIGN(attr->nla_len);
}
static void netlink_nest(int typ)
{
struct nlattr* attr = (struct nlattr*)nlmsg.pos;
attr->nla_type = typ;
nlmsg.pos += sizeof(*attr);
nlmsg.nested[nlmsg.nesting++] = attr;
}
static void netlink_done(void)
{
struct nlattr* attr = nlmsg.nested[--nlmsg.nesting];
attr->nla_len = nlmsg.pos - (char*)attr;
}
static int netlink_send(int sock)
{
if (nlmsg.pos > nlmsg.buf + sizeof(nlmsg.buf) || nlmsg.nesting)
exit(1);
struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg.buf;
hdr->nlmsg_len = nlmsg.pos - nlmsg.buf;
struct sockaddr_nl addr;
memset(&addr, 0, sizeof(addr));
addr.nl_family = AF_NETLINK;
unsigned n = sendto(sock, nlmsg.buf, hdr->nlmsg_len, 0,
(struct sockaddr*)&addr, sizeof(addr));
if (n != hdr->nlmsg_len)
exit(1);
n = recv(sock, nlmsg.buf, sizeof(nlmsg.buf), 0);
if (n < sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr))
exit(1);
if (hdr->nlmsg_type != NLMSG_ERROR)
exit(1);
return -((struct nlmsgerr*)(hdr + 1))->error;
}
static void netlink_add_device_impl(const char* type, const char* name)
{
struct ifinfomsg hdr;
memset(&hdr, 0, sizeof(hdr));
netlink_init(RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr));
if (name)
netlink_attr(IFLA_IFNAME, name, strlen(name));
netlink_nest(IFLA_LINKINFO);
netlink_attr(IFLA_INFO_KIND, type, strlen(type));
}
static void netlink_add_device(int sock, const char* type, const char* name)
{
netlink_add_device_impl(type, name);
netlink_done();
int err = netlink_send(sock);
(void)err;
}
static void netlink_add_veth(int sock, const char* name, const char* peer)
{
netlink_add_device_impl("veth", name);
netlink_nest(IFLA_INFO_DATA);
netlink_nest(VETH_INFO_PEER);
nlmsg.pos += sizeof(struct ifinfomsg);
netlink_attr(IFLA_IFNAME, peer, strlen(peer));
netlink_done();
netlink_done();
netlink_done();
int err = netlink_send(sock);
(void)err;
}
static void netlink_add_hsr(int sock, const char* name, const char* slave1,
const char* slave2)
{
netlink_add_device_impl("hsr", name);
netlink_nest(IFLA_INFO_DATA);
int ifindex1 = if_nametoindex(slave1);
netlink_attr(IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1));
int ifindex2 = if_nametoindex(slave2);
netlink_attr(IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2));
netlink_done();
netlink_done();
int err = netlink_send(sock);
(void)err;
}
static void netlink_device_change(int sock, const char* name, bool up,
const char* master, const void* mac,
int macsize)
{
struct ifinfomsg hdr;
memset(&hdr, 0, sizeof(hdr));
if (up)
hdr.ifi_flags = hdr.ifi_change = IFF_UP;
netlink_init(RTM_NEWLINK, 0, &hdr, sizeof(hdr));
netlink_attr(IFLA_IFNAME, name, strlen(name));
if (master) {
int ifindex = if_nametoindex(master);
netlink_attr(IFLA_MASTER, &ifindex, sizeof(ifindex));
}
if (macsize)
netlink_attr(IFLA_ADDRESS, mac, macsize);
int err = netlink_send(sock);
(void)err;
}
static int netlink_add_addr(int sock, const char* dev, const void* addr,
int addrsize)
{
struct ifaddrmsg hdr;
memset(&hdr, 0, sizeof(hdr));
hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6;
hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120;
hdr.ifa_scope = RT_SCOPE_UNIVERSE;
hdr.ifa_index = if_nametoindex(dev);
netlink_init(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr, sizeof(hdr));
netlink_attr(IFA_LOCAL, addr, addrsize);
netlink_attr(IFA_ADDRESS, addr, addrsize);
return netlink_send(sock);
}
static void netlink_add_addr4(int sock, const char* dev, const char* addr)
{
struct in_addr in_addr;
inet_pton(AF_INET, addr, &in_addr);
int err = netlink_add_addr(sock, dev, &in_addr, sizeof(in_addr));
(void)err;
}
static void netlink_add_addr6(int sock, const char* dev, const char* addr)
{
struct in6_addr in6_addr;
inet_pton(AF_INET6, addr, &in6_addr);
int err = netlink_add_addr(sock, dev, &in6_addr, sizeof(in6_addr));
(void)err;
}
static void netlink_add_neigh(int sock, const char* name, const void* addr,
int addrsize, const void* mac, int macsize)
{
struct ndmsg hdr;
memset(&hdr, 0, sizeof(hdr));
hdr.ndm_family = addrsize == 4 ? AF_INET : AF_INET6;
hdr.ndm_ifindex = if_nametoindex(name);
hdr.ndm_state = NUD_PERMANENT;
netlink_init(RTM_NEWNEIGH, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr));
netlink_attr(NDA_DST, addr, addrsize);
netlink_attr(NDA_LLADDR, mac, macsize);
int err = netlink_send(sock);
(void)err;
}
static int tunfd = -1;
static int tun_frags_enabled;
#define SYZ_TUN_MAX_PACKET_SIZE 1000
#define TUN_IFACE "syz_tun"
#define LOCAL_MAC 0xaaaaaaaaaaaa
#define REMOTE_MAC 0xaaaaaaaaaabb
#define LOCAL_IPV4 "172.20.20.170"
#define REMOTE_IPV4 "172.20.20.187"
#define LOCAL_IPV6 "fe80::aa"
#define REMOTE_IPV6 "fe80::bb"
#define IFF_NAPI 0x0010
#define IFF_NAPI_FRAGS 0x0020
static void initialize_tun(void)
{
tunfd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
if (tunfd == -1) {
printf("tun: can't open /dev/net/tun: please enable CONFIG_TUN=y\n");
printf("otherwise fuzzing or reproducing might not work as intended\n");
return;
}
const int kTunFd = 240;
if (dup2(tunfd, kTunFd) < 0)
exit(1);
close(tunfd);
tunfd = kTunFd;
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, TUN_IFACE, IFNAMSIZ);
ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_NAPI | IFF_NAPI_FRAGS;
if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) {
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0)
exit(1);
}
if (ioctl(tunfd, TUNGETIFF, (void*)&ifr) < 0)
exit(1);
tun_frags_enabled = (ifr.ifr_flags & IFF_NAPI_FRAGS) != 0;
char sysctl[64];
sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/accept_dad", TUN_IFACE);
write_file(sysctl, "0");
sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/router_solicitations", TUN_IFACE);
write_file(sysctl, "0");
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
netlink_add_addr4(sock, TUN_IFACE, LOCAL_IPV4);
netlink_add_addr6(sock, TUN_IFACE, LOCAL_IPV6);
uint64_t macaddr = REMOTE_MAC;
struct in_addr in_addr;
inet_pton(AF_INET, REMOTE_IPV4, &in_addr);
netlink_add_neigh(sock, TUN_IFACE, &in_addr, sizeof(in_addr), &macaddr,
ETH_ALEN);
struct in6_addr in6_addr;
inet_pton(AF_INET6, REMOTE_IPV6, &in6_addr);
netlink_add_neigh(sock, TUN_IFACE, &in6_addr, sizeof(in6_addr), &macaddr,
ETH_ALEN);
macaddr = LOCAL_MAC;
netlink_device_change(sock, TUN_IFACE, true, 0, &macaddr, ETH_ALEN);
close(sock);
}
#define DEV_IPV4 "172.20.20.%d"
#define DEV_IPV6 "fe80::%02hx"
#define DEV_MAC 0x00aaaaaaaaaa
static void initialize_netdevices(void)
{
char netdevsim[16];
sprintf(netdevsim, "netdevsim%d", (int)procid);
struct {
const char* type;
const char* dev;
} devtypes[] = {
{"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"},
{"vcan", "vcan0"}, {"bond", "bond0"},
{"team", "team0"}, {"dummy", "dummy0"},
{"nlmon", "nlmon0"}, {"caif", "caif0"},
{"batadv", "batadv0"}, {"vxcan", "vxcan1"},
{"netdevsim", netdevsim}, {"veth", 0},
};
const char* devmasters[] = {"bridge", "bond", "team"};
struct {
const char* name;
int macsize;
bool noipv6;
} devices[] = {
{"lo", ETH_ALEN},
{"sit0", 0},
{"bridge0", ETH_ALEN},
{"vcan0", 0, true},
{"tunl0", 0},
{"gre0", 0},
{"gretap0", ETH_ALEN},
{"ip_vti0", 0},
{"ip6_vti0", 0},
{"ip6tnl0", 0},
{"ip6gre0", 0},
{"ip6gretap0", ETH_ALEN},
{"erspan0", ETH_ALEN},
{"bond0", ETH_ALEN},
{"veth0", ETH_ALEN},
{"veth1", ETH_ALEN},
{"team0", ETH_ALEN},
{"veth0_to_bridge", ETH_ALEN},
{"veth1_to_bridge", ETH_ALEN},
{"veth0_to_bond", ETH_ALEN},
{"veth1_to_bond", ETH_ALEN},
{"veth0_to_team", ETH_ALEN},
{"veth1_to_team", ETH_ALEN},
{"veth0_to_hsr", ETH_ALEN},
{"veth1_to_hsr", ETH_ALEN},
{"hsr0", 0},
{"dummy0", ETH_ALEN},
{"nlmon0", 0},
{"vxcan1", 0, true},
{"caif0", ETH_ALEN},
{"batadv0", ETH_ALEN},
{netdevsim, ETH_ALEN},
};
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
unsigned i;
for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++)
netlink_add_device(sock, devtypes[i].type, devtypes[i].dev);
for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) {
char master[32], slave0[32], veth0[32], slave1[32], veth1[32];
sprintf(slave0, "%s_slave_0", devmasters[i]);
sprintf(veth0, "veth0_to_%s", devmasters[i]);
netlink_add_veth(sock, slave0, veth0);
sprintf(slave1, "%s_slave_1", devmasters[i]);
sprintf(veth1, "veth1_to_%s", devmasters[i]);
netlink_add_veth(sock, slave1, veth1);
sprintf(master, "%s0", devmasters[i]);
netlink_device_change(sock, slave0, false, master, 0, 0);
netlink_device_change(sock, slave1, false, master, 0, 0);
}
netlink_device_change(sock, "bridge_slave_0", true, 0, 0, 0);
netlink_device_change(sock, "bridge_slave_1", true, 0, 0, 0);
netlink_add_veth(sock, "hsr_slave_0", "veth0_to_hsr");
netlink_add_veth(sock, "hsr_slave_1", "veth1_to_hsr");
netlink_add_hsr(sock, "hsr0", "hsr_slave_0", "hsr_slave_1");
netlink_device_change(sock, "hsr_slave_0", true, 0, 0, 0);
netlink_device_change(sock, "hsr_slave_1", true, 0, 0, 0);
for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) {
char addr[32];
sprintf(addr, DEV_IPV4, i + 10);
netlink_add_addr4(sock, devices[i].name, addr);
if (!devices[i].noipv6) {
sprintf(addr, DEV_IPV6, i + 10);
netlink_add_addr6(sock, devices[i].name, addr);
}
uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40);
netlink_device_change(sock, devices[i].name, true, 0, &macaddr,
devices[i].macsize);
}
close(sock);
}
static void initialize_netdevices_init(void)
{
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
struct {
const char* type;
int macsize;
bool noipv6;
bool noup;
} devtypes[] = {
{"nr", 7, true},
{"rose", 5, true, true},
};
unsigned i;
for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) {
char dev[32], addr[32];
sprintf(dev, "%s%d", devtypes[i].type, (int)procid);
sprintf(addr, "172.30.%d.%d", i, (int)procid + 1);
netlink_add_addr4(sock, dev, addr);
if (!devtypes[i].noipv6) {
sprintf(addr, "fe88::%02hx:%02hx", i, (int)procid + 1);
netlink_add_addr6(sock, dev, addr);
}
int macsize = devtypes[i].macsize;
uint64_t macaddr = 0xbbbbbb +
((unsigned long long)i << (8 * (macsize - 2))) +
(procid << (8 * (macsize - 1)));
netlink_device_change(sock, dev, !devtypes[i].noup, 0, &macaddr, macsize);
}
close(sock);
}
static int read_tun(char* data, int size)
{
if (tunfd < 0)
return -1;
int rv = read(tunfd, data, size);
if (rv < 0) {
if (errno == EAGAIN)
return -1;
if (errno == EBADFD)
return -1;
exit(1);
}
return rv;
}
static void flush_tun()
{
char data[SYZ_TUN_MAX_PACKET_SIZE];
while (read_tun(&data[0], sizeof(data)) != -1) {
}
}
static long syz_open_procfs(long a0, long a1)
{
char buf[128];
memset(buf, 0, sizeof(buf));
if (a0 == 0) {
NONFAILING(snprintf(buf, sizeof(buf), "/proc/self/%s", (char*)a1));
} else if (a0 == -1) {
NONFAILING(snprintf(buf, sizeof(buf), "/proc/thread-self/%s", (char*)a1));
} else {
NONFAILING(snprintf(buf, sizeof(buf), "/proc/self/task/%d/%s", (int)a0,
(char*)a1));
}
int fd = open(buf, O_RDWR);
if (fd == -1)
fd = open(buf, O_RDONLY);
return fd;
}
#define XT_TABLE_SIZE 1536
#define XT_MAX_ENTRIES 10
struct xt_counters {
uint64_t pcnt, bcnt;
};
struct ipt_getinfo {
char name[32];
unsigned int valid_hooks;
unsigned int hook_entry[5];
unsigned int underflow[5];
unsigned int num_entries;
unsigned int size;
};
struct ipt_get_entries {
char name[32];
unsigned int size;
void* entrytable[XT_TABLE_SIZE / sizeof(void*)];
};
struct ipt_replace {
char name[32];
unsigned int valid_hooks;
unsigned int num_entries;
unsigned int size;
unsigned int hook_entry[5];
unsigned int underflow[5];
unsigned int num_counters;
struct xt_counters* counters;
char entrytable[XT_TABLE_SIZE];
};
struct ipt_table_desc {
const char* name;
struct ipt_getinfo info;
struct ipt_replace replace;
};
static struct ipt_table_desc ipv4_tables[] = {
{.name = "filter"}, {.name = "nat"}, {.name = "mangle"},
{.name = "raw"}, {.name = "security"},
};
static struct ipt_table_desc ipv6_tables[] = {
{.name = "filter"}, {.name = "nat"}, {.name = "mangle"},
{.name = "raw"}, {.name = "security"},
};
#define IPT_BASE_CTL 64
#define IPT_SO_SET_REPLACE (IPT_BASE_CTL)
#define IPT_SO_GET_INFO (IPT_BASE_CTL)
#define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1)
struct arpt_getinfo {
char name[32];
unsigned int valid_hooks;
unsigned int hook_entry[3];
unsigned int underflow[3];
unsigned int num_entries;
unsigned int size;
};
struct arpt_get_entries {
char name[32];
unsigned int size;
void* entrytable[XT_TABLE_SIZE / sizeof(void*)];
};
struct arpt_replace {
char name[32];
unsigned int valid_hooks;
unsigned int num_entries;
unsigned int size;
unsigned int hook_entry[3];
unsigned int underflow[3];
unsigned int num_counters;
struct xt_counters* counters;
char entrytable[XT_TABLE_SIZE];
};
struct arpt_table_desc {
const char* name;
struct arpt_getinfo info;
struct arpt_replace replace;
};
static struct arpt_table_desc arpt_tables[] = {
{.name = "filter"},
};
#define ARPT_BASE_CTL 96
#define ARPT_SO_SET_REPLACE (ARPT_BASE_CTL)
#define ARPT_SO_GET_INFO (ARPT_BASE_CTL)
#define ARPT_SO_GET_ENTRIES (ARPT_BASE_CTL + 1)
static void checkpoint_iptables(struct ipt_table_desc* tables, int num_tables,
int family, int level)
{
struct ipt_get_entries entries;
socklen_t optlen;
int fd, i;
fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < num_tables; i++) {
struct ipt_table_desc* table = &tables[i];
strcpy(table->info.name, table->name);
strcpy(table->replace.name, table->name);
optlen = sizeof(table->info);
if (getsockopt(fd, level, IPT_SO_GET_INFO, &table->info, &optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->info.size > sizeof(table->replace.entrytable))
exit(1);
if (table->info.num_entries > XT_MAX_ENTRIES)
exit(1);
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size;
if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
table->replace.valid_hooks = table->info.valid_hooks;
table->replace.num_entries = table->info.num_entries;
table->replace.size = table->info.size;
memcpy(table->replace.hook_entry, table->info.hook_entry,
sizeof(table->replace.hook_entry));
memcpy(table->replace.underflow, table->info.underflow,
sizeof(table->replace.underflow));
memcpy(table->replace.entrytable, entries.entrytable, table->info.size);
}
close(fd);
}
static void reset_iptables(struct ipt_table_desc* tables, int num_tables,
int family, int level)
{
struct xt_counters counters[XT_MAX_ENTRIES];
struct ipt_get_entries entries;
struct ipt_getinfo info;
socklen_t optlen;
int fd, i;
fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < num_tables; i++) {
struct ipt_table_desc* table = &tables[i];
if (table->info.valid_hooks == 0)
continue;
memset(&info, 0, sizeof(info));
strcpy(info.name, table->name);
optlen = sizeof(info);
if (getsockopt(fd, level, IPT_SO_GET_INFO, &info, &optlen))
exit(1);
if (memcmp(&table->info, &info, sizeof(table->info)) == 0) {
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size;
if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
if (memcmp(table->replace.entrytable, entries.entrytable,
table->info.size) == 0)
continue;
}
table->replace.num_counters = info.num_entries;
table->replace.counters = counters;
optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) +
table->replace.size;
if (setsockopt(fd, level, IPT_SO_SET_REPLACE, &table->replace, optlen))
exit(1);
}
close(fd);
}
static void checkpoint_arptables(void)
{
struct arpt_get_entries entries;
socklen_t optlen;
unsigned i;
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) {
struct arpt_table_desc* table = &arpt_tables[i];
strcpy(table->info.name, table->name);
strcpy(table->replace.name, table->name);
optlen = sizeof(table->info);
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &table->info, &optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->info.size > sizeof(table->replace.entrytable))
exit(1);
if (table->info.num_entries > XT_MAX_ENTRIES)
exit(1);
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size;
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
table->replace.valid_hooks = table->info.valid_hooks;
table->replace.num_entries = table->info.num_entries;
table->replace.size = table->info.size;
memcpy(table->replace.hook_entry, table->info.hook_entry,
sizeof(table->replace.hook_entry));
memcpy(table->replace.underflow, table->info.underflow,
sizeof(table->replace.underflow));
memcpy(table->replace.entrytable, entries.entrytable, table->info.size);
}
close(fd);
}
static void reset_arptables()
{
struct xt_counters counters[XT_MAX_ENTRIES];
struct arpt_get_entries entries;
struct arpt_getinfo info;
socklen_t optlen;
unsigned i;
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) {
struct arpt_table_desc* table = &arpt_tables[i];
if (table->info.valid_hooks == 0)
continue;
memset(&info, 0, sizeof(info));
strcpy(info.name, table->name);
optlen = sizeof(info);
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &info, &optlen))
exit(1);
if (memcmp(&table->info, &info, sizeof(table->info)) == 0) {
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size;
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
if (memcmp(table->replace.entrytable, entries.entrytable,
table->info.size) == 0)
continue;
} else {
}
table->replace.num_counters = info.num_entries;
table->replace.counters = counters;
optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) +
table->replace.size;
if (setsockopt(fd, SOL_IP, ARPT_SO_SET_REPLACE, &table->replace, optlen))
exit(1);
}
close(fd);
}
#define NF_BR_NUMHOOKS 6
#define EBT_TABLE_MAXNAMELEN 32
#define EBT_CHAIN_MAXNAMELEN 32
#define EBT_BASE_CTL 128
#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
#define EBT_SO_GET_INFO (EBT_BASE_CTL)
#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO + 1)
#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES + 1)
#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO + 1)
struct ebt_replace {
char name[EBT_TABLE_MAXNAMELEN];
unsigned int valid_hooks;
unsigned int nentries;
unsigned int entries_size;
struct ebt_entries* hook_entry[NF_BR_NUMHOOKS];
unsigned int num_counters;
struct ebt_counter* counters;
char* entries;
};
struct ebt_entries {
unsigned int distinguisher;
char name[EBT_CHAIN_MAXNAMELEN];
unsigned int counter_offset;
int policy;
unsigned int nentries;
char data[0] __attribute__((aligned(__alignof__(struct ebt_replace))));
};
struct ebt_table_desc {
const char* name;
struct ebt_replace replace;
char entrytable[XT_TABLE_SIZE];
};
static struct ebt_table_desc ebt_tables[] = {
{.name = "filter"},
{.name = "nat"},
{.name = "broute"},
};
static void checkpoint_ebtables(void)
{
socklen_t optlen;
unsigned i;
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) {
struct ebt_table_desc* table = &ebt_tables[i];
strcpy(table->replace.name, table->name);
optlen = sizeof(table->replace);
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_INFO, &table->replace,
&optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->replace.entries_size > sizeof(table->entrytable))
exit(1);
table->replace.num_counters = 0;
table->replace.entries = table->entrytable;
optlen = sizeof(table->replace) + table->replace.entries_size;
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_ENTRIES, &table->replace,
&optlen))
exit(1);
}
close(fd);
}
static void reset_ebtables()
{
struct ebt_replace replace;
char entrytable[XT_TABLE_SIZE];
socklen_t optlen;
unsigned i, j, h;
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) {
struct ebt_table_desc* table = &ebt_tables[i];
if (table->replace.valid_hooks == 0)
continue;
memset(&replace, 0, sizeof(replace));
strcpy(replace.name, table->name);
optlen = sizeof(replace);
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INFO, &replace, &optlen))
exit(1);
replace.num_counters = 0;
table->replace.entries = 0;
for (h = 0; h < NF_BR_NUMHOOKS; h++)
table->replace.hook_entry[h] = 0;
if (memcmp(&table->replace, &replace, sizeof(table->replace)) == 0) {
memset(&entrytable, 0, sizeof(entrytable));
replace.entries = entrytable;
optlen = sizeof(replace) + replace.entries_size;
if (getsockopt(fd, SOL_IP, EBT_SO_GET_ENTRIES, &replace, &optlen))
exit(1);
if (memcmp(table->entrytable, entrytable, replace.entries_size) == 0)
continue;
}
for (j = 0, h = 0; h < NF_BR_NUMHOOKS; h++) {
if (table->replace.valid_hooks & (1 << h)) {
table->replace.hook_entry[h] =
(struct ebt_entries*)table->entrytable + j;
j++;
}
}
table->replace.entries = table->entrytable;
optlen = sizeof(table->replace) + table->replace.entries_size;
if (setsockopt(fd, SOL_IP, EBT_SO_SET_ENTRIES, &table->replace, optlen))
exit(1);
}
close(fd);
}
static void checkpoint_net_namespace(void)
{
checkpoint_ebtables();
checkpoint_arptables();
checkpoint_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]),
AF_INET, SOL_IP);
checkpoint_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]),
AF_INET6, SOL_IPV6);
}
static void reset_net_namespace(void)
{
reset_ebtables();
reset_arptables();
reset_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]),
AF_INET, SOL_IP);
reset_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]),
AF_INET6, SOL_IPV6);
}
static void setup_cgroups()
{
if (mkdir("/syzcgroup", 0777)) {
}
if (mkdir("/syzcgroup/unified", 0777)) {
}
if (mount("none", "/syzcgroup/unified", "cgroup2", 0, NULL)) {
}
if (chmod("/syzcgroup/unified", 0777)) {
}
write_file("/syzcgroup/unified/cgroup.subtree_control",
"+cpu +memory +io +pids +rdma");
if (mkdir("/syzcgroup/cpu", 0777)) {
}
if (mount("none", "/syzcgroup/cpu", "cgroup", 0,
"cpuset,cpuacct,perf_event,hugetlb")) {
}
write_file("/syzcgroup/cpu/cgroup.clone_children", "1");
if (chmod("/syzcgroup/cpu", 0777)) {
}
if (mkdir("/syzcgroup/net", 0777)) {
}
if (mount("none", "/syzcgroup/net", "cgroup", 0,
"net_cls,net_prio,devices,freezer")) {
}
if (chmod("/syzcgroup/net", 0777)) {
}
}
static void setup_binfmt_misc()
{
if (mount(0, "/proc/sys/fs/binfmt_misc", "binfmt_misc", 0, 0)) {
}
write_file("/proc/sys/fs/binfmt_misc/register", ":syz0:M:0:\x01::./file0:");
write_file("/proc/sys/fs/binfmt_misc/register",
":syz1:M:1:\x02::./file0:POC");
}
static void setup_common()
{
if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) {
}
setup_cgroups();
setup_binfmt_misc();
}
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 int do_sandbox_none(void)
{
if (unshare(CLONE_NEWPID)) {
}
int pid = fork();
if (pid != 0)
return wait_for_loop(pid);
setup_common();
sandbox_common();
initialize_netdevices_init();
if (unshare(CLONE_NEWNET)) {
}
initialize_tun();
initialize_netdevices();
loop();
exit(1);
}
#define FS_IOC_SETFLAGS _IOW('f', 2, long)
static void remove_dir(const char* dir)
{
DIR* dp;
struct dirent* ep;
int iter = 0;
retry:
while (umount2(dir, MNT_DETACH) == 0) {
}
dp = opendir(dir);
if (dp == NULL) {
if (errno == EMFILE) {
exit(1);
}
exit(1);
}
while ((ep = readdir(dp))) {
if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
continue;
char filename[FILENAME_MAX];
snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name);
while (umount2(filename, MNT_DETACH) == 0) {
}
struct stat st;
if (lstat(filename, &st))
exit(1);
if (S_ISDIR(st.st_mode)) {
remove_dir(filename);
continue;
}
int i;
for (i = 0;; i++) {
if (unlink(filename) == 0)
break;
if (errno == EPERM) {
int fd = open(filename, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0)
close(fd);
continue;
}
}
if (errno == EROFS) {
break;
}
if (errno != EBUSY || i > 100)
exit(1);
if (umount2(filename, MNT_DETACH))
exit(1);
}
}
closedir(dp);
int i;
for (i = 0;; i++) {
if (rmdir(dir) == 0)
break;
if (i < 100) {
if (errno == EPERM) {
int fd = open(dir, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0)
close(fd);
continue;
}
}
if (errno == EROFS) {
break;
}
if (errno == EBUSY) {
if (umount2(dir, MNT_DETACH))
exit(1);
continue;
}
if (errno == ENOTEMPTY) {
if (iter < 100) {
iter++;
goto retry;
}
}
}
exit(1);
}
}
static void kill_and_wait(int pid, int* status)
{
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
int i;
for (i = 0; i < 100; i++) {
if (waitpid(-1, status, WNOHANG | __WALL) == pid)
return;
usleep(1000);
}
DIR* dir = opendir("/sys/fs/fuse/connections");
if (dir) {
for (;;) {
struct dirent* ent = readdir(dir);
if (!ent)
break;
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
continue;
char abort[300];
snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
ent->d_name);
int fd = open(abort, O_WRONLY);
if (fd == -1) {
continue;
}
if (write(fd, abort, 1) < 0) {
}
close(fd);
}
closedir(dir);
} else {
}
while (waitpid(-1, status, __WALL) != pid) {
}
}
#define SYZ_HAVE_SETUP_LOOP 1
static void setup_loop()
{
int pid = getpid();
char cgroupdir[64];
char file[128];
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid);
if (mkdir(cgroupdir, 0777)) {
}
snprintf(file, sizeof(file), "%s/pids.max", cgroupdir);
write_file(file, "32");
snprintf(file, sizeof(file), "%s/memory.low", cgroupdir);
write_file(file, "%d", 298 << 20);
snprintf(file, sizeof(file), "%s/memory.high", cgroupdir);
write_file(file, "%d", 299 << 20);
snprintf(file, sizeof(file), "%s/memory.max", cgroupdir);
write_file(file, "%d", 300 << 20);
snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir);
write_file(file, "%d", pid);
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid);
if (mkdir(cgroupdir, 0777)) {
}
snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir);
write_file(file, "%d", pid);
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid);
if (mkdir(cgroupdir, 0777)) {
}
snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir);
write_file(file, "%d", pid);
checkpoint_net_namespace();
}
#define SYZ_HAVE_RESET_LOOP 1
static void reset_loop()
{
reset_net_namespace();
}
#define SYZ_HAVE_SETUP_TEST 1
static void setup_test()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
char cgroupdir[64];
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid);
if (symlink(cgroupdir, "./cgroup")) {
}
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid);
if (symlink(cgroupdir, "./cgroup.cpu")) {
}
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid);
if (symlink(cgroupdir, "./cgroup.net")) {
}
write_file("/proc/self/oom_score_adj", "1000");
flush_tun();
}
#define SYZ_HAVE_RESET_TEST 1
static void reset_test()
{
int fd;
for (fd = 3; fd < 30; fd++)
close(fd);
}
struct thread_t {
int created, call;
event_t ready, done;
};
static struct thread_t threads[16];
static void execute_call(int call);
static int running;
static void* thr(void* arg)
{
struct thread_t* th = (struct thread_t*)arg;
for (;;) {
event_wait(&th->ready);
event_reset(&th->ready);
execute_call(th->call);
__atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED);
event_set(&th->done);
}
return 0;
}
static void execute_one(void)
{
int i, call, thread;
int collide = 0;
again:
for (call = 0; call < 16; call++) {
for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0]));
thread++) {
struct thread_t* th = &threads[thread];
if (!th->created) {
th->created = 1;
event_init(&th->ready);
event_init(&th->done);
event_set(&th->done);
thread_start(thr, th);
}
if (!event_isset(&th->done))
continue;
event_reset(&th->done);
th->call = call;
__atomic_fetch_add(&running, 1, __ATOMIC_RELAXED);
event_set(&th->ready);
if (collide && (call % 2) == 0)
break;
event_timedwait(&th->done, 45);
break;
}
}
for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++)
sleep_ms(1);
if (!collide) {
collide = 1;
goto again;
}
}
static void execute_one(void);
#define WAIT_FLAGS __WALL
static void loop(void)
{
setup_loop();
int iter;
for (iter = 0;; iter++) {
char cwdbuf[32];
sprintf(cwdbuf, "./%d", iter);
if (mkdir(cwdbuf, 0777))
exit(1);
reset_loop();
int pid = fork();
if (pid < 0)
exit(1);
if (pid == 0) {
if (chdir(cwdbuf))
exit(1);
setup_test();
execute_one();
reset_test();
exit(0);
}
int status = 0;
uint64_t start = current_time_ms();
for (;;) {
if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
break;
sleep_ms(1);
if (current_time_ms() - start < 5 * 1000)
continue;
kill_and_wait(pid, &status);
break;
}
remove_dir(cwdbuf);
}
}
uint64_t r[1] = {0xffffffffffffffff};
void execute_call(int call)
{
long res;
switch (call) {
case 0:
NONFAILING(*(uint32_t*)0x20000180 = 1);
NONFAILING(*(uint32_t*)0x20000184 = 0x70);
NONFAILING(*(uint8_t*)0x20000188 = 0);
NONFAILING(*(uint8_t*)0x20000189 = 0);
NONFAILING(*(uint8_t*)0x2000018a = 0);
NONFAILING(*(uint8_t*)0x2000018b = 0);
NONFAILING(*(uint32_t*)0x2000018c = 0);
NONFAILING(*(uint64_t*)0x20000190 = 0x1ff);
NONFAILING(*(uint64_t*)0x20000198 = 0);
NONFAILING(*(uint64_t*)0x200001a0 = 0);
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 0, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 1, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 2, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 3, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 4, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 5, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 6, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 7, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 8, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 9, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 10, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 11, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 12, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 13, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 14, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 15, 2));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 17, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 18, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 19, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 20, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 21, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 22, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 23, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 24, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 25, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 26, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 27, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 28, 1));
NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x200001a8, 0, 29, 35));
NONFAILING(*(uint32_t*)0x200001b0 = 0);
NONFAILING(*(uint32_t*)0x200001b4 = 0);
NONFAILING(*(uint64_t*)0x200001b8 = 0);
NONFAILING(*(uint64_t*)0x200001c0 = 0);
NONFAILING(*(uint64_t*)0x200001c8 = 0);
NONFAILING(*(uint64_t*)0x200001d0 = 0);
NONFAILING(*(uint32_t*)0x200001d8 = 0);
NONFAILING(*(uint32_t*)0x200001dc = 0);
NONFAILING(*(uint64_t*)0x200001e0 = 0);
NONFAILING(*(uint32_t*)0x200001e8 = 0);
NONFAILING(*(uint16_t*)0x200001ec = 0);
NONFAILING(*(uint16_t*)0x200001ee = 0);
syscall(__NR_perf_event_open, 0x20000180, 0, -1, -1, 0);
break;
case 1:
syscall(__NR_setsockopt, -1, 0x29, 0x20, 0, 0);
break;
case 2:
syscall(__NR_ioctl, -1, 0x4020940d, 0);
break;
case 3:
res = syscall(__NR_socket, 0xa, 2, 0x88);
if (res != -1)
r[0] = res;
break;
case 4:
NONFAILING(memcpy((void*)0x20000100, "fdinfo/4\x00", 9));
syz_open_procfs(0, 0x20000100);
break;
case 5:
NONFAILING(*(uint16_t*)0x20000000 = 0xa);
NONFAILING(*(uint16_t*)0x20000002 = htobe16(0x4e24));
NONFAILING(*(uint32_t*)0x20000004 = 0);
NONFAILING(*(uint8_t*)0x20000008 = 0);
NONFAILING(*(uint8_t*)0x20000009 = 0);
NONFAILING(*(uint8_t*)0x2000000a = 0);
NONFAILING(*(uint8_t*)0x2000000b = 0);
NONFAILING(*(uint8_t*)0x2000000c = 0);
NONFAILING(*(uint8_t*)0x2000000d = 0);
NONFAILING(*(uint8_t*)0x2000000e = 0);
NONFAILING(*(uint8_t*)0x2000000f = 0);
NONFAILING(*(uint8_t*)0x20000010 = 0);
NONFAILING(*(uint8_t*)0x20000011 = 0);
NONFAILING(*(uint8_t*)0x20000012 = 0);
NONFAILING(*(uint8_t*)0x20000013 = 0);
NONFAILING(*(uint8_t*)0x20000014 = 0);
NONFAILING(*(uint8_t*)0x20000015 = 0);
NONFAILING(*(uint8_t*)0x20000016 = 0);
NONFAILING(*(uint8_t*)0x20000017 = 0);
NONFAILING(*(uint32_t*)0x20000018 = 0);
syscall(__NR_bind, r[0], 0x20000000, 0x1c);
break;
case 6:
syscall(__NR_getuid);
break;
case 7:
NONFAILING(memcpy((void*)0x20000140, "./file0\x00", 8));
syscall(__NR_lstat, 0x20000140, 0x20000280);
break;
case 8:
NONFAILING(*(uint32_t*)0x20007940 = 0xc);
syscall(__NR_getsockopt, r[0], 1, 0x11, 0x20007900, 0x20007940);
break;
case 9:
NONFAILING(*(uint32_t*)0x20007b00 = 0xee00);
syscall(__NR_getgroups, 1, 0x20007b00);
break;
case 10:
syscall(__NR_getuid);
break;
case 11:
syscall(__NR_getgid);
break;
case 12:
syscall(__NR_getgroups, 0, 0);
break;
case 13:
syscall(__NR_fstat, -1, 0x20008a00);
break;
case 14:
NONFAILING(*(uint16_t*)0x20000080 = 0xa);
NONFAILING(*(uint16_t*)0x20000082 = htobe16(0x4e24));
NONFAILING(*(uint32_t*)0x20000084 = 0);
NONFAILING(*(uint8_t*)0x20000088 = 0);
NONFAILING(*(uint8_t*)0x20000089 = 0);
NONFAILING(*(uint8_t*)0x2000008a = 0);
NONFAILING(*(uint8_t*)0x2000008b = 0);
NONFAILING(*(uint8_t*)0x2000008c = 0);
NONFAILING(*(uint8_t*)0x2000008d = 0);
NONFAILING(*(uint8_t*)0x2000008e = 0);
NONFAILING(*(uint8_t*)0x2000008f = 0);
NONFAILING(*(uint8_t*)0x20000090 = 0);
NONFAILING(*(uint8_t*)0x20000091 = 0);
NONFAILING(*(uint8_t*)0x20000092 = -1);
NONFAILING(*(uint8_t*)0x20000093 = -1);
NONFAILING(*(uint32_t*)0x20000094 = htobe32(0x7f000001));
NONFAILING(*(uint32_t*)0x20000098 = 0);
syscall(__NR_connect, r[0], 0x20000080, 0x1c);
break;
case 15:
syscall(__NR_sendmmsg, r[0], 0x200092c0, 0x4000000000000f5, 0);
break;
}
}
int main(void)
{
syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
install_segv_handler();
for (procid = 0; procid < 6; procid++) {
if (fork() == 0) {
use_temporary_dir();
do_sandbox_none();
}
}
sleep(1000000);
return 0;
}
|
the_stack_data/40762834.c
|
// C program for Flattering a Linked List
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int data;
struct node *right;
struct node *down;
}Node;
void push(Node **headref,int new_data)
{
Node *newnode =(Node*)malloc(sizeof(Node));
newnode->right = NULL;
newnode->data = new_data;
newnode->down = *headref;
*headref = newnode;
}
void printList(Node *node)
{
while(node!=NULL){
printf("%d ",node->data);
node = node->down;
}
}
Node *merge(Node *a,Node *b){
if(a==NULL)
return b;
if(b==NULL)
return a;
Node *result;
if(a->data < b->data){
result = a;
result->down = merge(a->down,b);
}
else
{
result = b;
result->down = merge(a,b->down);
}
return result;
}
// the Main Function the Linkd List
Node * flatten(Node* root)
{
if(root==NULL || root->right==NULL)
return root;
return merge(root,flatten(root->right));
}
// Driver Function
int main()
{
Node* root= NULL;
push(&root,30);
push(&root,8);
push(&root,7);
push(&root,5);
push(&(root->right),20);
push(&(root->right),10);
push(&(root->right->right),50);
push(&(root->right->right),22);
push(&(root->right->right),19);
push(&(root->right->right->right),45);
push(&(root->right->right->right),40);
push(&(root->right->right->right),35);
push(&(root->right->right->right),28);
root = flatten(root);
printList(root);
return 0;
}
|
the_stack_data/9031.c
|
/* depends on NoDepB */
void NoDepB_func();
void NoDepA_func()
{
NoDepB_func();
}
|
the_stack_data/51136.c
|
#include <stdio.h>
#include <sys/resource.h>
#include <sys/time.h>
int main() {
struct rlimit lim;
int temp = getrlimit(RLIMIT_STACK,&lim);
printf("stack size: %ld\n", (int)lim.rlim_cur);
temp = getrlimit(RLIMIT_NPROC,&lim);
printf("process limit: %ld\n", (int)lim.rlim_cur);
temp = getrlimit(RLIMIT_NOFILE,&lim);
printf("max file descriptors: %ld\n", (int)lim.rlim_cur);
return 0;
}
|
the_stack_data/159487.c
|
/*
* Copyright 2016 The Emscripten Authors. All rights reserved.
* Emscripten is available under two separate licenses, the MIT license and the
* University of Illinois/NCSA Open Source License. Both these licenses can be
* found in the LICENSE file.
*/
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
int main() {
const char *STRING = "0 -035 +04711";
char *end_char;
// undefined base
long long int l1 = strtoll(STRING, &end_char, 0);
assert(l1 == 0);
long long int l2 = strtoll(end_char, &end_char, 0);
assert(l2 == -29);
long long int l3 = strtoll(end_char, NULL, 0);
assert(l3 == 2505);
// defined base
long long int l4 = strtoll(STRING, &end_char, 8);
assert(l4 == 0);
long long int l5 = strtoll(end_char, &end_char, 8);
assert(l5 == -29);
long long int l6 = strtoll(end_char, NULL, 8);
assert(l6 == 2505);
printf("%lli\n", l1);
printf("%lli\n", l2);
printf("%lli\n", l3);
printf("%lli\n", l4);
printf("%lli\n", l5);
printf("%lli\n", l6);
return 0;
}
|
the_stack_data/76670.c
|
//UNSAFE
//NO new preds found with FLAT + INCREF, works with CF + incref ...
typedef struct __FILE { int BLAST_FLAG; } FILE ;
extern void *malloc(int t);
void errorFn() {
// ERROR: goto ERROR;
_TRACER_abort(1);
}
FILE *get_stderr() {
FILE *f = (FILE *)malloc(sizeof(FILE));
/*
f->BLAST_FLAG = 1; return f;
*/
if (f->BLAST_FLAG==1) {
return f;
} else {
STUCK: goto STUCK;
}
}
FILE *fopen (char *fname) {
FILE *f = (FILE *)malloc(sizeof(FILE));
f->BLAST_FLAG = 1; return f;
}
int fclose (FILE *f) {
if (f->BLAST_FLAG==0) {
errorFn();
}
f->BLAST_FLAG = 0;
}
void fprintf(FILE *f) {
if (f->BLAST_FLAG==0) {
errorFn();
}
}
int main() {
FILE *f, *out;
char *outfile;
while (1) {
if (outfile!=0) {
f = fopen(outfile);
//out = f;
} else {
f = get_stderr();
//out = f;
}
//fprintf(out);
fprintf(f);
fclose(f);
fprintf(f); //bug
}
}
|
the_stack_data/357859.c
|
#include <stdio.h>
#include <time.h>
int main(){
printf("tic: %ld\nclock: %ld\n", CLOCKS_PER_SEC, clock());
}
|
the_stack_data/20450646.c
|
/*
============================================================================
Author : Ztiany
Description : C语言联合体
============================================================================
*/
#include <stdio.h>
union UA {
int i;
float j;
};
void unionParameter(union UA ua);
void unionSample();
int main() {
unionSample();
return 0;
}
void unionSample() {
//联合体中的所以数据都放在同一个地址开始的内存单元中。每一瞬间,联合体只能存储其中一个成员
union Date {
int i;
char ch;
float f;
};
union Date date1;//联合体所占内存大小与其成员中类型最大的成员一样。
date1.f = 3.4F;
printf(" f = %f\n", date1.f);//结果正确
date1.i = -10;
printf(" f = %f\n", date1.f);//结果错误
//定义联合体的其他方式
union Date date2 = {3};//默认对第一个成员进行初始化
union Date date3 = {.ch = 'd'};
//C99 允许类型相同的联合体相互复制
date1 = date2;
//C99之前不允许联合体作为非指针函数的参数,C99后允许联合体作为函数的参数
union UA ua = {3};
unionParameter(ua);
}
void unionParameter(union UA ua) {
printf(" %d ", ua.i);
}
|
the_stack_data/229322.c
|
/*
* Test name: test13a.c
*
* Objective: The purpose of this tests is to show how a select can
* get into a race condition when dealing with signals.
*
* Description: The program waits for SIGHUP or input in the terminal
*/
#include <sys/types.h>
#include <sys/select.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <stdio.h>
#include <signal.h>
#include <errno.h>
int got_sighup = 0;
void catch_hup(int sig_num)
{
printf("Received a SIGHUP, set global vble \n");
got_sighup = 1;
}
int main(void) {
int ret; /* return value */
fd_set read_fds;
char data[1024];
/* Init read fd_set */
FD_ZERO(&read_fds);
FD_SET(0, &read_fds);
/* set the HUP signal handler to 'catch_hup' */
signal(SIGHUP, catch_hup);
/* Get proc_id and print it */
printf("Send a signal from other terminal with: kill -1 %d\n", getpid());
printf("Going to sleep for 5 seconds, if the signal arrives meanwhile\n");
printf("the process will be blocked until there is input in the keyboard\n");
printf("if the signal arrives after the timeout and while in select, it will\n");
printf("behave as it should.\n");
printf("Sleeping for 5 secs\n");
sleep(5);
printf("Blocking now on select...\n");
ret = select(1, &read_fds, NULL, NULL, NULL);
if (got_sighup) {
printf("We have a sighup signal so exit the program\n");
exit(0);
}
gets(data);
printf("Got entry for terminal then, bye\n");
}
|
the_stack_data/153268830.c
|
/*
** EPITECH PROJECT, 2019
** my_getnbr.c
** File description:
** fct that returns a nb, sent to the fct as a string
*/
int is_negative(int neg)
{
if (neg == 0)
return (1);
else
return (0);
}
int result(int nb, int neg)
{
if (neg == 1)
return (-nb);
else
return (nb);
}
int my_getnbr(char const *str)
{
int neg = 0;
int nb = 0;
int i = 0;
for (; str[i] == '+' || str[i] == '-'; i++) {
if (str[i] == '-')
neg = is_negative(neg);
}
for (; str[i] >= '0' && str[i] <= '9' && str[i] != '\0'; i++) {
nb = nb * 10;
nb = nb + (str[i] - 48);
if (nb < 0)
return (0);
}
return (result(nb, neg));
}
|
the_stack_data/175143139.c
|
//@ ltl invariant negative: (AP(x_2 - x_4 >= 16) || (AP(x_10 - x_15 >= 19) && AP(x_15 - x_9 >= -12)));
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;
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_;
while(1) {
x_0_ = ((((9.0 + x_0) > (13.0 + x_4)? (9.0 + x_0) : (13.0 + x_4)) > ((11.0 + x_5) > (3.0 + x_8)? (11.0 + x_5) : (3.0 + x_8))? ((9.0 + x_0) > (13.0 + x_4)? (9.0 + x_0) : (13.0 + x_4)) : ((11.0 + x_5) > (3.0 + x_8)? (11.0 + x_5) : (3.0 + x_8))) > (((18.0 + x_9) > (11.0 + x_10)? (18.0 + x_9) : (11.0 + x_10)) > ((1.0 + x_14) > (11.0 + x_15)? (1.0 + x_14) : (11.0 + x_15))? ((18.0 + x_9) > (11.0 + x_10)? (18.0 + x_9) : (11.0 + x_10)) : ((1.0 + x_14) > (11.0 + x_15)? (1.0 + x_14) : (11.0 + x_15)))? (((9.0 + x_0) > (13.0 + x_4)? (9.0 + x_0) : (13.0 + x_4)) > ((11.0 + x_5) > (3.0 + x_8)? (11.0 + x_5) : (3.0 + x_8))? ((9.0 + x_0) > (13.0 + x_4)? (9.0 + x_0) : (13.0 + x_4)) : ((11.0 + x_5) > (3.0 + x_8)? (11.0 + x_5) : (3.0 + x_8))) : (((18.0 + x_9) > (11.0 + x_10)? (18.0 + x_9) : (11.0 + x_10)) > ((1.0 + x_14) > (11.0 + x_15)? (1.0 + x_14) : (11.0 + x_15))? ((18.0 + x_9) > (11.0 + x_10)? (18.0 + x_9) : (11.0 + x_10)) : ((1.0 + x_14) > (11.0 + x_15)? (1.0 + x_14) : (11.0 + x_15))));
x_1_ = ((((18.0 + x_1) > (1.0 + x_2)? (18.0 + x_1) : (1.0 + x_2)) > ((2.0 + x_3) > (5.0 + x_5)? (2.0 + x_3) : (5.0 + x_5))? ((18.0 + x_1) > (1.0 + x_2)? (18.0 + x_1) : (1.0 + x_2)) : ((2.0 + x_3) > (5.0 + x_5)? (2.0 + x_3) : (5.0 + x_5))) > (((10.0 + x_6) > (10.0 + x_11)? (10.0 + x_6) : (10.0 + x_11)) > ((14.0 + x_12) > (8.0 + x_15)? (14.0 + x_12) : (8.0 + x_15))? ((10.0 + x_6) > (10.0 + x_11)? (10.0 + x_6) : (10.0 + x_11)) : ((14.0 + x_12) > (8.0 + x_15)? (14.0 + x_12) : (8.0 + x_15)))? (((18.0 + x_1) > (1.0 + x_2)? (18.0 + x_1) : (1.0 + x_2)) > ((2.0 + x_3) > (5.0 + x_5)? (2.0 + x_3) : (5.0 + x_5))? ((18.0 + x_1) > (1.0 + x_2)? (18.0 + x_1) : (1.0 + x_2)) : ((2.0 + x_3) > (5.0 + x_5)? (2.0 + x_3) : (5.0 + x_5))) : (((10.0 + x_6) > (10.0 + x_11)? (10.0 + x_6) : (10.0 + x_11)) > ((14.0 + x_12) > (8.0 + x_15)? (14.0 + x_12) : (8.0 + x_15))? ((10.0 + x_6) > (10.0 + x_11)? (10.0 + x_6) : (10.0 + x_11)) : ((14.0 + x_12) > (8.0 + x_15)? (14.0 + x_12) : (8.0 + x_15))));
x_2_ = ((((17.0 + x_1) > (2.0 + x_3)? (17.0 + x_1) : (2.0 + x_3)) > ((2.0 + x_5) > (3.0 + x_6)? (2.0 + x_5) : (3.0 + x_6))? ((17.0 + x_1) > (2.0 + x_3)? (17.0 + x_1) : (2.0 + x_3)) : ((2.0 + x_5) > (3.0 + x_6)? (2.0 + x_5) : (3.0 + x_6))) > (((10.0 + x_8) > (6.0 + x_10)? (10.0 + x_8) : (6.0 + x_10)) > ((14.0 + x_11) > (17.0 + x_15)? (14.0 + x_11) : (17.0 + x_15))? ((10.0 + x_8) > (6.0 + x_10)? (10.0 + x_8) : (6.0 + x_10)) : ((14.0 + x_11) > (17.0 + x_15)? (14.0 + x_11) : (17.0 + x_15)))? (((17.0 + x_1) > (2.0 + x_3)? (17.0 + x_1) : (2.0 + x_3)) > ((2.0 + x_5) > (3.0 + x_6)? (2.0 + x_5) : (3.0 + x_6))? ((17.0 + x_1) > (2.0 + x_3)? (17.0 + x_1) : (2.0 + x_3)) : ((2.0 + x_5) > (3.0 + x_6)? (2.0 + x_5) : (3.0 + x_6))) : (((10.0 + x_8) > (6.0 + x_10)? (10.0 + x_8) : (6.0 + x_10)) > ((14.0 + x_11) > (17.0 + x_15)? (14.0 + x_11) : (17.0 + x_15))? ((10.0 + x_8) > (6.0 + x_10)? (10.0 + x_8) : (6.0 + x_10)) : ((14.0 + x_11) > (17.0 + x_15)? (14.0 + x_11) : (17.0 + x_15))));
x_3_ = ((((8.0 + x_0) > (6.0 + x_5)? (8.0 + x_0) : (6.0 + x_5)) > ((7.0 + x_6) > (1.0 + x_7)? (7.0 + x_6) : (1.0 + x_7))? ((8.0 + x_0) > (6.0 + x_5)? (8.0 + x_0) : (6.0 + x_5)) : ((7.0 + x_6) > (1.0 + x_7)? (7.0 + x_6) : (1.0 + x_7))) > (((4.0 + x_8) > (2.0 + x_9)? (4.0 + x_8) : (2.0 + x_9)) > ((8.0 + x_11) > (10.0 + x_15)? (8.0 + x_11) : (10.0 + x_15))? ((4.0 + x_8) > (2.0 + x_9)? (4.0 + x_8) : (2.0 + x_9)) : ((8.0 + x_11) > (10.0 + x_15)? (8.0 + x_11) : (10.0 + x_15)))? (((8.0 + x_0) > (6.0 + x_5)? (8.0 + x_0) : (6.0 + x_5)) > ((7.0 + x_6) > (1.0 + x_7)? (7.0 + x_6) : (1.0 + x_7))? ((8.0 + x_0) > (6.0 + x_5)? (8.0 + x_0) : (6.0 + x_5)) : ((7.0 + x_6) > (1.0 + x_7)? (7.0 + x_6) : (1.0 + x_7))) : (((4.0 + x_8) > (2.0 + x_9)? (4.0 + x_8) : (2.0 + x_9)) > ((8.0 + x_11) > (10.0 + x_15)? (8.0 + x_11) : (10.0 + x_15))? ((4.0 + x_8) > (2.0 + x_9)? (4.0 + x_8) : (2.0 + x_9)) : ((8.0 + x_11) > (10.0 + x_15)? (8.0 + x_11) : (10.0 + x_15))));
x_4_ = ((((12.0 + x_2) > (13.0 + x_4)? (12.0 + x_2) : (13.0 + x_4)) > ((9.0 + x_5) > (10.0 + x_8)? (9.0 + x_5) : (10.0 + x_8))? ((12.0 + x_2) > (13.0 + x_4)? (12.0 + x_2) : (13.0 + x_4)) : ((9.0 + x_5) > (10.0 + x_8)? (9.0 + x_5) : (10.0 + x_8))) > (((6.0 + x_10) > (3.0 + x_11)? (6.0 + x_10) : (3.0 + x_11)) > ((3.0 + x_13) > (12.0 + x_14)? (3.0 + x_13) : (12.0 + x_14))? ((6.0 + x_10) > (3.0 + x_11)? (6.0 + x_10) : (3.0 + x_11)) : ((3.0 + x_13) > (12.0 + x_14)? (3.0 + x_13) : (12.0 + x_14)))? (((12.0 + x_2) > (13.0 + x_4)? (12.0 + x_2) : (13.0 + x_4)) > ((9.0 + x_5) > (10.0 + x_8)? (9.0 + x_5) : (10.0 + x_8))? ((12.0 + x_2) > (13.0 + x_4)? (12.0 + x_2) : (13.0 + x_4)) : ((9.0 + x_5) > (10.0 + x_8)? (9.0 + x_5) : (10.0 + x_8))) : (((6.0 + x_10) > (3.0 + x_11)? (6.0 + x_10) : (3.0 + x_11)) > ((3.0 + x_13) > (12.0 + x_14)? (3.0 + x_13) : (12.0 + x_14))? ((6.0 + x_10) > (3.0 + x_11)? (6.0 + x_10) : (3.0 + x_11)) : ((3.0 + x_13) > (12.0 + x_14)? (3.0 + x_13) : (12.0 + x_14))));
x_5_ = ((((16.0 + x_2) > (9.0 + x_3)? (16.0 + x_2) : (9.0 + x_3)) > ((4.0 + x_5) > (16.0 + x_6)? (4.0 + x_5) : (16.0 + x_6))? ((16.0 + x_2) > (9.0 + x_3)? (16.0 + x_2) : (9.0 + x_3)) : ((4.0 + x_5) > (16.0 + x_6)? (4.0 + x_5) : (16.0 + x_6))) > (((16.0 + x_9) > (16.0 + x_12)? (16.0 + x_9) : (16.0 + x_12)) > ((5.0 + x_13) > (14.0 + x_14)? (5.0 + x_13) : (14.0 + x_14))? ((16.0 + x_9) > (16.0 + x_12)? (16.0 + x_9) : (16.0 + x_12)) : ((5.0 + x_13) > (14.0 + x_14)? (5.0 + x_13) : (14.0 + x_14)))? (((16.0 + x_2) > (9.0 + x_3)? (16.0 + x_2) : (9.0 + x_3)) > ((4.0 + x_5) > (16.0 + x_6)? (4.0 + x_5) : (16.0 + x_6))? ((16.0 + x_2) > (9.0 + x_3)? (16.0 + x_2) : (9.0 + x_3)) : ((4.0 + x_5) > (16.0 + x_6)? (4.0 + x_5) : (16.0 + x_6))) : (((16.0 + x_9) > (16.0 + x_12)? (16.0 + x_9) : (16.0 + x_12)) > ((5.0 + x_13) > (14.0 + x_14)? (5.0 + x_13) : (14.0 + x_14))? ((16.0 + x_9) > (16.0 + x_12)? (16.0 + x_9) : (16.0 + x_12)) : ((5.0 + x_13) > (14.0 + x_14)? (5.0 + x_13) : (14.0 + x_14))));
x_6_ = ((((7.0 + x_4) > (15.0 + x_5)? (7.0 + x_4) : (15.0 + x_5)) > ((8.0 + x_6) > (5.0 + x_7)? (8.0 + x_6) : (5.0 + x_7))? ((7.0 + x_4) > (15.0 + x_5)? (7.0 + x_4) : (15.0 + x_5)) : ((8.0 + x_6) > (5.0 + x_7)? (8.0 + x_6) : (5.0 + x_7))) > (((19.0 + x_8) > (19.0 + x_11)? (19.0 + x_8) : (19.0 + x_11)) > ((20.0 + x_13) > (14.0 + x_14)? (20.0 + x_13) : (14.0 + x_14))? ((19.0 + x_8) > (19.0 + x_11)? (19.0 + x_8) : (19.0 + x_11)) : ((20.0 + x_13) > (14.0 + x_14)? (20.0 + x_13) : (14.0 + x_14)))? (((7.0 + x_4) > (15.0 + x_5)? (7.0 + x_4) : (15.0 + x_5)) > ((8.0 + x_6) > (5.0 + x_7)? (8.0 + x_6) : (5.0 + x_7))? ((7.0 + x_4) > (15.0 + x_5)? (7.0 + x_4) : (15.0 + x_5)) : ((8.0 + x_6) > (5.0 + x_7)? (8.0 + x_6) : (5.0 + x_7))) : (((19.0 + x_8) > (19.0 + x_11)? (19.0 + x_8) : (19.0 + x_11)) > ((20.0 + x_13) > (14.0 + x_14)? (20.0 + x_13) : (14.0 + x_14))? ((19.0 + x_8) > (19.0 + x_11)? (19.0 + x_8) : (19.0 + x_11)) : ((20.0 + x_13) > (14.0 + x_14)? (20.0 + x_13) : (14.0 + x_14))));
x_7_ = ((((5.0 + x_1) > (20.0 + x_4)? (5.0 + x_1) : (20.0 + x_4)) > ((19.0 + x_9) > (14.0 + x_10)? (19.0 + x_9) : (14.0 + x_10))? ((5.0 + x_1) > (20.0 + x_4)? (5.0 + x_1) : (20.0 + x_4)) : ((19.0 + x_9) > (14.0 + x_10)? (19.0 + x_9) : (14.0 + x_10))) > (((7.0 + x_12) > (10.0 + x_13)? (7.0 + x_12) : (10.0 + x_13)) > ((17.0 + x_14) > (16.0 + x_15)? (17.0 + x_14) : (16.0 + x_15))? ((7.0 + x_12) > (10.0 + x_13)? (7.0 + x_12) : (10.0 + x_13)) : ((17.0 + x_14) > (16.0 + x_15)? (17.0 + x_14) : (16.0 + x_15)))? (((5.0 + x_1) > (20.0 + x_4)? (5.0 + x_1) : (20.0 + x_4)) > ((19.0 + x_9) > (14.0 + x_10)? (19.0 + x_9) : (14.0 + x_10))? ((5.0 + x_1) > (20.0 + x_4)? (5.0 + x_1) : (20.0 + x_4)) : ((19.0 + x_9) > (14.0 + x_10)? (19.0 + x_9) : (14.0 + x_10))) : (((7.0 + x_12) > (10.0 + x_13)? (7.0 + x_12) : (10.0 + x_13)) > ((17.0 + x_14) > (16.0 + x_15)? (17.0 + x_14) : (16.0 + x_15))? ((7.0 + x_12) > (10.0 + x_13)? (7.0 + x_12) : (10.0 + x_13)) : ((17.0 + x_14) > (16.0 + x_15)? (17.0 + x_14) : (16.0 + x_15))));
x_8_ = ((((5.0 + x_0) > (15.0 + x_6)? (5.0 + x_0) : (15.0 + x_6)) > ((14.0 + x_7) > (2.0 + x_8)? (14.0 + x_7) : (2.0 + x_8))? ((5.0 + x_0) > (15.0 + x_6)? (5.0 + x_0) : (15.0 + x_6)) : ((14.0 + x_7) > (2.0 + x_8)? (14.0 + x_7) : (2.0 + x_8))) > (((20.0 + x_9) > (5.0 + x_10)? (20.0 + x_9) : (5.0 + x_10)) > ((2.0 + x_13) > (11.0 + x_14)? (2.0 + x_13) : (11.0 + x_14))? ((20.0 + x_9) > (5.0 + x_10)? (20.0 + x_9) : (5.0 + x_10)) : ((2.0 + x_13) > (11.0 + x_14)? (2.0 + x_13) : (11.0 + x_14)))? (((5.0 + x_0) > (15.0 + x_6)? (5.0 + x_0) : (15.0 + x_6)) > ((14.0 + x_7) > (2.0 + x_8)? (14.0 + x_7) : (2.0 + x_8))? ((5.0 + x_0) > (15.0 + x_6)? (5.0 + x_0) : (15.0 + x_6)) : ((14.0 + x_7) > (2.0 + x_8)? (14.0 + x_7) : (2.0 + x_8))) : (((20.0 + x_9) > (5.0 + x_10)? (20.0 + x_9) : (5.0 + x_10)) > ((2.0 + x_13) > (11.0 + x_14)? (2.0 + x_13) : (11.0 + x_14))? ((20.0 + x_9) > (5.0 + x_10)? (20.0 + x_9) : (5.0 + x_10)) : ((2.0 + x_13) > (11.0 + x_14)? (2.0 + x_13) : (11.0 + x_14))));
x_9_ = ((((7.0 + x_1) > (10.0 + x_2)? (7.0 + x_1) : (10.0 + x_2)) > ((1.0 + x_4) > (13.0 + x_6)? (1.0 + x_4) : (13.0 + x_6))? ((7.0 + x_1) > (10.0 + x_2)? (7.0 + x_1) : (10.0 + x_2)) : ((1.0 + x_4) > (13.0 + x_6)? (1.0 + x_4) : (13.0 + x_6))) > (((2.0 + x_7) > (2.0 + x_9)? (2.0 + x_7) : (2.0 + x_9)) > ((3.0 + x_10) > (5.0 + x_12)? (3.0 + x_10) : (5.0 + x_12))? ((2.0 + x_7) > (2.0 + x_9)? (2.0 + x_7) : (2.0 + x_9)) : ((3.0 + x_10) > (5.0 + x_12)? (3.0 + x_10) : (5.0 + x_12)))? (((7.0 + x_1) > (10.0 + x_2)? (7.0 + x_1) : (10.0 + x_2)) > ((1.0 + x_4) > (13.0 + x_6)? (1.0 + x_4) : (13.0 + x_6))? ((7.0 + x_1) > (10.0 + x_2)? (7.0 + x_1) : (10.0 + x_2)) : ((1.0 + x_4) > (13.0 + x_6)? (1.0 + x_4) : (13.0 + x_6))) : (((2.0 + x_7) > (2.0 + x_9)? (2.0 + x_7) : (2.0 + x_9)) > ((3.0 + x_10) > (5.0 + x_12)? (3.0 + x_10) : (5.0 + x_12))? ((2.0 + x_7) > (2.0 + x_9)? (2.0 + x_7) : (2.0 + x_9)) : ((3.0 + x_10) > (5.0 + x_12)? (3.0 + x_10) : (5.0 + x_12))));
x_10_ = ((((8.0 + x_0) > (20.0 + x_3)? (8.0 + x_0) : (20.0 + x_3)) > ((8.0 + x_4) > (8.0 + x_5)? (8.0 + x_4) : (8.0 + x_5))? ((8.0 + x_0) > (20.0 + x_3)? (8.0 + x_0) : (20.0 + x_3)) : ((8.0 + x_4) > (8.0 + x_5)? (8.0 + x_4) : (8.0 + x_5))) > (((17.0 + x_7) > (18.0 + x_12)? (17.0 + x_7) : (18.0 + x_12)) > ((14.0 + x_14) > (6.0 + x_15)? (14.0 + x_14) : (6.0 + x_15))? ((17.0 + x_7) > (18.0 + x_12)? (17.0 + x_7) : (18.0 + x_12)) : ((14.0 + x_14) > (6.0 + x_15)? (14.0 + x_14) : (6.0 + x_15)))? (((8.0 + x_0) > (20.0 + x_3)? (8.0 + x_0) : (20.0 + x_3)) > ((8.0 + x_4) > (8.0 + x_5)? (8.0 + x_4) : (8.0 + x_5))? ((8.0 + x_0) > (20.0 + x_3)? (8.0 + x_0) : (20.0 + x_3)) : ((8.0 + x_4) > (8.0 + x_5)? (8.0 + x_4) : (8.0 + x_5))) : (((17.0 + x_7) > (18.0 + x_12)? (17.0 + x_7) : (18.0 + x_12)) > ((14.0 + x_14) > (6.0 + x_15)? (14.0 + x_14) : (6.0 + x_15))? ((17.0 + x_7) > (18.0 + x_12)? (17.0 + x_7) : (18.0 + x_12)) : ((14.0 + x_14) > (6.0 + x_15)? (14.0 + x_14) : (6.0 + x_15))));
x_11_ = ((((14.0 + x_4) > (9.0 + x_5)? (14.0 + x_4) : (9.0 + x_5)) > ((9.0 + x_6) > (5.0 + x_8)? (9.0 + x_6) : (5.0 + x_8))? ((14.0 + x_4) > (9.0 + x_5)? (14.0 + x_4) : (9.0 + x_5)) : ((9.0 + x_6) > (5.0 + x_8)? (9.0 + x_6) : (5.0 + x_8))) > (((13.0 + x_9) > (20.0 + x_11)? (13.0 + x_9) : (20.0 + x_11)) > ((3.0 + x_12) > (6.0 + x_14)? (3.0 + x_12) : (6.0 + x_14))? ((13.0 + x_9) > (20.0 + x_11)? (13.0 + x_9) : (20.0 + x_11)) : ((3.0 + x_12) > (6.0 + x_14)? (3.0 + x_12) : (6.0 + x_14)))? (((14.0 + x_4) > (9.0 + x_5)? (14.0 + x_4) : (9.0 + x_5)) > ((9.0 + x_6) > (5.0 + x_8)? (9.0 + x_6) : (5.0 + x_8))? ((14.0 + x_4) > (9.0 + x_5)? (14.0 + x_4) : (9.0 + x_5)) : ((9.0 + x_6) > (5.0 + x_8)? (9.0 + x_6) : (5.0 + x_8))) : (((13.0 + x_9) > (20.0 + x_11)? (13.0 + x_9) : (20.0 + x_11)) > ((3.0 + x_12) > (6.0 + x_14)? (3.0 + x_12) : (6.0 + x_14))? ((13.0 + x_9) > (20.0 + x_11)? (13.0 + x_9) : (20.0 + x_11)) : ((3.0 + x_12) > (6.0 + x_14)? (3.0 + x_12) : (6.0 + x_14))));
x_12_ = ((((7.0 + x_0) > (17.0 + x_5)? (7.0 + x_0) : (17.0 + x_5)) > ((7.0 + x_7) > (18.0 + x_9)? (7.0 + x_7) : (18.0 + x_9))? ((7.0 + x_0) > (17.0 + x_5)? (7.0 + x_0) : (17.0 + x_5)) : ((7.0 + x_7) > (18.0 + x_9)? (7.0 + x_7) : (18.0 + x_9))) > (((5.0 + x_10) > (9.0 + x_11)? (5.0 + x_10) : (9.0 + x_11)) > ((20.0 + x_13) > (2.0 + x_15)? (20.0 + x_13) : (2.0 + x_15))? ((5.0 + x_10) > (9.0 + x_11)? (5.0 + x_10) : (9.0 + x_11)) : ((20.0 + x_13) > (2.0 + x_15)? (20.0 + x_13) : (2.0 + x_15)))? (((7.0 + x_0) > (17.0 + x_5)? (7.0 + x_0) : (17.0 + x_5)) > ((7.0 + x_7) > (18.0 + x_9)? (7.0 + x_7) : (18.0 + x_9))? ((7.0 + x_0) > (17.0 + x_5)? (7.0 + x_0) : (17.0 + x_5)) : ((7.0 + x_7) > (18.0 + x_9)? (7.0 + x_7) : (18.0 + x_9))) : (((5.0 + x_10) > (9.0 + x_11)? (5.0 + x_10) : (9.0 + x_11)) > ((20.0 + x_13) > (2.0 + x_15)? (20.0 + x_13) : (2.0 + x_15))? ((5.0 + x_10) > (9.0 + x_11)? (5.0 + x_10) : (9.0 + x_11)) : ((20.0 + x_13) > (2.0 + x_15)? (20.0 + x_13) : (2.0 + x_15))));
x_13_ = ((((8.0 + x_1) > (20.0 + x_2)? (8.0 + x_1) : (20.0 + x_2)) > ((10.0 + x_3) > (16.0 + x_10)? (10.0 + x_3) : (16.0 + x_10))? ((8.0 + x_1) > (20.0 + x_2)? (8.0 + x_1) : (20.0 + x_2)) : ((10.0 + x_3) > (16.0 + x_10)? (10.0 + x_3) : (16.0 + x_10))) > (((17.0 + x_11) > (1.0 + x_13)? (17.0 + x_11) : (1.0 + x_13)) > ((13.0 + x_14) > (20.0 + x_15)? (13.0 + x_14) : (20.0 + x_15))? ((17.0 + x_11) > (1.0 + x_13)? (17.0 + x_11) : (1.0 + x_13)) : ((13.0 + x_14) > (20.0 + x_15)? (13.0 + x_14) : (20.0 + x_15)))? (((8.0 + x_1) > (20.0 + x_2)? (8.0 + x_1) : (20.0 + x_2)) > ((10.0 + x_3) > (16.0 + x_10)? (10.0 + x_3) : (16.0 + x_10))? ((8.0 + x_1) > (20.0 + x_2)? (8.0 + x_1) : (20.0 + x_2)) : ((10.0 + x_3) > (16.0 + x_10)? (10.0 + x_3) : (16.0 + x_10))) : (((17.0 + x_11) > (1.0 + x_13)? (17.0 + x_11) : (1.0 + x_13)) > ((13.0 + x_14) > (20.0 + x_15)? (13.0 + x_14) : (20.0 + x_15))? ((17.0 + x_11) > (1.0 + x_13)? (17.0 + x_11) : (1.0 + x_13)) : ((13.0 + x_14) > (20.0 + x_15)? (13.0 + x_14) : (20.0 + x_15))));
x_14_ = ((((19.0 + x_0) > (12.0 + x_3)? (19.0 + x_0) : (12.0 + x_3)) > ((9.0 + x_6) > (18.0 + x_7)? (9.0 + x_6) : (18.0 + x_7))? ((19.0 + x_0) > (12.0 + x_3)? (19.0 + x_0) : (12.0 + x_3)) : ((9.0 + x_6) > (18.0 + x_7)? (9.0 + x_6) : (18.0 + x_7))) > (((10.0 + x_10) > (19.0 + x_13)? (10.0 + x_10) : (19.0 + x_13)) > ((19.0 + x_14) > (11.0 + x_15)? (19.0 + x_14) : (11.0 + x_15))? ((10.0 + x_10) > (19.0 + x_13)? (10.0 + x_10) : (19.0 + x_13)) : ((19.0 + x_14) > (11.0 + x_15)? (19.0 + x_14) : (11.0 + x_15)))? (((19.0 + x_0) > (12.0 + x_3)? (19.0 + x_0) : (12.0 + x_3)) > ((9.0 + x_6) > (18.0 + x_7)? (9.0 + x_6) : (18.0 + x_7))? ((19.0 + x_0) > (12.0 + x_3)? (19.0 + x_0) : (12.0 + x_3)) : ((9.0 + x_6) > (18.0 + x_7)? (9.0 + x_6) : (18.0 + x_7))) : (((10.0 + x_10) > (19.0 + x_13)? (10.0 + x_10) : (19.0 + x_13)) > ((19.0 + x_14) > (11.0 + x_15)? (19.0 + x_14) : (11.0 + x_15))? ((10.0 + x_10) > (19.0 + x_13)? (10.0 + x_10) : (19.0 + x_13)) : ((19.0 + x_14) > (11.0 + x_15)? (19.0 + x_14) : (11.0 + x_15))));
x_15_ = ((((10.0 + x_1) > (12.0 + x_2)? (10.0 + x_1) : (12.0 + x_2)) > ((10.0 + x_4) > (11.0 + x_5)? (10.0 + x_4) : (11.0 + x_5))? ((10.0 + x_1) > (12.0 + x_2)? (10.0 + x_1) : (12.0 + x_2)) : ((10.0 + x_4) > (11.0 + x_5)? (10.0 + x_4) : (11.0 + x_5))) > (((20.0 + x_8) > (20.0 + x_11)? (20.0 + x_8) : (20.0 + x_11)) > ((1.0 + x_12) > (19.0 + x_15)? (1.0 + x_12) : (19.0 + x_15))? ((20.0 + x_8) > (20.0 + x_11)? (20.0 + x_8) : (20.0 + x_11)) : ((1.0 + x_12) > (19.0 + x_15)? (1.0 + x_12) : (19.0 + x_15)))? (((10.0 + x_1) > (12.0 + x_2)? (10.0 + x_1) : (12.0 + x_2)) > ((10.0 + x_4) > (11.0 + x_5)? (10.0 + x_4) : (11.0 + x_5))? ((10.0 + x_1) > (12.0 + x_2)? (10.0 + x_1) : (12.0 + x_2)) : ((10.0 + x_4) > (11.0 + x_5)? (10.0 + x_4) : (11.0 + x_5))) : (((20.0 + x_8) > (20.0 + x_11)? (20.0 + x_8) : (20.0 + x_11)) > ((1.0 + x_12) > (19.0 + x_15)? (1.0 + x_12) : (19.0 + x_15))? ((20.0 + x_8) > (20.0 + x_11)? (20.0 + x_8) : (20.0 + x_11)) : ((1.0 + x_12) > (19.0 + x_15)? (1.0 + x_12) : (19.0 + x_15))));
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_;
}
return 0;
}
|
the_stack_data/147643.c
|
/* $OpenBSD: inet_addr.c,v 1.9 2005/08/06 20:30:03 espie Exp $ */
/*
* ++Copyright++ 1983, 1990, 1993
* -
* Copyright (c) 1983, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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.
* -
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies, and that
* the name of Digital Equipment Corporation not be used in advertising or
* publicity pertaining to distribution of the document or software without
* specific, written prior permission.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
* -
* --Copyright--
*/
#include <sys/types.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ctype.h>
/*
* Ascii internet address interpretation routine.
* The value returned is in network order.
*/
in_addr_t
inet_addr(const char *cp)
{
struct in_addr val;
if (inet_aton(cp, &val))
return (val.s_addr);
return (INADDR_NONE);
}
|
the_stack_data/111079335.c
|
#include <stdlib.h>
void main(void) {
stampa_cornicetta("Errico sei uno stronzo ");
}
|
the_stack_data/1153283.c
|
#include <stdio.h>
#include <stdlib.h>
void enum_strings(char *s, int a, int b, int start)
{
if (a == 0 && b == 0) {
s[start] == '\0';
printf("%s\n", s);
return;
}
if (a > 0) {
s[start] = 'A';
enum_strings(s, a-1, b, start+1);
}
if (b > 0) {
s[start] = 'B';
enum_strings(s, a, b-1, start+1);
}
}
main(int argc, char **argv)
{
char *s;
int a, b;
if (argc != 3 || sscanf(argv[1], "%d", &a) == 0 ||
sscanf(argv[1], "%d", &b) == 0 ||
a < 0 || b < 0) {
fprintf(stderr, "usage: q8 a b\n");
exit(1);
}
s = (char *) malloc(sizeof(char) * (a + b + 1));
enum_strings(s, a, b, 0);
}
|
the_stack_data/144898.c
|
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#if defined(__linux__)
# define MODEM "/dev/ttyACM0"
#elif defined(__APPLE__)
# define MODEM "/dev/cu.usbmodem0000001"
#elif defined(__NetBSD__)
# define MODEM "/dev/dtyU0"
#elif defined(__bsdi__) || defined(__DragonFly__)
# define MODEM "/dev/cuaU0"
#endif
static void make_blocking(int fd)
{
const int old = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, old & ~(int)O_NONBLOCK);
}
static void make_nonblocking(int fd)
{
const int old = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, old | (int)O_NONBLOCK);
}
/* gcc -Wall -g3 -O1 -std=c99 modem-read.c -o modem-read */
int main(int argc, char* argv[])
{
int fd = open(MODEM, O_RDWR | O_NOCTTY | O_SYNC);
if (fd == -1) {
printf("open failed\n");
goto finish;
}
printf("Setting TIOCEXCL\n");
/* Mark the fd as exclusive so ModemManager */
/* and friends cannot open and muck with state. */
if (ioctl(fd, TIOCEXCL, NULL) == -1) {
printf("ioctl failed\n");
goto finish;
}
printf("Getting tty\n");
struct termios tty;
if (tcgetattr(fd, &tty) != 0) {
printf("tcgetattr failed\n");
goto finish;
}
printf("Setting tty options\n");
cfmakeraw(&tty);
tty.c_cflag |= (CLOCAL | CRTSCTS);
// tty.c_cflag &= ~CSTOPB; /* 1 stop bit */
// tty.c_cflag |= CSTOPB; /* 2 stop bit */
cfsetospeed(&tty, B57600);
cfsetispeed(&tty, B57600);
printf("Flushing tty\n");
if (tcflush(fd, TCIOFLUSH) != 0) {
printf("tcflush failed\n");
goto finish;
}
printf("Setting tty\n");
if (tcsetattr(fd, TCSANOW, &tty) != 0) {
printf("tcsetattr failed\n");
goto finish;
}
/*********** Write ***********/
printf("Writing ATZ\n");
ssize_t res = write(fd, "ATZ\r", 4);
if (res == -1) {
printf("write failed\n");
goto finish;
}
printf("Waiting for write\n");
res = tcdrain(fd);
if (res == -1) {
printf("tcdrain failed\n");
goto finish;
}
printf("Wrote: ATZ\n");
/*********** Read ***********/
printf("Reading response\n");
make_blocking(fd);
for ( ; ; )
{
unsigned char buf[512];
res = read(fd, buf, sizeof(buf));
if (res == -1 && errno == EWOULDBLOCK) {
break;
}
else if (res == -1) {
printf("read failed\n");
goto finish;
}
make_nonblocking(fd);
buf[res] = '\0';
printf("Read: %s\n", buf);
}
finish:
if (fd != -1)
close(fd);
return 0;
}
|
the_stack_data/182954157.c
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAP_SCALE 16
#define BOOM_NUMBER 40
#define BOOM 9
#define BORDER 12
#define NONE "\033[m"
#define L_RED "\033[1;32;31m"
#define L_BLUE "\033[1;32;32m"
#define L_YELLO "\033[1;33m"
int map_value[ MAP_SCALE + 2 ][ MAP_SCALE + 2 ] = {0};/*存下炸彈的位置*/
int map_status[ MAP_SCALE + 2 ][ MAP_SCALE + 2 ] = {0};/*紀錄該位置的含義*/
int map_print[ MAP_SCALE + 2 ][ MAP_SCALE + 2 ] = {0};/*記錄要印出來的位置*/
int counter = 0;/*防止第一次踩到地雷*/
int flag = 0;
/*
flag -> 遊戲狀態
0 -> 預設
1 -> 勝利
2 -> 失敗
3 -> Give up
*/
void welcome();/*顯示歡迎畫面*/
void initialize();/*初始化地圖*/
void proceed();/*讓使用者輸入指令*/
void dig();/*踩下去*/
void find_space( int, int );/*空白擴散*/
void flg();/*立旗子*/
void print_graph();/*輸出圖形*/
void win();/*輸出勝利訊息*/
void lose();/*輸出失敗訊息*/
void give_up();/*輸出放棄訊息*/
void byebye();/*顯示結束畫面*/
int main()
{
srand( time(NULL) );
//start
system("clear");
welcome();
initialize();
print_graph();
do {
proceed();
} while ( flag == 0 );
if ( flag == 1 )
goto win;
else if ( flag == 2 )
goto lose;
else if ( flag == 3 )
goto give_up;
else /*例外錯誤*/
goto exit_bug;
win:
win();
print_graph();
goto exit;
lose:
lose();
print_graph();
goto exit;
give_up:
give_up();
print_graph();
goto exit;
exit:
byebye();
return 0;
exit_bug:
exit(1);
}
void welcome()
{
printf(L_BLUE"========================================================\n");
printf("| 踩地雷 made by hydai |\n");
printf("| |\n");
printf("| How to play: |\n");
printf("| |\n");
printf("| 1. d x y = 在(x,y)座標踩下去 |\n");
printf("| 2. f x y = 在(x,y)座標標旗子 |\n");
printf("| 3. q = 放棄遊戲(印出地雷) |\n");
printf("| |\n");
printf("| 注意!必須把所有旗子插完才算獲勝 |\n");
printf("| |\n");
printf("========================================================\n"NONE);
usleep(3000000);
}
void initialize()
{
int i, j;
int tmp_row, tmp_col;
for ( i = 1 ; i <= MAP_SCALE ; i++ )
for ( j = 1 ; j <= MAP_SCALE ; j++ )
{
map_value[i][j] = 0;
}
for ( i = 0 ; ; )
{
tmp_row = rand() % MAP_SCALE + 1;
tmp_col = rand() % MAP_SCALE + 1;
if ( map_value[tmp_row][tmp_col] == 1 )
continue;
if ( i >= BOOM_NUMBER )
break;
map_value[tmp_row][tmp_col] = 1;
i++;
}
for ( i = 1 ; i <= MAP_SCALE ; i++ )
for ( j = 1 ; j <= MAP_SCALE ; j++ )
map_status[i][j] = map_value[i-1][j-1] + map_value[i-1][j] + map_value[i-1][j+1] + map_value[i][j-1] + map_value[i][j+1] + map_value[i+1][j-1] + map_value[i+1][j] + map_value[i+1][j+1];
for ( i = 1 ; i <= MAP_SCALE ; i++ )
for ( j = 1 ; j <= MAP_SCALE ; j++ )
if ( map_value[i][j] == 1 )
map_status[i][j] = BOOM;
}
void proceed()
{
char input;
re_get:
scanf("%c", &input);
switch ( input )
{
case 'd':
dig();
break;
case 'f':
flg();
break;
case 'q':
flag = 3;
return;
default:
print_graph();
//printf("查無指令!請重新輸入!\n");
goto re_get;
}
if ( flag == 0 )
print_graph();
}
void dig()
{
int x, y;
printf(L_RED"請輸入 (x,y)\n"NONE);
scanf("%d%d", &x, &y);
if ( (x < 1) || (x > MAP_SCALE) || (y < 1) || (y > MAP_SCALE) )
{
printf(L_RED"輸入座標錯誤!\n"NONE);
return;
}
/*以防第一次踩到地雷*/
while ( counter == 0 )
{
if ( map_value[x][y] == 1 )
{
initialize();
continue;
}
else
counter = 1;
}
switch ( map_status[x][y] )
{
case BOOM:
flag = 2;
return;
case 0:
find_space(x, y);
break;
default:
map_print[x][y] = 1;
break;
}
}
void find_space( int x, int y )
{
static int check[ MAP_SCALE + 2 ][ MAP_SCALE + 2 ] = {0};
if ( check[x][y] == 1 )
return;
if ( x < 1 || x > MAP_SCALE )
return;
if ( y < 1 || y > MAP_SCALE )
return;
check[x][y] = 1;
if ( map_status[x][y] != 0 )
return;
map_print[x-1][y] = 1;
map_print[x-1][y-1] = 1;
map_print[x-1][y+1] = 1;
map_print[x][y] = 1;
map_print[x][y-1] = 1;
map_print[x][y+1] = 1;
map_print[x+1][y] = 1;
map_print[x+1][y-1] = 1;
map_print[x+1][y+1] = 1;
find_space( x-1, y-1 );
find_space( x-1, y );
find_space( x-1, y+1 );
find_space( x, y-1 );
find_space( x, y+1 );
find_space( x+1, y-1 );
find_space( x+1, y );
find_space( x+1, y+1 );
}
void flg()
{
int x, y;
static int boom_left = BOOM_NUMBER;
printf(L_RED"請輸入 (x,y)\n"NONE);
scanf("%d%d", &x, &y);
if ( ((x < 1)&&(x > MAP_SCALE)) || ((y < 1)&&(y > MAP_SCALE)) )
{
printf(L_RED"輸入座標錯誤!\n"NONE);
return;
}
if ( map_print[x][y] != 0 )
if ( map_print[x][y] == 2 )
{
map_print[x][y] = 0;
if ( map_status[x][y] == BOOM )
boom_left++;
}
else
{
printf(L_RED"該位置無法立旗!\n"NONE);
return;
}
else
map_print[x][y] = 2;
switch ( map_status[x][y] )
{
case BOOM:
boom_left--;
break;
default:
break;
}
if ( boom_left == 0 )
flag = 1;
}
void print_graph()
{
int i, j;
system("clear");
printf(" ");
for ( i = 1 ; i <= MAP_SCALE ; i++ )
printf(L_YELLO"%d"NONE, i%10);
printf("\n");
printf(L_YELLO" ##################\n"NONE);
for ( i = 1 ; i <= MAP_SCALE ; i++ )
{
printf(L_YELLO"%d#"NONE, i%10);
for ( j = 1 ; j <= MAP_SCALE ; j++ )
{
if ( map_print[i][j] == 0 )
printf("-");
else if ( map_print[i][j] == 1 )
{
if ( map_status[i][j] != 0 && map_status[i][j] != BOOM )
printf("%d", map_status[i][j]);
if ( map_status[i][j] == 0 )
printf(" ");
if ( map_status[i][j] == BOOM )
printf(L_RED"*"NONE);
}
else
printf(L_BLUE"$"NONE);
}
printf(L_YELLO"#");
putchar(10);
}
printf(" ##################\n"NONE);
putchar(10);
/*use to debug*/
printf("value\n");
for ( i = 1 ; i < MAP_SCALE + 1 ; i++ )
{
for ( j = 1 ; j < MAP_SCALE + 1 ; j++ )
printf("%2d", map_value[i][j]);
putchar(10);
}
/*
putchar(10);
printf("status\n");
for ( i = 1 ; i < MAP_SCALE + 1 ; i++ )
{
for ( j = 1 ; j < MAP_SCALE + 1 ; j++ )
printf("%2d", map_status[i][j]);
putchar(10);
}
putchar(10);
printf("print\n");
for ( i = 1 ; i < MAP_SCALE + 1 ; i++ )
{
for ( j = 1 ; j < MAP_SCALE + 1 ; j++ )
printf("%2d", map_print[i][j]);
putchar(10);
}
*/
printf("1. 輸入d x y = 在(x,y)座標踩下去\n");
printf("2. 輸入f x y = 在(x,y)座標標旗子\n");
printf("3. q = 放棄遊戲(印出地雷)\n");
printf("請輸入指令:\n");
}
void win()
{
int i, j;
printf(L_RED"Congratulation, You Win!!\n"NONE);
usleep(5000000);
for ( i = 1 ; i <= MAP_SCALE ; i++ )
for ( j = 1 ; j <= MAP_SCALE ; j++ )
if ( map_print[i][j] != 2 )
map_print[i][j] = 1;
}
void lose()
{
int i, j;
printf(L_RED"Sorry, You lose!!\n"NONE);
usleep(5000000);
for ( i = 1 ; i <= MAP_SCALE ; i++ )
for ( j = 1 ; j <= MAP_SCALE ; j++ )
if ( map_status[i][j] == BOOM )
map_print[i][j] = 1;
}
void give_up()
{
int i, j;
printf(L_RED"So Sad, You Give Up !!\n"NONE);
usleep(5000000);
for ( i = 1 ; i <= MAP_SCALE ; i++ )
for ( j = 1 ; j <= MAP_SCALE ; j++ )
if ( map_print[i][j] != 2 )
map_print[i][j] = 1;
}
void byebye()
{
printf(L_BLUE"\n");
printf("========================================================\n");
printf("| 踩地雷 made by hydai |\n");
printf("| |\n");
printf("| Thank you for playing my game! |\n");
printf("| See you next time! |\n");
printf("| |\n");
printf("========================================================\n"NONE);
}
|
the_stack_data/243433.c
|
int main()
{
int non_det;
int x = 0;
for(int i = 0; i != 5; ++i)
{
int y = 0;
x++;
y = 1;
}
}
|
the_stack_data/133396.c
|
a[69],b[69];main(n){gets(a);n=strlen(a)+4;while(n-->0)b[n]='*';printf("%s\n* %s *\n%s",b,a,b);}
|
the_stack_data/170451808.c
|
#include<stdlib.h>
#include<stdio.h>
int contar_palavras(char frase[100], char palavra[100])
{
int i=0, j=0, k=0;
while (frase[i] != '0'){
while( (frase[i+j] != '\0') && (palavra[j] != '\0') && (frase[i+j]==palavra[j]) );
j++;
if(palavra[j] == '\0')
k++;
j=0;
i++;
}
return k;
}
int main()
{
char frase[100], palavra[100];
printf("Digite uma frase: ");
gets(frase);
printf("Agora, digite uma palavra: ");
gets(palavra);
printf("Esse texto contem %d ocorrencias da palavra %s.\n\n", contar_palavras(frase, palavra), palavra);
system("PAUSE");
return 0;
}
|
the_stack_data/354682.c
|
#include <stdio.h>
double func(double x, void *params);
int main() {
double x = 0.5;
double params[] = {1.0, -2.0, 3.0};
printf("result = %lf\n", func(x, params));
return 0;
}
|
the_stack_data/220454844.c
|
/*
UCF EGN 3211
FALL 2018
Prof. Sundar Sinnappan
*** Homework 7B ***
by Allan Aquino Vieira
*/
#include <stdio.h>
#include <string.h>
#include<stdlib.h>
#include <time.h>
#define MAXENTRIES 100
//Structure Definition
typedef struct tools
{
unsigned int id;
char name[25];
unsigned int qty;
float cost;
} structTools;
//Function Prototype
/*LN 094*/int outputInventory (FILE *binfilePtr, int structSize, structTools *const structPtr, int outputFlag);
/*LN 227*/int changeInventory(FILE *binfilePtr, int structSize, structTools *structPtr, int changeModeFlag);
/*LN 284*/int inputToStruct(structTools *const inventoryPtr, int inputFlag);
/*LN 362*/void timeStamp(char timeStampStr[27]);
int main (void)
{
//Main Variable Declaration
FILE *bfPtr;
structTools Inventory = {0, "", 0, 0.0}, *const inventoryPtr = &Inventory;
int structToolsSize = sizeof(struct tools);
//printf("structToolsSize = %d\n",structToolsSize);//TEST PURPUSES
char mainPrompt[] = {
"INVENTORY MANAGEMENT SYSTEM\n\nYour choices are:\n"
"1 - EXPORT a formated text file of invetoried tools (hardware.txt) for printing\n"
"2 - UPDATE a tool record\n"
"3 - ADD a new tool record\n"
"4 - DELETE a tool record\n"
"5 - DISPLAY a tool record\n"
"6 - DISPLAY all tool records\n"
"9 - EXIT program\n\nSelection: "
};
char timeStampStr[27];
int selection = 0;
while(selection != 9)
{
selection = 0;
//timeStamp(timeStampStr);//TEST PURPUSES
printf("\n%s", mainPrompt);
scanf("%d", &selection);
fflush(stdin);
switch(selection)
{
case 1 ://EXPORT TXT
outputInventory(bfPtr, structToolsSize, inventoryPtr,0);;
break;
case 2 : //UPDATE
changeInventory(bfPtr, structToolsSize, inventoryPtr,1);
break;
case 3 ://ADD
changeInventory(bfPtr, structToolsSize, inventoryPtr,1);
break;
case 4 ://DELETE
changeInventory(bfPtr, structToolsSize, inventoryPtr,0);
break;
case 5 ://DISPLAY ONE
outputInventory(bfPtr, structToolsSize, inventoryPtr,1);
break;
case 6://DISPLAY ALL
outputInventory(bfPtr, structToolsSize, inventoryPtr,2);
break;
case 9 :
//fclose (bfPtr);
break;
default :
printf("!!Invalid entry!!\n");
break;
}
};
//fclose (bfPtr);
return 0;
}
/*O*/
int outputInventory(FILE *binfilePtr, int structSize, structTools *const structPtr, int outputFlag)
{
/********************************************************
outputInventory function can be used any time record(s)
must be output the outputFlag value define the output
method:
0 - ALL records output as .txt file (hardware.txt)
1 - SINGLE record output to SCREEN
2 - ALL records output to SCREEN
********************************************************/
//outputInventory VARIABLE DECLARATIONS
char timeStampStr[27];
int fseekReturn = 0;
int freadReturn = 0;
int record_id = 0;
int noRecords = 0;
binfilePtr = fopen("hardware.dat","rb+");
//"rb+" will open binary file read and writer rights
if(binfilePtr == NULL)
{
puts("!!*.dat File Could Not Be Open!!");
return 1;
//(ERROR 1) File could not be open
}
if(outputFlag == 0)
{//ALL RECORDS TO TXT
FILE *tfPtr;
tfPtr = fopen("hardware.txt","w+");
//"w+" will create user readable file, disacards content if file exists
if(tfPtr == NULL)
{
puts("!!*.txt File Could Not Be Open!!");
return 1;
//(ERROR 1) File could not be open
}
timeStamp(timeStampStr);
noRecords = 0;
//TXT File Output Header
fprintf(tfPtr, "\t\tINVENTORY at %s\n", timeStampStr);
fprintf(tfPtr, "%3s\t|%24s\t|%3s\t|%7s\n",
"ID", "PRODUCT NAME", "QTY", "COST");
while (!feof(binfilePtr))
{
freadReturn = fread(structPtr, structSize, 1, binfilePtr);
//printf("\nfreadReturn = %d\n", freadReturn);//TEST PURPUSES
if(freadReturn != 0 && structPtr->id != 0)
{
++noRecords;
fprintf(tfPtr, "%3u\t| %24s\t| %3u\t| %7.2f\n",
structPtr->id , structPtr->name, structPtr->qty, structPtr->cost);
}
}
if(noRecords == 0)
{
fprintf(tfPtr, "%3c\t| %24s\t| %3c\t| %c\n",
' ' , "NO RECORDS FOUND", ' ', ' ');
}
//printf("\nfreadReturn = %d\n", freadReturn);//TEST PURPUSES
fclose (tfPtr);
}
else if(outputFlag == 1)
{//SINGLE RECORD
inputToStruct(structPtr,0);
//printf("\nstructPtr->id = %u\n", structPtr->id);//TEST PURPUSES
fseekReturn = fseek(binfilePtr,(structPtr->id * ((unsigned int)structSize)),SEEK_SET);
//printf("\fseekReturn = %d\n", fseekReturn);//TEST PURPUSES
record_id = structPtr->id;
//Output Header
printf("\t\tCURRENT TOOL INFO\n"
"%3s\t|%24s\t|%3s\t|%7s\n",
"ID", "PRODUCT NAME", "QTY", "COST");
freadReturn = fread(structPtr, structSize, 1, binfilePtr);
//printf("\nfreadReturn = %d\n", freadReturn);//TEST PURPUSES
//Output One Record
if(freadReturn != 0 && structPtr->id != 0)
{
printf("%3u\t| %24s\t| %3u\t| %7.2f\n",
structPtr->id+1 , structPtr->name, structPtr->qty, structPtr->cost);
}
else
{
structPtr->id = record_id;
//printf("\nstructPtr->id = %3u\n", structPtr->id);//TEST PURPUSES
printf("%3u\t| %24s\t| %3c\t| %c\n", structPtr->id+1 , "DOES NOT EXIST", ' ', ' ');
}
}
else if(outputFlag == 2)
{//ALL RECORDS TO SCREEN
noRecords = 0;
//Output Header
printf("%3s\t|%24s\t|%3s\t|%7s\n",
"ID", "PRODUCT NAME", "QTY", "COST");
while (!feof(binfilePtr))
{
freadReturn = fread(structPtr, structSize, 1, binfilePtr);
if(freadReturn != 0 && structPtr->id != 0)
{
printf("%3u\t| %24s\t| %3u\t| %7.2f\n",
structPtr->id+1 , structPtr->name, structPtr->qty, structPtr->cost);
++noRecords;
}
}
if(noRecords == 0)
{
printf("%3c\t| %24s\t| %3c\t| %c\n",
' ' , "NO RECORDS FOUND", ' ', ' ');
}
//printf("\nfreadReturn = %d\n", freadReturn);//TEST PURPUSES
fclose (binfilePtr);
}
fclose (binfilePtr);
return 0;
}
/*C*/
int changeInventory(FILE *binfilePtr, int structSize, structTools *structPtr, int changeModeFlag)
{
/********************************************************
changeInventory function can be used to CHANDE or DELETE
any record.This is feature is defined by the
changeModeFlag value:
0 - DELETE
1 - CHANGE with user input
********************************************************/
//addInventory VARIABLE DECLARATIONS
int fseekReturn = 0;
int fwriteReturn = 0;
inputToStruct(structPtr,0);
binfilePtr = fopen("hardware.dat","rb+");
//"rb+" will open binary file read and writer rights
if(binfilePtr == NULL)
{
puts("!!*.dat File Could Not Be Open!!");
return 1;
}
fseekReturn = fseek(binfilePtr,(structPtr->id * ((unsigned int)structSize)),SEEK_SET);
//printf("\fseekReturn = %d\n", fseekReturn);//TEST PURPUSES
if (changeModeFlag == 0)
{//DELETE
strcpy(structPtr->name, "");
structPtr->qty = 0;
structPtr->cost = 0.0;
printf("\nTool ID %3u has been deleted!", structPtr->id+1);
structPtr->id = 0;
//printf("%3u\t| %24s\t| %3u\t| %7.2f\n",structPtr->id+1 , structPtr->name, structPtr->qty, structPtr->cost);//TEST PURPUSES
}
else if (changeModeFlag == 1)
{//CHANGE
inputToStruct(structPtr,1);
//printf("\n%3u\t| %24s\t| %3u\t| %7.2f\n", structPtr->id+1 , structPtr->name, structPtr->qty, structPtr->cost);
}
fwriteReturn = fwrite(structPtr, structSize, 1, binfilePtr);
/*if(fwriteReturn != 1)//TEST PURPUSES
{
printf("\n!!!error!!! Data could not be saved to file \nfwriteReturn = %d\n", fwriteReturn);//TEST PURPUSES
}
else
{
printf("\n write sucess \nfwriteReturn = %d\n", fwriteReturn);//TEST PURPUSES
}*/
fclose (binfilePtr);
return 0;
}
/*I*/
int inputToStruct(structTools *const inventoryPtr, int inputFlag)
{
/********************************************************
inputToStruct function can be used any time user input
is needed for structure ID only, for NAME, QUANITIY and
COST only or for all strucure elements. This is defined
by the inputFlag value:
0 - structure ID only
1 - structure NAME, QUANITIY and COST only
2 - structure ID, NAME, QUANITIY and COST.
********************************************************/
//inputToStruct VARIABLE DECLARATIONS
char usrInput[44]= "abcdefghijklmnopqrstuvwx 999999999 99999.99";//Max input accepted
int usrInputLeng = 0;
unsigned int item_id = 0;
//Taking structure id
if(inputFlag == 0 || inputFlag == 2)
{
do
{
printf("Enter new tool inventory ID (1-100): ");
scanf("%u", &item_id);
fflush(stdin);
}while(item_id < 1 && item_id > 100);
inventoryPtr->id = (unsigned int)(item_id - 1);
//printf("\ninventoryPtr->id = %u\n", inventoryPtr->id);//TEST PURPUSES
}
//Taking structure NAME, QUANITIY and COST
if(inputFlag == 1 || inputFlag == 2)
{
printf("Enter tool Name Quantity and Cost (separated by spaces only).\n");
gets(usrInput);
usrInputLeng = strlen(usrInput);
for(int i=usrInputLeng, spcDtctd=2; i>=0 && spcDtctd > 0; --i)
{
//printf("\ni=%d spcDtctd=%d",i ,spcDtctd);//TEST PURPOSES
if(usrInput[i-1]== ' ')
{
//printf("\nSPACE");//TEST PURPOSES
switch(spcDtctd)
{
case 2:
//float portion of input
inventoryPtr->cost = atof(&usrInput[i]);
usrInput[i-1] = '\0';
--spcDtctd;
//printf("\ninventoryPtr->cost=%f",inventoryPtr->cost);//TEST PURPOSES
break;
case 1:
//unsigned integet portion of input
usrInput[i-1] = '\0';
char *tempPtr;
//long temp = strtoul(&usrInput[i], &temp, 10);
inventoryPtr->qty = ((unsigned int)strtoul(&usrInput[i], &tempPtr, 10));//temp;
--spcDtctd;
//printf("\ninventoryPtr->qty = %u",inventoryPtr->qty);//TEST PURPOSES
//String portion of input
if((i-1) > 24)
{
usrInput[24] = '\0';
}
strcpy(inventoryPtr->name,usrInput);
//printf("\ninventoryPtr->name = %s",inventoryPtr->name);//TEST PURPOSES
break;
}
}
}
fflush(stdin);
}
return 0;
}
/*T*/
void timeStamp(char timeStampStr[27])
{
//timeStamp Varaible Definitions
time_t timer = 0;
struct tm* tm_info;
time(&timer);
tm_info = localtime(&timer);
strftime(timeStampStr, 26, "%H:%M:%S %m-%d-%Y ", tm_info);
timeStampStr[26] = '\0';
//printf("%s",timeStampStr);//TEST PURPUSES
}
|
the_stack_data/150141085.c
|
#include <stdio.h>
int main() {
printf("Howdy, Ya'll!");
return 0;
}
|
the_stack_data/59513446.c
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdint.h>
const off_t PL310_BASE = 0x00A02000;
const size_t PAGE_SIZE = 4096;
const off_t COUNTER0 = 0x210;
const off_t COUNTER1 = 0x20C;
/*
* mmap helper functions
*/
void* map_base(off_t base_address) {
int fd = open("/dev/mem", O_RDWR);
if (fd < 0)
return MAP_FAILED;
void *ptr = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, base_address);
close(fd);
return ptr;
}
void umap_base(void* base_ptr) {
munmap(base_ptr, PAGE_SIZE);
}
/*
* Register access helper functions
*/
uint32_t read_mem_register(void* base_ptr, off_t offset) {
uint32_t* ptr = base_ptr + offset;
return *ptr;
}
void write_mem_register(void* base_ptr, off_t offset, uint32_t value) {
uint32_t* ptr = base_ptr + offset;
*ptr = value;
}
/*
* Program to track PL310 events while doing PLD requests
*/
int main(int argc, char const *argv[])
{
uint32_t val;
uint32_t epfalloc, dwreq;
int data[10000];
int iterations;
/* Read iterations from console */
if (argc == 1) {
iterations = 100;
} else {
iterations = atoi(argv[1]);
}
printf("Doing %d iterations\n", iterations);
/* Init mapping to PL310 registers */
void* pl310_ptr = map_base(PL310_BASE);
if (pl310_ptr == MAP_FAILED) {
printf("mmap failed");
return -1;
}
/* Enable and reset PL310 counters */
val = 0b111;
write_mem_register(pl310_ptr, 0x200, val); // reg2_ev_counter_ctrl
val = read_mem_register(pl310_ptr, 0x200);
printf("reg2_ev_counter_ctrl = 0x%x\n", val);
/* Configure counter0 (cfg in 0x208) to track prefetch hint allocated into L2 (EPFALLOC 0b1100) */
val = 0b110000; // EPFALLOC + no interruptions
write_mem_register(pl310_ptr, 0x208, val); // reg2_ev_counter0_cfg
val = read_mem_register(pl310_ptr, 0x208);
printf("reg2_ev_counter0_cfg = 0x%x\n", val);
/* Configure counter1 (cfg in 0x204) to track L2 write lookup (request) (DWREQ b0101) */
// b101000 for IPFALLOC (hints generated by PL310)
val = 0b010100; // DWREQ + no interruptions
write_mem_register(pl310_ptr, 0x204, val); // reg2_ev_counter1_cfg
val = read_mem_register(pl310_ptr, 0x204);
printf("reg2_ev_counter1_cfg = 0x%x\n", val);
/* Iterate prefetches */
for (int i=0; i<iterations; i++) {
epfalloc = read_mem_register(pl310_ptr, COUNTER0);
dwreq = read_mem_register(pl310_ptr, COUNTER1);
printf("(%d) EPFALLOC=%d, DWREQ=%d\n", i, epfalloc, dwreq);
//asm volatile("pld\t[%0]" :: "r" (data+i));
//__builtin_prefetch (data+i, 0, 3);
}
/* Disable counters */
val = 0b110;
write_mem_register(pl310_ptr, 0x200, val); // reg2_ev_counter_ctrl
/* Unmap PL310 */
umap_base(pl310_ptr);
return 0;
}
|
the_stack_data/6389032.c
|
#include <stdio.h>
int main()
{
int i;
for (i = 0; i < 8; i++)
{
printf("%d", i);
if (i >= 3 && i <= 5)
continue;
printf(",");
}
}
|
the_stack_data/115758.c
|
#define NULL ((void*)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t; typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1
/* Forward declarations */
typedef struct TYPE_2__ TYPE_1__ ;
/* Type definitions */
typedef unsigned char u8 ;
typedef int u16 ;
struct sk_buff {int len; } ;
struct ieee80211_rx_status {int vendor_radiotap_len; int flag; int freq; scalar_t__ band; unsigned char signal; unsigned char antenna; int rate_idx; int vht_nss; int vendor_radiotap_align; int /*<<< orphan*/ vendor_radiotap_subns; int /*<<< orphan*/ * vendor_radiotap_oui; int /*<<< orphan*/ ampdu_delimiter_crc; int /*<<< orphan*/ ampdu_reference; int /*<<< orphan*/ vendor_radiotap_bitmap; } ;
struct ieee80211_rate {int bitrate; int flags; } ;
struct ieee80211_radiotap_header {int it_present; int /*<<< orphan*/ it_len; } ;
struct TYPE_2__ {int flags; int radiotap_vht_details; int /*<<< orphan*/ radiotap_mcs_details; } ;
struct ieee80211_local {TYPE_1__ hw; } ;
/* Variables and functions */
int BIT (int /*<<< orphan*/ ) ;
scalar_t__ FCS_LEN ;
scalar_t__ IEEE80211_BAND_5GHZ ;
int IEEE80211_CHAN_2GHZ ;
int IEEE80211_CHAN_5GHZ ;
int IEEE80211_CHAN_CCK ;
int IEEE80211_CHAN_DYN ;
int IEEE80211_CHAN_OFDM ;
int IEEE80211_HW_RX_INCLUDES_FCS ;
int IEEE80211_HW_SIGNAL_DBM ;
int IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR ;
int IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN ;
int IEEE80211_RADIOTAP_AMPDU_IS_LAST ;
int IEEE80211_RADIOTAP_AMPDU_IS_ZEROLEN ;
int IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN ;
int IEEE80211_RADIOTAP_AMPDU_REPORT_ZEROLEN ;
int IEEE80211_RADIOTAP_AMPDU_STATUS ;
int IEEE80211_RADIOTAP_ANTENNA ;
int IEEE80211_RADIOTAP_CHANNEL ;
int IEEE80211_RADIOTAP_DBM_ANTSIGNAL ;
int /*<<< orphan*/ IEEE80211_RADIOTAP_EXT ;
int IEEE80211_RADIOTAP_FLAGS ;
unsigned char IEEE80211_RADIOTAP_F_BADFCS ;
unsigned char IEEE80211_RADIOTAP_F_FCS ;
int IEEE80211_RADIOTAP_F_RX_BADPLCP ;
unsigned char IEEE80211_RADIOTAP_F_SHORTPRE ;
int IEEE80211_RADIOTAP_MCS ;
unsigned char IEEE80211_RADIOTAP_MCS_BW_40 ;
unsigned char IEEE80211_RADIOTAP_MCS_FMT_GF ;
unsigned char IEEE80211_RADIOTAP_MCS_SGI ;
int IEEE80211_RADIOTAP_RATE ;
int IEEE80211_RADIOTAP_RX_FLAGS ;
int IEEE80211_RADIOTAP_TSFT ;
int /*<<< orphan*/ IEEE80211_RADIOTAP_VENDOR_NAMESPACE ;
int IEEE80211_RADIOTAP_VHT ;
unsigned char IEEE80211_RADIOTAP_VHT_FLAG_SGI ;
int IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH ;
int IEEE80211_RATE_ERP_G ;
struct ieee80211_rx_status* IEEE80211_SKB_RXCB (struct sk_buff*) ;
int RX_FLAG_160MHZ ;
int RX_FLAG_40MHZ ;
int RX_FLAG_80MHZ ;
int RX_FLAG_80P80MHZ ;
int RX_FLAG_AMPDU_DELIM_CRC_ERROR ;
int RX_FLAG_AMPDU_DELIM_CRC_KNOWN ;
int RX_FLAG_AMPDU_DETAILS ;
int RX_FLAG_AMPDU_IS_LAST ;
int RX_FLAG_AMPDU_IS_ZEROLEN ;
int RX_FLAG_AMPDU_LAST_KNOWN ;
int RX_FLAG_AMPDU_REPORT_ZEROLEN ;
int RX_FLAG_FAILED_FCS_CRC ;
int RX_FLAG_FAILED_PLCP_CRC ;
int RX_FLAG_HT ;
int RX_FLAG_HT_GF ;
int RX_FLAG_NO_SIGNAL_VAL ;
int RX_FLAG_SHORTPRE ;
int RX_FLAG_SHORT_GI ;
int RX_FLAG_VHT ;
int /*<<< orphan*/ cpu_to_le16 (int) ;
int cpu_to_le32 (int) ;
int /*<<< orphan*/ ieee80211_calculate_rx_timestamp (struct ieee80211_local*,struct ieee80211_rx_status*,int,int /*<<< orphan*/ ) ;
scalar_t__ ieee80211_have_rx_timestamp (struct ieee80211_rx_status*) ;
int /*<<< orphan*/ memset (struct ieee80211_radiotap_header*,int /*<<< orphan*/ ,int) ;
int /*<<< orphan*/ put_unaligned_le16 (int,unsigned char*) ;
int /*<<< orphan*/ put_unaligned_le32 (int /*<<< orphan*/ ,unsigned char*) ;
int /*<<< orphan*/ put_unaligned_le64 (int /*<<< orphan*/ ,unsigned char*) ;
scalar_t__ skb_push (struct sk_buff*,int) ;
__attribute__((used)) static void
ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
struct sk_buff *skb,
struct ieee80211_rate *rate,
int rtap_len, bool has_fcs)
{
struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
struct ieee80211_radiotap_header *rthdr;
unsigned char *pos;
u16 rx_flags = 0;
int mpdulen;
mpdulen = skb->len;
if (!(has_fcs && (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)))
mpdulen += FCS_LEN;
rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
memset(rthdr, 0, rtap_len);
/* radiotap header, set always present flags */
rthdr->it_present =
cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
(1 << IEEE80211_RADIOTAP_CHANNEL) |
(1 << IEEE80211_RADIOTAP_ANTENNA) |
(1 << IEEE80211_RADIOTAP_RX_FLAGS));
rthdr->it_len = cpu_to_le16(rtap_len + status->vendor_radiotap_len);
pos = (unsigned char *)(rthdr + 1);
if (status->vendor_radiotap_len) {
rthdr->it_present |=
cpu_to_le32(BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE)) |
cpu_to_le32(BIT(IEEE80211_RADIOTAP_EXT));
put_unaligned_le32(status->vendor_radiotap_bitmap, pos);
pos += 4;
}
/* the order of the following fields is important */
/* IEEE80211_RADIOTAP_TSFT */
if (ieee80211_have_rx_timestamp(status)) {
/* padding */
while ((pos - (u8 *)rthdr) & 7)
*pos++ = 0;
put_unaligned_le64(
ieee80211_calculate_rx_timestamp(local, status,
mpdulen, 0),
pos);
rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
pos += 8;
}
/* IEEE80211_RADIOTAP_FLAGS */
if (has_fcs && (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS))
*pos |= IEEE80211_RADIOTAP_F_FCS;
if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
*pos |= IEEE80211_RADIOTAP_F_BADFCS;
if (status->flag & RX_FLAG_SHORTPRE)
*pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
pos++;
/* IEEE80211_RADIOTAP_RATE */
if (!rate || status->flag & (RX_FLAG_HT | RX_FLAG_VHT)) {
/*
* Without rate information don't add it. If we have,
* MCS information is a separate field in radiotap,
* added below. The byte here is needed as padding
* for the channel though, so initialise it to 0.
*/
*pos = 0;
} else {
rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
*pos = rate->bitrate / 5;
}
pos++;
/* IEEE80211_RADIOTAP_CHANNEL */
put_unaligned_le16(status->freq, pos);
pos += 2;
if (status->band == IEEE80211_BAND_5GHZ)
put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ,
pos);
else if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
put_unaligned_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ,
pos);
else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ,
pos);
else if (rate)
put_unaligned_le16(IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ,
pos);
else
put_unaligned_le16(IEEE80211_CHAN_2GHZ, pos);
pos += 2;
/* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM &&
!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
*pos = status->signal;
rthdr->it_present |=
cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
pos++;
}
/* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
/* IEEE80211_RADIOTAP_ANTENNA */
*pos = status->antenna;
pos++;
/* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
/* IEEE80211_RADIOTAP_RX_FLAGS */
/* ensure 2 byte alignment for the 2 byte field as required */
if ((pos - (u8 *)rthdr) & 1)
*pos++ = 0;
if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
put_unaligned_le16(rx_flags, pos);
pos += 2;
if (status->flag & RX_FLAG_HT) {
rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
*pos++ = local->hw.radiotap_mcs_details;
*pos = 0;
if (status->flag & RX_FLAG_SHORT_GI)
*pos |= IEEE80211_RADIOTAP_MCS_SGI;
if (status->flag & RX_FLAG_40MHZ)
*pos |= IEEE80211_RADIOTAP_MCS_BW_40;
if (status->flag & RX_FLAG_HT_GF)
*pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
pos++;
*pos++ = status->rate_idx;
}
if (status->flag & RX_FLAG_AMPDU_DETAILS) {
u16 flags = 0;
/* ensure 4 byte alignment */
while ((pos - (u8 *)rthdr) & 3)
pos++;
rthdr->it_present |=
cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS);
put_unaligned_le32(status->ampdu_reference, pos);
pos += 4;
if (status->flag & RX_FLAG_AMPDU_REPORT_ZEROLEN)
flags |= IEEE80211_RADIOTAP_AMPDU_REPORT_ZEROLEN;
if (status->flag & RX_FLAG_AMPDU_IS_ZEROLEN)
flags |= IEEE80211_RADIOTAP_AMPDU_IS_ZEROLEN;
if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
if (status->flag & RX_FLAG_AMPDU_IS_LAST)
flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
put_unaligned_le16(flags, pos);
pos += 2;
if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
*pos++ = status->ampdu_delimiter_crc;
else
*pos++ = 0;
*pos++ = 0;
}
if (status->flag & RX_FLAG_VHT) {
u16 known = local->hw.radiotap_vht_details;
rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
/* known field - how to handle 80+80? */
if (status->flag & RX_FLAG_80P80MHZ)
known &= ~IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
put_unaligned_le16(known, pos);
pos += 2;
/* flags */
if (status->flag & RX_FLAG_SHORT_GI)
*pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
pos++;
/* bandwidth */
if (status->flag & RX_FLAG_80MHZ)
*pos++ = 4;
else if (status->flag & RX_FLAG_80P80MHZ)
*pos++ = 0; /* marked not known above */
else if (status->flag & RX_FLAG_160MHZ)
*pos++ = 11;
else if (status->flag & RX_FLAG_40MHZ)
*pos++ = 1;
else /* 20 MHz */
*pos++ = 0;
/* MCS/NSS */
*pos = (status->rate_idx << 4) | status->vht_nss;
pos += 4;
/* coding field */
pos++;
/* group ID */
pos++;
/* partial_aid */
pos += 2;
}
if (status->vendor_radiotap_len) {
/* ensure 2 byte alignment for the vendor field as required */
if ((pos - (u8 *)rthdr) & 1)
*pos++ = 0;
*pos++ = status->vendor_radiotap_oui[0];
*pos++ = status->vendor_radiotap_oui[1];
*pos++ = status->vendor_radiotap_oui[2];
*pos++ = status->vendor_radiotap_subns;
put_unaligned_le16(status->vendor_radiotap_len, pos);
pos += 2;
/* align the actual payload as requested */
while ((pos - (u8 *)rthdr) & (status->vendor_radiotap_align - 1))
*pos++ = 0;
}
}
|
the_stack_data/132952727.c
|
#include <unistd.h>
int fchown(int fildes, uid_t owner, gid_t group)
{
return fildes;
}
/*
XOPEN(400)
POSIX(200112)
*/
|
the_stack_data/64201644.c
|
#include <sys/types.h>
#include <stdint.h>
#include <stddef.h>
#undef KEY
#if defined(__i386)
# define KEY '_','_','i','3','8','6'
#elif defined(__x86_64)
# define KEY '_','_','x','8','6','_','6','4'
#elif defined(__ppc__)
# define KEY '_','_','p','p','c','_','_'
#elif defined(__ppc64__)
# define KEY '_','_','p','p','c','6','4','_','_'
#elif defined(__aarch64__)
# define KEY '_','_','a','a','r','c','h','6','4','_','_'
#elif defined(__ARM_ARCH_7A__)
# define KEY '_','_','A','R','M','_','A','R','C','H','_','7','A','_','_'
#elif defined(__ARM_ARCH_7S__)
# define KEY '_','_','A','R','M','_','A','R','C','H','_','7','S','_','_'
#endif
#define SIZE (sizeof(unsigned short int))
char info_size[] = {'I', 'N', 'F', 'O', ':', 's','i','z','e','[',
('0' + ((SIZE / 10000)%10)),
('0' + ((SIZE / 1000)%10)),
('0' + ((SIZE / 100)%10)),
('0' + ((SIZE / 10)%10)),
('0' + (SIZE % 10)),
']',
#ifdef KEY
' ','k','e','y','[', KEY, ']',
#endif
'\0'};
#ifdef __CLASSIC_C__
int main(argc, argv) int argc; char *argv[];
#else
int main(int argc, char *argv[])
#endif
{
int require = 0;
require += info_size[argc];
(void)argv;
return require;
}
|
the_stack_data/1044032.c
|
// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -emit-pch -o %t %s
// RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
// RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
// RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -emit-pch -o %t %s
// RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
// expected-no-diagnostics
#ifndef HEADER
#define HEADER
// CHECK: [[KMP_DIM:%.+]] = type { i64, i64, i64 }
extern int n;
int a[10], b[10], c[10], d[10];
void foo();
// CHECK-LABEL: @main()
int main() {
int i;
// CHECK: [[DIMS:%.+]] = alloca [[KMP_DIM]],
// CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT:%.+]])
// CHECK: icmp
// CHECK-NEXT: br i1 %
// CHECK: [[CAST:%.+]] = bitcast [[KMP_DIM]]* [[DIMS]] to i8*
// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 [[CAST]], i8 0, i64 24, i1 false)
// CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIMS]], i32 0, i32 1
// CHECK: store i64 %{{.+}}, i64* %
// CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIMS]], i32 0, i32 2
// CHECK: store i64 1, i64* %
// CHECK: [[CAST:%.+]] = bitcast [[KMP_DIM]]* [[DIMS]] to i8*
// CHECK: call void @__kmpc_doacross_init([[IDENT]], i32 [[GTID]], i32 1, i8* [[CAST]])
// CHECK: call void @__kmpc_for_static_init_4(
#pragma omp for ordered(1)
for (i = 0; i < n; ++i) {
a[i] = b[i] + 1;
foo();
// CHECK: call void [[FOO:.+]](
// CHECK: load i32, i32* [[CNT:%.+]],
// CHECK-NEXT: sext i32 %{{.+}} to i64
// CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
// CHECK-NEXT: call void @__kmpc_doacross_post([[IDENT]], i32 [[GTID]], i64* [[TMP]])
#pragma omp ordered depend(source)
c[i] = c[i] + 1;
foo();
// CHECK: call void [[FOO]]
// CHECK: load i32, i32* [[CNT]],
// CHECK-NEXT: sub nsw i32 %{{.+}}, 2
// CHECK-NEXT: sext i32 %{{.+}} to i64
// CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
// CHECK-NEXT: call void @__kmpc_doacross_wait([[IDENT]], i32 [[GTID]], i64* [[TMP]])
#pragma omp ordered depend(sink : i - 2)
d[i] = a[i - 2];
}
// CHECK: call void @__kmpc_for_static_fini(
// CHECK: call void @__kmpc_doacross_fini([[IDENT]], i32 [[GTID]])
// CHECK: ret i32 0
return 0;
}
#endif // HEADER
|
the_stack_data/87639254.c
|
/* Generated by CIL v. 1.7.0 */
/* print_CIL_Input is false */
struct _IO_FILE;
struct timeval;
extern void signal(int sig , void *func ) ;
extern float strtof(char const *str , char const *endptr ) ;
typedef struct _IO_FILE FILE;
extern int atoi(char const *s ) ;
extern double strtod(char const *str , char const *endptr ) ;
extern int fclose(void *stream ) ;
extern void *fopen(char const *filename , char const *mode ) ;
extern void abort() ;
extern void exit(int status ) ;
extern int raise(int sig ) ;
extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ;
extern int strcmp(char const *a , char const *b ) ;
extern int rand() ;
extern unsigned long strtoul(char const *str , char const *endptr , int base ) ;
void RandomFunc(unsigned int input[1] , unsigned int output[1] ) ;
extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ;
extern int gettimeofday(struct timeval *tv , void *tz , ...) ;
extern int printf(char const *format , ...) ;
int main(int argc , char *argv[] ) ;
void megaInit(void) ;
extern unsigned long strlen(char const *s ) ;
extern long strtol(char const *str , char const *endptr , int base ) ;
extern unsigned long strnlen(char const *s , unsigned long maxlen ) ;
extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ;
struct timeval {
long tv_sec ;
long tv_usec ;
};
extern void *malloc(unsigned long size ) ;
extern int scanf(char const *format , ...) ;
void megaInit(void)
{
{
}
}
int main(int argc , char *argv[] )
{
unsigned int input[1] ;
unsigned int output[1] ;
int randomFuns_i5 ;
unsigned int randomFuns_value6 ;
int randomFuns_main_i7 ;
{
megaInit();
if (argc != 2) {
printf("Call this program with %i arguments\n", 1);
exit(-1);
} else {
}
randomFuns_i5 = 0;
while (randomFuns_i5 < 1) {
randomFuns_value6 = (unsigned int )strtoul(argv[randomFuns_i5 + 1], 0, 10);
input[randomFuns_i5] = randomFuns_value6;
randomFuns_i5 ++;
}
RandomFunc(input, output);
if (output[0] == 4242424242U) {
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 ;
unsigned short copy12 ;
unsigned short copy13 ;
{
state[0UL] = input[0UL] + 4284877637U;
local1 = 0UL;
while (local1 < 1UL) {
state[local1] += state[local1];
local1 += 2UL;
}
local1 = 0UL;
while (local1 < 1UL) {
copy12 = *((unsigned short *)(& state[0UL]) + 0);
*((unsigned short *)(& state[0UL]) + 0) = *((unsigned short *)(& state[0UL]) + 1);
*((unsigned short *)(& state[0UL]) + 1) = copy12;
copy12 = *((unsigned short *)(& state[0UL]) + 1);
*((unsigned short *)(& state[0UL]) + 1) = *((unsigned short *)(& state[0UL]) + 0);
*((unsigned short *)(& state[0UL]) + 0) = copy12;
copy13 = *((unsigned short *)(& state[local1]) + 1);
*((unsigned short *)(& state[local1]) + 1) = *((unsigned short *)(& state[local1]) + 0);
*((unsigned short *)(& state[local1]) + 0) = copy13;
local1 ++;
}
output[0UL] = state[0UL] - 957911421UL;
}
}
|
the_stack_data/1142051.c
|
/***********************************************************************/
/* program name : CRX2RNX */
/* */
/* Program to recover the RINEX file from Compact RINEX file */
/* Created by Yuki HATANAKA / Geographical Survey Institute, Japan */
/* */
/* ver. */
/* 4.0.0 2007.01.31 test version Y. Hatanaka */
/* - CRINEX 1/3 for RINEX 2.x/3.x */
/* 4.0.1 2007.05.08 Y. Hatanaka */
/* - elimination of supports for VMS and SUN OS 4.1.x */
/* - output not to the current directory but the same */
/* directory as the input file. */
/* - the same code for DOS and UNIX */
/* 4.0.2 2007.06.07 Y. Hatanaka */
/* - fixing incompatibility of argument and format */
/* string of printf. */
/* 4.0.3 2007.06.21 Y. Hatanaka */
/* - fixing a bug on lack of carrying the number */
/* between lower and upper digits */
/* 4.0.4 2009.06.31 Y. Hatanaka */
/* - check null pointer in macro CHOP_LF */
/* - increase MAXTYPE from 30 to 50 */
/* - correct typos in error messages */
/* */
/* Copyright (c) 2007 Geographical Survey Institute */
/* All rights reserved. */
/* */
/***********************************************************************/
#define VERSION "ver.4.0.4"
/**** Exit codes are defined here. ****/
#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
#endif
#ifndef EXIT_FAILURE
#define EXIT_FAILURE 1
#endif
#define EXIT_WARNING 2
/* Don't change the lines from here. */
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/*** define macros ***/
/* #define CHOP_LF(q,p) p = strchr(q,'\n'); *p = '\0'; */
#define CHOP_LF(q,p) p = strchr(q,'\n'); if(p != NULL){if( *(p-1) == '\r' && p>q )p--;*p = '\0';}
#define CHOP_BLANK(q,p) p = strchr(q,'\0');while(*--p == ' ' && p>q);*++p = '\0'
/* define global constants */
#define PROGNAME "CRX2RNX"
#define MAXSAT 90 /* Maximum number of satellites observed at one epoch */
#define MAXTYPE 50 /* Maximum number of data types */
#define MAXCLM 1024 /* Maximum columns in one line (>MAXTYPE*19+3) */
#define MAX_BUFF_SIZE 131072 /* Muximum size of output buffer (>MAXSAT*(MAXTYPE*19+4)+60 */
#define MAX_DIFF_ORDER 5 /* Muximum order of difference to be dealt with */
/* define data structure for fields of clock offset and obsercvation records */
typedef struct clock_format{
long u[MAX_DIFF_ORDER+1]; /* upper X digits for each diference order */
long l[MAX_DIFF_ORDER+1]; /* lower 8 digits */
} clock_format;
typedef struct data_format{
long u[MAX_DIFF_ORDER+1]; /* upper X digits for each diference order */
long l[MAX_DIFF_ORDER+1]; /* lower 5 digits */
int order;
int arc_order;
} data_format;
/* define global variables */
clock_format clk1,clk0;
data_format y1[MAXSAT][MAXTYPE],y0[MAXSAT][MAXTYPE];
char flag1[MAXSAT][MAXTYPE*2+1],flag[MAXSAT][MAXTYPE*2+1];
int rinex_version,crinex_version,ep_top_from,ep_top_to;
int nsat,ntype,ntype_gnss[UCHAR_MAX],ntype_record[MAXSAT],clk_order = 0, clk_arc_order = 0;
long nl_count=0;
int skip = 0;
int exit_status = EXIT_SUCCESS;
char out_buff[MAX_BUFF_SIZE],*p_buff;
/* declaration of functions */
void fileopen(int argc, char *argv[]);
void header();
int put_event_data(char *dline, char *p_event);
void skip_to_next(char *dline);
void process_clock(char *dline);
void set_sat_table(char *p_new, char *p_old, int nsat1, int *sattbl);
void data(char *p_sat_lst, int *sattbl, char dflag[][MAXTYPE*2]);
void repair(char *s, char *ds);
int getdiff(data_format *y, data_format *y0, int i0, char *dflag);
void putfield(data_format *y, char *flag);
void read_clock(char *dline ,long *yu, long *yl);
void print_clock(long yu, long yl, int shift_clk);
int read_chk_line(char *line);
void error_exit(int error_no, char *string);
/*---------------------------------------------------------------------*/
int main(int argc, char *argv[]){
static char line[MAXCLM]="", sat_lst_old[MAXSAT*3];
static int nsat1 = 0, n;
char dline[MAXCLM],*p;
int sattbl[MAXSAT],i,j,*i0;
size_t offset;
char dflag[MAXSAT][MAXTYPE*2];
char *p_event,*p_nsat,*p_satlst,*p_clock,shift_clk;
/* sattbl[i]: order (at the previous epoch) of i-th satellite */
/* (at the current epoch). -1 is set for the new satellites */
fileopen(argc,argv);
for(i=0;i<UCHAR_MAX;i++)ntype_gnss[i]=-1; /** -1 unless GNSS type is not defined **/
header();
if (rinex_version==2){
ep_top_from='&';
ep_top_to =' ';
p_event =&dline[28]; /** pointer to event flug **/
p_nsat = &line[29]; /** pointer to n_sat **/
p_satlst = &line[32]; /** pointer to address to add satellite list **/
p_clock = &line[68]; /** pointer to clock offset data **/
shift_clk = 1;
offset=3;
}else{
ep_top_from='>';
ep_top_to= '>';
p_event =&dline[31];
p_nsat = &line[32];
p_satlst = &line[41];
p_clock = &line[41];
shift_clk = 4;
offset=6;
}
while( fgets(dline,MAXCLM,stdin) != NULL ){ /*** exit program successfully ***/
nl_count++;
CHOP_LF(dline,p);
SKIP:
if(crinex_version == 3) { /*** skip escape lines of CRINEX version 3 ***/
while(dline[0] == '&'){
nl_count++;
if( fgets(dline,MAXCLM,stdin) == NULL ) return exit_status;
CHOP_LF(dline,p);
}
}
if(dline[0] == ep_top_from){
dline[0] = ep_top_to;
if(*p_event!='0' && *p_event!='1' ){
if(put_event_data(dline,p_event)!=0) skip_to_next(dline);
goto SKIP;
}
line[0] = '\0'; /**** initialize arc for epoch data ***/
nsat1 = 0; /**** initialize the all satellite arcs ****/
}else if( dline[0] == '\032' ){
return exit_status; /** DOS EOF **/
}
/**** read, repair the line ****/
repair(line,dline);
p=&line[offset]; /** pointer to the space between year and month **/
if(line[0] != ep_top_to || strlen(line)<(26+offset) || *(p+23) != ' '
|| *(p+24) != ' ' || ! isdigit(*(p+25)) ) {
skip_to_next(dline);
goto SKIP;
}
CHOP_BLANK(line,p);
nsat=atoi(p_nsat);
if(nsat > MAXSAT) error_exit(6,p_nsat);
set_sat_table(p_satlst,sat_lst_old,nsat1,sattbl); /**** set satellite table ****/
if(read_chk_line(dline) != 0) {skip_to_next(dline);goto SKIP;}
read_clock(dline,clk1.u,clk1.l);
for(i=0,i0=sattbl ; i<nsat ; i++,i0++){
ntype=ntype_record[i];
if( getdiff(y1[i],y0[*i0],*i0,dflag[i]) != 0 ) {skip_to_next(dline);goto SKIP;}
}
/*************************************/
/**** print the recovered line(s) ****/
/*************************************/
if(dline[0] != '\0') process_clock(dline);
p_buff = out_buff;
if(rinex_version == 2){
if(clk_order >= 0){
p_buff += sprintf(p_buff,"%-68.68s",line);
print_clock(clk1.u[clk_order],clk1.l[clk_order],shift_clk);
}else{
p_buff += sprintf(p_buff,"%.68s\n",line);
}
for(p = &line[68],n=nsat-12; n>0; n-=12,p+=36) p_buff += sprintf(p_buff,"%32.s%.36s\n"," ",p);
}else{
if(clk_order >= 0){
p_buff += sprintf(p_buff,"%.41s",line);
print_clock(clk1.u[clk_order],clk1.l[clk_order],shift_clk);
}else{
sprintf(p_buff,"%.41s",line);
CHOP_BLANK(p_buff,p);*p++='\n';p_buff=p;
}
}
data(p_satlst,sattbl,dflag);
*p_buff = '\0'; printf("%s",out_buff);
/****************************/
/**** save current epoch ****/
/****************************/
nsat1 = nsat;
clk0 = clk1;
strncpy(sat_lst_old,p_satlst,nsat*3);
for(i=0;i<nsat;i++){
strncpy(flag1[i],flag[i],ntype_record[i]*2);
for(j=0;j<ntype_record[i];j++) y0[i][j] = y1[i][j];
}
}
return exit_status;
}
/*---------------------------------------------------------------------*/
void fileopen(int argc, char *argv[]){
char *p,*infile,outfile[256],*progname;
int nfile=0, force=0, help=0;
int nfout = 0; /*** =0 default output file name ***/
/*** =1 standaed output ***/
FILE *ifp;
progname = argv[0];
argc--;argv++;
for(;argc>0;argc--,argv++){
if((*argv)[0] != '-'){
infile = *argv;
nfile++;
}else if(strcmp(*argv,"-") == 0){
nfout = 1;
}else if(strcmp(*argv,"-f") == 0){
force = 1;
}else if(strcmp(*argv,"-s") == 0){
skip = 1;
}else if(strcmp(*argv,"-h") == 0){
help = 1;
}else{
help = 1;
}
}
if(help == 1 || nfile > 1 || nfile < 0) error_exit(2,progname);
if(nfile == 0) return; /*** stdin & stdout will be used ***/
/***********************/
/*** open input file ***/
/***********************/
p=strrchr(infile,'.');
if(p == NULL || (*(p+3) != 'D' && *(p+3) != 'd') || *(p+4) != '\0') error_exit(3,p);
if((ifp = fopen(infile,"r")) == NULL) error_exit(4,infile);
/************************/
/*** open output file ***/
/************************/
if(nfout == 0) {
strcpy(outfile,infile);
p=strrchr(outfile,'.');
if(*(p+3) == 'd') { *(p+3) = 'o';}
else { *(p+3) = 'O';}
if((freopen(outfile,"r",stdout)) != NULL && force == 0){
fprintf(stderr,"The file %s already exists. Overwrite?(n)",outfile);
if(getchar() != 'y') exit(EXIT_SUCCESS);
}
freopen(outfile,"w",stdout);
}
fclose(ifp);
freopen(infile,"r",stdin);
}
/*---------------------------------------------------------------------*/
void header(){
char line[MAXCLM],*p;
if( read_chk_line(line) == 1 ) error_exit(5,(char*)"1.0-2.0");
crinex_version=atoi(line);
if( strncmp(&line[0],"1.0",3) != 0 && strncmp(&line[0],"3.0",3) != 0 ||
strncmp(&line[60],"CRINEX VERS / TYPE",19) != 0 ) error_exit(5,(char*)"1.0-2.0");
if( read_chk_line(line) == 1 ) error_exit(8,line);
if( read_chk_line(line) == 1 ) error_exit(8,line);
CHOP_BLANK(line,p);
printf("%s\n",line);
if(strncmp(&line[60],"RINEX VERSION / TYPE",20) != 0 ||
(line[5]!='2' && line[5]!='3') ) error_exit(15,(char*)"2.x or 3.x");
rinex_version=atoi(line);
do {
read_chk_line(line);
CHOP_BLANK(line,p);
printf("%s\n",line);
if (strncmp(&line[60],"# / TYPES OF OBSERV",19) == 0 && line[5] != ' '){
ntype=atoi(line); /** for RINEX2 **/
} else if(strncmp(&line[60],"SYS / # / OBS TYPES",19) == 0){ /** for RINEX3 **/
if (line[0] != ' ') ntype_gnss[line[0]]=atoi(&line[3]);
if (ntype_gnss[line[0]] > MAXTYPE) error_exit(15,line);
}
}while(strncmp(&line[60],"END OF HEADER",13) != 0);
}
/*---------------------------------------------------------------------*/
void read_clock(char *dline, long *yu, long *yl){
char *p,*s,*p1;
p = dline;
if(*p == '\0'){
clk_order = -1;
}else{
if(*(p+1) == '&') { /**** for the case of arc initialization ****/
sscanf(p,"%d&",&clk_arc_order);
if(clk_arc_order > MAX_DIFF_ORDER) error_exit(7,dline);
clk_order = -1;
p += 2;
}
p1=p; if(*p == '-') p1++;
s=strchr(p1,'\0');
if((s-p1) < 9 ){ /** s-p1 == strlen(p1) ***/
*yu = 0;
*yl = atol(p);
}else{
s -= 8;
*yl = atol(s);
*s = '\0';
*yu = atol(p);
if(*yu < 0) *yl = -*yl;
}
}
}
/*---------------------------------------------------------------------*/
void process_clock(char *dline){
int i,j;
/****************************************/
/**** recover the clock offset value ****/
/****************************************/
if(clk_order < clk_arc_order){
clk_order++;
for(i=0,j=1 ; i<clk_order ; i++,j++){
clk1.u[j] = clk1.u[i]+clk0.u[i];
clk1.l[j] = clk1.l[i]+clk0.l[i];
clk1.u[j] += clk1.l[j]/100000000; /*** to avoid overflow of y1.l ***/
clk1.l[j] %= 100000000;
}
}else{
for(i=0,j=1 ; i<clk_order ; i++,j++){
clk1.u[j] = clk1.u[i]+clk0.u[j];
clk1.l[j] = clk1.l[i]+clk0.l[j];
clk1.u[j] += clk1.l[j]/100000000;
clk1.l[j] %= 100000000;
}
}
}
/*---------------------------------------------------------------------*/
int put_event_data(char *dline, char *p_event){
/***********************************************************************/
/* - Put event data for one event. */
/* - This function is called when the event flag > 1. */
/***********************************************************************/
int i,n;
char *p;
do {
dline[0] = ep_top_to;
CHOP_BLANK(dline,p);
printf("%s\n",dline);
if( strlen(dline) > 29 ){
n=atoi((p_event+1));
for(i=0;i<n;i++){
read_chk_line(dline);
CHOP_BLANK(dline,p);
printf("%s\n",dline);
if (strncmp(&dline[60],"# / TYPES OF OBSERV",19) == 0 && dline[5] != ' ' ){
ntype=atoi(dline); /** for RINEX2 **/
} else if(strncmp(&dline[60],"SYS / # / OBS TYPES",19) == 0){ /** for RINEX3 **/
if (dline[0] != ' ') ntype_gnss[dline[0]]=atoi(&dline[3]);
if (ntype_gnss[dline[0]] > MAXTYPE) error_exit(15,dline);
}
}
}
do {
nl_count++;
if(fgets(dline,MAXCLM,stdin) == NULL) exit(exit_status); /*** eof: exit program successfully ***/
} while (crinex_version == 3 && dline[0] == '&');
CHOP_LF(dline,p);
if(dline[0] != ep_top_from || strlen(dline)<29 || ! isdigit(*p_event) ) {
if( ! skip ) error_exit(9,dline);
fprintf(stderr,"WARNING : The epoch should be initialized, but not.\n");
return 1;
}
}while(*p_event != '0' && *p_event != '1');
return 0;
}
/*---------------------------------------------------------------------*/
void skip_to_next(char *dline){
char *p;
exit_status=EXIT_WARNING;
fprintf(stderr," line %ld : skip until an initialized epoch is found.",nl_count);
if(rinex_version == 2) {
p=dline+3; /** pointer to the space between year and month **/
}else{
p=dline+6;
}
do {
nl_count++;
if(fgets(dline,MAXCLM,stdin) == NULL) {
fprintf(stderr," .....next epoch not found before EOF.\n");
printf("%29d%3d\n%-60sCOMMENT\n",4,1," *** Some epochs are skiped by CRX2RNX ***");
exit(exit_status);
}
}while(dline[0]!=ep_top_from || strlen(dline)<29 || *p != ' '
|| *(p+3) != ' ' || *(p+6) != ' ' || *(p+9) != ' '
|| *(p+12) != ' ' || *(p+23) != ' ' || *(p+24) != ' '
|| ! isdigit(*(p+25)) );
CHOP_LF(dline,p);
fprintf(stderr," .....next epoch found at line %ld.\n",nl_count);
printf("%29d%3d\n%-60sCOMMENT\n",4,1," *** Some epochs are skiped by CRX2RNX ***");
}
/*---------------------------------------------------------------------*/
void set_sat_table(char *p_new, char *p_old, int nsat1, int *sattbl){
/***********************************************************************/
/* - Read number of satellites (nsat) */
/* - Compare the satellite list at the epoch (*p_new) and that at the */
/* previous epoch(*p_old), and make index (*sattbl) for the */
/* corresponding order of the satellites. */
/* *sattbl is set to -1 for new satellites. */
/***********************************************************************/
int i,j;
char *ps;
/*** set # of data types for each satellite ***/
if(rinex_version == 2 ) { /** for RINEX2 **/
for (i=0 ; i<nsat ; i++){ ntype_record[i]=ntype; }
}else{ /** for RINEX3 **/
for (i=0,ps=p_new ; i<nsat ; i++,ps+=3){
ntype_record[i]=ntype_gnss[*ps]; /*** # of data type for the GNSS system ***/
if(ntype_record[i]<0)error_exit(20,p_new);
}
}
for (i=0,p_new ; i<nsat ; i++,p_new+=3){
*sattbl = -1;
for(j=0,ps=p_old ; j<nsat1 ; j++,ps+=3){
if(strncmp(p_new,ps,3) == 0){
*sattbl = j;
break;
}
}
sattbl++;
}
}
/*---------------------------------------------------------------------*/
void data(char *p_sat_lst, int *sattbl, char dflag[][MAXTYPE*2]){
/********************************************************************/
/* Functions */
/* (1) compose the original data from 3rd order difference */
/* (2) repair the flags */
/* sattbl : previous column on which the satellites are set */
/* new satellites are set to -1 */
/* u : upper X digits of the data */
/* l : lower 5 digits of the data */
/* ( y = u*100 + l/1000) */
/* date of previous epoch are set to y0 */
/********************************************************************/
data_format *py1,*py0;
int i,j,k,k1,*i0;
char *p;
for(i=0,i0=sattbl,p=p_sat_lst ; i<nsat ; i++,i0++,p+=3){
/**** set # of data types for the GNSS type ****/
/**** and write satellite ID in case of RINEX3 ****/
/**** ---------------------------------------- ****/
if(rinex_version == 3 ){
ntype=ntype_record[i];
strncpy(p_buff,p,3);
p_buff += 3;
}
/**** repair the data frags ****/
/**** ----------------------****/
if(*i0 < 0){ /* new satellite */
if(rinex_version == 3 ){
*flag[i]='\0';
}else{
sprintf(flag[i],"%-*s",ntype*2,dflag[i]);
}
}else{
strncpy(flag[i],flag1[*i0],ntype*2);
}
repair(flag[i],dflag[i]);
/**** recover the date, and output ****/
/**** ---------------------------- ****/
for(j=0,py1=y1[i] ; j<ntype ; j++,py1++){
if(py1->arc_order >= 0){
py0 = &(y0[*i0][j]);
if(py1->order < py1->arc_order){
(py1->order)++;
for(k=0,k1=1; k<py1->order; k++,k1++){
py1->u[k1] = py1->u[k] + py0->u[k];
py1->l[k1] = py1->l[k] + py0->l[k];
py1->u[k1] += py1->l[k1]/100000; /*** to avoid overflow of y1.l ***/
py1->l[k1] %= 100000;
}
}else{
for(k=0,k1=1; k<py1->order; k++,k1++){
py1->u[k1] = py1->u[k] + py0->u[k1];
py1->l[k1] = py1->l[k] + py0->l[k1];
py1->u[k1] += py1->l[k1]/100000;
py1->l[k1] %= 100000;
}
}
putfield(py1,&flag[i][j*2]);
}else{
if (crinex_version == 1 ) { /*** CRINEX 1 assumes that flags are always ***/
p_buff += sprintf(p_buff," "); /*** blank if data field is blank ***/
flag[i][j*2] = flag[i][j*2+1] = ' ';
}else{ /*** CRINEX 3 evaluate flags independently **/
p_buff += sprintf(p_buff," %c%c",flag[i][j*2],flag[i][j*2+1]);
}
}
if((j+1) == ntype || (rinex_version==2 && (j+1)%5 == 0 ) ){
while(*--p_buff == ' '); p_buff++; /*** cut spaces ***/
*p_buff++ = '\n';
}
}
}
}
/*---------------------------------------------------------------------*/
void repair(char *s, char *ds){
for(; *s != '\0' && *ds != '\0' ; ds++,s++){
if(*ds == ' ')continue;
if(*ds == '&')
*s = ' ';
else
*s = *ds;
}
if(*ds != '\0') {
sprintf(s,"%s",ds);
for(; *s != '\0' ;s++) {
if(*s == '&') *s = ' ';
}
}
}
/*---------------------------------------------------------------------*/
int getdiff(data_format *y, data_format *y0, int i0, char *dflag){
int j,length;
char *s,*s1,*s2,line[MAXCLM];
/******************************************/
/**** separate the fields with '\0' ****/
/******************************************/
if(read_chk_line(line)!=0) return 1;
for(j=0,s=line; j<ntype; s++){
if(*s == '\0') {
j++;
*(s+1) = '\0';
}else if(*s == ' '){
j++;
*s = '\0';
}
}
strcpy(dflag,s);
/************************************/
/* read the differenced data */
/************************************/
s1=line;
for(j=0;j<ntype;j++,y++,y0++){
if(*s1 == '\0'){
y->arc_order = -1; /**** arc_order < 0 means that the field is blank ****/
y->order = -1;
s1++;
}else{
if(*(s1+1) == '&'){ /**** arc initialization ****/
y->order = -1;
y->arc_order = atoi(s1);
s1 += 2;
if(y->arc_order > MAX_DIFF_ORDER) error_exit(7,line);
}else if(i0 < 0){
if( ! skip ) error_exit(11,line);
fprintf(stderr,"WARNING : New satellite, but data arc is not initialized.\n");
return 1;
}else if(y0->arc_order < 0){
if( ! skip ) error_exit(12,line);
fprintf(stderr,"WARNING : New data sequence but without initialization.\n");
return 1;
}else{
y->order = y0->order;
y->arc_order = y0->arc_order;
}
length=(s2=strchr(s1,'\0'))-s1;
if(*s1 == '-') length--;
if(length < 6){
y->u[0] = 0;
y->l[0] = atol(s1);
}else{
s = s2-5;
y->l[0] = atol(s); *s = '\0';
y->u[0] = atol(s1);
if(y->u[0] < 0) y->l[0] = -y->l[0];
}
s1 = s2+1;
}
}
return 0;
}
/*---------------------------------------------------------------------*/
void putfield(data_format *y, char *flag){
int i;
i=y->order;
if(y->u[i]<0 && y->l[i]>0){
y->u[i]++ ; y->l[i] -= 100000 ;
}else if(y->u[i]>0 && y->l[i]<0){
y->u[i]-- ; y->l[i] += 100000 ;
}
if(y->u[i]!=0){ /* ex) 123.456 -123.456 */
p_buff += sprintf(p_buff,"%8ld %05.5ld%c%c",y->u[i],labs(y->l[i]),*flag,*(flag+1));
p_buff[-8] = p_buff[-7];
p_buff[-7] = p_buff[-6];
}else{
p_buff += sprintf(p_buff," %05.5ld%c%c",labs(y->l[i]),*flag,*(flag+1));
if (p_buff[-7] != '0' ){ /* ex) 12.345 -2.345 */
p_buff[-8] = p_buff[-7];
p_buff[-7] = p_buff[-6];
if(y->l[i] <0) p_buff[-9]='-';
}else if (p_buff[-6] != '0' ){ /* ex) 1.234 -1.234 */
p_buff[-7] = p_buff[-6];
p_buff[-8] = (y->l[i] <0)? '-':' ';
}else{ /* ex) .123 -.123 */
p_buff[-7] = (y->l[i] <0)? '-':' ';
}
}
p_buff[-6] = '.';
}
/*---------------------------------------------------------------------*/
void print_clock(long yu, long yl, int shift_clk){
char tmp[8],*p_tmp,*p;
int n,sgn;
if(yu<0 && yl>0){
yu++ ; yl -= 100000000;
}else if(yu>0 && yl<0){
yu-- ; yl += 100000000;
}
/** add ond more digit to handle '-0'(RINEX2) or '-0000'(RINEX3) **/
sgn = (yl<0) ? -1:1;
n=sprintf(tmp,"%0.*ld",shift_clk+1,yu*10+sgn); /** AT LEAST fractional parts are filled with 0 **/
n--; /** n: number of digits excluding the additional digit **/
p_tmp=&tmp[n];
*p_tmp='\0';
p_tmp-=shift_clk; /** pointer to the top of last "shift_clk" digits **/
p_buff += sprintf(p_buff," .%s",p_tmp); /** print last "shift_clk" digits. **/
if( n > shift_clk ){
p_tmp--;
p=p_buff-shift_clk-2;
*p=*p_tmp;
if( n > shift_clk+1 ){ *(p-1)=*(p_tmp-1); }
}
p_buff += sprintf(p_buff,"%08.8ld\n",labs(yl));
}
/*---------------------------------------------------------------------*/
int read_chk_line(char *line){
char *p;
nl_count++;
if( fgets(line,MAXCLM,stdin) == NULL ) error_exit(8,line);
if( (p = strchr(line,'\n')) == NULL) {
if( fgetc(stdin) == EOF ) { /** check if EOF is there **/
error_exit(8,line);
}else{
if( ! skip ) error_exit(13,line);
return 1;
}
}
if( *(p-1) == '\n' )p--;
if( *(p-1) == '\r' )p--; /*** check DOS CR/LF ***/
*p = '\0';
return 0;
}
/*---------------------------------------------------------------------*/
void error_exit(int error_no, char *string){
if(error_no == 1 ){
fprintf(stderr,"Usage: %s input file [-o output file] [-f] [-s] [-h]\n",string);
fprintf(stderr," output file name can be omitted if input file name is *.[yy]d\n");
}else if(error_no == 2 ){
fprintf(stderr,"Usage: %s [file] [-] [-f] [-s] [-h]\n",string);
fprintf(stderr," stdin and stdout are used if input file name is not given.\n");
}
if(error_no == 1 || error_no == 2){
fprintf(stderr," - : output to stdout\n");
fprintf(stderr," -f : force overwrite of output file\n");
fprintf(stderr," -s : skip strange epochs (default:stop with error)\n");
fprintf(stderr," This option may be used for salvaging usable data when middle of\n");
fprintf(stderr," the Compact RINEX file is missing. The data after the missing part,\n");
fprintf(stderr," are, however, useless until the compression operation of all data\n");
fprintf(stderr," are initialized at some epoch. Combination with use of -e option\n");
fprintf(stderr," of RNX2CRX (ver.4.0 or after) may be effective.\n");
fprintf(stderr," Caution : It is assumed that no change in # of data types\n");
fprintf(stderr," happens in the lost part of the data.\n");
fprintf(stderr," -h : display help message\n\n");
fprintf(stderr," exit code = %d (success)\n",EXIT_SUCCESS);
fprintf(stderr," = %d (error)\n", EXIT_FAILURE);
fprintf(stderr," = %d (warning)\n",EXIT_WARNING);
fprintf(stderr," [version : %s]\n",VERSION);
exit(EXIT_FAILURE);
}
if(error_no == 3 ){
fprintf(stderr,"ERROR : invalid file name %s\n",string);
fprintf(stderr,"The extention of the input file name should be [.xxd].\n");
fprintf(stderr,"If the file name doesn't obey this naming convention, use this program as a filter. \n");
fprintf(stderr," for example) cat file.in | %s - > file.out\n",PROGNAME);
exit(EXIT_FAILURE);
}
if(error_no == 4 ){
fprintf(stderr,"ERROR : can't open %s\n",string);
exit(EXIT_FAILURE);
}
if(error_no == 5 ){
fprintf(stderr,"ERROR : The file format is not Compact RINEX or the version of\n");
fprintf(stderr," the format is not valid. This software can deal with\n");
fprintf(stderr," only Compact RINEX format ver.%s.\n",string);
exit(EXIT_FAILURE);
}
if(error_no == 6 ){
fprintf(stderr,"ERROR at line %ld : exceed maximum number of satellites(%d)\n",nl_count,MAXSAT);
fprintf(stderr," start>%s<end\n",string);
exit(EXIT_FAILURE);
}
if(error_no == 7 ){
fprintf(stderr,"ERROR at line %ld : exceed maximum order of difference (%d)\n",nl_count,MAX_DIFF_ORDER);
fprintf(stderr," start>%s<end\n",string);
exit(EXIT_FAILURE);
}
if(error_no == 8 ){
fprintf(stderr,"ERROR : The file seems to be truncated in the middle.\n");
fprintf(stderr," The conversion is interrupted after reading the line %ld :\n",nl_count);
fprintf(stderr," start>%s<end\n",string);
exit(EXIT_FAILURE);
}
if(error_no == 9 ){
fprintf(stderr,"ERROR at line %ld : The arc should be initialized, but not.\n",nl_count);
fprintf(stderr," start>%s<end\n",string);
exit(EXIT_FAILURE);
}
if(error_no == 11){
fprintf(stderr,"ERROR at line %ld : New satellite, but data arc is not initialized.\n",nl_count);
fprintf(stderr," start>%s<end\n",string);
exit(EXIT_FAILURE);
}
if(error_no == 12){
fprintf(stderr,"ERROR at line %ld : The data field in previous epoch is blank, but the arc is not initialized.\n",nl_count);
fprintf(stderr," start>%s<end\n",string);
exit(EXIT_FAILURE);
}
if(error_no == 13){
fprintf(stderr,"ERROR at line %ld : null character is found in the line or the line is too long (>%d) at line.\n",nl_count,MAXCLM);
fprintf(stderr," start>%s<end\n",string);
exit(EXIT_FAILURE);
}
if(error_no == 15 ){
fprintf(stderr,"ERROR : The format version of the original RINEX file is not valid.\n");
fprintf(stderr," This software can deal with only (compressed) RINEX format ver.%s.\n",string);
exit(EXIT_FAILURE);
}
if(error_no == 20 ){
fprintf(stderr,"ERROR at line %ld. : A GNSS type not defined in the header is found.\n",nl_count);
fprintf(stderr," start>%s<end\n",string);
exit(EXIT_FAILURE);
}
}
|
the_stack_data/253569.c
|
/*
gcc -std=c17 -lc -lm -pthread -o ../_build/c/string_byte_memset.exe ./c/string_byte_memset.c && (cd ../_build/c/;./string_byte_memset.exe)
https://en.cppreference.com/w/c/string/byte/memset
*/
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
char str[] = "ghghghghghghghghghghgh";
puts(str);
memset(str,'a',5);
puts(str);
#ifdef __STDC_LIB_EXT1__
set_constraint_handler_s(ignore_handler_s);
int r = memset_s(str, sizeof str, 'b', 5);
printf("str = \"%s\", r = %d\n", str, r);
r = memset_s(str, 5, 'c', 10); // count is greater than destsz
printf("str = \"%s\", r = %d\n", str, r);
#endif
}
|
the_stack_data/159514512.c
|
#define _GNU_SOURCE
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define SCALE_FACTOR 1000000
#define MIN_SLEEP 1
#define MAX_SLEEP 5
int num_running = 0;
pthread_mutex_t lock;
// generate random int between low and high inclusive
int random_int_in_range(const int low, const int high) {
return low + rand() % (high - low + 1);
}
void *sleep_print(void *ptr) {
int *thread_num = (int *)ptr;
long tid = (long)pthread_self();
// 16 least significant bits or shifted tid by 16
srand((time(NULL) & 0xFFFF) | (tid << 16));
useconds_t sleep_time = (useconds_t)random_int_in_range(
MIN_SLEEP * SCALE_FACTOR, MAX_SLEEP * SCALE_FACTOR);
printf("I, thread %d, am going to sleep for %.2f seconds.\n", *thread_num,
(double)sleep_time / SCALE_FACTOR);
usleep(sleep_time);
printf("I, thread %d, have finished.\n", *thread_num);
int retval;
if ((retval = pthread_mutex_lock(&lock)) != 0) {
fprintf(stderr, "Warning: cannot lock mutex. %s.\n", strerror(retval));
}
num_running--;
if ((retval = pthread_mutex_unlock(&lock)) != 0) {
fprintf(stderr, "Warning: cannot unlock mutex. %s.\n", strerror(retval));
}
pthread_exit(NULL);
}
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <num_threads>\n", argv[0]);
return EXIT_FAILURE;
}
int num_threads = atoi(argv[1]);
if (num_threads <= 0) {
fprintf(stderr, "Error: Invalid number of threads '%s'.\n", argv[1]);
return EXIT_FAILURE;
}
pthread_t *threads;
if ((threads = (pthread_t *)malloc(num_threads * sizeof(pthread_t))) ==
NULL) {
fprintf(stderr, "Error: Cannot allocate memory for threads.\n");
return EXIT_FAILURE;
}
int *thread_nums;
if ((thread_nums = (int *)malloc(num_threads * sizeof(int))) == NULL) {
fprintf(stderr, "Error: Cannot allocate memory for thread args.\n");
return EXIT_FAILURE;
}
int num_started = 0;
for (int i = 0; i < num_threads; i++) {
thread_nums[i] = i + 1;
int retval;
if ((retval = pthread_create(&threads[i], NULL, sleep_print,
(void *)(&thread_nums[i]))) != 0) {
fprintf(stderr,
"Error: Cannot create thread %d. No more threads will be "
"created. %s.\n",
i + 1, strerror(errno));
break;
}
num_started++;
if ((retval = pthread_mutex_lock(&lock)) != 0) {
fprintf(stderr, "Warning: cannot lock mutex. %s.\n", strerror(retval));
continue;
}
num_running++;
if ((retval = pthread_mutex_unlock(&lock)) != 0) {
fprintf(stderr, "Warning: cannot unlock mutex. %s.\n", strerror(retval));
}
}
// wait until threads are complete before main continues. if we don't wait,
// we run the risk of executing an exit, which will terminate the process and
// all threads before the threads have completed
for (int i = 0; i < num_started; i++) {
if (pthread_join(threads[i], NULL) != 0) {
// failed
fprintf(stderr, "Warning: Thread %d did not join properly.\n",
thread_nums[i]);
}
}
free(thread_nums);
free(threads);
printf("Threads started: %d.\nThreads still running: %d.\n", num_started,
num_running);
return EXIT_SUCCESS;
}
|
the_stack_data/34631.c
|
/*
* escsamples.c
*
* Samples for ANSI escape sequences
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
void cls() {
write(STDOUT_FILENO, "\33[2J", 4);
}
void home() {
write(STDOUT_FILENO, "\33[H", 3);
}
/*
* Move cursor to column x, row y
* (zero-based)
*/
void moveto(int x, int y) {
char ctl_string[128];
snprintf(ctl_string, 128, "\33[%d;%dH", y+1, x+1);
write(STDOUT_FILENO, ctl_string, strlen(ctl_string));
}
void cup(int lines) {
char ctl_string[128];
snprintf(ctl_string, 128, "\33[%dA", lines);
write(STDOUT_FILENO, ctl_string, strlen(ctl_string));
}
void cdown(int lines) {
char ctl_string[128];
snprintf(ctl_string, 128, "\33[%dB", lines);
write(STDOUT_FILENO, ctl_string, strlen(ctl_string));
}
void cright(int cols) {
char ctl_string[128];
snprintf(ctl_string, 128, "\33[%dC", cols);
write(STDOUT_FILENO, ctl_string, strlen(ctl_string));
}
void cleft(int cols) {
char ctl_string[128];
snprintf(ctl_string, 128, "\33[%dD", cols);
write(STDOUT_FILENO, ctl_string, strlen(ctl_string));
}
int main() {
char mystring[16];
cls();
home();
/*
* Print three characters
*/
write(STDOUT_FILENO, "123", 3);
/*
* Move cursor back to second column
*/
moveto(1, 0);
/*
* and erase everything from cursor to end-of-line
* including the cursor
*/
mystring[0]=27;
mystring[1]='[';
mystring[2]='K';
write(STDOUT_FILENO, mystring, 3);
/*
* Move cursor to position row 10, column 1
*/
moveto(0, 9);
/*
* Print some stuff
*/
write(STDOUT_FILENO, "abcde", 6);
/*
* Move cursor up one line
*/
cup(1);
/*
* and print some more stuff
*/
write(STDOUT_FILENO, "fg", 3);
/*
* Move cursor two characters to the right
*/
cright(2);
/*
* and print some more stuff
*/
write(STDOUT_FILENO, "h", 1);
/*
* Move cursor down two lines
*/
cdown(2);
/*
* and print some more stuff
*/
write(STDOUT_FILENO, "i", 1);
/*
* Move cursor left two characters
*/
cleft(2);
/*
* and print some more stuff
*/
write(STDOUT_FILENO, "j", 1);
/*
* Move cursor to position row 15, column 1
*/
moveto(0, 14);
/*
* Print three characters
*/
write(STDOUT_FILENO, "123", 3);
/*
* Move cursor to position row 15, column 2
*/
moveto(1, 14);
/*
* and erase everything to the end of the screen
* including the character at row 20, column 2 (i.e. '2')
*/
mystring[0]=27;
mystring[1]='[';
mystring[2]='0';
mystring[3]='J';
write(STDOUT_FILENO, mystring, 4);
/*
* Move cursor to position row 20, column 1
*/
moveto(0,19);
};
|
the_stack_data/13177.c
|
/*
* M1522.000800 System Programming
* Shell Lab
*
* tsh - A tiny shell program with job control
*
* Name: <omitted>
* Student id: <omitted>
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
/* Misc manifest constants */
#define MAXLINE 1024 /* max line size */
#define MAXARGS 128 /* max args on a command line */
#define MAXJOBS 16 /* max jobs at any point in time */
#define MAXJID 1<<16 /* max job ID */
/* Job states */
#define STATE_UNDEFINED 0 /* undefined */
#define STATE_FOREGROUND 1 /* running in foreground */
#define STATE_BACKGROUND 2 /* running in background */
#define STATE_STOPPED 3 /* stopped */
/*
* Jobs states: FG (foreground), BG (background), ST (stopped)
* Job state transitions and enabling actions:
* FG -> ST : ctrl-z
* ST -> FG : fg command
* ST -> BG : bg command
* BG -> FG : fg command
* At most 1 job can be in the FG state.
*/
/* Bool type & constants definitions */
#ifndef __cplusplus
typedef char bool;
#define true 1
#define false 0
#endif
/* End Bool type & constants definitions*/
/* Global variables */
extern char **environ; /* defined in libc */
const char prompt[] = "tsh> "; /* command line prompt (DO NOT CHANGE) */
int verbose = 0; /* if true, print additional output */
int nextjid = 1; /* next job ID to allocate */
char sbuf[MAXLINE]; /* for composing sprintf messages */
struct job_t /* The job struct */
{
pid_t pid; /* job PID */
int jid; /* job ID [1, 2, ...] */
int state; /* UNDEFINED, BG, FG, or ST */
char cmdline[MAXLINE]; /* command line */
};
struct job_t jobs[MAXJOBS]; /* The job list */
const sigset_t sigchild; /* sigset_t which only contains sigchild */
/* End global variables */
/* Function prototypes */
/*----------------------------------------------------------------------------
* Functions that you will implement
*/
void eval(const char *cmdline);
bool builtin_cmd(char **argv);
void do_bgfg(char **argv);
void wait_fg_process(pid_t pid);
void sigchld_handler(int sig);
void sigint_handler(int sig);
void sigtstp_handler(int sig);
/*----------------------------------------------------------------------------*/
/* These functions are already implemented for your convenience */
void parse_line(const char *cmdline, char **argv, bool *bg);
void sigquit_handler(int sig);
void clear_job_struct(struct job_t *job);
void initialize_job_list(struct job_t *jobs);
int get_max_jid(const struct job_t *jobs);
struct job_t *add_job(struct job_t *jobs, pid_t pid, int state, const char *cmdline);
bool delete_job_by_pid(struct job_t *jobs, pid_t pid);
void delete_job_by_job_t(struct job_t *jobs, struct job_t *job);
pid_t get_current_fg_pid(const struct job_t *jobs);
struct job_t *get_job_by_pid(const struct job_t *jobs, pid_t pid);
struct job_t *get_job_by_jid(const struct job_t *jobs, int jid);
int pid_to_jid(pid_t pid);
void print_job_list(const struct job_t *jobs);
void usage(void);
void unix_error(const char *msg);
void app_error(const char *msg);
typedef void handler_t(int);
handler_t *Signal(int signum, handler_t *handler);
/*
* main - The shell's main routine
*/
int main(int argc, char **argv)
{
char c;
char cmdline[MAXLINE];
int emit_prompt = 1; /* emit prompt (default) */
/* Redirect stderr to stdout (so that driver will get all output
* on the pipe connected to stdout) */
dup2(1, 2);
/* Parse the command line */
while ((c = getopt(argc, argv, "hvp")) != EOF)
{
switch (c)
{
case 'h': /* print help message */
usage();
break;
case 'v': /* emit additional diagnostic info */
verbose = 1;
break;
case 'p': /* don't print a prompt */
emit_prompt = 0; /* handy for automatic testing */
break;
default:
usage();
}
}
/* Install the signal handlers */
/* These are the ones you will need to implement */
Signal(SIGINT, sigint_handler); /* ctrl-c */
Signal(SIGTSTP, sigtstp_handler); /* ctrl-z */
Signal(SIGCHLD, sigchld_handler); /* Terminated or stopped child */
/* This one provides a clean way to kill the shell */
Signal(SIGQUIT, sigquit_handler);
/* Initialize the job list */
initialize_job_list(jobs);
/* Initialize global variable sigchild */
sigset_t *sigchild_pointer = (sigset_t *) &sigchild;
if (sigemptyset(sigchild_pointer) == -1)
unix_error("sigemptyset failed");
if (sigaddset(sigchild_pointer, SIGCHLD) == -1)
unix_error("sigaddset failed");
/* Execute the shell's read/eval loop */
while (1)
{
/* Read command line */
if (emit_prompt)
{
printf("%s", prompt);
fflush(stdout);
}
if ((fgets(cmdline, MAXLINE, stdin) == NULL) && ferror(stdin))
app_error("fgets error");
if (feof(stdin))
{ /* End of file (ctrl-d) */
fflush(stdout);
exit(0);
}
/* Evaluate the command line */
eval(cmdline);
fflush(stdout);
}
exit(0); /* control never reaches here */
}
/*
* eval - Evaluate the command line that the user has just typed in
*
* If the user has requested a built-in command (quit, jobs, bg or fg)
* then execute it immediately. Otherwise, fork a child process and
* run the job in the context of the child. If the job is running in
* the foreground, wait for it to terminate and then return. Note:
* each child process must have a unique process group ID so that our
* background children don't receive SIGINT (SIGTSTP) from the kernel
* when we type ctrl-c (ctrl-z) at the keyboard.
*/
void eval(const char *cmdline)
{
bool background;
char *argv[MAXARGS];
pid_t child_pid;
parse_line(cmdline, argv, &background);
if (!builtin_cmd(argv))
{
if (sigprocmask(SIG_BLOCK, &sigchild, NULL) == -1)
unix_error("Blocking SIGCHLD failed");
child_pid = fork();
if (child_pid == -1)
unix_error("fork failed");
else if (child_pid == 0)
{
if (setpgid(0, 0) == -1)
unix_error("setpgid failed");
if (sigprocmask(SIG_UNBLOCK, &sigchild, NULL) == -1)
unix_error("Unblocking SIGCHLD failed");
execvp(argv[0], argv);
// If exec fails,
if (errno == ENOENT)
fprintf(stderr, "%s: Command not found\n", argv[0]);
else
unix_error(argv[0]);
exit(0);
}
else
{
if (background)
{
struct job_t *job = add_job(jobs, child_pid, STATE_BACKGROUND, cmdline);
if (job != NULL)
printf("[%d] (%d) %s", job->jid, job->pid, job->cmdline);
if (sigprocmask(SIG_UNBLOCK, &sigchild, NULL) == -1)
unix_error("Unblocking SIGCHLD failed");
}
else
{
add_job(jobs, child_pid, STATE_FOREGROUND, cmdline);
if (sigprocmask(SIG_UNBLOCK, &sigchild, NULL) == -1)
unix_error("Unblocking SIGCHLD failed");
wait_fg_process(child_pid);
}
}
}
}
/*
* parse_line - Parse the command line and build the argv array.
*
* Characters enclosed in single quotes are treated as a single
* argument. Return true if the user has requested a BG job, false if
* the user has requested a FG job.
*/
void parse_line(const char *cmdline, char **argv, bool *bg)
{
static char array[MAXLINE]; /* holds local copy of command line */
char *buf = array; /* ptr that traverses command line */
char *delim; /* points to first space delimiter */
int argc; /* number of args */
bool background; /* background job? */
if (argv == NULL)
return;
strcpy(buf, cmdline);
buf[strlen(buf) - 1] = ' '; /* replace trailing '\n' with space */
while (*buf && (*buf == ' ')) /* ignore leading spaces */
buf++;
/* Build the argv list */
argc = 0;
if (*buf == '\'')
{
buf++;
delim = strchr(buf, '\'');
}
else
{
delim = strchr(buf, ' ');
}
while (delim)
{
argv[argc++] = buf;
*delim = '\0';
buf = delim + 1;
while (*buf && (*buf == ' ')) /* ignore spaces */
buf++;
if (*buf == '\'')
{
buf++;
delim = strchr(buf, '\'');
}
else
{
delim = strchr(buf, ' ');
}
if (argc >= MAXARGS) /* to prevent buffer overflow */
break;
}
argv[argc] = NULL;
if (argc == 0) /* ignore blank line */
background = true;
/* should the job run in the background? */
else if ((background = (*argv[argc - 1] == '&')))
{
argv[--argc] = NULL;
}
if (bg != NULL)
*bg = background;
}
/*
* try_execute_builtin_command - If the user has typed a built-in
* command then execute it immediately.
* Returns true if given command is built-in command, false otherwise.
*/
bool builtin_cmd(char **argv)
{
if (argv == NULL || argv[0] == NULL)
return false; // Goto normal execution routine to print error message
if (strcmp(argv[0], "quit") == 0)
{
/* Built-in commands are not executed in child process.
* This will exit shell process directly. */
exit(0);
}
else if (strcmp(argv[0], "fg") == 0 || strcmp(argv[0], "bg") == 0)
{
do_bgfg(argv);
return true;
}
else if (strcmp(argv[0], "jobs") == 0)
{
print_job_list(jobs);
return true;
}
else
return false; /* not a builtin command */
}
/*
* do_bgfg - Execute the builtin bg and fg commands
*/
void do_bgfg(char **argv)
{
bool background, argument_error = false;
struct job_t *target;
int jid;
pid_t pid;
if (argv == NULL || argv[0] == NULL)
return;
if (strcmp(argv[0], "bg") == 0)
background = true;
else if (strcmp(argv[0], "fg") == 0)
background = false;
else
return;
const char * const command = (background? "bg" : "fg");
if (argv[1] == NULL)
{
printf("%s command requires PID or %%jobid argument\n", command);
return;
}
else
{
char *endptr;
errno = 0; // Reset errno for strtol
if (argv[1][0] == '%')
{
jid = strtol(&argv[1][1], &endptr, 10);
if (&argv[1][1] == endptr || errno == ERANGE || errno == EINVAL)
argument_error = true;
else
target = get_job_by_jid(jobs, jid);
}
else
{
pid = strtol(&argv[1][0], &endptr, 10);
if (&argv[1][0] == endptr || errno == ERANGE || errno == EINVAL)
argument_error = true;
else
target = get_job_by_pid(jobs, pid);
}
}
if (argument_error)
{
printf("%s: argument must be a PID or %%jobid\n", command);
}
else if (target == NULL)
{
if (argv[1][0] == '%')
printf("%%%d: No such job\n", jid);
else
printf("(%d): No such process\n", pid);
}
else
{
if (kill(-target->pid, SIGCONT) == -1)
unix_error("Sending SIGCONT failed");
if (background)
{
printf("[%d] (%d) %s", target->jid, target->pid, target->cmdline);
target->state = STATE_BACKGROUND;
}
else
{
target->state = STATE_FOREGROUND;
wait_fg_process(target->pid);
}
}
}
/*
* wait_fg_process - Block until process pid is no longer the foreground process
*/
void wait_fg_process(pid_t pid)
{
struct job_t *job = get_job_by_pid(jobs, pid);
/* If job is terminated, state would have been changed to undefined
* by delete_job function */
while (job->state == STATE_FOREGROUND)
{
if (pause() != -1)
unix_error("pause() returned unexpected value");
}
}
/*****************
* Signal handlers
*****************/
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
pid_t child_pid;
int child_status;
while (true)
{
child_pid = waitpid(-1, &child_status, WNOHANG | WUNTRACED | WCONTINUED);
if (child_pid == 0)
break;
else if (child_pid == -1)
{
if (errno == ECHILD)
break;
else
unix_error("waitpid failed");
}
struct job_t *job = get_job_by_pid(jobs, child_pid);
if (WIFEXITED(child_status)) // Child is exited
delete_job_by_job_t(jobs, job);
else if (WIFSIGNALED(child_status)) // Child is terminated by signal
{
printf("Job [%d] (%d) terminated by signal %d\n", job->jid, job->pid, WTERMSIG(child_status));
delete_job_by_job_t(jobs, job);
}
else if (WIFSTOPPED(child_status)) // Child is stopped
{
printf("Job [%d] (%d) stopped by signal %d\n", job->jid, job->pid, WSTOPSIG(child_status));
job->state = STATE_STOPPED;
}
else if (WIFCONTINUED(child_status)) // Child is continued
{
// Do nothing if child is continued by fg command
if (job->state == STATE_FOREGROUND)
continue;
// If child is continued by bg command or signal from outside
else
job->state = STATE_BACKGROUND;
}
else
{
fprintf(stderr, "Untreated status %d from child %d\n", child_status, child_pid);
print_job_list(jobs);
exit(1);
}
}
}
/*
* sigint_handler - The kernel sends a SIGINT to the shell whenver the
* user types ctrl-c at the keyboard. Catch it and send it along
* to the foreground job.
*/
void sigint_handler(int sig)
{
pid_t foreground_process = get_current_fg_pid(jobs);
if (foreground_process != 0)
if(kill(-foreground_process, SIGINT) == -1)
unix_error("Sending signal failed");
}
/*
* sigtstp_handler - The kernel sends a SIGTSTP to the shell whenever
* the user types ctrl-z at the keyboard. Catch it and suspend the
* foreground job by sending it a SIGTSTP.
*/
void sigtstp_handler(int sig)
{
pid_t foreground_process = get_current_fg_pid(jobs);
if (foreground_process != 0)
if(kill(-foreground_process, SIGTSTP) == -1)
unix_error("Sending signal failed");
}
/*********************
* End signal handlers
*********************/
/***********************************************
* Helper routines that manipulate the job list
**********************************************/
/* clear_job_struct - Clear the entries in a job struct */
void clear_job_struct(struct job_t *job)
{
job->pid = 0;
job->jid = 0;
job->state = STATE_UNDEFINED;
job->cmdline[0] = '\0';
}
/* initialize_job_list - Initialize the job list */
void initialize_job_list(struct job_t *jobs)
{
int i;
for (i = 0; i < MAXJOBS; i++)
clear_job_struct(&jobs[i]);
}
/* get_max_jid - Returns largest allocated job ID */
int get_max_jid(const struct job_t *jobs)
{
int i, max = 0;
for (i = 0; i < MAXJOBS; i++)
if (jobs[i].jid > max)
max = jobs[i].jid;
return max;
}
/* add_job - Add a job to the job list
* Returns newly added job structure if success, NULL if not.
*/
struct job_t *add_job(struct job_t *jobs, pid_t pid, int state, const char *cmdline)
{
int i;
if (pid < 1)
return 0;
for (i = 0; i < MAXJOBS; i++)
{
if (jobs[i].pid == 0)
{
jobs[i].pid = pid;
jobs[i].state = state;
jobs[i].jid = nextjid++;
if (nextjid > MAXJOBS)
nextjid = 1;
strcpy(jobs[i].cmdline, cmdline);
if (verbose)
{
printf("Added job [%d] %d %s", jobs[i].jid, jobs[i].pid, jobs[i].cmdline);
}
return &jobs[i];
}
}
printf("Tried to create too many jobs\n");
return NULL;
}
/* delete_job_by_pid - Delete a job whose PID=pid from the job list
* Returns true if success, false if fails
*/
bool delete_job_by_pid(struct job_t *jobs, pid_t pid)
{
int i;
if (pid < 1)
return false;
for (i = 0; i < MAXJOBS; i++)
{
if (jobs[i].pid == pid)
{
delete_job_by_job_t(jobs, &jobs[i]);
return true;
}
}
return false;
}
/*
* delete_job_by_job_t - Delete a job using given job pointer
* struct job_t *jobs -
*/
void delete_job_by_job_t(struct job_t *jobs, struct job_t *job)
{
clear_job_struct(job);
nextjid = get_max_jid(jobs) + 1;
}
/* get_current_fg_pid - Return PID of current foreground job, 0 if no such job */
pid_t get_current_fg_pid(const struct job_t *jobs)
{
int i;
for (i = 0; i < MAXJOBS; i++)
if (jobs[i].state == STATE_FOREGROUND)
return jobs[i].pid;
return 0;
}
/* get_job_by_pid - Find a job (by PID) on the job list */
struct job_t *get_job_by_pid(const struct job_t *jobs, pid_t pid)
{
int i;
if (pid < 1)
return NULL;
for (i = 0; i < MAXJOBS; i++)
if (jobs[i].pid == pid)
return (struct job_t *) &jobs[i];
return NULL;
}
/* get_job_by_jid - Find a job (by JID) on the job list */
struct job_t *get_job_by_jid(const struct job_t *jobs, int jid)
{
int i;
if (jid < 1)
return NULL;
for (i = 0; i < MAXJOBS; i++)
if (jobs[i].jid == jid)
return (struct job_t *) &jobs[i];
return NULL;
}
/* pid_to_jid - Map process ID to job ID */
int pid_to_jid(pid_t pid)
{
int i;
if (pid < 1)
return 0;
for (i = 0; i < MAXJOBS; i++)
if (jobs[i].pid == pid)
{
return jobs[i].jid;
}
return 0;
}
/* print_job_list - Print the job list */
void print_job_list(const struct job_t *jobs)
{
int i;
for (i = 0; i < MAXJOBS; i++)
{
if (jobs[i].pid != 0)
{
printf("[%d] (%d) ", jobs[i].jid, jobs[i].pid);
switch (jobs[i].state)
{
case STATE_BACKGROUND:
printf("Running ");
break;
case STATE_FOREGROUND:
printf("Foreground ");
break;
case STATE_STOPPED:
printf("Stopped ");
break;
default:
printf("listjobs: Internal error: job[%d].state=%d ",
i, jobs[i].state);
}
printf("%s", jobs[i].cmdline);
}
}
}
/******************************
* end job list helper routines
******************************/
/***********************
* Other helper routines
***********************/
/*
* usage - print a help message
*/
void usage(void)
{
printf("Usage: shell [-hvp]\n");
printf(" -h print this message\n");
printf(" -v print additional diagnostic information\n");
printf(" -p do not emit a command prompt\n");
exit(1);
}
/*
* unix_error - unix-style error routine
*/
void unix_error(const char *msg)
{
fprintf(stdout, "%s: %s\n", msg, strerror(errno));
exit(1);
}
/*
* app_error - application-style error routine
*/
void app_error(const char *msg)
{
fprintf(stdout, "%s\n", msg);
exit(1);
}
/*
* Signal - wrapper for the sigaction function
*/
handler_t *Signal(int signum, handler_t *handler)
{
struct sigaction action, old_action;
action.sa_handler = handler;
sigemptyset(&action.sa_mask); /* block sigs of type being handled */
action.sa_flags = SA_RESTART; /* restart syscalls if possible */
if (sigaction(signum, &action, &old_action) < 0)
unix_error("Signal error");
return (old_action.sa_handler);
}
/*
* sigquit_handler - The driver program can gracefully terminate the
* child shell by sending it a SIGQUIT signal.
*/
void sigquit_handler(int sig)
{
printf("Terminating after receipt of SIGQUIT signal\n");
exit(1);
}
|
the_stack_data/294769.c
|
#include <stdio.h>
#include <stdlib.h>
int main()
{
//This pointer will hold the
//base address of the block created
int* ptr;
int n, i;
//Get the number of elements for the array
printf("Enter number of elements: ");
scanf("%d", &n);
printf("Entered number of elements: %d\n", n);
//Dynamically allocate memory using malloc()
ptr = (int*)malloc(n * sizeof(int));
//Check if the memory has been successfully
//allocated by malloc or not
if(ptr == NULL) {
printf("Memory not allocated.\n");
exit(0);
}
else{
//Memory has been successfully allocated
printf("Memory successfully allocated using malloc.\n");
//Get the elements of the array
for (i=0;i<n;++i) {
ptr[i] = i +1;
}
//Print the elements of the array
printf("The elements of the array are: \n");
for(i = 0; i<n; ++i) {
printf("%d, ",ptr[i]);
}
}
return 0;
}
|
the_stack_data/48575759.c
|
/*
Database "local_govt_mdm" contains tables:
benefits_overpayments
business_rates
cmi_cross_references
council_tax
customer_master_index
electoral_register
parking_fines
rent_arrears
*/
#ifndef LOCAL_GOVT_MDM
#define LOCAL_GOVT_MDM
struct T_benefits_overpayments {
double council_tax_id;
double cmi_cross_ref_id; // --> cmi_cross_references.cmi_cross_reference_id
};
struct T_business_rates {
double business_rates_id;
double cmi_cross_reference_id; // --> cmi_cross_references.cmi_cross_reference_id
};
struct T_cmi_cross_references {
double cmi_cross_reference_id;
double master_customer_id; // --> customer_master_index.master_customer_id
char source_system_code[10];
};
struct T_council_tax {
double council_tax_id;
double cmi_cross_reference_id; // --> cmi_cross_references.cmi_cross_reference_id
};
struct T_customer_master_index {
double master_customer_id;
char cmi_details[32];
};
struct T_electoral_register {
double electoral_register_id;
double cmi_cross_reference_id; // --> cmi_cross_references.cmi_cross_reference_id
};
struct T_parking_fines {
double council_tax_id;
double cmi_cross_reference_id; // --> cmi_cross_references.cmi_cross_reference_id
};
struct T_rent_arrears {
double council_tax_id;
double cmi_cross_reference_id; // --> cmi_cross_references.cmi_cross_reference_id
};
struct T_benefits_overpayments
benefits_overpayments[] = {
{ 3, 65 },
{ 6, 41 },
{ 7, 83 },
{ 8, 48 }
};
struct T_business_rates
business_rates[] = {
{ 2, 99 },
{ 5, 49 },
{ 8, 95 }
};
struct T_cmi_cross_references
cmi_cross_references[] = {
{ 2, 4, "Rent" },
{ 4, 5, "Parking" },
{ 8, 1, "Rent" },
{ 41, 5, "Benefits" },
{ 48, 5, "Benefits" },
{ 49, 1, "Business" },
{ 59, 1, "Rent" },
{ 65, 9, "Benefits" },
{ 75, 5, "Electoral" },
{ 77, 4, "Electoral" },
{ 81, 9, "Parking" },
{ 83, 3, "Benefits" },
{ 95, 2, "Business" },
{ 99, 9, "Business" },
{ 100, 4, "Rent" },
{ 101, 2, "Tax" },
{ 102, 4, "Tax" },
{ 103, 9, "Tax" },
{ 104, 2, "Tax" },
{ 105, 2, "Tax" },
{ 106, 1, "Tax" }
};
struct T_council_tax
council_tax[] = {
{ 1, 101 },
{ 2, 103 },
{ 3, 104 },
{ 7, 102 },
{ 8, 106 },
{ 9, 105 }
};
struct T_customer_master_index
customer_master_index[] = {
{ 1, "Schmitt-Lang" },
{ 2, "Volkman, Mills and Ferry" },
{ 3, "Gusikowski PLC" },
{ 4, "Schmidt, Kertzmann and Lubowitz" },
{ 5, "Gottlieb, Becker and Wyman" },
{ 6, "Mayer-Hagenes" },
{ 7, "Streich-Morissette" },
{ 8, "Quigley-Paucek" },
{ 9, "Reynolds-McClure" }
};
struct T_electoral_register
electoral_register[] = {
{ 2, 83 },
{ 3, 65 },
{ 4, 100 },
{ 6, 95 },
{ 7, 65 },
{ 8, 75 }
};
struct T_parking_fines
parking_fines[] = {
{ 9, 4 },
{ 10, 81 }
};
struct T_rent_arrears
rent_arrears[] = {
{ 1, 100 },
{ 2, 8 },
{ 6, 59 },
{ 7, 2 }
};
#endif
|
the_stack_data/122144.c
|
//shellcode copied from Ben Lynn's tutorial
//on ROP
//https://crypto.stanford.edu/~blynn/rop/
int main() {
asm("\
needle0: jmp there\n\
here: pop %rdi\n\
xor %rax, %rax\n\
movb $0x3b, %al\n\
xor %rsi, %rsi\n\
xor %rdx, %rdx\n\
syscall\n\
there: call here\n\
.string \"/bin/sh\"\n\
needle1: .octa 0xdeadbeef\n\
");
}
|
the_stack_data/162644144.c
|
/* Program takes the input dimensions A and B, and computes the area.
Incorrect values of A or B that do not result in a square or rectangle are rejected.
Then it is classified as square or rectangle */
#include <stdio.h>
int quadilateral(int a, int b);
int main()
{
char c;
do {
int a;
int b;
printf("enter dimension a \n");
scanf("%d", &a);
printf("enter dimension b \n");
scanf("%d", &b);
int ar= quadilateral(a,b);
if(!(a==0||b==0)&&(a==b))
printf("Square with Area %d \n", ar);
else if(!(a==0||b==0))
printf("Rectangle with Area %d \n", ar);
else
printf("One of the values was zero \n");
fflush(stdin);
printf("Continue? (y/n) \n");
scanf(" %c", &c);
}
while(c=='y');
}
int quadilateral(int a,int b)
{
int area = a*b;
if(a==0||b==0)
printf("Incorrect values, try again \n");
else
printf("area %d \n", area);
return area;
}
|
the_stack_data/105602.c
|
#include <stdio.h>
// Define boolean type
typedef enum {false, true} bool;
/**
* Main program
*
* @return: Exit code
**/
int main(void) {
/* Tracking variables */
int goes_up = 1;
int goes_down = 1;
float curr_price, prev_price;
bool can_buy = true;
bool can_sell = false;
/* Print first row */
if (scanf("%f", &curr_price) != EOF) {
prev_price = curr_price;
printf("%.3f\n", curr_price);
}
/* Read prices from file */
while (scanf("%f", &curr_price) != EOF) {
if (prev_price < curr_price) {
/* Buy */
if (3 <= goes_down && can_buy) printf("%.3f\tbuy\n", curr_price);
else printf("%.3f\n", curr_price);
/* Reset and update trackers */
goes_down = 1;
goes_up++;
} else if (curr_price < prev_price && can_sell) {
/* Sell */
if (3 <= goes_up && can_sell) printf("%.3f\tsell\n", curr_price);
else printf("%.3f\n", curr_price);
/* Reset and update trackers */
goes_up = 1;
goes_down++;
} else
printf("%.3f\n", curr_price);
/* Update tracker */
prev_price = curr_price;
}
return 0;
}
|
the_stack_data/70449810.c
|
#include <stdio.h>
#define TEN 10
int main(void)
{
int n = 0;
while (n++ < TEN)
printf("%5d", n);
printf("\n");
return 0;
}
|
the_stack_data/231392412.c
|
/*
* Copyright 2017 Google, Inc
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
void wiringPiI2CWriteReg8( int fd, int addr, int reg, int data )
{
unsigned char buf[2] = { reg, data };
ioctl( fd, I2C_SLAVE, addr );
write( fd, buf, 2 );
}
void set_backlight( int fd, int r, int g, int b )
{
wiringPiI2CWriteReg8( fd, 0x62, 0, 0 );
wiringPiI2CWriteReg8( fd, 0x62, 1, 0 );
wiringPiI2CWriteReg8( fd, 0x62, 8, 0xaa );
wiringPiI2CWriteReg8( fd, 0x62, 4, r );
wiringPiI2CWriteReg8( fd, 0x62, 3, g );
wiringPiI2CWriteReg8( fd, 0x62, 2, b );
}
void textCommand(int fd, int cmd)
{
wiringPiI2CWriteReg8( fd, 0x3e, 0x80, cmd );
}
void setText(int fd, char * text)
{
int i;
textCommand( fd, 0x01 ); // clear display
usleep( 5000);
textCommand( fd, 0x08 | 0x04 ); // display on, no cursor
textCommand( fd, 0x28 ); // 2 lines
usleep( 5000 );
for (i=0; text[i] != '\0'; i++) {
if (text[i] == '\n') {
textCommand( fd, 0xc0 );
} else {
wiringPiI2CWriteReg8( fd, 0x3e, 0x40, text[i] );
}
}
}
int i2c_lcd_test ( void )
{
int i;
int fd;
printf ("Rockpi4b i2c test\n") ;
// 0x62 is rgb, 0x3e is text
fd = open( "/dev/i2c-7", O_RDWR );
textCommand( fd, 0x01 ); // clear display
usleep( 5000 );
textCommand( fd, 0x08 | 0x04 ); // display on, no cursor
textCommand( fd, 0x28 ); // 2 lines
usleep( 5000 );
set_backlight( fd, 255, 0, 0 );
for ( i=0; i<5; i++ )
{
set_backlight( fd, 255, 0, 0 );
sleep( 1 );
set_backlight( fd, 255, 255, 0 );
sleep( 1 );
set_backlight( fd, 0, 255, 0 );
sleep( 1 );
set_backlight( fd, 0, 255, 255 );
sleep( 1 );
set_backlight( fd, 0, 0, 255 );
sleep( 1 );
set_backlight( fd, 255, 0, 255 );
sleep( 1 );
}
set_backlight( fd, 128, 255, 0 );
setText( fd, "Hello world !\nIt works !\n" );
close( fd );
return 0;
}
|
the_stack_data/564468.c
|
#include <stdio.h>
int main()
{
char input[10];
printf("Your name? ");
fgets(input,10,stdin);
printf("Pleased to meet you, %s!\n",input);
return(0);
}
|
the_stack_data/9511803.c
|
/* { dg-do compile } */
/* { dg-options "-O -fdump-tree-optimized" } */
/* { dg-additional-options "-fno-common" { target hppa*-*-hpux* } } */
typedef int v4si __attribute__((vector_size(4*sizeof (int))));
v4si v;
int foo (int i)
{
v4si v1 = (v4si) { i, i, i, i };
v4si v2 = (v4si) { 3, 3, 3, 3 };
v = v1 * v2;
}
/* The operation should be carried out as scalar op. */
/* { dg-final { scan-tree-dump-times " \* 3;" 1 "optimized" } } */
|
the_stack_data/165764607.c
|
/***
* This code is a part of EvoApproxLib library (ehw.fit.vutbr.cz/approxlib) distributed under The MIT License.
* When used, please cite the following article(s): V. Mrazek, R. Hrbacek, Z. Vasicek and L. Sekanina, "EvoApprox8b: Library of approximate adders and multipliers for circuit design and benchmarking of approximation methods". Design, Automation & Test in Europe Conference & Exhibition (DATE), 2017, Lausanne, 2017, pp. 258-261. doi: 10.23919/DATE.2017.7926993
* This file contains a circuit from evoapprox8b dataset. Note that a new version of library was already published.
***/
#include <stdint.h>
#include <stdlib.h>
/// Approximate function mul8_265
/// Library = EvoApprox8b
/// Circuit = mul8_265
/// Area (180) = 7344
/// Delay (180) = 5.570
/// Power (180) = 3522.80
/// Area (45) = 537
/// Delay (45) = 2.060
/// Power (45) = 307.50
/// Nodes = 116
/// HD = 228185
/// MAE = 45.89209
/// MSE = 3630.15625
/// MRE = 1.60 %
/// WCE = 268
/// WCRE = 100 %
/// EP = 91.4 %
uint16_t mul8_265(uint8_t a, uint8_t b)
{
uint16_t c = 0;
uint8_t n0 = (a >> 0) & 0x1;
uint8_t n2 = (a >> 1) & 0x1;
uint8_t n4 = (a >> 2) & 0x1;
uint8_t n6 = (a >> 3) & 0x1;
uint8_t n8 = (a >> 4) & 0x1;
uint8_t n10 = (a >> 5) & 0x1;
uint8_t n12 = (a >> 6) & 0x1;
uint8_t n14 = (a >> 7) & 0x1;
uint8_t n16 = (b >> 0) & 0x1;
uint8_t n18 = (b >> 1) & 0x1;
uint8_t n20 = (b >> 2) & 0x1;
uint8_t n22 = (b >> 3) & 0x1;
uint8_t n24 = (b >> 4) & 0x1;
uint8_t n26 = (b >> 5) & 0x1;
uint8_t n28 = (b >> 6) & 0x1;
uint8_t n30 = (b >> 7) & 0x1;
uint8_t n32;
uint8_t n38;
uint8_t n39;
uint8_t n41;
uint8_t n51;
uint8_t n64;
uint8_t n65;
uint8_t n81;
uint8_t n82;
uint8_t n83;
uint8_t n107;
uint8_t n114;
uint8_t n132;
uint8_t n136;
uint8_t n137;
uint8_t n139;
uint8_t n148;
uint8_t n182;
uint8_t n190;
uint8_t n211;
uint8_t n217;
uint8_t n221;
uint8_t n233;
uint8_t n248;
uint8_t n264;
uint8_t n282;
uint8_t n382;
uint8_t n398;
uint8_t n399;
uint8_t n414;
uint8_t n415;
uint8_t n464;
uint8_t n498;
uint8_t n514;
uint8_t n532;
uint8_t n548;
uint8_t n598;
uint8_t n601;
uint8_t n632;
uint8_t n633;
uint8_t n648;
uint8_t n649;
uint8_t n664;
uint8_t n665;
uint8_t n682;
uint8_t n683;
uint8_t n714;
uint8_t n732;
uint8_t n748;
uint8_t n764;
uint8_t n782;
uint8_t n798;
uint8_t n814;
uint8_t n832;
uint8_t n849;
uint8_t n865;
uint8_t n881;
uint8_t n882;
uint8_t n883;
uint8_t n898;
uint8_t n899;
uint8_t n914;
uint8_t n915;
uint8_t n932;
uint8_t n933;
uint8_t n948;
uint8_t n949;
uint8_t n964;
uint8_t n982;
uint8_t n998;
uint8_t n1014;
uint8_t n1032;
uint8_t n1048;
uint8_t n1064;
uint8_t n1082;
uint8_t n1099;
uint8_t n1114;
uint8_t n1132;
uint8_t n1133;
uint8_t n1148;
uint8_t n1149;
uint8_t n1164;
uint8_t n1165;
uint8_t n1182;
uint8_t n1183;
uint8_t n1198;
uint8_t n1199;
uint8_t n1214;
uint8_t n1215;
uint8_t n1232;
uint8_t n1248;
uint8_t n1264;
uint8_t n1282;
uint8_t n1298;
uint8_t n1314;
uint8_t n1332;
uint8_t n1348;
uint8_t n1364;
uint8_t n1365;
uint8_t n1382;
uint8_t n1383;
uint8_t n1398;
uint8_t n1399;
uint8_t n1414;
uint8_t n1415;
uint8_t n1432;
uint8_t n1433;
uint8_t n1448;
uint8_t n1449;
uint8_t n1464;
uint8_t n1465;
uint8_t n1482;
uint8_t n1483;
uint8_t n1498;
uint8_t n1514;
uint8_t n1532;
uint8_t n1548;
uint8_t n1564;
uint8_t n1582;
uint8_t n1598;
uint8_t n1614;
uint8_t n1632;
uint8_t n1633;
uint8_t n1648;
uint8_t n1649;
uint8_t n1664;
uint8_t n1665;
uint8_t n1682;
uint8_t n1683;
uint8_t n1698;
uint8_t n1699;
uint8_t n1714;
uint8_t n1715;
uint8_t n1732;
uint8_t n1733;
uint8_t n1748;
uint8_t n1749;
uint8_t n1764;
uint8_t n1782;
uint8_t n1798;
uint8_t n1814;
uint8_t n1832;
uint8_t n1848;
uint8_t n1864;
uint8_t n1882;
uint8_t n1898;
uint8_t n1899;
uint8_t n1914;
uint8_t n1915;
uint8_t n1932;
uint8_t n1933;
uint8_t n1948;
uint8_t n1949;
uint8_t n1964;
uint8_t n1965;
uint8_t n1982;
uint8_t n1983;
uint8_t n1998;
uint8_t n1999;
uint8_t n2014;
uint8_t n2015;
n32 = ~(n18 & n14);
n38 = ~(n18 | n32);
n39 = ~(n18 | n32);
n41 = (n2 & n38) | (n38 & n22) | (n2 & n22);
n51 = ~n39;
n64 = ~(n28 | n14 | n51);
n65 = ~(n28 | n14 | n51);
n81 = ~((n18 & n39) | n51);
n82 = n6 & n20;
n83 = n6 & n20;
n107 = ~(n81 | n82);
n114 = n10 & n16;
n132 = n12 & n16;
n136 = n12 ^ n38;
n137 = n12 & n38;
n139 = n51 | n136;
n148 = n14 & n16;
n182 = n22 & n64;
n190 = ~(n10 ^ n8);
n211 = ~n51;
n217 = ~((n18 & n190) | n139);
n221 = n41 | n114;
n233 = n8 & n18;
n248 = n10 & n18;
n264 = n12 & n18;
n282 = n14 & n18;
n382 = n132 | n248;
n398 = n148 ^ n264;
n399 = n148 & n264;
n414 = n399 ^ n282;
n415 = n399 & n282;
n464 = n4 | n20;
n498 = n8 & n20;
n514 = n10 & n20;
n532 = n12 & n20;
n548 = n14 & n20;
n598 = n107 | n464;
n601 = (n211 & n182) | (~n211 & n65);
n632 = n382 ^ n498;
n633 = n382 & n498;
n648 = (n398 ^ n514) ^ n633;
n649 = (n398 & n514) | (n514 & n633) | (n398 & n633);
n664 = (n414 ^ n532) ^ n649;
n665 = (n414 & n532) | (n532 & n649) | (n414 & n649);
n682 = (n415 ^ n548) ^ n665;
n683 = (n415 & n548) | (n548 & n665) | (n415 & n665);
n714 = n2 & n22;
n732 = n217 & n22;
n748 = n6 & n22;
n764 = n8 & n22;
n782 = n10 & n22;
n798 = n12 & n22;
n814 = n14 & n22;
n832 = n601;
n849 = n598 | n714;
n865 = (n233 & n732) | (n732 & n849) | (n233 & n849);
n881 = n665;
n882 = (n632 ^ n748) ^ n865;
n883 = (n632 & n748) | (n748 & n865) | (n632 & n865);
n898 = (n648 ^ n764) ^ n883;
n899 = (n648 & n764) | (n764 & n883) | (n648 & n883);
n914 = (n664 ^ n782) ^ n899;
n915 = (n664 & n782) | (n782 & n899) | (n664 & n899);
n932 = (n682 ^ n798) ^ n915;
n933 = (n682 & n798) | (n798 & n915) | (n682 & n915);
n948 = (n683 ^ n814) ^ n933;
n949 = (n683 & n814) | (n814 & n933) | (n683 & n933);
n964 = n949;
n982 = n2 & n24;
n998 = n4 & n24;
n1014 = n6 & n24;
n1032 = n8 & n24;
n1048 = n10 & n24;
n1064 = n12 & n24;
n1082 = n14 & n24;
n1099 = n881 & n964;
n1114 = (n137 ^ n982) ^ n1099;
n1132 = n882 ^ n998;
n1133 = n882 & n998;
n1148 = (n898 ^ n1014) ^ n1133;
n1149 = (n898 & n1014) | (n1014 & n1133) | (n898 & n1133);
n1164 = (n914 ^ n1032) ^ n1149;
n1165 = (n914 & n1032) | (n1032 & n1149) | (n914 & n1149);
n1182 = (n932 ^ n1048) ^ n1165;
n1183 = (n932 & n1048) | (n1048 & n1165) | (n932 & n1165);
n1198 = (n948 ^ n1064) ^ n1183;
n1199 = (n948 & n1064) | (n1064 & n1183) | (n948 & n1183);
n1214 = (n949 ^ n1082) ^ n1199;
n1215 = (n949 & n1082) | (n1082 & n1199) | (n949 & n1199);
n1232 = n0 & n26;
n1248 = n2 & n26;
n1264 = n4 & n26;
n1282 = n6 & n26;
n1298 = n8 & n26;
n1314 = n10 & n26;
n1332 = n12 & n26;
n1348 = n14 & n26;
n1364 = n1114 ^ n1232;
n1365 = n1114 & n1232;
n1382 = (n1132 ^ n1248) ^ n1365;
n1383 = (n1132 & n1248) | (n1248 & n1365) | (n1132 & n1365);
n1398 = (n1148 ^ n1264) ^ n1383;
n1399 = (n1148 & n1264) | (n1264 & n1383) | (n1148 & n1383);
n1414 = (n1164 ^ n1282) ^ n1399;
n1415 = (n1164 & n1282) | (n1282 & n1399) | (n1164 & n1399);
n1432 = (n1182 ^ n1298) ^ n1415;
n1433 = (n1182 & n1298) | (n1298 & n1415) | (n1182 & n1415);
n1448 = (n1198 ^ n1314) ^ n1433;
n1449 = (n1198 & n1314) | (n1314 & n1433) | (n1198 & n1433);
n1464 = (n1214 ^ n1332) ^ n1449;
n1465 = (n1214 & n1332) | (n1332 & n1449) | (n1214 & n1449);
n1482 = (n1215 ^ n1348) ^ n1465;
n1483 = (n1215 & n1348) | (n1348 & n1465) | (n1215 & n1465);
n1498 = n0 & n28;
n1514 = n2 & n28;
n1532 = n4 & n28;
n1548 = n6 & n28;
n1564 = n8 & n28;
n1582 = n10 & n28;
n1598 = n12 & n28;
n1614 = n14 & n28;
n1632 = n1382 ^ n1498;
n1633 = n1382 & n1498;
n1648 = (n1398 ^ n1514) ^ n1633;
n1649 = (n1398 & n1514) | (n1514 & n1633) | (n1398 & n1633);
n1664 = (n1414 ^ n1532) ^ n1649;
n1665 = (n1414 & n1532) | (n1532 & n1649) | (n1414 & n1649);
n1682 = (n1432 ^ n1548) ^ n1665;
n1683 = (n1432 & n1548) | (n1548 & n1665) | (n1432 & n1665);
n1698 = (n1448 ^ n1564) ^ n1683;
n1699 = (n1448 & n1564) | (n1564 & n1683) | (n1448 & n1683);
n1714 = (n1464 ^ n1582) ^ n1699;
n1715 = (n1464 & n1582) | (n1582 & n1699) | (n1464 & n1699);
n1732 = (n1482 ^ n1598) ^ n1715;
n1733 = (n1482 & n1598) | (n1598 & n1715) | (n1482 & n1715);
n1748 = (n1483 ^ n1614) ^ n1733;
n1749 = (n1483 & n1614) | (n1614 & n1733) | (n1483 & n1733);
n1764 = n0 & n30;
n1782 = n2 & n30;
n1798 = n4 & n30;
n1814 = n6 & n30;
n1832 = n8 & n30;
n1848 = n10 & n30;
n1864 = n12 & n30;
n1882 = n14 & n30;
n1898 = n1648 ^ n1764;
n1899 = n1648 & n1764;
n1914 = (n1664 ^ n1782) ^ n1899;
n1915 = (n1664 & n1782) | (n1782 & n1899) | (n1664 & n1899);
n1932 = (n1682 ^ n1798) ^ n1915;
n1933 = (n1682 & n1798) | (n1798 & n1915) | (n1682 & n1915);
n1948 = (n1698 ^ n1814) ^ n1933;
n1949 = (n1698 & n1814) | (n1814 & n1933) | (n1698 & n1933);
n1964 = (n1714 ^ n1832) ^ n1949;
n1965 = (n1714 & n1832) | (n1832 & n1949) | (n1714 & n1949);
n1982 = (n1732 ^ n1848) ^ n1965;
n1983 = (n1732 & n1848) | (n1848 & n1965) | (n1732 & n1965);
n1998 = (n1748 ^ n1864) ^ n1983;
n1999 = (n1748 & n1864) | (n1864 & n1983) | (n1748 & n1983);
n2014 = (n1749 ^ n1882) ^ n1999;
n2015 = (n1749 & n1882) | (n1882 & n1999) | (n1749 & n1999);
c |= (n633 & 0x1) << 0;
c |= (n182 & 0x1) << 1;
c |= (n83 & 0x1) << 2;
c |= (n832 & 0x1) << 3;
c |= (n221 & 0x1) << 4;
c |= (n1364 & 0x1) << 5;
c |= (n1632 & 0x1) << 6;
c |= (n1898 & 0x1) << 7;
c |= (n1914 & 0x1) << 8;
c |= (n1932 & 0x1) << 9;
c |= (n1948 & 0x1) << 10;
c |= (n1964 & 0x1) << 11;
c |= (n1982 & 0x1) << 12;
c |= (n1998 & 0x1) << 13;
c |= (n2014 & 0x1) << 14;
c |= (n2015 & 0x1) << 15;
return c;
}
|
the_stack_data/661590.c
|
/*#22) Se realiza una encuesta anonima sobre 50 personas, donde de cada una se conoce la edad y la cantidad
de hijos. Luego de ingresar los datos, se procesan los datos para obtener: 1. El listado de los 50 participantes,
ordenados por edad e informando edad y cantidad de hijos. Utilizar el método de insercion para realizar la
ordenacion. 2. Un listado donde se informe el promedio de hijos para cada una de las edades consideradas
(establecer como pre-condicion el rango de edades que se usara). */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 50
typedef struct {
int edad, hijos;
} tsPersona[SIZE];
void PrintAr(tsPersona n) {
int i;
for(i = 0; i < SIZE; i++) {
if( (i%5 == 0) && (i != 0))
puts("");
printf("[Edad: %2d; Hijos: %d] ", n[i].edad, n[i].hijos);
}
puts("");
}
void InitAr(tsPersona a) {
int i;
for( i = 0; i < SIZE; i++) {
a[i].edad = rand()%60+20; //edad entre 20 y 80
a[i].hijos = rand()%5; //entre 0 y 5 hijos
}
}
void InsertionSort(tsPersona v) {
int i, j, aux;
for(i=0; i < SIZE; i++) {
aux = v[i].edad;
j = i - 1;
while ((j>=0) && (v[j].edad > aux)) {
v[j+1].edad = v[j].edad;
j--;
}
v[j+1].edad = aux;
}
}
void Prom(tsPersona p) {
int i;
int s1 = 0, p1 = 0; //Entre 20 y 30
int s2 = 0, p2 = 0; //Entre 30 y 40
int s3 = 0, p3 = 0; //Entre 40 y 50
int s4 = 0, p4 = 0; //Entre 50 y 60
int s5 = 0, p5 = 0; //Entre 60 y 70
int s6 = 0, p6 = 0; //Entre 70 y 80
for(i = 0; i < SIZE; i++) {
if(p[i].edad <= 30) {
s1 += p[i].hijos;
p1++;
}
if(p[i].edad >= 30 && p[i].edad <= 40) {
s2 += p[i].hijos;
p2++;
}
if(p[i].edad >= 40 && p[i].edad <= 50) {
s3 += p[i].hijos;
p3++;
}
if(p[i].edad >= 50 && p[i].edad <= 60) {
s4 += p[i].hijos;
p4++;
}
if(p[i].edad >= 60 && p[i].edad <= 70) {
s5 += p[i].hijos;
p5++;
}
if(p[i].edad >= 70 && p[i].edad <= 80) {
s6 += p[i].hijos;
p6++;
}
}
printf("El promedio de hijos entre personas de 20 y 30 es: %0.2f\n", (float)s1/p1);
printf("El promedio de hijos entre personas de 30 y 40 es: %0.2f\n", (float)s2/p2);
printf("El promedio de hijos entre personas de 40 y 50 es: %0.2f\n", (float)s3/p3);
printf("El promedio de hijos entre personas de 50 y 60 es: %0.2f\n", (float)s4/p4);
printf("El promedio de hijos entre personas de 60 y 70 es: %0.2f\n", (float)s5/p5);
printf("El promedio de hijos entre personas de 70 y 80 es: %0.2f\n", (float)s6/p6);
}
int main() {
tsPersona arr;
InitAr(arr);
InsertionSort(arr);
PrintAr(arr);
Prom(arr);
return 0;
}
|
the_stack_data/153267826.c
|
extern void __VERIFIER_error() __attribute__ ((__noreturn__));
void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } }
#define N 50
int main( ) {
int a1[N];
int a2[N];
int a3[N];
int i;
for ( i = 0 ; i < N ; i++ ) {
a3[i] = a1[i];
}
for ( i = 0 ; i < N ; i++ ) {
a3[i] = a2[i];
}
int x;
for ( x = 0 ; x < N ; x++ ) {
__VERIFIER_assert( a1[x] == a3[x] );
}
return 0;
}
|
the_stack_data/201472.c
|
#include <stdio.h>
#define BUF_SIZE 8
int main() {
FILE *fin = fopen(__FILE__, "r");
char buf[BUF_SIZE];
while(!feof(fin))
fwrite(buf, sizeof(char),
fread(buf, sizeof(char), BUF_SIZE, fin),
stdout);
fclose(fin);
return 0;
}
|
the_stack_data/992774.c
|
#include <stdio.h>
#include <stdlib.h>
#define VERTEX_COUNT 10
#define false 0
#define true 1
// Initialize the graph
int graph[VERTEX_COUNT][VERTEX_COUNT] = {
// v0 v1 v2 v3 v4 v5 v6 v7 v8 v9
/*v0*/ {false, true, false, false, false, true, false, false, false, false},
/*v1*/ {false, false, false, false, false, false, false, true, false, false},
/*v2*/ {false, false, false, false, false, false, false, false, false, false},
/*v3*/ {false, false, true, false, true, false, false, true, true, false},
/*v4*/ {false, false, false, false, false, false, false, false, true, false},
/*v5*/ {false, false, false, false, false, false, false, false, false, false},
/*v6*/ {true, true, true, false, false, false, false, false, false, false},
/*v7*/ {false, false, false, false, false, false, false, false, false, false},
/*v8*/ {false, false, true, false, false, false, false, true, false, false},
/*v9*/ {false, false, false, false, true, false, false, false, false, false}
};
// In order to see if a value is in an array use this function
// This function takes; 1: the value that you wish to be checked, 2: The array, 3: the size of the array as input.
int isInArray(int value, int array[], int arraySize)
{
int i;
for(i = 0; i < arraySize; i++)
{
if(array[i] == value)
// If the value is within the array return 1
return 1;
}
// If it is not in the array return 0
return 0;
}
// this function takes; 1: the value that is wished to be appended, 2: the array where the values will be stored, 3: the free position index of the array(Where the value will be appended to)
int appendToArray(int value, int array[], int freePos){
array[freePos] = value;
freePos += 1;
return freePos;
}
// Sometimes the array has to be reset and if we reset it using memset() or other methods "0" will be seen in the array, to get the correct result every index has to be made -1.
// This function takes; 1: the array that will be voided, 2: the length of the array as inputs. Resets the free position by returning 0.
int nullifyArray(int array[], int arrayLength){
for(int i=0;i<arrayLength;i++){
array[i] = -1;
}
return 0;
}
// Given the graph this function will return an array with the in-degrees of every vertex
// This function takes the graph as input and returns the pointer of the in-degree array as output.
int * findIndegree(int graphArray[VERTEX_COUNT][VERTEX_COUNT]){
// Allocate memory for the array which will store the in-degree values
int * indegreeArray = malloc(sizeof(int)*VERTEX_COUNT);
// For every column
for(int i=0;i<VERTEX_COUNT;i++){
// Reset counter
int tempCounter = 0;
// Start checking the rows
for(int t=0;t<VERTEX_COUNT;t++){
// If the value at the t.nth row and i.th column is true increase counter
if(graphArray[t][i] == true){
tempCounter += 1;
}
}
// Insert value in to the array
indegreeArray[i] = tempCounter;
}
// Return the array
return indegreeArray;
};
// This function calculates the topological order from the given graph
// This function takes the graph as input and returns the pointer of the topological order array as the output.
int * findOrder(int graphArray[VERTEX_COUNT][VERTEX_COUNT]){
// Calculate in-degree of given graph
int * indegreeArray = findIndegree(graphArray);
// Allocate memory for the array where we will store the order of vertices
int * orderArray = malloc(sizeof(int)*VERTEX_COUNT);
// Initialize the temporary array and other variables
int vertexToBeAdded;
int tempArray[VERTEX_COUNT];
// In order to append to the order array and temporary array, the free position must also be known
int freePosOrderArray, freePosTempArray = 0;
// The array has to be initialized with values that are not in the graph, otherwise 0 will show up as an existing member of the array when checking
freePosOrderArray = nullifyArray(orderArray, VERTEX_COUNT);
// Start putting the vertices in order
for(int i=0;i<VERTEX_COUNT;i++){
// Reset the temporary array
freePosTempArray = nullifyArray(tempArray, VERTEX_COUNT);
// Find which vertex will be added to the temporary array next
for(int t=0;t<VERTEX_COUNT;t++){
// If this vertex is already in topological order, then skip it.
if(isInArray(t, orderArray, VERTEX_COUNT)){
continue;
}
// If the in-degree is equal to 0, add this vertex to the temporary array
if(indegreeArray[t] == 0){
freePosTempArray = appendToArray(t, tempArray, freePosTempArray);
}
};
// For every member of the temporary array
for(int l=0;l<freePosTempArray;l++){
// Append the vertex to the topological order array from the temporary array
freePosOrderArray = appendToArray(tempArray[l], orderArray, freePosOrderArray);
// Look for vertices this vertex points to and reduce their in-degree by 1
vertexToBeAdded = tempArray[l];
for(int k=0;k<VERTEX_COUNT;k++){
// If the vertex that will be removed points to another vertex
if(graphArray[vertexToBeAdded][k] == true){
// Reduce the in-degree value of that vertex
indegreeArray[k]--;
}
}
};
}
// return pointer of the order array
return orderArray;
};
int main()
{
// Initialize the pointers where the address of the outputs will be stored
int * order;
// Calculate order
order = findOrder(graph);
// Print the outputs
printf("\n");
printf("The topological order for the graph is:\n");
for(int i=0;i<10;i++){
printf("%d ",order[i]);
}
return 0;
}
|
the_stack_data/9513550.c
|
#include <string.h>
#include <stdio.h>
int main () {
int n, m, k;
int stu[12][10];
while (~scanf ("%d %d %d", &n, &m, &k)) {
int i, j, flag, flag2 = 0, flag3, flag4 = 0, sum = 0, sum2;
double average;
for (i = 0; i < n; i++) {\
for (j = 0; j < m; j++) {
scanf ("%d", &stu[i][j]);
if (j == k-1) {
sum += stu[i][j];
}
}
}
printf ("%d\n", sum/n);
for (i = 0; i < n; i++) {
sum2 = flag3 = flag = 0;
average = 0.0;
for (j = 0; j < m; j++) {
if (stu[i][j] < 60)
flag ++;
sum2 += stu[i][j];
}
if (flag >= 2) {
flag2 ++;
printf ("bad:%d", i+1);
for (j = 0; j < m; j++) {
printf (" %d", stu[i][j]);
}
printf (" %d", sum2/m);
printf ("\n");
}
}
if (flag2 == 0) {
printf ("NO\n");
}
for (i = 0; i < n; i++) {
flag3 = flag = 0;
average = 0.0;
for (j = 0; j < m; j++) {
if (stu[i][j] > 85) {
flag3 ++;
}
average += stu[i][j];
}
if (average/(double)m >= 90 || flag3 == m) {
flag4 ++;
printf ("good:%d", i+1);
for (j = 0; j < m; j++) {
printf (" %d", stu[i][j]);
}
printf ("\n");
}
}
if (flag4 == 0) {
printf ("NO\n");
}
}
return 0;
}
|
the_stack_data/148655.c
|
/* Copyright (C) 2002 Free Software Foundation, Inc. */
/* { dg-do preprocess } */
/* { dg-options "-funsigned-char -fsigned-char -traditional-cpp" } */
#if defined (__CHAR_UNSIGNED__)
# error __CHAR_UNSIGNED__ defined
#endif
|
the_stack_data/243892414.c
|
/******************************
* Tisma Miroslav 2006/0395
* Multiprocesorski sistemi
* domaci zadatak 2 - 5. zadatak
*******************************/
/*
* 5. Napisati program koji vrsi mnozenje dve dinamicki alocirane matrice elemenata tipa double. Glavna
* nit ucitava dimenzije i elemente matrica, stvara NUM_OF_THREADS niti i rasporedjuje posao ostalim
* nitima na sledeci nacin: svaka stvorena nit dobija zadatak da izracuna jedan element rezultujuce
* matrice. Kada zavrsi racunanje tekuceg elementa, stvorena nit trazi od glavne niti podatke potrebne za
* racunanje narednog elementa, sve dok ima posla. Glavna nit treba da ispise rezultujucu matricu. Pri
* resavanju pretpostaviti da je broj niti manji od broja elemenata rezultujuce matrice.
*/
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#define NUM_OF_THREADS 2 // broj niti u programu pored glavne niti
#define VALID 1
#define NOT_VALID -1
#define FINISHED 0
pthread_mutex_t mutex[NUM_OF_THREADS];
pthread_cond_t cond[NUM_OF_THREADS];
pthread_mutex_t mutexMain;
pthread_cond_t condMain;
double **matrixA;
double **matrixB;
double **matrixC;
int mA, nA, mB, nB;
typedef struct {
int row;
int col;
int valid;
} Job;
Job jobs[NUM_OF_THREADS];
double** createMatrix(int m, int n) {
double **matrix;
int i, j;
matrix = calloc(m, sizeof(double*));
for (i = 0; i < m; i++) {
matrix[i] = calloc(n, sizeof(double));
printf("Unesite %d. vrstu matrice:\n", i);
for (j = 0; j < n; j++)
scanf("%lf", &matrix[i][j]);
}
return matrix;
}
void printMatrix(double **matrix, int m, int n) {
int i, j;
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
printf("%4.2lf ", matrix[i][j]);
}
printf("\n");
}
}
void* thread(void* arg) {
int index = (int)arg;
int i;
double res = 0.0;
Job myJob;
while (1) {
pthread_mutex_lock(&mutex[index]);
while(!jobs[index].valid == VALID) // blokiramo se dok ne postavi glavna nit
pthread_cond_wait(&cond[index], &mutex[index]);
if (jobs[index].valid == NOT_VALID) // ako nema posla, iskaci iz petlje
break;
// obavestavamo glavnu nit da smo zavrsili
jobs[index].valid = FINISHED;
pthread_cond_signal(&cond[index]);
myJob = jobs[index];
for (i = 0; i < mA; i++)
res += matrixA[myJob.row][i]*matrixB[i][myJob.col];
matrixC[myJob.row][myJob.col] = res;
pthread_mutex_unlock(&mutex[index]);
}
pthread_exit(NULL);
return 0;
}
int main(int argc, char* argv[]) {
int i, j, rc, job_counter = 0;
pthread_t threads[NUM_OF_THREADS];
pthread_attr_t attribute;
printf("Unesite broj vrsta i kolona prve matrice:\n");
scanf("%d %d", &mA, &nA);
printf("Unesite broj vrsta i kolona druge matrice:\n");
scanf("%d %d", &mB, &nB);
if (mA != mB || mA < 1 || mB < 1) {
printf("Greska pri unosu velicine matrica!\n");
exit(EXIT_FAILURE);
}
matrixA = createMatrix(mA, nA);
printf("MATRICA A:\n\n");
printMatrix(matrixA, mA, nA);
printf("\n");
matrixB = createMatrix(mB, nB);
printf("\n\nMATRICA B:\n\n");
printMatrix(matrixB, mB, nB);
printf("\n");
matrixC = calloc(mA, sizeof(double*));
for (i = 0; i < mA; i++)
matrixC[i] = calloc(nB, sizeof(double));
for (i = 0; i < NUM_OF_THREADS; i++) {
pthread_mutex_init(&mutex[i], NULL);
pthread_cond_init(&cond[i], NULL);
}
pthread_attr_init(&attribute);
pthread_attr_setdetachstate(&attribute, PTHREAD_CREATE_JOINABLE);
for (i = 0; i < NUM_OF_THREADS; i++) {
rc = pthread_create(&threads[i], &attribute, thread, (void*)i);
if (rc) {
printf("GRESKA! Povratni kod iz pthread_create() je: %d", rc);
exit(EXIT_FAILURE);
}
}
job_counter = 0;
for (i = 0; i < mA; i++) {
for (j = 0; j < nB; j++) {
pthread_mutex_lock(&mutex[job_counter]);
jobs[job_counter].row = i; // postavi indeks vrste
jobs[job_counter].col = j; // postavi indeks kolone
jobs[job_counter].valid = VALID; // oznaci da je validno i javi blokiranoj niti
pthread_cond_signal(&cond[job_counter]);
pthread_cond_wait(&cond[job_counter], &mutex[job_counter]); // blokiraj se dok ne zavrsi
pthread_mutex_unlock(&mutex[job_counter]);
job_counter = (job_counter + 1) % NUM_OF_THREADS;
}
}
// obavesti sve da nema vise posla
for (i = 0; i < NUM_OF_THREADS; i++) {
pthread_mutex_lock(&mutex[i]);
jobs[i].row = NOT_VALID;
jobs[i].col = NOT_VALID;
jobs[i].valid = NOT_VALID;
pthread_cond_signal(&cond[i]);
pthread_mutex_unlock(&mutex[i]);
}
printf("\n\nMATRICA C:\n\n");
printMatrix(matrixC, mA, nB);
pthread_attr_destroy(&attribute);
for (i = 0; i < NUM_OF_THREADS; i++) {
pthread_mutex_destroy(&mutex[i]);
pthread_cond_destroy(&cond[i]);
}
pthread_mutex_destroy(&mutexMain);
pthread_cond_destroy(&condMain);
for (i = 0; i < mA; i++) {
free(matrixA[i]);
free(matrixC[i]);
}
free(matrixA);
free(matrixC);
for(i = 0; i < mB; i++)
free(matrixB[i]);
free(matrixB);
return EXIT_SUCCESS;
}
|
the_stack_data/79666.c
|
/* Copyright 1991 Digital Equipment Corporation.
** Distributed only by permission.
**
** Last modified on Wed Mar 2 11:32:59 MET 1994 by rmeyer
** modified on Fri Jan 28 14:24:13 MET 1994 by dumant
** modified on Thu Jun 24 06:55:40 1993 by Rmeyer
** modified on Thu Nov 26 20:13:50 1992 by herve
*****************************************************************/
/* $Id: xpred.c,v 1.4 1997/07/18 14:50:52 duchier Exp $ */
#ifndef lint
static char vcid[] = "$Id: xpred.c,v 1.4 1997/07/18 14:50:52 duchier Exp $";
#endif /* lint */
#ifdef X11
// Added next define due to error
#define __alpha 1
#ifdef REV401PLUS
#include "defs.h"
#endif
#ifdef REV102
#include <stdio.h>
#include <ctype.h>
#include <malloc.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/ioctl.h>
/* circumvent brain dead X11 includes and defines */
#include <string.h>
#ifndef NEEDXLIBINT
#include <X11/Xlib.h>
#else
#include <X11/Xlibint.h>
#endif
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include "extern.h"
#include "token.h"
#include "print.h"
#include "built_ins.h"
#include "types.h"
#include "trees.h"
#include "lefun.h"
#include "login.h"
#include "error.h"
#include "memory.h"
#include "templates.h"
#include "modules.h"
#include "xpred.h"
#include "xdisplaylist.h"
#include "life_icon"
/*****************************************/
/*****************************************/
#endif
#define stdin_fileno fileno(stdin)
#define CR 0x0d
#define BS 0x08
/* a closure for enum xevents_list */
typedef struct wl_EventClosure
{
Display *display;
Window window;
long mask;
ptr_psi_term beginSpan;
} EventClosure;
ptr_definition xevent,xkeyboard_event,xbutton_event,/* RM: 7/12/92 */
xexpose_event,xdestroy_event,xmotion_event,
xenter_event,xleave_event,xmisc_event,/* RM: 3rd May 93 */
xdisplay,xdrawable,xwindow,xpixmap,xconfigure_event,
xgc,xdisplaylist;
ptr_psi_term xevent_existing = NULL;
ptr_psi_term xevent_list = NULL;
long x_window_creation = FALSE;
/*****************************************/
static long xevent_mask[] = {
0, /* ??? 0 */
0, /* ??? 1 */
KeyPressMask, /* KeyPress 2 */
KeyReleaseMask, /* KeyRelease 3 */
ButtonPressMask, /* ButtonPress 4 */
ButtonReleaseMask, /* ButtonRelease 5 */
PointerMotionMask | PointerMotionHintMask | ButtonMotionMask |
Button1MotionMask | Button2MotionMask | Button3MotionMask |
Button4MotionMask | Button5MotionMask,
/* MotionNotify 6 */
EnterWindowMask, /* EnterNotify 7 */
LeaveWindowMask, /* LeaveNotify 8 */
FocusChangeMask, /* FocusIn 9 */
FocusChangeMask, /* FocusOut 10 */
KeymapStateMask, /* KeymapNotify 11 */
ExposureMask, /* Expose 12 */
0, /* GraphicsExpose 13 */
0, /* NoExpose 14 */
VisibilityChangeMask, /* VisibilityNotify 15 */
SubstructureNotifyMask, /* CreateNotify 16 */
SubstructureNotifyMask, /* DestroyNotify 17 */
StructureNotifyMask, /* UnmapNotify 18 */
StructureNotifyMask, /* MapNotify 19 */
SubstructureRedirectMask, /* MapRequest 20 */
SubstructureNotifyMask, /* ReparentNotify 21 */
StructureNotifyMask, /* ConfigureNotify 22 */
SubstructureRedirectMask, /* ConfigureRequest 23 */
StructureNotifyMask, /* GravityNotify 24 */
ResizeRedirectMask, /* ResizeRequest 25 */
StructureNotifyMask, /* CirculateNotify 26 */
SubstructureRedirectMask, /* CirculateRequest 27 */
PropertyChangeMask, /* PropertyNotify 28 */
0, /* SelectionClear 29 */
0, /* SelectionRequest 30 */
0, /* SelectionNotify 31 */
ColormapChangeMask, /* ColormapNotify 32 */
0, /* ClientMessage 33 */
0 /* MappingNotify 34 */
};
static char* xevent_name[] = {
"???",
"???",
"KeyPress",
"KeyRelease",
"ButtonPress",
"ButtonRelease",
"MotionNotify",
"EnterNotify",
"LeaveNotify",
"FocusIn",
"FocusOut",
"KeymapNotify",
"Expose",
"GraphicsExpose",
"NoExpose",
"VisibilityNotify",
"CreateNotify",
"DestroyNotify",
"UnmapNotify",
"MapNotify",
"MapRequest",
"ReparentNotify",
"ConfigureNotify",
"ConfigureRequest",
"GravityNotify",
"ResizeRequest",
"CirculateNotify",
"CirculateRequest",
"PropertyNotify",
"SelectionClear",
"SelectionRequest",
"SelectionNotify",
"ColormapNotify",
"ClientMessage",
"MappingNotify"
};
/*****************************************************************/
/* Macros */
#define DrawableGC(w)(GC)GetIntAttr(GetPsiAttr(w,"graphic_context"),"id")
#define WindowDisplayList(w) GetIntAttr(GetPsiAttr(w,"display_list"),"id")
/* Macros to keep GCC happy. RM: Feb 9 1994 */
#define DISP(X)(Display *)val[X]
#define DRAW(X)(Drawable)val[X]
#define WIND(X)(Window)val[X]
#define GCVAL(X)(GC)val[X]
#define FONT(X)(Font)val[X]
#define CMAP(X)(Colormap)val[X]
#define STRG(X)(char *)val[X]
/*****************************************************************/
/* Static */
/* handle the errors X */
static int x_handle_error(display,x_error)
Display *display;
XErrorEvent *x_error;
{
char msg[128];
XGetErrorText(display,x_error->error_code,msg,128);
Errorline("X error message: %s.\n",msg);
/* don't use abort_life(TRUE) because it tries to destroy windows ...
and loops because the window is yet in the stack !!
jch - Fri Aug 7 17:58:27 MET DST 1992
*/
exit_life(TRUE);
}
static int x_handle_fatal_error(display)
Display *display;
{
Errorline("fatal X Error.\n");
exit_life(TRUE);
}
/* RM: Jun 24 1993 */
/* JCH didn't understand ANYTHING about trailing! */
void bk_stack_add_int_attr(t,attrname,value)
ptr_psi_term t;
char *attrname;
long value;
{
ptr_psi_term t1;
ptr_node n;
char *perm;
perm=heap_copy_string(attrname);
n=find(FEATCMP,perm,t->attr_list);
if(n) {
t1=(ptr_psi_term)n->data;
deref_ptr(t1);
if(!t1->value_3) {
push_ptr_value(int_ptr,&(t1->value_3));
t1->value_3=heap_alloc(sizeof(REAL));
}
*(REAL *)t1->value_3 =(REAL) value;
}
else {
t1=stack_psi_term(4);
t1->type=integer;
t1->value_3=heap_alloc(sizeof(REAL));
*(REAL *)t1->value_3 =(REAL) value;
bk_stack_insert(FEATCMP,perm,&(t->attr_list),(GENERIC)t1);
}
}
void bk_change_psi_attr(t,attrname,value)
ptr_psi_term t;
char *attrname;
ptr_psi_term value;
{
ptr_psi_term t1;
ptr_node n;
char *perm;
perm=heap_copy_string(attrname);
n=find(FEATCMP,perm,t->attr_list);
if(n) {
t1=(ptr_psi_term)n->data;
deref_ptr(t1);
*t1= *value;
/*push_ptr_value(psi_term_ptr,&(t1->coref));*/
if(value!=t1)
value->coref=t1;
}
else
bk_stack_insert(FEATCMP,perm,&(t->attr_list),(GENERIC)value); // REV401PLUS cast
}
/*****************************************************************/
/* Utility */
/* unify psi_term T to the integer value V */
/* could be in builtins.c */
long unify_int_result(t,v)
ptr_psi_term t;
long v;
{
long smaller;
long success=TRUE;
deref_ptr(t);
push_ptr_value(int_ptr,&(t->value_3));
t->value_3 = heap_alloc(sizeof(REAL));
*(REAL *) t->value_3 = v;
matches(t->type,integer,&smaller);
if(!smaller)
{
push_ptr_value(def_ptr,(GENERIC *)&(t->type));
t->type = integer;
t->status = 0;
}
else
success = FALSE;
if(success)
{
i_check_out(t);
if(t->resid)
release_resid(t);
}
return success;
}
/*****************************************************************/
/* Static */
/* build a psi-term of type t with a feature f of value v */
static ptr_psi_term NewPsi(t,f,v)
ptr_definition t;
char * f;
long v;
{
ptr_psi_term p;
p = stack_psi_term(4);
p->type = t;
bk_stack_add_int_attr(p,f,v);
return p;
}
/*****************************************************************/
/* Utilities */
/* return the value of the attribute attributeName on the psi-term psiTerm */
long GetIntAttr(psiTerm,attributeName)
ptr_psi_term psiTerm;
char *attributeName;
{
ptr_node nodeAttr;
ptr_psi_term psiValue;
deref_ptr(psiTerm);
nodeAttr=find(FEATCMP,attributeName,psiTerm->attr_list);
if(!nodeAttr) {
Errorline("in GetIntAttr: didn't find %s on %P\n",
attributeName,
psiTerm);
exit_life(TRUE);
}
psiValue=(ptr_psi_term)nodeAttr->data;
deref_ptr(psiValue);
if(psiValue->value_3)
return *(REAL *) psiValue->value_3;
else {
/* Errorline("in GetIntAttr: no value!\n"); */
return -34466; /* Real nasty hack for now RM: Apr 23 1993 */
}
}
/*****************************************************************/
/* Utilities */
/* return the psi-term of the attribute attributeName on the psi-term psiTerm */
ptr_psi_term GetPsiAttr(psiTerm,attributeName)
ptr_psi_term psiTerm;
char *attributeName;
{
ptr_node nodeAttr;
ptr_psi_term psiValue;
if((nodeAttr = find(FEATCMP,attributeName,psiTerm->attr_list)) == NULL)
{
Errorline("in GetPsiAttr: no attribute name on psi-term ?\n");
exit_life(TRUE);
}
if((psiValue =(ptr_psi_term) nodeAttr->data) == NULL)
{
Errorline("in GetPsiAttr: no value on psi-term ?\n");
exit_life(TRUE);
}
return psiValue;
}
/*****************************************************************/
/* Static */
/* resize the pixmap of the window */
static void ResizePixmap(psi_window,display,window,width,height)
ptr_psi_term psi_window;
Display *display;
Window window;
unsigned long width,height;
{
Pixmap pixmap;
GC pixmapGC;
ptr_psi_term psiPixmap,psiPixmapGC;
XGCValues gcvalues;
XWindowAttributes attr;
ptr_psi_term psi_gc;
/* free the old pixmap */
psiPixmap = GetPsiAttr(psi_window,"pixmap");
psiPixmapGC=NULL;
if((pixmap = GetIntAttr(psiPixmap,"id")) != 0)
{
/* change the pixmap */
XFreePixmap(display,pixmap);
/* change the pixmap'gc too,because the gc is created on the pixmap ! */
psiPixmapGC = GetPsiAttr(psiPixmap,"graphic_context");
/* RM: Jun 24 1993 */
pixmapGC=(GC)GetIntAttr(psiPixmapGC,"id");
if(pixmapGC)
XFreeGC(display,pixmapGC);
bk_stack_add_int_attr(psiPixmap,"id",(long)NULL); // REV401PLUS cast
bk_stack_add_int_attr(psiPixmapGC,"id",(long)NULL); // REV401PLUS cast
}
/* init a new pixmap on the window */
XGetWindowAttributes(display,window,&attr);
if((pixmap = XCreatePixmap(display,window,
attr.width+1,attr.height+1,
attr.depth)) != 0)
{
bk_stack_add_int_attr(psiPixmap,"id",pixmap);
gcvalues.cap_style = CapRound;
gcvalues.join_style = JoinRound;
pixmapGC = XCreateGC(display,pixmap,
GCJoinStyle|GCCapStyle,&gcvalues);
/* RM: Jun 24 1993 */
if(psiPixmapGC)
bk_stack_add_int_attr(psiPixmapGC,"id",(long)pixmapGC);
else
psiPixmapGC=NewPsi(xgc,"id",pixmapGC);
bk_change_psi_attr(psiPixmap,"graphic_context",psiPixmapGC);
}
}
/*****************************************************************/
/* Static */
/* free all attributes of a window,that is: its display list,its gc,
its pixmap ... */
static void FreeWindow(display,psi_window)
Display *display;
ptr_psi_term psi_window;
{
ptr_psi_term psiPixmap;
XFreeGC(display,DrawableGC(psi_window));
x_free_display_list((ListHeader *)WindowDisplayList(psi_window)); // REV401PLUS cast
psiPixmap = GetPsiAttr(psi_window,"pixmap");
XFreeGC(display,DrawableGC(psiPixmap));
XFreePixmap(display,GetIntAttr(psiPixmap,"id"));
}
/*****************************************************************/
/******** xcOpenConnection
xcOpenConnection(+Name,-Connection)
open a connection to the X server.
*/
long xcOpenConnection()
{
include_var_builtin(2);
ptr_definition types[2];
char *display;
Display * connection;
ptr_psi_term psiConnection;
types[0] = quoted_string;
types[1] = xdisplay;
begin_builtin(xcOpenConnection,2,1,types);
if(strcmp(STRG(0),""))
display =STRG(0);
else
display = NULL;
if(connection = XOpenDisplay(display))
{
psiConnection = NewPsi(xdisplay,"id",connection);
push_goal(unify,psiConnection,args[1],NULL);
success = TRUE;
}
else
{
Errorline("could not open connection in %P.\n",g);
success = FALSE;
}
end_builtin();
}
/*****************************************************************/
/******** xcDefaultRootWindow
xcDefaultRootWindow(+Display,-Root)
return the root window of the given display
*/
long xcDefaultRootWindow()
{
include_var_builtin(2);
ptr_definition types[2];
Display *display;
ptr_psi_term psiRoot;
types[0] = real;
types[1] = xdrawable;
begin_builtin(xcDefaultRootWindow,2,1,types);
display = DISP(0);
psiRoot = NewPsi(xwindow,"id",DefaultRootWindow(display));
push_goal(unify,psiRoot,args[1],NULL);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** static GetConnectionAttribute */
static long GetConnectionAttribute(display,attributeId,attribute)
Display *display;
long attributeId,*attribute;
{
switch(attributeId)
{
case 0:
*attribute =(unsigned long) ConnectionNumber(display);
break;
case 1:
#ifndef __alpha
*attribute =(unsigned long)(display->proto_major_version);
#endif
break;
case 2:
#ifndef __alpha
*attribute =(unsigned long)(display->proto_minor_version);
#endif
break;
case 3:
*attribute =(unsigned long) ServerVendor(display);
break;
case 4:
*attribute =(unsigned long) ImageByteOrder(display);
break;
case 5:
*attribute =(unsigned long) BitmapUnit(display);
break;
case 6:
*attribute =(unsigned long) BitmapPad(display);
break;
case 7:
*attribute =(unsigned long) BitmapBitOrder(display);
break;
case 8:
*attribute =(unsigned long) VendorRelease(display);
break;
case 9:
#ifndef __alpha
*attribute =(unsigned long)(display->qlen);
#endif
break;
case 10:
*attribute =(unsigned long) LastKnownRequestProcessed(display);
break;
case 11:
#ifndef __alpha
*attribute =(unsigned long)(display->request);
#endif
break;
case 12:
*attribute =(unsigned long) DisplayString(display);
break;
case 13:
*attribute =(unsigned long) DefaultScreen(display);
break;
case 14:
#ifndef __alpha
*attribute =(unsigned long)(display->min_keycode);
#endif
break;
case 15:
#ifndef __alpha
*attribute =(unsigned long)(display->max_keycode);
#endif
break;
default:
return FALSE;
break;
}
return TRUE;
}
long xcQueryTextExtents(); /* RM: Apr 20 1993 */
/*****************************************************************/
/******** xcGetConnectionAttribute
xcGetConnectionAttribute(+Display,+AttributeId,-Value)
returns the value corresponding to the attribute id.
*/
long xcGetConnectionAttribute()
{
include_var_builtin(3);
ptr_definition types[3];
long attr;
types[0] = real;
types[1] = real;
types[2] = real;
begin_builtin(xcGetConnectionAttribute,3,2,types);
if(GetConnectionAttribute(DISP(0),DRAW(1),&attr))
{
unify_real_result(args[2],(REAL) attr);
success = TRUE;
}
else
{
Errorline("could not get connection attribute in %P.\n",g);
success = FALSE;
}
end_builtin();
}
/*****************************************************************/
/******** GetScreenAttribute */
static long GetScreenAttribute(display,screen,attributeId,attribute)
Display *display;
long screen,attributeId,*attribute;
{
Screen *s;
s = ScreenOfDisplay(display,screen);
switch(attributeId)
{
case 0:
*attribute =(unsigned long) DisplayOfScreen(s);
break;
case 1:
*attribute =(unsigned long) RootWindowOfScreen(s);
break;
case 2:
*attribute =(unsigned long) WidthOfScreen(s);
break;
case 3:
*attribute =(unsigned long) HeightOfScreen(s);
break;
case 4:
*attribute =(unsigned long) WidthMMOfScreen(s);
break;
case 5:
*attribute =(unsigned long) HeightMMOfScreen(s);
break;
case 6:
*attribute =(unsigned long) DefaultDepthOfScreen(s);
break;
case 7:
*attribute =(unsigned long) DefaultVisualOfScreen(s);
break;
case 8:
*attribute =(unsigned long) DefaultGCOfScreen(s);
break;
case 9:
*attribute =(unsigned long) DefaultColormapOfScreen(s);
break;
case 10:
*attribute =(unsigned long) WhitePixelOfScreen(s);
break;
case 11:
*attribute =(unsigned long) BlackPixelOfScreen(s);
break;
case 12:
*attribute =(unsigned long) MaxCmapsOfScreen(s);
break;
case 13:
*attribute =(unsigned long) MinCmapsOfScreen(s);
break;
case 14:
*attribute =(unsigned long) DoesBackingStore(s);
break;
case 15:
*attribute =(unsigned long) DoesSaveUnders(s);
break;
case 16:
*attribute =(unsigned long) EventMaskOfScreen(s);
break;
default:
return FALSE;
break;
}
return TRUE;
}
/*****************************************************************/
/******** xcGetScreenAttribute
xcGetScreenAttribute(+Display,+Screen,+AttributeId,-Value)
returns the value corresponding to the attribute id.
*/
long xcGetScreenAttribute()
{
include_var_builtin(4);
ptr_definition types[4];
long attr;
types[0] = real;
types[1] = real;
types[2] = real;
types[3] = real;
begin_builtin(xcGetScreenAttribute,4,3,types);
if(GetScreenAttribute(DISP(0),DRAW(1),val[2],&attr))
{
unify_real_result(args[3],(REAL) attr);
success = TRUE;
}
else
{
Errorline("could not get screen attribute in %P.\n",g);
success = FALSE;
}
end_builtin();
}
/*****************************************************************/
/******** xcCloseConnection
xcCloseConnection(+Connection)
Close the connection.
*/
long xcCloseConnection()
{
include_var_builtin(1);
ptr_definition types[1];
types[0] = real;
begin_builtin(xcCloseConnection,1,1,types);
XCloseDisplay(DISP(0));
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** xcCreateSimpleWindow
xcCreateSimpleWindow(+Display,+Parent,+X,+Y,+Width,+Height,
+BackGroundColor,+WindowTitle,+IconTitle,
+BorderWidth,+BorderColor,
+Permanent,+Show,-Window)
create a simple window.
*/
long xcCreateSimpleWindow()
{
include_var_builtin(14);
ptr_definition types[14];
Window window;
Pixmap life_icon;
XSizeHints hints;
XWindowChanges changes;
unsigned long changesMask;
XSetWindowAttributes attributes;
unsigned long attributesMask;
long j;
long permanent,show;
Display *display;
GC gc;
XGCValues gcvalues;
ptr_psi_term psiWindow;
for(j = 0; j < 14; j++)
types[j] = real;
types[7]= quoted_string;
types[8]= quoted_string;
types[11]= boolean;
types[12]= boolean;
begin_builtin(xcCreateSimpleWindow,14,13,types);
permanent = val[11];
show = val[12];
if(window = XCreateSimpleWindow(DISP(0),WIND(1),/* display,parent */
val[2],val[3],/* X,Y */
val[4],val[5],/* Width,Height */
val[9],val[10],/* BorderWidth,BorderColor */
val[6])) /* BackGround */
{
psiWindow = stack_psi_term(4);
psiWindow->type = xwindow;
bk_stack_add_int_attr(psiWindow,"id",window);
/* attach the icon of life */
life_icon = XCreateBitmapFromData(DISP(0),window,life_icon_bits,
life_icon_width,life_icon_height);
/* set properties */
#if 0
hints.x = val[2];
hints.y = val[3];
hints.width =val[4] ;
hints.height = val[5];
hints.flags = PPosition | PSize;
#endif
hints.flags = 0;
XSetStandardProperties(DISP(0),window,
STRG(7),STRG(8),
life_icon,arg_v,arg_c,
&hints);
#if 0
changes.x = val[2];
changes.y = val[3];
changes.width =val[4] ;
changes.height = val[5];
changesMask = CWX | CWY | CWWidth | CWHeight;
display = DISP(0);
XReconfigureWMWindow(DISP(0),window,DefaultScreen(display),
changesMask,&changes);
#endif
/* set the background color */
XSetWindowBackground(DISP(0),window,val[6]);
#if 0
/* set the geometry before to show the window */
XMoveResizeWindow(DISP(0),window,
val[2],val[3],val[4],val[5]);
#endif
/* set the back pixel in order to have the color when deiconify */
attributes.background_pixel = val[6];
attributes.backing_pixel = val[6];
attributesMask = CWBackingPixel|CWBackPixel;
XChangeWindowAttributes(DISP(0),window,
attributesMask,&attributes);
if(!permanent)
{
push_window(destroy_window,(long)DISP(0),window); // REV401PLUS cast
x_window_creation = TRUE;
}
else
if(show)
push_window(show_window,(long)DISP(0),window); // REV401PLUS cast
#if 0
/* map window is made in xCreateWindow(see xpred.lf) */
/* due to the flag overrideRedirect */
if(show)
x_show_window(DISP(0),window);
#endif
/* create a GC on the window for the next outputs */
gcvalues.cap_style = CapRound;
gcvalues.join_style = JoinRound;
gc = XCreateGC(DISP(0),window,GCJoinStyle|GCCapStyle,&gcvalues);
bk_change_psi_attr(psiWindow,"graphic_context",
NewPsi(xgc,"id",gc));
/* init a display list on the window for the refresh window */
bk_change_psi_attr(psiWindow,"display_list",
NewPsi(xdisplaylist,"id",x_display_list()));
/* init a pixmap on the window for the refresh mechanism */
bk_change_psi_attr(psiWindow,"pixmap",
NewPsi(xpixmap,"id",NULL));
ResizePixmap(psiWindow,DISP(0),window,val[4],val[5]);
push_goal(unify,psiWindow,args[13],NULL);
success = TRUE;
}
else
{
Errorline("could not create a simple window in %P.\n",g);
success = FALSE;
}
end_builtin();
}
/*****************************************************************/
#if 0
xcCreateWindow is not used anymore since we use xcCreateSimpleWindow.
I just keep this code in case - jch - Thu Aug 6 16:11:23 MET DST 1992
/******** xcCreateWindow
xcCreateWindow(+Connection,+Parent,+X,+Y,+Width,+Height,
+BorderWidth,+Depth,+Class,+Visual,
+Permanent,+Show,-Window)
create a window on the display Connection.
*/
long xcCreateWindow()
{
include_var_builtin(13);
ptr_definition types[13];
Window window;
XWindowChanges changes;
unsigned long changesMask;
XSizeHints hints;
long j,permanent,show;
GC gc;
XGCValues gcvalues;
for(j = 0; j < 13; j++)
types[j] = real;
begin_builtin(xcCreateWindow,13,12,types);
permanent = val[10];
show = val[11];
if(window = XCreateWindow(DISP(0),WIND(1),/* display,parent */
val[2],val[3],/* X,Y */
val[4],val[5],/* Width,Height */
val[6],val[7],/* BorderWidth,Depth */
val[8],val[9],/* Class,Visual */
0,(XSetWindowAttributes *) NULL))
{
unify_real_result(args[12],(REAL) window);
changes.x = val[2];
changes.y = val[3];
changes.width =val[4] ;
changes.height = val[5];
changesMask = CWX | CWY | CWWidth | CWHeight;
XConfigureWindow(DISP(0),window,changesMask,&changes);
hints.x = val[2];
hints.y = val[3];
hints.width =val[4] ;
hints.height = val[5];
hints.flags = PPosition | PSize;
XSetNormalHints(DISP(0),window,&hints);
if(!permanent)
{
push_window(destroy_window,DISP(0),window);
x_window_creation = TRUE;
}
else
if(show)
push_window(show_window,DISP(0),window);
if(show)
x_show_window(DISP(0),window);
/* create a GC on the window for the next outputs */
gcvalues.cap_style = CapRound;
gcvalues.join_style = JoinRound;
gc = XCreateGC(DISP(0),window,GCJoinStyle|GCCapStyle,&gcvalues);
bk_stack_add_int_attr(args[12],"gc",gc);
/* init a display list on the window for the refresh window */
bk_stack_add_int_attr(args[12],"display_list",NULL);
success = TRUE;
}
else
{
Errorline("could not create window in %P.\n",g);
success = FALSE;
}
end_builtin();
}
#endif
/*****************************************************************/
/******** xcSetStandardProperties
xcSetStandardProperties(+Display,+Window,+WindowTitle,+IconTitle,
+X,+Y,+Width,+Height)
*/
long xcSetStandardProperties()
{
include_var_builtin(8);
ptr_definition types[8];
long j;
XSizeHints hints;
for(j=0; j<8; j++)
types[j] = real;
types[1] = xwindow;
types[2] = quoted_string;
types[3] = quoted_string;
begin_builtin(xcSetStandardProperties,8,8,types);
hints.x = val[4];
hints.y = val[5];
hints.width = val[6] ;
hints.height = val[7];
hints.flags = PPosition | PSize;
XSetStandardProperties(DISP(0),WIND(1),
(char*)val[2],(char*)val[3],/* window title,icon title */
None, /* icon pixmap */
(char **) NULL,0, /* argv,argc */
&hints);
ResizePixmap(args[1],val[0],val[1],val[6],val[7]);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** xcGetWindowGeometry
xcGetWindowGeometry(+Display,+Window,-X,-Y,-Width,-Height)
returns the geometry of the window.
*/
long xcGetWindowGeometry()
{
include_var_builtin(6);
ptr_definition types[6];
int j,x,y;
unsigned int w,h,bw,d;
Window r;
for(j=0; j<6; j++)
types[j] = real;
types[1] = xdrawable;
begin_builtin(xcGetWindowGeometry,6,2,types);
if(XGetGeometry(DISP(0),DRAW(1),
&r,&x,&y,&w,&h,&bw,&d))
{
unify_real_result(args[2],(REAL) x);
unify_real_result(args[3],(REAL) y);
unify_real_result(args[4],(REAL) w);
unify_real_result(args[5],(REAL) h);
success = TRUE;
}
else
{
Errorline("could not get the geometry in %P.\n",g);
success = FALSE;
}
end_builtin();
}
/*****************************************************************/
/******** GetWindowAttribute */
static long GetWindowAttribute(display,window,attributeId,attribute)
Display *display; long window,attributeId,*attribute;
{
XWindowAttributes windowAttributes;
XGetWindowAttributes(display,window,&windowAttributes);
switch(attributeId)
{
case 0:
*attribute = windowAttributes.x;
break;
case 1:
*attribute = windowAttributes.y;
break;
case 2:
*attribute = windowAttributes.width;
break;
case 3:
*attribute = windowAttributes.height;
break;
case 4:
*attribute = windowAttributes.border_width;
break;
case 5:
*attribute = windowAttributes.depth;
break;
case 6:
*attribute = windowAttributes.root;
break;
case 7:
*attribute =(unsigned long)windowAttributes.screen;
break;
case 8:
*attribute =(unsigned long)windowAttributes.visual;
break;
case 9:
*attribute = windowAttributes.class;
break;
case 10:
*attribute = windowAttributes.all_event_masks;
break;
case 11:
*attribute = windowAttributes.bit_gravity;
break;
case 12:
*attribute = windowAttributes.win_gravity;
break;
case 13:
*attribute = windowAttributes.backing_store;
break;
case 14:
*attribute = windowAttributes.backing_planes;
break;
case 15:
*attribute = windowAttributes.backing_pixel;
break;
case 16:
*attribute = windowAttributes.override_redirect;
break;
case 17:
*attribute = windowAttributes.save_under;
break;
case 18:
*attribute = windowAttributes.your_event_mask;
break;
case 19:
*attribute = windowAttributes.do_not_propagate_mask;
break;
case 20:
*attribute = windowAttributes.colormap;
break;
case 21:
*attribute = windowAttributes.map_installed;
break;
case 22:
*attribute = windowAttributes.map_state;
break;
default:
return FALSE;
break;
}
return TRUE;
}
/*****************************************************************/
/******** xcGetWindowAttribute
xcGetWindowAttribute(+Display,+Window,+AttributeId,-Value)
returns the value corresponding to the attribute id of the window.
*/
long xcGetWindowAttribute()
{
include_var_builtin(4);
ptr_definition types[4];
long attr;
types[0] = real;
types[1] = xwindow;
types[2] = real;
types[3] = real;
begin_builtin(xcGetWindowAttribute,4,3,types);
if(GetWindowAttribute(DISP(0),WIND(1),val[2],&attr))
{
unify_real_result(args[3],(REAL) attr);
success = TRUE;
}
else
{
Errorline("could not get a window attribute in %P.\n",g);
success = FALSE;
}
end_builtin();
}
/*****************************************************************/
/******** xcSetWindowGeometry
xcSetWindowGeometry(+Display,+Window,+X,+Y,+Width,+Height)
set the geometry of the window.
*/
long xcSetWindowGeometry()
{
include_var_builtin(6);
ptr_definition types[6];
long j;
for(j=0; j<6; j++)
types[j] = real;
types[1] = xdrawable;
begin_builtin(xcSetWindowGeometry,6,6,types);
XMoveResizeWindow(DISP(0),DRAW(1),
val[2],val[3],val[4],val[5]);
/* modify the pixmap */
ResizePixmap(args[1],val[0],val[1],val[4],val[5]);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** xcMoveWindow
xcMoveWindow(+Display,+Window,+X,+Y)
Move a window to a different location.
*/
long xcMoveWindow() /* RM: May 4 1993 */
{
include_var_builtin(4);
ptr_definition types[4];
long j;
for(j=0; j<4; j++)
types[j] = real;
types[1] = xdrawable;
begin_builtin(xcMoveWindow,4,4,types);
XMoveWindow(DISP(0),DRAW(1), val[2],val[3]);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** SetWindowAttribute */
static long SetWindowAttribute(psi_window,display,window,attributeId,attribute)
ptr_psi_term psi_window;
Display *display;
Drawable window;
unsigned long attributeId,attribute;
{
XSetWindowAttributes attributes;
XWindowChanges changes;
unsigned long attributesMask = 0;
unsigned long changesMask = 0;
long backgroundChange = FALSE;
long sizeChange = FALSE;
unsigned int width,height;
int x,y;
unsigned int bw,d;
Window r;
switch(attributeId)
{
case 0:
changes.x = attribute;
changesMask |= CWX;
break;
case 1:
changes.y = attribute;
changesMask |= CWY;
break;
case 2:
changes.width = attribute;
changesMask |= CWWidth;
XGetGeometry(display,window,&r,&x,&y,&width,&height,&bw,&d);
width = attribute;
sizeChange = TRUE;
break;
case 3:
changes.height = attribute;
changesMask |= CWHeight;
XGetGeometry(display,window,&r,&x,&y,&width,&height,&bw,&d);
height = attribute;
sizeChange = TRUE;
break;
case 4:
changes.border_width = attribute;
changesMask |= CWBorderWidth;
break;
case 11:
attributes.bit_gravity = attribute;
attributesMask |= CWBitGravity;
break;
case 12:
attributes.win_gravity = attribute;
attributesMask |= CWWinGravity;
break;
case 13:
attributes.backing_store = attribute;
attributesMask |= CWBackingStore;
break;
case 14:
attributes.backing_planes = attribute;
attributesMask |= CWBackingPlanes;
break;
case 15:
attributes.backing_pixel = attribute;
attributesMask |= CWBackingPixel;
break;
case 16:
attributes.override_redirect = attribute;
attributesMask |= CWOverrideRedirect;
break;
case 17:
attributes.save_under = attribute;
attributesMask |= CWSaveUnder;
break;
case 18:
attributes.event_mask = attribute;
attributesMask |= CWEventMask;
break;
case 19:
attributes.do_not_propagate_mask = attribute;
attributesMask |= CWDontPropagate;
break;
case 20:
attributes.colormap = attribute;
attributesMask |= CWColormap;
break;
case 23:
changes.sibling = attribute;
changesMask |= CWSibling;
break;
case 24:
changes.stack_mode = attribute;
changesMask |= CWStackMode;
break;
case 25:
attributes.background_pixmap = attribute;
attributesMask |= CWBackPixmap;
break;
case 26:
attributes.background_pixel = attribute;
attributesMask |= CWBackPixel;
backgroundChange = TRUE;
/* change the backing_pixel in order to fill the pixmap with */
attributes.backing_pixel = attribute;
attributesMask |= CWBackingPixel;
break;
case 27:
attributes.border_pixmap = attribute;
attributesMask |= CWBorderPixmap;
break;
case 28:
attributes.border_pixel = attribute;
attributesMask |= CWBorderPixel;
break;
case 29:
attributes.cursor = attribute;
attributesMask |= CWCursor;
break;
default:
return FALSE;
break;
}
if(changesMask)
XConfigureWindow(display,window,changesMask,&changes);
if(attributesMask)
XChangeWindowAttributes(display,window,attributesMask,&attributes);
if(backgroundChange)
XClearArea(display,window,0,0,0,0,True);
if(sizeChange)
ResizePixmap(psi_window,display,window,width,height);
return TRUE;
}
/*****************************************************************/
/******** xcSetWindowAttribute
xcSetWindowAttribute(+Display,+Window,+AttributeId,+Value)
set the value corresponding to the attribute id.
*/
long xcSetWindowAttribute()
{
include_var_builtin(4);
ptr_definition types[4];
types[0] = real;
types[1] = xwindow;
types[2] = real;
types[3] = real;
begin_builtin(xcSetWindowAttribute,4,4,types);
if(SetWindowAttribute(args[1],val[0],val[1],val[2],val[3]))
{
XSync(DISP(0),0);
success = TRUE;
}
else
{
Errorline("could not set window attribute in %P.\n",g);
success = FALSE;
}
end_builtin();
}
/*****************************************************************/
/******** xcMapWindow
xcMapWindow(+Connection,+Window)
map the Window on the display Connection.
*/
long xcMapWindow()
{
include_var_builtin(2);
ptr_definition types[2];
types[0] = real;
types[1] = real;
begin_builtin(xcMapWindow,2,2,types);
XMapWindow(DISP(0),WIND(1));
XSync(DISP(0),0);
push_window(hide_window,(long)DISP(0),val[1]);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** xcRaiseWindow
xcRaiseWindow(+Connection,+Window)
raise the Window on the display Connection.
*/
long xcRaiseWindow()
{
include_var_builtin(2);
ptr_definition types[2];
types[0] = real;
types[1] = real;
begin_builtin(xcRaiseWindow,2,2,types);
XRaiseWindow(DISP(0),WIND(1));
XSync(DISP(0),0);
push_window(hide_window,(long)DISP(0),WIND(1));
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** xcUnmapWindow
xcUnmapWindow(+Connection,+Window)
unmap the Window on the display Connection.
*/
long xcUnmapWindow()
{
include_var_builtin(2);
ptr_definition types[2];
types[0] = real;
types[1] = real;
begin_builtin(xcUnmapWindow,2,2,types);
XUnmapWindow(DISP(0),WIND(1));
XSync(DISP(0),0);
push_window(show_window,(long)DISP(0),WIND(1));
success = TRUE;
end_builtin();
}
/*** RM 8/12/92 START ***/
/*****************************************************************/
/******** xcMapSubwindows
xcMapSubwindows(+Connection,+Window)
map the sub-windows on the display Connection.
*/
long xcMapSubwindows()
{
include_var_builtin(2);
ptr_definition types[2];
types[0] = real;
types[1] = real;
begin_builtin(xcMapSubwindow,2,2,types);
XMapSubwindows(DISP(0),WIND(1));
XSync(DISP(0),0);
push_window(hide_subwindow,(long)DISP(0),WIND(1));
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** xcUnmapSubwindows
xcUnmapSubwindows(+Connection,+Window)
unmap the sub-windows on the display Connection.
*/
long xcUnmapSubwindows()
{
include_var_builtin(2);
ptr_definition types[2];
types[0] = real;
types[1] = real;
begin_builtin(xcUnmapSubwindows,2,2,types);
XUnmapSubwindows(DISP(0),WIND(1));
XSync(DISP(0),0);
push_window(show_subwindow,(long)DISP(0),WIND(1));
success = TRUE;
end_builtin();
}
/*** RM 8/12/82 END ***/
/*****************************************************************/
/******** xcClearWindow
xcClearWindow(+Connection,+Window)
clear the Window on the display Connection.
*/
long xcClearWindow()
{
include_var_builtin(2);
ptr_definition types[2];
types[0] = real;
types[1] = xwindow;
begin_builtin(xcClearWindow,2,2,types);
XClearWindow(DISP(0),WIND(1));
XSync(DISP(0),0);
x_free_display_list((ListHeader *)WindowDisplayList(args[1]));
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** xcResizeWindowPixmap
xcResizeWindowPixmap(+Display,+Window,+Width,+Height)
resize the pixmap of the window,useful when we caught the resize event
eg: the window is resized manualy.
*/
long xcResizeWindowPixmap()
{
include_var_builtin(4);
ptr_definition types[4];
long j;
for(j=0; j<4; j++)
types[j] = real;
types[1] = xdrawable;
begin_builtin(xcResizeWindowPixmap,4,4,types);
/* modify the pixmap */
ResizePixmap(args[1],val[0],val[1],val[2],val[3]);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** xcSelectInput
xcSelectInput(+Connection,+Window,+Mask)
select the desired event types
*/
long xcSelectInput()
{
include_var_builtin(3);
ptr_definition types[3];
types[0] = real;
types[1] = real;
types[2] = real;
begin_builtin(xcSelectInput,3,3,types);
XSelectInput(DISP(0),WIND(1),val[2]);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** xcRefreshWindow
xcRefreshWindow(+Connection,+Window)
refresh the window
*/
long xcRefreshWindow()
{
include_var_builtin(2);
ptr_definition types[2];
Pixmap pixmap;
ptr_psi_term psiPixmap;
types[0] = real;
types[1] = xwindow;
begin_builtin(xcRefreshWindow,2,2,types);
psiPixmap = GetPsiAttr(args[1],"pixmap");
if((pixmap =(Pixmap) GetIntAttr(psiPixmap,"id")) != 0)
x_refresh_window((Display *)val[0],val[1],pixmap,
DrawableGC(psiPixmap),
(ListHeader *) WindowDisplayList(args[1]));
else
x_refresh_window((Display *)val[0],val[1],val[1],
DrawableGC(args[1]),
(ListHeader *)WindowDisplayList(args[1]));
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** xcPostScriptWindow
xcPostScriptWindow(+Display,+Window,Filename)
output the contents of the window in Filename
*/
long xcPostScriptWindow()
{
include_var_builtin(3);
ptr_definition types[3];
types[0] = real;
types[1] = xwindow;
types[2] = quoted_string;
begin_builtin(xcPostScriptWindow,3,3,types);
success = x_postscript_window((Display *)val[0],val[1],
(ListHeader *)GetIntAttr(GetPsiAttr(args[1],"display_list"),
"id"),
(char *)val[2]);
end_builtin();
}
/*****************************************************************/
/******** xcDestroyWindow
xcDestroyWindow(+Connection,+Window)
Close and destroy the window(unbacktrable).
*/
long xcDestroyWindow()
{
include_var_builtin(2);
ptr_definition types[2];
ptr_psi_term psi;
types[0] = real;
types[1] = xwindow;
begin_builtin(xcDestroyWindow,2,2,types);
psi = GetPsiAttr(args[1],"permanent");
if(!strcmp(psi->type->keyword->symbol,"true"))
{
Errorline("cannot destroy a permanent window.\n");
exit_life(TRUE); /* was: main_loop_ok=FALSE; - jch */
success = FALSE;
}
else
{
FreeWindow(val[0],args[1]);
XDestroyWindow(DISP(0),WIND(1));
XSync(DISP(0),0);
clean_undo_window((long)DISP(0),WIND(1));
success = TRUE;
}
end_builtin();
}
/*****************************************************************/
/******** CREATEGC
xcCreateGC(+Connection,+Drawable,-GC)
create a graphic context.
*/
long xcCreateGC()
{
include_var_builtin(3);
ptr_definition types[3];
GC gc;
XGCValues GCvalues;
types[0] = real;
types[1] = xdrawable;
types[2] = real;
begin_builtin(xcCreateGC,3,2,types);
if(gc = XCreateGC(DISP(0),WIND(1),0,&GCvalues)) /* RM: Feb 7 1994 */
{
unify_real_result(args[2],(REAL)(unsigned long) gc);
success = TRUE;
}
else
{
Errorline("could not create gc in %P.\n",g);
success = FALSE;
}
end_builtin();
}
/*****************************************************************/
/******** GETGCATTRIBUTE */
static long GetGCAttribute(gc,attributeId,attribute)
GC gc;
long attributeId,*attribute;
{
#ifndef __alpha
switch(attributeId)
{
case 0:
*attribute = gc->values.function;
break;
case 1:
*attribute = gc->values.plane_mask;
break;
case 2:
*attribute = gc->values.foreground;
break;
case 3:
*attribute = gc->values.background;
break;
case 4:
*attribute = gc->values.line_width;
break;
case 5:
*attribute = gc->values.line_style;
break;
case 6:
*attribute = gc->values.cap_style;
break;
case 7:
*attribute = gc->values.join_style;
break;
case 8:
*attribute = gc->values.fill_style;
break;
case 9:
*attribute = gc->values.fill_rule;
break;
case 10:
*attribute = gc->values.tile;
break;
case 11:
*attribute = gc->values.stipple;
break;
case 12:
*attribute = gc->values.ts_x_origin;
break;
case 13:
*attribute = gc->values.ts_y_origin;
break;
case 14:
*attribute = gc->values.font;
break;
case 15:
*attribute = gc->values.subwindow_mode;
break;
case 16:
*attribute = gc->values.graphics_exposures;
break;
case 17:
*attribute = gc->values.clip_x_origin;
break;
case 18:
*attribute = gc->values.clip_y_origin;
break;
case 19:
*attribute = gc->values.clip_mask;
break;
case 20:
*attribute = gc->values.dash_offset;
break;
case 21:
*attribute =(unsigned char)(gc->values.dashes);
break;
case 22:
*attribute = gc->values.arc_mode;
break;
case 23:
*attribute = gc->rects;
break;
case 24:
*attribute = gc->dashes;
break;
default:
return FALSE;
break;
}
#endif
return TRUE;
}
/*****************************************************************/
/******** GETGCATTRIBUTE
xcGetGCAttribute(+GC,+AttributeId,-Val)
get the value of the attribute id of GC.
*/
long xcGetGCAttribute()
{
include_var_builtin(3);
ptr_definition types[3];
long attr;
types[0] = real;
types[1] = real;
types[2] = real;
begin_builtin(xcGetGCAttribute,3,2,types);
if(GetGCAttribute((long)DISP(0),GCVAL(1),&attr))
{
unify_real_result(args[2],(REAL) attr);
success = TRUE;
}
else
{
Errorline("could not get gc attribute in %P.\n",g);
success = FALSE;
}
end_builtin();
}
/*****************************************************************/
/******** SETGCATTRIBUTE */
static long SetGCAttribute(display,gc,attributeId,attribute)
Display *display;
GC gc;
long attributeId,attribute;
{
XGCValues attributes;
unsigned long attributesMask = 0;
switch(attributeId)
{
case 0:
attributes.function = attribute;
attributesMask |= GCFunction;
break;
case 1:
attributes.plane_mask = attribute;
attributesMask |= GCPlaneMask;
break;
case 2:
attributes.foreground = attribute;
attributesMask |= GCForeground;
break;
case 3:
attributes.background = attribute;
attributesMask |= GCBackground;
break;
case 4:
attributes.line_width = attribute;
attributesMask |= GCLineWidth;
break;
case 5:
attributes.line_style = attribute;
attributesMask |= GCLineStyle;
break;
case 6:
attributes.cap_style = attribute;
attributesMask |= GCCapStyle;
break;
case 7:
attributes.join_style = attribute;
attributesMask |= GCJoinStyle;
break;
case 8:
attributes.fill_style = attribute;
attributesMask |= GCFillStyle;
break;
case 9:
attributes.fill_rule = attribute;
attributesMask |= GCFillRule;
break;
case 10:
attributes.tile = attribute;
attributesMask |= GCTile;
break;
case 11:
attributes.stipple = attribute;
attributesMask |= GCStipple;
break;
case 12:
attributes.ts_x_origin = attribute;
attributesMask |= GCTileStipXOrigin;
break;
case 13:
attributes.ts_y_origin = attribute;
attributesMask |= GCTileStipYOrigin;
break;
case 14:
attributes.font = attribute;
attributesMask |= GCFont;
break;
case 15:
attributes.subwindow_mode = attribute;
attributesMask |= GCSubwindowMode;
break;
case 16:
attributes.graphics_exposures = attribute;
attributesMask |= GCGraphicsExposures;
break;
case 17:
attributes.clip_x_origin = attribute;
attributesMask |= GCClipXOrigin;
break;
case 18:
attributes.clip_y_origin = attribute;
attributesMask |= GCClipYOrigin;
break;
case 19:
attributes.clip_mask = attribute;
attributesMask |= GCClipMask;
break;
case 20:
attributes.dash_offset = attribute;
attributesMask |= GCDashOffset;
break;
case 21:
attributes.dashes =(char)(0xFF & attribute);
attributesMask |= GCDashList;
break;
case 22:
attributes.arc_mode = attribute;
attributesMask |= GCArcMode;
break;
default:
return FALSE;
break;
}
XChangeGC(display,gc,attributesMask,&attributes);
return TRUE;
}
/*****************************************************************/
/******** SETGCATTRIBUTE
xcSetGCAttribute(+Display,+GC,+AttributeId,+Val)
set the value of the attribute id of GC.
*/
long xcSetGCAttribute()
{
include_var_builtin(4);
ptr_definition types[4];
types[0] = real;
types[1] = real;
types[2] = real;
types[3] = real;
begin_builtin(xcSetGCAttribute,4,4,types);
if(SetGCAttribute((long)DISP(0),GCVAL(1),val[2],val[3]))
success = TRUE;
else
{
Errorline("could not set gc attribute in %P.\n",g);
success = FALSE;
}
end_builtin();
}
/*****************************************************************/
/******** DESTROYGC
xcDestroyGC(+Connection,+GC)
destroys a graphic context.
*/
long xcDestroyGC()
{
include_var_builtin(2);
ptr_definition types[2];
types[0] = real;
types[1] = real;
begin_builtin(xcDestroyGC,2,2,types);
XFreeGC(DISP(0),GCVAL(1));
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** REQUESTCOLOR
xcRequestColor(+Connection,+ColorMap,+Red,+Green,+Blue,-Pixel)
get the closest color to(Red,Green,Blue) in the ColorMap
*/
long xcRequestColor()
{
include_var_builtin(6);
ptr_definition types[6];
long j;
XColor color;
for(j=0; j<6; j++)
types[j] = real;
begin_builtin(xcRequestColor,6,5,types);
color.red =(val[2]) << 8;
color.green =(val[3]) << 8;
color.blue =(val[4]) << 8;
color.flags = DoRed|DoGreen|DoBlue;
if(XAllocColor(DISP(0),CMAP(1),&color))
{
unify_real_result(args[5],(REAL) color.pixel);
success = TRUE;
}
else
{
Errorline("could not request a color in %P.\n",g);
success = FALSE;
}
end_builtin();
}
/*****************************************************************/
/******** REQUESTNAMEDCOLOR
xcRequestNamedColor(+Connection,+ColorMap,+Name,-Pixel)
get the color corresponding to Name in the ColorMap
*/
long xcRequestNamedColor()
{
include_var_builtin(4);
ptr_definition types[4];
long j;
XColor cell,rgb;
types[0] = real;
types[1] = real;
types[2] = quoted_string;
types[3] = real;
begin_builtin(xcRequestNamedColor,4,3,types);
if(XAllocNamedColor(DISP(0),CMAP(1),STRG(2),&cell,&rgb))
{
unify_real_result(args[3],(REAL) cell.pixel);
success = TRUE;
}
else
{
Errorline("could not request a named color in %P.\n",g);
success = FALSE;
}
end_builtin();
}
/*****************************************************************/
/******** FREECOLOR
xcFreeColor(+Connection,+ColorMap,+Pixel)
free the color in the colormap
*/
long xcFreeColor()
{
include_var_builtin(3);
ptr_definition types[3];
long j;
unsigned long pixel;
for(j=0; j<3; j++)
types[j] = real;
begin_builtin(xcFreeColor,3,3,types);
pixel = val[2];
XFreeColors(DISP(0),CMAP(1),&pixel,1,0);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** DrawLine
xcDrawLine(+Connection,+Drawable,+X0,+Y0,+X1,+Y1,
+Function,+Color,+LineWidth)
draw a line(X0,Y0) ->(X1,Y1)
*/
long xcDrawLine()
{
include_var_builtin(9);
ptr_definition types[9];
long j;
GC gc;
for(j = 0; j < 9; j++)
types[j] = real;
types[1] = xdrawable;
begin_builtin(xcDrawLine,9,9,types);
gc = DrawableGC(args[1]);
x_set_gc((Display *)val[0],gc,val[6],val[7],val[8],xDefaultFont);
XDrawLine(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
val[2],val[3],val[4],val[5]); /* X0,Y0,X1,Y1 */
x_record_line((ListHeader *)WindowDisplayList(args[1]),DRAW_LINE,
val[2],val[3],val[4],val[5],
val[6],val[7],val[8]);
XSync(DISP(0),0);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** DrawArc
xcDrawArc(+Connection,+Drawable,+X,+Y,+Width,+Height,+StartAngle,+ArcAngle,
+Function,+Color,+LineWidth)
draw arc(see X Vol.2 page 135 for the meanings of the arguments).
*/
long xcDrawArc()
{
include_var_builtin(11);
ptr_definition types[11];
long j;
GC gc;
for(j = 0; j < 11; j++)
types[j] = real;
types[1] = xdrawable;
begin_builtin(xcDrawArc,11,11,types);
gc = DrawableGC(args[1]);
x_set_gc((Display *)val[0],gc,val[8],val[9],val[10],xDefaultFont);
XDrawArc(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
val[2],val[3],val[4],val[5], /* X,Y,Width,Height */
val[6],val[7]); /* StartAngle,ArcAngle */
x_record_arc((ListHeader *)WindowDisplayList(args[1]),DRAW_ARC,
val[2],val[3],val[4],val[5],
val[6],val[7],val[8],val[9],val[10]);
XSync(DISP(0),0);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** DrawRectangle
xcDrawRectangle(+Connection,+Drawable,+X,+Y,+Width,+Height,
+Function,+Color,+LineWidth)
draw a rectangle.
*/
long xcDrawRectangle()
{
include_var_builtin(9);
ptr_definition types[9];
long j;
GC gc;
for(j = 0; j < 9; j++)
types[j] = real;
types[1] = xdrawable;
begin_builtin(xcDrawRectangle,9,9,types);
gc = DrawableGC(args[1]);
x_set_gc((Display *)val[0],gc,val[6],val[7],val[8],xDefaultFont);
XDrawRectangle(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
val[2],val[3],val[4],val[5]); /* X,Y,Width,Height */
x_record_rectangle((ListHeader *)WindowDisplayList(args[1]),DRAW_RECTANGLE,
val[2],val[3],val[4],val[5],
val[6],val[7],val[8]);
XSync(DISP(0),0);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** FillRectangle
xcFillRectangle(+Connection,+Drawable,+X,+Y,+Width,+Height,
+Function,+Color)
fill a rectangle.
*/
long xcFillRectangle()
{
include_var_builtin(8);
ptr_definition types[8];
long j;
GC gc;
for(j = 0; j < 8; j++)
types[j] = real;
types[1] = xdrawable;
begin_builtin(xcFillRectangle,8,8,types);
gc = DrawableGC(args[1]);
x_set_gc((Display *)val[0],gc,val[6],val[7],xDefaultLineWidth,xDefaultFont);
XFillRectangle(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
val[2],val[3],val[4],val[5]); /* X,Y,Width,Height */
x_record_rectangle((ListHeader *)WindowDisplayList(args[1]),FILL_RECTANGLE,
val[2],val[3],val[4],val[5],
val[6],val[7],
xDefaultLineWidth);
XSync(DISP(0),0);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** FillArc
xcFillArc(+Connection,+Drawable,+X,+Y,+Width,+Height,+StartAngle,+ArcAngle,
+Function,+Color)
fill an arc.
*/
long xcFillArc()
{
include_var_builtin(10);
ptr_definition types[10];
long j;
GC gc;
for(j = 0; j < 10; j++)
types[j] = real;
types[1] = xdrawable;
begin_builtin(xcFillArc,10,10,types);
gc = DrawableGC(args[1]);
x_set_gc((Display *)val[0],gc,val[8],val[9],xDefaultLineWidth,xDefaultFont);
XFillArc(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
val[2],val[3],val[4],val[5], /* X,Y,Width,Height */
val[6],val[7]); /* StartAngle,ArcAngle */
x_record_arc((ListHeader *)WindowDisplayList(args[1]),FILL_ARC,
val[2],val[3],val[4],val[5],
val[6],val[7],val[8],val[9],
xDefaultLineWidth);
XSync(DISP(0),0);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** PointsAlloc
xcPointsAlloc(+NbPoints,-Points)
allocate n points
*/
long xcPointsAlloc()
{
include_var_builtin(2);
ptr_definition types[2];
long Points;
types[0] = real;
types[1] = real;
begin_builtin(xcPointsAlloc,2,1,types);
Points =(long) malloc((val [0]) * 2 * sizeof(short));
unify_real_result(args[1],(REAL) Points);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** CoordPut
xcCoordPut(+Points,+N,+Coord)
put nth coordinate in Points
*/
long xcCoordPut()
{
include_var_builtin(3);
ptr_definition types[3];
short *Points;
types[0] = real;
types[1] = real;
types[2] = real;
begin_builtin(xcCoordPut,3,3,types);
Points =(short *) val [0];
Points += val[1];
*Points = val[2];
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** PointsFree
xcPointsFree(+Points)
free points
*/
long xcPointsFree()
{
include_var_builtin(1);
ptr_definition types[1];
types[0] = real;
begin_builtin(xcPointsFree,1,1,types);
free((void *)val [0]);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** DrawPolygon
xcDrawPolygon(+Connection,+Drawable,+Points,+NbPoints,
+Function,+Color,+LineWidth)
draw a polygon.
*/
long xcDrawPolygon()
{
include_var_builtin(7);
ptr_definition types[7];
long j;
GC gc;
for(j = 0; j < 7; j++)
types[j] = real;
types[1] = xdrawable;
begin_builtin(xcDrawPolygon,7,7,types);
gc = DrawableGC(args[1]);
x_set_gc((Display *)val[0],gc,val[4],val[5],val[6],xDefaultFont);
XDrawLines(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
(XPoint *)val[2],val[3],CoordModeOrigin); /* Points,NbPoints,mode */
x_record_polygon((ListHeader *)WindowDisplayList(args[1]),DRAW_POLYGON,
(XPoint *)val[2],val[3],val[4],val[5],val[6]);
XSync(DISP(0),0);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** FillPolygon
xcFillPolygon(+Connection,+Drawable,+Points,+NbPoints,+Function,+Color)
fill a polygon.
*/
long xcFillPolygon()
{
include_var_builtin(6);
ptr_definition types[6];
long j;
GC gc;
for(j = 0; j < 6; j++)
types[j] = real;
types[1] = xdrawable;
begin_builtin(xcFillPolygon,6,6,types);
gc = DrawableGC(args[1]);
x_set_gc((Display *)val[0],gc,val[4],val[5],xDefaultLineWidth,xDefaultFont);
XFillPolygon(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
(XPoint *)val[2],val[3], /* Points,NbPoints */
Complex,CoordModeOrigin); /* shape,mode */
x_record_polygon((ListHeader *)WindowDisplayList(args[1]),FILL_POLYGON,
(XPoint *)val[2],val[3],val[4],val[5],
xDefaultLineWidth);
XSync(DISP(0),0);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** LoadFont
xcLoadFont(+Connection,+Name,-Font)
load a font.
*/
long xcLoadFont()
{
include_var_builtin(3);
ptr_definition types[3];
Font font;
types[0] = real;
types[1] = quoted_string;
types[2] = real;
begin_builtin(xcLoadFont,3,2,types);
if(font=XLoadFont(DISP(0),STRG(1)))
{
unify_real_result(args[2],(REAL) font);
XSync(DISP(0),0);
success = TRUE;
}
else
{
Errorline("could not load a font in %P.\n",g);
success = FALSE;
}
end_builtin();
}
/*****************************************************************/
/******** UnloadFont
xcUnloadFont(+Connection,+Font)
unload a font.
*/
long xcUnloadFont()
{
include_var_builtin(2);
ptr_definition types[2];
types[0] = real;
types[1] = real;
begin_builtin(xcUnloadFont,2,2,types);
XUnloadFont(DISP(0),FONT(1));
XSync(DISP(0),0);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** DrawString
xcDrawString(+Connection,+Drawable,+X,+Y,String,
+Font,+Function,+Color)
Print the string(only foreground).
*/
long xcDrawString()
{
include_var_builtin(8);
ptr_definition types[8];
long j;
GC gc;
for(j = 0; j < 8; j++)
types[j] = real;
types[1] = xdrawable;
types[4] = quoted_string;
begin_builtin(xcDrawString,8,8,types);
gc = DrawableGC(args[1]);
x_set_gc((Display *)val[0],gc,val[6],val[7],xDefaultLineWidth,val[5]);
XDrawString(DISP(0),(Window) val[1],gc, /* Display,Window,GC */
val[2],val[3],STRG(4), /* X,Y *//* String */
strlen(STRG(4))); /* Length */
x_record_string((ListHeader *)WindowDisplayList(args[1]),DRAW_STRING,
val[2],val[3], /* X,Y */
STRG(4), /* String */
val[5], /* Font */
val[6],val[7]); /* Function,Color */
XSync(DISP(0),0);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** DrawImageString
xcDrawImageString(+Connection,+Drawable,+X,+Y,String,
+Font,+Function,+Color)
Print the string(foreground+background).
*/
long xcDrawImageString()
{
include_var_builtin(8);
ptr_definition types[8];
long j;
GC gc;
for(j = 0; j < 8; j++)
types[j] = real;
types[1] = xdrawable;
types[4] = quoted_string;
begin_builtin(xcDrawImageString,8,8,types);
gc = DrawableGC(args[1]);
x_set_gc((Display *)val[0],gc,val[6],val[7],xDefaultLineWidth,val[5]);
XDrawImageString(DISP(0),WIND(1),gc, /* Display,Window,GC */
val[2],val[3], /* X,Y */
STRG(4), /* String */
strlen(STRG(4))); /* Length */
x_record_string((ListHeader *)WindowDisplayList(args[1]),DRAW_IMAGE_STRING,
val[2],val[3], /* X,Y */
STRG(4), /* String */
val[5], /* Font */
val[6],val[7]); /* Function,Color */
XSync(DISP(0),0);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** StringWidth
xcStringWidth(+Connection,+Font,+String)
returns the width in pixels of the string in the given font.
*/
long xcStringWidth()
{
include_var_builtin(3);
ptr_definition types[3];
int direction,ascent,descent;
XCharStruct overall;
types[0] = real;
types[1] = real;
types[2] = quoted_string;
begin_builtin(xcStringWidth,3,3,types);
if(XQueryTextExtents(DISP(0),FONT(1),
STRG(2),strlen(STRG(2)),/* string,nbchars */
&direction,&ascent,&descent,&overall))
{
unify_real_result(aim->bbbb_1,(REAL) overall.width);
success = TRUE;
}
else
{
Errorline("bad font in %P.\n",g);
success = FALSE;
}
end_builtin();
}
/*****************************************************************/
/******** SYNC
xcSync(+Connection,+Discard)
flush the output of the connection.
*/
long xcSync()
{
include_var_builtin(2);
ptr_definition types[2];
types[0] = real;
types[1] = real;
begin_builtin(xcSync,2,2,types);
XSync(DISP(0),val[1]);
success = TRUE;
end_builtin();
}
/*****************************************************************/
/******** EVENTtoPSITERM */
static ptr_psi_term xcEventToPsiTerm(event)
XEvent *event;
{
ptr_psi_term psiEvent,psi_str;
KeySym keysym;
char buffer[10];
char tstr[2], *str;
str=tstr;
tstr[1]=0;
// dennis_debug("hello0001");
// printf("event->type = %d\n",event->type);
psiEvent = stack_psi_term(4);
bk_stack_add_int_attr(psiEvent,"display",(long)event->xany.display);
bk_stack_add_int_attr(psiEvent,"window",(long)event->xany.window);
switch(event->type) {
case KeyPress:
case KeyRelease:
psiEvent->type = xkeyboard_event;
bk_stack_add_int_attr(psiEvent,"x",event->xkey.x);
bk_stack_add_int_attr(psiEvent,"y",event->xkey.y);
bk_stack_add_int_attr(psiEvent,"state",event->xkey.state);
buffer[0] = 0;
*str = 0;
XLookupString((XKeyEvent*)event,buffer,sizeof(buffer),&keysym,NULL);
bk_stack_add_int_attr(psiEvent,"keycode",buffer[0]);
if(keysym==XK_Return || keysym==XK_KP_Enter || keysym==XK_Linefeed)
*str = CR;
else
if(keysym == XK_BackSpace || keysym == XK_Delete)
*str = BS;
else
if(isascii(buffer[0]))
/* if(isalnum(buffer[0]) || isspace(buffer[0])) 8.10 */
*str = buffer[0];
bk_stack_add_int_attr(psiEvent,"char",*str);
break;
case ButtonPress:
case ButtonRelease:
psiEvent->type = xbutton_event;
bk_stack_add_int_attr(psiEvent,"x",event->xbutton.x);
bk_stack_add_int_attr(psiEvent,"y",event->xbutton.y);
bk_stack_add_int_attr(psiEvent,"x_root",event->xbutton.x_root);
bk_stack_add_int_attr(psiEvent,"y_root",event->xbutton.y_root);
bk_stack_add_int_attr(psiEvent,"state",event->xbutton.state);
bk_stack_add_int_attr(psiEvent,"button",event->xbutton.button);
break;
case Expose:
psiEvent->type = xexpose_event;
bk_stack_add_int_attr(psiEvent,"width",event->xexpose.width);
bk_stack_add_int_attr(psiEvent,"height",event->xexpose.height);
break;
case DestroyNotify:
psiEvent->type = xdestroy_event;
break;
/*** RM 7/12/92 ***/
case MotionNotify:
psiEvent->type = xmotion_event;
bk_stack_add_int_attr(psiEvent,"x",event->xbutton.x);
bk_stack_add_int_attr(psiEvent,"y",event->xbutton.y);
bk_stack_add_int_attr(psiEvent,"x_root",event->xbutton.x_root);
bk_stack_add_int_attr(psiEvent,"y_root",event->xbutton.y_root);
break;
case ConfigureNotify:
psiEvent->type = xconfigure_event;
bk_stack_add_int_attr(psiEvent,"x",event->xconfigure.x);
bk_stack_add_int_attr(psiEvent,"y",event->xconfigure.y);
bk_stack_add_int_attr(psiEvent,"width",event->xconfigure.width);
bk_stack_add_int_attr(psiEvent,"height",event->xconfigure.height);
bk_stack_add_int_attr(psiEvent,"border_width",
event->xconfigure.border_width);
break;
/*** RM 7/12/92(END) ***/
/*** RM: May 3rd 1993 ***/
case EnterNotify:
psiEvent->type = xenter_event;
goto LeaveEnterCommon;
case LeaveNotify:
psiEvent->type = xleave_event;
LeaveEnterCommon:
bk_stack_add_int_attr(psiEvent,"root", event->xcrossing.root);
bk_stack_add_int_attr(psiEvent,"subwindow",event->xcrossing.subwindow);
bk_stack_add_int_attr(psiEvent,"x",event->xcrossing.x);
bk_stack_add_int_attr(psiEvent,"y",event->xcrossing.y);
bk_stack_add_int_attr(psiEvent,"focus",event->xcrossing.focus);
bk_stack_add_int_attr(psiEvent,"state",event->xcrossing.state);
break;
default:
psiEvent->type = xmisc_event;
bk_stack_add_int_attr(psiEvent,"event_type",event->type);
break;
}
return psiEvent;
}
/*****************************************************************/
/* some stuff to handle a list of psi-terms */
/* RM: Dec 15 1992 Re-written to handle new list structure */
/* RM: Dec 15 1992 Test if a list is empty */
long list_is_nil(lst)
ptr_psi_term(lst);
{
deref_ptr(lst);
return lst->type==nil;
}
/* RM: Dec 15 1992 Return the CDR of a list */
ptr_psi_term list_cdr(lst)
ptr_psi_term(lst);
{
ptr_psi_term car;
ptr_psi_term cdr;
deref_ptr(lst);
if(lst->type==alist) {
get_two_args(lst->attr_list,&car,&cdr);
if(cdr) {
deref_ptr(cdr);
return cdr;
}
}
Errorline("X event handling error in CDR(%P)\n",lst);
return lst;
}
/* RM: Dec 15 1992 Return the CAR of a list */
ptr_psi_term list_car(lst)
ptr_psi_term(lst);
{
ptr_psi_term car;
ptr_psi_term cdr;
deref_ptr(lst);
if(lst->type==alist) {
get_two_args(lst->attr_list,&car,&cdr);
if(car) {
deref_ptr(car);
return car;
}
}
Errorline("X event handling error in CAR(%P)\n",lst);
return lst;
}
/* RM: Dec 15 1992 Set the CAR of a list */
void list_set_car(lst,value)
ptr_psi_term lst;
ptr_psi_term value;
{
deref_ptr(lst);
stack_insert(FEATCMP,one,&(lst->attr_list),(GENERIC)value);
}
/* RM: Dec 15 1992 Set the CDR of a list */
void list_set_cdr(lst,value)
ptr_psi_term lst;
ptr_psi_term value;
{
deref_ptr(lst);
stack_insert(FEATCMP,two,&(lst->attr_list),(GENERIC)value);
}
/* RM: Dec 15 1992 Return the last element of a list */
ptr_psi_term list_last_cdr(lst)
ptr_psi_term lst;
{
while(!list_is_nil(lst))
lst=list_cdr(lst);
return lst;
}
/* RM: Dec 15 1992 Append an element to a list,return the new CONS cell */
ptr_psi_term append_to_list(lst,value)
ptr_psi_term lst;
ptr_psi_term value;
{
ptr_psi_term end;
end=list_last_cdr(lst);
push_ptr_value_global(psi_term_ptr,(GENERIC *)&(end->coref));
end->coref=stack_cons(value,stack_nil());
return end->coref;
}
/* RM: Dec 15 1992
Map a function,while TRUE,over the CONS cells of a list */
long map_funct_over_list(lst,proc,closure)
ptr_psi_term lst;
long(*proc)();
long *closure;
{
long notInterrupted=TRUE;
while(notInterrupted && !list_is_nil(lst)) {
notInterrupted =(*proc)(lst,closure);
lst=list_cdr(lst);
}
return notInterrupted;
}
/* RM: Dec 15 1992 Same thing,except map over the CARs of the list */
long map_funct_over_cars(lst,proc,closure)
ptr_psi_term lst;
long(*proc)();
long *closure;
{
ptr_psi_term cdr;
int notInterrupted = TRUE;
while(notInterrupted && !list_is_nil(lst)) {
/* save the next because the current could be removed
(eg: xcFlushEvents) */
cdr=list_cdr(lst);
notInterrupted=(*proc)(list_car(lst),closure);
lst=cdr;
}
return notInterrupted;
}
/* RM: Dec 15 1992 Re-written for new lists */
void list_remove_value(lst,value)
ptr_psi_term lst;
ptr_psi_term value;
{
ptr_psi_term car,cdr;
long still_there=TRUE;
deref_ptr(value);
while(!list_is_nil(lst) && still_there) {
car=list_car(lst);
cdr=list_cdr(lst);
if(car==value) {
still_there=FALSE;
push_ptr_value_global(psi_term_ptr,(GENERIC *)&(lst->coref));
lst->coref=cdr;
}
lst=cdr;
}
}
/*****************************************************************/
/* Static */
/* return FALSE if the events match */
static long x_union_event(psiEvent,closure)
ptr_psi_term psiEvent;
EventClosure *closure;
{
return !((Display *)GetIntAttr(psiEvent,"display") == closure->display
&& (Window)GetIntAttr(psiEvent,"window") == closure->window
&&(GetIntAttr(psiEvent,"mask") & closure->mask) != 0);
}
/*****************************************************************/
/******** GetEvent
xcGetEvent(+Display,+Window,+Mask)
return an event matching the mask in the window.
if no event residuate the call else return a null event.
*/
long xcGetEvent()
{
include_var_builtin(3);
ptr_definition types[3];
XEvent event;
ptr_psi_term psiEvent;
ptr_psi_term eventElt;
EventClosure eventClosure;
ptr_psi_term result;
types[0] = real;
types[1] = xwindow;
types[2] = real;
result=aim->bbbb_1;
begin_builtin(xcGetEvent,3,3,types);
if(!xevent_existing) {
/* warning if a same event is already waiting */
eventClosure.display = DISP(0);
eventClosure.window =WIND(1);
eventClosure.mask = val[2];
if(!map_funct_over_cars(xevent_list,x_union_event,(long *)&eventClosure))
Warningline("you have coinciding event handlers on the same window");
/* transform the request into a psi-term */
eventElt = stack_psi_term(4);
bk_stack_add_int_attr(eventElt,"display",val[0]);
bk_stack_add_int_attr(eventElt,"window",val[1]);
bk_stack_add_int_attr(eventElt,"mask",val[2]);
/* stack_insert(FEATCMP,"event",&(eventElt->attr_list),result); */
/* add the request in the list of waiting events */
append_to_list(xevent_list,eventElt); /* RM: Dec 15 1992 */
/* residuate the call */
residuate(eventElt); /* RM: May 5 1993 */
/* return a psi-term containing an `empty' event */
/* psiEvent = stack_psi_term(4);
psiEvent->type = xevent; RM: May 5 1993 */
}
else {
/* get the event built by x_exist_event */
psiEvent = GetPsiAttr(xevent_existing,"event");
push_ptr_value_global(psi_term_ptr,(GENERIC *)&xevent_existing);
xevent_existing = NULL;
push_goal(unify,psiEvent,aim->bbbb_1,NULL); /* RM: May 5 1993 */
}
/* push_goal(unify,psiEvent,aim->b,NULL); RM: May 5 1993 */
success = TRUE;
end_builtin();
}
/*****************************************************************/
/* Static */
/* remove the event from the queue if matching */
static long x_flush_event(eventElt,closure)
ptr_psi_term eventElt;
EventClosure *closure;
{
ptr_psi_term psiEvent;
psiEvent = list_car(eventElt);
if ((Display *)GetIntAttr(psiEvent,"display") == closure->display
&& (Window)GetIntAttr(psiEvent,"window") ==closure->window
&& (GetIntAttr(psiEvent,"mask") & closure->mask) != 0)
{
/* 9.10 */
/* if(xevent_list == eventElt) */
/* push_ptr_value_global(psi_term_ptr,&xevent_list); */
/* xevent_list = list_remove_value(xevent_list,psiEvent); */
list_remove_value(xevent_list,psiEvent); /* RM: Dec 15 1992 */
}
return TRUE;
}
/*****************************************************************/
/******** FlushEvents
xcFlushEvents(+Display,+Window,+Mask)
flush all residuated events matching(display,window,mask).
*/
long xcFlushEvents()
{
include_var_builtin(3);
ptr_definition types[3];
EventClosure eventClosure;
types[0] = real;
types[1] = xwindow;
types[2] = real;
begin_builtin(xcFlushEvents,3,3,types);
eventClosure.display = DISP(0);
eventClosure.window = val[1];
eventClosure.mask = val[2];
map_funct_over_list(xevent_list,x_flush_event,(long *)&eventClosure);
success = TRUE;
end_builtin();
}
#if 0
/*****************************************************************/
/******** xcSendEvent
xcSendEvent(+Display,+Window,+Event)
send the event to the specified window
*/
long xcSendEvent()
{
include_var_builtin(3);
ptr_definition types[3];
XEvent event;
ptr_psi_term psiEvent;
ptr_node nodeAttr;
ptr_psi_term psiValue;
types[0] = real;
types[1] = xwindow;
types[2] = xevent;
begin_builtin(xcSendEvent,3,3,types);
if(xcPsiEventToEvent(val[2],&event))
{
XSendEvent((long)DISP(0),WIND(1),False,?,&event);
success = TRUE;
}
else
{
Errorline("%P is not an event in %P.\n",val[2],g);
success = FALSE;
}
end_builtin();
}
#endif
/*** RM: 7/12/92 ***/
/*****************************************************************/
/******** xcQueryPointer
xcQueryPointer(+Display,+Window,
-root_return, -child_return,
-root_x_return,-root_y_return,
-win_x_return, -win_y_return,
-mask_return, -same_screen)
this predicate returns a psi-term containing loads of info about where the
pointer is at. See 'XQueryPointer' for a complete definition(the boolean
result of XQueryPointer is stored as 'same_screen'.
*/
long xcQueryPointer()
{
include_var_builtin(10);
ptr_definition types[10];
Window root_return,child_return;
int root_x_return,root_y_return;
int win_x_return,win_y_return;
unsigned int mask_return;
long same_screen;
long j;
for(j=0; j<10; j++)
types[j] = real;
types[1] = xdrawable;
begin_builtin(xcQueryPointer,10,2,types);
same_screen=XQueryPointer(DISP(0),
WIND(1),
&root_return, &child_return,
&root_x_return,&root_y_return,
&win_x_return, &win_y_return,
&mask_return);
unify_real_result(args[2],(REAL)root_return);
unify_real_result(args[3],(REAL)child_return);
unify_real_result(args[4],(REAL)root_x_return);
unify_real_result(args[5],(REAL)root_y_return);
unify_real_result(args[6],(REAL)win_x_return);
unify_real_result(args[7],(REAL)win_y_return);
unify_real_result(args[8],(REAL)mask_return);
unify_real_result(args[9],(REAL)same_screen);
/* printf("root: %ld\nchild: %ld\n",root_return,child_return); */
success = TRUE;
end_builtin();
}
/*** RM: 7/12/92(END) ***/
/*****************************************************************/
/******** SETUPBUILTINS
Set up the X built-in predicates.
*/
void x_setup_builtins()
{
set_current_module(x_module); /* RM: Feb 3 1993 */
raw_setup_builtins(); /* to move in life.c */
XSetErrorHandler(x_handle_error);
XSetIOErrorHandler(x_handle_fatal_error);
set_current_module(x_module); /* RM: Feb 3 1993 */
xevent = update_symbol(x_module,"event");
xkeyboard_event = update_symbol(x_module,"keyboard_event");
xbutton_event = update_symbol(x_module,"button_event");
xexpose_event = update_symbol(x_module,"expose_event");
xdestroy_event = update_symbol(x_module,"destroy_event");
/*** RM: 7/12/92 ***/
xconfigure_event = update_symbol(x_module,"configure_event");
xmotion_event = update_symbol(x_module,"motion_event");
/*** RM: 7/12/92 ***/
/*** RM: 3 May 92 ***/
xenter_event = update_symbol(x_module,"enter_event");
xleave_event = update_symbol(x_module,"leave_event");
xmisc_event = update_symbol(x_module,"misc_event");
/*** RM: 3 May 92 ***/
xdisplay = update_symbol(x_module,"display");
xdrawable = update_symbol(x_module,"drawable");
xwindow = update_symbol(x_module,"window");
xpixmap = update_symbol(x_module,"pixmap");
xgc = update_symbol(x_module,"graphic_context");
xdisplaylist = update_symbol(x_module,"display_list");
new_built_in(x_module,"xcOpenConnection", (def_type)predicate_it,xcOpenConnection);
new_built_in(x_module,"xcDefaultRootWindow", (def_type)predicate_it,xcDefaultRootWindow);
new_built_in(x_module,"xcGetScreenAttribute", (def_type)predicate_it,xcGetScreenAttribute);
new_built_in(x_module,"xcGetConnectionAttribute",(def_type)predicate_it,xcGetConnectionAttribute);
new_built_in(x_module,"xcCloseConnection", (def_type)predicate_it,xcCloseConnection);
new_built_in(x_module,"xcCreateSimpleWindow", (def_type)predicate_it,xcCreateSimpleWindow);
#if 0
new_built_in(x_module,"xcCreateWindow", (def_type)predicate_it,xcCreateWindow);
#endif
new_built_in(x_module,"xcSetStandardProperties", (def_type)predicate_it,xcSetStandardProperties);
new_built_in(x_module,"xcGetWindowGeometry", (def_type)predicate_it,xcGetWindowGeometry);
new_built_in(x_module,"xcSetWindowGeometry", (def_type)predicate_it,xcSetWindowGeometry);
new_built_in(x_module,"xcGetWindowAttribute", (def_type)predicate_it,xcGetWindowAttribute);
new_built_in(x_module,"xcSetWindowAttribute", (def_type)predicate_it,xcSetWindowAttribute);
new_built_in(x_module,"xcMapWindow", (def_type)predicate_it,xcMapWindow);
/* RM: May 6 1993 */
new_built_in(x_module,"xcRaiseWindow", (def_type)predicate_it,xcRaiseWindow);
new_built_in(x_module,"xcUnmapWindow", (def_type)predicate_it,xcUnmapWindow);
/*** RM 8/12/92 ***/
new_built_in(x_module,"xcMapSubwindows", (def_type)predicate_it,xcMapSubwindows);
new_built_in(x_module,"xcUnmapSubwindows", (def_type)predicate_it,xcUnmapSubwindows);
/*** RM 8/12/92 ***/
new_built_in(x_module,"xcClearWindow", (def_type)predicate_it,xcClearWindow);
new_built_in(x_module,"xcResizeWindowPixmap", (def_type)predicate_it,xcResizeWindowPixmap);
new_built_in(x_module,"xcSelectInput", (def_type)predicate_it,xcSelectInput);
new_built_in(x_module,"xcRefreshWindow", (def_type)predicate_it,xcRefreshWindow);
new_built_in(x_module,"xcPostScriptWindow", (def_type)predicate_it,xcPostScriptWindow);
new_built_in(x_module,"xcDestroyWindow", (def_type)predicate_it,xcDestroyWindow);
new_built_in(x_module,"xcCreateGC", (def_type)predicate_it,xcCreateGC);
new_built_in(x_module,"xcGetGCAttribute", (def_type)predicate_it,xcGetGCAttribute);
new_built_in(x_module,"xcSetGCAttribute", (def_type)predicate_it,xcSetGCAttribute);
new_built_in(x_module,"xcDestroyGC", (def_type)predicate_it,xcDestroyGC);
new_built_in(x_module,"xcDrawLine", (def_type)predicate_it,xcDrawLine);
new_built_in(x_module,"xcMoveWindow", (def_type)predicate_it,xcMoveWindow);
new_built_in(x_module,"xcDrawArc", (def_type)predicate_it,xcDrawArc);
new_built_in(x_module,"xcDrawRectangle", (def_type)predicate_it,xcDrawRectangle);
new_built_in(x_module,"xcDrawPolygon", (def_type)predicate_it,xcDrawPolygon);
new_built_in(x_module,"xcLoadFont", (def_type)predicate_it,xcLoadFont);
new_built_in(x_module,"xcUnloadFont", (def_type)predicate_it,xcUnloadFont);
new_built_in(x_module,"xcDrawString", (def_type)predicate_it,xcDrawString);
new_built_in(x_module,"xcDrawImageString", (def_type)predicate_it,xcDrawImageString);
new_built_in(x_module,"xcStringWidth", (def_type)function_it, xcStringWidth);
new_built_in(x_module,"xcRequestColor", (def_type)predicate_it,xcRequestColor);
new_built_in(x_module,"xcRequestNamedColor", (def_type)predicate_it,xcRequestNamedColor);
new_built_in(x_module,"xcFreeColor", (def_type)predicate_it,xcFreeColor);
new_built_in(x_module,"xcFillRectangle", (def_type)predicate_it,xcFillRectangle);
new_built_in(x_module,"xcFillArc", (def_type)predicate_it,xcFillArc);
new_built_in(x_module,"xcFillPolygon", (def_type)predicate_it,xcFillPolygon);
new_built_in(x_module,"xcPointsAlloc", (def_type)predicate_it,xcPointsAlloc);
new_built_in(x_module,"xcCoordPut", (def_type)predicate_it,xcCoordPut);
new_built_in(x_module,"xcPointsFree", (def_type)predicate_it,xcPointsFree);
new_built_in(x_module,"xcSync", (def_type)predicate_it,xcSync);
new_built_in(x_module,"xcGetEvent", (def_type)function_it, xcGetEvent);
new_built_in(x_module,"xcFlushEvents", (def_type)predicate_it,xcFlushEvents);
/*** RM: 7/12/92 ***/
new_built_in(x_module,"xcQueryPointer", (def_type)predicate_it,xcQueryPointer);
/*** RM: 7/12/92 ***/
/* RM: Apr 20 1993 */
new_built_in(x_module,"xcQueryTextExtents",(def_type)predicate_it,xcQueryTextExtents);
}
/*****************************************************************/
/* not a built-in */
/* called by what_next_aim in login.c */
static long WaitNextEvent(ptreventflag)
long *ptreventflag;
{
long nfds;
fd_set readfd,writefd,exceptfd;
struct timeval timeout;
long charflag = FALSE,nbchar;
char c = 0;
*ptreventflag = FALSE;
do
{
FD_ZERO(&readfd);
FD_SET(stdin_fileno, &readfd);
FD_ZERO(&writefd);
FD_ZERO(&exceptfd);
timeout.tv_sec = 0;
timeout.tv_usec = 100000;
nfds = select(32,&readfd,&writefd,&exceptfd,&timeout);
if(nfds == -1)
{
#if 0
/* not an error,but a signal has been occured */
/* handle_interrupt(); does not work */
exit();
#endif
if(errno != EINTR)
{
Errorline("in select: interruption error.\n");
exit_life(TRUE);
}
else
interrupt();
}
else
if(nfds == 0)
{
#ifdef X11
if(x_exist_event())
{
*ptreventflag = TRUE;
start_of_line = TRUE;
}
#endif
}
else
{
if(FD_ISSET(stdin_fileno, &readfd) != 0)
{
#if 0
if((nbchar = read(stdin_fileno,&c,1)) == -1)
{
Errorline("in select: keyboard error.\n");
exit_life(TRUE);
}
/* see manpage of read */
if(nbchar == 0)
c = EOF;
#endif
c = fgetc(input_stream);
charflag = TRUE;
}
else
{
Errorline("select error.\n");
exit_life(TRUE);
}
}
} while(!(charflag || *ptreventflag));
return c;
}
/*****************************************/
long x_read_stdin_or_event(ptreventflag)
long *ptreventflag;
{
long c = 0;
*ptreventflag = FALSE;
if(c = saved_char) /* not an error ;-) */
{
saved_char = old_saved_char;
old_saved_char=0;
}
else
{
if(feof(input_stream))
c = EOF;
else
{
if(start_of_line)
{
start_of_line = FALSE;
line_count ++ ;
Infoline("%s",prompt);
fflush(output_stream);
}
c = WaitNextEvent(ptreventflag);
if(*ptreventflag)
{
if(verbose) printf("<X event>");
if(NOTQUIET) printf("\n"); /* 21.1 */
}
if(c == EOLN)
start_of_line = TRUE;
}
}
return c;
}
/*****************************************************************/
/* Static */
/* returns TRUE if the mask matches the type */
static long mask_match_type(mask,type)
long mask,type;
{
long em;
/* printf("mask=%d,type=%d=%s\n",mask,type,xevent_name[type]); */
em=xevent_mask[type];
if(!em ||(em & mask))
return TRUE;
/* printf("FALSE\n"); printf("event mask=%d\n",em); */
return FALSE;
}
/*****************************************************************/
/* Static */
/* returns the psi-event of the list corresponding to the existing event */
static ptr_psi_term x_what_psi_event(beginSpan,endSpan,eventType)
ptr_psi_term beginSpan,endSpan;
long eventType;
{
if(beginSpan == endSpan)
return list_car(beginSpan);
else
if(mask_match_type(GetIntAttr(list_car(beginSpan),"mask"),
eventType))
return list_car(beginSpan);
else
return x_what_psi_event(list_cdr(beginSpan),
endSpan,eventType);
}
/*****************************************************************/
/* Static */
/* builds xevent_existing */
static void x_build_existing_event(event,beginSpan,endSpan,eventType)
XEvent *event;
ptr_psi_term beginSpan,endSpan;
long eventType;
{
ptr_psi_term psiEvent;
/* printf("building event: type=%s event=%s\n",
xevent_name[type],xevent_name[event->type]); */
/* get the event from the list */
psiEvent = x_what_psi_event(beginSpan,endSpan,eventType);
/* put the event on the waiting event */
bk_change_psi_attr(psiEvent,"event",xcEventToPsiTerm(event));
/* set the global */
if(xevent_existing)
Warningline("xevent_existing is non-null in x_build_existing_event");
push_ptr_value_global(psi_term_ptr,(GENERIC *)&xevent_existing);
xevent_existing = psiEvent;
/* remove the event from the list */
/* 9.10 */
/* if(list_car(xevent_list) == psiEvent) */
/* push_ptr_value_global(psi_term_ptr,&xevent_list); */
/* xevent_list = list_remove_value(xevent_list,psiEvent); */
list_remove_value(xevent_list,psiEvent); /* RM: Dec 15 1992 */
}
/*****************************************************************/
/* Static */
/* get the next span of waiting events */
static long x_next_event_span(eventElt,eventClosure)
ptr_psi_term eventElt;
EventClosure *eventClosure;
{
ptr_psi_term psiEvent;
Display *display;
Window window;
long mask;
XEvent event;
psiEvent = list_car(eventElt);
display =(Display *)GetIntAttr(psiEvent,"display");
window =(Window)GetIntAttr(psiEvent,"window");
mask = GetIntAttr(psiEvent,"mask");
if(eventClosure->display == NULL) {
/* new span */
eventClosure->display = display;
eventClosure->window = window;
eventClosure->mask = mask;
eventClosure->beginSpan = eventElt;
return TRUE;
}
else
if(eventClosure->display == display && eventClosure->window == window) {
/* same span */
eventClosure->mask |= mask;
return TRUE;
}
else {
/* a next span begins,check the current span */
Repeat:
if(XCheckWindowEvent(eventClosure->display,eventClosure->window,
eventClosure->mask,&event)
/* && event.xany.window == eventClosure->window */)
{
/* 9.10 */
/* printf("Event type = %ld.\n",event.type); */
if((event.type==Expose || event.type==GraphicsExpose)
&& event.xexpose.count!=0) {
/* printf("Expose count = %ld.\n", event.xexpose.count); */
goto Repeat;
}
/* build a psi-term containing the event */
/* printf("*** event %d ***\n",event.type); */
x_build_existing_event(&event,
eventClosure->beginSpan,
eventElt,event.type);
return FALSE; /* stop ! we have an existing event !! */
}
else
{
/* init the new span */
eventClosure->display = display;
eventClosure->window = window;
eventClosure->mask = mask;
eventClosure->beginSpan = eventElt;
return TRUE;
}
}
}
/*****************************************************************/
/* not a built-in */
/* used by main_prove() and what_next() */
long x_exist_event()
{
XEvent event,exposeEvent;
ptr_psi_term eventElt;
EventClosure eventClosure;
/*infoline("xevent_list=%P\n",xevent_list); */
if(xevent_existing)
return TRUE;
if(list_is_nil(xevent_list)) {
/* printf("nil event list\n"); */
return FALSE;
}
/* traverse the list of waiting events */
eventClosure.display = NULL;
if(!map_funct_over_list(xevent_list,x_next_event_span,(long *)&eventClosure))
return TRUE;
/* printf("display=%d,window=%d,mask=%d\n",
eventClosure.display,eventClosure.window,eventClosure.mask); */
/* check the last span */
if(XCheckWindowEvent(eventClosure.display,
eventClosure.window,
eventClosure.mask,
&event)) {
/* printf("*** here event %d ***\n",event.xany.type); */
if(event.xany.window==eventClosure.window) {
if(event.type == Expose)
while(XCheckWindowEvent(eventClosure.display,
eventClosure.window,
ExposureMask,
&exposeEvent))
; /* that is continue until no expose event */
/* build a psi-term containing the event */
x_build_existing_event(&event,
eventClosure.beginSpan,
list_last_cdr(xevent_list),/* RM: Dec 15 1992*/
event.type);
return TRUE;
}
}
else
return FALSE;
}
/*****************************************************************/
/* used when backtracking a created window in order to destroy the window */
void x_destroy_window(display,window)
Display *display;
Window window;
{
/* we need the psi-term window(not the value) to get the display list,the pixmap ...
jch - Fri Aug 7 15:29:14 MET DST 1992
FreeWindow(display,window);
*/
XDestroyWindow(display,window);
XSync(display,0);
}
/*****************************************************************/
/* used when backtracking a xcUnmapWindow in order to show the window */
void x_show_window(display,window)
Display *display;long window;
{
XMapWindow(display,window);
XSync(display,0);
}
/*****************************************************************/
/* used when backtracking a xcMapWindow in order to hide the window */
void x_hide_window(display,window)
Display *display; long window;
{
XUnmapWindow(display,window);
XSync(display,0);
}
/*** RM 8/12/92 ***/
/*****************************************************************/
/* used when backtracking a xcUnmapWindow in order to show the window */
void x_show_subwindow(display,window)
Display *display; long window;
{
XMapSubwindows(display,window);
XSync(display,0);
}
/*****************************************************************/
/* used when backtracking a xcMapWindow in order to hide the window */
void x_hide_subwindow(display,window)
Display *display; long window;
{
XUnmapSubwindows(display,window);
XSync(display,0);
}
/*** RM 8/12/92 ***/
/*** RM: Apr 20 1993 ***/
/*
xcQueryTextExtents(display,font,string,
direction,font-ascent,font-descent,
left-bearing,right-bearing,width,ascent,descent)
*/
long xcQueryTextExtents()
{
include_var_builtin(11);
ptr_definition types[11];
Font font;
XCharStruct over;
int i;
int direction,ascent,descent; /* RM: 28 Jan 94 */
types[0] = real; /* +Display */
types[1] = real; /* +Font ID */
types[2] = quoted_string; /* +String */
types[3] = real; /* -Direction */
types[4] = real; /* -Font-ascent */
types[5] = real; /* -Font-descent */
types[6] = real; /* -left bearing */
types[7] = real; /* -right bearing */
types[8] = real; /* -width */
types[9] = real; /* -ascent */
types[10]= real; /* -descent */
begin_builtin(xcLoadFont,11,3,types);
XQueryTextExtents(DISP(0),
(XID)val[1],
STRG(2),
strlen(STRG(2)),
&direction,
&ascent,
&descent,
&over);
val[3]=direction;
val[4]=ascent;
val[5]=descent;
val[6] =over.lbearing;
val[7] =over.rbearing;
val[8] =over.width;
val[9] =over.ascent;
val[10]=over.descent;
for(i=3;i<11;i++)
unify_real_result(args[i],(REAL)val[i]);
end_builtin();
}
/*** RM: Apr 20 1993 ***/
/*****************************************************************/
/* not used anymore, but interesting */
ptr_goal GoalFromPsiTerm(psiTerm)
ptr_psi_term psiTerm;
{
ptr_residuation resid;
ptr_goal aim;
if(psiTerm == NULL)
{
Errorline("X error in GoalFromPsiTerm: psiTerm is null\n");
return FALSE;
}
if((resid = psiTerm->resid) == NULL)
{
Errorline("X error in GoalFromPsiTerm: psiTerm has no residuating functions\n");
return FALSE;
}
if(resid->next != NULL)
{
Errorline("X error in GoalFromPsiTerm: psiTerm has more than one residuating function\n");
return FALSE;
}
if((aim = resid->goal) == NULL)
{
Errorline("X error in GoalFromPsiTerm: psiTerm has no goal\n");
return FALSE;
}
return aim;
}
#endif
|
the_stack_data/6027.c
|
void main(void) {
int arr[5];
int a;
a = input();
arr[2] = a;
output(arr[2]);
}
|
the_stack_data/3262537.c
|
/*******************************************************************************
* Author:
* @coronapl
* Program:
* descending
*******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
/**
* Add a tab per level
*/
void printtab(int level) {
for (int i = 0; i <= level; i++) {
printf("\t");
}
}
/**
* Level n - 1 creates n processes of level n
* level -> current level of the tree
* maxlevel -> level to stop creating child processes
*/
void child_process(int level, int maxlevel) {
int pid;
int i;
// Recursive function base case
if (level == maxlevel) {
printtab(level - 1);
printf("PPID = %i PID = %i LEVEL = %i\n", getppid(), getpid(), level);
sleep(1);
exit(0);
} else {
printtab(level - 1);
printf("PPID = %i PID = %i LEVEL = %i\n", getppid(), getpid(), level);
// Parent creates level + 1 child processes
for (i = 0; i <= level; i++) {
if ((pid = fork()) < 0) {
perror("recursive fork");
exit(-3);
} else if (pid == 0) {
child_process(++level, maxlevel);
sleep(1);
exit(0);
} else {
wait(NULL);
}
}
}
}
int main(int argc, char * argv[]) {
int levels;
if (argc != 2) {
printf("usage: %s number", argv[0]);
return -1;
}
levels = atoi(argv[1]);
if (levels <= 0) {
printf("%s: the parameter must be a positive integer number", argv[0]);
return -2;
}
child_process(0, levels);
return 0;
}
|
the_stack_data/751067.c
|
#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
#define ALPHABET "abcdefghijklmnopqrstuvwxyz"
int char_position(char ch);
bool is_letter(char ch);
int main(void)
{
char ch;
while ((ch = getchar()) != EOF)
{
if (is_letter(ch))
printf("letter:%c, number: %d\n", ch, char_position(ch));
else
printf("%c not letter\n", ch);
if (ch == '\n')
;
}
return 0;
}
int char_position(char ch)
{
int i = 0;
for (;i < sizeof(ALPHABET)/sizeof(ALPHABET[0]);++i)
{
if (ALPHABET[i-1]==tolower(ch))
return i;
}
return -1;
}
bool is_letter(char ch)
{
return (char_position(ch)>0) ? true : false;
}
|
the_stack_data/140765960.c
|
#include<stdio.h>
int main(){
int n, i;
scanf("%d", &n);
int arr[n];
for(i = 0; i < n; i++){
scanf("%d", &arr[i]);
if(arr[i] % 2 == 0){ i--; }
}
for (i = 0; i < (n / 2); i++) {
printf("%d\n", arr[i] - arr[n - 1 - i]);
}
if (n % 2 == 1) {
printf("%d\n", arr[n / 2]);
}
return 0;
}
|
the_stack_data/1021735.c
|
void fence() { asm("sync"); }
void lwfence() { asm("lwsync"); }
void isync() { asm("isync"); }
int __unbuffered_cnt=0;
int __unbuffered_p1_EAX=0;
int __unbuffered_p1_EBX=0;
int x=0;
int y=0;
int z=0;
void * P0(void * arg) {
x = 1;
y = 1;
// Instrumentation for CPROVER
fence();
__unbuffered_cnt++;
}
void * P1(void * arg) {
y = 2;
z = 1;
__unbuffered_p1_EAX = z;
__unbuffered_p1_EBX = x;
// Instrumentation for CPROVER
fence();
__unbuffered_cnt++;
}
int main() {
__CPROVER_ASYNC_0: P0(0);
__CPROVER_ASYNC_1: P1(0);
__CPROVER_assume(__unbuffered_cnt==2);
fence();
// EXPECT:exists
__CPROVER_assert(!(y==2 && __unbuffered_p1_EAX==1 && __unbuffered_p1_EBX==0), "Program proven to be relaxed for X86, model checker says YES.");
return 0;
}
|
the_stack_data/99320.c
|
static float FR, F0, F1;
static float DR, D0, D1;
static long double LDR, LD0, LD1;
static void testFloatBuiltinOps() {
FR = __builtin_fmodf(F0,F1);
DR = __builtin_fmod(D0,D1);
LDR = __builtin_fmodl(LD0,LD1);
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.