; LLVM IR from tfhe/spqlios-arithmetic :: spqlios/reim (reim_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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @reim_invtwiddle_ifft_ref(i64 noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @reim_invbitwiddle_ifft_ref(i64 noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @reim_ifft_bfs_16_ref(i64 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i64, 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 i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  store i64 %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %15 = load i64, ptr %5, align 8, !tbaa !5
  %16 = uitofp i64 %15 to double
  %17 = call double @log2(double noundef %16) #4
  %18 = fptoui double %17 to i64
  store i64 %18, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %10, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %36, %4
  %20 = load i64, ptr %10, align 8, !tbaa !5
  %21 = load i64, ptr %5, align 8, !tbaa !5
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %39

24:                                               ; preds = %19
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  %26 = load i64, ptr %10, align 8, !tbaa !5
  %27 = getelementptr inbounds double, ptr %25, i64 %26
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = load i64, ptr %10, align 8, !tbaa !5
  %30 = getelementptr inbounds double, ptr %28, i64 %29
  %31 = load ptr, ptr %8, align 8, !tbaa !9
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  call void @reim_ifft16_ref(ptr noundef %27, ptr noundef %30, ptr noundef %32)
  %33 = load ptr, ptr %8, align 8, !tbaa !9
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  %35 = getelementptr inbounds double, ptr %34, i64 16
  store ptr %35, ptr %33, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %24
  %37 = load i64, ptr %10, align 8, !tbaa !5
  %38 = add i64 %37, 16
  store i64 %38, ptr %10, align 8, !tbaa !5
  br label %19, !llvm.loop !11

39:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 16, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %40 = load i64, ptr %5, align 8, !tbaa !5
  %41 = udiv i64 %40, 2
  store i64 %41, ptr %12, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %71, %39
  %43 = load i64, ptr %11, align 8, !tbaa !5
  %44 = load i64, ptr %12, align 8, !tbaa !5
  %45 = icmp ult i64 %43, %44
  br i1 %45, label %46, label %73

46:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %47 = load i64, ptr %11, align 8, !tbaa !5
  %48 = shl i64 %47, 2
  store i64 %48, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store i64 0, ptr %14, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %67, %46
  %50 = load i64, ptr %14, align 8, !tbaa !5
  %51 = load i64, ptr %5, align 8, !tbaa !5
  %52 = icmp ult i64 %50, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %71

54:                                               ; preds = %49
  %55 = load i64, ptr %11, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !9
  %57 = load i64, ptr %14, align 8, !tbaa !5
  %58 = getelementptr inbounds double, ptr %56, i64 %57
  %59 = load ptr, ptr %7, align 8, !tbaa !9
  %60 = load i64, ptr %14, align 8, !tbaa !5
  %61 = getelementptr inbounds double, ptr %59, i64 %60
  %62 = load ptr, ptr %8, align 8, !tbaa !9
  %63 = load ptr, ptr %62, align 8, !tbaa !9
  call void @reim_invbitwiddle_ifft_ref(i64 noundef %55, ptr noundef %58, ptr noundef %61, ptr noundef %63)
  %64 = load ptr, ptr %8, align 8, !tbaa !9
  %65 = load ptr, ptr %64, align 8, !tbaa !9
  %66 = getelementptr inbounds double, ptr %65, i64 4
  store ptr %66, ptr %64, align 8, !tbaa !9
  br label %67

67:                                               ; preds = %54
  %68 = load i64, ptr %13, align 8, !tbaa !5
  %69 = load i64, ptr %14, align 8, !tbaa !5
  %70 = add i64 %69, %68
  store i64 %70, ptr %14, align 8, !tbaa !5
  br label %49, !llvm.loop !13

71:                                               ; preds = %53
  %72 = load i64, ptr %13, align 8, !tbaa !5
  store i64 %72, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %42, !llvm.loop !14

73:                                               ; preds = %42
  %74 = load i64, ptr %9, align 8, !tbaa !5
  %75 = urem i64 %74, 2
  %76 = icmp ne i64 %75, 0
  br i1 %76, label %77, label %92

77:                                               ; preds = %73
  %78 = load i64, ptr %11, align 8, !tbaa !5
  %79 = load i64, ptr %12, align 8, !tbaa !5
  %80 = icmp ne i64 %78, %79
  br i1 %80, label %81, label %82

81:                                               ; preds = %77
  call void @abort() #5
  unreachable

82:                                               ; preds = %77
  %83 = load i64, ptr %11, align 8, !tbaa !5
  %84 = load ptr, ptr %6, align 8, !tbaa !9
  %85 = load ptr, ptr %7, align 8, !tbaa !9
  %86 = load ptr, ptr %8, align 8, !tbaa !9
  %87 = load ptr, ptr %86, align 8, !tbaa !9
  call void @reim_invtwiddle_ifft_ref(i64 noundef %83, ptr noundef %84, ptr noundef %85, ptr noundef %87)
  %88 = load ptr, ptr %8, align 8, !tbaa !9
  %89 = load ptr, ptr %88, align 8, !tbaa !9
  %90 = getelementptr inbounds double, ptr %89, i64 2
  store ptr %90, ptr %88, align 8, !tbaa !9
  %91 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %91, ptr %11, align 8, !tbaa !5
  br label %92

92:                                               ; preds = %82, %73
  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 %9) #4
  ret void
}

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

; Function Attrs: noreturn nounwind
declare void @abort() #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { noreturn 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 = { nounwind }
attributes #5 = { noreturn 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 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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

; Function Attrs: nounwind uwtable
declare dso_local void @reim_invtwiddle_ifft_ref(i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @reim_invbitwiddle_ifft_ref(i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @reim_ifft_bfs_16_ref(i64 noundef %0, ptr noundef %1, ptr noundef %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = uitofp i64 %0 to double
  %6 = tail call double @log2(double noundef %5) #3
  %7 = fptoui double %6 to i64
  %.not47 = icmp eq i64 %0, 0
  br i1 %.not47, label %._crit_edge46, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %.pre = load ptr, ptr %3, align 8, !tbaa !5
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  %8 = lshr i64 %0, 1
  %9 = icmp ugt i64 %0, 33
  br i1 %9, label %.lr.ph42.us.preheader, label %._crit_edge46

.lr.ph42.us.preheader:                            ; preds = %._crit_edge
  %.pre49.pre = load ptr, ptr %3, align 8, !tbaa !5
  br label %.lr.ph42.us

.lr.ph42.us:                                      ; preds = %.lr.ph42.us.preheader, %..loopexit_crit_edge.us
  %.pre49 = phi ptr [ %16, %..loopexit_crit_edge.us ], [ %.pre49.pre, %.lr.ph42.us.preheader ]
  %.03543.us = phi i64 [ %10, %..loopexit_crit_edge.us ], [ 16, %.lr.ph42.us.preheader ]
  %10 = shl i64 %.03543.us, 2
  br label %11

11:                                               ; preds = %.lr.ph42.us, %11
  %12 = phi ptr [ %.pre49, %.lr.ph42.us ], [ %16, %11 ]
  %.040.us = phi i64 [ 0, %.lr.ph42.us ], [ %17, %11 ]
  %13 = getelementptr inbounds double, ptr %1, i64 %.040.us
  %14 = getelementptr inbounds double, ptr %2, i64 %.040.us
  tail call void @reim_invbitwiddle_ifft_ref(i64 noundef %.03543.us, ptr noundef %13, ptr noundef %14, ptr noundef %12)
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 32
  store ptr %16, ptr %3, align 8, !tbaa !5
  %17 = add i64 %.040.us, %10
  %18 = icmp ult i64 %17, %0
  br i1 %18, label %11, label %..loopexit_crit_edge.us, !llvm.loop !9

..loopexit_crit_edge.us:                          ; preds = %11
  %19 = icmp ult i64 %10, %8
  br i1 %19, label %.lr.ph42.us, label %._crit_edge46, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %20 = phi ptr [ %24, %.lr.ph ], [ %.pre, %.lr.ph.preheader ]
  %.03439 = phi i64 [ %25, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %21 = getelementptr inbounds double, ptr %1, i64 %.03439
  %22 = getelementptr inbounds double, ptr %2, i64 %.03439
  tail call void @reim_ifft16_ref(ptr noundef %21, ptr noundef %22, ptr noundef %20)
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 128
  store ptr %24, ptr %3, align 8, !tbaa !5
  %25 = add i64 %.03439, 16
  %26 = icmp ult i64 %25, %0
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge46:                                    ; preds = %..loopexit_crit_edge.us, %4, %._crit_edge
  %27 = phi i64 [ %8, %._crit_edge ], [ 0, %4 ], [ %8, %..loopexit_crit_edge.us ]
  %.035.lcssa = phi i64 [ 16, %._crit_edge ], [ 16, %4 ], [ %10, %..loopexit_crit_edge.us ]
  %28 = and i64 %7, 1
  %.not = icmp eq i64 %28, 0
  br i1 %.not, label %35, label %29

29:                                               ; preds = %._crit_edge46
  %.not38 = icmp eq i64 %.035.lcssa, %27
  br i1 %.not38, label %31, label %30

30:                                               ; preds = %29
  tail call void @abort() #4
  unreachable

31:                                               ; preds = %29
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  tail call void @reim_invtwiddle_ifft_ref(i64 noundef %27, ptr noundef %1, ptr noundef %2, ptr noundef %32)
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 16
  store ptr %34, ptr %3, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %31, %._crit_edge46
  ret void
}

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

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #2

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 = { 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 = { noreturn 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 }
attributes #4 = { noreturn 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}


; Effective O3 passes: ADCEPass,CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass