rewrite ZigZag
rewrite reverse int with overflow check