; LLVM IR from tfhe/spqlios-arithmetic :: spqlios/reim (reim_fft_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"

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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: nounwind
declare double @cos(double noundef) #2

; Function Attrs: nounwind
declare double @sin(double noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @reim_naive_fft(i64 noundef %0, double noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca i64, align 8
  %6 = alloca double, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca i64, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  store i64 %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !11
  store ptr %3, ptr %8, align 8, !tbaa !11
  %16 = load i64, ptr %5, align 8, !tbaa !5
  %17 = icmp eq i64 %16, 1
  br i1 %17, label %18, label %19

18:                                               ; preds = %4
  br label %120

19:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %20 = load i64, ptr %5, align 8, !tbaa !5
  %21 = udiv i64 %20, 2
  store i64 %21, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %22 = load double, ptr %6, align 8, !tbaa !9
  %23 = fdiv double %22, 2.000000e+00
  store double %23, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %24 = load double, ptr %10, align 8, !tbaa !9
  %25 = fmul double 0x401921FB54442D18, %24
  %26 = call double @cos(double noundef %25) #4
  store double %26, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %27 = load double, ptr %10, align 8, !tbaa !9
  %28 = fmul double 0x401921FB54442D18, %27
  %29 = call double @sin(double noundef %28) #4
  store double %29, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store i64 0, ptr %13, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %103, %19
  %31 = load i64, ptr %13, align 8, !tbaa !5
  %32 = load i64, ptr %9, align 8, !tbaa !5
  %33 = icmp ult i64 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %106

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

103:                                              ; preds = %35
  %104 = load i64, ptr %13, align 8, !tbaa !5
  %105 = add i64 %104, 1
  store i64 %105, ptr %13, align 8, !tbaa !5
  br label %30, !llvm.loop !13

106:                                              ; preds = %34
  %107 = load i64, ptr %9, align 8, !tbaa !5
  %108 = load double, ptr %10, align 8, !tbaa !9
  %109 = load ptr, ptr %7, align 8, !tbaa !11
  %110 = load ptr, ptr %8, align 8, !tbaa !11
  call void @reim_naive_fft(i64 noundef %107, double noundef %108, ptr noundef %109, ptr noundef %110)
  %111 = load i64, ptr %9, align 8, !tbaa !5
  %112 = load double, ptr %10, align 8, !tbaa !9
  %113 = fadd double %112, 5.000000e-01
  %114 = load ptr, ptr %7, align 8, !tbaa !11
  %115 = load i64, ptr %9, align 8, !tbaa !5
  %116 = getelementptr inbounds double, ptr %114, i64 %115
  %117 = load ptr, ptr %8, align 8, !tbaa !11
  %118 = load i64, ptr %9, align 8, !tbaa !5
  %119 = getelementptr inbounds double, ptr %117, i64 %118
  call void @reim_naive_fft(i64 noundef %111, double noundef %113, ptr noundef %116, ptr noundef %119)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %120

120:                                              ; preds = %106, %18
  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 "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 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 #4 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind memory(write, argmem: readwrite) uwtable
define dso_local void @reim_naive_fft(i64 noundef %0, double noundef %1, ptr nocapture noundef %2, ptr nocapture noundef %3) local_unnamed_addr #2 {
  %5 = icmp eq i64 %0, 1
  br i1 %5, label %tailrecurse._crit_edge, label %.lr.ph62

.lr.ph62:                                         ; preds = %4, %tailrecurse
  %.tr5560 = phi ptr [ %30, %tailrecurse ], [ %3, %4 ]
  %.tr5459 = phi ptr [ %29, %tailrecurse ], [ %2, %4 ]
  %.tr5358 = phi double [ %28, %tailrecurse ], [ %1, %4 ]
  %.tr57 = phi i64 [ %6, %tailrecurse ], [ %0, %4 ]
  %6 = lshr i64 %.tr57, 1
  %7 = fmul double %.tr5358, 5.000000e-01
  %8 = fmul double %7, 0x401921FB54442D18
  %9 = tail call double @cos(double noundef %8) #4
  %10 = tail call double @sin(double noundef %8) #4
  %.not = icmp ult i64 %.tr57, 2
  br i1 %.not, label %tailrecurse, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph62
  %min.iters.check = icmp ult i64 %.tr57, 8
  br i1 %min.iters.check, label %.lr.ph.preheader84, label %vector.memcheck

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

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %11 = shl i64 %6, 3
  %scevgep = getelementptr i8, ptr %.tr5459, i64 %11
  %scevgep63 = getelementptr i8, ptr %.tr5560, i64 %11
  %12 = shl i64 %6, 4
  %scevgep64 = getelementptr i8, ptr %.tr5560, i64 %12
  %scevgep65 = getelementptr i8, ptr %.tr5459, i64 %12
  %bound0 = icmp ult ptr %.tr5459, %scevgep63
  %bound1 = icmp ult ptr %.tr5560, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  %bound066 = icmp ult ptr %.tr5459, %scevgep64
  %bound167 = icmp ult ptr %.tr5560, %.tr5459
  %found.conflict68 = and i1 %bound066, %bound167
  %conflict.rdx = or i1 %found.conflict, %found.conflict68
  %bound069 = icmp ult ptr %.tr5459, %.tr5560
  %bound170 = icmp ult ptr %.tr5560, %scevgep65
  %found.conflict71 = and i1 %bound069, %bound170
  %conflict.rdx72 = or i1 %conflict.rdx, %found.conflict71
  %bound073 = icmp ult ptr %scevgep, %scevgep64
  %bound174 = icmp ult ptr %scevgep63, %scevgep65
  %found.conflict75 = and i1 %bound073, %bound174
  %conflict.rdx76 = or i1 %conflict.rdx72, %found.conflict75
  br i1 %conflict.rdx76, label %.lr.ph.preheader84, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %6, 9223372036854775806
  %broadcast.splatinsert = insertelement <2 x double> poison, double %10, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert78 = insertelement <2 x double> poison, double %9, i64 0
  %broadcast.splat79 = shufflevector <2 x double> %broadcast.splatinsert78, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %13 = add nuw i64 %index, %6
  %14 = getelementptr inbounds double, ptr %.tr5459, i64 %13
  %wide.load = load <2 x double>, ptr %14, align 8, !tbaa !5, !alias.scope !9, !noalias !12
  %15 = getelementptr inbounds double, ptr %.tr5560, i64 %13
  %wide.load77 = load <2 x double>, ptr %15, align 8, !tbaa !5, !alias.scope !15
  %16 = fneg <2 x double> %wide.load77
  %17 = fmul <2 x double> %broadcast.splat, %16
  %18 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %wide.load, <2 x double> %broadcast.splat79, <2 x double> %17)
  %19 = fmul <2 x double> %broadcast.splat, %wide.load
  %20 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %wide.load77, <2 x double> %broadcast.splat79, <2 x double> %19)
  %21 = getelementptr inbounds double, ptr %.tr5459, i64 %index
  %wide.load80 = load <2 x double>, ptr %21, align 8, !tbaa !5, !alias.scope !16, !noalias !12
  %22 = fsub <2 x double> %wide.load80, %18
  store <2 x double> %22, ptr %14, align 8, !tbaa !5, !alias.scope !9, !noalias !12
  %23 = getelementptr inbounds double, ptr %.tr5560, i64 %index
  %wide.load81 = load <2 x double>, ptr %23, align 8, !tbaa !5, !alias.scope !18
  %24 = fsub <2 x double> %wide.load81, %20
  store <2 x double> %24, ptr %15, align 8, !tbaa !5, !alias.scope !15
  %wide.load82 = load <2 x double>, ptr %21, align 8, !tbaa !5, !alias.scope !16, !noalias !12
  %25 = fadd <2 x double> %18, %wide.load82
  store <2 x double> %25, ptr %21, align 8, !tbaa !5, !alias.scope !16, !noalias !12
  %wide.load83 = load <2 x double>, ptr %23, align 8, !tbaa !5, !alias.scope !18
  %26 = fadd <2 x double> %20, %wide.load83
  store <2 x double> %26, ptr %23, align 8, !tbaa !5, !alias.scope !18
  %index.next = add nuw i64 %index, 2
  %27 = icmp eq i64 %index.next, %n.vec
  br i1 %27, label %middle.block, label %vector.body, !llvm.loop !19

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

tailrecurse:                                      ; preds = %.lr.ph, %middle.block, %.lr.ph62
  tail call void @reim_naive_fft(i64 noundef %6, double noundef %7, ptr noundef %.tr5459, ptr noundef %.tr5560)
  %28 = fadd double %7, 5.000000e-01
  %29 = getelementptr inbounds double, ptr %.tr5459, i64 %6
  %30 = getelementptr inbounds double, ptr %.tr5560, i64 %6
  %31 = icmp eq i64 %6, 1
  br i1 %31, label %tailrecurse._crit_edge, label %.lr.ph62

.lr.ph:                                           ; preds = %.lr.ph.preheader84, %.lr.ph
  %.056 = phi i64 [ %52, %.lr.ph ], [ %.056.ph, %.lr.ph.preheader84 ]
  %32 = add nuw i64 %.056, %6
  %33 = getelementptr inbounds double, ptr %.tr5459, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !5
  %35 = getelementptr inbounds double, ptr %.tr5560, i64 %32
  %36 = load double, ptr %35, align 8, !tbaa !5
  %37 = fneg double %36
  %38 = fmul double %10, %37
  %39 = tail call double @llvm.fmuladd.f64(double %34, double %9, double %38)
  %40 = fmul double %10, %34
  %41 = tail call double @llvm.fmuladd.f64(double %36, double %9, double %40)
  %42 = getelementptr inbounds double, ptr %.tr5459, i64 %.056
  %43 = load double, ptr %42, align 8, !tbaa !5
  %44 = fsub double %43, %39
  store double %44, ptr %33, align 8, !tbaa !5
  %45 = getelementptr inbounds double, ptr %.tr5560, i64 %.056
  %46 = load double, ptr %45, align 8, !tbaa !5
  %47 = fsub double %46, %41
  store double %47, ptr %35, align 8, !tbaa !5
  %48 = load double, ptr %42, align 8, !tbaa !5
  %49 = fadd double %39, %48
  store double %49, ptr %42, align 8, !tbaa !5
  %50 = load double, ptr %45, align 8, !tbaa !5
  %51 = fadd double %41, %50
  store double %51, ptr %45, align 8, !tbaa !5
  %52 = add nuw nsw i64 %.056, 1
  %exitcond.not = icmp eq i64 %52, %6
  br i1 %exitcond.not, label %tailrecurse, label %.lr.ph, !llvm.loop !23

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %4
  ret void
}

; 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>) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write) "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 = { nofree nounwind memory(write, 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13, !14}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}
!15 = !{!14}
!16 = !{!17}
!17 = distinct !{!17, !11}
!18 = !{!13}
!19 = distinct !{!19, !20, !21, !22}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!"llvm.loop.isvectorized", i32 1}
!22 = !{!"llvm.loop.unroll.runtime.disable"}
!23 = distinct !{!23, !20, !21}


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