Initial code acquisition of direct-sequence spread-spectrum signals is typically based on serial multidwell hypothesis tests to limit the costs of mobile terminals. The procedure that searches for the correct code and its actual time offset usually adopts a user-oriented quality criterion based on constant error rates. The false-alarm and miss detection probabilities can be theoretically evaluated by means of the class of generalized Q (GQ) functions. We show that the GQ functions constitute a useful tool not only for analytic performance analysis, but also for the optimized design of initial code synchronization systems. Some examples of application of two-dwell (search/verification) procedures are provided. The mathematical problem consists of the minimization of an objective function (i.e., the mean acquisition time) depending on four parameters (two testing durations and two thresholds) with two constraints (the probabilities of miss detection and false alarm). In particular, we have implemented and analyzed the convergence of the steepest descent and the Newton-Raphson numerical algorithms. The computational cost of the method and the effect of multipath Rayleigh channels are also discussed. The optimized acquisition procedure has evidenced a significant reduction of the mean duration of serial tests in comparison with (suboptimum) previous attempts.