{
integer a_dim1, a_offset, i__1, i__2, i__3;
integer i__, j, nb, kk, nx, iws;
extern logical lsame_(char *, char *);
integer nbmin, iinfo;
logical upper;
extern
int ssytd2_fla(char *, integer *, real *, integer *, real *, real *, real *, integer *), ssyr2k_(char *, char * , integer *, integer *, real *, real *, integer *, real *, integer *, real *, real *, integer *), xerbla_( char *, integer *);
extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *);
extern
int slatrd_(char *, integer *, integer *, real *, integer *, real *, real *, real *, integer *);
integer ldwork, lwkopt;
logical lquery;
a_dim1 = *lda;
a_offset = 1 + a_dim1;
a -= a_offset;
--d__;
--e;
--tau;
--work;
*info = 0;
upper = lsame_(uplo, "U");
lquery = *lwork == -1;
if (! upper && ! lsame_(uplo, "L"))
{
*info = -1;
}
else if (*n < 0)
{
*info = -2;
}
else if (*lda < max(1,*n))
{
*info = -4;
}
else if (*lwork < 1 && ! lquery)
{
*info = -9;
}
if (*info == 0)
{
nb = ilaenv_(&c__1, "SSYTRD", uplo, n, &c_n1, &c_n1, &c_n1);
lwkopt = *n * nb;
work[1] = (real) lwkopt;
}
if (*info != 0)
{
i__1 = -(*info);
xerbla_("SSYTRD", &i__1);
return 0;
}
else if (lquery)
{
return 0;
}
if (*n == 0)
{
work[1] = 1.f;
return 0;
}
nx = *n;
iws = 1;
if (nb > 1 && nb < *n)
{
i__1 = nb;
i__2 = ilaenv_(&c__3, "SSYTRD", uplo, n, &c_n1, &c_n1, & c_n1);
nx = max(i__1,i__2);
if (nx < *n)
{
ldwork = *n;
iws = ldwork * nb;
if (*lwork < iws)
{
i__1 = *lwork / ldwork;
nb = max(i__1,1);
nbmin = ilaenv_(&c__2, "SSYTRD", uplo, n, &c_n1, &c_n1, &c_n1);
if (nb < nbmin)
{
nx = *n;
}
}
}
else
{
nx = *n;
}
}
else
{
nb = 1;
}
if (upper)
{
kk = *n - (*n - nx + nb - 1) / nb * nb;
i__1 = kk + 1;
i__2 = -nb;
for (i__ = *n - nb + 1;
i__2 < 0 ? i__ >= i__1 : i__ <= i__1;
i__ += i__2)
{
i__3 = i__ + nb - 1;
slatrd_(uplo, &i__3, &nb, &a[a_offset], lda, &e[1], &tau[1], & work[1], &ldwork);
i__3 = i__ - 1;
ssyr2k_(uplo, "No transpose", &i__3, &nb, &c_b22, &a[i__ * a_dim1 + 1], lda, &work[1], &ldwork, &c_b23, &a[a_offset], lda);
i__3 = i__ + nb - 1;
for (j = i__;
j <= i__3;
++j)
{
a[j - 1 + j * a_dim1] = e[j - 1];
d__[j] = a[j + j * a_dim1];
}
}
ssytd2_fla(uplo, &kk, &a[a_offset], lda, &d__[1], &e[1], &tau[1], &iinfo);
}
else
{
i__2 = *n - nx;
i__1 = nb;
for (i__ = 1;
i__1 < 0 ? i__ >= i__2 : i__ <= i__2;
i__ += i__1)
{
i__3 = *n - i__ + 1;
slatrd_(uplo, &i__3, &nb, &a[i__ + i__ * a_dim1], lda, &e[i__], & tau[i__], &work[1], &ldwork);
i__3 = *n - i__ - nb + 1;
ssyr2k_(uplo, "No transpose", &i__3, &nb, &c_b22, &a[i__ + nb + i__ * a_dim1], lda, &work[nb + 1], &ldwork, &c_b23, &a[ i__ + nb + (i__ + nb) * a_dim1], lda);
i__3 = i__ + nb - 1;
for (j = i__;
j <= i__3;
++j)
{
a[j + 1 + j * a_dim1] = e[j];
d__[j] = a[j + j * a_dim1];
}
}
i__1 = *n - i__ + 1;
ssytd2_fla(uplo, &i__1, &a[i__ + i__ * a_dim1], lda, &d__[i__], &e[i__], &tau[i__], &iinfo);
}
work[1] = (real) lwkopt;
return 0;
}