; 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_twiddle_fft_ref(i32 noundef, ptr noundef, ptr noundef) #1

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

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

20:                                               ; preds = %59, %3
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = icmp sge i32 %21, 2
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %62

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %25, ptr %11, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %52, %24
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = icmp ult ptr %27, %28
  br i1 %29, label %31, label %30

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

31:                                               ; preds = %26
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = getelementptr inbounds [2 x double], ptr %33, i64 0
  %35 = getelementptr inbounds [2 x double], ptr %34, i64 0, i64 0
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds [2 x double], ptr %37, i64 1
  %39 = getelementptr inbounds [2 x double], ptr %38, i64 0, i64 0
  %40 = call i32 @memcmp(ptr noundef %35, ptr noundef %39, i64 noundef 8) #5
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %31
  call void @abort() #6
  unreachable

43:                                               ; preds = %31
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = getelementptr inbounds [2 x double], ptr %47, i64 0, i64 0
  call void @cplx_twiddle_fft_ref(i32 noundef %44, ptr noundef %45, ptr noundef %48)
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = getelementptr inbounds [2 x double], ptr %50, i64 2
  store ptr %51, ptr %49, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %43
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = mul nsw i32 2, %53
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = sext i32 %54 to i64
  %57 = getelementptr inbounds [2 x double], ptr %55, i64 %56
  store ptr %57, ptr %11, align 8, !tbaa !5
  br label %26, !llvm.loop !11

58:                                               ; preds = %30
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = ashr i32 %60, 1
  store i32 %61, ptr %9, align 4, !tbaa !9
  br label %20, !llvm.loop !13

62:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %63, ptr %12, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %105, %62
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = icmp ult ptr %65, %66
  br i1 %67, label %69, label %68

68:                                               ; preds = %64
  store i32 8, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %108

69:                                               ; preds = %64
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = load ptr, ptr %70, align 8, !tbaa !5
  %72 = getelementptr inbounds [2 x double], ptr %71, i64 0
  %73 = getelementptr inbounds [2 x double], ptr %72, i64 0, i64 0
  %74 = load double, ptr %73, align 8, !tbaa !14
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = load ptr, ptr %75, align 8, !tbaa !5
  %77 = getelementptr inbounds [2 x double], ptr %76, i64 1
  %78 = getelementptr inbounds [2 x double], ptr %77, i64 0, i64 0
  %79 = load double, ptr %78, align 8, !tbaa !14
  %80 = fneg double %79
  %81 = fcmp une double %74, %80
  br i1 %81, label %82, label %83

82:                                               ; preds = %69
  call void @abort() #6
  unreachable

83:                                               ; preds = %69
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = load ptr, ptr %84, align 8, !tbaa !5
  %86 = getelementptr inbounds [2 x double], ptr %85, i64 0
  %87 = getelementptr inbounds [2 x double], ptr %86, i64 0, i64 1
  %88 = load double, ptr %87, align 8, !tbaa !14
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = load ptr, ptr %89, align 8, !tbaa !5
  %91 = getelementptr inbounds [2 x double], ptr %90, i64 1
  %92 = getelementptr inbounds [2 x double], ptr %91, i64 0, i64 1
  %93 = load double, ptr %92, align 8, !tbaa !14
  %94 = fneg double %93
  %95 = fcmp une double %88, %94
  br i1 %95, label %96, label %97

96:                                               ; preds = %83
  call void @abort() #6
  unreachable

97:                                               ; preds = %83
  %98 = load ptr, ptr %12, align 8, !tbaa !5
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = load ptr, ptr %99, align 8, !tbaa !5
  %101 = getelementptr inbounds [2 x double], ptr %100, i64 0, i64 0
  call void @merge_fft_last_ref(ptr noundef %98, ptr noundef %101)
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = load ptr, ptr %102, align 8, !tbaa !5
  %104 = getelementptr inbounds [2 x double], ptr %103, i64 2
  store ptr %104, ptr %102, align 8, !tbaa !5
  br label %105

105:                                              ; preds = %97
  %106 = load ptr, ptr %12, align 8, !tbaa !5
  %107 = getelementptr inbounds [2 x double], ptr %106, i64 2
  store ptr %107, ptr %12, align 8, !tbaa !5
  br label %64, !llvm.loop !16

108:                                              ; preds = %68
  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 willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 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 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 #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 = { nounwind willreturn memory(read) }
attributes #6 = { 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 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = distinct !{!16, !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_twiddle_fft_ref(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @cplx_fft_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
  %6 = icmp ugt i32 %2, 3
  br i1 %6, label %.preheader29.us.preheader, label %.preheader

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

.preheader29.us:                                  ; preds = %.preheader29.us.preheader, %..loopexit_crit_edge.us
  %.pre = phi ptr [ %14, %..loopexit_crit_edge.us ], [ %.pre.pre, %.preheader29.us.preheader ]
  %.028.in32.us = phi i32 [ %.02833.us, %..loopexit_crit_edge.us ], [ %2, %.preheader29.us.preheader ]
  %.02833.us = lshr i32 %.028.in32.us, 1
  %7 = and i32 %.028.in32.us, -2
  %8 = zext nneg i32 %7 to i64
  br label %9

9:                                                ; preds = %.preheader29.us, %12
  %10 = phi ptr [ %.pre, %.preheader29.us ], [ %14, %12 ]
  %.02730.us = phi ptr [ %0, %.preheader29.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)
  %.not.us = icmp eq i32 %bcmp.us, 0
  br i1 %.not.us, label %12, label %.split.us

12:                                               ; preds = %9
  tail call void @cplx_twiddle_fft_ref(i32 noundef %.02833.us, ptr noundef %.02730.us, ptr noundef %10)
  %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 %.02730.us, i64 %8
  %16 = icmp ult ptr %15, %5
  br i1 %16, label %9, label %..loopexit_crit_edge.us, !llvm.loop !9

..loopexit_crit_edge.us:                          ; preds = %12
  %17 = icmp ugt i32 %.028.in32.us, 7
  br i1 %17, label %.preheader29.us, label %.preheader, !llvm.loop !11

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

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

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

._crit_edge:                                      ; preds = %33, %.preheader
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %33
  %18 = phi ptr [ %35, %33 ], [ %.pre36, %.lr.ph.preheader ]
  %.034 = phi ptr [ %36, %33 ], [ %0, %.lr.ph.preheader ]
  %19 = load double, ptr %18, align 8, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %18, i64 16
  %21 = load double, ptr %20, align 8, !tbaa !12
  %22 = fneg double %21
  %23 = fcmp une double %19, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %.lr.ph
  tail call void @abort() #3
  unreachable

25:                                               ; preds = %.lr.ph
  %26 = getelementptr inbounds i8, ptr %18, i64 8
  %27 = load double, ptr %26, align 8, !tbaa !12
  %28 = getelementptr inbounds i8, ptr %18, i64 24
  %29 = load double, ptr %28, align 8, !tbaa !12
  %30 = fneg double %29
  %31 = fcmp une double %27, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %25
  tail call void @abort() #3
  unreachable

33:                                               ; preds = %25
  tail call void @merge_fft_last_ref(ptr noundef %.034, ptr noundef nonnull %18)
  %34 = load ptr, ptr %1, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 32
  store ptr %35, ptr %1, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %.034, i64 32
  %37 = icmp ult ptr %36, %5
  br i1 %37, label %.lr.ph, label %._crit_edge, !llvm.loop !14
}

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

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) 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 = { 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 #2 = { nofree nounwind willreturn memory(argmem: read) }
attributes #3 = { 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 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = distinct !{!14, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass