Skip to content

Instantly share code, notes, and snippets.

@xacrimon
Created May 4, 2025 23:09
Show Gist options
  • Save xacrimon/dcda0a7b8f0ac36119ad8a7926ab426d to your computer and use it in GitHub Desktop.
Save xacrimon/dcda0a7b8f0ac36119ad8a7926ab426d to your computer and use it in GitHub Desktop.
Checking cmap v0.1.0 (/Users/joelwejdenstal/repos/cmap)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2024::*;
#[macro_use]
extern crate std;
use std::hint;
use cmap::map;
#[unsafe(no_mangle)]
#[inline(never)]
pub fn convert(s: &str) -> Option<i32> {
const fn parse(bytes: &[u8]) -> Option<i32> {
use typenum::*;
use std::ops::{Sub, Add, Shr, Mul};
use typenum::uint::*;
trait Counter {
type Next: Counter;
const COUNT: usize;
}
struct CounterImpl<Field>
where
Field: Unsigned,
{
_field: std::marker::PhantomData<Field>,
}
impl Counter for CounterImpl<U0> {
type Next = CounterImpl<U0>;
const COUNT: usize = 0;
}
impl<Field> Counter for CounterImpl<UInt<Field, B1>>
where
UInt<Field, B1>: Unsigned + Shr<U1>,
<UInt<Field, B1> as Shr<U1>>::Output: Unsigned + Shr<U1>,
CounterImpl<<UInt<Field, B1> as Shr<U1>>::Output>: Counter,
{
type Next = CounterImpl<<UInt<Field, B1> as Shr<U1>>::Output>;
const COUNT: usize = const {
<UInt<Field, B1> as Unsigned>::USIZE.count_ones() as usize
};
}
trait AsCounter {
type Counter: Counter;
}
struct FieldMap<const N: usize>(std::marker::PhantomData<[(); N]>);
impl<const N: usize> AsCounter for FieldMap<N>
where
Const<N>: ToUInt,
<Const<N> as ToUInt>::Output: Unsigned,
CounterImpl<U<N>>: Counter,
{
type Counter = CounterImpl<U<N>>;
}
#[inline(always)]
const fn cmp_wrapper<const N: usize, const R: usize>(a: &[u8], b: &[u8]) -> bool
where
FieldMap<N>: AsCounter,
{
cmp::<<FieldMap<N> as AsCounter>::Counter, N, R>(a.as_ptr(), b.as_ptr())
}
#[inline(always)]
const fn cmp<C, const END: usize, const R: usize>(
a: *const u8,
b: *const u8,
) -> bool
where
C: Counter,
{
#[inline(always)]
const fn adv(x: *const u8) -> *const u8 {
unsafe { x.add(8) }
}
if const { C::COUNT > 0 } {
let b0 = unsafe { std::ptr::read_unaligned(a as *const u64) }
== unsafe { std::ptr::read_unaligned(b as *const u64) };
let b1 = cmp::<C::Next, END, R>(adv(a), adv(b));
b0 && b1
} else if const { R == 0 } {
true
} else if const { R == 1 } {
(unsafe { std::ptr::read_unaligned(a as *const u8) })
== unsafe { std::ptr::read_unaligned(b as *const u8) }
} else if const { R == 2 } {
(unsafe { std::ptr::read_unaligned(a as *const u16) })
== unsafe { std::ptr::read_unaligned(b as *const u16) }
} else if const { R == 3 } {
(unsafe { std::ptr::read_unaligned(a as *const u16) })
== unsafe { std::ptr::read_unaligned(b as *const u16) }
&& unsafe { std::ptr::read_unaligned(a.add(2) as *const u8) }
== unsafe { std::ptr::read_unaligned(b.add(2) as *const u8) }
} else if const { R == 4 } {
(unsafe { std::ptr::read_unaligned(a as *const u32) })
== unsafe { std::ptr::read_unaligned(b as *const u32) }
} else if const { R == 5 } {
(unsafe { std::ptr::read_unaligned(a as *const u32) })
== unsafe { std::ptr::read_unaligned(b as *const u32) }
&& unsafe { std::ptr::read_unaligned(a.add(4) as *const u8) }
== unsafe { std::ptr::read_unaligned(b.add(4) as *const u8) }
} else if const { R == 6 } {
(unsafe { std::ptr::read_unaligned(a as *const u32) })
== unsafe { std::ptr::read_unaligned(b as *const u32) }
&& unsafe { std::ptr::read_unaligned(a.add(4) as *const u16) }
== unsafe { std::ptr::read_unaligned(b.add(4) as *const u16) }
} else if const { R == 7 } {
(unsafe { std::ptr::read_unaligned(a as *const u32) })
== unsafe { std::ptr::read_unaligned(b as *const u32) }
&& unsafe { std::ptr::read_unaligned(a.add(4) as *const u16) }
== unsafe { std::ptr::read_unaligned(b.add(4) as *const u16) }
&& unsafe { std::ptr::read_unaligned(a.add(6) as *const u8) }
== unsafe { std::ptr::read_unaligned(b.add(6) as *const u8) }
} else {
unsafe {
std::hint::unreachable_unchecked();
}
}
}
match bytes.len() {
5usize => {
let &[_i0, _i1, _i2, _i3, _i4] = bytes else {
unsafe { std::hint::unreachable_unchecked() }
};
if cmp_wrapper::<
0usize,
5usize,
>(
unsafe {
std::slice::from_raw_parts(bytes.as_ptr().add(0usize), 5usize)
},
&[97u8, 112u8, 112u8, 108u8, 101u8],
) {
return Some(0);
}
None
}
6usize => {
let &[_i0, _i1, _i2, _i3, _i4, _i5] = bytes else {
unsafe { std::hint::unreachable_unchecked() }
};
if _i1 == 97u8 {
if _i5 == 116u8 {
if _i0 == 99u8
&& cmp_wrapper::<
0usize,
3usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(2usize),
3usize,
)
},
&[114u8, 114u8, 111u8],
)
{
return Some(2);
}
} else {
if _i4 == 110u8 {
if _i0 == 98u8
&& cmp_wrapper::<
0usize,
2usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(2usize),
2usize,
)
},
&[110u8, 97u8],
)
{
return Some(1);
}
} else {
if _i0 == 104u8
&& cmp_wrapper::<
0usize,
2usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(2usize),
2usize,
)
},
&[103u8, 103u8],
)
{
return Some(7);
}
}
}
} else {
if _i5 == 116u8 {
if _i0 == 121u8
&& cmp_wrapper::<
0usize,
2usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(2usize),
2usize,
)
},
&[103u8, 117u8],
)
{
return Some(24);
}
} else {
if _i4 == 111u8 {
if _i0 == 113u8
&& cmp_wrapper::<
0usize,
2usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(2usize),
2usize,
)
},
&[105u8, 110u8],
)
{
return Some(16);
}
} else {
if _i0 == 103u8
&& cmp_wrapper::<
0usize,
2usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(2usize),
2usize,
)
},
&[97u8, 112u8],
)
{
return Some(6);
}
}
}
}
None
}
7usize => {
let &[_i0, _i1, _i2, _i3, _i4, _i5, _i6] = bytes else {
unsafe { std::hint::unreachable_unchecked() }
};
if cmp_wrapper::<
0usize,
7usize,
>(
unsafe {
std::slice::from_raw_parts(bytes.as_ptr().add(0usize), 7usize)
},
&[111u8, 114u8, 97u8, 110u8, 103u8, 101u8, 115u8],
) {
return Some(14);
}
if cmp_wrapper::<
0usize,
7usize,
>(
unsafe {
std::slice::from_raw_parts(bytes.as_ptr().add(0usize), 7usize)
},
&[118u8, 97u8, 110u8, 105u8, 108u8, 108u8, 97u8],
) {
return Some(21);
}
None
}
8usize => {
let &[_i0, _i1, _i2, _i3, _i4, _i5, _i6, _i7] = bytes else {
unsafe { std::hint::unreachable_unchecked() }
};
if _i5 == 97u8 {
if _i7 == 121u8 {
if cmp_wrapper::<
0usize,
5usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(0usize),
5usize,
)
},
&[114u8, 111u8, 115u8, 101u8, 109u8],
) && _i6 == 114u8
{
return Some(17);
}
} else {
if _i6 == 110u8 {
if cmp_wrapper::<
0usize,
5usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(0usize),
5usize,
)
},
&[101u8, 103u8, 103u8, 112u8, 108u8],
) {
return Some(4);
}
} else {
if cmp_wrapper::<
0usize,
5usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(0usize),
5usize,
)
},
&[108u8, 101u8, 109u8, 111u8, 110u8],
) {
return Some(11);
}
}
}
} else {
if _i4 == 104u8 {
if _i7 == 116u8 {
if cmp_wrapper::<
0usize,
4usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(0usize),
4usize,
)
},
&[100u8, 111u8, 117u8, 103u8],
) {
return Some(3);
}
} else {
if cmp_wrapper::<
0usize,
4usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(0usize),
4usize,
)
},
&[122u8, 117u8, 99u8, 99u8],
) {
return Some(25);
}
}
} else {
if cmp_wrapper::<
0usize,
4usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(0usize),
4usize,
)
},
&[116u8, 111u8, 109u8, 97u8],
) {
return Some(19);
}
}
}
None
}
9usize => {
let &[_i0, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8] = bytes else {
unsafe { std::hint::unreachable_unchecked() }
};
if cmp_wrapper::<
1usize,
1usize,
>(
unsafe {
std::slice::from_raw_parts(bytes.as_ptr().add(0usize), 9usize)
},
&[105u8, 99u8, 101u8, 32u8, 99u8, 114u8, 101u8, 97u8, 109u8],
) {
return Some(8);
}
if cmp_wrapper::<
1usize,
1usize,
>(
unsafe {
std::slice::from_raw_parts(bytes.as_ptr().add(0usize), 9usize)
},
&[115u8, 111u8, 117u8, 114u8, 100u8, 111u8, 117u8, 103u8, 104u8],
) {
return Some(18);
}
None
}
10usize => {
let &[_i0, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8, _i9] = bytes else {
unsafe { std::hint::unreachable_unchecked() }
};
if _i9 == 115u8 {
if _i8 == 101u8 {
if _i4 == 97u8 {
if _i7 == 110u8 {
if cmp_wrapper::<
0usize,
4usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(0usize),
4usize,
)
},
&[110u8, 101u8, 99u8, 116u8],
)
&& cmp_wrapper::<
0usize,
2usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(5usize),
2usize,
)
},
&[114u8, 105u8],
)
{
return Some(13);
}
} else {
if cmp_wrapper::<
0usize,
4usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(0usize),
4usize,
)
},
&[112u8, 105u8, 110u8, 101u8],
)
&& cmp_wrapper::<
0usize,
2usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(5usize),
2usize,
)
},
&[112u8, 112u8],
)
{
return Some(15);
}
}
}
}
} else {
if cmp_wrapper::<
0usize,
4usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(0usize),
4usize,
)
},
&[119u8, 97u8, 116u8, 101u8],
)
&& cmp_wrapper::<
0usize,
2usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(5usize),
2usize,
)
},
&[109u8, 101u8],
)
{
return Some(22);
}
}
None
}
11usize => {
let &[_i0, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8, _i9, _i10] = bytes
else { unsafe { std::hint::unreachable_unchecked() } };
if _i10 == 115u8 {
if _i9 == 119u8 {
if cmp_wrapper::<
1usize,
1usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(0usize),
9usize,
)
},
&[
109u8, 97u8, 115u8, 104u8, 109u8, 97u8, 108u8, 108u8, 111u8,
],
) {
return Some(12);
}
} else {
if cmp_wrapper::<
1usize,
1usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(0usize),
9usize,
)
},
&[106u8, 101u8, 108u8, 108u8, 121u8, 32u8, 98u8, 101u8, 97u8],
) {
return Some(9);
}
}
} else {
if cmp_wrapper::<
1usize,
1usize,
>(
unsafe {
std::slice::from_raw_parts(
bytes.as_ptr().add(0usize),
9usize,
)
},
&[102u8, 114u8, 97u8, 110u8, 107u8, 105u8, 110u8, 99u8, 101u8],
) {
return Some(5);
}
}
None
}
16usize => {
let &[_i0, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8, _i9, _i10, _i11, _i12,
_i13, _i14, _i15] = bytes else {
unsafe { std::hint::unreachable_unchecked() }
};
if cmp_wrapper::<
3usize,
0usize,
>(
unsafe {
std::slice::from_raw_parts(bytes.as_ptr().add(0usize), 16usize)
},
&[
117u8, 110u8, 108u8, 101u8, 97u8, 118u8, 101u8, 110u8, 101u8,
100u8, 32u8, 98u8, 114u8, 101u8, 97u8, 100u8,
],
) {
return Some(20);
}
if cmp_wrapper::<
3usize,
0usize,
>(
unsafe {
std::slice::from_raw_parts(bytes.as_ptr().add(0usize), 16usize)
},
&[
120u8, 105u8, 110u8, 111u8, 109u8, 97u8, 118u8, 114u8, 111u8,
32u8, 103u8, 114u8, 97u8, 112u8, 101u8, 115u8,
],
) {
return Some(23);
}
None
}
18usize => {
let &[_i0, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8, _i9, _i10, _i11, _i12,
_i13, _i14, _i15, _i16, _i17] = bytes else {
unsafe { std::hint::unreachable_unchecked() }
};
if cmp_wrapper::<
3usize,
2usize,
>(
unsafe {
std::slice::from_raw_parts(bytes.as_ptr().add(0usize), 18usize)
},
&[
107u8, 97u8, 102u8, 102u8, 105u8, 114u8, 32u8, 108u8, 105u8,
109u8, 101u8, 32u8, 108u8, 101u8, 97u8, 118u8, 101u8, 115u8,
],
) {
return Some(10);
}
None
}
_ => return None,
}
}
parse(s.as_bytes())
}
fn main() {
hint::black_box(convert(hint::black_box("983925g")));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment