I used to check all eight adjacent tiles if they are the same type or not, and then draw the autotile accordingly. I had two variables, one for sides, one for corners. Each of them was actually kind like a 4-bit flag. I set them according to the adjacent tiles, and then I had a huge (16-element, duh) case of sides_variable. Like, if no adjacent autotiles, draw the "single spock", if only one adjacent autotile, draw the connecting gfx on one half, and on the other half draw corners (which can be either inside or outside facing).

If you'd like, I can share some code, but you'll have to give me some time to add comments et cetera so it can be readable.