1/* PR middle-end/63762 */
2/* { dg-do assemble } */
3/* { dg-options "-O2" } */
4
5#include <stdlib.h>
6
7void *astFree ();
8void *astMalloc ();
9void astNegate (void *);
10int astGetNegated (void *);
11void astGetRegionBounds (void *, double *, double *);
12int astResampleF (void *, ...);
13
14extern int astOK;
15
16int
17MaskF (int inside, int ndim, const int lbnd[], const int ubnd[],
18       float in[], float val)
19{
20
21  void *used_region;
22  float *c, *d, *out, *tmp_out;
23  double *lbndgd, *ubndgd;
24  int *lbndg, *ubndg, idim, ipix, nax, nin, nout, npix, npixg, result = 0;
25  if (!astOK) return result;
26  lbndg = astMalloc (sizeof (int)*(size_t) ndim);
27  ubndg = astMalloc (sizeof (int)*(size_t) ndim);
28  lbndgd = astMalloc (sizeof (double)*(size_t) ndim);
29  ubndgd = astMalloc (sizeof (double)*(size_t) ndim);
30  if (astOK)
31    {
32      astGetRegionBounds (used_region, lbndgd, ubndgd);
33      npix = 1;
34      npixg = 1;
35      for (idim = 0; idim < ndim; idim++)
36        {
37          lbndg[ idim ] = lbnd[ idim ];
38          ubndg[ idim ] = ubnd[ idim ];
39          npix *= (ubnd[ idim ] - lbnd[ idim ] + 1);
40          if (npixg >= 0) npixg *= (ubndg[ idim ] - lbndg[ idim ] + 1);
41        }
42      if (npixg <= 0 && astOK)
43        {
44          if ((inside != 0) == (astGetNegated( used_region ) != 0))
45            {
46              c = in;
47              for (ipix = 0; ipix < npix; ipix++) *(c++) = val;
48              result = npix;
49            }
50        }
51      else if (npixg > 0 && astOK)
52        {
53          if ((inside != 0) == (astGetNegated (used_region) != 0))
54            {
55              tmp_out = astMalloc (sizeof (float)*(size_t) npix);
56              if (tmp_out)
57                {
58                  c = tmp_out;
59                  for (ipix = 0; ipix < npix; ipix++) *(c++) = val;
60                  result = npix - npixg;
61                }
62              out = tmp_out;
63            }
64          else
65            {
66              tmp_out = NULL;
67              out = in;
68            }
69          if (inside) astNegate (used_region);
70          result += astResampleF (used_region, ndim, lbnd, ubnd, in, NULL,
71                                  NULL, NULL, 0, 0.0, 100, val, ndim,
72                                  lbnd, ubnd, lbndg, ubndg, out, NULL);
73          if (inside) astNegate (used_region);
74        }
75    }
76  return result;
77}
78