; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

declare void @cplx_split_fft_ref(i32 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @cplx_ifft_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 i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = 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) #4
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = uitofp i32 %13 to double
  %15 = call double @log2(double noundef %14) #4
  %16 = fptoui double %15 to i64
  store i64 %16, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds [2 x double], ptr %17, i64 %19
  store ptr %20, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %21, ptr %9, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %34, %3
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = icmp ult ptr %23, %24
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %22
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  call void @cplx_ifft16_ref(ptr noundef %28, ptr noundef %30)
  %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 8
  store ptr %33, ptr %31, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %27
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = getelementptr inbounds [2 x double], ptr %35, i64 16
  store ptr %36, ptr %9, align 8, !tbaa !5
  br label %22, !llvm.loop !13

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

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

43:                                               ; preds = %57, %41
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = icmp ult ptr %44, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %63

48:                                               ; preds = %43
  %49 = load i32, ptr %10, align 4, !tbaa !9
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  %53 = getelementptr inbounds [2 x double], ptr %52, i64 0, i64 0
  call void @cplx_split_fft_ref(i32 noundef %49, ptr noundef %50, ptr noundef %53)
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %56 = getelementptr inbounds [2 x double], ptr %55, i64 1
  store ptr %56, ptr %54, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %48
  %58 = load i32, ptr %10, align 4, !tbaa !9
  %59 = mul nsw i32 2, %58
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = sext i32 %59 to i64
  %62 = getelementptr inbounds [2 x double], ptr %60, i64 %61
  store ptr %62, ptr %11, align 8, !tbaa !5
  br label %43, !llvm.loop !15

63:                                               ; preds = %47
  store i32 32, ptr %10, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %63, %37
  br label %65

65:                                               ; preds = %91, %64
  %66 = load i32, ptr %10, align 4, !tbaa !9
  %67 = load i32, ptr %6, align 4, !tbaa !9
  %68 = icmp ult i32 %66, %67
  br i1 %68, label %69, label %94

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

71:                                               ; preds = %84, %69
  %72 = load ptr, ptr %12, align 8, !tbaa !5
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = icmp ult ptr %72, %73
  br i1 %74, label %76, label %75

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

76:                                               ; preds = %71
  %77 = load i32, ptr %10, align 4, !tbaa !9
  %78 = load ptr, ptr %12, align 8, !tbaa !5
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = load ptr, ptr %79, align 8, !tbaa !5
  call void @cplx_bisplit_fft_ref(i32 noundef %77, ptr noundef %78, ptr noundef %80)
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load ptr, ptr %81, align 8, !tbaa !5
  %83 = getelementptr inbounds [2 x double], ptr %82, i64 2
  store ptr %83, ptr %81, align 8, !tbaa !5
  br label %84

84:                                               ; preds = %76
  %85 = load i32, ptr %10, align 4, !tbaa !9
  %86 = mul nsw i32 4, %85
  %87 = load ptr, ptr %12, align 8, !tbaa !5
  %88 = sext i32 %86 to i64
  %89 = getelementptr inbounds [2 x double], ptr %87, i64 %88
  store ptr %89, ptr %12, align 8, !tbaa !5
  br label %71, !llvm.loop !16

90:                                               ; preds = %75
  br label %91

91:                                               ; preds = %90
  %92 = load i32, ptr %10, align 4, !tbaa !9
  %93 = shl i32 %92, 2
  store i32 %93, ptr %10, align 4, !tbaa !9
  br label %65, !llvm.loop !17

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

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

declare void @cplx_bisplit_fft_ref(i32 noundef, ptr noundef, ptr 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 = { "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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}


; 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_ifft16_ref(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @cplx_split_fft_ref(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @cplx_ifft_ref_bfs_16(ptr noundef %0, ptr nocapture noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = uitofp i32 %2 to double
  %5 = tail call double @log2(double noundef %4) #3
  %6 = fptoui double %5 to i64
  %7 = zext i32 %2 to i64
  %8 = getelementptr inbounds [2 x double], ptr %0, i64 %7
  %.not44 = icmp eq i32 %2, 0
  br i1 %.not44, label %._crit_edge.thread, label %.lr.ph.preheader

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

._crit_edge:                                      ; preds = %.lr.ph
  %9 = and i64 %6, 1
  %.not = icmp eq i64 %9, 0
  %brmerge = or i1 %.not, %.not44
  %.mux = select i1 %.not, i32 16, i32 32
  br i1 %brmerge, label %.loopexit, label %.lr.ph38.preheader

._crit_edge.thread:                               ; preds = %3
  %10 = and i64 %6, 1
  %.not50 = icmp eq i64 %10, 0
  %spec.select = select i1 %.not50, i32 16, i32 32
  br label %.loopexit

.lr.ph38.preheader:                               ; preds = %._crit_edge
  %.pre47 = load ptr, ptr %1, align 8, !tbaa !5
  br label %.lr.ph38

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %11 = phi ptr [ %13, %.lr.ph ], [ %.pre, %.lr.ph.preheader ]
  %.03336 = phi ptr [ %14, %.lr.ph ], [ %0, %.lr.ph.preheader ]
  tail call void @cplx_ifft16_ref(ptr noundef %.03336, ptr noundef %11)
  %12 = load ptr, ptr %1, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 128
  store ptr %13, ptr %1, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %.03336, i64 256
  %15 = icmp ult ptr %14, %8
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.lr.ph38:                                         ; preds = %.lr.ph38.preheader, %.lr.ph38
  %16 = phi ptr [ %18, %.lr.ph38 ], [ %.pre47, %.lr.ph38.preheader ]
  %.03137 = phi ptr [ %19, %.lr.ph38 ], [ %0, %.lr.ph38.preheader ]
  tail call void @cplx_split_fft_ref(i32 noundef 16, ptr noundef %.03137, ptr noundef %16) #3
  %17 = load ptr, ptr %1, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  store ptr %18, ptr %1, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.03137, i64 512
  %20 = icmp ult ptr %19, %8
  br i1 %20, label %.lr.ph38, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %.lr.ph38, %._crit_edge.thread, %._crit_edge
  %.032 = phi i32 [ %.mux, %._crit_edge ], [ %spec.select, %._crit_edge.thread ], [ 32, %.lr.ph38 ]
  %21 = icmp ult i32 %.032, %2
  br i1 %21, label %.preheader.us.preheader, label %._crit_edge43

.preheader.us.preheader:                          ; preds = %.loopexit
  %.pre48.pre = load ptr, ptr %1, align 8, !tbaa !5
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge41.us
  %.pre48 = phi ptr [ %27, %._crit_edge41.us ], [ %.pre48.pre, %.preheader.us.preheader ]
  %.142.us = phi i32 [ %22, %._crit_edge41.us ], [ %.032, %.preheader.us.preheader ]
  %22 = shl i32 %.142.us, 2
  %23 = sext i32 %22 to i64
  br label %24

24:                                               ; preds = %.preheader.us, %24
  %25 = phi ptr [ %.pre48, %.preheader.us ], [ %27, %24 ]
  %.039.us = phi ptr [ %0, %.preheader.us ], [ %28, %24 ]
  tail call void @cplx_bisplit_fft_ref(i32 noundef %.142.us, ptr noundef %.039.us, ptr noundef %25) #3
  %26 = load ptr, ptr %1, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 32
  store ptr %27, ptr %1, align 8, !tbaa !5
  %28 = getelementptr inbounds [2 x double], ptr %.039.us, i64 %23
  %29 = icmp ult ptr %28, %8
  br i1 %29, label %24, label %._crit_edge41.us, !llvm.loop !12

._crit_edge41.us:                                 ; preds = %24
  %30 = icmp ult i32 %22, %2
  br i1 %30, label %.preheader.us, label %._crit_edge43, !llvm.loop !13

._crit_edge43:                                    ; preds = %._crit_edge41.us, %.loopexit
  ret void
}

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

declare void @cplx_bisplit_fft_ref(i32 noundef, ptr noundef, ptr 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 = { "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 = { 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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass