When the ball crosses the end line and the defensive team last touched the ball?

If the defensive team touched it last it becomes a corner kick for the offensive team. If the offensive team touched it last it becomes a goal kick.