// #target: macos-x64
// #opt: --fp-math=relaxed
module test;
import std::io;

fn float tester1(float a, float b, float c)
{
	return a * b + c;
}
fn float tester2(float a, float b, float c)
{
	return c + a * b;
}
fn float tester3(float a, float b, float c)
{
	c = -c;
	return a * b - c;
}
fn float tester4(float a, float b, float c)
{
	c = -c;
	return -c + a * b;
}

fn float tester5(float a, float b, float c)
{
	c = -c;
	return -(c - a * b);
}
fn float tester6(float a, float b, float c)
{
	c = -c;
	return -(-a * b + c);
}

fn void main()
{
	float a = 3.1;
	float b = 1.4;
	float c = 0.1;
	io::printfn("%f", tester1(a, b, c));
	io::printfn("%f", tester2(a, b, c));
	io::printfn("%f", tester3(a, b, c));
	io::printfn("%f", tester4(a, b, c));
	io::printfn("%f", tester5(a, b, c));
	io::printfn("%f", tester6(a, b, c));
}

/* #expect: test.ll

   %3 = call reassoc arcp contract float @llvm.fmuladd.f32(float %0, float %1, float %2)

   %3 = call reassoc arcp contract float @llvm.fmuladd.f32(float %0, float %1, float %2)

   %3 = load float, ptr %c, align 4
   %fneg = fneg reassoc arcp contract float %3
   store float %fneg, ptr %c, align 4
   %4 = load float, ptr %c, align 4
   %5 = fneg reassoc arcp contract float %4
   %6 = call reassoc arcp contract float @llvm.fmuladd.f32(float %0, float %1, float %5)

   %fneg = fneg reassoc arcp contract float %3
   store float %fneg, ptr %c, align 4
   %4 = load float, ptr %c, align 4
   %fneg1 = fneg reassoc arcp contract float %4
   %5 = call reassoc arcp contract float @llvm.fmuladd.f32(float %0, float %1, float %fneg1)

   %3 = load float, ptr %c, align 4
   %fneg = fneg reassoc arcp contract float %3
   store float %fneg, ptr %c, align 4
   %4 = load float, ptr %c, align 4
   %5 = fneg reassoc arcp contract float %1
   %6 = call reassoc arcp contract float @llvm.fmuladd.f32(float %0, float %5, float %4)
   %fneg1 = fneg reassoc arcp contract float %6

   %3 = load float, ptr %c, align 4
   %fneg = fneg reassoc arcp contract float %3
   store float %fneg, ptr %c, align 4
   %fneg1 = fneg reassoc arcp contract float %0
   %4 = load float, ptr %c, align 4
   %5 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fneg1, float %1, float %4)
   %fneg2 = fneg reassoc arcp contract float %5
