quebex

A software analysis framework built around the QBE intermediate language

git clone https://git.8pit.net/quebex.git

 1// SPDX-FileCopyrightText: 2024 University of Bremen
 2// SPDX-FileCopyrightText: 2025 Sören Tempel <soeren+git@soeren-tempel.net>
 3//
 4// SPDX-License-Identifier: MIT AND GPL-3.0-only
 5
 6static unsigned
 7first_divisor(unsigned a)
 8{
 9	unsigned i;
10
11	for (i = 2; i < a; i++) {
12		if (a % i == 0) {
13			return i;
14		}
15	}
16
17	return a;
18}
19
20unsigned
21entry(unsigned a)
22{
23	// Written in this convoluted way to avoid phi instructions,
24	// which (at the time of writing) quebex doesn't support yet.
25	if (a <= 50) {
26		unsigned b = a;
27		if (b <= 1) {
28			return 0;
29		} else {
30			unsigned c = b;
31			if (first_divisor(c) == c) {
32				return 1;
33			} else {
34				return 0;
35			}
36		}
37	}
38
39	return 0;
40}