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

declare double @fracrevbits(i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @fill_cplx_ifft_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 = load i32, ptr %6, align 4, !tbaa !11
  %14 = uitofp i32 %13 to double
  %15 = fdiv double %12, %14
  store double %15, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %16

16:                                               ; preds = %35, %3
  %17 = load i32, ptr %8, align 4, !tbaa !11
  %18 = load i32, ptr %6, align 4, !tbaa !11
  %19 = udiv i32 %18, 2
  %20 = icmp ult i32 %17, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %38

22:                                               ; preds = %16
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = getelementptr inbounds [2 x double], ptr %24, i64 0
  %26 = getelementptr inbounds [2 x double], ptr %25, i64 0, i64 0
  %27 = load double, ptr %7, align 8, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !11
  %29 = call double @fracrevbits(i32 noundef %28)
  %30 = fdiv double %29, 2.000000e+00
  %31 = fadd double %27, %30
  call void @cplx_set_e2pimx(ptr noundef %26, double noundef %31)
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = getelementptr inbounds [2 x double], ptr %33, i64 1
  store ptr %34, ptr %32, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %22
  %36 = load i32, ptr %8, align 4, !tbaa !11
  %37 = add i32 %36, 1
  store i32 %37, ptr %8, align 4, !tbaa !11
  br label %16, !llvm.loop !13

38:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 2, ptr %9, align 4, !tbaa !11
  br label %39

39:                                               ; preds = %84, %38
  %40 = load i32, ptr %9, align 4, !tbaa !11
  %41 = load i32, ptr %6, align 4, !tbaa !11
  %42 = udiv i32 %41, 2
  %43 = icmp ule i32 %40, %42
  br i1 %43, label %45, label %44

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

45:                                               ; preds = %39
  %46 = load double, ptr %7, align 8, !tbaa !5
  %47 = fmul double %46, 2.000000e+00
  store double %47, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %48

48:                                               ; preds = %80, %45
  %49 = load i32, ptr %11, align 4, !tbaa !11
  %50 = load i32, ptr %6, align 4, !tbaa !11
  %51 = load i32, ptr %9, align 4, !tbaa !11
  %52 = mul nsw i32 2, %51
  %53 = udiv i32 %50, %52
  %54 = icmp ult i32 %49, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %48
  store i32 8, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %83

56:                                               ; preds = %48
  %57 = load ptr, ptr %5, align 8, !tbaa !9
  %58 = getelementptr inbounds ptr, ptr %57, i64 0
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  %60 = getelementptr inbounds [2 x double], ptr %59, i64 0
  %61 = getelementptr inbounds [2 x double], ptr %60, i64 0, i64 0
  %62 = load double, ptr %7, align 8, !tbaa !5
  %63 = load i32, ptr %11, align 4, !tbaa !11
  %64 = call double @fracrevbits(i32 noundef %63)
  %65 = fdiv double %64, 2.000000e+00
  %66 = fadd double %62, %65
  call void @cplx_set_e2pimx(ptr noundef %61, double noundef %66)
  %67 = load ptr, ptr %5, align 8, !tbaa !9
  %68 = getelementptr inbounds ptr, ptr %67, i64 0
  %69 = load ptr, ptr %68, align 8, !tbaa !9
  %70 = getelementptr inbounds [2 x double], ptr %69, i64 1
  %71 = getelementptr inbounds [2 x double], ptr %70, i64 0, i64 0
  %72 = load ptr, ptr %5, align 8, !tbaa !9
  %73 = getelementptr inbounds ptr, ptr %72, i64 0
  %74 = load ptr, ptr %73, align 8, !tbaa !9
  %75 = getelementptr inbounds [2 x double], ptr %74, i64 0
  %76 = getelementptr inbounds [2 x double], ptr %75, i64 0, i64 0
  call void @cplx_set(ptr noundef %71, ptr noundef %76)
  %77 = load ptr, ptr %5, align 8, !tbaa !9
  %78 = load ptr, ptr %77, align 8, !tbaa !9
  %79 = getelementptr inbounds [2 x double], ptr %78, i64 2
  store ptr %79, ptr %77, align 8, !tbaa !9
  br label %80

80:                                               ; preds = %56
  %81 = load i32, ptr %11, align 4, !tbaa !11
  %82 = add i32 %81, 1
  store i32 %82, ptr %11, align 4, !tbaa !11
  br label %48, !llvm.loop !15

83:                                               ; preds = %55
  br label %84

84:                                               ; preds = %83
  %85 = load i32, ptr %9, align 4, !tbaa !11
  %86 = shl i32 %85, 1
  store i32 %86, ptr %9, align 4, !tbaa !11
  br label %39, !llvm.loop !16

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

declare void @cplx_set(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_e2pimx(ptr noundef, double noundef) local_unnamed_addr #0

declare double @fracrevbits(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @fill_cplx_ifft_omegas_bfs_2(double noundef %0, ptr nocapture noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = uitofp i32 %2 to double
  %5 = fdiv double %0, %4
  %6 = lshr i32 %2, 1
  %.not35 = icmp ult i32 %2, 2
  br i1 %.not35, label %._crit_edge, label %.lr.ph.preheader

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

.preheader:                                       ; preds = %.lr.ph
  %.not31 = icmp ult i32 %2, 4
  br i1 %.not31, label %._crit_edge, label %.lr.ph34

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %7 = phi ptr [ %12, %.lr.ph ], [ %.pre, %.lr.ph.preheader ]
  %.02327 = phi i32 [ %13, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %8 = tail call double @fracrevbits(i32 noundef %.02327) #2
  %9 = fmul double %8, 5.000000e-01
  %10 = fadd double %5, %9
  tail call void @cplx_set_e2pimx(ptr noundef %7, double noundef %10)
  %11 = load ptr, ptr %1, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  store ptr %12, ptr %1, align 8, !tbaa !5
  %13 = add nuw nsw i32 %.02327, 1
  %exitcond.not = icmp eq i32 %13, %6
  br i1 %exitcond.not, label %.preheader, label %.lr.ph, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph29, %.lr.ph34
  %.not = icmp ugt i32 %15, %6
  br i1 %.not, label %._crit_edge, label %.lr.ph34, !llvm.loop !11

._crit_edge:                                      ; preds = %.loopexit, %3, %.preheader
  ret void

.lr.ph34:                                         ; preds = %.preheader, %.loopexit
  %.02233 = phi i32 [ %15, %.loopexit ], [ 2, %.preheader ]
  %.02432 = phi double [ %14, %.loopexit ], [ %5, %.preheader ]
  %14 = fmul double %.02432, 2.000000e+00
  %15 = shl nuw nsw i32 %.02233, 1
  %16 = udiv i32 %2, %15
  %.not36 = icmp ugt i32 %15, %2
  br i1 %.not36, label %.loopexit, label %.lr.ph29.preheader

.lr.ph29.preheader:                               ; preds = %.lr.ph34
  %.pre37 = load ptr, ptr %1, align 8, !tbaa !5
  br label %.lr.ph29

.lr.ph29:                                         ; preds = %.lr.ph29.preheader, %.lr.ph29
  %17 = phi ptr [ %24, %.lr.ph29 ], [ %.pre37, %.lr.ph29.preheader ]
  %.028 = phi i32 [ %25, %.lr.ph29 ], [ 0, %.lr.ph29.preheader ]
  %18 = tail call double @fracrevbits(i32 noundef %.028) #2
  %19 = fmul double %18, 5.000000e-01
  %20 = fadd double %14, %19
  tail call void @cplx_set_e2pimx(ptr noundef %17, double noundef %20)
  %21 = load ptr, ptr %1, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  tail call void @cplx_set(ptr noundef nonnull %22, ptr noundef %21) #2
  %23 = load ptr, ptr %1, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 32
  store ptr %24, ptr %1, align 8, !tbaa !5
  %25 = add nuw i32 %.028, 1
  %26 = icmp ult i32 %25, %16
  br i1 %26, label %.lr.ph29, label %.loopexit, !llvm.loop !12
}

declare void @cplx_set(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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass