; LLVM IR from tfhe/spqlios-arithmetic :: spqlios/cplx (cplx_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 @cplx_fft16_ref(ptr noundef, ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @cplx_fft_ref_bfs_16(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %14, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds [2 x double], ptr %15, i64 %17
  store ptr %18, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %19 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %19, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = uitofp i32 %20 to double
  %22 = call double @log2(double noundef %21) #3
  %23 = fptoui double %22 to i32
  store i32 %23, ptr %10, align 4, !tbaa !9
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = urem i32 %24, 2
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %39

27:                                               ; preds = %3
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = udiv i32 %28, 2
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds [2 x double], ptr %32, i64 0, i64 0
  call void @cplx_twiddle_fft_ref(i32 noundef %29, ptr noundef %30, ptr noundef %33)
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = getelementptr inbounds [2 x double], ptr %35, i64 2
  store ptr %36, ptr %34, align 8, !tbaa !5
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = lshr i32 %37, 1
  store i32 %38, ptr %9, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %27, %3
  br label %40

40:                                               ; preds = %65, %39
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = icmp ugt i32 %41, 16
  br i1 %42, label %43, label %67

43:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = udiv i32 %44, 4
  store i32 %45, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %46, ptr %12, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %60, %43
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = icmp ult ptr %48, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %65

52:                                               ; preds = %47
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  call void @cplx_bitwiddle_fft_ref(i32 noundef %53, ptr noundef %54, ptr noundef %56)
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load ptr, ptr %57, align 8, !tbaa !5
  %59 = getelementptr inbounds [2 x double], ptr %58, i64 2
  store ptr %59, ptr %57, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %52
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  %63 = zext i32 %61 to i64
  %64 = getelementptr inbounds [2 x double], ptr %62, i64 %63
  store ptr %64, ptr %12, align 8, !tbaa !5
  br label %47, !llvm.loop !11

65:                                               ; preds = %51
  %66 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %66, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %40, !llvm.loop !13

67:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %68, ptr %13, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %81, %67
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = icmp ult ptr %70, %71
  br i1 %72, label %74, label %73

73:                                               ; preds = %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %84

74:                                               ; preds = %69
  %75 = load ptr, ptr %13, align 8, !tbaa !5
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = load ptr, ptr %76, align 8, !tbaa !5
  call void @cplx_fft16_ref(ptr noundef %75, ptr noundef %77)
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load ptr, ptr %78, align 8, !tbaa !5
  %80 = getelementptr inbounds [2 x double], ptr %79, i64 8
  store ptr %80, ptr %78, align 8, !tbaa !5
  br label %81

81:                                               ; preds = %74
  %82 = load ptr, ptr %13, align 8, !tbaa !5
  %83 = getelementptr inbounds [2 x double], ptr %82, i64 16
  store ptr %83, ptr %13, align 8, !tbaa !5
  br label %69, !llvm.loop !14

84:                                               ; preds = %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

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

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 = { 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, !10, i64 0}
!10 = !{!"int", !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 @cplx_fft16_ref(ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @cplx_fft_ref_bfs_16(ptr noundef %0, ptr nocapture noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = zext i32 %2 to i64
  %5 = getelementptr inbounds [2 x double], ptr %0, i64 %4
  %6 = uitofp i32 %2 to double
  %7 = tail call double @log2(double noundef %6) #2
  %8 = fptoui double %7 to i32
  %9 = and i32 %8, 1
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %15, label %10

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

15:                                               ; preds = %10, %3
  %.030 = phi i32 [ %11, %10 ], [ %2, %3 ]
  %16 = icmp ugt i32 %.030, 16
  br i1 %16, label %.lr.ph33, label %.preheader

.lr.ph33:                                         ; preds = %15
  %.not35 = icmp eq i32 %2, 0
  br i1 %.not35, label %._crit_edge, label %.lr.ph.us.preheader

.lr.ph.us.preheader:                              ; preds = %.lr.ph33
  %.pre.pre = load ptr, ptr %1, 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 ]
  %.132.us = phi i32 [ %17, %..loopexit_crit_edge.us ], [ %.030, %.lr.ph.us.preheader ]
  %17 = lshr i32 %.132.us, 2
  %18 = zext i32 %.132.us to i64
  br label %19

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

..loopexit_crit_edge.us:                          ; preds = %19
  %25 = icmp ugt i32 %.132.us, 67
  br i1 %25, label %.lr.ph.us, label %.preheader, !llvm.loop !11

.preheader:                                       ; preds = %..loopexit_crit_edge.us, %15
  %.not36 = icmp eq i32 %2, 0
  br i1 %.not36, label %._crit_edge, label %.lr.ph.preheader

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

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

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %26 = phi ptr [ %28, %.lr.ph ], [ %.pre38, %.lr.ph.preheader ]
  %.034 = phi ptr [ %29, %.lr.ph ], [ %0, %.lr.ph.preheader ]
  tail call void @cplx_fft16_ref(ptr noundef %.034, ptr noundef %26)
  %27 = load ptr, ptr %1, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 128
  store ptr %28, ptr %1, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %.034, i64 256
  %30 = icmp ult ptr %29, %5
  br i1 %30, label %.lr.ph, label %._crit_edge, !llvm.loop !12
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log2(double noundef) local_unnamed_addr #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 = { 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 = { 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: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass