C implementation, initial commit