Your very close. Nicey done. Here is the full soultion.
(int) - casts an int
void ***q = pointer to pointer to pointer to void.
malloc(8) = pointer to 8 writable bytes.
"*q=q" = set the first 4 of those bytes to point to themselves.
Like if the bytes are at 0x11223344, the list of bytes will go 0x44,0x33,0x22,0x11,?,?,?,?.
"*((long long *)*q)" = retrieve that pointer.
Then cast is as a pointer to a long long, then derefrenced.
At that point, q = *q, because we did *q=q
So it's equivalent to "*((long long*)q)", and the "0x012345678abcdef;" stores that 64-bit hex value into the memory location.
Those 8 bytes are set to 0xef,0xcd,0xab,0x78,0x56,0x34,0x12 or something to that effect.
First Byte = 0xef, so *((char*)q) = (char)0xef
255=-1,255=-2,etc.
0xef=239
239=-16