; LLVM IR from tfhe/spqlios-arithmetic :: test/testlib/fft64_dft.ll (Z12simple_fft64RK10polynomialIlE)

; 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"

%class.reim_fft64vec = type { %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN13reim_fft64vec4dataEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z12simple_fft64RK10polynomialIlE(ptr dead_on_unwind noalias writable sret(%class.reim_fft64vec) align 8 %0, ptr noundef nonnull align 8 dereferenceable(24) %1) #2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i1, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call noundef i64 @_ZNK10polynomialIlE2nnEv(ptr noundef nonnull align 8 dereferenceable(24) %12)
  store i64 %13, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = udiv i64 %14, 2
  store i64 %15, ptr %6, align 8, !tbaa !9
  store i1 false, ptr %7, align 1
  %16 = load i64, ptr %5, align 8, !tbaa !9
  call void @_ZN13reim_fft64vecC1Em(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %16)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %17 = call noundef ptr @_ZN13reim_fft64vec4dataEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  store ptr %17, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %32, %2
  %19 = load i64, ptr %9, align 8, !tbaa !9
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %23, label %22

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

23:                                               ; preds = %18
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = invoke noundef i64 @_ZNK10polynomialIlE9get_coeffEl(ptr noundef nonnull align 8 dereferenceable(24) %24, i64 noundef %25)
          to label %27 unwind label %35

27:                                               ; preds = %23
  %28 = sitofp i64 %26 to double
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load i64, ptr %9, align 8, !tbaa !9
  %31 = getelementptr inbounds double, ptr %29, i64 %30
  store double %28, ptr %31, align 8, !tbaa !11
  br label %32

32:                                               ; preds = %27
  %33 = load i64, ptr %9, align 8, !tbaa !9
  %34 = add i64 %33, 1
  store i64 %34, ptr %9, align 8, !tbaa !9
  br label %18, !llvm.loop !13

35:                                               ; preds = %23
  %36 = landingpad { ptr, i32 }
          cleanup
  %37 = extractvalue { ptr, i32 } %36, 0
  store ptr %37, ptr %10, align 8
  %38 = extractvalue { ptr, i32 } %36, 1
  store i32 %38, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %49

39:                                               ; preds = %22
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = trunc i64 %40 to i32
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  invoke void @reim_fft_simple(i32 noundef %41, ptr noundef %42)
          to label %43 unwind label %45

43:                                               ; preds = %39
  store i1 true, ptr %7, align 1
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %44 = load i1, ptr %7, align 1
  br i1 %44, label %51, label %50

45:                                               ; preds = %39
  %46 = landingpad { ptr, i32 }
          cleanup
  %47 = extractvalue { ptr, i32 } %46, 0
  store ptr %47, ptr %10, align 8
  %48 = extractvalue { ptr, i32 } %46, 1
  store i32 %48, ptr %11, align 4
  br label %49

49:                                               ; preds = %45, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @_ZN13reim_fft64vecD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %0) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %52

50:                                               ; preds = %43
  call void @_ZN13reim_fft64vecD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %0) #5
  br label %51

51:                                               ; preds = %50, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void

52:                                               ; preds = %49
  %53 = load ptr, ptr %10, align 8
  %54 = load i32, ptr %11, align 4
  %55 = insertvalue { ptr, i32 } poison, ptr %53, 0
  %56 = insertvalue { ptr, i32 } %55, i32 %54, 1
  resume { ptr, i32 } %56
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN13reim_fft64vecD2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #3 align 2

declare noundef i64 @_ZNK10polynomialIlE2nnEv(ptr noundef nonnull align 8 dereferenceable(24)) #4

declare noundef i64 @_ZNK10polynomialIlE9get_coeffEl(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #4

declare void @reim_fft_simple(i32 noundef, ptr noundef) #4

declare void @_ZN13reim_fft64vecC1Em(ptr, i64)

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 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 = { inlinehint mustprogress 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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"

%class.reim_fft64vec = type { %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" = type { ptr, ptr, ptr }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN13reim_fft64vec4dataEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z12simple_fft64RK10polynomialIlE(ptr dead_on_unwind noalias writable sret(%class.reim_fft64vec) align 8 %0, ptr noundef nonnull align 8 dereferenceable(24) %1) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %3 = tail call noundef i64 @_ZNK10polynomialIlE2nnEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %4 = lshr i64 %3, 1
  tail call void @_ZN13reim_fft64vecC1Em(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %3)
  %5 = tail call noundef ptr @_ZN13reim_fft64vec4dataEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %8, %2
  %6 = trunc i64 %4 to i32
  invoke void @reim_fft_simple(i32 noundef %6, ptr noundef %5)
          to label %17 unwind label %14

.lr.ph:                                           ; preds = %2, %8
  %.01517 = phi i64 [ %11, %8 ], [ 0, %2 ]
  %7 = invoke noundef i64 @_ZNK10polynomialIlE9get_coeffEl(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.01517)
          to label %8 unwind label %12

8:                                                ; preds = %.lr.ph
  %9 = sitofp i64 %7 to double
  %10 = getelementptr inbounds double, ptr %5, i64 %.01517
  store double %9, ptr %10, align 8, !tbaa !5
  %11 = add nuw i64 %.01517, 1
  %exitcond.not = icmp eq i64 %11, %3
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

12:                                               ; preds = %.lr.ph
  %13 = landingpad { ptr, i32 }
          cleanup
  br label %16

14:                                               ; preds = %._crit_edge
  %15 = landingpad { ptr, i32 }
          cleanup
  br label %16

16:                                               ; preds = %14, %12
  %.pn = phi { ptr, i32 } [ %13, %12 ], [ %15, %14 ]
  tail call void @_ZN13reim_fft64vecD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  resume { ptr, i32 } %.pn

17:                                               ; preds = %._crit_edge
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN13reim_fft64vecD2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

declare noundef i64 @_ZNK10polynomialIlE2nnEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #3

declare noundef i64 @_ZNK10polynomialIlE9get_coeffEl(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #3

declare void @reim_fft_simple(i32 noundef, ptr noundef) local_unnamed_addr #3

declare void @_ZN13reim_fft64vecC1Em(ptr, i64) local_unnamed_addr

attributes #0 = { mustprogress 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 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 = { inlinehint mustprogress 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 = { "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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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