porting sub.c to sub.go