The cremaster muscle's function is to raise and lower the testes in order to regulate scrotal temperature for optimal spermatogenesis and survival of the resultant spermatozoa. It does this by increasing or decreasing the exposed surface area of the surrounding tissue, allowing faster or slower dissipation of body heat.