1c5f01b2fSopenharmony_ci// This file is distributed under the University of Illinois Open Source
2c5f01b2fSopenharmony_ci// License. See LICENSE.TXT for details.
3c5f01b2fSopenharmony_ci
4c5f01b2fSopenharmony_ci// Source code for a simple DSO.
5c5f01b2fSopenharmony_ci
6c5f01b2fSopenharmony_ci#include <cstdint>
7c5f01b2fSopenharmony_ci#include <cstdlib>
8c5f01b2fSopenharmony_ci#include <cstring>
9c5f01b2fSopenharmony_ci#include <cstdio>
10c5f01b2fSopenharmony_ciextern int DSO1(int a);
11c5f01b2fSopenharmony_ciextern int DSO2(int a);
12c5f01b2fSopenharmony_ciextern int DSOTestExtra(int a);
13c5f01b2fSopenharmony_ci
14c5f01b2fSopenharmony_cistatic volatile int *nil = 0;
15c5f01b2fSopenharmony_ci
16c5f01b2fSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
17c5f01b2fSopenharmony_ci  int x, y, z;
18c5f01b2fSopenharmony_ci  if (Size < sizeof(int) * 3) {
19c5f01b2fSopenharmony_ci    x = y = z = 0;
20c5f01b2fSopenharmony_ci  } else {
21c5f01b2fSopenharmony_ci    memcpy(&x, Data + 0 * sizeof(int), sizeof(int));
22c5f01b2fSopenharmony_ci    memcpy(&y, Data + 1 * sizeof(int), sizeof(int));
23c5f01b2fSopenharmony_ci    memcpy(&z, Data + 2 * sizeof(int), sizeof(int));
24c5f01b2fSopenharmony_ci  }
25c5f01b2fSopenharmony_ci  int sum = DSO1(x) + DSO2(y) + (z ? DSOTestExtra(z) : 0);
26c5f01b2fSopenharmony_ci  if (sum == 3) {
27c5f01b2fSopenharmony_ci    fprintf(stderr, "BINGO %d %d %d\n", x, y, z);
28c5f01b2fSopenharmony_ci    *nil = 0;
29c5f01b2fSopenharmony_ci  }
30c5f01b2fSopenharmony_ci  return 0;
31c5f01b2fSopenharmony_ci}
32