; LLVM IR from tfhe/spqlios-arithmetic :: spqlios/cplx (cplx_fftvec_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.cplx_addmul_precomp = type { ptr, i64 }

; Function Attrs: nounwind uwtable
define dso_local void @cplx_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 i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca double, align 8
  %15 = 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 4, ptr %9) #3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.cplx_addmul_precomp, ptr %16, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = trunc i64 %18 to i32
  store i32 %19, ptr %9, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %20, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %21, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %22, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !12
  br label %23

23:                                               ; preds = %98, %4
  %24 = load i32, ptr %13, align 4, !tbaa !12
  %25 = load i32, ptr %9, align 4, !tbaa !12
  %26 = icmp ult i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %101

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load i32, ptr %13, align 4, !tbaa !12
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds [2 x double], ptr %29, i64 %31
  %33 = getelementptr inbounds [2 x double], ptr %32, i64 0, i64 0
  %34 = load double, ptr %33, align 8, !tbaa !14
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = load i32, ptr %13, align 4, !tbaa !12
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds [2 x double], ptr %35, i64 %37
  %39 = getelementptr inbounds [2 x double], ptr %38, i64 0, i64 0
  %40 = load double, ptr %39, align 8, !tbaa !14
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = load i32, ptr %13, align 4, !tbaa !12
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds [2 x double], ptr %41, i64 %43
  %45 = getelementptr inbounds [2 x double], ptr %44, i64 0, i64 1
  %46 = load double, ptr %45, align 8, !tbaa !14
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = load i32, ptr %13, align 4, !tbaa !12
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds [2 x double], ptr %47, i64 %49
  %51 = getelementptr inbounds [2 x double], ptr %50, i64 0, i64 1
  %52 = load double, ptr %51, align 8, !tbaa !14
  %53 = fmul double %46, %52
  %54 = fneg double %53
  %55 = call double @llvm.fmuladd.f64(double %34, double %40, double %54)
  store double %55, ptr %14, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = load i32, ptr %13, align 4, !tbaa !12
  %58 = zext i32 %57 to i64
  %59 = getelementptr inbounds [2 x double], ptr %56, i64 %58
  %60 = getelementptr inbounds [2 x double], ptr %59, i64 0, i64 0
  %61 = load double, ptr %60, align 8, !tbaa !14
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = load i32, ptr %13, align 4, !tbaa !12
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds [2 x double], ptr %62, i64 %64
  %66 = getelementptr inbounds [2 x double], ptr %65, i64 0, i64 1
  %67 = load double, ptr %66, align 8, !tbaa !14
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = load i32, ptr %13, align 4, !tbaa !12
  %70 = zext i32 %69 to i64
  %71 = getelementptr inbounds [2 x double], ptr %68, i64 %70
  %72 = getelementptr inbounds [2 x double], ptr %71, i64 0, i64 1
  %73 = load double, ptr %72, align 8, !tbaa !14
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  %75 = load i32, ptr %13, align 4, !tbaa !12
  %76 = zext i32 %75 to i64
  %77 = getelementptr inbounds [2 x double], ptr %74, i64 %76
  %78 = getelementptr inbounds [2 x double], ptr %77, i64 0, i64 0
  %79 = load double, ptr %78, align 8, !tbaa !14
  %80 = fmul double %73, %79
  %81 = call double @llvm.fmuladd.f64(double %61, double %67, double %80)
  store double %81, ptr %15, align 8, !tbaa !14
  %82 = load double, ptr %14, align 8, !tbaa !14
  %83 = load ptr, ptr %12, align 8, !tbaa !5
  %84 = load i32, ptr %13, align 4, !tbaa !12
  %85 = zext i32 %84 to i64
  %86 = getelementptr inbounds [2 x double], ptr %83, i64 %85
  %87 = getelementptr inbounds [2 x double], ptr %86, i64 0, i64 0
  %88 = load double, ptr %87, align 8, !tbaa !14
  %89 = fadd double %88, %82
  store double %89, ptr %87, align 8, !tbaa !14
  %90 = load double, ptr %15, align 8, !tbaa !14
  %91 = load ptr, ptr %12, align 8, !tbaa !5
  %92 = load i32, ptr %13, align 4, !tbaa !12
  %93 = zext i32 %92 to i64
  %94 = getelementptr inbounds [2 x double], ptr %91, i64 %93
  %95 = getelementptr inbounds [2 x double], ptr %94, i64 0, i64 1
  %96 = load double, ptr %95, align 8, !tbaa !14
  %97 = fadd double %96, %90
  store double %97, ptr %95, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %98

98:                                               ; preds = %28
  %99 = load i32, ptr %13, align 4, !tbaa !12
  %100 = add i32 %99, 1
  store i32 %100, ptr %13, align 4, !tbaa !12
  br label %23, !llvm.loop !16

101:                                              ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, 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 = !{!"cplx_addmul_precomp", !6, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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 @cplx_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
  %7 = and i64 %6, 4294967295
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %wide.trip.count = and i64 %6, 4294967295
  %min.iters.check = icmp ult i64 %wide.trip.count, 4
  br i1 %min.iters.check, label %.lr.ph.preheader42, label %vector.memcheck

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

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %8 = shl nuw nsw i64 %wide.trip.count, 4
  %scevgep = getelementptr i8, ptr %1, i64 %8
  %scevgep30 = getelementptr i8, ptr %2, i64 %8
  %scevgep31 = getelementptr i8, ptr %3, i64 %8
  %bound0 = icmp ugt ptr %scevgep30, %1
  %bound1 = icmp ugt ptr %scevgep, %2
  %found.conflict = and i1 %bound0, %bound1
  %bound032 = icmp ugt ptr %scevgep31, %1
  %bound133 = icmp ugt ptr %scevgep, %3
  %found.conflict34 = and i1 %bound032, %bound133
  %conflict.rdx = or i1 %found.conflict, %found.conflict34
  br i1 %conflict.rdx, label %.lr.ph.preheader42, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.mod.vf = and i64 %6, 1
  %n.vec = sub nsw i64 %wide.trip.count, %n.mod.vf
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %9 = getelementptr inbounds [2 x double], ptr %2, i64 %index
  %wide.vec = load <4 x double>, ptr %9, align 8, !tbaa !11
  %strided.vec = shufflevector <4 x double> %wide.vec, <4 x double> poison, <2 x i32> <i32 0, i32 2>
  %strided.vec35 = shufflevector <4 x double> %wide.vec, <4 x double> poison, <2 x i32> <i32 1, i32 3>
  %10 = getelementptr inbounds [2 x double], ptr %3, i64 %index
  %wide.vec36 = load <4 x double>, ptr %10, align 8, !tbaa !11
  %strided.vec37 = shufflevector <4 x double> %wide.vec36, <4 x double> poison, <2 x i32> <i32 0, i32 2>
  %strided.vec38 = shufflevector <4 x double> %wide.vec36, <4 x double> poison, <2 x i32> <i32 1, i32 3>
  %11 = fneg <2 x double> %strided.vec35
  %12 = fmul <2 x double> %strided.vec38, %11
  %13 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %strided.vec, <2 x double> %strided.vec37, <2 x double> %12)
  %14 = fmul <2 x double> %strided.vec37, %strided.vec35
  %15 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %strided.vec, <2 x double> %strided.vec38, <2 x double> %14)
  %16 = getelementptr inbounds [2 x double], ptr %1, i64 %index
  %wide.vec39 = load <4 x double>, ptr %16, align 8, !tbaa !11
  %strided.vec40 = shufflevector <4 x double> %wide.vec39, <4 x double> poison, <2 x i32> <i32 0, i32 2>
  %strided.vec41 = shufflevector <4 x double> %wide.vec39, <4 x double> poison, <2 x i32> <i32 1, i32 3>
  %17 = fadd <2 x double> %strided.vec40, %13
  %18 = fadd <2 x double> %15, %strided.vec41
  %interleaved.vec = shufflevector <2 x double> %17, <2 x double> %18, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
  store <4 x double> %interleaved.vec, ptr %16, align 8, !tbaa !11
  %index.next = add nuw i64 %index, 2
  %19 = icmp eq i64 %index.next, %n.vec
  br i1 %19, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.mod.vf, 0
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader42

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

.lr.ph:                                           ; preds = %.lr.ph.preheader42, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader42 ]
  %20 = getelementptr inbounds [2 x double], ptr %2, i64 %indvars.iv
  %21 = load double, ptr %20, align 8, !tbaa !11
  %22 = getelementptr inbounds [2 x double], ptr %3, i64 %indvars.iv
  %23 = getelementptr inbounds i8, ptr %20, i64 8
  %24 = load double, ptr %23, align 8, !tbaa !11
  %25 = fneg double %24
  %26 = getelementptr inbounds [2 x double], ptr %1, i64 %indvars.iv
  %27 = load <2 x double>, ptr %22, align 8, !tbaa !11
  %28 = insertelement <2 x double> poison, double %24, i64 0
  %29 = insertelement <2 x double> %28, double %25, i64 1
  %30 = fmul <2 x double> %27, %29
  %31 = shufflevector <2 x double> %30, <2 x double> poison, <2 x i32> <i32 1, i32 0>
  %32 = insertelement <2 x double> poison, double %21, i64 0
  %33 = shufflevector <2 x double> %32, <2 x double> poison, <2 x i32> zeroinitializer
  %34 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %33, <2 x double> %27, <2 x double> %31)
  %35 = load <2 x double>, ptr %26, align 8, !tbaa !11
  %36 = fadd <2 x double> %35, %34
  store <2 x double> %36, ptr %26, align 8, !tbaa !11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  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>) #1

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 = { 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 = !{!"cplx_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 = 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,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass