Skip to content

Instantly share code, notes, and snippets.

View ilyakurdyukov's full-sized avatar

Ilya Kurdyukov ilyakurdyukov

View GitHub Profile
@ilyakurdyukov
ilyakurdyukov / concat-hello.c
Created October 8, 2020 11:31
An example of splitting a C program into separate characters.
#include <stdio.h>
#define X(a,b) a##b
#define x(a,b) X(a,b)
#define s(a) #a
x ( i , x ( n , t
) ) x ( m , x ( a
, x ( i , n ) ) )
( ) { x ( p , x (
r , x ( i , x ( n
# include <stdlib.h>
# include <stdio.h>
#include <math.h>
#include <time.h>
/*moomin*/
#define F printf
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/time.h>
static int64_t get_time_usec() {
struct timeval time;
gettimeofday(&time, NULL);
return (int64_t)time.tv_sec * 1000000 + time.tv_usec;
}
#include <time.h>
#include <stdio.h>
int main(
){int x=- 44,
a=2551443,b=- x,
y=2-b,z=(time(0 )
-592531)%a*512/a ;
for(;y<=b;putchar (
++x>=a?x=-b,y+=4, 9
@ilyakurdyukov
ilyakurdyukov / perfume.c
Created December 5, 2020 05:47
A bottle of perfume with the fragrance of the x86/x86_64 instruction set.
char main
[/*x86*/]
__attribute__
((section(".text"))
)="WTYH)9Zj8_j7H)9]R"
"H)9^\350\0\0\0\0H)1^R"
"H))Z8<2u\366j<)9Xj9"
")9j9VY)<$[S_H\xbd^["
"H$@\xcd\200-XP\xf"
@ilyakurdyukov
ilyakurdyukov / positive.c
Created December 12, 2020 04:30
That's just another Hello World. But with heavy restrictions, no keywords, no numbers, no strings or literals, only 3 operations: x(!=0), x++, x+=y. Inspired by the "addleq" OISC.
P,o,S,i,t,I,v,E;
main(){v?(o+=o)?i+=i,i++:(
o+=t,S?E? P?i+=v:(o
+=i,o+= o,o+=o)
,o++:( (I?P?o
+=i:o ,o+=o
,o+=t ,o+=o
,o+=o :(o+=
o,o+= t,P?++ o,o+=o ,o++,
o+=o: (o+=o,++ o,o+=o,o ++)))
@ilyakurdyukov
ilyakurdyukov / fizzbuzz.c
Created December 16, 2020 08:54
Imagine that you apply for a job at Obfuscate Inc. and they ask you to write a simple program to prove your skills. How will you write it?
#include <stdio.h>
i,x=1,y, z= 1,a;main (){((a<1
)& (x >y )?
++ i- 2< 99
?a=x=i %3 ?i %5
?z *= i+ 1>
z? 10 :1 :4
:0 ,y =i%5?i%3 ?0:4:8,1
@ilyakurdyukov
ilyakurdyukov / main.c
Created November 22, 2021 09:47
SSE2 assembly to intrinsics convertor. Unfinished, but still useful for porting.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
static int is_mem(const char *s, int n) {
int a, i;
for (i = 0; i < n; i++) {
a = s[i];
if (a == '[' || a == ']') return 1;
}
@ilyakurdyukov
ilyakurdyukov / faster_lzma_decoder_x86.patch
Last active June 18, 2023 17:04
Faster LZMA decoder for x86 CPUs (patch for XZ Utils).
From 387fd25f57f41009fc317f7922e957de9f370ff2 Mon Sep 17 00:00:00 2001
From: Ilya Kurdyukov <jpegqs@gmail.com>
Date: Tue, 14 Dec 2021 21:54:32 +0700
Subject: [PATCH] faster lzma_decoder for x86
Notice: Uses inline assembly with CMOV instruction.
Another change that removes the comparison with in_size can give a few
percent speedup for architectures with a small number of registers.
---
@ilyakurdyukov
ilyakurdyukov / safesys.h
Last active January 19, 2022 04:32
Helper function for escaping special characters from user-provided strings to be used in calls to system().
#ifndef SAFESYS_H
#define SAFESYS_H
#include <stdlib.h>
#include <stdarg.h>
#ifndef SAFESYS_NOMEM
#include <errno.h>
#define SAFESYS_NOMEM ENOMEM
#endif