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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @reim_fft_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
  %19 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %19, ptr %10, align 8, !tbaa !5
  %20 = load i64, ptr %9, align 8, !tbaa !5
  %21 = urem i64 %20, 2
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %35

23:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %24 = load i64, ptr %10, align 8, !tbaa !5
  %25 = lshr i64 %24, 1
  store i64 %25, ptr %11, align 8, !tbaa !5
  %26 = load i64, ptr %11, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = load ptr, ptr %8, align 8, !tbaa !9
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  call void @reim_twiddle_fft_ref(i64 noundef %26, ptr noundef %27, ptr noundef %28, ptr noundef %30)
  %31 = load ptr, ptr %8, align 8, !tbaa !9
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds double, ptr %32, i64 2
  store ptr %33, ptr %31, align 8, !tbaa !9
  %34 = load i64, ptr %11, align 8, !tbaa !5
  store i64 %34, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %35

35:                                               ; preds = %23, %4
  br label %36

36:                                               ; preds = %64, %35
  %37 = load i64, ptr %10, align 8, !tbaa !5
  %38 = icmp ugt i64 %37, 16
  br i1 %38, label %39, label %66

39:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %40 = load i64, ptr %10, align 8, !tbaa !5
  %41 = lshr i64 %40, 2
  store i64 %41, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store i64 0, ptr %13, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %60, %39
  %43 = load i64, ptr %13, align 8, !tbaa !5
  %44 = load i64, ptr %5, align 8, !tbaa !5
  %45 = icmp ult i64 %43, %44
  br i1 %45, label %47, label %46

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

47:                                               ; preds = %42
  %48 = load i64, ptr %12, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !9
  %50 = load i64, ptr %13, align 8, !tbaa !5
  %51 = getelementptr inbounds double, ptr %49, i64 %50
  %52 = load ptr, ptr %7, align 8, !tbaa !9
  %53 = load i64, ptr %13, align 8, !tbaa !5
  %54 = getelementptr inbounds double, ptr %52, i64 %53
  %55 = load ptr, ptr %8, align 8, !tbaa !9
  %56 = load ptr, ptr %55, align 8, !tbaa !9
  call void @reim_bitwiddle_fft_ref(i64 noundef %48, ptr noundef %51, ptr noundef %54, ptr noundef %56)
  %57 = load ptr, ptr %8, align 8, !tbaa !9
  %58 = load ptr, ptr %57, align 8, !tbaa !9
  %59 = getelementptr inbounds double, ptr %58, i64 4
  store ptr %59, ptr %57, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %47
  %61 = load i64, ptr %10, align 8, !tbaa !5
  %62 = load i64, ptr %13, align 8, !tbaa !5
  %63 = add i64 %62, %61
  store i64 %63, ptr %13, align 8, !tbaa !5
  br label %42, !llvm.loop !11

64:                                               ; preds = %46
  %65 = load i64, ptr %12, align 8, !tbaa !5
  store i64 %65, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %36, !llvm.loop !13

66:                                               ; preds = %36
  %67 = load i64, ptr %10, align 8, !tbaa !5
  %68 = icmp ne i64 %67, 16
  br i1 %68, label %69, label %70

69:                                               ; preds = %66
  call void @abort() #5
  unreachable

70:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store i64 0, ptr %14, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %88, %70
  %72 = load i64, ptr %14, align 8, !tbaa !5
  %73 = load i64, ptr %5, align 8, !tbaa !5
  %74 = icmp ult i64 %72, %73
  br i1 %74, label %76, label %75

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

76:                                               ; preds = %71
  %77 = load ptr, ptr %6, align 8, !tbaa !9
  %78 = load i64, ptr %14, align 8, !tbaa !5
  %79 = getelementptr inbounds double, ptr %77, i64 %78
  %80 = load ptr, ptr %7, align 8, !tbaa !9
  %81 = load i64, ptr %14, align 8, !tbaa !5
  %82 = getelementptr inbounds double, ptr %80, i64 %81
  %83 = load ptr, ptr %8, align 8, !tbaa !9
  %84 = load ptr, ptr %83, align 8, !tbaa !9
  call void @reim_fft16_ref(ptr noundef %79, ptr noundef %82, ptr noundef %84)
  %85 = load ptr, ptr %8, align 8, !tbaa !9
  %86 = load ptr, ptr %85, align 8, !tbaa !9
  %87 = getelementptr inbounds double, ptr %86, i64 16
  store ptr %87, ptr %85, align 8, !tbaa !9
  br label %88

88:                                               ; preds = %76
  %89 = load i64, ptr %14, align 8, !tbaa !5
  %90 = add i64 %89, 16
  store i64 %90, ptr %14, align 8, !tbaa !5
  br label %71, !llvm.loop !14

91:                                               ; preds = %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #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_fft16_ref(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @reim_fft_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
  %8 = and i64 %7, 1
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %14, label %9

9:                                                ; preds = %4
  %10 = lshr i64 %0, 1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  tail call void @reim_twiddle_fft_ref(i64 noundef %10, ptr noundef %1, ptr noundef %2, ptr noundef %11)
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  store ptr %13, ptr %3, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %9, %4
  %.034 = phi i64 [ %10, %9 ], [ %0, %4 ]
  %15 = icmp ugt i64 %.034, 16
  br i1 %15, label %.lr.ph38, label %._crit_edge

.lr.ph38:                                         ; preds = %14
  %.not41 = icmp eq i64 %0, 0
  br i1 %.not41, label %.loopexit, label %.lr.ph.us.preheader

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

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %..loopexit_crit_edge.us
  %.pre = phi ptr [ %22, %..loopexit_crit_edge.us ], [ %.pre.pre, %.lr.ph.us.preheader ]
  %.137.us = phi i64 [ %16, %..loopexit_crit_edge.us ], [ %.034, %.lr.ph.us.preheader ]
  %16 = lshr i64 %.137.us, 2
  br label %17

17:                                               ; preds = %.lr.ph.us, %17
  %18 = phi ptr [ %.pre, %.lr.ph.us ], [ %22, %17 ]
  %.03336.us = phi i64 [ 0, %.lr.ph.us ], [ %23, %17 ]
  %19 = getelementptr inbounds double, ptr %1, i64 %.03336.us
  %20 = getelementptr inbounds double, ptr %2, i64 %.03336.us
  tail call void @reim_bitwiddle_fft_ref(i64 noundef %16, ptr noundef %19, ptr noundef %20, ptr noundef %18)
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 32
  store ptr %22, ptr %3, align 8, !tbaa !5
  %23 = add i64 %.03336.us, %.137.us
  %24 = icmp ult i64 %23, %0
  br i1 %24, label %17, label %..loopexit_crit_edge.us, !llvm.loop !9

..loopexit_crit_edge.us:                          ; preds = %17
  %25 = icmp ugt i64 %.137.us, 67
  br i1 %25, label %.lr.ph.us, label %._crit_edge, !llvm.loop !11

.loopexit:                                        ; preds = %.lr.ph38, %.loopexit
  %.137 = phi i64 [ %26, %.loopexit ], [ %.034, %.lr.ph38 ]
  %26 = lshr i64 %.137, 2
  %27 = icmp ugt i64 %.137, 67
  br i1 %27, label %.loopexit, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %..loopexit_crit_edge.us, %.loopexit, %14
  %.1.lcssa = phi i64 [ %.034, %14 ], [ %26, %.loopexit ], [ %16, %..loopexit_crit_edge.us ]
  %.not35 = icmp eq i64 %.1.lcssa, 16
  br i1 %.not35, label %.preheader, label %28

.preheader:                                       ; preds = %._crit_edge
  %.not42 = icmp eq i64 %0, 0
  br i1 %.not42, label %._crit_edge40, label %.lr.ph.preheader

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

28:                                               ; preds = %._crit_edge
  tail call void @abort() #4
  unreachable

._crit_edge40:                                    ; preds = %.lr.ph, %.preheader
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %29 = phi ptr [ %33, %.lr.ph ], [ %.pre45, %.lr.ph.preheader ]
  %.039 = phi i64 [ %34, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %30 = getelementptr inbounds double, ptr %1, i64 %.039
  %31 = getelementptr inbounds double, ptr %2, i64 %.039
  tail call void @reim_fft16_ref(ptr noundef %30, ptr noundef %31, ptr noundef %29)
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 128
  store ptr %33, ptr %3, align 8, !tbaa !5
  %34 = add i64 %.039, 16
  %35 = icmp ult i64 %34, %0
  br i1 %35, label %.lr.ph, label %._crit_edge40, !llvm.loop !12
}

; 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: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass