; 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_addmul_precomp = type { ptr, i64 }

; Function Attrs: nounwind uwtable
define dso_local void @reim_fftvec_addmul_ref(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %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_addmul_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 = %81, %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 %84

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
  %71 = load double, ptr %70, align 8, !tbaa !13
  %72 = fadd double %71, %67
  store double %72, ptr %70, align 8, !tbaa !13
  %73 = load double, ptr %12, align 8, !tbaa !13
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = load i64, ptr %10, align 8, !tbaa !12
  %76 = load i64, ptr %9, align 8, !tbaa !12
  %77 = add i64 %75, %76
  %78 = getelementptr inbounds double, ptr %74, i64 %77
  %79 = load double, ptr %78, align 8, !tbaa !13
  %80 = fadd double %79, %73
  store double %80, ptr %78, 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 %81

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

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

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

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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_addmul_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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @reim_fftvec_addmul_ref(ptr nocapture noundef readonly %0, ptr nocapture noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %min.iters.check = icmp ult i64 %6, 12
  br i1 %min.iters.check, label %.lr.ph.preheader69, label %vector.memcheck

.lr.ph.preheader69:                               ; 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
  %7 = shl i64 %6, 3
  %scevgep = getelementptr i8, ptr %1, i64 %7
  %8 = shl i64 %6, 4
  %scevgep32 = getelementptr i8, ptr %1, i64 %8
  %scevgep33 = getelementptr i8, ptr %2, i64 %7
  %scevgep34 = getelementptr i8, ptr %2, i64 %8
  %scevgep35 = getelementptr i8, ptr %3, i64 %7
  %scevgep36 = getelementptr i8, ptr %3, i64 %8
  %bound0 = icmp ult ptr %scevgep, %scevgep34
  %bound1 = icmp ult ptr %scevgep33, %scevgep32
  %found.conflict = and i1 %bound0, %bound1
  %bound037 = icmp ult ptr %1, %2
  %bound138 = icmp ugt ptr %scevgep32, %2
  %found.conflict39 = and i1 %bound037, %bound138
  %conflict.rdx = or i1 %found.conflict, %found.conflict39
  %bound040 = icmp ult ptr %scevgep, %scevgep36
  %bound141 = icmp ult ptr %scevgep35, %scevgep32
  %found.conflict42 = and i1 %bound040, %bound141
  %conflict.rdx43 = or i1 %conflict.rdx, %found.conflict42
  %bound044 = icmp ult ptr %1, %3
  %bound145 = icmp ugt ptr %scevgep32, %3
  %found.conflict46 = and i1 %bound044, %bound145
  %conflict.rdx47 = or i1 %conflict.rdx43, %found.conflict46
  %bound048 = icmp ugt ptr %scevgep34, %1
  %bound149 = icmp ult ptr %2, %1
  %found.conflict50 = and i1 %bound048, %bound149
  %conflict.rdx51 = or i1 %conflict.rdx47, %found.conflict50
  %bound052 = icmp ugt ptr %scevgep33, %1
  %bound153 = icmp ugt ptr %scevgep, %2
  %found.conflict54 = and i1 %bound052, %bound153
  %conflict.rdx55 = or i1 %conflict.rdx51, %found.conflict54
  %bound056 = icmp ugt ptr %scevgep36, %1
  %bound157 = icmp ult ptr %3, %1
  %found.conflict58 = and i1 %bound056, %bound157
  %conflict.rdx59 = or i1 %conflict.rdx55, %found.conflict58
  %bound060 = icmp ugt ptr %scevgep35, %1
  %bound161 = icmp ugt ptr %scevgep, %3
  %found.conflict62 = and i1 %bound060, %bound161
  %conflict.rdx63 = or i1 %conflict.rdx59, %found.conflict62
  br i1 %conflict.rdx63, label %.lr.ph.preheader69, label %vector.ph

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

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %9 = getelementptr inbounds double, ptr %2, i64 %index
  %wide.load = load <2 x double>, ptr %9, align 8, !tbaa !11, !alias.scope !13
  %10 = getelementptr inbounds double, ptr %3, i64 %index
  %wide.load64 = load <2 x double>, ptr %10, align 8, !tbaa !11, !alias.scope !16
  %11 = add i64 %index, %6
  %12 = getelementptr inbounds double, ptr %2, i64 %11
  %wide.load65 = load <2 x double>, ptr %12, align 8, !tbaa !11, !alias.scope !18
  %13 = getelementptr inbounds double, ptr %3, i64 %11
  %wide.load66 = load <2 x double>, ptr %13, align 8, !tbaa !11, !alias.scope !20
  %14 = fneg <2 x double> %wide.load65
  %15 = fmul <2 x double> %wide.load66, %14
  %16 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %wide.load, <2 x double> %wide.load64, <2 x double> %15)
  %17 = fmul <2 x double> %wide.load64, %wide.load65
  %18 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %wide.load, <2 x double> %wide.load66, <2 x double> %17)
  %19 = getelementptr inbounds double, ptr %1, i64 %index
  %wide.load67 = load <2 x double>, ptr %19, align 8, !tbaa !11, !alias.scope !22, !noalias !24
  %20 = fadd <2 x double> %wide.load67, %16
  store <2 x double> %20, ptr %19, align 8, !tbaa !11, !alias.scope !22, !noalias !24
  %21 = getelementptr inbounds double, ptr %1, i64 %11
  %wide.load68 = load <2 x double>, ptr %21, align 8, !tbaa !11, !alias.scope !25, !noalias !24
  %22 = fadd <2 x double> %18, %wide.load68
  store <2 x double> %22, ptr %21, align 8, !tbaa !11, !alias.scope !25, !noalias !24
  %index.next = add nuw i64 %index, 2
  %23 = icmp eq i64 %index.next, %n.vec
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !27

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

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

.lr.ph:                                           ; preds = %.lr.ph.preheader69, %.lr.ph
  %.031 = phi i64 [ %44, %.lr.ph ], [ %.031.ph, %.lr.ph.preheader69 ]
  %24 = getelementptr inbounds double, ptr %2, i64 %.031
  %25 = load double, ptr %24, align 8, !tbaa !11
  %26 = getelementptr inbounds double, ptr %3, i64 %.031
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = add i64 %.031, %6
  %29 = getelementptr inbounds double, ptr %2, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !11
  %31 = getelementptr inbounds double, ptr %3, i64 %28
  %32 = load double, ptr %31, align 8, !tbaa !11
  %33 = fneg double %30
  %34 = fmul double %32, %33
  %35 = tail call double @llvm.fmuladd.f64(double %25, double %27, double %34)
  %36 = fmul double %27, %30
  %37 = tail call double @llvm.fmuladd.f64(double %25, double %32, double %36)
  %38 = getelementptr inbounds double, ptr %1, i64 %.031
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = fadd double %39, %35
  store double %40, ptr %38, align 8, !tbaa !11
  %41 = getelementptr inbounds double, ptr %1, i64 %28
  %42 = load double, ptr %41, align 8, !tbaa !11
  %43 = fadd double %37, %42
  store double %43, ptr %41, align 8, !tbaa !11
  %44 = add nuw i64 %.031, 1
  %exitcond.not = icmp eq i64 %44, %6
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !31
}

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

; 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 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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_addmul_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 = !{!14}
!14 = distinct !{!14, !15}
!15 = distinct !{!15, !"LVerDomain"}
!16 = !{!17}
!17 = distinct !{!17, !15}
!18 = !{!19}
!19 = distinct !{!19, !15}
!20 = !{!21}
!21 = distinct !{!21, !15}
!22 = !{!23}
!23 = distinct !{!23, !15}
!24 = !{!19, !14, !21, !17}
!25 = !{!26}
!26 = distinct !{!26, !15}
!27 = distinct !{!27, !28, !29, !30}
!28 = !{!"llvm.loop.mustprogress"}
!29 = !{!"llvm.loop.isvectorized", i32 1}
!30 = !{!"llvm.loop.unroll.runtime.disable"}
!31 = distinct !{!31, !28, !29}


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