summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memcmp.c
blob: fd6556d227b4d7f621bdaa1a21838eb5174d3a21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
extern void abort(void);
extern int inside_main;

__attribute__ ((__noinline__))
int
memcmp (const void *s1, const void *s2, __SIZE_TYPE__ len)
{
  const unsigned char *sp1, *sp2;

#ifdef __OPTIMIZE__
  if (inside_main)
    abort ();
#endif

  sp1 = s1;
  sp2 = s2;
  while (len != 0 && *sp1 == *sp2)
    sp1++, sp2++, len--;

  if (len == 0)
    return 0;
  return *sp1 - *sp2;
}