; LLVM IR from tfhe/spqlios-arithmetic :: spqlios/cplx (cplx_ifft_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 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
declare dso_local void @cplx_set_e2pimx(ptr noundef, double noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @cplx_ifft16_precomp(double noundef, ptr noundef) #2

; Function Attrs: nounwind
declare double @log2(double noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @fill_cplx_ifft_omegas_bfs_16(double noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store double %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %13 = load i32, ptr %6, align 4, !tbaa !11
  %14 = uitofp i32 %13 to double
  %15 = call double @log2(double noundef %14) #5
  %16 = fptoui double %15 to i64
  store i64 %16, ptr %7, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %17 = load double, ptr %4, align 8, !tbaa !5
  %18 = fmul double %17, 1.600000e+01
  %19 = load i32, ptr %6, align 4, !tbaa !11
  %20 = uitofp i32 %19 to double
  %21 = fdiv double %18, %20
  store double %21, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %22

22:                                               ; preds = %34, %3
  %23 = load i32, ptr %9, align 4, !tbaa !11
  %24 = load i32, ptr %6, align 4, !tbaa !11
  %25 = udiv i32 %24, 16
  %26 = icmp ult i32 %23, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %37

28:                                               ; preds = %22
  %29 = load double, ptr %8, align 8, !tbaa !5
  %30 = load i32, ptr %9, align 4, !tbaa !11
  %31 = call double @fracrevbits(i32 noundef %30)
  %32 = fadd double %29, %31
  %33 = load ptr, ptr %5, align 8, !tbaa !9
  call void @cplx_ifft16_precomp(double noundef %32, ptr noundef %33)
  br label %34

34:                                               ; preds = %28
  %35 = load i32, ptr %9, align 4, !tbaa !11
  %36 = add i32 %35, 1
  store i32 %36, ptr %9, align 4, !tbaa !11
  br label %22, !llvm.loop !15

37:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 16, ptr %10, align 4, !tbaa !11
  %38 = load i64, ptr %7, align 8, !tbaa !13
  %39 = urem i64 %38, 2
  %40 = icmp ne i64 %39, 0
  br i1 %40, label %41, label %70

41:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %42

42:                                               ; preds = %64, %41
  %43 = load i32, ptr %11, align 4, !tbaa !11
  %44 = load i32, ptr %6, align 4, !tbaa !11
  %45 = load i32, ptr %10, align 4, !tbaa !11
  %46 = mul nsw i32 2, %45
  %47 = udiv i32 %44, %46
  %48 = icmp ult i32 %43, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %67

50:                                               ; preds = %42
  %51 = load ptr, ptr %5, align 8, !tbaa !9
  %52 = getelementptr inbounds ptr, ptr %51, i64 0
  %53 = load ptr, ptr %52, align 8, !tbaa !9
  %54 = getelementptr inbounds [2 x double], ptr %53, i64 0
  %55 = getelementptr inbounds [2 x double], ptr %54, i64 0, i64 0
  %56 = load double, ptr %8, align 8, !tbaa !5
  %57 = load i32, ptr %11, align 4, !tbaa !11
  %58 = call double @fracrevbits(i32 noundef %57)
  %59 = fdiv double %58, 2.000000e+00
  %60 = fadd double %56, %59
  call void @cplx_set_e2pimx(ptr noundef %55, double noundef %60)
  %61 = load ptr, ptr %5, align 8, !tbaa !9
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  %63 = getelementptr inbounds [2 x double], ptr %62, i64 1
  store ptr %63, ptr %61, align 8, !tbaa !9
  br label %64

64:                                               ; preds = %50
  %65 = load i32, ptr %11, align 4, !tbaa !11
  %66 = add i32 %65, 1
  store i32 %66, ptr %11, align 4, !tbaa !11
  br label %42, !llvm.loop !17

67:                                               ; preds = %49
  %68 = load double, ptr %8, align 8, !tbaa !5
  %69 = fmul double %68, 2.000000e+00
  store double %69, ptr %8, align 8, !tbaa !5
  store i32 32, ptr %10, align 4, !tbaa !11
  br label %70

70:                                               ; preds = %67, %37
  br label %71

71:                                               ; preds = %113, %70
  %72 = load i32, ptr %10, align 4, !tbaa !11
  %73 = load i32, ptr %6, align 4, !tbaa !11
  %74 = icmp ult i32 %72, %73
  br i1 %74, label %75, label %116

75:                                               ; preds = %71
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %76

76:                                               ; preds = %107, %75
  %77 = load i32, ptr %12, align 4, !tbaa !11
  %78 = load i32, ptr %6, align 4, !tbaa !11
  %79 = load i32, ptr %10, align 4, !tbaa !11
  %80 = mul nsw i32 2, %79
  %81 = udiv i32 %78, %80
  %82 = icmp ult i32 %77, %81
  br i1 %82, label %84, label %83

83:                                               ; preds = %76
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %110

84:                                               ; preds = %76
  %85 = load ptr, ptr %5, align 8, !tbaa !9
  %86 = getelementptr inbounds ptr, ptr %85, i64 0
  %87 = load ptr, ptr %86, align 8, !tbaa !9
  %88 = getelementptr inbounds [2 x double], ptr %87, i64 0
  %89 = getelementptr inbounds [2 x double], ptr %88, i64 0, i64 0
  %90 = load double, ptr %8, align 8, !tbaa !5
  %91 = load i32, ptr %12, align 4, !tbaa !11
  %92 = call double @fracrevbits(i32 noundef %91)
  %93 = fdiv double %92, 2.000000e+00
  %94 = fadd double %90, %93
  call void @cplx_set_e2pimx(ptr noundef %89, double noundef %94)
  %95 = load ptr, ptr %5, align 8, !tbaa !9
  %96 = getelementptr inbounds ptr, ptr %95, i64 0
  %97 = load ptr, ptr %96, align 8, !tbaa !9
  %98 = getelementptr inbounds [2 x double], ptr %97, i64 1
  %99 = getelementptr inbounds [2 x double], ptr %98, i64 0, i64 0
  %100 = load double, ptr %8, align 8, !tbaa !5
  %101 = load i32, ptr %12, align 4, !tbaa !11
  %102 = call double @fracrevbits(i32 noundef %101)
  %103 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %100, double %102)
  call void @cplx_set_e2pimx(ptr noundef %99, double noundef %103)
  %104 = load ptr, ptr %5, align 8, !tbaa !9
  %105 = load ptr, ptr %104, align 8, !tbaa !9
  %106 = getelementptr inbounds [2 x double], ptr %105, i64 2
  store ptr %106, ptr %104, align 8, !tbaa !9
  br label %107

107:                                              ; preds = %84
  %108 = load i32, ptr %12, align 4, !tbaa !11
  %109 = add i32 %108, 2
  store i32 %109, ptr %12, align 4, !tbaa !11
  br label %76, !llvm.loop !18

110:                                              ; preds = %83
  %111 = load double, ptr %8, align 8, !tbaa !5
  %112 = fmul double %111, 4.000000e+00
  store double %112, ptr %8, align 8, !tbaa !5
  br label %113

113:                                              ; preds = %110
  %114 = load i32, ptr %10, align 4, !tbaa !11
  %115 = shl i32 %114, 2
  store i32 %115, ptr %10, align 4, !tbaa !11
  br label %71, !llvm.loop !19

116:                                              ; preds = %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret void
}

declare double @fracrevbits(i32 noundef) #4

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 "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 = { "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 #5 = { 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, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}
!19 = distinct !{!19, !16}


; 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: nounwind uwtable
declare dso_local void @cplx_set_e2pimx(ptr noundef, double noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @cplx_ifft16_precomp(double noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @fill_cplx_ifft_omegas_bfs_16(double noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = uitofp i32 %2 to double
  %5 = tail call double @log2(double noundef %4) #4
  %6 = fptoui double %5 to i64
  %7 = fmul double %0, 1.600000e+01
  %8 = fdiv double %7, %4
  %9 = lshr i32 %2, 4
  %.not50 = icmp ult i32 %2, 16
  br i1 %.not50, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %3
  %10 = and i64 %6, 1
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %23, label %.preheader39

.preheader39:                                     ; preds = %._crit_edge
  %11 = lshr i32 %2, 5
  %.not51 = icmp ult i32 %2, 32
  br i1 %.not51, label %._crit_edge43, label %.lr.ph42.preheader

.lr.ph42.preheader:                               ; preds = %.preheader39
  %.pre = load ptr, ptr %1, align 8, !tbaa !5
  br label %.lr.ph42

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.03540 = phi i32 [ %14, %.lr.ph ], [ 0, %3 ]
  %12 = tail call double @fracrevbits(i32 noundef %.03540) #4
  %13 = fadd double %8, %12
  tail call void @cplx_ifft16_precomp(double noundef %13, ptr noundef %1)
  %14 = add nuw nsw i32 %.03540, 1
  %exitcond.not = icmp eq i32 %14, %9
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge43:                                    ; preds = %.lr.ph42, %.preheader39
  %15 = fmul double %8, 2.000000e+00
  br label %23

.lr.ph42:                                         ; preds = %.lr.ph42.preheader, %.lr.ph42
  %16 = phi ptr [ %21, %.lr.ph42 ], [ %.pre, %.lr.ph42.preheader ]
  %.03341 = phi i32 [ %22, %.lr.ph42 ], [ 0, %.lr.ph42.preheader ]
  %17 = tail call double @fracrevbits(i32 noundef %.03341) #4
  %18 = fmul double %17, 5.000000e-01
  %19 = fadd double %8, %18
  tail call void @cplx_set_e2pimx(ptr noundef %16, double noundef %19)
  %20 = load ptr, ptr %1, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  store ptr %21, ptr %1, align 8, !tbaa !5
  %22 = add nuw nsw i32 %.03341, 1
  %exitcond53.not = icmp eq i32 %22, %11
  br i1 %exitcond53.not, label %._crit_edge43, label %.lr.ph42, !llvm.loop !11

23:                                               ; preds = %._crit_edge43, %._crit_edge
  %.036 = phi double [ %15, %._crit_edge43 ], [ %8, %._crit_edge ]
  %.034 = phi i32 [ 32, %._crit_edge43 ], [ 16, %._crit_edge ]
  %24 = icmp ult i32 %.034, %2
  br i1 %24, label %.preheader, label %._crit_edge49

.preheader:                                       ; preds = %23, %._crit_edge46
  %.148 = phi i32 [ %28, %._crit_edge46 ], [ %.034, %23 ]
  %.13747 = phi double [ %27, %._crit_edge46 ], [ %.036, %23 ]
  %25 = shl nsw i32 %.148, 1
  %26 = udiv i32 %2, %25
  %.not52 = icmp ugt i32 %25, %2
  br i1 %.not52, label %._crit_edge46, label %.lr.ph45.preheader

.lr.ph45.preheader:                               ; preds = %.preheader
  %.pre54 = load ptr, ptr %1, align 8, !tbaa !5
  br label %.lr.ph45

._crit_edge46:                                    ; preds = %.lr.ph45, %.preheader
  %27 = fmul double %.13747, 4.000000e+00
  %28 = shl i32 %.148, 2
  %29 = icmp ult i32 %28, %2
  br i1 %29, label %.preheader, label %._crit_edge49, !llvm.loop !12

.lr.ph45:                                         ; preds = %.lr.ph45.preheader, %.lr.ph45
  %30 = phi ptr [ %39, %.lr.ph45 ], [ %.pre54, %.lr.ph45.preheader ]
  %.044 = phi i32 [ %40, %.lr.ph45 ], [ 0, %.lr.ph45.preheader ]
  %31 = tail call double @fracrevbits(i32 noundef %.044) #4
  %32 = fmul double %31, 5.000000e-01
  %33 = fadd double %.13747, %32
  tail call void @cplx_set_e2pimx(ptr noundef %30, double noundef %33)
  %34 = load ptr, ptr %1, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 16
  %36 = tail call double @fracrevbits(i32 noundef %.044) #4
  %37 = tail call double @llvm.fmuladd.f64(double %.13747, double 2.000000e+00, double %36)
  tail call void @cplx_set_e2pimx(ptr noundef nonnull %35, double noundef %37)
  %38 = load ptr, ptr %1, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i64 32
  store ptr %39, ptr %1, align 8, !tbaa !5
  %40 = add i32 %.044, 2
  %41 = icmp ult i32 %40, %26
  br i1 %41, label %.lr.ph45, label %._crit_edge46, !llvm.loop !13

._crit_edge49:                                    ; preds = %._crit_edge46, %23
  ret void
}

declare double @fracrevbits(i32 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #2 = { 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 #3 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass