; LLVM IR from tfhe/spqlios-arithmetic :: spqlios/reim (reim_fftvec_addmul_ref)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.reim_mul_precomp = type { ptr, i64 }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @reim_fftvec_mul_ref(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.reim_mul_precomp, ptr %13, i32 0, i32 1
  %15 = load i64, ptr %14, align 8, !tbaa !9
  store i64 %15, ptr %9, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !12
  br label %16

16:                                               ; preds = %77, %4
  %17 = load i64, ptr %10, align 8, !tbaa !12
  %18 = load i64, ptr %9, align 8, !tbaa !12
  %19 = icmp ult i64 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %80

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load i64, ptr %10, align 8, !tbaa !12
  %24 = getelementptr inbounds double, ptr %22, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !13
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load i64, ptr %10, align 8, !tbaa !12
  %28 = getelementptr inbounds double, ptr %26, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !13
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load i64, ptr %10, align 8, !tbaa !12
  %32 = load i64, ptr %9, align 8, !tbaa !12
  %33 = add i64 %31, %32
  %34 = getelementptr inbounds double, ptr %30, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !13
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load i64, ptr %10, align 8, !tbaa !12
  %38 = load i64, ptr %9, align 8, !tbaa !12
  %39 = add i64 %37, %38
  %40 = getelementptr inbounds double, ptr %36, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !13
  %42 = fmul double %35, %41
  %43 = fneg double %42
  %44 = call double @llvm.fmuladd.f64(double %25, double %29, double %43)
  store double %44, ptr %11, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load i64, ptr %10, align 8, !tbaa !12
  %47 = getelementptr inbounds double, ptr %45, i64 %46
  %48 = load double, ptr %47, align 8, !tbaa !13
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load i64, ptr %10, align 8, !tbaa !12
  %51 = load i64, ptr %9, align 8, !tbaa !12
  %52 = add i64 %50, %51
  %53 = getelementptr inbounds double, ptr %49, i64 %52
  %54 = load double, ptr %53, align 8, !tbaa !13
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = load i64, ptr %10, align 8, !tbaa !12
  %57 = load i64, ptr %9, align 8, !tbaa !12
  %58 = add i64 %56, %57
  %59 = getelementptr inbounds double, ptr %55, i64 %58
  %60 = load double, ptr %59, align 8, !tbaa !13
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load i64, ptr %10, align 8, !tbaa !12
  %63 = getelementptr inbounds double, ptr %61, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !13
  %65 = fmul double %60, %64
  %66 = call double @llvm.fmuladd.f64(double %48, double %54, double %65)
  store double %66, ptr %12, align 8, !tbaa !13
  %67 = load double, ptr %11, align 8, !tbaa !13
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = load i64, ptr %10, align 8, !tbaa !12
  %70 = getelementptr inbounds double, ptr %68, i64 %69
  store double %67, ptr %70, align 8, !tbaa !13
  %71 = load double, ptr %12, align 8, !tbaa !13
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = load i64, ptr %10, align 8, !tbaa !12
  %74 = load i64, ptr %9, align 8, !tbaa !12
  %75 = add i64 %73, %74
  %76 = getelementptr inbounds double, ptr %72, i64 %75
  store double %71, ptr %76, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %77

77:                                               ; preds = %21
  %78 = load i64, ptr %10, align 8, !tbaa !12
  %79 = add i64 %78, 1
  store i64 %79, ptr %10, align 8, !tbaa !12
  br label %16, !llvm.loop !15

80:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"reim_mul_precomp", !6, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @reim_fftvec_mul_ref(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3) local_unnamed_addr #1 {
  %5 = ptrtoint ptr %3 to i64
  %6 = ptrtoint ptr %2 to i64
  %7 = ptrtoint ptr %1 to i64
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %.not = icmp eq i64 %9, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %min.iters.check = icmp ult i64 %9, 10
  br i1 %min.iters.check, label %.lr.ph.preheader44, label %vector.memcheck

.lr.ph.preheader44:                               ; preds = %middle.block, %vector.memcheck, %.lr.ph.preheader
  %.031.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %10 = sub i64 %7, %6
  %diff.check = icmp ult i64 %10, 16
  %11 = shl i64 %9, 3
  %12 = add i64 %11, %7
  %13 = sub i64 %12, %6
  %diff.check32 = icmp ult i64 %13, 16
  %conflict.rdx = or i1 %diff.check, %diff.check32
  %14 = sub i64 %7, %5
  %diff.check33 = icmp ult i64 %14, 16
  %conflict.rdx34 = or i1 %conflict.rdx, %diff.check33
  %15 = add i64 %11, %7
  %16 = sub i64 %15, %5
  %diff.check35 = icmp ult i64 %16, 16
  %conflict.rdx36 = or i1 %conflict.rdx34, %diff.check35
  %17 = add i64 %11, %6
  %18 = sub i64 %7, %17
  %diff.check37 = icmp ult i64 %18, 16
  %conflict.rdx38 = or i1 %conflict.rdx36, %diff.check37
  %19 = add i64 %11, %5
  %20 = sub i64 %7, %19
  %diff.check39 = icmp ult i64 %20, 16
  %conflict.rdx40 = or i1 %conflict.rdx38, %diff.check39
  br i1 %conflict.rdx40, label %.lr.ph.preheader44, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %9, -2
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %21 = getelementptr inbounds double, ptr %2, i64 %index
  %wide.load = load <2 x double>, ptr %21, align 8, !tbaa !11
  %22 = getelementptr inbounds double, ptr %3, i64 %index
  %wide.load41 = load <2 x double>, ptr %22, align 8, !tbaa !11
  %23 = add i64 %index, %9
  %24 = getelementptr inbounds double, ptr %2, i64 %23
  %wide.load42 = load <2 x double>, ptr %24, align 8, !tbaa !11
  %25 = getelementptr inbounds double, ptr %3, i64 %23
  %wide.load43 = load <2 x double>, ptr %25, align 8, !tbaa !11
  %26 = fneg <2 x double> %wide.load42
  %27 = fmul <2 x double> %wide.load43, %26
  %28 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %wide.load, <2 x double> %wide.load41, <2 x double> %27)
  %29 = fmul <2 x double> %wide.load41, %wide.load42
  %30 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %wide.load, <2 x double> %wide.load43, <2 x double> %29)
  %31 = getelementptr inbounds double, ptr %1, i64 %index
  store <2 x double> %28, ptr %31, align 8, !tbaa !11
  %32 = getelementptr inbounds double, ptr %1, i64 %23
  store <2 x double> %30, ptr %32, align 8, !tbaa !11
  %index.next = add nuw i64 %index, 2
  %33 = icmp eq i64 %index.next, %n.vec
  br i1 %33, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %9, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader44

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %4
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader44, %.lr.ph
  %.031 = phi i64 [ %50, %.lr.ph ], [ %.031.ph, %.lr.ph.preheader44 ]
  %34 = getelementptr inbounds double, ptr %2, i64 %.031
  %35 = load double, ptr %34, align 8, !tbaa !11
  %36 = getelementptr inbounds double, ptr %3, i64 %.031
  %37 = load double, ptr %36, align 8, !tbaa !11
  %38 = add i64 %.031, %9
  %39 = getelementptr inbounds double, ptr %2, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = getelementptr inbounds double, ptr %3, i64 %38
  %42 = load double, ptr %41, align 8, !tbaa !11
  %43 = fneg double %40
  %44 = fmul double %42, %43
  %45 = tail call double @llvm.fmuladd.f64(double %35, double %37, double %44)
  %46 = fmul double %37, %40
  %47 = tail call double @llvm.fmuladd.f64(double %35, double %42, double %46)
  %48 = getelementptr inbounds double, ptr %1, i64 %.031
  store double %45, ptr %48, align 8, !tbaa !11
  %49 = getelementptr inbounds double, ptr %1, i64 %38
  store double %47, ptr %49, align 8, !tbaa !11
  %50 = add nuw i64 %.031, 1
  %exitcond.not = icmp eq i64 %50, %9
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !10, i64 8}
!6 = !{!"reim_mul_precomp", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !8, i64 0}
!13 = distinct !{!13, !14, !15, !16}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !14, !15}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass