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

declare double @fracrevbits(i32 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @fill_cplx_fft_omegas_bfs_2(double noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store double %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %12 = load double, ptr %4, align 8, !tbaa !5
  %13 = fdiv double %12, 2.000000e+00
  store double %13, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %14 = load i32, ptr %6, align 4, !tbaa !11
  %15 = udiv i32 %14, 2
  store i32 %15, ptr %8, align 4, !tbaa !11
  br label %16

16:                                               ; preds = %59, %3
  %17 = load i32, ptr %8, align 4, !tbaa !11
  %18 = icmp sge i32 %17, 2
  br i1 %18, label %20, label %19

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

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %21

21:                                               ; preds = %53, %20
  %22 = load i32, ptr %10, align 4, !tbaa !11
  %23 = load i32, ptr %6, align 4, !tbaa !11
  %24 = load i32, ptr %8, align 4, !tbaa !11
  %25 = mul nsw i32 2, %24
  %26 = udiv i32 %23, %25
  %27 = icmp ult i32 %22, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %21
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %56

29:                                               ; preds = %21
  %30 = load ptr, ptr %5, align 8, !tbaa !9
  %31 = getelementptr inbounds ptr, ptr %30, i64 0
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds [2 x double], ptr %32, i64 0
  %34 = getelementptr inbounds [2 x double], ptr %33, i64 0, i64 0
  %35 = load double, ptr %7, align 8, !tbaa !5
  %36 = load i32, ptr %10, align 4, !tbaa !11
  %37 = call double @fracrevbits(i32 noundef %36)
  %38 = fdiv double %37, 2.000000e+00
  %39 = fadd double %35, %38
  call void @cplx_set_e2pix(ptr noundef %34, double noundef %39)
  %40 = load ptr, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds ptr, ptr %40, i64 0
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds [2 x double], ptr %42, i64 1
  %44 = getelementptr inbounds [2 x double], ptr %43, i64 0, i64 0
  %45 = load ptr, ptr %5, align 8, !tbaa !9
  %46 = getelementptr inbounds ptr, ptr %45, i64 0
  %47 = load ptr, ptr %46, align 8, !tbaa !9
  %48 = getelementptr inbounds [2 x double], ptr %47, i64 0
  %49 = getelementptr inbounds [2 x double], ptr %48, i64 0, i64 0
  call void @cplx_set(ptr noundef %44, ptr noundef %49)
  %50 = load ptr, ptr %5, align 8, !tbaa !9
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  %52 = getelementptr inbounds [2 x double], ptr %51, i64 2
  store ptr %52, ptr %50, align 8, !tbaa !9
  br label %53

53:                                               ; preds = %29
  %54 = load i32, ptr %10, align 4, !tbaa !11
  %55 = add i32 %54, 1
  store i32 %55, ptr %10, align 4, !tbaa !11
  br label %21, !llvm.loop !13

56:                                               ; preds = %28
  %57 = load double, ptr %7, align 8, !tbaa !5
  %58 = fdiv double %57, 2.000000e+00
  store double %58, ptr %7, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %56
  %60 = load i32, ptr %8, align 4, !tbaa !11
  %61 = ashr i32 %60, 1
  store i32 %61, ptr %8, align 4, !tbaa !11
  br label %16, !llvm.loop !15

62:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %63

63:                                               ; preds = %90, %62
  %64 = load i32, ptr %11, align 4, !tbaa !11
  %65 = load i32, ptr %6, align 4, !tbaa !11
  %66 = udiv i32 %65, 2
  %67 = icmp ult i32 %64, %66
  br i1 %67, label %69, label %68

68:                                               ; preds = %63
  store i32 8, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %93

69:                                               ; preds = %63
  %70 = load ptr, ptr %5, align 8, !tbaa !9
  %71 = load ptr, ptr %70, align 8, !tbaa !9
  %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 %7, align 8, !tbaa !5
  %75 = load i32, ptr %11, align 4, !tbaa !11
  %76 = call double @fracrevbits(i32 noundef %75)
  %77 = fdiv double %76, 2.000000e+00
  %78 = fadd double %74, %77
  call void @cplx_set_e2pix(ptr noundef %73, double noundef %78)
  %79 = load ptr, ptr %5, align 8, !tbaa !9
  %80 = load ptr, ptr %79, align 8, !tbaa !9
  %81 = getelementptr inbounds [2 x double], ptr %80, i64 1
  %82 = getelementptr inbounds [2 x double], ptr %81, i64 0, i64 0
  %83 = load ptr, ptr %5, align 8, !tbaa !9
  %84 = load ptr, ptr %83, align 8, !tbaa !9
  %85 = getelementptr inbounds [2 x double], ptr %84, i64 0
  %86 = getelementptr inbounds [2 x double], ptr %85, i64 0, i64 0
  call void @cplx_neg(ptr noundef %82, ptr noundef %86)
  %87 = load ptr, ptr %5, align 8, !tbaa !9
  %88 = load ptr, ptr %87, align 8, !tbaa !9
  %89 = getelementptr inbounds [2 x double], ptr %88, i64 2
  store ptr %89, ptr %87, align 8, !tbaa !9
  br label %90

90:                                               ; preds = %69
  %91 = load i32, ptr %11, align 4, !tbaa !11
  %92 = add i32 %91, 1
  store i32 %92, ptr %11, align 4, !tbaa !11
  br label %63, !llvm.loop !16

93:                                               ; preds = %68
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

declare void @cplx_neg(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 }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !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_set_e2pix(ptr noundef, double noundef) local_unnamed_addr #0

declare double @fracrevbits(i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @fill_cplx_fft_omegas_bfs_2(double noundef %0, ptr nocapture noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = lshr i32 %2, 1
  %.02528 = fmul double %0, 5.000000e-01
  %5 = icmp ugt i32 %2, 3
  br i1 %5, label %.preheader26, label %.preheader

.preheader26:                                     ; preds = %3, %._crit_edge
  %.02530 = phi double [ %.025, %._crit_edge ], [ %.02528, %3 ]
  %.02429 = phi i32 [ %8, %._crit_edge ], [ %4, %3 ]
  %6 = shl nuw nsw i32 %.02429, 1
  %7 = udiv i32 %2, %6
  %.not = icmp ugt i32 %6, %2
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

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

.preheader:                                       ; preds = %._crit_edge, %3
  %.025.lcssa = phi double [ %.02528, %3 ], [ %.025, %._crit_edge ]
  %.not34 = icmp ult i32 %2, 2
  br i1 %.not34, label %._crit_edge33, label %.lr.ph32.preheader

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

._crit_edge:                                      ; preds = %.lr.ph, %.preheader26
  %8 = lshr i32 %.02429, 1
  %.025 = fmul double %.02530, 5.000000e-01
  %9 = icmp ugt i32 %.02429, 3
  br i1 %9, label %.preheader26, label %.preheader, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %10 = phi ptr [ %17, %.lr.ph ], [ %.pre, %.lr.ph.preheader ]
  %.02327 = phi i32 [ %18, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %11 = tail call double @fracrevbits(i32 noundef %.02327) #2
  %12 = fmul double %11, 5.000000e-01
  %13 = fadd double %.02530, %12
  tail call void @cplx_set_e2pix(ptr noundef %10, double noundef %13)
  %14 = load ptr, ptr %1, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  tail call void @cplx_set(ptr noundef nonnull %15, ptr noundef %14) #2
  %16 = load ptr, ptr %1, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 32
  store ptr %17, ptr %1, align 8, !tbaa !5
  %18 = add nuw nsw i32 %.02327, 1
  %19 = icmp ult i32 %18, %7
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge33:                                    ; preds = %.lr.ph32, %.preheader
  ret void

.lr.ph32:                                         ; preds = %.lr.ph32.preheader, %.lr.ph32
  %20 = phi ptr [ %27, %.lr.ph32 ], [ %.pre36, %.lr.ph32.preheader ]
  %.031 = phi i32 [ %28, %.lr.ph32 ], [ 0, %.lr.ph32.preheader ]
  %21 = tail call double @fracrevbits(i32 noundef %.031) #2
  %22 = fmul double %21, 5.000000e-01
  %23 = fadd double %.025.lcssa, %22
  tail call void @cplx_set_e2pix(ptr noundef %20, double noundef %23)
  %24 = load ptr, ptr %1, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  tail call void @cplx_neg(ptr noundef nonnull %25, ptr noundef %24) #2
  %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 = add nuw nsw i32 %.031, 1
  %exitcond.not = icmp eq i32 %28, %4
  br i1 %exitcond.not, label %._crit_edge33, label %.lr.ph32, !llvm.loop !12
}

declare void @cplx_neg(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 = { 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,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass