CLANG = ~/.clang/bin/clang++ --gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/11 -mavx
#-march=native -mprefer-vector-width=512

all: test.ll test.s test.hwsan.ll cve.hwsan.ll cve.hwsan.s cve.hwsan test.hwsan.s test.swsan.ll cve.swsan.ll cve.swsan test.swsan.s

clean:
	rm test.ll test.s test.hwsan.ll cve.hwsan.ll cve.hwsan.s cve.hwsan test.hwsan.s test.swsan.ll cve.swsan.ll cve.swsan test.swsan.s passes.log

test.ll: test.cpp
	$(CLANG) -O3 test.cpp -S -emit-llvm -o test.ll

test.s: test.cpp
	$(CLANG) -O3 test.cpp -S -masm=intel -o test.s

test.hwsan.ll: test.cpp
	$(CLANG) -O3 -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-hw-support=2 test.cpp -S -emit-llvm -o test.hwsan.ll -mllvm --metadata-to-check -mllvm -print-changed -mllvm -print-module-scope -mllvm -filter-print-funcs=_Z15ihevce_had4_4x4PhiS_iPsiPiii 2> passes.log
	$(CLANG) -O3 -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-hw-support=2 test.cpp -S -emit-llvm -o test.hwsan.ll -mllvm --metadata-to-check

cve.hwsan.ll: cve.cpp
	$(CLANG) -O3 -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-hw-support=2 cve.cpp -S -emit-llvm -o cve.hwsan.ll -mllvm --disable-instcombine -mllvm --metadata-to-check

cve.hwsan.s: cve.cpp
	$(CLANG) -O3 -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-hw-support=2 cve.cpp -S -masm=intel -o cve.hwsan.s -mllvm --disable-instcombine -mllvm --optimize-after-metadata-to-intrinsic

cve.hwsan: cve.cpp aux.cpp
	$(CLANG) -O3 -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-hw-support=2 cve.cpp aux.cpp -o cve.hwsan -mllvm --disable-instcombine -mllvm --optimize-after-metadata-to-intrinsic

test.hwsan.s: test.cpp
	$(CLANG) -O3 -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-hw-support=1 test.cpp -S -masm=intel -o test.hwsan.s -mllvm -print-after-all 2> test.log

test.swsan.ll: test.cpp
	$(CLANG) -O3 -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-hw-support=0 test.cpp -S -emit-llvm -o test.swsan.ll

cve.swsan.ll: cve.cpp
	$(CLANG) -O3 -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-hw-support=0 cve.cpp -S -emit-llvm -o cve.swsan.ll

cve.swsan: cve.cpp aux.cpp
	$(CLANG) -O3 -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-hw-support=0 cve.cpp aux.cpp -o cve.swsan

test.swsan.s: test.cpp
	$(CLANG) -O3 -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-hw-support=0 test.cpp -S -masm=intel -o test.swsan.s
