file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/184519028.c | #include "stdio.h"
#include "stdlib.h"
#include "time.h"
#include "limits.h"
void swap (int *a, int *b) {
int t = *a;
*a = *b;
*b = t;
}
void heapify (int *arr, int current, int arr_len) {
int max = current;
int l = 2 * current + 1;
int r = 2 * current + 2;
if ( (l < arr_len) && (arr[l] > arr[max]) ) max = l;
if ( (r < arr_len) && (arr[r] > arr[max]) ) max = r;
if (max != current) {
swap(&arr[current], &arr[max]);
heapify(arr, max, arr_len);
}
}
void build_heap (int *arr, int arr_len) {
for (int i = arr_len / 2 - 1; i >= 0; i--) heapify(arr, i, arr_len);
}
void heap_sort (int *arr, int size) {
build_heap(arr, size);
for (int i = size - 1; i >= 0; i--) {
swap(&arr[0], &arr[i]);
heapify(arr, 0, i);
}
}
int main () {
int arr_len;
scanf("%d", &arr_len);
int *arr = malloc(sizeof(int) * arr_len);
srand(time(NULL));
for (int i = 0; i < arr_len; i++) {
arr[i] = rand() % INT_MAX;
printf("%d ", arr[i]);
}
printf("\n");
clock_t begin = clock();
heap_sort(arr, arr_len);
clock_t end = clock();
double time_spent = (double)(end - begin) * 1000 / CLOCKS_PER_SEC;
for (int i = 0; i < arr_len; i++) printf("%d ", arr[i]);
printf("\n time = %lf\n", time_spent);
return 0;
}
|
the_stack_data/120414.c | /*
* $PIP_license: <Simplified BSD License>
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
* $
* $RIKEN_copyright: Riken Center for Computational Sceience (R-CCS),
* System Software Development Team, 2016-2020
* $
* $PIP_TESTSUITE: Version 1.0.0$
*
* $Author: Atsushi Hori (R-CCS) mailto: [email protected] or [email protected]
* $
*/
#include <sched.h>
int main() {
while( 1 ) sched_yield();
}
|
the_stack_data/107352.c | /* PR middle-end/17813 */
/* Origin: Tom Hughes <[email protected]> */
/* { dg-do run { target i?86-*-linux* x86_64-*-linux* } } */
/* { dg-options "-O -fomit-frame-pointer" } */
/* { dg-options "-O -fomit-frame-pointer -march=i386" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
#include <setjmp.h>
#include <signal.h>
#include <stdlib.h>
static jmp_buf segv_jmpbuf;
static void segv_handler(int seg)
{
__builtin_longjmp(segv_jmpbuf, 1);
}
static int is_addressable(void *p, size_t size)
{
volatile char * volatile cp = (volatile char *)p;
volatile int ret;
struct sigaction sa, origsa;
sigset_t mask;
sa.sa_handler = segv_handler;
sa.sa_flags = 0;
sigfillset(&sa.sa_mask);
sigaction(SIGSEGV, &sa, &origsa);
sigprocmask(SIG_SETMASK, NULL, &mask);
if (__builtin_setjmp(segv_jmpbuf) == 0) {
while(size--)
*cp++;
ret = 1;
} else
ret = 0;
sigaction(SIGSEGV, &origsa, NULL);
sigprocmask(SIG_SETMASK, &mask, NULL);
return ret;
}
int main(int argc, char **argv)
{
is_addressable(0x0, 1);
return 0;
}
|
the_stack_data/173579476.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 RandomFunc(unsigned int input[1] , unsigned int output[1] )
{
unsigned int state[1] ;
unsigned int local1 ;
unsigned short copy11 ;
{
state[0UL] = (input[0UL] + 914778474UL) ^ 3462201355U;
local1 = 0UL;
while (local1 < 0U) {
if (state[0UL] > local1) {
if (state[0UL] == local1) {
state[0UL] = state[local1] - state[0UL];
} else {
copy11 = *((unsigned short *)(& state[local1]) + 1);
*((unsigned short *)(& state[local1]) + 1) = *((unsigned short *)(& state[local1]) + 0);
*((unsigned short *)(& state[local1]) + 0) = copy11;
}
} else {
state[0UL] = state[local1] + state[0UL];
}
local1 ++;
}
output[0UL] = ((state[0UL] >> 9U) | (state[0UL] << 23U)) | 1689005553U;
}
}
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] == 4110183933U) {
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 megaInit(void)
{
{
}
}
|
the_stack_data/90766282.c | //@ ltl invariant negative: ( ([] ( (<> ( ( AP((gate_l1 != 0)) && (! AP((gate_l0 != 0)))) && ( (X AP((gate_l1 != 0))) && (X AP((gate_l0 != 0)))))) || (! ( ( (! AP((gate_l0 != 0))) && (! AP((gate_l1 != 0)))) && ( (! (X AP((gate_l1 != 0)))) && (X AP((gate_l0 != 0)))))))) || (! ([] (<> AP((1.0 <= _diverge_delta))))));
extern float __VERIFIER_nondet_float(void);
extern int __VERIFIER_nondet_int(void);
char __VERIFIER_nondet_bool(void) {
return __VERIFIER_nondet_int() != 0;
}
char t5_l1, _x_t5_l1;
char t5_evt1, _x_t5_evt1;
char t5_evt0, _x_t5_evt0;
char t4_l1, _x_t4_l1;
char t4_l0, _x_t4_l0;
float t5_x, _x_t5_x;
char t4_evt1, _x_t4_evt1;
char t4_evt0, _x_t4_evt0;
char t3_l1, _x_t3_l1;
float t4_x, _x_t4_x;
char t3_evt1, _x_t3_evt1;
char t3_l0, _x_t3_l0;
int controller_cnt, _x_controller_cnt;
char t5_l0, _x_t5_l0;
char controller_evt2, _x_controller_evt2;
float controller_z, _x_controller_z;
char controller_evt1, _x_controller_evt1;
char controller_evt0, _x_controller_evt0;
char controller_l1, _x_controller_l1;
char controller_l0, _x_controller_l0;
char gate_l0, _x_gate_l0;
float t3_x, _x_t3_x;
char t2_evt1, _x_t2_evt1;
float delta, _x_delta;
float t0_x, _x_t0_x;
char t0_evt0, _x_t0_evt0;
char t0_l0, _x_t0_l0;
char t0_evt1, _x_t0_evt1;
float t1_x, _x_t1_x;
float gate_y, _x_gate_y;
char t0_l1, _x_t0_l1;
char t1_evt0, _x_t1_evt0;
float _diverge_delta, _x__diverge_delta;
char gate_evt0, _x_gate_evt0;
char t1_l0, _x_t1_l0;
char t1_evt1, _x_t1_evt1;
float t2_x, _x_t2_x;
char gate_evt1, _x_gate_evt1;
char t1_l1, _x_t1_l1;
char t2_evt0, _x_t2_evt0;
char gate_l1, _x_gate_l1;
char t2_l0, _x_t2_l0;
char t3_evt0, _x_t3_evt0;
char t2_l1, _x_t2_l1;
int main()
{
t5_l1 = __VERIFIER_nondet_bool();
t5_evt1 = __VERIFIER_nondet_bool();
t5_evt0 = __VERIFIER_nondet_bool();
t4_l1 = __VERIFIER_nondet_bool();
t4_l0 = __VERIFIER_nondet_bool();
t5_x = __VERIFIER_nondet_float();
t4_evt1 = __VERIFIER_nondet_bool();
t4_evt0 = __VERIFIER_nondet_bool();
t3_l1 = __VERIFIER_nondet_bool();
t4_x = __VERIFIER_nondet_float();
t3_evt1 = __VERIFIER_nondet_bool();
t3_l0 = __VERIFIER_nondet_bool();
controller_cnt = __VERIFIER_nondet_int();
t5_l0 = __VERIFIER_nondet_bool();
controller_evt2 = __VERIFIER_nondet_bool();
controller_z = __VERIFIER_nondet_float();
controller_evt1 = __VERIFIER_nondet_bool();
controller_evt0 = __VERIFIER_nondet_bool();
controller_l1 = __VERIFIER_nondet_bool();
controller_l0 = __VERIFIER_nondet_bool();
gate_l0 = __VERIFIER_nondet_bool();
t3_x = __VERIFIER_nondet_float();
t2_evt1 = __VERIFIER_nondet_bool();
delta = __VERIFIER_nondet_float();
t0_x = __VERIFIER_nondet_float();
t0_evt0 = __VERIFIER_nondet_bool();
t0_l0 = __VERIFIER_nondet_bool();
t0_evt1 = __VERIFIER_nondet_bool();
t1_x = __VERIFIER_nondet_float();
gate_y = __VERIFIER_nondet_float();
t0_l1 = __VERIFIER_nondet_bool();
t1_evt0 = __VERIFIER_nondet_bool();
_diverge_delta = __VERIFIER_nondet_float();
gate_evt0 = __VERIFIER_nondet_bool();
t1_l0 = __VERIFIER_nondet_bool();
t1_evt1 = __VERIFIER_nondet_bool();
t2_x = __VERIFIER_nondet_float();
gate_evt1 = __VERIFIER_nondet_bool();
t1_l1 = __VERIFIER_nondet_bool();
t2_evt0 = __VERIFIER_nondet_bool();
gate_l1 = __VERIFIER_nondet_bool();
t2_l0 = __VERIFIER_nondet_bool();
t3_evt0 = __VERIFIER_nondet_bool();
t2_l1 = __VERIFIER_nondet_bool();
int __ok = (((((((( !(t5_l0 != 0)) && ( !(t5_l1 != 0))) && (t5_x == 0.0)) && (((( !(t5_l0 != 0)) && ( !(t5_l1 != 0))) || ((t5_l0 != 0) && ( !(t5_l1 != 0)))) || (((t5_l1 != 0) && ( !(t5_l0 != 0))) || ((t5_l0 != 0) && (t5_l1 != 0))))) && (((( !(t5_evt0 != 0)) && ( !(t5_evt1 != 0))) || ((t5_evt0 != 0) && ( !(t5_evt1 != 0)))) || (((t5_evt1 != 0) && ( !(t5_evt0 != 0))) || ((t5_evt0 != 0) && (t5_evt1 != 0))))) && ((( !(t5_l0 != 0)) && ( !(t5_l1 != 0))) || (t5_x <= 5.0))) && ((((((( !(t4_l0 != 0)) && ( !(t4_l1 != 0))) && (t4_x == 0.0)) && (((( !(t4_l0 != 0)) && ( !(t4_l1 != 0))) || ((t4_l0 != 0) && ( !(t4_l1 != 0)))) || (((t4_l1 != 0) && ( !(t4_l0 != 0))) || ((t4_l0 != 0) && (t4_l1 != 0))))) && (((( !(t4_evt0 != 0)) && ( !(t4_evt1 != 0))) || ((t4_evt0 != 0) && ( !(t4_evt1 != 0)))) || (((t4_evt1 != 0) && ( !(t4_evt0 != 0))) || ((t4_evt0 != 0) && (t4_evt1 != 0))))) && ((( !(t4_l0 != 0)) && ( !(t4_l1 != 0))) || (t4_x <= 5.0))) && ((((((( !(t3_l0 != 0)) && ( !(t3_l1 != 0))) && (t3_x == 0.0)) && (((( !(t3_l0 != 0)) && ( !(t3_l1 != 0))) || ((t3_l0 != 0) && ( !(t3_l1 != 0)))) || (((t3_l1 != 0) && ( !(t3_l0 != 0))) || ((t3_l0 != 0) && (t3_l1 != 0))))) && (((( !(t3_evt0 != 0)) && ( !(t3_evt1 != 0))) || ((t3_evt0 != 0) && ( !(t3_evt1 != 0)))) || (((t3_evt1 != 0) && ( !(t3_evt0 != 0))) || ((t3_evt0 != 0) && (t3_evt1 != 0))))) && ((( !(t3_l0 != 0)) && ( !(t3_l1 != 0))) || (t3_x <= 5.0))) && ((((((( !(t2_l0 != 0)) && ( !(t2_l1 != 0))) && (t2_x == 0.0)) && (((( !(t2_l0 != 0)) && ( !(t2_l1 != 0))) || ((t2_l0 != 0) && ( !(t2_l1 != 0)))) || (((t2_l1 != 0) && ( !(t2_l0 != 0))) || ((t2_l0 != 0) && (t2_l1 != 0))))) && (((( !(t2_evt0 != 0)) && ( !(t2_evt1 != 0))) || ((t2_evt0 != 0) && ( !(t2_evt1 != 0)))) || (((t2_evt1 != 0) && ( !(t2_evt0 != 0))) || ((t2_evt0 != 0) && (t2_evt1 != 0))))) && ((( !(t2_l0 != 0)) && ( !(t2_l1 != 0))) || (t2_x <= 5.0))) && ((((((( !(t1_l0 != 0)) && ( !(t1_l1 != 0))) && (t1_x == 0.0)) && (((( !(t1_l0 != 0)) && ( !(t1_l1 != 0))) || ((t1_l0 != 0) && ( !(t1_l1 != 0)))) || (((t1_l1 != 0) && ( !(t1_l0 != 0))) || ((t1_l0 != 0) && (t1_l1 != 0))))) && (((( !(t1_evt0 != 0)) && ( !(t1_evt1 != 0))) || ((t1_evt0 != 0) && ( !(t1_evt1 != 0)))) || (((t1_evt1 != 0) && ( !(t1_evt0 != 0))) || ((t1_evt0 != 0) && (t1_evt1 != 0))))) && ((( !(t1_l0 != 0)) && ( !(t1_l1 != 0))) || (t1_x <= 5.0))) && ((((((( !(t0_l0 != 0)) && ( !(t0_l1 != 0))) && (t0_x == 0.0)) && (((( !(t0_l0 != 0)) && ( !(t0_l1 != 0))) || ((t0_l0 != 0) && ( !(t0_l1 != 0)))) || (((t0_l1 != 0) && ( !(t0_l0 != 0))) || ((t0_l0 != 0) && (t0_l1 != 0))))) && (((( !(t0_evt0 != 0)) && ( !(t0_evt1 != 0))) || ((t0_evt0 != 0) && ( !(t0_evt1 != 0)))) || (((t0_evt1 != 0) && ( !(t0_evt0 != 0))) || ((t0_evt0 != 0) && (t0_evt1 != 0))))) && ((( !(t0_l0 != 0)) && ( !(t0_l1 != 0))) || (t0_x <= 5.0))) && (((((((( !(controller_l0 != 0)) && ( !(controller_l1 != 0))) && (controller_z == 0.0)) && (((( !(controller_l0 != 0)) && ( !(controller_l1 != 0))) || ((controller_l0 != 0) && ( !(controller_l1 != 0)))) || (((controller_l1 != 0) && ( !(controller_l0 != 0))) || ((controller_l0 != 0) && (controller_l1 != 0))))) && (((( !(controller_evt2 != 0)) && (( !(controller_evt0 != 0)) && ( !(controller_evt1 != 0)))) || (( !(controller_evt2 != 0)) && ((controller_evt0 != 0) && ( !(controller_evt1 != 0))))) || ((( !(controller_evt2 != 0)) && ((controller_evt1 != 0) && ( !(controller_evt0 != 0)))) || ((( !(controller_evt2 != 0)) && ((controller_evt0 != 0) && (controller_evt1 != 0))) || ((controller_evt2 != 0) && (( !(controller_evt0 != 0)) && ( !(controller_evt1 != 0)))))))) && ((((((((controller_cnt == 0) || (controller_cnt == 1)) || (controller_cnt == 2)) || (controller_cnt == 3)) || (controller_cnt == 4)) || (controller_cnt == 5)) || (controller_cnt == 6)) || (controller_cnt == 7))) && ((controller_z <= 1.0) || ( !(((controller_l0 != 0) && ( !(controller_l1 != 0))) || ((controller_l0 != 0) && (controller_l1 != 0)))))) && (((((((( !(gate_l0 != 0)) && ( !(gate_l1 != 0))) && (gate_y == 0.0)) && (((( !(gate_l0 != 0)) && ( !(gate_l1 != 0))) || ((gate_l0 != 0) && ( !(gate_l1 != 0)))) || (((gate_l1 != 0) && ( !(gate_l0 != 0))) || ((gate_l0 != 0) && (gate_l1 != 0))))) && (((( !(gate_evt0 != 0)) && ( !(gate_evt1 != 0))) || ((gate_evt0 != 0) && ( !(gate_evt1 != 0)))) || (((gate_evt1 != 0) && ( !(gate_evt0 != 0))) || ((gate_evt0 != 0) && (gate_evt1 != 0))))) && ((gate_y <= 1.0) || ( !((gate_l0 != 0) && ( !(gate_l1 != 0)))))) && ((gate_y <= 2.0) || ( !((gate_l0 != 0) && (gate_l1 != 0))))) && (0.0 <= delta))))))))) && (delta == _diverge_delta));
while (__ok) {
_x_t5_l1 = __VERIFIER_nondet_bool();
_x_t5_evt1 = __VERIFIER_nondet_bool();
_x_t5_evt0 = __VERIFIER_nondet_bool();
_x_t4_l1 = __VERIFIER_nondet_bool();
_x_t4_l0 = __VERIFIER_nondet_bool();
_x_t5_x = __VERIFIER_nondet_float();
_x_t4_evt1 = __VERIFIER_nondet_bool();
_x_t4_evt0 = __VERIFIER_nondet_bool();
_x_t3_l1 = __VERIFIER_nondet_bool();
_x_t4_x = __VERIFIER_nondet_float();
_x_t3_evt1 = __VERIFIER_nondet_bool();
_x_t3_l0 = __VERIFIER_nondet_bool();
_x_controller_cnt = __VERIFIER_nondet_int();
_x_t5_l0 = __VERIFIER_nondet_bool();
_x_controller_evt2 = __VERIFIER_nondet_bool();
_x_controller_z = __VERIFIER_nondet_float();
_x_controller_evt1 = __VERIFIER_nondet_bool();
_x_controller_evt0 = __VERIFIER_nondet_bool();
_x_controller_l1 = __VERIFIER_nondet_bool();
_x_controller_l0 = __VERIFIER_nondet_bool();
_x_gate_l0 = __VERIFIER_nondet_bool();
_x_t3_x = __VERIFIER_nondet_float();
_x_t2_evt1 = __VERIFIER_nondet_bool();
_x_delta = __VERIFIER_nondet_float();
_x_t0_x = __VERIFIER_nondet_float();
_x_t0_evt0 = __VERIFIER_nondet_bool();
_x_t0_l0 = __VERIFIER_nondet_bool();
_x_t0_evt1 = __VERIFIER_nondet_bool();
_x_t1_x = __VERIFIER_nondet_float();
_x_gate_y = __VERIFIER_nondet_float();
_x_t0_l1 = __VERIFIER_nondet_bool();
_x_t1_evt0 = __VERIFIER_nondet_bool();
_x__diverge_delta = __VERIFIER_nondet_float();
_x_gate_evt0 = __VERIFIER_nondet_bool();
_x_t1_l0 = __VERIFIER_nondet_bool();
_x_t1_evt1 = __VERIFIER_nondet_bool();
_x_t2_x = __VERIFIER_nondet_float();
_x_gate_evt1 = __VERIFIER_nondet_bool();
_x_t1_l1 = __VERIFIER_nondet_bool();
_x_t2_evt0 = __VERIFIER_nondet_bool();
_x_gate_l1 = __VERIFIER_nondet_bool();
_x_t2_l0 = __VERIFIER_nondet_bool();
_x_t3_evt0 = __VERIFIER_nondet_bool();
_x_t2_l1 = __VERIFIER_nondet_bool();
__ok = ((((((((((((((((((((((( !(_x_t5_l0 != 0)) && ( !(_x_t5_l1 != 0))) || ((_x_t5_l0 != 0) && ( !(_x_t5_l1 != 0)))) || (((_x_t5_l1 != 0) && ( !(_x_t5_l0 != 0))) || ((_x_t5_l0 != 0) && (_x_t5_l1 != 0)))) && (((( !(_x_t5_evt0 != 0)) && ( !(_x_t5_evt1 != 0))) || ((_x_t5_evt0 != 0) && ( !(_x_t5_evt1 != 0)))) || (((_x_t5_evt1 != 0) && ( !(_x_t5_evt0 != 0))) || ((_x_t5_evt0 != 0) && (_x_t5_evt1 != 0))))) && ((( !(_x_t5_l0 != 0)) && ( !(_x_t5_l1 != 0))) || (_x_t5_x <= 5.0))) && (((((t5_l0 != 0) == (_x_t5_l0 != 0)) && ((t5_l1 != 0) == (_x_t5_l1 != 0))) && ((delta + (t5_x + (-1.0 * _x_t5_x))) == 0.0)) || ( !(( !(delta <= 0.0)) || (( !(t5_evt0 != 0)) && ( !(t5_evt1 != 0))))))) && (((((_x_t5_l0 != 0) && ( !(_x_t5_l1 != 0))) && ((t5_evt0 != 0) && ( !(t5_evt1 != 0)))) && (_x_t5_x == 0.0)) || ( !((( !(t5_l0 != 0)) && ( !(t5_l1 != 0))) && ((delta == 0.0) && ( !(( !(t5_evt0 != 0)) && ( !(t5_evt1 != 0))))))))) && (((((_x_t5_l1 != 0) && ( !(_x_t5_l0 != 0))) && ( !(t5_x <= 2.0))) && (((t5_evt0 != 0) && (t5_evt1 != 0)) && (t5_x == _x_t5_x))) || ( !(((t5_l0 != 0) && ( !(t5_l1 != 0))) && ((delta == 0.0) && ( !(( !(t5_evt0 != 0)) && ( !(t5_evt1 != 0))))))))) && (((t5_x == _x_t5_x) && (((_x_t5_l0 != 0) && (_x_t5_l1 != 0)) && ((t5_evt0 != 0) && (t5_evt1 != 0)))) || ( !(((t5_l1 != 0) && ( !(t5_l0 != 0))) && ((delta == 0.0) && ( !(( !(t5_evt0 != 0)) && ( !(t5_evt1 != 0))))))))) && ((((( !(_x_t5_l0 != 0)) && ( !(_x_t5_l1 != 0))) && (t5_x <= 5.0)) && (((t5_evt1 != 0) && ( !(t5_evt0 != 0))) && (t5_x == _x_t5_x))) || ( !(((t5_l0 != 0) && (t5_l1 != 0)) && ((delta == 0.0) && ( !(( !(t5_evt0 != 0)) && ( !(t5_evt1 != 0))))))))) && (((((((((((( !(_x_t4_l0 != 0)) && ( !(_x_t4_l1 != 0))) || ((_x_t4_l0 != 0) && ( !(_x_t4_l1 != 0)))) || (((_x_t4_l1 != 0) && ( !(_x_t4_l0 != 0))) || ((_x_t4_l0 != 0) && (_x_t4_l1 != 0)))) && (((( !(_x_t4_evt0 != 0)) && ( !(_x_t4_evt1 != 0))) || ((_x_t4_evt0 != 0) && ( !(_x_t4_evt1 != 0)))) || (((_x_t4_evt1 != 0) && ( !(_x_t4_evt0 != 0))) || ((_x_t4_evt0 != 0) && (_x_t4_evt1 != 0))))) && ((( !(_x_t4_l0 != 0)) && ( !(_x_t4_l1 != 0))) || (_x_t4_x <= 5.0))) && (((((t4_l0 != 0) == (_x_t4_l0 != 0)) && ((t4_l1 != 0) == (_x_t4_l1 != 0))) && ((delta + (t4_x + (-1.0 * _x_t4_x))) == 0.0)) || ( !(( !(delta <= 0.0)) || (( !(t4_evt0 != 0)) && ( !(t4_evt1 != 0))))))) && (((((_x_t4_l0 != 0) && ( !(_x_t4_l1 != 0))) && ((t4_evt0 != 0) && ( !(t4_evt1 != 0)))) && (_x_t4_x == 0.0)) || ( !((( !(t4_l0 != 0)) && ( !(t4_l1 != 0))) && ((delta == 0.0) && ( !(( !(t4_evt0 != 0)) && ( !(t4_evt1 != 0))))))))) && (((((_x_t4_l1 != 0) && ( !(_x_t4_l0 != 0))) && ( !(t4_x <= 2.0))) && (((t4_evt0 != 0) && (t4_evt1 != 0)) && (t4_x == _x_t4_x))) || ( !(((t4_l0 != 0) && ( !(t4_l1 != 0))) && ((delta == 0.0) && ( !(( !(t4_evt0 != 0)) && ( !(t4_evt1 != 0))))))))) && (((t4_x == _x_t4_x) && (((_x_t4_l0 != 0) && (_x_t4_l1 != 0)) && ((t4_evt0 != 0) && (t4_evt1 != 0)))) || ( !(((t4_l1 != 0) && ( !(t4_l0 != 0))) && ((delta == 0.0) && ( !(( !(t4_evt0 != 0)) && ( !(t4_evt1 != 0))))))))) && ((((( !(_x_t4_l0 != 0)) && ( !(_x_t4_l1 != 0))) && (t4_x <= 5.0)) && (((t4_evt1 != 0) && ( !(t4_evt0 != 0))) && (t4_x == _x_t4_x))) || ( !(((t4_l0 != 0) && (t4_l1 != 0)) && ((delta == 0.0) && ( !(( !(t4_evt0 != 0)) && ( !(t4_evt1 != 0))))))))) && (((((((((((( !(_x_t3_l0 != 0)) && ( !(_x_t3_l1 != 0))) || ((_x_t3_l0 != 0) && ( !(_x_t3_l1 != 0)))) || (((_x_t3_l1 != 0) && ( !(_x_t3_l0 != 0))) || ((_x_t3_l0 != 0) && (_x_t3_l1 != 0)))) && (((( !(_x_t3_evt0 != 0)) && ( !(_x_t3_evt1 != 0))) || ((_x_t3_evt0 != 0) && ( !(_x_t3_evt1 != 0)))) || (((_x_t3_evt1 != 0) && ( !(_x_t3_evt0 != 0))) || ((_x_t3_evt0 != 0) && (_x_t3_evt1 != 0))))) && ((( !(_x_t3_l0 != 0)) && ( !(_x_t3_l1 != 0))) || (_x_t3_x <= 5.0))) && (((((t3_l0 != 0) == (_x_t3_l0 != 0)) && ((t3_l1 != 0) == (_x_t3_l1 != 0))) && ((delta + (t3_x + (-1.0 * _x_t3_x))) == 0.0)) || ( !(( !(delta <= 0.0)) || (( !(t3_evt0 != 0)) && ( !(t3_evt1 != 0))))))) && (((((_x_t3_l0 != 0) && ( !(_x_t3_l1 != 0))) && ((t3_evt0 != 0) && ( !(t3_evt1 != 0)))) && (_x_t3_x == 0.0)) || ( !((( !(t3_l0 != 0)) && ( !(t3_l1 != 0))) && ((delta == 0.0) && ( !(( !(t3_evt0 != 0)) && ( !(t3_evt1 != 0))))))))) && (((((_x_t3_l1 != 0) && ( !(_x_t3_l0 != 0))) && ( !(t3_x <= 2.0))) && (((t3_evt0 != 0) && (t3_evt1 != 0)) && (t3_x == _x_t3_x))) || ( !(((t3_l0 != 0) && ( !(t3_l1 != 0))) && ((delta == 0.0) && ( !(( !(t3_evt0 != 0)) && ( !(t3_evt1 != 0))))))))) && (((t3_x == _x_t3_x) && (((_x_t3_l0 != 0) && (_x_t3_l1 != 0)) && ((t3_evt0 != 0) && (t3_evt1 != 0)))) || ( !(((t3_l1 != 0) && ( !(t3_l0 != 0))) && ((delta == 0.0) && ( !(( !(t3_evt0 != 0)) && ( !(t3_evt1 != 0))))))))) && ((((( !(_x_t3_l0 != 0)) && ( !(_x_t3_l1 != 0))) && (t3_x <= 5.0)) && (((t3_evt1 != 0) && ( !(t3_evt0 != 0))) && (t3_x == _x_t3_x))) || ( !(((t3_l0 != 0) && (t3_l1 != 0)) && ((delta == 0.0) && ( !(( !(t3_evt0 != 0)) && ( !(t3_evt1 != 0))))))))) && (((((((((((( !(_x_t2_l0 != 0)) && ( !(_x_t2_l1 != 0))) || ((_x_t2_l0 != 0) && ( !(_x_t2_l1 != 0)))) || (((_x_t2_l1 != 0) && ( !(_x_t2_l0 != 0))) || ((_x_t2_l0 != 0) && (_x_t2_l1 != 0)))) && (((( !(_x_t2_evt0 != 0)) && ( !(_x_t2_evt1 != 0))) || ((_x_t2_evt0 != 0) && ( !(_x_t2_evt1 != 0)))) || (((_x_t2_evt1 != 0) && ( !(_x_t2_evt0 != 0))) || ((_x_t2_evt0 != 0) && (_x_t2_evt1 != 0))))) && ((( !(_x_t2_l0 != 0)) && ( !(_x_t2_l1 != 0))) || (_x_t2_x <= 5.0))) && (((((t2_l0 != 0) == (_x_t2_l0 != 0)) && ((t2_l1 != 0) == (_x_t2_l1 != 0))) && ((delta + (t2_x + (-1.0 * _x_t2_x))) == 0.0)) || ( !(( !(delta <= 0.0)) || (( !(t2_evt0 != 0)) && ( !(t2_evt1 != 0))))))) && (((((_x_t2_l0 != 0) && ( !(_x_t2_l1 != 0))) && ((t2_evt0 != 0) && ( !(t2_evt1 != 0)))) && (_x_t2_x == 0.0)) || ( !((( !(t2_l0 != 0)) && ( !(t2_l1 != 0))) && ((delta == 0.0) && ( !(( !(t2_evt0 != 0)) && ( !(t2_evt1 != 0))))))))) && (((((_x_t2_l1 != 0) && ( !(_x_t2_l0 != 0))) && ( !(t2_x <= 2.0))) && (((t2_evt0 != 0) && (t2_evt1 != 0)) && (t2_x == _x_t2_x))) || ( !(((t2_l0 != 0) && ( !(t2_l1 != 0))) && ((delta == 0.0) && ( !(( !(t2_evt0 != 0)) && ( !(t2_evt1 != 0))))))))) && (((t2_x == _x_t2_x) && (((_x_t2_l0 != 0) && (_x_t2_l1 != 0)) && ((t2_evt0 != 0) && (t2_evt1 != 0)))) || ( !(((t2_l1 != 0) && ( !(t2_l0 != 0))) && ((delta == 0.0) && ( !(( !(t2_evt0 != 0)) && ( !(t2_evt1 != 0))))))))) && ((((( !(_x_t2_l0 != 0)) && ( !(_x_t2_l1 != 0))) && (t2_x <= 5.0)) && (((t2_evt1 != 0) && ( !(t2_evt0 != 0))) && (t2_x == _x_t2_x))) || ( !(((t2_l0 != 0) && (t2_l1 != 0)) && ((delta == 0.0) && ( !(( !(t2_evt0 != 0)) && ( !(t2_evt1 != 0))))))))) && (((((((((((( !(_x_t1_l0 != 0)) && ( !(_x_t1_l1 != 0))) || ((_x_t1_l0 != 0) && ( !(_x_t1_l1 != 0)))) || (((_x_t1_l1 != 0) && ( !(_x_t1_l0 != 0))) || ((_x_t1_l0 != 0) && (_x_t1_l1 != 0)))) && (((( !(_x_t1_evt0 != 0)) && ( !(_x_t1_evt1 != 0))) || ((_x_t1_evt0 != 0) && ( !(_x_t1_evt1 != 0)))) || (((_x_t1_evt1 != 0) && ( !(_x_t1_evt0 != 0))) || ((_x_t1_evt0 != 0) && (_x_t1_evt1 != 0))))) && ((( !(_x_t1_l0 != 0)) && ( !(_x_t1_l1 != 0))) || (_x_t1_x <= 5.0))) && (((((t1_l0 != 0) == (_x_t1_l0 != 0)) && ((t1_l1 != 0) == (_x_t1_l1 != 0))) && ((delta + (t1_x + (-1.0 * _x_t1_x))) == 0.0)) || ( !(( !(delta <= 0.0)) || (( !(t1_evt0 != 0)) && ( !(t1_evt1 != 0))))))) && (((((_x_t1_l0 != 0) && ( !(_x_t1_l1 != 0))) && ((t1_evt0 != 0) && ( !(t1_evt1 != 0)))) && (_x_t1_x == 0.0)) || ( !((( !(t1_l0 != 0)) && ( !(t1_l1 != 0))) && ((delta == 0.0) && ( !(( !(t1_evt0 != 0)) && ( !(t1_evt1 != 0))))))))) && (((((_x_t1_l1 != 0) && ( !(_x_t1_l0 != 0))) && ( !(t1_x <= 2.0))) && (((t1_evt0 != 0) && (t1_evt1 != 0)) && (t1_x == _x_t1_x))) || ( !(((t1_l0 != 0) && ( !(t1_l1 != 0))) && ((delta == 0.0) && ( !(( !(t1_evt0 != 0)) && ( !(t1_evt1 != 0))))))))) && (((t1_x == _x_t1_x) && (((_x_t1_l0 != 0) && (_x_t1_l1 != 0)) && ((t1_evt0 != 0) && (t1_evt1 != 0)))) || ( !(((t1_l1 != 0) && ( !(t1_l0 != 0))) && ((delta == 0.0) && ( !(( !(t1_evt0 != 0)) && ( !(t1_evt1 != 0))))))))) && ((((( !(_x_t1_l0 != 0)) && ( !(_x_t1_l1 != 0))) && (t1_x <= 5.0)) && (((t1_evt1 != 0) && ( !(t1_evt0 != 0))) && (t1_x == _x_t1_x))) || ( !(((t1_l0 != 0) && (t1_l1 != 0)) && ((delta == 0.0) && ( !(( !(t1_evt0 != 0)) && ( !(t1_evt1 != 0))))))))) && (((((((((((( !(_x_t0_l0 != 0)) && ( !(_x_t0_l1 != 0))) || ((_x_t0_l0 != 0) && ( !(_x_t0_l1 != 0)))) || (((_x_t0_l1 != 0) && ( !(_x_t0_l0 != 0))) || ((_x_t0_l0 != 0) && (_x_t0_l1 != 0)))) && (((( !(_x_t0_evt0 != 0)) && ( !(_x_t0_evt1 != 0))) || ((_x_t0_evt0 != 0) && ( !(_x_t0_evt1 != 0)))) || (((_x_t0_evt1 != 0) && ( !(_x_t0_evt0 != 0))) || ((_x_t0_evt0 != 0) && (_x_t0_evt1 != 0))))) && ((( !(_x_t0_l0 != 0)) && ( !(_x_t0_l1 != 0))) || (_x_t0_x <= 5.0))) && (((((t0_l0 != 0) == (_x_t0_l0 != 0)) && ((t0_l1 != 0) == (_x_t0_l1 != 0))) && ((delta + (t0_x + (-1.0 * _x_t0_x))) == 0.0)) || ( !(( !(delta <= 0.0)) || (( !(t0_evt0 != 0)) && ( !(t0_evt1 != 0))))))) && (((((_x_t0_l0 != 0) && ( !(_x_t0_l1 != 0))) && ((t0_evt0 != 0) && ( !(t0_evt1 != 0)))) && (_x_t0_x == 0.0)) || ( !((( !(t0_l0 != 0)) && ( !(t0_l1 != 0))) && ((delta == 0.0) && ( !(( !(t0_evt0 != 0)) && ( !(t0_evt1 != 0))))))))) && (((((_x_t0_l1 != 0) && ( !(_x_t0_l0 != 0))) && ( !(t0_x <= 2.0))) && (((t0_evt0 != 0) && (t0_evt1 != 0)) && (t0_x == _x_t0_x))) || ( !(((t0_l0 != 0) && ( !(t0_l1 != 0))) && ((delta == 0.0) && ( !(( !(t0_evt0 != 0)) && ( !(t0_evt1 != 0))))))))) && (((t0_x == _x_t0_x) && (((_x_t0_l0 != 0) && (_x_t0_l1 != 0)) && ((t0_evt0 != 0) && (t0_evt1 != 0)))) || ( !(((t0_l1 != 0) && ( !(t0_l0 != 0))) && ((delta == 0.0) && ( !(( !(t0_evt0 != 0)) && ( !(t0_evt1 != 0))))))))) && ((((( !(_x_t0_l0 != 0)) && ( !(_x_t0_l1 != 0))) && (t0_x <= 5.0)) && (((t0_evt1 != 0) && ( !(t0_evt0 != 0))) && (t0_x == _x_t0_x))) || ( !(((t0_l0 != 0) && (t0_l1 != 0)) && ((delta == 0.0) && ( !(( !(t0_evt0 != 0)) && ( !(t0_evt1 != 0))))))))) && (((((((((((((((((( !(_x_controller_l0 != 0)) && ( !(_x_controller_l1 != 0))) || ((_x_controller_l0 != 0) && ( !(_x_controller_l1 != 0)))) || (((_x_controller_l1 != 0) && ( !(_x_controller_l0 != 0))) || ((_x_controller_l0 != 0) && (_x_controller_l1 != 0)))) && (((( !(_x_controller_evt2 != 0)) && (( !(_x_controller_evt0 != 0)) && ( !(_x_controller_evt1 != 0)))) || (( !(_x_controller_evt2 != 0)) && ((_x_controller_evt0 != 0) && ( !(_x_controller_evt1 != 0))))) || ((( !(_x_controller_evt2 != 0)) && ((_x_controller_evt1 != 0) && ( !(_x_controller_evt0 != 0)))) || ((( !(_x_controller_evt2 != 0)) && ((_x_controller_evt0 != 0) && (_x_controller_evt1 != 0))) || ((_x_controller_evt2 != 0) && (( !(_x_controller_evt0 != 0)) && ( !(_x_controller_evt1 != 0)))))))) && ((((((((_x_controller_cnt == 0) || (_x_controller_cnt == 1)) || (_x_controller_cnt == 2)) || (_x_controller_cnt == 3)) || (_x_controller_cnt == 4)) || (_x_controller_cnt == 5)) || (_x_controller_cnt == 6)) || (_x_controller_cnt == 7))) && ((_x_controller_z <= 1.0) || ( !(((_x_controller_l0 != 0) && ( !(_x_controller_l1 != 0))) || ((_x_controller_l0 != 0) && (_x_controller_l1 != 0)))))) && ((((((controller_l0 != 0) == (_x_controller_l0 != 0)) && ((controller_l1 != 0) == (_x_controller_l1 != 0))) && ((delta + (controller_z + (-1.0 * _x_controller_z))) == 0.0)) && (controller_cnt == _x_controller_cnt)) || ( !(( !(delta <= 0.0)) || (( !(controller_evt2 != 0)) && (( !(controller_evt0 != 0)) && ( !(controller_evt1 != 0)))))))) && (((((_x_controller_l0 != 0) && ( !(_x_controller_l1 != 0))) && (( !(controller_evt2 != 0)) && ((controller_evt0 != 0) && ( !(controller_evt1 != 0))))) && ((_x_controller_cnt == 1) && (_x_controller_z == 0.0))) || ( !((( !(controller_l0 != 0)) && ( !(controller_l1 != 0))) && ((delta == 0.0) && ( !(( !(controller_evt2 != 0)) && (( !(controller_evt0 != 0)) && ( !(controller_evt1 != 0)))))))))) && (((controller_z == _x_controller_z) && (((_x_controller_l0 != 0) && ( !(_x_controller_l1 != 0))) || ((_x_controller_l1 != 0) && ( !(_x_controller_l0 != 0))))) || ( !(((controller_l0 != 0) && ( !(controller_l1 != 0))) && ((delta == 0.0) && ( !(( !(controller_evt2 != 0)) && (( !(controller_evt0 != 0)) && ( !(controller_evt1 != 0)))))))))) && ((((( !(controller_evt2 != 0)) && ((controller_evt0 != 0) && ( !(controller_evt1 != 0)))) && ((controller_cnt + (-1 * _x_controller_cnt)) == -1)) || ((( !(controller_evt2 != 0)) && ((controller_evt1 != 0) && ( !(controller_evt0 != 0)))) && ((controller_cnt + (-1 * _x_controller_cnt)) == 1))) || ( !(((delta == 0.0) && ( !(( !(controller_evt2 != 0)) && (( !(controller_evt0 != 0)) && ( !(controller_evt1 != 0)))))) && (((controller_l0 != 0) && ( !(controller_l1 != 0))) && ((_x_controller_l0 != 0) && ( !(_x_controller_l1 != 0)))))))) && (((( !(controller_evt2 != 0)) && ((controller_evt0 != 0) && (controller_evt1 != 0))) && ((controller_cnt == _x_controller_cnt) && (controller_z == 1.0))) || ( !(((delta == 0.0) && ( !(( !(controller_evt2 != 0)) && (( !(controller_evt0 != 0)) && ( !(controller_evt1 != 0)))))) && (((controller_l0 != 0) && ( !(controller_l1 != 0))) && ((_x_controller_l1 != 0) && ( !(_x_controller_l0 != 0)))))))) && ((((_x_controller_l1 != 0) && ( !(_x_controller_l0 != 0))) || ((_x_controller_l0 != 0) && (_x_controller_l1 != 0))) || ( !(((controller_l1 != 0) && ( !(controller_l0 != 0))) && ((delta == 0.0) && ( !(( !(controller_evt2 != 0)) && (( !(controller_evt0 != 0)) && ( !(controller_evt1 != 0)))))))))) && (((controller_z == _x_controller_z) && (((( !(controller_evt2 != 0)) && ((controller_evt0 != 0) && ( !(controller_evt1 != 0)))) && ((controller_cnt + (-1 * _x_controller_cnt)) == -1)) || (((( !(controller_evt2 != 0)) && ((controller_evt1 != 0) && ( !(controller_evt0 != 0)))) && ((controller_cnt + (-1 * _x_controller_cnt)) == 1)) && ( !(controller_cnt <= 1))))) || ( !(((delta == 0.0) && ( !(( !(controller_evt2 != 0)) && (( !(controller_evt0 != 0)) && ( !(controller_evt1 != 0)))))) && (((controller_l1 != 0) && ( !(controller_l0 != 0))) && ((_x_controller_l1 != 0) && ( !(_x_controller_l0 != 0)))))))) && ((((( !(controller_evt2 != 0)) && ((controller_evt1 != 0) && ( !(controller_evt0 != 0)))) && (controller_cnt == 1)) && ((_x_controller_cnt == 0) && (_x_controller_z == 0.0))) || ( !(((delta == 0.0) && ( !(( !(controller_evt2 != 0)) && (( !(controller_evt0 != 0)) && ( !(controller_evt1 != 0)))))) && (((controller_l1 != 0) && ( !(controller_l0 != 0))) && ((_x_controller_l0 != 0) && (_x_controller_l1 != 0))))))) && (((controller_z == _x_controller_z) && ((( !(_x_controller_l0 != 0)) && ( !(_x_controller_l1 != 0))) || ((_x_controller_l1 != 0) && ( !(_x_controller_l0 != 0))))) || ( !(((controller_l0 != 0) && (controller_l1 != 0)) && ((delta == 0.0) && ( !(( !(controller_evt2 != 0)) && (( !(controller_evt0 != 0)) && ( !(controller_evt1 != 0)))))))))) && ((((controller_cnt + (-1 * _x_controller_cnt)) == -1) && ((( !(controller_evt2 != 0)) && ((controller_evt0 != 0) && ( !(controller_evt1 != 0)))) && (controller_z <= 1.0))) || ( !(((delta == 0.0) && ( !(( !(controller_evt2 != 0)) && (( !(controller_evt0 != 0)) && ( !(controller_evt1 != 0)))))) && (((_x_controller_l1 != 0) && ( !(_x_controller_l0 != 0))) && ((controller_l0 != 0) && (controller_l1 != 0))))))) && ((((((((((((( !(_x_gate_l0 != 0)) && ( !(_x_gate_l1 != 0))) || ((_x_gate_l0 != 0) && ( !(_x_gate_l1 != 0)))) || (((_x_gate_l1 != 0) && ( !(_x_gate_l0 != 0))) || ((_x_gate_l0 != 0) && (_x_gate_l1 != 0)))) && (((( !(_x_gate_evt0 != 0)) && ( !(_x_gate_evt1 != 0))) || ((_x_gate_evt0 != 0) && ( !(_x_gate_evt1 != 0)))) || (((_x_gate_evt1 != 0) && ( !(_x_gate_evt0 != 0))) || ((_x_gate_evt0 != 0) && (_x_gate_evt1 != 0))))) && ((_x_gate_y <= 1.0) || ( !((_x_gate_l0 != 0) && ( !(_x_gate_l1 != 0)))))) && ((_x_gate_y <= 2.0) || ( !((_x_gate_l0 != 0) && (_x_gate_l1 != 0))))) && (((((gate_l0 != 0) == (_x_gate_l0 != 0)) && ((gate_l1 != 0) == (_x_gate_l1 != 0))) && ((delta + (gate_y + (-1.0 * _x_gate_y))) == 0.0)) || ( !((( !(gate_evt0 != 0)) && ( !(gate_evt1 != 0))) || ( !(delta <= 0.0)))))) && (((((_x_gate_l0 != 0) && ( !(_x_gate_l1 != 0))) && ((gate_evt0 != 0) && ( !(gate_evt1 != 0)))) && (_x_gate_y == 0.0)) || ( !((( !(gate_l0 != 0)) && ( !(gate_l1 != 0))) && ((delta == 0.0) && ( !(( !(gate_evt0 != 0)) && ( !(gate_evt1 != 0))))))))) && (((((_x_gate_l1 != 0) && ( !(_x_gate_l0 != 0))) && ((gate_evt0 != 0) && (gate_evt1 != 0))) && ((gate_y <= 1.0) && (gate_y == _x_gate_y))) || ( !(((gate_l0 != 0) && ( !(gate_l1 != 0))) && ((delta == 0.0) && ( !(( !(gate_evt0 != 0)) && ( !(gate_evt1 != 0))))))))) && (((_x_gate_y == 0.0) && (((_x_gate_l0 != 0) && (_x_gate_l1 != 0)) && ((gate_evt1 != 0) && ( !(gate_evt0 != 0))))) || ( !(((gate_l1 != 0) && ( !(gate_l0 != 0))) && ((delta == 0.0) && ( !(( !(gate_evt0 != 0)) && ( !(gate_evt1 != 0))))))))) && (((gate_y == _x_gate_y) && (((( !(_x_gate_l0 != 0)) && ( !(_x_gate_l1 != 0))) && (1.0 <= gate_y)) && (((gate_evt0 != 0) && (gate_evt1 != 0)) && (gate_y <= 2.0)))) || ( !(((gate_l0 != 0) && (gate_l1 != 0)) && ((delta == 0.0) && ( !(( !(gate_evt0 != 0)) && ( !(gate_evt1 != 0))))))))) && (0.0 <= _x_delta))))))))) && ((( !(t5_evt0 != 0)) && ( !(t5_evt1 != 0))) || ( !((delta == 0.0) && ( !(( !(t0_evt0 != 0)) && ( !(t0_evt1 != 0)))))))) && ((( !(t5_evt0 != 0)) && ( !(t5_evt1 != 0))) || ( !((delta == 0.0) && ( !(( !(t1_evt0 != 0)) && ( !(t1_evt1 != 0)))))))) && ((( !(t5_evt0 != 0)) && ( !(t5_evt1 != 0))) || ( !((delta == 0.0) && ( !(( !(t2_evt0 != 0)) && ( !(t2_evt1 != 0)))))))) && ((( !(t5_evt0 != 0)) && ( !(t5_evt1 != 0))) || ( !((delta == 0.0) && ( !(( !(t3_evt0 != 0)) && ( !(t3_evt1 != 0)))))))) && ((( !(t5_evt0 != 0)) && ( !(t5_evt1 != 0))) || ( !((delta == 0.0) && ( !(( !(t4_evt0 != 0)) && ( !(t4_evt1 != 0)))))))) && ((( !(t4_evt0 != 0)) && ( !(t4_evt1 != 0))) || ( !((delta == 0.0) && ( !(( !(t5_evt0 != 0)) && ( !(t5_evt1 != 0)))))))) && ((((gate_evt0 != 0) && ( !(gate_evt1 != 0))) == (( !(controller_evt2 != 0)) && ((controller_evt0 != 0) && (controller_evt1 != 0)))) || ( !(delta == 0.0)))) && (( !(delta == 0.0)) || (((gate_evt1 != 0) && ( !(gate_evt0 != 0))) == ((controller_evt2 != 0) && (( !(controller_evt0 != 0)) && ( !(controller_evt1 != 0))))))) && (( !(delta == 0.0)) || ((( !(controller_evt2 != 0)) && ((controller_evt0 != 0) && ( !(controller_evt1 != 0)))) == (((t5_evt0 != 0) && ( !(t5_evt1 != 0))) || (((t4_evt0 != 0) && ( !(t4_evt1 != 0))) || (((t3_evt0 != 0) && ( !(t3_evt1 != 0))) || (((t2_evt0 != 0) && ( !(t2_evt1 != 0))) || (((t0_evt0 != 0) && ( !(t0_evt1 != 0))) || ((t1_evt0 != 0) && ( !(t1_evt1 != 0))))))))))) && (( !(delta == 0.0)) || ((( !(controller_evt2 != 0)) && ((controller_evt1 != 0) && ( !(controller_evt0 != 0)))) == (((t5_evt1 != 0) && ( !(t5_evt0 != 0))) || (((t4_evt1 != 0) && ( !(t4_evt0 != 0))) || (((t3_evt1 != 0) && ( !(t3_evt0 != 0))) || (((t2_evt1 != 0) && ( !(t2_evt0 != 0))) || (((t0_evt1 != 0) && ( !(t0_evt0 != 0))) || ((t1_evt1 != 0) && ( !(t1_evt0 != 0))))))))))) && (((delta == _x__diverge_delta) || ( !(1.0 <= _diverge_delta))) && ((1.0 <= _diverge_delta) || ((delta + (_diverge_delta + (-1.0 * _x__diverge_delta))) == 0.0))));
t5_l1 = _x_t5_l1;
t5_evt1 = _x_t5_evt1;
t5_evt0 = _x_t5_evt0;
t4_l1 = _x_t4_l1;
t4_l0 = _x_t4_l0;
t5_x = _x_t5_x;
t4_evt1 = _x_t4_evt1;
t4_evt0 = _x_t4_evt0;
t3_l1 = _x_t3_l1;
t4_x = _x_t4_x;
t3_evt1 = _x_t3_evt1;
t3_l0 = _x_t3_l0;
controller_cnt = _x_controller_cnt;
t5_l0 = _x_t5_l0;
controller_evt2 = _x_controller_evt2;
controller_z = _x_controller_z;
controller_evt1 = _x_controller_evt1;
controller_evt0 = _x_controller_evt0;
controller_l1 = _x_controller_l1;
controller_l0 = _x_controller_l0;
gate_l0 = _x_gate_l0;
t3_x = _x_t3_x;
t2_evt1 = _x_t2_evt1;
delta = _x_delta;
t0_x = _x_t0_x;
t0_evt0 = _x_t0_evt0;
t0_l0 = _x_t0_l0;
t0_evt1 = _x_t0_evt1;
t1_x = _x_t1_x;
gate_y = _x_gate_y;
t0_l1 = _x_t0_l1;
t1_evt0 = _x_t1_evt0;
_diverge_delta = _x__diverge_delta;
gate_evt0 = _x_gate_evt0;
t1_l0 = _x_t1_l0;
t1_evt1 = _x_t1_evt1;
t2_x = _x_t2_x;
gate_evt1 = _x_gate_evt1;
t1_l1 = _x_t1_l1;
t2_evt0 = _x_t2_evt0;
gate_l1 = _x_gate_l1;
t2_l0 = _x_t2_l0;
t3_evt0 = _x_t3_evt0;
t2_l1 = _x_t2_l1;
}
}
|
the_stack_data/48576181.c | /*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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[] = "@(#)memcmp.c 8.1 (Berkeley) 6/4/93";
static char sccsid[] = "@(#)memset.c 8.1 (Berkeley) 6/4/93";
static char sccsid[] = "@(#)memcpy.c 8.1 (Berkeley) 6/4/93";
static char sccsid[] = "@(#)memmove.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifndef __STDC__
#define const
#endif
#include <sys/types.h>
#ifdef HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#include <limits.h>
/*
* Compare memory regions.
*/
int
memcmp(s1, s2, n)
const void *s1, *s2;
int n;
{
if (n != 0) {
register const unsigned char *p1 = s1, *p2 = s2;
do {
if (*p1++ != *p2++)
return (*--p1 - *--p2);
} while (--n != 0);
}
return (0);
}
/*
* Copy a block of memory, handling overlap.
*/
void *
memmove(dst, src, length)
void *dst;
const void *src;
register int length;
{
bcopy((const char *)src, (char *)dst, length);
return(dst);
}
#define wsize sizeof(u_int)
#define wmask (wsize - 1)
#ifdef BZERO
#define RETURN return
#define VAL 0
#define WIDEVAL 0
void
bzero(dst0, length)
void *dst0;
register int length;
#else
#define RETURN return (dst0)
#define VAL c0
#define WIDEVAL c
void *
memset(dst0, c0, length)
void *dst0;
register int c0;
register int length;
#endif
{
register int t;
register u_int c;
register u_char *dst;
dst = dst0;
/*
* If not enough words, just fill bytes. A length >= 2 words
* guarantees that at least one of them is `complete' after
* any necessary alignment. For instance:
*
* |-----------|-----------|-----------|
* |00|01|02|03|04|05|06|07|08|09|0A|00|
* ^---------------------^
* dst dst+length-1
*
* but we use a minimum of 3 here since the overhead of the code
* to do word writes is substantial.
*/
if (length < 3 * wsize) {
while (length != 0) {
*dst++ = VAL;
--length;
}
RETURN;
}
#ifndef BZERO
if ((c = (u_char)c0) != 0) { /* Fill the word. */
#ifndef UINT_MAX
UINT_MAX must be defined, try 0xFFFFFFFF;
#endif
c = (c << 8) | c; /* u_int is 16 bits. */
#if UINT_MAX > 0xffff
c = (c << 16) | c; /* u_int is 32 bits. */
#endif
#if UINT_MAX > 0xffffffff
c = (c << 32) | c; /* u_int is 64 bits. */
#endif
}
#endif
/* Align destination by filling in bytes. */
if ((t = (int)dst & wmask) != 0) {
t = wsize - t;
length -= t;
do {
*dst++ = VAL;
} while (--t != 0);
}
/* Fill words. Length was >= 2*words so we know t >= 1 here. */
t = length / wsize;
do {
*(u_int *)dst = WIDEVAL;
dst += wsize;
} while (--t != 0);
/* Mop up trailing bytes, if any. */
t = length & wmask;
if (t != 0)
do {
*dst++ = VAL;
} while (--t != 0);
RETURN;
}
|
the_stack_data/153267025.c | int main() {
char *string = "The quick brown fox";
memcpy(&string[4], "slow ", 5); // <-- not allowed!
printf("%s\n", string);
return 0;
}
|
the_stack_data/813006.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbarbari <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/05 15:15:31 by mbarbari #+# #+# */
/* Updated: 2014/11/07 17:37:26 by mbarbari ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
void ft_memdel(void **ap)
{
if (ap)
{
free(*ap);
*ap = NULL;
}
}
|
the_stack_data/82951553.c | int main()
{
int i, space, rows, k=0;
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=1; i<=rows; ++i, k=0)
{
for(space=1; space<=rows-i; ++space)
{
printf(" ");
}
while(k != 2*i-1)
{
printf("* ");
++k;
}
printf("\n");
}
return 0;
} |
the_stack_data/6824.c | /*
* Copyright (c) 2016, 2017 Pedro Falcato
* This file is part of Onyx, and is released under the terms of the MIT License
* check LICENSE at the root directory for more information
*/
#include <string.h>
#include <stdint.h>
void *memset(void *bufptr, int value, size_t size)
{
unsigned char *b = bufptr;
for(size_t s = 0; s < size; s++)
*b++ = value;
return bufptr;
}
void *memset_s(void *s, int c, size_t n)
{
return memset(s, c, n);
}
|
the_stack_data/457747.c | /*
A C-program for MT19937, with initialization improved 2002/1/26.
Coded by Takuji Nishimura and Makoto Matsumoto.
Before using, initialize the state by using init_genrand(seed)
or init_by_array(init_key, key_length).
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
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. The names of its contributors may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 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.
Any feedback is very welcome.
http://www.math.keio.ac.jp/matumoto/emt.html
email: [email protected]
*/
#include <stdio.h>
/* Period parameters */
#define N 624
#define M 397
#define MATRIX_A 0x9908b0dfUL /* constant vector a */
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
static unsigned long mt[N]; /* the array for the state vector */
static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */
/* initializes mt[N] with a seed */
void init_genrand(unsigned long s)
{
mt[0]= s & 0xffffffffUL;
for (mti=1; mti<N; mti++) {
mt[mti] =
(1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
/* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array mt[]. */
/* 2002/01/09 modified by Makoto Matsumoto */
mt[mti] &= 0xffffffffUL;
/* for >32 bit machines */
}
}
/* initialize by an array with array-length */
/* init_key is the array for initializing keys */
/* key_length is its length */
void init_by_array(unsigned long init_key[], int key_length)
{
int i, j, k;
init_genrand(19650218UL);
i=1; j=0;
k = (N>key_length ? N : key_length);
for (; k; k--) {
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))
+ init_key[j] + j; /* non linear */
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
i++; j++;
if (i>=N) { mt[0] = mt[N-1]; i=1; }
if (j>=key_length) j=0;
}
for (k=N-1; k; k--) {
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))
- i; /* non linear */
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
i++;
if (i>=N) { mt[0] = mt[N-1]; i=1; }
}
mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
}
/* generates a random number on [0,0xffffffff]-interval */
unsigned long genrand_int32(void)
{
unsigned long y;
static unsigned long mag01[2]={0x0UL, MATRIX_A};
/* mag01[x] = x * MATRIX_A for x=0,1 */
if (mti >= N) { /* generate N words at one time */
int kk;
if (mti == N+1) /* if init_genrand() has not been called, */
init_genrand(5489UL); /* a default initial seed is used */
for (kk=0;kk<N-M;kk++) {
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
}
for (;kk<N-1;kk++) {
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
}
y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
mti = 0;
}
y = mt[mti++];
/* Tempering */
y ^= (y >> 11);
y ^= (y << 7) & 0x9d2c5680UL;
y ^= (y << 15) & 0xefc60000UL;
y ^= (y >> 18);
return y;
}
/* generates a random number on [0,0x7fffffff]-interval */
long genrand_int31(void)
{
return (long)(genrand_int32()>>1);
}
/* generates a random number on [0,1]-real-interval */
double genrand_real1(void)
{
return genrand_int32()*(1.0/4294967295.0);
/* divided by 2^32-1 */
}
/* generates a random number on [0,1)-real-interval */
double genrand_real2(void)
{
return genrand_int32()*(1.0/4294967296.0);
/* divided by 2^32 */
}
/* generates a random number on (0,1)-real-interval */
double genrand_real3(void)
{
return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0);
/* divided by 2^32 */
}
/* generates a random number on [0,1) with 53-bit resolution*/
double genrand_res53(void)
{
unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6;
return(a*67108864.0+b)*(1.0/9007199254740992.0);
}
/* These real versions are due to Isaku Wada, 2002/01/09 added */
/* This main() outputs 2000 generated integers and reals. */
/*
int main(void)
{
int i;
unsigned long init[4]={0x123, 0x234, 0x345, 0x456}, length=4;
init_by_array(init, length);
printf("1000 outputs of genrand_int32()\n");
for (i=0; i<1000; i++) {
printf("%10lu ", genrand_int32());
if (i%5==4) printf("\n");
}
printf("\n1000 outputs of genrand_real2()\n");
for (i=0; i<1000; i++) {
printf("%10.8f ", genrand_real2());
if (i%5==4) printf("\n");
}
return 0;
}
*/
|
the_stack_data/579074.c | #include <stdio.h>
int LinearSearch(int arr[], int length, int target){
for(int i=0; i<length; ++i){
if(arr[i]==target){
return i;
}
}
return -1;
}
void Print(int arr[], int length){
for(int i=0; i<length; ++i){
printf("%d ", arr[i]);
}
printf("\n");
}
int main()
{
int arr[10] = {-2, 94, 7, -90, -34, 30, 24, 3, 100, -23};
Print(arr, 10);
int index = LinearSearch(arr, 10, 30);
printf("Target at index: ");
printf("%d\n", index);
return 0;
}
|
the_stack_data/159516042.c | /* Array Privatization Example
The variable t is an array used temporarily during a single iteration of the
outer loop. No value of t is used in an iteration other than the one that
produced it. Without privatization, executing different iterations in
parallel would create conflicts on accesses to t. Declaring t private gives
each thread a separate storage space, avoiding these conflicts.
*/
int main(){
float a[1000][1000], b[1000][1000], t[1000];
int i, j;
for (i=1; i<1000; i++) {
for (j=1; j<1000; j++) {
t[j] = a[i][j]+b[i][j];
}
for (j=1; j<1000; j++) {
b[i][j] = t[j] + sqrt(t[j]);
}
}
return 0;
}
|
the_stack_data/1209726.c | /*
* Copyright (c) 2013 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* string/strcoll_l.c
* Compare two strings using the given locale.
*/
#include <string.h>
int strcoll_l(const char* s1, const char* s2, locale_t locale)
{
(void) locale;
return strcoll(s1, s2);
}
|
the_stack_data/242331740.c | /*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define _GNU_SOURCE
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <stdbool.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/resource.h>
#include <sys/mount.h>
#include <sys/sendfile.h>
#include <sys/signalfd.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
static void wipe_directory(char *path) {
DIR *d = opendir(path);
if (d == NULL) {
printf("opendir(%s): %m\n", path);
return;
}
struct dirent *dent;
while ((dent = readdir(d)) != NULL) {
if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0)
continue;
if (unlinkat(dirfd(d), dent->d_name, 0))
printf("unable to unlink %s/%s: %m\n", path, dent->d_name);
}
closedir(d);
if (rmdir(path))
printf("unable to unlink %s: %m\n", path);
}
int main(void) {
setbuf(stdout, NULL);
setbuf(stderr, NULL);
signal(SIGCHLD, SIG_IGN);
if (mount("none", "/proc", "proc", MS_NODEV|MS_NOEXEC|MS_NOSUID, ""))
err(1, "mount procfs");
if (mount("none", "/tmp", "tmpfs", MS_NODEV|MS_NOEXEC|MS_NOSUID, ""))
err(1, "mount /tmp");
if (chdir("/tmp"))
err(1, "chdir /tmp");
int s = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (s == -1) err(1, "socket");
int one = 1;
if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)))
err(1, "SO_REUSEPORT");
struct sockaddr_in addr = {
.sin_family = AF_INET,
.sin_port = htons(1234),
.sin_addr = { .s_addr = htonl(0) }
};
if (bind(s, (struct sockaddr *)&addr, sizeof(addr))) err(1, "bind");
if (listen(s, 16)) err(1, "listen");
sigset_t sigchld_mask;
if (sigemptyset(&sigchld_mask)) err(1, "sigemptyset");
if (sigaddset(&sigchld_mask, SIGCHLD)) err(1, "sigaddset");
if (sigprocmask(SIG_BLOCK, &sigchld_mask, NULL)) err(1, "sigprocmask");
int sigfd = signalfd(-1, &sigchld_mask, SFD_CLOEXEC|SFD_NONBLOCK);
if (sigfd == -1) err(1, "signalfd");
while (1) {
int c = accept(s, NULL, NULL);
if (c == -1) {
/* not fatal, errors on a not-yet-accepted socket can cause this */
perror("unable to accept connection");
continue;
}
/* we have a new connection, spawn a child to handle it */
write(c, "launching child process...\n", 27);
pid_t child = fork();
if (child == 0) {
if (dup2(c, 0) == -1) err(1, "dup2");
if (dup2(c, 1) == -1) err(1, "dup2");
if (dup2(c, 2) == -1) err(1, "dup2");
close(s);
close(c);
alarm(60);
printf("please select an unguessable working directory for yourself, or specify an existing one:\n> ");
char wd_name[100];
for (int i=0; ; i++) {
if (i == sizeof(wd_name))
errx(1, "wd_name too long");
char c;
if (read(0, &c, 1) != 1)
err(1, "reading working directory name");
if (c == '\n') {
if (i < 10)
errx(1, "working directory name too short");
wd_name[i] = '\0';
break;
} else if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ' ' || c == '_') {
wd_name[i] = c;
} else {
errx(1, "bad char '%c'", c);
}
}
bool created = (mkdir(wd_name, 0700) == 0);
if (!created && errno != EEXIST) err(1, "mkdir");
if (chdir(wd_name)) err(1, "enter workdir");
if (created) {
printf("copying flagdb\n");
int orig_fd = open("/flagdb", O_RDONLY|O_CLOEXEC);
if (orig_fd == -1) err(1, "unable to open orig flagdb");
int copy_fd = open("flagdb", O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0600);
if (copy_fd == -1) err(1, "unable to open copy flagdb");
struct stat st;
if (fstat(orig_fd, &st)) err(1, "fstat");
if (sendfile(copy_fd, orig_fd, NULL, st.st_size) != st.st_size)
err(1, "unable to copy flagdb");
close(orig_fd);
close(copy_fd);
}
struct rlimit rlim_core = { .rlim_cur = 0, .rlim_max = 0 };
if (setrlimit(RLIMIT_CORE, &rlim_core)) err(1, "RLIMIT_CORE");
struct rlimit rlim_fsize = { .rlim_cur = 10000, .rlim_max = 10000 };
if (setrlimit(RLIMIT_FSIZE, &rlim_fsize)) err(1, "RLIMIT_FSIZE");
execl("/bin/database", "database", NULL);
err(1, "execute database");
}
if (child == -1) {
perror("fork handler child");
write(c, "fork failed\n", 12);
}
close(c);
/* try to delete anything older than 60s */
time_t old_time = time(NULL) - 60;
DIR *tmpdir = opendir(".");
if (!tmpdir) {
perror("temporary error opening /tmp");
continue;
}
struct dirent *tmp_dent;
while ((tmp_dent = readdir(tmpdir)) != NULL) {
if (strcmp(tmp_dent->d_name, ".") == 0 || strcmp(tmp_dent->d_name, "..") == 0)
continue;
struct stat st;
if (stat(tmp_dent->d_name, &st)) {
perror("stat /tmp entry");
continue;
}
if (st.st_ctime > old_time)
continue;
printf("cleaning up '%s'\n", tmp_dent->d_name);
wipe_directory(tmp_dent->d_name);
}
closedir(tmpdir);
}
} |
the_stack_data/72011970.c | #include <stdio.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <pwd.h>
#include <signal.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <grp.h>
int changePrivByUname(char *username) {
struct passwd *pw = getpwnam(username);
if (pw == NULL) {
fprintf(stderr, "User %s does not exist\n", username);
return 1;
}
if (setgroups(0, NULL) != 0) {
perror("setgroups");
return 1;
}
if (setgid(pw->pw_gid) != 0) {
perror("setgid");
return 1;
}
if (setuid(pw->pw_uid) != 0) {
perror("setuid");
return 1;
}
return 0;
}
void perrorAndExit(char* s){
perror(s);
exit(-1);
}
void handler(int signum){
perrorAndExit("timeout~");
}
int readAInt(){
char tmps[13];
if(read(STDIN_FILENO,tmps,12)<=0){
perrorAndExit("read error!");
}
return atoi(tmps);
}
void setNoBufAndTimeout(int time){
setvbuf(stdout,0,_IONBF,0);
setvbuf(stdin,0,_IONBF,0);
setvbuf(stderr,0,_IONBF,0);
signal(SIGALRM,handler);
alarm(time);
}
int readNbytes(char*s ,size_t len,char endC){
char tmpc;
int i = 0;
for(;i < len-1;i++){
if(read(STDIN_FILENO,&tmpc,1)<=0)
perrorAndExit("read error!");
if(tmpc==0x0a){
s[i]=0;
break;
}
s[i]=tmpc;
}
s[i]=0;
return i;
}
int readNbytesEndWith0A(char* s,size_t len){
return readNbytes(s,len,'\n');
}
|
the_stack_data/36361.c | int romanCharToInt(char c) {
switch (c) {
case 'I': return 1;
case 'V': return 5;
case 'X': return 10;
case 'L': return 50;
case 'C': return 100;
case 'D': return 500;
case 'M': return 1000;
default: return 0;
}
}
int romanToInt(char * s) {
if (strlen(s) == 0) {return 0;}
int sum = 0, cacheSum = 0;
for (int i = 0; i < strlen(s) - 1; i ++) {
int thisValue = romanCharToInt(s[i]);
int nextValue = romanCharToInt(s[i + 1]);
if (nextValue > thisValue) {
cacheSum += thisValue;
} else {
sum -= cacheSum;
cacheSum = 0;
sum += thisValue;
}
}
sum -= cacheSum;
sum += romanCharToInt(s[strlen(s) - 1]);
return sum;
}
|
the_stack_data/119196.c | #include <assert.h>
struct B {
int b1;
int b2;
void (*f)(void);
};
struct A {
int a;
int c;
struct B *b;
};
void foo(int a, struct A *a2) {
if (a < 0)
assert(0);
if (a2->c != 3)
assert(0);
if (a2->a == a2->c)
assert(0);
a2->b[a2->a-1].b1=4;
}
|
the_stack_data/11427.c | int main(int argc, char **argv)
{
double dset1[] = { 199809., 200665., 199607., 200270., 199649. };
double dset2[] = { 522573., 244456., 139979., 71531., 21461. };
double *dsets[] = { dset1, dset2 };
int dslens[] = { 5, 5 };
int k, l;
double dist, prob;
int dof;
for (k=0; k<2; k++) {
printf("Dataset: [ ");
for(l=0;l<dslens[k]; l++)
printf("%.0f, ", dsets[k][l]);
printf("]\n");
dist = chi2UniformDistance(dsets[k], dslens[k]);
dof = dslens[k]-1;
printf("dof: %d distance: %.4f", dof, dist);
prob = chi2Probability( dof, dist );
printf(" probability: %.6f", prob);
printf(" uniform? %s\n", chiIsUniform(dsets[k], dslens[k], 0.05)? "Yes":"No");
}
return 0;
}
|
the_stack_data/140765163.c | #include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <regex.h>
#include <time.h>
#define MAX_BUF 256
void chomp(char *str){
int len;
len = strlen(str);
if((len > 0) && (str[len - 1] == '\n')){
str[len - 1] = '\0';
}
return;
}
void scan(char *socks_ipaddr, char *socks_port, char *signature,
char *uri_proto, char *uri_hostname, char *uri_ipaddr, char *uri_path){
struct sockaddr_in addr;
int sock;
char recv_buf[MAX_BUF];
char header[MAX_BUF*2];
int recv_len, err;
SSL *ssl;
SSL_CTX *ctx;
clock_t start_time, end_time;
start_time = clock();
if((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1){
perror("socket");
exit(EXIT_FAILURE);
}
addr.sin_family = AF_INET;
addr.sin_port = htons(atoi(socks_port));
addr.sin_addr.s_addr = inet_addr(socks_ipaddr);
if(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1){
perror("connect");
goto CONNECTION_END;
};
char first_request[] = {
0x05, /* socks version */
0x01, /* auth list num */
0x00 /* unencessary authentication */
};
send(sock, first_request, sizeof(first_request), 0);
recv_len = recv(sock, recv_buf, MAX_BUF, 0);
if( recv_len > 0 ){
if(recv_buf[0] != 0x05){
printf("[!] Invalid socks version\n");
goto CONNECTION_END;
}
if(recv_buf[1] != 0x00){
printf("[!] Invalid authentication method\n");
goto CONNECTION_END;
}
char second_request[MAX_BUF] = {
0x05, /* socks version */
0x01, /* connect method */
0x00, /* reserved */
0x01 /* ip v4 */
};
addr.sin_port = htons(443);
addr.sin_addr.s_addr = inet_addr(uri_ipaddr);
memcpy(second_request + 4, &addr.sin_addr.s_addr, 4);
memcpy(second_request + 8, &addr.sin_port, 2);
send(sock, second_request, 10, 0);
memset(recv_buf, '\0', MAX_BUF);
recv_len = recv(sock, recv_buf, 10, 0);
if ( recv_len <= 0 ){
goto CONNECTION_END;
}
SSL_load_error_strings();
SSL_library_init();
ctx = SSL_CTX_new(SSLv23_client_method());
ssl = SSL_new(ctx);
err = SSL_set_fd(ssl, sock);
SSL_connect(ssl);
sprintf(header, "GET /%s HTTP/1.1\r\nHost: %s\r\n\r\n",
uri_path, uri_hostname);
SSL_write(ssl, header, strlen(header));
int buf_size = 256;
char buf[buf_size];
int read_size;
do {
read_size = SSL_read(ssl, buf, buf_size);
//write(1, buf, read_size);
} while(read_size > 0);
end_time = clock();
if(strstr(buf, signature) != NULL){
printf("OK %dms %s:%s\n",
end_time - start_time, socks_ipaddr, socks_port);
}
SSL_shutdown(ssl);
SSL_free(ssl);
SSL_CTX_free(ctx);
ERR_free_strings();
}
CONNECTION_END:
close(sock);
}
void uriparse(char *uri, char **uri_proto, char **uri_hostname, char **uri_path){
const char *re = "^([^/]+?)://([^/]+?)/?(.*)$";
regex_t regbuf;
regmatch_t regmatch[4];
regcomp(®buf, re, REG_EXTENDED);
regexec(®buf, uri, 4, regmatch, 0);
//get proto
if (regmatch[1].rm_so >= 0 && regmatch[1].rm_eo >= 0) {
int start = regmatch[1].rm_so;
int end = regmatch[1].rm_eo;
int size = end - start;
char buf[size];
int i=0,j=0;
for(i=start; i<end; i++,j++){
buf[j] = uri[i];
}
buf[size] = '\0';
*uri_proto = (char *)malloc(sizeof(char) * size);
strcpy(*uri_proto, buf);
}
// get host
if (regmatch[2].rm_so >= 0 && regmatch[2].rm_eo >= 0) {
int start = regmatch[2].rm_so;
int end = regmatch[2].rm_eo;
int size = end - start;
char buf[size];
int i=0,j=0;
for(i=start; i<end; i++,j++){
buf[j] = uri[i];
}
buf[size] = '\0';
*uri_hostname = (char *)malloc(sizeof(char) * size);
strcpy(*uri_hostname, buf);
}
// get path
if (regmatch[3].rm_so >= 0 && regmatch[3].rm_eo >= 0) {
int start = regmatch[3].rm_so;
int end = regmatch[3].rm_eo;
int size = end - start;
char buf[size];
int i=0,j=0;
for(i=start; i<end; i++,j++){
buf[j] = uri[i];
}
buf[size] = '\0';
*uri_path = (char *)malloc(sizeof(char) * size);
strcpy(*uri_path, buf);
}
}
int main(int argc, char *argv[]){
int opts;
char *target_list;
char *uri;
char *signature;
FILE *fp;
char line[MAX_BUF];
char *uri_proto, *uri_hostname, *uri_ipaddr, *uri_path;
struct hostent* uri_hostent;
while((opts=getopt(argc, argv, "l:u:s:")) != -1){
switch(opts){
case 'l':
target_list = optarg;
break;
case 'u':
uri = optarg;
break;
case 's':
signature = optarg;
break;
default:
break;
}
}
uriparse(uri, &uri_proto, &uri_hostname, &uri_path);
fprintf(stderr, "[+] TARGET_LIST : %s\n", target_list);
fprintf(stderr, "[+] SIGNATURE : %s\n", signature);
fprintf(stderr, "[+] URI : %s\n", uri);
fprintf(stderr, "[+] URI_PROTO : %s\n", uri_proto);
fprintf(stderr, "[+] URI_HOSTNAME : %s\n", uri_hostname);
fprintf(stderr, "[+] URI_PATH : %s\n", uri_path);
if(strcmp(uri_proto, "https") != 0){
fprintf(stderr, "[+] URI_PATH : %s\n", uri_path);
}
uri_hostent = gethostbyname(uri_hostname);
if(uri_hostent == NULL){
perror("gethostbyname");
exit(EXIT_FAILURE);
}
uri_ipaddr = inet_ntoa(*(struct in_addr*)(uri_hostent->h_addr_list[0]));
fprintf(stderr, "[+] URI_IPADDR : %s\n", uri_ipaddr);
if((fp = fopen(target_list, "r")) == NULL){
perror("fopen");
exit(EXIT_FAILURE);
}
while((fgets(line, MAX_BUF, fp)) != NULL){
char *socks_ipaddr, *socks_port;
chomp(line);
socks_ipaddr = strtok(line, ":");
socks_port = strtok(NULL, ":");
scan(socks_ipaddr, socks_port, signature, uri_proto, uri_hostname, uri_ipaddr, uri_path);
}
free(uri_proto);
free(uri_hostname);
free(uri_path);
fclose(fp);
return 0;
}
|
the_stack_data/6386827.c | #include <stdio.h>
int arr[30] = { 1, 6, 2 };
int find_series(int num)
{
int i;
for (i = 3; i < num; i++)
{
if (i % 2)
{
arr[i] = arr[i - 1] + arr[i - 3];
printf("홀 ");
}
else
{
arr[i] = arr[i - 1] - arr[i - 3];
printf("짝 ");
}
printf("검토용 arr[%d] = %d\n", i, arr[i]);
}
return arr[num - 1];
}
int main(void)
{
int res = find_series(20);
printf("res = %d\n", res);
}
|
the_stack_data/4577.c | #include <stdio.h>
int main(){
int n, fat=1, i=1;
printf("Enter number: \n");
scanf("%d", &n);
//if/else/for version
// if(n<0){
// printf("negative numbers no can do.\n");
// }
// else{
// if(n==0){
// fat=0;
// }
// else{
// for(i; i<=n; i++){
// fat = fat * i;
// }
// }
// printf("%d factorial = %d\n", n, fat);
// }
//if/else/do/while version
// if(n<0){
// printf("negative number no can do.\n");
// }
// else{
// if(n==0){
// fat=1;
// }
// else{
// do{
// fat = fat * i;
// i++;
// }
// while(i <= n);
// }
// printf("%d factorial = %d\n", n, fat);
// }
//if/else/while version
if(n<0){
prinf("negative number no acn do.\n");
}
else{
i = n;
while(i!=0){
fat = fat * i;
i--;
}
printf("%d factorial = %d\n", n, fat);
}
return 0;
} |
the_stack_data/314393.c | #include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#define SIZE 1024
char buf[SIZE];
#define TIME_PORT 8189
int sockfd, client_sockfd;
void intHandler(int dummy) {
close(client_sockfd);
close(sockfd);
exit(1);
}
int main(int argc, char *argv[]) {
int sockfd, client_sockfd;
int nread, len;
struct sockaddr_in serv_addr, client_addr;
time_t t;
signal(SIGINT, intHandler);
/* create endpoint */
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror(NULL); exit(2);
}
/* bind address */
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(TIME_PORT);
if (bind(sockfd,
(struct sockaddr *) &serv_addr,
sizeof(serv_addr)) < 0) {
perror(NULL); exit(3);
}
/* specify queue */
listen(sockfd, 5);
for (;;) {
len = sizeof(client_addr);
client_sockfd = accept(sockfd,
(struct sockaddr *) &client_addr,
&len);
if (client_sockfd == -1) {
perror(NULL); continue;
}
printf("Client connected\n");
while ((nread = read(client_sockfd, buf, SIZE-1)) > 0) {
int n;
buf[nread] = '\0';
for (n = 0; n < strlen(buf); n++)
fprintf(stdout, "%X ", buf[n]);
fputs("\n", stdout);
fputs(buf, stdout);
fflush(stdout);
}
close(client_sockfd);
}
}
|
the_stack_data/13974.c | /* Generated by CIL v. 1.7.0 */
/* print_CIL_Input is false */
struct _IO_FILE;
struct timeval;
extern float strtof(char const *str , char const *endptr ) ;
extern void signal(int sig , void *func ) ;
typedef struct _IO_FILE FILE;
extern int atoi(char const *s ) ;
extern double strtod(char const *str , char const *endptr ) ;
extern int fclose(void *stream ) ;
extern void *fopen(char const *filename , char const *mode ) ;
extern void abort() ;
extern void exit(int status ) ;
extern int raise(int sig ) ;
extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ;
extern int strcmp(char const *a , char const *b ) ;
extern int rand() ;
extern unsigned long strtoul(char const *str , char const *endptr , int base ) ;
void RandomFunc(unsigned int input[1] , unsigned int output[1] ) ;
extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ;
extern int gettimeofday(struct timeval *tv , void *tz , ...) ;
extern int printf(char const *format , ...) ;
int main(int argc , char *argv[] ) ;
void megaInit(void) ;
extern unsigned long strlen(char const *s ) ;
extern long strtol(char const *str , char const *endptr , int base ) ;
extern unsigned long strnlen(char const *s , unsigned long maxlen ) ;
extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ;
struct timeval {
long tv_sec ;
long tv_usec ;
};
extern void *malloc(unsigned long size ) ;
extern int scanf(char const *format , ...) ;
int main(int argc , char *argv[] )
{
unsigned int input[1] ;
unsigned int output[1] ;
int randomFuns_i5 ;
unsigned int randomFuns_value6 ;
int randomFuns_main_i7 ;
{
megaInit();
if (argc != 2) {
printf("Call this program with %i arguments\n", 1);
exit(-1);
} else {
}
randomFuns_i5 = 0;
while (randomFuns_i5 < 1) {
randomFuns_value6 = (unsigned int )strtoul(argv[randomFuns_i5 + 1], 0, 10);
input[randomFuns_i5] = randomFuns_value6;
randomFuns_i5 ++;
}
RandomFunc(input, output);
if (output[0] == 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 local2 ;
unsigned int local1 ;
{
state[0UL] = (input[0UL] - 51238316UL) - 339126204U;
local1 = 0UL;
while (local1 < 1UL) {
local2 = 0UL;
while (local2 < 1UL) {
state[local1] |= state[local2];
state[0UL] = state[local1] ^ state[local2];
local2 += 2UL;
}
local1 ++;
}
output[0UL] = state[0UL] + 1610845808U;
}
}
void megaInit(void)
{
{
}
}
|
the_stack_data/72013423.c | /*
* Copyright (c) 2010 Intel Corporation. All rights reserved.
* Copyright (c) Imagination Technologies Limited, UK
* Redistribution. Redistribution and use in binary form, without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions must reproduce the above copyright notice and the following
* disclaimer in the documentation and/or other materials provided with the
* distribution.Neither the name of Intel Corporation nor the names of its
* suppliers may be used to endorse or promote products derived from this
* software without specific prior written permission. No reverse engineering,
* decompilation, or disassembly of this software is permitted.
* Limited patent license. Intel Corporation grants a world-wide, royalty-free,
* non-exclusive license under patents it now or hereafter owns or controls
* to make, have made, use, import,offer to sell and sell ("utilize") this
* software, but solely to the extent that any such patent is necessary to
* Utilize the software alone. The patent license shall not apply to any
* combinations which include this software. No hardware per se is licensed hereunder.
*
* DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 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.
*/
// This file was automatically generated from ../release/H264MasterFirmwareVBR.dnl using dnl2c.
unsigned char *szH264MasterFirmwareVBR_buildtag="BUILD_TOPAZ_SC_1_00_00_0327";
unsigned long ui32H264VBR_MasterMTXTOPAZFWTextSize = 3881;
unsigned long ui32H264VBR_MasterMTXTOPAZFWDataSize = 604;
unsigned long ui32H264VBR_MasterMTXTOPAZFWTextRelocSize = 0;
unsigned long ui32H264VBR_MasterMTXTOPAZFWDataRelocSize = 0;
unsigned long ui32H264VBR_MasterMTXTOPAZFWTextOrigin = 0x80900000;
unsigned long ui32H264VBR_MasterMTXTOPAZFWDataOrigin = 0x82883cc0;
unsigned long aui32H264VBR_MasterMTXTOPAZFWText[] =
{
0x9040c001,
0xc80993fe,
0xc0000e42,
0xc8290e00,
0xc4628422,
0xc8298440,
0xc3cc8622,
0x9e838600,
0xc8099e43,
0xc7920d42,
0xc8090d20,
0xc7920942,
0xc8090960,
0xc00a0e42,
0xc8090e40,
0xc00e87c2,
0x9c1887d0,
0x0c020802,
0x09820d82,
0x09020d02,
0x08820c82,
0x9320fffe,
0xa401c838,
0x0dc2c809,
0x0de0c790,
0x0e42c809,
0x0b46b080,
0x7e74b77f,
0xa48d0882,
0xffff9ff3,
0x9d1393e0,
0xf8398081,
0x0707a205,
0x06850307,
0x03839e97,
0x0fa0060f,
0x018d058d,
0x9c62008f,
0x9340ffff,
0x0ea0060b,
0xffff9c62,
0x058d93a0,
0xb700018d,
0xb780540c,
0x9c015394,
0x0687a605,
0x0ea0060b,
0xffff9c62,
0xf9f893a0,
0xf9f8aa9d,
0x9c22aa1d,
0xa6059c22,
0x85028420,
0xb55f0a82,
0x850a7f7c,
0x9c89c037,
0x9c80c971,
0x75002a08,
0x9184c000,
0x9979c014,
0x450cb780,
0xc0007500,
0x0d8290a4,
0x9998c054,
0x7f6cb79f,
0xc0007500,
0xc05490e4,
0x0d8a99a0,
0x998ec054,
0x8d80e032,
0x99b2c014,
0x0800e000,
0x91c4c000,
0x9abcc014,
0x450cb780,
0x2a797402,
0x450cb580,
0x90e4c000,
0x9100c000,
0xc0149e83,
0x75409a2f,
0x9162fffe,
0x7eeeb79f,
0x7f6eb7bf,
0x9c228c60,
0x85028702,
0x6818b543,
0x6898b543,
0x6918b543,
0x6c18b543,
0x6c98b543,
0x6d18b543,
0x4d18b542,
0x7218b543,
0x4784b540,
0x4804b540,
0x4884b540,
0x4904b540,
0x4984b540,
0x4b84b540,
0x4c04b540,
0x4c84b540,
0x4202b540,
0x4282b540,
0x4f84b540,
0x7a84b540,
0x4e04b540,
0x4602b540,
0xa6059c22,
0xfff48420,
0x0d8a9b8b,
0x9938c054,
0x9bcafff4,
0x9943c054,
0x0cd2c420,
0xb4810a02,
0xb105c000,
0x0d8a4220,
0x8d80e031,
0x9aebc014,
0x0922c829,
0x0920c462,
0x7f6cb73f,
0x2a5ed071,
0x448cb580,
0x2a80c01e,
0xf0088502,
0x7102a8c2,
0x5a95c280,
0x458cb5a0,
0x4434b341,
0xb5407640,
0xb520451c,
0xc000440c,
0xd01190c2,
0xf0080e12,
0xb780a241,
0xc807548c,
0xc57008c2,
0xc0320880,
0xb5800caa,
0xb421530c,
0x0a2ac000,
0xb4810cf4,
0x1a28c000,
0xc0020902,
0xb96008ba,
0xc2004078,
0xd2240a00,
0xb441588b,
0xce00c000,
0xffff0a11,
0xe0009301,
0xffff1884,
0xc8079244,
0xc5760a42,
0xc0320a00,
0xb4810caa,
0x0a02c000,
0x09020882,
0xb9600884,
0xc2004078,
0xd2240a00,
0xb441588b,
0xce00c000,
0xffff0a11,
0xc0049301,
0xffff745a,
0x0a02923c,
0x0c9ec034,
0xc000b481,
0x9b11fff4,
0xb79f0802,
0xb7bf7eee,
0x8c607f6e,
0x9e549c22,
0x0c82c040,
0xb4219e59,
0xc040c000,
0xb4820d02,
0x9c22c000,
0x2d7cc00e,
0x29e0c00e,
0x9e545d30,
0x0c82c040,
0xb46131b8,
0xc040c000,
0xb4420d02,
0x9c22c000,
0x8420a60d,
0x06870703,
0x5c8dc280,
0xd0a21c84,
0x02875ca0,
0x0a5ed011,
0x5a0dc200,
0xc2001a04,
0x5cd05a30,
0x9e4c3098,
0xc0320405,
0x30980c8a,
0x3880c801,
0xc000b421,
0xc8019ea9,
0xc0020a02,
0x65530a00,
0x0c8ac030,
0xc000b481,
0x0882c002,
0xb4210c84,
0x9e93c000,
0x5f09d022,
0x5d0d9e53,
0xfff41d04,
0xc2809bb4,
0x1e845e91,
0x5e84c280,
0x1a849e6c,
0x5a90c280,
0x3a80c181,
0x09820d8a,
0x314a0d02,
0x9baefff4,
0x0d82c0c0,
0xc0020992,
0xc0020d02,
0xc0540902,
0x0a0a9862,
0x0c9ec034,
0xc000b481,
0x75bf1b04,
0xc0008502,
0x9dcf9202,
0x7f7cb55f,
0x9835c054,
0xa045f231,
0x7f7cb75f,
0x75bf1b04,
0xffff8510,
0xc0029284,
0xc0300a42,
0xb4810c8e,
0xb79fc000,
0xb7bf7e6e,
0xb7df7eee,
0xc0027f6e,
0x9c228c00,
0xf8399c22,
0xb780a285,
0x0986448c,
0x0d0270c8,
0x9096c001,
0x4514b760,
0x08020c06,
0x0902c1cc,
0x19c4d010,
0x9e5d9e44,
0x508cc200,
0xc0007942,
0xd1249202,
0xc400588b,
0xb4013c80,
0xb104c000,
0x9e554220,
0x750230d2,
0x4822b321,
0xc00c9e8a,
0x09840900,
0x9101ffff,
0x4514b540,
0xaa9df9f8,
0xc2009c22,
0xc0378502,
0xc1719c89,
0xc8179c80,
0x9c229c80,
0xb780a605,
0x9e5d450c,
0xc000790a,
0xfff49162,
0xfff49bf0,
0xb7809bbe,
0x790a450c,
0x9324ffff,
0x7f6eb79f,
0x7feeb7bf,
0x9c228c40,
0xc002a61d,
0x9e5d8400,
0xaa21f208,
0xc0017500,
0xc4209004,
0x0a020cda,
0xc000b481,
0x4220b101,
0xb4811c84,
0xb106c000,
0xb4814220,
0xb107c000,
0x008f4220,
0xc000b481,
0x4240b106,
0xc000b481,
0x4240b105,
0x2a6ed1f1,
0xb40d7516,
0xf2084622,
0x7480a921,
0x92c2c000,
0x8c80e092,
0x098a0dc2,
0x0d02c002,
0x9b0afff4,
0x7cecb7df,
0x7c6cb79f,
0x7d6cb7ff,
0x7df4b7df,
0x7e74b7bf,
0xa221f208,
0x5aa1c300,
0x2afcc00e,
0x0d869ea9,
0xfff455e4,
0xd3129ba3,
0xc1c068d1,
0x5c8b0c80,
0xc000b4c1,
0x6951d312,
0x0d10c1c0,
0xb4e25d0b,
0xd312c000,
0x9e7468d1,
0x0ca0c1c0,
0xb4815c8b,
0xd312c000,
0x9e6c6951,
0x0d30c1c0,
0xb4825d0b,
0xd312c000,
0x0a0268d1,
0x0cc0c1c0,
0xc4005c8b,
0xb4813c80,
0xb106c000,
0xcfff4220,
0xd3122b7c,
0xc1c068d1,
0x5c8b0cc0,
0xc000b4c1,
0x450cb720,
0xc2000a04,
0x000b5214,
0xb5203098,
0xb79f450c,
0xb7bf7c6e,
0xb7df7cee,
0xb7ff7d6e,
0xc0047dee,
0x9c228c00,
0xa205f839,
0x0e30f011,
0x919cc000,
0x9ea10a04,
0x55e40d86,
0xc0343d88,
0x0d8a9b3d,
0x9b3ac034,
0xaa1df9f8,
0xa6059c22,
0x0a42c801,
0x0a00c010,
0x2ebed3f2,
0x0caac032,
0xc000b481,
0x0cf408aa,
0xc000b421,
0x550cb780,
0x0c92c080,
0xa881f208,
0xc000b421,
0x550cb780,
0xf2080c88,
0xb421a889,
0xb780c000,
0x0c84550c,
0xa88df208,
0xc000b421,
0x1c980902,
0xc000b441,
0x550cb780,
0xf2080c90,
0xb421a885,
0xb7a0c000,
0x0dd2550c,
0x9af5c034,
0xaa25f208,
0xffff7008,
0x0daa9344,
0x0d060982,
0x0902c121,
0x9a4afff4,
0x4694b760,
0x0d02c021,
0x09c20d04,
0x9a37fff4,
0x4694b760,
0x0d0609c2,
0x9a31fff4,
0x09820daa,
0xc1010d02,
0xfff40902,
0x0d929a35,
0x9ad1c034,
0xaa25f208,
0xffff7008,
0x77409344,
0x90a2c000,
0xc0340d8e,
0x0d8a9ad3,
0x9ad0c034,
0x7f6eb79f,
0x7feeb7bf,
0x9c228c40,
0xc470a60d,
0x0a020c8e,
0xc000b481,
0x4220b101,
0x550cb780,
0xa085f208,
0x0a021c8c,
0xc000b481,
0x4220b105,
0x2b5ed1f1,
0x550cb780,
0xcff09ead,
0xc2802e80,
0xf2085ea1,
0xc280a281,
0x2a845a9d,
0x0a020c84,
0xc000b481,
0x4220b101,
0x460cb520,
0xb4810c84,
0xb101c000,
0xb5204220,
0xc070468c,
0xb4810c8e,
0x0882c000,
0xb4211c8c,
0x0c90c000,
0xc000b481,
0xb4211c8c,
0x0c84c000,
0xc000b481,
0x6104b740,
0x5908d326,
0xe0309e2d,
0x9ea4aa4d,
0xb7809c62,
0x7740550c,
0x9ea98502,
0xd0010d82,
0xf2080db2,
0x2596a10f,
0x9b3ffff4,
0xc0700a06,
0xb4810c82,
0x000dc000,
0x7eeeb79f,
0x7f6eb7bf,
0x7feeb7df,
0x9c228c60,
0x4494b760,
0xc0020a7f,
0x9ea18502,
0x89afe220,
0xfff355ad,
0xc01c91a0,
0xc0007ebe,
0xd1a29244,
0xc0905e08,
0xd2240a00,
0x08825909,
0x3d00c400,
0xc000b422,
0x4220b104,
0xffff7500,
0xc1809364,
0xc0905c88,
0x5c890c80,
0xc000b461,
0xc1809c22,
0xc0905c88,
0x5c890c80,
0x3c80c400,
0xb4810a02,
0xb101c000,
0xf0084220,
0x5d88a0e1,
0x0d80c090,
0xb4835d89,
0x9c22c000,
0xd3129e5b,
0x0a0268b1,
0x0cc0c1c0,
0xc4005c8b,
0xb4813c80,
0xb102c000,
0xb7604220,
0xd3125894,
0x85026931,
0xb9609e51,
0xc1c04070,
0xf03108e0,
0xd0a4aa65,
0xb4815889,
0x0890c000,
0xffff8510,
0xc1c09301,
0xe2108560,
0xb76080ad,
0xc0015a94,
0xce3e3904,
0xb9608521,
0xf0314048,
0xd0a4aa65,
0xb4815889,
0x0890c000,
0xffff8510,
0xe2209301,
0xb780812d,
0xc001580c,
0xc1c03908,
0x5d090d60,
0xa885dac8,
0xc000b422,
0x68b1d312,
0x0cc0c1c0,
0xb4415c8b,
0x9c22c000,
0x500cb740,
0x6cb1d312,
0xc1c00a02,
0x5c8b0cc0,
0x3c80c400,
0xc000b481,
0x4220b101,
0x6cb1d312,
0x0cf0c1ca,
0xb4415c8b,
0xc00cc000,
0xc0016d82,
0xc1c038c0,
0x5d8b0dc0,
0xc000b423,
0x84209c22,
0xe0318502,
0x09068d80,
0x7f7cb55f,
0x0cd2c472,
0xb4810a02,
0xb101c000,
0x9e8a4220,
0xc0010203,
0x75002a40,
0x9362c000,
0x68a1d312,
0xc1ca0a02,
0x5c8b0cf0,
0x3c80c400,
0xc000b481,
0x4220b101,
0xa0e1f008,
0x501cb740,
0x7f6cb79f,
0xf3109e51,
0xcfff8021,
0xb58028be,
0xd312500c,
0xc1c068a1,
0x5c8b0cc0,
0xc000b421,
0x9c228c20,
0xc006a605,
0x87028420,
0xc4720c06,
0x0a020cd2,
0xc000b481,
0x4220b105,
0x020b9eaa,
0x2a04c001,
0xc0017500,
0xd31190c2,
0xe1b16c81,
0xb7608d00,
0x09825894,
0x4070b960,
0x08e0c1c0,
0x5889d0a4,
0x3c80c400,
0xc000b461,
0x4220b104,
0xa245f029,
0x87100890,
0x9281ffff,
0xa973f050,
0x796cb79f,
0xf3109e55,
0xcfff8021,
0xf0502afa,
0x020ba271,
0x2a08c001,
0xd3127500,
0xc0026e81,
0xe0b19082,
0xc1c08d00,
0xe1108760,
0xb74082a3,
0x09825a94,
0x4048b960,
0xd0a49e93,
0xc4005889,
0xb4613c80,
0xb104c000,
0xf0294220,
0x0890a245,
0x92a1ffff,
0x580cb780,
0xa943f010,
0xa891da08,
0xaa61f010,
0xa95cf012,
0xa9c7f050,
0x8021f310,
0xa94bd850,
0xd8101884,
0xf010a0c9,
0xb79fa241,
0xb73f7b6a,
0xb73f7eec,
0xf3107ff4,
0xe2108021,
0xe22082a3,
0xcfff80bb,
0xd8502af6,
0xf010a249,
0xf050a0dd,
0x020ba0c6,
0x2a10c001,
0xc0007500,
0xc01490c2,
0xcfff9838,
0xc1c02aee,
0xc2800ec0,
0xb4a15c8b,
0xb79fc000,
0xb7bf78ee,
0xc006796e,
0x9c228c60,
0x6cb1d312,
0xc1c00a02,
0x5c8b0cc0,
0x3c80c400,
0xc000b481,
0x4220b103,
0x5994b740,
0x6d31d311,
0x4058b960,
0xc1c00085,
0xf03108e0,
0xd0a4aa45,
0xb4815889,
0x0890c000,
0x9321ffff,
0x3990c001,
0x0940c1c0,
0x588bd124,
0xc000b461,
0xa6059c22,
0x8440c002,
0x5994b740,
0xc4720a86,
0x08820cd2,
0x8502c00c,
0xc000b421,
0x4220b104,
0xc0010189,
0x75002a10,
0x9302ffff,
0x8d00e0d1,
0x08029d47,
0x4058b960,
0x08e0c1c0,
0x5889d0a4,
0x3c80c400,
0xc000b401,
0x4220b104,
0xa245f029,
0xffff0890,
0x9dc792a1,
0x29eecfff,
0x0cc0c1c0,
0xb4615c8b,
0xf010c000,
0xb79fa94b,
0xf0127b6c,
0xb73fa94c,
0xd8107bec,
0xf310a9cb,
0xf0108021,
0xe210a953,
0xd81282a3,
0xf010a94c,
0xf010a249,
0xb79fa0cd,
0xb73f7c6c,
0xb73f75ea,
0xf3107572,
0xe2108021,
0xe22082a3,
0x0d8680bb,
0xa251f010,
0xa0cdd810,
0xa0cad810,
0x9b7efff4,
0x68d1d312,
0xc1c00a02,
0x5c8b0cc0,
0x3c80c400,
0xc000b481,
0x4220b104,
0x3a20c001,
0x68d1d312,
0x0cc0c1c0,
0xb4815c8b,
0xb79fc000,
0xb7bf7c6e,
0xc0047cee,
0x9c228c00,
0xa285f839,
0xaa61f010,
0xc0007500,
0xd0089164,
0x9e48a8c1,
0xc2000a06,
0x30985200,
0xa0c1d008,
0x0d38d011,
0xa9f2d010,
0x1a30f011,
0xa943f010,
0xc0001984,
0xcff193e2,
0xcff08702,
0xc00f8700,
0xc00e087e,
0xc050087c,
0xf0290c1a,
0xd020a8c5,
0x5ca12095,
0x22109e4d,
0x5a20c200,
0xba0930d8,
0xb4204006,
0xf011c000,
0x19841a30,
0x91e4ffff,
0x802ff210,
0xa241f010,
0xaa9df9f8,
0xa60d9c22,
0x59409e5d,
0x5841f124,
0x2d2ed3f1,
0x4422b350,
0x93e2c002,
0xaa61f008,
0x2a1ce000,
0x4422b425,
0xaa61d808,
0xe2108522,
0x2a1c88a9,
0x9ea31218,
0x0a7ec00e,
0x400bba1b,
0x5207c200,
0xc0012128,
0x9e599276,
0x5a20c100,
0xc2001103,
0x9ea25209,
0x58a1c200,
0xd0319e8d,
0xd2080cb0,
0xc00ea8a2,
0xc2002a7c,
0xc00e5207,
0x349a2a7c,
0xa0a2d208,
0xa963f008,
0xd3f19ea1,
0xc2012a2e,
0xf3108128,
0x85028821,
0xa261f008,
0xa127d228,
0xcff09eab,
0x59402d01,
0x35225941,
0x2d7cc00e,
0x9bb1fff4,
0x92e0c000,
0xaa21d208,
0x000b9e5e,
0x324250d8,
0xa205d029,
0xa8e1f008,
0x291ed013,
0x8029f210,
0x9e447510,
0xf0080098,
0xb350a0e1,
0xb79f4426,
0xb7bf7eee,
0xb7df7f6e,
0x8c607fee,
0xa6059c22,
0x59409e58,
0x74b05941,
0x06850287,
0x9374c000,
0x5d61c280,
0x59401960,
0xfff45941,
0x9e839b82,
0xc280018b,
0xc00e5d41,
0x09222d7c,
0x9b79fff4,
0x018b9e83,
0x5d21c280,
0x2d7cc00e,
0xc0010922,
0x74a090a0,
0x92d4c000,
0x018b9e83,
0x5d41c280,
0x2d7cc00e,
0x59401940,
0xfff45941,
0x9e839b62,
0xc280018b,
0xc00e5d21,
0x09222d7c,
0x91c0c000,
0xc0007490,
0x9e8392d4,
0xc280018b,
0xc00e5d21,
0x19202d7c,
0x59415940,
0x9b4bfff4,
0x018b9e83,
0x2d5ed3f2,
0xfff40922,
0xc0009b44,
0x9e839100,
0xd3f2018b,
0xfff42d5e,
0xb79f9b3c,
0xb7bf7f6e,
0x8c407fee,
0xa60d9c22,
0x9e690685,
0x0b029e9e,
0x0a867182,
0x9208c000,
0x16d29ea9,
0xc2809e69,
0xd0115a84,
0x71021a52,
0x08e2d011,
0x2b1ed3f1,
0x9286ffff,
0x0a62d011,
0x028d7510,
0x91d4c000,
0x0d029e73,
0xfff40922,
0x1aa09b14,
0x0a52d011,
0x9e837510,
0x92d2ffff,
0x0d069e73,
0x0952d011,
0x297cc00e,
0x9b05fff4,
0x9e837590,
0x92f4c000,
0x1a60d031,
0x2b4ed3f1,
0x9e739e6c,
0x5299c200,
0x295ed3f2,
0xfff40922,
0x9e839af4,
0x52b8c200,
0x75909ea9,
0xffff16d2,
0x9e7391b2,
0x2d5ed3f2,
0xfff4010d,
0xb79f9ae6,
0xb7bf7eee,
0xb7df7f6e,
0x8c607fee,
0xf0119c22,
0x9e990ca0,
0x5a04d09a,
0x1a42d00d,
0x909ac000,
0x12421203,
0x9ea29e4b,
0x9360fffc,
0x8420a60d,
0x9e558502,
0xb55f9e9e,
0xf0107f7c,
0xf012aa61,
0xb55f8c8e,
0x1a087ffc,
0xd2267512,
0x8540590c,
0x8044e05a,
0x9200c006,
0x9280c000,
0x90e0c001,
0x9200c001,
0x9340c001,
0x9040c002,
0x92a0c002,
0x9120c003,
0x9320c004,
0x9060c005,
0x9240c005,
0x568cb720,
0x49adb780,
0x75002a08,
0xb352856a,
0x9d574462,
0x8d88e011,
0x1954d072,
0xb5a0058b,
0xfff44f8c,
0xc0059bb6,
0xb7409120,
0xe0114f94,
0x9ea98d88,
0x1514058b,
0x9babfff4,
0x93c0c004,
0x8d88e011,
0x295ed3f2,
0x0916058b,
0x9a7dfff4,
0x4f8cb5a0,
0x9240c004,
0x8d88e011,
0x295ed3f2,
0x0916058b,
0x9a71fff4,
0x9100c004,
0xaa41d210,
0x8c88f011,
0x4a7d058b,
0x2aced012,
0x09060d06,
0xfff4018b,
0x9e839a62,
0x018b9e6a,
0xfff40d02,
0xc0039a5c,
0xd2109260,
0xf011aa41,
0x058b8c88,
0xd0124a7d,
0x0d022ace,
0x018b0906,
0x9a4dfff4,
0x9e6a9e83,
0xc00e018b,
0xfff40d7e,
0xc0029a46,
0xb72093a0,
0xd272568c,
0xb7800890,
0x7500404d,
0xc0000303,
0xf2c89104,
0xb580aa51,
0xc000404d,
0xb7809100,
0xf248588c,
0xb520a895,
0xd271404d,
0xf2080ae0,
0xfa88a8a1,
0x0c82a951,
0x05830183,
0x9a29c0b4,
0x0a60d2b1,
0xa903f208,
0xe0119e41,
0xe2208d88,
0x058b8923,
0xf208095e,
0xfff4a0a1,
0xc0019a84,
0xb7809160,
0xe011570c,
0xf2088d88,
0x058ba902,
0xfff4095e,
0xc0009a78,
0xb74093e0,
0xb7837f1c,
0xe0117e08,
0xf3108d88,
0x9dcb8021,
0x095e058b,
0x7f0cb580,
0x9a67fff4,
0x91c0c000,
0x7e10b743,
0x8d88e011,
0x091e058b,
0x99edfff4,
0x9080c000,
0x90e0c001,
0x7e68b79f,
0x0cfec00f,
0x0cfcc00e,
0xb59f9e4a,
0xb73f7c68,
0xcff17f6c,
0xcff00a02,
0xc0500a00,
0x22180c9a,
0x5a21c200,
0x58a02094,
0xba243242,
0xb59f4006,
0xb4817f6c,
0xf210c000,
0xb79fa943,
0xf3107fec,
0xf2108021,
0xb79fa241,
0xb7bf7e6e,
0xb7df7eee,
0xc0027f6e,
0x9c228c00,
0x8440a61d,
0x9e9d8502,
0xabe5f031,
0xb55f0b02,
0xb55f7878,
0x718e7efc,
0xc0019d3a,
0xaa4191e8,
0xc0007502,
0xd0189392,
0xe032aad1,
0xe0518d08,
0x9dcf8d00,
0x85109eb1,
0x7f7cb55f,
0x0a9cc002,
0x5a95c280,
0xfff4018b,
0xb75f9957,
0xc2807f7c,
0xc3015a88,
0xc0008122,
0xe03191a0,
0x9dcf8d88,
0x8510050b,
0x7f7cb55f,
0x9ab8fff4,
0x7f7cb75f,
0x718e0b04,
0x92a6fffe,
0x7868b79f,
0x0c9ec050,
0xc000b481,
0x0d16c050,
0xc000b4e2,
0x7eecb71f,
0x7d6eb79f,
0x7deeb7bf,
0x7e6eb7df,
0x7eeeb7ff,
0x8c40c002,
0xa6059c22,
0x0c8ac450,
0xb4810a02,
0xb102c000,
0xe00e4240,
0xd1042d7c,
0xc8015d10,
0x0a400a02,
0x0c8ac030,
0xc000b481,
0x0c8408c2,
0xc000b421,
0x5d8cb740,
0xa947f048,
0x802df210,
0xa245f048,
0x0c86c450,
0xb4810a02,
0xb101c000,
0xc8014220,
0xc0100a42,
0xc0320a00,
0xb4810caa,
0x08aac000,
0x0d1ec034,
0xc000b422,
0x0cf2c450,
0xb4810a02,
0xb101c000,
0xd0534220,
0xb7801910,
0xf248568c,
0xf210a891,
0x0d8288a3,
0x018b0d06,
0x9ad7ffd4,
0x0ca2c080,
0xc000b4a1,
0x0d82c002,
0x991bc014,
0xffff700a,
0x0daa9364,
0x0d0a0982,
0x0902c121,
0x9872ffd4,
0x568cb780,
0xa992f248,
0x0d02c0a1,
0x09c20d04,
0x985dffd4,
0x0d82c0c0,
0x0d420992,
0xc0140942,
0xb79f991e,
0xb7bf7f6e,
0x8c407fee,
0xa6059c22,
0x8400c010,
0x568cb720,
0x49adb780,
0x75002a20,
0x588cb7a0,
0xc0000902,
0xb7829182,
0x75004d08,
0x90e2c000,
0xaa21d288,
0xc0037500,
0xb7209284,
0xd01149ad,
0x75002a18,
0x3924d002,
0x9124c000,
0x2a14d011,
0xd0027500,
0xd0013922,
0xc0503926,
0xb4410c82,
0x9d87c000,
0x460cb740,
0x09c20dc2,
0x0d02c010,
0x0c81cff0,
0x9834ffd4,
0x4d08b782,
0x75009d0b,
0x0901cff0,
0x9282c000,
0xaa21d288,
0xc0007500,
0xb79f91e2,
0xe211606c,
0xc0108d00,
0x75002a00,
0x0a03cff0,
0x8001f310,
0x4422b342,
0x4068b79e,
0x08c2c801,
0x0880c010,
0x0ceac032,
0x606cb59f,
0xc000b421,
0xa9adda08,
0xfff49e93,
0xc8019add,
0xc00a0a02,
0xc0300a00,
0xb4810c8a,
0xc008c000,
0x0c8408c2,
0xc000b421,
0x0a02c008,
0xb4810c88,
0xc0c0c000,
0x09920d82,
0x0d02c008,
0x0902c008,
0x989bc014,
0x0a02c008,
0x0c8ec030,
0xc000b481,
0x590cb720,
0xb5408506,
0xfff44039,
0xb79f9b08,
0xb7bf6f6e,
0xc0106fee,
0x9c228c40,
0xa205f839,
0x0c82c450,
0xb4810a02,
0xb101c000,
0xc0084220,
0xc0300a40,
0xb4810c8e,
0xc002c000,
0xc05038c0,
0xb4210c82,
0xc0c0c000,
0x09920d82,
0x0d02c008,
0x0902c008,
0x9869c014,
0x0a02c008,
0x0c8ec030,
0xc000b481,
0xaa1df9f8,
0x9320fff6,
0xf011a60d,
0xc0010eb0,
0xc01e9182,
0xc0080f7e,
0xc0300b02,
0xc0400e8e,
0x9e747540,
0x0c96c050,
0x4426b354,
0xc20012d8,
0xb4815a14,
0xc030c000,
0xb4c20d0a,
0xb4c5c000,
0xc030c000,
0xb4c10c96,
0xc0c0c000,
0x09920d82,
0x0d02c008,
0x0902c008,
0x9835c014,
0xc000b4c5,
0xfffe7540,
0xfff493c4,
0xb79f9aa8,
0xb7bf7eee,
0xb7df7f6e,
0x8c607fee,
0xb4639c22,
0x9c22c000,
0xa062f812,
0xc2009c22,
0x5d890d80,
0x09829e59,
0x3d80c400,
0xc000b463,
0x4620b203,
0x9c220007,
0x9c8fc127,
0x080a9c22,
0x56f1b971,
0x9c81c017,
0x9c80c071,
0x9c80c017,
0x4000b960,
0xffff9c22,
0x9e5c9280,
0xd1a401c6,
0x08825889,
0x3c80c400,
0xc000b421,
0x4220b104,
0x9e532244,
0xffff7106,
0x9c229324,
0xc004a60d,
0xc8298420,
0xc4400ca2,
0xc0300cf0,
0xe133ac3d,
0xc0388d00,
0xc030a45d,
0xc038ac3d,
0xc010a45d,
0xc018ac3d,
0xc010a45d,
0xc018ac25,
0xb7a0a445,
0x9ea9568c,
0xb5408502,
0xb541641a,
0xb7404998,
0x0dc2460c,
0x0d42c00a,
0xffb409c2,
0xd2519b1b,
0xda080a58,
0x7502aa01,
0xc0009ead,
0xb5809084,
0xb780440c,
0x87025d8c,
0xa8a2f210,
0xb543850a,
0xf2107e18,
0xb540a8a5,
0xb5405004,
0xf20a4702,
0xf208a100,
0xf210a086,
0xf208a929,
0xf210a089,
0xf210a92e,
0xf208a8b2,
0xf250a10d,
0xf208a8b1,
0xf208a112,
0xf208a096,
0xc050a09a,
0x08c00cf2,
0xa085f248,
0xc000b421,
0xc0360a0a,
0xb4810c92,
0x0896c000,
0xb4211c8c,
0x8502c000,
0x8c00f031,
0x8d80e131,
0xb7c09ea3,
0x0d025c0c,
0x4078b960,
0x7ffcb55f,
0xa103f208,
0xd1229dba,
0x9e2d5d0d,
0xa8e5f029,
0x2caed012,
0xd1265c88,
0x9e4a5908,
0xaa4de038,
0x28bc0d04,
0x324250a8,
0xffffa241,
0xf01091c1,
0xc036aa61,
0xb4810c8e,
0xb73fc000,
0x1c847fec,
0xc000b421,
0x998fc014,
0xaa4dd208,
0xc0007500,
0xf2909262,
0xf011aa2d,
0xc0002ac8,
0xc80091a4,
0x75002a00,
0x90c4c000,
0xa9c6f208,
0x9ae8fff4,
0xa2cdd208,
0xaaadf290,
0x2a54d011,
0xc0007500,
0xc8099102,
0xc5320a42,
0xb5800a70,
0xb780528c,
0x7500458c,
0x9162c000,
0x5a31c280,
0xc03e2a04,
0xb4810cea,
0xc000c000,
0xb7809280,
0x7502440c,
0x915cc000,
0x2a80c100,
0x0a0e7540,
0x1a46d001,
0x9060c000,
0xc03e0a02,
0xb4810cea,
0xb79fc000,
0xb7bf7a6e,
0xb7df7aee,
0xc0067b6e,
0x9c228c00,
0x530cb780,
0x0892c0c8,
0x40f8b960,
0x0948d011,
0xaa45f029,
0x5889d0a4,
0xc000b481,
0xffff0890,
0x9c229321,
0xb720a605,
0xb780458c,
0x74407b8c,
0xb5800a04,
0xc0007b8c,
0xb7829364,
0x75004d08,
0x92c2c000,
0x440cb720,
0x508cb780,
0x3a407442,
0x508cb580,
0x919cc000,
0x5c0cb780,
0xa889d208,
0xc0007440,
0x850690a4,
0x7218b543,
0x0a42c801,
0x0a00c010,
0x0ceac032,
0xc000b481,
0x08c2c008,
0x1ce0c002,
0xc000b421,
0x0a42c008,
0x0d0ec030,
0xc000b482,
0x0c82c450,
0x1a40c008,
0xc000b481,
0x4220b101,
0x38c0c002,
0x0c82c050,
0xc000b421,
0x0d82c0c0,
0xc0080992,
0xc0080d02,
0xfff40902,
0xc4509aac,
0x0a020c86,
0xc000b481,
0x4220b105,
0x0a00c008,
0x0d0ec030,
0xc000b482,
0xc0080c84,
0xb4811a00,
0xb101c000,
0xc0804220,
0xc8015a35,
0x09400902,
0x28fcc00e,
0x5910d0a8,
0x29ced071,
0x0c8ac030,
0xb4419dc8,
0x0a42c000,
0xb4810c84,
0x7680c000,
0x9182c000,
0x5d8cb720,
0x44bdb740,
0x8a27f210,
0x8021f310,
0x44adb580,
0x0c86c450,
0xb4810a02,
0xb105c000,
0x0cec4220,
0xc000b481,
0x4220b105,
0x08ea12d6,
0x0c9ec034,
0xc000b421,
0x568cb780,
0xa891f248,
0x1950d053,
0x88a3f210,
0x0d060d82,
0x5a0cc280,
0x500cb580,
0xffb4018b,
0xc0809bea,
0xb4a10ca2,
0xb780c000,
0x0c88470c,
0xc000b481,
0x5814b7a0,
0x0d82c002,
0x9a27fff4,
0xffff700a,
0xb7809364,
0xf2107b8c,
0xf250a8ad,
0x6243a8a2,
0x71029e49,
0x90b8c000,
0xb5438506,
0xb7807018,
0x7500458c,
0xc0010a82,
0xb7809204,
0x7502440c,
0x933cc000,
0x4d08b782,
0xc0007500,
0xb7809282,
0x2a79450c,
0x450cb580,
0x9ba8ffb4,
0x7208b783,
0xc0007500,
0xffd490c2,
0xb5a3987f,
0xffd47208,
0xb7829844,
0x75004d08,
0x92a2c000,
0x996bc014,
0x5c0cb780,
0xa889d208,
0xc0007440,
0xc0809182,
0xc0000a82,
0x0d829100,
0x9810ffd4,
0xffd40d82,
0xc08098fb,
0xb4a10ca6,
0xc002c000,
0xfff40d92,
0x700a99d4,
0x9364ffff,
0x09820dea,
0xc1210d0a,
0xffb40902,
0xb780992b,
0xf248568c,
0xc0a1a992,
0x0d040d02,
0xffb409c2,
0xc0c09916,
0x09920d82,
0x09420d42,
0x99d7fff4,
0xc03e0a02,
0xb4810cea,
0xb79fc000,
0xb7bf7f6e,
0x8c407fee,
0xa61d9c22,
0x568cb720,
0x49adb780,
0x2a00c002,
0xc0037500,
0xc8099242,
0xc54a0942,
0xc8090960,
0xc5de0d42,
0xc8090d30,
0xc63009c2,
0xc8090990,
0xc5fe0c42,
0xc8090c00,
0xc5420cc2,
0xc8090cd0,
0xc6b40842,
0xc8090860,
0xc6fe0ec2,
0xc8090e80,
0xc7600b42,
0xc8090b40,
0xc5360f42,
0xc8090f20,
0xc53a85c2,
0xb7e085e0,
0xc809568c,
0xc5368742,
0xc8098740,
0xc76208c2,
0xd15108c0,
0x9eab0af0,
0x5e8cb780,
0xb5428506,
0x0f824d18,
0x7b94b5e0,
0x7010b5e3,
0xa109f208,
0xa112f208,
0xa195f208,
0xa01af208,
0xa08ef208,
0xa01df208,
0xa282f248,
0xa305f248,
0xa30af248,
0xa187f208,
0xa100f20a,
0xa08df248,
0x9c620603,
0xaa6df288,
0x5894b720,
0xa8a1d208,
0x75002a08,
0x4312b5e0,
0x41cbb520,
0x90e2c000,
0xb540856a,
0xc0004f9c,
0xb78090c0,
0xb58041cb,
0xb7c04f8c,
0xb720580c,
0xf2085694,
0xb780a8d9,
0x70484d4d,
0x9142c000,
0x5e8cb780,
0xa88df248,
0x0d90d152,
0x9c629e8c,
0x4d08b782,
0xc0037500,
0xb72092e2,
0x76404594,
0x9244c003,
0x430ab720,
0xc0007440,
0xda0890e2,
0x7048aa55,
0x9324c000,
0x5e8cb7a0,
0x5c14b7a0,
0xa9d6da08,
0x4312b520,
0xaa29f208,
0xd210098a,
0x1d84a0aa,
0x9c629ea4,
0xa8b1f208,
0x9e8c0d8a,
0xc0009c62,
0xb7809180,
0xf2085e8c,
0xb7a0a891,
0x0d865c14,
0x9e8c0289,
0xb7809c62,
0xb720430a,
0x0a04588c,
0x430ab580,
0xaa29d210,
0x598cb7c0,
0x4829b580,
0xa8a1f208,
0x9e8c9eb3,
0xd2109c62,
0x7500aa29,
0x92a4c000,
0xa9c1f208,
0xa83df208,
0x9e840d82,
0xf2089c62,
0xf248a041,
0x9eb3a825,
0x9e840982,
0xda089c62,
0xb581aa41,
0xb780788a,
0x7502440c,
0x90bcc000,
0xffb40d86,
0xd2109a9f,
0x7500aa29,
0x9122c000,
0x550cb720,
0x412db780,
0xc0003a08,
0xb72090e0,
0xb780550c,
0x2a75412d,
0x412db580,
0x4d08b722,
0x508cb780,
0x3a047440,
0x508cb580,
0x9204c000,
0x568cb7e0,
0x588cb740,
0x0a70d151,
0xa882d208,
0xa881d208,
0x4f94b520,
0xa0cdd808,
0x7e6eb79f,
0x7eeeb7bf,
0x7f6eb7df,
0x7feeb7ff,
0x8c00c002,
0xa60d9c22,
0x5e94b7a0,
0x5994b760,
0xa825f210,
0x5c14b7c0,
0x500cb7c0,
0x9c629e84,
0xaa49d210,
0x02817500,
0x9184c000,
0xaa21f250,
0x9c629ea4,
0xa8b5f210,
0x11ead020,
0x9c629e8c,
0xaa39f210,
0x9e739eb3,
0x9c629ea4,
0x568cb720,
0x49adb780,
0x2a00c400,
0xc0007500,
0x85029102,
0xa14bd210,
0xd2108506,
0xb780a143,
0xcffe508c,
0xb5802a3d,
0xb79f508c,
0xb7bf7eee,
0xb7df7f6e,
0x8c607fee,
0xb7209c22,
0x9e5c4a8c,
0x2a40c0ff,
0x28c0c0ff,
0x85027102,
0x9062c000,
0xb5408506,
0xb5604b1c,
0x9c224a94,
0x9e5da605,
0x2a50d051,
0xc0007500,
0xb78090e4,
0x75004b0c,
0x9142c000,
0x0d82c0c0,
0x09c2c012,
0x09420d02,
0x983dfff4,
0x4a8cb780,
0x0cb6c034,
0xc000b481,
0x0d32c034,
0xc000b4a2,
0x4a0cb5a0,
0x7f6eb79f,
0x7feeb7bf,
0x9c228c40,
0x8420a61d,
0x4d08b782,
0xc0007500,
0xb7809122,
0xd288588c,
0x7440a881,
0x9284c015,
0x460cb740,
0x5614b7a0,
0x098e0dc2,
0x0d42c002,
0xff94048b,
0xf2109b65,
0xb7c0aa35,
0xf210558c,
0xf210a8a5,
0xb7a0a8aa,
0xda10568c,
0xb580a922,
0xda10470c,
0xf208aa39,
0xda10a0d5,
0xf208a8bd,
0xd252a0de,
0xf25008d0,
0xf208a927,
0xf248a259,
0xd131a0c1,
0xda080a50,
0x9e53a881,
0x404bb740,
0xa8b2da90,
0xc08060b2,
0xc2005a7f,
0x00985a71,
0x58945893,
0x80a3e210,
0x7e7edffc,
0xc1005915,
0x018b5b90,
0xa0ddf248,
0x91e2c000,
0x5d40e100,
0x9164c000,
0xaa35da90,
0xb5208502,
0xb5404692,
0xb580479a,
0xf288458a,
0xd132aa21,
0xda100950,
0xf248a8a1,
0xf248a255,
0xd810a259,
0xf248aa41,
0xda48a93b,
0x6218a8ba,
0x8021f310,
0xa93dda48,
0xa0caf248,
0xa249f288,
0xaa29da48,
0xa151f248,
0xa923f208,
0xa8aeda48,
0xc2006218,
0xf3105a10,
0xf2088021,
0xf208a241,
0x9e4ca927,
0xa928f20a,
0x588c6098,
0x8023f210,
0x82a3e210,
0x5d8cb740,
0xa249f208,
0xa8aada48,
0xaa21da10,
0xa0cdf208,
0xa8c1d810,
0xa0c6f208,
0xa937f248,
0x62430a04,
0xa8a1da10,
0x8021f310,
0xa8a2da10,
0xa245f288,
0xa953f008,
0xa954f00a,
0x5c9c58a0,
0x80a3e210,
0x82a3e020,
0xaa2dda48,
0xa0adf208,
0xa0b2f208,
0xa0c5f248,
0xa0cef248,
0xa251f208,
0xa941d810,
0x1880c004,
0x4e8cb520,
0x0a54d131,
0xa881da08,
0x1c80c002,
0x4f14b520,
0x59515940,
0xa155f288,
0x58d158c0,
0xa0d9f288,
0x0cf2c42e,
0xb4810a02,
0xb101c000,
0x28844220,
0xd1327440,
0xc0000b50,
0xda109102,
0xc09caa41,
0xc00e753e,
0xc0c092b2,
0xc05008c6,
0xb4210ce2,
0xf210c000,
0xd131a939,
0xda080a30,
0xd052a881,
0x764028a0,
0xb5205891,
0xc0004e0c,
0x0a029222,
0x0caec060,
0xc000b481,
0xa8a1da10,
0xc0007440,
0x85029302,
0x4e1cb540,
0x9260c000,
0x2900c200,
0xc0007480,
0x0a0a9122,
0x0caec060,
0xc000b481,
0x90e0c000,
0xc0600a06,
0xb4810cae,
0xf210c000,
0x2a04aa39,
0x850a7500,
0x489cb540,
0x90a2c000,
0xb5408504,
0xb782489c,
0x75004d08,
0x5e94b7e0,
0x91a2c000,
0x458cb780,
0xc0007500,
0xb7609102,
0xf2105994,
0x9ea4aa61,
0xf2109c62,
0x2a20aa39,
0xc0007500,
0xda1090e2,
0x7500aa21,
0x9244c000,
0x588cb780,
0x528cb720,
0xa98eda08,
0x9c629e8c,
0x4d08b782,
0xc0007500,
0x850690a2,
0x7518b543,
0xa8b9f210,
0x2a14d011,
0xc0017500,
0xd01190e2,
0x75002a12,
0xcffe8516,
0xc0380a7e,
0xe0010cfa,
0xb5408d28,
0xb4814c9c,
0xda10c000,
0xb720a8c1,
0xc2846194,
0xc6840a6a,
0xc058856a,
0xb5207462,
0xc0385194,
0xb3240c82,
0xb4814c28,
0x0882c000,
0x0c80c002,
0xc000b421,
0x9b98ffd4,
0x488cb780,
0x0c82c03e,
0xc000b481,
0x4c8cb720,
0x0c82c050,
0xc000b421,
0xa921da10,
0xa8d5f288,
0xa926da10,
0x9e536123,
0xaa21da10,
0xb7206097,
0x87025d14,
0x7982b541,
0xb540857f,
0x851a449a,
0x439ab540,
0x1a040d86,
0x4d0cb580,
0x405bb540,
0xb5408526,
0xb540415b,
0x5891450a,
0xb52018a0,
0xb55f40cb,
0xc0147fe4,
0xb75f9b0b,
0xda107fe4,
0xf288a8a6,
0x8506aa55,
0x7418b543,
0xb7209e49,
0xb5435614,
0xb5437480,
0xb5437a00,
0xb5437a80,
0xb5437580,
0x62437600,
0x434db720,
0x0a828502,
0xc10158c8,
0x9e892880,
0xa9c2da10,
0x4d9cb540,
0x511cb540,
0x5a11c200,
0xc0ff5dc0,
0xca012dc0,
0xb5803db0,
0x3596440a,
0x99ddfff4,
0x0d82c0c0,
0x09c2c012,
0x09420d02,
0x9a35ffd4,
0x8546714e,
0x9148c001,
0xfff49dcf,
0xc0c099df,
0xc0120d82,
0x0d0209c2,
0xffd40906,
0xd0919a26,
0x71481a70,
0xd00b0a02,
0xda100a42,
0xc200a9c2,
0x9ea15a28,
0xc0ff5dc0,
0xc8012dc0,
0x35963db0,
0x99b3fff4,
0x0a50d051,
0x5a40c200,
0x5ac1c200,
0x8506714e,
0x9346fffe,
0xaa71f250,
0xcfce7500,
0xb540857f,
0xc0007e1c,
0xf2109102,
0xb760a9be,
0x9ea4440a,
0x0d829c62,
0x9899c014,
0x7488b783,
0x85027500,
0x7418b543,
0x9144c000,
0xc0140d86,
0xb783988e,
0x75007488,
0x9342ffff,
0x0d82c0c0,
0x09c2c012,
0x09060d02,
0x99dfffd4,
0x0a02c801,
0x510cb580,
0x0d82c0c0,
0x09c2c012,
0x09420d02,
0x99d3ffd4,
0x5114b760,
0x996ffff4,
0xfff40d86,
0xc0c0997d,
0xc0120d82,
0x0d0209c2,
0xffd40906,
0x850299c4,
0x0892c006,
0x0c9ac430,
0xb5400902,
0xc006511c,
0xb4418510,
0xb104c000,
0x2a404220,
0x9d4f7500,
0x4422b313,
0xe0000087,
0xffff1884,
0xb7409284,
0xc0064594,
0xc4300892,
0x09020c9a,
0x8512c006,
0xc000b441,
0x4220b104,
0x2a00c002,
0x9d537500,
0x4422b314,
0xe0000089,
0xffff1884,
0x0a029264,
0x0ceac03e,
0x40e8b960,
0xc000b481,
0x93c1ffff,
0xc0007680,
0x0a029122,
0x0ceac03e,
0xc000b481,
0x9180c000,
0x440cb780,
0x088a7504,
0x0ceac03e,
0x1894d00c,
0xc000b421,
0x0d82c0c0,
0x0d0209e2,
0xffd40942,
0x0a029970,
0x0cb6c034,
0xc000b481,
0x7deeb79f,
0x7e6eb7bf,
0x7eeeb7df,
0x7f6eb7ff,
0x8c20c002,
0xa60d9c22,
0x7efec01c,
0xc0000a82,
0xc0c09182,
0xc0120d82,
0x0d0209c2,
0xffd40906,
0xc0009952,
0xc4349240,
0x0a020cb2,
0xc000b481,
0x4220b101,
0x74402884,
0x90e2c000,
0x7408b783,
0xc0067500,
0xb7809322,
0x75024d8c,
0x90c4c000,
0xc0140d82,
0x3ac099d5,
0x5614b740,
0x558cb740,
0xa8c5d810,
0xaa55f088,
0x4492b720,
0x9e496243,
0x5a11c200,
0xba090a04,
0xba244002,
0x70484002,
0x06850305,
0x9138c000,
0x488cb780,
0xb5802a51,
0xc003488c,
0xf21091c0,
0x2a04aa39,
0xc0027500,
0xb78093a2,
0x7440488c,
0x3942d011,
0x488cb540,
0x929cc002,
0x4692b760,
0xba249e5c,
0xc002400a,
0xc00291a2,
0xb760911c,
0xb740640a,
0x9e995e04,
0xba099e2d,
0xd0a24003,
0x9e485e7f,
0x5a6dc200,
0xc2000208,
0xd2265a17,
0x0c065908,
0x5a14c200,
0x9e401208,
0xa94ee038,
0x4002ba24,
0x9e545090,
0xc0017902,
0xb7819102,
0x75004988,
0x9064c001,
0x460ab780,
0xba249e48,
0x70084002,
0x9378c000,
0xc0007640,
0xb78190e4,
0x75024908,
0x92c2c000,
0x1e32d011,
0x468ab580,
0x48fd9e54,
0x460ab560,
0x4990b501,
0xb5402959,
0x20c2488c,
0xc000a0c1,
0x850290a0,
0x4998b541,
0x448ab780,
0x400aba24,
0x90fcc000,
0x640ab780,
0xb5800a04,
0xb720640a,
0xc03e488c,
0xb4210c82,
0xb780c000,
0x0a04448a,
0x448ab580,
0x9a42c014,
0x983ec014,
0x4d8cb780,
0xa955f288,
0x71040a04,
0x4d8cb580,
0x90a4c000,
0xb5408502,
0xda104d9c,
0xb720a8a5,
0x58914492,
0xba0960a3,
0x9e484003,
0x08843a84,
0x020b7002,
0x2a3dcffe,
0x4426b354,
0xd0510289,
0x744028d0,
0x9142c000,
0x0d82c0c0,
0x09c2c012,
0x09420d02,
0x9871ffd4,
0x510cb780,
0xc0007500,
0x9eab90a2,
0x981afff4,
0x7eeeb79f,
0x7f6eb7bf,
0x7feeb7df,
0x9c228c60,
0xa205f839,
0x7a08b723,
0x5184b740,
0x438ab780,
0x5908d0a6,
0xb7409e2d,
0xe030568c,
0xb760a94e,
0xb743621c,
0xb7437a98,
0x1a047a00,
0x438ab580,
0xa8cdc030,
0x5a40e200,
0x0a20d251,
0xa882da08,
0x82a3e210,
0x5114b540,
0x5c905c95,
0x7a08b523,
0x92c4c001,
0x7a88b783,
0xd3f10a04,
0x744428ce,
0x7a88b583,
0x9034c001,
0x7e14b760,
0xb5438506,
0x24a67498,
0xb5437640,
0xb5207618,
0xc0005114,
0xd1319202,
0xb78008a0,
0xc801402b,
0x9e483c80,
0x5a40c200,
0x2a40c0ff,
0xb5803208,
0x0806510c,
0xaa1df9f8,
0xb7239c22,
0xb7407a88,
0xd0a65d04,
0x9e2d5904,
0xaa4dc830,
0x438ab580,
0x09a0d132,
0x448ab720,
0xaa61d810,
0x4002ba19,
0x5a11c200,
0x70c81a04,
0x9104c000,
0x7e0cb780,
0x3a00c040,
0x7e0cb580,
0x4e0cb720,
0x0a18d011,
0xc00070c8,
0xb7809104,
0xc0107e0c,
0xb5803a00,
0xd0117e0c,
0x70c80a1c,
0x9104c000,
0x7e0cb780,
0x3a00c020,
0x7e0cb580,
0x558cb780,
0xa916f288,
0xa919f288,
0xb7209e50,
0xd011450a,
0x62411a24,
0x4002ba09,
0x704800b2,
0x9106c000,
0x7e0cb780,
0x2a7acfff,
0x7e0cb580,
0x1a22d011,
0x62459e52,
0xc0007048,
0xb7809106,
0xc7fe7e0c,
0xb5802a7e,
0xb7407e0c,
0xd0a2441a,
0xf3105e11,
0x70c88821,
0x9104c000,
0x7e0cb780,
0x2a4ecfff,
0x7e0cb580,
0x560cb740,
0x7e0cb720,
0xaa45d808,
0x9e8a9e50,
0x5a11c200,
0x62091a04,
0x5114b720,
0xba240a04,
0x70c84002,
0xb5202494,
0xc0005114,
0xc8019118,
0xb5203c80,
0xc0005114,
0xd81091c0,
0xc801aa61,
0x9e483c80,
0x5a40c200,
0x2a40c0ff,
0xb5803208,
0xf008510c,
0xc040aa59,
0x75002a00,
0x9102c000,
0x510cb780,
0x3a00c101,
0x510cb580,
0x5114b760,
0x9b09ffd4,
0xf9f80802,
0x9c22aa1d,
0x5694b700,
0x0e04d251,
0x558cb760,
0xa881da08,
0x2dfcc00e,
0x0cbac034,
0xa961f008,
0xc0805895,
0x9e825810,
0xc000b441,
0x454ab780,
0xa963f008,
0x5a10c200,
0x8021f310,
0xa8e9f008,
0xf0080c84,
0xb421a261,
0xb780c000,
0xf00846ca,
0xf310a96b,
0xf0088021,
0x0c84a8ed,
0xa269f008,
0xc000b421,
0x46cab780,
0xa96ff008,
0x8021f310,
0xa8f5f008,
0xf0080c8c,
0xb421a26d,
0xf008c000,
0x0c84a97d,
0xc000b441,
0x4d0cb780,
0xd2240a08,
0x72445890,
0x931cc000,
0x0e04d131,
0xa903da08,
0xe2109e4c,
0x710288a1,
0x91d6c000,
0xaa75f008,
0xa8fdf008,
0x0a00c010,
0xa275f008,
0x0880c008,
0xa0fdf008,
0x4e8cb780,
0x0cdac034,
0xc000b481,
0x4f0cb720,
0xb4210c84,
0xb780c000,
0x0ce44e8c,
0xb4810a40,
0xb720c000,
0x0c844f0c,
0xb42108c0,
0xb780c000,
0xb7204e8c,
0x1ce44f0c,
0x0a00c010,
0x4e8cb580,
0xaa65f048,
0x0880c008,
0x4f0cb520,
0xc000b481,
0xa8edf048,
0xb4210c84,
0xf048c000,
0xf048aa65,
0x0c84a8ed,
0x0a00c010,
0xa265f048,
0xaa75f048,
0x0880c008,
0xa0edf048,
0xc000b481,
0xa965f088,
0xb4410c88,
0xd131c000,
0xb7800c80,
0xf088402b,
0xcffea967,
0xf3102a40,
0xf0888021,
0x0c88a969,
0xa265f088,
0xc000b441,
0x0c80d131,
0x402bb780,
0xa96bf088,
0x2a40cffe,
0x8021f310,
0xa97df048,
0xf0881c8c,
0xb441a269,
0xd131c000,
0xb7800c80,
0xf048402b,
0x76c0a97f,
0x5a11c200,
0x5a14c200,
0x8021f310,
0xa27df048,
0x9182c001,
0x454ab720,
0xb4211ca8,
0xb780c000,
0x0c8446ca,
0x5a0dc200,
0x58c0c200,
0xb4813242,
0xd131c000,
0xd8080d04,
0x0c8caa41,
0x588cc200,
0x28fccffe,
0x5a50c200,
0xb4213098,
0xd251c000,
0xd8080d04,
0x0ca0aa41,
0x5a11c200,
0x2a3c1a10,
0x3a00c004,
0xc000b481,
0x4d0cb780,
0xb5800a04,
0x9c224d0c,
0xc43ea685,
0x0a020c92,
0xc000b481,
0x4240b102,
0x5b8cb780,
0xa885da08,
0xa909da08,
0xa10ada08,
0xa081da08,
0xa105da08,
0x0a020cd0,
0xc000b481,
0x4240b102,
0x5b0cb720,
0x510cb780,
0x5b94b700,
0x40b3b720,
0x412bb740,
0x4133b540,
0x75002a40,
0xb5200283,
0xb5404033,
0xc00040ab,
0xb78390e2,
0x750a7a08,
0x90f2c000,
0x7a08b783,
0xc006751a,
0xb7819104,
0x0a04798a,
0x798ab581,
0x0ca6c450,
0xb4810a02,
0xb102c000,
0x9e514240,
0x9e509e54,
0x2a7cc00f,
0x59c1d228,
0x2880c031,
0x59e1c080,
0x287ccffe,
0x0a020c88,
0xc000b481,
0x4240b102,
0x5f41d122,
0xcffe0585,
0x0cbc2dfc,
0xc000b481,
0x4240b102,
0x2caed0f2,
0x560cb720,
0x4a2bb780,
0xdffc9e8a,
0xb5217d3e,
0xc0027892,
0x74c291a2,
0x9364c000,
0x470ab780,
0x5e04b740,
0x4002ba24,
0x58ffc200,
0x00c258ed,
0xd0a65897,
0x9e2d5908,
0x12425894,
0xe0385270,
0x4a7da8ce,
0x249a9ea5,
0xc001a0c2,
0xb7809180,
0xb720458a,
0xba24404a,
0x70484002,
0x907cc001,
0x478ab780,
0x4712b720,
0x5e04b740,
0xb5800a04,
0xba09478a,
0xd0a24003,
0x9e495e7f,
0xc2009e2d,
0x02185a6d,
0x5a17c200,
0x5908d226,
0x5a14c200,
0xe0389ea5,
0x149aa94d,
0x08869e4c,
0x312250b0,
0xb780a141,
0x0a04470a,
0x470ab580,
0xf01074c2,
0x0882aa59,
0x0892d001,
0x5994b720,
0x79022a04,
0xc0010360,
0xc00005b6,
0xb78090e2,
0x0a04414b,
0x414bb580,
0x415db740,
0x41c5b740,
0x8025f310,
0x82a7e010,
0x414db580,
0x41cdb520,
0x7088b783,
0x08827500,
0x0892d002,
0x0a0274c2,
0x0a42d002,
0xc0007848,
0xc07c90c2,
0xb5408542,
0x74c2405a,
0x425db740,
0x90c4c000,
0xaa21da08,
0x9080c000,
0x404ab780,
0x80a1e310,
0x41cbb780,
0x424db520,
0xb5800a04,
0xb7bf41cb,
0xb7df7f6e,
0x8c407fee,
0xc0369c22,
0x9e5c0cfe,
0xc000b481,
0xc0029c22,
0xd01172c0,
0x9c221c0a,
0x9c220802,
0x588cb780,
0xda088502,
0xf010a88d,
0xf010a16b,
0xf010a16f,
0xd810a173,
0xd810a16f,
0xf010a16b,
0x9c22a0e1,
0x5a14b720,
0xa8e9d810,
0x414bb520,
0xaa71f010,
0x5a8cb740,
0x5a0fc200,
0xa245f048,
0xa8edf010,
0x41cdb520,
0xaa69f010,
0x414db580,
0xa96ff010,
0xa869f010,
0x8021e210,
0xa041f008,
0xc0309c22,
0xb740ac7d,
0xc038581c,
0xc030a45d,
0xc038ac7d,
0xc030a45d,
0xc038ac7d,
0xb720a45d,
0xb7805794,
0x8706588c,
0x5c0cb720,
0x8576c002,
0xa108d28a,
0x475bb540,
0xb5408502,
0xb5404039,
0x9c2240a1,
0x8420a61d,
0x5814b7a0,
0xb7a09e5a,
0xb57f578c,
0xd0117f74,
0x00810822,
0xaa2df210,
0x01030c82,
0xd2100503,
0x0189a8a9,
0x59ffd224,
0x5894b7c0,
0x2a1ed3f1,
0x7524c004,
0x5c8cb7c0,
0x0c020b82,
0x1c02d003,
0xa8cef250,
0xa3a5f208,
0xa04df208,
0x9e409e44,
0xa0a2f248,
0x20904a7d,
0x2a44c002,
0xd2103098,
0xc054a0a9,
0x097f98ac,
0x01819e92,
0xc0540581,
0xf20898a6,
0x0089aa35,
0x58ffd224,
0x9eaf7202,
0x90fac000,
0x90e4c000,
0xc0007002,
0xf2109094,
0xf208a075,
0xf250a947,
0xf210aa25,
0xf310a949,
0xd1248021,
0x00895908,
0x58ffd224,
0xfa08769c,
0xc000a0c9,
0x850a90b2,
0x91e0c000,
0x5a04c100,
0xc000751c,
0x850e90b2,
0x90e0c000,
0x7698c004,
0xe009850a,
0xf2108d22,
0xf210aa39,
0x1209a8f5,
0x6245c301,
0x70485890,
0x9236c000,
0xaa65d2d0,
0xc0007500,
0xda509184,
0x8506aa79,
0xa167d2d0,
0xda500a04,
0xc000a279,
0xf21093e0,
0xf210a8b9,
0xc301aa75,
0xc2006095,
0x71025a0c,
0x923cc000,
0xaa65d2d0,
0xc0007500,
0xda509184,
0x8506aa79,
0xa167d2d0,
0xda501a04,
0xc000a279,
0x850290a0,
0xa167d2d0,
0xaa79da50,
0x4002ba24,
0x752ac004,
0x90dac000,
0x855ac002,
0x9100c000,
0x7502c008,
0x90dcc000,
0x8506c004,
0xa17bda50,
0xa8f9da50,
0xaa4df208,
0xa8aef210,
0x4002ba09,
0xb7406243,
0x9e495a94,
0x62438502,
0xa959d050,
0x0a00c002,
0x5919d228,
0xf2087482,
0xc000a147,
0xf21090c4,
0xc000aa75,
0xf21092a0,
0xf210a8f6,
0xd0a2aa39,
0x12095c90,
0xc0007048,
0x764090b8,
0x91dcc000,
0x5d04d0a6,
0x802bf210,
0x5a13c200,
0x8a21f310,
0xa245f208,
0x9080c000,
0xa144f20a,
0xaa49f210,
0x7f6cb75f,
0x75020a04,
0xa149f208,
0xa249f210,
0x9144c000,
0xaa21d210,
0xa225dad0,
0xa251da50,
0x9040c009,
0x5a94b740,
0xaa51d050,
0xc0007500,
0xd0509184,
0x7500aa59,
0x9142c000,
0xaa41da90,
0xc0007504,
0x850690b4,
0x9060c000,
0xd2908502,
0xda10a153,
0xf210a94b,
0xf252aa4d,
0xd0b1a974,
0xf3100ed0,
0xd20889a1,
0xd3a4a922,
0xe0205987,
0x5d0483a7,
0x55eb018f,
0x9b48c034,
0xa9caf210,
0xaa65f250,
0x1cb4d011,
0x60c38502,
0xa8a2d208,
0xa177f250,
0x9e5b1d84,
0x0102d030,
0xe2205d85,
0x050381af,
0xa1e6f250,
0xc03455e7,
0xb7209b2f,
0xb7805a8c,
0x75004629,
0xa065f250,
0x90e2c001,
0xaa55da50,
0xda507500,
0xc000a957,
0xda909102,
0xe200aa41,
0xc0005a40,
0xb7809144,
0xda08598c,
0xdad0a881,
0xc001a0a1,
0xc2009120,
0xf3105a45,
0xda908021,
0xdad0a9c1,
0xdad0a221,
0x0d02a9a2,
0x9b04c034,
0xc0001804,
0xb74092e0,
0xda105a8c,
0xd848aa49,
0xc200a947,
0xc2005a40,
0xf3105a45,
0xda108021,
0xdad0a9c9,
0xdad0a221,
0x0d02a9a2,
0x9aecc034,
0xa021dad0,
0x7f6cb71f,
0x0a02d031,
0x5993d224,
0xf21076c2,
0x0d82aa49,
0x0db2d00d,
0xc0017504,
0xdad09094,
0xda50a8a2,
0xd011a8d1,
0x70480e14,
0x913ac000,
0xa961da10,
0x1a14d011,
0xc0007088,
0xd01190d6,
0xc0001e12,
0xd01191c0,
0x70481e14,
0x90f8c000,
0x0a14d011,
0xc0007088,
0xd01190dc,
0xdad00e12,
0xdad0a221,
0xf210a923,
0xdad0882f,
0xdad0a221,
0x7468a8a1,
0x9298c000,
0xa8e2da10,
0x1e14d011,
0xd00e7048,
0xc0000a12,
0xd011913c,
0x70480e14,
0x90dcc000,
0x1a12d011,
0xa221dad0,
0xaa49f210,
0xc0007504,
0xd21093b4,
0x752caa2d,
0x9312c000,
0xa8e2da10,
0xaa5dda50,
0x1c9cd011,
0x4002ba24,
0xc0007102,
0xdad091b6,
0xd011a8a1,
0x70481e16,
0x90dcc000,
0x1a14d011,
0xa221dad0,
0xa929d210,
0xaa21dad0,
0xd2107104,
0x0a02a8a6,
0x1a42d00a,
0xa8a1dad0,
0x9ea29e48,
0x4d7d2098,
0x21289e54,
0xc0803094,
0xc2005a40,
0x70085a41,
0xd0040902,
0x9e921922,
0x42440a7f,
0x20982494,
0x34949e8a,
0xa0a2dad0,
0xa0a6dad0,
0xa0d2da50,
0xb7808502,
0x87065a8c,
0xa148d292,
0xa14ff210,
0xa113d248,
0xa11bd248,
0xa15bd290,
0xa117d248,
0xa15fd290,
0xa107da48,
0xaa25dad0,
0xa14bda10,
0xa157da50,
0xa143da90,
0xa25dda50,
0x7deeb79f,
0x7e6eb7bf,
0x7eeeb7df,
0x7f6eb7ff,
0x8c20c002,
0xa60d9c22,
0x5a8cb7c0,
0x588cb780,
0x5a14b7c0,
0x76c20802,
0xa182f208,
0xc0030289,
0xb7a09044,
0xf2485794,
0xda10a045,
0xf210a049,
0xf210a9b6,
0x0d02a9a5,
0xc0345d84,
0xda089a0f,
0x0a22a8aa,
0x7008c010,
0xc01208c3,
0x76407002,
0x92e2c000,
0x580cb780,
0xa88df208,
0xa8a6f210,
0x5914d0a6,
0x88a3e210,
0x5d04d0a6,
0xc2015897,
0xe210812a,
0x088880a3,
0xf248588b,
0xf210a0b1,
0xd226aa25,
0xf3105904,
0xf2488021,
0xd224a8b1,
0x9e4c5889,
0xb3117102,
0x9e894828,
0xa0b2f248,
0xaa51d248,
0xc0007500,
0xd24891e2,
0x7500aa59,
0x9144c000,
0x5d0cd0a6,
0x802bf210,
0x5a0fc200,
0xa231f248,
0xa8b1f248,
0x5c8cb740,
0xf0086211,
0xc200a8da,
0x10985a17,
0xc4109e8a,
0xf2487244,
0x8502a0b2,
0xa14bf210,
0xa14ff210,
0xa143f208,
0x7eeeb79f,
0x7f6eb7bf,
0x7feeb7df,
0x9c228c60,
0xb720a61d,
0xb7e05c94,
0xb7405a8c,
0xf20840dd,
0x9e9daa61,
0x8821f310,
0x5884b760,
0x40cdb580,
0xaa29d210,
0xa265d080,
0xa8a9d210,
0x74429e4d,
0xb4279e5c,
0xb7c04622,
0xb7c05814,
0xf20a578c,
0xf210a960,
0xf208aa4d,
0xf040a957,
0xf310a9f7,
0xe3108a21,
0xf31080a1,
0xde018031,
0xf0407440,
0xf208a275,
0xc000a0d5,
0xcf0190d6,
0xf2080a02,
0xf210a255,
0xf208a94f,
0xf310aa61,
0xfa088821,
0x0089a829,
0x58ffd224,
0x0002e000,
0xd0030402,
0xd0220c02,
0xc0005e0c,
0xd02058f5,
0xc0003118,
0xe000590c,
0x15201120,
0x1d22d003,
0x5cf4d122,
0x5a0dc100,
0xf0403198,
0x0087aa75,
0x58ffd1a4,
0xfa087500,
0xfa08a029,
0xc000a0ad,
0x850290b6,
0xa177f040,
0xaa61f000,
0xc0007504,
0xd0b19344,
0xd2080e60,
0xf208a882,
0xf208a9a9,
0x9e4ca8a5,
0x5985d1a4,
0x5133d026,
0x81afe220,
0xf2080503,
0xc034a1c6,
0xf208992b,
0xc001a045,
0xf2089320,
0xd800aa29,
0x8502a8e9,
0xa16fd080,
0xf2081a04,
0x0884a229,
0xa0e9d800,
0xa8a2d210,
0xc0017640,
0xf21090e4,
0xf040aa5d,
0x6a36a8f5,
0x5a13c200,
0xc0007048,
0x8506929c,
0xa12bd210,
0xaa29f208,
0xc0007500,
0xd21091c2,
0xda48aa49,
0xf310a967,
0xda488021,
0xc000a265,
0xd2109080,
0xf208a0aa,
0x7500aa29,
0x9084c000,
0xa229d210,
0x7e6eb79f,
0x7eeeb7bf,
0x7f6eb7df,
0x7feeb7ff,
0x8c00c002,
0xb7809c22,
0xb7205a8c,
0xf208588c,
0xb720a903,
0x9e8a4035,
0x812fe210,
0x01897642,
0xa101f208,
0x9144c008,
0xaa49d810,
0xc0007500,
0xd09090e2,
0x76c0a9ce,
0x91c2c000,
0x5a0cb780,
0x578cb720,
0xa88ada08,
0x00039ea0,
0x46b3b520,
0x9220c001,
0x5a14b720,
0x580cb720,
0x414bb780,
0x412bb740,
0xd0116a14,
0x710268a6,
0x578cb700,
0xc0000403,
0xb78091bc,
0xb72046aa,
0xba24414a,
0x6a164002,
0x70485888,
0x917ac000,
0x414ab720,
0x6a26d3f1,
0x5a23c200,
0xc0007048,
0x8506915c,
0xa177d048,
0xd090850e,
0xc000a14b,
0xd0489080,
0xb780a1f6,
0xf2085c8c,
0x747ca88d,
0x93b2c004,
0xaa49f010,
0xc0007502,
0xd8109364,
0x7500aa49,
0x90e2c000,
0xaa4dd090,
0xc0007500,
0xf0489222,
0x8502a8e5,
0xa157d090,
0x412cb520,
0x414ab780,
0x40aab580,
0xa15bd090,
0x93e0c003,
0xa8dad090,
0xc0007640,
0xb7809342,
0xb72040aa,
0xba24414a,
0x688c4002,
0xc2000242,
0xb5805a0b,
0xf04840aa,
0x8502a8e5,
0x412cb520,
0xa15bd090,
0xd0908506,
0xc003a157,
0xb7409040,
0xd090580c,
0xb720a0d6,
0xd808414a,
0x68a8aa49,
0x70486a24,
0x925cc001,
0x40aab780,
0x414ab720,
0x4002ba24,
0x58846a0e,
0xc0017048,
0xb78090fc,
0xf048412c,
0xd226a8e5,
0xf3105904,
0x70488021,
0x939cc000,
0xd0908506,
0xd090a15b,
0xd808a15f,
0xd048aa55,
0xd810a173,
0x6a14a8c9,
0x5a0fc200,
0xd8507048,
0xd890a0d6,
0xc000a0c2,
0x8502907a,
0xa17bd048,
0x90a0c001,
0xaa75d048,
0x85027500,
0xa15bd090,
0x93a4c000,
0x40aab780,
0x414ab720,
0x4002ba24,
0x6947d013,
0x80a3e210,
0x4134b720,
0xb520588b,
0xf04840aa,
0xd0a6aa65,
0xc2015d04,
0xf310812a,
0xc2008021,
0xb5805a0b,
0xb780412c,
0xb580414a,
0xd09046aa,
0x7440a8dd,
0x9202c000,
0xaa71d048,
0x85067500,
0x9102c000,
0xaa79d048,
0xc0007500,
0x850e9064,
0xa14bd090,
0xaa49d810,
0xb3407500,
0xb78048a4,
0xb580414c,
0x9c2245ac,
0xb3407644,
0xc00348a4,
0xc0007486,
0xb720931a,
0xb7405814,
0xb7205f04,
0x9e2d4ccb,
0x5904d0a6,
0xaa4dc830,
0x578cb720,
0x05836229,
0xc2000003,
0xb5805a37,
0xc00141ad,
0xb7009100,
0xc100578c,
0x75005a4b,
0x5814b760,
0xc0000c82,
0xc200911c,
0x75005a07,
0xffff0c84,
0xd8d0939a,
0xb740a8e5,
0xd0a65f04,
0x9e2d5904,
0xaa61f008,
0xa8cdc830,
0xc2009e4a,
0x6243520b,
0xe2108536,
0xc20088ab,
0xb5805207,
0xf01041ac,
0x7502aa49,
0x90e4c000,
0x41acb780,
0x422cb580,
0xd0909c22,
0x74c0a9d1,
0x90e4c005,
0x422cb740,
0x41b4b720,
0x590cd126,
0x5c88d0a2,
0x8825f210,
0xc0007048,
0xd0a69176,
0xe2105d0c,
0xc10088ab,
0x70485a08,
0x91bac004,
0x85869e4c,
0xd0907104,
0xd090a1cf,
0xc002a1df,
0x9e49905c,
0x5a04c100,
0xc0007048,
0xd0a290f6,
0x71045e04,
0x937ac000,
0x472ab720,
0x5c94b720,
0xb5200898,
0xb780472a,
0xf01041cd,
0xb740a8ed,
0x624340c5,
0xc2000a20,
0xf3105a11,
0x851a8221,
0xa14bd090,
0xc002850e,
0xb7209340,
0xb720472a,
0x08885c94,
0x472ab520,
0x41cdb780,
0xa8edf010,
0x40c5b740,
0x0a406243,
0x5a15c200,
0x8221f310,
0xd090850e,
0xb580a14b,
0xb56040cd,
0xfffc4c38,
0x9e499320,
0x5a04c100,
0xc0007048,
0xd0a290f6,
0x71045e04,
0x937ac000,
0x472ab720,
0x5c94b720,
0xb5201888,
0xb780472a,
0xf01041cd,
0xb740a8ed,
0x624340c5,
0xc2000a40,
0xf3105a15,
0x851a8a21,
0xa14bd090,
0xc000857b,
0xb7209340,
0xb720472a,
0x18845c94,
0x472ab520,
0x41cdb780,
0xa8edf010,
0x40c5b740,
0xc0026243,
0xc2000a00,
0xf3105a19,
0x850e8a21,
0xa14bd090,
0xb580857f,
0xb54040cd,
0xfffa4c38,
0xd09092e0,
0xfffaa1cd,
0x85029260,
0xa14fd090,
0x91c0fffa,
0xb780a60d,
0xf208588c,
0x9ea5a881,
0x00077444,
0xc0000301,
0xb7809104,
0xdac8580c,
0xc008a805,
0x74429160,
0x9104c008,
0xaa29da10,
0xc0007500,
0xd2909324,
0x7500aa2d,
0x9284c000,
0xaa25d290,
0x580cb720,
0x5a94b720,
0xb7007500,
0xb7804cab,
0xd00244cb,
0x02400a46,
0x44cbb580,
0x9180c007,
0xaa2dd290,
0xc0017500,
0xb7209342,
0xb7805814,
0xd290578c,
0xb760a926,
0xb7605a94,
0xd2c840c9,
0xb740a881,
0x76804149,
0xba090407,
0x00024000,
0x0a02d011,
0x4422b304,
0xc0100009,
0xcc127004,
0x768070c0,
0xaa65d850,
0xd0020007,
0x02400a46,
0xa265d850,
0x4648b780,
0xc0007500,
0xda5091a2,
0xda90a937,
0xe210aa21,
0x0a0480a7,
0xa221da90,
0xa0b5da50,
0xc0050007,
0xd29091e0,
0x7500aa39,
0x9162c001,
0x580cb780,
0xa881d208,
0xa909d208,
0xaa85d208,
0xaa25d290,
0x0812d011,
0x7004c010,
0x5a8cb720,
0x7140d412,
0x000b7500,
0x44abb780,
0x0a46d002,
0xda500240,
0xb580a937,
0xda9044ab,
0xf310a8a1,
0x000b8023,
0xda900884,
0xda50a0a1,
0xc004a235,
0xb7809020,
0xf250578c,
0xf248a8b1,
0x7440a991,
0xf2489ea6,
0xc000a189,
0xb7209316,
0xb7805a8c,
0x75004729,
0xd0029e88,
0xc0000802,
0xd29090a4,
0x0008aa29,
0x580cb780,
0xa889d208,
0xc0109ea2,
0xc0017040,
0xb7a091a0,
0xd0b1580c,
0xd2080a50,
0xf250a882,
0x1196a929,
0xa8adf208,
0x9e4c5c85,
0xcc12588b,
0x515070c2,
0xd12651f3,
0xd1a45914,
0xe2205987,
0x0d0281af,
0xa129f250,
0x99f6c014,
0xc0149e83,
0xd2909a1d,
0x9eaaa8a9,
0x5a94b700,
0xc0100262,
0x10e27008,
0x7040c012,
0xa8a6d290,
0xa8c9d010,
0xd0107640,
0xd011a945,
0xb3040a02,
0x00094422,
0x7040c010,
0x7080c812,
0xb7807640,
0x000544ca,
0x0a46d002,
0xb78000c0,
0x75004648,
0x44cab520,
0x91a2c000,
0xa937da50,
0xaa21da90,
0x80a5e210,
0xda900a04,
0xda50a221,
0xd810a0b5,
0xda10aa55,
0x1a08a8a9,
0xb4167048,
0x00054443,
0x7eeeb79f,
0x7f6eb7bf,
0x7feeb7df,
0x9c228c60,
0xb720a60d,
0xb780588c,
0x7502402d,
0xc00b0283,
0xb78093a4,
0xf2085a0c,
0xc003a90e,
0x01897686,
0x93bac000,
0x598cb780,
0x5f04b740,
0xa882f208,
0x580cb740,
0xd0a69e2d,
0xd0b15d04,
0xc8300a20,
0xd208a8cd,
0x9e54a882,
0x9e9660c3,
0x5817d0a4,
0x578cb7c0,
0xc0015407,
0xd1229180,
0xb7c05ccb,
0x74405814,
0x578cb7c0,
0xc0000d02,
0x588790fc,
0x0d047440,
0x93baffff,
0x598cb780,
0x5f04b740,
0xa882f208,
0xd0a69e2d,
0xd0b15d04,
0xc8300e60,
0xf008a8ce,
0xd208a8ed,
0x9e54a901,
0x50b39d1e,
0x6097c301,
0xd0a49e91,
0x54075817,
0xda085408,
0x7500aa29,
0x90e2c000,
0xaa2dd288,
0xc0007500,
0xf24892c2,
0xf210a957,
0xf2488029,
0xf248a255,
0xf248a026,
0xf248a02a,
0xf008a042,
0xf248aa69,
0xf248a24d,
0xc007a251,
0xd2889320,
0x7500aa39,
0x91e4c007,
0x5a8cb720,
0x46a9b780,
0x9e897500,
0x90e4c007,
0xa957f248,
0x8029f210,
0xa255f248,
0xa8b5d288,
0xc0007440,
0xf00890c2,
0xc000aa69,
0xf2489240,
0xf008a8cd,
0xd0a6aa69,
0xe2405908,
0xd2268123,
0xf3105904,
0xf3108021,
0xc2008221,
0xf2485a0d,
0xf248a24d,
0xf248aa4d,
0xd288a251,
0x7440a8b5,
0x9102c000,
0xa026f248,
0xa02af248,
0x9380c005,
0x4649b780,
0xc0017500,
0xda8890e2,
0xf248a8a2,
0xda88a925,
0x1c84aa21,
0xd0b19d1e,
0xd3330ce0,
0xb7606127,
0xc2004031,
0xc2005a40,
0xc2015a45,
0xf3108128,
0x9ea18021,
0xa9a1da88,
0xf2480507,
0x55afa225,
0x98d8c014,
0xa025f248,
0xa029f248,
0x9240c004,
0xa92bda08,
0xaa2df208,
0xa8a6f248,
0x88a1e310,
0xda0a9e4a,
0x8185a928,
0xd0331884,
0xf3206122,
0xf31088b1,
0xc0088a21,
0xc2007740,
0xc2015a07,
0xf3108128,
0xf2488021,
0xc000a225,
0x058b91dc,
0x9be1ffb4,
0xaa25f248,
0xc2009e81,
0xc20056a7,
0xf2485203,
0xb740a225,
0xf2485f84,
0xd2a6aa25,
0x9e2d5d04,
0xa8cdc830,
0xd2240189,
0x0c8259ff,
0x05030103,
0x98ffc014,
0x601cb740,
0xc2109dc7,
0x0181a92a,
0xc0140581,
0xf20898db,
0x7502aa29,
0xa025f248,
0x90c4c000,
0xa029f248,
0x9040c002,
0xa8aada08,
0xa954da12,
0x5c84d0a2,
0x8e22f011,
0xc0007048,
0xf2489176,
0x0208aa41,
0x5a07c200,
0xa229f248,
0x91c0c001,
0xa8c1f248,
0x0e12d011,
0xf3109e4a,
0xd0338a21,
0x60996104,
0x8122c201,
0xa12bf248,
0xaa55da10,
0x0ce0d0b1,
0xc2001a04,
0xf3105a07,
0xb7608021,
0xf2484031,
0xda10a229,
0x9ea1a9d5,
0x55af0507,
0xc0141984,
0xf248984b,
0xc000a029,
0xf20890e0,
0x0a04aa2d,
0xa22df208,
0xa8c5f248,
0xaa29f208,
0xa8aaf248,
0x5904d0a6,
0xc2017502,
0xf2108122,
0xf248802b,
0xc200a0ae,
0xc000588b,
0x9e4a90f4,
0x7044d010,
0xa229f248,
0x7eeeb79f,
0x7f6eb7bf,
0x7feeb7df,
0x9c228c60,
0x588cb720,
0xaa61d810,
0xb5800802,
0x9c2241ab,
0x580cb740,
0x5c94b720,
0xa96cf012,
0xaa4df008,
0x414db720,
0x40ddb740,
0x8a21f310,
0xf3106243,
0xb5808021,
0xf01040cd,
0xf008a8ed,
0x9c22a0cd,
0x74c0c008,
0x9e529e58,
0x90fcc000,
0x70c0d002,
0x51f31a14,
0xc0055013,
0xc0007400,
0xd00290fc,
0x1a507000,
0x01285013,
0x5f84b740,
0x600cb780,
0x5904d1a6,
0xc0409e2d,
0xc830a8e5,
0x7044aa4d,
0xd01d6009,
0xd01a1214,
0xb3405013,
0x122248ba,
0x9c225010,
0x75269e5c,
0xd01e0882,
0xb3404000,
0xc38048bc,
0xc0007500,
0xc00290bc,
0x9c22084e,
0x7508c004,
0x915cc000,
0xc2000a04,
0xc0045a07,
0x08847508,
0x935affff,
0x609cb740,
0xc2209d4b,
0xd013a805,
0xe210691d,
0x9c228021,
0x0d00e000,
0x4422b330,
0x4842b330,
0x48a2b340,
0x8502c002,
0x882df210,
0xc0007500,
0x9e5990fa,
0x12090c02,
0x9c225031,
0x50d09e5a,
0x54699e52,
0x30425269,
0xa6859c22,
0x9e810007,
0xcffe9e90,
0x9e412cfc,
0x5c419e4c,
0xcffe6491,
0x62c328fc,
0x9e445841,
0x60096083,
0x5a41c280,
0x04909ea0,
0x9d099e88,
0x9e4c0490,
0xc0017102,
0xd0a28504,
0xb3025e41,
0xf3204468,
0xd0a68121,
0xcffe5d40,
0xf3102afc,
0x000d8123,
0x9e54040d,
0x6138d033,
0x61459e5c,
0x8125e210,
0x04629e91,
0x7f6eb7bf,
0x7feeb7df,
0x9c228c40,
0x87c2c809,
0x0c20b060,
0x87c2c809,
0x0a60b060,
0x87c2c809,
0x09c0b060,
};
unsigned long aui32H264VBR_MasterMTXTOPAZFWData[] =
{
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x809000b0,
0x80900364,
0x82884394,
0x82883ec0,
0x82883ed0,
0x82883f70,
0x82883de0,
0x82883e78,
0x82883fa0,
0x82883fd8,
0x82884014,
0x8288404c,
0x82884050,
0x82884080,
0x828840b0,
0x828840d8,
0x82883dd4,
0x828840e0,
0x828840e8,
0x82884118,
0x82884120,
0x82884154,
0x828845f4,
0x828844c6,
0x8288452e,
0x828845b0,
0x828844a0,
0x82884354,
0x8288445c,
0x8288449c,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x809007b8,
0x809007b8,
0x809028e0,
0x80902444,
0x809037f8,
0x80902cb8,
0x80902688,
0x809007b8,
0x809007b8,
0x809007b8,
0x809007b8,
0x809007b8,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0xa0101100,
0xa01001b0,
0xa0101102,
0xa01001b2,
0xa0101104,
0xa0100124,
0xa0101106,
0xa0100126,
0xa0100134,
0x00000000,
0xa0101120,
0xa0100136,
0xa0101122,
0xa0100144,
0x80101160,
0x80101162,
0x80101180,
0x80101182,
0x80100140,
0x80100142,
0x80100150,
0x80100152,
0x80100154,
0x80100146,
0x803003a0,
0x80100100,
0x80105156,
0xa0101164,
0xa0100184,
0x80101194,
0x801001b4,
0x80100146,
0x00000000,
0x00000003,
0x00000002,
0x00000002,
0x00000001,
0x00000001,
0x00000001,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000005,
0x000f9400,
0x000f9401,
0x000fd403,
0x000fd407,
0x000fd517,
0x000fdd37,
0x000fff37,
0x000ffb37,
0x00006b37,
0x00006b36,
0x00002b36,
0x00002b30,
0x00002a20,
0x40002220,
0x00000000,
0x00000000,
0x00010001,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x01010000,
0x02020201,
0x04030303,
0x05040404,
0x00140005,
0x001a0016,
0x0020001c,
0x00280024,
0x0034002c,
0x00400038,
0x00500048,
0x00680058,
0x00800070,
0x00a00090,
0x00d000b0,
0x010000e0,
0x01400120,
0x01a00160,
0x020001c0,
0x02800240,
0x034002c0,
0x04000380,
0x05000480,
0x06800580,
0x08000700,
0x0a000900,
0x0d000b00,
0x10000e00,
0x14001200,
0x1a001600,
0x00001c00,
0x00200040,
0x001002ab,
0x015500cd,
0x00080249,
0x00cd01c7,
0x0155005d,
0x0249013b,
0x00040111,
0x01c700f1,
0x00cd01af,
0x005d00c3,
0x01550059,
0x013b0029,
0x0249025f,
0x01110235,
0x00020021,
0x00f1001f,
0x01c70075,
0x01af006f,
0x00cd0069,
0x00c30019,
0x005d017d,
0x0059005b,
0x015502b9,
0x002900a7,
0x013b0283,
0x025f0135,
0x02490095,
0x0235023f,
0x0111008b,
0x00210219,
0x00010041,
0x0b060600,
0x0c0b0a06,
0x0a0b0c06,
0x0c0d0c0c,
0x0d0d0c06,
0x0b0b0c0c,
0x0e0d0a0d,
0x0a0d0e0e,
0x0c0d0a06,
0x0c0e0c0e,
0x0e0d0a0d,
0x0f0c0c0c,
0x0f0b0d0e,
0x0d0f0e0e,
0x0d0f0f0f,
0x0c0b0f0e,
0x00000006,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x1234baac,
0x00000000,
};
unsigned long aui32H264VBR_MasterMTXTOPAZFWTextReloc[] =
{
0
};
unsigned char aui8H264VBR_MasterMTXTOPAZFWTextRelocType[] =
{
0
};
unsigned long aui32H264VBR_MasterMTXTOPAZFWTextRelocFullAddr[] =
{
0
};
unsigned long aui32H264VBR_MasterMTXTOPAZFWDataReloc[] =
{
0
};
|
the_stack_data/155249.c | /**
* @copyright(C) 2021 Andreas Bank, [email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int hex2uint(char c) {
if (c >= '0' && c <= '9') {
return c - '0';
} else if (c >= 'a' && c <= 'f') {
return c - 'a' + 10;
} else if (c >= 'A' && c <= 'F') {
return c - 'A' + 10;
} else {
return -1;
}
}
int main(int argc, char **argv) {
int retval = 1;
FILE *fp = NULL;
const char *hex = NULL;
size_t hex_len;
uint8_t *bin = NULL;
size_t bin_len;
const char *filename = NULL;
FILE *write_dest = stdout;
size_t arg_idx = 1;
int written;
if (argc != 2 && argc != 4) {
fprintf(stderr, "Wrong number of arguments\n");
return 1;
}
if (strcmp(argv[arg_idx], "-f") == 0) {
arg_idx++;
filename = argv[arg_idx++];
}
hex_len = strlen(argv[arg_idx]);
hex = argv[arg_idx++];
/* Convert the hexadecimal string to binary */
bin_len = hex_len / 2;
bin = malloc(bin_len);
for (size_t i = 0; i < bin_len; i++) {
char u1 = hex2uint(hex[i*2]);
char u2 = hex2uint(hex[i*2 + 1]);
if (u1 < 0 || u1 > 15 || u2 < 0 || u2 > 15) {
fprintf(stderr, "Invalid HEX characters in string "
"('%c' or '%c'))\n", u1, u2);
goto cleanup;
}
bin[i] = (uint8_t) ((u1 << 4) | u2);
}
if (filename != NULL) {
if ((fp = fopen(filename, "wbx")) == NULL) {
fprintf(stderr, "Failed to create file: %s\n",
strerror(errno));
goto cleanup;
}
write_dest = fp;
}
written = fwrite(bin, 1, bin_len, write_dest);
if (written != bin_len) {
fprintf(stderr, "Failed to write data to file: %s\n",
strerror(errno));
goto cleanup;
}
printf("\n");
retval = 0;
#if TEST
char *test_str = malloc(bin_len * 2 + 1);
for (size_t i = 0; i < bin_len; i++) {
sprintf(&test_str[i * 2], "%02x", bin[i]);
}
test_str[bin_len * 2] = '\0';
printf("input string: '%s', test string: '%s'\n", hex, test_str);
printf("Test result: %s\n",
strcmp(hex, test_str) == 0 ? "SUCCESS" : "FAILURE");
#endif
cleanup:
if (fp != NULL) {
fclose(fp);
}
if (bin) {
free(bin);
}
return retval;
}
|
the_stack_data/57949514.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* \brief Check if majority element present
* Check if majority element is present in array.
* __IMPORTANT__ O(N)
*
* \param[in] A array of integers (long*)
* \param[in] size_a size of array (size_t)
* \return 1 is majority element present 0 otherwise (int)
* */
int majority_element(long* A, size_t size_a);
/*
* \brief Check if majority element present
* Check if majority element is present in array.
* __IMPORTANT__ O(ln(N))
*
* \param[in] A array of integers (long*)
* \param[in] size_a size of array (size_t)
* \return 1 is majority element present 0 otherwise (int)
* */
int majority_element_sort(long* A, size_t size_a);
int compare(const void* a, const void* b) {
const long* A = a;
const long* B = b;
if (*A < *B) return -1;
if (*A == *B) return 0;
if (*A > *B) return 1;
}
int main() {
long i, N;
long* Array;
scanf("%ld", &N);
Array = (long*) malloc(sizeof(long) * N);
i = 0;
int count = 0;
long test = 0;
while (i < N) {
scanf("%ld", &Array[i]);
i++;
}
//check simplest cases
if (N == 1) {
count = 1;
} else {
count = majority_element(Array, N);
// maj = majority_element_sort(Array, N);
}
printf("%d\n", count);
free(Array);
}
int majority_element(long* a, size_t size_a) {
long count, i, curr_num;
curr_num = a[0];
count = 0;
// get element with the biggest frequency
//
for (i = 1; i < size_a; i++) {
if (a[i] == curr_num) count++;
else if (count == 0) {
curr_num = a[i];
count = 0;
} else count--;
}
// check if element is majority element
count = 0;
for (i = 0; i < size_a; ++i) {
if (curr_num == a[i]) count++;
}
if (count > size_a / 2)
return 1;
else return 0;
}
int majority_element_sort(long* A, size_t size_a) {
long Mid, median, count;
long i;
Mid = size_a / 2;
count = 0;
// sort array
qsort(A, size_a, sizeof(long), &compare);
median = A[Mid];
// check if median is majority element
for (i = 0; i < size_a; ++i) {
if (median == A[i]) count++;
}
if (count > Mid) return 1;
else return 0;
}
|
the_stack_data/165766357.c |
int main(){
return 0x1F;
}
|
the_stack_data/70449013.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
FILE* f;
char buffer[100];
f = fopen("input.txt", "r");
if (f == NULL) {
return 1;
}
int numberOfValid = 0;
while (fgets(buffer, sizeof(buffer), f)) {
int pos1, pos2;
char letter;
char password[100];
int occurences = 0;
sscanf(buffer, "%d-%d %c: %s", &pos1, &pos2, &letter, password);
if((password[pos1-1] == letter || password[pos2-1] == letter)
&& !(password[pos1-1] == letter && password[pos2-1] == letter)) {
numberOfValid++;
}
}
printf("Valid passwords: %d\n", numberOfValid);
fclose(f);
return 0;
} |
the_stack_data/122947.c |
#include <stdio.h>
int main()
{
int i, j;
for (i = 0; i < 4; i++)
{
for (j = 0; j < i; j++)
{
printf(" ");
}
for (j = 0; j < 5; j++)
{
printf("*");
}
printf("\n");
}
return 0;
} |
the_stack_data/225144425.c | /*
Glidix Runtime
Copyright (c) 2014-2017, Madd Games.
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.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <string.h>
void *calloc(size_t nitems, size_t size)
{
size_t totalSize = nitems * size;
void *ret = malloc(totalSize);
memset(ret, 0, totalSize);
return ret;
};
|
the_stack_data/145313.c | // forkExecChild.c sleeps for a while to show the use of fork+exec*
// to start several child programs.
//
// build: cc forkExecChild.c -o forkExecChild
// use: ./forkExecChild
// ./forkExecChild 3
/////////////////////////////////////////////////////////////////////
#include <stdio.h> // printf
#include <stdlib.h> // atoi
#include <unistd.h> // getpid sleep
// EXIT_SUCCESS or EXIT_FAILURE or an error number would be recommended.
// But in this trial I use the input value to show the relation
// between child and parent by the use of the exit status.
int main(const int argc, const char *argv[])
{
int seconds = 1;
if (argc > 1)
seconds = atoi(argv[1]);
printf("Child pid %d sleeps for %d seconds.\n", getpid(), seconds);
sleep(seconds);
printf("Child pid %d exits with %d.\n", getpid(), seconds);
return seconds;
}
|
the_stack_data/305141.c | /*************************************************************************
> File Name: bt.c
> Author: xgod
> Mail: [email protected]
> Created Time: Tue 15 Mar 2016 11:11:49 AM CST
************************************************************************/
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void
myfunc3(void)
{
int j, nptrs;
#define SIZE 100
void *buffer[100];
char **strings;
nptrs = backtrace(buffer, SIZE);
printf("backtrace() returned %d addresses\n", nptrs);
/* The call backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO)
* would produce similar output to the following: */
strings = backtrace_symbols(buffer, nptrs);
if (strings == NULL) {
perror("backtrace_symbols");
exit(EXIT_FAILURE);
}
for (j = 0; j < nptrs; j++)
printf("%s\n", strings[j]);
free(strings);
}
static void /* "static" means don't export the symbol... */
myfunc2(void)
{
myfunc3();
}
void
myfunc(int ncalls)
{
if (ncalls > 1)
myfunc(ncalls - 1);
else
myfunc2();
}
int
main(int argc, char *argv[])
{
if (argc != 2) {
fprintf(stderr, "%s num-calls\n", argv[0]);
exit(EXIT_FAILURE);
}
myfunc(atoi(argv[1]));
exit(EXIT_SUCCESS);
}
|
the_stack_data/165769341.c |
/* Avoid warning about empty compilation unit. */
void keyring_macos_dummy() { }
#ifdef __APPLE__
#include <CoreFoundation/CoreFoundation.h>
#include <Security/Security.h>
#include <R.h>
#include <R_ext/Rdynload.h>
#include <Rinternals.h>
#include <sys/param.h>
#include <string.h>
void keyring_macos_error(const char *func, OSStatus status) {
CFStringRef str = SecCopyErrorMessageString(status, NULL);
CFIndex length = CFStringGetLength(str);
CFIndex maxSize =
CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
char *buffer = R_alloc(maxSize, 1);
if (CFStringGetCString(str, buffer, maxSize, kCFStringEncodingUTF8)) {
error("keyring error (macOS Keychain), %s: %s", func, buffer);
} else {
error("keyring error (macOS Keychain), %s", func);
}
}
void keyring_macos_handle_status(const char *func, OSStatus status) {
if (status != errSecSuccess) keyring_macos_error(func, status);
}
SecKeychainRef keyring_macos_open_keychain(const char *pathName) {
SecKeychainRef keychain;
OSStatus status = SecKeychainOpen(pathName, &keychain);
keyring_macos_handle_status("cannot open keychain", status);
/* We need to query the status, because SecKeychainOpen succeeds,
even if the keychain file does not exists. (!) */
SecKeychainStatus keychainStatus = 0;
status = SecKeychainGetStatus(keychain, &keychainStatus);
keyring_macos_handle_status("cannot open keychain", status);
return keychain;
}
SEXP keyring_macos_get(SEXP keyring, SEXP service, SEXP username) {
const char* empty = "";
const char* cservice = CHAR(STRING_ELT(service, 0));
const char* cusername =
isNull(username) ? empty :CHAR(STRING_ELT(username, 0));
void *data;
UInt32 length;
SEXP result;
SecKeychainRef keychain =
isNull(keyring) ? NULL :
keyring_macos_open_keychain(CHAR(STRING_ELT(keyring, 0)));
OSStatus status = SecKeychainFindGenericPassword(
keychain,
(UInt32) strlen(cservice), cservice,
(UInt32) strlen(cusername), cusername,
&length, &data,
/* itemRef = */ NULL);
if (keychain != NULL) CFRelease(keychain);
keyring_macos_handle_status("cannot get password", status);
result = PROTECT(allocVector(RAWSXP, length));
memcpy(RAW(result), data, length);
SecKeychainItemFreeContent(NULL, data);
UNPROTECT(1);
return result;
}
SEXP keyring_macos_set(SEXP keyring, SEXP service, SEXP username,
SEXP password) {
const char* empty = "";
const char* cservice = CHAR(STRING_ELT(service, 0));
const char* cusername =
isNull(username) ? empty : CHAR(STRING_ELT(username, 0));
SecKeychainItemRef item;
SecKeychainRef keychain =
isNull(keyring) ? NULL :
keyring_macos_open_keychain(CHAR(STRING_ELT(keyring, 0)));
/* Try to find it, and it is exists, update it */
OSStatus status = SecKeychainFindGenericPassword(
keychain,
(UInt32) strlen(cservice), cservice,
(UInt32) strlen(cusername), cusername,
/* passwordLength = */ NULL, /* passwordData = */ NULL,
&item);
if (status == errSecItemNotFound) {
status = SecKeychainAddGenericPassword(
keychain,
(UInt32) strlen(cservice), cservice,
(UInt32) strlen(cusername), cusername,
(UInt32) LENGTH(password), RAW(password),
/* itemRef = */ NULL);
} else {
status = SecKeychainItemModifyAttributesAndData(
item,
/* attrList= */ NULL,
(UInt32) LENGTH(password), RAW(password));
CFRelease(item);
}
if (keychain != NULL) CFRelease(keychain);
keyring_macos_handle_status("cannot set password", status);
return R_NilValue;
}
SEXP keyring_macos_delete(SEXP keyring, SEXP service, SEXP username) {
const char* empty = "";
const char* cservice = CHAR(STRING_ELT(service, 0));
const char* cusername =
isNull(username) ? empty : CHAR(STRING_ELT(username, 0));
SecKeychainRef keychain =
isNull(keyring) ? NULL : keyring_macos_open_keychain(CHAR(STRING_ELT(keyring, 0)));
SecKeychainItemRef item;
OSStatus status = SecKeychainFindGenericPassword(
keychain,
(UInt32) strlen(cservice), cservice,
(UInt32) strlen(cusername), cusername,
/* *passwordLength = */ NULL, /* *passwordData = */ NULL,
&item);
if (status != errSecSuccess) {
if (keychain != NULL) CFRelease(keychain);
keyring_macos_error("cannot delete password", status);
}
status = SecKeychainItemDelete(item);
if (status != errSecSuccess) {
if (keychain != NULL) CFRelease(keychain);
keyring_macos_error("cannot delete password", status);
}
if (keychain != NULL) CFRelease(keychain);
CFRelease(item);
return R_NilValue;
}
static void keyring_macos_list_item(SecKeychainItemRef item, SEXP result,
int idx) {
SecItemClass class;
SecKeychainAttribute attrs[] = {
{ kSecServiceItemAttr },
{ kSecAccountItemAttr }
};
SecKeychainAttributeList attrList = { 2, attrs };
/* This should not happen, not a keychain... */
if (SecKeychainItemGetTypeID() != CFGetTypeID(item)) {
SET_STRING_ELT(VECTOR_ELT(result, 0), idx, mkChar(""));
SET_STRING_ELT(VECTOR_ELT(result, 1), idx, mkChar(""));
return;
}
OSStatus status = SecKeychainItemCopyContent(item, &class, &attrList,
/* length = */ NULL,
/* outData = */ NULL);
keyring_macos_handle_status("cannot list passwords", status);
SET_STRING_ELT(VECTOR_ELT(result, 0), idx,
mkCharLen(attrs[0].data, attrs[0].length));
SET_STRING_ELT(VECTOR_ELT(result, 1), idx,
mkCharLen(attrs[1].data, attrs[1].length));
SecKeychainItemFreeContent(&attrList, NULL);
}
CFArrayRef keyring_macos_list_get(const char *ckeyring,
const char *cservice) {
CFStringRef cfservice = NULL;
CFMutableDictionaryRef query = CFDictionaryCreateMutable(
kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(query, kSecMatchLimit, kSecMatchLimitAll);
CFDictionarySetValue(query, kSecReturnData, kCFBooleanFalse);
CFDictionarySetValue(query, kSecReturnRef, kCFBooleanTrue);
CFDictionarySetValue(query, kSecClass, kSecClassGenericPassword);
CFArrayRef searchList = NULL;
if (ckeyring) {
SecKeychainRef keychain = keyring_macos_open_keychain(ckeyring);
searchList = CFArrayCreate(NULL, (const void **) &keychain, 1,
&kCFTypeArrayCallBacks);
CFDictionaryAddValue(query, kSecMatchSearchList, searchList);
}
if (cservice) {
cfservice = CFStringCreateWithBytes(
/* alloc = */ NULL,
(const UInt8*) cservice, strlen(cservice),
kCFStringEncodingUTF8,
/* isExternalRepresentation = */ 0);
CFDictionaryAddValue(query, kSecAttrService, cfservice);
}
CFArrayRef resArray = NULL;
OSStatus status = SecItemCopyMatching(query, (CFTypeRef*) &resArray);
CFRelease(query);
if (cfservice != NULL) CFRelease(cfservice);
if (searchList != NULL) CFRelease(searchList);
/* If there are no elements in the keychain, then SecItemCopyMatching
returns with an error, so we need work around that and return an
empty list instead. */
if (status == errSecItemNotFound) {
resArray = CFArrayCreate(NULL, NULL, 0, NULL);
return resArray;
} else if (status != errSecSuccess) {
if (resArray != NULL) CFRelease(resArray);
keyring_macos_handle_status("cannot list passwords", status);
return NULL;
} else {
return resArray;
}
}
SEXP keyring_macos_list(SEXP keyring, SEXP service) {
const char *ckeyring =
isNull(keyring) ? NULL : CHAR(STRING_ELT(keyring, 0));
const char *cservice =
isNull(service) ? NULL : CHAR(STRING_ELT(service, 0));
CFArrayRef resArray = keyring_macos_list_get(ckeyring, cservice);
CFIndex i, num = CFArrayGetCount(resArray);
SEXP result;
PROTECT(result = allocVector(VECSXP, 2));
SET_VECTOR_ELT(result, 0, allocVector(STRSXP, num));
SET_VECTOR_ELT(result, 1, allocVector(STRSXP, num));
for (i = 0; i < num; i++) {
SecKeychainItemRef item =
(SecKeychainItemRef) CFArrayGetValueAtIndex(resArray, i);
keyring_macos_list_item(item, result, (int) i);
}
CFRelease(resArray);
UNPROTECT(1);
return result;
}
SEXP keyring_macos_create(SEXP keyring, SEXP password) {
const char *ckeyring = CHAR(STRING_ELT(keyring, 0));
const char *cpassword = CHAR(STRING_ELT(password, 0));
SecKeychainRef result = NULL;
OSStatus status = SecKeychainCreate(
ckeyring,
/* passwordLength = */ (UInt32) strlen(cpassword),
(const void*) cpassword,
/* promptUser = */ 0, /* initialAccess = */ NULL,
&result);
keyring_macos_handle_status("cannot create keychain", status);
CFArrayRef keyrings = NULL;
status = SecKeychainCopyDomainSearchList(
kSecPreferencesDomainUser,
&keyrings);
if (status) {
SecKeychainDelete(result);
if (result != NULL) CFRelease(result);
keyring_macos_handle_status("cannot create keychain", status);
}
/* We need to add the new keychain to the keychain search list,
otherwise applications like Keychain Access will not see it.
There is no API to append it, we need to query the current
search list, add it, and then set the whole new search list.
This is of course a race condition. :/ */
CFIndex count = CFArrayGetCount(keyrings);
CFMutableArrayRef newkeyrings =
CFArrayCreateMutableCopy(NULL, count + 1, keyrings);
CFArrayAppendValue(newkeyrings, result);
status = SecKeychainSetDomainSearchList(
kSecPreferencesDomainUser,
newkeyrings);
if (status) {
SecKeychainDelete(result);
if (result) CFRelease(result);
if (keyrings) CFRelease(keyrings);
if (newkeyrings) CFRelease(newkeyrings);
keyring_macos_handle_status("cannot create keychain", status);
}
CFRelease(result);
CFRelease(keyrings);
CFRelease(newkeyrings);
return R_NilValue;
}
SEXP keyring_macos_list_keyring() {
CFArrayRef keyrings = NULL;
OSStatus status =
SecKeychainCopyDomainSearchList(kSecPreferencesDomainUser, &keyrings);
keyring_macos_handle_status("cannot list keyrings", status);
CFIndex i, num = CFArrayGetCount(keyrings);
SEXP result = PROTECT(allocVector(VECSXP, 3));
SET_VECTOR_ELT(result, 0, allocVector(STRSXP, num));
SET_VECTOR_ELT(result, 1, allocVector(INTSXP, num));
SET_VECTOR_ELT(result, 2, allocVector(LGLSXP, num));
for (i = 0; i < num; i++) {
SecKeychainRef keychain =
(SecKeychainRef) CFArrayGetValueAtIndex(keyrings, i);
UInt32 pathLength = MAXPATHLEN;
char pathName[MAXPATHLEN + 1];
status = SecKeychainGetPath(keychain, &pathLength, pathName);
pathName[pathLength] = '\0';
if (status) {
CFRelease(keyrings);
keyring_macos_handle_status("cannot list keyrings", status);
}
SET_STRING_ELT(VECTOR_ELT(result, 0), i, mkCharLen(pathName, pathLength));
CFArrayRef resArray =
keyring_macos_list_get(pathName, /* cservice = */ NULL);
CFIndex numitems = CFArrayGetCount(resArray);
CFRelease(resArray);
INTEGER(VECTOR_ELT(result, 1))[i] = (int) numitems;
SecKeychainStatus kstatus;
status = SecKeychainGetStatus(keychain, &kstatus);
if (status) {
LOGICAL(VECTOR_ELT(result, 2))[i] = NA_LOGICAL;
} else {
LOGICAL(VECTOR_ELT(result, 2))[i] =
! (kstatus & kSecUnlockStateStatus);
}
}
CFRelease(keyrings);
UNPROTECT(1);
return result;
}
SEXP keyring_macos_delete_keyring(SEXP keyring) {
const char *ckeyring = CHAR(STRING_ELT(keyring, 0));
/* Need to remove it from the search list as well */
CFArrayRef keyrings = NULL;
OSStatus status = SecKeychainCopyDomainSearchList(
kSecPreferencesDomainUser,
&keyrings);
keyring_macos_handle_status("cannot delete keyring", status);
CFIndex i, count = CFArrayGetCount(keyrings);
CFMutableArrayRef newkeyrings =
CFArrayCreateMutableCopy(NULL, count, keyrings);
for (i = 0; i < count; i++) {
SecKeychainRef item =
(SecKeychainRef) CFArrayGetValueAtIndex(keyrings, i);
UInt32 pathLength = MAXPATHLEN;
char pathName[MAXPATHLEN + 1];
status = SecKeychainGetPath(item, &pathLength, pathName);
pathName[pathLength] = '\0';
if (status) {
CFRelease(keyrings);
CFRelease(newkeyrings);
keyring_macos_handle_status("cannot delete keyring", status);
}
if (!strcmp(pathName, ckeyring)) {
CFArrayRemoveValueAtIndex(newkeyrings, (CFIndex) i);
status = SecKeychainSetDomainSearchList(
kSecPreferencesDomainUser,
newkeyrings);
if (status) {
CFRelease(keyrings);
CFRelease(newkeyrings);
keyring_macos_handle_status("cannot delete keyring", status);
}
}
}
/* If we haven't found it on the search list,
then we just keep silent about it ... */
CFRelease(keyrings);
CFRelease(newkeyrings);
/* And now remove the file as well... */
SecKeychainRef keychain = keyring_macos_open_keychain(ckeyring);
status = SecKeychainDelete(keychain);
CFRelease(keychain);
keyring_macos_handle_status("cannot delete keyring", status);
return R_NilValue;
}
SEXP keyring_macos_lock_keyring(SEXP keyring) {
SecKeychainRef keychain =
isNull(keyring) ? NULL :
keyring_macos_open_keychain(CHAR(STRING_ELT(keyring, 0)));
OSStatus status = SecKeychainLock(keychain);
if (keychain) CFRelease(keychain);
keyring_macos_handle_status("cannot lock keychain", status);
return R_NilValue;
}
SEXP keyring_macos_unlock_keyring(SEXP keyring, SEXP password) {
const char *cpassword = CHAR(STRING_ELT(password, 0));
SecKeychainRef keychain =
isNull(keyring) ? NULL :
keyring_macos_open_keychain(CHAR(STRING_ELT(keyring, 0)));
OSStatus status = SecKeychainUnlock(
keychain,
(UInt32) strlen(cpassword),
(const void*) cpassword,
/* usePassword = */ TRUE);
if (keychain) CFRelease(keychain);
keyring_macos_handle_status("cannot unlock keychain", status);
return R_NilValue;
}
SEXP keyring_macos_is_locked_keyring(SEXP keyring) {
SecKeychainRef keychain =
isNull(keyring) ? NULL :
keyring_macos_open_keychain(CHAR(STRING_ELT(keyring, 0)));
SecKeychainStatus kstatus;
OSStatus status = SecKeychainGetStatus(keychain, &kstatus);
if (status) keyring_macos_error("cannot get lock information", status);
return ScalarLogical(! (kstatus & kSecUnlockStateStatus));
}
static const R_CallMethodDef callMethods[] = {
{ "keyring_macos_get", (DL_FUNC) &keyring_macos_get, 3 },
{ "keyring_macos_set", (DL_FUNC) &keyring_macos_set, 4 },
{ "keyring_macos_delete", (DL_FUNC) &keyring_macos_delete, 3 },
{ "keyring_macos_list", (DL_FUNC) &keyring_macos_list, 2 },
{ "keyring_macos_create", (DL_FUNC) &keyring_macos_create, 2 },
{ "keyring_macos_list_keyring",
(DL_FUNC) &keyring_macos_list_keyring, 0 },
{ "keyring_macos_delete_keyring",
(DL_FUNC) &keyring_macos_delete_keyring, 1 },
{ "keyring_macos_lock_keyring",
(DL_FUNC) &keyring_macos_lock_keyring, 1 },
{ "keyring_macos_unlock_keyring",
(DL_FUNC) &keyring_macos_unlock_keyring, 2 },
{ "keyring_macos_is_locked_keyring",
(DL_FUNC) &keyring_macos_is_locked_keyring, 1 },
{ NULL, NULL, 0 }
};
void R_init_keyring(DllInfo *dll) {
R_registerRoutines(dll, NULL, callMethods, NULL, NULL);
R_useDynamicSymbols(dll, FALSE);
R_forceSymbols(dll, TRUE);
}
#endif // __APPLE__
|
the_stack_data/876701.c | typedef unsigned int size_t;
typedef long __time_t;
struct buf_mem_st {
int length ;
char *data ;
int max ;
};
typedef struct buf_mem_st BUF_MEM;
typedef __time_t time_t;
struct stack_st {
int num ;
char **data ;
int sorted ;
int num_alloc ;
int (*comp)(char const * const * , char const * const * ) ;
};
typedef struct stack_st STACK;
struct bio_st;
struct crypto_ex_data_st {
STACK *sk ;
int dummy ;
};
typedef struct crypto_ex_data_st CRYPTO_EX_DATA;
typedef struct bio_st BIO;
typedef void bio_info_cb(struct bio_st * , int , char const * , int , long ,
long );struct bio_method_st {
int type ;
char const *name ;
int (*bwrite)(BIO * , char const * , int ) ;
int (*bread)(BIO * , char * , int ) ;
int (*bputs)(BIO * , char const * ) ;
int (*bgets)(BIO * , char * , int ) ;
long (*ctrl)(BIO * , int , long , void * ) ;
int (*create)(BIO * ) ;
int (*destroy)(BIO * ) ;
long (*callback_ctrl)(BIO * , int , bio_info_cb * ) ;
};
typedef struct bio_method_st BIO_METHOD;
struct bio_st {
BIO_METHOD *method ;
long (*callback)(struct bio_st * , int , char const * , int , long , long ) ;
char *cb_arg ;
int init ;
int shutdown ;
int flags ;
int retry_reason ;
int num ;
void *ptr ;
struct bio_st *next_bio ;
struct bio_st *prev_bio ;
int references ;
unsigned long num_read ;
unsigned long num_write ;
CRYPTO_EX_DATA ex_data ;
};
struct bignum_st {
unsigned long *d ;
int top ;
int dmax ;
int neg ;
int flags ;
};
typedef struct bignum_st BIGNUM;
struct bignum_ctx {
int tos ;
BIGNUM bn[16] ;
int flags ;
int depth ;
int pos[12] ;
int too_many ;
};
typedef struct bignum_ctx BN_CTX;
struct bn_blinding_st {
int init ;
BIGNUM *A ;
BIGNUM *Ai ;
BIGNUM *mod ;
};
typedef struct bn_blinding_st BN_BLINDING;
struct bn_mont_ctx_st {
int ri ;
BIGNUM RR ;
BIGNUM N ;
BIGNUM Ni ;
unsigned long n0 ;
int flags ;
};
typedef struct bn_mont_ctx_st BN_MONT_CTX;
struct X509_algor_st;struct X509_algor_st;
struct asn1_object_st {
char const *sn ;
char const *ln ;
int nid ;
int length ;
unsigned char *data ;
int flags ;
};
typedef struct asn1_object_st ASN1_OBJECT;
struct asn1_string_st {
int length ;
int type ;
unsigned char *data ;
long flags ;
};
typedef struct asn1_string_st ASN1_STRING;
typedef struct asn1_string_st ASN1_INTEGER;
typedef struct asn1_string_st ASN1_ENUMERATED;
typedef struct asn1_string_st ASN1_BIT_STRING;
typedef struct asn1_string_st ASN1_OCTET_STRING;
typedef struct asn1_string_st ASN1_PRINTABLESTRING;
typedef struct asn1_string_st ASN1_T61STRING;
typedef struct asn1_string_st ASN1_IA5STRING;
typedef struct asn1_string_st ASN1_GENERALSTRING;
typedef struct asn1_string_st ASN1_UNIVERSALSTRING;
typedef struct asn1_string_st ASN1_BMPSTRING;
typedef struct asn1_string_st ASN1_UTCTIME;
typedef struct asn1_string_st ASN1_TIME;
typedef struct asn1_string_st ASN1_GENERALIZEDTIME;
typedef struct asn1_string_st ASN1_VISIBLESTRING;
typedef struct asn1_string_st ASN1_UTF8STRING;
typedef int ASN1_BOOLEAN;
union __anonunion_value_19 {
char *ptr ;
ASN1_BOOLEAN boolean ;
ASN1_STRING *asn1_string ;
ASN1_OBJECT *object ;
ASN1_INTEGER *integer ;
ASN1_ENUMERATED *enumerated ;
ASN1_BIT_STRING *bit_string ;
ASN1_OCTET_STRING *octet_string ;
ASN1_PRINTABLESTRING *printablestring ;
ASN1_T61STRING *t61string ;
ASN1_IA5STRING *ia5string ;
ASN1_GENERALSTRING *generalstring ;
ASN1_BMPSTRING *bmpstring ;
ASN1_UNIVERSALSTRING *universalstring ;
ASN1_UTCTIME *utctime ;
ASN1_GENERALIZEDTIME *generalizedtime ;
ASN1_VISIBLESTRING *visiblestring ;
ASN1_UTF8STRING *utf8string ;
ASN1_STRING *set ;
ASN1_STRING *sequence ;
};
struct asn1_type_st {
int type ;
union __anonunion_value_19 value ;
};
typedef struct asn1_type_st ASN1_TYPE;
struct MD5state_st {
unsigned int A ;
unsigned int B ;
unsigned int C ;
unsigned int D ;
unsigned int Nl ;
unsigned int Nh ;
unsigned int data[16] ;
int num ;
};
typedef struct MD5state_st MD5_CTX;
struct SHAstate_st {
unsigned int h0 ;
unsigned int h1 ;
unsigned int h2 ;
unsigned int h3 ;
unsigned int h4 ;
unsigned int Nl ;
unsigned int Nh ;
unsigned int data[16] ;
int num ;
};
typedef struct SHAstate_st SHA_CTX;
struct MD2state_st {
int num ;
unsigned char data[16] ;
unsigned int cksm[16] ;
unsigned int state[16] ;
};
typedef struct MD2state_st MD2_CTX;
struct MD4state_st {
unsigned int A ;
unsigned int B ;
unsigned int C ;
unsigned int D ;
unsigned int Nl ;
unsigned int Nh ;
unsigned int data[16] ;
int num ;
};
typedef struct MD4state_st MD4_CTX;
struct RIPEMD160state_st {
unsigned int A ;
unsigned int B ;
unsigned int C ;
unsigned int D ;
unsigned int E ;
unsigned int Nl ;
unsigned int Nh ;
unsigned int data[16] ;
int num ;
};
typedef struct RIPEMD160state_st RIPEMD160_CTX;
typedef unsigned char des_cblock[8];
union __anonunion_ks_20 {
des_cblock cblock ;
unsigned long deslong[2] ;
};
struct des_ks_struct {
union __anonunion_ks_20 ks ;
int weak_key ;
};
typedef struct des_ks_struct des_key_schedule[16];
struct rc4_key_st {
unsigned int x ;
unsigned int y ;
unsigned int data[256] ;
};
typedef struct rc4_key_st RC4_KEY;
struct rc2_key_st {
unsigned int data[64] ;
};
typedef struct rc2_key_st RC2_KEY;
struct rc5_key_st {
int rounds ;
unsigned long data[34] ;
};
typedef struct rc5_key_st RC5_32_KEY;
struct bf_key_st {
unsigned int P[18] ;
unsigned int S[1024] ;
};
typedef struct bf_key_st BF_KEY;
struct cast_key_st {
unsigned long data[32] ;
int short_key ;
};
typedef struct cast_key_st CAST_KEY;
struct idea_key_st {
unsigned int data[9][6] ;
};
typedef struct idea_key_st IDEA_KEY_SCHEDULE;
struct mdc2_ctx_st {
int num ;
unsigned char data[8] ;
des_cblock h ;
des_cblock hh ;
int pad_type ;
};
typedef struct mdc2_ctx_st MDC2_CTX;
struct rsa_st;typedef struct rsa_st RSA;
struct rsa_meth_st {
char const *name ;
int (*rsa_pub_enc)(int flen , unsigned char *from , unsigned char *to , RSA *rsa ,
int padding ) ;
int (*rsa_pub_dec)(int flen , unsigned char *from , unsigned char *to , RSA *rsa ,
int padding ) ;
int (*rsa_priv_enc)(int flen , unsigned char *from , unsigned char *to , RSA *rsa ,
int padding ) ;
int (*rsa_priv_dec)(int flen , unsigned char *from , unsigned char *to , RSA *rsa ,
int padding ) ;
int (*rsa_mod_exp)(BIGNUM *r0 , BIGNUM *I , RSA *rsa ) ;
int (*bn_mod_exp)(BIGNUM *r , BIGNUM *a , BIGNUM const *p , BIGNUM const *m ,
BN_CTX *ctx , BN_MONT_CTX *m_ctx ) ;
int (*init)(RSA *rsa ) ;
int (*finish)(RSA *rsa ) ;
int flags ;
char *app_data ;
int (*rsa_sign)(int type , unsigned char *m , unsigned int m_len , unsigned char *sigret ,
unsigned int *siglen , RSA *rsa ) ;
int (*rsa_verify)(int dtype , unsigned char *m , unsigned int m_len , unsigned char *sigbuf ,
unsigned int siglen , RSA *rsa ) ;
};
typedef struct rsa_meth_st RSA_METHOD;
struct rsa_st {
int pad ;
int version ;
RSA_METHOD *meth ;
BIGNUM *n ;
BIGNUM *e ;
BIGNUM *d ;
BIGNUM *p ;
BIGNUM *q ;
BIGNUM *dmp1 ;
BIGNUM *dmq1 ;
BIGNUM *iqmp ;
CRYPTO_EX_DATA ex_data ;
int references ;
int flags ;
BN_MONT_CTX *_method_mod_n ;
BN_MONT_CTX *_method_mod_p ;
BN_MONT_CTX *_method_mod_q ;
char *bignum_data ;
BN_BLINDING *blinding ;
};
struct dh_st;typedef struct dh_st DH;
struct dh_method {
char const *name ;
int (*generate_key)(DH *dh ) ;
int (*compute_key)(unsigned char *key , BIGNUM *pub_key , DH *dh ) ;
int (*bn_mod_exp)(DH *dh , BIGNUM *r , BIGNUM *a , BIGNUM const *p , BIGNUM const *m ,
BN_CTX *ctx , BN_MONT_CTX *m_ctx ) ;
int (*init)(DH *dh ) ;
int (*finish)(DH *dh ) ;
int flags ;
char *app_data ;
};
typedef struct dh_method DH_METHOD;
struct dh_st {
int pad ;
int version ;
BIGNUM *p ;
BIGNUM *g ;
int length ;
BIGNUM *pub_key ;
BIGNUM *priv_key ;
int flags ;
char *method_mont_p ;
BIGNUM *q ;
BIGNUM *j ;
unsigned char *seed ;
int seedlen ;
BIGNUM *counter ;
int references ;
CRYPTO_EX_DATA ex_data ;
DH_METHOD *meth ;
};
struct dsa_st;typedef struct dsa_st DSA;
struct DSA_SIG_st {
BIGNUM *r ;
BIGNUM *s ;
};
typedef struct DSA_SIG_st DSA_SIG;
struct dsa_method {
char const *name ;
DSA_SIG *(*dsa_do_sign)(unsigned char const *dgst , int dlen , DSA *dsa ) ;
int (*dsa_sign_setup)(DSA *dsa , BN_CTX *ctx_in , BIGNUM **kinvp , BIGNUM **rp ) ;
int (*dsa_do_verify)(unsigned char const *dgst , int dgst_len , DSA_SIG *sig ,
DSA *dsa ) ;
int (*dsa_mod_exp)(DSA *dsa , BIGNUM *rr , BIGNUM *a1 , BIGNUM *p1 , BIGNUM *a2 ,
BIGNUM *p2 , BIGNUM *m , BN_CTX *ctx , BN_MONT_CTX *in_mont ) ;
int (*bn_mod_exp)(DSA *dsa , BIGNUM *r , BIGNUM *a , BIGNUM const *p , BIGNUM const *m ,
BN_CTX *ctx , BN_MONT_CTX *m_ctx ) ;
int (*init)(DSA *dsa ) ;
int (*finish)(DSA *dsa ) ;
int flags ;
char *app_data ;
};
typedef struct dsa_method DSA_METHOD;
struct dsa_st {
int pad ;
int version ;
int write_params ;
BIGNUM *p ;
BIGNUM *q ;
BIGNUM *g ;
BIGNUM *pub_key ;
BIGNUM *priv_key ;
BIGNUM *kinv ;
BIGNUM *r ;
int flags ;
char *method_mont_p ;
int references ;
CRYPTO_EX_DATA ex_data ;
DSA_METHOD *meth ;
};
union __anonunion_pkey_21 {
char *ptr ;
struct rsa_st *rsa ;
struct dsa_st *dsa ;
struct dh_st *dh ;
};
struct evp_pkey_st {
int type ;
int save_type ;
int references ;
union __anonunion_pkey_21 pkey ;
int save_parameters ;
STACK *attributes ;
};
typedef struct evp_pkey_st EVP_PKEY;
struct env_md_st {
int type ;
int pkey_type ;
int md_size ;
void (*init)() ;
void (*update)() ;
void (*final)() ;
int (*sign)() ;
int (*verify)() ;
int required_pkey_type[5] ;
int block_size ;
int ctx_size ;
};
typedef struct env_md_st EVP_MD;
union __anonunion_md_22 {
unsigned char base[4] ;
MD2_CTX md2 ;
MD5_CTX md5 ;
MD4_CTX md4 ;
RIPEMD160_CTX ripemd160 ;
SHA_CTX sha ;
MDC2_CTX mdc2 ;
};
struct env_md_ctx_st {
EVP_MD const *digest ;
union __anonunion_md_22 md ;
};
typedef struct env_md_ctx_st EVP_MD_CTX;
struct evp_cipher_st;typedef struct evp_cipher_st EVP_CIPHER;
struct evp_cipher_ctx_st;typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;
struct evp_cipher_st {
int nid ;
int block_size ;
int key_len ;
int iv_len ;
unsigned long flags ;
int (*init)(EVP_CIPHER_CTX *ctx , unsigned char const *key , unsigned char const *iv ,
int enc ) ;
int (*do_cipher)(EVP_CIPHER_CTX *ctx , unsigned char *out , unsigned char const *in ,
unsigned int inl ) ;
int (*cleanup)(EVP_CIPHER_CTX * ) ;
int ctx_size ;
int (*set_asn1_parameters)(EVP_CIPHER_CTX * , ASN1_TYPE * ) ;
int (*get_asn1_parameters)(EVP_CIPHER_CTX * , ASN1_TYPE * ) ;
int (*ctrl)(EVP_CIPHER_CTX * , int type , int arg , void *ptr ) ;
void *app_data ;
};
struct __anonstruct_rc4_24 {
unsigned char key[16] ;
RC4_KEY ks ;
};
struct __anonstruct_desx_cbc_25 {
des_key_schedule ks ;
des_cblock inw ;
des_cblock outw ;
};
struct __anonstruct_des_ede_26 {
des_key_schedule ks1 ;
des_key_schedule ks2 ;
des_key_schedule ks3 ;
};
struct __anonstruct_rc2_27 {
int key_bits ;
RC2_KEY ks ;
};
struct __anonstruct_rc5_28 {
int rounds ;
RC5_32_KEY ks ;
};
union __anonunion_c_23 {
struct __anonstruct_rc4_24 rc4 ;
des_key_schedule des_ks ;
struct __anonstruct_desx_cbc_25 desx_cbc ;
struct __anonstruct_des_ede_26 des_ede ;
IDEA_KEY_SCHEDULE idea_ks ;
struct __anonstruct_rc2_27 rc2 ;
struct __anonstruct_rc5_28 rc5 ;
BF_KEY bf_ks ;
CAST_KEY cast_ks ;
};
struct evp_cipher_ctx_st {
EVP_CIPHER const *cipher ;
int encrypt ;
int buf_len ;
unsigned char oiv[8] ;
unsigned char iv[8] ;
unsigned char buf[8] ;
int num ;
void *app_data ;
int key_len ;
union __anonunion_c_23 c ;
};
struct X509_algor_st {
ASN1_OBJECT *algorithm ;
ASN1_TYPE *parameter ;
};
typedef struct X509_algor_st X509_ALGOR;
struct X509_val_st {
ASN1_TIME *notBefore ;
ASN1_TIME *notAfter ;
};
typedef struct X509_val_st X509_VAL;
struct X509_pubkey_st {
X509_ALGOR *algor ;
ASN1_BIT_STRING *public_key ;
EVP_PKEY *pkey ;
};
typedef struct X509_pubkey_st X509_PUBKEY;
struct X509_name_st {
STACK *entries ;
int modified ;
BUF_MEM *bytes ;
unsigned long hash ;
};
typedef struct X509_name_st X509_NAME;
struct x509_cinf_st {
ASN1_INTEGER *version ;
ASN1_INTEGER *serialNumber ;
X509_ALGOR *signature ;
X509_NAME *issuer ;
X509_VAL *validity ;
X509_NAME *subject ;
X509_PUBKEY *key ;
ASN1_BIT_STRING *issuerUID ;
ASN1_BIT_STRING *subjectUID ;
STACK *extensions ;
};
typedef struct x509_cinf_st X509_CINF;
struct x509_cert_aux_st {
STACK *trust ;
STACK *reject ;
ASN1_UTF8STRING *alias ;
ASN1_OCTET_STRING *keyid ;
STACK *other ;
};
typedef struct x509_cert_aux_st X509_CERT_AUX;
struct AUTHORITY_KEYID_st;struct x509_st {
X509_CINF *cert_info ;
X509_ALGOR *sig_alg ;
ASN1_BIT_STRING *signature ;
int valid ;
int references ;
char *name ;
CRYPTO_EX_DATA ex_data ;
long ex_pathlen ;
unsigned long ex_flags ;
unsigned long ex_kusage ;
unsigned long ex_xkusage ;
unsigned long ex_nscert ;
ASN1_OCTET_STRING *skid ;
struct AUTHORITY_KEYID_st *akid ;
unsigned char sha1_hash[20] ;
X509_CERT_AUX *aux ;
};
typedef struct x509_st X509;
struct lhash_node_st {
void *data ;
struct lhash_node_st *next ;
unsigned long hash ;
};
typedef struct lhash_node_st LHASH_NODE;
struct lhash_st {
LHASH_NODE **b ;
int (*comp)() ;
unsigned long (*hash)() ;
unsigned int num_nodes ;
unsigned int num_alloc_nodes ;
unsigned int p ;
unsigned int pmax ;
unsigned long up_load ;
unsigned long down_load ;
unsigned long num_items ;
unsigned long num_expands ;
unsigned long num_expand_reallocs ;
unsigned long num_contracts ;
unsigned long num_contract_reallocs ;
unsigned long num_hash_calls ;
unsigned long num_comp_calls ;
unsigned long num_insert ;
unsigned long num_replace ;
unsigned long num_delete ;
unsigned long num_no_delete ;
unsigned long num_retrieve ;
unsigned long num_retrieve_miss ;
unsigned long num_hash_comps ;
int error ;
};
struct x509_store_ctx_st;typedef struct x509_store_ctx_st X509_STORE_CTX;
struct x509_store_st {
int cache ;
STACK *objs ;
STACK *get_cert_methods ;
int (*verify)(X509_STORE_CTX *ctx ) ;
int (*verify_cb)(int ok , X509_STORE_CTX *ctx ) ;
CRYPTO_EX_DATA ex_data ;
int references ;
int depth ;
};
typedef struct x509_store_st X509_STORE;
struct x509_store_ctx_st {
X509_STORE *ctx ;
int current_method ;
X509 *cert ;
STACK *untrusted ;
int purpose ;
int trust ;
time_t check_time ;
unsigned long flags ;
void *other_ctx ;
int (*verify)(X509_STORE_CTX *ctx ) ;
int (*verify_cb)(int ok , X509_STORE_CTX *ctx ) ;
int (*get_issuer)(X509 **issuer , X509_STORE_CTX *ctx , X509 *x ) ;
int (*check_issued)(X509_STORE_CTX *ctx , X509 *x , X509 *issuer ) ;
int (*cleanup)(X509_STORE_CTX *ctx ) ;
int depth ;
int valid ;
int last_untrusted ;
STACK *chain ;
int error_depth ;
int error ;
X509 *current_cert ;
X509 *current_issuer ;
CRYPTO_EX_DATA ex_data ;
};
struct comp_method_st {
int type ;
char const *name ;
int (*init)() ;
void (*finish)() ;
int (*compress)() ;
int (*expand)() ;
long (*ctrl)() ;
long (*callback_ctrl)() ;
};
typedef struct comp_method_st COMP_METHOD;
struct comp_ctx_st {
COMP_METHOD *meth ;
unsigned long compress_in ;
unsigned long compress_out ;
unsigned long expand_in ;
unsigned long expand_out ;
CRYPTO_EX_DATA ex_data ;
};
typedef struct comp_ctx_st COMP_CTX;
typedef int pem_password_cb(char *buf , int size , int rwflag , void *userdata );
struct ssl_st;
struct ssl_cipher_st {
int valid ;
char const *name ;
unsigned long id ;
unsigned long algorithms ;
unsigned long algo_strength ;
unsigned long algorithm2 ;
int strength_bits ;
int alg_bits ;
unsigned long mask ;
unsigned long mask_strength ;
};
typedef struct ssl_cipher_st SSL_CIPHER;
typedef struct ssl_st SSL;
struct ssl_ctx_st;typedef struct ssl_ctx_st SSL_CTX;
struct ssl3_enc_method;struct ssl_method_st {
int version ;
int (*ssl_new)(SSL *s ) ;
void (*ssl_clear)(SSL *s ) ;
void (*ssl_free)(SSL *s ) ;
int (*ssl_accept)(SSL *s ) ;
int (*ssl_connect)(SSL *s ) ;
int (*ssl_read)(SSL *s , void *buf , int len ) ;
int (*ssl_peek)(SSL *s , void *buf , int len ) ;
int (*ssl_write)(SSL *s , void const *buf , int len ) ;
int (*ssl_shutdown)(SSL *s ) ;
int (*ssl_renegotiate)(SSL *s ) ;
int (*ssl_renegotiate_check)(SSL *s ) ;
long (*ssl_ctrl)(SSL *s , int cmd , long larg , char *parg ) ;
long (*ssl_ctx_ctrl)(SSL_CTX *ctx , int cmd , long larg , char *parg ) ;
SSL_CIPHER *(*get_cipher_by_char)(unsigned char const *ptr ) ;
int (*put_cipher_by_char)(SSL_CIPHER const *cipher , unsigned char *ptr ) ;
int (*ssl_pending)(SSL *s ) ;
int (*num_ciphers)(void) ;
SSL_CIPHER *(*get_cipher)(unsigned int ncipher ) ;
struct ssl_method_st *(*get_ssl_method)(int version ) ;
long (*get_timeout)(void) ;
struct ssl3_enc_method *ssl3_enc ;
int (*ssl_version)() ;
long (*ssl_callback_ctrl)(SSL *s , int cb_id , void (*fp)() ) ;
long (*ssl_ctx_callback_ctrl)(SSL_CTX *s , int cb_id , void (*fp)() ) ;
};
typedef struct ssl_method_st SSL_METHOD;
struct sess_cert_st;struct ssl_session_st {
int ssl_version ;
unsigned int key_arg_length ;
unsigned char key_arg[8] ;
int master_key_length ;
unsigned char master_key[48] ;
unsigned int session_id_length ;
unsigned char session_id[32] ;
unsigned int sid_ctx_length ;
unsigned char sid_ctx[32] ;
int not_resumable ;
struct sess_cert_st *sess_cert ;
X509 *peer ;
long verify_result ;
int references ;
long timeout ;
long time ;
int compress_meth ;
SSL_CIPHER *cipher ;
unsigned long cipher_id ;
STACK *ciphers ;
CRYPTO_EX_DATA ex_data ;
struct ssl_session_st *prev ;
struct ssl_session_st *next ;
};
typedef struct ssl_session_st SSL_SESSION;
struct ssl_comp_st {
int id ;
char *name ;
COMP_METHOD *method ;
};
typedef struct ssl_comp_st SSL_COMP;
struct __anonstruct_stats_37 {
int sess_connect ;
int sess_connect_renegotiate ;
int sess_connect_good ;
int sess_accept ;
int sess_accept_renegotiate ;
int sess_accept_good ;
int sess_miss ;
int sess_timeout ;
int sess_cache_full ;
int sess_hit ;
int sess_cb_hit ;
};
struct cert_st;struct ssl_ctx_st {
SSL_METHOD *method ;
unsigned long options ;
unsigned long mode ;
STACK *cipher_list ;
STACK *cipher_list_by_id ;
struct x509_store_st *cert_store ;
struct lhash_st *sessions ;
unsigned long session_cache_size ;
struct ssl_session_st *session_cache_head ;
struct ssl_session_st *session_cache_tail ;
int session_cache_mode ;
long session_timeout ;
int (*new_session_cb)(struct ssl_st *ssl , SSL_SESSION *sess ) ;
void (*remove_session_cb)(struct ssl_ctx_st *ctx , SSL_SESSION *sess ) ;
SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl , unsigned char *data , int len ,
int *copy ) ;
struct __anonstruct_stats_37 stats ;
int references ;
void (*info_callback)() ;
int (*app_verify_callback)() ;
char *app_verify_arg ;
struct cert_st *cert ;
int read_ahead ;
int verify_mode ;
int verify_depth ;
unsigned int sid_ctx_length ;
unsigned char sid_ctx[32] ;
int (*default_verify_callback)(int ok , X509_STORE_CTX *ctx ) ;
int purpose ;
int trust ;
pem_password_cb *default_passwd_callback ;
void *default_passwd_callback_userdata ;
int (*client_cert_cb)() ;
STACK *client_CA ;
int quiet_shutdown ;
CRYPTO_EX_DATA ex_data ;
EVP_MD const *rsa_md5 ;
EVP_MD const *md5 ;
EVP_MD const *sha1 ;
STACK *extra_certs ;
STACK *comp_methods ;
};
struct ssl2_state_st;struct ssl3_state_st;struct ssl_st {
int version ;
int type ;
SSL_METHOD *method ;
BIO *rbio ;
BIO *wbio ;
BIO *bbio ;
int rwstate ;
int in_handshake ;
int (*handshake_func)() ;
int server ;
int new_session ;
int quiet_shutdown ;
int shutdown ;
int state ;
int rstate ;
BUF_MEM *init_buf ;
int init_num ;
int init_off ;
unsigned char *packet ;
unsigned int packet_length ;
struct ssl2_state_st *s2 ;
struct ssl3_state_st *s3 ;
int read_ahead ;
int hit ;
int purpose ;
int trust ;
STACK *cipher_list ;
STACK *cipher_list_by_id ;
EVP_CIPHER_CTX *enc_read_ctx ;
EVP_MD const *read_hash ;
COMP_CTX *expand ;
EVP_CIPHER_CTX *enc_write_ctx ;
EVP_MD const *write_hash ;
COMP_CTX *compress ;
struct cert_st *cert ;
unsigned int sid_ctx_length ;
unsigned char sid_ctx[32] ;
SSL_SESSION *session ;
int verify_mode ;
int verify_depth ;
int (*verify_callback)(int ok , X509_STORE_CTX *ctx ) ;
void (*info_callback)() ;
int error ;
int error_code ;
SSL_CTX *ctx ;
int debug ;
long verify_result ;
CRYPTO_EX_DATA ex_data ;
STACK *client_CA ;
int references ;
unsigned long options ;
unsigned long mode ;
int first_packet ;
int client_version ;
};
struct __anonstruct_tmp_38 {
unsigned int conn_id_length ;
unsigned int cert_type ;
unsigned int cert_length ;
unsigned int csl ;
unsigned int clear ;
unsigned int enc ;
unsigned char ccl[32] ;
unsigned int cipher_spec_length ;
unsigned int session_id_length ;
unsigned int clen ;
unsigned int rlen ;
};
struct ssl2_state_st {
int three_byte_header ;
int clear_text ;
int escape ;
int ssl2_rollback ;
unsigned int wnum ;
int wpend_tot ;
unsigned char const *wpend_buf ;
int wpend_off ;
int wpend_len ;
int wpend_ret ;
int rbuf_left ;
int rbuf_offs ;
unsigned char *rbuf ;
unsigned char *wbuf ;
unsigned char *write_ptr ;
unsigned int padding ;
unsigned int rlength ;
int ract_data_length ;
unsigned int wlength ;
int wact_data_length ;
unsigned char *ract_data ;
unsigned char *wact_data ;
unsigned char *mac_data ;
unsigned char *pad_data_UNUSED ;
unsigned char *read_key ;
unsigned char *write_key ;
unsigned int challenge_length ;
unsigned char challenge[32] ;
unsigned int conn_id_length ;
unsigned char conn_id[16] ;
unsigned int key_material_length ;
unsigned char key_material[48] ;
unsigned long read_sequence ;
unsigned long write_sequence ;
struct __anonstruct_tmp_38 tmp ;
};
struct ssl3_record_st {
int type ;
unsigned int length ;
unsigned int off ;
unsigned char *data ;
unsigned char *input ;
unsigned char *comp ;
};
typedef struct ssl3_record_st SSL3_RECORD;
struct ssl3_buffer_st {
unsigned char *buf ;
int offset ;
int left ;
};
typedef struct ssl3_buffer_st SSL3_BUFFER;
struct __anonstruct_tmp_39 {
unsigned char cert_verify_md[72] ;
unsigned char finish_md[72] ;
int finish_md_len ;
unsigned char peer_finish_md[72] ;
int peer_finish_md_len ;
unsigned long message_size ;
int message_type ;
SSL_CIPHER *new_cipher ;
DH *dh ;
int next_state ;
int reuse_message ;
int cert_req ;
int ctype_num ;
char ctype[7] ;
STACK *ca_names ;
int use_rsa_tmp ;
int key_block_length ;
unsigned char *key_block ;
EVP_CIPHER const *new_sym_enc ;
EVP_MD const *new_hash ;
SSL_COMP const *new_compression ;
int cert_request ;
};
struct ssl3_state_st {
long flags ;
int delay_buf_pop_ret ;
unsigned char read_sequence[8] ;
unsigned char read_mac_secret[36] ;
unsigned char write_sequence[8] ;
unsigned char write_mac_secret[36] ;
unsigned char server_random[32] ;
unsigned char client_random[32] ;
SSL3_BUFFER rbuf ;
SSL3_BUFFER wbuf ;
SSL3_RECORD rrec ;
SSL3_RECORD wrec ;
unsigned char alert_fragment[2] ;
unsigned int alert_fragment_len ;
unsigned char handshake_fragment[4] ;
unsigned int handshake_fragment_len ;
unsigned int wnum ;
int wpend_tot ;
int wpend_type ;
int wpend_ret ;
unsigned char const *wpend_buf ;
EVP_MD_CTX finish_dgst1 ;
EVP_MD_CTX finish_dgst2 ;
int change_cipher_spec ;
int warn_alert ;
int fatal_alert ;
int alert_dispatch ;
unsigned char send_alert[2] ;
int renegotiate ;
int total_renegotiations ;
int num_renegotiations ;
int in_read_app_data ;
struct __anonstruct_tmp_39 tmp ;
};
struct cert_pkey_st {
X509 *x509 ;
EVP_PKEY *privatekey ;
};
typedef struct cert_pkey_st CERT_PKEY;
struct cert_st {
CERT_PKEY *key ;
int valid ;
unsigned long mask ;
unsigned long export_mask ;
RSA *rsa_tmp ;
RSA *(*rsa_tmp_cb)(SSL *ssl , int is_export , int keysize ) ;
DH *dh_tmp ;
DH *(*dh_tmp_cb)(SSL *ssl , int is_export , int keysize ) ;
CERT_PKEY pkeys[5] ;
int references ;
};
typedef struct cert_st CERT;
struct sess_cert_st {
STACK *cert_chain ;
int peer_cert_type ;
CERT_PKEY *peer_key ;
CERT_PKEY peer_pkeys[5] ;
RSA *peer_rsa_tmp ;
DH *peer_dh_tmp ;
int references ;
};
typedef struct sess_cert_st SESS_CERT;
struct ssl3_enc_method {
int (*enc)(SSL * , int ) ;
int (*mac)(SSL * , unsigned char * , int ) ;
int (*setup_key_block)(SSL * ) ;
int (*generate_master_secret)(SSL * , unsigned char * , unsigned char * , int ) ;
int (*change_cipher_state)(SSL * , int ) ;
int (*final_finish_mac)(SSL * , EVP_MD_CTX * , EVP_MD_CTX * , char const * ,
int , unsigned char * ) ;
int finish_mac_length ;
int (*cert_verify_mac)(SSL * , EVP_MD_CTX * , unsigned char * ) ;
char const *client_finished_label ;
int client_finished_label_len ;
char const *server_finished_label ;
int server_finished_label_len ;
int (*alert_value)(int ) ;
};
extern BUF_MEM *BUF_MEM_new(void) ;
extern void BUF_MEM_free(BUF_MEM *a ) ;
extern int BUF_MEM_grow(BUF_MEM *str , int len ) ;
extern int RAND_pseudo_bytes(unsigned char *buf , int num ) ;
extern void RAND_add(void const *buf , int num , double entropy ) ;
extern int sk_num(STACK const * ) ;
extern char *sk_value(STACK const * , int ) ;
extern STACK *sk_new_null(void) ;
extern void sk_free(STACK * ) ;
extern void sk_pop_free(STACK *st , void (*func)(void * ) ) ;
extern int sk_push(STACK *st , char *data ) ;
extern char *sk_shift(STACK *st ) ;
extern int CRYPTO_add_lock(int *pointer , int amount , int type , char const *file ,
int line ) ;
extern long BIO_ctrl(BIO *bp , int cmd , long larg , void *parg ) ;
extern time_t time(time_t *__timer ) ;
extern int BN_num_bits(BIGNUM const *a ) ;
extern void BN_clear_free(BIGNUM *a ) ;
extern BIGNUM *BN_bin2bn(unsigned char const *s , int len , BIGNUM *ret ) ;
extern int BN_bn2bin(BIGNUM const *a , unsigned char *to ) ;
extern BIGNUM *BN_dup(BIGNUM const *a ) ;
extern char *ASN1_dup(int (*i2d)() , char *(*d2i)() , char *x ) ;
extern int RSA_private_decrypt(int flen , unsigned char *from , unsigned char *to ,
RSA *rsa , int padding ) ;
extern int RSA_sign(int type , unsigned char *m , unsigned int m_len , unsigned char *sigret ,
unsigned int *siglen , RSA *rsa ) ;
extern int RSA_verify(int type , unsigned char *m , unsigned int m_len , unsigned char *sigbuf ,
unsigned int siglen , RSA *rsa ) ;
extern void DH_free(DH *dh ) ;
extern int DH_generate_key(DH *dh ) ;
extern int DH_compute_key(unsigned char *key , BIGNUM *pub_key , DH *dh ) ;
DH *d2i_DHparams(DH **a , unsigned char **pp , long length ) {}
int i2d_DHparams(DH *a , unsigned char **pp ) {}
extern int DSA_verify(int type , unsigned char const *dgst , int dgst_len , unsigned char *sigbuf ,
int siglen , DSA *dsa ) ;
extern void EVP_DigestInit(EVP_MD_CTX *ctx , EVP_MD const *type ) ;
extern void EVP_DigestUpdate(EVP_MD_CTX *ctx , void const *d , unsigned int cnt ) ;
extern void EVP_DigestFinal(EVP_MD_CTX *ctx , unsigned char *md , unsigned int *s ) ;
extern int EVP_SignFinal(EVP_MD_CTX *ctx , unsigned char *md , unsigned int *s , EVP_PKEY *pkey ) ;
extern EVP_MD *EVP_dss1(void) ;
extern int EVP_PKEY_size(EVP_PKEY *pkey ) ;
extern void EVP_PKEY_free(EVP_PKEY *pkey ) ;
extern int i2d_X509_NAME(X509_NAME *a , unsigned char **pp ) ;
void X509_free(X509 *a ) {}
extern X509 *d2i_X509(X509 **a , unsigned char **pp , long length ) ;
extern EVP_PKEY *X509_get_pubkey(X509 *x ) ;
extern int X509_certificate_type(X509 *x , EVP_PKEY *pubkey ) ;
extern void *memcpy(void * /* __restrict */ __dest , void const * /* __restrict */ __src ,
size_t __n ) ;
extern void *memset(void *__s , int __c , size_t __n ) ;
extern int *__errno_location(void) /* __attribute__((__const__)) */ ;
extern void ERR_put_error(int lib , int func , int reason , char const *file , int line ) ;
extern void ERR_clear_error(void) ;
extern int SSL_clear(SSL *s ) ;
SSL_METHOD *SSLv3_server_method(void) ;
extern STACK *SSL_get_client_CA_list(SSL *s ) ;
extern int SSL_state(SSL *ssl ) ;
extern SSL_METHOD *sslv3_base_method(void) ;
extern SESS_CERT *ssl_sess_cert_new(void) ;
extern int ssl_get_new_session(SSL *s , int session ) ;
extern int ssl_get_prev_session(SSL *s , unsigned char *session , int len ) ;
extern STACK *ssl_bytes_to_cipher_list(SSL *s , unsigned char *p , int num , STACK **skp ) ;
extern void ssl_update_cache(SSL *s , int mode ) ;
extern int ssl_verify_cert_chain(SSL *s , STACK *sk ) ;
extern X509 *ssl_get_server_send_cert(SSL * ) ;
extern EVP_PKEY *ssl_get_sign_pkey(SSL * , SSL_CIPHER * ) ;
extern STACK *ssl_get_ciphers_by_id(SSL *s ) ;
extern int ssl_verify_alarm_type(long type ) ;
extern int ssl3_put_cipher_by_char(SSL_CIPHER const *c , unsigned char *p ) ;
extern void ssl3_init_finished_mac(SSL *s ) ;
int ssl3_send_server_certificate(SSL *s ) ;
extern int ssl3_get_finished(SSL *s , int state_a , int state_b ) ;
extern int ssl3_send_change_cipher_spec(SSL *s , int state_a , int state_b ) ;
extern void ssl3_cleanup_key_block(SSL *s ) ;
extern int ssl3_do_write(SSL *s , int type ) ;
extern void ssl3_send_alert(SSL *s , int level , int desc ) ;
extern int ssl3_get_req_cert_type(SSL *s , unsigned char *p ) ;
extern long ssl3_get_message(SSL *s , int st1 , int stn , int mt , long max , int *ok ) ;
extern int ssl3_send_finished(SSL *s , int a , int b , char const *sender , int slen ) ;
extern unsigned long ssl3_output_cert_chain(SSL *s , X509 *x ) ;
extern SSL_CIPHER *ssl3_choose_cipher(SSL *ssl , STACK *have , STACK *pref ) ;
extern int ssl3_setup_buffers(SSL *s ) ;
int ssl3_accept(SSL *s ) ;
extern int ssl_init_wbio_buffer(SSL *s , int push ) ;
extern void ssl_free_wbio_buffer(SSL *s ) ;
static SSL_METHOD *ssl3_get_server_method(int ver ) ;
static int ssl3_get_client_hello(SSL *s ) ;
static int ssl3_check_client_hello(SSL *s ) ;
static int ssl3_send_server_hello(SSL *s ) ;
static int ssl3_send_server_key_exchange(SSL *s ) ;
static int ssl3_send_certificate_request(SSL *s ) ;
static int ssl3_send_server_done(SSL *s ) ;
static int ssl3_get_client_key_exchange(SSL *s ) ;
static int ssl3_get_client_certificate(SSL *s ) ;
static int ssl3_get_cert_verify(SSL *s ) ;
static int ssl3_send_hello_request(SSL *s ) ;
static SSL_METHOD *ssl3_get_server_method(int ver )
{ SSL_METHOD *tmp ;
{
if (ver == 768) { tmp = SSLv3_server_method(); return (tmp);
} else {
return ((SSL_METHOD *)((void *)0));
}
}
}
SSL_METHOD *SSLv3_server_method(void) ;static int init = 1;
static SSL_METHOD SSLv3_server_data ;
SSL_METHOD *SSLv3_server_method(void)
{ char *tmp ;
{
if (init) {
tmp = (char *)sslv3_base_method(); memcpy((void * )((char *)(& SSLv3_server_data)), (void const * )tmp,
sizeof(SSL_METHOD ));
SSLv3_server_data.ssl_accept = & ssl3_accept;
SSLv3_server_data.get_ssl_method = & ssl3_get_server_method;
init = 0;
}
return (& SSLv3_server_data);
}
}
// TRACER: to shadow s->state
int myState;
// TRACER: to shadow (s->s3)->tmp.next_state
int myStateNext;
extern int unknown();
int main()
{
SSL *s = 0;
return ssl3_accept(s);
}
int ssl3_accept(SSL *s )
{
BUF_MEM *buf ;
unsigned long l ;
unsigned long Time ;
unsigned long tmp ;
void (*cb)() ;
long num1 ;
int ret ;
int new_state ;
int state ;
int skip ;
int got_new_session ;
int *tmp___0 ;
int tmp___1 ;
int tmp___2 ;
int tmp___3 ;
int tmp___4 ;
int tmp___5 ;
int tmp___6 ;
int tmp___7 ;
long tmp___8 ;
int tmp___9 ;
int tmp___10 ;
int blastFlag;
{
myState /*s->state*/ = 8464;
blastFlag = 0;
//tmp = (unsigned long )time((time_t *)((void *)0));
tmp = unknown();
Time = tmp;
cb = (void (*)())((void *)0);
ret = -1;
skip = 0;
got_new_session = 0;
//RAND_add((void const *)(& Time), (int )sizeof(Time), (double )0);
//ERR_clear_error();
//tmp___0 = __errno_location(); (*tmp___0) = 0;
if ((unsigned long )s->info_callback != (unsigned long )((void *)0)) {
cb = s->info_callback;
} else {
if ((unsigned long )(s->ctx)->info_callback != (unsigned long )((void *)0)) {
cb = (s->ctx)->info_callback;
}
}
s->in_handshake ++;
//tmp___1 = SSL_state(s);
if (tmp___1 & 12288) {
//tmp___2 = SSL_state(s);
if (tmp___2 & 16384) {
//SSL_clear(s);
}
} else {
//SSL_clear(s);
}
if ((unsigned long )s->cert == (unsigned long )((void *)0)) {
//ERR_put_error(20, 128, 179, (char const *)"s3_srvr.c", 187);
return (-1);
}
while (1) {
state = myState /*s->state*/;
switch (myState /*s->state*/) {
case 12292:
s->new_session = 1;
case 16384: ;
case 8192: ;
case 24576: ;
case 8195:
s->server = 1;
if ((unsigned long )cb != (unsigned long )((void *)0)) {
//((*cb))(s, 16, 1);
}
if (s->version >> 8 != 3) {
//ERR_put_error(20, 128, 157, (char const *)"s3_srvr.c", 211);
return (-1);
}
s->type = 8192;
if ((unsigned long )s->init_buf == (unsigned long )((void *)0)) {
//buf = BUF_MEM_new();
buf = unknown();
if ((unsigned long )buf == (unsigned long )((void *)0)) {
ret = -1;
goto end;
}
//tmp___3 = BUF_MEM_grow(buf, 16384);
if (! tmp___3) {
ret = -1;
goto end;
}
s->init_buf = buf;
}
//tmp___4 = ssl3_setup_buffers(s);
if (! tmp___4) {
ret = -1;
goto end;
}
s->init_num = 0;
if (myState /*s->state*/ != 12292) {
//tmp___5 = ssl_init_wbio_buffer(s, 1);
if (! tmp___5) {
ret = -1;
goto end;
}
//ssl3_init_finished_mac(s);
myState /*s->state*/ = 8464;
(s->ctx)->stats.sess_accept ++;
} else {
(s->ctx)->stats.sess_accept_renegotiate ++;
myState /*s->state*/ = 8480;
}
break;
case 8480: ;
case 8481:
s->shutdown = 0;
//ret = ssl3_send_hello_request(s);
ret = unknown();
if (ret <= 0) {
goto end;
}
myStateNext /*(s->s3)->tmp.next_state*/ = 8482;
myState /*s->state*/ = 8448;
s->init_num = 0;
//ssl3_init_finished_mac(s);
break;
case 8482:
myState /*s->state*/ = 3;
break;
case 8464: ;
case 8465: ;
case 8466:
s->shutdown = 0;
//ret = ssl3_get_client_hello(s);
ret = unknown();
if(blastFlag == 0) blastFlag = 1;
if (ret <= 0) {
goto end;
}
got_new_session = 1;
myState /*s->state*/ = 8496;
s->init_num = 0;
break;
case 8496: ;
case 8497:
//ret = ssl3_send_server_hello(s);
ret = unknown();
if(blastFlag == 1) blastFlag = 2;
if (ret <= 0) {
goto end;
}
if (s->hit) {
myState /*s->state*/ = 8656;
} else {
myState /*s->state*/ = 8512;
}
s->init_num = 0;
break;
case 8512: ;
case 8513: ;
if (((s->s3)->tmp.new_cipher)->algorithms & 256UL) {
skip = 1;
} else {
//ret = ssl3_send_server_certificate(s);
ret = unknown();
if(blastFlag == 2) blastFlag = 6;
if (ret <= 0) {
goto end;
}
}
myState /*s->state*/ = 8528;
s->init_num = 0;
break;
case 8528: ;
case 8529:
l = ((s->s3)->tmp.new_cipher)->algorithms;
if (s->options & 2097152UL) {
(s->s3)->tmp.use_rsa_tmp = 1;
} else {
(s->s3)->tmp.use_rsa_tmp = 0;
}
if ((s->s3)->tmp.use_rsa_tmp) {
goto _L___0;
} else {
if (l & 30UL) {
goto _L___0;
} else {
if (l & 1UL) {
if ((unsigned long )(s->cert)->pkeys[0].privatekey == (unsigned long )((void *)0)) {
goto _L___0;
} else {
if (((s->s3)->tmp.new_cipher)->algo_strength & 2UL) {
//tmp___6 = EVP_PKEY_size((s->cert)->pkeys[0].privatekey);
if (((s->s3)->tmp.new_cipher)->algo_strength & 4UL) {
tmp___7 = 512;
} else {
tmp___7 = 1024;
}
if (tmp___6 * 8 > tmp___7) {
_L___0:
_L:
//ret = ssl3_send_server_key_exchange(s);
ret = unknown();
if(blastFlag == 6) blastFlag = 7;
if (ret <= 0) {
goto end;
}
} else {
skip = 1;
}
} else {
skip = 1;
}
}
} else {
skip = 1;
}
}
}
myState /*s->state*/ = 8544;
s->init_num = 0;
break;
case 8544: ;
case 8545: ;
if (s->verify_mode & 1) {
if ((unsigned long )(s->session)->peer != (unsigned long )((void *)0)) {
if (s->verify_mode & 4) {
skip = 1;
(s->s3)->tmp.cert_request = 0;
myState /*s->state*/ = 8560;
} else {
goto _L___2;
}
} else {
_L___2:
if (((s->s3)->tmp.new_cipher)->algorithms & 256UL) {
if (s->verify_mode & 2) {
goto _L___1;
} else {
skip = 1;
(s->s3)->tmp.cert_request = 0;
myState /*s->state*/ = 8560;
}
} else {
_L___1:
(s->s3)->tmp.cert_request = 1;
//ret = ssl3_send_certificate_request(s);
ret = unknown();
_TRACER_abort(blastFlag == 8); //if(blastFlag == 8) goto ERROR;
if (ret <= 0) {
goto end;
}
myState /*s->state*/ = 8448;
myStateNext /*(s->s3)->tmp.next_state*/ = 8576;
s->init_num = 0;
}
}
} else {
skip = 1;
(s->s3)->tmp.cert_request = 0;
myState /*s->state*/ = 8560;
}
break;
case 8560: ;
case 8561:
//ret = ssl3_send_server_done(s);
ret = unknown();
if (ret <= 0) {
goto end;
}
myStateNext /*(s->s3)->tmp.next_state*/ = 8576;
myState /*s->state*/ = 8448;
s->init_num = 0;
break;
case 8448:
//num1 = BIO_ctrl(s->wbio, 3, 0L, (void *)0);
if (num1 > 0L) {
s->rwstate = 2;
//tmp___8 = BIO_ctrl(s->wbio, 11, 0L, (void *)0);
num1 = (long )((int )tmp___8);
if (num1 <= 0L) {
ret = -1;
goto end;
}
s->rwstate = 1;
}
myState /*s->state*/ = myStateNext /*(s->s3)->tmp.next_state*/;
break;
case 8576: ;
case 8577:
//ret = ssl3_check_client_hello(s);
ret = unknown();
if (ret <= 0) {
goto end;
} if (ret == 2) {
myState /*s->state*/ = 8466;
} else {
//ret = ssl3_get_client_certificate(s);
ret = unknown();
if (ret <= 0) {
goto end;
}
s->init_num = 0;
myState /*s->state*/ = 8592;
}
break;
case 8592: ;
case 8593:
//ret = ssl3_get_client_key_exchange(s);
ret = unknown();
if (ret <= 0) {
goto end;
}
myState /*s->state*/ = 8608;
s->init_num = 0;
//((*(((s->method)->ssl3_enc)->cert_verify_mac)))(s, & (s->s3)->finish_dgst1, & (s->s3)->tmp.cert_verify_md[0]);
//((*(((s->method)->ssl3_enc)->cert_verify_mac)))(s, & (s->s3)->finish_dgst2, & (s->s3)->tmp.cert_verify_md[16]);
break;
case 8608: ;
case 8609:
//ret = ssl3_get_cert_verify(s);
ret = unknown();
if(blastFlag == 4) blastFlag = 5;
else if(blastFlag == 7) blastFlag = 8;
if (ret <= 0) {
goto end;
}
myState /*s->state*/ = 8640;
s->init_num = 0;
break;
case 8640: ;
case 8641:
//ret = ssl3_get_finished(s, 8640, 8641);
ret = unknown();
_TRACER_abort(blastFlag == 5); //if(blastFlag == 5) goto ERROR;
if (ret <= 0) {
goto end;
}
if (s->hit) { myState /*s->state*/ = 3;
} else {
myState /*s->state*/ = 8656;
}
s->init_num = 0;
break;
case 8656: ;
case 8657:
(s->session)->cipher = (s->s3)->tmp.new_cipher;
//tmp___9 = ((*(((s->method)->ssl3_enc)->setup_key_block)))(s);
if (! tmp___9) {
ret = -1;
goto end;
}
//ret = ssl3_send_change_cipher_spec(s, 8656, 8657);
ret = unknown();
if(blastFlag == 2) blastFlag = 3;
if (ret <= 0) {
goto end;
}
myState /*s->state*/ = 8672;
s->init_num = 0;
//tmp___10 = ((*(((s->method)->ssl3_enc)->change_cipher_state)))(s, 34);
if (! tmp___10) {
ret = -1;
goto end;
}
break;
case 8672: ;
case 8673:
//ret = ssl3_send_finished(s, 8672, 8673, ((s->method)->ssl3_enc)->server_finished_label,((s->method)->ssl3_enc)->server_finished_label_len);
ret = unknown();
if(blastFlag == 3) blastFlag = 4;
if (ret <= 0) {
goto end;
}
myState /*s->state*/ = 8448;
if (s->hit) {
myStateNext /*(s->s3)->tmp.next_state*/ = 8640;
} else {
myStateNext /*(s->s3)->tmp.next_state*/ = 3;
}
s->init_num = 0;
break;
case 3:
//ssl3_cleanup_key_block(s);
//BUF_MEM_free(s->init_buf);
s->init_buf = (BUF_MEM *)((void *)0);
//ssl_free_wbio_buffer(s);
s->init_num = 0;
if (got_new_session) {
s->new_session = 0;
//ssl_update_cache(s, 2);
(s->ctx)->stats.sess_accept_good ++;
s->handshake_func = (int (*)())(& ssl3_accept);
if ((unsigned long )cb != (unsigned long )((void *)0)) {
//((*cb))(s, 32, 1);
}
} ret = 1;
goto end;
default:
//ERR_put_error(20, 128, 255, (char const *)"s3_srvr.c", 536);
ret = -1;
goto end;
}
if (! (s->s3)->tmp.reuse_message) {
if (! skip) {
if (s->debug) {
//ret = (int )BIO_ctrl(s->wbio, 11, 0L, (void *)0);
ret = unknown();
if (ret <= 0) {
goto end;
}
} if ((unsigned long )cb != (unsigned long )((void *)0)) {
if (myState /*s->state*/ != state) {
new_state = myState /*s->state*/;
myState /*s->state*/ = state;
//((*cb))(s, 8193, 1);
myState /*s->state*/ = new_state;
}
}
}
}
skip = 0;
}
end:
s->in_handshake --;
if ((unsigned long )cb != (unsigned long )((void *)0)) {
//((*cb))(s, 8194, ret);
}
return (ret);
// ERROR: goto ERROR;
}
}
static int ssl3_send_hello_request(SSL *s )
{ unsigned char *p ;
unsigned char *tmp ;
unsigned char *tmp___0 ;
unsigned char *tmp___1 ;
unsigned char *tmp___2 ;
int tmp___3 ;
{
if (s->state == 8480) {
p = (unsigned char *)(s->init_buf)->data;
tmp = p; p ++; (*tmp) = 0;
tmp___0 = p; p ++; (*tmp___0) = 0;
tmp___1 = p; p ++; (*tmp___1) = 0;
tmp___2 = p; p ++; (*tmp___2) = 0;
s->state = 8481;
s->init_num = 4;
s->init_off = 0;
}
tmp___3 = ssl3_do_write(s, 22); return (tmp___3);
}
}static int ssl3_check_client_hello(SSL *s )
{ int ok ;
long n ;
{ n = ssl3_get_message(s, 8576, 8577, -1, 102400L, & ok);
if (! ok) { return ((int )n);
} (s->s3)->tmp.reuse_message = 1;
if ((s->s3)->tmp.message_type == 1) {
if ((unsigned long )(s->s3)->tmp.dh != (unsigned long )((void *)0)) {
DH_free((s->s3)->tmp.dh);
(s->s3)->tmp.dh = (DH *)((void *)0);
}
return (2);
}
return (1);
}
}static int ssl3_get_client_hello(SSL *s )
{ int i ;
int j ;
int ok ;
int al ;
int ret ;
long n ;
unsigned long id ;
unsigned char *p ;
unsigned char *d ;
unsigned char *q ;
SSL_CIPHER *c ;
SSL_COMP *comp ;
STACK *ciphers ;
unsigned char *tmp ;
int tmp___0 ;
int tmp___1 ;
STACK *tmp___2 ;
int tmp___4 ;
int tmp___6 ;
unsigned char *tmp___7 ;
int m ;
int nn ;
int o ;
int v ;
int done ;
STACK *tmp___9 ;
STACK *sk ;
SSL_CIPHER *nc ;
SSL_CIPHER *ec ;
int tmp___11 ;
{
ret = -1;
comp = (SSL_COMP *)((void *)0);
ciphers = (STACK *)((void *)0);
if (s->state == 8464) {
s->first_packet = 1;
s->state = 8465;
}
n = ssl3_get_message(s, 8465, 8466, 1, 16384L, & ok);
if (! ok) { return ((int )n);
} p = (unsigned char *)(s->init_buf)->data; d = p;
s->client_version = ((int )(*(p + 0)) << 8) | (int )(*(p + 1));
p += 2;
if (s->client_version < s->version) {
ERR_put_error(20, 138, 267, (char const *)"s3_srvr.c", 667);
if (s->client_version >> 8 == 3) {
s->version = s->client_version;
}
al = 70;
goto f_err;
}
memcpy((void * )((s->s3)->client_random), (void const * )p,
32U); p += 32;
tmp = p; p ++; j = (int )(*tmp);
s->hit = 0;
if (j == 0) {
tmp___0 = ssl_get_new_session(s, 1); if (! tmp___0) {
goto err;
}
} else {
i = ssl_get_prev_session(s, p, j);
if (i == 1) {
s->hit = 1;
} else {
if (i == -1) {
goto err;
} else {
tmp___1 = ssl_get_new_session(s, 1); if (! tmp___1) {
goto err;
}
}
}
}
p += j;
i = (int )(((unsigned int )(*(p + 0)) << 8) | (unsigned int )(*(p + 1))); p += 2;
if (i == 0) { if (j != 0) {
al = 47;
ERR_put_error(20, 138, 183, (char const *)"s3_srvr.c", 712);
goto f_err;
}
} if ((unsigned long )(p + i) > (unsigned long )(d + n)) {
al = 50;
ERR_put_error(20, 138, 159, (char const *)"s3_srvr.c", 719);
goto f_err;
}
if (i > 0) { tmp___2 = ssl_bytes_to_cipher_list(s, p, i, & ciphers); if ((unsigned long )tmp___2 == (unsigned long )((void *)0)) {
goto err;
}
}
p += i;
if (s->hit) { if (i > 0) {
j = 0;
id = ((s->session)->cipher)->id;
i = 0; while (1) { tmp___4 = sk_num((STACK const *)ciphers); if (! (i < tmp___4)) { break;
}
c = (SSL_CIPHER *)sk_value((STACK const *)ciphers, i);
if (c->id == id) {
j = 1;
break;
}
i ++;
}
if (j == 0) {
if (s->options & 8UL) { tmp___6 = sk_num((STACK const *)ciphers); if (tmp___6 == 1) {
(s->session)->cipher = (SSL_CIPHER *)sk_value((STACK const *)ciphers,
0);
} else {
al = 47;
ERR_put_error(20, 138, 215, (char const *)"s3_srvr.c", 764);
goto f_err;
}
} else {
al = 47;
ERR_put_error(20, 138, 215, (char const *)"s3_srvr.c", 764);
goto f_err;
}
}
}
} tmp___7 = p; p ++; i = (int )(*tmp___7);
q = p;
j = 0; while (j < i) {
if ((int )(*(p + j)) == 0) { break;
}
j ++;
}
p += i;
if (j >= i) {
al = 50;
ERR_put_error(20, 138, 187, (char const *)"s3_srvr.c", 783);
goto f_err;
}
(s->s3)->tmp.new_compression = (SSL_COMP const *)((void *)0);
if ((unsigned long )(s->ctx)->comp_methods != (unsigned long )((void *)0)) {
done = 0;
nn = sk_num((STACK const *)(s->ctx)->comp_methods);
m = 0; while (m < nn) {
comp = (SSL_COMP *)sk_value((STACK const *)(s->ctx)->comp_methods, m);
v = comp->id;
o = 0; while (o < i) {
if (v == (int )(*(q + o))) {
done = 1;
break;
}
o ++;
}
if (done) { break;
}
m ++;
}
if (done) { (s->s3)->tmp.new_compression = (SSL_COMP const *)comp;
} else {
comp = (SSL_COMP *)((void *)0);
}
}
if (s->version == 768) {
if ((unsigned long )p > (unsigned long )(d + n)) {
al = 50;
ERR_put_error(20, 138, 159, (char const *)"s3_srvr.c", 824);
goto f_err;
}
}
if (s->hit) {
nc = (SSL_CIPHER *)((void *)0);
ec = (SSL_CIPHER *)((void *)0);
if (s->options & 2147483648UL) {
sk = (s->session)->ciphers;
i = 0; while (1) { tmp___11 = sk_num((STACK const *)sk); if (! (i < tmp___11)) { break;
}
c = (SSL_CIPHER *)sk_value((STACK const *)sk, i);
if (c->algorithms & 65536UL) { nc = c;
}
if (c->algo_strength & 2UL) { ec = c;
}
i ++;
}
if ((unsigned long )nc != (unsigned long )((void *)0)) { (s->s3)->tmp.new_cipher = nc;
} else {
if ((unsigned long )ec != (unsigned long )((void *)0)) { (s->s3)->tmp.new_cipher = ec;
} else {
(s->s3)->tmp.new_cipher = (s->session)->cipher;
}
}
} else { (s->s3)->tmp.new_cipher = (s->session)->cipher;
}
} else {
if ((unsigned long )comp == (unsigned long )((void *)0)) { (s->session)->compress_meth = 0;
} else {
(s->session)->compress_meth = comp->id;
} if ((unsigned long )(s->session)->ciphers != (unsigned long )((void *)0)) { sk_free((s->session)->ciphers);
}
(s->session)->ciphers = ciphers;
if ((unsigned long )ciphers == (unsigned long )((void *)0)) {
al = 47;
ERR_put_error(20, 138, 182, (char const *)"s3_srvr.c", 841);
goto f_err;
}
ciphers = (STACK *)((void *)0);
tmp___9 = ssl_get_ciphers_by_id(s); c = ssl3_choose_cipher(s, (s->session)->ciphers, tmp___9);
if ((unsigned long )c == (unsigned long )((void *)0)) {
al = 40;
ERR_put_error(20, 138, 193, (char const *)"s3_srvr.c", 851);
goto f_err;
}
(s->s3)->tmp.new_cipher = c;
}
ret = 1;
if (0) {
f_err:
ssl3_send_alert(s, 2, al);
}
err:
if ((unsigned long )ciphers != (unsigned long )((void *)0)) { sk_free(ciphers);
} return (ret);
}
}static int ssl3_send_server_hello(SSL *s )
{ unsigned char *buf ;
unsigned char *p ;
unsigned char *d ;
int i ;
int sl ;
unsigned long l ;
unsigned long Time ;
unsigned char *tmp ;
unsigned char *tmp___0 ;
unsigned char *tmp___1 ;
unsigned char *tmp___2 ;
unsigned char *tmp___3 ;
unsigned char *tmp___4 ;
unsigned char *tmp___5 ;
unsigned char *tmp___6 ;
unsigned char *tmp___7 ;
unsigned char *tmp___8 ;
int tmp___9 ;
{
if (s->state == 8496) {
buf = (unsigned char *)(s->init_buf)->data;
p = (s->s3)->server_random;
Time = (unsigned long )time((time_t *)((void *)0));
tmp = p; p ++; (*tmp) = (unsigned char )((Time >> 24) & 255UL); tmp___0 = p; p ++; (*tmp___0) = (unsigned char )((Time >> 16) & 255UL); tmp___1 = p; p ++; (*tmp___1) = (unsigned char )((Time >> 8) & 255UL); tmp___2 = p; p ++; (*tmp___2) = (unsigned char )(Time & 255UL);
RAND_pseudo_bytes(p, (int )(32U - sizeof(Time)));
p = buf + 4; d = p;
tmp___3 = p; p ++; (*tmp___3) = (unsigned char )(s->version >> 8);
tmp___4 = p; p ++; (*tmp___4) = (unsigned char )(s->version & 255);
memcpy((void * )p, (void const * )((s->s3)->server_random),
32U); p += 32;
if (! ((s->ctx)->session_cache_mode & 2)) { (s->session)->session_id_length = 0U;
}
sl = (int )(s->session)->session_id_length;
tmp___5 = p; p ++; (*tmp___5) = (unsigned char )sl;
memcpy((void * )p, (void const * )((s->session)->session_id),
(unsigned int )sl); p += sl;
i = ssl3_put_cipher_by_char((SSL_CIPHER const *)(s->s3)->tmp.new_cipher, p);
p += i;
if ((unsigned long )(s->s3)->tmp.new_compression == (unsigned long )((void *)0)) { tmp___6 = p; p ++; (*tmp___6) = 0;
} else {
tmp___7 = p; p ++; (*tmp___7) = (unsigned char )((s->s3)->tmp.new_compression)->id;
}
l = (unsigned long )(p - d);
d = buf;
tmp___8 = d; d ++; (*tmp___8) = 2;
(*(d + 0)) = (unsigned char )((l >> 16) & 255UL); (*(d + 1)) = (unsigned char )((l >> 8) & 255UL); (*(d + 2)) = (unsigned char )(l & 255UL); d += 3;
s->state = 4369;
s->init_num = p - buf;
s->init_off = 0;
}
tmp___9 = ssl3_do_write(s, 22); return (tmp___9);
}
}static int ssl3_send_server_done(SSL *s )
{ unsigned char *p ;
unsigned char *tmp ;
unsigned char *tmp___0 ;
unsigned char *tmp___1 ;
unsigned char *tmp___2 ;
int tmp___3 ;
{
if (s->state == 8560) {
p = (unsigned char *)(s->init_buf)->data;
tmp = p; p ++; (*tmp) = 14;
tmp___0 = p; p ++; (*tmp___0) = 0;
tmp___1 = p; p ++; (*tmp___1) = 0;
tmp___2 = p; p ++; (*tmp___2) = 0;
s->state = 8561;
s->init_num = 4;
s->init_off = 0;
}
tmp___3 = ssl3_do_write(s, 22); return (tmp___3);
}
}static int ssl3_send_server_key_exchange(SSL *s )
{ unsigned char *q ;
int j ;
int num ;
RSA *rsa ;
unsigned char md_buf[36] ;
unsigned int u ;
DH *dh ;
DH *dhp ;
EVP_PKEY *pkey ;
unsigned char *p ;
unsigned char *d ;
int al ;
int i ;
unsigned long type ;
int n ;
CERT *cert ;
BIGNUM *r[4] ;
int nr[4] ;
int kn ;
BUF_MEM *buf ;
EVP_MD_CTX md_ctx ;
int tmp ;
int tmp___0 ;
int tmp___2 ;
int tmp___3 ;
int tmp___4 ;
EVP_MD const *tmp___5 ;
int tmp___6 ;
EVP_MD const *tmp___7 ;
int tmp___8 ;
unsigned char *tmp___9 ;
int tmp___10 ;
{
dh = (DH *)((void *)0);
if (s->state == 8528) {
type = ((s->s3)->tmp.new_cipher)->algorithms & 31UL;
cert = s->cert;
buf = s->init_buf;
r[3] = (BIGNUM *)((void *)0); r[2] = r[3]; r[1] = r[2]; r[0] = r[1];
n = 0;
if (type & 1UL) {
rsa = cert->rsa_tmp;
if ((unsigned long )rsa == (unsigned long )((void *)0)) { if ((unsigned long )(s->cert)->rsa_tmp_cb != (unsigned long )((void *)0)) {
if (((s->s3)->tmp.new_cipher)->algo_strength & 4UL) { tmp = 512;
} else {
tmp = 1024;
}
rsa = ((*((s->cert)->rsa_tmp_cb)))(s, (int )(((s->s3)->tmp.new_cipher)->algo_strength &
2UL), tmp);
if ((unsigned long )rsa == (unsigned long )((void *)0)) {
al = 40;
ERR_put_error(20, 155, 1092, (char const *)"s3_srvr.c", 1043);
goto f_err;
}
CRYPTO_add_lock(& rsa->references, 1, 9, (char const *)"s3_srvr.c", 1046);
cert->rsa_tmp = rsa;
}
} if ((unsigned long )rsa == (unsigned long )((void *)0)) {
al = 40;
ERR_put_error(20, 155, 172, (char const *)"s3_srvr.c", 1052);
goto f_err;
}
r[0] = rsa->n;
r[1] = rsa->e;
(s->s3)->tmp.use_rsa_tmp = 1;
} else {
if (type & 16UL) {
dhp = cert->dh_tmp;
if ((unsigned long )dhp == (unsigned long )((void *)0)) { if ((unsigned long )(s->cert)->dh_tmp_cb != (unsigned long )((void *)0)) { if (((s->s3)->tmp.new_cipher)->algo_strength & 4UL) { tmp___0 = 512;
} else {
tmp___0 = 1024;
}
dhp = ((*((s->cert)->dh_tmp_cb)))(s, (int )(((s->s3)->tmp.new_cipher)->algo_strength &
2UL), tmp___0);
}
}
if ((unsigned long )dhp == (unsigned long )((void *)0)) {
al = 40;
ERR_put_error(20, 155, 171, (char const *)"s3_srvr.c", 1072);
goto f_err;
}
if ((unsigned long )(s->s3)->tmp.dh != (unsigned long )((void *)0)) {
DH_free(dh);
ERR_put_error(20, 155, 157, (char const *)"s3_srvr.c", 1079);
goto err;
}
dh = (DH *)ASN1_dup((int (*)())(& i2d_DHparams), (char *(*)())(& d2i_DHparams),
(char *)dhp);
if ((unsigned long )dh == (unsigned long )((void *)0)) {
ERR_put_error(20, 155, 5, (char const *)"s3_srvr.c", 1085);
goto err;
}
(s->s3)->tmp.dh = dh;
if ((unsigned long )dhp->pub_key == (unsigned long )((void *)0)) {
goto _L;
} else {
if ((unsigned long )dhp->priv_key == (unsigned long )((void *)0)) {
goto _L;
} else {
if (s->options & 1048576UL) {
_L:
tmp___2 = DH_generate_key(dh); if (! tmp___2) {
ERR_put_error(20, 155, 5, (char const *)"s3_srvr.c", 1096);
goto err;
}
} else {
dh->pub_key = BN_dup((BIGNUM const *)dhp->pub_key);
dh->priv_key = BN_dup((BIGNUM const *)dhp->priv_key);
if ((unsigned long )dh->pub_key == (unsigned long )((void *)0)) {
ERR_put_error(20, 155, 5, (char const *)"s3_srvr.c", 1108);
goto err;
} else {
if ((unsigned long )dh->priv_key == (unsigned long )((void *)0)) {
ERR_put_error(20, 155, 5, (char const *)"s3_srvr.c", 1108);
goto err;
}
}
}
}
}
r[0] = dh->p;
r[1] = dh->g;
r[2] = dh->pub_key;
} else {
al = 40;
ERR_put_error(20, 155, 250, (char const *)"s3_srvr.c", 1120);
goto f_err;
}
} i = 0; while ((unsigned long )r[i] != (unsigned long )((void *)0)) {
tmp___3 = BN_num_bits((BIGNUM const *)r[i]); nr[i] = (tmp___3 + 7) / 8;
n += 2 + nr[i];
i ++;
}
if (((s->s3)->tmp.new_cipher)->algorithms & 256UL) {
pkey = (EVP_PKEY *)((void *)0);
kn = 0;
} else {
pkey = ssl_get_sign_pkey(s, (s->s3)->tmp.new_cipher); if ((unsigned long )pkey == (unsigned long )((void *)0)) {
al = 50;
goto f_err;
}
kn = EVP_PKEY_size(pkey);
}
tmp___4 = BUF_MEM_grow(buf, (n + 4) + kn); if (! tmp___4) {
ERR_put_error(20, 155, 7, (char const *)"s3_srvr.c", 1147);
goto err;
}
d = (unsigned char *)(s->init_buf)->data;
p = d + 4;
i = 0; while ((unsigned long )r[i] != (unsigned long )((void *)0)) {
(*(p + 0)) = (unsigned char )((nr[i] >> 8) & 255); (*(p + 1)) = (unsigned char )(nr[i] & 255); p += 2;
BN_bn2bin((BIGNUM const *)r[i], p);
p += nr[i];
i ++;
}
if ((unsigned long )pkey != (unsigned long )((void *)0)) {
if (pkey->type == 6) {
q = md_buf;
j = 0;
num = 2; while (num > 0) {
if (num == 2) { tmp___5 = (s->ctx)->md5;
} else {
tmp___5 = (s->ctx)->sha1;
}
EVP_DigestInit(& md_ctx, tmp___5);
EVP_DigestUpdate(& md_ctx, (void const *)(& (s->s3)->client_random[0]),
32U); EVP_DigestUpdate(& md_ctx, (void const *)(& (s->s3)->server_random[0]),
32U); EVP_DigestUpdate(& md_ctx, (void const *)(d + 4), (unsigned int )n);
EVP_DigestFinal(& md_ctx, q, (unsigned int *)(& i));
q += i;
j += i;
num --;
}
tmp___6 = RSA_sign(114, md_buf, (unsigned int )j, p + 2, & u, pkey->pkey.rsa); if (tmp___6 <= 0) {
ERR_put_error(20, 155, 4, (char const *)"s3_srvr.c", 1185);
goto err;
}
(*(p + 0)) = (unsigned char )((u >> 8) & 255U); (*(p + 1)) = (unsigned char )(u & 255U); p += 2;
n = (int )((unsigned int )n + (u + 2U));
} else {
if (pkey->type == 116) {
tmp___7 = (EVP_MD const *)EVP_dss1(); EVP_DigestInit(& md_ctx, tmp___7);
EVP_DigestUpdate(& md_ctx, (void const *)(& (s->s3)->client_random[0]),
32U); EVP_DigestUpdate(& md_ctx, (void const *)(& (s->s3)->server_random[0]),
32U); EVP_DigestUpdate(& md_ctx, (void const *)(d + 4), (unsigned int )n);
tmp___8 = EVP_SignFinal(& md_ctx, p + 2, (unsigned int *)(& i), pkey); if (! tmp___8) {
ERR_put_error(20, 155, 10, (char const *)"s3_srvr.c", 1204);
goto err;
}
(*(p + 0)) = (unsigned char )((i >> 8) & 255); (*(p + 1)) = (unsigned char )(i & 255); p += 2;
n += i + 2;
} else {
al = 40;
ERR_put_error(20, 155, 251, (char const *)"s3_srvr.c", 1215);
goto f_err;
}
}
} tmp___9 = d; d ++; (*tmp___9) = 12;
(*(d + 0)) = (unsigned char )((n >> 16) & 255); (*(d + 1)) = (unsigned char )((n >> 8) & 255); (*(d + 2)) = (unsigned char )(n & 255); d += 3;
s->init_num = n + 4;
s->init_off = 0;
}
s->state = 8529;
tmp___10 = ssl3_do_write(s, 22); return (tmp___10);
f_err:
ssl3_send_alert(s, 2, al);
err:
return (-1);
}
}static int ssl3_send_certificate_request(SSL *s )
{ unsigned char *p ;
unsigned char *d ;
int i ;
int j ;
int nl ;
int off ;
int n ;
STACK *sk ;
X509_NAME *name ;
BUF_MEM *buf ;
int tmp___0 ;
int tmp___1 ;
unsigned char *tmp___2 ;
unsigned char *tmp___3 ;
unsigned char *tmp___4 ;
unsigned char *tmp___5 ;
unsigned char *tmp___6 ;
int tmp___7 ;
{
sk = (STACK *)((void *)0);
if (s->state == 8544) {
buf = s->init_buf;
p = (unsigned char *)(buf->data + 4); d = p;
p ++;
n = ssl3_get_req_cert_type(s, p);
(*(d + 0)) = (unsigned char )n;
p += n;
n ++;
off = n;
p += 2;
n += 2;
sk = SSL_get_client_CA_list(s);
nl = 0;
if ((unsigned long )sk != (unsigned long )((void *)0)) {
i = 0; while (1) { tmp___1 = sk_num((STACK const *)sk); if (! (i < tmp___1)) { break;
}
name = (X509_NAME *)sk_value((STACK const *)sk, i);
j = i2d_X509_NAME(name, (unsigned char **)((void *)0));
tmp___0 = BUF_MEM_grow(buf, ((4 + n) + j) + 2); if (! tmp___0) {
ERR_put_error(20, 150, 7, (char const *)"s3_srvr.c", 1272);
goto err;
}
p = (unsigned char *)(buf->data + (4 + n));
if (s->options & 536870912UL) {
d = p;
i2d_X509_NAME(name, & p);
j -= 2; (*(d + 0)) = (unsigned char )((j >> 8) & 255); (*(d + 1)) = (unsigned char )(j & 255); d += 2; j += 2;
n += j;
nl += j;
} else {
(*(p + 0)) = (unsigned char )((j >> 8) & 255); (*(p + 1)) = (unsigned char )(j & 255); p += 2;
i2d_X509_NAME(name, & p);
n += 2 + j;
nl += 2 + j;
}
i ++;
}
}
p = (unsigned char *)(buf->data + (4 + off));
(*(p + 0)) = (unsigned char )((nl >> 8) & 255); (*(p + 1)) = (unsigned char )(nl & 255); p += 2;
d = (unsigned char *)buf->data;
tmp___2 = d; d ++; (*tmp___2) = 13;
(*(d + 0)) = (unsigned char )((n >> 16) & 255); (*(d + 1)) = (unsigned char )((n >> 8) & 255); (*(d + 2)) = (unsigned char )(n & 255); d += 3;
s->init_num = n + 4;
s->init_off = 0;
p = (unsigned char *)(s->init_buf)->data + s->init_num;
tmp___3 = p; p ++; (*tmp___3) = 14;
tmp___4 = p; p ++; (*tmp___4) = 0;
tmp___5 = p; p ++; (*tmp___5) = 0;
tmp___6 = p; p ++; (*tmp___6) = 0;
s->init_num += 4;
}
tmp___7 = ssl3_do_write(s, 22); return (tmp___7);
err:
return (-1);
}
}static int ssl3_get_client_key_exchange(SSL *s )
{ int i ;
int al ;
int ok ;
long n ;
unsigned long l ;
unsigned char *p ;
RSA *rsa ;
EVP_PKEY *pkey ;
BIGNUM *pub ;
DH *dh_srvr ;
{
rsa = (RSA *)((void *)0);
pkey = (EVP_PKEY *)((void *)0);
pub = (BIGNUM *)((void *)0);
n = ssl3_get_message(s, 8592, 8593, 16, 2048L, & ok);
if (! ok) { return ((int )n);
} p = (unsigned char *)(s->init_buf)->data;
l = ((s->s3)->tmp.new_cipher)->algorithms;
if (l & 1UL) {
if ((s->s3)->tmp.use_rsa_tmp) {
if ((unsigned long )s->cert != (unsigned long )((void *)0)) { if ((unsigned long )(s->cert)->rsa_tmp != (unsigned long )((void *)0)) { rsa = (s->cert)->rsa_tmp;
}
} if ((unsigned long )rsa == (unsigned long )((void *)0)) {
al = 40;
ERR_put_error(20, 139, 173, (char const *)"s3_srvr.c", 1365);
goto f_err;
}
} else {
pkey = (s->cert)->pkeys[0].privatekey;
if ((unsigned long )pkey == (unsigned long )((void *)0)) {
al = 40;
ERR_put_error(20, 139, 168, (char const *)"s3_srvr.c", 1378);
goto f_err;
} else {
if (pkey->type != 6) {
al = 40;
ERR_put_error(20, 139, 168, (char const *)"s3_srvr.c", 1378);
goto f_err;
} else {
if ((unsigned long )pkey->pkey.rsa == (unsigned long )((void *)0)) {
al = 40;
ERR_put_error(20, 139, 168, (char const *)"s3_srvr.c", 1378);
goto f_err;
}
}
}
rsa = pkey->pkey.rsa;
}
if (s->version > 768) {
i = (int )(((unsigned int )(*(p + 0)) << 8) | (unsigned int )(*(p + 1))); p += 2;
if (n != (long )(i + 2)) {
if (s->options & 256UL) {
p -= 2;
} else {
ERR_put_error(20, 139, 234, (char const *)"s3_srvr.c", 1392);
goto err;
}
} else {
n = (long )i;
}
}
i = RSA_private_decrypt((int )n, p, p, rsa, 1);
al = -1;
if (i != 48) {
al = 50;
ERR_put_error(20, 139, 118, (char const *)"s3_srvr.c", 1409);
}
if (al == -1) { if ((int )(*(p + 0)) == s->client_version >> 8) { if (! ((int )(*(p + 1)) == (s->client_version & 255))) {
goto _L;
}
} else {
_L:
if (s->options & 1024UL) { if ((int )(*(p + 0)) == s->version >> 8) { if (! ((int )(*(p + 1)) == (s->version & 255))) {
al = 50;
ERR_put_error(20, 139, 116, (char const *)"s3_srvr.c", 1425);
goto f_err;
}
} else {
al = 50;
ERR_put_error(20, 139, 116, (char const *)"s3_srvr.c", 1425);
goto f_err;
}
} else {
al = 50;
ERR_put_error(20, 139, 116, (char const *)"s3_srvr.c", 1425);
goto f_err;
}
}
} if (al != -1) {
ERR_clear_error();
i = 48;
(*(p + 0)) = (unsigned char )(s->client_version >> 8);
(*(p + 1)) = (unsigned char )(s->client_version & 255);
RAND_pseudo_bytes(p + 2, i - 2);
}
(s->session)->master_key_length = ((*(((s->method)->ssl3_enc)->generate_master_secret)))(s,
(s->session)->master_key,
p,
i);
memset((void *)p, 0, (unsigned int )i);
} else {
if (l & 22UL) {
i = (int )(((unsigned int )(*(p + 0)) << 8) | (unsigned int )(*(p + 1))); p += 2;
if (n != (long )(i + 2)) {
if (s->options & 128UL) {
p -= 2;
i = (int )n;
} else {
ERR_put_error(20, 139, 148, (char const *)"s3_srvr.c", 1467);
goto err;
}
}
if (n == 0L) {
al = 40;
ERR_put_error(20, 139, 236, (char const *)"s3_srvr.c", 1480);
goto f_err;
} else {
if ((unsigned long )(s->s3)->tmp.dh == (unsigned long )((void *)0)) {
al = 40;
ERR_put_error(20, 139, 171, (char const *)"s3_srvr.c", 1488);
goto f_err;
} else {
dh_srvr = (s->s3)->tmp.dh;
}
}
pub = BN_bin2bn((unsigned char const *)p, i, (BIGNUM *)((void *)0));
if ((unsigned long )pub == (unsigned long )((void *)0)) {
ERR_put_error(20, 139, 130, (char const *)"s3_srvr.c", 1498);
goto err;
}
i = DH_compute_key(p, pub, dh_srvr);
if (i <= 0) {
ERR_put_error(20, 139, 5, (char const *)"s3_srvr.c", 1506);
goto err;
}
DH_free((s->s3)->tmp.dh);
(s->s3)->tmp.dh = (DH *)((void *)0);
BN_clear_free(pub);
pub = (BIGNUM *)((void *)0);
(s->session)->master_key_length = ((*(((s->method)->ssl3_enc)->generate_master_secret)))(s,
(s->session)->master_key,
p,
i); memset((void *)p, 0, (unsigned int )i);
} else {
al = 40;
ERR_put_error(20, 139, 249, (char const *)"s3_srvr.c", 1524);
goto f_err;
}
} return (1);
f_err:
ssl3_send_alert(s, 2, al);
err:
return (-1);
}
}static int ssl3_get_cert_verify(SSL *s )
{ EVP_PKEY *pkey ;
unsigned char *p ;
int al ;
int ok ;
int ret ;
long n ;
int type ;
int i ;
int j ;
X509 *peer ;
{
pkey = (EVP_PKEY *)((void *)0);
ret = 0;
type = 0;
n = ssl3_get_message(s, 8608, 8609, -1, 512L, & ok);
if (! ok) { return ((int )n);
} if ((unsigned long )(s->session)->peer != (unsigned long )((void *)0)) {
peer = (s->session)->peer;
pkey = X509_get_pubkey(peer);
type = X509_certificate_type(peer, pkey);
} else {
peer = (X509 *)((void *)0);
pkey = (EVP_PKEY *)((void *)0);
}
if ((s->s3)->tmp.message_type != 15) {
(s->s3)->tmp.reuse_message = 1;
if ((unsigned long )peer != (unsigned long )((void *)0)) { if (type | 16) {
al = 10;
ERR_put_error(20, 136, 174, (char const *)"s3_srvr.c", 1573);
goto f_err;
}
} ret = 1;
goto end;
}
if ((unsigned long )peer == (unsigned long )((void *)0)) {
ERR_put_error(20, 136, 186, (char const *)"s3_srvr.c", 1582);
al = 10;
goto f_err;
}
if (! (type & 16)) {
ERR_put_error(20, 136, 220, (char const *)"s3_srvr.c", 1589);
al = 47;
goto f_err;
}
if ((s->s3)->change_cipher_spec) {
ERR_put_error(20, 136, 133, (char const *)"s3_srvr.c", 1596);
al = 10;
goto f_err;
}
p = (unsigned char *)(s->init_buf)->data;
i = (int )(((unsigned int )(*(p + 0)) << 8) | (unsigned int )(*(p + 1))); p += 2;
n -= 2L;
if ((long )i > n) {
ERR_put_error(20, 136, 159, (char const *)"s3_srvr.c", 1607);
al = 50;
goto f_err;
}
j = EVP_PKEY_size(pkey);
if (i > j) {
ERR_put_error(20, 136, 265, (char const *)"s3_srvr.c", 1615);
al = 50;
goto f_err;
} else {
if (n > (long )j) {
ERR_put_error(20, 136, 265, (char const *)"s3_srvr.c", 1615);
al = 50;
goto f_err;
} else {
if (n <= 0L) {
ERR_put_error(20, 136, 265, (char const *)"s3_srvr.c", 1615);
al = 50;
goto f_err;
}
}
}
if (pkey->type == 6) {
i = RSA_verify(114, (s->s3)->tmp.cert_verify_md, 36U, p, (unsigned int )i, pkey->pkey.rsa);
if (i < 0) {
al = 51;
ERR_put_error(20, 136, 118, (char const *)"s3_srvr.c", 1629);
goto f_err;
}
if (i == 0) {
al = 51;
ERR_put_error(20, 136, 122, (char const *)"s3_srvr.c", 1635);
goto f_err;
}
} else {
if (pkey->type == 116) {
j = DSA_verify(pkey->save_type, (unsigned char const *)(& (s->s3)->tmp.cert_verify_md[16]),
20, p, i, pkey->pkey.dsa);
if (j <= 0) {
al = 51;
ERR_put_error(20, 136, 112, (char const *)"s3_srvr.c", 1651);
goto f_err;
}
} else {
ERR_put_error(20, 136, 157, (char const *)"s3_srvr.c", 1658);
al = 43;
goto f_err;
}
} ret = 1;
if (0) {
f_err:
ssl3_send_alert(s, 2, al);
}
end:
EVP_PKEY_free(pkey);
return (ret);
}
}static int ssl3_get_client_certificate(SSL *s )
{ int i ;
int ok ;
int al ;
int ret ;
X509 *x ;
unsigned long l ;
unsigned long nc ;
unsigned long llen ;
unsigned long n ;
unsigned char *p ;
unsigned char *d ;
unsigned char *q ;
STACK *sk ;
int tmp ;
int tmp___0 ;
{
ret = -1;
x = (X509 *)((void *)0);
sk = (STACK *)((void *)0);
n = (unsigned long )ssl3_get_message(s, 8576, 8577, -1, 102400L, & ok);
if (! ok) { return ((int )n);
} if ((s->s3)->tmp.message_type == 16) {
if (s->verify_mode & 1) { if (s->verify_mode & 2) {
ERR_put_error(20, 137, 199, (char const *)"s3_srvr.c", 1701);
al = 40;
goto f_err;
}
} if (s->version > 768) { if ((s->s3)->tmp.cert_request) {
ERR_put_error(20, 137, 233, (char const *)"s3_srvr.c", 1708);
al = 10;
goto f_err;
}
} (s->s3)->tmp.reuse_message = 1;
return (1);
}
if ((s->s3)->tmp.message_type != 11) {
al = 10;
ERR_put_error(20, 137, 262, (char const *)"s3_srvr.c", 1719);
goto f_err;
}
p = (unsigned char *)(s->init_buf)->data; d = p;
sk = sk_new_null(); if ((unsigned long )sk == (unsigned long )((void *)0)) {
ERR_put_error(20, 137, 33, (char const *)"s3_srvr.c", 1726);
goto err;
}
llen = (((unsigned long )(*(p + 0)) << 16) | ((unsigned long )(*(p + 1)) << 8)) |
(unsigned long )(*(p + 2));
p += 3;
if (llen + 3UL != n) {
al = 50;
ERR_put_error(20, 137, 159, (char const *)"s3_srvr.c", 1734);
goto f_err;
}
nc = 0UL; while (nc < llen) {
l = (((unsigned long )(*(p + 0)) << 16) | ((unsigned long )(*(p + 1)) << 8)) |
(unsigned long )(*(p + 2));
p += 3;
if ((l + nc) + 3UL > llen) {
al = 50;
ERR_put_error(20, 137, 135, (char const *)"s3_srvr.c", 1743);
goto f_err;
}
q = p;
x = d2i_X509((X509 **)((void *)0), & p, (long )l);
if ((unsigned long )x == (unsigned long )((void *)0)) {
ERR_put_error(20, 137, 13, (char const *)"s3_srvr.c", 1751);
goto err;
}
if ((unsigned long )p != (unsigned long )(q + l)) {
al = 50;
ERR_put_error(20, 137, 135, (char const *)"s3_srvr.c", 1757);
goto f_err;
}
tmp = sk_push(sk, (char *)x); if (! tmp) {
ERR_put_error(20, 137, 33, (char const *)"s3_srvr.c", 1762);
goto err;
}
x = (X509 *)((void *)0);
nc += l + 3UL;
}
tmp___0 = sk_num((STACK const *)sk); if (tmp___0 <= 0) {
if (s->version == 768) {
al = 40;
ERR_put_error(20, 137, 176, (char const *)"s3_srvr.c", 1775);
goto f_err;
} else {
if (s->verify_mode & 1) { if (s->verify_mode & 2) {
ERR_put_error(20, 137, 199, (char const *)"s3_srvr.c", 1782);
al = 40;
goto f_err;
}
}
}
} else {
i = ssl_verify_cert_chain(s, sk);
if (! i) {
al = ssl_verify_alarm_type(s->verify_result);
ERR_put_error(20, 137, 178, (char const *)"s3_srvr.c", 1793);
goto f_err;
}
}
if ((unsigned long )(s->session)->peer != (unsigned long )((void *)0)) { X509_free((s->session)->peer);
}
(s->session)->peer = (X509 *)sk_shift(sk);
(s->session)->verify_result = s->verify_result;
if ((unsigned long )(s->session)->sess_cert == (unsigned long )((void *)0)) {
(s->session)->sess_cert = ssl_sess_cert_new();
if ((unsigned long )(s->session)->sess_cert == (unsigned long )((void *)0)) {
ERR_put_error(20, 137, 33, (char const *)"s3_srvr.c", 1810);
goto err;
}
}
if ((unsigned long )((s->session)->sess_cert)->cert_chain != (unsigned long )((void *)0)) { sk_pop_free(((s->session)->sess_cert)->cert_chain, (void (*)(void * ))(& X509_free));
}
((s->session)->sess_cert)->cert_chain = sk;
sk = (STACK *)((void *)0);
ret = 1;
if (0) {
f_err:
ssl3_send_alert(s, 2, al);
}
err:
if ((unsigned long )x != (unsigned long )((void *)0)) { X509_free(x);
} if ((unsigned long )sk != (unsigned long )((void *)0)) { sk_pop_free(sk, (void (*)(void * ))(& X509_free));
} return (ret);
}
}int ssl3_send_server_certificate(SSL *s )
{ unsigned long l ;
X509 *x ;
int tmp ;
{
if (s->state == 8512) {
x = ssl_get_server_send_cert(s);
if ((unsigned long )x == (unsigned long )((void *)0)) {
ERR_put_error(20, 154, 157, (char const *)"s3_srvr.c", 1844);
return (0);
}
l = ssl3_output_cert_chain(s, x);
s->state = 8513;
s->init_num = (int )l;
s->init_off = 0;
}
tmp = ssl3_do_write(s, 22); return (tmp);
}
}
|
the_stack_data/26700305.c | /* $OpenBSD: syslogc.c,v 1.18 2015/10/13 16:30:55 deraadt Exp $ */
/*
* Copyright (c) 2004 Damien Miller
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <err.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define DEFAULT_CTLSOCK "/var/run/syslogd.sock"
#define MAX_MEMBUF_NAME 64 /* Max length of membuf log name */
/*
* Client protocol NB. all numeric fields in network byte order
*/
#define CTL_VERSION 2
/* Request */
struct ctl_cmd {
u_int32_t version;
#define CMD_READ 1 /* Read out log */
#define CMD_READ_CLEAR 2 /* Read and clear log */
#define CMD_CLEAR 3 /* Clear log */
#define CMD_LIST 4 /* List available logs */
#define CMD_FLAGS 5 /* Query flags only */
#define CMD_READ_CONT 6 /* Read out log continuously */
u_int32_t cmd;
u_int32_t lines;
char logname[MAX_MEMBUF_NAME];
};
/* Reply */
struct ctl_reply_hdr {
u_int32_t version;
#define CTL_HDR_FLAG_OVERFLOW 0x01
u_int32_t flags;
/* Reply text follows, up to MAX_MEMBUF long */
};
static void
usage(void)
{
extern char *__progname;
fprintf(stderr,
"usage: %s [-Ccfo] [-n lines] [-s reporting_socket] logname\n"
" %s -q\n", __progname, __progname);
exit(1);
}
int
main(int argc, char **argv)
{
const char *ctlsock_path;
char buf[8192];
struct sockaddr_un ctl;
int ctlsock, ch, oflag, rval;
FILE *ctlf;
extern char *optarg;
extern int optind;
struct ctl_cmd cc;
struct ctl_reply_hdr rr;
const char *errstr;
memset(&cc, '\0', sizeof(cc));
ctlsock_path = DEFAULT_CTLSOCK;
rval = oflag = 0;
while ((ch = getopt(argc, argv, "Ccfhon:qs:")) != -1) {
switch (ch) {
case 'C':
cc.cmd = CMD_CLEAR;
break;
case 'c':
cc.cmd = CMD_READ_CLEAR;
break;
case 'h':
usage();
break;
case 'f':
cc.cmd = CMD_READ_CONT;
break;
case 'n':
cc.lines = strtonum(optarg, 1, UINT32_MAX, &errstr);
if (errstr)
errx(1, "number of lines is %s: %s",
errstr, optarg);
break;
case 'o':
cc.cmd = CMD_FLAGS;
oflag = 1;
break;
case 'q':
cc.cmd = CMD_LIST;
break;
case 's':
ctlsock_path = optarg;
break;
default:
usage();
break;
}
}
if (cc.cmd == 0)
cc.cmd = CMD_READ;
if ((cc.cmd != CMD_LIST && optind != argc - 1) ||
(cc.cmd == CMD_LIST && optind != argc))
usage();
if (cc.cmd != CMD_LIST) {
if (strlcpy(cc.logname, argv[optind], sizeof(cc.logname)) >=
sizeof(cc.logname))
errx(1, "Specified log name is too long");
}
memset(&ctl, '\0', sizeof(ctl));
strlcpy(ctl.sun_path, ctlsock_path, sizeof(ctl.sun_path));
ctl.sun_family = AF_UNIX;
if ((ctlsock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1)
err(1, "socket");
if (connect(ctlsock, (struct sockaddr *)&ctl, sizeof(ctl)) == -1)
err(1, "connect: %s", ctl.sun_path);
if ((ctlf = fdopen(ctlsock, "r+")) == NULL)
err(1, "fdopen");
if (pledge("stdio", NULL) == -1)
err(1, "stdio");
cc.version = htonl(CTL_VERSION);
cc.cmd = htonl(cc.cmd);
/* Send command */
if (fwrite(&cc, sizeof(cc), 1, ctlf) != 1)
err(1, "fwrite");
fflush(ctlf);
setvbuf(ctlf, NULL, _IOLBF, 0);
setvbuf(stdout, NULL, _IOLBF, 0);
/* Fetch header */
if (fread(&rr, sizeof(rr), 1, ctlf) != 1)
err(1, "fread header");
if (ntohl(rr.version) != CTL_VERSION)
errx(1, "unsupported syslogd version");
/* Write out reply */
while ((fgets(buf, sizeof(buf), ctlf)) != NULL) {
if (!strcmp(buf, "<ENOBUFS>\n"))
fprintf(stderr, "syslogc [%s]: Lines were dropped!\n",
cc.logname);
else
fputs(buf, stdout);
}
if (oflag && (ntohl(rr.flags) & CTL_HDR_FLAG_OVERFLOW)) {
printf("%s has overflowed\n", cc.logname);
rval = 1;
}
fclose(ctlf);
close(ctlsock);
exit(rval);
}
|
the_stack_data/150141886.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,sum=0,i=1;
printf("Enter nmber : ");
scanf("%d", &n);
while(i<=n)
{
sum= i;
++i;
}
printf("sum= %d", sum);
return 0;
}
|
the_stack_data/212641881.c | /** EL2208 Praktikum Pemecahan Masalah dengan C 2021/2022
* Modul : 1
* Percobaan : Tugas Pendahuluan
* Hari dan Tanggal : Kamis, 17 Februari 2022
* Nama (NIM) : Eraraya Morenzo Muten (18320003)
* Asisten (NIM) : Dhanurangga Al Fadh (13218005)
* Nama File : above_average.c
* Deskripsi : Program menghitung rata-rata nilai (0-100)
* dari mahasiswa sejumlah integer positif N
* dan menampilkan nilai yang di atas rata-rata.
*/
#include <stdio.h>
#include <stdlib.h>
int main() {
// Deklarasi variabel
int N;
int i;
int sum = 0;
int score[N];
scanf("%d",&N);
for (i=0; i<N; ++i){
scanf("%d", &score[i]);
sum+=score[i];
}
//printf("%d\n", sum/N); // Memeriksa rata-rata semua nilai
for (i=0; i<N; ++i){
if (score[i]>(sum/N)){
printf("%d\n", score[i]);
}
}
return 0;
}
|
the_stack_data/161081224.c | #include <stdio.h>
void singleVsDoubleQuotes()
{
//
char c = 'c';
char* d = "d";
}
int main(void)
{
singleVsDoubleQuotes();
}
|
the_stack_data/94666.c |
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#define STACK_SIZE 20
typedef struct {
int *enqueue;
int *dequeue;
int size;
} MyQueue;
/** Initialize your data structure here. */
bool myQueueEmpty(MyQueue *obj);
MyQueue *myQueueCreate() {
MyQueue *stack = (MyQueue *) malloc(sizeof(MyQueue));
if (NULL != stack) {
// stack->enqueue = (int *) malloc(sizeof(int) * STACK_SIZE);
stack->enqueue = (int *) calloc(STACK_SIZE, sizeof(int));
stack->dequeue = (int *) calloc(STACK_SIZE, sizeof(int));
stack->size = 0;
if (NULL == stack->enqueue) {
free(stack->enqueue);
free(stack->dequeue);
stack->enqueue = NULL;
stack->dequeue = NULL;
free(stack);
}
}
return stack;
}
/** Push element x to the back of queue. */
void myQueuePush(MyQueue *obj, int x) {
if (obj->size < STACK_SIZE)
obj->enqueue[obj->size++] = x;
}
/** Removes the element from in front of queue and returns that element. */
int myQueuePop(MyQueue *obj) {
int res = -1;
if (myQueueEmpty(obj))return res;
int i = 0;
int j = obj->size;
while (j >= 0) {
obj->dequeue[i++] = obj->enqueue[j];
obj->enqueue[j--] = 0;
}
res = obj->dequeue[obj->size];
obj->dequeue[obj->size--] = 0;
i=0;
j = obj->size;
while (j >= 0) {
obj->enqueue[i++] = obj->dequeue[j];
obj->dequeue[j--] = 0;
}
return res;
}
/** Get the front element. */
int myQueuePeek(MyQueue *obj) {
int res = -1;
if (myQueueEmpty(obj))return res;
int i = 0;
int j = obj->size;
while (j >= 0) {
obj->dequeue[i++] = obj->enqueue[j--];
}
res = obj->dequeue[obj->size];
j = obj->size;
while (j >= 0) {
obj->dequeue[j--] = 0;
}
return res;
}
/** Returns whether the queue is empty. */
bool myQueueEmpty(MyQueue *obj) {
return NULL == obj || obj->size == 0;
}
void myQueueFree(MyQueue *obj) {
if (NULL != obj) {
free(obj->enqueue);
free(obj->dequeue);
obj->enqueue = NULL;
obj->dequeue = NULL;
free(obj);
obj = NULL;
}
}
int main() {
MyQueue *obj = myQueueCreate();
myQueuePush(obj, 1);
myQueuePush(obj, 2);
int param_2 = myQueuePop(obj);
int param_3 = myQueuePeek(obj);
bool param_4 = myQueueEmpty(obj);
myQueueFree(obj);
}
/**
* Your MyQueue struct will be instantiated and called as such:
* MyQueue* obj = myQueueCreate();
* myQueuePush(obj, x);
* int param_2 = myQueuePop(obj);
* int param_3 = myQueuePeek(obj);
* bool param_4 = myQueueEmpty(obj);
* myQueueFree(obj);
*/
|
the_stack_data/692754.c | /*
* Date: 2014-06-08
* Author: [email protected]
*
*
* This is Example 1.1 from the test suit used in
*
* Termination Proofs for Linear Simple Loops.
* Hong Yi Chen, Shaked Flur, and Supratik Mukhopadhyay.
* SAS 2012.
*
* The test suite is available at the following URL.
* https://tigerbytes2.lsu.edu/users/hchen11/lsl/LSL_benchmark.txt
*
* Comment: terminating, non-linear
*/
typedef enum {false, true} bool;
extern int __VERIFIER_nondet_int(void);
int main() {
int x;
x = __VERIFIER_nondet_int();
while (x > 0) {
x = -2*x + 10;
}
return 0;
}
|
the_stack_data/53466.c | #ifdef __cplusplus
# error "A C++ compiler has been selected for C."
#endif
#if defined(__18CXX)
# define ID_VOID_MAIN
#endif
/* Version number components: V=Version, R=Revision, P=Patch
Version date components: YYYY=Year, MM=Month, DD=Day */
#if defined(__INTEL_COMPILER) || defined(__ICC)
# define COMPILER_ID "Intel"
# if defined(_MSC_VER)
# define SIMULATE_ID "MSVC"
# endif
/* __INTEL_COMPILER = VRP */
# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100)
# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10)
# if defined(__INTEL_COMPILER_UPDATE)
# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE)
# else
# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10)
# endif
# if defined(__INTEL_COMPILER_BUILD_DATE)
/* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */
# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE)
# endif
# if defined(_MSC_VER)
/* _MSC_VER = VVRR */
# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
# endif
#elif defined(__PATHCC__)
# define COMPILER_ID "PathScale"
# define COMPILER_VERSION_MAJOR DEC(__PATHCC__)
# define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__)
# if defined(__PATHCC_PATCHLEVEL__)
# define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__)
# endif
#elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__)
# define COMPILER_ID "Embarcadero"
# define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF)
# define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF)
# define COMPILER_VERSION_PATCH HEX(__CODEGEARC_VERSION__ & 0xFFFF)
#elif defined(__BORLANDC__)
# define COMPILER_ID "Borland"
/* __BORLANDC__ = 0xVRR */
# define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8)
# define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF)
#elif defined(__WATCOMC__) && __WATCOMC__ < 1200
# define COMPILER_ID "Watcom"
/* __WATCOMC__ = VVRR */
# define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100)
# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10)
# if (__WATCOMC__ % 10) > 0
# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10)
# endif
#elif defined(__WATCOMC__)
# define COMPILER_ID "OpenWatcom"
/* __WATCOMC__ = VVRP + 1100 */
# define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100)
# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10)
# if (__WATCOMC__ % 10) > 0
# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10)
# endif
#elif defined(__SUNPRO_C)
# define COMPILER_ID "SunPro"
# if __SUNPRO_C >= 0x5100
/* __SUNPRO_C = 0xVRRP */
# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>12)
# define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xFF)
# define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF)
# else
/* __SUNPRO_CC = 0xVRP */
# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>8)
# define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xF)
# define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF)
# endif
#elif defined(__HP_cc)
# define COMPILER_ID "HP"
/* __HP_cc = VVRRPP */
# define COMPILER_VERSION_MAJOR DEC(__HP_cc/10000)
# define COMPILER_VERSION_MINOR DEC(__HP_cc/100 % 100)
# define COMPILER_VERSION_PATCH DEC(__HP_cc % 100)
#elif defined(__DECC)
# define COMPILER_ID "Compaq"
/* __DECC_VER = VVRRTPPPP */
# define COMPILER_VERSION_MAJOR DEC(__DECC_VER/10000000)
# define COMPILER_VERSION_MINOR DEC(__DECC_VER/100000 % 100)
# define COMPILER_VERSION_PATCH DEC(__DECC_VER % 10000)
#elif defined(__IBMC__) && defined(__COMPILER_VER__)
# define COMPILER_ID "zOS"
/* __IBMC__ = VRP */
# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100)
# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10)
# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10)
#elif defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ >= 800
# define COMPILER_ID "XL"
/* __IBMC__ = VRP */
# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100)
# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10)
# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10)
#elif defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ < 800
# define COMPILER_ID "VisualAge"
/* __IBMC__ = VRP */
# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100)
# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10)
# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10)
#elif defined(__PGI)
# define COMPILER_ID "PGI"
# define COMPILER_VERSION_MAJOR DEC(__PGIC__)
# define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__)
# if defined(__PGIC_PATCHLEVEL__)
# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__)
# endif
#elif defined(_CRAYC)
# define COMPILER_ID "Cray"
# define COMPILER_VERSION_MAJOR DEC(_RELEASE)
# define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR)
#elif defined(__TI_COMPILER_VERSION__)
# define COMPILER_ID "TI"
/* __TI_COMPILER_VERSION__ = VVVRRRPPP */
# define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000)
# define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000)
# define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000)
#elif defined(__FUJITSU) || defined(__FCC_VERSION) || defined(__fcc_version)
# define COMPILER_ID "Fujitsu"
#elif defined(__TINYC__)
# define COMPILER_ID "TinyCC"
#elif defined(__SCO_VERSION__)
# define COMPILER_ID "SCO"
#elif defined(__clang__) && defined(__apple_build_version__)
# define COMPILER_ID "AppleClang"
# if defined(_MSC_VER)
# define SIMULATE_ID "MSVC"
# endif
# define COMPILER_VERSION_MAJOR DEC(__clang_major__)
# define COMPILER_VERSION_MINOR DEC(__clang_minor__)
# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__)
# if defined(_MSC_VER)
/* _MSC_VER = VVRR */
# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
# endif
# define COMPILER_VERSION_TWEAK DEC(__apple_build_version__)
#elif defined(__clang__)
# define COMPILER_ID "Clang"
# if defined(_MSC_VER)
# define SIMULATE_ID "MSVC"
# endif
# define COMPILER_VERSION_MAJOR DEC(__clang_major__)
# define COMPILER_VERSION_MINOR DEC(__clang_minor__)
# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__)
# if defined(_MSC_VER)
/* _MSC_VER = VVRR */
# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
# endif
#elif defined(__GNUC__)
# define COMPILER_ID "GNU"
# define COMPILER_VERSION_MAJOR DEC(__GNUC__)
# define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__)
# if defined(__GNUC_PATCHLEVEL__)
# define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__)
# endif
#elif defined(_MSC_VER)
# define COMPILER_ID "MSVC"
/* _MSC_VER = VVRR */
# define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100)
# define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100)
# if defined(_MSC_FULL_VER)
# if _MSC_VER >= 1400
/* _MSC_FULL_VER = VVRRPPPPP */
# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000)
# else
/* _MSC_FULL_VER = VVRRPPPP */
# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000)
# endif
# endif
# if defined(_MSC_BUILD)
# define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD)
# endif
#elif defined(__VISUALDSPVERSION__) || defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)
# define COMPILER_ID "ADSP"
#if defined(__VISUALDSPVERSION__)
/* __VISUALDSPVERSION__ = 0xVVRRPP00 */
# define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24)
# define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF)
# define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF)
#endif
#elif defined(__IAR_SYSTEMS_ICC__ ) || defined(__IAR_SYSTEMS_ICC)
# define COMPILER_ID "IAR"
#elif defined(SDCC)
# define COMPILER_ID "SDCC"
/* SDCC = VRP */
# define COMPILER_VERSION_MAJOR DEC(SDCC/100)
# define COMPILER_VERSION_MINOR DEC(SDCC/10 % 10)
# define COMPILER_VERSION_PATCH DEC(SDCC % 10)
#elif defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION)
# define COMPILER_ID "MIPSpro"
# if defined(_SGI_COMPILER_VERSION)
/* _SGI_COMPILER_VERSION = VRP */
# define COMPILER_VERSION_MAJOR DEC(_SGI_COMPILER_VERSION/100)
# define COMPILER_VERSION_MINOR DEC(_SGI_COMPILER_VERSION/10 % 10)
# define COMPILER_VERSION_PATCH DEC(_SGI_COMPILER_VERSION % 10)
# else
/* _COMPILER_VERSION = VRP */
# define COMPILER_VERSION_MAJOR DEC(_COMPILER_VERSION/100)
# define COMPILER_VERSION_MINOR DEC(_COMPILER_VERSION/10 % 10)
# define COMPILER_VERSION_PATCH DEC(_COMPILER_VERSION % 10)
# endif
/* These compilers are either not known or too old to define an
identification macro. Try to identify the platform and guess that
it is the native compiler. */
#elif defined(__sgi)
# define COMPILER_ID "MIPSpro"
#elif defined(__hpux) || defined(__hpua)
# define COMPILER_ID "HP"
#else /* unknown compiler */
# define COMPILER_ID ""
#endif
/* Construct the string literal in pieces to prevent the source from
getting matched. Store it in a pointer rather than an array
because some compilers will just produce instructions to fill the
array rather than assigning a pointer to a static array. */
char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]";
#ifdef SIMULATE_ID
char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]";
#endif
#ifdef __QNXNTO__
char const* qnxnto = "INFO" ":" "qnxnto";
#endif
/* Identify known platforms by name. */
#if defined(__linux) || defined(__linux__) || defined(linux)
# define PLATFORM_ID "Linux"
#elif defined(__CYGWIN__)
# define PLATFORM_ID "Cygwin"
#elif defined(__MINGW32__)
# define PLATFORM_ID "MinGW"
#elif defined(__APPLE__)
# define PLATFORM_ID "Darwin"
#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
# define PLATFORM_ID "Windows"
#elif defined(__FreeBSD__) || defined(__FreeBSD)
# define PLATFORM_ID "FreeBSD"
#elif defined(__NetBSD__) || defined(__NetBSD)
# define PLATFORM_ID "NetBSD"
#elif defined(__OpenBSD__) || defined(__OPENBSD)
# define PLATFORM_ID "OpenBSD"
#elif defined(__sun) || defined(sun)
# define PLATFORM_ID "SunOS"
#elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__)
# define PLATFORM_ID "AIX"
#elif defined(__sgi) || defined(__sgi__) || defined(_SGI)
# define PLATFORM_ID "IRIX"
#elif defined(__hpux) || defined(__hpux__)
# define PLATFORM_ID "HP-UX"
#elif defined(__HAIKU__)
# define PLATFORM_ID "Haiku"
#elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS)
# define PLATFORM_ID "BeOS"
#elif defined(__QNX__) || defined(__QNXNTO__)
# define PLATFORM_ID "QNX"
#elif defined(__tru64) || defined(_tru64) || defined(__TRU64__)
# define PLATFORM_ID "Tru64"
#elif defined(__riscos) || defined(__riscos__)
# define PLATFORM_ID "RISCos"
#elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__)
# define PLATFORM_ID "SINIX"
#elif defined(__UNIX_SV__)
# define PLATFORM_ID "UNIX_SV"
#elif defined(__bsdos__)
# define PLATFORM_ID "BSDOS"
#elif defined(_MPRAS) || defined(MPRAS)
# define PLATFORM_ID "MP-RAS"
#elif defined(__osf) || defined(__osf__)
# define PLATFORM_ID "OSF1"
#elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv)
# define PLATFORM_ID "SCO_SV"
#elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX)
# define PLATFORM_ID "ULTRIX"
#elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX)
# define PLATFORM_ID "Xenix"
#elif defined(__WATCOMC__)
# if defined(__LINUX__)
# define PLATFORM_ID "Linux"
# elif defined(__DOS__)
# define PLATFORM_ID "DOS"
# elif defined(__OS2__)
# define PLATFORM_ID "OS2"
# elif defined(__WINDOWS__)
# define PLATFORM_ID "Windows3x"
# else /* unknown platform */
# define PLATFORM_ID ""
# endif
#else /* unknown platform */
# define PLATFORM_ID ""
#endif
/* For windows compilers MSVC and Intel we can determine
the architecture of the compiler being used. This is because
the compilers do not have flags that can change the architecture,
but rather depend on which compiler is being used
*/
#if defined(_WIN32) && defined(_MSC_VER)
# if defined(_M_IA64)
# define ARCHITECTURE_ID "IA64"
# elif defined(_M_X64) || defined(_M_AMD64)
# define ARCHITECTURE_ID "x64"
# elif defined(_M_IX86)
# define ARCHITECTURE_ID "X86"
# elif defined(_M_ARM)
# define ARCHITECTURE_ID "ARM"
# elif defined(_M_MIPS)
# define ARCHITECTURE_ID "MIPS"
# elif defined(_M_SH)
# define ARCHITECTURE_ID "SHx"
# else /* unknown architecture */
# define ARCHITECTURE_ID ""
# endif
#elif defined(__WATCOMC__)
# if defined(_M_I86)
# define ARCHITECTURE_ID "I86"
# elif defined(_M_IX86)
# define ARCHITECTURE_ID "X86"
# else /* unknown architecture */
# define ARCHITECTURE_ID ""
# endif
#else
# define ARCHITECTURE_ID ""
#endif
/* Convert integer to decimal digit literals. */
#define DEC(n) \
('0' + (((n) / 10000000)%10)), \
('0' + (((n) / 1000000)%10)), \
('0' + (((n) / 100000)%10)), \
('0' + (((n) / 10000)%10)), \
('0' + (((n) / 1000)%10)), \
('0' + (((n) / 100)%10)), \
('0' + (((n) / 10)%10)), \
('0' + ((n) % 10))
/* Convert integer to hex digit literals. */
#define HEX(n) \
('0' + ((n)>>28 & 0xF)), \
('0' + ((n)>>24 & 0xF)), \
('0' + ((n)>>20 & 0xF)), \
('0' + ((n)>>16 & 0xF)), \
('0' + ((n)>>12 & 0xF)), \
('0' + ((n)>>8 & 0xF)), \
('0' + ((n)>>4 & 0xF)), \
('0' + ((n) & 0xF))
/* Construct a string literal encoding the version number components. */
#ifdef COMPILER_VERSION_MAJOR
char const info_version[] = {
'I', 'N', 'F', 'O', ':',
'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[',
COMPILER_VERSION_MAJOR,
# ifdef COMPILER_VERSION_MINOR
'.', COMPILER_VERSION_MINOR,
# ifdef COMPILER_VERSION_PATCH
'.', COMPILER_VERSION_PATCH,
# ifdef COMPILER_VERSION_TWEAK
'.', COMPILER_VERSION_TWEAK,
# endif
# endif
# endif
']','\0'};
#endif
/* Construct a string literal encoding the version number components. */
#ifdef SIMULATE_VERSION_MAJOR
char const info_simulate_version[] = {
'I', 'N', 'F', 'O', ':',
's','i','m','u','l','a','t','e','_','v','e','r','s','i','o','n','[',
SIMULATE_VERSION_MAJOR,
# ifdef SIMULATE_VERSION_MINOR
'.', SIMULATE_VERSION_MINOR,
# ifdef SIMULATE_VERSION_PATCH
'.', SIMULATE_VERSION_PATCH,
# ifdef SIMULATE_VERSION_TWEAK
'.', SIMULATE_VERSION_TWEAK,
# endif
# endif
# endif
']','\0'};
#endif
/* Construct the string literal in pieces to prevent the source from
getting matched. Store it in a pointer rather than an array
because some compilers will just produce instructions to fill the
array rather than assigning a pointer to a static array. */
char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]";
char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]";
/*--------------------------------------------------------------------------*/
#ifdef ID_VOID_MAIN
void main() {}
#else
int main(int argc, char* argv[])
{
int require = 0;
require += info_compiler[argc];
require += info_platform[argc];
require += info_arch[argc];
#ifdef COMPILER_VERSION_MAJOR
require += info_version[argc];
#endif
#ifdef SIMULATE_ID
require += info_simulate[argc];
#endif
#ifdef SIMULATE_VERSION_MAJOR
require += info_simulate_version[argc];
#endif
(void)argv;
return require;
}
#endif
|
the_stack_data/74320.c | #include <stdio.h>
#include <string.h>
// A function to check if a string str is palindrome
void isPalindrome(char str[])
{
// Start from leftmost and rightmost corners of str
int l = 0;
int h = strlen(str) - 1;
// Keep comparing characters while they are same
while (h > l)
{
if (str[l++] != str[h--])
{
printf("%s is Not Palindrome", str);
return;
}
}
printf("%s is palindrome", str);
}
// Driver program to test above function
int main()
{
isPalindrome("abba");
isPalindrome("abbccbba");
isPalindrome("geeks");
return 0;
}
|
the_stack_data/112639214.c | #include <arpa/inet.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define RECEIVER_IP_ADDRESS "127.0.0.1"
#define RECEIVER_PORT_NUM 18080
#define STRERROR_BUF_SIZE 64
char strerror_buf[STRERROR_BUF_SIZE];
int main() {
errno = 0;
// ソケットの作成
// See: https://manpages.debian.org/buster/manpages-ja-dev/socket.2.ja.html
int sender_socket_descripter = socket(AF_INET, SOCK_DGRAM, 0);
if (sender_socket_descripter == -1) {
strerror_r(errno, strerror_buf, STRERROR_BUF_SIZE);
fprintf(stderr, "socket error: %d, %s.", errno, strerror_buf);
exit(1);
}
// ソケットの設定
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(RECEIVER_PORT_NUM);
addr.sin_addr.s_addr = inet_addr(RECEIVER_IP_ADDRESS);
// データ送信
size_t send_size = sendto(sender_socket_descripter,
"HELLO", 5, 0, (struct sockaddr *)&addr, sizeof(addr));
if (send_size == -1) {
strerror_r(errno, strerror_buf, STRERROR_BUF_SIZE);
fprintf(stderr, "send error: %d, %s.", errno, strerror_buf);
exit(2);
}
// socketの終了
// See: https://manpages.debian.org/buster/manpages-ja-dev/close.2.ja.html
int sender_socket_close_result = close(sender_socket_descripter);
if (sender_socket_close_result == -1) {
strerror_r(errno, strerror_buf, STRERROR_BUF_SIZE);
fprintf(stderr, "sender socket close error: %d, %s.", errno, strerror_buf);
exit(3);
}
return 0;
}
|
the_stack_data/179830265.c | #include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#define BUFFER_SIZE (65) // enough to fit the result of at most "50!"
void
print_factorial(unsigned int n)
{
int buffer[BUFFER_SIZE];
buffer[0] = 1;
int i, j, product;
int carry = 0;
int len = 1;
for (i = 2; i <= n; i++)
{
for (j = 0; j < len; j++)
{
product = i * buffer[j] + carry;
carry = product / 10;
buffer[j] = product % 10;
}
while (carry > 0)
{
buffer[len++] = carry % 10;
carry /= 10;
}
}
for (i = len - 1; i >= 0; i--)
{
printf("%i", buffer[i]);
}
}
int
main(int argc, char **argv)
{
for (int i = 1; i <= 50; i++)
{
printf("%i! = ", i);
print_factorial(i);
printf("\n");
}
return 0;
}
|
the_stack_data/116180.c | #include<stdio.h>
int linear_search(int [],int,int);
void main()
{
int n,i,arr[20],s;
printf("Enter Size of Array: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("Enter the no. you want to search: ");
scanf("%d",&s);
i=linear_search(arr,n,s);
if(i>0)
{
printf("No. found on %dth Location\n",i+1);
}
else
{
printf("N0. Not Found\n");
}
}
int linear_search(int arr[],int n,int s)
{
int i=-1;
for(i=0;i<n;i++)
{
if(arr[i]==s)
{
break;
}
}
return i;
}
|
the_stack_data/39377.c | int tree_bar(void)
{
return 8;
}
|
the_stack_data/371494.c | // RUN: %libomp-compile
// RUN: env OMP_ALLOCATOR=111 %libomp-run 2>&1 | FileCheck %s
// RUN: env OMP_ALLOCATOR=omp_default_mem_alloc_xyz %libomp-run 2>&1 | FileCheck %s
// UNSUPPORTED: gcc
// Both invocations of the test should produce (different) warnings:
// OMP: Warning #42: OMP_ALLOCATOR: "111" is an invalid value; ignored.
// OMP: Warning #189: Allocator omp_const_mem_alloc is not available, will use default allocator.
#include <stdio.h>
#include <omp.h>
int main() {
volatile int n = omp_get_max_threads(); // causes library initialization
return 0;
}
// CHECK: {{^OMP: Warning #[0-9]+}}: {{.*$}}
|
the_stack_data/1081762.c | /***********************************************************************
* FILE NAME: Cola-11150.c
*
* PURPOSE:
*
* @author: Md. Arafat Hasan Jenin
* EMAIL: [email protected]
*
* DEVELOPMENT HISTORY:
* Date Change Version Description
* -------------------------------------------------------------------
* 27 Aug 2016 New 1.0 Completed, Accepted
***********************************************************************/
#include<stdio.h>
int cola(int n) {
if(n<3)
return 0;
if(n%3==0)
return n/3+cola(n/3);
int y;
y=n/3;
if(n%3==1)
return y+cola(y+1);
return y+cola(y+2);
}
int main() {
int n;
while(scanf("%d", &n)==1) {
printf("%d\n",cola(n+1)+n);
}
return 0;
}
|
the_stack_data/51935.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
/** author: mayukh
* github.com/mayukh42
*/
#define MAXSIZE 32
#define MAXSYM 256
typedef enum Bool {
false,
true
} Bool;
char * remove_at (char * cs, unsigned idx) {
unsigned len = strlen (cs);
if (idx >= len)
return cs;
char * ds = (char *) malloc (sizeof (char) * len);
for (unsigned i = 0; i < len - 1; i++) {
if (i >= idx)
ds[i] = cs[i+1];
else
ds[i] = cs[i];
}
ds[len - 1] = '\0';
return ds;
}
void test_remove_at () {
char cs[] = "germany";
unsigned i = 6;
char * ds = remove_at (cs, i);
printf ("%s, after removal at %u = %s\n", cs, i, ds);
free (ds);
}
/** is_equal ()
* returns true iff 2 strings are equal
*/
Bool is_equal (char * first, char * second) {
if (first[0] == '\0' && second[0] == '\0')
return true;
else
return (first[0] == second[0]) &&
is_equal (first + 1, second + 1);
}
/** is_equal_upto ()
* returns true if same chars up to the given index
*/
Bool is_equal_upto (char * first, char * second, int n) {
if (n == 0)
return first[0] == second[0];
else
return (first[0] == second[0]) &&
is_equal_upto (first + 1, second + 1, n - 1);
}
void print_upto (char * str, int idx) {
for (int i = 0; i <= idx; i++)
printf ("%c", str[i]);
printf ("\n");
}
void test_basic_utilities () {
char cs[] = "hellgate";
char ds[] = "hello";
Bool eq = is_equal (cs, ds);
int idx = 3;
Bool eq_upto = is_equal_upto (cs, ds, idx);
printf ("the strings are %sequal\n", eq ? "" : "not ");
printf ("the strings are %sequal upto index %d\n", eq_upto ? "" : "not ", idx);
print_upto (cs, 3);
}
/** permute ()
* print all permutations of a given string
*/
void permute (char * cs, char * buf, int last) {
if (strlen (cs) == 0) {
buf[last] = '\0';
printf ("%s\n", buf);
} else {
for (unsigned i = 0; i < strlen (cs); i++) {
buf[last] = cs[i];
char * rest = remove_at (cs, i);
permute (rest, buf, last + 1);
free (rest);
}
}
}
/** subsets ()
* print all subsets of the given string, including the empty string
*/
void subsets (char * cs, char * buf, int last) {
if (strlen (cs) == 0) {
buf[last] = '\0';
printf ("%s\n", buf);
} else {
char c = cs[0];
char * rest = remove_at (cs, 0);
subsets (rest, buf, last);
buf[last] = c;
subsets (rest, buf, last + 1);
free (rest);
}
}
/** sequences ()
* print all sequences of length k composed of given alphabet
* includes repetitions
* assumes alphabet is a collection of unique chars
*/
void sequences (char * cs, char * buf, unsigned k, unsigned j) {
if (j == k) {
buf[k] = '\0';
printf ("%s\n", buf);
} else {
for (unsigned i = 0; i < strlen (cs); i++) {
buf[j] = cs[i];
sequences (cs, buf, k, j + 1);
}
}
}
void test_combinatorics () {
char * buf = (char *) malloc (sizeof (char) * MAXSIZE);
char cs[] = "abc";
printf ("\npermutations of %s:\n", cs);
permute (cs, buf, 0);
printf ("\nsubsets of %s:\n", cs);
subsets (cs, buf, 0);
unsigned len = 2;
printf ("\nsequences of alphabet %s, length = %d:\n", cs, len);
sequences (cs, buf, len, 0);
free (buf);
}
/** String matching algorithms
*/
/** naive_matcher ()
* O(n-m+1 . m)
*/
void naive_matcher (char * text, char * pat) {
unsigned t = strlen (text), p = strlen (pat);
if (p > t)
return;
for (unsigned i = 0; i < t-p+1; i++) {
if (is_equal_upto (pat, text + i, p - 1))
printf ("strings match at shift %d\n", i);
}
}
void test_naive () {
char cs[] = "2359023141526739921";
char ds[] = "59023141526";
naive_matcher (cs, ds);
}
/** rabin_karp ()
* Rabin-Karp algorithm for string matching
* O(n-m+1 . m) w/ better avg performance
* Power of 2 used = 65536 (2^16)
* Prime = 2147483647 (2^31 - 1); @TODO: does not work always
* Alphabet = 8 bit ASCII; base = 256
*/
void rabin_karp (char * text, char * pat, int radix, int q) {
int tlen = strlen (text), plen = strlen (pat);
long h = ((long) pow (radix * 1.0, (plen - 1) * 1.0)) % q;
long m = 0, ts = 0;
// preprocessing
for (int i = 0; i < plen; i++) {
m = (radix * m + pat[i]) % q;
ts = (radix * ts + text[i]) % q;
}
// matching
printf ("looking for a match of \"%s\":\n", pat);
for (int s = 0; s < tlen - plen + 1; s++) {
if (m == ts) {
if (is_equal_upto (pat, text + s, plen - 1))
printf ("strings match at shift %d\n", s);
}
if (s < tlen - plen)
ts = (radix * (ts - text[s] * h) + text[s + plen]) % q;
}
}
void test_rabin_karp () {
int base = 256, q = 65536;
char cs[] = "naive string matcher algorithm for strings";
char ds[] = "string";
rabin_karp (cs, ds, base, q);
char es[] = "2359023141526739921";
char fs[] = "90231415267";
rabin_karp (es, fs, base, q);
}
void print_int_array (int * xs, unsigned n) {
printf ("[");
for (unsigned i = 0; i < n; i++)
printf ("%d ", xs[i]);
printf ("]\n");
}
/** boyer_moore ()
* Boyer-Moore string matcher algorithm
* matches all occurrences
* O (m/n) avg
*/
void boyer_moore (char * text, char * pat) {
unsigned n = strlen (text), m = strlen (pat);
if (n < m || n == 0 || m == 0)
return;
int * last_idx = (int *) malloc (sizeof (int) * MAXSYM);
for (unsigned i = 0; i < MAXSYM; i++)
last_idx[i] = -1;
for (unsigned i = 0; i < m; i++)
last_idx[(int) pat[i]] = i; // cast to avoid -Wchar-subscripts
unsigned i = 0;
while (i < n - m + 1) {
int j = m - 1;
while (j >= 0 && pat[j] == text[i + j])
j--;
if (j == -1) {
printf ("shift occurs at %u for '%s'\n", i, pat);
i++;
} else {
if (last_idx[(int) text[i+j]] != -1)
i += j - last_idx[(int) text[i+j]];
else
i += m;
}
}
free (last_idx);
}
void test_boyer_moore () {
char cs[] = "findinahaystackneedleinahaystackneedlefindallneedles";
char ds[] = "needle";
boyer_moore (cs, ds);
char es[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; // worst case for Boyer Moore
char fs[] = "aaaaaaaaa";
boyer_moore (es, fs);
}
void test_matchers () {
// test_naive ();
// test_rabin_karp ();
test_boyer_moore ();
}
void run_tests () {
// test_remove_at ();
// test_basic_utilities ();
test_combinatorics ();
// test_matchers ();
}
int main () {
run_tests ();
return 0;
}
|
the_stack_data/7949402.c |
//{{BLOCK(VueMasterImage4)
//======================================================================
//
// VueMasterImage4, 8x14360@2,
// + 1795 tiles not compressed
// Total size: 28720 = 28720
//
// Exported by Cearn's GBA Image Transmogrifier, v0.8.6
// ( http://www.coranac.com/projects/#grit )
//
//======================================================================
const unsigned int VueMasterImage4Tiles[7180] __attribute__((aligned(4)))=
{
0x00000000,0x00000000,0x00000000,0x00000000,0xEEEEAAAA,0xBAEEAAAA,0xEBAEAAAA,0xEBBBAEAA,
0xEEEEAAAA,0xAEBABAEB,0xBABAEBAB,0xAAEEEBAA,0xEEEEAAAA,0xBAEBEBAE,0xAEAEEBBA,0xBBAEEAEA,
0xEEEEAAAA,0xEBAEEEBA,0xEBAEAEBA,0xEBAEAEBA,0xEEEEAAAA,0xEEBAEBAE,0xAEBABAEB,0xAABABAEB,
0xEEEEAAAA,0xBBAEAABA,0xEAEBAEBA,0xEEABAEEE,0xBAEEAAAA,0xBABBEBAA,0xEEFAABAB,0x6556AAAB,
0xAAAEAAAA,0xEAAABBBA,0xBAEBAEEE,0xAAAAEEAE,0xBAAAAAAA,0xBAAAABBB,0xBBABABBA,0xBBAEAABA,
0xEAEBAAAA,0xAABBAEAA,0xABBBEEAA,0xBAEBEAAA,0xBABAAAAA,0xEAEAABAB,0xEAAAAEAE,0xEAAAAEEE,
0xAAAAAAAA,0xAAAAEEEE,0xBAAAEBBA,0xBABAABAE,0xBAAEAAAA,0xAABAABAA,0xAEAABAEA,0xEAABAABA,
0xBAAAAAAA,0xAAAAEBBB,0xAEBABAEB,0xAEBAAAAA,0xEEEEAAAA,0xBAEEAAAA,0xAAEBEBAA,0xABAAEEAE,
0xAEBAAAAA,0xAABABAAB,0xAAAEBBAA,0xAAEEBBAA,0xAEEBAAAA,0xAEEFBAAE,0xABBBBAAA,0xABBBBAAA,
0xEAEBAAAA,0xEAEBAEAE,0xEABBAEEA,0xEAABAEEA,0xAEBAAAAA,0xABBABAAB,0xABBABBAB,0xAEBAFAEB,
0xAAABAAAA,0xEABBBBBA,0xBBAEAEEB,0xAEBEBAEA,0xAABAAAAA,0xEABABBAB,0xEAAEAEEB,0xEAABAFFB,
0xAAAAAAAA,0xAAAAEEEE,0xAAEAEFBB,0xAAAABBAE,0xAAAAAAAA,0xAAAEEEEE,0xEAEBEFBA,0xAAABBBAE,
0xAAAAAAAA,0xBAEAABAE,0xBAEAABAE,0xBAEBABAE,0xAAAAAAAA,0xAAABAAAA,0xABABBABA,0xAAEBBABA,
0xAAAAAAAA,0xAAAAAAAA,0xAAABAAAA,0xAEAABAEE,0xA6AA9AAA,0xAAAAAA9A,0xAAAAAAAA,0xAAABAAAE,
0x9AAA5999,0x6AAA9999,0xAAAAA66A,0xAAAAAAAA,0x56695555,0x55A66656,0x5A66A9A9,0xAAAA69AA,
0x55555555,0x56565555,0x59965565,0x65995566,0x55555555,0x55555555,0x55555555,0x55555555,
0x51555555,0x15555551,0x54555555,0x55554555,0x44445555,0x51455555,0x55514555,0x55554455,
0x11441455,0x11545515,0x14545145,0x44545545,0xEBBAAEAB,0xAEEAEAAE,0xAEAEBAEE,0xAEBBEAEA,
0xAAEEEEAA,0xAAEEEEAA,0xABBAEEAB,0xAEEABAAE,0xBAAEEBBA,0xAEAEEBBA,0xAEBBBAEA,0xAEABBAEA,
0xEBAEAEBA,0xEAEBAEBA,0xBBABAEEE,0xEEEBEAEE,0xAABABBAB,0xABBABBAB,0xEEAEBAEB,0xBAAEABBA,
0x5EAB6AEE,0x56AA57BA,0x55EA56BB,0xA1EA95AF,0x99955595,0xBBAAAAA9,0xABAAEABA,0xABAABABB,
0xA955AAA5,0xAAAE56AA,0xAABAAAAA,0x6AAAAAAB,0xAAAAAAAA,0xAA56AAA9,0x56AA5AAA,0x5A55555A,
0xBAAAABAE,0xAAEE9AAA,0x5444AA55,0x55955555,0x66AAAFBB,0x45555455,0x555555AA,0x55554545,
0x5555ABAB,0x15105155,0x5555A555,0x51115555,0xA955AEEA,0x44454451,0xAAA956A9,0x44445555,
0xEAAABAEB,0x44045554,0x599A1155,0xAA55AAAA,0xBBAEEABB,0xA554AAA9,0x01154000,0xAAAA55AA,
0xAABABBAA,0x401A956B,0x41000405,0x00014400,0xEAEFBAAA,0xB940AFA6,0x40449404,0x41040410,
0xAABAAEEE,0xAABABBBB,0xAAE9BBBB,0xE904BB90,0xBAEBEBAA,0xBAEBABAA,0xABAAEAAE,0xBABAEEAE,
0xEEFEBBAA,0xEAAEAEEB,0xEAAEAEEA,0xBAAFAEEA,0xEAAAAEEE,0xEBAAAEBB,0xABAAAEBB,0xAAABBABA,
0xAAAAABBA,0xEAEAAEAE,0xABBAAEBB,0xAEBABAEB,0xEBAEAAAA,0xAAEEAAAA,0xAABAEBAB,0xBABAEBAB,
0xEAAAAEAA,0xABAAAAAE,0xAAAAEEAE,0xEBAAAEBA,0xAAEBEEAE,0xAAAABAAE,0xAEAAAAEE,0xBABAEBBB,
0xBAAAAAEE,0xAEAAEABA,0xAAEAAAAB,0xEAEEAEAA,0xBAAEABAA,0xAEBAAAAA,0xAABAAAAB,0xAEAABAEA,
0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAE,0xAAAA9AAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,
0x65AA9A66,0xAAAA9A9A,0x69A6A6AA,0x6AAAA6AA,0x55595555,0x66695596,0x999A5999,0xA69A59A6,
0x55555555,0x55555455,0x55595555,0x55995556,0x51545515,0x55455555,0x55555555,0x55555555,
0x44555545,0x45155554,0x15555555,0x55555555,0xAEAEEAEA,0xBAAEEBBA,0xBAAEEBBA,0xBAABEBBA,
0xABBABAAE,0xAEEABAAE,0xBAEEEBAE,0xBAEEEBAA,0xAAABBAEE,0xAAABBBBA,0xAAAEBBBA,0xAAAEEEEA,
0xEBEBBAAE,0xAAEBEEAE,0xAAEAEEAE,0xAAEAEEAE,0xAEAEEBBA,0xBBAEEAEA,0xBBAEAABA,0xBAAEABBA,
0x95EA95AE,0x96EA91AE,0x56AB92AE,0x46AE96AA,0xAAAAAAAE,0x5AAAAAAA,0xA95A95AA,0xAA569995,
0xA55A56AA,0xAAA9AE95,0xBBAABAAA,0xBBBBBBBA,0xAAAAA6AA,0xEEEEBBAA,0xBBBBEEEF,0xAEBBEBBB,
0xAEAAAAAA,0xAEBABBEF,0xAEEBBAEE,0xBBAEBAEE,0xAEAAA6AA,0xAEABBAEF,0xEEBBAAEA,0xAEBABAEB,
0x6AAA5559,0xBAEBABBB,0xBAEAAEAE,0xEBABAEEE,0x15550115,0xABAA6ABB,0xABAAAABB,0xABAAAABB,
0x00115400,0x11160445,0x556A516A,0xA56A55AA,0x9555AA6A,0x45515550,0x14551141,0x55515145,
0x10014101,0x04440011,0x44110045,0x01040044,0x00404410,0x40014404,0x00040100,0x00011110,
0x55449410,0x05A04690,0x10141054,0x50054114,0xBAEAABEF,0xBAE5ABAD,0xED5AAB54,0xE955AD52,
0xBABBABBB,0xEEABABBA,0xEAAAAEBA,0xAAEABBBB,0xAAAAEEEE,0xAEAABBBB,0xEEAAAAEE,0xEEABAAEE,
0xAEAEBAEA,0xEBABBABA,0xAEEABABB,0xEBAEBABE,0xEEBBABAB,0xEBAEBAEA,0xBBBBBAEE,0xAEEEEEEF,
0xABAAAEBB,0xAEBABAEE,0xBAAEEEEB,0xABAEEEFA,0xEFBAAEAB,0xABAEBABB,0xEAAEAEBA,0xAEABABBA,
0xAEEEAAAA,0xAEAAEAAA,0xABAAEAAE,0xAAAEBAAA,0xBABBAAEA,0xAEAEAAAA,0xEAAAAAAA,0xAAAEABBA,
0xAAAAAAEB,0xBAAEBBBA,0xAAAAEAEA,0xAAAEEAAA,0xAAAAAAAA,0xAAAAAAEB,0xBAEAAAAE,0xAAAAAAAA,
0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0x6AAA9A6A,0x6AAAA9AA,0xAAAAA6AA,0xAAAAAAAA,
0x66665666,0x699AA6A9,0xA6999AAA,0x99AA6AAA,0x55565555,0x99A65999,0x99665659,0x6669659A,
0x55555555,0x55555555,0x55655566,0x55965659,0xEBAEAEEE,0xEBAEAEBA,0xBAEBAEBA,0xBAEBEFBE,
0xAABAEBAB,0xABBAEEAB,0xAEEEBAAB,0xEBABBAEE,0xBAAAEBBA,0xAAEAABAE,0xAAEBBAAE,0xAAEABAAE,
0xAAEAEEAE,0xAABAEEAB,0xABAAEEAA,0xAEABAAAE,0xBAEEABAA,0xAAAEABAA,0x6AAAAAAA,0x56ABAAAA,
0x15AA4AAA,0x555A155A,0xE5156555,0xBA46ED55,0xEEE6BA9A,0xBBA5EEE9,0xBAA1ABA4,0xBA87BA93,
0xEEEEBBBB,0xBBBBEEEE,0xBAEBEBAE,0xEBAEBBBB,0xBAEEFBBB,0xEEEEAEEE,0xBBBABBAE,0xBBAEEBBB,
0xBEBBEBBA,0xEEEEBAEB,0xEBBBBBBB,0xEEBBBBBA,0xAEBBBAEE,0xEBAEBBBB,0xEEBAEEEB,0xEAEEBAEE,
0xEEEBAEBB,0xBAEAAEAE,0xBAEAABAE,0xEBBAAAAE,0xAAAABABB,0xAEBABBBB,0xAEBAEAEB,0xD5BA57EB,
0x5AAA59AA,0x556A55AA,0xAAA59A56,0xEEAAEABA,0x5A955655,0xAAA9AAA5,0xBAEBABAE,0xBAEAABAE,
0x01151051,0x455A1555,0x6AAA55AA,0xAAAB9AAA,0x40010440,0x40000104,0x44550455,0x55591555,
0x50044000,0x50044410,0x40000110,0x95554555,0xE550A950,0xE405E500,0x10154015,0x07E94694,
0xAEBABEEE,0xE956BAEE,0x4104A400,0x44040040,0xBBAAAAEE,0xEEEAAABB,0xAEBAEBAF,0xAE44BBD5,
0xBBABAEBA,0xBAEAEBAE,0xAAEEEBAE,0xAEEBBBBA,0xAEBFEAEA,0xBAAEEBBA,0xBBABABBA,0xFBBBAABA,
0xEABABEEE,0xBBBBAFAE,0xBAEEEEEB,0xEBBABBBB,0xAEBAEAEE,0xAEBBEAEB,0xAEEABAEE,0xBEBAEAEF,
0xBAEEABAA,0xBBBBAAAA,0xABBBAAAA,0xEAEEAEAA,0xBAEBAAAA,0xEABAABAA,0xAAAAAAAB,0xEBBABAAB,
0xBABAAAAA,0xAAAAEAEA,0xAEBBAAAA,0xAAEEAAAA,0xAAAAAAAA,0xAAAAAEBA,0xAAEAEAAA,0xAAABBBAA,
0xABAAAAAA,0xEAAAAAAA,0xAAAAAEAA,0xEAEBAEAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAE,0xBAEAAAAE,
0x9AAAAAAA,0x66AAAAAA,0xA6AAAAAA,0xAAAA9AAA,0x66669999,0x66999A6A,0x699A9A69,0x99AA6699,
0x65955659,0x5565565A,0x5666599A,0x59995966,0xBBAEBBBB,0xEEBBEBBA,0xBBBAEBAE,0xBBABEAEE,
0xBBBBEEEE,0xEEEEAEBA,0xEEEEAEBA,0xBAEEEBAE,0xAEBBAEEE,0xABBABAEB,0xABBABABB,0xBAEEEEAE,
0xAAEBAAAA,0xAEBBAAAA,0xBABBAAEA,0xBAEEABAA,0x95AA5AAA,0x65AA56AA,0x55AA966A,0x5AAA56AA,
0xEE46BA46,0xED46BA46,0xA51AED0A,0x8469A059,0xE52EEA5B,0x55EE947B,0x4BEB86BA,0xBAEA3EAE,
0xEEBAEEEE,0xEEEEAEEF,0xBAE9EEE9,0xBA51EE95,0xBBBABAEE,0xBBAEEEBB,0xBBAEAEEE,0xBBBBEAEE,
0xEBBBBBBB,0xBAEBBBBA,0xABBBBBBB,0xAAEEEEAA,0xEEBAAEEB,0xEEBBAAEB,0xEEBBAEEA,0x55BB5BBA,
0xBBAAAEBB,0x55AE5AEE,0x9A55A56B,0xFA95A995,0xAA95B95B,0xFEAAAAA9,0xFFBAABA9,0xFEEBAAEE,
0xEEEEEEEA,0xEEEEBBBB,0xEEEEBBBB,0xBBFBBBBB,0xBAEEABAE,0xEBAEAEEB,0xBAEEAEBB,0xBBBBEBBB,
0xAAAAAAAE,0xBAAAABBB,0xABABAEEE,0xAEEBEABA,0x566A5566,0x5AAAA9AA,0x9AAAAAAA,0x6AAAAAAA,
0xA555A955,0x95569555,0x55595555,0x15565155,0x41EB51FE,0x01EA41AE,0x0A9912A5,0x01550655,
0x10040410,0x10011104,0x14004110,0x40411110,0xB551F914,0x9511E440,0x51018440,0x15044414,
0xEEEEEEBE,0xEEEEBBBB,0xEEEEBBBB,0xBBB5EEED,0xEEEEEEEE,0xEBBBEEEE,0xBBBBEEEE,0xBBBBEEEE,
0xEEEEEEEE,0xEEEEEEEE,0xBBBBBEEE,0xEEFBEEEE,0xEEEEBBEE,0xEEEEEEEE,0xBBBBBBBB,0xBEEEEEEE,
0xEEEEAEBB,0xEEEEEEEE,0xBBBBBBBB,0xBEEFBBFB,0xBAEAAEBB,0xBBAEEBBE,0xBBBBBBBB,0xEEEFBBBB,
0xBABBBBAA,0xAEEEEEEE,0xBBBBBBBB,0xEEEEBBBB,0xAEAAAAEE,0xEEEBEAEE,0xBBBBAEBB,0xAEEEBBBB,
0xEAEAAAAE,0xBAEAABAE,0xEEBBABAE,0xAEBBBAEB,0xABAEAAAA,0xAABBBAAA,0xAAAEEEEA,0xBABBEEEB,
0xAAABAAAA,0xAAAAAAAA,0xAAAEAABA,0xAAAEEEEA,0x99AA6A9A,0x6AAAAAAA,0xAAAAAAAA,0xAAAAAAAA,
0x599959A6,0x5A9A6669,0x5AA96A6A,0x6AAA69AA,0xEBAEBAEE,0xEEEBAEBA,0xAABABAEE,0xBAEAAAAA,
0xAEBABBAB,0xBBBAEBBB,0xBAEBAEAE,0xBABAABAA,0xAEBBEBAB,0xAEEEBAEA,0xEEBBBAEB,0xEAEBAEAA,
0xBABBABAA,0xBAEBABAE,0xAEBAEEEE,0xAEAABAEB,0x6AAA6AAB,0xAAEAAABB,0xAEEBBBAE,0xBBABBAEE,
0x06951165,0x65561956,0x56AB556A,0xABAE5ABB,0xAA91AAA9,0x55016544,0x51550015,0x559A5555,
0x546BA546,0x159551AA,0x11045551,0x55554444,0xBBAAEAEE,0x5555AA55,0x55551104,0x54515144,
0xABAAEEBA,0x555556AB,0x55556555,0x51554555,0x5555655A,0xFA95A955,0xA555EFA5,0x11044444,
0xEEEEBBA9,0xBEEEBBBB,0x01BA5BEE,0x04011055,0xFBEBEFBE,0x001656BF,0x10441100,0x44440401,
0xFBAAEFBF,0x00005555,0x40010444,0x10101144,0xBBBFEEEE,0xE540FFA5,0x01004011,0x10414414,
0xAEBBEAEE,0xEBBBBBAE,0xEEE8AEEE,0xBD04BB90,0xAAABAAAE,0xAAAEAAEA,0xAABAAAEB,0xABBBAEAE,
0x15565156,0x15665156,0x156A555A,0x55AA559A,0x10450051,0x41110114,0x44110445,0x10450114,
0x04114440,0x11041040,0x14440010,0x04110040,0x95415910,0x11005011,0x84404001,0x08409004,
0xEED5AEE5,0xBB94EE99,0xEF85EE54,0xEE54EF56,0xEBEEEEBB,0xBAEEEFBE,0xBEEEBBBB,0xFFBEBBEE,
0xEEEEBBAE,0xBBBBEEEE,0xFEFBBBBB,0xFEEEAFEF,0xEEEEBBEF,0xBBBBEEEE,0xFAFFEFFB,0xEEEEEFBB,
0xBBEEFBBB,0xEEEFBEEE,0xBBBEEEEE,0xFBEEEFBB,0xBBBFEFEE,0xEFBBFBBB,0xBEFBEEEE,0xEEEEFBEF,
0xBBBBBBBB,0xBBBEFBEE,0xBEFBEEEE,0xEEFBEFBE,0xBBBBFBBB,0xEEFBEEEE,0xEEEFEEEE,0xBEFBEFBE,
0xBBBBEEEE,0xEEEEEEEE,0xBBBBEEEE,0xEFBFEEEE,0xBBBBEBBA,0xEBAEAEEE,0xBBAFEEFA,0xBBAEEEFA,
0xEABAAEEA,0xAEBAAEEB,0xBBBBBAEE,0xBBBBBBAE,0xAEAAAAEE,0xBABAAAEB,0xBABBABAB,0xEAEBAEEE,
0x6AAA6AAA,0xAAAA6AAA,0xAAAB6AAE,0xAAAE6BAA,0xABAAAAAE,0xAAAAAAAA,0xEAAAAEBA,0xBBAAABBB,
0xAEAAAAAA,0xBAAAEAEB,0xEBAEAAAA,0xAAAAAAAA,0xAAEAAEAE,0xAAEABAAE,0xAABABAAA,0xBAAAABAA,
0xBABBAAEA,0xAAABEBAA,0xAAAABBBA,0xBAAAAAEB,0xEEAEAABA,0xEEAAAAEA,0xAEABAAEE,0xAAAABABA,
0xEAAAAEBA,0xAAAAAEEE,0xAABAEBAB,0xBAEBAAAA,0xAAAAAAAA,0xBABAAAEB,0xAEEAAAAA,0xAAAABAAE,
0xAAAA5566,0xEBBAAAAA,0xEABBAEAA,0xEAAEAEEA,0xAAAAAA59,0xABAAEEBA,0xABAEEEBA,0xABAABABA,
0xAEEEAAAA,0xEBAEEEBA,0xBBAEBAEA,0xEBAAAEBB,0x1ABB555A,0x02EE1BAA,0x10BB01EE,0x402E046E,
0x04144100,0x04114040,0x50100101,0x00100041,0x44010110,0x10550110,0x55550564,0x85555445,
0x54500541,0xD1144444,0x6514A451,0x14423845,0x40400404,0x41010412,0x40410411,0x00511104,
0xD010F401,0x00404104,0x10041104,0x04014110,0xAEEEBAEB,0xAFEDBABF,0x5540FAA4,0x01100004,
0x59AB56AA,0x6ABB5AAA,0xAAAAAAEF,0x40045550,0x41150444,0x01154451,0x11564515,0x11444515,
0x40040040,0x00040040,0x00444410,0x50050440,0x50405504,0x45100451,0x14515104,0x85040451,
0xEE41FE40,0xFFD1BB45,0xFFFCBBB0,0xBFFBBBBE,0xEEFFEEEE,0xEFBBFBEE,0xFFBFEEFB,0xEFEFEEFB,
0xFEFBEEEE,0xFBEEAFBE,0xFBEEEFBF,0xFBBEBFFB,0xBBEFFEFE,0xEFEEFBBF,0xFFBBBEFF,0xFBBBEFFF,
0xFBEFBBBE,0xFBFFEEEE,0xFFFFEFBB,0xFEFBBBEE,0xEEEEBEFB,0xEFBBBEFE,0xFBFBBBBE,0xFBFBBFBF,
0xBBFBFEEF,0xBFBFFBBB,0xEFBFFBFB,0xFBEFBEFB,0xFBEFEFBE,0xFFFBBBBE,0xEFEFBBBE,0xEFBBBEFB,
0xEFBEEEFB,0xBEFBFBEF,0xFEFBBBEF,0xFEFBBBEF,0xBBBBBBBE,0xEEEFEEEE,0xEFBBBBFB,0xBEFBFBBF,
0xEBBBBBBB,0xBBAEEEEE,0xBBAEEEFB,0xEEEFEEFE,0xABAEBBBB,0xBBBBEEEE,0xEFBBBAEE,0xEEEEEEEE,
0x6AAB6ABA,0xABAEABBA,0xABBAAEBB,0xAEEEAEAE,0xAAAAEABB,0xAAAABBBA,0xAAAAAAAA,0xAEBAAAAA,
0xAAAABBBA,0xAAEBEBAA,0xAAAAAAAA,0xAAAAAAAA,0xEAAAAABB,0xAABAABAA,0xAAAAAAAA,0xAAAAAAAA,
0xAAAAAAAA,0xAAAAAAAE,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAEAAA,0xAAAAAAAA,0xAAAAAAAA,
0xAAEAEAAE,0xABAABAAE,0xAAAAAAAA,0xAAAAAAAA,0xABAAEEEE,0xBAAAEAAE,0xEAAAAAEA,0xAAAAAAAA,
0xBAEEBBAA,0xBAEEABAA,0xBAEEABAA,0xBAAAABAA,0xAEEBBAEF,0xEEEAAAAE,0xAEEAAAAE,0xAAEABAAE,
0xEBABAEBB,0xAAAAAEEE,0xAEBBBAEA,0xABBABAAB,0x101E042A,0x101A011B,0x101B011B,0x411B041A,
0x04100441,0x04101041,0x04101041,0x04101041,0x44005440,0x15504401,0x91101101,0x8401C000,
0x44411107,0x00151114,0x00561055,0x40454515,0x01541151,0x01591065,0x14244068,0x04004114,
0x04014044,0x41011044,0x41540410,0x1E4006D0,0xA4405404,0x44409011,0x11100004,0x11100001,
0x455A0000,0xBFBAAAEF,0xFFF4BAF9,0xBF41EED0,0x00004000,0xAAFB155A,0xFFFFEEBB,0xBBBBEEEE,
0x44405144,0x01551001,0xFFFE6ABB,0xAEEEFEEF,0xE545D110,0xBE05F950,0xE446F511,0xD46FE51F,
0xBBBFEEEF,0xFBEFEFBA,0xBBFEBFBE,0xBEFEEFBB,0xEFBBFABB,0xBAFBBFEE,0xFBFFEFBB,0xFBFBEFBF,
0xEFBEBEEE,0xEFFBFEFB,0xBBEFFEEE,0xBBEEFEFE,0xFBBBBFFF,0xFBEFEFBE,0xEFEFBEFE,0xEEEFBEFE,
0xFFFBBBEF,0xFBBEAEEE,0xBEFBEFEF,0xBBBEFBEF,0xFBFBEFBF,0xBEFBEFAE,0xEFBFBBEE,0xEFEFFBBB,
0xFBEFBFBE,0xEEFBEFBE,0xEEFBEEEF,0xFBEEBBBE,0xBEEEFBFF,0xBBBAFFFF,0xEEEEEEEE,0xBBBEFBBB,
0xEEFFBFEF,0xBEFFFFEE,0xEEEEEEEE,0xEEEFFBEE,0xBEFFFBEF,0xBFFFFBEE,0xAEEEFBBB,0xEEEEBEEE,
0xBBFFFEEE,0xEFEFFBAE,0xEEEBFBBE,0xBBBEBBEF,0xEFEFEEFB,0xBEEEBBBE,0xBAFAEFEF,0xBBBBEFAF,
0xBAEEAEEE,0xABBBAFBB,0xBBBBBBBB,0xBBAAAAEE,0xEAAAAAAA,0xAAAAABAE,0xAAAABAEA,0xAAAAAAAE,
0xAAAAAAAA,0xAAAAAABB,0xAAAAAAAA,0xAAABAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAA6AAAAA,0x6AA6A6AA,
0xAAAAAAAA,0xAAAAAAAA,0xA69AAAAA,0x9A6AA9AA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0x6A66A69A,
0xAAAAAAAA,0xAAAAAAAA,0xAAA9AAAA,0xEAA6AAAA,0xBAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAEAAEAEA,
0xAABAEBAB,0xAAAABAAA,0xAAAAAAAA,0xAAAAABAE,0xAAAABAAA,0xAAAABBBA,0xAAABBBAA,0xEAAAAAAA,
0x401B041A,0x101B041A,0x00070116,0x10010446,0x04104041,0x40104441,0x10110441,0x41000440,
0x44444044,0x44041040,0x44010110,0x11040110,0x11000441,0x11044044,0x04104041,0x10414104,
0xE8045051,0xEE44FD00,0xFE04EF00,0xD444E800,0xD0BF6815,0x07FE43FB,0x0BFE0BBB,0x06FF47FF,
0x41060401,0x1095405A,0x14010114,0x94047910,0x5400F904,0x00105044,0x10104441,0x04114101,
0xBBEAEEFF,0x9441FE54,0x16800044,0x6E046F84,0xBFBEFBBB,0xEFFFFEFB,0xE944BFA5,0x26EE411D,
0xE46FD56E,0xE51FE52F,0xF952E94B,0xFE54FA52,0xEFBBFBFF,0xBFBBFEFF,0xBFEEFBFF,0xFBEFFEFE,
0xFBEFBEEE,0xFBEFBEFE,0xFBFBBFBF,0xFBFEEFBF,0xFBFBEFBF,0xBFFBEEEF,0xEFEEFEFF,0xBFFBFBBF,
0xBFBEFBFB,0xBFBFEEFB,0xBFBEFBFB,0xAFFFFBEF,0xEEFFEFBB,0xBBFFFFBB,0xFEFFBFEE,0x5556EFFF,
0xEEEEBEEE,0xEFBFBBFB,0xEFBFFEFB,0xE955FFFE,0xBEEEEEEF,0xEEEEEEFB,0xEEEEEEFF,0xBBBFFFFF,
0xBBBBBBEB,0xEEEBEFBE,0xBBBEEEEE,0xEFBFBEFB,0xFEFBBBBB,0xFBFBEEEE,0xBBBBEEEE,0xBBBBBEFB,
0xBBBEEEFB,0xFBBEBBEE,0xEFBBEEFB,0xBBEFFBBB,0xEEEFEEEE,0xBBBEBBBB,0xBEEEEFBB,0xBEFBEBEF,
0xEEEEAEEE,0xBBBBBBBB,0xBBFBEEEF,0xBBBBBBBB,0xAEBAAAEF,0xBBBBBBBB,0xABBBAEEE,0xBBBBBBBB,
0xAAAAAAAA,0xAAEAAAAA,0xAAAAAAAA,0xAAAAAAAA,0x6AAAAAAA,0x9AAAAAAA,0x9AAAAA6A,0x6AAAAAAA,
0x69AAA69A,0x6AA6AAAA,0x6A66A6AA,0x9A66A6AA,0x666AAAA6,0xA66A6AA6,0x99A66666,0x59996659,
0x66AA99AA,0x66669A66,0x65669999,0x59669595,0xA69AAA66,0x66669999,0x96599965,0xA6955965,
0xAAAAAAAA,0x6AAAAAA9,0x69996665,0x999A6666,0xAAAAAAAA,0xA96AAAAA,0x056A5A96,0x14454056,
0x1AAA6AAA,0x445545AA,0x11414404,0x10444104,0x10104111,0x40040441,0x41111110,0x11111104,
0x00011004,0x01040110,0x01045010,0x04111041,0x01011010,0x01001044,0x04011010,0x00411010,
0x10414104,0x10414104,0x11114000,0x10414104,0x45049010,0x11040010,0x04044110,0x01041040,
0xE01541AE,0xB801F440,0xE401F810,0x41119011,0x0BFF41A9,0x7FFF2FBB,0x7FFF7EEE,0x1FFE6FEF,
0x44AD400B,0x465005A4,0x44040041,0x10100444,0x50445410,0x44440140,0x01401111,0x04504451,
0xFEFB7EEB,0xFD50EEA5,0x00119441,0x01111110,0x405A9501,0x40FF01FF,0x10010556,0x11114110,
0xFF95FFFE,0x4040A944,0x41111104,0x04411104,0xBFFFFEEF,0x000155AF,0x44444444,0x10110441,
0x156AEFFF,0x04444001,0x44104444,0x44411111,0x1000115A,0x44411114,0x44444444,0x44441111,
0x11110000,0x44441111,0x44441114,0x10441111,0x04514000,0x04445111,0x04445111,0x44551111,
0xFE50FFE9,0x4111D404,0x11110444,0x44441111,0xEFFEFEFB,0xFBFDBFEF,0xFF41FFE4,0xE044F811,
0xBFEFFBFE,0xBFFFFBBF,0xEFFFFEFB,0xFFBFFFFE,0xEFEFFEFE,0xEFFBFEFF,0xBFFFFEEF,0xFBEFFFFE,
0xFFFEBBBB,0xFBBEBBBB,0xFBBFBFFB,0xBEFEBBFB,0xFFFBEEEF,0xFBEEBBBF,0xEEFBBFBF,0xBFBBFBEF,
0xBBBEAEEE,0xAEEEAEEF,0xBEBBBBEF,0xBBEFAEFE,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAA6A9AAA,
0xAAAAAAAA,0x6AAAAAAA,0xA9AAAAAA,0xAAAA9AA6,0x69AAAAA9,0x99AAAAA6,0x99AAAA9A,0x966A6A66,
0x666AA9A6,0x65999A66,0x66999A6A,0x99995966,0x59666599,0x59565599,0x59555599,0x55555566,
0x55656556,0x55555555,0x55555555,0x55555555,0x65969959,0x55555655,0x55555555,0x55555555,
0x15555669,0x11594555,0x11054455,0x10441111,0x50441111,0x41114444,0x11114444,0x51111111,
0x51104441,0x51444504,0x55515444,0xAA555555,0x45541444,0x55545511,0x56655555,0x15665566,
0xBA555555,0xFF95FFA5,0xA555EA55,0x15115514,0x04560404,0x105B115F,0x41160456,0x41110411,
0x10404104,0x00104001,0x00400101,0x10104000,0x44444410,0x10510400,0x10441100,0x41000400,
0x41044410,0x44440441,0x04041041,0x10441111,0x11544AF9,0x04444401,0x44114110,0x10440441,
0x44414104,0x40410410,0xA4109104,0x1A94AA41,0x10544151,0x41494419,0x00414416,0x10114504,
0x41041010,0x41041010,0x04444400,0x44104100,0x10444104,0x41101104,0x04111104,0x90104104,
0x10541104,0x11F801A9,0x1A950154,0xEEEA7AAE,0x11114444,0x04411111,0x41111011,0x94019010,
0x44441104,0x10AA112D,0x45B90141,0xAEBA2EEB,0x44444444,0x41044411,0x41104411,0x41100011,
0x00444444,0x05511545,0x55545550,0x55545554,0x45455518,0x05445454,0x51155550,0x54558555,
0x11141045,0x451A1119,0x44561146,0x45151152,0x01114504,0x44441111,0x44441111,0x11141111,
0xFBFEBFFF,0xFFE4FFF8,0xEF40FFD1,0xFE11FE45,0xEFBFFFFF,0xBFFEFFFF,0xFFFFFEFF,0xFFFFEFEF,
0xBFBBFBFF,0xFEFFFFFF,0xFFFFBFFB,0xFFFBFBFF,0xBFFBFBFF,0xBFEFFEFF,0xFEFFFFFF,0xFFFFEFFB,
0xAEFBBFBF,0xBEFFBFEF,0xBFBEBFFF,0xBBEFBFFF,0xA9AA6AAA,0x9AAAAA9A,0xA69AAAAA,0x66AAAA69,
0xAA9A666A,0x699A66A9,0xA99A66A9,0x659A9A69,0x999A99A6,0x966669A6,0x5999999A,0x55969659,
0x96595666,0x55955966,0x55596559,0x55555555,0x55555555,0x55555555,0x15555555,0x51555555,
0x55555555,0x45555555,0x55455455,0x54545555,0x45551555,0x10554155,0x44450445,0x44100105,
0x44444441,0x11114110,0x51101111,0x54441111,0x55144444,0xE551A544,0xFE51EA55,0xBFF5FFA5,
0xABBAAAA9,0x6BBFABBB,0x5ABF6AFB,0x15BB56FF,0x1156515A,0x44454455,0x14414115,0x45111044,
0x05111044,0x05045044,0x00510444,0x10040004,0x04440001,0x00000001,0x00001000,0x00400000,
0x00040000,0x00004100,0x04000010,0x40010000,0x04404004,0x44441100,0x41011044,0x11040410,
0x11440400,0x55454411,0x44104444,0x44040111,0x95514401,0x55555554,0x11040444,0x04441041,
0x115945A9,0x10444115,0x41114441,0x11111041,0x10414110,0x04444104,0x04101041,0x04411044,
0x11101040,0x44101100,0x44404101,0x11001001,0x90119041,0x81048044,0x11101044,0x04444111,
0xFAEAABAE,0xFEBAEBAE,0x6EE5FBA9,0x11051650,0xA443B046,0x9112A006,0x44444111,0x11110411,
0xEEBAEAEB,0xFFBABAEB,0x2BF5BEAA,0x11044551,0x41110401,0x41101111,0x44411044,0x41114444,
0x54045540,0x40040011,0x50040050,0x10044410,0x40641059,0x45511115,0x19152445,0x46155551,
0x55115044,0x65119051,0x78416444,0x14442404,0x11111144,0x11144451,0x44444444,0x11114445,
0xF811FD11,0xF851F844,0xF444F444,0xE511F444,0xBFEFFBFE,0xBFFFFEFF,0xFFFEFBEF,0xFFBFBEFF,
0xEFEFFEFF,0xFBBFFFFF,0xFFFFEFFB,0xFEFFFBEF,0xEFEFFEFE,0xFFBEFFFF,0xFEFEEFFF,0xEFFFFFFB,
0xBEFFBFFF,0xBFFEBFFB,0xBFEFBEFF,0xBEFBBFFF,0x969A6A66,0x9A6669A6,0x996666A9,0x9965669A,
0x66669A66,0x55996659,0x95595996,0x55655999,0x65965559,0x55555559,0x55555556,0x55555555,
0x55555555,0x55555555,0x55555555,0x45555555,0x45555515,0x51555545,0x45155554,0x55511555,
0x45551545,0x01551544,0x44154055,0x10010445,0x41104441,0x44411044,0x11101104,0x51114441,
0x54445144,0xE5149551,0xFA55E951,0xFF95FE94,0xFFFEFFBA,0xBFFFFFFB,0xABFFAFFF,0x5AFF6FFF,
0x456A456F,0x1156445A,0x11054456,0x11014455,0x51040444,0x44110444,0x01110444,0x04111044,
0x00100041,0x55001401,0x55405100,0x15505101,0x04000000,0x00000011,0x01150415,0x15550454,
0x10004040,0x40410400,0x44400400,0x44100041,0x04044110,0x10104441,0x10404111,0x10440104,
0x18744050,0x76A86B24,0x9D3D58F8,0xB386D70D,0x10404410,0x056E1009,0xAD3569B3,0xD387C72E,
0x11040410,0x44444111,0x10524101,0x49281476,0x41114411,0x11101104,0x04411044,0x44114444,
0x40004404,0x00104045,0x01110111,0x04445104,0x04445044,0x11111110,0x44401104,0x10114100,
0x11111110,0x11111111,0x11440411,0x10441104,0x11111111,0x44111111,0x41111111,0x04411044,
0x41114451,0x41441411,0x44441411,0x11114441,0x10444444,0x10444511,0x44441111,0x11114444,
0x11110010,0x51111104,0x44444111,0x44111104,0x56444740,0x54544141,0x15444444,0x44444411,
0x51144551,0x51144545,0x11141511,0x10444544,0x44444445,0x11141111,0x11154441,0x11111110,
0xF844F444,0xFD11F911,0xFF81FE44,0xFFB8FED1,0xFFFBEFFF,0xFFFFEFBF,0xBFFFFFFF,0xFFFFFFFF,
0xEFEFBFFE,0xFFBFFFFF,0xFBFBFFFB,0xFBFFFFBF,0xFFFFBFBF,0xFFFEBEEF,0xFEFFFFFB,0xEFFBFFFF,
0xBEFBBFFF,0xBBFBBFFF,0xBFFFBFFF,0xBFBFBFFE,0x9665599A,0x55955966,0x55966659,0x56555559,
0x55955956,0x55565555,0x55555555,0x55555555,0x55555555,0x54555555,0x55555555,0x55555555,
0x15555455,0x01545545,0x10554555,0x10054155,0x10041111,0x44040440,0x10444110,0x41141100,
0x54414444,0x54445511,0xE5449544,0xF954E911,0xFFF9FFA5,0xFFFEFFFA,0xBFFFFFFF,0x6FFFBFFF,
0x56AF5ABF,0x15AA46AF,0x455A115B,0x14555116,0x11014454,0x44414454,0x05144445,0x11514444,
0x10010044,0x00000044,0x10004044,0x15004004,0x15145040,0x44454450,0x04415114,0x04115144,
0x45555111,0x44441444,0x11110444,0x41110444,0x44104041,0x04101041,0x04101041,0x40104441,
0x41040410,0x01114410,0x11041011,0x04101041,0x595069D1,0x00418404,0x10411104,0x44410404,
0x34E371C3,0x9D245C75,0x5010B901,0x11100111,0xC3C7471D,0xB269D3E3,0x19E669AE,0x75115E80,
0x1B424107,0x75D06A81,0xD7B49DA0,0x675DA728,0x04405044,0x056E1015,0xB26953B2,0x0F4E6A9C,
0x45514044,0x41115411,0x04441444,0x10454440,0x44500400,0x15540105,0x1F011D11,0x1AC12B44,
0x04444411,0x10114441,0x44101144,0x04104041,0x44414410,0x41001114,0x45440415,0x00041110,
0x44444444,0x44511104,0x41454400,0x10105511,0x44101144,0x44444111,0x11104444,0x45511115,
0x44441111,0x11104444,0x11114444,0x55155111,0x44441111,0x04444444,0xA9555004,0xD9556954,
0x90444111,0xAF90B904,0xAAAAAABA,0xEAAFAAFE,0xFFEBFFEE,0xFFFAFFFA,0xFFFEFFFE,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFBFFFF,0xFFFFFFFF,0xFBFFFFFF,
0xFEFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xBFFFBFFF,0xBFFFFFFB,0xBFBFBFFF,0xBFFFFFFF,
0x55595565,0x55555555,0x55555565,0x55555555,0x55555555,0x55555555,0x55555555,0x51555555,
0x55141555,0x55555555,0x15555555,0x05515555,0x00114115,0x40101105,0x10410404,0x10104100,
0x44111040,0x44404444,0x51105105,0x91104511,0xFF55FA51,0xFFA5FE94,0xFFF9FFE5,0xFFFEFFFA,
0x5AFFABFF,0x56BF56FF,0x55AB55AF,0x555A156B,0x51151145,0x45451111,0x44441454,0x05115455,
0x04144111,0x01114445,0x10114441,0x44414444,0x15404004,0x14444044,0x14444111,0x14444111,
0x04115144,0x04115144,0x44111144,0x44111144,0x04114444,0x04111044,0x00441041,0x00041111,
0x10440504,0x11110401,0x44010110,0x00014444,0x11044111,0x11044041,0x04104041,0x01014444,
0x10500104,0x51044414,0x14405144,0x44114104,0x11044411,0x14444110,0x11454104,0x44444514,
0x44410044,0x41044414,0x41110444,0x40441104,0xA85429E9,0x0044B400,0x10044511,0x41100441,
0x11D30687,0x05A440E1,0x11011910,0x11044044,0x41114444,0x10411104,0x40410444,0x91118410,
0x06A41AD0,0x11A906A4,0x445A1159,0x41154456,0x11104001,0x44100001,0x14440111,0x51444444,
0x00041040,0x40100000,0x01010000,0x00440004,0x10100101,0x10000100,0x10000104,0x00004000,
0x04011044,0x11014110,0x01041010,0x41041010,0x41015451,0x11114444,0x11115104,0x11105111,
0xE544D555,0xB545F514,0xA945A954,0xEA55A955,0xFEA7FAAF,0xBFEAFEAA,0xFBFEFFEA,0xFFFFFFFE,
0xFFFFFFFF,0xFFBBFBFF,0xFFFFFFFF,0xFEFFEFFB,0xFFFFFFFF,0xEFBFFFFF,0xFFFFFFFF,0xFFBFFBFF,
0xFFFFFFFF,0xFFEFFFFF,0xFFFEEFFF,0xFFFFFFBF,0xFFFFFFFF,0xFFBFFFFF,0xFFFFFFFF,0xFBFFFFFF,
0xBFFFBFFF,0xBFFFBFFF,0xBBFFFFFF,0xBFEFBFFF,0x55555555,0x55555555,0x55555555,0x15555555,
0x55555555,0x55555555,0x54555555,0x55555555,0x55555551,0x55555555,0x55555554,0x55555555,
0x01551555,0x00551555,0x00551155,0x00551115,0x10401101,0x41410404,0x41111000,0x44041040,
0x95449511,0xE944E451,0xF954F951,0xFF54FE51,0xBFFFBFFE,0xABFFAFFF,0xAAFFABFF,0x6ABFAAFF,
0x5556116A,0x5456455A,0x55154555,0x15154555,0x11454451,0x11154444,0x11044454,0x41451111,
0x11111104,0x44411104,0x11114444,0x14514444,0x11114111,0x44441111,0x11114444,0x11111111,
0x11114444,0x44441111,0x11114444,0x11111111,0x04111144,0x11100111,0x04414044,0x04114111,
0x00114440,0x01104401,0x40404404,0x00400404,0x01044410,0x01041010,0x01001010,0x01004411,
0x11111040,0x44104101,0x04004041,0x04004044,0x11115111,0x41104444,0x41044444,0x41040410,
0x11451144,0x44101444,0x11104104,0x04101041,0x11011045,0x04414045,0x14104044,0x11114101,
0x10440441,0x10441104,0x41040410,0x10414410,0x7844A041,0x69516911,0x1A441A04,0x86444A50,
0x44510505,0x41504445,0x44551115,0x51151155,0x44444511,0x45145451,0x45151451,0x55451451,
0x01140045,0x04540545,0x14511545,0x15515555,0x00004401,0x00014400,0x00004410,0x01101400,
0x41040400,0x40040410,0x40100440,0x40400401,0x14445111,0x44444441,0x44444444,0x51104441,
0xFE95FA54,0xFF94FE95,0xFF54FF95,0xFE54FE95,0xFFFFBFFF,0xEFFFFFFF,0xFFBFFFFF,0xFFFFFFFF,
0xFFEFFFFF,0xFFFFFBFF,0xFFFFBFEF,0xFFFFFFFF,0xBFFEFFFF,0xFFEFFEFF,0xFBFFFFFF,0xFFFBFFFF,
0xFFFFFFFF,0xFFFFEEFB,0xEFFEFFBF,0xFBEFBFFF,0xFFFFFFFF,0xFFFFFFFB,0xFFFFFBEF,0xFFFFFFFF,
0xBFFFFFFF,0xBFFFBFFF,0xBFFFFFFF,0xBFFFFFFF,0x55555555,0x55555155,0x55155555,0x55554555,
0x55555515,0x55555555,0x55555555,0x55555555,0x10054115,0x00454115,0x10450005,0x40450005,
0x11041110,0x51044410,0x44404410,0x50405104,0xFFE5FE95,0xBFF5FFA5,0xBBF9FFE9,0xAAA9AFB9,
0x5AAB5AAF,0x56AA56AF,0x55AA55AA,0x556A556A,0x55551155,0x45451115,0x45141455,0x44441555,
0x51140451,0x55114445,0x55515511,0x55555551,0x51114145,0x51114555,0x51151555,0x55551555,
0x14444444,0x44441114,0x51114515,0x45111155,0x04454444,0x11145111,0x44441111,0x45114451,
0x04114444,0x01111044,0x10441111,0x10440504,0x00401104,0x00104401,0x10100101,0x10100101,
0x01041011,0x01001010,0x01001011,0x00411004,0x10104111,0x10104101,0x10100101,0x10100101,
0x40040400,0x10000110,0x10000111,0x10000111,0x44104101,0x44010040,0x01010010,0x00044410,
0x44440040,0x41040410,0x41000410,0x40400404,0x41100411,0x00404411,0x41044444,0x41044410,
0xA2849651,0xA591A590,0xA9A0A954,0x6A94AA94,0x469A4556,0xFFA66EAA,0xEFE9EEEA,0xEFBAFEEA,
0x54451154,0x115B5554,0xFFFF6AFF,0xFBFEFFEF,0x55515455,0x15555515,0x15AA5545,0x2FFF2BFF,
0x00404401,0x01104400,0x01044440,0x10011110,0x10041100,0x10441100,0x11104400,0x51100401,
0x45141111,0x44511441,0x11555444,0x51145511,0xFE51FE55,0xFE55FE55,0xFD55FA55,0xFD55FA55,
0xBFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFEFF,0xFFFFFFFF,0xFFFFFBFF,0xBFFFFFFF,0xFFFFFEFB,
0xFFFEEFBF,0xFFEFFFFF,0xFFFFFFFF,0xFFEFFFFF,0xBFFFFFFF,0xBFFEFFFF,0xBFFFFFFF,0xBFFFFFFF,
0x55555555,0x55555555,0x55555555,0x95555555,0x55555555,0x55556555,0x59596595,0x99655595,
0x00460105,0x40161105,0x40160455,0x44650459,0x44404404,0x44404404,0x44404411,0x10404411,
0xAA95AAA5,0xA954AA54,0x6554A554,0x55559544,0x555A455A,0x51564556,0x55551516,0x54554545,
0x11115555,0x51114555,0x51115155,0x55445515,0x55555554,0x55555555,0x55555555,0x55565555,
0x45555455,0x55554555,0x55555555,0x55555555,0x11441114,0x11445115,0x45451455,0x51554555,
0x11111111,0x11114444,0x44441111,0x11141111,0x44000041,0x44000044,0x44100041,0x44410001,
0x00444400,0x04444000,0x11044000,0x41000010,0x04044040,0x04440000,0x04444000,0x01041000,
0x00044110,0x41000410,0x10400004,0x10010104,0x00004440,0x00104441,0x00414400,0x40111000,
0x10400404,0x10400104,0x40410404,0x41040410,0x41010410,0x11114010,0x41100401,0x44041041,
0x9AA4AAA4,0xAAA4A6A4,0xE9A9A9B9,0xFA6DEA69,0xEFFEFEFA,0xEFFFFEEE,0xFEFFFFEE,0xFFFFEFEE,
0xEFFBFFBF,0xFFFFFFEF,0xFFFEFBFF,0xFFFFBFBF,0x1FFF1FFF,0x1BFF1BFB,0x07FF47FF,0x02FF16FF,
0x44100144,0x44440041,0x11040010,0x44040041,0x54440000,0x54100100,0x51104041,0x51101101,
0x55115551,0x55445455,0x95455554,0xA5519551,0xFA55FA55,0xFA66FA55,0xFA9AFA66,0xFE6AFAAA,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFBFFF,0xFFFFFEFF,0xFFEFBFFF,0xFFFFFBFF,0xFFFFFFFF,0xEFFFFFEF,
0xFEFFFFFF,0xFFFFFFFF,0xFFFFFFFB,0xFFFFFFFF,0xBFFFBFFF,0xBFFFFFFF,0xBFFFFFFF,0xBFFFFFFF,
0x55555555,0x65965659,0x56559559,0x95599966,0x59555555,0x99995555,0x96656659,0x66656599,
0x99565595,0x65955999,0x66669999,0xA99A6665,0x41591195,0x59961A65,0x9A6A9999,0x999969A6,
0x44444104,0x11041040,0x55590015,0xAAAA56AA,0x11445510,0x45115451,0x11515104,0x45555445,
0x51454555,0x51454514,0xA1454514,0xA955A554,0x56445515,0x66656594,0x666A6665,0x666A6A99,
0x55955555,0x55565655,0x59966599,0x66666666,0x55555555,0x55555555,0x55555656,0x56566666,
0x44554445,0x55551151,0x55555555,0x55555555,0x41040004,0x40040411,0x10450155,0x55554555,
0x40040410,0x40100400,0x40400101,0x00050400,0x11040000,0x04100000,0x00041000,0x00411100,
0x10040100,0x10110100,0x00414000,0x00041100,0x40010440,0x40000444,0x40000444,0x40010444,
0x04101040,0x01101001,0x41104401,0x41040410,0x44114110,0x50044441,0x44045110,0x91104044,
0xFE9AEA9A,0xFEA6FAE6,0xEFA9FEB9,0xFBEABFAB,0xFBFFFFEE,0xFFEFBFFE,0xFFBFFBFE,0xFBFBFFFF,
0xFBFFFFFB,0xFFEFFFFF,0xFFFEBFFF,0xFFFFFFFF,0x01BF45FF,0x017F11BF,0x406F117F,0x401F046F,
0x04040044,0x11044041,0x01004011,0x11004011,0x51101101,0x54441104,0x44441100,0x14445110,
0xA551A955,0xE951A955,0xBA55BA55,0xFA55EE95,0xFEAAFAAA,0xFEAAFAAB,0xFEABFAAB,0xFEAEFEAE,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFEFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFEFEFF,0xEFFFFFFF,0xFFBFFFFF,
0xFFFFEFFF,0xFFFFFFBE,0xFBFBFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFEFFFF,0xFFFFFFBF,
0xBFFFFFFF,0xBFFFFFFF,0xBFFFFFFF,0xBFFFFFFF,0xA5995A66,0x999AA999,0xA66A9AA6,0x59AAAA66,
0x9A669999,0x66999999,0xA6996A6A,0x669AAA69,0x66996669,0x9A669999,0xAA9A9A66,0xAAA6A9AA,
0xA6A6699A,0xA6996A6A,0xAAA9AA66,0xAAAAAAAA,0x9AA9A996,0xAAAAAAAA,0xAAA9AAAA,0xAAAAAAAA,
0xAAAA556A,0x9AAAAAA6,0x6AAAA9AA,0xAAAAAAAA,0xAAAA9A95,0xAA6699AA,0x6A9A99AA,0x6A6AA6A9,
0x9AA969A6,0x9999999A,0x599A9999,0x699A6669,0x59996666,0x65996666,0x69965659,0x999A5665,
0x59566599,0x595665A6,0x69669595,0x99995555,0x55665555,0x65965656,0x55655555,0x59595555,
0x55555555,0x55595555,0x55555955,0x55595555,0x54555555,0x55551555,0x55555555,0x55555555,
0x45550455,0x55551555,0x55555545,0x55555555,0x04004004,0x04151045,0x55554555,0x55555555,
0x04041040,0x00041040,0x00111100,0x45550455,0x00114440,0x00111100,0x40114440,0x40040440,
0x41044410,0x10114441,0x44444100,0x44441040,0x54109104,0x94449044,0x94109104,0xE444D444,
0xFBFEBFBA,0xEEFEFFBA,0xFEEFBFEE,0xFEEFEFFE,0xFFFFFFEF,0xFFFFFBFB,0xFFFFFFBF,0xFEFFFFFB,
0xFFFFFFFF,0xFFFBFBFF,0xFFFFFFFF,0xFFFFFFFF,0x401B045F,0x1017044B,0x10060106,0x10410105,
0x01004011,0x41001011,0x41000411,0x11000011,0x55445110,0x55444441,0x55515110,0x55145511,
0xFF95EE95,0xFFA5EEA5,0xFFE9FBA9,0xBFF9FFA9,0xFFAEFEAB,0xFFAEFEAB,0xFFEAFEAF,0xFFEBFEAF,
0x659A6A99,0xAAAAAAA9,0xAAA6A9AA,0xAAAAA6AA,0x9A9AA9A6,0xAAAA6AA9,0xAAAAAAAA,0xAAAAAA69,
0xAAAAAAAA,0xAAAAAAAA,0xAAAABAAA,0xAAAAABBA,0xAAAAAAAA,0xAAAAAAAA,0xAAABAAAA,0xAEAAAAAA,
0xAAAAA6AA,0xAAAAAAAA,0xAAAAAAAA,0xAAAEAAAA,0xA9AAAAAA,0xA6AAAAAA,0xAAAA9AA9,0xAAAAAAAA,
0x99999AAA,0xA9AA9A9A,0x99AA9A99,0x6AAAAAAA,0x96656666,0x96696966,0x9965669A,0x6AAA9A9A,
0x66659556,0x55959659,0x69999566,0x666A9999,0x65999595,0x55559655,0x95995959,0x96596666,
0x65655595,0x59555596,0x59559599,0x665995A6,0x55555555,0x55555555,0x55555665,0x95955959,
0x55555555,0x96555555,0x66555965,0xA6656666,0x00554405,0x56555555,0xA6665666,0xAAA9AAA6,
0x44440410,0x10454100,0x6A6A4555,0xEFAAEAAA,0xF504A511,0xFD44B844,0xFBFAAE40,0xBEEEBBAE,
0xEFBFBFBB,0xEFFFFEFB,0xBBBBBEEE,0xBFBBEEFB,0xFFFFEFFB,0xFFFBFFBF,0xFEFBEFFF,0xFEFFBFEF,
0x7FFFFFFB,0x6FFF7FFF,0x1FFF6FFB,0x1BFB5FBF,0x10010104,0x10000110,0x10000110,0x10000110,
0x41001011,0x41000411,0x41010410,0x11014410,0x55445551,0x95519514,0x95549511,0xA555A544,
0xFFFAFFBA,0xBFFAFFEE,0xBFFFFFFE,0xAFFFFFFA,0xFFFAFFAA,0xFFFAFFAB,0xFFFAFFEB,0xFFEEFFEE,
0x00000000,0x00C000C0,0x03000300,0xCC000300,0x00000000,0x30CCF0CC,0x30C330C3,0x30C0F0C3,
0x00000000,0x0300F0FF,0x03000300,0x030000FF,0x00000000,0x300C33FF,0x300C300C,0x300C300C,
0x00000000,0x03000300,0x03000300,0xC300C300,0x00000000,0x300C300C,0x30333033,0x30C030C0,
0x00000000,0x30030FFF,0x30033003,0x30030FFF,0x00000000,0xC0033FFC,0xC003C003,0xC003C003,
0x00000000,0xC00CC00C,0x0CC03030,0x03000300,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xEAAAAAAA,
0xAAAAAAAA,0xEAAAAAAA,0xAAAAAABA,0xAAEAAEAA,0xBAAAAAAA,0xAAAAAAEA,0xAAAABAAA,0xBAAAAAEB,
0xAABBEAAA,0xAAAABAAA,0xBAEEAAAA,0xAAAAAAAA,0xBAAAAAAA,0xAAAAAABA,0xAAEAAAAA,0xAAAAABAA,
0xAAAAAAAA,0xAAABAAAA,0xAAAAAAEA,0xAAAAAAAA,0x6A6AA6AA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,
0x666AA666,0x9AAAA9AA,0xAAAAAAAA,0x9A6AAAAA,0x66666699,0xA9AA9A69,0xA6A69A9A,0x6A669AAA,
0x59666666,0x66699999,0xA6699A9A,0x999A66A6,0x65A65655,0x65995659,0x99A5599A,0x9999666A,
0x56565959,0x59555565,0x55596566,0x96969966,0x55555555,0x59565559,0x55596555,0x96656595,
0x55555555,0x56669955,0x55966595,0x65959959,0x96595955,0x66556565,0x66656666,0x99996659,
0xAAA69999,0x9A6AA999,0xAA66A9A6,0x9AA9AAA6,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xABAAEAAA,
0xEBAABAAE,0xBEEAAAAA,0xBBAEEAAA,0xBBAEEABA,0xEFEEBBAE,0xFFBBEEBA,0xBBEEEBBA,0xEEEFFBAE,
0xEEEEFFEE,0xFBBFBFFB,0xBBFFBEEA,0xBEFEFBEE,0xFFFBBBEE,0xFFFBBBBF,0xFFBBBEFF,0xFFEFEFFF,
0x07FB0BBF,0x02EF16FF,0x01FB42FF,0x017E44FF,0x10010110,0x10040110,0x04040040,0x01001010,
0x14004044,0x51004111,0x51100411,0x45105101,0xE555A944,0xE955B954,0xFA55FA51,0xFE95FA94,
0xAFFFBFFF,0xAFFFBBFF,0xBBFFEBFF,0xEBFFEEFF,0xFFFEFFFB,0xFFFBFFFB,0xFFFFFBFE,0xFFFEFFFE,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFE,0xFFFFFFFF,0x3000CC00,0x00003000,0x00000000,0x00000000,
0x30C030C0,0x000030C0,0x00000000,0x00000000,0x03000300,0x00000300,0x00000000,0x00000000,
0x300C300C,0x0000C00C,0x00000000,0x00000000,0x3300C300,0x000030FF,0x00000000,0x00000000,
0x330030FF,0x0000F300,0x00000000,0x00000000,0x00000000,0x000000FF,0x00000000,0x00000000,
0x30033003,0x00000FFF,0x00000000,0x00000000,0xC003C003,0x00003FFC,0x00000000,0x00000000,
0xAAAAAAAA,0xEBAAAABA,0xAEAEAAAA,0xBAAAAAAA,0xAAAAAAAA,0xBBAAAAAE,0xAAAEAAAA,0xBABAEBAA,
0xAAAAAAAA,0xAAABAAAA,0xAABAABAA,0xAAAABAAA,0xAAAAAAAA,0xABABABAA,0xAABABAAA,0xAAEABAAA,
0xAAAAAAAA,0xABAAAAAA,0xAAAAAAAA,0xBAABEAEE,0xAAAAAAAA,0xAAAAAAAA,0xAAAEAAAA,0xAAEAEBAA,
0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xABAAAAAA,0xAAAAA6AA,0xAA6A6AAA,0xAAAAAAAA,0xAAAAAAAA,
0xA6A66A6A,0x666AAAAA,0x9AAAAAAA,0xAAAAAAAA,0x9AA6999A,0xA6666A6A,0x69A6669A,0xAAAAAAAA,
0x59999999,0x65999966,0x66669A6A,0x699966AA,0x66665959,0x66599599,0xA6565565,0x9666599A,
0x55599666,0x65999955,0x55655656,0x99966659,0x66669995,0x69A66659,0x66A6A659,0x6669A995,
0xAAAAAAAA,0xAAAAAA66,0xAAAAAA99,0xAAAAAAAA,0xEAAAAEAA,0xEAAAAAAA,0xABAAAAAA,0xAAAABAAA,
0xAAAEBBAA,0xEBAABBBA,0xEBAAAEBB,0xBBAABABB,0xEFBBEEFA,0xEEEEBBBB,0xEEEFFBBA,0xFFBBEEEE,
0xBBFBFFAE,0xEFFEFEEF,0xEFBEFEEF,0xEEFEFFEF,0xFFBFEEFE,0xFBEEBFFF,0xEFBEFFFF,0xBEFBFFFF,
0x106F407F,0x102F012F,0x101B012F,0x10070117,0x00401004,0x01014404,0x04111000,0x04004040,
0x51041441,0x55144440,0x55444441,0x55445110,0xFF95FE95,0xFFA5FEA5,0xFFE9FFE5,0xFFE9FFB9,
0xEEFFBAFF,0xEEBFBBBF,0xFEEFFBBF,0xFBEFEEAF,0xFFFFFFFF,0xFFFFFFFF,0xBFFFFFBF,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFBFFFFF,0xFFFFFFFF,0x00000000,0x03F00000,0xC00CCC0C,0xCC0CC00C,
0x00000000,0xCC3F0000,0x0CC03CC0,0x0CC00CC0,0x03000000,0xCF0F0300,0xC330C330,0xC330C330,
0x00000000,0x3F0F0000,0xC0C0C0C0,0xC0C0C0C0,0x030C030C,0x030C030C,0xC30CC30C,0xC30CC30C,
0x00000000,0xFC3F0000,0x0CFF0CC0,0x0CC00C00,0xABAAAABA,0xAAAAAEAE,0xAEBAAAAA,0xAAEEEAAA,
0xAEEAAAAB,0xEBBAAAAB,0xAAAAAEAA,0xEBAAAEBA,0xEAAAABAE,0xAABAABAB,0xABABAEAA,0xABAAEABA,
0xAAAAAAAA,0xAEABAABA,0xAABAEAAA,0xABBAAEAA,0xAAAAAAAA,0xBABAAAEA,0xEAAAABAA,0xAEAAAABB,
0xBAAEAAAA,0xABAAAAAA,0xAAEABAAE,0xABAAEAAE,0xEAAAAAEA,0xABAAAEAE,0xAEBAAAAB,0xAAAAAAAA,
0xEABAAAAA,0xAAABAAAA,0xAAAABBAA,0xAAEAAABB,0xABAEAAAA,0xBAEAAAAA,0xAAAEAAAA,0xAEAAAAAA,
0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAEAAAAAE,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAE,0xAAAAAAAA,
0xAAAAAAAA,0xAAAAA6AA,0xAAAAAAAA,0xAAAAAAAA,0x6AAAA6AA,0x6AAAA66A,0xA6AAAAAA,0xAAAAAA6A,
0x5A6AA999,0x666A99A6,0x66AAAA66,0x66AAAA69,0x9A666599,0x9A666599,0x9A9A6599,0x66A6A669,
0xAAA9AA66,0xA6A99A5A,0xA6AAAA66,0xAAAAAA69,0xAAAAAAA6,0xAAAAAAAA,0xAAA9AAAA,0xAAAAEAAA,
0xBAAAEBAA,0xBBAAAABA,0xEBAEAABA,0xEEEFBAAA,0xEEEEEEBA,0xEEBBEEEB,0xEEFABBAB,0xBEFFBBAE,
0xEFBEBBEE,0xEEEEBEFB,0xFBBEBFEF,0xBFFBBBBB,0xEEFBFFEF,0xEEFFFFEF,0xFBFFBFBB,0xBBFFFFBB,
0xFBFEFFEF,0xFEFBFFFF,0xBFEFBFFF,0x6FFF7EFF,0x10060117,0x10410112,0x10100105,0x10440101,
0x01001011,0x44411004,0x11040000,0x11004010,0x54515111,0x94445544,0x94519544,0xA551A544,
0xFFFAFFFA,0xBFFEFFFA,0xBFFFFFFE,0xAFFFBFFE,0xFEEEFEEB,0xFFFAFFBB,0xFFEEFEEE,0xFFEFFFFB,
0xFFFFFFFF,0xFFFEFFFF,0xFFFFFFFF,0xFFFFFEFF,0xBFFFFFFF,0xBFFFFFFF,0xBFFFBFFF,0xBFFFFFFF,
0x000003F0,0x00000000,0x00000000,0x00000000,0x00000C3F,0x00000000,0x00000000,0x00000000,
0x0000CC30,0x00000000,0x00000000,0x00000000,0x00003F00,0x00000000,0x00000000,0x00000000,
0x0000030C,0x00000000,0x00000000,0x00000000,0xAAAEAEAA,0xAAAABBAA,0xAEAABAEE,0xBAEEAAAA,
0xAAABAABA,0xAAEBBBAA,0xEAAAAEAA,0xABAAAABB,0xAAEABAAE,0xAABAEBAB,0xAAAAEEEA,0xAAAABBBB,
0xBAEAAAAB,0xABAEAAAA,0xAAAEEEBA,0xAABABBAB,0xBAABAAEE,0xAAAAAAEA,0xEAEAAEAE,0xAEBAAAAB,
0xAABABAAB,0xABAAAEAB,0xEABAAAAA,0xAAABABAA,0xEAAAAEEE,0xAAEAAEAB,0xEAAAAAAA,0xEAAAAEEE,
0xABAABAAE,0xABAABABB,0xAAAABAAA,0xEBAAAABA,0xABABAAAA,0xAAEBAAAA,0xAAAEAAAA,0xAAAAEBAA,
0xABAAAAAA,0xEABAAAAA,0xAAAAAAAA,0xAABAAAEA,0xAAAAAABA,0xAAAAAAAA,0xEAAAABAA,0xAAAAAAAE,
0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAEAAAAEA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAEAAAA,
0x9A6AAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAA6AA6A,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,
0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xEAAAAAAB,0xEAAAAEAA,0xAAAEAAAA,0xAAAAEEAA,0xEAAAAEEA,
0xBEEAAABA,0xBAEEEBBB,0xBAEABBAE,0xEEEBEBAE,0xBEBFFBEA,0xBFBBEEEE,0xBEEEFBBB,0xEEEEFBBA,
0xBFEFFBBF,0xFFFFFFFF,0xFFFFFBFB,0xFFABBBFE,0xFFEFFFBF,0xFEFEEFFF,0xBEFBFFFF,0xFBFFFFEF,
0x2FFF3FBB,0x1FBF2FFE,0x1FFF5BFF,0x5BFF1FEF,0x41010011,0x01010411,0x11040014,0x44440041,
0x10401104,0x44404404,0x44404004,0x44101104,0xE951E511,0xF554A954,0xE944E944,0xA514A951,
0xEBFFBBFF,0xBAFFEBFF,0xEEAFFBBF,0xFBABBBBF,0xFFFEFFFB,0xFFFFFFFB,0xFBFFFFFE,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFBFFFFF,0xFFFFBFFF,0xBFFFBFFF,0xBFFFFFFF,0xBFFFFFFF,
0xEAEAAAAA,0xAEEAAEAE,0xBAEAEBAE,0xABAAEAAE,0xAEAEBABA,0xAEEEBAAA,0xAEEEBAAA,0xAAEEBAAA,
0xAABBEEEA,0xBAEBAEAE,0xBAEBABAE,0xEEBBAAAA,0xAEAABAEA,0xAAEAEAAE,0xAABABBAB,0xAAEABBAB,
0xABBABAAB,0xAEEEEAAA,0xEBABBABA,0xAEABBAEE,0xAEAEEAEA,0xEEAEAAEA,0xEEAEAAEA,0xEEBBAAEA,
0xABAAAEBA,0xAEEAEAAE,0xAEEAEAAE,0xAEEAEAAE,0xAAAAAEAE,0xAAEAEBAE,0xEAAABBAE,0xEEABAEEE,
0xAAAEEAEA,0xBAEAABAA,0xAAAAEAAE,0xAAEABBAE,0xABAABAAA,0xAAAAAAAE,0xBABAEAAA,0xAAABAAEA,
0xAAAAAEAA,0xBAAAAAEB,0xABAAAABA,0xABAABABA,0xAAABBABA,0xABBAAEAA,0xBAAAAAAB,0xAAABEAEE,
0xAAAAABAA,0xAAEAAAAE,0xAAAABAAA,0xEEAAAABA,0xAAAAAAAA,0xAAAAAAAA,0xABAEAAAA,0xAAAAAAAA,
0xAAAAAAEA,0xAABBAEAA,0xBAAAABAA,0xAABAEAAA,0xAEAABAEB,0xEEBBAAEA,0xAEEEBAAA,0xAEEEEAAA,
0xBBABEAEE,0xFBAEAEBA,0xEEBBAEEA,0xEEEBBBBA,0xEEEEBEEE,0xEEEEBBBB,0xFBBEBBBB,0xBEEEEFBB,
0xFFFEEEFF,0xFFFBEEEF,0xFFFEEEEF,0xFFFFBBBB,0xFFBFFFFE,0xFEFEBFFB,0xFFEFFFFF,0xFFFBBEFF,
0x2FBF1FFE,0x7FFB6FFF,0xFFFFBFFF,0xFFEFFFFF,0x11110011,0x10441104,0x11114114,0x444B1143,
0x44111040,0x41111100,0x44414444,0x44441111,0x95449551,0x55145451,0x95449444,0x95159551,
0xEFEABEAA,0xFEEEFBBA,0xFFBAFEEE,0xFFEEFFBA,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFBFBFFF,
0x00000000,0x00000000,0x80000000,0x80008000,0x00000000,0x00000000,0x00020000,0x00000000,
0x00000000,0x00000000,0x02000000,0x02000200,0x00000000,0x00000000,0x00000000,0x00080008,
0x00000000,0x00000000,0xA0000000,0x00000800,0x00000000,0x00000000,0x2A020000,0x80888088,
0x00000000,0x00000000,0xA8800000,0x008000A8,0x00000000,0x00000000,0xA00A0000,0x80028008,
0xABBABAAB,0xABBABAAB,0xABAEEEAA,0xABAAEEBA,0xEAEBEEAA,0xEAEAAEAE,0xABBABAAE,0xBAEAEEAE,
0xAEAEAAEA,0xAEEEBAEA,0xBBBBAAAA,0xEEEBAABA,0xABABBAAA,0xAEABBABA,0xAEAAEAEE,0xAEEAEAEE,
0xAEABBAEE,0xEEAEAAEA,0xAEAEAAEA,0xAEAEBAEA,0xBBBBAAAA,0xBBAAAABA,0xEBAAAABB,0xEAAAAEBB,
0xAAABBBAA,0xAAEBBBAE,0xAEEEBAAA,0xBAEEABAA,0xEEABAAEE,0xEEBBAAEA,0xBAEBABAA,0xBAABABAE,
0xBAEAEBAE,0xEEEAAAAE,0xBAEBAAAE,0xBABBEBAA,0xAAAABBBA,0xAAAABAEE,0xAAAAEEEB,0xBAAAEBBA,
0xABAABABB,0xABAABABB,0xEEAEAABA,0xAEAEAAEA,0xAABBBBAA,0xABBABAAA,0xAEEAEAAB,0xAAEAEAAE,
0xAAEBAAAE,0xAAEAEEAE,0xAAAEEEAA,0xAABAEBAA,0xAEAEAAAA,0xBAAEEAEA,0xEABAABAA,0xBAAEABAA,
0xAEBAAAAB,0xEEAEAAEA,0xEEEEAAAA,0xEEEEAAAA,0xAAAAEAEB,0xBBEEEAAA,0xFAAEABAA,0xBAAEABBA,
0xAEEEFAAA,0xBBAAAABA,0xBAEEEEBA,0xEAEBEFBB,0xBBEEEEBA,0xBBBBEEBB,0xBBBBFBBA,0xFBEEFEEE,
0xFBEFEEEE,0xFFEBEEFE,0xEEEFFEFE,0xFFEFFBFE,0xFFFBEEEE,0xFFFFEEFF,0xBBBEFFFE,0xEFEFFFFF,
0xFFBEFBFF,0xFEFFFFFF,0xFBFFFFEF,0xEFBFFFFB,0xFFFEFBFF,0xFBFFFFBF,0xFEFEFFFB,0xFFEFEFFF,
0x10BF142F,0x1BFE07FF,0xFFFEFFFF,0xFFFBFEFF,0x51111111,0x45501445,0x15AF5005,0xFFFFFFFF,
0xA554A551,0x9A55A955,0xFE55E955,0xFFFFFFFE,0xFFFBFFEA,0xFFFFFFFE,0xFBFFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFEFFFFF,0xFFFFFFFF,0x80008000,0x80008000,0x80008000,0x80008000,
0x0800A800,0x08000800,0xA8000800,0x08020800,0x0A20A20A,0x02200220,0x020A0220,0x00000000,
0x80882A02,0x80888088,0x2A088088,0x00000000,0x0208A828,0x02080208,0xA8200208,0x00000000,
0x00020000,0x20028002,0xA8000802,0x00000000,0x80828088,0x80808080,0x2A0A8080,0x00000000,
0x80800080,0x20808080,0x20802080,0x00000000,0x80008002,0x80008000,0x80008000,0xA0008000,
0xAEEAEABB,0xBAEAEAAE,0xAAAAEBAE,0xAAAABBBB,0xBAEAABAE,0xBAEAEBAE,0xEEEAAAAE,0xAEAAAABB,
0xAAEAAEAE,0xAEEABAAE,0xBBAAAABB,0xAAAAAABB,0xBBAAEABB,0xBBBAEABB,0xBBBAAAAB,0xEAAAABAB,
0xAAEABAEE,0xEBBAAEAE,0xEBAAAEBB,0xABAAAEBB,0xEAEBAEEE,0xEAEABBAE,0xEBAAAEBB,0xAAABEEBA,
0xBAEEABAA,0xBAEEEBAA,0xBAEEABAA,0xEAEEAEAA,0xBAABABBA,0xBBAEABBA,0xEEBAAAEB,0xAEBAAAEB,
0xAABBBBEA,0xAAEEBBAB,0xABBAEEEB,0xABBABAAB,0xBBABABBB,0xBBABAABA,0xBBBBAAAA,0xAEABEABA,
0xEEBBAAEA,0xBAEBABAE,0xEABBABAA,0xAAAABAEE,0xBBBAAAAB,0xEEEAAAAB,0xEEEEAAAA,0xEBBAAAAA,
0xABBBAEAA,0xBBBAEAAB,0xEEBAAAEB,0xAAEAAEAE,0xAAAEEAEA,0xABAAEEBA,0xEAEAEEBB,0xEBAAAEBB,
0xEEEEEAAA,0xEAEEAEAA,0xEBAEEEBA,0xBABAAEEB,0xEBAEBBBA,0xBBAEAEBA,0xBAEEAEBA,0xEABAAEEB,
0xEEBABBAE,0xEFBBBAEB,0xEEEBBBBB,0xEEAABBBB,0xFBAEAFBA,0xFEEEEAEE,0xFBEEEBBB,0xEBBABEEF,
0xFBEEBFBE,0xFFEEBBBB,0xFEFBBBBE,0xEEEEBBEF,0xFFBFBEFB,0xBFBFFBFB,0xBFBFFBFB,0xEFFBFEFB,
0xFEFFFFFB,0xFFBFEFFB,0xEEFFFFFB,0xEEFEFFEF,0xEFFFFEFE,0xFBFEFFEF,0xFFBBFFFF,0xFBBEFFFF,
0xFFBFFFFF,0xFBFFBFFB,0xFFFFFFBE,0xEFEFFFFE,0xFFFFFFFF,0xFFFFFFFF,0xBFFBFEFF,0xFFFFFFFF,
0xFFFFFFFF,0xFFBFEFFF,0xBFFFFFFF,0xFEFFFFFF,0xFFFFFFFB,0xFFFFFFBF,0xFFFFEFFF,0xFFFEFFBF,
0xFFFFFFFF,0xFFFFEFFB,0xFEFFFFFF,0xBFFFFFFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFB,0xEFBFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFEFEF,0xBEFBFFFF,0xFFFFFFFF,0xFFBFFFFF,0xFFFFFFFF,0xFEFBFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xBFEFFEFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFBEFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFEFBFFFF,0xBFFFFFFF,0xBFFFFFFF,0xBFFFFFFF,0xBEFBFFFF,
0xAAAAAAAA,0xAAAAAAAA,0xAEAAAAAA,0xEAEAAAAA,0xAAAAAAAA,0xAAAABAEE,0xBAABABAA,0xAEAAAAEA,
0xEEEBAAAA,0xBAEAAAAE,0xBAAAABAB,0xBAAAABBB,0xEEEEAAAA,0xBBBBEAAA,0xAEBBEAEA,0xABBBBAAA,
0xEEEEAAAA,0xAEEEBAAA,0xEBAABAEE,0xEBAEAEBB,0xEEEEAAAA,0xEAEBBBAE,0xEBAEAEBA,0xEBAEAEBA,
0xEEEEAAAA,0xEBBAAEAE,0xAEBABAEB,0xAEBAEAEB,0xEEEEAAAA,0xEEBAAAEB,0xBAAEAEEB,0x56EBAFBA,
0xEEEEAAAA,0xEEEEAAAA,0xEEBBABAB,0xAA65AAAA,0xBAAEAAAA,0xBAEEABAA,0xEAEEAEAA,0xAAAABBBB,
0xBAEAAAAA,0xBAABABAE,0xBAAEEBBA,0xBABBABAA,0xBABBAAAA,0xAAAEEBAA,0xAEAEBAEA,0xEEABAAEA,
0xAAAEAAAA,0xAABABBAA,0xBBBAAAAB,0xBBBAAAAB,0xABAAAAAA,0xAAAABABB,0xEAABAEEA,0xABABAEBA,
0xBAABAAAA,0xAAABEBBA,0xAABABAEA,0xAAEABAAB,0xBAAAAAAA,0xAAAEEBBA,0xAAEBEEAA,0xAAAEEBAA,
0xAEEEAAAA,0xAAEEBAAA,0xAAEEBBAA,0xEBAEAEAA,0xBAEBAAAA,0xEABBEBAA,0xEABBAEAA,0xABBAAEAA,
0xAEEEAAAA,0xEEEEEAAA,0xBAEAABAE,0xBAABABAE,0xAEAEAAAA,0xAEAEEAEA,0xAEBBBAEA,0xAEABBAEA,
0xAEAEAAAA,0xAEAEEAEA,0xEABABBEB,0xEBAEAEEB,0xAAAEAAAA,0xAABBEEEA,0xBAEABBAE,0xEAEEBBAE,
0xAAAEAAAA,0xAAAABBBA,0xEAABBBBB,0xEAAEAEFE,0xAAAAAAAA,0xAEABBAEE,0xAEEABAEE,0xAEEAEAAE,
0xAAAAAAAA,0xAAAABBBB,0xABAEEEFB,0xABAAEEBA,0xAAAAAAAA,0xAEAAAAEB,0xAEEAEAEE,0xAEEBEAAE,
0xAAAAAAAA,0xAAAAAAAA,0xBAEAABAE,0xEEEEAAAE,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xEBAAAEBB,
0xAAAAA6AA,0x6AAAAAAA,0xAAAAAAAA,0xAAEAAAAB,0x9AAA9599,0x9A9A69A9,0xAAAA99AA,0xAAAAAAAA,
0x59995555,0x65995666,0x66999A6A,0x9AAA9A6A,0x55555555,0x55555566,0x55665599,0x55996659,
0x55555555,0x55555155,0x55555555,0x55555555,0xAAAAAEAA,0xABAABABA,0xBAEAAAAE,0xBABAABAB,
0xAAAABAEE,0xAAAABBBB,0xABAABBBB,0xABBABABB,0xBAAAABBB,0xBAEAABBB,0xEAEAAEAF,0xEBAAAEBB,
0xAAEBEEAA,0xAEEBBAAE,0xAAEABAAE,0xAAEABBAE,0xABABEEBA,0xABABEEBA,0xABABEEBA,0xEAABEEBA,
0xEBAEAEBA,0xEBABAEBA,0xEBAEAEBA,0xBAEEAEBA,0xAABABAEB,0xABBAEEAB,0xBBBAEEAB,0xEEEEEAAB,
0x556A95AE,0xA95AA55E,0xAA56BA56,0xEA55AE96,0x566AA555,0xABBBAAAA,0xAAEBEEAA,0xAAEABAAE,
0xAA95AAAA,0x6AAA955A,0xAAAAAABA,0x5AAAAAAE,0xAAAAABAA,0xAAA5AAAA,0x556A556A,0x55A95555,
0xEEAAAAEE,0x5AAA5AAA,0x5551A995,0x55555555,0x656AABBA,0x11155555,0x55555565,0x55554515,
0x5555EAEE,0x55514515,0x95555555,0x44445555,0xAA95EEAE,0x04455114,0xABAA5599,0x4444A555,
0xEEAABBBA,0x4444A555,0x55961115,0xAAA5AAAA,0xEAAEAEBA,0xBA55AEEA,0x00055440,0x0AAA4169,
0xEBAABABA,0x0504AA56,0x14444040,0x10440100,0xEEAAABBA,0xEEE5AAEE,0xE504BA90,0x01105011,
0xAEAEEAEE,0xAEBEAAEB,0xAAEEBAAA,0xABA5EEBA,0xAEEABABA,0xABBABAAB,0xAEBABAAB,0xFEABAAEA,
0xEBEFBBAA,0xABBBBABB,0xAABBEEAA,0xEABAAEEA,0xEABAAEEA,0xEAAAAEEB,0xEABAAEEE,0xAAEAAEAB,
0xAAAAEAAE,0xAEAEAAEA,0xAEAFEAEA,0xAEEAEAEE,0xBABAAAAA,0xAAEAEAAB,0xAAEABAAE,0xEAEAAEAE,
0xBBBAEAAA,0xAEAAEAAA,0xEEAAAAEB,0xEEBAAAEB,0xBBAEAAAA,0xEAEAAAAA,0xAAAAAAAB,0xBAEAEBBE,
0xAEEAAAAE,0xABAAEAAE,0xAAAEBAAA,0xBAAEABAA,0xAEEAAAAE,0xAABAAAAA,0xAAAAABAB,0xEAABAEBA,
0xAAABAAAA,0xAAAAAAAA,0xAAABAAAA,0xAAAAAAAA,0x9AAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,
0x96696666,0x69AA9AA6,0x9A6AAAAA,0xAAAA69AA,0x55595555,0x559A5565,0x966A6999,0x9A6699A6,
0x55555555,0x55555555,0x55555555,0x55595555,0xBAAEABAA,0xAEAAEAEA,0xAEAAEAEE,0xAEAABAEE,
0xABBAEEAB,0xABAEBABA,0xBAEEBBAA,0xEEBAABAB,0xAEABBAEE,0xBAABEBBA,0xBAABEBBA,0xBBAEABBA,
0xAAEBEEAE,0xABAEEEBA,0xAEAEBAEA,0xAEBABAEB,0xAAAEBBBA,0xABAAEEBA,0xBBAAEABB,0xBBAAAABB,
0xBAEFEBAA,0xBAEEEBAA,0xBAEAEBAE,0xAEEBEAAE,0xEEEEAAAA,0xEEAEAAEA,0xEEAEAAEA,0xBAAEABBA,
0xAA56AE92,0xAA56AE95,0xA986AA96,0x565A5A5A,0xAAABABAA,0xA5AA5AAA,0x99A5AA56,0xEEA6A999,
0xAA95956A,0xEAAAAAAA,0xEBBABEAA,0xEBBBBEEE,0xAAA6A99A,0xBBBEEEEA,0xEBAEBBBB,0xEBAEBBBB,
0xAAAEAAAA,0xEBBAEEEE,0xEAEAAEBB,0xEBAEBBBB,0xAEAA66AA,0xBBAAEAEE,0xBBAEAABA,0xBBAEAABA,
0x6AAA5556,0xEAAEAEEE,0xEABAAEEB,0xAEBABBBB,0x05551045,0xAABA5AAB,0xAAAEAAAA,0xAAABAAEA,
0x50119540,0x51150101,0x55564555,0x5656155A,0x165516AA,0x11455555,0x44554514,0x15554555,
0x00444400,0x00111100,0x10441104,0x10410104,0x04111104,0x91014110,0x54015010,0x14015044,
0xB959BA90,0x9415B51A,0x55105441,0x55444910,0xBABBEBBB,0xAABBBBAA,0xAAB9AEEA,0xAAA5EEE9,
0xEAAAAEEB,0xBAAAAEEF,0xBAAAABBB,0xAAEEEBAE,0xAAEAEEAE,0xBAEBEBAE,0xAEEAEAAE,0xBAEABAAE,
0xAEEAEAAE,0xBAEAEBAE,0xBAEAEBAE,0xEEEAFBAF,0xEAEEAEAE,0xEAEEBBAA,0xEEEBBBAE,0xEEEEAAEE,
0xBAEEABAA,0xBAEEABAA,0xAEBAEBAE,0xBAEAEBBB,0xAAEBEBAE,0xBAABABEE,0xAAAEAAEA,0xAAAEAEBA,
0xBABBABAA,0xAABABBAA,0xAAABBBAA,0xEAAAABAA,0xAAABABBA,0xBABAEAEA,0xAAABABAA,0xEEAAAAAA,
0xAEAAAABA,0xABAABAEE,0xABAAAEAE,0xEBAAAAAB,0xAAAAAAAA,0xAAAAAAAE,0xAAEAAAAB,0xAAAAAAAA,
0xAAAA6AAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0x9A9A69AA,0x99AAAAAA,0xAAAAAAAA,0xAAAAAAAA,
0x999A5666,0xA6AA9A69,0x6AA99A6A,0x6A9AA66A,0xAEAABAEE,0xAEAABAEE,0xAEEBBAEE,0xAEEAEAAE,
0xBAEBEBBB,0xBAEBEBAE,0xAEBBEBAE,0xBBBBBBBA,0xEEEEAABA,0xBBAEAABA,0xAEBBBBBA,0xBAEBBBBB,
0xAABABAEB,0xAABABBAB,0xABBBEEAB,0xEAEEEEEB,0xBBAAAABB,0xAEAAAABB,0xAAAAEAEE,0xAEAABAEE,
0xAAEABAAE,0xAABABBAB,0xAAAEEBAA,0xAAAAAEBA,0xAABAABAB,0x6AAAAAEB,0x56AA5AAA,0x596A55AA,
0x991A5956,0xA815D955,0x92959595,0x4BB897A5,0xEFAEBAEA,0xBBABBAFA,0xEEAEEBBE,0xBBBABAEA,
0xBBBBEEEE,0xEEEEBBBB,0xAEBAEBAE,0xEEEBBAEE,0xEEBBAEEE,0xAEEEBBBB,0xBAEBBBBA,0xBABAAFBB,
0xAFBABAEB,0xBBBBBBBB,0xBAEBAEBB,0xEAEBBBBB,0xAEBBBAEB,0xBBBAEAEB,0xBAEBEBBB,0xBAEEEBAE,
0xAAEEBAEB,0xEAEEBBAA,0xEAEEAEAA,0xBAEEAEAA,0xABABAABA,0xABABAABA,0xA5BA5AEE,0xAB95BA5B,
0x555A459A,0xA5659556,0xEBAABA6A,0xEEEAAEBA,0x55AA5555,0xAAAA56AA,0xABAAAABB,0xABAAAABB,
0x44110104,0x11550455,0x55AA1556,0x59AA5AAA,0x11040410,0x11011010,0x44450011,0x51551555,
0x50504140,0x05100141,0x55005441,0xAA555115,0xAE95BBA5,0x5684BB94,0x44100140,0x11071056,
0xAAEAEEBB,0xAAE9EEAF,0xEA50BFA4,0x5111E541,0xBAEAABAE,0xBBBAEAAE,0xEEBAABAB,0xEEAEAAEE,
0xEEEEEABB,0xBAEEEEAA,0xEEBAABAB,0xAEAEBAEB,0xEAEAAEAE,0xBBBAAEAE,0xEBBABAAB,0xEEEBAEBA,
0xAEBAEBAF,0xBBBBEAEB,0xEAEABBBB,0xEBBABEEF,0xAEAEEBBA,0xEEAEEAEA,0xEEBAAAEB,0xBAEEABAE,
0xBBAEAABA,0xABAEEAAA,0xABAAEABA,0xEAEBAEAE,0xAAAAAAAE,0xAAAAEBBA,0xEABAAEAA,0xBAEEABAA,
0xAAAAAAAA,0xAAAAABAE,0xAAAAAAEA,0xAEABAAAE,0xAAAAEAAA,0xAABBAAAA,0xAAEABAAA,0xBAEAAAAB,
0xAEAAAABA,0xAAEAAAAA,0xABAABAAE,0xAAEABAAE,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAB,0xAABBAAAA,
0x9A6AA6AA,0x69AAAAAA,0xAAAAA6AA,0xAAAA9AAA,0xAEAABAEE,0xAEEABAEE,0xBBBAEAAE,0xEBBAAEAB,
0xEBBBAEBA,0xBBAEBAEB,0xAEABEBBA,0xEBBABAEE,0xEEEEBBBB,0xEBAEBAEB,0xAEEBEEEE,0xEEBABAEE,
0xBBEEEEBB,0xBAEEEBAE,0xEBBBBBBA,0xBAEEBBAE,0xEEAEAAEE,0xEEBAAAEE,0xEAAEAEEB,0xEAEBBBBA,
0xABAAAAAE,0xAAAEAAAA,0xAAAEAAEA,0xAAEEABAA,0x1A5A559A,0x1A56159A,0x695A5966,0xA59A656A,
0x6FB92EE9,0xEFB5BAE9,0xEB94BAB4,0xAA11AE90,0xBBA5EEE9,0xBA52BB94,0x991EE94B,0x55EB54BE,
0xBBAEAEEE,0xBBBBEBBB,0xBBBBBAEE,0xEBE9EEBA,0xBAEBEFBB,0xBBBBAEEE,0xEEEEBAEB,0xBAEAABAE,
0xBBBBAEEE,0xEEEEEAEB,0xEBAEBABB,0xBBABAEBA,0xBAEEEBAB,0xBAEEAEAA,0x56AE5BBA,0x5556956B,
0x96BE5BAA,0xAA56A55B,0xEA99A9A5,0xFBBAAEA9,0xBAAAAAB9,0xBBAAEEEA,0xEEEBEEFE,0xEFEEBBBE,
0xBBBBAEEF,0xAEBBEEEE,0xBAEEBBEE,0xBBBBBBBB,0xABAEBABB,0xAEEBBABA,0xABAEBABB,0xBBBBBAEB,
0xAAABAAAA,0xAABBAAAA,0xAAABAAEE,0xABABAABA,0x55665555,0x559A5A6A,0x596A66AA,0x59AA56AA,
0xFA95EAA5,0xA655AA55,0x5555A555,0x54555545,0x41110452,0x41120442,0x440A0046,0x41014415,
0x55044504,0x10444411,0x10144111,0x44441144,0xBBB9EEF9,0xBED5EBB4,0xBF51EB91,0xED11EE51,
0xBBBBEEFA,0xBBBBBBAE,0xBBBBEEEE,0xEEEEEEEE,0xBBBBEEEE,0xEEEBBBBB,0xEFBBBAEE,0xFAEEEEEE,
0xBBBBEEEE,0xEEEEBBBB,0xEEEEBBBB,0xEEEEEEEE,0xBBBBEEEE,0xEEEEBBBB,0xEEEEBBBB,0xBEEEFBEE,
0xEEEBAEBA,0xEBAEBBBB,0xBBBEBBBB,0xBEFBEEEE,0xEBBABAAB,0xEEBABBBB,0xBBBBBBBB,0xBBBBEEEE,
0xAEAEEAEA,0xEBBABBBB,0xFBBBAEEF,0xBBBBAEEE,0xBBAEAAAA,0xEFAEAABA,0xBBBAAABB,0xABBBEEBB,
0xAAAABBAB,0xAAEABBAE,0xBAEBBBAE,0xEEBBEBBA,0xAAEBBBAA,0xEBAAAAAE,0xAAEAAEBB,0xABBAEEAE,
0xAAAAAAAA,0xAAAAAAAA,0xAAEAAAAE,0xEEEBAAAE,0xABBABAAB,0xAEEEBAAA,0xAAEABAAA,0xAAAAAEAA,
0xBBEBBAAE,0xEBABBABA,0xEAABAEEE,0xBAEAAAAA,0xBAEBAEEE,0xAEEEEEAE,0xBAEAEBAB,0xAAAAEAAA,
0xBBAEAEEB,0xAEEBBAEE,0xAEEEBABA,0xAEEEAAAA,0xBBAEAEBB,0xEBBBBAEB,0xBBBBEEBA,0xBABAABAB,
0xABBABAAB,0xABBAEEBB,0xAEEEEEAE,0xAEBABAEB,0x55AA966A,0x6AEA5AAE,0xBBAEAABB,0xBAEEEBBB,
0x5116A506,0x05551065,0x555A5555,0xAAAE55AA,0x6AAA4AAA,0x5551AA95,0x11115104,0x59591155,
0xA554EE55,0x54565545,0x55111155,0x55551111,0xABAEAEAE,0x5551AAA9,0x55555515,0x55555551,
0x55AB5AEE,0x95555556,0x51559555,0x11551511,0xEE95E555,0xAFBABBA9,0x005556FB,0x44111101,
0xBFEEEEEE,0x004556AF,0x44541400,0x10100441,0xFFEFBBBE,0x40009555,0x04101145,0x44404111,
0xBBBBBBBE,0xBE94BBFB,0x5044E501,0x11100104,0xEBBBBBBB,0xBBBBBBBB,0xBAEFBBBB,0xBBE0BBB9,
0xAABABBBB,0xAABBEEEB,0xAEEBBBAE,0xEEFBEBBB,0x56AA5AAA,0x66AA6AAA,0x6AAA6AAB,0x6AAEAABA,
0x14555145,0x45555145,0x11565455,0x04565555,0x11114400,0x11441000,0x44111104,0x10410444,
0x51115044,0x10110111,0x44044044,0x44411001,0xE5A5B956,0xE504A955,0xE0689540,0xE501E6A5,
0xFBBAAEBB,0xEEEEEEEB,0xEEEEEEEF,0xBBBBBEEE,0xEEEEAEEB,0xEEEEEEEE,0xFBBEEEEE,0xEEFBBBEF,
0xEEEEEFBB,0xEEEEEEEE,0xFBEEEEEE,0xEEEEEFBF,0xEEEEEEEE,0xEEEEEEEE,0xEFBBBBBB,0xBBBEFBEE,
0xFBEEEFBB,0xEEEEBBBE,0xBBEEBBBB,0xBEEFEFBE,0xBBBEEEFB,0xEEFBEFBB,0xBEEFFBBB,0xBFBBEEFB,
0xBBBBEEEE,0xEEEEEEFB,0xEEEFBEEE,0xBEEFBBEE,0xEBBBBEEE,0xEEEEBEEE,0xEEEEBBBB,0xBEFBBBEF,
0xAEEEBBBB,0xEEEEBBBB,0xEEEEBBBB,0xBBBBBBBB,0xBAEBBABB,0xEEEEAEBB,0xEEEEBBBB,0xBBBBBBBB,
0xEEEBAAAE,0xEEEBAAEE,0xBBEEAEBB,0xBBBBEEBB,0xAAAAAABA,0xAAAAAAAA,0xEAAAAABA,0xAAAAAAAB,
0xAAAAAAAA,0xAAAAAAAA,0xEBAEAAAA,0xEBAAAEBA,0xEAAAAEAE,0xAAAAAAEA,0xAEEABAAE,0xAAAEAAAA,
0xABBABAAA,0xBBBAEAAB,0xBAEAAAAA,0xAABAAAAB,0xEEBAABAB,0xBBAEAAEA,0xEEABAABA,0xBABAAAEA,
0xABBAEAAB,0xAABBEEAA,0xEAAAAEEA,0xEAAAAEEE,0xBBAEEAAA,0xABAAEABA,0xEAAAAEBB,0xBAEAABAE,
0xAAEEAAAA,0xABAEEEAA,0xAABABAAA,0xABAEAEAA,0xAAAA6AAA,0xBAEEAAAA,0xEEEBAAAA,0xBBBBAAAA,
0xAAAA5566,0xBBBBEAAA,0xAEEEEAAA,0xABBBEAAA,0xAEAABAA6,0xAEAAEAEE,0xAEAABAEE,0xEBAABAEE,
0x06EE1AAB,0x406F11BA,0x040B111A,0x00411113,0x10410444,0x51004111,0x54115044,0x54042441,
0x41041111,0x44054044,0x51551055,0x19551545,0x04551045,0x0A111544,0x16851B51,0x155441E1,
0x04111041,0x04044441,0x04411044,0x41011044,0xBE01BB41,0x5011E410,0x41100441,0x45041011,
0xABBBBBBB,0xEFF9BEEF,0x4404A950,0x45A40004,0xABBBAAAB,0xEEFBAAAE,0xEA95AFEE,0x00405400,
0x45565556,0x456A556A,0x56AA55AA,0x14445665,0x04441104,0x04114104,0x11111044,0x01151045,
0x10101100,0x51041110,0x14114144,0x51144511,0x90559405,0xB451E141,0xEF05BD14,0xEFE0FB81,
0xBFEFEEFB,0xEFFBFABB,0xEFFFEEEF,0xEEEFFEEE,0xEFBBBBBB,0xFBEEEEFE,0xEFFEBEEF,0xEEEEBEEF,
0xEFBEFBEF,0xEEFBFFEE,0xFEFBEFEF,0xFBBBEFFF,0xBBEEEEFB,0xBFEEFBBE,0xFBEEFBBF,0xFBEEEFBF,
0xEEFBBBBB,0xBEEFFBEE,0xFEEFBBFE,0xFEEFEFFE,0xBBBBFBFB,0xFBFBEFBE,0xFBEFEFBB,0xBBEFFFBE,
0xFBEFEFBE,0xFEEEEEFB,0xFBEFEFBE,0xBFFFEEEE,0xFBBEEFBB,0xEEFFBFEE,0xFBFBBEEE,0xFBEFBFBE,
0xBBBEEEFB,0xBEFBEFBB,0xBEFEEEEF,0xBEFEFBEF,0xBBBBEEEE,0xBBBBEEEE,0xEEFBBBBB,0xFBEFEFBE,
0xBBBBEEEE,0xBBBBEEEE,0xEEFBEFBB,0xBFBEEEEE,0xEAAAAAAA,0xAAAAAAAA,0xAEAAAAAA,0xBAAAAAAA,
0xAEEEAAAA,0xAAAABAAA,0xAAAAAAAA,0xAAAEAAAA,0xAAABBAEA,0xEBAAAABA,0xAAAAAAAA,0xAAAAAAAA,
0xBABAEBAB,0xABAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xEABAAAAA,0xABABAEAA,0xAAAAAAAA,0xAAAAAAAA,
0xAAAAAAAA,0xAAAAAAEA,0xAAAAAAAA,0xAAAAAAAA,0xAEEAAAAA,0xAAABBAAA,0xAAAAAAAA,0xAAAAAAAA,
0xABABBABA,0xAAAABAAE,0xAAAAABAA,0xAAAAAAAA,0xBBBAAAAB,0xABAEBAAA,0xAABAEEAA,0xAAAAEEAA,
0xAEEBEEEE,0xAAEBBAAE,0xAAAEBBAA,0xAAAEEEAA,0xBBAAAEBB,0xABAABABB,0x6EAABABB,0xAEAABAEE,
0x04045111,0x11044110,0x04141040,0x41041110,0x00444010,0x41100504,0x00414411,0x01101104,
0x18542944,0x54541140,0x5A515445,0x15515740,0x45455044,0x6844A411,0x90416401,0x11115104,
0x44460411,0x04054105,0x40404445,0x00054510,0x44100041,0x41040444,0x41060410,0x006A441A,
0xFB906AE1,0xB910AE01,0x9110F411,0x01418004,0x56AB0115,0xEABBBEEE,0xFFBBEFBA,0xBBBEEEEF,
0x00114000,0xAEEF5AAA,0xFEFFFBEE,0xBBBFEEEA,0x41105510,0x05AA1005,0xFFEF7BBE,0xEEEBBBBE,
0x55554054,0xEA115551,0xF947F945,0xF55BE91B,0xEFB9FBF4,0xEEEBBBBE,0xBFBBFEFE,0xFFFBEBBE,
0xEEEEBBEE,0xBBFBEEEF,0xEFEFBEBB,0xEEFEBFBB,0xBEEFBBEE,0xBEEBFBBE,0xBEFBBBEF,0xEFBBFBEF,
0xBEBFEFFB,0xFFBFBBFB,0xEFEFEEFB,0xAEFBFEEE,0xBBBBFFFF,0xBBBEFBBB,0xEFBEFBFB,0xBBBBBEEF,
0xFEEFEFFE,0xEEEFBBBA,0xEFFBBBBE,0xFBBBBEEF,0xFBEFEFBE,0xBBBBEFBE,0xEEFBEFBB,0xBBFBBEEF,
0xBEFEFBBB,0xBEBAFBEF,0xEEEEBBBB,0xBBBBBBBB,0xFBEFEFBE,0xEEEFFFFE,0xEEEEBBBB,0xBBBBEFBB,
0xBEFEFBEF,0xEEFEFFEF,0xEEBEFBEB,0xEEBBEFEE,0xFEEFEFBE,0xFBEFEEFE,0xEEEEEEEE,0xEEEEEFBE,
0xEFBEFBFB,0xEFBEFEFB,0xEFBEFEFB,0xBEEEBAEE,0xAAAAAAAA,0xEAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,
0xAAEAAAAA,0xAAAAAAAA,0xAAAABAAA,0xAAAAABAA,0xAAEBAAAA,0xAAAEAEAA,0xAAAAAAAA,0xAAAAAAAA,
0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xA6A99AAA,0xAAAAAAAA,0xAAAAAAAA,0xAAA9AAAA,0xA69999AA,
0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xA999AAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAEAEEAAA,
0xAAAAEEEE,0xAAAAAAEA,0xBAAAAAAA,0xAAAAABBA,0xAEAA6ABA,0x6EAA6AAE,0x1EAA6AAA,0x06AA56AA,
0x04101041,0x41001111,0x44041040,0x00444010,0x44411411,0x44100111,0x11041044,0x41110410,
0x41110500,0x11100411,0x41044441,0x11100411,0x10414444,0x01040411,0x01044410,0x10100441,
0xFFF41540,0xBFFEFBB9,0xFEEEFBBE,0xFFA4FBF8,0x06914564,0x950B5A46,0x044F500F,0x0007104F,
0x41041410,0x04401044,0x41144401,0x42940479,0xE950FFA4,0x04415444,0x44104444,0x10444441,
0xEEFFEEFF,0xFE91EFEA,0x0417A440,0xEE6D5D6F,0xFBEEBBBA,0xFBBEEFBB,0x2FA57FFF,0x50264A41,
0xF947B94B,0xBE51FA53,0xEF95BE94,0xFFE5BEE9,0xFBFBEFBF,0xFBFFBFBF,0xEEFBFFBB,0xEFBBFBEF,
0xBBFBFEEE,0xFBEFEFBF,0xFBEFEFBE,0xBBBFFFFE,0xBFEFEEFE,0xEFBEEEFB,0xEFBEFEFB,0xBFFBFEFF,
0xEEFBFFBE,0xEFFBFEEF,0xFEFEEEEF,0x55ABFFFF,0xBFBEFBFB,0xFEEFFBEE,0xFFEFEFFE,0x5551EEEE,
0xEEEFAEEE,0xBBFBFFBE,0xEFFFFEEE,0xFFF9BEEF,0xEEEEBBBB,0xBBEFEEEE,0xEFEFBBBE,0xEFFBFEFF,
0xEEEEEEEF,0xBBBBEEEE,0xEEEEBBBB,0xBEEEFBFF,0xBEEEEEEE,0xFBBBEEEE,0xEEEEBBBB,0xBEEFBBBE,
0xBEEFEFEE,0xBBEEBBBE,0xBBBEFBBB,0xBEEFEFBB,0xBBBBEFEE,0xBEEFEEFB,0xBEFBBBBE,0xBBEFFBBE,
0xEEBBFBEE,0xEBFBBEFB,0xFFBBBEEF,0xEEEFAEFE,0xA6AAAAAA,0xAAAAAAAA,0x69AAAAA6,0xAAAAA6AA,
0x6AAAAA9A,0x6A6AA6AA,0x669A99A9,0x999A9A69,0xAAAA9AAA,0x9A66999A,0x966699A6,0x59595999,
0x99A99A66,0x9999A659,0x96556599,0xA6556566,0xAAA9BAAA,0xA699AA99,0x56656A66,0x155A56A6,
0xAAAAAAAA,0x55AAAAAA,0x10450556,0x41051114,0x406A45AA,0x04401115,0x41104445,0x44501105,
0x11040440,0x04114040,0x44404044,0x11100445,0x10400410,0x50040101,0x04400044,0x41001011,
0x41000411,0x04401045,0x11014044,0x04001110,0x10401105,0x41010444,0x04101044,0x10114441,
0x1511BF91,0x11044010,0x10410111,0x44450410,0xFFE46A41,0xFBF9EFB8,0xEFB8FEFD,0xFE90FFE0,
0x7A070B51,0x512EA41F,0x046F443F,0x441B412F,0x11044410,0x51064111,0x50444110,0x51105104,
0xFB50EF94,0x44146501,0x44101141,0x11041044,0x6AFE017E,0xFBFEFFEF,0x01005A94,0x44441011,
0x9510FA95,0x44011040,0x44441044,0x11041111,0xFFFFFEFB,0x0440ABE5,0x11441011,0x11111104,
0x5ABFFFFE,0x44400115,0x11111111,0x44114444,0x004556AF,0x44454440,0x44451110,0x44441110,
0x44410004,0x44401114,0x44444515,0x41144441,0x11140000,0x44444441,0x44441110,0x15444444,
0x9005EA40,0x44440444,0x11101111,0x44454444,0xEFBEFEFF,0xBE80FFE5,0xD011F911,0x04444144,
0xBFEEFBFF,0xBFBBFBFF,0xFFFFFFFF,0xFFF9EFEE,0xBEFFFBEE,0xFBFFFFEF,0xEFFFFFBE,0xBFFBFEFF,
0xFEEFFBFE,0xFBEFEFFE,0xEFFFFFBE,0xBEFFFFEF,0xBBEFFFBE,0xBFEFFBBE,0xBFBFFBFE,0xBFBFFBFB,
0xEEFFFFEE,0xEEFFFFEE,0xBBFFFEEE,0xBBEFFFBB,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0x9AAAAA6A,
0xAAAAAAAA,0xAAAAAAAA,0x6AA9A9AA,0xA69AAA6A,0xAAAAAAAA,0xA9AAAAAA,0xAAAA9AA6,0x9A6999AA,
0x66AAAA6A,0x666AAA66,0x9AA9A9A6,0xA699666A,0x599A6669,0x966699A6,0x5965599A,0x5565659A,
0x59656596,0x55555556,0x55555555,0x55555556,0x96555966,0x55555555,0x11654595,0x11064455,
0x11155155,0x11144451,0x44454444,0x11114444,0x44114444,0x51114444,0x45441444,0xA5556514,
0x51451104,0x55514514,0x6A95A555,0x5AAAAAAA,0x99555451,0xE995EA55,0x5556A59A,0x51154555,
0x46BB0415,0x5BFF1BFF,0x15AA45BA,0x41141155,0x11044011,0x11040011,0x01014010,0x00004411,
0x41101104,0x44100441,0x44041040,0x00104000,0x44144440,0x10444141,0x41044444,0x04441110,
0x5544FE44,0x45110004,0x11101044,0x44411111,0x10441146,0x44444111,0x04111111,0xA5049041,
0x19115411,0x46901604,0x416945A4,0x1116112B,0x00414444,0x04101111,0x04041044,0x14414044,
0x44541100,0x11114101,0x41111111,0x04111110,0x15444044,0x7B416A04,0xA9505511,0xBAA8ABA1,
0x44414444,0x44441110,0x04451110,0x112B101A,0x45441044,0x19944B41,0xAA941441,0xEAA9BBB5,
0x44441111,0x44110444,0x01111110,0x110E1046,0x41141441,0x65141451,0x55515510,0x56105540,
0x15105241,0x15015105,0x15555415,0x05555155,0x11511115,0x11D55191,0x146554A4,0x51551529,
0x11115044,0x11114444,0x10444511,0x11445111,0xFF91FBE0,0xFD01FF44,0xF441B854,0xD041E114,
0xFFFFFFBF,0xFFFFBEFE,0xFFFFFBEF,0xFBFFFFBE,0xEFBFFFFB,0xFBFFFFFF,0xFFFEFFEF,0xFFFFBEFF,
0xBFBFFBFB,0xFEFEFFFF,0xFFFBBFFF,0xFFEFFBFF,0xFFFFFFBE,0xFFFFEFEF,0xFFEFFEFF,0xFEFEFFFF,
0xAAAAAAAA,0xAAAAA6AA,0x6A6AA6AA,0x6A6AA6A6,0xA9AAAAA6,0xA69AAAA9,0x999AAAA9,0x699A9AA9,
0x99A9AAAA,0x99A96A9A,0x99A96A9A,0x6666999A,0x66A6A9AA,0x96666A6A,0x6666699A,0x55669999,
0x965A69A9,0x666699A6,0x56566599,0x55595565,0x55595596,0x55565565,0x55555555,0x55555555,
0x65555555,0x45554955,0x10551155,0x44451115,0x44401115,0x44441114,0x11114441,0x54441111,
0x51144511,0x55445511,0xE555A551,0xFE95FA51,0xEFA5BA95,0xEFFEFEF9,0xAEFFBFFF,0x6AFFAFFF,
0x55AE5AAB,0x056A55AA,0x0456515A,0x04455115,0x44444445,0x11114444,0x51114444,0x01111444,
0x01041111,0x00451110,0x00004004,0x40410000,0x00010444,0x00000410,0x00000410,0x04104000,
0x10004441,0x14004101,0x41101041,0x10441100,0x41114400,0x45514444,0x04445104,0x10111041,
0x44441044,0x55555544,0x44411114,0x44444111,0x59956A54,0x11154555,0x11101111,0x44444444,
0x04444411,0x10414444,0x11114444,0x44100444,0x44414004,0x44411004,0x44414004,0x11040011,
0x04441044,0x04441111,0x44444444,0x11111111,0xBAB9AEE8,0xBBA4EBA8,0xBA44BA90,0x11115511,
0x046E007B,0x046F107E,0x1117452F,0x11111111,0xEBAEBBBA,0xFBA9AEB9,0xEE84EBA4,0x41111511,
0x511E042E,0x111F411F,0x4111444B,0x41111445,0x44105001,0x01110044,0x01041410,0x44040041,
0x46450695,0x55540450,0x91455114,0x65446515,0x44514440,0x50454514,0x94119141,0x44448044,
0x45154445,0x4446444A,0x44524446,0x11144451,0x8444D114,0x84448444,0x84444444,0xC1114444,
0xBEFFFFEF,0xFFFBFFFF,0xFFEFEEFF,0xEFBBFFFF,0xEFFFBEFB,0xFBFFFFBF,0xEEFBFFEF,0xFFFFBFFF,
0xFFFBEFBF,0xEFFEBEFF,0xFBFBFFBF,0xFBBBBFFF,0xEFBBFFFF,0xFFBFFFFF,0xFFFFFBFB,0xFBFFFFFB,
0x699AA6A9,0x699AA6A9,0x69A6A6A6,0xA6669A6A,0x699AA6A6,0x99A69999,0x65969A69,0x65999A69,
0x999A6699,0x59999665,0x66599599,0x66665565,0x55599996,0x55599995,0x55595595,0x55555555,
0x15555555,0x01555555,0x40151555,0x41014455,0x05111041,0x11101044,0x11041111,0x44441110,
0x54511111,0x91515511,0xE955A511,0xFE55FA51,0xFFE9FFA5,0xFFFEFFFA,0xBFFFFFFF,0xABFFBFFF,
0x56AF6AFF,0x45AB55AF,0x415A156A,0x11165456,0x44411114,0x44441114,0x44441111,0x11114444,
0x00441111,0x01041011,0x00000411,0x40004044,0x04010000,0x11541540,0x51455514,0x11445514,
0x10410000,0x01000004,0x44154011,0x41150454,0x41014410,0x04441111,0x04404404,0x10444111,
0x8B040910,0x7641D744,0xD3C14F84,0x686471A0,0x44064440,0x56DA015A,0xD359DA76,0x387A72AD,
0x10444444,0x44401111,0x05691016,0x91CE475C,0x41114444,0x44441111,0x11111111,0x41144441,
0x11040044,0x44440111,0x11111111,0x44444444,0x44441111,0x44441110,0x44411100,0x00444004,
0x11144441,0x11144441,0x11144441,0x11011110,0x11114444,0x11114444,0x41114444,0x11041111,
0x41111444,0x41111444,0x44441444,0x10441111,0x41141441,0x41141441,0x11144441,0x11114441,
0x04440111,0x04445111,0x11114444,0x44114444,0x55012910,0x55450414,0x14444444,0x41101111,
0x14515145,0x14515145,0x05115111,0x44445111,0x44451111,0x44411114,0x44451114,0x44441110,
0x94449111,0xF444E111,0xFA04E911,0xFAB0FB91,0xFFFFFFFF,0xFFFFEEEF,0xFFBEFFFB,0xFFFFBBFF,
0xFFFFBBBE,0xFFFFBFEF,0xFFFFFBFF,0xFFFFFFFF,0xEFFFFFFF,0xFFFBFFBF,0xFFFEFBEF,0xFFFFBEEF,
0xBEEEFFFF,0xFFFBFFFF,0xFFFFFBFF,0xFFEFFFBF,0x5999999A,0x66669666,0x665659A9,0x55966669,
0x99965999,0x65665665,0x55659656,0x55555996,0x55595555,0x55595555,0x55555555,0x55555555,
0x55555555,0x05555555,0x01555555,0x04151155,0x44401015,0x04414404,0x10441110,0x11144101,
0x44441444,0x55115444,0x95145441,0xF551A544,0xFFE5FB95,0xFFFAFFE9,0xFFFFFFFE,0xBFFFFFFF,
0x6ABF6BFF,0x56AF5AFF,0x556A15AB,0x5556456A,0x11051155,0x14454454,0x11454511,0x11445114,
0x01114511,0x00144451,0x01014445,0x01040011,0x50004104,0x45001004,0x11101400,0x11111140,
0x15505115,0x44514445,0x11114511,0x11054451,0x40150451,0x44010444,0x10410444,0x04104104,
0x04101101,0x11104111,0x44114041,0x41041110,0x95019D11,0x11044050,0x44044110,0x11101044,
0xCB291D2A,0xB184D358,0x44449010,0x11111104,0x2D7274E7,0x599D2E5C,0xEB64CEFB,0x9411B501,
0xB81D1438,0xCA479D0B,0x7A90AB41,0xDD7658D1,0x11014444,0x16F94062,0x5DD72A8D,0x7D35E973,
0x51111544,0x11104444,0x44474446,0x11041110,0x10054110,0x64510554,0xB844F104,0xAE01BD11,
0x11111044,0x04444444,0x10415110,0x41110402,0x11114441,0x04414444,0x55511114,0x44440000,
0x11114444,0x11114444,0x44514404,0x11105111,0x11114444,0x11114444,0x11044444,0x54444555,
0x44114444,0x44444444,0x11114444,0x54544444,0x44444444,0x01044444,0x95555410,0x95555551,
0x90440444,0xAA90E904,0xAAEAAAAA,0xAABFAAF9,0xFEABBEAD,0xBFAAFEAA,0xFFEAFFEA,0xFEFEEFFA,
0xFFFFFFEF,0xFFFFFFFF,0xFFFBFFBF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFBFB,0xFFFFFFFF,0xFBFFFFFF,
0x5665665A,0x59959559,0x55956559,0x55559659,0x55555566,0x55555565,0x55555555,0x55555555,
0x55555555,0x55555555,0x15555555,0x15555555,0x04451055,0x44114045,0x44001045,0x11010444,
0x44114441,0x51041110,0x51101111,0x54444511,0xFE54E954,0xFF95FE55,0xFFE5FFA5,0xFFFAFFF9,
0x6BFFAFFF,0x5ABFABFF,0x66AF66BF,0x55AA566F,0x14551156,0x15155155,0x55514455,0x45554445,
0x11511515,0x44511115,0x11141111,0x44444445,0x41010411,0x11104411,0x44544501,0x11145140,
0x51111114,0x44514444,0x11441111,0x04415114,0x11141111,0x44440444,0x44510111,0x11110444,
0x41111041,0x41104404,0x44101041,0x10104101,0x44100441,0x10400444,0x10441104,0x44140440,
0x41404411,0x44511111,0x51114500,0x51040044,0x11044110,0x11111111,0x05141111,0x41445451,
0x14110144,0x41111111,0x11111111,0x41044444,0xE141A7A4,0x04449011,0x44441111,0x41044441,
0x474E0E1C,0x159042C6,0x41042441,0x04441110,0x11104111,0x44114444,0x04441041,0x80414111,
0x6BC16B44,0x16B41AE0,0x416E15A8,0x5456449A,0x40100401,0x00110441,0x10441501,0x44444444,
0x04100041,0x00101001,0x00110101,0x04450044,0x11104001,0x11104001,0x04404001,0x04001001,
0x11040110,0x44044110,0x04044110,0x44101041,0x41115111,0x44401104,0x51114444,0x44441111,
0xD1449514,0xA554E511,0xAA54A911,0xA955A955,0xAAABAAAF,0xFAAAFAAA,0xFFAABEAA,0xFFFEFFEA,
0xEFBFFFFF,0xFBFBFFFF,0xBFFFFFBF,0xFBEFFFFF,0xFFFFFEFF,0xFEFFEFEE,0xFFFFFFFB,0xFFFBFBFF,
0xFFFFFFFB,0xFFFFEFBF,0xFFFFFBFB,0xBFEFFEFF,0xFFFFFFFF,0xFEFFFFFB,0xFFBFEFFE,0xFFFFFFFF,
0x55555566,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x55551555,0x55555555,
0x41551555,0x01551555,0x01151155,0x01151055,0x11004044,0x04411044,0x44111040,0x44111040,
0x95515110,0xE551A444,0xF954E911,0xFE55EE51,0xBFFFFFFE,0xABFFBFFE,0xAAFFAFFF,0xAAAFAAFF,
0x156A559A,0x555A556A,0x55565156,0x55555555,0x05555451,0x11555445,0x44551144,0x45151444,
0x04441111,0x11114444,0x44441045,0x45045111,0x11114511,0x11114451,0x45141111,0x51441111,
0x11111114,0x44111144,0x44441145,0x14441111,0x11114445,0x44441111,0x44441111,0x44451111,
0x01104104,0x04101041,0x10104101,0x40040441,0x10444100,0x10444101,0x10444100,0x10104101,
0x10440410,0x11040440,0x41041010,0x41040410,0x11114411,0x11111111,0x04104444,0x10104441,
0x11451551,0x40411511,0x04114444,0x04445040,0x04454411,0x11114105,0x41114410,0x41111100,
0x44411044,0x41044444,0x04441010,0x44441101,0xB510D111,0x68447444,0x29116941,0x49445A44,
0x15154456,0x54514545,0x45551554,0x15A55556,0x14511104,0x14505101,0x15545101,0x15515101,
0x11151151,0x54554544,0x54555544,0x55554545,0x04041010,0x04004040,0x10411104,0x41110401,
0x10110441,0x44040440,0x14100041,0x44104101,0x11115111,0x14445111,0x51115111,0x51441444,
0xEA55AA54,0xFE95EA95,0xFF95FE94,0xFF95FF95,0xFFFFFFFE,0xFFBFFFFF,0xFFFFFBFE,0xFFFFFFFF,
0xBFFFFFFF,0xFEFFFFFF,0xEFEFFFFF,0xFFFFFFFF,0xFFFFBFBF,0xFBFEEFEF,0xFFFFFFFF,0xBFBFFFFF,
0xFFBFFFFF,0xFFFFFBFB,0xFFFFFEFE,0xFFFFBFEF,0xFEFFFFFB,0xFFEEEFFF,0xEFFFFEFF,0xFEFFFFEF,
0xFFFBFFFF,0xFEFFFFFF,0xFFFFFFEF,0xFFFEFFFF,0x55555555,0x55555555,0x15555555,0x55555555,
0x15555555,0x55555555,0x54555555,0x55555555,0x04051055,0x01054055,0x01051015,0x11050015,
0x44411110,0x51114404,0x54114440,0x51104101,0xFF95FB94,0xBFA5FEE5,0xABB9FFE9,0xAAA9BBA9,
0x5AAB6ABF,0x56AA5AAF,0x55AA56AA,0x556A556A,0x55554555,0x54551155,0x51454555,0x55554515,
0x14511144,0x11444515,0x54454451,0x55455444,0x15115151,0x55551154,0x55154555,0x15555555,
0x11111451,0x44514515,0x44551545,0x44551545,0x51111145,0x45141111,0x44515111,0x11515445,
0x44441111,0x11114451,0x11441114,0x44451114,0x00041111,0x00111104,0x10111111,0x10040111,
0x10414104,0x10404104,0x00104101,0x00104441,0x41040410,0x41040410,0x10440400,0x10040100,
0x44100101,0x44100041,0x40100441,0x10110441,0x11001011,0x40400411,0x41100404,0x41000411,
0x04111044,0x10444440,0x41100401,0x00104401,0x44050110,0x04444110,0x04101041,0x44101104,
0x52849641,0x95916590,0xA5919951,0xA994A594,0xA5AA5699,0xA966A9AA,0xAA5AAA6A,0xAAA6AA96,
0x156A5105,0xAFEA56BA,0xEFBEFEFA,0xBBFBFEEE,0x55555145,0x15555451,0x2FFF55AF,0x1FBB1FFF,
0x41100441,0x41100441,0x40440444,0x01041111,0x44104441,0x44501104,0x15104441,0x45115044,
0x45441444,0x45445445,0x55455451,0x55515514,0xFF95FF95,0xFF95FE95,0xFF95FF55,0xFF95FEA5,
0xFFFFFFFF,0xFFFFFFFF,0xFFFBFFFF,0xFFFFFBFF,0xFFFFFBFF,0xFFFFFFFF,0xBFEFFFFF,0xFFFFFEFF,
0xEFFFFFFF,0xFFFFFFBF,0xFFEFFFFF,0xFFFFEFFF,0xFFFFFFBF,0xFFFEFFFF,0xFFFFFFFF,0xFFFFFFFF,
0x00450015,0x04151115,0x04551055,0x11651056,0x51104441,0x44504401,0x44441101,0x45041041,
0xAA55AAA5,0x6955A554,0x95546551,0x55545511,0x555A555A,0x5156155A,0x55555556,0x55451455,
0x51454514,0x44451555,0x44451554,0x45111155,0x55515544,0x55545551,0x55555555,0x55555555,
0x55551555,0x55555555,0x55555551,0x55555555,0x15154445,0x15555151,0x55155155,0x55555555,
0x44454544,0x11451114,0x44454514,0x11144555,0x41040451,0x40110451,0x40440544,0x04451111,
0x01104401,0x40404404,0x40400404,0x00414404,0x00041110,0x00441100,0x00444400,0x40444400,
0x11110100,0x11010010,0x11040010,0x10444100,0x40410411,0x40411104,0x10400404,0x10440104,
0x44401111,0x41100404,0x00404411,0x41041411,0x10104101,0x44400111,0x41110404,0x41101104,
0xAA95AA54,0x6A946A94,0x9AA45AA5,0xA6A496A5,0xEAA9AAA5,0xFAAAEAA9,0xFEAAEAAA,0xFFAAEEAA,
0xBBEEFFBF,0xBFFEFFBF,0xFBBEFFFB,0xFFFEFFFB,0x47FB0BFF,0x02FF46FF,0x41BE11FF,0x447F10BF,
0x04041051,0x04411044,0x41041011,0x04101041,0x44441441,0x51111511,0x55114444,0x54511144,
0x55515545,0x69556555,0x9A55AA54,0xAA95AA95,0xFFA5FEA5,0xFFA6FFA5,0xFFA9FEA6,0xFFA6FFA9,
0xFFFFFFFF,0xFBEFFFFF,0xFFFFFFFF,0xFFFBEFFF,0xFFFFFEFB,0xFBFBFFFF,0xFFFFFFFF,0xFFFBFFFF,
0xFFFFFFFB,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0x55555555,0x56595555,0x59556555,0x66555555,
0x55555555,0x55595555,0x55559995,0x55959959,0x95555555,0x59995555,0x99996555,0x69965659,
0x45551155,0x59561599,0x99999599,0x66666666,0x41104411,0x44404444,0x15564015,0xAA6655A6,
0x45445444,0x54444444,0x11514444,0x51554515,0x55141155,0x15144451,0x44455151,0x55145151,
0x54445155,0x99459511,0x66956654,0x9A6699A9,0x55555555,0x56595565,0x96565565,0x65995969,
0x55555555,0x55555555,0x55555555,0x65655659,0x55555555,0x45555555,0x55555555,0x55555555,
0x55555555,0x55554555,0x55555515,0x55555555,0x45151110,0x51554451,0x55555555,0x45555555,
0x00404404,0x00404404,0x00454411,0x11554555,0x10440400,0x10044100,0x10044110,0x00114100,
0x10114100,0x00444100,0x00444400,0x00444400,0x10044100,0x01044110,0x11041010,0x41040410,
0x01044410,0x04111040,0x44111100,0x10410110,0x10411104,0x11010444,0x14100044,0x10411111,
0xA9A5A5A5,0xAA55A965,0xAAA1AA95,0xAAA5AAA4,0xFBEAEFAA,0xBEFAFFEA,0xFFBEFBFA,0xBEFFFBEE,
0xFFEFFEFF,0xFFFFBBFE,0xFFFFFEFB,0xFFFFFFBE,0x102F446E,0x110B111F,0x1047110F,0x40420506,
0x44044444,0x11040441,0x14104041,0x11101041,0x54444544,0x54515151,0x51455544,0x94515551,
0xAAA5AEA5,0xAAE9AFA9,0xAEEAAFB9,0xAFBAAEFE,0xFFAAFFAA,0xFFEAFFAA,0xFFEAFFAA,0xFFEAFFEA,
0xFFFFFFFF,0xFFBFFFFF,0xFFFFFBFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFEFBFF,0xFFFFFFBF,0xFFFFBFFF,
0xFFBEFBFF,0xFBFFFFFF,0xBFFFFFEF,0xFEFFFFFF,0xFFFFFFBF,0xFBFFFFFE,0xFFEFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFEF,0x95555999,0x99969999,0x99966669,0xA6669999,
0x95656656,0x55996A99,0x96696A66,0x965969A6,0x99999665,0x66666596,0x66666666,0x9A66A9A9,
0x99999999,0x9A666666,0xA9A66666,0xAAA6A6AA,0xA5995999,0xA69A9A66,0x9A9AA9A9,0xAAAAAAAA,
0xAA695666,0x69AAA6A6,0x6AA6AAAA,0xAAAAA9AA,0x9AA6A955,0x999A6669,0xA66A9AA6,0x6A6A66A6,
0x6699699A,0x9A666666,0x999A6599,0x99A69999,0x66665666,0x59556666,0x55556666,0x55996599,
0x55569666,0x55569999,0x55565955,0x56565565,0x55595555,0x55995655,0x55955555,0x55555555,
0x55555551,0x15555515,0x55555555,0x55555555,0x01154411,0x15555555,0x55555555,0x55555555,
0x00444400,0x41114401,0x45550455,0x55555555,0x01041010,0x04041040,0x04044110,0x01151045,
0x10411104,0x10410444,0x04414410,0x11011044,0x04414444,0x11114411,0x11114440,0x11044111,
0xEAA5EAA4,0xFAA5EAA4,0xBEA5BAA4,0xEFA5FBA4,0xFEEFFBEE,0xBFBBFFFE,0xFFBBFBFF,0xBFEEFBFF,
0xBFBEFFFF,0x7FEFBFFF,0x1FFF3FFF,0x0BBF1FFE,0x04441101,0x04441040,0x04111040,0x04111040,
0x51411004,0x11414404,0x44415104,0x14415110,0x95519545,0xA545A554,0xE955E554,0xF955A951,
0xAEFBABFE,0xAEFFAFEF,0xAEFFABFE,0xEAFFABFF,0xEFEEFFEA,0xFFFEFFEA,0xFFFBFFEA,0xFFFEFFFA,
0xBFFFFFFF,0xFFFEFFBF,0xEFFFFFFF,0xFFFFFFFB,0xFFFBFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0x99996666,0xAAA6999A,0xA66666A9,0xA66A6AA6,0x99996666,0x9AAA6999,0x6AA6A9A6,0xA9AAA69A,
0xAA99A9A6,0xAAAA666A,0xAAAAAAA6,0xAAA9AA9A,0xAAAA6A9A,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,
0x6AAAAAAA,0xAAAAA6AA,0xAAAAAAAA,0xAAAAAAAA,0xA66AAAA6,0xAA6A9AAA,0xAAAA66A6,0xAAAAAAAA,
0xA669669A,0x99A66A9A,0x66A6666A,0x9AAAAAAA,0x65599A66,0x66665666,0x56666666,0x699999AA,
0x56596565,0x56569565,0x56556566,0x599AA966,0x56555565,0x55555559,0x55955555,0x55999959,
0x56555555,0x55555556,0x59955555,0x59959559,0x55555555,0x55555555,0x65955556,0x96595559,
0x55555555,0x55555555,0x55555555,0x55655555,0x45555555,0x55555555,0x55555555,0x55555555,
0x55455455,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x99959555,
0x55551555,0x56555555,0x66656596,0xA6999999,0x04011044,0x45561155,0xAA965569,0xAAAAAAAA,
0x11111111,0x11104441,0xAAAA5115,0xBABABBAA,0xEFE5FBA5,0xBBEDFEF8,0xEEFBFBAE,0xEEBEBBEB,
0xBFFEFBBE,0xFFFFFEEF,0xFBBAEEEE,0xFFBEEEEF,0x07FF0BFF,0x41EF03FE,0x10BE01FF,0x407E10BF,
0x04041041,0x04104041,0x44101041,0x44100041,0x11115104,0x45115440,0x44441444,0x45145441,
0xFA55EE55,0xFE95FA95,0xFFA5FEA5,0xFFE9FFA5,0xEABFABFF,0xAEBFEAFF,0xAEAFEAFF,0xABAFBABF,
0xFFFEFFFA,0xFFFEFFFE,0xFFFFFFFE,0xFFFFFFFF,0x9AAAAAAA,0xAAAAAA9A,0xAAAA9AAA,0xAAAAAAAA,
0xAAAAAAA9,0xAAAAAAAA,0xAAAA9AA6,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAABAAAAA,
0xAAAAAAAA,0xAAAAAEAA,0xAAAAAAAA,0xAAAAAAAA,0x9A69999A,0x6AAA99A6,0x9AAAAAAA,0x9AAAA9AA,
0x55959999,0x999A9999,0x99AA6999,0x65A99A66,0x55999955,0x65996659,0x99999666,0x96669999,
0x65559559,0x66595666,0x69999599,0x65996659,0x56555565,0x55959559,0x56669959,0x96595996,
0x55555556,0x55555959,0x95655655,0x95A55956,0x55555555,0x95555555,0x55555965,0x56656656,
0x95555555,0x95595655,0x65655996,0x99659656,0x65959959,0x99656999,0xA6669999,0xA9999999,
0xA9AAAA69,0xAA696AA6,0xA6AAAA99,0xAA9AAAA9,0xAAAAAAAA,0xAAAAAAAA,0xBAAAAAAA,0xEBAEAAAA,
0xAEABBBBA,0xAEBABAEA,0xAEAEBAEA,0xEEAABBBA,0xBBBFEBBB,0xBFBFFBBA,0xEEEBBBBB,0xFBEEEEEE,
0xBEBFBBFB,0xBFBEFBFB,0xBEFBFBBB,0xFEFEFBEF,0x101F042F,0x410B041F,0x4047040B,0x40420403,
0x04101041,0x04001041,0x10004444,0x11041110,0x55515441,0x55515111,0x55519444,0x95519515,
0xFFF9FFA9,0xFFFAFFEA,0xFFFEFFFA,0xBFFFBFFE,0xBBAFBABB,0xEEBAEBAB,0xEEBAEEEB,0xFAFAFBAB,
0xFFFFFFFF,0xFFFFEFEF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFBEFB,0xFBEFFFFF,0xFFFFBFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFBFEFFF,0xFFFFFFFF,0xAAAAAAAA,0xAAAAAAAA,0xABAAAAAA,0xAAAAAAAE,
0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAEAA,0xAAAAAAAA,0xAAABAAAA,0xAAAAAAAA,0xAAEAAAAE,
0xAAAAAAAA,0xAAAAAAAA,0xAAAAA6AA,0xAAAAAAAA,0x9AAAAA9A,0xAAAAAAAA,0xAAAAA9AA,0xAAAAAAAA,
0x9AAA6A9A,0x6AAAAAAA,0xAAAAA6AA,0xAAAAAAAA,0xAAA6999A,0xAAA6666A,0xAAAA999A,0xAAAA99AA,
0x66A99959,0x6665999A,0x9A696666,0x9A6A69A6,0x999A5965,0x66666599,0x99996659,0x99AA6666,
0x95955A5A,0x65995959,0x65655656,0x99999666,0x59556599,0x66565599,0x59959565,0x66995559,
0x65959656,0x66655966,0x66556595,0x66599966,0xA9A6AA99,0x9A669999,0x9A9AA9A6,0xAA66AA69,
0xAAA9AAAA,0xAAAAAAAA,0xAAA9AAAA,0xAAAAAAAA,0xEAAAAEAA,0xAAEAABAA,0xBBAEEAAA,0xBAAAAAAA,
0xEAAAEEEE,0xEBAABBBB,0xEFAEBABA,0xEEBABAEB,0xBBEEEEBB,0xEFEEFEBB,0xBBEEEEEE,0xFBBEEFBB,
0xFEEFEFEE,0x7BBEBFFB,0x2FBF6FFB,0x1FBE2EFB,0x41000411,0x41040410,0x44400010,0x04410004,
0x11041010,0x51044440,0x11001110,0x44105111,0xA555A511,0xE555E944,0xFA55E951,0xFE55FA54,
0xAFFFFFFE,0xAFFFEFFF,0xEBFFAFFF,0xBAFFEBFF,0xFFBAFBAE,0xFFBBFAEE,0xFFBEFEEB,0xFFFBFFBA,
0xFFFFFFFF,0xFFFFFBEF,0xFFFBBFFF,0xFFBFFFFF,0xFFFEFFFF,0xFFFFFFFF,0xFFFFBFBF,0xFFFFFFFF,
0xAAAAAAAA,0xEBAAAAAA,0xAAAAAAAA,0xABAAAAAA,0xBAAAAAAA,0xAEAAAAAB,0xAAAAAAAA,0xAEAAAABA,
0xAAAEEAEA,0xABABAAAA,0xAAABBAAA,0xEAEBABAA,0xAAAAAAAA,0xAAEAAAAA,0xAAAABAAE,0xAEAAAAAA,
0xAAAAAAAA,0xBAAAAAAA,0xAAAAAAAA,0xAAEAAEAE,0xAAAAAAAA,0xAAAAAAAA,0xEAAAABAA,0xAAAEAAAA,
0x6AA6AAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xA9AAAAA6,0x9AAA6AAA,0xAAAAAAAA,0xAAAAAAAA,
0xA66A6A99,0x9A6A66A6,0x99A6AAAA,0x99AAAA9A,0x6699665A,0x6666999A,0x9A6699A9,0x669AA669,
0x66666566,0x96999959,0x66999966,0x99969969,0x9A6699A6,0x6999A599,0x6A66A665,0x6A66A699,
0xAAA9A9AA,0xAAAAAA66,0xAA9AA9A9,0xAAAAAAA9,0xAAAAAAAA,0xEAAAAAAA,0xAEAAAAAA,0xAEAABAEA,
0xAEABEBBA,0xAEBABAEA,0xBAABBAEA,0xBEEBBBBA,0xEEBBBBEE,0xBBBBBEEA,0xEEEEBBBB,0xEFBFEEEB,
0xFBFBEFBB,0xBEEFEFBB,0xBBEEFBBB,0xBBEEFFBE,0x47BE0BFB,0x42FF07FB,0x41FF05EE,0x447F04BB,
0x11044010,0x11100001,0x11100001,0x11100001,0x51104504,0x51101111,0x54414511,0x51114444,
0xFF55FA94,0xFF95FE95,0xFFE5FFA5,0xFFE9FFA9,0xEEBFEAFF,0xEEAFBAEF,0xBBABBBBF,0xBBAAEEEF,
0xFFEEBFEE,0xFBFEFFFB,0xFFFFFFFB,0xFEFFFFFE,0xFFFFFFFF,0xFFEFFFFF,0xFFFFEFFF,0xFFFBFFFF,
0xEFFFFFFF,0xFFFFFFFF,0xFFFFFFEF,0xFBFFFFFF,0xFFEFFFFF,0xFFFEFBFF,0xFFFFFFEF,0xFFFFBFFF,
0xFFFFFFFF,0xFFFFFEFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFBFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0xABAAAAAE,0xAAAAEAAA,0xBAAAAAEA,0xAAAAAAAA,0xBAAAAAAA,0xBAAEAAAA,0xAAAAAAEA,0xAAAAAAAE,
0xBAAAAAAA,0xEBAAAABA,0xAAAAAEAB,0xAAABBAEA,0xAAAAAABA,0xAAAABAAE,0xEAABAEEA,0xAAAEABBA,
0xAEAAAAAB,0xAAAAEABA,0xAEBAAAAA,0xEAEAAAAB,0xAAAAAAEA,0xAAAAEEAA,0xAEAEAAAA,0xAAAAAAAA,
0xAAAABAEA,0xAAAAAAAA,0xAAEAAAAA,0xAAAEBAAA,0xAABAEEAA,0xEAAAAAEB,0xAAAAAAAA,0xAABBAAAA,
0xAAAAAAAA,0xAAAAAAAE,0xAAAAAAAE,0xAAAAAAAA,0xAAAAAAAA,0xAAAA69AA,0xAAAAAAAA,0xAAAAAAAA,
0xAAAAAAAA,0xAA6A6AAA,0xAAAAA9AA,0xAAAAAAAA,0x9A6AAAA9,0xAAA6A9AA,0xAAAAAA9A,0xAAAA9AAA,
0xA9A9669A,0xAAA9669A,0xAAAAA9AA,0xA6AAAA9A,0xAAA6A99A,0xAAAAAAAA,0xAA9AAAAA,0xAAAAAAAA,
0xEAAAAEEA,0xAEAABBBA,0xEAAEBAEA,0xEBBAAEAA,0xBBBABBAE,0xBAEEEEEB,0xBBAAEBBB,0xEBBAEEBB,
0xFFFBFBBB,0xFFBBBFBE,0xFFEFEEFE,0xAEEEFEFA,0xBFFBFBEF,0xFFFFFBBF,0xFBFEEFBF,0xBBFBFFBB,
0x446F047E,0x112E012F,0x011F112F,0x412F145E,0x11104001,0x41101001,0x44100401,0x11004041,
0x55445444,0x55445111,0x54445111,0x44455510,0xBFF9BFF9,0xAFFAEFFA,0xEAFAAFFA,0xBAAAAAEA,
0xEFBAEEEB,0xFBBAEEEE,0xFEEEFBBB,0xFFBBFEBB,0xFFFFFFFF,0xFFFFBFFF,0xFFFFFEFB,0xFFFFFFFF,
0xFBFFFFFF,0xFFFFFFFF,0xBFFFFFFB,0xFBFFFFFF,0xFFFFFEFF,0xFFFFFFFF,0xFFBFFFFF,0xEFFFFFFF,
0xFFFFFFFF,0xFFFBFFFF,0xFFFFFFFF,0xFFEFFFFF,0xAABAABAA,0xEBAAAAAA,0xAEAAAEAA,0xEBAAAAAE,
0xEABAABAB,0xABAAAAAA,0xAEBABAAB,0xEAAAAAEA,0xEBAAAEAA,0xAAEAAABB,0xAEEBBAAE,0xEABAAAAA,
0xAEEAEAAA,0xEABAAAAA,0xABAAAEAB,0xEEAAAABB,0xABAEAAAA,0xEAAAAEAA,0xABABAEBA,0xAEAABABA,
0xBAABAAEA,0xABAAAABA,0xAAEBEEAA,0xBAEAAAAE,0xAAAAABAA,0xAAAABAAE,0xEAAEAEEA,0xABAEAAAA,
0xAAAABAAA,0xAAABAAEA,0xAAAABABA,0xBAABEBAE,0xAABAEAAA,0xAAABAAAA,0xAEAEEAAA,0xAAAAAABA,
0xAAAAAAAA,0xBAAAAAEA,0xAAAAAAAA,0xABABAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAEABAAA,
0xAAA6AAAA,0xAAAAAAAA,0xA6AAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAA9,0xAAAAAAAA,0xAAAAAAAA,
0xAAAAAAAA,0xAAAAEBAA,0xEEBAAAAA,0xABAAAAAA,0xABBAAEAB,0xEEBAAAAA,0xAEAAEAEB,0xAEAABAEE,
0xEEBAEEEB,0xBABAEEEB,0xBBEBBBAE,0xBBEFEEBA,0xBFEEFBBE,0xFEEFEBBA,0xFBFBEEEE,0xBEEFEFAE,
0xBFEFFFBE,0xBFBBFBFE,0xFFBEFBFE,0xFBBFEFFB,0x412F146F,0x106F457F,0x11FE14FF,0x4BFB53FF,
0x11101011,0x44114104,0x11111111,0x44444444,0x51115510,0x44441444,0x11115144,0x45145444,
0xEEA5EAA5,0xAE95BAA5,0xAEA5EAA5,0xEAA5BAA5,0xBFEEFFAE,0xFFFBFFEB,0xEFFFFFFE,0xFFFFFFBF,
0xFEFFFFFF,0xBFFFFFFB,0xFFFFFFFF,0xFEFFEFFB,0xFFEFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFEFEF,
0xBABAAAAA,0xEAAAABAB,0xAABAAEAA,0xABAAEAAA,0xAAEAAEAE,0xBBAEAAAA,0xAAEEEAAA,0xBABAEBAA,
0xABBAAAAB,0xAEBABAAB,0xAEAAEAEA,0xBBAEAABA,0xAAABAAAA,0xEAAEAAEA,0xAABAAEAA,0xAAABBAEA,
0xEAAAAAEE,0xAAEAABAB,0xAEABBAAA,0xBABAAAEA,0xAAEAEAAB,0xABAAAEAE,0xAAEAAAAE,0xAEBAEAAB,
0xAAAABAAA,0xAAABAEBA,0xAAEAEAAE,0xAABAEEAA,0xBAABABBA,0xAAAEABAA,0xAAAABAEA,0xAAEAEBAE,
0xAAEBBBAE,0xABABEAAA,0xAEAEEABA,0xEAEEAAAA,0xAAAEAEBA,0xAEBAAAAA,0xEBAEAAAA,0xAEAAAAAA,
0xAEAAAAAB,0xAAAAAAEB,0xAAAAAEAE,0xBABAAAEA,0xEAEBAAAA,0xABABAAAA,0xBAAAAAAA,0xAAAAAAEE,
0xAABAAAAA,0xAEAEBAAA,0xAAAAEAAA,0xAAAAAAEB,0xAAAAAAAA,0xAABAAAAA,0xAAAAAAAA,0xEBAEAAAA,
0xAAAAAAAA,0xAAAAAAAA,0xAABAEAAA,0xABAABAAA,0xAAAAAAAA,0xBAAAAAAA,0xABBAEAAA,0xBAABAAAA,
0xBABAEAAA,0xAEAAAAAA,0xAEAEAAAA,0xBAAABBEE,0xBBAAEAEE,0xABABEEBA,0xBBABBAEE,0xBEEBEBBA,
0xBBBBEEBA,0xBBBBEEEE,0xAFBEFEEB,0xFFBBBAFB,0xEEEFEFBA,0xBFFFFEFE,0xBBBBFFEF,0xBBBEFFFB,
0xFFBEBFFB,0xFFBFBBFB,0xFBBBEFFF,0xEEEFFFFE,0x7FFF1FBF,0xFFFFFEFB,0xFBEEEFBF,0xEEFBFFFF,
0x11101115,0x511B1442,0x5AFF057F,0xEFFFFFEE,0x55115451,0x55515545,0x95455114,0xFFFFFEBB,
0xFAA5EAA5,0xFF95FE69,0xFFFEFFF9,0xFBFFFFFF,0xFFFFEFFB,0xFFFEFFBF,0xEFEFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0xFBFEFFFF,0xBFFFFFEF,0xFBFFFFFF,0xFFFFFFFF,0xFFFFFFEF,0xFFFFFFFF,0xEFFFFFFF,
0xFFFFFFEF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xEBAEAAAA,0xBAEAAAAA,0xEAAAAAAA,0xAAAAAEBA,
0xAAAAEBAB,0xAEAEBAEA,0xBAAAAAEA,0xAAAAAABA,0xBAAAABBA,0xAEEBAAAE,0xBBAEAAAA,0xAAAAEABA,
0xBABBAEEA,0xEAAAABAA,0xAAAAAEEE,0xAAAABBBA,0xAEAAAAEB,0xAEAAAAEE,0xAABABAEB,0xABAABAAB,
0xAAEBEAAA,0xAAABBBAA,0xAAABBBBA,0xAAAAEBBA,0xAAAAEBAA,0xAAEBBBAE,0xABAEBAAA,0xAAAABABA,
0xAEBABAAA,0xEBBAAAAB,0xAEBABAEB,0xAAAAAAAB,0xAEAEBBAA,0xAEAEAAEA,0xAEBBBAEA,0xBAAAAAEA,
0xAEABEAEE,0xAAAAEAEE,0xAEBAEAAB,0xAAAABAEB,0xBAAEABAA,0xAAAEEBAA,0xAABAEBAA,0xAAAAAAEB,
0xAEAEAAAA,0xBAAAAAEA,0xEAEAAAAA,0xAAAAAEAB,0xAEAAAAAA,0xEBAAAABB,0xAAAEAEBA,0xAAAABAEA,
0xAAAAAAAA,0xAEBAAAAA,0xAEABEAEA,0xEAAEAAEA,0xBAAAAABA,0xAEBAEAAB,0xEEAAAAEA,0xBAAAAAEE,
0xEAAEABBA,0xEBAEAEAA,0xBBAAAABA,0xABAAAABB,0xEABAAAEB,0xEEEEAEAA,0xEBBBBAAA,0xABABBABA,
0xEEEABAAE,0xBAEAABAE,0xFBEEAEBB,0xBAEBEBAE,0xBBBAFBBB,0xBBAFEEEE,0xEEEEFBBB,0xEEEEBEEE,
0xEFEFFEFB,0xFBFBBEBE,0xFBBABFBF,0xBAEEBFEF,0xBEFFFFEE,0xFEFEFBEF,0xFBFBEFEF,0xEEFBFFBF,
0xBEFFFFEF,0xBFBEFBFB,0xFEEEFFFF,0xFEEEEFFF,0xFFFFFEFB,0xFEFFFBEF,0xFFFFBFEE,0xEFBEFEFB,
0xFFFFFFFF,0xFFFFBFBE,0xFFFFEFEF,0xEFFFFEFB,0xFFEFBFFF,0xBEFFFFFF,0xFFFEFFFF,0xFBFBBFEF,
0xFFFFFBEF,0xFBFFFFBF,0xFFBFFFFB,0xFEFBEFFF,0xFFBFFFFE,0xEFFEFFFF,0xFFFFFFBF,0xFBBFFFFB,
0xFFFBFFFF,0xFFBFFFFF,0xFFFFFFFE,0xFFBEEFFF,0xFFFFFFFF,0xFFEFFFFF,0xFBFFFFFF,0xEFFFFFEF,
0xFFFBFEFF,0xFFFFFFFF,0xEFFFFFFF,0xFFFFFFBE,0xFFFFFFFF,0xFFFFFFEF,0xFFFFFFFF,0xFEEEBFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFBEFFFF,
};
//}}BLOCK(VueMasterImage4)
|
the_stack_data/9832.c | #include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
/* -------------------------------------------------------------------------- */
/* program name */
static char *prog = "splitNet";
/* for line read in from net file */
static char line[LINE_MAX];
static char chrom[LINE_MAX];
/* command line options, defaults */
static struct options {
char *in_file;
char *out_dir;
int out_dir_len;
char *suffix;
} opt = {
"/dev/stdin",
NULL,
0,
".net"
};
/* -------------------------------------------------------------------------- */
/* unix-like error message */
static void unix_error(char *msg) {
fprintf(stderr, "%s: %s: %s\n", prog, msg, strerror(errno));
exit(EXIT_FAILURE);
}
/* strdup, check for errors */
static char *Strdup(const char *s1) {
char *p;
if ((p = strdup(s1)) == NULL) {
unix_error("stdrup failed");
}
return(p);
}
/* fopen, check for errors */
static FILE *Fopen(const char *filename, const char *mode) {
FILE *p;
if ((p = fopen(filename, mode)) == NULL) {
unix_error("fopen failed");
}
return(p);
}
/* fgets, check for errors */
static char *Fgets(char *s, int n, FILE *stream) {
char *p;
if ((p = fgets(s, n, stream)) == NULL) {
if (feof(stream) != 0) {
return(NULL);
} else if (ferror(stream) != 0) {
unix_error("fgets failed");
} else {
fprintf(stderr, "%s: fgets failed really badly\n", prog);
exit(EXIT_FAILURE);
}
}
return(p);
}
/* malloc, checking for errors */
void *Malloc(size_t size) {
void *p;
if ((p = malloc(size)) == NULL) {
unix_error("malloc failed");
}
return(p);
}
/* fclose, checking for erros */
void Fclose(FILE *stream) {
if (fclose(stream) == EOF) {
unix_error("fclose failed");
}
}
/* -------------------------------------------------------------------------- */
/* print usage information */
static void usage(int status) {
if (status == EXIT_SUCCESS) {
printf("Usage: %s [-h] [-i <input file>] -o <output dir>\n", prog);
printf(" -h help\n");
printf(" -i combined net file to split [defaults to stdin]\n");
printf(" -o directory where the split nets will be placed\n");
} else {
fprintf(stderr, "%s: Try '%s -h' for usage information.\n", prog, prog);
}
exit(status);
}
/* process command line arguments */
static void parse_args(int argc, char **argv) {
extern char *optarg;
extern int optopt;
int c;
while((c = getopt(argc, argv, ":hi:o:")) != -1) {
switch(c) {
case 'h':
usage(EXIT_SUCCESS);
break;
case 'i':
opt.in_file = Strdup((const char *) optarg);
break;
case 'o':
opt.out_dir = Strdup((const char *) optarg);
opt.out_dir_len = (int) strlen(opt.out_dir);
break;
case ':':
fprintf(stderr, "%s: Missing argument for -%c.\n", prog, (char) optopt);
usage(EXIT_FAILURE);
break;
case '?':
fprintf(stderr, "%s: Unrecognized option -%c.\n", prog, (char) optopt);
usage(EXIT_FAILURE);
}
}
if (opt.out_dir == NULL) {
fprintf(stderr, "%s: -o argument required\n", prog);
usage(EXIT_FAILURE);
}
}
/* -------------------------------------------------------------------------- */
/* split a net file */
static void split_net(void) {
FILE *input;
FILE *output;
int filename_len;
char *filename;
int open = 0;
input = Fopen(opt.in_file, "r");
/* make the output directory */
if ((mkdir(opt.out_dir, S_IRWXU | S_IRWXG | S_IRWXO) == -1)) {
if (errno != EEXIST) {
unix_error("mkdir failed");
}
}
/* very simple splitter */
while (Fgets(line, LINE_MAX, input) != NULL) {
/* find the net line */
if (strstr(line, "net") == line) {
/* get the chrom name */
if (sscanf(line, "net %s ", chrom) != 1) {
fprintf(stderr, "%s: Can't parse the following line:\n", prog);
fprintf(stderr, "%s", line);
exit(EXIT_FAILURE);
}
/* build the output filename */
filename_len = opt.out_dir_len + (int) strlen(chrom) + (int) strlen(opt.suffix) + 2;
filename = (char *) Malloc (filename_len * sizeof(char));
strcpy(filename, opt.out_dir);
strcat(filename, "/");
strcat(filename, chrom);
strcat(filename, opt.suffix);
/* close if necessary */
if (open) {
Fclose(output);
}
output = Fopen(filename, "w");
free(filename);
fprintf(output, "%s", line);
open = 1;
continue;
}
if (! open) {
fprintf(stderr, "Out of synch (didn't find net line?)\n");
exit(EXIT_FAILURE);
}
fprintf(output, "%s", line);
}
Fclose(input);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv) {
prog = argv[0];
parse_args(argc, argv);
split_net();
return(EXIT_SUCCESS);
}
|
the_stack_data/117208.c | /*
* Copyright (c) 1991-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that (i) the above copyright notices and this permission notice appear in
* all copies of the software and related documentation, and (ii) the names of
* Sam Leffler and Silicon Graphics may not be used in any advertising or
* publicity relating to the software without the specific, prior written
* permission of Sam Leffler and Silicon Graphics.
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#include <string.h>
#include <stdio.h>
/*
* Hack program to construct tables used to find
* runs of zeros and ones in Group 3 Fax encoding.
*/
dumparray(name, runs)
char *name;
unsigned char runs[256];
{
int i;
char *sep;
printf("static unsigned char %s[256] = {\n", name);
sep = " ";
for (i = 0; i < 256; i++) {
printf("%s%d", sep, runs[i]);
if (((i + 1) % 16) == 0) {
printf(", /* 0x%02x - 0x%02x */\n", i-15, i);
sep = " ";
} else
sep = ", ";
}
printf("\n};\n");
}
main()
{
unsigned char runs[2][256];
memset(runs[0], 0, 256*sizeof (char));
memset(runs[1], 0, 256*sizeof (char));
{ register int run, runlen, i;
runlen = 1;
for (run = 0x80; run != 0xff; run = (run>>1)|0x80) {
for (i = run-1; i >= 0; i--) {
runs[1][run|i] = runlen;
runs[0][(~(run|i)) & 0xff] = runlen;
}
runlen++;
}
runs[1][0xff] = runs[0][0] = 8;
}
dumparray("bruns", runs[0]);
dumparray("wruns", runs[1]);
}
/* vim: set ts=8 sts=8 sw=8 noet: */
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
|
the_stack_data/618503.c | /***
* MIT License
*
* Copyright (c) 2021 Konychev Valerii
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "string.h"
#include <stdint.h>
void *memcpy(void *dest, const void *src, size_t n)
{
uint8_t *d = dest;
const uint8_t *s = src;
while (n--)
*d++ = *s++;
return dest;
}
|
the_stack_data/40762037.c | /*
* isLessOrEqual - if x <= y then return 1, else return 0
* Example: isLessOrEqual(4,5) = 1.
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 24
* Rating: 3
*/
/* x<=y
<=> !(y<x) ,在(y+(-x))不溢出的情况下
<=> !(y+(-x)<0)
<=> !(((y+(~x+1))>>31)&1) 即:
两数和为负则return 0,
为正则return 1.
溢出时:两个参数彼此同号,其和与二者异号
<=> ((!(((y>>31)&1)^(((~x+1)>>31)&1))) ^ (((y+(~x+1))>>31)&1))
溢出的情况下:
1) 和溢出为负,y,(-x)是两个正数.此时一定有x<y成立 return 1
2) 和溢出为正,y,(-x)是两个负数.此时一定有x>y成立 return 0
那么有真值表
是否溢出 和是否为负 返回值
y+(-x) 0 0 1
0 1 0
1 0 0
1 1 1
综上:
*/
int isLessOrEqual(int x, int y) {
int sign_y=(y>>31)&1;
int sign_m_x=((~x+1)>>31)&1;
int sum=y+(~x+1);
int sign_sum=(sum>>31)&1;
int is_same_sign=(!(sign_y^sign_m_x));
int of_flag=is_same_sign&(sign_y^sign_sum);
return ((!(of_flag^sign_sum))|(!(~((~(1<<31))^x))));//注意当x==Tmin,x>0,(即两数异号不会溢出的情况)由于Tmin=-Tmin,会导致y+(-x)永远<0(而两数均为Tmin时==0)
//故判定失效,此时需要将x==Tmin特殊处理,即x==Tmin时总是返回1.
}
|
the_stack_data/915065.c | //
// main.c
// AoC
//
// Created by Matteo Negro on 01/12/20.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NOMEFILE "/Users/matteoblack/Desktop/AoC/AoC_1/AoC/input.txt"
#define ANNO 2020
typedef struct EL{
int Numero;
struct EL* pNext;
}NumeroList;
typedef NumeroList* ListaNum;
//Funz Lettura File
ListaNum LetturaFile(void);
//Stampa Lista
void StampaLista(ListaNum pListaStamp);
//Funz DAY1_1, cerca due val che sommati facciano 2020 e moltiplicali tra loro
int DAY1_1(ListaNum pLista);
//Funz DAY1_2, cerca tre val che sommati facciano 2020 e moltiplicali tra loro
int DAY1_2(ListaNum pLista);
int main() {
ListaNum pListaFile;
int result;
pListaFile = LetturaFile();
StampaLista(pListaFile);
result = DAY1_2(pListaFile);
printf("\nIl risultato è: %d\n", result);
return 0;
}
ListaNum LetturaFile(){
ListaNum pLista;
ListaNum pNuovoElem;
ListaNum pPrec;
int val;
int c;
FILE* pFile;
pPrec = NULL;
pLista = NULL;
pFile = fopen(NOMEFILE, "r");
if(pFile == NULL){
printf("Errore in APERTURA");
}else{
c = 0;
//Fai la ptima lettura
fscanf(pFile, "%d", &val);
pLista = malloc(sizeof(NumeroList));
pLista->Numero = val;
pNuovoElem = malloc(sizeof(NumeroList));
pLista->pNext = pNuovoElem;
//Ciclo lettura del File
while((fscanf(pFile, "%d", &val))!=EOF){
pNuovoElem->Numero = val;
pNuovoElem->pNext = malloc(sizeof(NumeroList));
pPrec = pNuovoElem;
pNuovoElem = pNuovoElem->pNext;
}
//Segno la fine della lista e cancello elemento in più
pPrec->pNext = NULL;
free(pNuovoElem);
}
fclose(pFile);
return pLista;
}
void StampaLista(ListaNum pListaStamp){
ListaNum pCurr;
pCurr = pListaStamp;
int c = 1;
printf("\nLista Num: \n\n");
while(pCurr!=NULL){
printf("%d- ",c);
printf("%d\n", pCurr->Numero);
pCurr = pCurr->pNext;
c++;
}
}
int DAY1_1(ListaNum pLista){
int day1;
int sum;
int END;
int in;
int ext;
ListaNum pCurrEXT;
ListaNum pCurrIN;
day1 = 0;
ext = 1;
END = 0;
pCurrEXT = pLista;
while((pCurrEXT!=NULL)&&(END == 0)){
in = 1;
pCurrIN = pLista;
while((pCurrIN!=NULL)&&(END == 0)){
if(in==ext) break;
sum = (pCurrEXT->Numero) + (pCurrIN->Numero);
if(sum == ANNO){
printf("%d.%d - SUM = %d + %d = %d\n", ext, in, pCurrEXT->Numero,pCurrIN->Numero, sum);
day1 = (pCurrEXT->Numero) * (pCurrIN->Numero);
END = 1;
break;
}
pCurrIN = pCurrIN->pNext;
in++;
}
pCurrEXT = pCurrEXT->pNext;
ext++;
}
return day1;
}
int DAY1_2(ListaNum pLista){
int day1;
int sum;
int END;
int in;
int ext;
int mid;
ListaNum pCurrEXT;
ListaNum pCurrIN;
ListaNum pCurrMID;
day1 = 0;
ext = 1;
END = 0;
pCurrEXT = pLista;
while((pCurrEXT!=NULL)&&(END == 0)){
mid = 1;
pCurrMID = pLista;
while((pCurrMID!=NULL)&&(END == 0)){
in = 1;
if(in==ext) break;
pCurrIN = pLista;
while((pCurrIN!=NULL)&&(END == 0)){
if((in==mid)||(ext==mid)) break;
sum = (pCurrEXT->Numero) + (pCurrIN->Numero) + (pCurrMID->Numero);
if(sum == ANNO){
printf("%d.%d.%d - SUM = %d + %d + %d = %d\n", ext, mid, in, pCurrEXT->Numero, pCurrIN->Numero, pCurrMID->Numero, sum);
day1 = (pCurrEXT->Numero) * (pCurrIN->Numero) * (pCurrMID->Numero);
END = 1;
break;
}
pCurrIN = pCurrIN->pNext;
in++;
}
pCurrMID = pCurrMID->pNext;
mid++;
}
pCurrEXT = pCurrEXT->pNext;
ext++;
}
return day1;
}
|
the_stack_data/932723.c | int min;
int max;
void f(int i, int j) {
if (j > i) {
min = i;
max = j;
} else {
min = j;
max = i;
}
}
void _start() {
f(1, -1);
}
|
the_stack_data/178266396.c | #include<stdio.h>
void bubble_sort(int arr[],int n)
{
int i,j,temp;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
}
int main()
{
int arr[100],n;
printf("Enter the size of the array: \n");
scanf("%d",&n);
printf("Enter %d numbers \n", n);
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
bubble_sort(arr,n);
for (int i = 0; i < n; i++)
{
printf("%d\t",arr[i]);
}
}
|
the_stack_data/248581544.c | // RUN: %check_clang_tidy %s google-readability-casting %t -- -- -x c
// The testing script always adds .cpp extension to the input file name, so we
// need to run clang-tidy directly in order to verify handling of .c files:
// RUN: clang-tidy --checks=-*,google-readability-casting %s -- -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:'
// RUN: cp %s %t.main_file.cpp
// RUN: clang-tidy --checks=-*,google-readability-casting -header-filter='.*' %t.main_file.cpp -- -I%S -DTEST_INCLUDE -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:'
#ifdef TEST_INCLUDE
#undef TEST_INCLUDE
#include "google-readability-casting.c"
#else
void f(const char *cpc) {
const char *cpc2 = (const char*)cpc;
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant cast to the same type [google-readability-casting]
// CHECK-FIXES: const char *cpc2 = cpc;
char *pc = (char*)cpc;
typedef const char *Typedef1;
(Typedef1)cpc;
}
#endif
|
the_stack_data/153268033.c | /*
* This code was written by Rich Felker in 2010; no copyright is claimed.
* This code is in the public domain. Attribution is appreciated but
* unnecessary.
*/
#include <stdlib.h>
#include <wchar.h>
int mblen(const char *s, size_t n)
{
return mbtowc(0, s, n);
}
|
the_stack_data/25137129.c | int
main()
{
int arr[2];
int *p;
arr[0] = 2;
arr[1] = 3;
p = &arr[0];
if(*(p++) != 2)
return 1;
if(*(p++) != 3)
return 2;
p = &arr[1];
if(*(p--) != 3)
return 1;
if(*(p--) != 2)
return 2;
p = &arr[0];
if(*(++p) != 3)
return 1;
p = &arr[1];
if(*(--p) != 2)
return 1;
return 0;
}
|
the_stack_data/108344.c | // Copyright (c) 2020, devgo.club
// All rights reserved.
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main(int argc, char const *argv[])
{
pid_t pid = fork();
if (pid < 0)
{
fprintf(stderr, "fork failed: %s\n", strerror(errno));
return errno;
}
else if (pid == 0)
{
// 子进程
for (int i = 60; i >= 0; i--)
{
sleep(1);
printf("[C] I'm child process, pid = %d, ppid = %d\n", getpid(), getppid());
}
}
else
{
// 父进程
for (int i = 10; i >= 0; i--)
{
sleep(1);
printf("[P] I'm parent process, pid = %d\n", getpid());
}
}
return EXIT_SUCCESS;
}
// int main(int argc, char const *argv[])
// {
// pid_t pid = fork();
// if (pid < 0)
// {
// fprintf(stderr, "fork failed: %s\n", strerror(errno));
// return errno;
// }
// else if (pid == 0)
// {
// // 子进程
// for (int i = 10; i >= 0; i--)
// {
// sleep(1);
// printf("[C] I'm child process, pid = %d, ppid = %d\n", getpid(), getppid());
// }
// }
// else
// {
// // 父进程
// for (int i = 60; i >= 0; i--)
// {
// sleep(1);
// printf("[P] I'm parent process, pid = %d\n", getpid());
// }
// }
// return EXIT_SUCCESS;
// } |
the_stack_data/86075333.c | #if LV_BUILD_TEST
#include "../lvgl.h"
#include "../demos/lv_demos.h"
#include "unity/unity.h"
#include "lv_test_helpers.h"
#include "lv_test_indev.h"
static void loop_through_stress_test(void)
{
#if LV_USE_DEMO_STRESS
lv_test_indev_wait(LV_DEMO_STRESS_TIME_STEP*33); /* FIXME: remove magic number of states */
#endif
}
void test_demo_stress(void)
{
#if LV_USE_DEMO_STRESS
lv_demo_stress();
#endif
/* loop once to allow objects to be created */
loop_through_stress_test();
uint32_t mem_before = lv_test_get_free_mem();
/* loop 10 more times */
for(uint32_t i = 0; i < 10; i++) {
loop_through_stress_test();
}
TEST_ASSERT_EQUAL(mem_before, lv_test_get_free_mem());
}
#endif
|
the_stack_data/67324634.c | /*
@@@@ PROGRAM NAME: knkcch06e11.c
@@@@ FLAGS: -std=c99
@@@@ PROGRAM STATEMENT: What output does the following program
fragment produce?
sum=0;
for(i=0;i<10;i++){
if(i%2)
continue;
sum+=i;
}
printf("%d\n",sum);
*/
#include<stdio.h>
//------------------------START OF MAIN()--------------------------------------
int main(void)
{
printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
int sum=0;
for(int i=0;i<10;i++){
if(i%2)
continue;
sum+=i;
}
printf("sum= %d",sum);
printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
return 0;
}
//-------------------------END OF MAIN()---------------------------------------
//---------------------------------------------------------------------------
/*
OUTPUT:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sum= 20
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
//--------------------------------------------------------------------------- |
the_stack_data/145258.c | /*numPass=0, numTotal=6
Verdict:WRONG_ANSWER, Visibility:1, Input:"18", ExpOutput:"3
", Output:""
Verdict:WRONG_ANSWER, Visibility:1, Input:"4", ExpOutput:"0
", Output:""
Verdict:WRONG_ANSWER, Visibility:1, Input:"24", ExpOutput:"4
", Output:""
Verdict:WRONG_ANSWER, Visibility:0, Input:"40", ExpOutput:"5
", Output:""
Verdict:WRONG_ANSWER, Visibility:0, Input:"100", ExpOutput:"8
", Output:""
Verdict:WRONG_ANSWER, Visibility:0, Input:"70", ExpOutput:"7
", Output:""
*/
#include<stdio.h>
int main()
{
int n;
scanf("%d",n);
return 0;
} |
the_stack_data/61076627.c | /*
Simple calculator project
by Kelvin Mugambi
Last updated on 15 Feb 2022
c99 compiler
MIT LICENSE
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
//variable declaration
char name [100];
int n1,n2,sum,product,diff;
float quot;
printf("Simple Calculator!/n");
//input
printf("Enter your name:");
gets(name);
printf("Enter two integers:");
scanf("%d%d",&n1,&n2);
//computations
sum = n1 + n2;
diff = n1 - n2;
product = n1 * n2;
quot = (float) n1/n2;
//output
printf("Hey %s,here are the results:\n",name);
printf("%d+%d=%d\n",n1,n2,sum);
printf("%d-%d=%d\n",n1,n2,diff);
printf("%d*%d=%d\n",n1,n2,product);
printf("%d/%d=%f\n",n1,n2,quot);
return 0;
}
|
the_stack_data/482805.c | #define P_PORTB 0x38
#define P_DDRB 0x37
main()
{
char * p_PortB = (char *)P_PORTB;
char * p_DirB = (char *)P_DDRB;
volatile int i=0;
*p_DirB = 0x01;
while(1)
{
for(i=0;i<20000;i++);
*p_PortB^=0x1;
}
}
|
the_stack_data/89199881.c | #include <time.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <dirent.h>
#include <unistd.h>
#include <stdarg.h>
#ifdef __MINGW32__
#include <windows.h>
#else
#include <pthread.h>
#include <termios.h>
#include <sys/ioctl.h>
#endif
#define WM_TOOL_PATH_MAX 256
#define WM_TOOL_ONCE_READ_LEN 1024
#define WM_TOOL_RUN_IMG_HEADER_LEN 0x100
#define WM_TOOL_SECBOOT_IMG_ADDR (0x2100)
#define WM_TOOL_SECBOOT_HEADER_LEN (0x100)
#define WM_TOOL_SECBOOT_HEADER_POS (WM_TOOL_SECBOOT_IMG_ADDR - WM_TOOL_SECBOOT_HEADER_LEN)
#define WM_TOOL_SECBOOT_IMG_AREA_TOTAL_LEN (56 * 1024)
#define WM_TOOL_IMG_HEAD_MAGIC_NO (0xA0FFFF9F)
#define WM_TOOL_DEFAULT_BAUD_RATE 115200
#define WM_TOOL_DOWNLOAD_TIMEOUT_SEC (60 * 1)
#define WM_TOOL_USE_1K_XMODEM 1 /* 1 for use 1k_xmodem 0 for xmodem */
/* Xmodem Frame form: <SOH><blk #><255-blk #><--128 data bytes--><CRC hi><CRC lo> */
#define XMODEM_SOH 0x01
#define XMODEM_STX 0x02
#define XMODEM_EOT 0x04
#define XMODEM_ACK 0x06
#define XMODEM_NAK 0x15
#define XMODEM_CAN 0x18
#define XMODEM_CRC_CHR 'C'
#define XMODEM_CRC_SIZE 2 /* Crc_High Byte + Crc_Low Byte */
#define XMODEM_FRAME_ID_SIZE 2 /* Frame_Id + 255-Frame_Id */
#define XMODEM_DATA_SIZE_SOH 128 /* for Xmodem protocol */
#define XMODEM_DATA_SIZE_STX 1024 /* for 1K xmodem protocol */
#if (WM_TOOL_USE_1K_XMODEM)
#define XMODEM_DATA_SIZE XMODEM_DATA_SIZE_STX
#define XMODEM_HEAD XMODEM_STX
#else
#define XMODEM_DATA_SIZE XMODEM_DATA_SIZE_SOH
#define XMODEM_HEAD XMODEM_SOH
#endif
#ifdef WM_DEBUG
#define WM_TOOL_DBG_PRINT wm_tool_printf
#else
#define WM_TOOL_DBG_PRINT(...)
#endif
typedef enum {
WM_TOOL_DL_ACTION_NONE = 0,
WM_TOOL_DL_ACTION_AT,
WM_TOOL_DL_ACTION_RTS
} wm_tool_dl_action_e;
typedef enum {
WM_TOOL_DL_ERASE_NONE = 0,
WM_TOOL_DL_ERASE_SECBOOT,
WM_TOOL_DL_ERASE_ALL
} wm_tool_dl_erase_e;
typedef enum {
WM_TOOL_DL_TYPE_IMAGE = 0,
WM_TOOL_DL_TYPE_FLS
} wm_tool_dl_type_e;
typedef enum {
WM_TOOL_LAYOUT_TYPE_1M = 0,
WM_TOOL_LAYOUT_TYPE_2M = 3
} wm_tool_layout_type_e;
typedef enum {
WM_TOOL_ZIP_TYPE_UNCOMPRESS = 0,
WM_TOOL_ZIP_TYPE_COMPRESS
} wm_tool_zip_type_e;
typedef enum {
WM_TOOL_CRC32_REFLECT_OUTPUT = 1,
WM_TOOL_CRC32_REFLECT_INPUT = 2
} wm_tool_crc32_reflect_e;
typedef enum {
WM_TOOL_SHOW_LOG_NONE = 0,
WM_TOOL_SHOW_LOG_STR,
WM_TOOL_SHOW_LOG_HEX
} wm_tool_show_log_e;
typedef struct {
unsigned int magic_no;
unsigned short img_type;
unsigned short zip_type;
unsigned int run_img_addr;
unsigned int run_img_len;
unsigned int run_org_checksum;
unsigned int upd_img_addr;
unsigned int upd_img_len;
unsigned int upd_checksum;
unsigned int upd_no;
unsigned char ver[16];
unsigned int hd_checksum;
} wm_tool_firmware_booter_t;
const static char *wm_tool_version = "1.0.4";
static int wm_tool_show_usage = 0;
static int wm_tool_list_com = 0;
static int wm_tool_show_ver = 0;
static char wm_tool_serial_path[WM_TOOL_PATH_MAX] = "/dev/ttyS0";
static unsigned int wm_tool_download_serial_rate = WM_TOOL_DEFAULT_BAUD_RATE;
static unsigned int wm_tool_normal_serial_rate = WM_TOOL_DEFAULT_BAUD_RATE;
static wm_tool_dl_action_e wm_tool_dl_action = WM_TOOL_DL_ACTION_NONE;
static wm_tool_dl_erase_e wm_tool_dl_erase = WM_TOOL_DL_ERASE_NONE;
static wm_tool_dl_type_e wm_tool_dl_type = WM_TOOL_DL_TYPE_IMAGE;
static char *wm_tool_download_image = NULL;
static char *wm_tool_input_binary = NULL;
static char *wm_tool_output_image = NULL;
static char *wm_tool_secboot_image = NULL;
static unsigned int wm_tool_src_binary_len = 0;
static unsigned int wm_tool_src_binary_crc = 0;
static int wm_tool_is_debug = 0;
static wm_tool_layout_type_e wm_tool_image_type = WM_TOOL_LAYOUT_TYPE_1M;
static wm_tool_zip_type_e wm_tool_zip_type = WM_TOOL_ZIP_TYPE_COMPRESS;
static unsigned int wm_tool_upd_addr = 0x90000;
static unsigned int wm_tool_run_addr = 0x10100;
static unsigned int wm_tool_file_crc = 0xFFFFFFFF;
static wm_tool_show_log_e wm_tool_show_log_type = WM_TOOL_SHOW_LOG_NONE;
#ifdef __MINGW32__
#ifndef CBR_2000000
#define CBR_2000000 2000000
#endif
#ifndef CBR_1000000
#define CBR_1000000 1000000
#endif
#ifndef CBR_921600
#define CBR_921600 921600
#endif
#ifndef CBR_460800
#define CBR_460800 460800
#endif
static DWORD wm_tool_uart_block = 0;
static HANDLE wm_tool_uart_handle = NULL;
const static int wm_tool_uart_speed_array[] = {CBR_2000000, CBR_1000000, CBR_921600, CBR_460800, CBR_115200, CBR_38400,
CBR_19200, CBR_9600, CBR_4800, CBR_2400, CBR_1200};
#else /* __MINGW32__ */
#ifndef B2000000
#define B2000000 2000000
#endif
#ifndef B1000000
#define B1000000 1000000
#endif
#ifndef B921600
#define B921600 921600
#endif
#ifndef B460800
#define B460800 460800
#endif
static int wm_tool_uart_fd = -1;
static struct termios wm_tool_saved_serial_cfg;
const static int wm_tool_uart_speed_array[] = {B2000000, B1000000, B921600, B460800, B115200, B38400,
B19200, B9600, B4800, B2400, B1200};
#endif /* __MINGW32__ */
const static int wm_tool_uart_name_array[] = {2000000, 1000000, 921600, 460800, 115200, 38400,
19200, 9600, 4800, 2400, 1200};
const static unsigned char wm_tool_chip_cmd_b115200[] = {0x21, 0x0a, 0x00, 0x97, 0x4b, 0x31, 0x00, 0x00, 0x00, 0x00, 0xc2, 0x01, 0x00};
const static unsigned char wm_tool_chip_cmd_b460800[] = {0x21, 0x0a, 0x00, 0x07, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x08, 0x07, 0x00};
const static unsigned char wm_tool_chip_cmd_b921600[] = {0x21, 0x0a, 0x00, 0x5d, 0x50, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00};
const static unsigned char wm_tool_chip_cmd_b1000000[] = {0x21, 0x0a, 0x00, 0x5e, 0x3d, 0x31, 0x00, 0x00, 0x00, 0x40, 0x42, 0x0f, 0x00};
const static unsigned char wm_tool_chip_cmd_b2000000[] = {0x21, 0x0a, 0x00, 0xef, 0x2a, 0x31, 0x00, 0x00, 0x00, 0x80, 0x84, 0x1e, 0x00};
const static unsigned char wm_tool_chip_cmd_get_mac[] = {0x21, 0x06, 0x00, 0xea, 0x2d, 0x38, 0x00, 0x00, 0x00};
static const unsigned int wm_tool_crc32_tab[] = {0x00000000L, 0x77073096L, 0xee0e612cL,
0x990951baL, 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L,
0x0edb8832L, 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL,
0x7eb17cbdL, 0xe7b82d07L, 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L,
0xf3b97148L, 0x84be41deL, 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L,
0x83d385c7L, 0x136c9856L, 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL,
0x14015c4fL, 0x63066cd9L, 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L,
0x4c69105eL, 0xd56041e4L, 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L,
0xd20d85fdL, 0xa50ab56bL, 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L,
0xacbcf940L, 0x32d86ce3L, 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L,
0x26d930acL, 0x51de003aL, 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L,
0x56b3c423L, 0xcfba9599L, 0xb8bda50fL, 0x2802b89eL, 0x5f058808L,
0xc60cd9b2L, 0xb10be924L, 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL,
0xb6662d3dL, 0x76dc4190L, 0x01db7106L, 0x98d220bcL, 0xefd5102aL,
0x71b18589L, 0x06b6b51fL, 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L,
0x0f00f934L, 0x9609a88eL, 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL,
0x91646c97L, 0xe6635c01L, 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L,
0xf262004eL, 0x6c0695edL, 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L,
0x65b0d9c6L, 0x12b7e950L, 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL,
0x15da2d49L, 0x8cd37cf3L, 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL,
0xa3bc0074L, 0xd4bb30e2L, 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL,
0xd3d6f4fbL, 0x4369e96aL, 0x346ed9fcL, 0xad678846L, 0xda60b8d0L,
0x44042d73L, 0x33031de5L, 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL,
0x270241aaL, 0xbe0b1010L, 0xc90c2086L, 0x5768b525L, 0x206f85b3L,
0xb966d409L, 0xce61e49fL, 0x5edef90eL, 0x29d9c998L, 0xb0d09822L,
0xc7d7a8b4L, 0x59b33d17L, 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL,
0xedb88320L, 0x9abfb3b6L, 0x03b6e20cL, 0x74b1d29aL, 0xead54739L,
0x9dd277afL, 0x04db2615L, 0x73dc1683L, 0xe3630b12L, 0x94643b84L,
0x0d6d6a3eL, 0x7a6a5aa8L, 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L,
0x7d079eb1L, 0xf00f9344L, 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL,
0xf762575dL, 0x806567cbL, 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L,
0x89d32be0L, 0x10da7a5aL, 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L,
0x17b7be43L, 0x60b08ed5L, 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L,
0x4fdff252L, 0xd1bb67f1L, 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL,
0xd80d2bdaL, 0xaf0a1b4cL, 0x36034af6L, 0x41047a60L, 0xdf60efc3L,
0xa867df55L, 0x316e8eefL, 0x4669be79L, 0xcb61b38cL, 0xbc66831aL,
0x256fd2a0L, 0x5268e236L, 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L,
0x5505262fL, 0xc5ba3bbeL, 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L,
0xc2d7ffa7L, 0xb5d0cf31L, 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L,
0xec63f226L, 0x756aa39cL, 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL,
0x72076785L, 0x05005713L, 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL,
0x0cb61b38L, 0x92d28e9bL, 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L,
0x86d3d2d4L, 0xf1d4e242L, 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL,
0xf6b9265bL, 0x6fb077e1L, 0x18b74777L, 0x88085ae6L, 0xff0f6a70L,
0x66063bcaL, 0x11010b5cL, 0x8f659effL, 0xf862ae69L, 0x616bffd3L,
0x166ccf45L, 0xa00ae278L, 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L,
0xa7672661L, 0xd06016f7L, 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL,
0xd9d65adcL, 0x40df0b66L, 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L,
0x47b2cf7fL, 0x30b5ffe9L, 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L,
0x24b4a3a6L, 0xbad03605L, 0xcdd70693L, 0x54de5729L, 0x23d967bfL,
0xb3667a2eL, 0xc4614ab8L, 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L,
0xc30c8ea1L, 0x5a05df1bL, 0x2d02ef8dL};
static void wm_tool_stdin_to_uart(void);
/* ============================ zlib gzip ================================== */
#define ALLOC(size) zcalloc((voidp)0, 1, size)
#define TRYFREE(p) {if (p) zcfree((voidp)0, p);}
#define BINARY 0
#define ASCII 1
#define UNKNOWN 2
#define STORED_BLOCK 0
#define STATIC_TREES 1
#define DYN_TREES 2
#define REP_3_6 16
#define REPZ_3_10 17
#define REPZ_11_138 18
#define MAX_BL_BITS 7
#define BASE 65521 /* largest prime smaller than 65536 */
#define NMAX 5552
#define DO1(buf) {s1 += *buf++; s2 += s1;}
#define DO2(buf) DO1(buf); DO1(buf);
#define DO4(buf) DO2(buf); DO2(buf);
#define DO8(buf) DO4(buf); DO4(buf);
#define DO16(buf) DO8(buf); DO8(buf);
#define Z_OK 0
#define Z_STREAM_END 1
#define Z_ERRNO (-1)
#define Z_STREAM_ERROR (-2)
#define Z_DATA_ERROR (-3)
#define Z_MEM_ERROR (-4)
#define Z_BUF_ERROR (-5)
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
#define Z_BEST_SPEED 1
#define Z_BEST_COMPRESSION 9
#define Z_DEFAULT_COMPRESSION (-1)
#define DEFLATED 8
#ifndef WBITS
# define WBITS 15 /* 32K window */
#endif
#ifndef MEM_LEVEL
# define MEM_LEVEL 8
#endif
#define Z_BUFSIZE 4096
#define GZ_MAGIC_1 0x1f
#define GZ_MAGIC_2 0x8b
#ifndef OS_CODE
# define OS_CODE 0x03 /* assume Unix */
#endif
#ifndef TOO_FAR
# define TOO_FAR 4096
#endif
#define Z_NO_FLUSH 0
#define Z_FINISH 4
#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */
#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
#define COMMENT 0x10 /* bit 4 set: file comment present */
#define RESERVED 0xE0 /* bits 5..7: reserved */
#define LENGTH_CODES 29/* number of length codes, not counting the special END_BLOCK code */
#define LITERALS 256/* number of literal bytes 0..255 */
#define L_CODES (LITERALS+1+LENGTH_CODES)/* number of Literal or Length codes, including the END_BLOCK code */
#define D_CODES 30/* number of distance codes */
#define BL_CODES 19/* number of codes used to transfer the bit lengths */
#define HEAP_SIZE (2*L_CODES+1)/* maximum heap size */
#define END_BLOCK 256
#define MAX_BITS 15
#define MAX_MEM_LEVEL 9
#define MIN_MATCH 3
#define MAX_MATCH 258
#define Z_UNKNOWN 2
#define INIT_STATE 42
#define BUSY_STATE 113
#define FINISH_STATE 666
#define NIL 0
#define Z_FILTERED 1
#define Z_HUFFMAN_ONLY 2
#define Z_DEFAULT_STRATEGY 0
#define SMALLEST 1
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
#define ERR_RETURN(strm,err) return (strm->msg=z_errmsg[1-err], err)
#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
#define put_short(s, w) { \
put_byte(s, (uch)((w) & 0xff)); \
put_byte(s, (uch)((ush)(w) >> 8)); \
}
#define INSERT_STRING(s, str, match_head) \
(UPDATE_HASH(s, s->ins_h, s->window[(str) + MIN_MATCH-1]), \
s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \
s->head[s->ins_h] = (str))
#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
#define check_match(s, start, match, length)
#define d_code(dist) \
((dist) < 256 ? dist_code[dist] : dist_code[256+((dist)>>7)])
#define FLUSH_BLOCK_ONLY(s, eof) { \
ct_flush_block(s, (s->block_start >= 0L ? \
(char*)&s->window[(unsigned)s->block_start] : \
(char*)Z_NULL), (long)s->strstart - s->block_start, (eof)); \
s->block_start = s->strstart; \
flush_pending(s->strm); \
}
#define FLUSH_BLOCK(s, eof) { \
FLUSH_BLOCK_ONLY(s, eof); \
if (s->strm->avail_out == 0) return 1; \
}
#define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
#define MAX(a,b) (a >= b ? a : b)
#define Buf_size (8 * 2*sizeof(char))
#define smaller(tree, n, m, depth) \
(tree[n].Freq < tree[m].Freq || \
(tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
#define pqremove(s, tree, top) \
{\
top = s->heap[SMALLEST]; \
s->heap[SMALLEST] = s->heap[s->heap_len--]; \
pqdownheap(s, tree, SMALLEST); \
}
#ifndef local
# define local static
#endif
#ifndef __P
#define __P(args) args
#endif
#define ZALLOC(strm, items, size) \
(*((strm)->zalloc))((strm)->opaque, (items), (size))
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidp)(addr))
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
#define Assert(cond,msg)
#ifndef Byte
typedef unsigned char Byte; /* 8 bits */
#endif
#ifndef uInt
typedef unsigned int uInt; /* may be 16 or 32 bits */
#endif
#ifndef uLong
typedef unsigned long uLong; /* 32 bits or more */
#endif
typedef Byte *voidp;
typedef voidp gzFile;
typedef unsigned char uch;
typedef unsigned long ulg;
typedef unsigned short ush;
typedef ush Pos;
typedef unsigned IPos;
typedef voidp (*alloc_func) __P((voidp opaque, uInt items, uInt size));
typedef void (*free_func) __P((voidp opaque, voidp address));
typedef uLong (*check_func) __P((uLong check, Byte *buf, uInt len));
typedef struct z_stream_s {
Byte *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
uLong total_in; /* total nb of input bytes read so far */
Byte *next_out; /* next output byte should be put there */
uInt avail_out; /* remaining free space at next_out */
uLong total_out; /* total nb of bytes output so far */
char *msg; /* last error message, NULL if no error */
struct internal_state *state; /* not visible by applications */
alloc_func zalloc; /* used to allocate the internal state */
free_func zfree; /* used to free the internal state */
voidp opaque; /* private data object passed to zalloc and zfree */
Byte data_type; /* best guess about the data type: ascii or binary */
} z_stream;
typedef struct gz_stream {
z_stream stream;
int z_err; /* error code for last stream operation */
int z_eof; /* set if end of input file */
FILE *file; /* .gz file */
Byte *inbuf; /* input buffer */
Byte *outbuf; /* output buffer */
uLong crc; /* crc32 of uncompressed data */
char *msg; /* error message */
char *path; /* path name for debugging only */
int transparent; /* 1 if input file is not a .gz file */
char mode; /* 'w' or 'r' */
} gz_stream;
/* Data structure describing a single value and its code string. */
typedef struct ct_data_s {
union {
ush freq; /* frequency count */
ush code; /* bit string */
} fc;
union {
ush dad; /* father node in Huffman tree */
ush len; /* length of bit string */
} dl;
} ct_data;
struct static_tree_desc_s {
ct_data *static_tree; /* static tree or NULL */
int *extra_bits; /* extra bits for each code or NULL */
int extra_base; /* base index for extra_bits */
int elems; /* max number of elements in the tree */
int max_length; /* max bit length for the codes */
};
typedef struct static_tree_desc_s static_tree_desc;
typedef struct tree_desc_s {
ct_data *dyn_tree; /* the dynamic tree */
int max_code; /* largest code with non zero frequency */
static_tree_desc *stat_desc; /* the corresponding static tree */
} tree_desc;
typedef struct inflate_huft_s inflate_huft;
struct inflate_huft_s {
union {
struct {
char Exop; /* number of extra bits or operation */
char Bits; /* number of bits in this code or subcode */
} what;
Byte *pad; /* pad structure to a power of 2 (4 bytes for */
} word; /* 16-bit, 8 bytes for 32-bit machines) */
union {
uInt Base; /* literal, length base, or distance base */
inflate_huft *Next; /* pointer to next level of table */
} more;
};
/* inflate codes private state */
struct inflate_codes_state {
/* mode */
enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
START, /* x: set up for LEN */
LEN, /* i: get length/literal/eob next */
LENEXT, /* i: getting length extra (have base) */
DIST, /* i: get distance next */
DISTEXT, /* i: getting distance extra */
COPY, /* o: copying bytes in window, waiting for space */
LIT, /* o: got literal, waiting for output space */
WASH, /* o: got eob, possibly still output waiting */
END, /* x: got eob and all data flushed */
BAD} /* x: got error */
mode; /* current inflate_codes mode */
/* mode dependent information */
uInt len;
union {
struct {
inflate_huft *tree; /* pointer into tree */
uInt need; /* bits needed */
} code; /* if LEN or DIST, where in tree */
uInt lit; /* if LIT, literal */
struct {
uInt get; /* bits to get for extra */
uInt dist; /* distance back to copy from */
} copy; /* if EXT or COPY, where and how much */
} sub; /* submode */
/* mode independent information */
Byte lbits; /* ltree bits decoded per branch */
Byte dbits; /* dtree bits decoder per branch */
inflate_huft *ltree; /* literal/length/eob tree */
inflate_huft *dtree; /* distance tree */
};
/* inflate blocks semi-private state */
struct inflate_blocks_state {
/* mode */
enum {
TYPE, /* get type bits (3, including end bit) */
LENS, /* get lengths for stored */
STORED, /* processing stored block */
TABLE, /* get table lengths */
BTREE, /* get bit lengths tree for a dynamic block */
DTREE, /* get length, distance trees for a dynamic block */
CODES, /* processing fixed or dynamic block */
DRY, /* output remaining window bytes */
DONE, /* finished last block, done */
INF_ERROR}/* got a data error--stuck here */
mode; /* current inflate_block mode */
/* mode dependent information */
union {
uInt left; /* if STORED, bytes left to copy */
struct {
uInt table; /* table lengths (14 bits) */
uInt index; /* index into blens (or border) */
uInt *blens; /* bit lengths of codes */
uInt bb; /* bit length tree depth */
inflate_huft *tb; /* bit length decoding tree */
} trees; /* if DTREE, decoding info for trees */
struct inflate_codes_state
*codes; /* if CODES, current state */
} sub; /* submode */
uInt last; /* true if this block is the last block */
/* mode independent information */
uInt bitk; /* bits in bit buffer */
uLong bitb; /* bit buffer */
Byte *window; /* sliding window */
Byte *end; /* one byte after sliding window */
Byte *read; /* window read pointer */
Byte *write; /* window write pointer */
check_func checkfn; /* check function */
uLong check; /* check on output */
};
typedef struct internal_state {
z_stream *strm; /* pointer back to this zlib stream */
int status; /* as the name implies */
Byte *pending_buf; /* output still pending */
Byte *pending_out; /* next pending byte to output to the stream */
int pending; /* nb of bytes in the pending buffer */
uLong adler; /* adler32 of uncompressed data */
int noheader; /* suppress zlib header and adler32 */
Byte data_type; /* UNKNOWN, BINARY or ASCII */
Byte method; /* STORED (for zip only) or DEFLATED */
/* used by deflate.c: */
uInt w_size; /* LZ77 window size (32K by default) */
uInt w_bits; /* log2(w_size) (8..16) */
uInt w_mask; /* w_size - 1 */
Byte *window;
/* Sliding window. Input bytes are read into the second half of the window,
* and move to the first half later to keep a dictionary of at least wSize
* bytes. With this organization, matches are limited to a distance of
* wSize-MAX_MATCH bytes, but this ensures that IO is always
* performed with a length multiple of the block size. Also, it limits
* the window size to 64K, which is quite useful on MSDOS.
* To do: use the user input buffer as sliding window.
*/
ulg window_size;
/* Actual size of window: 2*wSize, except when the user input buffer
* is directly used as sliding window.
*/
Pos *prev;
/* Link to older string with same hash index. To limit the size of this
* array to 64K, this link is maintained only for the last 32K strings.
* An index in this array is thus a window index modulo 32K.
*/
Pos *head; /* Heads of the hash chains or NIL. */
uInt ins_h; /* hash index of string to be inserted */
uInt hash_size; /* number of elements in hash table */
uInt hash_bits; /* log2(hash_size) */
uInt hash_mask; /* hash_size-1 */
uInt hash_shift;
/* Number of bits by which ins_h must be shifted at each input
* step. It must be such that after MIN_MATCH steps, the oldest
* byte no longer takes part in the hash key, that is:
* hash_shift * MIN_MATCH >= hash_bits
*/
long block_start;
/* Window position at the beginning of the current output block. Gets
* negative when the window is moved backwards.
*/
uInt match_length; /* length of best match */
IPos prev_match; /* previous match */
int match_available; /* set if previous match exists */
uInt strstart; /* start of string to insert */
uInt match_start; /* start of matching string */
uInt lookahead; /* number of valid bytes ahead in window */
uInt prev_length;
/* Length of the best match at previous step. Matches not greater than this
* are discarded. This is used in the lazy match evaluation.
*/
uInt max_chain_length;
/* To speed up deflation, hash chains are never searched beyond this
* length. A higher limit improves compression ratio but degrades the
* speed.
*/
uInt max_lazy_match;
/* Attempt to find a better match only when the current match is strictly
* smaller than this value. This mechanism is used only for compression
* levels >= 4.
*/
# define max_insert_length max_lazy_match
/* Insert new strings in the hash table only if the match length is not
* greater than this length. This saves time but degrades compression.
* max_insert_length is used only for compression levels <= 3.
*/
int level; /* compression level (1..9) */
int strategy; /* favor or force Huffman coding*/
uInt good_match;
/* Use a faster search when the previous match is longer than this */
int nice_match; /* Stop searching when current match exceeds this */
/* used by trees.c: */
ct_data dyn_ltree[HEAP_SIZE]; /* literal and length tree */
ct_data dyn_dtree[2*D_CODES+1]; /* distance tree */
ct_data bl_tree[2*BL_CODES+1]; /* Huffman tree for the bit lengths */
tree_desc l_desc; /* descriptor for literal tree */
tree_desc d_desc; /* descriptor for distance tree */
tree_desc bl_desc; /* descriptor for bit length tree */
ush bl_count[MAX_BITS+1];
/* number of codes at each bit length for an optimal tree */
int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
int heap_len; /* number of elements in the heap */
int heap_max; /* element of largest frequency */
/* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
* The same heap array is used to build all trees.
*/
uch depth[2*L_CODES+1];
/* Depth of each subtree used as tie breaker for trees of equal frequency
*/
uch *l_buf; /* buffer for literals or lengths */
uInt lit_bufsize;
/* Size of match buffer for literals/lengths. There are 4 reasons for
* limiting lit_bufsize to 64K:
* - frequencies can be kept in 16 bit counters
* - if compression is not successful for the first block, all input
* data is still in the window so we can still emit a stored block even
* when input comes from standard input. (This can also be done for
* all blocks if lit_bufsize is not greater than 32K.)
* - if compression is not successful for a file smaller than 64K, we can
* even emit a stored file instead of a stored block (saving 5 bytes).
* This is applicable only for zip (not gzip or zlib).
* - creating new Huffman trees less frequently may not provide fast
* adaptation to changes in the input data statistics. (Take for
* example a binary file with poorly compressible code followed by
* a highly compressible string table.) Smaller buffer sizes give
* fast adaptation but have of course the overhead of transmitting
* trees more frequently.
* - I can't count above 4
*/
uInt last_lit; /* running index in l_buf */
ush *d_buf;
/* Buffer for distances. To simplify the code, d_buf and l_buf have
* the same number of elements. To use different lengths, an extra flag
* array would be necessary.
*/
ulg opt_len; /* bit length of current block with optimal trees */
ulg static_len; /* bit length of current block with static trees */
ulg compressed_len; /* total bit length of compressed file */
uInt matches; /* number of string matches in current block */
#ifdef DEBUG
ulg bits_sent; /* bit length of the compressed data */
#endif
ush bi_buf;
/* Output buffer. bits are inserted starting at the bottom (least
* significant bits).
*/
int bi_valid;
/* Number of valid bits in bi_buf. All bits above the last valid bit
* are always zero.
*/
/* mode */
enum {
METHOD, /* waiting for method byte */
FLAG, /* waiting for flag byte */
//START, /* make new blocks state */
BLOCKS, /* decompressing blocks */
CHECK4, /* four check bytes to go */
CHECK3, /* three check bytes to go */
CHECK2, /* two check bytes to go */
CHECK1, /* one check byte to go */
//DONE, /* finished check, done */
//INF_ERROR/* got an error--stay here */
}
mode; /* current inflate mode */
/* mode dependent information */
union {
uInt method; /* if FLAGS, method byte */
struct inflate_blocks_state
*blocks; /* if BLOCKS, current state */
struct {
uLong was; /* computed check value */
uLong need; /* stream check value */
} check; /* if CHECK, check values to compare */
} sub; /* submode */
/* mode independent information */
int nowrap; /* flag for no wrapper */
uInt wbits; /* log2(window size) (8..15, defaults to 15) */
} deflate_state;
typedef struct config_s {
ush good_length; /* reduce lazy search above this match length */
ush max_lazy; /* do not perform lazy search above this match length */
ush nice_length; /* quit search above this match length */
ush max_chain;
} config;
char *z_errmsg[] = {
"stream end", /* Z_STREAM_END 1 */
"", /* Z_OK 0 */
"file error", /* Z_ERRNO (-1) */
"stream error", /* Z_STREAM_ERROR (-2) */
"data error", /* Z_DATA_ERROR (-3) */
"insufficient memory", /* Z_MEM_ERROR (-4) */
"buffer error", /* Z_BUF_ERROR (-5) */
""};
local int base_length[LENGTH_CODES];
local int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
= {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
local uch length_code[MAX_MATCH-MIN_MATCH+1];
local int base_dist[D_CODES];
local int extra_dbits[D_CODES] /* extra bits for each distance code */
= {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
local ct_data static_ltree[L_CODES+2];
local uch dist_code[512];
local int base_dist[D_CODES];
local ct_data static_dtree[D_CODES];
local static_tree_desc static_l_desc =
{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
local static_tree_desc static_d_desc =
{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
local int extra_blbits[BL_CODES]/* extra bits for each bit length code */
= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
local static_tree_desc static_bl_desc =
{(ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
local uch bl_order[BL_CODES]
= {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
local config configuration_table[10] = {
/* good lazy nice chain */
/* 0 */ {0, 0, 0, 0}, /* store only */
/* 1 */ {4, 4, 8, 4}, /* maximum speed, no lazy matches */
/* 2 */ {4, 5, 16, 8},
/* 3 */ {4, 6, 32, 32},
/* 4 */ {4, 4, 16, 16}, /* lazy matches */
/* 5 */ {8, 16, 32, 32},
/* 6 */ {8, 16, 128, 128},
/* 7 */ {8, 32, 128, 256},
/* 8 */ {32, 128, 258, 1024},
/* 9 */ {32, 258, 258, 4096}}; /* maximum compression */
#define FIXEDH 530 /* number of hufts used by fixed tables */
local inflate_huft fixed_mem[FIXEDH];
#define next more.Next
#define Freq fc.freq
#define Code fc.code
#define Dad dl.dad
#define Len dl.len
local voidp zcalloc (opaque, items, size)
voidp opaque;
unsigned items;
unsigned size;
{
return calloc(items, size);
}
local void zcfree (opaque, ptr)
voidp opaque;
voidp ptr;
{
free(ptr);
}
local uLong crc32(crc, buf, len)
uLong crc;
Byte *buf;
uInt len;
{
if (buf == Z_NULL) return 0L;
crc = crc ^ 0xffffffffL;
if (len) do {
crc = wm_tool_crc32_tab[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
} while (--len);
return crc ^ 0xffffffffL;
}
local void zmemcpy(dest, source, len)
Byte* dest;
Byte* source;
uInt len;
{
if (len == 0) return;
do {
*dest++ = *source++; /* ??? to be unrolled */
} while (--len != 0);
}
local void zmemzero(dest, len)
Byte* dest;
uInt len;
{
if (len == 0) return;
do {
*dest++ = 0; /* ??? to be unrolled */
} while (--len != 0);
}
local uLong adler32(adler, buf, len)
uLong adler;
Byte *buf;
uInt len;
{
unsigned long s1 = adler & 0xffff;
unsigned long s2 = (adler >> 16) & 0xffff;
int k;
if (buf == Z_NULL) return 1L;
while (len > 0) {
k = len < NMAX ? len : NMAX;
len -= k;
while (k >= 16) {
DO16(buf);
k -= 16;
}
if (k != 0) do {
DO1(buf);
} while (--k);
s1 %= BASE;
s2 %= BASE;
}
return (s2 << 16) | s1;
}
local int read_buf(strm, buf, size)
z_stream *strm;
char *buf;
unsigned size;
{
unsigned len = strm->avail_in;
if (len > size) len = size;
if (len == 0) return 0;
strm->avail_in -= len;
if (!strm->state->noheader) {
strm->state->adler = adler32(strm->state->adler, strm->next_in, len);
}
zmemcpy((Byte *)buf, strm->next_in, len);
strm->next_in += len;
strm->total_in += len;
return (int)len;
}
local int inflate_trees_free(t, z)
inflate_huft *t; /* table to free */
z_stream *z; /* for zfree function */
/* Free the malloc'ed tables built by huft_build(), which makes a linked
list of the tables it made, with the links in a dummy first entry of
each table. */
{
register inflate_huft *p, *q;
/* Don't free fixed trees */
if (t >= fixed_mem && t <= fixed_mem + FIXEDH)
return Z_OK;
/* Go through linked list, freeing from the malloced (t[-1]) address. */
p = t;
while (p != Z_NULL)
{
q = (--p)->next;
ZFREE(z,p);
p = q;
}
return Z_OK;
}
local void inflate_codes_free(c, z)
struct inflate_codes_state *c;
z_stream *z;
{
inflate_trees_free(c->dtree, z);
inflate_trees_free(c->ltree, z);
ZFREE(z, c);
}
local int inflate_blocks_free(s, z, c)
struct inflate_blocks_state *s;
z_stream *z;
uLong *c;
{
if (s->checkfn != Z_NULL)
*c = s->check;
if (s->mode == BTREE || s->mode == DTREE)
ZFREE(z, s->sub.trees.blens);
if (s->mode == CODES)
inflate_codes_free(s->sub.codes, z);
ZFREE(z, s->window);
ZFREE(z, s);
return Z_OK;
}
local int deflateEnd (strm)
z_stream *strm;
{
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
TRY_FREE(strm, strm->state->window);
TRY_FREE(strm, strm->state->prev);
TRY_FREE(strm, strm->state->head);
TRY_FREE(strm, strm->state->pending_buf);
ZFREE(strm, strm->state);
strm->state = Z_NULL;
return Z_OK;
}
local int inflateEnd(z)
z_stream *z;
{
uLong c;
if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
return Z_STREAM_ERROR;
if (z->state->mode == BLOCKS)
inflate_blocks_free(z->state->sub.blocks, z, &c);
ZFREE(z, z->state);
z->state = Z_NULL;
return Z_OK;
}
local int destroy (s)
gz_stream *s;
{
int err = Z_OK;
if (!s) return Z_STREAM_ERROR;
TRYFREE(s->inbuf);
TRYFREE(s->outbuf);
TRYFREE((voidp)s->path);
TRYFREE((voidp)s->msg);
if (s->stream.state != NULL) {
if (s->mode == 'w') {
err = deflateEnd(&(s->stream));
} else if (s->mode == 'r') {
err = inflateEnd(&(s->stream));
}
}
if (s->file != NULL && fclose(s->file)) {
err = Z_ERRNO;
}
if (s->z_err < 0) err = s->z_err;
zcfree((voidp)0, (voidp)s);
return err;
}
local void putLong (file, x)
FILE *file;
uLong x;
{
int n;
for (n = 0; n < 4; n++) {
fputc((int)(x & 0xff), file);
x >>= 8;
}
}
local uLong getLong (buf)
Byte *buf;
{
uLong x = 0;
Byte *p = buf+4;
do {
x <<= 8;
x |= *--p;
} while (p != buf);
return x;
}
local unsigned bi_reverse(code, len)
unsigned code; /* the value to invert */
int len; /* its bit length */
{
register unsigned res = 0;
do {
res |= code & 1;
code >>= 1, res <<= 1;
} while (--len > 0);
return res >> 1;
}
local void gen_codes (tree, max_code, bl_count)
ct_data *tree; /* the tree to decorate */
int max_code; /* largest code with non zero frequency */
ush bl_count[]; /* number of codes at each bit length */
{
ush next_code[MAX_BITS+1]; /* next code value for each bit length */
ush code = 0; /* running code value */
int bits; /* bit index */
int n; /* code index */
/* The distribution counts are first used to generate the code values
* without bit reversal.
*/
for (bits = 1; bits <= MAX_BITS; bits++) {
next_code[bits] = code = (code + bl_count[bits-1]) << 1;
}
/* Check that the bit counts in bl_count are consistent. The last code
* must be all ones.
*/
Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
"inconsistent bit counts");
for (n = 0; n <= max_code; n++) {
int len = tree[n].Len;
if (len == 0) continue;
/* Now reverse the bits */
tree[n].Code = bi_reverse(next_code[len]++, len);
}
}
local void ct_static_init()
{
int n; /* iterates over tree elements */
int bits; /* bit counter */
int length; /* length value */
int code; /* code value */
int dist; /* distance index */
ush bl_count[MAX_BITS+1];
/* number of codes at each bit length for an optimal tree */
/* Initialize the mapping length (0..255) -> length code (0..28) */
length = 0;
for (code = 0; code < LENGTH_CODES-1; code++) {
base_length[code] = length;
for (n = 0; n < (1<<extra_lbits[code]); n++) {
length_code[length++] = (uch)code;
}
}
Assert (length == 256, "ct_static_init: length != 256");
/* Note that the length 255 (match length 258) can be represented
* in two different ways: code 284 + 5 bits or code 285, so we
* overwrite length_code[255] to use the best encoding:
*/
length_code[length-1] = (uch)code;
/* Initialize the mapping dist (0..32K) -> dist code (0..29) */
dist = 0;
for (code = 0 ; code < 16; code++) {
base_dist[code] = dist;
for (n = 0; n < (1<<extra_dbits[code]); n++) {
dist_code[dist++] = (uch)code;
}
}
Assert (dist == 256, "ct_static_init: dist != 256");
dist >>= 7; /* from now on, all distances are divided by 128 */
for ( ; code < D_CODES; code++) {
base_dist[code] = dist << 7;
for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
dist_code[256 + dist++] = (uch)code;
}
}
Assert (dist == 256, "ct_static_init: 256+dist != 512");
/* Construct the codes of the static literal tree */
for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
n = 0;
while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
/* Codes 286 and 287 do not exist, but we must include them in the
* tree construction to get a canonical Huffman tree (longest code
* all ones)
*/
gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
/* The static distance tree is trivial: */
for (n = 0; n < D_CODES; n++) {
static_dtree[n].Len = 5;
static_dtree[n].Code = bi_reverse(n, 5);
}
}
local void init_block(s)
deflate_state *s;
{
int n; /* iterates over tree elements */
/* Initialize the trees. */
for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
s->dyn_ltree[END_BLOCK].Freq = 1;
s->opt_len = s->static_len = 0L;
s->last_lit = s->matches = 0;
}
local void ct_init(s)
deflate_state *s;
{
if (static_dtree[0].Len == 0) {
ct_static_init(); /* To do: at compile time */
}
s->compressed_len = 0L;
s->l_desc.dyn_tree = s->dyn_ltree;
s->l_desc.stat_desc = &static_l_desc;
s->d_desc.dyn_tree = s->dyn_dtree;
s->d_desc.stat_desc = &static_d_desc;
s->bl_desc.dyn_tree = s->bl_tree;
s->bl_desc.stat_desc = &static_bl_desc;
s->bi_buf = 0;
s->bi_valid = 0;
#ifdef DEBUG
s->bits_sent = 0L;
#endif
/* Initialize the first block of the first file: */
init_block(s);
}
local void lm_init (s)
deflate_state *s;
{
register unsigned j;
s->window_size = (ulg)2L*s->w_size;
/* Initialize the hash table (avoiding 64K overflow for 16 bit systems).
* prev[] will be initialized on the fly.
*/
s->head[s->hash_size-1] = NIL;
zmemzero((unsigned char*)s->head, (unsigned int)(s->hash_size-1)*sizeof(*s->head));
/* Set the default configuration parameters:
*/
s->max_lazy_match = configuration_table[s->level].max_lazy;
s->good_match = configuration_table[s->level].good_length;
s->nice_match = configuration_table[s->level].nice_length;
s->max_chain_length = configuration_table[s->level].max_chain;
s->strstart = 0;
s->block_start = 0L;
s->lookahead = 0;
s->match_length = MIN_MATCH-1;
s->match_available = 0;
#ifdef ASMV
match_init(); /* initialize the asm code */
#endif
s->ins_h = 0;
for (j=0; j<MIN_MATCH-1; j++) UPDATE_HASH(s, s->ins_h, s->window[j]);
/* If lookahead < MIN_MATCH, ins_h is garbage, but this is
* not important since only literal bytes will be emitted.
*/
}
local int deflateReset (strm)
z_stream *strm;
{
deflate_state *s;
if (strm == Z_NULL || strm->state == Z_NULL ||
strm->zalloc == Z_NULL || strm->zfree == Z_NULL) return Z_STREAM_ERROR;
strm->total_in = strm->total_out = 0;
strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
strm->data_type = Z_UNKNOWN;
s = (deflate_state *)strm->state;
s->pending = 0;
s->pending_out = s->pending_buf;
s->status = s->noheader ? BUSY_STATE : INIT_STATE;
s->adler = 1;
ct_init(s);
lm_init(s);
return Z_OK;
}
local int deflateInit2 (strm, level, method, windowBits, memLevel, strategy)
z_stream *strm;
int level;
int method;
int windowBits;
int memLevel;
int strategy;
{
deflate_state *s;
int noheader = 0;
if (strm == Z_NULL) return Z_STREAM_ERROR;
strm->msg = Z_NULL;
if (strm->zalloc == Z_NULL) strm->zalloc = zcalloc;
if (strm->zfree == Z_NULL) strm->zfree = zcfree;
if (level == Z_DEFAULT_COMPRESSION) level = 6;
if (windowBits < 0) { /* undocumented feature: suppress zlib header */
noheader = 1;
windowBits = -windowBits;
}
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != DEFLATED ||
windowBits < 8 || windowBits > 15 || level < 1 || level > 9) {
return Z_STREAM_ERROR;
}
s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
if (s == Z_NULL) return Z_MEM_ERROR;
strm->state = (struct internal_state *)s;
s->strm = strm;
s->noheader = noheader;
s->w_bits = windowBits;
s->w_size = 1 << s->w_bits;
s->w_mask = s->w_size - 1;
s->hash_bits = memLevel + 7;
s->hash_size = 1 << s->hash_bits;
s->hash_mask = s->hash_size - 1;
s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
s->window = (Byte*) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
s->prev = (Pos*) ZALLOC(strm, s->w_size, sizeof(Pos));
s->head = (Pos*) ZALLOC(strm, s->hash_size, sizeof(Pos));
s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
s->pending_buf = (uch*) ZALLOC(strm, s->lit_bufsize, 2*sizeof(ush));
if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
s->pending_buf == Z_NULL) {
strm->msg = z_errmsg[1-Z_MEM_ERROR];
deflateEnd (strm);
return Z_MEM_ERROR;
}
s->d_buf = (ush*) &(s->pending_buf[s->lit_bufsize]);
s->l_buf = (uch*) &(s->pending_buf[3*s->lit_bufsize]);
/* We overlay pending_buf and d_buf+l_buf. This works since the average
* output size for (length,distance) codes is <= 32 bits (worst case
* is 15+15+13=33).
*/
s->level = level;
s->strategy = strategy;
s->method = (Byte)method;
return deflateReset(strm);
}
local int inflateInit2(z, w)
z_stream *z;
int w;
{
/* initialize state */
if (z == Z_NULL)
return Z_STREAM_ERROR;
if (z->zalloc == Z_NULL) z->zalloc = zcalloc;
if (z->zfree == Z_NULL) z->zfree = zcfree;
z->total_in = z->total_out = 0;
z->msg = Z_NULL;
if ((z->state = (struct internal_state *)
ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
return Z_MEM_ERROR;
z->state->mode = METHOD;
/* handle undocumented nowrap option (no zlib header or check) */
z->state->nowrap = 0;
if (w < 0)
{
w = - w;
z->state->nowrap = 1;
z->state->mode = START;
}
/* set window size */
if (w < 8 || w > 15)
{
inflateEnd(z);
return Z_STREAM_ERROR;
}
z->state->wbits = w;
return Z_OK;
}
local void putShortMSB (s, b)
deflate_state *s;
uInt b;
{
put_byte(s, (Byte)(b >> 8));
put_byte(s, (Byte)(b & 0xff));
}
local void flush_pending(strm)
z_stream *strm;
{
unsigned len = strm->state->pending;
if (len > strm->avail_out) len = strm->avail_out;
if (len == 0) return;
zmemcpy(strm->next_out, strm->state->pending_out, len);
strm->next_out += len;
strm->state->pending_out += len;
strm->total_out += len;
strm->avail_out -= len;
strm->state->pending -= len;
if (strm->state->pending == 0) {
strm->state->pending_out = strm->state->pending_buf;
}
}
local void fill_window(s)
deflate_state *s;
{
register unsigned n, m;
unsigned more; /* Amount of free space at the end of the window. */
do {
more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
/* Deal with !@#$% 64K limit: */
if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
more = s->w_size;
} else if (more == (unsigned)(-1)) {
/* Very unlikely, but possible on 16 bit machine if strstart == 0
* and lookahead == 1 (input done one byte at time)
*/
more--;
/* If the window is almost full and there is insufficient lookahead,
* move the upper half to the lower one to make room in the upper half.
*/
} else if (s->strstart >= s->w_size+MAX_DIST(s)) {
/* By the IN assertion, the window is not empty so we can't confuse
* more == 0 with more == 64K on a 16 bit machine.
*/
memcpy((char*)s->window, (char*)s->window+s->w_size,
(unsigned)s->w_size);
s->match_start -= s->w_size;
s->strstart -= s->w_size; /* we now have strstart >= MAX_DIST */
s->block_start -= (long) s->w_size;
for (n = 0; n < s->hash_size; n++) {
m = s->head[n];
s->head[n] = (Pos)(m >= s->w_size ? m-s->w_size : NIL);
}
for (n = 0; n < s->w_size; n++) {
m = s->prev[n];
s->prev[n] = (Pos)(m >= s->w_size ? m-s->w_size : NIL);
/* If n is not on any hash chain, prev[n] is garbage but
* its value will never be used.
*/
}
more += s->w_size;
}
if (s->strm->avail_in == 0) return;
/* If there was no sliding:
* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
* more == window_size - lookahead - strstart
* => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
* => more >= window_size - 2*WSIZE + 2
* In the BIG_MEM or MMAP case (not yet supported),
* window_size == input_size + MIN_LOOKAHEAD &&
* strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
* Otherwise, window_size == 2*WSIZE so more >= 2.
* If there was sliding, more >= WSIZE. So in all cases, more >= 2.
*/
Assert(more >= 2, "more < 2");
n = read_buf(s->strm, (char*)s->window + s->strstart + s->lookahead,
more);
s->lookahead += n;
} while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
}
/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
* match.S. The code will be functionally equivalent.
*/
local int longest_match(s, cur_match)
deflate_state *s;
IPos cur_match; /* current match */
{
unsigned chain_length = s->max_chain_length;/* max hash chain length */
register Byte *scan = s->window + s->strstart; /* current string */
register Byte *match; /* matched string */
register int len; /* length of current match */
int best_len = s->prev_length; /* best match length so far */
IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
s->strstart - (IPos)MAX_DIST(s) : NIL;
/* Stop when cur_match becomes <= limit. To simplify the code,
* we prevent matches with the string of window index 0.
*/
#ifdef UNALIGNED_OK
/* Compare two bytes at a time. Note: this is not always beneficial.
* Try with and without -DUNALIGNED_OK to check.
*/
register Byte *strend = s->window + s->strstart + MAX_MATCH - 1;
register ush scan_start = *(ush*)scan;
register ush scan_end = *(ush*)(scan+best_len-1);
#else
register Byte *strend = s->window + s->strstart + MAX_MATCH;
register Byte scan_end1 = scan[best_len-1];
register Byte scan_end = scan[best_len];
#endif
/* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
* It is easy to get rid of this optimization if necessary.
*/
Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
/* Do not waste too much time if we already have a good match: */
if (s->prev_length >= s->good_match) {
chain_length >>= 2;
}
Assert(s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
do {
Assert(cur_match < s->strstart, "no future");
match = s->window + cur_match;
/* Skip to next match if the match length cannot increase
* or if the match length is less than 2:
*/
#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
/* This code assumes sizeof(unsigned short) == 2. Do not use
* UNALIGNED_OK if your compiler uses a different size.
*/
if (*(ush*)(match+best_len-1) != scan_end ||
*(ush*)match != scan_start) continue;
/* It is not necessary to compare scan[2] and match[2] since they are
* always equal when the other bytes match, given that the hash keys
* are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
* strstart+3, +5, ... up to strstart+257. We check for insufficient
* lookahead only every 4th comparison; the 128th check will be made
* at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
* necessary to put more guard bytes at the end of the window, or
* to check more often for insufficient lookahead.
*/
scan++, match++;
do {
} while (*(ush*)(scan+=2) == *(ush*)(match+=2) &&
*(ush*)(scan+=2) == *(ush*)(match+=2) &&
*(ush*)(scan+=2) == *(ush*)(match+=2) &&
*(ush*)(scan+=2) == *(ush*)(match+=2) &&
scan < strend);
/* The funny "do {}" generates better code on most compilers */
/* Here, scan <= window+strstart+257 */
Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
if (*scan == *match) scan++;
len = (MAX_MATCH - 1) - (int)(strend-scan);
scan = strend - (MAX_MATCH-1);
#else /* UNALIGNED_OK */
if (match[best_len] != scan_end ||
match[best_len-1] != scan_end1 ||
*match != *scan ||
*++match != scan[1]) continue;
/* The check at best_len-1 can be removed because it will be made
* again later. (This heuristic is not always a win.)
* It is not necessary to compare scan[2] and match[2] since they
* are always equal when the other bytes match, given that
* the hash keys are equal and that HASH_BITS >= 8.
*/
scan += 2, match++;
/* We check for insufficient lookahead only every 8th comparison;
* the 256th check will be made at strstart+258.
*/
do {
} while (*++scan == *++match && *++scan == *++match &&
*++scan == *++match && *++scan == *++match &&
*++scan == *++match && *++scan == *++match &&
*++scan == *++match && *++scan == *++match &&
scan < strend);
Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
len = MAX_MATCH - (int)(strend - scan);
scan = strend - MAX_MATCH;
#endif /* UNALIGNED_OK */
if (len > best_len) {
s->match_start = cur_match;
best_len = len;
if (len >= s->nice_match) break;
#ifdef UNALIGNED_OK
scan_end = *(ush*)(scan+best_len-1);
#else
scan_end1 = scan[best_len-1];
scan_end = scan[best_len];
#endif
}
} while ((cur_match = s->prev[cur_match & s->w_mask]) > limit
&& --chain_length != 0);
return best_len;
}
local int ct_tally (s, dist, lc)
deflate_state *s;
int dist; /* distance of matched string */
int lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
{
s->d_buf[s->last_lit] = (ush)dist;
s->l_buf[s->last_lit++] = (uch)lc;
if (dist == 0) {
/* lc is the unmatched char */
s->dyn_ltree[lc].Freq++;
} else {
s->matches++;
/* Here, lc is the match length - MIN_MATCH */
dist--; /* dist = match distance - 1 */
Assert((ush)dist < (ush)MAX_DIST(s) &&
(ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
(ush)d_code(dist) < (ush)D_CODES, "ct_tally: bad match");
s->dyn_ltree[length_code[lc]+LITERALS+1].Freq++;
s->dyn_dtree[d_code(dist)].Freq++;
}
/* Try to guess if it is profitable to stop the current block here */
if (s->level > 2 && (s->last_lit & 0xfff) == 0) {
/* Compute an upper bound for the compressed length */
ulg out_length = (ulg)s->last_lit*8L;
ulg in_length = (ulg)s->strstart - s->block_start;
int dcode;
for (dcode = 0; dcode < D_CODES; dcode++) {
out_length += (ulg)s->dyn_dtree[dcode].Freq *
(5L+extra_dbits[dcode]);
}
out_length >>= 3;
if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
}
return (s->last_lit == s->lit_bufsize-1);
/* We avoid equality with lit_bufsize because of wraparound at 64K
* on 16 bit machines and because stored blocks are restricted to
* 64K-1 bytes.
*/
}
local void set_data_type(s)
deflate_state *s;
{
int n = 0;
unsigned ascii_freq = 0;
unsigned bin_freq = 0;
while (n < 7) bin_freq += s->dyn_ltree[n++].Freq;
while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq;
while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq;
s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? BINARY : ASCII);
}
local void pqdownheap(s, tree, k)
deflate_state *s;
ct_data *tree; /* the tree to restore */
int k; /* node to move down */
{
int v = s->heap[k];
int j = k << 1; /* left son of k */
while (j <= s->heap_len) {
/* Set j to the smallest of the two sons: */
if (j < s->heap_len &&
smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
j++;
}
/* Exit if v is smaller than both sons */
if (smaller(tree, v, s->heap[j], s->depth)) break;
/* Exchange v with the smallest son */
s->heap[k] = s->heap[j]; k = j;
/* And continue down the tree, setting j to the left son of k */
j <<= 1;
}
s->heap[k] = v;
}
local void gen_bitlen(s, desc)
deflate_state *s;
tree_desc *desc; /* the tree descriptor */
{
ct_data *tree = desc->dyn_tree;
int max_code = desc->max_code;
ct_data *stree = desc->stat_desc->static_tree;
int *extra = desc->stat_desc->extra_bits;
int base = desc->stat_desc->extra_base;
int max_length = desc->stat_desc->max_length;
int h; /* heap index */
int n, m; /* iterate over the tree elements */
int bits; /* bit length */
int xbits; /* extra bits */
ush f; /* frequency */
int overflow = 0; /* number of elements with bit length too large */
for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
/* In a first pass, compute the optimal bit lengths (which may
* overflow in the case of the bit length tree).
*/
tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
n = s->heap[h];
bits = tree[tree[n].Dad].Len + 1;
if (bits > max_length) bits = max_length, overflow++;
tree[n].Len = (ush)bits;
/* We overwrite tree[n].Dad which is no longer needed */
if (n > max_code) continue; /* not a leaf node */
s->bl_count[bits]++;
xbits = 0;
if (n >= base) xbits = extra[n-base];
f = tree[n].Freq;
s->opt_len += (ulg)f * (bits + xbits);
if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
}
if (overflow == 0) return;
/* This happens for example on obj2 and pic of the Calgary corpus */
/* Find the first bit length which could increase: */
do {
bits = max_length-1;
while (s->bl_count[bits] == 0) bits--;
s->bl_count[bits]--; /* move one leaf down the tree */
s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
s->bl_count[max_length]--;
/* The brother of the overflow item also moves one step up,
* but this does not affect bl_count[max_length]
*/
overflow -= 2;
} while (overflow > 0);
/* Now recompute all bit lengths, scanning in increasing frequency.
* h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
* lengths instead of fixing only the wrong ones. This idea is taken
* from 'ar' written by Haruhiko Okumura.)
*/
for (bits = max_length; bits != 0; bits--) {
n = s->bl_count[bits];
while (n != 0) {
m = s->heap[--h];
if (m > max_code) continue;
if (tree[m].Len != (unsigned) bits) {
s->opt_len += ((long)bits - (long)tree[m].Len)
*(long)tree[m].Freq;
tree[m].Len = (ush)bits;
}
n--;
}
}
}
local void build_tree(s, desc)
deflate_state *s;
tree_desc *desc; /* the tree descriptor */
{
ct_data *tree = desc->dyn_tree;
ct_data *stree = desc->stat_desc->static_tree;
int elems = desc->stat_desc->elems;
int n, m; /* iterate over heap elements */
int max_code = -1; /* largest code with non zero frequency */
int node = elems; /* next internal node of the tree */
int new; /* new node being created */
/* Construct the initial heap, with least frequent element in
* heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
* heap[0] is not used.
*/
s->heap_len = 0, s->heap_max = HEAP_SIZE;
for (n = 0; n < elems; n++) {
if (tree[n].Freq != 0) {
s->heap[++(s->heap_len)] = max_code = n;
s->depth[n] = 0;
} else {
tree[n].Len = 0;
}
}
/* The pkzip format requires that at least one distance code exists,
* and that at least one bit should be sent even if there is only one
* possible code. So to avoid special checks later on we force at least
* two codes of non zero frequency.
*/
while (s->heap_len < 2) {
new = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
tree[new].Freq = 1;
s->depth[new] = 0;
s->opt_len--; if (stree) s->static_len -= stree[new].Len;
/* new is 0 or 1 so it does not have extra bits */
}
desc->max_code = max_code;
/* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
* establish sub-heaps of increasing lengths:
*/
for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
/* Construct the Huffman tree by repeatedly combining the least two
* frequent nodes.
*/
do {
pqremove(s, tree, n); /* n = node of least frequency */
m = s->heap[SMALLEST]; /* m = node of next least frequency */
s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
s->heap[--(s->heap_max)] = m;
/* Create a new node father of n and m */
tree[node].Freq = tree[n].Freq + tree[m].Freq;
s->depth[node] = (uch) (MAX(s->depth[n], s->depth[m]) + 1);
tree[n].Dad = tree[m].Dad = (ush)node;
#ifdef DUMP_BL_TREE
if (tree == s->bl_tree) {
fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
}
#endif
/* and insert the new node in the heap */
s->heap[SMALLEST] = node++;
pqdownheap(s, tree, SMALLEST);
} while (s->heap_len >= 2);
s->heap[--(s->heap_max)] = s->heap[SMALLEST];
/* At this point, the fields freq and dad are set. We can now
* generate the bit lengths.
*/
gen_bitlen(s, (tree_desc *)desc);
/* The field len is now set, we can generate the bit codes */
gen_codes ((ct_data *)tree, max_code, s->bl_count);
}
local void scan_tree (s, tree, max_code)
deflate_state *s;
ct_data *tree; /* the tree to be scanned */
int max_code; /* and its largest code of non zero frequency */
{
int n; /* iterates over all tree elements */
int prevlen = -1; /* last emitted length */
int curlen; /* length of current code */
int nextlen = tree[0].Len; /* length of next code */
int count = 0; /* repeat count of the current code */
int max_count = 7; /* max repeat count */
int min_count = 4; /* min repeat count */
if (nextlen == 0) max_count = 138, min_count = 3;
tree[max_code+1].Len = (ush)0xffff; /* guard */
for (n = 0; n <= max_code; n++) {
curlen = nextlen; nextlen = tree[n+1].Len;
if (++count < max_count && curlen == nextlen) {
continue;
} else if (count < min_count) {
s->bl_tree[curlen].Freq += count;
} else if (curlen != 0) {
if (curlen != prevlen) s->bl_tree[curlen].Freq++;
s->bl_tree[REP_3_6].Freq++;
} else if (count <= 10) {
s->bl_tree[REPZ_3_10].Freq++;
} else {
s->bl_tree[REPZ_11_138].Freq++;
}
count = 0; prevlen = curlen;
if (nextlen == 0) {
max_count = 138, min_count = 3;
} else if (curlen == nextlen) {
max_count = 6, min_count = 3;
} else {
max_count = 7, min_count = 4;
}
}
}
local int build_bl_tree(s)
deflate_state *s;
{
int max_blindex; /* index of last bit length code of non zero freq */
/* Determine the bit length frequencies for literal and distance trees */
scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
/* Build the bit length tree: */
build_tree(s, (tree_desc *)(&(s->bl_desc)));
/* opt_len now includes the length of the tree representations, except
* the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
*/
/* Determine the number of bit length codes to send. The pkzip format
* requires that at least 4 bit length codes be sent. (appnote.txt says
* 3 but the actual value used is 4.)
*/
for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
}
/* Update opt_len to include the bit length tree and counts */
s->opt_len += 3*(max_blindex+1) + 5+5+4;
return max_blindex;
}
local void send_bits(s, value, length)
deflate_state *s;
int value; /* value to send */
int length; /* number of bits */
{
#ifdef DEBUG
Assert(length > 0 && length <= 15, "invalid length");
s->bits_sent += (ulg)length;
#endif
/* If not enough room in bi_buf, use (valid) bits from bi_buf and
* (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
* unused bits in value.
*/
if (s->bi_valid > (int)Buf_size - length) {
s->bi_buf |= (value << s->bi_valid);
put_short(s, s->bi_buf);
s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
s->bi_valid += length - Buf_size;
} else {
s->bi_buf |= value << s->bi_valid;
s->bi_valid += length;
}
}
local void bi_windup(s)
deflate_state *s;
{
if (s->bi_valid > 8) {
put_short(s, s->bi_buf);
} else if (s->bi_valid > 0) {
put_byte(s, (Byte)s->bi_buf);
}
s->bi_buf = 0;
s->bi_valid = 0;
#ifdef DEBUG
s->bits_sent = (s->bits_sent+7) & ~7;
#endif
}
local void copy_block(s, buf, len, header)
deflate_state *s;
char *buf; /* the input data */
unsigned len; /* its length */
int header; /* true if block header must be written */
{
bi_windup(s); /* align on byte boundary */
if (header) {
put_short(s, (ush)len);
put_short(s, (ush)~len);
#ifdef DEBUG
s->bits_sent += 2*16;
#endif
}
#ifdef DEBUG
s->bits_sent += (ulg)len<<3;
#endif
while (len--) {
put_byte(s, *buf++);
}
}
local void compress_block(s, ltree, dtree)
deflate_state *s;
ct_data *ltree; /* literal tree */
ct_data *dtree; /* distance tree */
{
unsigned dist; /* distance of matched string */
int lc; /* match length or unmatched char (if dist == 0) */
unsigned lx = 0; /* running index in l_buf */
unsigned code; /* the code to send */
int extra; /* number of extra bits to send */
if (s->last_lit != 0) do {
dist = s->d_buf[lx];
lc = s->l_buf[lx++];
if (dist == 0) {
send_code(s, lc, ltree); /* send a literal byte */
} else {
/* Here, lc is the match length - MIN_MATCH */
code = length_code[lc];
send_code(s, code+LITERALS+1, ltree); /* send the length code */
extra = extra_lbits[code];
if (extra != 0) {
lc -= base_length[code];
send_bits(s, lc, extra); /* send the extra length bits */
}
dist--; /* dist is now the match distance - 1 */
code = d_code(dist);
Assert (code < D_CODES, "bad d_code");
send_code(s, code, dtree); /* send the distance code */
extra = extra_dbits[code];
if (extra != 0) {
dist -= base_dist[code];
send_bits(s, dist, extra); /* send the extra distance bits */
}
} /* literal or match pair ? */
/* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
Assert(s->pending < s->lit_bufsize + 2*lx, "pendingBuf overflow");
} while (lx < s->last_lit);
send_code(s, END_BLOCK, ltree);
}
local void send_tree (s, tree, max_code)
deflate_state *s;
ct_data *tree; /* the tree to be scanned */
int max_code; /* and its largest code of non zero frequency */
{
int n; /* iterates over all tree elements */
int prevlen = -1; /* last emitted length */
int curlen; /* length of current code */
int nextlen = tree[0].Len; /* length of next code */
int count = 0; /* repeat count of the current code */
int max_count = 7; /* max repeat count */
int min_count = 4; /* min repeat count */
/* tree[max_code+1].Len = -1; */ /* guard already set */
if (nextlen == 0) max_count = 138, min_count = 3;
for (n = 0; n <= max_code; n++) {
curlen = nextlen; nextlen = tree[n+1].Len;
if (++count < max_count && curlen == nextlen) {
continue;
} else if (count < min_count) {
do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
} else if (curlen != 0) {
if (curlen != prevlen) {
send_code(s, curlen, s->bl_tree); count--;
}
Assert(count >= 3 && count <= 6, " 3_6?");
send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
} else if (count <= 10) {
send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
} else {
send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
}
count = 0; prevlen = curlen;
if (nextlen == 0) {
max_count = 138, min_count = 3;
} else if (curlen == nextlen) {
max_count = 6, min_count = 3;
} else {
max_count = 7, min_count = 4;
}
}
}
local void send_all_trees(s, lcodes, dcodes, blcodes)
deflate_state *s;
int lcodes, dcodes, blcodes; /* number of codes for each tree */
{
int rank; /* index in bl_order */
Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
"too many codes");
send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
send_bits(s, dcodes-1, 5);
send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
for (rank = 0; rank < blcodes; rank++) {
send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
}
send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
}
ulg ct_flush_block(s, buf, stored_len, eof)
deflate_state *s;
char *buf; /* input block, or NULL if too old */
ulg stored_len; /* length of input block */
int eof; /* true if this is the last block for a file */
{
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
int max_blindex; /* index of last bit length code of non zero freq */
/* Check if the file is ascii or binary */
if (s->data_type == UNKNOWN) set_data_type(s);
/* Construct the literal and distance trees */
build_tree(s, (tree_desc *)(&(s->l_desc)));
build_tree(s, (tree_desc *)(&(s->d_desc)));
/* At this point, opt_len and static_len are the total bit lengths of
* the compressed block data, excluding the tree representations.
*/
/* Build the bit length tree for the above two trees, and get the index
* in bl_order of the last bit length code to send.
*/
max_blindex = build_bl_tree(s);
/* Determine the best encoding. Compute first the block length in bytes */
opt_lenb = (s->opt_len+3+7)>>3;
static_lenb = (s->static_len+3+7)>>3;
if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
/* If compression failed and this is the first and last block,
* and if the .zip file can be seeked (to rewrite the local header),
* the whole file is transformed into a stored file:
*/
if (stored_len+4 <= opt_lenb && buf != (char*)0) {
/* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
* Otherwise we can't have processed more than WSIZE input bytes since
* the last block flush, because compression would have been
* successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
* transform a block into a stored block.
*/
send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
s->compressed_len = (s->compressed_len + 3 + 7) & ~7L;
s->compressed_len += (stored_len + 4) << 3;
copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
} else if (static_lenb == opt_lenb) {
send_bits(s, (STATIC_TREES<<1)+eof, 3);
compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
s->compressed_len += 3 + s->static_len;
} else {
send_bits(s, (DYN_TREES<<1)+eof, 3);
send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
max_blindex+1);
compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
s->compressed_len += 3 + s->opt_len;
}
Assert (s->compressed_len == s->bits_sent, "bad compressed size");
init_block(s);
if (eof) {
bi_windup(s);
s->compressed_len += 7; /* align on byte boundary */
}
return s->compressed_len >> 3;
}
local int deflate_fast(s, flush)
deflate_state *s;
int flush;
{
IPos hash_head; /* head of the hash chain */
int bflush; /* set if current block must be flushed */
s->prev_length = MIN_MATCH-1;
for (;;) {
/* Make sure that we always have enough lookahead, except
* at the end of the input file. We need MAX_MATCH bytes
* for the next match, plus MIN_MATCH bytes to insert the
* string following the next match.
*/
if (s->lookahead < MIN_LOOKAHEAD) {
fill_window(s);
if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) return 1;
if (s->lookahead == 0) break; /* flush the current block */
}
/* Insert the string window[strstart .. strstart+2] in the
* dictionary, and set hash_head to the head of the hash chain:
*/
INSERT_STRING(s, s->strstart, hash_head);
/* Find the longest match, discarding those <= prev_length.
* At this point we have always match_length < MIN_MATCH
*/
if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
/* To simplify the code, we prevent matches with the string
* of window index 0 (in particular we have to avoid a match
* of the string with itself at the start of the input file).
*/
if (s->strategy != Z_HUFFMAN_ONLY) {
s->match_length = longest_match (s, hash_head);
}
/* longest_match() sets match_start */
if (s->match_length > s->lookahead) s->match_length = s->lookahead;
}
if (s->match_length >= MIN_MATCH) {
check_match(s, s->strstart, s->match_start, s->match_length);
bflush = ct_tally(s, s->strstart - s->match_start,
s->match_length - MIN_MATCH);
s->lookahead -= s->match_length;
/* Insert new strings in the hash table only if the match length
* is not too large. This saves time but degrades compression.
*/
if (s->match_length <= s->max_insert_length) {
s->match_length--; /* string at strstart already in hash table */
do {
s->strstart++;
INSERT_STRING(s, s->strstart, hash_head);
/* strstart never exceeds WSIZE-MAX_MATCH, so there are
* always MIN_MATCH bytes ahead. If lookahead < MIN_MATCH
* these bytes are garbage, but it does not matter since
* the next lookahead bytes will be emitted as literals.
*/
} while (--s->match_length != 0);
s->strstart++;
} else {
s->strstart += s->match_length;
s->match_length = 0;
s->ins_h = s->window[s->strstart];
UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
#if MIN_MATCH != 3
Call UPDATE_HASH() MIN_MATCH-3 more times
#endif
}
} else {
/* No match, output a literal byte */
bflush = ct_tally (s, 0, s->window[s->strstart]);
s->lookahead--;
s->strstart++;
}
if (bflush) FLUSH_BLOCK(s, 0);
}
FLUSH_BLOCK(s, flush == Z_FINISH);
return 0; /* normal exit */
}
local int deflate_slow(s, flush)
deflate_state *s;
int flush;
{
IPos hash_head; /* head of hash chain */
int bflush; /* set if current block must be flushed */
/* Process the input block. */
for (;;) {
/* Make sure that we always have enough lookahead, except
* at the end of the input file. We need MAX_MATCH bytes
* for the next match, plus MIN_MATCH bytes to insert the
* string following the next match.
*/
if (s->lookahead < MIN_LOOKAHEAD) {
fill_window(s);
if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) return 1;
if (s->lookahead == 0) break; /* flush the current block */
}
/* Insert the string window[strstart .. strstart+2] in the
* dictionary, and set hash_head to the head of the hash chain:
*/
INSERT_STRING(s, s->strstart, hash_head);
/* Find the longest match, discarding those <= prev_length.
*/
s->prev_length = s->match_length, s->prev_match = s->match_start;
s->match_length = MIN_MATCH-1;
if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
s->strstart - hash_head <= MAX_DIST(s)) {
/* To simplify the code, we prevent matches with the string
* of window index 0 (in particular we have to avoid a match
* of the string with itself at the start of the input file).
*/
if (s->strategy != Z_HUFFMAN_ONLY) {
s->match_length = longest_match (s, hash_head);
}
/* longest_match() sets match_start */
if (s->match_length > s->lookahead) s->match_length = s->lookahead;
if (s->match_length <= 5 && (s->strategy == Z_FILTERED ||
(s->match_length == MIN_MATCH &&
s->strstart - s->match_start > TOO_FAR))) {
/* If prev_match is also MIN_MATCH, match_start is garbage
* but we will ignore the current match anyway.
*/
s->match_length = MIN_MATCH-1;
}
}
/* If there was a match at the previous step and the current
* match is not better, output the previous match:
*/
if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
check_match(s, s->strstart-1, s->prev_match, s->prev_length);
bflush = ct_tally(s, s->strstart -1 - s->prev_match,
s->prev_length - MIN_MATCH);
/* Insert in hash table all strings up to the end of the match.
* strstart-1 and strstart are already inserted.
*/
s->lookahead -= s->prev_length-1;
s->prev_length -= 2;
do {
s->strstart++;
INSERT_STRING(s, s->strstart, hash_head);
/* strstart never exceeds WSIZE-MAX_MATCH, so there are
* always MIN_MATCH bytes ahead. If lookahead < MIN_MATCH
* these bytes are garbage, but it does not matter since the
* next lookahead bytes will always be emitted as literals.
*/
} while (--s->prev_length != 0);
s->match_available = 0;
s->match_length = MIN_MATCH-1;
s->strstart++;
if (bflush) FLUSH_BLOCK(s, 0);
} else if (s->match_available) {
/* If there was no match at the previous position, output a
* single literal. If there was a match but the current match
* is longer, truncate the previous match to a single literal.
*/
if (ct_tally (s, 0, s->window[s->strstart-1])) {
FLUSH_BLOCK_ONLY(s, 0);
}
s->strstart++;
s->lookahead--;
if (s->strm->avail_out == 0) return 1;
} else {
/* There is no previous match to compare with, wait for
* the next step to decide.
*/
s->match_available = 1;
s->strstart++;
s->lookahead--;
}
}
if (s->match_available) ct_tally (s, 0, s->window[s->strstart-1]);
FLUSH_BLOCK(s, flush == Z_FINISH);
return 0;
}
local int deflate (strm, flush)
z_stream *strm;
int flush;
{
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
if (strm->next_out == Z_NULL || strm->next_in == Z_NULL) {
ERR_RETURN(strm, Z_STREAM_ERROR);
}
if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
strm->state->strm = strm; /* just in case */
/* Write the zlib header */
if (strm->state->status == INIT_STATE) {
uInt header = (DEFLATED + ((strm->state->w_bits-8)<<4)) << 8;
uInt level_flags = (strm->state->level-1) >> 1;
if (level_flags > 3) level_flags = 3;
header |= (level_flags << 6);
header += 31 - (header % 31);
strm->state->status = BUSY_STATE;
putShortMSB(strm->state, header);
}
/* Flush as much pending output as possible */
if (strm->state->pending != 0) {
flush_pending(strm);
if (strm->avail_out == 0) return Z_OK;
}
/* User must not provide more input after the first FINISH: */
if (strm->state->status == FINISH_STATE && strm->avail_in != 0) {
ERR_RETURN(strm, Z_BUF_ERROR);
}
/* Start a new block or continue the current one.
*/
if (strm->avail_in != 0 ||
(flush == Z_FINISH && strm->state->status != FINISH_STATE)) {
if (flush == Z_FINISH) {
strm->state->status = FINISH_STATE;
}
if (strm->state->level <= 3) {
if (deflate_fast(strm->state, flush)) return Z_OK;
} else {
if (deflate_slow(strm->state, flush)) return Z_OK;
}
}
Assert(strm->avail_out > 0, "bug2");
if (flush != Z_FINISH) return Z_OK;
if (strm->state->noheader) return Z_STREAM_END;
/* Write the zlib trailer (adler32) */
putShortMSB(strm->state, (uInt)(strm->state->adler >> 16));
putShortMSB(strm->state, (uInt)(strm->state->adler & 0xffff));
flush_pending(strm);
/* If avail_out is zero, the application will call deflate again
* to flush the rest.
*/
strm->state->noheader = 1; /* write the trailer only once! */
return strm->state->pending != 0 ? Z_OK : Z_STREAM_END;
}
local int gzflush (file, flush)
gzFile file;
int flush;
{
uInt len;
int done = 0;
gz_stream *s = (gz_stream*)file;
if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
s->stream.avail_in = 0; /* should be zero already anyway */
for (;;) {
len = Z_BUFSIZE - s->stream.avail_out;
if (len != 0) {
if (fwrite(s->outbuf, 1, len, s->file) != len) {
s->z_err = Z_ERRNO;
return Z_ERRNO;
}
s->stream.next_out = s->outbuf;
s->stream.avail_out = Z_BUFSIZE;
}
if (done) break;
s->z_err = deflate(&(s->stream), flush);
/* deflate has finished flushing only when it hasn't used up
* all the available space in the output buffer:
*/
done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END);
if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break;
}
return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
}
local gzFile gz_open (path, mode, fd)
char *path;
char *mode;
int fd;
{
int err;
char *p = mode;
gz_stream *s = (gz_stream *)ALLOC(sizeof(gz_stream));
if (!s) return Z_NULL;
s->stream.zalloc = (alloc_func)0;
s->stream.zfree = (free_func)0;
s->stream.next_in = s->inbuf = Z_NULL;
s->stream.next_out = s->outbuf = Z_NULL;
s->stream.avail_in = s->stream.avail_out = 0;
s->file = NULL;
s->z_err = Z_OK;
s->z_eof = 0;
s->crc = crc32(0L, Z_NULL, 0);
s->msg = NULL;
s->transparent = 0;
s->path = (char*)ALLOC(strlen(path)+1);
if (s->path == NULL) {
return destroy(s), (gzFile)Z_NULL;
}
strcpy(s->path, path); /* do this early for debugging */
s->mode = '\0';
do {
if (*p == 'r') s->mode = 'r';
if (*p == 'w') s->mode = 'w';
} while (*p++);
if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
if (s->mode == 'w') {
err = deflateInit2(&(s->stream), Z_BEST_COMPRESSION,
DEFLATED, -WBITS, MEM_LEVEL, 0);
/* windowBits is passed < 0 to suppress zlib header */
s->stream.next_out = s->outbuf = ALLOC(Z_BUFSIZE);
if (err != Z_OK || s->outbuf == Z_NULL) {
return destroy(s), (gzFile)Z_NULL;
}
} else {
err = inflateInit2(&(s->stream), -WBITS);
s->stream.next_in = s->inbuf = ALLOC(Z_BUFSIZE);
if (err != Z_OK || s->inbuf == Z_NULL) {
return destroy(s), (gzFile)Z_NULL;
}
}
s->stream.avail_out = Z_BUFSIZE;
errno = 0;
s->file = fd < 0 ? fopen(path, mode) : fdopen(fd, mode);
if (s->file == NULL) {
return destroy(s), (gzFile)Z_NULL;
}
if (s->mode == 'w') {
/* Write a very simple .gz header:
*/
fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", GZ_MAGIC_1, GZ_MAGIC_2,
DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
} else {
/* Check and skip the header:
*/
Byte c1 = 0, c2 = 0;
Byte method = 0;
Byte flags = 0;
Byte xflags = 0;
Byte time[4];
Byte osCode;
int c;
s->stream.avail_in = fread(s->inbuf, 1, 2, s->file);
if (s->stream.avail_in != 2 || s->inbuf[0] != GZ_MAGIC_1
|| s->inbuf[1] != GZ_MAGIC_2) {
s->transparent = 1;
return (gzFile)s;
}
s->stream.avail_in = 0;
err = fscanf(s->file,"%c%c%4c%c%c", &method, &flags, time, &xflags, &osCode);
if (method != DEFLATED || feof(s->file) || (flags & RESERVED) != 0) {
s->z_err = Z_DATA_ERROR;
return (gzFile)s;
}
if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
long len;
err = fscanf(s->file, "%c%c", &c1, &c2);
len = c1 + ((long)c2<<8);
fseek(s->file, len, SEEK_CUR);
}
if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
while ((c = getc(s->file)) != 0 && c != EOF) ;
}
if ((flags & COMMENT) != 0) { /* skip the .gz file comment */
while ((c = getc(s->file)) != 0 && c != EOF) ;
}
if ((flags & HEAD_CRC) != 0) { /* skip the header crc */
err = fscanf(s->file, "%c%c", &c1, &c2);
}
if (feof(s->file)) {
s->z_err = Z_DATA_ERROR;
}
}
return (gzFile)s;
}
local gzFile gzopen (path, mode)
char *path;
char *mode;
{
return gz_open (path, mode, -1);
}
local int gzwrite (file, buf, len)
gzFile file;
voidp buf;
unsigned len;
{
gz_stream *s = (gz_stream*)file;
if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
s->stream.next_in = buf;
s->stream.avail_in = len;
while (s->stream.avail_in != 0) {
if (s->stream.avail_out == 0) {
s->stream.next_out = s->outbuf;
if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
s->z_err = Z_ERRNO;
break;
}
s->stream.avail_out = Z_BUFSIZE;
}
s->z_err = deflate(&(s->stream), Z_NO_FLUSH);
if (s->z_err != Z_OK) break;
}
s->crc = crc32(s->crc, buf, len);
return len - s->stream.avail_in;
}
local int gzclose (file)
gzFile file;
{
uInt n;
int err;
gz_stream *s = (gz_stream*)file;
if (s == NULL) return Z_STREAM_ERROR;
if (s->mode == 'w') {
err = gzflush (file, Z_FINISH);
if (err != Z_OK) return destroy((gz_stream *)file);
putLong (s->file, s->crc);
putLong (s->file, s->stream.total_in);
} else if (s->mode == 'r' && s->z_err == Z_STREAM_END) {
/* slide CRC and original size if they are at the end of inbuf */
if ((n = s->stream.avail_in) < 8 && !s->z_eof) {
Byte *p = s->inbuf;
Byte *q = s->stream.next_in;
while (n--) { *p++ = *q++; };
n = s->stream.avail_in;
n += fread(p, 1, 8, s->file);
s->stream.next_in = s->inbuf;
}
/* check CRC and original size */
if (n < 8 ||
getLong(s->stream.next_in) != s->crc ||
getLong(s->stream.next_in + 4) != s->stream.total_out) {
s->z_err = Z_DATA_ERROR;
}
}
return destroy((gz_stream *)file);
}
/* ========================================================================= */
static int wm_tool_printf(const char *format, ...)
{
int ret;
va_list ap;
va_start(ap, format);
ret = vprintf(format, ap);
va_end(ap);
fflush(stdout);
return ret;
}
static unsigned long long wm_tool_crc32_reflect(unsigned long long ref, unsigned char ch)
{
int i;
unsigned long long value = 0;
for ( i = 1; i < ( ch + 1 ); i++ )
{
if( ref & 1 )
value |= 1 << ( ch - i );
ref >>= 1;
}
return value;
}
static unsigned int wm_tool_crc32(unsigned int crc, unsigned char *buffer, int size, wm_tool_crc32_reflect_e mode)
{
int i;
unsigned char temp;
for (i = 0; i < size; i++)
{
if (mode & WM_TOOL_CRC32_REFLECT_INPUT)
{
temp = wm_tool_crc32_reflect(buffer[i], 8);
}
else
{
temp = buffer[i];
}
crc = wm_tool_crc32_tab[(crc ^ temp) & 0xff] ^ (crc >> 8);
}
return crc ;
}
static unsigned int wm_tool_get_crc32(unsigned char *buffer, int size, wm_tool_crc32_reflect_e mode)
{
wm_tool_file_crc = wm_tool_crc32(wm_tool_file_crc, buffer, size, mode);
if (mode & WM_TOOL_CRC32_REFLECT_OUTPUT)
{
wm_tool_file_crc = wm_tool_crc32_reflect(wm_tool_file_crc, 32);
}
return wm_tool_file_crc;
}
static unsigned short wm_tool_get_crc16(unsigned char *ptr, unsigned short count)
{
unsigned short crc, i;
crc = 0;
while (count--)
{
crc = crc ^ (int) *ptr++ << 8;
for (i = 0; i < 8; i++)
{
if (crc & 0x8000)
crc = crc << 1 ^ 0x1021;
else
crc = crc << 1;
}
}
return (crc & 0xFFFF);
}
static int wm_tool_char_to_hex(char ch)
{
int hex;
hex = -1;
if ((ch >= '0') && (ch <= '9'))
{
hex = ch - '0';
}
else if ((ch >= 'a') && (ch <= 'f'))
{
hex = ch - 'a' + 0xa;
}
else if ((ch >= 'A') && (ch <= 'F'))
{
hex = ch - 'A' + 0xa;
}
return hex;
}
static int wm_tool_str_to_hex_array(char *str, int cnt, unsigned char array[])
{
int hex;
unsigned char tmp;
unsigned char *des;
des = array;
while (cnt-- > 0)
{
hex = wm_tool_char_to_hex(*str++);
if (hex < 0)
{
return -1;
}
else
{
tmp = (hex << 4) & 0xf0;
}
hex = wm_tool_char_to_hex(*str++);
if (hex < 0)
{
return -1;
}
else
{
tmp = tmp | (hex & 0x0f);
}
*des++ = (unsigned char) tmp;
}
return ((*str == 0) ? 0 : -1);
}
static char *wm_tool_strcasestr(const char *str1, const char *str2)
{
char *cp = (char *) str1;
char *s1, *s2;
if (!*str2) return (char *) str1;
while (*cp) {
s1 = cp;
s2 = (char *) str2;
while (*s1 && *s2 && !(tolower((int)*s1) - tolower((int)*s2))) s1++, s2++;
if (!*s2) return cp;
cp++;
}
return NULL;
}
static int wm_tool_get_file_size(const char* filename)
{
FILE *fp = fopen(filename, "r");
if(!fp) return -1;
fseek(fp,0L,SEEK_END);
int size = ftell(fp);
fclose(fp);
return size;
}
static char *wm_tool_get_name(const char *name)
{
static char sz_name[WM_TOOL_PATH_MAX] = {0};
char *p = (char *)name;
char *q = (char *)name;
do
{
#ifdef __MINGW32__
p = strchr(p, '\\');
#else
p = strchr(p, '/');
#endif
if (p)
{
p++;
q = p;
}
} while (p);
strncpy(sz_name, q, WM_TOOL_PATH_MAX);
#ifdef __MINGW32__
p = wm_tool_strcasestr(sz_name, ".exe");
if (p)
*p = '\0';
#endif
return sz_name;
}
static void wm_tool_print_usage(const char *name)
{
wm_tool_printf("Usage: %s [-h] [-v] [-b] [-o] [-sb] [-ct] [-it] [-ua] [-ra] [-df]"
" [-l] [-c] [-ws] [-ds] [-rs] [-eo] [-dl] [-sl]"
"\r\n"
"\r\n"
"WinnerMicro firmware packaging "
"and programming "
"tool\r\n\r\n"
"options:\r\n\r\n"
" -h , show usage\r\n"
" -v , show version\r\n"
"\r\n"
" -b binary , original binary file\r\n"
" -o output_name , output firmware file\r\n"
" the default is the same as the original binary file name\r\n"
" -sb second_boot , second boot file, used to generate fls file\r\n"
" -fc compress_type , whether the firmware is compressed, default is compressed\r\n"
" <0 | 1> or <uncompress | compress>\r\n"
" -it image_type , firmware image layout type, default is 1M layout\r\n"
" <0 | 3> or <1M | 2M>\r\n"
" -ua update_address , upgrade storage location (hexadecimal)\r\n"
" the default is 90000\r\n"
" -ra run_address , runtime position (hexadecimal)\r\n"
" the default is 10100\r\n"
" -df , generate debug firmware for openocd\r\n"
"\r\n"
" -l , list the local serial port\r\n"
" -c serial_name , connect a serial port\r\n"
#if defined(__APPLE__) && defined(__MACH__)
" e.g: tty.usbserial0 tty.usbserial3 tty.usbserial7\r\n"
#elif defined(__MINGW32__) || defined(__CYGWIN__)
" e.g: COM0 COM3 COM7\r\n"
#elif defined(__linux__)
" e.g: ttyUSB0 ttyUSB3 ttyUSB7\r\n"
#endif
" -ws baud_rate , set the serial port speed during normal work, default is 115200\r\n"
" <1200 - 2000000> or <1M | 2M>\r\n"
" -ds baud_rate , set the serial port speed when downloading, default is 115200\r\n"
" <115200 | 460800 | 921600 | 1000000 | 2000000> or <1M | 2M>\r\n"
" -rs reset_action , set device reset method, default is manual control\r\n"
" <none | at | rts>\r\n"
" none - manual control device reset\r\n"
" at - use the at command to control the device reset\r\n"
" rts - use the serial port rts pin to control the device reset\r\n"
" -eo erase_option , firmware area erase option\r\n"
" <secboot | all>\r\n"
" secboot - erase the second boot area\r\n"
" all - erase all areas\r\n"
" -dl download_firmware, firmware file to be downloaded, default download compressed image\r\n"
" -sl display_format , display the log information output from the serial port\r\n"
" <0 | 1> or <str | hex>\r\n"
" str - string mode display\r\n"
" hex - hexadecimal format\r\n"
, wm_tool_get_name(name));
return;
}
static void wm_tool_print_version(const char *name)
{
wm_tool_printf("%s %s\r\nCopyright (C) 2013 - 2019 WinnerMicro, Inc.\r\n", wm_tool_get_name(name), wm_tool_version);
return;
}
static int wm_tool_parse_arv(int argc, char *argv[])
{
int opt;
int option_index = 0;
char *opt_string = "hvlc:b:o:";
int cnt = 0;
opterr = 1;/* show err info */
struct option long_options[] = {
{"dl", required_argument, NULL, 'd'},
{"ws", required_argument, NULL, 'w'},
{"ds", required_argument, NULL, 's'},
{"sb", required_argument, NULL, 'S'},
{"it", required_argument, NULL, 'i'},
{"fc", required_argument, NULL, 'C'},
{"ua", required_argument, NULL, 'u'},
{"ra", required_argument, NULL, 'r'},
{"df", no_argument, NULL, 'D'},
{"rs", required_argument, NULL, 'a'},
{"eo", required_argument, NULL, 'e'},
{"sl", required_argument, NULL, 'g'},
{0, 0, NULL, 0}
};
while ( (opt = getopt_long_only(argc, argv, opt_string, long_options, &option_index)) != -1)
{
WM_TOOL_DBG_PRINT("%c-%s\r\n", opt, optarg);
switch (opt)
{
case '?':
case 'h':
{
wm_tool_show_usage = 1;
break;
}
case 'v':
{
wm_tool_show_ver = 1;
break;
}
case 'l':
{
wm_tool_list_com = 1;
break;
}
case 'c':
{
#if defined(__MINGW32__)
strcpy(wm_tool_serial_path, optarg);
#elif defined(__CYGWIN__)
sprintf(wm_tool_serial_path, "/dev/ttyS%d", atoi(optarg + strlen("COM")) - 1);
#else
sprintf(wm_tool_serial_path, "/dev/%s", optarg);
#endif
break;
}
case 'w':
{
if ('M' == optarg[1])
wm_tool_normal_serial_rate = (optarg[0] - 0x30) * 1000000;
else
wm_tool_normal_serial_rate = strtol(optarg, NULL, 10);
break;
}
case 's':
{
if ('M' == optarg[1])
wm_tool_download_serial_rate = (optarg[0] - 0x30) * 1000000;
else
wm_tool_download_serial_rate = strtol(optarg, NULL, 10);
break;
}
case 'a':
{
if (0 == strncmp(optarg, "none", strlen("none")))
wm_tool_dl_action = WM_TOOL_DL_ACTION_NONE;
else if (0 == strncmp(optarg, "at", strlen("at")))
wm_tool_dl_action = WM_TOOL_DL_ACTION_AT;
else if (0 == strncmp(optarg, "rts", strlen("rts")))
wm_tool_dl_action = WM_TOOL_DL_ACTION_RTS;
else
wm_tool_show_usage = 1;
break;
}
case 'e':
{
if (0 == strncmp(optarg, "secboot", strlen("secboot")))
wm_tool_dl_erase = WM_TOOL_DL_ERASE_SECBOOT;
else if (0 == strncmp(optarg, "all", strlen("all")))
wm_tool_dl_erase = WM_TOOL_DL_ERASE_ALL;
else
wm_tool_show_usage = 1;
break;
}
case 'd':
{
wm_tool_download_image = strdup(optarg);
if (wm_tool_strcasestr(wm_tool_download_image, ".fls"))
wm_tool_dl_type = WM_TOOL_DL_TYPE_FLS;
break;
}
case 'o':
{
wm_tool_output_image = strdup(optarg);
break;
}
case 'b':
{
wm_tool_input_binary = strdup(optarg);
break;
}
case 'S':
{
wm_tool_secboot_image = strdup(optarg);
break;
}
case 'i':
{
if ('0' == optarg[0])
wm_tool_image_type = WM_TOOL_LAYOUT_TYPE_1M;
else if ('3' == optarg[0])
wm_tool_image_type = WM_TOOL_LAYOUT_TYPE_2M;
else if (0 == strncmp(optarg, "1M", strlen("1M")))
wm_tool_image_type = WM_TOOL_LAYOUT_TYPE_1M;
else if (0 == strncmp(optarg, "2M", strlen("2M")))
wm_tool_image_type = WM_TOOL_LAYOUT_TYPE_2M;
else
{
if (isdigit((int)optarg[0]))
wm_tool_image_type = optarg[0] - 0x30;
else
wm_tool_show_usage = 1;
}
break;
}
case 'C':
{
if ('0' == optarg[0])
wm_tool_zip_type = WM_TOOL_ZIP_TYPE_UNCOMPRESS;
else if ('1' == optarg[0])
wm_tool_zip_type = WM_TOOL_ZIP_TYPE_COMPRESS;
else if (0 == strncmp(optarg, "compress", strlen("compress")))
wm_tool_zip_type = WM_TOOL_ZIP_TYPE_COMPRESS;
else if (0 == strncmp(optarg, "uncompress", strlen("uncompress")))
wm_tool_zip_type = WM_TOOL_ZIP_TYPE_UNCOMPRESS;
else
wm_tool_show_usage = 1;
break;
}
case 'u':
{
wm_tool_upd_addr = strtol(optarg, NULL, 16);
break;
}
case 'r':
{
wm_tool_run_addr = strtol(optarg, NULL, 16);
break;
}
case 'D':
{
wm_tool_is_debug = 1;
break;
}
case 'g':
{
if ('0' == optarg[0])
wm_tool_show_log_type = WM_TOOL_SHOW_LOG_STR;
else if ('1' == optarg[0])
wm_tool_show_log_type = WM_TOOL_SHOW_LOG_HEX;
else if (0 == strncmp(optarg, "str", strlen("str")))
wm_tool_show_log_type = WM_TOOL_SHOW_LOG_STR;
else if (0 == strncmp(optarg, "hex", strlen("hex")))
wm_tool_show_log_type = WM_TOOL_SHOW_LOG_HEX;
else
wm_tool_show_usage = 1;
break;
break;
}
default:
{
wm_tool_show_usage = 1;
break;
}
}
cnt++;
}
return cnt;
}
static int wm_tool_pack_image(const char *outfile)
{
FILE *fpbin = NULL;
FILE *fpimg = NULL;
char *name = "2.0.0";
int readlen = 0;
int filelen = 0;
int patch = 0;
wm_tool_firmware_booter_t fbooter;
unsigned char buf[WM_TOOL_ONCE_READ_LEN + 1];
fpbin = fopen(wm_tool_input_binary, "rb");
if (NULL == fpbin)
{
wm_tool_printf("can not open input file [%s].\r\n", wm_tool_input_binary);
return -2;
}
fpimg = fopen(outfile, "wb+");
if (NULL == fpimg)
{
wm_tool_printf("open img file error: [%s].\r\n", outfile);
fclose(fpbin);
return -3;
}
/* --------deal with upgrade image's CRC begin---- */
wm_tool_file_crc = 0xFFFFFFFF;
while (!feof(fpbin))
{
memset(buf, 0, sizeof(buf));
readlen = fread(buf, 1, WM_TOOL_ONCE_READ_LEN, fpbin);
if(readlen % 4 != 0)
{
patch = 4 - readlen%4;
readlen += patch;
}
filelen += readlen;
wm_tool_get_crc32((unsigned char*)buf, readlen, 0);
}
/* --------deal with upgrade image's CRC end---- */
wm_tool_src_binary_len = filelen;
wm_tool_src_binary_crc = wm_tool_file_crc;
memset(&fbooter, 0, sizeof(wm_tool_firmware_booter_t));
strcpy((char *)fbooter.ver, name);
fbooter.magic_no = WM_TOOL_IMG_HEAD_MAGIC_NO;
fbooter.run_org_checksum = wm_tool_file_crc;
fbooter.img_type = wm_tool_image_type;
fbooter.run_img_len = filelen;
fbooter.run_img_addr = wm_tool_run_addr;
fbooter.zip_type = WM_TOOL_ZIP_TYPE_UNCOMPRESS;
fbooter.upd_img_len = filelen;
fbooter.upd_img_addr = wm_tool_upd_addr;
fbooter.upd_checksum = wm_tool_file_crc;
/* calculate image's header's CRC */
wm_tool_file_crc = 0xFFFFFFFF;
wm_tool_get_crc32((unsigned char *)&fbooter, sizeof(wm_tool_firmware_booter_t) - 4, 0);
fbooter.hd_checksum = wm_tool_file_crc;
/* write image's header to output file */
fwrite(&fbooter, 1, sizeof(wm_tool_firmware_booter_t), fpimg);
/* write image to output file */
fseek(fpbin, 0, SEEK_SET);
while (!feof(fpbin))
{
readlen = fread(buf, 1, WM_TOOL_ONCE_READ_LEN, fpbin);
fwrite(buf, 1, readlen, fpimg);
}
/* write dummy data to pad 4byte-aligned */
if (patch > 0)
{
memset(buf, 0, patch);
fwrite(buf, 1, patch, fpimg);
}
if (fpbin)
{
fclose(fpbin);
}
if (fpimg)
{
fclose(fpimg);
}
wm_tool_printf("generate normal image completed.\r\n");
return 0;
}
static int wm_tool_pack_gz_image(const char *gzbin, const char *outfile)
{
FILE *fpbin = NULL;
FILE *fpimg = NULL;
char *name = "2.0.0";
int readlen = 0;
int filelen = 0;
int patch = 0;
wm_tool_firmware_booter_t fbooter;
unsigned char buf[WM_TOOL_ONCE_READ_LEN + 1];
fpbin = fopen(gzbin, "rb");
if (NULL == fpbin)
{
wm_tool_printf("can not open input file [%s].\r\n", gzbin);
return -2;
}
fpimg = fopen(outfile, "wb+");
if (NULL == fpimg)
{
wm_tool_printf("open img file error: [%s].\r\n", outfile);
fclose(fpbin);
return -3;
}
/* --------deal with upgrade image's CRC begin---- */
wm_tool_file_crc = 0xFFFFFFFF;
while (!feof(fpbin))
{
memset(buf, 0, sizeof(buf));
readlen = fread(buf, 1, WM_TOOL_ONCE_READ_LEN, fpbin);
if(readlen % 4 != 0)
{
patch = 4 - readlen%4;
readlen += patch;
}
filelen += readlen;
wm_tool_get_crc32((unsigned char*)buf, readlen, 0);
}
/* --------deal with upgrade image's CRC end---- */
memset(&fbooter, 0, sizeof(wm_tool_firmware_booter_t));
strcpy((char *)fbooter.ver, name);
fbooter.magic_no = WM_TOOL_IMG_HEAD_MAGIC_NO;
fbooter.run_org_checksum = wm_tool_src_binary_crc;
fbooter.img_type = wm_tool_image_type;
fbooter.run_img_len = wm_tool_src_binary_len;
fbooter.run_img_addr = wm_tool_run_addr;
fbooter.zip_type = wm_tool_zip_type;
fbooter.upd_img_len = filelen;
fbooter.upd_img_addr = wm_tool_upd_addr;
fbooter.upd_checksum = wm_tool_file_crc;
/* calculate image's header's CRC */
wm_tool_file_crc = 0xFFFFFFFF;
wm_tool_get_crc32((unsigned char *)&fbooter, sizeof(wm_tool_firmware_booter_t) - 4, 0);
fbooter.hd_checksum = wm_tool_file_crc;
/* write image's header to output file */
fwrite(&fbooter, 1, sizeof(wm_tool_firmware_booter_t), fpimg);
/* write image to output file */
fseek(fpbin, 0, SEEK_SET);
while (!feof(fpbin))
{
readlen = fread(buf, 1, WM_TOOL_ONCE_READ_LEN, fpbin);
fwrite(buf, 1, readlen, fpimg);
}
/* write dummy data to pad 4byte-aligned */
if (patch > 0)
{
memset(buf, 0, patch);
fwrite(buf, 1, patch, fpimg);
}
if (fpbin)
{
fclose(fpbin);
}
if (fpimg)
{
fclose(fpimg);
}
wm_tool_printf("generate compressed image completed.\r\n");
return 0;
}
static int wm_tool_pack_dbg_image(const char *image, const char *outfile)
{
FILE *fpimg = NULL;
FILE *fout = NULL;
unsigned char buf[WM_TOOL_ONCE_READ_LEN + 1];
int readlen = 0;
int i;
wm_tool_firmware_booter_t fbooter;
int appimg_len = 0;
int final_len = 0;
int magic_word = 0;
fpimg = fopen(image, "rb");
if (NULL == fpimg)
{
wm_tool_printf("open img file error: [%s].\r\n", image);
return -4;
}
magic_word = 0;
readlen = fread(&magic_word, 1, 4, fpimg);
if (magic_word != WM_TOOL_IMG_HEAD_MAGIC_NO)
{
wm_tool_printf("input [%s] file magic error.\n", image);
fclose(fpimg);
return -4;
}
fout = fopen(outfile, "wb+");
appimg_len = wm_tool_get_file_size(image);
/* write 0xFF to output file */
final_len = WM_TOOL_RUN_IMG_HEADER_LEN + (appimg_len - sizeof(wm_tool_firmware_booter_t));
for (i = 0; i < (final_len /WM_TOOL_ONCE_READ_LEN); i++)
{
memset(buf, 0xff, WM_TOOL_ONCE_READ_LEN);
fwrite(buf, 1, WM_TOOL_ONCE_READ_LEN, fout);
}
memset(buf, 0xff, final_len % WM_TOOL_ONCE_READ_LEN);
fwrite(buf, 1, final_len % WM_TOOL_ONCE_READ_LEN, fout);
memset(&fbooter, 0, sizeof(wm_tool_firmware_booter_t));
/* write sec img to output file */
fseek(fpimg, 0, SEEK_SET);
readlen = fread((unsigned char *)&fbooter, 1, sizeof(wm_tool_firmware_booter_t), fpimg);
fseek(fout, 0, SEEK_SET);
fwrite(&fbooter, 1, sizeof(wm_tool_firmware_booter_t), fout);
fseek(fout, WM_TOOL_RUN_IMG_HEADER_LEN, SEEK_SET);
while (!feof(fpimg))
{
readlen = fread(buf, 1, WM_TOOL_ONCE_READ_LEN, fpimg);
fwrite(buf, 1, readlen, fout);
}
if (fpimg)
{
fclose(fpimg);
}
if (fout)
{
fclose(fout);
}
wm_tool_printf("generate debug image completed.\r\n");
return 0;
}
static int wm_tool_pack_fls(const char *image, const char *outfile)
{
FILE *fpbin = NULL;
FILE *fpimg = NULL;
FILE *fout = NULL;
unsigned char buf[WM_TOOL_ONCE_READ_LEN + 1];
int readlen = 0;
int filelen = 0;
int i;
wm_tool_firmware_booter_t fbooter;
int appimg_len = 0;
int final_len = 0;
int magic_word = 0;
if (!wm_tool_secboot_image)
return 0;/* maybe return 1 */
fpbin = fopen(wm_tool_secboot_image,"rb");
if (NULL == fpbin)
{
wm_tool_printf("can not open input file [%s].\r\n", wm_tool_secboot_image);
return -2;
}
magic_word = 0;
readlen = fread(&magic_word, 1, 4, fpbin);
if (magic_word != WM_TOOL_IMG_HEAD_MAGIC_NO)
{
wm_tool_printf("input [%s] file magic error.\r\n", wm_tool_secboot_image);
return -3;
}
fpimg = fopen(image, "rb");
if (NULL == fpimg)
{
wm_tool_printf("open img file error [%s].\r\n", image);
fclose(fpbin);
return -4;
}
magic_word = 0;
readlen = fread(&magic_word, 1, 4, fpimg);
if (magic_word != WM_TOOL_IMG_HEAD_MAGIC_NO)
{
wm_tool_printf("input [%s] file magic error.\r\n", image);
return -4;
}
fout = fopen(outfile, "wb+");
appimg_len = wm_tool_get_file_size(image);
/* write 0xFF to output file */
final_len = WM_TOOL_SECBOOT_IMG_AREA_TOTAL_LEN + appimg_len;
for (i = 0; i < (final_len /WM_TOOL_ONCE_READ_LEN); i++)
{
memset(buf, 0xff, WM_TOOL_ONCE_READ_LEN);
fwrite(buf, 1, WM_TOOL_ONCE_READ_LEN, fout);
}
memset(buf, 0xff, final_len % WM_TOOL_ONCE_READ_LEN);
fwrite(buf, 1, final_len % WM_TOOL_ONCE_READ_LEN, fout);
fseek(fout, sizeof(wm_tool_firmware_booter_t), SEEK_SET);
fseek(fpbin, 0, SEEK_SET);
/* write SECBOOT header to output file */
readlen = fread(buf, 1, sizeof(wm_tool_firmware_booter_t), fpbin);
fwrite(buf, 1, sizeof(wm_tool_firmware_booter_t), fout);
/* write SECBOOT image to output file */
fseek(fout, sizeof(wm_tool_firmware_booter_t) + 256, SEEK_SET);
while (!feof(fpbin))
{
readlen = fread(buf, 1, WM_TOOL_ONCE_READ_LEN, fpbin);
fwrite(buf, 1, readlen, fout);
}
/* write run img header to output file */
fseek(fout, sizeof(wm_tool_firmware_booter_t) + WM_TOOL_SECBOOT_IMG_AREA_TOTAL_LEN, SEEK_SET);
fseek(fpimg, 0, SEEK_SET);
readlen = fread(buf, 1, sizeof(wm_tool_firmware_booter_t), fpimg);
fwrite(buf, 1, readlen, fout);
fseek(fout, sizeof(wm_tool_firmware_booter_t) + WM_TOOL_SECBOOT_IMG_AREA_TOTAL_LEN + WM_TOOL_RUN_IMG_HEADER_LEN, SEEK_SET);
/* write run img to output file */
fseek(fpimg, sizeof(wm_tool_firmware_booter_t), SEEK_SET);
while (!feof(fpimg))
{
readlen = fread(buf, 1, WM_TOOL_ONCE_READ_LEN, fpimg);
fwrite(buf, 1, readlen, fout);
}
/* calculate CRC from secboot header */
wm_tool_file_crc = 0xFFFFFFFF;
fseek(fout, sizeof(wm_tool_firmware_booter_t), SEEK_SET);
filelen = 0;
while (!feof(fout))
{
readlen = fread(buf, 1, WM_TOOL_ONCE_READ_LEN, fout);
filelen += readlen;
wm_tool_get_crc32((unsigned char*)buf, readlen, 0);
}
memset(&fbooter, 0, sizeof(wm_tool_firmware_booter_t));
fbooter.magic_no = WM_TOOL_IMG_HEAD_MAGIC_NO;
fbooter.run_org_checksum = wm_tool_file_crc;
fbooter.img_type = 0;
fbooter.run_img_len = filelen;
fbooter.run_img_addr = WM_TOOL_SECBOOT_HEADER_POS;
fbooter.zip_type = 0;
fbooter.upd_img_len = 0;
fbooter.upd_img_addr = 0;
fbooter.upd_checksum = 0;
/* write fls's header to output file */
wm_tool_file_crc = 0xFFFFFFFF;
wm_tool_get_crc32((unsigned char *)&fbooter, sizeof(wm_tool_firmware_booter_t) - 4, 0);
fbooter.hd_checksum = wm_tool_file_crc;
fseek(fout, 0, SEEK_SET);
fwrite(&fbooter, 1, sizeof(wm_tool_firmware_booter_t), fout);
if (fpbin)
{
fclose(fpbin);
}
if (fpimg)
{
fclose(fpimg);
}
if (fout)
{
fclose(fout);
}
wm_tool_printf("generate flash file completed.\r\n");
return 0;
}
static int wm_tool_gzip_bin(const char *binary, const char *gzbin)
{
FILE *bfp;
gzFile gzfp;
int ret;
char buf[1024];
bfp = fopen(binary, "rb");
gzfp = gzopen((char *)gzbin, "wb+");
if (!bfp || !gzfp)
{
wm_tool_printf("can not gzip binary.\r\n");
return -1;
}
do {
ret = fread(buf, 1, sizeof(buf), bfp);
if (ret > 0)
{
ret = gzwrite(gzfp, (voidp)buf, ret);
if (ret <= 0)
{
wm_tool_printf("can not write gzip binary.\r\n");
return -2;
}
}
} while (ret > 0);
gzclose(gzfp);
fclose(bfp);
wm_tool_printf("compress binary completed.\r\n");
return 0;
}
static int wm_tool_pack_firmware(void)
{
int ret;
char *path;
char *name;
char *image;
char *gzbin;
char *gzimg;
char *dbgimg;
char *fls;
if (!wm_tool_input_binary)
return 1;
if (!wm_tool_output_image)
{
char *r = wm_tool_input_binary;
char *t = wm_tool_input_binary;
do
{
r = strchr(r, '.');
if (r)
{
t = r;
r++;
}
} while (r);
wm_tool_output_image = malloc(t - wm_tool_input_binary + 1);
if (!wm_tool_output_image)
return -1;
memcpy(wm_tool_output_image, wm_tool_input_binary, t - wm_tool_input_binary);
wm_tool_output_image[t - wm_tool_input_binary] = '\0';
}
char *p = wm_tool_output_image;
char *q = wm_tool_output_image;
do
{
p = strchr(p, '/');
if (p)
{
p++;
q = p;
}
} while (p);
/* output file */
name = strdup(q);
*q = '\0';
path = strdup(wm_tool_output_image);
image = malloc(strlen(path) + strlen(name) + strlen(".img") + 1);
if (!image)
return -1;
sprintf(image, "%s%s.img", path, name);
ret = wm_tool_pack_image(image);
if (ret)
return ret;
if (WM_TOOL_ZIP_TYPE_COMPRESS == wm_tool_zip_type)
{
gzbin = malloc(strlen(path) + strlen(name) + strlen("_gz.bin") + 1);
gzimg = malloc(strlen(path) + strlen(name) + strlen("_gz.img") + 1);
if (!gzbin || !gzimg)
return -1;
sprintf(gzbin, "%s%s.bin.gz", path, name);
sprintf(gzimg, "%s%s_gz.img", path, name);
ret = wm_tool_gzip_bin(wm_tool_input_binary, gzbin);
if (ret)
return ret;
ret = wm_tool_pack_gz_image(gzbin, gzimg);
free(gzbin);
free(gzimg);
if (ret)
return ret;
}
if (wm_tool_is_debug)
{
dbgimg = malloc(strlen(path) + strlen(name) + strlen("_dbg.img") + 1);
if (!dbgimg)
return -1;
sprintf(dbgimg, "%s%s_dbg.img", path, name);
ret = wm_tool_pack_dbg_image(image, dbgimg);
free(dbgimg);
if (ret)
return ret;
}
fls = malloc(strlen(path) + strlen(name) + strlen(".fls") + 1);
if (!fls)
return -1;
sprintf(fls, "%s%s.fls", path, name);
ret = wm_tool_pack_fls(image, fls);
free(image);
free(fls);
return ret;
}
#ifdef __MINGW32__
static void wm_tool_delay_ms(int ms)
{
Sleep(ms);
return;
}
static int wm_tool_uart_set_rts(int boolflag)
{
return EscapeCommFunction(wm_tool_uart_handle,((boolflag) ? SETRTS : CLRRTS)) ? 0 : -1;
}
static int wm_tool_uart_set_dtr(int boolflag)
{
return EscapeCommFunction(wm_tool_uart_handle,((boolflag) ? SETDTR : CLRDTR)) ? 0 : -1;
}
static int wm_tool_uart_set_timeout(void)
{
BOOL ret;
COMMTIMEOUTS timeout;
timeout.ReadIntervalTimeout = MAXDWORD;
timeout.ReadTotalTimeoutConstant = 0;
timeout.ReadTotalTimeoutMultiplier = 0;
timeout.WriteTotalTimeoutConstant = 0;
timeout.WriteTotalTimeoutMultiplier = 0;
ret = SetCommTimeouts(wm_tool_uart_handle, &timeout);
if (ret)
ret = SetCommMask(wm_tool_uart_handle, EV_TXEMPTY);
return ret ? 0 : -1;
}
static void wm_tool_uart_set_block(int bolck)
{
if (bolck)
wm_tool_uart_block = INFINITE;
else
wm_tool_uart_block = 0;
return;
}
static int wm_tool_uart_set_speed(int speed)
{
int i;
int size;
DCB cfg;
size = sizeof(wm_tool_uart_speed_array) / sizeof(int);
for (i= 0; i < size; i++)
{
if (speed == wm_tool_uart_name_array[i])
{
if (GetCommState(wm_tool_uart_handle, &cfg))
{
cfg.DCBlength = sizeof(DCB);
cfg.BaudRate = wm_tool_uart_speed_array[i];
cfg.fBinary = TRUE;
cfg.fParity = FALSE;
cfg.fDtrControl = DTR_CONTROL_DISABLE;
cfg.fDsrSensitivity = FALSE;
cfg.fRtsControl = RTS_CONTROL_DISABLE;
cfg.ByteSize = 8;
cfg.StopBits = ONESTOPBIT;
cfg.fAbortOnError = FALSE;
cfg.fOutX = FALSE;
cfg.fInX = FALSE;
cfg.fErrorChar = FALSE;
cfg.fNull = FALSE;
cfg.fOutxCtsFlow = FALSE;
cfg.fOutxDsrFlow = FALSE;
cfg.Parity = NOPARITY;
cfg.fTXContinueOnXoff = FALSE;
return SetCommState(wm_tool_uart_handle, &cfg) ? 0 : -1;
}
else
{
return -3;
}
}
}
return -2;
}
static void wm_tool_uart_clear(void)
{
PurgeComm(wm_tool_uart_handle, PURGE_RXCLEAR);
return;
}
static int wm_tool_uart_open(const char *device)
{
BOOL ret;
char name[40];
sprintf(name,"\\\\.\\%s", device);
wm_tool_uart_handle = CreateFile(name, GENERIC_WRITE | GENERIC_READ,
0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
if (wm_tool_uart_handle == INVALID_HANDLE_VALUE)
{
return -1;
}
ret = SetupComm(wm_tool_uart_handle, 4096, 4096);
if (ret)
{
ret = wm_tool_uart_set_speed(WM_TOOL_DEFAULT_BAUD_RATE);
ret |= wm_tool_uart_set_timeout();
}
else
{
ret = -1;
}
return ret;
}
static int wm_tool_uart_read(void *data, unsigned int size)
{
BOOL ret;
DWORD wait;
unsigned long len = 0;
COMSTAT state;
DWORD error;
OVERLAPPED event;
do
{
memset(&event, 0, sizeof(OVERLAPPED));
event.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
ClearCommError(wm_tool_uart_handle, &error, &state);
ret = ReadFile(wm_tool_uart_handle, data, size, &len, &event);
if (!ret)
{
if (ERROR_IO_PENDING == GetLastError())
{
wait = WaitForSingleObject(event.hEvent, wm_tool_uart_block);
if (WAIT_OBJECT_0 == wait)
ret = TRUE;
}
}
} while (wm_tool_uart_block && !len);
if (ret)
{
if (len > 0)
return (int)len;
}
return -1;
}
static int wm_tool_uart_write(const void *data, unsigned int size)
{
BOOL ret;
DWORD wait;
OVERLAPPED event;
COMSTAT state;
DWORD error;
unsigned int snd = 0;
unsigned long len = 0;
memset(&event, 0, sizeof(OVERLAPPED));
event.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
do
{
ClearCommError(wm_tool_uart_handle, &error, &state);
ret = WriteFile(wm_tool_uart_handle, data + snd, size - snd, &len, &event);
if (!ret)
{
if (ERROR_IO_PENDING == GetLastError())
{
wait = WaitForSingleObject(event.hEvent, INFINITE);
if (WAIT_OBJECT_0 == wait)
ret = TRUE;
}
}
if (ret)
{
if ((len > 0) && (snd != size))
{
snd += len;
}
else
{
return size;
}
}
else
{
break;
}
} while (1);
return -1;
}
static void wm_tool_uart_close(void)
{
FlushFileBuffers(wm_tool_uart_handle);
CloseHandle(wm_tool_uart_handle);
wm_tool_uart_handle = NULL;
return;
}
static DWORD WINAPI wm_tool_uart_tx_thread(LPVOID arg)
{
wm_tool_stdin_to_uart();
return 0;
}
static int wm_tool_create_thread(void)
{
HANDLE thread_handle;
thread_handle = CreateThread(0, 0, wm_tool_uart_tx_thread, NULL, 0, NULL);
CloseHandle(thread_handle);
return 0;
}
#else
static void wm_tool_delay_ms(int ms)
{
usleep(ms * 1000);
return;
}
static int wm_tool_uart_set_rts(int boolflag)
{
int ret;
int controlbits;
ret = ioctl(wm_tool_uart_fd, TIOCMGET, &controlbits);
if (ret < 0)
{
WM_TOOL_DBG_PRINT("TIOCMGET failed!\r\n");
return ret;
}
if (controlbits & TIOCM_RTS)
{
WM_TOOL_DBG_PRINT("TIOCM_RTS!, %d!\r\n", boolflag);
}
else
{
WM_TOOL_DBG_PRINT("~TIOCM_RTS!, %d!\r\n", boolflag);
}
if (boolflag)
controlbits |= TIOCM_RTS;
else
controlbits &= ~TIOCM_RTS;
ret = ioctl(wm_tool_uart_fd, TIOCMSET, &controlbits);
if (ret < 0)
{
WM_TOOL_DBG_PRINT("TIOCMSET failed!\r\n");
}
if (ret >= 0)
ret = 0;
return ret;
}
static int wm_tool_uart_set_dtr(int boolflag)
{
int ret;
int controlbits;
ret = ioctl(wm_tool_uart_fd, TIOCMGET, &controlbits);
if (ret < 0)
{
WM_TOOL_DBG_PRINT("TIOCMGET failed!\r\n");
return ret;
}
if (controlbits & TIOCM_DTR)
{
WM_TOOL_DBG_PRINT("TIOCM_DTR, %d!\r\n", boolflag);
}
else
{
WM_TOOL_DBG_PRINT("~TIOCM_DTR, %d!\r\n", boolflag);
}
if (boolflag)
controlbits |= TIOCM_DTR;
else
controlbits &= ~TIOCM_DTR;
ret = ioctl(wm_tool_uart_fd, TIOCMSET, &controlbits);
if (ret < 0)
{
WM_TOOL_DBG_PRINT("TIOCMSET failed!\r\n");
}
if (ret >= 0)
ret = 0;
return ret;
}
static void wm_tool_uart_set_block(int bolck)
{
int comopt;
comopt = fcntl(wm_tool_uart_fd, F_GETFL, 0);
if (bolck)
fcntl(wm_tool_uart_fd, F_SETFL, comopt & ~O_NDELAY);
else
fcntl(wm_tool_uart_fd, F_SETFL, comopt | O_NDELAY);
return;
}
static int wm_tool_uart_set_speed(int speed)
{
int i;
int size;
int status;
struct termios opt;
tcgetattr(wm_tool_uart_fd, &opt);
size = sizeof(wm_tool_uart_speed_array) / sizeof(int);
for (i= 0; i < size; i++)
{
if (speed == wm_tool_uart_name_array[i])
{
cfsetispeed(&opt, wm_tool_uart_speed_array[i]);
cfsetospeed(&opt, wm_tool_uart_speed_array[i]);
status = tcsetattr(wm_tool_uart_fd, TCSANOW, &opt);
if (status != 0)
{
return -1;
}
}
}
return 0;
}
static void wm_tool_uart_clear(void)
{
tcflush(wm_tool_uart_fd, TCIFLUSH);
return;
}
static int wm_tool_uart_open(const char *device)
{
struct termios tty;
wm_tool_uart_fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
if (-1 == wm_tool_uart_fd)
{
return -1;
}
tcgetattr(wm_tool_uart_fd, &wm_tool_saved_serial_cfg);
wm_tool_uart_set_dtr(0);
tcgetattr(wm_tool_uart_fd, &tty);
/* databit 8bit */
tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;
/* set into raw, no echo mode */
tty.c_iflag = IGNBRK;
tty.c_lflag = 0;
tty.c_oflag = 0;
tty.c_cflag |= CLOCAL | CREAD;
tty.c_cflag &= ~CRTSCTS;
tty.c_cc[VMIN] = 1;
tty.c_cc[VTIME] = 5;
/* have no software flow control */
tty.c_iflag &= ~(IXON|IXOFF|IXANY);
/* parity none */
tty.c_cflag &= ~(PARENB | PARODD);
/* stopbit 1bit */
tty.c_cflag &= ~CSTOPB;
tcsetattr(wm_tool_uart_fd, TCSANOW, &tty);
return wm_tool_uart_set_speed(WM_TOOL_DEFAULT_BAUD_RATE);
}
static int wm_tool_uart_read(void *data, unsigned int size)
{
return read(wm_tool_uart_fd, data, size);
}
static int wm_tool_uart_write(const void *data, unsigned int size)
{
int snd = 0;
int ret = 0;
do
{
ret = write(wm_tool_uart_fd, data + snd, size - snd);
if (ret > 0)
{
snd += ret;
if (snd == size)
{
return size;
}
}
else
{
break;
}
} while (1);
return -1;
}
static void wm_tool_uart_close(void)
{
tcsetattr(wm_tool_uart_fd, TCSANOW, &wm_tool_saved_serial_cfg);
tcdrain(wm_tool_uart_fd);
tcflush(wm_tool_uart_fd, TCIOFLUSH);
close(wm_tool_uart_fd);
wm_tool_uart_fd = -1;
return;
}
static void *wm_tool_uart_tx_thread(void *arg)
{
wm_tool_stdin_to_uart();
return NULL;
}
static int wm_tool_create_thread(void)
{
pthread_t thread_id;
return pthread_create(&thread_id, NULL, wm_tool_uart_tx_thread, NULL);
}
#endif
static void wm_tool_stdin_to_uart(void)
{
int ret;
char buf[WM_TOOL_ONCE_READ_LEN];
while (1)
{
if (fgets(buf, WM_TOOL_ONCE_READ_LEN, stdin))
{
ret = wm_tool_uart_write(buf, strlen(buf));
if (ret <= 0)
{
WM_TOOL_DBG_PRINT("failed to write [%s].\r\n", buf);
}
}
}
return;
}
static int wm_tool_show_log_from_serial(void)
{
int i;
int ret;
unsigned int j = 0;
unsigned char buf[WM_TOOL_ONCE_READ_LEN + 1];
ret = wm_tool_uart_open(wm_tool_serial_path);
if (ret)
{
wm_tool_printf("can not open serial\r\n");
return ret;
}
if (WM_TOOL_DEFAULT_BAUD_RATE != wm_tool_normal_serial_rate)
{
ret = wm_tool_uart_set_speed(wm_tool_normal_serial_rate);
if (ret)
{
wm_tool_printf("can not set serial baud rate.\r\n");
wm_tool_uart_close();
return ret;
}
}
ret = wm_tool_create_thread();
if (ret)
{
wm_tool_printf("can not create thread.\r\n");
wm_tool_uart_close();
return ret;
}
wm_tool_uart_set_block(0);
while (1)
{
ret = wm_tool_uart_read(buf, WM_TOOL_ONCE_READ_LEN);
if (ret > 0)
{
if (WM_TOOL_SHOW_LOG_STR == wm_tool_show_log_type)
{
buf[ret] = '\0';
wm_tool_printf("%s", (char *)buf);
}
else if (WM_TOOL_SHOW_LOG_HEX == wm_tool_show_log_type)
{
for (i = 0; i < ret; i++, j++)
{
wm_tool_printf("%02X ", buf[i]);
if ((j + 1) % 16 == 0)
{
wm_tool_printf("\r\n");
}
}
}
else
{
break;
}
}
else
{
wm_tool_delay_ms(3);
}
}
wm_tool_uart_close();
return ret;
}
static int wm_tool_set_wifi_chip_speed(int speed)
{
int ret;
if (2000000 == speed)
{
ret = wm_tool_uart_write(wm_tool_chip_cmd_b2000000, sizeof(wm_tool_chip_cmd_b2000000));
}
else if (1000000 == speed)
{
ret = wm_tool_uart_write(wm_tool_chip_cmd_b1000000, sizeof(wm_tool_chip_cmd_b1000000));
}
else if (921600 == speed)
{
ret = wm_tool_uart_write(wm_tool_chip_cmd_b921600, sizeof(wm_tool_chip_cmd_b921600));
}
else if (460800 == speed)
{
ret = wm_tool_uart_write(wm_tool_chip_cmd_b460800, sizeof(wm_tool_chip_cmd_b460800));
}
else
{
ret = wm_tool_uart_write(wm_tool_chip_cmd_b115200, sizeof(wm_tool_chip_cmd_b115200));
}
return ret;
}
static int wm_tool_send_esc2uart(int ms)
{
int i;
int err = 0;
unsigned char esc_key = 27;
for (i = 0; i < (ms / 10); i++)
{
err = wm_tool_uart_write(&esc_key, 1);
wm_tool_delay_ms(10);/* 10-50ms */
}
return err;
}
static int wm_tool_erase_image(wm_tool_dl_erase_e type)
{
int cnt = 0;
int ret = -1;
unsigned char ch;
unsigned char sec_cmd[] = {0x21, 0x06, 0x00, 0xc7, 0x7c, 0x3f, 0x00, 0x00, 0x00};
unsigned char rom_cmd[] = {0x21, 0x06, 0x00, 0x41, 0x45, 0x32, 0x00, 0x00, 0x00};
WM_TOOL_DBG_PRINT("start erase.\r\n");
if (WM_TOOL_DL_ERASE_SECBOOT == type)
{
wm_tool_printf("erase second boot area...\r\n");
ret = wm_tool_uart_write(sec_cmd, sizeof(sec_cmd));
}
else if (WM_TOOL_DL_ERASE_ALL == type)
{
wm_tool_printf("erase image area...\r\n");
ret = wm_tool_uart_write(rom_cmd, sizeof(rom_cmd));
}
if (ret <= 0)
return -1;
wm_tool_uart_clear();
wm_tool_uart_set_block(1);
do
{
ret = wm_tool_uart_read(&ch, 1);
if (ret > 0)
{
if (('C' == ch) || ('P' == ch))
cnt++;
else
cnt = 0;
}
else
{
wm_tool_printf("erase error, errno = %d.\r\n", errno);
return -2;
}
} while (cnt < 3);
wm_tool_uart_set_block(0);
wm_tool_printf("erase finish.\r\n");
return 0;
}
static int wm_tool_query_mac(void)
{
int ret = -1;
int err;
int offset = 0;
char macstr[32] = {0};
int len = strlen("MAC:AABBCCDDEEFF\n");/* resp format, ROM "Mac:AABBCCDDEEFF\n", SECBOOT "MAC:AABBCCDDEEFF\n" */
unsigned char macaddr[6] = {0};
wm_tool_uart_clear();
wm_tool_uart_set_block(1);
err = wm_tool_uart_write(wm_tool_chip_cmd_get_mac, sizeof(wm_tool_chip_cmd_get_mac));
if (err > 0)
{
do
{
err = wm_tool_uart_read((unsigned char *)(macstr + offset), sizeof(macstr) - 1 - offset);
if (err > 0)
{
offset += err;
if (offset >= len)
{
macstr[len - 1] = '\0';/* \n -> 0 */
err = wm_tool_str_to_hex_array(macstr + strlen("MAC:"), 6, macaddr);
if (!err)
{
wm_tool_printf("mac %02X-%02X-%02X-%02X-%02X-%02X.\r\n", macaddr[0],
macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
if (!strncmp(macstr, "Mac:", strlen("Mac:")) &&
(WM_TOOL_DL_TYPE_FLS != wm_tool_dl_type))
{
wm_tool_printf("please download the firmware in .fls format.\r\n");
}
else
{
ret = 0;
}
}
break;
}
}
} while (err > 0);
}
wm_tool_uart_set_block(0);
return ret;
}
static int wm_tool_xmodem_download(const char *image)
{
FILE *imgfp;
unsigned char packet_data[XMODEM_DATA_SIZE];
unsigned char frame_data[XMODEM_DATA_SIZE + XMODEM_CRC_SIZE + XMODEM_FRAME_ID_SIZE + 1];
int complete, retry_num, pack_counter, read_number, write_number = 0, i;
unsigned short crc_value;
unsigned char ack_id;
int sndlen;
int ret = -111;
imgfp = fopen(image, "rb");
if (!imgfp)
{
wm_tool_printf("can not open image to download.\r\n");
return -1;
}
sndlen = 0;
pack_counter = 0;
complete = 0;
retry_num = 0;
wm_tool_printf("start download.\r\n");
wm_tool_printf("0%% [");
wm_tool_uart_clear();
wm_tool_uart_set_block(1);
ack_id = XMODEM_ACK;
while (!complete)
{
WM_TOOL_DBG_PRINT("switch ack_id = %x\r\n", ack_id);
switch(ack_id)
{
case XMODEM_ACK:
{
retry_num = 0;
pack_counter++;
read_number = fread(packet_data, sizeof(char), XMODEM_DATA_SIZE, imgfp);
WM_TOOL_DBG_PRINT("fread = %d\r\n", read_number);
if (read_number > 0)
{
sndlen += read_number;
if (read_number < XMODEM_DATA_SIZE)
{
WM_TOOL_DBG_PRINT("start filling the last frame!\r\n");
for ( ; read_number < XMODEM_DATA_SIZE; read_number++)
packet_data[read_number] = 0x0;
}
frame_data[0] = XMODEM_HEAD;
frame_data[1] = (char)pack_counter;
frame_data[2] = (char)(255 - frame_data[1]);
for (i = 0; i < XMODEM_DATA_SIZE; i++)
frame_data[i + 3] = packet_data[i];
crc_value = wm_tool_get_crc16(packet_data, XMODEM_DATA_SIZE);
frame_data[XMODEM_DATA_SIZE + 3]=(unsigned char)(crc_value >> 8);
frame_data[XMODEM_DATA_SIZE + 4]=(unsigned char)(crc_value);
write_number = wm_tool_uart_write(frame_data, XMODEM_DATA_SIZE + 5);
if (write_number <= 0)
wm_tool_printf("write serial error, errno = %d.\r\n", errno);
WM_TOOL_DBG_PRINT("waiting for ack, %d, %d ...\r\n", pack_counter, write_number);
while ((wm_tool_uart_read(&ack_id, 1)) <= 0);
if (ack_id == XMODEM_ACK)
{
WM_TOOL_DBG_PRINT("Ok!\r\n");
if (sndlen % 10240 == 0)
{
wm_tool_printf("#");
}
}
else
{
WM_TOOL_DBG_PRINT("error = %x!\r\n", ack_id);
}
}
else
{
ack_id = XMODEM_EOT;
complete = 1;
WM_TOOL_DBG_PRINT("waiting for complete ack ...\r\n");
while (ack_id != XMODEM_ACK)
{
ack_id = XMODEM_EOT;
write_number = wm_tool_uart_write(&ack_id, 1);
if (write_number <= 0)
wm_tool_printf("write serial error, errno = %d.\r\n", errno);
while ((wm_tool_uart_read(&ack_id, 1)) <= 0);
}
WM_TOOL_DBG_PRINT("ok\r\n");
wm_tool_printf("] 100%%\r\n");
wm_tool_printf("download completed.\r\n");
ret = 0;
}
break;
}
case XMODEM_NAK:
{
if ( retry_num++ > 100)
{
WM_TOOL_DBG_PRINT("retry too many times, quit!\r\n");
wm_tool_printf("download firmware timeout.\r\n");
complete = 1;
}
else
{
write_number = wm_tool_uart_write(frame_data, XMODEM_DATA_SIZE + 5);
if (write_number <= 0)
wm_tool_printf("write serial error, errno = %d.\r\n", errno);
WM_TOOL_DBG_PRINT("retry for ack, %d, %d ...\r\n", pack_counter, write_number);
while ((wm_tool_uart_read(&ack_id, 1)) <= 0);
if (ack_id == XMODEM_ACK)
{
WM_TOOL_DBG_PRINT("ok\r\n");
}
else
{
WM_TOOL_DBG_PRINT("error!\r\n");
}
}
break;
}
default:
{
WM_TOOL_DBG_PRINT("fatal error!\r\n");
WM_TOOL_DBG_PRINT("unknown xmodem protocal [%x].\r\n", ack_id);
wm_tool_printf("\r\ndownload failed, please reset and try again.\r\n");
complete = 1;
break;
}
}
}
wm_tool_uart_set_block(0);
fclose(imgfp);
return ret;
}
static int wm_tool_download_firmware(void)
{
int ret;
int cnt = 0;
int note = 1;
int timeout = 0;
float timeuse;
time_t start, end;
unsigned char ch;
wm_tool_printf("connecting serial...\r\n");
ret = wm_tool_uart_open(wm_tool_serial_path);
if (ret)
{
wm_tool_printf("can not open serial\r\n");
return ret;
}
/* In some cases, setting the serial port initialization setting requires a delay. */
wm_tool_delay_ms(500);
wm_tool_printf("serial connected.\r\n");
if (WM_TOOL_DL_ACTION_AT == wm_tool_dl_action)
{
if (WM_TOOL_DEFAULT_BAUD_RATE != wm_tool_normal_serial_rate)
wm_tool_uart_set_speed(wm_tool_normal_serial_rate);
#if 0 /* use erase option */
if (WM_TOOL_DL_TYPE_FLS == wm_tool_dl_type)
{
ret = wm_tool_uart_write("AT+&FLSW=8002000,0\r\n", strlen("AT+&FLSW=8002000,0\r\n"));
if (ret <= 0)
{
wm_tool_printf("destroy secboot failed.\r\n");
wm_tool_uart_close();
return -3;
}
wm_tool_delay_ms(300);
}
#endif
ret = wm_tool_uart_write("AT+Z\r\n", strlen("AT+Z\r\n"));
if (ret <= 0)
{
wm_tool_printf("reset error.\r\n");
wm_tool_uart_close();
return -4;
}
if (WM_TOOL_DEFAULT_BAUD_RATE != wm_tool_normal_serial_rate)
wm_tool_uart_set_speed(WM_TOOL_DEFAULT_BAUD_RATE);
}
else if (WM_TOOL_DL_ACTION_RTS == wm_tool_dl_action)
{
ret = wm_tool_uart_set_dtr(0);
ret |= wm_tool_uart_set_rts(1);
wm_tool_delay_ms(50);
ret |= wm_tool_uart_set_dtr(1);
ret |= wm_tool_uart_set_rts(0);
wm_tool_delay_ms(50);
ret |= wm_tool_uart_set_dtr(0);
if (ret < 0)
{
wm_tool_printf("set rts to reboot error.\r\n");
wm_tool_uart_close();
return -5;
}
}
wm_tool_printf("wait serial sync...");
wm_tool_send_esc2uart(500);/* used for delay */
start = time(NULL);
do
{
ret = wm_tool_uart_read(&ch, 1);
WM_TOOL_DBG_PRINT("ret=%d, %x-%c\r\n", ret, ch, ch);
if (ret > 0)
{
if (('C' == ch) || ('P' == ch))
cnt++;
else
cnt = 0;
}
else
{
wm_tool_send_esc2uart(30);
}
end = time(NULL);
timeuse = difftime(end, start);
if (timeuse >= 1)
{
wm_tool_printf(".");
timeout++;
if ((timeout >= (WM_TOOL_DOWNLOAD_TIMEOUT_SEC / 10)) && note)
{
wm_tool_printf("\r\nplease manually reset the device.\r\n");
note = 0;
}
else if (timeout > WM_TOOL_DOWNLOAD_TIMEOUT_SEC)
{
wm_tool_uart_close();
wm_tool_printf("\r\nserial sync timeout.\r\n");
return -6;
}
start = time(NULL);
}
} while (cnt < 3);
wm_tool_printf("\r\nserial sync sucess.\r\n");
ret = wm_tool_query_mac();
if (ret)
{
wm_tool_uart_close();
wm_tool_printf("download failed.\r\n");
return ret;
}
if (WM_TOOL_DL_ERASE_SECBOOT == wm_tool_dl_erase)
{
ret = wm_tool_erase_image(WM_TOOL_DL_ERASE_SECBOOT);
if (ret)
{
wm_tool_uart_close();
wm_tool_printf("failed to erase.\r\n");
return ret;
}
}
else if (WM_TOOL_DL_ERASE_ALL == wm_tool_dl_erase)
{
ret = wm_tool_erase_image(WM_TOOL_DL_ERASE_SECBOOT);
ret |= wm_tool_erase_image(WM_TOOL_DL_ERASE_ALL);
if (ret)
{
wm_tool_uart_close();
wm_tool_printf("failed to erase.\r\n");
return ret;
}
}
if (WM_TOOL_DEFAULT_BAUD_RATE != wm_tool_download_serial_rate)
{
ret = wm_tool_set_wifi_chip_speed(wm_tool_download_serial_rate);
if (ret > 0)
{
wm_tool_delay_ms(1 * 1000);
wm_tool_uart_set_speed(wm_tool_download_serial_rate);
}
}
ret = wm_tool_xmodem_download(wm_tool_download_image);
if (ret)
{
if (WM_TOOL_DEFAULT_BAUD_RATE != wm_tool_download_serial_rate)
{
wm_tool_delay_ms(1 * 1000);
wm_tool_set_wifi_chip_speed(WM_TOOL_DEFAULT_BAUD_RATE);
wm_tool_delay_ms(1 * 1000);
}
}
else
{
if (WM_TOOL_DL_TYPE_FLS == wm_tool_dl_type)
{
if (WM_TOOL_DL_ACTION_RTS == wm_tool_dl_action)/* auto reset */
{
wm_tool_uart_set_dtr(0);
wm_tool_uart_set_rts(1);
wm_tool_delay_ms(50);
wm_tool_uart_set_dtr(1);
wm_tool_uart_set_rts(0);
wm_tool_delay_ms(50);
wm_tool_uart_set_dtr(0);
}
else
{
wm_tool_printf("please manually reset the device.\r\n");
}
}
}
wm_tool_uart_close();
return ret;
}
static void wm_tool_show_local_com(void)
{
#if defined(__APPLE__) && defined(__MACH__)
char *comstr = "tty.usbserial";
#elif defined(__CYGWIN__)
int num;
char *comstr = "ttyS";
#elif defined(__linux__)
char *comstr = "ttyUSB";
#endif
#if defined(__APPLE__) || defined(__MACH__) || defined(__CYGWIN__) || defined(__linux__)
DIR *dir;
struct dirent *file;
dir = opendir("/dev");
if (dir)
{
while (NULL != (file = readdir(dir)))
{
if ((0 == strncmp(file->d_name, comstr, strlen(comstr))) && (DT_CHR == file->d_type))
{
#if defined(__CYGWIN__)
num = atoi(file->d_name + strlen(comstr));
wm_tool_printf("COM%d ", num + 1);
#else
wm_tool_printf("%s ", file->d_name);
#endif
}
}
closedir(dir);
wm_tool_printf("\r\n");
}
#elif defined(__MINGW32__)
LONG ret;
HKEY key;
DWORD i = 0;
DWORD knlen;
char kname[WM_TOOL_PATH_MAX] = {0};
DWORD kvlen;
char kvalue[WM_TOOL_PATH_MAX] = {0};
REGSAM kmask = KEY_READ;
#if defined(KEY_WOW64_64KEY)
BOOL is_64;
if (IsWow64Process(GetCurrentProcess(), &is_64))
{
if (is_64)
kmask |= KEY_WOW64_64KEY;
}
#endif
ret = RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DEVICEMAP\\SERIALCOMM"), 0, NULL, 0, kmask, NULL, &key, NULL);
if (ret != ERROR_SUCCESS)
{
return;
}
do{
knlen = sizeof(kname);
kvlen = sizeof(kvalue);
ret = RegEnumValue(key, i, kname, &knlen, 0, NULL, (LPBYTE)kvalue, &kvlen);
if (ret == ERROR_SUCCESS)
{
if (strcmp(kvalue, "") != 0)
{
wm_tool_printf("%s ", kvalue);
}
}
i++;
} while (ret != ERROR_NO_MORE_ITEMS);
RegCloseKey(key);
wm_tool_printf("\r\n");
#else
wm_tool_printf("\r\nunsupported system.\r\n");
#endif
return;
}
static void wm_tool_free_res(void)
{
if (wm_tool_download_image)
free(wm_tool_download_image);
if (wm_tool_output_image)
free(wm_tool_output_image);
if (wm_tool_input_binary)
free(wm_tool_input_binary);
if (wm_tool_secboot_image)
free(wm_tool_secboot_image);
return;
}
int main(int argc, char *argv[])
{
int ret = 0;
if (!wm_tool_parse_arv(argc, argv))
{
wm_tool_print_usage(argv[0]);
wm_tool_free_res();
return 0;
}
if (wm_tool_show_usage)
{
wm_tool_print_usage(argv[0]);
wm_tool_free_res();
return 0;
}
if (wm_tool_show_ver)
{
wm_tool_print_version(argv[0]);
wm_tool_free_res();
return 0;
}
if (wm_tool_list_com)
{
wm_tool_show_local_com();
wm_tool_free_res();
return 0;
}
if (wm_tool_input_binary)
{
ret = wm_tool_pack_firmware();
}
if (wm_tool_download_image)
{
ret = wm_tool_download_firmware();
}
if (wm_tool_show_log_type)
{
ret = wm_tool_show_log_from_serial();
}
if (ret > 0)
wm_tool_print_usage(argv[0]);
wm_tool_free_res();
return ret;
}
|
the_stack_data/165768182.c | // this source is derived from CHILL AST originally from file '/uufs/chpc.utah.edu/common/home/u1142914/lib/ytopt_vinu/polybench/polybench-code/stencils/fdtd-2d/kernel.c' as parsed by frontend compiler rose
void kernel_fdtd_2d(int tmax, int nx, int ny, double ex[1000 + 0][1200 + 0], double ey[1000 + 0][1200 + 0], double hz[1000 + 0][1200 + 0], double _fict_[500 + 0]) {
int t10;
int t8;
int t6;
int t4;
int t2;
for (t2 = 0; t2 <= tmax - 1; t2 += 1) {
for (t4 = 0; t4 <= ny - 1; t4 += 1)
ey[0][t4] = _fict_[t2];
for (t4 = 1; t4 <= nx - 1; t4 += 100)
for (t6 = t4; t6 <= (t4 + 99 < nx - 1 ? t4 + 99 : nx - 1); t6 += 1)
for (t8 = 0; t8 <= ny - 1; t8 += 30)
for (t10 = t8; t10 <= (ny - 1 < t8 + 29 ? ny - 1 : t8 + 29); t10 += 1)
ey[t6][t10] = ey[t6][t10] - 0.5 * (hz[t6][t10] - hz[t6 - 1][t10]);
for (t4 = 0; t4 <= nx - 1; t4 += 100)
for (t6 = t4; t6 <= (t4 + 99 < nx - 1 ? t4 + 99 : nx - 1); t6 += 1)
for (t8 = 1; t8 <= ny - 1; t8 += 30)
for (t10 = t8; t10 <= (ny - 1 < t8 + 29 ? ny - 1 : t8 + 29); t10 += 1)
ex[t6][t10] = ex[t6][t10] - 0.5 * (hz[t6][t10] - hz[t6][t10 - 1]);
for (t4 = 0; t4 <= nx - 2; t4 += 100)
for (t6 = t4; t6 <= (t4 + 99 < nx - 2 ? t4 + 99 : nx - 2); t6 += 1)
for (t8 = 0; t8 <= ny - 2; t8 += 30)
for (t10 = t8; t10 <= (ny - 2 < t8 + 29 ? ny - 2 : t8 + 29); t10 += 1)
hz[t6][t10] = hz[t6][t10] - 0.69999999999999996 * (ex[t6][t10 + 1] - ex[t6][t10] + ey[t6 + 1][t10] - ey[t6][t10]);
}
}
|
the_stack_data/764260.c | #include <stdio.h>
int main(void)
{
int year, month, day;
int sumdays = 0;
do {
printf("请输入日期(y/m/d):");
scanf("%d/%d/%d", &year, &month, &day);
} while(!(year > 0 && (month > 0 && month <= 12) && (day > 0 && day <= 31)));
sumdays = day;
#if 0
// 1~month-1
switch(month-1) {
case 11:
sumdays += 30;
case 10:
sumdays += 31;
case 9:
sumdays += 30;
case 8:
sumdays += 31;
case 7:
sumdays += 31;
case 6:
sumdays += 30;
case 5:
sumdays += 31;
case 4:
sumdays += 30;
case 3:
sumdays += 31;
case 2:
sumdays += (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? 29:28;
case 1:
sumdays += 31;
break;
default:
break;
}
#endif
for (int i = 1; i < month; i++) {
if (i == 1 || i == 3 || i == 5 || \
i == 7 || i == 8 || i == 10 || i == 12)
sumdays += 31;
else if (i == 4 || i == 6 || i == 9 || i == 11)
sumdays += 30;
else
sumdays += (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? 29:28;
}
printf("%d/%d/%d是这一年的第%d天\n", year, month, day, sumdays);
return 0;
}
|
the_stack_data/850284.c | /*BEGIN_LEGAL
Intel Open Source License
Copyright (c) 2002-2016 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 little application is used to test calling application functions.
//
#include <stdio.h>
#if defined (TARGET_WINDOWS)
#define EXPORT_SYM __declspec( dllexport )
#else
#define EXPORT_SYM extern
#endif
EXPORT_SYM int Bar9( int,int,int,int,int,int,int,int,int );
int main()
{
int total;
total = Bar9( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
printf( "main: total = %d\n", total );
return 0;
}
|
the_stack_data/132956.c | #include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <complex.h>
#ifdef complex
#undef complex
#endif
#ifdef I
#undef I
#endif
#if defined(_WIN64)
typedef long long BLASLONG;
typedef unsigned long long BLASULONG;
#else
typedef long BLASLONG;
typedef unsigned long BLASULONG;
#endif
#ifdef LAPACK_ILP64
typedef BLASLONG blasint;
#if defined(_WIN64)
#define blasabs(x) llabs(x)
#else
#define blasabs(x) labs(x)
#endif
#else
typedef int blasint;
#define blasabs(x) abs(x)
#endif
typedef blasint integer;
typedef unsigned int uinteger;
typedef char *address;
typedef short int shortint;
typedef float real;
typedef double doublereal;
typedef struct { real r, i; } complex;
typedef struct { doublereal r, i; } doublecomplex;
#ifdef _MSC_VER
static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
#else
static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
#endif
#define pCf(z) (*_pCf(z))
#define pCd(z) (*_pCd(z))
typedef int logical;
typedef short int shortlogical;
typedef char logical1;
typedef char integer1;
#define TRUE_ (1)
#define FALSE_ (0)
/* Extern is for use with -E */
#ifndef Extern
#define Extern extern
#endif
/* I/O stuff */
typedef int flag;
typedef int ftnlen;
typedef int ftnint;
/*external read, write*/
typedef struct
{ flag cierr;
ftnint ciunit;
flag ciend;
char *cifmt;
ftnint cirec;
} cilist;
/*internal read, write*/
typedef struct
{ flag icierr;
char *iciunit;
flag iciend;
char *icifmt;
ftnint icirlen;
ftnint icirnum;
} icilist;
/*open*/
typedef struct
{ flag oerr;
ftnint ounit;
char *ofnm;
ftnlen ofnmlen;
char *osta;
char *oacc;
char *ofm;
ftnint orl;
char *oblnk;
} olist;
/*close*/
typedef struct
{ flag cerr;
ftnint cunit;
char *csta;
} cllist;
/*rewind, backspace, endfile*/
typedef struct
{ flag aerr;
ftnint aunit;
} alist;
/* inquire */
typedef struct
{ flag inerr;
ftnint inunit;
char *infile;
ftnlen infilen;
ftnint *inex; /*parameters in standard's order*/
ftnint *inopen;
ftnint *innum;
ftnint *innamed;
char *inname;
ftnlen innamlen;
char *inacc;
ftnlen inacclen;
char *inseq;
ftnlen inseqlen;
char *indir;
ftnlen indirlen;
char *infmt;
ftnlen infmtlen;
char *inform;
ftnint informlen;
char *inunf;
ftnlen inunflen;
ftnint *inrecl;
ftnint *innrec;
char *inblank;
ftnlen inblanklen;
} inlist;
#define VOID void
union Multitype { /* for multiple entry points */
integer1 g;
shortint h;
integer i;
/* longint j; */
real r;
doublereal d;
complex c;
doublecomplex z;
};
typedef union Multitype Multitype;
struct Vardesc { /* for Namelist */
char *name;
char *addr;
ftnlen *dims;
int type;
};
typedef struct Vardesc Vardesc;
struct Namelist {
char *name;
Vardesc **vars;
int nvars;
};
typedef struct Namelist Namelist;
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (fabs(x))
#define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
#define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
#define dmin(a,b) (f2cmin(a,b))
#define dmax(a,b) (f2cmax(a,b))
#define bit_test(a,b) ((a) >> (b) & 1)
#define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
#define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
#define abort_() { sig_die("Fortran abort routine called", 1); }
#define c_abs(z) (cabsf(Cf(z)))
#define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
#ifdef _MSC_VER
#define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
#define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
#else
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
#endif
#define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
#define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
#define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
//#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
#define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
#define d_abs(x) (fabs(*(x)))
#define d_acos(x) (acos(*(x)))
#define d_asin(x) (asin(*(x)))
#define d_atan(x) (atan(*(x)))
#define d_atn2(x, y) (atan2(*(x),*(y)))
#define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
#define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
#define d_cos(x) (cos(*(x)))
#define d_cosh(x) (cosh(*(x)))
#define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
#define d_exp(x) (exp(*(x)))
#define d_imag(z) (cimag(Cd(z)))
#define r_imag(z) (cimagf(Cf(z)))
#define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define d_log(x) (log(*(x)))
#define d_mod(x, y) (fmod(*(x), *(y)))
#define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
#define d_nint(x) u_nint(*(x))
#define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
#define d_sign(a,b) u_sign(*(a),*(b))
#define r_sign(a,b) u_sign(*(a),*(b))
#define d_sin(x) (sin(*(x)))
#define d_sinh(x) (sinh(*(x)))
#define d_sqrt(x) (sqrt(*(x)))
#define d_tan(x) (tan(*(x)))
#define d_tanh(x) (tanh(*(x)))
#define i_abs(x) abs(*(x))
#define i_dnnt(x) ((integer)u_nint(*(x)))
#define i_len(s, n) (n)
#define i_nint(x) ((integer)u_nint(*(x)))
#define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
#define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
#define pow_si(B,E) spow_ui(*(B),*(E))
#define pow_ri(B,E) spow_ui(*(B),*(E))
#define pow_di(B,E) dpow_ui(*(B),*(E))
#define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
#define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
#define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
#define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
#define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
#define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
#define sig_die(s, kill) { exit(1); }
#define s_stop(s, n) {exit(0);}
static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
#define z_abs(z) (cabs(Cd(z)))
#define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
#define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
#define myexit_() break;
#define mycycle() continue;
#define myceiling(w) {ceil(w)}
#define myhuge(w) {HUGE_VAL}
//#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
#define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
/* procedure parameter types for -A and -C++ */
#define F2C_proc_par_types 1
#ifdef __cplusplus
typedef logical (*L_fp)(...);
#else
typedef logical (*L_fp)();
#endif
static float spow_ui(float x, integer n) {
float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static double dpow_ui(double x, integer n) {
double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#ifdef _MSC_VER
static _Fcomplex cpow_ui(complex x, integer n) {
complex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
for(u = n; ; ) {
if(u & 01) pow.r *= x.r, pow.i *= x.i;
if(u >>= 1) x.r *= x.r, x.i *= x.i;
else break;
}
}
_Fcomplex p={pow.r, pow.i};
return p;
}
#else
static _Complex float cpow_ui(_Complex float x, integer n) {
_Complex float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
#ifdef _MSC_VER
static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
_Dcomplex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
for(u = n; ; ) {
if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
else break;
}
}
_Dcomplex p = {pow._Val[0], pow._Val[1]};
return p;
}
#else
static _Complex double zpow_ui(_Complex double x, integer n) {
_Complex double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
static integer pow_ii(integer x, integer n) {
integer pow; unsigned long int u;
if (n <= 0) {
if (n == 0 || x == 1) pow = 1;
else if (x != -1) pow = x == 0 ? 1/x : 0;
else n = -n;
}
if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
u = n;
for(pow = 1; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer dmaxloc_(double *w, integer s, integer e, integer *n)
{
double m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static integer smaxloc_(float *w, integer s, integer e, integer *n)
{
float m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i]) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i]) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
/* -- translated by f2c (version 20000121).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
/* Table of constant values */
static integer c__1 = 1;
/* > \brief \b DGBCON */
/* =========== DOCUMENTATION =========== */
/* Online html documentation available at */
/* http://www.netlib.org/lapack/explore-html/ */
/* > \htmlonly */
/* > Download DGBCON + dependencies */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgbcon.
f"> */
/* > [TGZ]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgbcon.
f"> */
/* > [ZIP]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgbcon.
f"> */
/* > [TXT]</a> */
/* > \endhtmlonly */
/* Definition: */
/* =========== */
/* SUBROUTINE DGBCON( NORM, N, KL, KU, AB, LDAB, IPIV, ANORM, RCOND, */
/* WORK, IWORK, INFO ) */
/* CHARACTER NORM */
/* INTEGER INFO, KL, KU, LDAB, N */
/* DOUBLE PRECISION ANORM, RCOND */
/* INTEGER IPIV( * ), IWORK( * ) */
/* DOUBLE PRECISION AB( LDAB, * ), WORK( * ) */
/* > \par Purpose: */
/* ============= */
/* > */
/* > \verbatim */
/* > */
/* > DGBCON estimates the reciprocal of the condition number of a real */
/* > general band matrix A, in either the 1-norm or the infinity-norm, */
/* > using the LU factorization computed by DGBTRF. */
/* > */
/* > An estimate is obtained for norm(inv(A)), and the reciprocal of the */
/* > condition number is computed as */
/* > RCOND = 1 / ( norm(A) * norm(inv(A)) ). */
/* > \endverbatim */
/* Arguments: */
/* ========== */
/* > \param[in] NORM */
/* > \verbatim */
/* > NORM is CHARACTER*1 */
/* > Specifies whether the 1-norm condition number or the */
/* > infinity-norm condition number is required: */
/* > = '1' or 'O': 1-norm; */
/* > = 'I': Infinity-norm. */
/* > \endverbatim */
/* > */
/* > \param[in] N */
/* > \verbatim */
/* > N is INTEGER */
/* > The order of the matrix A. N >= 0. */
/* > \endverbatim */
/* > */
/* > \param[in] KL */
/* > \verbatim */
/* > KL is INTEGER */
/* > The number of subdiagonals within the band of A. KL >= 0. */
/* > \endverbatim */
/* > */
/* > \param[in] KU */
/* > \verbatim */
/* > KU is INTEGER */
/* > The number of superdiagonals within the band of A. KU >= 0. */
/* > \endverbatim */
/* > */
/* > \param[in] AB */
/* > \verbatim */
/* > AB is DOUBLE PRECISION array, dimension (LDAB,N) */
/* > Details of the LU factorization of the band matrix A, as */
/* > computed by DGBTRF. U is stored as an upper triangular band */
/* > matrix with KL+KU superdiagonals in rows 1 to KL+KU+1, and */
/* > the multipliers used during the factorization are stored in */
/* > rows KL+KU+2 to 2*KL+KU+1. */
/* > \endverbatim */
/* > */
/* > \param[in] LDAB */
/* > \verbatim */
/* > LDAB is INTEGER */
/* > The leading dimension of the array AB. LDAB >= 2*KL+KU+1. */
/* > \endverbatim */
/* > */
/* > \param[in] IPIV */
/* > \verbatim */
/* > IPIV is INTEGER array, dimension (N) */
/* > The pivot indices; for 1 <= i <= N, row i of the matrix was */
/* > interchanged with row IPIV(i). */
/* > \endverbatim */
/* > */
/* > \param[in] ANORM */
/* > \verbatim */
/* > ANORM is DOUBLE PRECISION */
/* > If NORM = '1' or 'O', the 1-norm of the original matrix A. */
/* > If NORM = 'I', the infinity-norm of the original matrix A. */
/* > \endverbatim */
/* > */
/* > \param[out] RCOND */
/* > \verbatim */
/* > RCOND is DOUBLE PRECISION */
/* > The reciprocal of the condition number of the matrix A, */
/* > computed as RCOND = 1/(norm(A) * norm(inv(A))). */
/* > \endverbatim */
/* > */
/* > \param[out] WORK */
/* > \verbatim */
/* > WORK is DOUBLE PRECISION array, dimension (3*N) */
/* > \endverbatim */
/* > */
/* > \param[out] IWORK */
/* > \verbatim */
/* > IWORK is INTEGER array, dimension (N) */
/* > \endverbatim */
/* > */
/* > \param[out] INFO */
/* > \verbatim */
/* > INFO is INTEGER */
/* > = 0: successful exit */
/* > < 0: if INFO = -i, the i-th argument had an illegal value */
/* > \endverbatim */
/* Authors: */
/* ======== */
/* > \author Univ. of Tennessee */
/* > \author Univ. of California Berkeley */
/* > \author Univ. of Colorado Denver */
/* > \author NAG Ltd. */
/* > \date December 2016 */
/* > \ingroup doubleGBcomputational */
/* ===================================================================== */
/* Subroutine */ int dgbcon_(char *norm, integer *n, integer *kl, integer *ku,
doublereal *ab, integer *ldab, integer *ipiv, doublereal *anorm,
doublereal *rcond, doublereal *work, integer *iwork, integer *info)
{
/* System generated locals */
integer ab_dim1, ab_offset, i__1, i__2, i__3;
doublereal d__1;
/* Local variables */
integer kase;
extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
integer *);
integer kase1, j;
doublereal t, scale;
extern logical lsame_(char *, char *);
integer isave[3];
extern /* Subroutine */ int drscl_(integer *, doublereal *, doublereal *,
integer *);
logical lnoti;
extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *,
integer *, doublereal *, integer *), dlacn2_(integer *,
doublereal *, doublereal *, integer *, doublereal *, integer *,
integer *);
integer kd;
extern doublereal dlamch_(char *);
integer lm, jp, ix;
extern integer idamax_(integer *, doublereal *, integer *);
extern /* Subroutine */ int dlatbs_(char *, char *, char *, char *,
integer *, integer *, doublereal *, integer *, doublereal *,
doublereal *, doublereal *, integer *), xerbla_(char *, integer *, ftnlen);
doublereal ainvnm;
logical onenrm;
char normin[1];
doublereal smlnum;
/* -- LAPACK computational routine (version 3.7.0) -- */
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
/* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
/* December 2016 */
/* ===================================================================== */
/* Test the input parameters. */
/* Parameter adjustments */
ab_dim1 = *ldab;
ab_offset = 1 + ab_dim1 * 1;
ab -= ab_offset;
--ipiv;
--work;
--iwork;
/* Function Body */
*info = 0;
onenrm = *(unsigned char *)norm == '1' || lsame_(norm, "O");
if (! onenrm && ! lsame_(norm, "I")) {
*info = -1;
} else if (*n < 0) {
*info = -2;
} else if (*kl < 0) {
*info = -3;
} else if (*ku < 0) {
*info = -4;
} else if (*ldab < (*kl << 1) + *ku + 1) {
*info = -6;
} else if (*anorm < 0.) {
*info = -8;
}
if (*info != 0) {
i__1 = -(*info);
xerbla_("DGBCON", &i__1, (ftnlen)6);
return 0;
}
/* Quick return if possible */
*rcond = 0.;
if (*n == 0) {
*rcond = 1.;
return 0;
} else if (*anorm == 0.) {
return 0;
}
smlnum = dlamch_("Safe minimum");
/* Estimate the norm of inv(A). */
ainvnm = 0.;
*(unsigned char *)normin = 'N';
if (onenrm) {
kase1 = 1;
} else {
kase1 = 2;
}
kd = *kl + *ku + 1;
lnoti = *kl > 0;
kase = 0;
L10:
dlacn2_(n, &work[*n + 1], &work[1], &iwork[1], &ainvnm, &kase, isave);
if (kase != 0) {
if (kase == kase1) {
/* Multiply by inv(L). */
if (lnoti) {
i__1 = *n - 1;
for (j = 1; j <= i__1; ++j) {
/* Computing MIN */
i__2 = *kl, i__3 = *n - j;
lm = f2cmin(i__2,i__3);
jp = ipiv[j];
t = work[jp];
if (jp != j) {
work[jp] = work[j];
work[j] = t;
}
d__1 = -t;
daxpy_(&lm, &d__1, &ab[kd + 1 + j * ab_dim1], &c__1, &
work[j + 1], &c__1);
/* L20: */
}
}
/* Multiply by inv(U). */
i__1 = *kl + *ku;
dlatbs_("Upper", "No transpose", "Non-unit", normin, n, &i__1, &
ab[ab_offset], ldab, &work[1], &scale, &work[(*n << 1) +
1], info);
} else {
/* Multiply by inv(U**T). */
i__1 = *kl + *ku;
dlatbs_("Upper", "Transpose", "Non-unit", normin, n, &i__1, &ab[
ab_offset], ldab, &work[1], &scale, &work[(*n << 1) + 1],
info);
/* Multiply by inv(L**T). */
if (lnoti) {
for (j = *n - 1; j >= 1; --j) {
/* Computing MIN */
i__1 = *kl, i__2 = *n - j;
lm = f2cmin(i__1,i__2);
work[j] -= ddot_(&lm, &ab[kd + 1 + j * ab_dim1], &c__1, &
work[j + 1], &c__1);
jp = ipiv[j];
if (jp != j) {
t = work[jp];
work[jp] = work[j];
work[j] = t;
}
/* L30: */
}
}
}
/* Divide X by 1/SCALE if doing so will not cause overflow. */
*(unsigned char *)normin = 'Y';
if (scale != 1.) {
ix = idamax_(n, &work[1], &c__1);
if (scale < (d__1 = work[ix], abs(d__1)) * smlnum || scale == 0.)
{
goto L40;
}
drscl_(n, &scale, &work[1], &c__1);
}
goto L10;
}
/* Compute the estimate of the reciprocal condition number. */
if (ainvnm != 0.) {
*rcond = 1. / ainvnm / *anorm;
}
L40:
return 0;
/* End of DGBCON */
} /* dgbcon_ */
|
the_stack_data/220455284.c | /**
* @file ex3.c
* @brief pointer test
* @version 0.1
*
* @copyright Copyright (c) 2021
*
*/
int main(){
int a = 2;
int b = 3;
printf("%d, %d\n", a, b);
int* pa = &a;
int* pb = &b;
int t = *pb;
*pb = *pa;
*pa = t;
printf("%d, %d\n", a, b);
return 0;
} |
the_stack_data/87637882.c | #include <stdio.h>
int main()
{
printf("Velkommen til Digitale Systemer\n");
return 0;
}
|
the_stack_data/213133.c | #ifdef CS333_P2
#include "types.h"
#include "user.h"
static int
exec_helper(int current,char ** ptr)
{
int ret = fork();
if(ret < 0)
{
printf(2, "fork() failed\n");
return -2;
}
if(ret == 0)
{
exec(ptr[current], ptr+current);
return -1;
}
else
{
wait();
}
return 0;
}
int
main(int argc, char *argv[])
{
int start, end;
start = uptime();
int res = exec_helper(1, argv);
if(res == -2)
{
printf(2, "fork() failed. Unable to execute.", argv[1]);
exit();
}
if(res == -1)
{
exit();
}
end = uptime();
int total_time = (end-start)/1000;
int total_remain = (end-start)%1000;
if(total_remain == 0)
printf(2, "%s ran in %d seconds\n", argv[1], total_time);
else if(total_remain < 10)
printf(2, "%s ran in %d.00%d seconds\n", argv[1], total_time, total_remain);
else if(total_remain < 100)
printf(2, "%s ran in %d.0%d seconds\n", argv[1], total_time, total_remain);
else
printf(2, "%s ran in %d.%d seconds\n", argv[1], total_time, total_remain);
exit();
}
#endif
|
the_stack_data/68889229.c | #include <stdio.h>
int main() {
int *p, x = 10;
p = &x;
(*p)++;
printf("%d \n", *p);
}
//https://pt.stackoverflow.com/q/143084/101
|
the_stack_data/156393527.c | #ifdef STM32F0xx
#include "stm32f0xx_hal_pwr_ex.c"
#elif STM32F2xx
#include "stm32f2xx_hal_pwr_ex.c"
#elif STM32F3xx
#include "stm32f3xx_hal_pwr_ex.c"
#elif STM32F4xx
#include "stm32f4xx_hal_pwr_ex.c"
#elif STM32F7xx
#include "stm32f7xx_hal_pwr_ex.c"
#elif STM32G0xx
#include "stm32g0xx_hal_pwr_ex.c"
#elif STM32G4xx
#include "stm32g4xx_hal_pwr_ex.c"
#elif STM32H7xx
#include "stm32h7xx_hal_pwr_ex.c"
#elif STM32L0xx
#include "stm32l0xx_hal_pwr_ex.c"
#elif STM32L1xx
#include "stm32l1xx_hal_pwr_ex.c"
#elif STM32L4xx
#include "stm32l4xx_hal_pwr_ex.c"
#elif STM32L5xx
#include "stm32l5xx_hal_pwr_ex.c"
#elif STM32MP1xx
#include "stm32mp1xx_hal_pwr_ex.c"
#elif STM32WBxx
#include "stm32wbxx_hal_pwr_ex.c"
#endif
|
the_stack_data/150142716.c |
/*
Copyright (C) 1999-2005 by Mark D. Hill and David A. Wood for the
Wisconsin Multifacet Project. Contact: [email protected]
http://www.cs.wisc.edu/gems/
--------------------------------------------------------------------
This file is part of the Opal Timing-First Microarchitectural
Simulator, a component of the Multifacet GEMS (General
Execution-driven Multiprocessor Simulator) software toolset
originally developed at the University of Wisconsin-Madison.
Opal was originally developed by Carl Mauer based upon code by
Craig Zilles.
Substantial further development of Multifacet GEMS at the
University of Wisconsin was performed by Alaa Alameldeen, Brad
Beckmann, Jayaram Bobba, Ross Dickson, Dan Gibson, Pacia Harper,
Milo Martin, Michael Marty, Carl Mauer, Michelle Moravan,
Kevin Moore, Manoj Plakal, Daniel Sorin, Min Xu, and Luke Yen.
--------------------------------------------------------------------
If your use of this software contributes to a published paper, we
request that you (1) cite our summary paper that appears on our
website (http://www.cs.wisc.edu/gems/) and (2) e-mail a citation
for your published paper to [email protected].
If you redistribute derivatives of this software, we request that
you notify us and either (1) ask people to register with us at our
website (http://www.cs.wisc.edu/gems/) or (2) collect registration
information and periodically send it to us.
--------------------------------------------------------------------
Multifacet GEMS is free software; you can redistribute it and/or
modify it under the terms of version 2 of the GNU General Public
License as published by the Free Software Foundation.
Multifacet GEMS 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 the Multifacet GEMS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307, USA
The GNU General Public License is contained in the file LICENSE.
### END HEADER ###
*/
/*****************************************************************************
* Microbenchmark to test the file i/o speed. Also, this calls
* gettimeofday() to establish run time.
*
* A command line parameter gives the number of times to run the benchmark,
* as well as the number of elements in the array.
*
****************************************************************************/
/* -- define magic call for breakpoint */
#define RUBY_MAGIC_CALL( service ) \
do \
{ \
asm volatile ( \
"sethi %0, %%g0" \
: /* -- no outputs */ \
: "g" ( (((service) & 0xff) << 16) | 0 ) \
); \
} while( 0 );
#include "stdio.h"
#include "stdlib.h"
#include <sys/time.h>
int icomp( const void *i1, const void *i2 )
{
int a = *((int *) i1);
int b = *((int *) i2);
if ( a == b )
return 0;
else if ( a < b )
return -1;
// a > b
return 1;
}
int main(int argc, char* argv[])
{
if ( argc != 3 ) {
printf("usage: %s number-of-trials filename\n", argv[0]);
exit(1);
}
int numTrials = atoi( argv[1] );
FILE *fp;
int numToRead = 262144;
int numRead;
int *buffer = (int *) malloc( sizeof(int)*numToRead );
struct timeval start_tv;
struct timeval end_tv;
long total;
int rc;
/* -- 4 == Do_Breakpoint */
RUBY_MAGIC_CALL( 4 );
rc = gettimeofday( &start_tv, NULL );
if (rc != 0) {
printf("error calling: gettimeofday\n");
exit(1);
}
fp = fopen( argv[2], "r" );
if (fp == NULL) {
printf("error: unable to open file %s\n", argv[2]);
exit(1);
}
for (int i = 0; i < numTrials; i++) {
numRead = fwrite( (void *) buffer, sizeof(int), numToRead, fp );
total += buffer[0];
}
fclose( fp );
rc = gettimeofday( &end_tv, NULL );
if (rc != 0) {
printf("error calling: gettimeofday\n");
exit(1);
}
/* -- 4 == Do_Breakpoint */
RUBY_MAGIC_CALL( 4 );
printf("delta sec = %d\n", (end_tv.tv_sec - start_tv.tv_sec));
printf("delta ms = %d\n", (end_tv.tv_usec - start_tv.tv_usec));
printf("delta time= %d\n",
(end_tv.tv_sec - start_tv.tv_sec)*1000000 +
(end_tv.tv_usec - start_tv.tv_usec));
printf("(element total %ld)\n", total);
free( buffer );
return 0;
}
|
the_stack_data/212642711.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int f(char t[]) {
if (strcmp(t, "al") == 0) return 0;
if (strcmp(t, "cl") == 0) return 1;
if (strcmp(t, "dl") == 0) return 2;
if (strcmp(t, "bl") == 0) return 3;
if (strcmp(t, "ah") == 0) return 4;
if (strcmp(t, "ch") == 0) return 5;
if (strcmp(t, "dh") == 0) return 6;
if (strcmp(t, "bh") == 0) return 7;
if (strcmp(t, "ax") == 0) return 8;
if (strcmp(t, "cx") == 0) return 9;
if (strcmp(t, "dx") == 0) return 10;
if (strcmp(t, "bx") == 0) return 11;
if (strcmp(t, "sp") == 0) return 12;
if (strcmp(t, "bp") == 0) return 13;
if (strcmp(t, "si") == 0) return 14;
if (strcmp(t, "di") == 0) return 15;
return 200;
}
int main(void) {
FILE *fp, *inpF;
int sy[200], fjump[200], mcodes[200];
char t[10], u[10], v[10]; int i, g;
printf("Give filename: ");
scanf("%s", t);
inpF = fopen( t, "r");
fscanf(inpF, "%s", t);
fscanf(inpF, "%s", t);
fscanf(inpF, "%s", t);
fp = fopen( "t2", "w");
for (i = 0; i < 200; i++) {
sy[i] = -1;
fjump[i] = -1;
}
i = 0;
int j = 0;
do {
fscanf(inpF, "%s", t);
if (t[1] == ':') {
if (fjump[t[0]] != -1) {
mcodes[fjump[t[0]]] = i - fjump[t[0]] - 1;
}
sy[t[0]] = i;
}
if (strcmp(t, "int") == 0) {
fscanf(inpF, "%d", &g);
i += 2;
mcodes[j++] = 205;
mcodes[j++] = g;
}
if (strcmp(t, "jc") == 0) {
fscanf(inpF, "%s", u);
i += 2;
mcodes[j++] = 114;
if (sy[u[0]] == -1) {
fjump[u[0]] = j++;
} else {
mcodes[j++] = sy[u[0]] - i;
}
}
if (strcmp(t, "jmp") == 0) {
fscanf(inpF, "%s", u);
i += 2;
mcodes[j++] = 235;
mcodes[j++] = sy[u[0]] - i;
}
if (strcmp(t, "jl") == 0) {
fscanf(inpF, "%s", u);
i += 2;
mcodes[j++] = 124;
mcodes[j++] = sy[u[0]] - i;
}
if (strcmp(t, "add") == 0) {
fscanf(inpF, "%s%s", u, v);
if (v[0] >= '0' && v[0] <= '9') {
i += 3;
mcodes[j++] = 128;
mcodes[j++] = 192 + f(u);
mcodes[j++] = atoi(v);
} else {
i += 2;
mcodes[j++] = 2;
mcodes[j++] = 192 + f(u)*8 + f(v);
}
}
if (strcmp(t, "cmp") == 0) {
fscanf(inpF, "%s%s", u, v);
if (v[0] >= '0' && v[0] <= '9') {
i += 3;
mcodes[j++] = 128;
mcodes[j++] = 248 + f(u);
mcodes[j++] = atoi(v);
} else {
i += 2;
mcodes[j++] = 58;
mcodes[j++] = 192 + f(u)*8 + f(v);
}
}
if (strcmp(t, "mov") == 0) {
fscanf(inpF, "%s%s", u, v);
if (f(u) < 8) {
i += 2;
if (f(v) < 200) {
mcodes[j++] = 138;
mcodes[j++] = 192 + f(u)*8 + f(v);
} else {
mcodes[j++] = 176 + f(u);
mcodes[j++] = atoi(v);
}
} else {
if (f(v) < 200) {
i += 2;
mcodes[j++] = 139;
mcodes[j++] = 192 + (f(u)-8)*8 + f(v)-8;
} else {
i += 3;
mcodes[j++] = 184 + f(u)-8;
mcodes[j++] = (atoi(v) % 256);
mcodes[j++] = (atoi(v) / 256);
}
}
}
} while (strcmp(t, "end") != 0);
for (int k = 0; k < j; k++)
fprintf(fp, "%d ", mcodes[k]);
return 0;
} |
the_stack_data/576129.c | #ifdef DEBUG
#include "private.h"
#include "target-utils/lub/dump.h"
/*-------------------------------------------------------- */
void konf_query_dump(konf_query_t *this)
{
const char *op;
lub_dump_printf("query(%p)\n", this);
lub_dump_indent();
switch (this->op) {
case KONF_QUERY_OP_SET:
op = "SET";
break;
case KONF_QUERY_OP_UNSET:
op = "UNSET";
break;
case KONF_QUERY_OP_DUMP:
op = "DUMP";
break;
case KONF_QUERY_OP_OK:
op = "OK";
break;
case KONF_QUERY_OP_ERROR:
op = "ERROR";
break;
case KONF_QUERY_OP_STREAM:
op = "STREAM";
break;
default:
op = "UNKNOWN";
break;
}
lub_dump_printf("operation : %s\n", op);
lub_dump_printf("pattern : %s\n", this->pattern);
lub_dump_printf("priority : 0x%x\n", this->priority);
lub_dump_printf("sequence : %u\n", this->seq ? "true" : "false");
lub_dump_printf("seq_num : %u\n", this->seq_num);
lub_dump_printf("line : %s\n", this->line);
lub_dump_printf("path : %s\n", this->path);
lub_dump_printf("pwdc : %u\n", this->pwdc);
lub_dump_printf("splitter : %s\n", this->splitter ? "true" : "false");
lub_dump_printf("unique : %s\n", this->unique ? "true" : "false");
lub_dump_printf("depth : %d\n", this->depth);
lub_dump_undent();
}
#endif /* DEBUG */
|
the_stack_data/7949549.c | #include<stdio.h>
int main()
{
char x[6];
int i=0;
gets(x);
while(x[i]!='\0'){
i++;
}
printf("%d\n",i);
puts(x);
while(i>=0){
printf("%c",x[i-1]);
i--;
}
return 0;
}
|
the_stack_data/130405.c | #include <stdlib.h>
#include <unistd.h>
int pid;
int pipe1[2];
int pipe2[2];
void exec1()
{
// input from stdin (already done)
// output to pipe1
dup2(pipe1[1], 1);
// close fds
close(pipe1[0]);
close(pipe1[1]);
// exec
execlp("ps", "ps", "aux", NULL);
// exec didn't work, exit
perror("bad exec ps");
_exit(1);
}
void exec2()
{
// input from pipe1
dup2(pipe1[0], 0);
// output to pipe2
dup2(pipe2[1], 1);
// close fds
close(pipe1[0]);
close(pipe1[1]);
close(pipe2[0]);
close(pipe2[1]);
// exec
execlp("grep", "grep", "root", NULL);
// exec didn't work, exit
perror("bad exec grep root");
_exit(1);
}
void exec3()
{
// input from pipe2
dup2(pipe2[0], 0);
// output to stdout (already done)
// close fds
close(pipe2[0]);
close(pipe2[1]);
// exec
execlp("grep", "grep", "sbin", NULL);
// exec didn't work, exit
perror("bad exec grep sbin");
_exit(1);
}
void main()
{
// create pipe1
if (pipe(pipe1) == -1)
{
perror("bad pipe1");
exit(1);
}
// fork (ps aux)
if ((pid = fork()) == -1)
{
perror("bad fork1");
exit(1);
}
else if (pid == 0)
{
// stdin --> ps --> pipe1
exec1();
}
// parent
// create pipe2
if (pipe(pipe2) == -1)
{
perror("bad pipe2");
exit(1);
}
// fork (grep root)
if ((pid = fork()) == -1)
{
perror("bad fork2");
exit(1);
}
else if (pid == 0)
{
// pipe1 --> grep --> pipe2
exec2();
}
// parent
// close unused fds
close(pipe1[0]);
close(pipe1[1]);
// fork (grep sbin)
if ((pid = fork()) == -1)
{
perror("bad fork3");
exit(1);
}
else if (pid == 0)
{
// pipe2 --> grep --> stdout
exec3();
}
// parent
}
|
the_stack_data/117343.c | #include <stdlib.h>
extern char *getenv(const char *name);
extern int foo();
extern int bar();
int
main()
{
int rc;
char *t1 = getenv("gude");
int is_env_set = t1 != NULL;
if (is_env_set) {
int a = 0;
if (is_env_set) {
rc = 1;
} else {
rc = 0;
}
int b = 0;
}
int a = 0;
return rc;
}
|
the_stack_data/9979.c | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ____ ___ __ _
// / __// o |,'_/ .' \
// / _/ / _,'/ /_n / o / _ __ _ ___ _ _ __
// /_/ /_/ |__,'/_n_/ / \,' /.' \ ,' _/,' \ / |/ /
// / \,' // o /_\ `./ o // || /
// /_/ /_//_n_//___,'|_,'/_/|_/
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Author : Wesley Taylor-Rendal (WTR)
// Design history : Review git logs.
// Description : Illustrate Bitwise Operators
// Concepts : The various bitwise operators. See language for precedence
// : Recall the temp needed in sort comand, xor shows this
// : can be done without needing temp variable
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <stdio.h>
int main(void)
{
unsigned int w1 = 0525u, w2 = 0707u, w3 = 0122u;
printf("w1 & w2, w1 | w2, w1 ^ w2\n");
printf("%o %o %o\n", w1 & w2, w1 | w2, w1 ^ w2);
printf("~w1, ~w2, ~w3\n");
printf("%o %o %o\n", ~w1, ~w2, ~w3);
printf("w1 ^ w1, w1 & ~w2, w1 | w2 | w3\n");
printf("%o %o %o\n", w1 ^ w1, w1 & ~w2, w1 | w2 | w3);
printf("w1 | w2 & w3, w1 | w2 & ~w3\n");
printf("%o %o\n", w1 | w2 & w3, w1 | w2 & ~w3);
printf("Demorgans\n");
printf("~(~w1 & ~w2), ~(~w1 | ~w2)\n");
printf("%o %o\n", ~(~w1 & ~w2), ~(~w1 | ~w2));
printf("w1 = %o, w2 = %o\n", w1, w2);
w1 ^= w2;
w2 ^= w1;
w1 ^= w2;
printf("w1 = %o, w2 = %o\n", w1, w2);
return 0;
}
|
the_stack_data/156391874.c | #include <stdio.h>
#include <stdlib.h>
void f()
{
int y = 0;
int* x = malloc(10 * sizeof(int));
x[10] = 0;
free(x);
}
int main()
{
f();
return 0;
} |
the_stack_data/212643499.c | /*************************************************************************\
* Copyright (C) Michael Kerrisk, 2022. *
* *
* This program is free software. You may use, modify, and redistribute it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation, either version 3 or (at your option) any *
* later version. This program is distributed without any warranty. See *
* the file COPYING.gpl-v3 for details. *
\*************************************************************************/
/* Supplementary program for Chapter 61 */
/* list_host_addresses.c
List host's network interfaces and IP addresses.
*/
#define _GNU_SOURCE /* To get definition of NI_MAXHOST */
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/if_link.h>
int
main(int argc, char *argv[])
{
struct ifaddrs *ifaddr;
if (getifaddrs(&ifaddr) == -1) {
perror("getifaddrs");
exit(EXIT_FAILURE);
}
/* Walk through linked list, ignoring loopback interface and
non-AF_INET* addresses */
for (; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
if (ifaddr->ifa_addr == NULL || strcmp(ifaddr->ifa_name, "lo") == 0)
continue;
int family = ifaddr->ifa_addr->sa_family;
if (family != AF_INET && family != AF_INET6)
continue;
/* Display interface name and address */
char host[NI_MAXHOST];
int s = getnameinfo(ifaddr->ifa_addr,
(family == AF_INET) ? sizeof(struct sockaddr_in) :
sizeof(struct sockaddr_in6),
host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
if (s != 0) {
printf("getnameinfo() failed: %s\n", gai_strerror(s));
exit(EXIT_FAILURE);
}
printf("%-16s %s\n", ifaddr->ifa_name, host);
}
exit(EXIT_SUCCESS);
}
|
the_stack_data/23575636.c | /* This testcase is part of GDB, the GNU debugger.
Copyright (C) 2010-2016 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/>. */
int
dummy_2 (int a, int b, int c)
{
return a + b + c;
}
int
dummy_3 (int a, int b, int c)
{
return a - b - c;
}
|
the_stack_data/803017.c | #include <stdio.h>
int convertSecondsToSeconds(int seconds);
int convertSecondsToMinutes(int seconds);
int convertSecondsToHours(int seconds);
void main()
{
int seconds;
printf("Enter any seconds: ");
scanf("%d", &seconds);
printf("Convert %d seconds in %d seconds", seconds, convertSecondsToSeconds(seconds));
printf("\nConvert %d seconds in %d minutes", seconds, convertSecondsToMinutes(seconds));
printf("\nConvert %d minutes in %d hours", seconds, convertSecondsToHours(seconds));
}
int convertSecondsToSeconds(int seconds)
{
int sec;
return sec;
}
int convertSecondsToMinutes(int seconds)
{
int min;
min = seconds / 60;
return min;
}
int convertSecondsToHours(int seconds)
{
int hours;
hours = seconds / 60 / 60;
return hours;
}
|
the_stack_data/248580787.c | #include <stdio.h>
#include <stdlib.h>
#define IN 1
#define OUT 0
/*
* This program shows one words of text per line.
*/
int main()
{
unsigned state = OUT;
int c;
while ((c = getchar()) != EOF)
{
// detect word
if (c == ' ' || c == '\n' || c == '\t')
{
state = OUT;
// if c is non-blank and state is OUT
// a word are initialized
} else if (state == OUT)
{
state = IN;
putchar('\n');
}
putchar(c);
}
return EXIT_SUCCESS;
}
|
the_stack_data/86075278.c | // KASAN: slab-out-of-bounds Write in eth_header_parse
// https://syzkaller.appspot.com/bug?id=f4c90f2f3df2ef1ab580a3ff70eb4bf2a47aee29
// status:fixed
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <net/if_arp.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/prctl.h>
#include <sys/resource.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.h>
#include <linux/if_ether.h>
#include <linux/if_tun.h>
#include <linux/ip.h>
#include <linux/tcp.h>
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()
{
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);
}
uint64_t current_time_ms()
{
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 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);
}
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);
}
static void event_wait(event_t* ev)
{
while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
syscall(SYS_futex, &ev->state, FUTEX_WAIT, 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, 0, &ts);
if (__atomic_load_n(&ev->state, __ATOMIC_RELAXED))
return 1;
now = current_time_ms();
if (now - start > timeout)
return 0;
}
}
static void vsnprintf_check(char* str, size_t size, const char* format,
va_list args)
{
int rv;
rv = vsnprintf(str, size, format, args);
if (rv < 0)
exit(1);
if ((size_t)rv >= size)
exit(1);
}
#define COMMAND_MAX_LEN 128
#define PATH_PREFIX \
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin "
#define PATH_PREFIX_LEN (sizeof(PATH_PREFIX) - 1)
static void execute_command(bool panic, const char* format, ...)
{
va_list args;
char command[PATH_PREFIX_LEN + COMMAND_MAX_LEN];
int rv;
va_start(args, format);
memcpy(command, PATH_PREFIX, PATH_PREFIX_LEN);
vsnprintf_check(command + PATH_PREFIX_LEN, COMMAND_MAX_LEN, format, args);
va_end(args);
rv = system(command);
if (rv) {
if (panic)
exit(1);
}
}
static int tunfd = -1;
static int tun_frags_enabled;
#define SYZ_TUN_MAX_PACKET_SIZE 1000
#define TUN_IFACE "syz_tun"
#define LOCAL_MAC "aa:aa:aa:aa:aa:aa"
#define REMOTE_MAC "aa:aa:aa:aa:aa:bb"
#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;
execute_command(0, "sysctl -w net.ipv6.conf.%s.accept_dad=0", TUN_IFACE);
execute_command(0, "sysctl -w net.ipv6.conf.%s.router_solicitations=0",
TUN_IFACE);
execute_command(1, "ip link set dev %s address %s", TUN_IFACE, LOCAL_MAC);
execute_command(1, "ip addr add %s/24 dev %s", LOCAL_IPV4, TUN_IFACE);
execute_command(1, "ip neigh add %s lladdr %s dev %s nud permanent",
REMOTE_IPV4, REMOTE_MAC, TUN_IFACE);
execute_command(0, "ip -6 addr add %s/120 dev %s", LOCAL_IPV6, TUN_IFACE);
execute_command(0, "ip -6 neigh add %s lladdr %s dev %s nud permanent",
REMOTE_IPV6, REMOTE_MAC, TUN_IFACE);
execute_command(1, "ip link set dev %s up", TUN_IFACE);
}
#define DEV_IPV4 "172.20.20.%d"
#define DEV_IPV6 "fe80::%02hx"
#define DEV_MAC "aa:aa:aa:aa:aa:%02hx"
static void snprintf_check(char* str, size_t size, const char* format, ...)
{
va_list args;
va_start(args, format);
vsnprintf_check(str, size, format, args);
va_end(args);
}
static void initialize_netdevices(void)
{
unsigned i;
const char* devtypes[] = {"ip6gretap", "bridge", "vcan", "bond", "team"};
const char* devnames[] = {"lo",
"sit0",
"bridge0",
"vcan0",
"tunl0",
"gre0",
"gretap0",
"ip_vti0",
"ip6_vti0",
"ip6tnl0",
"ip6gre0",
"ip6gretap0",
"erspan0",
"bond0",
"veth0",
"veth1",
"team0",
"veth0_to_bridge",
"veth1_to_bridge",
"veth0_to_bond",
"veth1_to_bond",
"veth0_to_team",
"veth1_to_team"};
const char* devmasters[] = {"bridge", "bond", "team"};
for (i = 0; i < sizeof(devtypes) / (sizeof(devtypes[0])); i++)
execute_command(0, "ip link add dev %s0 type %s", devtypes[i], devtypes[i]);
execute_command(0, "ip link add type veth");
for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) {
execute_command(
0, "ip link add name %s_slave_0 type veth peer name veth0_to_%s",
devmasters[i], devmasters[i]);
execute_command(
0, "ip link add name %s_slave_1 type veth peer name veth1_to_%s",
devmasters[i], devmasters[i]);
execute_command(0, "ip link set %s_slave_0 master %s0", devmasters[i],
devmasters[i]);
execute_command(0, "ip link set %s_slave_1 master %s0", devmasters[i],
devmasters[i]);
execute_command(0, "ip link set veth0_to_%s up", devmasters[i]);
execute_command(0, "ip link set veth1_to_%s up", devmasters[i]);
}
execute_command(0, "ip link set bridge_slave_0 up");
execute_command(0, "ip link set bridge_slave_1 up");
for (i = 0; i < sizeof(devnames) / (sizeof(devnames[0])); i++) {
char addr[32];
snprintf_check(addr, sizeof(addr), DEV_IPV4, i + 10);
execute_command(0, "ip -4 addr add %s/24 dev %s", addr, devnames[i]);
snprintf_check(addr, sizeof(addr), DEV_IPV6, i + 10);
execute_command(0, "ip -6 addr add %s/120 dev %s", addr, devnames[i]);
snprintf_check(addr, sizeof(addr), DEV_MAC, i + 10);
execute_command(0, "ip link set dev %s address %s", devnames[i], addr);
execute_command(0, "ip link set dev %s up", devnames[i]);
}
}
static void setup_common()
{
}
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 = 160 << 20;
setrlimit(RLIMIT_AS, &rlim);
rlim.rlim_cur = rlim.rlim_max = 8 << 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)) {
}
}
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();
if (unshare(CLONE_NEWNET)) {
}
initialize_tun();
initialize_netdevices();
loop();
exit(1);
}
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 loop()
{
int call, thread;
for (call = 0; call < 6; call++) {
for (thread = 0; thread < sizeof(threads) / sizeof(threads[0]); thread++) {
struct thread_t* th = &threads[thread];
if (!th->created) {
th->created = 1;
event_init(&th->ready);
event_init(&th->done);
event_set(&th->done);
thread_start(thr, th);
}
if (!event_isset(&th->done))
continue;
event_reset(&th->done);
th->call = call;
__atomic_fetch_add(&running, 1, __ATOMIC_RELAXED);
event_set(&th->ready);
event_timedwait(&th->done, 25);
if (__atomic_load_n(&running, __ATOMIC_RELAXED))
sleep_ms((call == 6 - 1) ? 10 : 2);
break;
}
}
}
#ifndef __NR_bpf
#define __NR_bpf 321
#endif
uint64_t r[1] = {0xffffffffffffffff};
void execute_call(int call)
{
long res;
switch (call) {
case 0:
NONFAILING(*(uint32_t*)0x20000000 = 0);
NONFAILING(*(uint32_t*)0x20000004 = 2);
NONFAILING(*(uint64_t*)0x20000008 = 0x20001000);
NONFAILING(memcpy((void*)0x20001000, "\x7b\x1a\xf8\xf7\x80\xc9\xe7\x11\x48"
"\xcd\x5c\x67\x1a\x4e\xe9\x00\x00\x00"
"\xe9\xa2\x90\xff",
22));
NONFAILING(*(uint64_t*)0x20000010 = 0x20000100);
NONFAILING(memcpy((void*)0x20000100, "GPL", 4));
NONFAILING(*(uint32_t*)0x20000018 = 0);
NONFAILING(*(uint32_t*)0x2000001c = 0);
NONFAILING(*(uint64_t*)0x20000020 = 0);
NONFAILING(*(uint32_t*)0x20000028 = 0);
NONFAILING(*(uint32_t*)0x2000002c = 0);
NONFAILING(*(uint8_t*)0x20000030 = 0);
NONFAILING(*(uint8_t*)0x20000031 = 0);
NONFAILING(*(uint8_t*)0x20000032 = 0);
NONFAILING(*(uint8_t*)0x20000033 = 0);
NONFAILING(*(uint8_t*)0x20000034 = 0);
NONFAILING(*(uint8_t*)0x20000035 = 0);
NONFAILING(*(uint8_t*)0x20000036 = 0);
NONFAILING(*(uint8_t*)0x20000037 = 0);
NONFAILING(*(uint8_t*)0x20000038 = 0);
NONFAILING(*(uint8_t*)0x20000039 = 0);
NONFAILING(*(uint8_t*)0x2000003a = 0);
NONFAILING(*(uint8_t*)0x2000003b = 0);
NONFAILING(*(uint8_t*)0x2000003c = 0);
NONFAILING(*(uint8_t*)0x2000003d = 0);
NONFAILING(*(uint8_t*)0x2000003e = 0);
NONFAILING(*(uint8_t*)0x2000003f = 0);
NONFAILING(*(uint32_t*)0x20000040 = 0);
NONFAILING(*(uint32_t*)0x20000044 = 0);
syscall(__NR_bpf, 5, 0x20000000, 0x48);
break;
case 1:
NONFAILING(*(uint32_t*)0x20001000 = 0x10000);
NONFAILING(*(uint32_t*)0x20001004 = 4);
NONFAILING(*(uint32_t*)0x20001008 = 0x100);
NONFAILING(*(uint32_t*)0x2000100c = 0x400);
syscall(__NR_setsockopt, -1, 0x84, 0, 0x20001000, 6);
break;
case 2:
res = syscall(__NR_socket, 0x11, 0x80002, 0);
if (res != -1)
r[0] = res;
break;
case 3:
NONFAILING(*(uint32_t*)0x20788000 = 2);
syscall(__NR_setsockopt, r[0], 0x107, 0xa, 0x20788000, 4);
break;
case 4:
NONFAILING(*(uint16_t*)0x20000480 = 0x11);
NONFAILING(*(uint16_t*)0x20000482 = htobe16(3));
NONFAILING(*(uint32_t*)0x20000484 = 0);
NONFAILING(*(uint16_t*)0x20000488 = 1);
NONFAILING(*(uint8_t*)0x2000048a = 0);
NONFAILING(*(uint8_t*)0x2000048b = 6);
NONFAILING(*(uint8_t*)0x2000048c = 0xaa);
NONFAILING(*(uint8_t*)0x2000048d = 0xaa);
NONFAILING(*(uint8_t*)0x2000048e = 0xaa);
NONFAILING(*(uint8_t*)0x2000048f = 0xaa);
NONFAILING(*(uint8_t*)0x20000490 = 0xaa);
NONFAILING(*(uint8_t*)0x20000491 = 0xaa);
NONFAILING(*(uint8_t*)0x20000492 = 0);
NONFAILING(*(uint8_t*)0x20000493 = 0);
syscall(__NR_bind, r[0], 0x20000480, 0x14);
break;
case 5:
syscall(__NR_setsockopt, r[0], 0x107, 5, 0x20001000, 0xc5);
break;
}
}
int main()
{
syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
install_segv_handler();
do_sandbox_none();
return 0;
}
|
the_stack_data/447756.c | /*
* Copyright © 2008 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Soft-
* ware"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, provided that the above copyright
* notice(s) and this permission notice appear in all copies of the Soft-
* ware and that both the above copyright notice(s) and this permission
* notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
* ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
* RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
* THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
* QUENTIAL 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 PERFOR-
* MANCE OF THIS SOFTWARE.
*
* Except as contained in this notice, the name of a copyright holder shall
* not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization of
* the copyright holder.
*
* Authors:
* Kristian Høgsberg ([email protected])
*/
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
#include <X11/Xlib.h>
#include <X11/extensions/Xfixes.h>
#include <X11/Xlib-xcb.h>
#include <xcb/xcb.h>
#include <xcb/dri2.h>
#include "glxclient.h"
#include <X11/extensions/dri2proto.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/time.h>
#include "dri2.h"
#include "dri_common.h"
#include "dri2_priv.h"
#include "loader.h"
/* From driconf.h, user exposed so should be stable */
#define DRI_CONF_VBLANK_NEVER 0
#define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
#define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
#define DRI_CONF_VBLANK_ALWAYS_SYNC 3
#undef DRI2_MINOR
#define DRI2_MINOR 1
struct dri2_display
{
__GLXDRIdisplay base;
/*
** XFree86-DRI version information
*/
int driMajor;
int driMinor;
int driPatch;
int swapAvailable;
int invalidateAvailable;
__glxHashTable *dri2Hash;
const __DRIextension *loader_extensions[5];
};
struct dri2_drawable
{
__GLXDRIdrawable base;
__DRIdrawable *driDrawable;
__DRIbuffer buffers[5];
int bufferCount;
int width, height;
int have_back;
int have_fake_front;
int swap_interval;
uint64_t previous_time;
unsigned frames;
};
static const struct glx_context_vtable dri2_context_vtable;
/* For XCB's handling of ust/msc/sbc counters, we have to hand it the high and
* low halves separately. This helps you split them.
*/
static void
split_counter(uint64_t counter, uint32_t *hi, uint32_t *lo)
{
*hi = (counter >> 32);
*lo = counter & 0xffffffff;
}
static uint64_t
merge_counter(uint32_t hi, uint32_t lo)
{
return ((uint64_t)hi << 32) | lo;
}
static void
dri2_destroy_context(struct glx_context *context)
{
struct dri2_context *pcp = (struct dri2_context *) context;
struct dri2_screen *psc = (struct dri2_screen *) context->psc;
driReleaseDrawables(&pcp->base);
free((char *) context->extensions);
(*psc->core->destroyContext) (pcp->driContext);
free(pcp);
}
static Bool
dri2_bind_context(struct glx_context *context, struct glx_context *old,
GLXDrawable draw, GLXDrawable read)
{
struct dri2_context *pcp = (struct dri2_context *) context;
struct dri2_screen *psc = (struct dri2_screen *) pcp->base.psc;
struct dri2_drawable *pdraw, *pread;
__DRIdrawable *dri_draw = NULL, *dri_read = NULL;
struct glx_display *dpyPriv = psc->base.display;
struct dri2_display *pdp;
pdraw = (struct dri2_drawable *) driFetchDrawable(context, draw);
pread = (struct dri2_drawable *) driFetchDrawable(context, read);
driReleaseDrawables(&pcp->base);
if (pdraw)
dri_draw = pdraw->driDrawable;
else if (draw != None)
return GLXBadDrawable;
if (pread)
dri_read = pread->driDrawable;
else if (read != None)
return GLXBadDrawable;
if (!(*psc->core->bindContext) (pcp->driContext, dri_draw, dri_read))
return GLXBadContext;
/* If the server doesn't send invalidate events, we may miss a
* resize before the rendering starts. Invalidate the buffers now
* so the driver will recheck before rendering starts. */
pdp = (struct dri2_display *) dpyPriv->dri2Display;
if (!pdp->invalidateAvailable && pdraw) {
dri2InvalidateBuffers(psc->base.dpy, pdraw->base.xDrawable);
if (pread != pdraw && pread)
dri2InvalidateBuffers(psc->base.dpy, pread->base.xDrawable);
}
return Success;
}
static void
dri2_unbind_context(struct glx_context *context, struct glx_context *new)
{
struct dri2_context *pcp = (struct dri2_context *) context;
struct dri2_screen *psc = (struct dri2_screen *) pcp->base.psc;
(*psc->core->unbindContext) (pcp->driContext);
}
static struct glx_context *
dri2_create_context_attribs(struct glx_screen *base,
struct glx_config *config_base,
struct glx_context *shareList,
unsigned num_attribs,
const uint32_t *attribs,
unsigned *error)
{
struct dri2_context *pcp = NULL;
struct dri2_context *pcp_shared = NULL;
struct dri2_screen *psc = (struct dri2_screen *) base;
__GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base;
__DRIcontext *shared = NULL;
uint32_t minor_ver;
uint32_t major_ver;
uint32_t renderType;
uint32_t flags;
unsigned api;
int reset;
int release;
uint32_t ctx_attribs[2 * 6];
unsigned num_ctx_attribs = 0;
if (psc->dri2->base.version < 3) {
*error = __DRI_CTX_ERROR_NO_MEMORY;
goto error_exit;
}
/* Remap the GLX tokens to DRI2 tokens.
*/
if (!dri2_convert_glx_attribs(num_attribs, attribs,
&major_ver, &minor_ver, &renderType, &flags,
&api, &reset, &release, error))
goto error_exit;
if (!dri2_check_no_error(flags, shareList, major_ver, error)) {
goto error_exit;
}
/* Check the renderType value */
if (!validate_renderType_against_config(config_base, renderType))
goto error_exit;
if (shareList) {
/* If the shareList context is not a DRI2 context, we cannot possibly
* create a DRI2 context that shares it.
*/
if (shareList->vtable->destroy != dri2_destroy_context) {
return NULL;
}
pcp_shared = (struct dri2_context *) shareList;
shared = pcp_shared->driContext;
}
pcp = calloc(1, sizeof *pcp);
if (pcp == NULL) {
*error = __DRI_CTX_ERROR_NO_MEMORY;
goto error_exit;
}
if (!glx_context_init(&pcp->base, &psc->base, config_base))
goto error_exit;
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MAJOR_VERSION;
ctx_attribs[num_ctx_attribs++] = major_ver;
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MINOR_VERSION;
ctx_attribs[num_ctx_attribs++] = minor_ver;
/* Only send a value when the non-default value is requested. By doing
* this we don't have to check the driver's DRI2 version before sending the
* default value.
*/
if (reset != __DRI_CTX_RESET_NO_NOTIFICATION) {
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_RESET_STRATEGY;
ctx_attribs[num_ctx_attribs++] = reset;
}
if (release != __DRI_CTX_RELEASE_BEHAVIOR_FLUSH) {
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR;
ctx_attribs[num_ctx_attribs++] = release;
}
if (flags != 0) {
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_FLAGS;
/* The current __DRI_CTX_FLAG_* values are identical to the
* GLX_CONTEXT_*_BIT values.
*/
ctx_attribs[num_ctx_attribs++] = flags;
}
/* The renderType is retrieved from attribs, or set to default
* of GLX_RGBA_TYPE.
*/
pcp->base.renderType = renderType;
if (flags & __DRI_CTX_FLAG_NO_ERROR)
pcp->base.noError = GL_TRUE;
pcp->driContext =
(*psc->dri2->createContextAttribs) (psc->driScreen,
api,
config ? config->driConfig : NULL,
shared,
num_ctx_attribs / 2,
ctx_attribs,
error,
pcp);
if (pcp->driContext == NULL)
goto error_exit;
pcp->base.vtable = &dri2_context_vtable;
return &pcp->base;
error_exit:
free(pcp);
return NULL;
}
static void
dri2DestroyDrawable(__GLXDRIdrawable *base)
{
struct dri2_screen *psc = (struct dri2_screen *) base->psc;
struct dri2_drawable *pdraw = (struct dri2_drawable *) base;
struct glx_display *dpyPriv = psc->base.display;
struct dri2_display *pdp = (struct dri2_display *)dpyPriv->dri2Display;
__glxHashDelete(pdp->dri2Hash, pdraw->base.xDrawable);
(*psc->core->destroyDrawable) (pdraw->driDrawable);
/* If it's a GLX 1.3 drawables, we can destroy the DRI2 drawable
* now, as the application explicitly asked to destroy the GLX
* drawable. Otherwise, for legacy drawables, we let the DRI2
* drawable linger on the server, since there's no good way of
* knowing when the application is done with it. The server will
* destroy the DRI2 drawable when it destroys the X drawable or the
* client exits anyway. */
if (pdraw->base.xDrawable != pdraw->base.drawable)
DRI2DestroyDrawable(psc->base.dpy, pdraw->base.xDrawable);
free(pdraw);
}
static __GLXDRIdrawable *
dri2CreateDrawable(struct glx_screen *base, XID xDrawable,
GLXDrawable drawable, struct glx_config *config_base)
{
struct dri2_drawable *pdraw;
struct dri2_screen *psc = (struct dri2_screen *) base;
__GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base;
struct glx_display *dpyPriv;
struct dri2_display *pdp;
GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
dpyPriv = __glXInitialize(psc->base.dpy);
if (dpyPriv == NULL)
return NULL;
pdraw = calloc(1, sizeof(*pdraw));
if (!pdraw)
return NULL;
pdraw->base.destroyDrawable = dri2DestroyDrawable;
pdraw->base.xDrawable = xDrawable;
pdraw->base.drawable = drawable;
pdraw->base.psc = &psc->base;
pdraw->bufferCount = 0;
pdraw->swap_interval = 1; /* default may be overridden below */
pdraw->have_back = 0;
if (psc->config)
psc->config->configQueryi(psc->driScreen,
"vblank_mode", &vblank_mode);
switch (vblank_mode) {
case DRI_CONF_VBLANK_NEVER:
case DRI_CONF_VBLANK_DEF_INTERVAL_0:
pdraw->swap_interval = 0;
break;
case DRI_CONF_VBLANK_DEF_INTERVAL_1:
case DRI_CONF_VBLANK_ALWAYS_SYNC:
default:
pdraw->swap_interval = 1;
break;
}
DRI2CreateDrawable(psc->base.dpy, xDrawable);
pdp = (struct dri2_display *)dpyPriv->dri2Display;
/* Create a new drawable */
pdraw->driDrawable =
(*psc->dri2->createNewDrawable) (psc->driScreen,
config->driConfig, pdraw);
if (!pdraw->driDrawable) {
DRI2DestroyDrawable(psc->base.dpy, xDrawable);
free(pdraw);
return NULL;
}
if (__glxHashInsert(pdp->dri2Hash, xDrawable, pdraw)) {
(*psc->core->destroyDrawable) (pdraw->driDrawable);
DRI2DestroyDrawable(psc->base.dpy, xDrawable);
free(pdraw);
return None;
}
/*
* Make sure server has the same swap interval we do for the new
* drawable.
*/
if (psc->vtable.setSwapInterval)
psc->vtable.setSwapInterval(&pdraw->base, pdraw->swap_interval);
return &pdraw->base;
}
static int
dri2DrawableGetMSC(struct glx_screen *psc, __GLXDRIdrawable *pdraw,
int64_t *ust, int64_t *msc, int64_t *sbc)
{
xcb_connection_t *c = XGetXCBConnection(pdraw->psc->dpy);
xcb_dri2_get_msc_cookie_t get_msc_cookie;
xcb_dri2_get_msc_reply_t *get_msc_reply;
get_msc_cookie = xcb_dri2_get_msc_unchecked(c, pdraw->xDrawable);
get_msc_reply = xcb_dri2_get_msc_reply(c, get_msc_cookie, NULL);
if (!get_msc_reply)
return 0;
*ust = merge_counter(get_msc_reply->ust_hi, get_msc_reply->ust_lo);
*msc = merge_counter(get_msc_reply->msc_hi, get_msc_reply->msc_lo);
*sbc = merge_counter(get_msc_reply->sbc_hi, get_msc_reply->sbc_lo);
free(get_msc_reply);
return 1;
}
static int
dri2WaitForMSC(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc)
{
xcb_connection_t *c = XGetXCBConnection(pdraw->psc->dpy);
xcb_dri2_wait_msc_cookie_t wait_msc_cookie;
xcb_dri2_wait_msc_reply_t *wait_msc_reply;
uint32_t target_msc_hi, target_msc_lo;
uint32_t divisor_hi, divisor_lo;
uint32_t remainder_hi, remainder_lo;
split_counter(target_msc, &target_msc_hi, &target_msc_lo);
split_counter(divisor, &divisor_hi, &divisor_lo);
split_counter(remainder, &remainder_hi, &remainder_lo);
wait_msc_cookie = xcb_dri2_wait_msc_unchecked(c, pdraw->xDrawable,
target_msc_hi, target_msc_lo,
divisor_hi, divisor_lo,
remainder_hi, remainder_lo);
wait_msc_reply = xcb_dri2_wait_msc_reply(c, wait_msc_cookie, NULL);
if (!wait_msc_reply)
return 0;
*ust = merge_counter(wait_msc_reply->ust_hi, wait_msc_reply->ust_lo);
*msc = merge_counter(wait_msc_reply->msc_hi, wait_msc_reply->msc_lo);
*sbc = merge_counter(wait_msc_reply->sbc_hi, wait_msc_reply->sbc_lo);
free(wait_msc_reply);
return 1;
}
static int
dri2WaitForSBC(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust,
int64_t *msc, int64_t *sbc)
{
xcb_connection_t *c = XGetXCBConnection(pdraw->psc->dpy);
xcb_dri2_wait_sbc_cookie_t wait_sbc_cookie;
xcb_dri2_wait_sbc_reply_t *wait_sbc_reply;
uint32_t target_sbc_hi, target_sbc_lo;
split_counter(target_sbc, &target_sbc_hi, &target_sbc_lo);
wait_sbc_cookie = xcb_dri2_wait_sbc_unchecked(c, pdraw->xDrawable,
target_sbc_hi, target_sbc_lo);
wait_sbc_reply = xcb_dri2_wait_sbc_reply(c, wait_sbc_cookie, NULL);
if (!wait_sbc_reply)
return 0;
*ust = merge_counter(wait_sbc_reply->ust_hi, wait_sbc_reply->ust_lo);
*msc = merge_counter(wait_sbc_reply->msc_hi, wait_sbc_reply->msc_lo);
*sbc = merge_counter(wait_sbc_reply->sbc_hi, wait_sbc_reply->sbc_lo);
free(wait_sbc_reply);
return 1;
}
static __DRIcontext *
dri2GetCurrentContext()
{
struct glx_context *gc = __glXGetCurrentContext();
struct dri2_context *dri2Ctx = (struct dri2_context *)gc;
return (gc != &dummyContext) ? dri2Ctx->driContext : NULL;
}
/**
* dri2Throttle - Request driver throttling
*
* This function uses the DRI2 throttle extension to give the
* driver the opportunity to throttle on flush front, copysubbuffer
* and swapbuffers.
*/
static void
dri2Throttle(struct dri2_screen *psc,
struct dri2_drawable *draw,
enum __DRI2throttleReason reason)
{
if (psc->throttle) {
__DRIcontext *ctx = dri2GetCurrentContext();
psc->throttle->throttle(ctx, draw->driDrawable, reason);
}
}
/**
* Asks the driver to flush any queued work necessary for serializing with the
* X command stream, and optionally the slightly more strict requirement of
* glFlush() equivalence (which would require flushing even if nothing had
* been drawn to a window system framebuffer, for example).
*/
static void
dri2Flush(struct dri2_screen *psc,
__DRIcontext *ctx,
struct dri2_drawable *draw,
unsigned flags,
enum __DRI2throttleReason throttle_reason)
{
if (ctx && psc->f && psc->f->base.version >= 4) {
psc->f->flush_with_flags(ctx, draw->driDrawable, flags, throttle_reason);
} else {
if (flags & __DRI2_FLUSH_CONTEXT)
glFlush();
if (psc->f)
psc->f->flush(draw->driDrawable);
dri2Throttle(psc, draw, throttle_reason);
}
}
static void
__dri2CopySubBuffer(__GLXDRIdrawable *pdraw, int x, int y,
int width, int height,
enum __DRI2throttleReason reason, Bool flush)
{
struct dri2_drawable *priv = (struct dri2_drawable *) pdraw;
struct dri2_screen *psc = (struct dri2_screen *) pdraw->psc;
XRectangle xrect;
XserverRegion region;
__DRIcontext *ctx = dri2GetCurrentContext();
unsigned flags;
/* Check we have the right attachments */
if (!priv->have_back)
return;
xrect.x = x;
xrect.y = priv->height - y - height;
xrect.width = width;
xrect.height = height;
flags = __DRI2_FLUSH_DRAWABLE;
if (flush)
flags |= __DRI2_FLUSH_CONTEXT;
dri2Flush(psc, ctx, priv, flags, __DRI2_THROTTLE_COPYSUBBUFFER);
region = XFixesCreateRegion(psc->base.dpy, &xrect, 1);
DRI2CopyRegion(psc->base.dpy, pdraw->xDrawable, region,
DRI2BufferFrontLeft, DRI2BufferBackLeft);
/* Refresh the fake front (if present) after we just damaged the real
* front.
*/
if (priv->have_fake_front)
DRI2CopyRegion(psc->base.dpy, pdraw->xDrawable, region,
DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft);
XFixesDestroyRegion(psc->base.dpy, region);
}
static void
dri2CopySubBuffer(__GLXDRIdrawable *pdraw, int x, int y,
int width, int height, Bool flush)
{
__dri2CopySubBuffer(pdraw, x, y, width, height,
__DRI2_THROTTLE_COPYSUBBUFFER, flush);
}
static void
dri2_copy_drawable(struct dri2_drawable *priv, int dest, int src)
{
XRectangle xrect;
XserverRegion region;
struct dri2_screen *psc = (struct dri2_screen *) priv->base.psc;
xrect.x = 0;
xrect.y = 0;
xrect.width = priv->width;
xrect.height = priv->height;
if (psc->f)
(*psc->f->flush) (priv->driDrawable);
region = XFixesCreateRegion(psc->base.dpy, &xrect, 1);
DRI2CopyRegion(psc->base.dpy, priv->base.xDrawable, region, dest, src);
XFixesDestroyRegion(psc->base.dpy, region);
}
static void
dri2_wait_x(struct glx_context *gc)
{
struct dri2_drawable *priv = (struct dri2_drawable *)
GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
if (priv == NULL || !priv->have_fake_front)
return;
dri2_copy_drawable(priv, DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft);
}
static void
dri2_wait_gl(struct glx_context *gc)
{
struct dri2_drawable *priv = (struct dri2_drawable *)
GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
if (priv == NULL || !priv->have_fake_front)
return;
dri2_copy_drawable(priv, DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
}
/**
* Called by the driver when it needs to update the real front buffer with the
* contents of its fake front buffer.
*/
static void
dri2FlushFrontBuffer(__DRIdrawable *driDrawable, void *loaderPrivate)
{
struct glx_display *priv;
struct dri2_display *pdp;
struct glx_context *gc;
struct dri2_drawable *pdraw = loaderPrivate;
struct dri2_screen *psc;
if (!pdraw)
return;
if (!pdraw->base.psc)
return;
psc = (struct dri2_screen *) pdraw->base.psc;
priv = __glXInitialize(psc->base.dpy);
if (priv == NULL)
return;
pdp = (struct dri2_display *) priv->dri2Display;
gc = __glXGetCurrentContext();
dri2Throttle(psc, pdraw, __DRI2_THROTTLE_FLUSHFRONT);
/* Old servers don't send invalidate events */
if (!pdp->invalidateAvailable)
dri2InvalidateBuffers(priv->dpy, pdraw->base.xDrawable);
dri2_wait_gl(gc);
}
static void
dri2DestroyScreen(struct glx_screen *base)
{
struct dri2_screen *psc = (struct dri2_screen *) base;
/* Free the direct rendering per screen data */
(*psc->core->destroyScreen) (psc->driScreen);
driDestroyConfigs(psc->driver_configs);
free(psc->driverName);
close(psc->fd);
free(psc);
}
/**
* Process list of buffer received from the server
*
* Processes the list of buffers received in a reply from the server to either
* \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat.
*/
static void
process_buffers(struct dri2_drawable * pdraw, DRI2Buffer * buffers,
unsigned count)
{
int i;
pdraw->bufferCount = count;
pdraw->have_fake_front = 0;
pdraw->have_back = 0;
/* This assumes the DRI2 buffer attachment tokens matches the
* __DRIbuffer tokens. */
for (i = 0; i < count; i++) {
pdraw->buffers[i].attachment = buffers[i].attachment;
pdraw->buffers[i].name = buffers[i].name;
pdraw->buffers[i].pitch = buffers[i].pitch;
pdraw->buffers[i].cpp = buffers[i].cpp;
pdraw->buffers[i].flags = buffers[i].flags;
if (pdraw->buffers[i].attachment == __DRI_BUFFER_FAKE_FRONT_LEFT)
pdraw->have_fake_front = 1;
if (pdraw->buffers[i].attachment == __DRI_BUFFER_BACK_LEFT)
pdraw->have_back = 1;
}
}
unsigned dri2GetSwapEventType(Display* dpy, XID drawable)
{
struct glx_display *glx_dpy = __glXInitialize(dpy);
__GLXDRIdrawable *pdraw;
pdraw = dri2GetGlxDrawableFromXDrawableId(dpy, drawable);
if (!pdraw || !(pdraw->eventMask & GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK))
return 0;
return glx_dpy->codes->first_event + GLX_BufferSwapComplete;
}
static void show_fps(struct dri2_drawable *draw)
{
const int interval =
((struct dri2_screen *) draw->base.psc)->show_fps_interval;
struct timeval tv;
uint64_t current_time;
gettimeofday(&tv, 0);
current_time = (uint64_t)tv.tv_sec*1000000 + (uint64_t)tv.tv_usec;
draw->frames++;
if (draw->previous_time + interval * 1000000 <= current_time) {
if (draw->previous_time) {
fprintf(stderr, "libGL: FPS = %.2f\n",
((uint64_t)draw->frames * 1000000) /
(double)(current_time - draw->previous_time));
}
draw->frames = 0;
draw->previous_time = current_time;
}
}
static int64_t
dri2XcbSwapBuffers(Display *dpy,
__GLXDRIdrawable *pdraw,
int64_t target_msc,
int64_t divisor,
int64_t remainder)
{
xcb_dri2_swap_buffers_cookie_t swap_buffers_cookie;
xcb_dri2_swap_buffers_reply_t *swap_buffers_reply;
uint32_t target_msc_hi, target_msc_lo;
uint32_t divisor_hi, divisor_lo;
uint32_t remainder_hi, remainder_lo;
int64_t ret = 0;
xcb_connection_t *c = XGetXCBConnection(dpy);
split_counter(target_msc, &target_msc_hi, &target_msc_lo);
split_counter(divisor, &divisor_hi, &divisor_lo);
split_counter(remainder, &remainder_hi, &remainder_lo);
swap_buffers_cookie =
xcb_dri2_swap_buffers_unchecked(c, pdraw->xDrawable,
target_msc_hi, target_msc_lo,
divisor_hi, divisor_lo,
remainder_hi, remainder_lo);
/* Immediately wait on the swapbuffers reply. If we didn't, we'd have
* to do so some time before reusing a (non-pageflipped) backbuffer.
* Otherwise, the new rendering could get ahead of the X Server's
* dispatch of the swapbuffer and you'd display garbage.
*
* We use XSync() first to reap the invalidate events through the event
* filter, to ensure that the next drawing doesn't use an invalidated
* buffer.
*/
XSync(dpy, False);
swap_buffers_reply =
xcb_dri2_swap_buffers_reply(c, swap_buffers_cookie, NULL);
if (swap_buffers_reply) {
ret = merge_counter(swap_buffers_reply->swap_hi,
swap_buffers_reply->swap_lo);
free(swap_buffers_reply);
}
return ret;
}
static int64_t
dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
int64_t remainder, Bool flush)
{
struct dri2_drawable *priv = (struct dri2_drawable *) pdraw;
struct glx_display *dpyPriv = __glXInitialize(priv->base.psc->dpy);
struct dri2_screen *psc = (struct dri2_screen *) priv->base.psc;
struct dri2_display *pdp =
(struct dri2_display *)dpyPriv->dri2Display;
int64_t ret = 0;
/* Check we have the right attachments */
if (!priv->have_back)
return ret;
/* Old servers can't handle swapbuffers */
if (!pdp->swapAvailable) {
__dri2CopySubBuffer(pdraw, 0, 0, priv->width, priv->height,
__DRI2_THROTTLE_SWAPBUFFER, flush);
} else {
__DRIcontext *ctx = dri2GetCurrentContext();
unsigned flags = __DRI2_FLUSH_DRAWABLE;
if (flush)
flags |= __DRI2_FLUSH_CONTEXT;
dri2Flush(psc, ctx, priv, flags, __DRI2_THROTTLE_SWAPBUFFER);
ret = dri2XcbSwapBuffers(pdraw->psc->dpy, pdraw,
target_msc, divisor, remainder);
}
if (psc->show_fps_interval) {
show_fps(priv);
}
/* Old servers don't send invalidate events */
if (!pdp->invalidateAvailable)
dri2InvalidateBuffers(dpyPriv->dpy, pdraw->xDrawable);
return ret;
}
static __DRIbuffer *
dri2GetBuffers(__DRIdrawable * driDrawable,
int *width, int *height,
unsigned int *attachments, int count,
int *out_count, void *loaderPrivate)
{
struct dri2_drawable *pdraw = loaderPrivate;
DRI2Buffer *buffers;
buffers = DRI2GetBuffers(pdraw->base.psc->dpy, pdraw->base.xDrawable,
width, height, attachments, count, out_count);
if (buffers == NULL)
return NULL;
pdraw->width = *width;
pdraw->height = *height;
process_buffers(pdraw, buffers, *out_count);
free(buffers);
return pdraw->buffers;
}
static __DRIbuffer *
dri2GetBuffersWithFormat(__DRIdrawable * driDrawable,
int *width, int *height,
unsigned int *attachments, int count,
int *out_count, void *loaderPrivate)
{
struct dri2_drawable *pdraw = loaderPrivate;
DRI2Buffer *buffers;
buffers = DRI2GetBuffersWithFormat(pdraw->base.psc->dpy,
pdraw->base.xDrawable,
width, height, attachments,
count, out_count);
if (buffers == NULL)
return NULL;
pdraw->width = *width;
pdraw->height = *height;
process_buffers(pdraw, buffers, *out_count);
free(buffers);
return pdraw->buffers;
}
static int
dri2SetSwapInterval(__GLXDRIdrawable *pdraw, int interval)
{
xcb_connection_t *c = XGetXCBConnection(pdraw->psc->dpy);
struct dri2_drawable *priv = (struct dri2_drawable *) pdraw;
GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
struct dri2_screen *psc = (struct dri2_screen *) priv->base.psc;
if (psc->config)
psc->config->configQueryi(psc->driScreen,
"vblank_mode", &vblank_mode);
switch (vblank_mode) {
case DRI_CONF_VBLANK_NEVER:
if (interval != 0)
return GLX_BAD_VALUE;
break;
case DRI_CONF_VBLANK_ALWAYS_SYNC:
if (interval <= 0)
return GLX_BAD_VALUE;
break;
default:
break;
}
xcb_dri2_swap_interval(c, priv->base.xDrawable, interval);
priv->swap_interval = interval;
return 0;
}
static int
dri2GetSwapInterval(__GLXDRIdrawable *pdraw)
{
struct dri2_drawable *priv = (struct dri2_drawable *) pdraw;
return priv->swap_interval;
}
static void
driSetBackgroundContext(void *loaderPrivate)
{
struct dri2_context *pcp = (struct dri2_context *) loaderPrivate;
__glXSetCurrentContext(&pcp->base);
}
static GLboolean
driIsThreadSafe(void *loaderPrivate)
{
struct dri2_context *pcp = (struct dri2_context *) loaderPrivate;
/* Check Xlib is running in thread safe mode
*
* 'lock_fns' is the XLockDisplay function pointer of the X11 display 'dpy'.
* It wll be NULL if XInitThreads wasn't called.
*/
return pcp->base.psc->dpy->lock_fns != NULL;
}
static const __DRIdri2LoaderExtension dri2LoaderExtension = {
.base = { __DRI_DRI2_LOADER, 3 },
.getBuffers = dri2GetBuffers,
.flushFrontBuffer = dri2FlushFrontBuffer,
.getBuffersWithFormat = dri2GetBuffersWithFormat,
};
static const __DRIdri2LoaderExtension dri2LoaderExtension_old = {
.base = { __DRI_DRI2_LOADER, 3 },
.getBuffers = dri2GetBuffers,
.flushFrontBuffer = dri2FlushFrontBuffer,
.getBuffersWithFormat = NULL,
};
static const __DRIuseInvalidateExtension dri2UseInvalidate = {
.base = { __DRI_USE_INVALIDATE, 1 }
};
static const __DRIbackgroundCallableExtension driBackgroundCallable = {
.base = { __DRI_BACKGROUND_CALLABLE, 2 },
.setBackgroundContext = driSetBackgroundContext,
.isThreadSafe = driIsThreadSafe,
};
_X_HIDDEN void
dri2InvalidateBuffers(Display *dpy, XID drawable)
{
__GLXDRIdrawable *pdraw =
dri2GetGlxDrawableFromXDrawableId(dpy, drawable);
struct dri2_screen *psc;
struct dri2_drawable *pdp = (struct dri2_drawable *) pdraw;
if (!pdraw)
return;
psc = (struct dri2_screen *) pdraw->psc;
if (psc->f && psc->f->base.version >= 3 && psc->f->invalidate)
psc->f->invalidate(pdp->driDrawable);
}
static void
dri2_bind_tex_image(Display * dpy,
GLXDrawable drawable,
int buffer, const int *attrib_list)
{
struct glx_context *gc = __glXGetCurrentContext();
struct dri2_context *pcp = (struct dri2_context *) gc;
__GLXDRIdrawable *base = GetGLXDRIDrawable(dpy, drawable);
struct glx_display *dpyPriv = __glXInitialize(dpy);
struct dri2_drawable *pdraw = (struct dri2_drawable *) base;
struct dri2_display *pdp;
struct dri2_screen *psc;
if (dpyPriv == NULL)
return;
pdp = (struct dri2_display *) dpyPriv->dri2Display;
if (pdraw != NULL) {
psc = (struct dri2_screen *) base->psc;
if (!pdp->invalidateAvailable && psc->f &&
psc->f->base.version >= 3 && psc->f->invalidate)
psc->f->invalidate(pdraw->driDrawable);
if (psc->texBuffer->base.version >= 2 &&
psc->texBuffer->setTexBuffer2 != NULL) {
(*psc->texBuffer->setTexBuffer2) (pcp->driContext,
pdraw->base.textureTarget,
pdraw->base.textureFormat,
pdraw->driDrawable);
}
else {
(*psc->texBuffer->setTexBuffer) (pcp->driContext,
pdraw->base.textureTarget,
pdraw->driDrawable);
}
}
}
static void
dri2_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer)
{
struct glx_context *gc = __glXGetCurrentContext();
struct dri2_context *pcp = (struct dri2_context *) gc;
__GLXDRIdrawable *base = GetGLXDRIDrawable(dpy, drawable);
struct glx_display *dpyPriv = __glXInitialize(dpy);
struct dri2_drawable *pdraw = (struct dri2_drawable *) base;
struct dri2_screen *psc;
if (dpyPriv != NULL && pdraw != NULL) {
psc = (struct dri2_screen *) base->psc;
if (psc->texBuffer->base.version >= 3 &&
psc->texBuffer->releaseTexBuffer != NULL) {
(*psc->texBuffer->releaseTexBuffer) (pcp->driContext,
pdraw->base.textureTarget,
pdraw->driDrawable);
}
}
}
static const struct glx_context_vtable dri2_context_vtable = {
.destroy = dri2_destroy_context,
.bind = dri2_bind_context,
.unbind = dri2_unbind_context,
.wait_gl = dri2_wait_gl,
.wait_x = dri2_wait_x,
.use_x_font = DRI_glXUseXFont,
.bind_tex_image = dri2_bind_tex_image,
.release_tex_image = dri2_release_tex_image,
.get_proc_address = NULL,
.interop_query_device_info = dri2_interop_query_device_info,
.interop_export_object = dri2_interop_export_object
};
static void
dri2BindExtensions(struct dri2_screen *psc, struct glx_display * priv,
const char *driverName)
{
const struct dri2_display *const pdp = (struct dri2_display *)
priv->dri2Display;
const __DRIextension **extensions;
int i;
extensions = psc->core->getExtensions(psc->driScreen);
__glXEnableDirectExtension(&psc->base, "GLX_EXT_swap_control");
__glXEnableDirectExtension(&psc->base, "GLX_SGI_swap_control");
__glXEnableDirectExtension(&psc->base, "GLX_MESA_swap_control");
__glXEnableDirectExtension(&psc->base, "GLX_SGI_make_current_read");
/*
* GLX_INTEL_swap_event is broken on the server side, where it's
* currently unconditionally enabled. This completely breaks
* systems running on drivers which don't support that extension.
* There's no way to test for its presence on this side, so instead
* of disabling it unconditionally, just disable it for drivers
* which are known to not support it, or for DDX drivers supporting
* only an older (pre-ScheduleSwap) version of DRI2.
*
* This is a hack which is required until:
* http://lists.x.org/archives/xorg-devel/2013-February/035449.html
* is merged and updated xserver makes it's way into distros:
*/
if (pdp->swapAvailable && strcmp(driverName, "vmwgfx") != 0) {
__glXEnableDirectExtension(&psc->base, "GLX_INTEL_swap_event");
}
if (psc->dri2->base.version >= 3) {
const unsigned mask = psc->dri2->getAPIMask(psc->driScreen);
__glXEnableDirectExtension(&psc->base, "GLX_ARB_create_context");
__glXEnableDirectExtension(&psc->base, "GLX_ARB_create_context_profile");
if ((mask & ((1 << __DRI_API_GLES) |
(1 << __DRI_API_GLES2) |
(1 << __DRI_API_GLES3))) != 0) {
__glXEnableDirectExtension(&psc->base,
"GLX_EXT_create_context_es_profile");
__glXEnableDirectExtension(&psc->base,
"GLX_EXT_create_context_es2_profile");
}
}
for (i = 0; extensions[i]; i++) {
if ((strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0)) {
psc->texBuffer = (__DRItexBufferExtension *) extensions[i];
__glXEnableDirectExtension(&psc->base, "GLX_EXT_texture_from_pixmap");
}
if ((strcmp(extensions[i]->name, __DRI2_FLUSH) == 0)) {
psc->f = (__DRI2flushExtension *) extensions[i];
/* internal driver extension, no GL extension exposed */
}
if ((strcmp(extensions[i]->name, __DRI2_CONFIG_QUERY) == 0))
psc->config = (__DRI2configQueryExtension *) extensions[i];
if (((strcmp(extensions[i]->name, __DRI2_THROTTLE) == 0)))
psc->throttle = (__DRI2throttleExtension *) extensions[i];
/* DRI2 version 3 is also required because
* GLX_ARB_create_context_robustness requires GLX_ARB_create_context.
*/
if (psc->dri2->base.version >= 3
&& strcmp(extensions[i]->name, __DRI2_ROBUSTNESS) == 0)
__glXEnableDirectExtension(&psc->base,
"GLX_ARB_create_context_robustness");
/* DRI2 version 3 is also required because
* GLX_ARB_create_context_no_error requires GLX_ARB_create_context.
*/
if (psc->dri2->base.version >= 3
&& strcmp(extensions[i]->name, __DRI2_NO_ERROR) == 0)
__glXEnableDirectExtension(&psc->base,
"GLX_ARB_create_context_no_error");
/* DRI2 version 3 is also required because GLX_MESA_query_renderer
* requires GLX_ARB_create_context_profile.
*/
if (psc->dri2->base.version >= 3
&& strcmp(extensions[i]->name, __DRI2_RENDERER_QUERY) == 0) {
psc->rendererQuery = (__DRI2rendererQueryExtension *) extensions[i];
__glXEnableDirectExtension(&psc->base, "GLX_MESA_query_renderer");
}
if (strcmp(extensions[i]->name, __DRI2_INTEROP) == 0)
psc->interop = (__DRI2interopExtension*)extensions[i];
/* DRI2 version 3 is also required because
* GLX_ARB_control_flush_control requires GLX_ARB_create_context.
*/
if (psc->dri2->base.version >= 3
&& strcmp(extensions[i]->name, __DRI2_FLUSH_CONTROL) == 0)
__glXEnableDirectExtension(&psc->base,
"GLX_ARB_context_flush_control");
}
}
static char *
dri2_get_driver_name(struct glx_screen *glx_screen)
{
struct dri2_screen *psc = (struct dri2_screen *)glx_screen;
return psc->driverName;
}
static const struct glx_screen_vtable dri2_screen_vtable = {
.create_context = dri_common_create_context,
.create_context_attribs = dri2_create_context_attribs,
.query_renderer_integer = dri2_query_renderer_integer,
.query_renderer_string = dri2_query_renderer_string,
.get_driver_name = dri2_get_driver_name,
};
static struct glx_screen *
dri2CreateScreen(int screen, struct glx_display * priv)
{
const __DRIconfig **driver_configs;
const __DRIextension **extensions;
const struct dri2_display *const pdp = (struct dri2_display *)
priv->dri2Display;
struct dri2_screen *psc;
__GLXDRIscreen *psp;
struct glx_config *configs = NULL, *visuals = NULL;
char *driverName = NULL, *loader_driverName, *deviceName, *tmp;
drm_magic_t magic;
int i;
psc = calloc(1, sizeof *psc);
if (psc == NULL)
return NULL;
psc->fd = -1;
if (!glx_screen_init(&psc->base, screen, priv)) {
free(psc);
return NULL;
}
if (!DRI2Connect(priv->dpy, RootWindow(priv->dpy, screen),
&driverName, &deviceName)) {
glx_screen_cleanup(&psc->base);
free(psc);
InfoMessageF("screen %d does not appear to be DRI2 capable\n", screen);
return NULL;
}
psc->fd = loader_open_device(deviceName);
if (psc->fd < 0) {
ErrorMessageF("failed to open %s: %s\n", deviceName, strerror(errno));
goto handle_error;
}
if (drmGetMagic(psc->fd, &magic)) {
ErrorMessageF("failed to get magic\n");
goto handle_error;
}
if (!DRI2Authenticate(priv->dpy, RootWindow(priv->dpy, screen), magic)) {
ErrorMessageF("failed to authenticate magic %d\n", magic);
goto handle_error;
}
/* If Mesa knows about the appropriate driver for this fd, then trust it.
* Otherwise, default to the server's value.
*/
loader_driverName = loader_get_driver_for_fd(psc->fd);
if (loader_driverName) {
free(driverName);
driverName = loader_driverName;
}
psc->driverName = driverName;
extensions = driOpenDriver(driverName, &psc->driver);
if (extensions == NULL)
goto handle_error;
for (i = 0; extensions[i]; i++) {
if (strcmp(extensions[i]->name, __DRI_CORE) == 0)
psc->core = (__DRIcoreExtension *) extensions[i];
if (strcmp(extensions[i]->name, __DRI_DRI2) == 0)
psc->dri2 = (__DRIdri2Extension *) extensions[i];
}
if (psc->core == NULL || psc->dri2 == NULL) {
ErrorMessageF("core dri or dri2 extension not found\n");
goto handle_error;
}
if (psc->dri2->base.version >= 4) {
psc->driScreen =
psc->dri2->createNewScreen2(screen, psc->fd,
(const __DRIextension **)
&pdp->loader_extensions[0],
extensions,
&driver_configs, psc);
} else {
psc->driScreen =
psc->dri2->createNewScreen(screen, psc->fd,
(const __DRIextension **)
&pdp->loader_extensions[0],
&driver_configs, psc);
}
if (psc->driScreen == NULL) {
ErrorMessageF("failed to create dri screen\n");
goto handle_error;
}
dri2BindExtensions(psc, priv, driverName);
configs = driConvertConfigs(psc->core, psc->base.configs, driver_configs);
visuals = driConvertConfigs(psc->core, psc->base.visuals, driver_configs);
if (!configs || !visuals) {
ErrorMessageF("No matching fbConfigs or visuals found\n");
goto handle_error;
}
glx_config_destroy_list(psc->base.configs);
psc->base.configs = configs;
glx_config_destroy_list(psc->base.visuals);
psc->base.visuals = visuals;
psc->driver_configs = driver_configs;
psc->base.vtable = &dri2_screen_vtable;
psp = &psc->vtable;
psc->base.driScreen = psp;
psp->destroyScreen = dri2DestroyScreen;
psp->createDrawable = dri2CreateDrawable;
psp->swapBuffers = dri2SwapBuffers;
psp->getDrawableMSC = NULL;
psp->waitForMSC = NULL;
psp->waitForSBC = NULL;
psp->setSwapInterval = NULL;
psp->getSwapInterval = NULL;
psp->getBufferAge = NULL;
if (pdp->driMinor >= 2) {
psp->getDrawableMSC = dri2DrawableGetMSC;
psp->waitForMSC = dri2WaitForMSC;
psp->waitForSBC = dri2WaitForSBC;
psp->setSwapInterval = dri2SetSwapInterval;
psp->getSwapInterval = dri2GetSwapInterval;
__glXEnableDirectExtension(&psc->base, "GLX_OML_sync_control");
}
__glXEnableDirectExtension(&psc->base, "GLX_SGI_video_sync");
if (psc->config->base.version > 1 &&
psc->config->configQuerys(psc->driScreen, "glx_extension_override",
&tmp) == 0)
__glXParseExtensionOverride(&psc->base, tmp);
if (psc->config->base.version > 1 &&
psc->config->configQuerys(psc->driScreen,
"indirect_gl_extension_override",
&tmp) == 0)
__IndirectGlParseExtensionOverride(&psc->base, tmp);
/* DRI2 supports SubBuffer through DRI2CopyRegion, so it's always
* available.*/
psp->copySubBuffer = dri2CopySubBuffer;
__glXEnableDirectExtension(&psc->base, "GLX_MESA_copy_sub_buffer");
free(deviceName);
tmp = getenv("LIBGL_SHOW_FPS");
psc->show_fps_interval = (tmp) ? atoi(tmp) : 0;
if (psc->show_fps_interval < 0)
psc->show_fps_interval = 0;
InfoMessageF("Using DRI2 for screen %d\n", screen);
return &psc->base;
handle_error:
CriticalErrorMessageF("failed to load driver: %s\n", driverName);
if (configs)
glx_config_destroy_list(configs);
if (visuals)
glx_config_destroy_list(visuals);
if (psc->driScreen)
psc->core->destroyScreen(psc->driScreen);
psc->driScreen = NULL;
if (psc->fd >= 0)
close(psc->fd);
if (psc->driver)
dlclose(psc->driver);
free(deviceName);
glx_screen_cleanup(&psc->base);
free(psc);
return NULL;
}
/* Called from __glXFreeDisplayPrivate.
*/
static void
dri2DestroyDisplay(__GLXDRIdisplay * dpy)
{
struct dri2_display *pdp = (struct dri2_display *) dpy;
__glxHashDestroy(pdp->dri2Hash);
free(dpy);
}
_X_HIDDEN __GLXDRIdrawable *
dri2GetGlxDrawableFromXDrawableId(Display *dpy, XID id)
{
struct glx_display *d = __glXInitialize(dpy);
struct dri2_display *pdp = (struct dri2_display *) d->dri2Display;
__GLXDRIdrawable *pdraw;
if (__glxHashLookup(pdp->dri2Hash, id, (void *) &pdraw) == 0)
return pdraw;
return NULL;
}
/*
* Allocate, initialize and return a __DRIdisplayPrivate object.
* This is called from __glXInitialize() when we are given a new
* display pointer.
*/
_X_HIDDEN __GLXDRIdisplay *
dri2CreateDisplay(Display * dpy)
{
struct dri2_display *pdp;
int eventBase, errorBase, i;
if (!DRI2QueryExtension(dpy, &eventBase, &errorBase))
return NULL;
pdp = malloc(sizeof *pdp);
if (pdp == NULL)
return NULL;
if (!DRI2QueryVersion(dpy, &pdp->driMajor, &pdp->driMinor)) {
free(pdp);
return NULL;
}
pdp->driPatch = 0;
pdp->swapAvailable = (pdp->driMinor >= 2);
pdp->invalidateAvailable = (pdp->driMinor >= 3);
pdp->base.destroyDisplay = dri2DestroyDisplay;
pdp->base.createScreen = dri2CreateScreen;
i = 0;
if (pdp->driMinor < 1)
pdp->loader_extensions[i++] = &dri2LoaderExtension_old.base;
else
pdp->loader_extensions[i++] = &dri2LoaderExtension.base;
pdp->loader_extensions[i++] = &dri2UseInvalidate.base;
pdp->loader_extensions[i++] = &driBackgroundCallable.base;
pdp->loader_extensions[i++] = NULL;
pdp->dri2Hash = __glxHashCreate();
if (pdp->dri2Hash == NULL) {
free(pdp);
return NULL;
}
return &pdp->base;
}
#endif /* GLX_DIRECT_RENDERING */
|
the_stack_data/25137062.c | /*****************************************************************************
*
* Copyright (c) 2000 - 2008, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400142
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* 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 disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL 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 LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY 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.
*
* Modifications:
*
*****************************************************************************/
#ifndef WIN32
#include <sys/types.h>
#include <sys/socket.h>
#endif
int
main()
{
socklen_t dummy;
}
|
the_stack_data/175143871.c | #include <stdlib.h>
#include <stdio.h>
/* lower and upper iteration limits centered around 1.0 */
static double const eps1m01 = 1.0 - 0x1P-01;
static double const eps1p01 = 1.0 + 0x1P-01;
static double const eps1m24 = 1.0 - 0x1P-24;
static double const eps1p24 = 1.0 + 0x1P-24;
int main(int argc, char* argv[argc+1]) {
for (int i = 1; i < argc; ++i) { // process args
double const a = strtod(argv[i], 0); // arg -> double
double x = 1.0;
for (;;) { // by powers of 2
double prod = a*x;
if (prod < eps1m01) {
x *= 2.0;
} else if (eps1p01 < prod) {
x *= 0.5;
} else {
break;
}
}
for (;;) { // Heron approximation
double prod = a*x;
if ((prod < eps1m24) || (eps1p24 < prod)) {
x *= (2.0 - prod);
} else {
break;
}
}
printf("heron: a=%.5e,\tx=%.5e,\ta*x=%.12f\n",
a, x, a*x);
}
return EXIT_SUCCESS;
}
|
the_stack_data/237643876.c | /**
******************************************************************************
* @file stm32wbxx_ll_pwr.c
* @author MCD Application Team
* @brief PWR LL module driver.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2019 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 "stm32wbxx_ll_pwr.h"
#include "stm32wbxx_ll_bus.h"
/** @addtogroup STM32WBxx_LL_Driver
* @{
*/
#if defined(PWR)
/** @defgroup PWR_LL PWR
* @{
*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/** @defgroup PWR_LL_Private_Constants PWR Private Constants
* @{
*/
/* Definitions of PWR registers reset value */
#define PWR_CR1_RESET_VALUE (0x00000200)
#define PWR_CR2_RESET_VALUE (0x00000000)
#define PWR_CR3_RESET_VALUE (0x00008000)
#define PWR_CR4_RESET_VALUE (0x00000000)
#define PWR_CR5_RESET_VALUE (0x00004272)
#define PWR_PUCRA_RESET_VALUE (0x00000000)
#define PWR_PDCRA_RESET_VALUE (0x00000000)
#define PWR_PUCRB_RESET_VALUE (0x00000000)
#define PWR_PDCRB_RESET_VALUE (0x00000000)
#define PWR_PUCRC_RESET_VALUE (0x00000000)
#define PWR_PDCRC_RESET_VALUE (0x00000000)
#define PWR_PUCRD_RESET_VALUE (0x00000000)
#define PWR_PDCRD_RESET_VALUE (0x00000000)
#define PWR_PUCRE_RESET_VALUE (0x00000000)
#define PWR_PDCRE_RESET_VALUE (0x00000000)
#define PWR_PUCRH_RESET_VALUE (0x00000000)
#define PWR_PDCRH_RESET_VALUE (0x00000000)
#define PWR_C2CR1_RESET_VALUE (0x00000000)
#define PWR_C2CR3_RESET_VALUE (0x00008000)
/**
* @}
*/
/* Private macros ------------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup PWR_LL_Exported_Functions
* @{
*/
/** @addtogroup PWR_LL_EF_Init
* @{
*/
/**
* @brief De-initialize the PWR registers to their default reset values.
* @retval An ErrorStatus enumeration value:
* - SUCCESS: PWR registers are de-initialized
* - ERROR: not applicable
*/
ErrorStatus LL_PWR_DeInit(void)
{
/* Apply reset values to all PWR registers */
LL_PWR_WriteReg(CR1, PWR_CR1_RESET_VALUE);
LL_PWR_WriteReg(CR2, PWR_CR2_RESET_VALUE);
LL_PWR_WriteReg(CR3, PWR_CR3_RESET_VALUE);
LL_PWR_WriteReg(CR4, PWR_CR4_RESET_VALUE);
LL_PWR_WriteReg(CR5, PWR_CR5_RESET_VALUE);
LL_PWR_WriteReg(PUCRA, PWR_PUCRA_RESET_VALUE);
LL_PWR_WriteReg(PDCRA, PWR_PDCRA_RESET_VALUE);
LL_PWR_WriteReg(PUCRB, PWR_PUCRB_RESET_VALUE);
LL_PWR_WriteReg(PDCRB, PWR_PDCRB_RESET_VALUE);
LL_PWR_WriteReg(PUCRC, PWR_PUCRC_RESET_VALUE);
LL_PWR_WriteReg(PDCRC, PWR_PDCRC_RESET_VALUE);
#if defined(GPIOD)
LL_PWR_WriteReg(PUCRD, PWR_PUCRD_RESET_VALUE);
LL_PWR_WriteReg(PDCRD, PWR_PDCRD_RESET_VALUE);
#endif
LL_PWR_WriteReg(PUCRE, PWR_PUCRE_RESET_VALUE);
LL_PWR_WriteReg(PDCRE, PWR_PDCRE_RESET_VALUE);
LL_PWR_WriteReg(PUCRH, PWR_PUCRH_RESET_VALUE);
LL_PWR_WriteReg(PDCRH, PWR_PDCRH_RESET_VALUE);
LL_PWR_WriteReg(C2CR1, PWR_C2CR1_RESET_VALUE);
LL_PWR_WriteReg(C2CR3, PWR_C2CR3_RESET_VALUE);
/* Clear all flags */
LL_PWR_WriteReg(SCR,
LL_PWR_SCR_CC2HF
| LL_PWR_SCR_CBLEAF
| LL_PWR_SCR_CCRPEF
#if defined(PWR_CR3_E802A)
| LL_PWR_SCR_C802AF
| LL_PWR_SCR_C802WUF
#endif
| LL_PWR_SCR_CBLEWUF
#if defined(PWR_CR5_SMPSEN)
| LL_PWR_SCR_CBORHF
| LL_PWR_SCR_CSMPSFBF
#endif
| LL_PWR_SCR_CWUF
);
LL_PWR_WriteReg(EXTSCR,
LL_PWR_EXTSCR_CCRPF
| LL_PWR_EXTSCR_C2CSSF
| LL_PWR_EXTSCR_C1CSSF
);
return SUCCESS;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* defined(PWR) */
/**
* @}
*/
#endif /* USE_FULL_LL_DRIVER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
the_stack_data/153268178.c | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* minimum required number of parameters */
#define MIN_REQUIRED 2
/* display usage */
int help() {
printf("Usage: ./a.exe NLINES NBIT\n");
printf("\tNLINES: number of LUT line address, as unsigned\n");
printf("\tNBIT : y bit-depth, as C2 balanced\n");
return 0;
}
/* main */
int main(int argc, char *argv[]){
if (argc < MIN_REQUIRED) {
return help();
}
int NLINES = atoi(argv[1]);
int NBIT = atoi(argv[2]);
printf("\n");
printf("-- SIN samples for VHDL LUT\n");
printf("-- LUT lines: %4d\n", NLINES);
printf("-- number of LUT line address, as unsigned\n");
printf("-- bit depth: %4d\n", NBIT);
printf("-- y bit-depth, as C2 balanced\n");
printf("\n");
double lsb_yq = 1.0/(pow(2,NBIT-1)-1); // balanced
double f;
// quantization
for (int i=0; i<NLINES; i++){
f = sin(2.0*M_PI*i/NLINES);
f = round(f/lsb_yq);
printf("%4d => %6d ,\n", i, (int)f);
}
return 0;
} |
the_stack_data/26370.c | // #include <bteifgl.h>
#ifdef _WIN32
#include <windows.h>
#include <commctrl.h>
#include <GL/GL.h>
HWND mainwindow;
HGLRC mainrc;
HDC maindc;
RECT mainrect;
HINSTANCE gfxdrv_hInstance;
int gfxdrv_nCmdShow;
int *gfxdrv_rkill;
int gfxdrv_kill=0;
volatile int gfxdrv_waitdc=0;
volatile int gfxdrv_waitok=0;
volatile int gfxdrv_dt_swap=0;
void *gfxdrv_mutex=NULL;
int gfxdrv_dtt_swap;
int window_center_x;
int window_center_y;
int window_mouse_buttons;
int window_width;
int window_height;
int window_active;
int window_lastactive;
int window_fullscreen;
// int window_def_width=640;
// int window_def_height=480;
//int window_def_width=1024;
//int window_def_height=768;
//int window_def_width=1280;
//int window_def_height=960;
int window_def_width=960;
int window_def_height=720;
char *window_def_label="BTEIFGL";
int window_def_fullscreen=0;
int window_fullscreen_width=0;
int window_fullscreen_height=0;
int window_desktop_width=1680;
int window_desktop_height=1050;
int window_max_width=0;
int window_max_height=0;
char *gl_vendor, *gl_renderer, *gl_version, *gl_extensions;
void GfxDrv_V_HandleMessages();
void FRGL_EndInputFrame();
void gfxdrv_lock()
{
// thLockFastMutex(gfxdrv_mutex);
}
void gfxdrv_unlock()
{
// thUnlockFastMutex(gfxdrv_mutex);
}
void gfxdrv_sleep(int ms)
{
}
static int gfxdrv_log2up(int v)
{
int i, j;
i=v; j=0;
while(i>1) { i=(i+1)>>1; j++; }
return(j);
}
void GfxDrv_GetWindowSize(int *xs, int *ys)
{ *xs=window_width; *ys=window_height; }
void GfxDrv_GetWindowTexSize(int *xs, int *ys)
{
*xs=1<<gfxdrv_log2up(window_width);
*ys=1<<gfxdrv_log2up(window_height);
}
void GfxDrv_GetWindowMaxSize(int *xs, int *ys)
{ *xs=window_max_width; *ys=window_max_height; }
void GfxDrv_GetWindowMaxTexSize(int *xs, int *ys)
{
*xs=1<<gfxdrv_log2up(window_max_width);
*ys=1<<gfxdrv_log2up(window_max_height);
}
bool GfxDrv_WindowIsActiveP(void)
{ return(window_active); }
bool GfxDrv_WindowIsFullActiveP(void)
{ return(window_active && window_lastactive); }
bool GfxDrv_WindowIsFullscreenP(void)
{ return(window_fullscreen); }
void GfxDrv_BeginDrawing()
{
int t0, t1;
gfxdrv_dtt_swap=0;
t0=clock();
GfxDrv_V_HandleMessages();
glViewport(0, 0, window_width, window_height);
glClearColor(0, 0, 0, 1);
// glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
t1=clock();
gfxdrv_dtt_swap+=t1-t0;
}
void GfxDrv_KeyEvent(int key, int down)
{
GfxDev_Key_Event(key, down);
}
void GfxDrv_EndDrawing(void)
{
int w1, h1;
int t0, t1;
t0=clock();
// if(btesh2_gfxcon_framebuf && btesh2_gfxcon_fb_dirty)
// if(btesh2_gfxcon_framebuf)
if(btesh2_gfxcon_framebuf && (btesh2_gfxcon_fb_dirty>0))
{
glViewport(0, 0, window_width, window_height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// w1=window_width/2;
// h1=window_height/2;
w1=btesh2_gfxcon_fbxs/2;
h1=btesh2_gfxcon_fbys/2;
glOrtho(-w1, w1, -h1, h1, -999999999, 999999999);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// glRasterPos2i(0, 0);
// glWindowPos2i(0, 0);
glRasterPos2i(-btesh2_gfxcon_fbxs/2, btesh2_gfxcon_fbys/2);
// glRasterPos2i(-btesh2_gfxcon_fbxs/2, 0);
// glWindowPos2i(0, btesh2_gfxcon_fbys);
// glPixelZoom(1, -1);
glPixelZoom((float)window_width/btesh2_gfxcon_fbxs,
-(float)window_height/btesh2_gfxcon_fbys);
glDrawPixels(btesh2_gfxcon_fbxs, btesh2_gfxcon_fbys,
GL_RGBA, GL_UNSIGNED_BYTE, btesh2_gfxcon_framebuf);
btesh2_gfxcon_fb_dirty--;
}
// glFinish();
SwapBuffers(maindc);
FRGL_EndInputFrame();
window_lastactive=window_active;
if(gfxdrv_waitdc)
{
gfxdrv_lock();
wglMakeCurrent(NULL, NULL);
gfxdrv_waitok=1;
gfxdrv_unlock();
while(gfxdrv_waitdc>0)
gfxdrv_sleep(10);
gfxdrv_waitok=0;
gfxdrv_sleep(10);
gfxdrv_lock();
wglMakeCurrent(maindc, mainrc);
gfxdrv_unlock();
}
t1=clock();
gfxdrv_dtt_swap+=t1-t0;
gfxdrv_dt_swap=gfxdrv_dtt_swap;
}
void GfxDrv_V_HandleMessages()
{
MSG msg;
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
void GfxDrv_V_CenterWindow(HWND hWnd,
int width, int height) //AH:ignore
{
RECT rect;
int cx, cy;
cx=GetSystemMetrics(SM_CXSCREEN);
cy=GetSystemMetrics(SM_CYSCREEN);
cx=(cx-width)/2; cy=(cy-height)/2;
if(cx>cy*2)cx/=2;
if(cx<0)cx=0;
if(cy<0)cy=0;
SetWindowPos(hWnd, NULL, cx, cy, 0, 0,
SWP_NOSIZE|SWP_NOZORDER|SWP_SHOWWINDOW|SWP_DRAWFRAME);
// SetWindowPos(hWnd, NULL, cx, cy, width, height,
// SWP_NOZORDER|SWP_SHOWWINDOW|SWP_DRAWFRAME);
window_center_x=cx+(width/2);
window_center_y=cy+(height/2)+24;
window_width=width;
window_height=height;
}
int GfxDrv_V_SetWindowedMode()
{
static DWORD ws=
WS_OVERLAPPED|WS_BORDER|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX;
RECT rect;
ChangeDisplaySettings (NULL, 0);
window_fullscreen=0;
SetWindowLong(mainwindow, GWL_STYLE, ws);
SetWindowPos(mainwindow, NULL, 0, 0, 0, 0,
SWP_NOSIZE|SWP_NOZORDER|SWP_SHOWWINDOW|
SWP_DRAWFRAME|SWP_FRAMECHANGED);
rect.top=rect.left=0;
rect.right=window_def_width;
rect.bottom=window_def_height;
AdjustWindowRectEx(&rect, ws, FALSE, 0);
window_width=rect.right-rect.left;
window_height=rect.bottom-rect.top;
MoveWindow(mainwindow, 0, 0, window_width, window_height, TRUE );
GfxDrv_V_CenterWindow(mainwindow, window_width, window_height);
return(0);
}
int GfxDrv_V_GetDesktopSize()
{
DEVMODE devmode;
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devmode);
window_desktop_width=devmode.dmPelsWidth;
window_desktop_height=devmode.dmPelsHeight;
if(window_fullscreen_width<=0)
{
window_fullscreen_width=window_desktop_width;
window_fullscreen_height=window_desktop_height;
}
window_max_width=window_def_width;
window_max_height=window_def_height;
if(window_fullscreen_width>window_max_width)
{ window_max_width=window_fullscreen_width; }
if(window_fullscreen_height>window_max_height)
{ window_max_height=window_fullscreen_height; }
return(0);
}
int GfxDrv_V_SetFullscreenMode()
{
DEVMODE devmode;
RECT rect;
DWORD ws;
int width, height;
int i;
// EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devmode);
// width=devmode.dmPelsWidth;
// height=devmode.dmPelsHeight;
// width=window_def_width;
// height=window_def_height;
width=window_fullscreen_width;
height=window_fullscreen_height;
devmode.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
devmode.dmBitsPerPel=32;
devmode.dmPelsWidth=width;
devmode.dmPelsHeight=height;
devmode.dmSize=sizeof(devmode);
i=ChangeDisplaySettingsEx(NULL, &devmode, NULL, CDS_FULLSCREEN, NULL);
// if(ChangeDisplaySettings(&devmode, CDS_FULLSCREEN)!=
// DISP_CHANGE_SUCCESSFUL)
if(i!=DISP_CHANGE_SUCCESSFUL)
{
printf("GfxDrv_V_SetFullscreenMode: Failed To Set Fullscreen\n");
window_fullscreen=0;
return(-1);
}
rect.top=rect.left=0;
rect.right=width;
rect.bottom=height;
ws=WS_POPUP;
AdjustWindowRectEx(&rect, ws, FALSE, 0);
SetWindowLong(mainwindow, GWL_STYLE, ws);
SetWindowPos(mainwindow, NULL, 0, 0, 0, 0,
SWP_NOSIZE|SWP_NOZORDER|SWP_SHOWWINDOW|SWP_FRAMECHANGED);
window_width=rect.right-rect.left;
window_height=rect.bottom-rect.top;
MoveWindow(mainwindow, 0, 0, window_width, window_height, TRUE );
window_center_x=window_width/2;
window_center_y=window_height/2;
return(1);
}
void GfxDrv_UpdateMode()
{
#if 0
gfxdrv_lock();
wglMakeCurrent(NULL, NULL);
// gfxdrv_waitok=1;
gfxdrv_unlock();
if(maindc && mainwindow)
{
ReleaseDC(mainwindow, maindc);
maindc=NULL;
}
#endif
if(window_fullscreen)
{
GfxDrv_V_SetFullscreenMode();
}else
{
GfxDrv_V_SetWindowedMode();
}
#if 0
GfxDrv_SetupMainDC();
gfxdrv_lock();
wglMakeCurrent(maindc, mainrc);
gfxdrv_unlock();
#endif
}
int GfxDrv_V_SetupWindow()
{
// static DWORD ws=
// WS_OVERLAPPED|WS_BORDER|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX;
static DWORD ws=WS_POPUP;
HDC hdc;
RECT rect;
int lastmodestate, width, height;
GfxDrv_V_GetDesktopSize();
mainrect.top=mainrect.left=0;
// mainrect.right=window_def_width;
// mainrect.bottom=window_def_height;
// mainrect.right=window_desktop_width;
// mainrect.bottom=window_desktop_height;
mainrect.right=window_max_width;
mainrect.bottom=window_max_height;
rect=mainrect;
AdjustWindowRectEx(&rect, ws, FALSE, 0);
width=rect.right-rect.left;
height=rect.bottom-rect.top;
mainwindow=CreateWindowEx(
0,
"bgbui",
window_def_label,
ws,
rect.left, rect.top,
width, height,
NULL, NULL,
gfxdrv_hInstance,
NULL);
GfxDrv_V_CenterWindow(mainwindow,
mainrect.right-mainrect.left,
mainrect.bottom-mainrect.top);
ShowWindow(mainwindow, SW_SHOWDEFAULT);
UpdateWindow(mainwindow);
// hdc=GetDC(mainwindow);
// PatBlt(hdc, 0, 0, mainrect.right, mainrect.bottom, BLACKNESS);
// ReleaseDC(mainwindow, hdc);
GfxDrv_V_HandleMessages();
Sleep(100);
SetWindowPos(mainwindow, HWND_TOP, 0, 0, 0, 0,
SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW |
SWP_NOCOPYBITS);
SetForegroundWindow(mainwindow);
return(-1);
}
void GfxDrv_InitGL()
{
gl_vendor=(char *)glGetString(GL_VENDOR);
gl_renderer=(char *)glGetString(GL_RENDERER);
gl_version=(char *)glGetString(GL_VERSION);
gl_extensions=(char *)glGetString(GL_EXTENSIONS);
printf("OpenGL Vendor=%s\n", gl_vendor);
printf("OpenGL Renderer=%s\n", gl_renderer);
printf("OpenGL Version=%s\n", gl_version);
// printf("OpenGL Extensions=%s\n", gl_extensions);
// BGBBTJ_SetGlExtensions(gl_extensions);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glShadeModel(GL_SMOOTH);
glClearColor(0, 0, 0, 1);
glCullFace(GL_FRONT);
glEnable(GL_TEXTURE_2D);
glAlphaFunc(GL_GREATER, 0.75);
glDisable(GL_ALPHA_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glShadeModel(GL_SMOOTH);
}
void GfxDrv_InitGL2()
{
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glShadeModel(GL_SMOOTH);
glClearColor(0, 0, 0, 1);
glCullFace(GL_FRONT);
glEnable(GL_TEXTURE_2D);
glAlphaFunc(GL_GREATER, 0.75);
glDisable(GL_ALPHA_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
void GfxDrv_Shutdown()
{
HGLRC hrc;
HDC hdc;
if(window_fullscreen)
{ ChangeDisplaySettings (NULL, 0); }
hrc=wglGetCurrentContext();
hdc=wglGetCurrentDC();
wglMakeCurrent(NULL, NULL);
if(hrc)
wglDeleteContext(hrc);
if(hdc && mainwindow)
ReleaseDC(mainwindow, hdc);
if(maindc && mainwindow)
ReleaseDC(mainwindow, maindc);
}
static int scantokey[128]=
{
0, K_ESC, '1','2','3','4','5','6',
'7','8','9','0','-','=', K_BACKSPACE, 9,
'q','w','e','r','t','y','u','i',
'o','p','[',']',13 , K_CTRL, 'a','s',
'd','f','g','h','j','k','l',';',
'\'', '`', K_SHIFT,'\\', 'z','x','c','v',
'b','n','m',',','.',K_NUMPAD_DIV, K_SHIFT,'*',
K_ALT, ' ', K_CAPSLOCK, K_F1, K_F2, K_F3, K_F4, K_F5,
K_F6, K_F7, K_F8, K_F9, K_F10, K_PAUSE, K_SCROLL, K_HOME,
K_UPARROW, K_PGUP, '-', K_LEFTARROW,'5', K_RIGHTARROW, '+', K_END,
K_DOWNARROW, K_PGDN, K_INS, K_DEL, 0, 0, 0,
K_F11,
K_F12, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
static int scantokeyb[128]=
{
0, K_ESC, '1','2','3','4','5','6',
'7','8','9','0','-','=', K_BACKSPACE, 9,
'q','w','e','r','t','y','u','i',
'o','p','[',']',13 , K_CTRL, 'a','s',
'd','f','g','h','j','k','l',';',
'\'', '`', K_SHIFT,'\\', 'z','x','c','v',
'b','n','m',',','.','/', K_SHIFT, K_NUMPAD_MUL,
K_ALT, ' ', 0, K_F1, K_F2, K_F3, K_F4, K_F5,
K_F6, K_F7, K_F8, K_F9, K_F10, K_PAUSE, 0, K_NUMPAD7,
K_NUMPAD8, K_NUMPAD9, K_NUMPAD_SUB, K_NUMPAD4, K_NUMPAD5, K_NUMPAD6,
K_NUMPAD_ADD, K_NUMPAD1,
K_NUMPAD2, K_NUMPAD3, K_NUMPAD0, K_DEL, 0, 0, 0,
K_F11,
K_F12, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
int GfxDrv_MapKey(int key)
{
int al, val;
// frgl_printf("Key: 0x%08X\n", key);
al=(key>>24)&1;
key=(key>>16)&255;
if(key>127)
return 0;
// if(!scantokey[key])
// frgl_printf("no mapping for key 0x%02X\n", key);
val=scantokey[key];
if(!al)
val=scantokeyb[key];
// frgl_printf("Map Key: %d\n", val);
return(val);
}
void GfxDrv_AppActivate(bool active, bool minimized)
{
window_active=active&&(!minimized);
if(window_fullscreen)
{
if(window_active)
{
GfxDrv_V_SetFullscreenMode();
}else
{
ChangeDisplaySettings(NULL, 0);
}
}
}
LONG WINAPI GfxDrv_MainWndProc(
HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) //AH:ignore
{
LONG ret;
int xp, yp;
int i, j;
ret=1;
switch(uMsg)
{
case WM_CREATE:
break;
case WM_SYSCHAR:
break;
case WM_ACTIVATE:
i = LOWORD(wParam);
j = (BOOL) HIWORD(wParam);
GfxDrv_AppActivate(i!=WA_INACTIVE, j);
break;
case WM_MOVE:
if(!window_fullscreen)
{
xp=(int) LOWORD(lParam);
yp=(int) HIWORD(lParam);
window_center_x=xp+(window_width/2);
window_center_y=yp+(window_height/2);
}
break;
case WM_SYSKEYDOWN:
if(wParam==0xFF)break;
if(wParam==0x0D)
{
window_fullscreen=!window_fullscreen;
GfxDrv_UpdateMode();
}
if(wParam==0x3E)
{
if(gfxdrv_rkill)*gfxdrv_rkill=1;
gfxdrv_kill=1;
}
GfxDrv_KeyEvent(GfxDrv_MapKey(lParam),-1);
break;
case WM_KEYDOWN:
// case WM_SYSKEYDOWN:
if(wParam==0xFF)break;
GfxDrv_KeyEvent(GfxDrv_MapKey(lParam),-1);
break;
case WM_KEYUP:
case WM_SYSKEYUP:
if(wParam==0xFF)break;
GfxDrv_KeyEvent(GfxDrv_MapKey(lParam), 0);
break;
case WM_LBUTTONDOWN: case WM_LBUTTONUP:
case WM_RBUTTONDOWN: case WM_RBUTTONUP:
case WM_MBUTTONDOWN: case WM_MBUTTONUP:
case WM_MOUSEMOVE:
i=0;
if(wParam&MK_LBUTTON)i|=1;
if(wParam&MK_RBUTTON)i|=4;
if(wParam&MK_MBUTTON)i|=2;
j=window_mouse_buttons^i;
window_mouse_buttons=i;
if(j&1)GfxDrv_KeyEvent(K_MOUSE1, (i&1)?(-1):0);
if(j&2)GfxDrv_KeyEvent(K_MOUSE2, (i&2)?(-1):0);
if(j&4)GfxDrv_KeyEvent(K_MOUSE3, (i&4)?(-1):0);
// if(FRGL_CvarGetInt("hide_os_cursor"))
// SetCursor(NULL);
break;
case WM_MOUSEWHEEL:
if(((short)HIWORD(wParam))>0)
{
GfxDrv_KeyEvent(K_MWHEELUP, -1);
GfxDrv_KeyEvent(K_MWHEELUP, 0);
}else
{
GfxDrv_KeyEvent(K_MWHEELDOWN, -1);
GfxDrv_KeyEvent(K_MWHEELDOWN, 0);
}
break;
case WM_SIZE:
xp=(int)LOWORD(lParam);
yp=(int)HIWORD(lParam);
window_width=xp;
window_height=yp;
break;
case WM_CLOSE:
if(gfxdrv_rkill)*gfxdrv_rkill=1;
gfxdrv_kill=1;
break;
case WM_DESTROY:
if(mainwindow)
DestroyWindow(mainwindow);
PostQuitMessage(0);
break;
default:
ret=DefWindowProc(hWnd, uMsg, wParam, lParam);
break;
}
return(ret);
}
void GfxDrv_SetDefaults(char *label, int width, int height)
{
if(label)window_def_label=label;
window_def_width=width;
window_def_height=height;
}
void GfxDrv_SetDefaultFullscreen(int fs)
{
window_def_fullscreen=fs;
}
void GfxDrv_SetFullscreenResolution(int width, int height)
{
window_fullscreen_width=width;
window_fullscreen_height=height;
}
int GfxDrv_SetupMainDC()
{
PIXELFORMATDESCRIPTOR pfd;
int i;
#if 1
maindc=GetDC(mainwindow);
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize=sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion=1;
pfd.dwFlags=PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER;
pfd.iPixelType=PFD_TYPE_RGBA;
pfd.cColorBits=24;
pfd.cDepthBits=32;
pfd.cStencilBits=16;
pfd.iLayerType=PFD_MAIN_PLANE;
i=ChoosePixelFormat(maindc, &pfd);
if(!i)return(-1);
i=SetPixelFormat(maindc, i, &pfd);
if(!i)return(-1);
#endif
return(0);
}
int GfxDrv_Start()
{
// PIXELFORMATDESCRIPTOR pfd;
WNDCLASS wc;
HDC hdc;
int i;
// FRGL_CvarSetDefault("hide_os_cursor", "0");
// MessageBox(NULL, "GL Init failed", "Error", MB_OK);
// gfxdrv_mutex=thFastMutex();
if(!gfxdrv_hInstance)
gfxdrv_hInstance=GetModuleHandle(NULL);
memset(&wc, 0, sizeof(WNDCLASS));
wc.lpfnWndProc=(WNDPROC)GfxDrv_MainWndProc;
wc.hInstance=gfxdrv_hInstance;
wc.lpszClassName="bgbui";
i=RegisterClass(&wc);
if(!i)return(-1);
hdc=GetDC(NULL);
if(GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)
return(-1);
ReleaseDC(NULL, hdc);
GfxDrv_V_SetupWindow();
if(window_def_fullscreen)
{
window_fullscreen=1;
GfxDrv_V_SetFullscreenMode();
}
GfxDrv_SetupMainDC();
mainrc=wglCreateContext(maindc);
if(!mainrc)return(-1);
i=wglMakeCurrent(maindc, mainrc);
if(!i)return(-1);
// if(FRGL_CvarGetInt("hide_os_cursor"))
// SetCursor(NULL);
GfxDrv_InitGL();
if(!window_def_fullscreen)
{
GfxDrv_V_SetWindowedMode();
}
// btesh2_gfxcon_fbxs=window_width;
// btesh2_gfxcon_fbys=window_height;
// btesh2_gfxcon_fbsz=btesh2_gfxcon_fbxs*btesh2_gfxcon_fbys;
return(0);
}
int GfxDrv_SetupThreadShareLists()
{
HGLRC altrc;
int i;
// *(int *)-1=-1;
gfxdrv_waitdc++;
while(!gfxdrv_waitok)
gfxdrv_sleep(10);
gfxdrv_lock();
altrc=wglCreateContext(maindc);
if(!altrc)
{
gfxdrv_unlock();
return(-1);
}
i=wglShareLists(mainrc, altrc);
if(!i)
{
gfxdrv_unlock();
return(-1);
}
i=wglMakeCurrent(maindc, altrc);
if(!i)
{
gfxdrv_unlock();
return(-1);
}
GfxDrv_InitGL2();
gfxdrv_waitdc--;
gfxdrv_unlock();
return(0);
}
int GfxDrv_TeardownThreadShareLists()
{
HGLRC hrc;
hrc=wglGetCurrentContext();
wglMakeCurrent(NULL, NULL);
if(hrc)
wglDeleteContext(hrc);
return(0);
}
int GfxDrv_Init(void *hInstance, int nCmdShow, int *rkill)
{
gfxdrv_hInstance=hInstance;
gfxdrv_nCmdShow=nCmdShow;
gfxdrv_rkill=rkill;
return(0);
}
int GfxDrv_SetInstance(void *hInstance, int nCmdShow)
{
gfxdrv_hInstance=hInstance;
gfxdrv_nCmdShow=nCmdShow;
// gfxdrv_rkill=rkill;
return(0);
}
int GfxDrv_SetKill(int *rkill)
{
gfxdrv_rkill=rkill;
return(0);
}
int GfxDrv_GetDtSwap()
{
return(gfxdrv_dt_swap);
}
int GfxDrv_PrepareFramebuf()
{
btesh2_gfxcon_fb_dirty=3;
if(!btesh2_gfxcon_framebuf)
{
btesh2_gfxcon_framebuf=malloc(window_width*window_height*4);
}
return(0);
}
int GfxDrv_MainLoop(void (*fcn)())
{
static int lt=0;
int ct, dt;
ct=FRGL_TimeMS();
while(!gfxdrv_kill)
{
ct=FRGL_TimeMS();
dt=ct-lt;
if((dt>=0) && (dt<10))
{
Sleep(1);
continue;
}
fcn();
lt=ct;
}
}
#endif
|
the_stack_data/109187.c | /*
============================================================================
Author : Ztiany
Description : C语言的运算符
============================================================================
*/
#include <stdio.h>
void bitOperation(); //位运算
void printInt(char name, int x);
int main(void)
{
//位运算
bitOperation();
return 1;
}
void bitOperation()
{
int x = 10;
int y = 12;
int z = x & y;
int v = ~x;
int b = x ^ y;
int n = x | y;
int m = x << 3;
int l = x >> 3;
printInt('x', x);
printInt('y', y);
printInt('z', z);
printInt('v', v);
printInt('b', b);
printInt('n', n);
printInt('m', m);
printInt('l', l);
printInt('l', l);
}
void printInt(char name, int x)
{
printf("数据%c的值为%d \n", name, x);
} |
the_stack_data/82951418.c | // Ogg Vorbis audio decoder - v1.11 - public domain
// http://nothings.org/stb_vorbis/
//
// Original version written by Sean Barrett in 2007.
//
// Originally sponsored by RAD Game Tools. Seeking sponsored
// by Phillip Bennefall, Marc Andersen, Aaron Baker, Elias Software,
// Aras Pranckevicius, and Sean Barrett.
//
// LICENSE
//
// See end of file for license information.
//
// Limitations:
//
// - floor 0 not supported (used in old ogg vorbis files pre-2004)
// - lossless sample-truncation at beginning ignored
// - cannot concatenate multiple vorbis streams
// - sample positions are 32-bit, limiting seekable 192Khz
// files to around 6 hours (Ogg supports 64-bit)
//
// Feature contributors:
// Dougall Johnson (sample-exact seeking)
//
// Bugfix/warning contributors:
// Terje Mathisen Niklas Frykholm Andy Hill
// Casey Muratori John Bolton Gargaj
// Laurent Gomila Marc LeBlanc Ronny Chevalier
// Bernhard Wodo Evan Balster alxprd@github
// Tom Beaumont Ingo Leitgeb Nicolas Guillemot
// Phillip Bennefall Rohit Thiago Goulart
// manxorist@github saga musix github:infatum
//
// Partial history:
// 1.11 - 2017/07/23 - fix MinGW compilation
// 1.10 - 2017/03/03 - more robust seeking; fix negative ilog(); clear error in open_memory
// 1.09 - 2016/04/04 - back out 'truncation of last frame' fix from previous version
// 1.08 - 2016/04/02 - warnings; setup memory leaks; truncation of last frame
// 1.07 - 2015/01/16 - fixes for crashes on invalid files; warning fixes; const
// 1.06 - 2015/08/31 - full, correct support for seeking API (Dougall Johnson)
// some crash fixes when out of memory or with corrupt files
// fix some inappropriately signed shifts
// 1.05 - 2015/04/19 - don't define __forceinline if it's redundant
// 1.04 - 2014/08/27 - fix missing const-correct case in API
// 1.03 - 2014/08/07 - warning fixes
// 1.02 - 2014/07/09 - declare qsort comparison as explicitly _cdecl in Windows
// 1.01 - 2014/06/18 - fix stb_vorbis_get_samples_float (interleaved was correct)
// 1.0 - 2014/05/26 - fix memory leaks; fix warnings; fix bugs in >2-channel;
// (API change) report sample rate for decode-full-file funcs
//
// See end of file for full version history.
//////////////////////////////////////////////////////////////////////////////
//
// HEADER BEGINS HERE
//
#ifndef STB_VORBIS_INCLUDE_STB_VORBIS_H
#define STB_VORBIS_INCLUDE_STB_VORBIS_H
#if defined(STB_VORBIS_NO_CRT) && !defined(STB_VORBIS_NO_STDIO)
#define STB_VORBIS_NO_STDIO 1
#endif
#ifndef STB_VORBIS_NO_STDIO
#include <stdio.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
/////////// THREAD SAFETY
// Individual stb_vorbis* handles are not thread-safe; you cannot decode from
// them from multiple threads at the same time. However, you can have multiple
// stb_vorbis* handles and decode from them independently in multiple thrads.
/////////// MEMORY ALLOCATION
// normally stb_vorbis uses malloc() to allocate memory at startup,
// and alloca() to allocate temporary memory during a frame on the
// stack. (Memory consumption will depend on the amount of setup
// data in the file and how you set the compile flags for speed
// vs. size. In my test files the maximal-size usage is ~150KB.)
//
// You can modify the wrapper functions in the source (setup_malloc,
// setup_temp_malloc, temp_malloc) to change this behavior, or you
// can use a simpler allocation model: you pass in a buffer from
// which stb_vorbis will allocate _all_ its memory (including the
// temp memory). "open" may fail with a VORBIS_outofmem if you
// do not pass in enough data; there is no way to determine how
// much you do need except to succeed (at which point you can
// query get_info to find the exact amount required. yes I know
// this is lame).
//
// If you pass in a non-NULL buffer of the type below, allocation
// will occur from it as described above. Otherwise just pass NULL
// to use malloc()/alloca()
typedef struct
{
char *alloc_buffer;
int alloc_buffer_length_in_bytes;
} stb_vorbis_alloc;
/////////// FUNCTIONS USEABLE WITH ALL INPUT MODES
typedef struct stb_vorbis stb_vorbis;
typedef struct
{
unsigned int sample_rate;
int channels;
unsigned int setup_memory_required;
unsigned int setup_temp_memory_required;
unsigned int temp_memory_required;
int max_frame_size;
} stb_vorbis_info;
// get general information about the file
extern stb_vorbis_info stb_vorbis_get_info(stb_vorbis *f);
// get the last error detected (clears it, too)
extern int stb_vorbis_get_error(stb_vorbis *f);
// close an ogg vorbis file and free all memory in use
extern void stb_vorbis_close(stb_vorbis *f);
// this function returns the offset (in samples) from the beginning of the
// file that will be returned by the next decode, if it is known, or -1
// otherwise. after a flush_pushdata() call, this may take a while before
// it becomes valid again.
// NOT WORKING YET after a seek with PULLDATA API
extern int stb_vorbis_get_sample_offset(stb_vorbis *f);
// returns the current seek point within the file, or offset from the beginning
// of the memory buffer. In pushdata mode it returns 0.
extern unsigned int stb_vorbis_get_file_offset(stb_vorbis *f);
/////////// PUSHDATA API
#ifndef STB_VORBIS_NO_PUSHDATA_API
// this API allows you to get blocks of data from any source and hand
// them to stb_vorbis. you have to buffer them; stb_vorbis will tell
// you how much it used, and you have to give it the rest next time;
// and stb_vorbis may not have enough data to work with and you will
// need to give it the same data again PLUS more. Note that the Vorbis
// specification does not bound the size of an individual frame.
extern stb_vorbis *stb_vorbis_open_pushdata(
const unsigned char * datablock, int datablock_length_in_bytes,
int *datablock_memory_consumed_in_bytes,
int *error,
const stb_vorbis_alloc *alloc_buffer);
// create a vorbis decoder by passing in the initial data block containing
// the ogg&vorbis headers (you don't need to do parse them, just provide
// the first N bytes of the file--you're told if it's not enough, see below)
// on success, returns an stb_vorbis *, does not set error, returns the amount of
// data parsed/consumed on this call in *datablock_memory_consumed_in_bytes;
// on failure, returns NULL on error and sets *error, does not change *datablock_memory_consumed
// if returns NULL and *error is VORBIS_need_more_data, then the input block was
// incomplete and you need to pass in a larger block from the start of the file
extern int stb_vorbis_decode_frame_pushdata(
stb_vorbis *f,
const unsigned char *datablock, int datablock_length_in_bytes,
int *channels, // place to write number of float * buffers
float ***output, // place to write float ** array of float * buffers
int *samples // place to write number of output samples
);
// decode a frame of audio sample data if possible from the passed-in data block
//
// return value: number of bytes we used from datablock
//
// possible cases:
// 0 bytes used, 0 samples output (need more data)
// N bytes used, 0 samples output (resynching the stream, keep going)
// N bytes used, M samples output (one frame of data)
// note that after opening a file, you will ALWAYS get one N-bytes,0-sample
// frame, because Vorbis always "discards" the first frame.
//
// Note that on resynch, stb_vorbis will rarely consume all of the buffer,
// instead only datablock_length_in_bytes-3 or less. This is because it wants
// to avoid missing parts of a page header if they cross a datablock boundary,
// without writing state-machiney code to record a partial detection.
//
// The number of channels returned are stored in *channels (which can be
// NULL--it is always the same as the number of channels reported by
// get_info). *output will contain an array of float* buffers, one per
// channel. In other words, (*output)[0][0] contains the first sample from
// the first channel, and (*output)[1][0] contains the first sample from
// the second channel.
extern void stb_vorbis_flush_pushdata(stb_vorbis *f);
// inform stb_vorbis that your next datablock will not be contiguous with
// previous ones (e.g. you've seeked in the data); future attempts to decode
// frames will cause stb_vorbis to resynchronize (as noted above), and
// once it sees a valid Ogg page (typically 4-8KB, as large as 64KB), it
// will begin decoding the _next_ frame.
//
// if you want to seek using pushdata, you need to seek in your file, then
// call stb_vorbis_flush_pushdata(), then start calling decoding, then once
// decoding is returning you data, call stb_vorbis_get_sample_offset, and
// if you don't like the result, seek your file again and repeat.
#endif
////////// PULLING INPUT API
#ifndef STB_VORBIS_NO_PULLDATA_API
// This API assumes stb_vorbis is allowed to pull data from a source--
// either a block of memory containing the _entire_ vorbis stream, or a
// FILE * that you or it create, or possibly some other reading mechanism
// if you go modify the source to replace the FILE * case with some kind
// of callback to your code. (But if you don't support seeking, you may
// just want to go ahead and use pushdata.)
#if !defined(STB_VORBIS_NO_STDIO) && !defined(STB_VORBIS_NO_INTEGER_CONVERSION)
extern int stb_vorbis_decode_filename(const char *filename, int *channels, int *sample_rate, short **output);
#endif
#if !defined(STB_VORBIS_NO_INTEGER_CONVERSION)
extern int stb_vorbis_decode_memory(const unsigned char *mem, int len, int *channels, int *sample_rate, short **output);
#endif
// decode an entire file and output the data interleaved into a malloc()ed
// buffer stored in *output. The return value is the number of samples
// decoded, or -1 if the file could not be opened or was not an ogg vorbis file.
// When you're done with it, just free() the pointer returned in *output.
extern stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len,
int *error, const stb_vorbis_alloc *alloc_buffer);
// create an ogg vorbis decoder from an ogg vorbis stream in memory (note
// this must be the entire stream!). on failure, returns NULL and sets *error
#ifndef STB_VORBIS_NO_STDIO
extern stb_vorbis * stb_vorbis_open_filename(const char *filename,
int *error, const stb_vorbis_alloc *alloc_buffer);
// create an ogg vorbis decoder from a filename via fopen(). on failure,
// returns NULL and sets *error (possibly to VORBIS_file_open_failure).
extern stb_vorbis * stb_vorbis_open_file(FILE *f, int close_handle_on_close,
int *error, const stb_vorbis_alloc *alloc_buffer);
// create an ogg vorbis decoder from an open FILE *, looking for a stream at
// the _current_ seek point (ftell). on failure, returns NULL and sets *error.
// note that stb_vorbis must "own" this stream; if you seek it in between
// calls to stb_vorbis, it will become confused. Morever, if you attempt to
// perform stb_vorbis_seek_*() operations on this file, it will assume it
// owns the _entire_ rest of the file after the start point. Use the next
// function, stb_vorbis_open_file_section(), to limit it.
extern stb_vorbis * stb_vorbis_open_file_section(FILE *f, int close_handle_on_close,
int *error, const stb_vorbis_alloc *alloc_buffer, unsigned int len);
// create an ogg vorbis decoder from an open FILE *, looking for a stream at
// the _current_ seek point (ftell); the stream will be of length 'len' bytes.
// on failure, returns NULL and sets *error. note that stb_vorbis must "own"
// this stream; if you seek it in between calls to stb_vorbis, it will become
// confused.
#endif
extern int stb_vorbis_seek_frame(stb_vorbis *f, unsigned int sample_number);
extern int stb_vorbis_seek(stb_vorbis *f, unsigned int sample_number);
// these functions seek in the Vorbis file to (approximately) 'sample_number'.
// after calling seek_frame(), the next call to get_frame_*() will include
// the specified sample. after calling stb_vorbis_seek(), the next call to
// stb_vorbis_get_samples_* will start with the specified sample. If you
// do not need to seek to EXACTLY the target sample when using get_samples_*,
// you can also use seek_frame().
extern int stb_vorbis_seek_start(stb_vorbis *f);
// this function is equivalent to stb_vorbis_seek(f,0)
extern unsigned int stb_vorbis_stream_length_in_samples(stb_vorbis *f);
extern float stb_vorbis_stream_length_in_seconds(stb_vorbis *f);
// these functions return the total length of the vorbis stream
extern int stb_vorbis_get_frame_float(stb_vorbis *f, int *channels, float ***output);
// decode the next frame and return the number of samples. the number of
// channels returned are stored in *channels (which can be NULL--it is always
// the same as the number of channels reported by get_info). *output will
// contain an array of float* buffers, one per channel. These outputs will
// be overwritten on the next call to stb_vorbis_get_frame_*.
//
// You generally should not intermix calls to stb_vorbis_get_frame_*()
// and stb_vorbis_get_samples_*(), since the latter calls the former.
#ifndef STB_VORBIS_NO_INTEGER_CONVERSION
extern int stb_vorbis_get_frame_short_interleaved(stb_vorbis *f, int num_c, short *buffer, int num_shorts);
extern int stb_vorbis_get_frame_short (stb_vorbis *f, int num_c, short **buffer, int num_samples);
#endif
// decode the next frame and return the number of *samples* per channel.
// Note that for interleaved data, you pass in the number of shorts (the
// size of your array), but the return value is the number of samples per
// channel, not the total number of samples.
//
// The data is coerced to the number of channels you request according to the
// channel coercion rules (see below). You must pass in the size of your
// buffer(s) so that stb_vorbis will not overwrite the end of the buffer.
// The maximum buffer size needed can be gotten from get_info(); however,
// the Vorbis I specification implies an absolute maximum of 4096 samples
// per channel.
// Channel coercion rules:
// Let M be the number of channels requested, and N the number of channels present,
// and Cn be the nth channel; let stereo L be the sum of all L and center channels,
// and stereo R be the sum of all R and center channels (channel assignment from the
// vorbis spec).
// M N output
// 1 k sum(Ck) for all k
// 2 * stereo L, stereo R
// k l k > l, the first l channels, then 0s
// k l k <= l, the first k channels
// Note that this is not _good_ surround etc. mixing at all! It's just so
// you get something useful.
extern int stb_vorbis_get_samples_float_interleaved(stb_vorbis *f, int channels, float *buffer, int num_floats);
extern int stb_vorbis_get_samples_float(stb_vorbis *f, int channels, float **buffer, int num_samples);
// gets num_samples samples, not necessarily on a frame boundary--this requires
// buffering so you have to supply the buffers. DOES NOT APPLY THE COERCION RULES.
// Returns the number of samples stored per channel; it may be less than requested
// at the end of the file. If there are no more samples in the file, returns 0.
#ifndef STB_VORBIS_NO_INTEGER_CONVERSION
extern int stb_vorbis_get_samples_short_interleaved(stb_vorbis *f, int channels, short *buffer, int num_shorts);
extern int stb_vorbis_get_samples_short(stb_vorbis *f, int channels, short **buffer, int num_samples);
#endif
// gets num_samples samples, not necessarily on a frame boundary--this requires
// buffering so you have to supply the buffers. Applies the coercion rules above
// to produce 'channels' channels. Returns the number of samples stored per channel;
// it may be less than requested at the end of the file. If there are no more
// samples in the file, returns 0.
#endif
//////// ERROR CODES
enum STBVorbisError
{
VORBIS__no_error,
VORBIS_need_more_data=1, // not a real error
VORBIS_invalid_api_mixing, // can't mix API modes
VORBIS_outofmem, // not enough memory
VORBIS_feature_not_supported, // uses floor 0
VORBIS_too_many_channels, // STB_VORBIS_MAX_CHANNELS is too small
VORBIS_file_open_failure, // fopen() failed
VORBIS_seek_without_length, // can't seek in unknown-length file
VORBIS_unexpected_eof=10, // file is truncated?
VORBIS_seek_invalid, // seek past EOF
// decoding errors (corrupt/invalid stream) -- you probably
// don't care about the exact details of these
// vorbis errors:
VORBIS_invalid_setup=20,
VORBIS_invalid_stream,
// ogg errors:
VORBIS_missing_capture_pattern=30,
VORBIS_invalid_stream_structure_version,
VORBIS_continued_packet_flag_invalid,
VORBIS_incorrect_stream_serial_number,
VORBIS_invalid_first_page,
VORBIS_bad_packet_type,
VORBIS_cant_find_last_page,
VORBIS_seek_failed
};
#ifdef __cplusplus
}
#endif
#endif // STB_VORBIS_INCLUDE_STB_VORBIS_H
//
// HEADER ENDS HERE
//
//////////////////////////////////////////////////////////////////////////////
#ifndef STB_VORBIS_HEADER_ONLY
// global configuration settings (e.g. set these in the project/makefile),
// or just set them in this file at the top (although ideally the first few
// should be visible when the header file is compiled too, although it's not
// crucial)
// STB_VORBIS_NO_PUSHDATA_API
// does not compile the code for the various stb_vorbis_*_pushdata()
// functions
// #define STB_VORBIS_NO_PUSHDATA_API
// STB_VORBIS_NO_PULLDATA_API
// does not compile the code for the non-pushdata APIs
// #define STB_VORBIS_NO_PULLDATA_API
// STB_VORBIS_NO_STDIO
// does not compile the code for the APIs that use FILE *s internally
// or externally (implied by STB_VORBIS_NO_PULLDATA_API)
// #define STB_VORBIS_NO_STDIO
// STB_VORBIS_NO_INTEGER_CONVERSION
// does not compile the code for converting audio sample data from
// float to integer (implied by STB_VORBIS_NO_PULLDATA_API)
// #define STB_VORBIS_NO_INTEGER_CONVERSION
// STB_VORBIS_NO_FAST_SCALED_FLOAT
// does not use a fast float-to-int trick to accelerate float-to-int on
// most platforms which requires endianness be defined correctly.
//#define STB_VORBIS_NO_FAST_SCALED_FLOAT
// STB_VORBIS_MAX_CHANNELS [number]
// globally define this to the maximum number of channels you need.
// The spec does not put a restriction on channels except that
// the count is stored in a byte, so 255 is the hard limit.
// Reducing this saves about 16 bytes per value, so using 16 saves
// (255-16)*16 or around 4KB. Plus anything other memory usage
// I forgot to account for. Can probably go as low as 8 (7.1 audio),
// 6 (5.1 audio), or 2 (stereo only).
#ifndef STB_VORBIS_MAX_CHANNELS
#define STB_VORBIS_MAX_CHANNELS 16 // enough for anyone?
#endif
// STB_VORBIS_PUSHDATA_CRC_COUNT [number]
// after a flush_pushdata(), stb_vorbis begins scanning for the
// next valid page, without backtracking. when it finds something
// that looks like a page, it streams through it and verifies its
// CRC32. Should that validation fail, it keeps scanning. But it's
// possible that _while_ streaming through to check the CRC32 of
// one candidate page, it sees another candidate page. This #define
// determines how many "overlapping" candidate pages it can search
// at once. Note that "real" pages are typically ~4KB to ~8KB, whereas
// garbage pages could be as big as 64KB, but probably average ~16KB.
// So don't hose ourselves by scanning an apparent 64KB page and
// missing a ton of real ones in the interim; so minimum of 2
#ifndef STB_VORBIS_PUSHDATA_CRC_COUNT
#define STB_VORBIS_PUSHDATA_CRC_COUNT 4
#endif
// STB_VORBIS_FAST_HUFFMAN_LENGTH [number]
// sets the log size of the huffman-acceleration table. Maximum
// supported value is 24. with larger numbers, more decodings are O(1),
// but the table size is larger so worse cache missing, so you'll have
// to probe (and try multiple ogg vorbis files) to find the sweet spot.
#ifndef STB_VORBIS_FAST_HUFFMAN_LENGTH
#define STB_VORBIS_FAST_HUFFMAN_LENGTH 10
#endif
// STB_VORBIS_FAST_BINARY_LENGTH [number]
// sets the log size of the binary-search acceleration table. this
// is used in similar fashion to the fast-huffman size to set initial
// parameters for the binary search
// STB_VORBIS_FAST_HUFFMAN_INT
// The fast huffman tables are much more efficient if they can be
// stored as 16-bit results instead of 32-bit results. This restricts
// the codebooks to having only 65535 possible outcomes, though.
// (At least, accelerated by the huffman table.)
#ifndef STB_VORBIS_FAST_HUFFMAN_INT
#define STB_VORBIS_FAST_HUFFMAN_SHORT
#endif
// STB_VORBIS_NO_HUFFMAN_BINARY_SEARCH
// If the 'fast huffman' search doesn't succeed, then stb_vorbis falls
// back on binary searching for the correct one. This requires storing
// extra tables with the huffman codes in sorted order. Defining this
// symbol trades off space for speed by forcing a linear search in the
// non-fast case, except for "sparse" codebooks.
// #define STB_VORBIS_NO_HUFFMAN_BINARY_SEARCH
// STB_VORBIS_DIVIDES_IN_RESIDUE
// stb_vorbis precomputes the result of the scalar residue decoding
// that would otherwise require a divide per chunk. you can trade off
// space for time by defining this symbol.
// #define STB_VORBIS_DIVIDES_IN_RESIDUE
// STB_VORBIS_DIVIDES_IN_CODEBOOK
// vorbis VQ codebooks can be encoded two ways: with every case explicitly
// stored, or with all elements being chosen from a small range of values,
// and all values possible in all elements. By default, stb_vorbis expands
// this latter kind out to look like the former kind for ease of decoding,
// because otherwise an integer divide-per-vector-element is required to
// unpack the index. If you define STB_VORBIS_DIVIDES_IN_CODEBOOK, you can
// trade off storage for speed.
//#define STB_VORBIS_DIVIDES_IN_CODEBOOK
#ifdef STB_VORBIS_CODEBOOK_SHORTS
#error "STB_VORBIS_CODEBOOK_SHORTS is no longer supported as it produced incorrect results for some input formats"
#endif
// STB_VORBIS_DIVIDE_TABLE
// this replaces small integer divides in the floor decode loop with
// table lookups. made less than 1% difference, so disabled by default.
// STB_VORBIS_NO_INLINE_DECODE
// disables the inlining of the scalar codebook fast-huffman decode.
// might save a little codespace; useful for debugging
// #define STB_VORBIS_NO_INLINE_DECODE
// STB_VORBIS_NO_DEFER_FLOOR
// Normally we only decode the floor without synthesizing the actual
// full curve. We can instead synthesize the curve immediately. This
// requires more memory and is very likely slower, so I don't think
// you'd ever want to do it except for debugging.
// #define STB_VORBIS_NO_DEFER_FLOOR
//////////////////////////////////////////////////////////////////////////////
#ifdef STB_VORBIS_NO_PULLDATA_API
#define STB_VORBIS_NO_INTEGER_CONVERSION
#define STB_VORBIS_NO_STDIO
#endif
#if defined(STB_VORBIS_NO_CRT) && !defined(STB_VORBIS_NO_STDIO)
#define STB_VORBIS_NO_STDIO 1
#endif
#ifndef STB_VORBIS_NO_INTEGER_CONVERSION
#ifndef STB_VORBIS_NO_FAST_SCALED_FLOAT
// only need endianness for fast-float-to-int, which we don't
// use for pushdata
#ifndef STB_VORBIS_BIG_ENDIAN
#define STB_VORBIS_ENDIAN 0
#else
#define STB_VORBIS_ENDIAN 1
#endif
#endif
#endif
#ifndef STB_VORBIS_NO_STDIO
#include <stdio.h>
#endif
#ifndef STB_VORBIS_NO_CRT
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
// find definition of alloca if it's not in stdlib.h:
#if defined(_MSC_VER) || defined(__MINGW32__)
#include <malloc.h>
#endif
#if defined(__linux__) || defined(__linux) || defined(__EMSCRIPTEN__)
#include <alloca.h>
#endif
#else // STB_VORBIS_NO_CRT
#define NULL 0
#define malloc(s) 0
#define free(s) ((void) 0)
#define realloc(s) 0
#endif // STB_VORBIS_NO_CRT
#include <limits.h>
#ifdef __MINGW32__
// eff you mingw:
// "fixed":
// http://sourceforge.net/p/mingw-w64/mailman/message/32882927/
// "no that broke the build, reverted, who cares about C":
// http://sourceforge.net/p/mingw-w64/mailman/message/32890381/
#ifdef __forceinline
#undef __forceinline
#endif
#define __forceinline
#define alloca __builtin_alloca
#elif !defined(_MSC_VER)
#if __GNUC__
#define __forceinline inline
#else
#define __forceinline
#endif
#endif
#if STB_VORBIS_MAX_CHANNELS > 256
#error "Value of STB_VORBIS_MAX_CHANNELS outside of allowed range"
#endif
#if STB_VORBIS_FAST_HUFFMAN_LENGTH > 24
#error "Value of STB_VORBIS_FAST_HUFFMAN_LENGTH outside of allowed range"
#endif
#if 0
#include <crtdbg.h>
#define CHECK(f) _CrtIsValidHeapPointer(f->channel_buffers[1])
#else
#define CHECK(f) ((void) 0)
#endif
#define MAX_BLOCKSIZE_LOG 13 // from specification
#define MAX_BLOCKSIZE (1 << MAX_BLOCKSIZE_LOG)
typedef unsigned char uint8;
typedef signed char int8;
typedef unsigned short uint16;
typedef signed short int16;
typedef unsigned int uint32;
typedef signed int int32;
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
typedef float codetype;
// @NOTE
//
// Some arrays below are tagged "//varies", which means it's actually
// a variable-sized piece of data, but rather than malloc I assume it's
// small enough it's better to just allocate it all together with the
// main thing
//
// Most of the variables are specified with the smallest size I could pack
// them into. It might give better performance to make them all full-sized
// integers. It should be safe to freely rearrange the structures or change
// the sizes larger--nothing relies on silently truncating etc., nor the
// order of variables.
#define FAST_HUFFMAN_TABLE_SIZE (1 << STB_VORBIS_FAST_HUFFMAN_LENGTH)
#define FAST_HUFFMAN_TABLE_MASK (FAST_HUFFMAN_TABLE_SIZE - 1)
typedef struct
{
int dimensions, entries;
uint8 *codeword_lengths;
float minimum_value;
float delta_value;
uint8 value_bits;
uint8 lookup_type;
uint8 sequence_p;
uint8 sparse;
uint32 lookup_values;
codetype *multiplicands;
uint32 *codewords;
#ifdef STB_VORBIS_FAST_HUFFMAN_SHORT
int16 fast_huffman[FAST_HUFFMAN_TABLE_SIZE];
#else
int32 fast_huffman[FAST_HUFFMAN_TABLE_SIZE];
#endif
uint32 *sorted_codewords;
int *sorted_values;
int sorted_entries;
} Codebook;
typedef struct
{
uint8 order;
uint16 rate;
uint16 bark_map_size;
uint8 amplitude_bits;
uint8 amplitude_offset;
uint8 number_of_books;
uint8 book_list[16]; // varies
} Floor0;
typedef struct
{
uint8 partitions;
uint8 partition_class_list[32]; // varies
uint8 class_dimensions[16]; // varies
uint8 class_subclasses[16]; // varies
uint8 class_masterbooks[16]; // varies
int16 subclass_books[16][8]; // varies
uint16 Xlist[31*8+2]; // varies
uint8 sorted_order[31*8+2];
uint8 neighbors[31*8+2][2];
uint8 floor1_multiplier;
uint8 rangebits;
int values;
} Floor1;
typedef union
{
Floor0 floor0;
Floor1 floor1;
} Floor;
typedef struct
{
uint32 begin, end;
uint32 part_size;
uint8 classifications;
uint8 classbook;
uint8 **classdata;
int16 (*residue_books)[8];
} Residue;
typedef struct
{
uint8 magnitude;
uint8 angle;
uint8 mux;
} MappingChannel;
typedef struct
{
uint16 coupling_steps;
MappingChannel *chan;
uint8 submaps;
uint8 submap_floor[15]; // varies
uint8 submap_residue[15]; // varies
} Mapping;
typedef struct
{
uint8 blockflag;
uint8 mapping;
uint16 windowtype;
uint16 transformtype;
} Mode;
typedef struct
{
uint32 goal_crc; // expected crc if match
int bytes_left; // bytes left in packet
uint32 crc_so_far; // running crc
int bytes_done; // bytes processed in _current_ chunk
uint32 sample_loc; // granule pos encoded in page
} CRCscan;
typedef struct
{
uint32 page_start, page_end;
uint32 last_decoded_sample;
} ProbedPage;
struct stb_vorbis
{
// user-accessible info
unsigned int sample_rate;
int channels;
unsigned int setup_memory_required;
unsigned int temp_memory_required;
unsigned int setup_temp_memory_required;
// input config
#ifndef STB_VORBIS_NO_STDIO
FILE *f;
uint32 f_start;
int close_on_free;
#endif
uint8 *stream;
uint8 *stream_start;
uint8 *stream_end;
uint32 stream_len;
uint8 push_mode;
uint32 first_audio_page_offset;
ProbedPage p_first, p_last;
// memory management
stb_vorbis_alloc alloc;
int setup_offset;
int temp_offset;
// run-time results
int eof;
enum STBVorbisError error;
// user-useful data
// header info
int blocksize[2];
int blocksize_0, blocksize_1;
int codebook_count;
Codebook *codebooks;
int floor_count;
uint16 floor_types[64]; // varies
Floor *floor_config;
int residue_count;
uint16 residue_types[64]; // varies
Residue *residue_config;
int mapping_count;
Mapping *mapping;
int mode_count;
Mode mode_config[64]; // varies
uint32 total_samples;
// decode buffer
float *channel_buffers[STB_VORBIS_MAX_CHANNELS];
float *outputs [STB_VORBIS_MAX_CHANNELS];
float *previous_window[STB_VORBIS_MAX_CHANNELS];
int previous_length;
#ifndef STB_VORBIS_NO_DEFER_FLOOR
int16 *finalY[STB_VORBIS_MAX_CHANNELS];
#else
float *floor_buffers[STB_VORBIS_MAX_CHANNELS];
#endif
uint32 current_loc; // sample location of next frame to decode
int current_loc_valid;
// per-blocksize precomputed data
// twiddle factors
float *A[2],*B[2],*C[2];
float *window[2];
uint16 *bit_reverse[2];
// current page/packet/segment streaming info
uint32 serial; // stream serial number for verification
int last_page;
int segment_count;
uint8 segments[255];
uint8 page_flag;
uint8 bytes_in_seg;
uint8 first_decode;
int next_seg;
int last_seg; // flag that we're on the last segment
int last_seg_which; // what was the segment number of the last seg?
uint32 acc;
int valid_bits;
int packet_bytes;
int end_seg_with_known_loc;
uint32 known_loc_for_packet;
int discard_samples_deferred;
uint32 samples_output;
// push mode scanning
int page_crc_tests; // only in push_mode: number of tests active; -1 if not searching
#ifndef STB_VORBIS_NO_PUSHDATA_API
CRCscan scan[STB_VORBIS_PUSHDATA_CRC_COUNT];
#endif
// sample-access
int channel_buffer_start;
int channel_buffer_end;
};
#if defined(STB_VORBIS_NO_PUSHDATA_API)
#define IS_PUSH_MODE(f) FALSE
#elif defined(STB_VORBIS_NO_PULLDATA_API)
#define IS_PUSH_MODE(f) TRUE
#else
#define IS_PUSH_MODE(f) ((f)->push_mode)
#endif
typedef struct stb_vorbis vorb;
static int error(vorb *f, enum STBVorbisError e)
{
f->error = e;
if (!f->eof && e != VORBIS_need_more_data) {
f->error=e; // breakpoint for debugging
}
return 0;
}
// these functions are used for allocating temporary memory
// while decoding. if you can afford the stack space, use
// alloca(); otherwise, provide a temp buffer and it will
// allocate out of those.
#define array_size_required(count,size) (count*(sizeof(void *)+(size)))
#define temp_alloc(f,size) (f->alloc.alloc_buffer ? setup_temp_malloc(f,size) : alloca(size))
#ifdef dealloca
#define temp_free(f,p) (f->alloc.alloc_buffer ? 0 : dealloca(size))
#else
#define temp_free(f,p) 0
#endif
#define temp_alloc_save(f) ((f)->temp_offset)
#define temp_alloc_restore(f,p) ((f)->temp_offset = (p))
#define temp_block_array(f,count,size) make_block_array(temp_alloc(f,array_size_required(count,size)), count, size)
// given a sufficiently large block of memory, make an array of pointers to subblocks of it
static void *make_block_array(void *mem, int count, int size)
{
int i;
void ** p = (void **) mem;
char *q = (char *) (p + count);
for (i=0; i < count; ++i) {
p[i] = q;
q += size;
}
return p;
}
static void *setup_malloc(vorb *f, int sz)
{
sz = (sz+3) & ~3;
f->setup_memory_required += sz;
if (f->alloc.alloc_buffer) {
void *p = (char *) f->alloc.alloc_buffer + f->setup_offset;
if (f->setup_offset + sz > f->temp_offset) return NULL;
f->setup_offset += sz;
return p;
}
return sz ? malloc(sz) : NULL;
}
static void setup_free(vorb *f, void *p)
{
if (f->alloc.alloc_buffer) return; // do nothing; setup mem is a stack
free(p);
}
static void *setup_temp_malloc(vorb *f, int sz)
{
sz = (sz+3) & ~3;
if (f->alloc.alloc_buffer) {
if (f->temp_offset - sz < f->setup_offset) return NULL;
f->temp_offset -= sz;
return (char *) f->alloc.alloc_buffer + f->temp_offset;
}
return malloc(sz);
}
static void setup_temp_free(vorb *f, void *p, int sz)
{
if (f->alloc.alloc_buffer) {
f->temp_offset += (sz+3)&~3;
return;
}
free(p);
}
#define CRC32_POLY 0x04c11db7 // from spec
static uint32 crc_table[256];
static void crc32_init(void)
{
int i,j;
uint32 s;
for(i=0; i < 256; i++) {
for (s=(uint32) i << 24, j=0; j < 8; ++j)
s = (s << 1) ^ (s >= (1U<<31) ? CRC32_POLY : 0);
crc_table[i] = s;
}
}
static __forceinline uint32 crc32_update(uint32 crc, uint8 byte)
{
return (crc << 8) ^ crc_table[byte ^ (crc >> 24)];
}
// used in setup, and for huffman that doesn't go fast path
static unsigned int bit_reverse(unsigned int n)
{
n = ((n & 0xAAAAAAAA) >> 1) | ((n & 0x55555555) << 1);
n = ((n & 0xCCCCCCCC) >> 2) | ((n & 0x33333333) << 2);
n = ((n & 0xF0F0F0F0) >> 4) | ((n & 0x0F0F0F0F) << 4);
n = ((n & 0xFF00FF00) >> 8) | ((n & 0x00FF00FF) << 8);
return (n >> 16) | (n << 16);
}
static float square(float x)
{
return x*x;
}
// this is a weird definition of log2() for which log2(1) = 1, log2(2) = 2, log2(4) = 3
// as required by the specification. fast(?) implementation from stb.h
// @OPTIMIZE: called multiple times per-packet with "constants"; move to setup
static int ilog(int32 n)
{
static signed char log2_4[16] = { 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4 };
if (n < 0) return 0; // signed n returns 0
// 2 compares if n < 16, 3 compares otherwise (4 if signed or n > 1<<29)
if (n < (1 << 14))
if (n < (1 << 4)) return 0 + log2_4[n ];
else if (n < (1 << 9)) return 5 + log2_4[n >> 5];
else return 10 + log2_4[n >> 10];
else if (n < (1 << 24))
if (n < (1 << 19)) return 15 + log2_4[n >> 15];
else return 20 + log2_4[n >> 20];
else if (n < (1 << 29)) return 25 + log2_4[n >> 25];
else return 30 + log2_4[n >> 30];
}
#ifndef M_PI
#define M_PI 3.14159265358979323846264f // from CRC
#endif
// code length assigned to a value with no huffman encoding
#define NO_CODE 255
/////////////////////// LEAF SETUP FUNCTIONS //////////////////////////
//
// these functions are only called at setup, and only a few times
// per file
static float float32_unpack(uint32 x)
{
// from the specification
uint32 mantissa = x & 0x1fffff;
uint32 sign = x & 0x80000000;
uint32 exp = (x & 0x7fe00000) >> 21;
double res = sign ? -(double)mantissa : (double)mantissa;
return (float) ldexp((float)res, exp-788);
}
// zlib & jpeg huffman tables assume that the output symbols
// can either be arbitrarily arranged, or have monotonically
// increasing frequencies--they rely on the lengths being sorted;
// this makes for a very simple generation algorithm.
// vorbis allows a huffman table with non-sorted lengths. This
// requires a more sophisticated construction, since symbols in
// order do not map to huffman codes "in order".
static void add_entry(Codebook *c, uint32 huff_code, int symbol, int count, int len, uint32 *values)
{
if (!c->sparse) {
c->codewords [symbol] = huff_code;
} else {
c->codewords [count] = huff_code;
c->codeword_lengths[count] = len;
values [count] = symbol;
}
}
static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values)
{
int i,k,m=0;
uint32 available[32];
memset(available, 0, sizeof(available));
// find the first entry
for (k=0; k < n; ++k) if (len[k] < NO_CODE) break;
if (k == n) { assert(c->sorted_entries == 0); return TRUE; }
// add to the list
add_entry(c, 0, k, m++, len[k], values);
// add all available leaves
for (i=1; i <= len[k]; ++i)
available[i] = 1U << (32-i);
// note that the above code treats the first case specially,
// but it's really the same as the following code, so they
// could probably be combined (except the initial code is 0,
// and I use 0 in available[] to mean 'empty')
for (i=k+1; i < n; ++i) {
uint32 res;
int z = len[i], y;
if (z == NO_CODE) continue;
// find lowest available leaf (should always be earliest,
// which is what the specification calls for)
// note that this property, and the fact we can never have
// more than one free leaf at a given level, isn't totally
// trivial to prove, but it seems true and the assert never
// fires, so!
while (z > 0 && !available[z]) --z;
if (z == 0) { return FALSE; }
res = available[z];
assert(z >= 0 && z < 32);
available[z] = 0;
add_entry(c, bit_reverse(res), i, m++, len[i], values);
// propogate availability up the tree
if (z != len[i]) {
assert(len[i] >= 0 && len[i] < 32);
for (y=len[i]; y > z; --y) {
assert(available[y] == 0);
available[y] = res + (1 << (32-y));
}
}
}
return TRUE;
}
// accelerated huffman table allows fast O(1) match of all symbols
// of length <= STB_VORBIS_FAST_HUFFMAN_LENGTH
static void compute_accelerated_huffman(Codebook *c)
{
int i, len;
for (i=0; i < FAST_HUFFMAN_TABLE_SIZE; ++i)
c->fast_huffman[i] = -1;
len = c->sparse ? c->sorted_entries : c->entries;
#ifdef STB_VORBIS_FAST_HUFFMAN_SHORT
if (len > 32767) len = 32767; // largest possible value we can encode!
#endif
for (i=0; i < len; ++i) {
if (c->codeword_lengths[i] <= STB_VORBIS_FAST_HUFFMAN_LENGTH) {
uint32 z = c->sparse ? bit_reverse(c->sorted_codewords[i]) : c->codewords[i];
// set table entries for all bit combinations in the higher bits
while (z < FAST_HUFFMAN_TABLE_SIZE) {
c->fast_huffman[z] = i;
z += 1 << c->codeword_lengths[i];
}
}
}
}
#ifdef _MSC_VER
#define STBV_CDECL __cdecl
#else
#define STBV_CDECL
#endif
static int STBV_CDECL uint32_compare(const void *p, const void *q)
{
uint32 x = * (uint32 *) p;
uint32 y = * (uint32 *) q;
return x < y ? -1 : x > y;
}
static int include_in_sort(Codebook *c, uint8 len)
{
if (c->sparse) { assert(len != NO_CODE); return TRUE; }
if (len == NO_CODE) return FALSE;
if (len > STB_VORBIS_FAST_HUFFMAN_LENGTH) return TRUE;
return FALSE;
}
// if the fast table above doesn't work, we want to binary
// search them... need to reverse the bits
static void compute_sorted_huffman(Codebook *c, uint8 *lengths, uint32 *values)
{
int i, len;
// build a list of all the entries
// OPTIMIZATION: don't include the short ones, since they'll be caught by FAST_HUFFMAN.
// this is kind of a frivolous optimization--I don't see any performance improvement,
// but it's like 4 extra lines of code, so.
if (!c->sparse) {
int k = 0;
for (i=0; i < c->entries; ++i)
if (include_in_sort(c, lengths[i]))
c->sorted_codewords[k++] = bit_reverse(c->codewords[i]);
assert(k == c->sorted_entries);
} else {
for (i=0; i < c->sorted_entries; ++i)
c->sorted_codewords[i] = bit_reverse(c->codewords[i]);
}
qsort(c->sorted_codewords, c->sorted_entries, sizeof(c->sorted_codewords[0]), uint32_compare);
c->sorted_codewords[c->sorted_entries] = 0xffffffff;
len = c->sparse ? c->sorted_entries : c->entries;
// now we need to indicate how they correspond; we could either
// #1: sort a different data structure that says who they correspond to
// #2: for each sorted entry, search the original list to find who corresponds
// #3: for each original entry, find the sorted entry
// #1 requires extra storage, #2 is slow, #3 can use binary search!
for (i=0; i < len; ++i) {
int huff_len = c->sparse ? lengths[values[i]] : lengths[i];
if (include_in_sort(c,huff_len)) {
uint32 code = bit_reverse(c->codewords[i]);
int x=0, n=c->sorted_entries;
while (n > 1) {
// invariant: sc[x] <= code < sc[x+n]
int m = x + (n >> 1);
if (c->sorted_codewords[m] <= code) {
x = m;
n -= (n>>1);
} else {
n >>= 1;
}
}
assert(c->sorted_codewords[x] == code);
if (c->sparse) {
c->sorted_values[x] = values[i];
c->codeword_lengths[x] = huff_len;
} else {
c->sorted_values[x] = i;
}
}
}
}
// only run while parsing the header (3 times)
static int vorbis_validate(uint8 *data)
{
static uint8 vorbis[6] = { 'v', 'o', 'r', 'b', 'i', 's' };
return memcmp(data, vorbis, 6) == 0;
}
// called from setup only, once per code book
// (formula implied by specification)
static int lookup1_values(int entries, int dim)
{
int r = (int) floor(exp((float) log((float) entries) / dim));
if ((int) floor(pow((float) r+1, dim)) <= entries) // (int) cast for MinGW warning;
++r; // floor() to avoid _ftol() when non-CRT
assert(pow((float) r+1, dim) > entries);
assert((int) floor(pow((float) r, dim)) <= entries); // (int),floor() as above
return r;
}
// called twice per file
static void compute_twiddle_factors(int n, float *A, float *B, float *C)
{
int n4 = n >> 2, n8 = n >> 3;
int k,k2;
for (k=k2=0; k < n4; ++k,k2+=2) {
A[k2 ] = (float) cos(4*k*M_PI/n);
A[k2+1] = (float) -sin(4*k*M_PI/n);
B[k2 ] = (float) cos((k2+1)*M_PI/n/2) * 0.5f;
B[k2+1] = (float) sin((k2+1)*M_PI/n/2) * 0.5f;
}
for (k=k2=0; k < n8; ++k,k2+=2) {
C[k2 ] = (float) cos(2*(k2+1)*M_PI/n);
C[k2+1] = (float) -sin(2*(k2+1)*M_PI/n);
}
}
static void compute_window(int n, float *window)
{
int n2 = n >> 1, i;
for (i=0; i < n2; ++i)
window[i] = (float) sin(0.5 * M_PI * square((float) sin((i - 0 + 0.5) / n2 * 0.5 * M_PI)));
}
static void compute_bitreverse(int n, uint16 *rev)
{
int ld = ilog(n) - 1; // ilog is off-by-one from normal definitions
int i, n8 = n >> 3;
for (i=0; i < n8; ++i)
rev[i] = (bit_reverse(i) >> (32-ld+3)) << 2;
}
static int init_blocksize(vorb *f, int b, int n)
{
int n2 = n >> 1, n4 = n >> 2, n8 = n >> 3;
f->A[b] = (float *) setup_malloc(f, sizeof(float) * n2);
f->B[b] = (float *) setup_malloc(f, sizeof(float) * n2);
f->C[b] = (float *) setup_malloc(f, sizeof(float) * n4);
if (!f->A[b] || !f->B[b] || !f->C[b]) return error(f, VORBIS_outofmem);
compute_twiddle_factors(n, f->A[b], f->B[b], f->C[b]);
f->window[b] = (float *) setup_malloc(f, sizeof(float) * n2);
if (!f->window[b]) return error(f, VORBIS_outofmem);
compute_window(n, f->window[b]);
f->bit_reverse[b] = (uint16 *) setup_malloc(f, sizeof(uint16) * n8);
if (!f->bit_reverse[b]) return error(f, VORBIS_outofmem);
compute_bitreverse(n, f->bit_reverse[b]);
return TRUE;
}
static void neighbors(uint16 *x, int n, int *plow, int *phigh)
{
int low = -1;
int high = 65536;
int i;
for (i=0; i < n; ++i) {
if (x[i] > low && x[i] < x[n]) { *plow = i; low = x[i]; }
if (x[i] < high && x[i] > x[n]) { *phigh = i; high = x[i]; }
}
}
// this has been repurposed so y is now the original index instead of y
typedef struct
{
uint16 x,id;
} stbv__floor_ordering;
static int STBV_CDECL point_compare(const void *p, const void *q)
{
stbv__floor_ordering *a = (stbv__floor_ordering *) p;
stbv__floor_ordering *b = (stbv__floor_ordering *) q;
return a->x < b->x ? -1 : a->x > b->x;
}
//
/////////////////////// END LEAF SETUP FUNCTIONS //////////////////////////
#if defined(STB_VORBIS_NO_STDIO)
#define USE_MEMORY(z) TRUE
#else
#define USE_MEMORY(z) ((z)->stream)
#endif
static uint8 get8(vorb *z)
{
if (USE_MEMORY(z)) {
if (z->stream >= z->stream_end) { z->eof = TRUE; return 0; }
return *z->stream++;
}
#ifndef STB_VORBIS_NO_STDIO
{
int c = fgetc(z->f);
if (c == EOF) { z->eof = TRUE; return 0; }
return c;
}
#endif
}
static uint32 get32(vorb *f)
{
uint32 x;
x = get8(f);
x += get8(f) << 8;
x += get8(f) << 16;
x += (uint32) get8(f) << 24;
return x;
}
static int getn(vorb *z, uint8 *data, int n)
{
if (USE_MEMORY(z)) {
if (z->stream+n > z->stream_end) { z->eof = 1; return 0; }
memcpy(data, z->stream, n);
z->stream += n;
return 1;
}
#ifndef STB_VORBIS_NO_STDIO
if (fread(data, n, 1, z->f) == 1)
return 1;
else {
z->eof = 1;
return 0;
}
#endif
}
static void skip(vorb *z, int n)
{
if (USE_MEMORY(z)) {
z->stream += n;
if (z->stream >= z->stream_end) z->eof = 1;
return;
}
#ifndef STB_VORBIS_NO_STDIO
{
long x = ftell(z->f);
fseek(z->f, x+n, SEEK_SET);
}
#endif
}
static int set_file_offset(stb_vorbis *f, unsigned int loc)
{
#ifndef STB_VORBIS_NO_PUSHDATA_API
if (f->push_mode) return 0;
#endif
f->eof = 0;
if (USE_MEMORY(f)) {
if (f->stream_start + loc >= f->stream_end || f->stream_start + loc < f->stream_start) {
f->stream = f->stream_end;
f->eof = 1;
return 0;
} else {
f->stream = f->stream_start + loc;
return 1;
}
}
#ifndef STB_VORBIS_NO_STDIO
if (loc + f->f_start < loc || loc >= 0x80000000) {
loc = 0x7fffffff;
f->eof = 1;
} else {
loc += f->f_start;
}
if (!fseek(f->f, loc, SEEK_SET))
return 1;
f->eof = 1;
fseek(f->f, f->f_start, SEEK_END);
return 0;
#endif
}
static uint8 ogg_page_header[4] = { 0x4f, 0x67, 0x67, 0x53 };
static int capture_pattern(vorb *f)
{
if (0x4f != get8(f)) return FALSE;
if (0x67 != get8(f)) return FALSE;
if (0x67 != get8(f)) return FALSE;
if (0x53 != get8(f)) return FALSE;
return TRUE;
}
#define PAGEFLAG_continued_packet 1
#define PAGEFLAG_first_page 2
#define PAGEFLAG_last_page 4
static int start_page_no_capturepattern(vorb *f)
{
uint32 loc0,loc1,n;
// stream structure version
if (0 != get8(f)) return error(f, VORBIS_invalid_stream_structure_version);
// header flag
f->page_flag = get8(f);
// absolute granule position
loc0 = get32(f);
loc1 = get32(f);
// @TODO: validate loc0,loc1 as valid positions?
// stream serial number -- vorbis doesn't interleave, so discard
get32(f);
//if (f->serial != get32(f)) return error(f, VORBIS_incorrect_stream_serial_number);
// page sequence number
n = get32(f);
f->last_page = n;
// CRC32
get32(f);
// page_segments
f->segment_count = get8(f);
if (!getn(f, f->segments, f->segment_count))
return error(f, VORBIS_unexpected_eof);
// assume we _don't_ know any the sample position of any segments
f->end_seg_with_known_loc = -2;
if (loc0 != ~0U || loc1 != ~0U) {
int i;
// determine which packet is the last one that will complete
for (i=f->segment_count-1; i >= 0; --i)
if (f->segments[i] < 255)
break;
// 'i' is now the index of the _last_ segment of a packet that ends
if (i >= 0) {
f->end_seg_with_known_loc = i;
f->known_loc_for_packet = loc0;
}
}
if (f->first_decode) {
int i,len;
ProbedPage p;
len = 0;
for (i=0; i < f->segment_count; ++i)
len += f->segments[i];
len += 27 + f->segment_count;
p.page_start = f->first_audio_page_offset;
p.page_end = p.page_start + len;
p.last_decoded_sample = loc0;
f->p_first = p;
}
f->next_seg = 0;
return TRUE;
}
static int start_page(vorb *f)
{
if (!capture_pattern(f)) return error(f, VORBIS_missing_capture_pattern);
return start_page_no_capturepattern(f);
}
static int start_packet(vorb *f)
{
while (f->next_seg == -1) {
if (!start_page(f)) return FALSE;
if (f->page_flag & PAGEFLAG_continued_packet)
return error(f, VORBIS_continued_packet_flag_invalid);
}
f->last_seg = FALSE;
f->valid_bits = 0;
f->packet_bytes = 0;
f->bytes_in_seg = 0;
// f->next_seg is now valid
return TRUE;
}
static int maybe_start_packet(vorb *f)
{
if (f->next_seg == -1) {
int x = get8(f);
if (f->eof) return FALSE; // EOF at page boundary is not an error!
if (0x4f != x ) return error(f, VORBIS_missing_capture_pattern);
if (0x67 != get8(f)) return error(f, VORBIS_missing_capture_pattern);
if (0x67 != get8(f)) return error(f, VORBIS_missing_capture_pattern);
if (0x53 != get8(f)) return error(f, VORBIS_missing_capture_pattern);
if (!start_page_no_capturepattern(f)) return FALSE;
if (f->page_flag & PAGEFLAG_continued_packet) {
// set up enough state that we can read this packet if we want,
// e.g. during recovery
f->last_seg = FALSE;
f->bytes_in_seg = 0;
return error(f, VORBIS_continued_packet_flag_invalid);
}
}
return start_packet(f);
}
static int next_segment(vorb *f)
{
int len;
if (f->last_seg) return 0;
if (f->next_seg == -1) {
f->last_seg_which = f->segment_count-1; // in case start_page fails
if (!start_page(f)) { f->last_seg = 1; return 0; }
if (!(f->page_flag & PAGEFLAG_continued_packet)) return error(f, VORBIS_continued_packet_flag_invalid);
}
len = f->segments[f->next_seg++];
if (len < 255) {
f->last_seg = TRUE;
f->last_seg_which = f->next_seg-1;
}
if (f->next_seg >= f->segment_count)
f->next_seg = -1;
assert(f->bytes_in_seg == 0);
f->bytes_in_seg = len;
return len;
}
#define EOP (-1)
#define INVALID_BITS (-1)
static int get8_packet_raw(vorb *f)
{
if (!f->bytes_in_seg) { // CLANG!
if (f->last_seg) return EOP;
else if (!next_segment(f)) return EOP;
}
assert(f->bytes_in_seg > 0);
--f->bytes_in_seg;
++f->packet_bytes;
return get8(f);
}
static int get8_packet(vorb *f)
{
int x = get8_packet_raw(f);
f->valid_bits = 0;
return x;
}
static void flush_packet(vorb *f)
{
while (get8_packet_raw(f) != EOP);
}
// @OPTIMIZE: this is the secondary bit decoder, so it's probably not as important
// as the huffman decoder?
static uint32 get_bits(vorb *f, int n)
{
uint32 z;
if (f->valid_bits < 0) return 0;
if (f->valid_bits < n) {
if (n > 24) {
// the accumulator technique below would not work correctly in this case
z = get_bits(f, 24);
z += get_bits(f, n-24) << 24;
return z;
}
if (f->valid_bits == 0) f->acc = 0;
while (f->valid_bits < n) {
int z = get8_packet_raw(f);
if (z == EOP) {
f->valid_bits = INVALID_BITS;
return 0;
}
f->acc += z << f->valid_bits;
f->valid_bits += 8;
}
}
if (f->valid_bits < 0) return 0;
z = f->acc & ((1 << n)-1);
f->acc >>= n;
f->valid_bits -= n;
return z;
}
// @OPTIMIZE: primary accumulator for huffman
// expand the buffer to as many bits as possible without reading off end of packet
// it might be nice to allow f->valid_bits and f->acc to be stored in registers,
// e.g. cache them locally and decode locally
static __forceinline void prep_huffman(vorb *f)
{
if (f->valid_bits <= 24) {
if (f->valid_bits == 0) f->acc = 0;
do {
int z;
if (f->last_seg && !f->bytes_in_seg) return;
z = get8_packet_raw(f);
if (z == EOP) return;
f->acc += (unsigned) z << f->valid_bits;
f->valid_bits += 8;
} while (f->valid_bits <= 24);
}
}
enum
{
VORBIS_packet_id = 1,
VORBIS_packet_comment = 3,
VORBIS_packet_setup = 5
};
static int codebook_decode_scalar_raw(vorb *f, Codebook *c)
{
int i;
prep_huffman(f);
if (c->codewords == NULL && c->sorted_codewords == NULL)
return -1;
// cases to use binary search: sorted_codewords && !c->codewords
// sorted_codewords && c->entries > 8
if (c->entries > 8 ? c->sorted_codewords!=NULL : !c->codewords) {
// binary search
uint32 code = bit_reverse(f->acc);
int x=0, n=c->sorted_entries, len;
while (n > 1) {
// invariant: sc[x] <= code < sc[x+n]
int m = x + (n >> 1);
if (c->sorted_codewords[m] <= code) {
x = m;
n -= (n>>1);
} else {
n >>= 1;
}
}
// x is now the sorted index
if (!c->sparse) x = c->sorted_values[x];
// x is now sorted index if sparse, or symbol otherwise
len = c->codeword_lengths[x];
if (f->valid_bits >= len) {
f->acc >>= len;
f->valid_bits -= len;
return x;
}
f->valid_bits = 0;
return -1;
}
// if small, linear search
assert(!c->sparse);
for (i=0; i < c->entries; ++i) {
if (c->codeword_lengths[i] == NO_CODE) continue;
if (c->codewords[i] == (f->acc & ((1 << c->codeword_lengths[i])-1))) {
if (f->valid_bits >= c->codeword_lengths[i]) {
f->acc >>= c->codeword_lengths[i];
f->valid_bits -= c->codeword_lengths[i];
return i;
}
f->valid_bits = 0;
return -1;
}
}
error(f, VORBIS_invalid_stream);
f->valid_bits = 0;
return -1;
}
#ifndef STB_VORBIS_NO_INLINE_DECODE
#define DECODE_RAW(var, f,c) \
if (f->valid_bits < STB_VORBIS_FAST_HUFFMAN_LENGTH) \
prep_huffman(f); \
var = f->acc & FAST_HUFFMAN_TABLE_MASK; \
var = c->fast_huffman[var]; \
if (var >= 0) { \
int n = c->codeword_lengths[var]; \
f->acc >>= n; \
f->valid_bits -= n; \
if (f->valid_bits < 0) { f->valid_bits = 0; var = -1; } \
} else { \
var = codebook_decode_scalar_raw(f,c); \
}
#else
static int codebook_decode_scalar(vorb *f, Codebook *c)
{
int i;
if (f->valid_bits < STB_VORBIS_FAST_HUFFMAN_LENGTH)
prep_huffman(f);
// fast huffman table lookup
i = f->acc & FAST_HUFFMAN_TABLE_MASK;
i = c->fast_huffman[i];
if (i >= 0) {
f->acc >>= c->codeword_lengths[i];
f->valid_bits -= c->codeword_lengths[i];
if (f->valid_bits < 0) { f->valid_bits = 0; return -1; }
return i;
}
return codebook_decode_scalar_raw(f,c);
}
#define DECODE_RAW(var,f,c) var = codebook_decode_scalar(f,c);
#endif
#define DECODE(var,f,c) \
DECODE_RAW(var,f,c) \
if (c->sparse) var = c->sorted_values[var];
#ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
#define DECODE_VQ(var,f,c) DECODE_RAW(var,f,c)
#else
#define DECODE_VQ(var,f,c) DECODE(var,f,c)
#endif
// CODEBOOK_ELEMENT_FAST is an optimization for the CODEBOOK_FLOATS case
// where we avoid one addition
#define CODEBOOK_ELEMENT(c,off) (c->multiplicands[off])
#define CODEBOOK_ELEMENT_FAST(c,off) (c->multiplicands[off])
#define CODEBOOK_ELEMENT_BASE(c) (0)
static int codebook_decode_start(vorb *f, Codebook *c)
{
int z = -1;
// type 0 is only legal in a scalar context
if (c->lookup_type == 0)
error(f, VORBIS_invalid_stream);
else {
DECODE_VQ(z,f,c);
if (c->sparse) assert(z < c->sorted_entries);
if (z < 0) { // check for EOP
if (!f->bytes_in_seg)
if (f->last_seg)
return z;
error(f, VORBIS_invalid_stream);
}
}
return z;
}
static int codebook_decode(vorb *f, Codebook *c, float *output, int len)
{
int i,z = codebook_decode_start(f,c);
if (z < 0) return FALSE;
if (len > c->dimensions) len = c->dimensions;
#ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
if (c->lookup_type == 1) {
float last = CODEBOOK_ELEMENT_BASE(c);
int div = 1;
for (i=0; i < len; ++i) {
int off = (z / div) % c->lookup_values;
float val = CODEBOOK_ELEMENT_FAST(c,off) + last;
output[i] += val;
if (c->sequence_p) last = val + c->minimum_value;
div *= c->lookup_values;
}
return TRUE;
}
#endif
z *= c->dimensions;
if (c->sequence_p) {
float last = CODEBOOK_ELEMENT_BASE(c);
for (i=0; i < len; ++i) {
float val = CODEBOOK_ELEMENT_FAST(c,z+i) + last;
output[i] += val;
last = val + c->minimum_value;
}
} else {
float last = CODEBOOK_ELEMENT_BASE(c);
for (i=0; i < len; ++i) {
output[i] += CODEBOOK_ELEMENT_FAST(c,z+i) + last;
}
}
return TRUE;
}
static int codebook_decode_step(vorb *f, Codebook *c, float *output, int len, int step)
{
int i,z = codebook_decode_start(f,c);
float last = CODEBOOK_ELEMENT_BASE(c);
if (z < 0) return FALSE;
if (len > c->dimensions) len = c->dimensions;
#ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
if (c->lookup_type == 1) {
int div = 1;
for (i=0; i < len; ++i) {
int off = (z / div) % c->lookup_values;
float val = CODEBOOK_ELEMENT_FAST(c,off) + last;
output[i*step] += val;
if (c->sequence_p) last = val;
div *= c->lookup_values;
}
return TRUE;
}
#endif
z *= c->dimensions;
for (i=0; i < len; ++i) {
float val = CODEBOOK_ELEMENT_FAST(c,z+i) + last;
output[i*step] += val;
if (c->sequence_p) last = val;
}
return TRUE;
}
static int codebook_decode_deinterleave_repeat(vorb *f, Codebook *c, float **outputs, int ch, int *c_inter_p, int *p_inter_p, int len, int total_decode)
{
int c_inter = *c_inter_p;
int p_inter = *p_inter_p;
int i,z, effective = c->dimensions;
// type 0 is only legal in a scalar context
if (c->lookup_type == 0) return error(f, VORBIS_invalid_stream);
while (total_decode > 0) {
float last = CODEBOOK_ELEMENT_BASE(c);
DECODE_VQ(z,f,c);
#ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
assert(!c->sparse || z < c->sorted_entries);
#endif
if (z < 0) {
if (!f->bytes_in_seg)
if (f->last_seg) return FALSE;
return error(f, VORBIS_invalid_stream);
}
// if this will take us off the end of the buffers, stop short!
// we check by computing the length of the virtual interleaved
// buffer (len*ch), our current offset within it (p_inter*ch)+(c_inter),
// and the length we'll be using (effective)
if (c_inter + p_inter*ch + effective > len * ch) {
effective = len*ch - (p_inter*ch - c_inter);
}
#ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
if (c->lookup_type == 1) {
int div = 1;
for (i=0; i < effective; ++i) {
int off = (z / div) % c->lookup_values;
float val = CODEBOOK_ELEMENT_FAST(c,off) + last;
if (outputs[c_inter])
outputs[c_inter][p_inter] += val;
if (++c_inter == ch) { c_inter = 0; ++p_inter; }
if (c->sequence_p) last = val;
div *= c->lookup_values;
}
} else
#endif
{
z *= c->dimensions;
if (c->sequence_p) {
for (i=0; i < effective; ++i) {
float val = CODEBOOK_ELEMENT_FAST(c,z+i) + last;
if (outputs[c_inter])
outputs[c_inter][p_inter] += val;
if (++c_inter == ch) { c_inter = 0; ++p_inter; }
last = val;
}
} else {
for (i=0; i < effective; ++i) {
float val = CODEBOOK_ELEMENT_FAST(c,z+i) + last;
if (outputs[c_inter])
outputs[c_inter][p_inter] += val;
if (++c_inter == ch) { c_inter = 0; ++p_inter; }
}
}
}
total_decode -= effective;
}
*c_inter_p = c_inter;
*p_inter_p = p_inter;
return TRUE;
}
static int predict_point(int x, int x0, int x1, int y0, int y1)
{
int dy = y1 - y0;
int adx = x1 - x0;
// @OPTIMIZE: force int division to round in the right direction... is this necessary on x86?
int err = abs(dy) * (x - x0);
int off = err / adx;
return dy < 0 ? y0 - off : y0 + off;
}
// the following table is block-copied from the specification
static float inverse_db_table[256] =
{
1.0649863e-07f, 1.1341951e-07f, 1.2079015e-07f, 1.2863978e-07f,
1.3699951e-07f, 1.4590251e-07f, 1.5538408e-07f, 1.6548181e-07f,
1.7623575e-07f, 1.8768855e-07f, 1.9988561e-07f, 2.1287530e-07f,
2.2670913e-07f, 2.4144197e-07f, 2.5713223e-07f, 2.7384213e-07f,
2.9163793e-07f, 3.1059021e-07f, 3.3077411e-07f, 3.5226968e-07f,
3.7516214e-07f, 3.9954229e-07f, 4.2550680e-07f, 4.5315863e-07f,
4.8260743e-07f, 5.1396998e-07f, 5.4737065e-07f, 5.8294187e-07f,
6.2082472e-07f, 6.6116941e-07f, 7.0413592e-07f, 7.4989464e-07f,
7.9862701e-07f, 8.5052630e-07f, 9.0579828e-07f, 9.6466216e-07f,
1.0273513e-06f, 1.0941144e-06f, 1.1652161e-06f, 1.2409384e-06f,
1.3215816e-06f, 1.4074654e-06f, 1.4989305e-06f, 1.5963394e-06f,
1.7000785e-06f, 1.8105592e-06f, 1.9282195e-06f, 2.0535261e-06f,
2.1869758e-06f, 2.3290978e-06f, 2.4804557e-06f, 2.6416497e-06f,
2.8133190e-06f, 2.9961443e-06f, 3.1908506e-06f, 3.3982101e-06f,
3.6190449e-06f, 3.8542308e-06f, 4.1047004e-06f, 4.3714470e-06f,
4.6555282e-06f, 4.9580707e-06f, 5.2802740e-06f, 5.6234160e-06f,
5.9888572e-06f, 6.3780469e-06f, 6.7925283e-06f, 7.2339451e-06f,
7.7040476e-06f, 8.2047000e-06f, 8.7378876e-06f, 9.3057248e-06f,
9.9104632e-06f, 1.0554501e-05f, 1.1240392e-05f, 1.1970856e-05f,
1.2748789e-05f, 1.3577278e-05f, 1.4459606e-05f, 1.5399272e-05f,
1.6400004e-05f, 1.7465768e-05f, 1.8600792e-05f, 1.9809576e-05f,
2.1096914e-05f, 2.2467911e-05f, 2.3928002e-05f, 2.5482978e-05f,
2.7139006e-05f, 2.8902651e-05f, 3.0780908e-05f, 3.2781225e-05f,
3.4911534e-05f, 3.7180282e-05f, 3.9596466e-05f, 4.2169667e-05f,
4.4910090e-05f, 4.7828601e-05f, 5.0936773e-05f, 5.4246931e-05f,
5.7772202e-05f, 6.1526565e-05f, 6.5524908e-05f, 6.9783085e-05f,
7.4317983e-05f, 7.9147585e-05f, 8.4291040e-05f, 8.9768747e-05f,
9.5602426e-05f, 0.00010181521f, 0.00010843174f, 0.00011547824f,
0.00012298267f, 0.00013097477f, 0.00013948625f, 0.00014855085f,
0.00015820453f, 0.00016848555f, 0.00017943469f, 0.00019109536f,
0.00020351382f, 0.00021673929f, 0.00023082423f, 0.00024582449f,
0.00026179955f, 0.00027881276f, 0.00029693158f, 0.00031622787f,
0.00033677814f, 0.00035866388f, 0.00038197188f, 0.00040679456f,
0.00043323036f, 0.00046138411f, 0.00049136745f, 0.00052329927f,
0.00055730621f, 0.00059352311f, 0.00063209358f, 0.00067317058f,
0.00071691700f, 0.00076350630f, 0.00081312324f, 0.00086596457f,
0.00092223983f, 0.00098217216f, 0.0010459992f, 0.0011139742f,
0.0011863665f, 0.0012634633f, 0.0013455702f, 0.0014330129f,
0.0015261382f, 0.0016253153f, 0.0017309374f, 0.0018434235f,
0.0019632195f, 0.0020908006f, 0.0022266726f, 0.0023713743f,
0.0025254795f, 0.0026895994f, 0.0028643847f, 0.0030505286f,
0.0032487691f, 0.0034598925f, 0.0036847358f, 0.0039241906f,
0.0041792066f, 0.0044507950f, 0.0047400328f, 0.0050480668f,
0.0053761186f, 0.0057254891f, 0.0060975636f, 0.0064938176f,
0.0069158225f, 0.0073652516f, 0.0078438871f, 0.0083536271f,
0.0088964928f, 0.009474637f, 0.010090352f, 0.010746080f,
0.011444421f, 0.012188144f, 0.012980198f, 0.013823725f,
0.014722068f, 0.015678791f, 0.016697687f, 0.017782797f,
0.018938423f, 0.020169149f, 0.021479854f, 0.022875735f,
0.024362330f, 0.025945531f, 0.027631618f, 0.029427276f,
0.031339626f, 0.033376252f, 0.035545228f, 0.037855157f,
0.040315199f, 0.042935108f, 0.045725273f, 0.048696758f,
0.051861348f, 0.055231591f, 0.058820850f, 0.062643361f,
0.066714279f, 0.071049749f, 0.075666962f, 0.080584227f,
0.085821044f, 0.091398179f, 0.097337747f, 0.10366330f,
0.11039993f, 0.11757434f, 0.12521498f, 0.13335215f,
0.14201813f, 0.15124727f, 0.16107617f, 0.17154380f,
0.18269168f, 0.19456402f, 0.20720788f, 0.22067342f,
0.23501402f, 0.25028656f, 0.26655159f, 0.28387361f,
0.30232132f, 0.32196786f, 0.34289114f, 0.36517414f,
0.38890521f, 0.41417847f, 0.44109412f, 0.46975890f,
0.50028648f, 0.53279791f, 0.56742212f, 0.60429640f,
0.64356699f, 0.68538959f, 0.72993007f, 0.77736504f,
0.82788260f, 0.88168307f, 0.9389798f, 1.0f
};
// @OPTIMIZE: if you want to replace this bresenham line-drawing routine,
// note that you must produce bit-identical output to decode correctly;
// this specific sequence of operations is specified in the spec (it's
// drawing integer-quantized frequency-space lines that the encoder
// expects to be exactly the same)
// ... also, isn't the whole point of Bresenham's algorithm to NOT
// have to divide in the setup? sigh.
#ifndef STB_VORBIS_NO_DEFER_FLOOR
#define LINE_OP(a,b) a *= b
#else
#define LINE_OP(a,b) a = b
#endif
#ifdef STB_VORBIS_DIVIDE_TABLE
#define DIVTAB_NUMER 32
#define DIVTAB_DENOM 64
int8 integer_divide_table[DIVTAB_NUMER][DIVTAB_DENOM]; // 2KB
#endif
static __forceinline void draw_line(float *output, int x0, int y0, int x1, int y1, int n)
{
int dy = y1 - y0;
int adx = x1 - x0;
int ady = abs(dy);
int base;
int x=x0,y=y0;
int err = 0;
int sy;
#ifdef STB_VORBIS_DIVIDE_TABLE
if (adx < DIVTAB_DENOM && ady < DIVTAB_NUMER) {
if (dy < 0) {
base = -integer_divide_table[ady][adx];
sy = base-1;
} else {
base = integer_divide_table[ady][adx];
sy = base+1;
}
} else {
base = dy / adx;
if (dy < 0)
sy = base - 1;
else
sy = base+1;
}
#else
base = dy / adx;
if (dy < 0)
sy = base - 1;
else
sy = base+1;
#endif
ady -= abs(base) * adx;
if (x1 > n) x1 = n;
if (x < x1) {
LINE_OP(output[x], inverse_db_table[y]);
for (++x; x < x1; ++x) {
err += ady;
if (err >= adx) {
err -= adx;
y += sy;
} else
y += base;
LINE_OP(output[x], inverse_db_table[y]);
}
}
}
static int residue_decode(vorb *f, Codebook *book, float *target, int offset, int n, int rtype)
{
int k;
if (rtype == 0) {
int step = n / book->dimensions;
for (k=0; k < step; ++k)
if (!codebook_decode_step(f, book, target+offset+k, n-offset-k, step))
return FALSE;
} else {
for (k=0; k < n; ) {
if (!codebook_decode(f, book, target+offset, n-k))
return FALSE;
k += book->dimensions;
offset += book->dimensions;
}
}
return TRUE;
}
static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int rn, uint8 *do_not_decode)
{
int i,j,pass;
Residue *r = f->residue_config + rn;
int rtype = f->residue_types[rn];
int c = r->classbook;
int classwords = f->codebooks[c].dimensions;
int n_read = r->end - r->begin;
int part_read = n_read / r->part_size;
int temp_alloc_point = temp_alloc_save(f);
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
uint8 ***part_classdata = (uint8 ***) temp_block_array(f,f->channels, part_read * sizeof(**part_classdata));
#else
int **classifications = (int **) temp_block_array(f,f->channels, part_read * sizeof(**classifications));
#endif
CHECK(f);
for (i=0; i < ch; ++i)
if (!do_not_decode[i])
memset(residue_buffers[i], 0, sizeof(float) * n);
if (rtype == 2 && ch != 1) {
for (j=0; j < ch; ++j)
if (!do_not_decode[j])
break;
if (j == ch)
goto done;
for (pass=0; pass < 8; ++pass) {
int pcount = 0, class_set = 0;
if (ch == 2) {
while (pcount < part_read) {
int z = r->begin + pcount*r->part_size;
int c_inter = (z & 1), p_inter = z>>1;
if (pass == 0) {
Codebook *c = f->codebooks+r->classbook;
int q;
DECODE(q,f,c);
if (q == EOP) goto done;
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
part_classdata[0][class_set] = r->classdata[q];
#else
for (i=classwords-1; i >= 0; --i) {
classifications[0][i+pcount] = q % r->classifications;
q /= r->classifications;
}
#endif
}
for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
int z = r->begin + pcount*r->part_size;
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
int c = part_classdata[0][class_set][i];
#else
int c = classifications[0][pcount];
#endif
int b = r->residue_books[c][pass];
if (b >= 0) {
Codebook *book = f->codebooks + b;
#ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size))
goto done;
#else
// saves 1%
if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size))
goto done;
#endif
} else {
z += r->part_size;
c_inter = z & 1;
p_inter = z >> 1;
}
}
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
++class_set;
#endif
}
} else if (ch == 1) {
while (pcount < part_read) {
int z = r->begin + pcount*r->part_size;
int c_inter = 0, p_inter = z;
if (pass == 0) {
Codebook *c = f->codebooks+r->classbook;
int q;
DECODE(q,f,c);
if (q == EOP) goto done;
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
part_classdata[0][class_set] = r->classdata[q];
#else
for (i=classwords-1; i >= 0; --i) {
classifications[0][i+pcount] = q % r->classifications;
q /= r->classifications;
}
#endif
}
for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
int z = r->begin + pcount*r->part_size;
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
int c = part_classdata[0][class_set][i];
#else
int c = classifications[0][pcount];
#endif
int b = r->residue_books[c][pass];
if (b >= 0) {
Codebook *book = f->codebooks + b;
if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size))
goto done;
} else {
z += r->part_size;
c_inter = 0;
p_inter = z;
}
}
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
++class_set;
#endif
}
} else {
while (pcount < part_read) {
int z = r->begin + pcount*r->part_size;
int c_inter = z % ch, p_inter = z/ch;
if (pass == 0) {
Codebook *c = f->codebooks+r->classbook;
int q;
DECODE(q,f,c);
if (q == EOP) goto done;
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
part_classdata[0][class_set] = r->classdata[q];
#else
for (i=classwords-1; i >= 0; --i) {
classifications[0][i+pcount] = q % r->classifications;
q /= r->classifications;
}
#endif
}
for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
int z = r->begin + pcount*r->part_size;
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
int c = part_classdata[0][class_set][i];
#else
int c = classifications[0][pcount];
#endif
int b = r->residue_books[c][pass];
if (b >= 0) {
Codebook *book = f->codebooks + b;
if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size))
goto done;
} else {
z += r->part_size;
c_inter = z % ch;
p_inter = z / ch;
}
}
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
++class_set;
#endif
}
}
}
goto done;
}
CHECK(f);
for (pass=0; pass < 8; ++pass) {
int pcount = 0, class_set=0;
while (pcount < part_read) {
if (pass == 0) {
for (j=0; j < ch; ++j) {
if (!do_not_decode[j]) {
Codebook *c = f->codebooks+r->classbook;
int temp;
DECODE(temp,f,c);
if (temp == EOP) goto done;
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
part_classdata[j][class_set] = r->classdata[temp];
#else
for (i=classwords-1; i >= 0; --i) {
classifications[j][i+pcount] = temp % r->classifications;
temp /= r->classifications;
}
#endif
}
}
}
for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
for (j=0; j < ch; ++j) {
if (!do_not_decode[j]) {
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
int c = part_classdata[j][class_set][i];
#else
int c = classifications[j][pcount];
#endif
int b = r->residue_books[c][pass];
if (b >= 0) {
float *target = residue_buffers[j];
int offset = r->begin + pcount * r->part_size;
int n = r->part_size;
Codebook *book = f->codebooks + b;
if (!residue_decode(f, book, target, offset, n, rtype))
goto done;
}
}
}
}
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
++class_set;
#endif
}
}
done:
CHECK(f);
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
temp_free(f,part_classdata);
#else
temp_free(f,classifications);
#endif
temp_alloc_restore(f,temp_alloc_point);
}
#if 0
// slow way for debugging
void inverse_mdct_slow(float *buffer, int n)
{
int i,j;
int n2 = n >> 1;
float *x = (float *) malloc(sizeof(*x) * n2);
memcpy(x, buffer, sizeof(*x) * n2);
for (i=0; i < n; ++i) {
float acc = 0;
for (j=0; j < n2; ++j)
// formula from paper:
//acc += n/4.0f * x[j] * (float) cos(M_PI / 2 / n * (2 * i + 1 + n/2.0)*(2*j+1));
// formula from wikipedia
//acc += 2.0f / n2 * x[j] * (float) cos(M_PI/n2 * (i + 0.5 + n2/2)*(j + 0.5));
// these are equivalent, except the formula from the paper inverts the multiplier!
// however, what actually works is NO MULTIPLIER!?!
//acc += 64 * 2.0f / n2 * x[j] * (float) cos(M_PI/n2 * (i + 0.5 + n2/2)*(j + 0.5));
acc += x[j] * (float) cos(M_PI / 2 / n * (2 * i + 1 + n/2.0)*(2*j+1));
buffer[i] = acc;
}
free(x);
}
#elif 0
// same as above, but just barely able to run in real time on modern machines
void inverse_mdct_slow(float *buffer, int n, vorb *f, int blocktype)
{
float mcos[16384];
int i,j;
int n2 = n >> 1, nmask = (n << 2) -1;
float *x = (float *) malloc(sizeof(*x) * n2);
memcpy(x, buffer, sizeof(*x) * n2);
for (i=0; i < 4*n; ++i)
mcos[i] = (float) cos(M_PI / 2 * i / n);
for (i=0; i < n; ++i) {
float acc = 0;
for (j=0; j < n2; ++j)
acc += x[j] * mcos[(2 * i + 1 + n2)*(2*j+1) & nmask];
buffer[i] = acc;
}
free(x);
}
#elif 0
// transform to use a slow dct-iv; this is STILL basically trivial,
// but only requires half as many ops
void dct_iv_slow(float *buffer, int n)
{
float mcos[16384];
float x[2048];
int i,j;
int n2 = n >> 1, nmask = (n << 3) - 1;
memcpy(x, buffer, sizeof(*x) * n);
for (i=0; i < 8*n; ++i)
mcos[i] = (float) cos(M_PI / 4 * i / n);
for (i=0; i < n; ++i) {
float acc = 0;
for (j=0; j < n; ++j)
acc += x[j] * mcos[((2 * i + 1)*(2*j+1)) & nmask];
buffer[i] = acc;
}
}
void inverse_mdct_slow(float *buffer, int n, vorb *f, int blocktype)
{
int i, n4 = n >> 2, n2 = n >> 1, n3_4 = n - n4;
float temp[4096];
memcpy(temp, buffer, n2 * sizeof(float));
dct_iv_slow(temp, n2); // returns -c'-d, a-b'
for (i=0; i < n4 ; ++i) buffer[i] = temp[i+n4]; // a-b'
for ( ; i < n3_4; ++i) buffer[i] = -temp[n3_4 - i - 1]; // b-a', c+d'
for ( ; i < n ; ++i) buffer[i] = -temp[i - n3_4]; // c'+d
}
#endif
#ifndef LIBVORBIS_MDCT
#define LIBVORBIS_MDCT 0
#endif
#if LIBVORBIS_MDCT
// directly call the vorbis MDCT using an interface documented
// by Jeff Roberts... useful for performance comparison
typedef struct
{
int n;
int log2n;
float *trig;
int *bitrev;
float scale;
} mdct_lookup;
extern void mdct_init(mdct_lookup *lookup, int n);
extern void mdct_clear(mdct_lookup *l);
extern void mdct_backward(mdct_lookup *init, float *in, float *out);
mdct_lookup M1,M2;
void inverse_mdct(float *buffer, int n, vorb *f, int blocktype)
{
mdct_lookup *M;
if (M1.n == n) M = &M1;
else if (M2.n == n) M = &M2;
else if (M1.n == 0) { mdct_init(&M1, n); M = &M1; }
else {
if (M2.n) __asm int 3;
mdct_init(&M2, n);
M = &M2;
}
mdct_backward(M, buffer, buffer);
}
#endif
// the following were split out into separate functions while optimizing;
// they could be pushed back up but eh. __forceinline showed no change;
// they're probably already being inlined.
static void imdct_step3_iter0_loop(int n, float *e, int i_off, int k_off, float *A)
{
float *ee0 = e + i_off;
float *ee2 = ee0 + k_off;
int i;
assert((n & 3) == 0);
for (i=(n>>2); i > 0; --i) {
float k00_20, k01_21;
k00_20 = ee0[ 0] - ee2[ 0];
k01_21 = ee0[-1] - ee2[-1];
ee0[ 0] += ee2[ 0];//ee0[ 0] = ee0[ 0] + ee2[ 0];
ee0[-1] += ee2[-1];//ee0[-1] = ee0[-1] + ee2[-1];
ee2[ 0] = k00_20 * A[0] - k01_21 * A[1];
ee2[-1] = k01_21 * A[0] + k00_20 * A[1];
A += 8;
k00_20 = ee0[-2] - ee2[-2];
k01_21 = ee0[-3] - ee2[-3];
ee0[-2] += ee2[-2];//ee0[-2] = ee0[-2] + ee2[-2];
ee0[-3] += ee2[-3];//ee0[-3] = ee0[-3] + ee2[-3];
ee2[-2] = k00_20 * A[0] - k01_21 * A[1];
ee2[-3] = k01_21 * A[0] + k00_20 * A[1];
A += 8;
k00_20 = ee0[-4] - ee2[-4];
k01_21 = ee0[-5] - ee2[-5];
ee0[-4] += ee2[-4];//ee0[-4] = ee0[-4] + ee2[-4];
ee0[-5] += ee2[-5];//ee0[-5] = ee0[-5] + ee2[-5];
ee2[-4] = k00_20 * A[0] - k01_21 * A[1];
ee2[-5] = k01_21 * A[0] + k00_20 * A[1];
A += 8;
k00_20 = ee0[-6] - ee2[-6];
k01_21 = ee0[-7] - ee2[-7];
ee0[-6] += ee2[-6];//ee0[-6] = ee0[-6] + ee2[-6];
ee0[-7] += ee2[-7];//ee0[-7] = ee0[-7] + ee2[-7];
ee2[-6] = k00_20 * A[0] - k01_21 * A[1];
ee2[-7] = k01_21 * A[0] + k00_20 * A[1];
A += 8;
ee0 -= 8;
ee2 -= 8;
}
}
static void imdct_step3_inner_r_loop(int lim, float *e, int d0, int k_off, float *A, int k1)
{
int i;
float k00_20, k01_21;
float *e0 = e + d0;
float *e2 = e0 + k_off;
for (i=lim >> 2; i > 0; --i) {
k00_20 = e0[-0] - e2[-0];
k01_21 = e0[-1] - e2[-1];
e0[-0] += e2[-0];//e0[-0] = e0[-0] + e2[-0];
e0[-1] += e2[-1];//e0[-1] = e0[-1] + e2[-1];
e2[-0] = (k00_20)*A[0] - (k01_21) * A[1];
e2[-1] = (k01_21)*A[0] + (k00_20) * A[1];
A += k1;
k00_20 = e0[-2] - e2[-2];
k01_21 = e0[-3] - e2[-3];
e0[-2] += e2[-2];//e0[-2] = e0[-2] + e2[-2];
e0[-3] += e2[-3];//e0[-3] = e0[-3] + e2[-3];
e2[-2] = (k00_20)*A[0] - (k01_21) * A[1];
e2[-3] = (k01_21)*A[0] + (k00_20) * A[1];
A += k1;
k00_20 = e0[-4] - e2[-4];
k01_21 = e0[-5] - e2[-5];
e0[-4] += e2[-4];//e0[-4] = e0[-4] + e2[-4];
e0[-5] += e2[-5];//e0[-5] = e0[-5] + e2[-5];
e2[-4] = (k00_20)*A[0] - (k01_21) * A[1];
e2[-5] = (k01_21)*A[0] + (k00_20) * A[1];
A += k1;
k00_20 = e0[-6] - e2[-6];
k01_21 = e0[-7] - e2[-7];
e0[-6] += e2[-6];//e0[-6] = e0[-6] + e2[-6];
e0[-7] += e2[-7];//e0[-7] = e0[-7] + e2[-7];
e2[-6] = (k00_20)*A[0] - (k01_21) * A[1];
e2[-7] = (k01_21)*A[0] + (k00_20) * A[1];
e0 -= 8;
e2 -= 8;
A += k1;
}
}
static void imdct_step3_inner_s_loop(int n, float *e, int i_off, int k_off, float *A, int a_off, int k0)
{
int i;
float A0 = A[0];
float A1 = A[0+1];
float A2 = A[0+a_off];
float A3 = A[0+a_off+1];
float A4 = A[0+a_off*2+0];
float A5 = A[0+a_off*2+1];
float A6 = A[0+a_off*3+0];
float A7 = A[0+a_off*3+1];
float k00,k11;
float *ee0 = e +i_off;
float *ee2 = ee0+k_off;
for (i=n; i > 0; --i) {
k00 = ee0[ 0] - ee2[ 0];
k11 = ee0[-1] - ee2[-1];
ee0[ 0] = ee0[ 0] + ee2[ 0];
ee0[-1] = ee0[-1] + ee2[-1];
ee2[ 0] = (k00) * A0 - (k11) * A1;
ee2[-1] = (k11) * A0 + (k00) * A1;
k00 = ee0[-2] - ee2[-2];
k11 = ee0[-3] - ee2[-3];
ee0[-2] = ee0[-2] + ee2[-2];
ee0[-3] = ee0[-3] + ee2[-3];
ee2[-2] = (k00) * A2 - (k11) * A3;
ee2[-3] = (k11) * A2 + (k00) * A3;
k00 = ee0[-4] - ee2[-4];
k11 = ee0[-5] - ee2[-5];
ee0[-4] = ee0[-4] + ee2[-4];
ee0[-5] = ee0[-5] + ee2[-5];
ee2[-4] = (k00) * A4 - (k11) * A5;
ee2[-5] = (k11) * A4 + (k00) * A5;
k00 = ee0[-6] - ee2[-6];
k11 = ee0[-7] - ee2[-7];
ee0[-6] = ee0[-6] + ee2[-6];
ee0[-7] = ee0[-7] + ee2[-7];
ee2[-6] = (k00) * A6 - (k11) * A7;
ee2[-7] = (k11) * A6 + (k00) * A7;
ee0 -= k0;
ee2 -= k0;
}
}
static __forceinline void iter_54(float *z)
{
float k00,k11,k22,k33;
float y0,y1,y2,y3;
k00 = z[ 0] - z[-4];
y0 = z[ 0] + z[-4];
y2 = z[-2] + z[-6];
k22 = z[-2] - z[-6];
z[-0] = y0 + y2; // z0 + z4 + z2 + z6
z[-2] = y0 - y2; // z0 + z4 - z2 - z6
// done with y0,y2
k33 = z[-3] - z[-7];
z[-4] = k00 + k33; // z0 - z4 + z3 - z7
z[-6] = k00 - k33; // z0 - z4 - z3 + z7
// done with k33
k11 = z[-1] - z[-5];
y1 = z[-1] + z[-5];
y3 = z[-3] + z[-7];
z[-1] = y1 + y3; // z1 + z5 + z3 + z7
z[-3] = y1 - y3; // z1 + z5 - z3 - z7
z[-5] = k11 - k22; // z1 - z5 + z2 - z6
z[-7] = k11 + k22; // z1 - z5 - z2 + z6
}
static void imdct_step3_inner_s_loop_ld654(int n, float *e, int i_off, float *A, int base_n)
{
int a_off = base_n >> 3;
float A2 = A[0+a_off];
float *z = e + i_off;
float *base = z - 16 * n;
while (z > base) {
float k00,k11;
k00 = z[-0] - z[-8];
k11 = z[-1] - z[-9];
z[-0] = z[-0] + z[-8];
z[-1] = z[-1] + z[-9];
z[-8] = k00;
z[-9] = k11 ;
k00 = z[ -2] - z[-10];
k11 = z[ -3] - z[-11];
z[ -2] = z[ -2] + z[-10];
z[ -3] = z[ -3] + z[-11];
z[-10] = (k00+k11) * A2;
z[-11] = (k11-k00) * A2;
k00 = z[-12] - z[ -4]; // reverse to avoid a unary negation
k11 = z[ -5] - z[-13];
z[ -4] = z[ -4] + z[-12];
z[ -5] = z[ -5] + z[-13];
z[-12] = k11;
z[-13] = k00;
k00 = z[-14] - z[ -6]; // reverse to avoid a unary negation
k11 = z[ -7] - z[-15];
z[ -6] = z[ -6] + z[-14];
z[ -7] = z[ -7] + z[-15];
z[-14] = (k00+k11) * A2;
z[-15] = (k00-k11) * A2;
iter_54(z);
iter_54(z-8);
z -= 16;
}
}
static void inverse_mdct(float *buffer, int n, vorb *f, int blocktype)
{
int n2 = n >> 1, n4 = n >> 2, n8 = n >> 3, l;
int ld;
// @OPTIMIZE: reduce register pressure by using fewer variables?
int save_point = temp_alloc_save(f);
float *buf2 = (float *) temp_alloc(f, n2 * sizeof(*buf2));
float *u=NULL,*v=NULL;
// twiddle factors
float *A = f->A[blocktype];
// IMDCT algorithm from "The use of multirate filter banks for coding of high quality digital audio"
// See notes about bugs in that paper in less-optimal implementation 'inverse_mdct_old' after this function.
// kernel from paper
// merged:
// copy and reflect spectral data
// step 0
// note that it turns out that the items added together during
// this step are, in fact, being added to themselves (as reflected
// by step 0). inexplicable inefficiency! this became obvious
// once I combined the passes.
// so there's a missing 'times 2' here (for adding X to itself).
// this propogates through linearly to the end, where the numbers
// are 1/2 too small, and need to be compensated for.
{
float *d,*e, *AA, *e_stop;
d = &buf2[n2-2];
AA = A;
e = &buffer[0];
e_stop = &buffer[n2];
while (e != e_stop) {
d[1] = (e[0] * AA[0] - e[2]*AA[1]);
d[0] = (e[0] * AA[1] + e[2]*AA[0]);
d -= 2;
AA += 2;
e += 4;
}
e = &buffer[n2-3];
while (d >= buf2) {
d[1] = (-e[2] * AA[0] - -e[0]*AA[1]);
d[0] = (-e[2] * AA[1] + -e[0]*AA[0]);
d -= 2;
AA += 2;
e -= 4;
}
}
// now we use symbolic names for these, so that we can
// possibly swap their meaning as we change which operations
// are in place
u = buffer;
v = buf2;
// step 2 (paper output is w, now u)
// this could be in place, but the data ends up in the wrong
// place... _somebody_'s got to swap it, so this is nominated
{
float *AA = &A[n2-8];
float *d0,*d1, *e0, *e1;
e0 = &v[n4];
e1 = &v[0];
d0 = &u[n4];
d1 = &u[0];
while (AA >= A) {
float v40_20, v41_21;
v41_21 = e0[1] - e1[1];
v40_20 = e0[0] - e1[0];
d0[1] = e0[1] + e1[1];
d0[0] = e0[0] + e1[0];
d1[1] = v41_21*AA[4] - v40_20*AA[5];
d1[0] = v40_20*AA[4] + v41_21*AA[5];
v41_21 = e0[3] - e1[3];
v40_20 = e0[2] - e1[2];
d0[3] = e0[3] + e1[3];
d0[2] = e0[2] + e1[2];
d1[3] = v41_21*AA[0] - v40_20*AA[1];
d1[2] = v40_20*AA[0] + v41_21*AA[1];
AA -= 8;
d0 += 4;
d1 += 4;
e0 += 4;
e1 += 4;
}
}
// step 3
ld = ilog(n) - 1; // ilog is off-by-one from normal definitions
// optimized step 3:
// the original step3 loop can be nested r inside s or s inside r;
// it's written originally as s inside r, but this is dumb when r
// iterates many times, and s few. So I have two copies of it and
// switch between them halfway.
// this is iteration 0 of step 3
imdct_step3_iter0_loop(n >> 4, u, n2-1-n4*0, -(n >> 3), A);
imdct_step3_iter0_loop(n >> 4, u, n2-1-n4*1, -(n >> 3), A);
// this is iteration 1 of step 3
imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*0, -(n >> 4), A, 16);
imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*1, -(n >> 4), A, 16);
imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*2, -(n >> 4), A, 16);
imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*3, -(n >> 4), A, 16);
l=2;
for (; l < (ld-3)>>1; ++l) {
int k0 = n >> (l+2), k0_2 = k0>>1;
int lim = 1 << (l+1);
int i;
for (i=0; i < lim; ++i)
imdct_step3_inner_r_loop(n >> (l+4), u, n2-1 - k0*i, -k0_2, A, 1 << (l+3));
}
for (; l < ld-6; ++l) {
int k0 = n >> (l+2), k1 = 1 << (l+3), k0_2 = k0>>1;
int rlim = n >> (l+6), r;
int lim = 1 << (l+1);
int i_off;
float *A0 = A;
i_off = n2-1;
for (r=rlim; r > 0; --r) {
imdct_step3_inner_s_loop(lim, u, i_off, -k0_2, A0, k1, k0);
A0 += k1*4;
i_off -= 8;
}
}
// iterations with count:
// ld-6,-5,-4 all interleaved together
// the big win comes from getting rid of needless flops
// due to the constants on pass 5 & 4 being all 1 and 0;
// combining them to be simultaneous to improve cache made little difference
imdct_step3_inner_s_loop_ld654(n >> 5, u, n2-1, A, n);
// output is u
// step 4, 5, and 6
// cannot be in-place because of step 5
{
uint16 *bitrev = f->bit_reverse[blocktype];
// weirdly, I'd have thought reading sequentially and writing
// erratically would have been better than vice-versa, but in
// fact that's not what my testing showed. (That is, with
// j = bitreverse(i), do you read i and write j, or read j and write i.)
float *d0 = &v[n4-4];
float *d1 = &v[n2-4];
while (d0 >= v) {
int k4;
k4 = bitrev[0];
d1[3] = u[k4+0];
d1[2] = u[k4+1];
d0[3] = u[k4+2];
d0[2] = u[k4+3];
k4 = bitrev[1];
d1[1] = u[k4+0];
d1[0] = u[k4+1];
d0[1] = u[k4+2];
d0[0] = u[k4+3];
d0 -= 4;
d1 -= 4;
bitrev += 2;
}
}
// (paper output is u, now v)
// data must be in buf2
assert(v == buf2);
// step 7 (paper output is v, now v)
// this is now in place
{
float *C = f->C[blocktype];
float *d, *e;
d = v;
e = v + n2 - 4;
while (d < e) {
float a02,a11,b0,b1,b2,b3;
a02 = d[0] - e[2];
a11 = d[1] + e[3];
b0 = C[1]*a02 + C[0]*a11;
b1 = C[1]*a11 - C[0]*a02;
b2 = d[0] + e[ 2];
b3 = d[1] - e[ 3];
d[0] = b2 + b0;
d[1] = b3 + b1;
e[2] = b2 - b0;
e[3] = b1 - b3;
a02 = d[2] - e[0];
a11 = d[3] + e[1];
b0 = C[3]*a02 + C[2]*a11;
b1 = C[3]*a11 - C[2]*a02;
b2 = d[2] + e[ 0];
b3 = d[3] - e[ 1];
d[2] = b2 + b0;
d[3] = b3 + b1;
e[0] = b2 - b0;
e[1] = b1 - b3;
C += 4;
d += 4;
e -= 4;
}
}
// data must be in buf2
// step 8+decode (paper output is X, now buffer)
// this generates pairs of data a la 8 and pushes them directly through
// the decode kernel (pushing rather than pulling) to avoid having
// to make another pass later
// this cannot POSSIBLY be in place, so we refer to the buffers directly
{
float *d0,*d1,*d2,*d3;
float *B = f->B[blocktype] + n2 - 8;
float *e = buf2 + n2 - 8;
d0 = &buffer[0];
d1 = &buffer[n2-4];
d2 = &buffer[n2];
d3 = &buffer[n-4];
while (e >= v) {
float p0,p1,p2,p3;
p3 = e[6]*B[7] - e[7]*B[6];
p2 = -e[6]*B[6] - e[7]*B[7];
d0[0] = p3;
d1[3] = - p3;
d2[0] = p2;
d3[3] = p2;
p1 = e[4]*B[5] - e[5]*B[4];
p0 = -e[4]*B[4] - e[5]*B[5];
d0[1] = p1;
d1[2] = - p1;
d2[1] = p0;
d3[2] = p0;
p3 = e[2]*B[3] - e[3]*B[2];
p2 = -e[2]*B[2] - e[3]*B[3];
d0[2] = p3;
d1[1] = - p3;
d2[2] = p2;
d3[1] = p2;
p1 = e[0]*B[1] - e[1]*B[0];
p0 = -e[0]*B[0] - e[1]*B[1];
d0[3] = p1;
d1[0] = - p1;
d2[3] = p0;
d3[0] = p0;
B -= 8;
e -= 8;
d0 += 4;
d2 += 4;
d1 -= 4;
d3 -= 4;
}
}
temp_free(f,buf2);
temp_alloc_restore(f,save_point);
}
#if 0
// this is the original version of the above code, if you want to optimize it from scratch
void inverse_mdct_naive(float *buffer, int n)
{
float s;
float A[1 << 12], B[1 << 12], C[1 << 11];
int i,k,k2,k4, n2 = n >> 1, n4 = n >> 2, n8 = n >> 3, l;
int n3_4 = n - n4, ld;
// how can they claim this only uses N words?!
// oh, because they're only used sparsely, whoops
float u[1 << 13], X[1 << 13], v[1 << 13], w[1 << 13];
// set up twiddle factors
for (k=k2=0; k < n4; ++k,k2+=2) {
A[k2 ] = (float) cos(4*k*M_PI/n);
A[k2+1] = (float) -sin(4*k*M_PI/n);
B[k2 ] = (float) cos((k2+1)*M_PI/n/2);
B[k2+1] = (float) sin((k2+1)*M_PI/n/2);
}
for (k=k2=0; k < n8; ++k,k2+=2) {
C[k2 ] = (float) cos(2*(k2+1)*M_PI/n);
C[k2+1] = (float) -sin(2*(k2+1)*M_PI/n);
}
// IMDCT algorithm from "The use of multirate filter banks for coding of high quality digital audio"
// Note there are bugs in that pseudocode, presumably due to them attempting
// to rename the arrays nicely rather than representing the way their actual
// implementation bounces buffers back and forth. As a result, even in the
// "some formulars corrected" version, a direct implementation fails. These
// are noted below as "paper bug".
// copy and reflect spectral data
for (k=0; k < n2; ++k) u[k] = buffer[k];
for ( ; k < n ; ++k) u[k] = -buffer[n - k - 1];
// kernel from paper
// step 1
for (k=k2=k4=0; k < n4; k+=1, k2+=2, k4+=4) {
v[n-k4-1] = (u[k4] - u[n-k4-1]) * A[k2] - (u[k4+2] - u[n-k4-3])*A[k2+1];
v[n-k4-3] = (u[k4] - u[n-k4-1]) * A[k2+1] + (u[k4+2] - u[n-k4-3])*A[k2];
}
// step 2
for (k=k4=0; k < n8; k+=1, k4+=4) {
w[n2+3+k4] = v[n2+3+k4] + v[k4+3];
w[n2+1+k4] = v[n2+1+k4] + v[k4+1];
w[k4+3] = (v[n2+3+k4] - v[k4+3])*A[n2-4-k4] - (v[n2+1+k4]-v[k4+1])*A[n2-3-k4];
w[k4+1] = (v[n2+1+k4] - v[k4+1])*A[n2-4-k4] + (v[n2+3+k4]-v[k4+3])*A[n2-3-k4];
}
// step 3
ld = ilog(n) - 1; // ilog is off-by-one from normal definitions
for (l=0; l < ld-3; ++l) {
int k0 = n >> (l+2), k1 = 1 << (l+3);
int rlim = n >> (l+4), r4, r;
int s2lim = 1 << (l+2), s2;
for (r=r4=0; r < rlim; r4+=4,++r) {
for (s2=0; s2 < s2lim; s2+=2) {
u[n-1-k0*s2-r4] = w[n-1-k0*s2-r4] + w[n-1-k0*(s2+1)-r4];
u[n-3-k0*s2-r4] = w[n-3-k0*s2-r4] + w[n-3-k0*(s2+1)-r4];
u[n-1-k0*(s2+1)-r4] = (w[n-1-k0*s2-r4] - w[n-1-k0*(s2+1)-r4]) * A[r*k1]
- (w[n-3-k0*s2-r4] - w[n-3-k0*(s2+1)-r4]) * A[r*k1+1];
u[n-3-k0*(s2+1)-r4] = (w[n-3-k0*s2-r4] - w[n-3-k0*(s2+1)-r4]) * A[r*k1]
+ (w[n-1-k0*s2-r4] - w[n-1-k0*(s2+1)-r4]) * A[r*k1+1];
}
}
if (l+1 < ld-3) {
// paper bug: ping-ponging of u&w here is omitted
memcpy(w, u, sizeof(u));
}
}
// step 4
for (i=0; i < n8; ++i) {
int j = bit_reverse(i) >> (32-ld+3);
assert(j < n8);
if (i == j) {
// paper bug: original code probably swapped in place; if copying,
// need to directly copy in this case
int i8 = i << 3;
v[i8+1] = u[i8+1];
v[i8+3] = u[i8+3];
v[i8+5] = u[i8+5];
v[i8+7] = u[i8+7];
} else if (i < j) {
int i8 = i << 3, j8 = j << 3;
v[j8+1] = u[i8+1], v[i8+1] = u[j8 + 1];
v[j8+3] = u[i8+3], v[i8+3] = u[j8 + 3];
v[j8+5] = u[i8+5], v[i8+5] = u[j8 + 5];
v[j8+7] = u[i8+7], v[i8+7] = u[j8 + 7];
}
}
// step 5
for (k=0; k < n2; ++k) {
w[k] = v[k*2+1];
}
// step 6
for (k=k2=k4=0; k < n8; ++k, k2 += 2, k4 += 4) {
u[n-1-k2] = w[k4];
u[n-2-k2] = w[k4+1];
u[n3_4 - 1 - k2] = w[k4+2];
u[n3_4 - 2 - k2] = w[k4+3];
}
// step 7
for (k=k2=0; k < n8; ++k, k2 += 2) {
v[n2 + k2 ] = ( u[n2 + k2] + u[n-2-k2] + C[k2+1]*(u[n2+k2]-u[n-2-k2]) + C[k2]*(u[n2+k2+1]+u[n-2-k2+1]))/2;
v[n-2 - k2] = ( u[n2 + k2] + u[n-2-k2] - C[k2+1]*(u[n2+k2]-u[n-2-k2]) - C[k2]*(u[n2+k2+1]+u[n-2-k2+1]))/2;
v[n2+1+ k2] = ( u[n2+1+k2] - u[n-1-k2] + C[k2+1]*(u[n2+1+k2]+u[n-1-k2]) - C[k2]*(u[n2+k2]-u[n-2-k2]))/2;
v[n-1 - k2] = (-u[n2+1+k2] + u[n-1-k2] + C[k2+1]*(u[n2+1+k2]+u[n-1-k2]) - C[k2]*(u[n2+k2]-u[n-2-k2]))/2;
}
// step 8
for (k=k2=0; k < n4; ++k,k2 += 2) {
X[k] = v[k2+n2]*B[k2 ] + v[k2+1+n2]*B[k2+1];
X[n2-1-k] = v[k2+n2]*B[k2+1] - v[k2+1+n2]*B[k2 ];
}
// decode kernel to output
// determined the following value experimentally
// (by first figuring out what made inverse_mdct_slow work); then matching that here
// (probably vorbis encoder premultiplies by n or n/2, to save it on the decoder?)
s = 0.5; // theoretically would be n4
// [[[ note! the s value of 0.5 is compensated for by the B[] in the current code,
// so it needs to use the "old" B values to behave correctly, or else
// set s to 1.0 ]]]
for (i=0; i < n4 ; ++i) buffer[i] = s * X[i+n4];
for ( ; i < n3_4; ++i) buffer[i] = -s * X[n3_4 - i - 1];
for ( ; i < n ; ++i) buffer[i] = -s * X[i - n3_4];
}
#endif
static float *get_window(vorb *f, int len)
{
len <<= 1;
if (len == f->blocksize_0) return f->window[0];
if (len == f->blocksize_1) return f->window[1];
assert(0);
return NULL;
}
#ifndef STB_VORBIS_NO_DEFER_FLOOR
typedef int16 YTYPE;
#else
typedef int YTYPE;
#endif
static int do_floor(vorb *f, Mapping *map, int i, int n, float *target, YTYPE *finalY, uint8 *step2_flag)
{
int n2 = n >> 1;
int s = map->chan[i].mux, floor;
floor = map->submap_floor[s];
if (f->floor_types[floor] == 0) {
return error(f, VORBIS_invalid_stream);
} else {
Floor1 *g = &f->floor_config[floor].floor1;
int j,q;
int lx = 0, ly = finalY[0] * g->floor1_multiplier;
for (q=1; q < g->values; ++q) {
j = g->sorted_order[q];
#ifndef STB_VORBIS_NO_DEFER_FLOOR
if (finalY[j] >= 0)
#else
if (step2_flag[j])
#endif
{
int hy = finalY[j] * g->floor1_multiplier;
int hx = g->Xlist[j];
if (lx != hx)
draw_line(target, lx,ly, hx,hy, n2);
CHECK(f);
lx = hx, ly = hy;
}
}
if (lx < n2) {
// optimization of: draw_line(target, lx,ly, n,ly, n2);
for (j=lx; j < n2; ++j)
LINE_OP(target[j], inverse_db_table[ly]);
CHECK(f);
}
}
return TRUE;
}
// The meaning of "left" and "right"
//
// For a given frame:
// we compute samples from 0..n
// window_center is n/2
// we'll window and mix the samples from left_start to left_end with data from the previous frame
// all of the samples from left_end to right_start can be output without mixing; however,
// this interval is 0-length except when transitioning between short and long frames
// all of the samples from right_start to right_end need to be mixed with the next frame,
// which we don't have, so those get saved in a buffer
// frame N's right_end-right_start, the number of samples to mix with the next frame,
// has to be the same as frame N+1's left_end-left_start (which they are by
// construction)
static int vorbis_decode_initial(vorb *f, int *p_left_start, int *p_left_end, int *p_right_start, int *p_right_end, int *mode)
{
Mode *m;
int i, n, prev, next, window_center;
f->channel_buffer_start = f->channel_buffer_end = 0;
retry:
if (f->eof) return FALSE;
if (!maybe_start_packet(f))
return FALSE;
// check packet type
if (get_bits(f,1) != 0) {
if (IS_PUSH_MODE(f))
return error(f,VORBIS_bad_packet_type);
while (EOP != get8_packet(f));
goto retry;
}
if (f->alloc.alloc_buffer)
assert(f->alloc.alloc_buffer_length_in_bytes == f->temp_offset);
i = get_bits(f, ilog(f->mode_count-1));
if (i == EOP) return FALSE;
if (i >= f->mode_count) return FALSE;
*mode = i;
m = f->mode_config + i;
if (m->blockflag) {
n = f->blocksize_1;
prev = get_bits(f,1);
next = get_bits(f,1);
} else {
prev = next = 0;
n = f->blocksize_0;
}
// WINDOWING
window_center = n >> 1;
if (m->blockflag && !prev) {
*p_left_start = (n - f->blocksize_0) >> 2;
*p_left_end = (n + f->blocksize_0) >> 2;
} else {
*p_left_start = 0;
*p_left_end = window_center;
}
if (m->blockflag && !next) {
*p_right_start = (n*3 - f->blocksize_0) >> 2;
*p_right_end = (n*3 + f->blocksize_0) >> 2;
} else {
*p_right_start = window_center;
*p_right_end = n;
}
return TRUE;
}
static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start, int left_end, int right_start, int right_end, int *p_left)
{
Mapping *map;
int i,j,k,n,n2;
int zero_channel[256];
int really_zero_channel[256];
// WINDOWING
n = f->blocksize[m->blockflag];
map = &f->mapping[m->mapping];
// FLOORS
n2 = n >> 1;
CHECK(f);
for (i=0; i < f->channels; ++i) {
int s = map->chan[i].mux, floor;
zero_channel[i] = FALSE;
floor = map->submap_floor[s];
if (f->floor_types[floor] == 0) {
return error(f, VORBIS_invalid_stream);
} else {
Floor1 *g = &f->floor_config[floor].floor1;
if (get_bits(f, 1)) {
short *finalY;
uint8 step2_flag[256];
static int range_list[4] = { 256, 128, 86, 64 };
int range = range_list[g->floor1_multiplier-1];
int offset = 2;
finalY = f->finalY[i];
finalY[0] = get_bits(f, ilog(range)-1);
finalY[1] = get_bits(f, ilog(range)-1);
for (j=0; j < g->partitions; ++j) {
int pclass = g->partition_class_list[j];
int cdim = g->class_dimensions[pclass];
int cbits = g->class_subclasses[pclass];
int csub = (1 << cbits)-1;
int cval = 0;
if (cbits) {
Codebook *c = f->codebooks + g->class_masterbooks[pclass];
DECODE(cval,f,c);
}
for (k=0; k < cdim; ++k) {
int book = g->subclass_books[pclass][cval & csub];
cval = cval >> cbits;
if (book >= 0) {
int temp;
Codebook *c = f->codebooks + book;
DECODE(temp,f,c);
finalY[offset++] = temp;
} else
finalY[offset++] = 0;
}
}
if (f->valid_bits == INVALID_BITS) goto error; // behavior according to spec
step2_flag[0] = step2_flag[1] = 1;
for (j=2; j < g->values; ++j) {
int low, high, pred, highroom, lowroom, room, val;
low = g->neighbors[j][0];
high = g->neighbors[j][1];
//neighbors(g->Xlist, j, &low, &high);
pred = predict_point(g->Xlist[j], g->Xlist[low], g->Xlist[high], finalY[low], finalY[high]);
val = finalY[j];
highroom = range - pred;
lowroom = pred;
if (highroom < lowroom)
room = highroom * 2;
else
room = lowroom * 2;
if (val) {
step2_flag[low] = step2_flag[high] = 1;
step2_flag[j] = 1;
if (val >= room)
if (highroom > lowroom)
finalY[j] = val - lowroom + pred;
else
finalY[j] = pred - val + highroom - 1;
else
if (val & 1)
finalY[j] = pred - ((val+1)>>1);
else
finalY[j] = pred + (val>>1);
} else {
step2_flag[j] = 0;
finalY[j] = pred;
}
}
#ifdef STB_VORBIS_NO_DEFER_FLOOR
do_floor(f, map, i, n, f->floor_buffers[i], finalY, step2_flag);
#else
// defer final floor computation until _after_ residue
for (j=0; j < g->values; ++j) {
if (!step2_flag[j])
finalY[j] = -1;
}
#endif
} else {
error:
zero_channel[i] = TRUE;
}
// So we just defer everything else to later
// at this point we've decoded the floor into buffer
}
}
CHECK(f);
// at this point we've decoded all floors
if (f->alloc.alloc_buffer)
assert(f->alloc.alloc_buffer_length_in_bytes == f->temp_offset);
// re-enable coupled channels if necessary
memcpy(really_zero_channel, zero_channel, sizeof(really_zero_channel[0]) * f->channels);
for (i=0; i < map->coupling_steps; ++i)
if (!zero_channel[map->chan[i].magnitude] || !zero_channel[map->chan[i].angle]) {
zero_channel[map->chan[i].magnitude] = zero_channel[map->chan[i].angle] = FALSE;
}
CHECK(f);
// RESIDUE DECODE
for (i=0; i < map->submaps; ++i) {
float *residue_buffers[STB_VORBIS_MAX_CHANNELS];
int r;
uint8 do_not_decode[256];
int ch = 0;
for (j=0; j < f->channels; ++j) {
if (map->chan[j].mux == i) {
if (zero_channel[j]) {
do_not_decode[ch] = TRUE;
residue_buffers[ch] = NULL;
} else {
do_not_decode[ch] = FALSE;
residue_buffers[ch] = f->channel_buffers[j];
}
++ch;
}
}
r = map->submap_residue[i];
decode_residue(f, residue_buffers, ch, n2, r, do_not_decode);
}
if (f->alloc.alloc_buffer)
assert(f->alloc.alloc_buffer_length_in_bytes == f->temp_offset);
CHECK(f);
// INVERSE COUPLING
for (i = map->coupling_steps-1; i >= 0; --i) {
int n2 = n >> 1;
float *m = f->channel_buffers[map->chan[i].magnitude];
float *a = f->channel_buffers[map->chan[i].angle ];
for (j=0; j < n2; ++j) {
float a2,m2;
if (m[j] > 0)
if (a[j] > 0)
m2 = m[j], a2 = m[j] - a[j];
else
a2 = m[j], m2 = m[j] + a[j];
else
if (a[j] > 0)
m2 = m[j], a2 = m[j] + a[j];
else
a2 = m[j], m2 = m[j] - a[j];
m[j] = m2;
a[j] = a2;
}
}
CHECK(f);
// finish decoding the floors
#ifndef STB_VORBIS_NO_DEFER_FLOOR
for (i=0; i < f->channels; ++i) {
if (really_zero_channel[i]) {
memset(f->channel_buffers[i], 0, sizeof(*f->channel_buffers[i]) * n2);
} else {
do_floor(f, map, i, n, f->channel_buffers[i], f->finalY[i], NULL);
}
}
#else
for (i=0; i < f->channels; ++i) {
if (really_zero_channel[i]) {
memset(f->channel_buffers[i], 0, sizeof(*f->channel_buffers[i]) * n2);
} else {
for (j=0; j < n2; ++j)
f->channel_buffers[i][j] *= f->floor_buffers[i][j];
}
}
#endif
// INVERSE MDCT
CHECK(f);
for (i=0; i < f->channels; ++i)
inverse_mdct(f->channel_buffers[i], n, f, m->blockflag);
CHECK(f);
// this shouldn't be necessary, unless we exited on an error
// and want to flush to get to the next packet
flush_packet(f);
if (f->first_decode) {
// assume we start so first non-discarded sample is sample 0
// this isn't to spec, but spec would require us to read ahead
// and decode the size of all current frames--could be done,
// but presumably it's not a commonly used feature
f->current_loc = -n2; // start of first frame is positioned for discard
// we might have to discard samples "from" the next frame too,
// if we're lapping a large block then a small at the start?
f->discard_samples_deferred = n - right_end;
f->current_loc_valid = TRUE;
f->first_decode = FALSE;
} else if (f->discard_samples_deferred) {
if (f->discard_samples_deferred >= right_start - left_start) {
f->discard_samples_deferred -= (right_start - left_start);
left_start = right_start;
*p_left = left_start;
} else {
left_start += f->discard_samples_deferred;
*p_left = left_start;
f->discard_samples_deferred = 0;
}
} else if (f->previous_length == 0 && f->current_loc_valid) {
// we're recovering from a seek... that means we're going to discard
// the samples from this packet even though we know our position from
// the last page header, so we need to update the position based on
// the discarded samples here
// but wait, the code below is going to add this in itself even
// on a discard, so we don't need to do it here...
}
// check if we have ogg information about the sample # for this packet
if (f->last_seg_which == f->end_seg_with_known_loc) {
// if we have a valid current loc, and this is final:
if (f->current_loc_valid && (f->page_flag & PAGEFLAG_last_page)) {
uint32 current_end = f->known_loc_for_packet - (n-right_end);
// then let's infer the size of the (probably) short final frame
if (current_end < f->current_loc + (right_end-left_start)) {
if (current_end < f->current_loc) {
// negative truncation, that's impossible!
*len = 0;
} else {
*len = current_end - f->current_loc;
}
*len += left_start;
if (*len > right_end) *len = right_end; // this should never happen
f->current_loc += *len;
return TRUE;
}
}
// otherwise, just set our sample loc
// guess that the ogg granule pos refers to the _middle_ of the
// last frame?
// set f->current_loc to the position of left_start
f->current_loc = f->known_loc_for_packet - (n2-left_start);
f->current_loc_valid = TRUE;
}
if (f->current_loc_valid)
f->current_loc += (right_start - left_start);
if (f->alloc.alloc_buffer)
assert(f->alloc.alloc_buffer_length_in_bytes == f->temp_offset);
*len = right_end; // ignore samples after the window goes to 0
CHECK(f);
return TRUE;
}
static int vorbis_decode_packet(vorb *f, int *len, int *p_left, int *p_right)
{
int mode, left_end, right_end;
if (!vorbis_decode_initial(f, p_left, &left_end, p_right, &right_end, &mode)) return 0;
return vorbis_decode_packet_rest(f, len, f->mode_config + mode, *p_left, left_end, *p_right, right_end, p_left);
}
static int vorbis_finish_frame(stb_vorbis *f, int len, int left, int right)
{
int prev,i,j;
// we use right&left (the start of the right- and left-window sin()-regions)
// to determine how much to return, rather than inferring from the rules
// (same result, clearer code); 'left' indicates where our sin() window
// starts, therefore where the previous window's right edge starts, and
// therefore where to start mixing from the previous buffer. 'right'
// indicates where our sin() ending-window starts, therefore that's where
// we start saving, and where our returned-data ends.
// mixin from previous window
if (f->previous_length) {
int i,j, n = f->previous_length;
float *w = get_window(f, n);
for (i=0; i < f->channels; ++i) {
for (j=0; j < n; ++j)
f->channel_buffers[i][left+j] =
f->channel_buffers[i][left+j]*w[ j] +
f->previous_window[i][ j]*w[n-1-j];
}
}
prev = f->previous_length;
// last half of this data becomes previous window
f->previous_length = len - right;
// @OPTIMIZE: could avoid this copy by double-buffering the
// output (flipping previous_window with channel_buffers), but
// then previous_window would have to be 2x as large, and
// channel_buffers couldn't be temp mem (although they're NOT
// currently temp mem, they could be (unless we want to level
// performance by spreading out the computation))
for (i=0; i < f->channels; ++i)
for (j=0; right+j < len; ++j)
f->previous_window[i][j] = f->channel_buffers[i][right+j];
if (!prev)
// there was no previous packet, so this data isn't valid...
// this isn't entirely true, only the would-have-overlapped data
// isn't valid, but this seems to be what the spec requires
return 0;
// truncate a short frame
if (len < right) right = len;
f->samples_output += right-left;
return right - left;
}
static int vorbis_pump_first_frame(stb_vorbis *f)
{
int len, right, left, res;
res = vorbis_decode_packet(f, &len, &left, &right);
if (res)
vorbis_finish_frame(f, len, left, right);
return res;
}
#ifndef STB_VORBIS_NO_PUSHDATA_API
static int is_whole_packet_present(stb_vorbis *f, int end_page)
{
// make sure that we have the packet available before continuing...
// this requires a full ogg parse, but we know we can fetch from f->stream
// instead of coding this out explicitly, we could save the current read state,
// read the next packet with get8() until end-of-packet, check f->eof, then
// reset the state? but that would be slower, esp. since we'd have over 256 bytes
// of state to restore (primarily the page segment table)
int s = f->next_seg, first = TRUE;
uint8 *p = f->stream;
if (s != -1) { // if we're not starting the packet with a 'continue on next page' flag
for (; s < f->segment_count; ++s) {
p += f->segments[s];
if (f->segments[s] < 255) // stop at first short segment
break;
}
// either this continues, or it ends it...
if (end_page)
if (s < f->segment_count-1) return error(f, VORBIS_invalid_stream);
if (s == f->segment_count)
s = -1; // set 'crosses page' flag
if (p > f->stream_end) return error(f, VORBIS_need_more_data);
first = FALSE;
}
for (; s == -1;) {
uint8 *q;
int n;
// check that we have the page header ready
if (p + 26 >= f->stream_end) return error(f, VORBIS_need_more_data);
// validate the page
if (memcmp(p, ogg_page_header, 4)) return error(f, VORBIS_invalid_stream);
if (p[4] != 0) return error(f, VORBIS_invalid_stream);
if (first) { // the first segment must NOT have 'continued_packet', later ones MUST
if (f->previous_length)
if ((p[5] & PAGEFLAG_continued_packet)) return error(f, VORBIS_invalid_stream);
// if no previous length, we're resynching, so we can come in on a continued-packet,
// which we'll just drop
} else {
if (!(p[5] & PAGEFLAG_continued_packet)) return error(f, VORBIS_invalid_stream);
}
n = p[26]; // segment counts
q = p+27; // q points to segment table
p = q + n; // advance past header
// make sure we've read the segment table
if (p > f->stream_end) return error(f, VORBIS_need_more_data);
for (s=0; s < n; ++s) {
p += q[s];
if (q[s] < 255)
break;
}
if (end_page)
if (s < n-1) return error(f, VORBIS_invalid_stream);
if (s == n)
s = -1; // set 'crosses page' flag
if (p > f->stream_end) return error(f, VORBIS_need_more_data);
first = FALSE;
}
return TRUE;
}
#endif // !STB_VORBIS_NO_PUSHDATA_API
static int start_decoder(vorb *f)
{
uint8 header[6], x,y;
int len,i,j,k, max_submaps = 0;
int longest_floorlist=0;
// first page, first packet
if (!start_page(f)) return FALSE;
// validate page flag
if (!(f->page_flag & PAGEFLAG_first_page)) return error(f, VORBIS_invalid_first_page);
if (f->page_flag & PAGEFLAG_last_page) return error(f, VORBIS_invalid_first_page);
if (f->page_flag & PAGEFLAG_continued_packet) return error(f, VORBIS_invalid_first_page);
// check for expected packet length
if (f->segment_count != 1) return error(f, VORBIS_invalid_first_page);
if (f->segments[0] != 30) return error(f, VORBIS_invalid_first_page);
// read packet
// check packet header
if (get8(f) != VORBIS_packet_id) return error(f, VORBIS_invalid_first_page);
if (!getn(f, header, 6)) return error(f, VORBIS_unexpected_eof);
if (!vorbis_validate(header)) return error(f, VORBIS_invalid_first_page);
// vorbis_version
if (get32(f) != 0) return error(f, VORBIS_invalid_first_page);
f->channels = get8(f); if (!f->channels) return error(f, VORBIS_invalid_first_page);
if (f->channels > STB_VORBIS_MAX_CHANNELS) return error(f, VORBIS_too_many_channels);
f->sample_rate = get32(f); if (!f->sample_rate) return error(f, VORBIS_invalid_first_page);
get32(f); // bitrate_maximum
get32(f); // bitrate_nominal
get32(f); // bitrate_minimum
x = get8(f);
{
int log0,log1;
log0 = x & 15;
log1 = x >> 4;
f->blocksize_0 = 1 << log0;
f->blocksize_1 = 1 << log1;
if (log0 < 6 || log0 > 13) return error(f, VORBIS_invalid_setup);
if (log1 < 6 || log1 > 13) return error(f, VORBIS_invalid_setup);
if (log0 > log1) return error(f, VORBIS_invalid_setup);
}
// framing_flag
x = get8(f);
if (!(x & 1)) return error(f, VORBIS_invalid_first_page);
// second packet!
if (!start_page(f)) return FALSE;
if (!start_packet(f)) return FALSE;
do {
len = next_segment(f);
skip(f, len);
f->bytes_in_seg = 0;
} while (len);
// third packet!
if (!start_packet(f)) return FALSE;
#ifndef STB_VORBIS_NO_PUSHDATA_API
if (IS_PUSH_MODE(f)) {
if (!is_whole_packet_present(f, TRUE)) {
// convert error in ogg header to write type
if (f->error == VORBIS_invalid_stream)
f->error = VORBIS_invalid_setup;
return FALSE;
}
}
#endif
crc32_init(); // always init it, to avoid multithread race conditions
if (get8_packet(f) != VORBIS_packet_setup) return error(f, VORBIS_invalid_setup);
for (i=0; i < 6; ++i) header[i] = get8_packet(f);
if (!vorbis_validate(header)) return error(f, VORBIS_invalid_setup);
// codebooks
f->codebook_count = get_bits(f,8) + 1;
f->codebooks = (Codebook *) setup_malloc(f, sizeof(*f->codebooks) * f->codebook_count);
if (f->codebooks == NULL) return error(f, VORBIS_outofmem);
memset(f->codebooks, 0, sizeof(*f->codebooks) * f->codebook_count);
for (i=0; i < f->codebook_count; ++i) {
uint32 *values;
int ordered, sorted_count;
int total=0;
uint8 *lengths;
Codebook *c = f->codebooks+i;
CHECK(f);
x = get_bits(f, 8); if (x != 0x42) return error(f, VORBIS_invalid_setup);
x = get_bits(f, 8); if (x != 0x43) return error(f, VORBIS_invalid_setup);
x = get_bits(f, 8); if (x != 0x56) return error(f, VORBIS_invalid_setup);
x = get_bits(f, 8);
c->dimensions = (get_bits(f, 8)<<8) + x;
x = get_bits(f, 8);
y = get_bits(f, 8);
c->entries = (get_bits(f, 8)<<16) + (y<<8) + x;
ordered = get_bits(f,1);
c->sparse = ordered ? 0 : get_bits(f,1);
if (c->dimensions == 0 && c->entries != 0) return error(f, VORBIS_invalid_setup);
if (c->sparse)
lengths = (uint8 *) setup_temp_malloc(f, c->entries);
else
lengths = c->codeword_lengths = (uint8 *) setup_malloc(f, c->entries);
if (!lengths) return error(f, VORBIS_outofmem);
if (ordered) {
int current_entry = 0;
int current_length = get_bits(f,5) + 1;
while (current_entry < c->entries) {
int limit = c->entries - current_entry;
int n = get_bits(f, ilog(limit));
if (current_entry + n > (int) c->entries) { return error(f, VORBIS_invalid_setup); }
memset(lengths + current_entry, current_length, n);
current_entry += n;
++current_length;
}
} else {
for (j=0; j < c->entries; ++j) {
int present = c->sparse ? get_bits(f,1) : 1;
if (present) {
lengths[j] = get_bits(f, 5) + 1;
++total;
if (lengths[j] == 32)
return error(f, VORBIS_invalid_setup);
} else {
lengths[j] = NO_CODE;
}
}
}
if (c->sparse && total >= c->entries >> 2) {
// convert sparse items to non-sparse!
if (c->entries > (int) f->setup_temp_memory_required)
f->setup_temp_memory_required = c->entries;
c->codeword_lengths = (uint8 *) setup_malloc(f, c->entries);
if (c->codeword_lengths == NULL) return error(f, VORBIS_outofmem);
memcpy(c->codeword_lengths, lengths, c->entries);
setup_temp_free(f, lengths, c->entries); // note this is only safe if there have been no intervening temp mallocs!
lengths = c->codeword_lengths;
c->sparse = 0;
}
// compute the size of the sorted tables
if (c->sparse) {
sorted_count = total;
} else {
sorted_count = 0;
#ifndef STB_VORBIS_NO_HUFFMAN_BINARY_SEARCH
for (j=0; j < c->entries; ++j)
if (lengths[j] > STB_VORBIS_FAST_HUFFMAN_LENGTH && lengths[j] != NO_CODE)
++sorted_count;
#endif
}
c->sorted_entries = sorted_count;
values = NULL;
CHECK(f);
if (!c->sparse) {
c->codewords = (uint32 *) setup_malloc(f, sizeof(c->codewords[0]) * c->entries);
if (!c->codewords) return error(f, VORBIS_outofmem);
} else {
unsigned int size;
if (c->sorted_entries) {
c->codeword_lengths = (uint8 *) setup_malloc(f, c->sorted_entries);
if (!c->codeword_lengths) return error(f, VORBIS_outofmem);
c->codewords = (uint32 *) setup_temp_malloc(f, sizeof(*c->codewords) * c->sorted_entries);
if (!c->codewords) return error(f, VORBIS_outofmem);
values = (uint32 *) setup_temp_malloc(f, sizeof(*values) * c->sorted_entries);
if (!values) return error(f, VORBIS_outofmem);
}
size = c->entries + (sizeof(*c->codewords) + sizeof(*values)) * c->sorted_entries;
if (size > f->setup_temp_memory_required)
f->setup_temp_memory_required = size;
}
if (!compute_codewords(c, lengths, c->entries, values)) {
if (c->sparse) setup_temp_free(f, values, 0);
return error(f, VORBIS_invalid_setup);
}
if (c->sorted_entries) {
// allocate an extra slot for sentinels
c->sorted_codewords = (uint32 *) setup_malloc(f, sizeof(*c->sorted_codewords) * (c->sorted_entries+1));
if (c->sorted_codewords == NULL) return error(f, VORBIS_outofmem);
// allocate an extra slot at the front so that c->sorted_values[-1] is defined
// so that we can catch that case without an extra if
c->sorted_values = ( int *) setup_malloc(f, sizeof(*c->sorted_values ) * (c->sorted_entries+1));
if (c->sorted_values == NULL) return error(f, VORBIS_outofmem);
++c->sorted_values;
c->sorted_values[-1] = -1;
compute_sorted_huffman(c, lengths, values);
}
if (c->sparse) {
setup_temp_free(f, values, sizeof(*values)*c->sorted_entries);
setup_temp_free(f, c->codewords, sizeof(*c->codewords)*c->sorted_entries);
setup_temp_free(f, lengths, c->entries);
c->codewords = NULL;
}
compute_accelerated_huffman(c);
CHECK(f);
c->lookup_type = get_bits(f, 4);
if (c->lookup_type > 2) return error(f, VORBIS_invalid_setup);
if (c->lookup_type > 0) {
uint16 *mults;
c->minimum_value = float32_unpack(get_bits(f, 32));
c->delta_value = float32_unpack(get_bits(f, 32));
c->value_bits = get_bits(f, 4)+1;
c->sequence_p = get_bits(f,1);
if (c->lookup_type == 1) {
c->lookup_values = lookup1_values(c->entries, c->dimensions);
} else {
c->lookup_values = c->entries * c->dimensions;
}
if (c->lookup_values == 0) return error(f, VORBIS_invalid_setup);
mults = (uint16 *) setup_temp_malloc(f, sizeof(mults[0]) * c->lookup_values);
if (mults == NULL) return error(f, VORBIS_outofmem);
for (j=0; j < (int) c->lookup_values; ++j) {
int q = get_bits(f, c->value_bits);
if (q == EOP) { setup_temp_free(f,mults,sizeof(mults[0])*c->lookup_values); return error(f, VORBIS_invalid_setup); }
mults[j] = q;
}
#ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
if (c->lookup_type == 1) {
int len, sparse = c->sparse;
float last=0;
// pre-expand the lookup1-style multiplicands, to avoid a divide in the inner loop
if (sparse) {
if (c->sorted_entries == 0) goto skip;
c->multiplicands = (codetype *) setup_malloc(f, sizeof(c->multiplicands[0]) * c->sorted_entries * c->dimensions);
} else
c->multiplicands = (codetype *) setup_malloc(f, sizeof(c->multiplicands[0]) * c->entries * c->dimensions);
if (c->multiplicands == NULL) { setup_temp_free(f,mults,sizeof(mults[0])*c->lookup_values); return error(f, VORBIS_outofmem); }
len = sparse ? c->sorted_entries : c->entries;
for (j=0; j < len; ++j) {
unsigned int z = sparse ? c->sorted_values[j] : j;
unsigned int div=1;
for (k=0; k < c->dimensions; ++k) {
int off = (z / div) % c->lookup_values;
float val = mults[off];
val = mults[off]*c->delta_value + c->minimum_value + last;
c->multiplicands[j*c->dimensions + k] = val;
if (c->sequence_p)
last = val;
if (k+1 < c->dimensions) {
if (div > UINT_MAX / (unsigned int) c->lookup_values) {
setup_temp_free(f, mults,sizeof(mults[0])*c->lookup_values);
return error(f, VORBIS_invalid_setup);
}
div *= c->lookup_values;
}
}
}
c->lookup_type = 2;
}
else
#endif
{
float last=0;
CHECK(f);
c->multiplicands = (codetype *) setup_malloc(f, sizeof(c->multiplicands[0]) * c->lookup_values);
if (c->multiplicands == NULL) { setup_temp_free(f, mults,sizeof(mults[0])*c->lookup_values); return error(f, VORBIS_outofmem); }
for (j=0; j < (int) c->lookup_values; ++j) {
float val = mults[j] * c->delta_value + c->minimum_value + last;
c->multiplicands[j] = val;
if (c->sequence_p)
last = val;
}
}
#ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
skip:;
#endif
setup_temp_free(f, mults, sizeof(mults[0])*c->lookup_values);
CHECK(f);
}
CHECK(f);
}
// time domain transfers (notused)
x = get_bits(f, 6) + 1;
for (i=0; i < x; ++i) {
uint32 z = get_bits(f, 16);
if (z != 0) return error(f, VORBIS_invalid_setup);
}
// Floors
f->floor_count = get_bits(f, 6)+1;
f->floor_config = (Floor *) setup_malloc(f, f->floor_count * sizeof(*f->floor_config));
if (f->floor_config == NULL) return error(f, VORBIS_outofmem);
for (i=0; i < f->floor_count; ++i) {
f->floor_types[i] = get_bits(f, 16);
if (f->floor_types[i] > 1) return error(f, VORBIS_invalid_setup);
if (f->floor_types[i] == 0) {
Floor0 *g = &f->floor_config[i].floor0;
g->order = get_bits(f,8);
g->rate = get_bits(f,16);
g->bark_map_size = get_bits(f,16);
g->amplitude_bits = get_bits(f,6);
g->amplitude_offset = get_bits(f,8);
g->number_of_books = get_bits(f,4) + 1;
for (j=0; j < g->number_of_books; ++j)
g->book_list[j] = get_bits(f,8);
return error(f, VORBIS_feature_not_supported);
} else {
stbv__floor_ordering p[31*8+2];
Floor1 *g = &f->floor_config[i].floor1;
int max_class = -1;
g->partitions = get_bits(f, 5);
for (j=0; j < g->partitions; ++j) {
g->partition_class_list[j] = get_bits(f, 4);
if (g->partition_class_list[j] > max_class)
max_class = g->partition_class_list[j];
}
for (j=0; j <= max_class; ++j) {
g->class_dimensions[j] = get_bits(f, 3)+1;
g->class_subclasses[j] = get_bits(f, 2);
if (g->class_subclasses[j]) {
g->class_masterbooks[j] = get_bits(f, 8);
if (g->class_masterbooks[j] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
}
for (k=0; k < 1 << g->class_subclasses[j]; ++k) {
g->subclass_books[j][k] = get_bits(f,8)-1;
if (g->subclass_books[j][k] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
}
}
g->floor1_multiplier = get_bits(f,2)+1;
g->rangebits = get_bits(f,4);
g->Xlist[0] = 0;
g->Xlist[1] = 1 << g->rangebits;
g->values = 2;
for (j=0; j < g->partitions; ++j) {
int c = g->partition_class_list[j];
for (k=0; k < g->class_dimensions[c]; ++k) {
g->Xlist[g->values] = get_bits(f, g->rangebits);
++g->values;
}
}
// precompute the sorting
for (j=0; j < g->values; ++j) {
p[j].x = g->Xlist[j];
p[j].id = j;
}
qsort(p, g->values, sizeof(p[0]), point_compare);
for (j=0; j < g->values; ++j)
g->sorted_order[j] = (uint8) p[j].id;
// precompute the neighbors
for (j=2; j < g->values; ++j) {
int low,hi;
neighbors(g->Xlist, j, &low,&hi);
g->neighbors[j][0] = low;
g->neighbors[j][1] = hi;
}
if (g->values > longest_floorlist)
longest_floorlist = g->values;
}
}
// Residue
f->residue_count = get_bits(f, 6)+1;
f->residue_config = (Residue *) setup_malloc(f, f->residue_count * sizeof(f->residue_config[0]));
if (f->residue_config == NULL) return error(f, VORBIS_outofmem);
memset(f->residue_config, 0, f->residue_count * sizeof(f->residue_config[0]));
for (i=0; i < f->residue_count; ++i) {
uint8 residue_cascade[64];
Residue *r = f->residue_config+i;
f->residue_types[i] = get_bits(f, 16);
if (f->residue_types[i] > 2) return error(f, VORBIS_invalid_setup);
r->begin = get_bits(f, 24);
r->end = get_bits(f, 24);
if (r->end < r->begin) return error(f, VORBIS_invalid_setup);
r->part_size = get_bits(f,24)+1;
r->classifications = get_bits(f,6)+1;
r->classbook = get_bits(f,8);
if (r->classbook >= f->codebook_count) return error(f, VORBIS_invalid_setup);
for (j=0; j < r->classifications; ++j) {
uint8 high_bits=0;
uint8 low_bits=get_bits(f,3);
if (get_bits(f,1))
high_bits = get_bits(f,5);
residue_cascade[j] = high_bits*8 + low_bits;
}
r->residue_books = (short (*)[8]) setup_malloc(f, sizeof(r->residue_books[0]) * r->classifications);
if (r->residue_books == NULL) return error(f, VORBIS_outofmem);
for (j=0; j < r->classifications; ++j) {
for (k=0; k < 8; ++k) {
if (residue_cascade[j] & (1 << k)) {
r->residue_books[j][k] = get_bits(f, 8);
if (r->residue_books[j][k] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
} else {
r->residue_books[j][k] = -1;
}
}
}
// precompute the classifications[] array to avoid inner-loop mod/divide
// call it 'classdata' since we already have r->classifications
r->classdata = (uint8 **) setup_malloc(f, sizeof(*r->classdata) * f->codebooks[r->classbook].entries);
if (!r->classdata) return error(f, VORBIS_outofmem);
memset(r->classdata, 0, sizeof(*r->classdata) * f->codebooks[r->classbook].entries);
for (j=0; j < f->codebooks[r->classbook].entries; ++j) {
int classwords = f->codebooks[r->classbook].dimensions;
int temp = j;
r->classdata[j] = (uint8 *) setup_malloc(f, sizeof(r->classdata[j][0]) * classwords);
if (r->classdata[j] == NULL) return error(f, VORBIS_outofmem);
for (k=classwords-1; k >= 0; --k) {
r->classdata[j][k] = temp % r->classifications;
temp /= r->classifications;
}
}
}
f->mapping_count = get_bits(f,6)+1;
f->mapping = (Mapping *) setup_malloc(f, f->mapping_count * sizeof(*f->mapping));
if (f->mapping == NULL) return error(f, VORBIS_outofmem);
memset(f->mapping, 0, f->mapping_count * sizeof(*f->mapping));
for (i=0; i < f->mapping_count; ++i) {
Mapping *m = f->mapping + i;
int mapping_type = get_bits(f,16);
if (mapping_type != 0) return error(f, VORBIS_invalid_setup);
m->chan = (MappingChannel *) setup_malloc(f, f->channels * sizeof(*m->chan));
if (m->chan == NULL) return error(f, VORBIS_outofmem);
if (get_bits(f,1))
m->submaps = get_bits(f,4)+1;
else
m->submaps = 1;
if (m->submaps > max_submaps)
max_submaps = m->submaps;
if (get_bits(f,1)) {
m->coupling_steps = get_bits(f,8)+1;
for (k=0; k < m->coupling_steps; ++k) {
m->chan[k].magnitude = get_bits(f, ilog(f->channels-1));
m->chan[k].angle = get_bits(f, ilog(f->channels-1));
if (m->chan[k].magnitude >= f->channels) return error(f, VORBIS_invalid_setup);
if (m->chan[k].angle >= f->channels) return error(f, VORBIS_invalid_setup);
if (m->chan[k].magnitude == m->chan[k].angle) return error(f, VORBIS_invalid_setup);
}
} else
m->coupling_steps = 0;
// reserved field
if (get_bits(f,2)) return error(f, VORBIS_invalid_setup);
if (m->submaps > 1) {
for (j=0; j < f->channels; ++j) {
m->chan[j].mux = get_bits(f, 4);
if (m->chan[j].mux >= m->submaps) return error(f, VORBIS_invalid_setup);
}
} else
// @SPECIFICATION: this case is missing from the spec
for (j=0; j < f->channels; ++j)
m->chan[j].mux = 0;
for (j=0; j < m->submaps; ++j) {
get_bits(f,8); // discard
m->submap_floor[j] = get_bits(f,8);
m->submap_residue[j] = get_bits(f,8);
if (m->submap_floor[j] >= f->floor_count) return error(f, VORBIS_invalid_setup);
if (m->submap_residue[j] >= f->residue_count) return error(f, VORBIS_invalid_setup);
}
}
// Modes
f->mode_count = get_bits(f, 6)+1;
for (i=0; i < f->mode_count; ++i) {
Mode *m = f->mode_config+i;
m->blockflag = get_bits(f,1);
m->windowtype = get_bits(f,16);
m->transformtype = get_bits(f,16);
m->mapping = get_bits(f,8);
if (m->windowtype != 0) return error(f, VORBIS_invalid_setup);
if (m->transformtype != 0) return error(f, VORBIS_invalid_setup);
if (m->mapping >= f->mapping_count) return error(f, VORBIS_invalid_setup);
}
flush_packet(f);
f->previous_length = 0;
for (i=0; i < f->channels; ++i) {
f->channel_buffers[i] = (float *) setup_malloc(f, sizeof(float) * f->blocksize_1);
f->previous_window[i] = (float *) setup_malloc(f, sizeof(float) * f->blocksize_1/2);
f->finalY[i] = (int16 *) setup_malloc(f, sizeof(int16) * longest_floorlist);
if (f->channel_buffers[i] == NULL || f->previous_window[i] == NULL || f->finalY[i] == NULL) return error(f, VORBIS_outofmem);
#ifdef STB_VORBIS_NO_DEFER_FLOOR
f->floor_buffers[i] = (float *) setup_malloc(f, sizeof(float) * f->blocksize_1/2);
if (f->floor_buffers[i] == NULL) return error(f, VORBIS_outofmem);
#endif
}
if (!init_blocksize(f, 0, f->blocksize_0)) return FALSE;
if (!init_blocksize(f, 1, f->blocksize_1)) return FALSE;
f->blocksize[0] = f->blocksize_0;
f->blocksize[1] = f->blocksize_1;
#ifdef STB_VORBIS_DIVIDE_TABLE
if (integer_divide_table[1][1]==0)
for (i=0; i < DIVTAB_NUMER; ++i)
for (j=1; j < DIVTAB_DENOM; ++j)
integer_divide_table[i][j] = i / j;
#endif
// compute how much temporary memory is needed
// 1.
{
uint32 imdct_mem = (f->blocksize_1 * sizeof(float) >> 1);
uint32 classify_mem;
int i,max_part_read=0;
for (i=0; i < f->residue_count; ++i) {
Residue *r = f->residue_config + i;
int n_read = r->end - r->begin;
int part_read = n_read / r->part_size;
if (part_read > max_part_read)
max_part_read = part_read;
}
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
classify_mem = f->channels * (sizeof(void*) + max_part_read * sizeof(uint8 *));
#else
classify_mem = f->channels * (sizeof(void*) + max_part_read * sizeof(int *));
#endif
f->temp_memory_required = classify_mem;
if (imdct_mem > f->temp_memory_required)
f->temp_memory_required = imdct_mem;
}
f->first_decode = TRUE;
if (f->alloc.alloc_buffer) {
assert(f->temp_offset == f->alloc.alloc_buffer_length_in_bytes);
// check if there's enough temp memory so we don't error later
if (f->setup_offset + sizeof(*f) + f->temp_memory_required > (unsigned) f->temp_offset)
return error(f, VORBIS_outofmem);
}
f->first_audio_page_offset = stb_vorbis_get_file_offset(f);
return TRUE;
}
static void vorbis_deinit(stb_vorbis *p)
{
int i,j;
if (p->residue_config) {
for (i=0; i < p->residue_count; ++i) {
Residue *r = p->residue_config+i;
if (r->classdata) {
for (j=0; j < p->codebooks[r->classbook].entries; ++j)
setup_free(p, r->classdata[j]);
setup_free(p, r->classdata);
}
setup_free(p, r->residue_books);
}
}
if (p->codebooks) {
CHECK(p);
for (i=0; i < p->codebook_count; ++i) {
Codebook *c = p->codebooks + i;
setup_free(p, c->codeword_lengths);
setup_free(p, c->multiplicands);
setup_free(p, c->codewords);
setup_free(p, c->sorted_codewords);
// c->sorted_values[-1] is the first entry in the array
setup_free(p, c->sorted_values ? c->sorted_values-1 : NULL);
}
setup_free(p, p->codebooks);
}
setup_free(p, p->floor_config);
setup_free(p, p->residue_config);
if (p->mapping) {
for (i=0; i < p->mapping_count; ++i)
setup_free(p, p->mapping[i].chan);
setup_free(p, p->mapping);
}
CHECK(p);
for (i=0; i < p->channels && i < STB_VORBIS_MAX_CHANNELS; ++i) {
setup_free(p, p->channel_buffers[i]);
setup_free(p, p->previous_window[i]);
#ifdef STB_VORBIS_NO_DEFER_FLOOR
setup_free(p, p->floor_buffers[i]);
#endif
setup_free(p, p->finalY[i]);
}
for (i=0; i < 2; ++i) {
setup_free(p, p->A[i]);
setup_free(p, p->B[i]);
setup_free(p, p->C[i]);
setup_free(p, p->window[i]);
setup_free(p, p->bit_reverse[i]);
}
#ifndef STB_VORBIS_NO_STDIO
if (p->close_on_free) fclose(p->f);
#endif
}
void stb_vorbis_close(stb_vorbis *p)
{
if (p == NULL) return;
vorbis_deinit(p);
setup_free(p,p);
}
static void vorbis_init(stb_vorbis *p, const stb_vorbis_alloc *z)
{
memset(p, 0, sizeof(*p)); // NULL out all malloc'd pointers to start
if (z) {
p->alloc = *z;
p->alloc.alloc_buffer_length_in_bytes = (p->alloc.alloc_buffer_length_in_bytes+3) & ~3;
p->temp_offset = p->alloc.alloc_buffer_length_in_bytes;
}
p->eof = 0;
p->error = VORBIS__no_error;
p->stream = NULL;
p->codebooks = NULL;
p->page_crc_tests = -1;
#ifndef STB_VORBIS_NO_STDIO
p->close_on_free = FALSE;
p->f = NULL;
#endif
}
int stb_vorbis_get_sample_offset(stb_vorbis *f)
{
if (f->current_loc_valid)
return f->current_loc;
else
return -1;
}
stb_vorbis_info stb_vorbis_get_info(stb_vorbis *f)
{
stb_vorbis_info d;
d.channels = f->channels;
d.sample_rate = f->sample_rate;
d.setup_memory_required = f->setup_memory_required;
d.setup_temp_memory_required = f->setup_temp_memory_required;
d.temp_memory_required = f->temp_memory_required;
d.max_frame_size = f->blocksize_1 >> 1;
return d;
}
int stb_vorbis_get_error(stb_vorbis *f)
{
int e = f->error;
f->error = VORBIS__no_error;
return e;
}
static stb_vorbis * vorbis_alloc(stb_vorbis *f)
{
stb_vorbis *p = (stb_vorbis *) setup_malloc(f, sizeof(*p));
return p;
}
#ifndef STB_VORBIS_NO_PUSHDATA_API
void stb_vorbis_flush_pushdata(stb_vorbis *f)
{
f->previous_length = 0;
f->page_crc_tests = 0;
f->discard_samples_deferred = 0;
f->current_loc_valid = FALSE;
f->first_decode = FALSE;
f->samples_output = 0;
f->channel_buffer_start = 0;
f->channel_buffer_end = 0;
}
static int vorbis_search_for_page_pushdata(vorb *f, uint8 *data, int data_len)
{
int i,n;
for (i=0; i < f->page_crc_tests; ++i)
f->scan[i].bytes_done = 0;
// if we have room for more scans, search for them first, because
// they may cause us to stop early if their header is incomplete
if (f->page_crc_tests < STB_VORBIS_PUSHDATA_CRC_COUNT) {
if (data_len < 4) return 0;
data_len -= 3; // need to look for 4-byte sequence, so don't miss
// one that straddles a boundary
for (i=0; i < data_len; ++i) {
if (data[i] == 0x4f) {
if (0==memcmp(data+i, ogg_page_header, 4)) {
int j,len;
uint32 crc;
// make sure we have the whole page header
if (i+26 >= data_len || i+27+data[i+26] >= data_len) {
// only read up to this page start, so hopefully we'll
// have the whole page header start next time
data_len = i;
break;
}
// ok, we have it all; compute the length of the page
len = 27 + data[i+26];
for (j=0; j < data[i+26]; ++j)
len += data[i+27+j];
// scan everything up to the embedded crc (which we must 0)
crc = 0;
for (j=0; j < 22; ++j)
crc = crc32_update(crc, data[i+j]);
// now process 4 0-bytes
for ( ; j < 26; ++j)
crc = crc32_update(crc, 0);
// len is the total number of bytes we need to scan
n = f->page_crc_tests++;
f->scan[n].bytes_left = len-j;
f->scan[n].crc_so_far = crc;
f->scan[n].goal_crc = data[i+22] + (data[i+23] << 8) + (data[i+24]<<16) + (data[i+25]<<24);
// if the last frame on a page is continued to the next, then
// we can't recover the sample_loc immediately
if (data[i+27+data[i+26]-1] == 255)
f->scan[n].sample_loc = ~0;
else
f->scan[n].sample_loc = data[i+6] + (data[i+7] << 8) + (data[i+ 8]<<16) + (data[i+ 9]<<24);
f->scan[n].bytes_done = i+j;
if (f->page_crc_tests == STB_VORBIS_PUSHDATA_CRC_COUNT)
break;
// keep going if we still have room for more
}
}
}
}
for (i=0; i < f->page_crc_tests;) {
uint32 crc;
int j;
int n = f->scan[i].bytes_done;
int m = f->scan[i].bytes_left;
if (m > data_len - n) m = data_len - n;
// m is the bytes to scan in the current chunk
crc = f->scan[i].crc_so_far;
for (j=0; j < m; ++j)
crc = crc32_update(crc, data[n+j]);
f->scan[i].bytes_left -= m;
f->scan[i].crc_so_far = crc;
if (f->scan[i].bytes_left == 0) {
// does it match?
if (f->scan[i].crc_so_far == f->scan[i].goal_crc) {
// Houston, we have page
data_len = n+m; // consumption amount is wherever that scan ended
f->page_crc_tests = -1; // drop out of page scan mode
f->previous_length = 0; // decode-but-don't-output one frame
f->next_seg = -1; // start a new page
f->current_loc = f->scan[i].sample_loc; // set the current sample location
// to the amount we'd have decoded had we decoded this page
f->current_loc_valid = f->current_loc != ~0U;
return data_len;
}
// delete entry
f->scan[i] = f->scan[--f->page_crc_tests];
} else {
++i;
}
}
return data_len;
}
// return value: number of bytes we used
int stb_vorbis_decode_frame_pushdata(
stb_vorbis *f, // the file we're decoding
const uint8 *data, int data_len, // the memory available for decoding
int *channels, // place to write number of float * buffers
float ***output, // place to write float ** array of float * buffers
int *samples // place to write number of output samples
)
{
int i;
int len,right,left;
if (!IS_PUSH_MODE(f)) return error(f, VORBIS_invalid_api_mixing);
if (f->page_crc_tests >= 0) {
*samples = 0;
return vorbis_search_for_page_pushdata(f, (uint8 *) data, data_len);
}
f->stream = (uint8 *) data;
f->stream_end = (uint8 *) data + data_len;
f->error = VORBIS__no_error;
// check that we have the entire packet in memory
if (!is_whole_packet_present(f, FALSE)) {
*samples = 0;
return 0;
}
if (!vorbis_decode_packet(f, &len, &left, &right)) {
// save the actual error we encountered
enum STBVorbisError error = f->error;
if (error == VORBIS_bad_packet_type) {
// flush and resynch
f->error = VORBIS__no_error;
while (get8_packet(f) != EOP)
if (f->eof) break;
*samples = 0;
return (int) (f->stream - data);
}
if (error == VORBIS_continued_packet_flag_invalid) {
if (f->previous_length == 0) {
// we may be resynching, in which case it's ok to hit one
// of these; just discard the packet
f->error = VORBIS__no_error;
while (get8_packet(f) != EOP)
if (f->eof) break;
*samples = 0;
return (int) (f->stream - data);
}
}
// if we get an error while parsing, what to do?
// well, it DEFINITELY won't work to continue from where we are!
stb_vorbis_flush_pushdata(f);
// restore the error that actually made us bail
f->error = error;
*samples = 0;
return 1;
}
// success!
len = vorbis_finish_frame(f, len, left, right);
for (i=0; i < f->channels; ++i)
f->outputs[i] = f->channel_buffers[i] + left;
if (channels) *channels = f->channels;
*samples = len;
*output = f->outputs;
return (int) (f->stream - data);
}
stb_vorbis *stb_vorbis_open_pushdata(
const unsigned char *data, int data_len, // the memory available for decoding
int *data_used, // only defined if result is not NULL
int *error, const stb_vorbis_alloc *alloc)
{
stb_vorbis *f, p;
vorbis_init(&p, alloc);
p.stream = (uint8 *) data;
p.stream_end = (uint8 *) data + data_len;
p.push_mode = TRUE;
if (!start_decoder(&p)) {
if (p.eof)
*error = VORBIS_need_more_data;
else
*error = p.error;
return NULL;
}
f = vorbis_alloc(&p);
if (f) {
*f = p;
*data_used = (int) (f->stream - data);
*error = 0;
return f;
} else {
vorbis_deinit(&p);
return NULL;
}
}
#endif // STB_VORBIS_NO_PUSHDATA_API
unsigned int stb_vorbis_get_file_offset(stb_vorbis *f)
{
#ifndef STB_VORBIS_NO_PUSHDATA_API
if (f->push_mode) return 0;
#endif
if (USE_MEMORY(f)) return (unsigned int) (f->stream - f->stream_start);
#ifndef STB_VORBIS_NO_STDIO
return (unsigned int) (ftell(f->f) - f->f_start);
#endif
}
#ifndef STB_VORBIS_NO_PULLDATA_API
//
// DATA-PULLING API
//
static uint32 vorbis_find_page(stb_vorbis *f, uint32 *end, uint32 *last)
{
for(;;) {
int n;
if (f->eof) return 0;
n = get8(f);
if (n == 0x4f) { // page header candidate
unsigned int retry_loc = stb_vorbis_get_file_offset(f);
int i;
// check if we're off the end of a file_section stream
if (retry_loc - 25 > f->stream_len)
return 0;
// check the rest of the header
for (i=1; i < 4; ++i)
if (get8(f) != ogg_page_header[i])
break;
if (f->eof) return 0;
if (i == 4) {
uint8 header[27];
uint32 i, crc, goal, len;
for (i=0; i < 4; ++i)
header[i] = ogg_page_header[i];
for (; i < 27; ++i)
header[i] = get8(f);
if (f->eof) return 0;
if (header[4] != 0) goto invalid;
goal = header[22] + (header[23] << 8) + (header[24]<<16) + (header[25]<<24);
for (i=22; i < 26; ++i)
header[i] = 0;
crc = 0;
for (i=0; i < 27; ++i)
crc = crc32_update(crc, header[i]);
len = 0;
for (i=0; i < header[26]; ++i) {
int s = get8(f);
crc = crc32_update(crc, s);
len += s;
}
if (len && f->eof) return 0;
for (i=0; i < len; ++i)
crc = crc32_update(crc, get8(f));
// finished parsing probable page
if (crc == goal) {
// we could now check that it's either got the last
// page flag set, OR it's followed by the capture
// pattern, but I guess TECHNICALLY you could have
// a file with garbage between each ogg page and recover
// from it automatically? So even though that paranoia
// might decrease the chance of an invalid decode by
// another 2^32, not worth it since it would hose those
// invalid-but-useful files?
if (end)
*end = stb_vorbis_get_file_offset(f);
if (last) {
if (header[5] & 0x04)
*last = 1;
else
*last = 0;
}
set_file_offset(f, retry_loc-1);
return 1;
}
}
invalid:
// not a valid page, so rewind and look for next one
set_file_offset(f, retry_loc);
}
}
}
#define SAMPLE_unknown 0xffffffff
// seeking is implemented with a binary search, which narrows down the range to
// 64K, before using a linear search (because finding the synchronization
// pattern can be expensive, and the chance we'd find the end page again is
// relatively high for small ranges)
//
// two initial interpolation-style probes are used at the start of the search
// to try to bound either side of the binary search sensibly, while still
// working in O(log n) time if they fail.
static int get_seek_page_info(stb_vorbis *f, ProbedPage *z)
{
uint8 header[27], lacing[255];
int i,len;
// record where the page starts
z->page_start = stb_vorbis_get_file_offset(f);
// parse the header
getn(f, header, 27);
if (header[0] != 'O' || header[1] != 'g' || header[2] != 'g' || header[3] != 'S')
return 0;
getn(f, lacing, header[26]);
// determine the length of the payload
len = 0;
for (i=0; i < header[26]; ++i)
len += lacing[i];
// this implies where the page ends
z->page_end = z->page_start + 27 + header[26] + len;
// read the last-decoded sample out of the data
z->last_decoded_sample = header[6] + (header[7] << 8) + (header[8] << 16) + (header[9] << 24);
// restore file state to where we were
set_file_offset(f, z->page_start);
return 1;
}
// rarely used function to seek back to the preceeding page while finding the
// start of a packet
static int go_to_page_before(stb_vorbis *f, unsigned int limit_offset)
{
unsigned int previous_safe, end;
// now we want to seek back 64K from the limit
if (limit_offset >= 65536 && limit_offset-65536 >= f->first_audio_page_offset)
previous_safe = limit_offset - 65536;
else
previous_safe = f->first_audio_page_offset;
set_file_offset(f, previous_safe);
while (vorbis_find_page(f, &end, NULL)) {
if (end >= limit_offset && stb_vorbis_get_file_offset(f) < limit_offset)
return 1;
set_file_offset(f, end);
}
return 0;
}
// implements the search logic for finding a page and starting decoding. if
// the function succeeds, current_loc_valid will be true and current_loc will
// be less than or equal to the provided sample number (the closer the
// better).
static int seek_to_sample_coarse(stb_vorbis *f, uint32 sample_number)
{
ProbedPage left, right, mid;
int i, start_seg_with_known_loc, end_pos, page_start;
uint32 delta, stream_length, padding;
double offset, bytes_per_sample;
int probe = 0;
// find the last page and validate the target sample
stream_length = stb_vorbis_stream_length_in_samples(f);
if (stream_length == 0) return error(f, VORBIS_seek_without_length);
if (sample_number > stream_length) return error(f, VORBIS_seek_invalid);
// this is the maximum difference between the window-center (which is the
// actual granule position value), and the right-start (which the spec
// indicates should be the granule position (give or take one)).
padding = ((f->blocksize_1 - f->blocksize_0) >> 2);
if (sample_number < padding)
sample_number = 0;
else
sample_number -= padding;
left = f->p_first;
while (left.last_decoded_sample == ~0U) {
// (untested) the first page does not have a 'last_decoded_sample'
set_file_offset(f, left.page_end);
if (!get_seek_page_info(f, &left)) goto error;
}
right = f->p_last;
assert(right.last_decoded_sample != ~0U);
// starting from the start is handled differently
if (sample_number <= left.last_decoded_sample) {
if (stb_vorbis_seek_start(f))
return 1;
return 0;
}
while (left.page_end != right.page_start) {
assert(left.page_end < right.page_start);
// search range in bytes
delta = right.page_start - left.page_end;
if (delta <= 65536) {
// there's only 64K left to search - handle it linearly
set_file_offset(f, left.page_end);
} else {
if (probe < 2) {
if (probe == 0) {
// first probe (interpolate)
double data_bytes = right.page_end - left.page_start;
bytes_per_sample = data_bytes / right.last_decoded_sample;
offset = left.page_start + bytes_per_sample * (sample_number - left.last_decoded_sample);
} else {
// second probe (try to bound the other side)
double error = ((double) sample_number - mid.last_decoded_sample) * bytes_per_sample;
if (error >= 0 && error < 8000) error = 8000;
if (error < 0 && error > -8000) error = -8000;
offset += error * 2;
}
// ensure the offset is valid
if (offset < left.page_end)
offset = left.page_end;
if (offset > right.page_start - 65536)
offset = right.page_start - 65536;
set_file_offset(f, (unsigned int) offset);
} else {
// binary search for large ranges (offset by 32K to ensure
// we don't hit the right page)
set_file_offset(f, left.page_end + (delta / 2) - 32768);
}
if (!vorbis_find_page(f, NULL, NULL)) goto error;
}
for (;;) {
if (!get_seek_page_info(f, &mid)) goto error;
if (mid.last_decoded_sample != ~0U) break;
// (untested) no frames end on this page
set_file_offset(f, mid.page_end);
assert(mid.page_start < right.page_start);
}
// if we've just found the last page again then we're in a tricky file,
// and we're close enough.
if (mid.page_start == right.page_start)
break;
if (sample_number < mid.last_decoded_sample)
right = mid;
else
left = mid;
++probe;
}
// seek back to start of the last packet
page_start = left.page_start;
set_file_offset(f, page_start);
if (!start_page(f)) return error(f, VORBIS_seek_failed);
end_pos = f->end_seg_with_known_loc;
assert(end_pos >= 0);
for (;;) {
for (i = end_pos; i > 0; --i)
if (f->segments[i-1] != 255)
break;
start_seg_with_known_loc = i;
if (start_seg_with_known_loc > 0 || !(f->page_flag & PAGEFLAG_continued_packet))
break;
// (untested) the final packet begins on an earlier page
if (!go_to_page_before(f, page_start))
goto error;
page_start = stb_vorbis_get_file_offset(f);
if (!start_page(f)) goto error;
end_pos = f->segment_count - 1;
}
// prepare to start decoding
f->current_loc_valid = FALSE;
f->last_seg = FALSE;
f->valid_bits = 0;
f->packet_bytes = 0;
f->bytes_in_seg = 0;
f->previous_length = 0;
f->next_seg = start_seg_with_known_loc;
for (i = 0; i < start_seg_with_known_loc; i++)
skip(f, f->segments[i]);
// start decoding (optimizable - this frame is generally discarded)
if (!vorbis_pump_first_frame(f))
return 0;
if (f->current_loc > sample_number)
return error(f, VORBIS_seek_failed);
return 1;
error:
// try to restore the file to a valid state
stb_vorbis_seek_start(f);
return error(f, VORBIS_seek_failed);
}
// the same as vorbis_decode_initial, but without advancing
static int peek_decode_initial(vorb *f, int *p_left_start, int *p_left_end, int *p_right_start, int *p_right_end, int *mode)
{
int bits_read, bytes_read;
if (!vorbis_decode_initial(f, p_left_start, p_left_end, p_right_start, p_right_end, mode))
return 0;
// either 1 or 2 bytes were read, figure out which so we can rewind
bits_read = 1 + ilog(f->mode_count-1);
if (f->mode_config[*mode].blockflag)
bits_read += 2;
bytes_read = (bits_read + 7) / 8;
f->bytes_in_seg += bytes_read;
f->packet_bytes -= bytes_read;
skip(f, -bytes_read);
if (f->next_seg == -1)
f->next_seg = f->segment_count - 1;
else
f->next_seg--;
f->valid_bits = 0;
return 1;
}
int stb_vorbis_seek_frame(stb_vorbis *f, unsigned int sample_number)
{
uint32 max_frame_samples;
if (IS_PUSH_MODE(f)) return error(f, VORBIS_invalid_api_mixing);
// fast page-level search
if (!seek_to_sample_coarse(f, sample_number))
return 0;
assert(f->current_loc_valid);
assert(f->current_loc <= sample_number);
// linear search for the relevant packet
max_frame_samples = (f->blocksize_1*3 - f->blocksize_0) >> 2;
while (f->current_loc < sample_number) {
int left_start, left_end, right_start, right_end, mode, frame_samples;
if (!peek_decode_initial(f, &left_start, &left_end, &right_start, &right_end, &mode))
return error(f, VORBIS_seek_failed);
// calculate the number of samples returned by the next frame
frame_samples = right_start - left_start;
if (f->current_loc + frame_samples > sample_number) {
return 1; // the next frame will contain the sample
} else if (f->current_loc + frame_samples + max_frame_samples > sample_number) {
// there's a chance the frame after this could contain the sample
vorbis_pump_first_frame(f);
} else {
// this frame is too early to be relevant
f->current_loc += frame_samples;
f->previous_length = 0;
maybe_start_packet(f);
flush_packet(f);
}
}
// the next frame will start with the sample
assert(f->current_loc == sample_number);
return 1;
}
int stb_vorbis_seek(stb_vorbis *f, unsigned int sample_number)
{
if (!stb_vorbis_seek_frame(f, sample_number))
return 0;
if (sample_number != f->current_loc) {
int n;
uint32 frame_start = f->current_loc;
stb_vorbis_get_frame_float(f, &n, NULL);
assert(sample_number > frame_start);
assert(f->channel_buffer_start + (int) (sample_number-frame_start) <= f->channel_buffer_end);
f->channel_buffer_start += (sample_number - frame_start);
}
return 1;
}
int stb_vorbis_seek_start(stb_vorbis *f)
{
if (IS_PUSH_MODE(f)) { return error(f, VORBIS_invalid_api_mixing); }
set_file_offset(f, f->first_audio_page_offset);
f->previous_length = 0;
f->first_decode = TRUE;
f->next_seg = -1;
return vorbis_pump_first_frame(f);
}
unsigned int stb_vorbis_stream_length_in_samples(stb_vorbis *f)
{
unsigned int restore_offset, previous_safe;
unsigned int end, last_page_loc;
if (IS_PUSH_MODE(f)) return error(f, VORBIS_invalid_api_mixing);
if (!f->total_samples) {
unsigned int last;
uint32 lo,hi;
char header[6];
// first, store the current decode position so we can restore it
restore_offset = stb_vorbis_get_file_offset(f);
// now we want to seek back 64K from the end (the last page must
// be at most a little less than 64K, but let's allow a little slop)
if (f->stream_len >= 65536 && f->stream_len-65536 >= f->first_audio_page_offset)
previous_safe = f->stream_len - 65536;
else
previous_safe = f->first_audio_page_offset;
set_file_offset(f, previous_safe);
// previous_safe is now our candidate 'earliest known place that seeking
// to will lead to the final page'
if (!vorbis_find_page(f, &end, &last)) {
// if we can't find a page, we're hosed!
f->error = VORBIS_cant_find_last_page;
f->total_samples = 0xffffffff;
goto done;
}
// check if there are more pages
last_page_loc = stb_vorbis_get_file_offset(f);
// stop when the last_page flag is set, not when we reach eof;
// this allows us to stop short of a 'file_section' end without
// explicitly checking the length of the section
while (!last) {
set_file_offset(f, end);
if (!vorbis_find_page(f, &end, &last)) {
// the last page we found didn't have the 'last page' flag
// set. whoops!
break;
}
previous_safe = last_page_loc+1;
last_page_loc = stb_vorbis_get_file_offset(f);
}
set_file_offset(f, last_page_loc);
// parse the header
getn(f, (unsigned char *)header, 6);
// extract the absolute granule position
lo = get32(f);
hi = get32(f);
if (lo == 0xffffffff && hi == 0xffffffff) {
f->error = VORBIS_cant_find_last_page;
f->total_samples = SAMPLE_unknown;
goto done;
}
if (hi)
lo = 0xfffffffe; // saturate
f->total_samples = lo;
f->p_last.page_start = last_page_loc;
f->p_last.page_end = end;
f->p_last.last_decoded_sample = lo;
done:
set_file_offset(f, restore_offset);
}
return f->total_samples == SAMPLE_unknown ? 0 : f->total_samples;
}
float stb_vorbis_stream_length_in_seconds(stb_vorbis *f)
{
return stb_vorbis_stream_length_in_samples(f) / (float) f->sample_rate;
}
int stb_vorbis_get_frame_float(stb_vorbis *f, int *channels, float ***output)
{
int len, right,left,i;
if (IS_PUSH_MODE(f)) return error(f, VORBIS_invalid_api_mixing);
if (!vorbis_decode_packet(f, &len, &left, &right)) {
f->channel_buffer_start = f->channel_buffer_end = 0;
return 0;
}
len = vorbis_finish_frame(f, len, left, right);
for (i=0; i < f->channels; ++i)
f->outputs[i] = f->channel_buffers[i] + left;
f->channel_buffer_start = left;
f->channel_buffer_end = left+len;
if (channels) *channels = f->channels;
if (output) *output = f->outputs;
return len;
}
#ifndef STB_VORBIS_NO_STDIO
stb_vorbis * stb_vorbis_open_file_section(FILE *file, int close_on_free, int *error, const stb_vorbis_alloc *alloc, unsigned int length)
{
stb_vorbis *f, p;
vorbis_init(&p, alloc);
p.f = file;
p.f_start = (uint32) ftell(file);
p.stream_len = length;
p.close_on_free = close_on_free;
if (start_decoder(&p)) {
f = vorbis_alloc(&p);
if (f) {
*f = p;
vorbis_pump_first_frame(f);
return f;
}
}
if (error) *error = p.error;
vorbis_deinit(&p);
return NULL;
}
stb_vorbis * stb_vorbis_open_file(FILE *file, int close_on_free, int *error, const stb_vorbis_alloc *alloc)
{
unsigned int len, start;
start = (unsigned int) ftell(file);
fseek(file, 0, SEEK_END);
len = (unsigned int) (ftell(file) - start);
fseek(file, start, SEEK_SET);
return stb_vorbis_open_file_section(file, close_on_free, error, alloc, len);
}
stb_vorbis * stb_vorbis_open_filename(const char *filename, int *error, const stb_vorbis_alloc *alloc)
{
#ifdef _MSC_VER
FILE *f;
fopen_s(&f, filename, "rb");
#else
FILE *f = fopen(filename, "rb");
#endif
if (f)
return stb_vorbis_open_file(f, TRUE, error, alloc);
if (error) *error = VORBIS_file_open_failure;
return NULL;
}
#endif // STB_VORBIS_NO_STDIO
stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *error, const stb_vorbis_alloc *alloc)
{
stb_vorbis *f, p;
if (data == NULL) return NULL;
vorbis_init(&p, alloc);
p.stream = (uint8 *) data;
p.stream_end = (uint8 *) data + len;
p.stream_start = (uint8 *) p.stream;
p.stream_len = len;
p.push_mode = FALSE;
if (start_decoder(&p)) {
f = vorbis_alloc(&p);
if (f) {
*f = p;
vorbis_pump_first_frame(f);
if (error) *error = VORBIS__no_error;
return f;
}
}
if (error) *error = p.error;
vorbis_deinit(&p);
return NULL;
}
#ifndef STB_VORBIS_NO_INTEGER_CONVERSION
#define PLAYBACK_MONO 1
#define PLAYBACK_LEFT 2
#define PLAYBACK_RIGHT 4
#define L (PLAYBACK_LEFT | PLAYBACK_MONO)
#define C (PLAYBACK_LEFT | PLAYBACK_RIGHT | PLAYBACK_MONO)
#define R (PLAYBACK_RIGHT | PLAYBACK_MONO)
static int8 channel_position[7][6] =
{
{ 0 },
{ C },
{ L, R },
{ L, C, R },
{ L, R, L, R },
{ L, C, R, L, R },
{ L, C, R, L, R, C },
};
#ifndef STB_VORBIS_NO_FAST_SCALED_FLOAT
typedef union {
float f;
int i;
} float_conv;
typedef char stb_vorbis_float_size_test[sizeof(float)==4 && sizeof(int) == 4];
#define FASTDEF(x) float_conv x
// add (1<<23) to convert to int, then divide by 2^SHIFT, then add 0.5/2^SHIFT to round
#define MAGIC(SHIFT) (1.5f * (1 << (23-SHIFT)) + 0.5f/(1 << SHIFT))
#define ADDEND(SHIFT) (((150-SHIFT) << 23) + (1 << 22))
#define FAST_SCALED_FLOAT_TO_INT(temp,x,s) (temp.f = (x) + MAGIC(s), temp.i - ADDEND(s))
#define check_endianness()
#else
#define FAST_SCALED_FLOAT_TO_INT(temp,x,s) ((int) ((x) * (1 << (s))))
#define check_endianness()
#define FASTDEF(x)
#endif
static void copy_samples(short *dest, float *src, int len)
{
int i;
check_endianness();
for (i=0; i < len; ++i) {
FASTDEF(temp);
int v = FAST_SCALED_FLOAT_TO_INT(temp, src[i],15);
if ((unsigned int) (v + 32768) > 65535)
v = v < 0 ? -32768 : 32767;
dest[i] = v;
}
}
static void compute_samples(int mask, short *output, int num_c, float **data, int d_offset, int len)
{
#define BUFFER_SIZE 32
float buffer[BUFFER_SIZE];
int i,j,o,n = BUFFER_SIZE;
check_endianness();
for (o = 0; o < len; o += BUFFER_SIZE) {
memset(buffer, 0, sizeof(buffer));
if (o + n > len) n = len - o;
for (j=0; j < num_c; ++j) {
if (channel_position[num_c][j] & mask) {
for (i=0; i < n; ++i)
buffer[i] += data[j][d_offset+o+i];
}
}
for (i=0; i < n; ++i) {
FASTDEF(temp);
int v = FAST_SCALED_FLOAT_TO_INT(temp,buffer[i],15);
if ((unsigned int) (v + 32768) > 65535)
v = v < 0 ? -32768 : 32767;
output[o+i] = v;
}
}
}
static void compute_stereo_samples(short *output, int num_c, float **data, int d_offset, int len)
{
#define BUFFER_SIZE 32
float buffer[BUFFER_SIZE];
int i,j,o,n = BUFFER_SIZE >> 1;
// o is the offset in the source data
check_endianness();
for (o = 0; o < len; o += BUFFER_SIZE >> 1) {
// o2 is the offset in the output data
int o2 = o << 1;
memset(buffer, 0, sizeof(buffer));
if (o + n > len) n = len - o;
for (j=0; j < num_c; ++j) {
int m = channel_position[num_c][j] & (PLAYBACK_LEFT | PLAYBACK_RIGHT);
if (m == (PLAYBACK_LEFT | PLAYBACK_RIGHT)) {
for (i=0; i < n; ++i) {
buffer[i*2+0] += data[j][d_offset+o+i];
buffer[i*2+1] += data[j][d_offset+o+i];
}
} else if (m == PLAYBACK_LEFT) {
for (i=0; i < n; ++i) {
buffer[i*2+0] += data[j][d_offset+o+i];
}
} else if (m == PLAYBACK_RIGHT) {
for (i=0; i < n; ++i) {
buffer[i*2+1] += data[j][d_offset+o+i];
}
}
}
for (i=0; i < (n<<1); ++i) {
FASTDEF(temp);
int v = FAST_SCALED_FLOAT_TO_INT(temp,buffer[i],15);
if ((unsigned int) (v + 32768) > 65535)
v = v < 0 ? -32768 : 32767;
output[o2+i] = v;
}
}
}
static void convert_samples_short(int buf_c, short **buffer, int b_offset, int data_c, float **data, int d_offset, int samples)
{
int i;
if (buf_c != data_c && buf_c <= 2 && data_c <= 6) {
static int channel_selector[3][2] = { {0}, {PLAYBACK_MONO}, {PLAYBACK_LEFT, PLAYBACK_RIGHT} };
for (i=0; i < buf_c; ++i)
compute_samples(channel_selector[buf_c][i], buffer[i]+b_offset, data_c, data, d_offset, samples);
} else {
int limit = buf_c < data_c ? buf_c : data_c;
for (i=0; i < limit; ++i)
copy_samples(buffer[i]+b_offset, data[i]+d_offset, samples);
for ( ; i < buf_c; ++i)
memset(buffer[i]+b_offset, 0, sizeof(short) * samples);
}
}
int stb_vorbis_get_frame_short(stb_vorbis *f, int num_c, short **buffer, int num_samples)
{
float **output;
int len = stb_vorbis_get_frame_float(f, NULL, &output);
if (len > num_samples) len = num_samples;
if (len)
convert_samples_short(num_c, buffer, 0, f->channels, output, 0, len);
return len;
}
static void convert_channels_short_interleaved(int buf_c, short *buffer, int data_c, float **data, int d_offset, int len)
{
int i;
check_endianness();
if (buf_c != data_c && buf_c <= 2 && data_c <= 6) {
assert(buf_c == 2);
for (i=0; i < buf_c; ++i)
compute_stereo_samples(buffer, data_c, data, d_offset, len);
} else {
int limit = buf_c < data_c ? buf_c : data_c;
int j;
for (j=0; j < len; ++j) {
for (i=0; i < limit; ++i) {
FASTDEF(temp);
float f = data[i][d_offset+j];
int v = FAST_SCALED_FLOAT_TO_INT(temp, f,15);//data[i][d_offset+j],15);
if ((unsigned int) (v + 32768) > 65535)
v = v < 0 ? -32768 : 32767;
*buffer++ = v;
}
for ( ; i < buf_c; ++i)
*buffer++ = 0;
}
}
}
int stb_vorbis_get_frame_short_interleaved(stb_vorbis *f, int num_c, short *buffer, int num_shorts)
{
float **output;
int len;
if (num_c == 1) return stb_vorbis_get_frame_short(f,num_c,&buffer, num_shorts);
len = stb_vorbis_get_frame_float(f, NULL, &output);
if (len) {
if (len*num_c > num_shorts) len = num_shorts / num_c;
convert_channels_short_interleaved(num_c, buffer, f->channels, output, 0, len);
}
return len;
}
int stb_vorbis_get_samples_short_interleaved(stb_vorbis *f, int channels, short *buffer, int num_shorts)
{
float **outputs;
int len = num_shorts / channels;
int n=0;
int z = f->channels;
if (z > channels) z = channels;
while (n < len) {
int k = f->channel_buffer_end - f->channel_buffer_start;
if (n+k >= len) k = len - n;
if (k)
convert_channels_short_interleaved(channels, buffer, f->channels, f->channel_buffers, f->channel_buffer_start, k);
buffer += k*channels;
n += k;
f->channel_buffer_start += k;
if (n == len) break;
if (!stb_vorbis_get_frame_float(f, NULL, &outputs)) break;
}
return n;
}
int stb_vorbis_get_samples_short(stb_vorbis *f, int channels, short **buffer, int len)
{
float **outputs;
int n=0;
int z = f->channels;
if (z > channels) z = channels;
while (n < len) {
int k = f->channel_buffer_end - f->channel_buffer_start;
if (n+k >= len) k = len - n;
if (k)
convert_samples_short(channels, buffer, n, f->channels, f->channel_buffers, f->channel_buffer_start, k);
n += k;
f->channel_buffer_start += k;
if (n == len) break;
if (!stb_vorbis_get_frame_float(f, NULL, &outputs)) break;
}
return n;
}
#ifndef STB_VORBIS_NO_STDIO
int stb_vorbis_decode_filename(const char *filename, int *channels, int *sample_rate, short **output)
{
int data_len, offset, total, limit, error;
short *data;
stb_vorbis *v = stb_vorbis_open_filename(filename, &error, NULL);
if (v == NULL) return -1;
limit = v->channels * 4096;
*channels = v->channels;
if (sample_rate)
*sample_rate = v->sample_rate;
offset = data_len = 0;
total = limit;
data = (short *) malloc(total * sizeof(*data));
if (data == NULL) {
stb_vorbis_close(v);
return -2;
}
for (;;) {
int n = stb_vorbis_get_frame_short_interleaved(v, v->channels, data+offset, total-offset);
if (n == 0) break;
data_len += n;
offset += n * v->channels;
if (offset + limit > total) {
short *data2;
total *= 2;
data2 = (short *) realloc(data, total * sizeof(*data));
if (data2 == NULL) {
free(data);
stb_vorbis_close(v);
return -2;
}
data = data2;
}
}
*output = data;
stb_vorbis_close(v);
return data_len;
}
#endif // NO_STDIO
int stb_vorbis_decode_memory(const uint8 *mem, int len, int *channels, int *sample_rate, short **output)
{
int data_len, offset, total, limit, error;
short *data;
stb_vorbis *v = stb_vorbis_open_memory(mem, len, &error, NULL);
if (v == NULL) return -1;
limit = v->channels * 4096;
*channels = v->channels;
if (sample_rate)
*sample_rate = v->sample_rate;
offset = data_len = 0;
total = limit;
data = (short *) malloc(total * sizeof(*data));
if (data == NULL) {
stb_vorbis_close(v);
return -2;
}
for (;;) {
int n = stb_vorbis_get_frame_short_interleaved(v, v->channels, data+offset, total-offset);
if (n == 0) break;
data_len += n;
offset += n * v->channels;
if (offset + limit > total) {
short *data2;
total *= 2;
data2 = (short *) realloc(data, total * sizeof(*data));
if (data2 == NULL) {
free(data);
stb_vorbis_close(v);
return -2;
}
data = data2;
}
}
*output = data;
stb_vorbis_close(v);
return data_len;
}
#endif // STB_VORBIS_NO_INTEGER_CONVERSION
int stb_vorbis_get_samples_float_interleaved(stb_vorbis *f, int channels, float *buffer, int num_floats)
{
float **outputs;
int len = num_floats / channels;
int n=0;
int z = f->channels;
if (z > channels) z = channels;
while (n < len) {
int i,j;
int k = f->channel_buffer_end - f->channel_buffer_start;
if (n+k >= len) k = len - n;
for (j=0; j < k; ++j) {
for (i=0; i < z; ++i)
*buffer++ = f->channel_buffers[i][f->channel_buffer_start+j];
for ( ; i < channels; ++i)
*buffer++ = 0;
}
n += k;
f->channel_buffer_start += k;
if (n == len)
break;
if (!stb_vorbis_get_frame_float(f, NULL, &outputs))
break;
}
return n;
}
int stb_vorbis_get_samples_float(stb_vorbis *f, int channels, float **buffer, int num_samples)
{
float **outputs;
int n=0;
int z = f->channels;
if (z > channels) z = channels;
while (n < num_samples) {
int i;
int k = f->channel_buffer_end - f->channel_buffer_start;
if (n+k >= num_samples) k = num_samples - n;
if (k) {
for (i=0; i < z; ++i)
memcpy(buffer[i]+n, f->channel_buffers[i]+f->channel_buffer_start, sizeof(float)*k);
for ( ; i < channels; ++i)
memset(buffer[i]+n, 0, sizeof(float) * k);
}
n += k;
f->channel_buffer_start += k;
if (n == num_samples)
break;
if (!stb_vorbis_get_frame_float(f, NULL, &outputs))
break;
}
return n;
}
#endif // STB_VORBIS_NO_PULLDATA_API
/* Version history
1.10 - 2017/03/03 - more robust seeking; fix negative ilog(); clear error in open_memory
1.09 - 2016/04/04 - back out 'avoid discarding last frame' fix from previous version
1.08 - 2016/04/02 - fixed multiple warnings; fix setup memory leaks;
avoid discarding last frame of audio data
1.07 - 2015/01/16 - fixed some warnings, fix mingw, const-correct API
some more crash fixes when out of memory or with corrupt files
1.06 - 2015/08/31 - full, correct support for seeking API (Dougall Johnson)
some crash fixes when out of memory or with corrupt files
1.05 - 2015/04/19 - don't define __forceinline if it's redundant
1.04 - 2014/08/27 - fix missing const-correct case in API
1.03 - 2014/08/07 - Warning fixes
1.02 - 2014/07/09 - Declare qsort compare function _cdecl on windows
1.01 - 2014/06/18 - fix stb_vorbis_get_samples_float
1.0 - 2014/05/26 - fix memory leaks; fix warnings; fix bugs in multichannel
(API change) report sample rate for decode-full-file funcs
0.99996 - bracket #include <malloc.h> for macintosh compilation by Laurent Gomila
0.99995 - use union instead of pointer-cast for fast-float-to-int to avoid alias-optimization problem
0.99994 - change fast-float-to-int to work in single-precision FPU mode, remove endian-dependence
0.99993 - remove assert that fired on legal files with empty tables
0.99992 - rewind-to-start
0.99991 - bugfix to stb_vorbis_get_samples_short by Bernhard Wodo
0.9999 - (should have been 0.99990) fix no-CRT support, compiling as C++
0.9998 - add a full-decode function with a memory source
0.9997 - fix a bug in the read-from-FILE case in 0.9996 addition
0.9996 - query length of vorbis stream in samples/seconds
0.9995 - bugfix to another optimization that only happened in certain files
0.9994 - bugfix to one of the optimizations that caused significant (but inaudible?) errors
0.9993 - performance improvements; runs in 99% to 104% of time of reference implementation
0.9992 - performance improvement of IMDCT; now performs close to reference implementation
0.9991 - performance improvement of IMDCT
0.999 - (should have been 0.9990) performance improvement of IMDCT
0.998 - no-CRT support from Casey Muratori
0.997 - bugfixes for bugs found by Terje Mathisen
0.996 - bugfix: fast-huffman decode initialized incorrectly for sparse codebooks; fixing gives 10% speedup - found by Terje Mathisen
0.995 - bugfix: fix to 'effective' overrun detection - found by Terje Mathisen
0.994 - bugfix: garbage decode on final VQ symbol of a non-multiple - found by Terje Mathisen
0.993 - bugfix: pushdata API required 1 extra byte for empty page (failed to consume final page if empty) - found by Terje Mathisen
0.992 - fixes for MinGW warning
0.991 - turn fast-float-conversion on by default
0.990 - fix push-mode seek recovery if you seek into the headers
0.98b - fix to bad release of 0.98
0.98 - fix push-mode seek recovery; robustify float-to-int and support non-fast mode
0.97 - builds under c++ (typecasting, don't use 'class' keyword)
0.96 - somehow MY 0.95 was right, but the web one was wrong, so here's my 0.95 rereleased as 0.96, fixes a typo in the clamping code
0.95 - clamping code for 16-bit functions
0.94 - not publically released
0.93 - fixed all-zero-floor case (was decoding garbage)
0.92 - fixed a memory leak
0.91 - conditional compiles to omit parts of the API and the infrastructure to support them: STB_VORBIS_NO_PULLDATA_API, STB_VORBIS_NO_PUSHDATA_API, STB_VORBIS_NO_STDIO, STB_VORBIS_NO_INTEGER_CONVERSION
0.90 - first public release
*/
#endif // STB_VORBIS_HEADER_ONLY
/*
------------------------------------------------------------------------------
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2017 Sean Barrett
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
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 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.
------------------------------------------------------------------------------
*/
|
the_stack_data/361485.c | //Write a recursive function to find factorial of a number.
#include<stdio.h>
int factorial(int);
int main()
{
int i, num, result;
printf("\nEnter any number: ");
scanf("%d", &num);
result = factorial(num);
printf("\nFactorial of %d is %d\n", num, result);
return 0;
}
int factorial(int n)
{
int i, fact = 1;
if(n<2)
return 1;
else
return factorial(n-1)*n;
return fact;
}
|
the_stack_data/106191.c | #include <stdio.h>
#define IN 1 /* inside a word */
#define OUT 0 /* outside a word */
/* very basic version of wc program */
int main() {
int c, nl, nw, nc, state;
state = OUT;
nl = nw = nc =0;
while ((c = getchar()) != EOF) {
++nc;
if (c == '\n')
++nl;
if (c == ' ' || c == '\n' || c == '\t')
state = OUT;
else if (state == OUT) {
state = IN;
++nw;
}
}
printf("%d %d %d\n", nl, nw, nc);
}
|