; 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
define dso_local void @cplx_ifft_ref_bfs_2(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
  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) #5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds [2 x double], ptr %13, i64 %15
  store ptr %16, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %17, ptr %8, align 8, !tbaa !5
  br label %18

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

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

23:                                               ; preds = %18
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds [2 x double], ptr %26, i64 0
  %28 = getelementptr inbounds [2 x double], ptr %27, i64 0, i64 0
  call void @split_fft_last_ref(ptr noundef %24, ptr noundef %28)
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds [2 x double], ptr %30, i64 1
  store ptr %31, ptr %29, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %23
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds [2 x double], ptr %33, i64 2
  store ptr %34, ptr %8, align 8, !tbaa !5
  br label %18, !llvm.loop !11

35:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = udiv i32 %36, 2
  store i32 %37, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 2, ptr %10, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %78, %35
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = icmp sle i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 5, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %81

43:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %44, ptr %12, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %71, %43
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = icmp ult ptr %46, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %45
  store i32 8, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %77

50:                                               ; preds = %45
  %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
  %54 = getelementptr inbounds [2 x double], ptr %53, i64 0, i64 0
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = getelementptr inbounds [2 x double], ptr %56, i64 1
  %58 = getelementptr inbounds [2 x double], ptr %57, i64 0, i64 0
  %59 = call i32 @memcmp(ptr noundef %54, ptr noundef %58, i64 noundef 8) #6
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %62

61:                                               ; preds = %50
  call void @abort() #7
  unreachable

62:                                               ; preds = %50
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = getelementptr inbounds [2 x double], ptr %66, i64 0, i64 0
  call void @cplx_split_fft_ref(i32 noundef %63, ptr noundef %64, ptr noundef %67)
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = getelementptr inbounds [2 x double], ptr %69, i64 2
  store ptr %70, ptr %68, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %62
  %72 = load i32, ptr %10, align 4, !tbaa !9
  %73 = mul nsw i32 2, %72
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  %75 = sext i32 %73 to i64
  %76 = getelementptr inbounds [2 x double], ptr %74, i64 %75
  store ptr %76, ptr %12, align 8, !tbaa !5
  br label %45, !llvm.loop !13

77:                                               ; preds = %49
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %10, align 4, !tbaa !9
  %80 = shl i32 %79, 1
  store i32 %80, ptr %10, align 4, !tbaa !9
  br label %38, !llvm.loop !14

81:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret void
}

declare void @split_fft_last_ref(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #3

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

declare void @cplx_split_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 willreturn memory(read) "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 = { 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { 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 = !{!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
define dso_local void @cplx_ifft_ref_bfs_2(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
  %.not34 = icmp eq i32 %2, 0
  br i1 %.not34, label %._crit_edge33, 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
  %6 = lshr i32 %2, 1
  %.not31 = icmp ult i32 %2, 4
  br i1 %.not31, label %._crit_edge33, label %.preheader.us.preheader

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

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge30.us
  %.pre36 = phi ptr [ %14, %._crit_edge30.us ], [ %.pre36.pre, %.preheader.us.preheader ]
  %.02332.us = phi i32 [ %7, %._crit_edge30.us ], [ 2, %.preheader.us.preheader ]
  %7 = shl i32 %.02332.us, 1
  %8 = sext i32 %7 to i64
  br label %9

9:                                                ; preds = %.preheader.us, %12
  %10 = phi ptr [ %.pre36, %.preheader.us ], [ %14, %12 ]
  %.028.us = phi ptr [ %0, %.preheader.us ], [ %15, %12 ]
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %bcmp.us = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(8) %10, ptr noundef nonnull dereferenceable(8) %11, i64 8)
  %.not26.us = icmp eq i32 %bcmp.us, 0
  br i1 %.not26.us, label %12, label %.split.us

12:                                               ; preds = %9
  tail call void @cplx_split_fft_ref(i32 noundef %.02332.us, ptr noundef %.028.us, ptr noundef %10) #4
  %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
  %15 = getelementptr inbounds [2 x double], ptr %.028.us, i64 %8
  %16 = icmp ult ptr %15, %5
  br i1 %16, label %9, label %._crit_edge30.us, !llvm.loop !9

._crit_edge30.us:                                 ; preds = %12
  %.not.us = icmp sgt i32 %7, %6
  br i1 %.not.us, label %._crit_edge33, label %.preheader.us, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %17 = phi ptr [ %19, %.lr.ph ], [ %.pre, %.lr.ph.preheader ]
  %.02427 = phi ptr [ %20, %.lr.ph ], [ %0, %.lr.ph.preheader ]
  tail call void @split_fft_last_ref(ptr noundef %.02427, ptr noundef %17) #4
  %18 = load ptr, ptr %1, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  store ptr %19, ptr %1, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %.02427, i64 32
  %21 = icmp ult ptr %20, %5
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge33:                                    ; preds = %._crit_edge30.us, %3, %._crit_edge
  ret void

.split.us:                                        ; preds = %9
  tail call void @abort() #5
  unreachable
}

declare void @split_fft_last_ref(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #3

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 = { 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 = { nofree nounwind willreturn memory(argmem: read) }
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 = !{!"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,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass